/* ══════════════════════════════════════════════════════
   YuliGM Pro CHAMPIONSHIP — style.css v23
   Mobile-first | Desktop = CCC layout
══════════════════════════════════════════════════════ */

/* ─── TOKENS ─────────────────────────────────────── */
:root {
    --bg:       #1a1a1a;
    --bg2:      #212121;
    --hdr:      #111111;
    --bdr:      #363636;
    --acc:      #81b64c;
    --red:      #e05252;
    --wht:      #f0f0f0;
    --wt:       #111111;
    --TOPBAR:   46px;
    --TECH:     42px;
    --CTRL:     52px;
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: #fff;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ═══════════════════════════════════════════════════
   TOP BAR (shared)
═══════════════════════════════════════════════════ */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: var(--TOPBAR);
    padding: 0 12px;
    background: var(--hdr);
    border-bottom: 1px solid var(--bdr);
    position: sticky;
    top: 0;
    z-index: 999;
    gap: 8px;
}
.tb-left  { display: flex; align-items: center; gap: 8px; }
.tb-right { display: flex; align-items: center; gap: 6px; }

.brand-icon { font-size: 18px; color: var(--acc); }
.brand-name { font-size: 14px; font-weight: 700; color: #ddd; white-space: nowrap; }
.brand-name strong { color: var(--acc); }

.tc-badge {
    background: #2a2a2a; color: #ccc; font-size: 11px; font-weight: 800;
    padding: 2px 8px; border-radius: 10px; border: 1px solid #3a3a3a;
}
.viewers-badge {
    display: flex; align-items: center; gap: 3px;
    font-size: 12px; font-weight: 700; color: #aaa;
    background: rgba(255,255,255,0.04); padding: 2px 8px;
    border-radius: 10px; border: 1px solid #333;
}
.eye { font-size: 11px; }
.live-badge {
    font-size: 11px; font-weight: 800; padding: 2px 10px;
    border-radius: 10px; background: #2a2a2a; color: #555;
    border: 1px solid #3a3a3a; text-transform: uppercase;
    transition: all .3s;
}
.live-badge.connected {
    background: rgba(129,182,76,0.12); color: var(--acc);
    border-color: rgba(129,182,76,0.4);
    animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{box-shadow:0 0 0 0 rgba(129,182,76,0)} 50%{box-shadow:0 0 6px 2px rgba(129,182,76,0.2)} }

.hdr-btn {
    background: none; border: none; color: #777; font-size: 16px;
    cursor: pointer; padding: 4px; border-radius: 4px; transition: color .2s;
}
.hdr-btn:hover { color: #fff; }

/* ═══════════════════════════════════════════════════
   SHARED: eval bar segments
═══════════════════════════════════════════════════ */
.eval-seg-black { background: #1a1a1a; transition: height .5s ease-out; flex-shrink: 0; }
.eval-seg-white { background: #e8e8e8; transition: height .5s ease-out; flex: 1; }
.eval-midline   { position: absolute; top: 50%; left: 0; right: 0; height: 1px; background: #444; transform: translateY(-50%); }

/* ═══════════════════════════════════════════════════
   SHARED: buttons
═══════════════════════════════════════════════════ */
.c-btn {
    background: #2a2a2a; border: 1px solid #3a3a3a; border-radius: 6px;
    color: #bbb; font-size: 14px; width: 36px; height: 36px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: background .15s, color .15s; flex-shrink: 0;
}
.c-btn:hover  { background: #3a3a3a; color: #fff; }
.c-btn:active { background: #444; }
.c-btn--live  { color: var(--red); border-color: rgba(224,82,82,0.3); }
.c-btn--live:hover { background: rgba(224,82,82,0.1); }
.c-sep { width: 1px; height: 22px; background: #333; flex-shrink: 0; margin: 0 2px; }

/* highlight last move */
.highlight-move  { background-color: rgba(255,255,0,0.40) !important; }


/* ═══════════════════════════════════════════════════
   ██  MOBILE  (< 900px)
   Stack: card-black | board | controls | card-white
═══════════════════════════════════════════════════ */

/* Hide desktop on mobile */
.d-layout { display: none; }

/* ── Engine card ── */
.m-engine-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    min-height: 76px;
    gap: 10px;
    border-bottom: 1px solid var(--bdr);
}
.m-engine--black { background: var(--bg2); }
.m-engine--white {
    background: var(--wht);
    color: var(--wt);
    border-top: 1px solid #ddd;
    border-bottom: none;
}

.m-card-left  { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.m-card-right { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; flex-shrink: 0; }

/* Avatar */
.m-avatar-wrap { position: relative; flex-shrink: 0; }
.m-avatar {
    width: 48px; height: 48px; border-radius: 8px;
    object-fit: cover; border: 2px solid rgba(255,255,255,0.1); background: #111;
}
.m-engine--white .m-avatar { border-color: rgba(0,0,0,0.1); }
.m-flag {
    position: absolute; bottom: -4px; right: -4px;
    font-size: 13px; line-height: 1;
    background: var(--bg2); border-radius: 3px; padding: 1px 2px;
}
.m-engine--white .m-flag { background: var(--wht); }

/* Engine info */
.m-engine-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.m-rank { font-size: 11px; font-weight: 700; color: var(--acc); letter-spacing: .3px; }
.m-engine--white .m-rank { color: #4a7a18; }
.m-name {
    font-size: 14px; font-weight: 800;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 175px;
}
.m-engine--white .m-name { color: var(--wt); }
.m-stats { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.ms-lbl { font-size: 9px; font-weight: 700; text-transform: uppercase; color: #555; }
.m-engine--white .ms-lbl { color: #999; }
.ms-val {
    font-size: 10px; font-weight: 700; color: #aaa;
    background: rgba(255,255,255,0.05); padding: 1px 5px; border-radius: 3px;
    font-variant-numeric: tabular-nums;
}
.m-engine--white .ms-val { color: #333; background: rgba(0,0,0,0.06); }

/* Eval + Clock */
.m-eval  { font-size: 32px; font-weight: 900; letter-spacing: -1.5px; font-variant-numeric: tabular-nums; line-height: 1; }
.m-clock { font-size: 14px; font-weight: 700; color: #888; font-variant-numeric: tabular-nums; letter-spacing: .5px; }
.m-engine--white .m-clock { color: #777; }

/* ── Board zone ── */
.m-board-zone {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    width: 100%;
    background: #000;
    position: relative;
}

/* Vertical eval bar */
.m-eval-bar  { width: 18px; flex-shrink: 0; background: #111; }
.m-eval-inner{
    width: 100%; height: 100%;
    position: relative; display: flex; flex-direction: column; overflow: hidden;
}

/* Board itself fills remaining width exactly */
.m-board-wrap { flex: 1; min-width: 0; }
.m-board-wrap > div { width: 100%; aspect-ratio: 1/1; }

/* Moves list (right of board) */
.m-moves-panel {
    width: 52px; flex-shrink: 0;
    background: #0a0a0a; border-left: 1px solid #222;
    display: flex; flex-direction: column; overflow: hidden;
}
.m-moves-hdr {
    font-size: 8px; font-weight: 800; text-transform: uppercase;
    color: #444; padding: 5px 3px 3px; border-bottom: 1px solid #222; letter-spacing: .5px;
}
.m-moves-list {
    flex: 1; overflow-y: auto; padding: 3px 2px;
    scrollbar-width: thin; scrollbar-color: #333 transparent;
}
.m-moves-list::-webkit-scrollbar { width: 2px; }
.m-moves-list::-webkit-scrollbar-thumb { background: #333; }
.m-pgn-row  { font-size: 9px; font-weight: 700; color: #4db3ff; line-height: 1.6; white-space: nowrap; }

/* ── Controls bar ── */
.m-controls {
    display: flex; align-items: center; justify-content: center;
    gap: 4px; padding: 8px 14px;
    background: #111; border-top: 1px solid var(--bdr); border-bottom: 1px solid var(--bdr);
}


/* ═══════════════════════════════════════════════════
   ██  DESKTOP  (≥ 900px)
   d-layout: d-left (board+table+ctrl) | d-right (engine cards)
═══════════════════════════════════════════════════ */
@media (min-width: 900px) {

    body { overflow: hidden; }

    /* Hide mobile elements */
    .m-engine-card,
    .m-board-zone,
    .m-controls    { display: none !important; }

    /* Show desktop layout */
    .d-layout {
        display: flex;
        flex-direction: row;
        height: calc(100vh - var(--TOPBAR));
        overflow: hidden;
    }

    /* ── LEFT: board + tech + controls ── */
    .d-left {
        display: flex;
        flex-direction: column;
        flex-shrink: 0;
        flex-grow: 0;
        border-right: 1px solid var(--bdr);
        overflow: hidden;
    }

    /* Board zone fills remaining left height */
    .d-board-zone {
        display: flex;
        flex-direction: row;
        align-items: stretch;
        flex: 1;
        min-height: 0;
        background: #000;
        overflow: hidden;
    }

    /* Eval bar */
    .d-eval-bar    { width: 20px; flex-shrink: 0; background: #111; }
    .d-eval-inner  {
        width: 100%; height: 100%;
        position: relative; display: flex; flex-direction: column; overflow: hidden;
    }
    .eval-lbl-top, .eval-lbl-bot {
        position: absolute; left: 50%; transform: translateX(-50%);
        font-size: 7px; font-weight: 800; color: #888;
        writing-mode: vertical-rl; white-space: nowrap;
    }
    .eval-lbl-top { top: 4px; }
    .eval-lbl-bot { bottom: 4px; }

    /* Board: square derived from available height */
    .d-board-wrap {
        --bsz: calc(100vh - var(--TOPBAR) - var(--TECH) - var(--CTRL));
        width:  var(--bsz);
        height: var(--bsz);
        flex-shrink: 0;
        overflow: hidden;
    }
    .d-board-wrap > div { width: 100% !important; height: 100% !important; }

    /* Moves panel */
    .d-moves-panel {
        width: 76px; background: #0a0a0a; border-left: 1px solid #1a1a1a;
        display: flex; flex-direction: column; overflow: hidden; flex-shrink: 0;
    }
    .d-moves-hdr {
        font-size: 9px; font-weight: 800; text-transform: uppercase;
        color: #444; padding: 5px 4px 3px; border-bottom: 1px solid #1a1a1a; letter-spacing: .5px;
    }
    .d-moves-list {
        flex: 1; overflow-y: auto; padding: 4px 3px;
        scrollbar-width: thin; scrollbar-color: #333 transparent;
    }
    .d-moves-list::-webkit-scrollbar { width: 3px; }
    .d-moves-list::-webkit-scrollbar-thumb { background: #333; }
    .d-pgn-row { font-size: 11px; font-weight: 700; color: #4db3ff; line-height: 1.5; white-space: nowrap; }

    /* Tech table */
    .d-tech-table {
        flex-shrink: 0; height: var(--TECH);
        background: #0e0e0e; border-top: 1px solid var(--bdr);
        display: flex; flex-direction: column; overflow: hidden;
    }
    .d-tech-row {
        display: grid;
        grid-template-columns: 112px repeat(6, 1fr);
        font-size: 10px; font-weight: 700; text-align: center;
        padding: 0 8px; flex: 1; align-items: center;
        font-variant-numeric: tabular-nums;
    }
    .d-tech-hdr  { font-size: 9px; color: #555; text-transform: uppercase; flex: none; height: 14px; border-bottom: 1px solid #1a1a1a; }
    .d-tech-lbl  { text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #888; font-size: 9px; }
    .d-tech-dark { background: #1a1a1a; color: #ddd; }
    .d-tech-light{ background: #e0e0e0; color: #222; }

    /* Controls */
    .d-controls {
        flex-shrink: 0; height: var(--CTRL);
        display: flex; align-items: center; justify-content: center;
        gap: 4px; padding: 0 14px;
        background: #141414; border-top: 1px solid var(--bdr);
    }

    /* ── RIGHT: engine cards ── */
    .d-right {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-width: 0;
        overflow: hidden;
    }

    /* Engine card: each = 50% height */
    .d-engine-card {
        display: flex;
        flex-direction: column;
        height: 50%;
        overflow: hidden;
        border-bottom: 1px solid var(--bdr);
    }
    .d-engine--black { background: #1e1e1e; }
    .d-engine--white { background: var(--wht); color: var(--wt); border-bottom: none; }

    /* Card main row: identity | eval | pv-board */
    .d-card-row {
        display: flex;
        flex-direction: row;
        align-items: center;
        flex: 1;
        min-height: 0;
        overflow: hidden;
        padding: 12px 18px;
        gap: 14px;
    }

    /* Identity: avatar + meta */
    .d-card-identity {
        display: flex; align-items: center; gap: 12px;
        flex-shrink: 0; width: 200px;
    }
    .d-avatar-wrap { position: relative; flex-shrink: 0; }
    .d-avatar {
        width: 64px; height: 64px; border-radius: 10px;
        object-fit: cover; border: 2px solid rgba(255,255,255,0.1); background: #111;
        display: block;
    }
    .d-engine--white .d-avatar { border-color: rgba(0,0,0,0.1); }
    .d-flag {
        position: absolute; bottom: -5px; right: -5px;
        font-size: 14px; background: #1e1e1e; border-radius: 3px; padding: 1px 3px;
    }
    .d-engine--white .d-flag { background: var(--wht); }

    .d-engine-meta { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
    .d-rank  { font-size: 12px; font-weight: 700; color: var(--acc); letter-spacing: .3px; }
    .d-engine--white .d-rank { color: #4a7a18; }
    .d-name  { font-size: 15px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
    .d-engine--white .d-name { color: var(--wt); }
    .d-stats { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
    .ds-l { font-size: 9px; font-weight: 700; text-transform: uppercase; color: #555; }
    .d-engine--white .ds-l { color: #aaa; }
    .ds-v {
        font-size: 10px; font-weight: 700; color: #aaa;
        background: rgba(255,255,255,0.06); padding: 1px 6px; border-radius: 3px;
        font-variant-numeric: tabular-nums;
    }
    .d-engine--white .ds-v { color: #333; background: rgba(0,0,0,0.07); }

    /* Eval + Clock (center) */
    .d-card-center {
        flex: 1;
        display: flex; flex-direction: column;
        align-items: center; justify-content: center;
        gap: 6px;
    }
    .d-eval  { font-size: 68px; font-weight: 900; letter-spacing: -3px; font-variant-numeric: tabular-nums; line-height: 1; }
    .d-clock { font-size: 20px; font-weight: 800; color: #777; font-variant-numeric: tabular-nums; }
    .d-engine--white .d-clock { color: #999; }

    /* PV mini-board (right) */
    .d-pv-wrap {
        display: flex; align-items: center; justify-content: center;
        flex-shrink: 0;
    }
    .d-pv-board {
        --pvs: calc((100vh - var(--TOPBAR)) / 2 - 30px);
        width:  min(var(--pvs), 240px);
        height: min(var(--pvs), 240px);
        min-width:  140px;
        min-height: 140px;
    }

    /* PV moves text (bottom strip of each card) */
    .d-pv-moves {
        padding: 0 18px 10px;
        font-size: 11px; font-weight: 600; color: #666;
        flex-shrink: 0; height: 26px;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .d-engine--white .d-pv-moves { color: #aaa; }
    .pv-mv { color: var(--acc); font-weight: 700; margin-right: 3px; }
}

/* ═══════════════════════════════════════════════════
   SMALL PHONE tweaks
═══════════════════════════════════════════════════ */
@media (max-width: 380px) {
    .m-name  { max-width: 130px; font-size: 13px; }
    .m-eval  { font-size: 26px; }
    .c-btn   { width: 30px; height: 30px; font-size: 12px; }
}
