*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: 'Inter', sans-serif;
    color: var(--text-main);
    background: #0E0906;
    overflow: hidden;
    overscroll-behavior: none;
}

/* ── Full-page container ────────────────────────────────────────────────────
   Column flex so the header sits at the top and board-area takes the rest. */
.app-background {
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
    background:
        radial-gradient(ellipse 90% 45% at 50% 0%, rgba(160, 28, 12, 0.20) 0%, transparent 85%),
        radial-gradient(ellipse 50% 30% at 50% 100%, rgba(40, 10, 0, 0.45) 0%, transparent 100%),
        #0E0906;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ── Game layout — full-height column, max-width centred ────────────────── */
.game-layout {
    width: 100%;
    max-width: 620px;
    height: 100dvh;
    min-height: 0;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* ── Header — always pinned to the top of the layout column ─────────────── */
.game-header {
    flex-shrink: 0;
    text-align: center;
    padding: 18px 10px 10px;
    position: sticky;
    top: 0;
    z-index: 150;
    background: transparent;
    transition: background 0.3s ease, backdrop-filter 0.3s ease;
}

/* Optional: gain a subtle tint when scrolled - requires JS or a scroll-shadow technique. 
   For now, we keep it fully seamless as requested. */


.main-title {
    font-family: 'Noto Serif', serif;
    font-size: clamp(0.95rem, 4.5vw, 2.5rem);
    font-weight: 700;
    color: var(--dragon-red);
    letter-spacing: clamp(1px, 0.8vw, 4px);
    text-transform: uppercase;
    text-shadow:
        1px 1px 3px rgba(0,0,0,0.9),
        0 0 18px rgba(192, 57, 43, 0.40);
    margin: 0;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.subtitle {
    font-family: 'Inter', sans-serif;
    font-size: clamp(0.52rem, 2vw, 0.82rem);
    font-weight: 600;
    color: var(--text-main);
    letter-spacing: clamp(2px, 1.2vw, 5px);
    text-transform: uppercase;
    opacity: 0.55;
    margin: 4px 0 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Shared name-fit utility: JS sets font-size and optional horizontal scale to
   guarantee no truncation/overflow across constrained UI regions. */
.name-autofit {
    display: inline-block;
    min-width: 0;
    max-width: 100%;
    white-space: nowrap;
    overflow: visible;
    text-overflow: clip;
    transform-origin: left center;
    transform: scaleX(var(--name-scale-x, 1));
    will-change: transform, font-size;
}

/* ── Board area — column stack: opp strip / board / self strip ───────────── */
.board-area {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4px 8px 12px;
    gap: 6px;
}

/* ── Board frame — dark rosewood / lacquered wood ───────────────────────── */
.board-wrapper {
    /* JS sets width + height to canvas + 3px border (box-sizing:border-box).
       Canvas is flush with the frame border — zero padding gap.
       overflow:hidden clips the canvas to the rounded frame corners. */
    flex-shrink: 0;
    overflow: hidden;
    border-radius: 12px;
    background: linear-gradient(150deg, #2E1A08 0%, #1C0E04 55%, #120A03 100%);
    border: 1.5px solid rgba(197, 160, 89, 0.55);
    outline: 1px solid rgba(0, 0, 0, 0.6);
    outline-offset: -2px;
    box-shadow:
        0 24px 55px -8px rgba(0, 0, 0, 0.92),
        0 0 60px -10px rgba(140, 22, 8, 0.18),
        inset 0 1px 0 rgba(220, 170, 80, 0.18);
}

/* ── Canvas — cool dark slate; temperature contrast from warm frame ──────── */
.xiangqi-board {
    display: block;
    /* width and height set explicitly by JS — wrapper border-box matches */
    background: #0A0A10;
    box-shadow:
        inset 0 0 60px rgba(0, 0, 0, 0.92),
        inset 0 0 12px rgba(0, 0, 30, 0.5);
}

/* ── Landscape phones — collapse header so board fills screen ────────────── */
@media (max-height: 500px) and (orientation: landscape) {
    .game-header { padding: 6px 8px 4px; }
    .main-title  { font-size: 1.1rem; letter-spacing: 4px; }
    .subtitle    { display: none; }
    .board-area  { padding: 2px 4px 6px; }
}
