/* ── Fonts ───────────────────────────────────────────────────── */
  @import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;600&family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@300;400;500&display=swap');

  /* ── Design tokens ───────────────────────────────────────────── */
  :root {
    /* ── Grays ── */
    --bg:         #1a1a1a;   /* app background */
    --bg-mid:     #222222;   /* panel / topbar */
    --bg-light:   #2a2a2a;   /* hover, subtle lift */
    --border:     #383838;   /* dividers */
    --border-dim: #2e2e2e;   /* very subtle lines */

    /* ── Text ── */
    --text:       #e8e8e8;   /* primary text */
    --text-dim:   #888888;   /* secondary / labels */
    --text-mute:  #555555;   /* placeholder, disabled */

    /* ── Player colours ── */
    --p1:         #1a1a1a;   /* black checker */
    --p1-text:    #e8e8e8;
    --p2:         #e8e8e8;   /* white checker */
    --p2-text:    #1a1a1a;

    /* ── Accent (used sparingly: selected row, active element) ── */
    --accent:     #5a8fc0;   /* steel blue */
    --accent-dim: #3a6090;

    /* ── Error severity (colorblind-safe) ── */
    --best:       #4a9a6a;   /* muted green  — best play */
    --inaccuracy: #5a8fc0;   /* steel blue   — small error */
    --error:      #c89000;   /* amber        — error */
    --blunder:    #e05a00;   /* red-orange   — blunder */

    /* ── Board triangle colours ── */
    --tri-a:      #3a3a3a;   /* dark triangle */
    --tri-b:      #555555;   /* light triangle */

    --panel-w:    320px;
    --header-h:   56px;
    --mono:       'IBM Plex Mono', monospace;
    --sans:       'IBM Plex Sans', sans-serif;
    --serif:      'Playfair Display', serif;
  }

  /* ── Light theme overrides ───────────────────────────────────── */
  :root[data-theme="light"] {
    --bg:         #f0f0ed;
    --bg-mid:     #e6e6e2;
    --bg-light:   #dcdcd7;
    --border:     #c4c4be;
    --border-dim: #d4d4ce;

    --text:       #1a1a1a;
    --text-dim:   #555555;
    --text-mute:  #999999;

    --p1:         #1a1a1a;
    --p1-text:    #e8e8e8;
    --p2:         #e8e8e8;
    --p2-text:    #1a1a1a;

    --accent:     #2e6da4;
    --accent-dim: #1e4d7a;

    --tri-a:      #c8c8c2;
    --tri-b:      #a8a8a0;
  }

  /* ── Reset & base ────────────────────────────────────────────── */
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

  html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 14px;
    overflow: hidden;
  }

  /* ── App shell ───────────────────────────────────────────────── */
  #app {
    display: flex;
    flex-direction: column;
    height: 100vh;
  }

  /* ── Top bar ─────────────────────────────────────────────────── */
  #topbar {
    height: var(--header-h);
    min-height: var(--header-h);
    background: var(--bg-mid);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 20px;
    z-index: 10;
  }

  #topbar .logo {
    font-family: var(--sans);
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    white-space: nowrap;
  }

  #topbar .logo span {
    color: var(--text-dim);
    font-size: 13px;
    font-family: var(--sans);
    font-weight: 300;
    margin-left: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  #topbar .spacer { flex: 1; }

  /* upload button in top bar */
  #upload-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 18px;
    height: 34px;
    background: transparent;
    border: 1px solid var(--text-mute);
    border-radius: 3px;
    color: var(--accent);
    font-family: var(--sans);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
  }
  #upload-btn:hover {
    background: rgba(90,143,192,0.08);
    border-color: var(--accent);
    color: var(--accent);
  }
  #upload-btn svg { flex-shrink: 0; }
  #file-input { display: none; }

  /* match info pill in topbar */
  #match-info {
    font-family: var(--sans);
    font-size: 12px;
    color: var(--text-dim);
    letter-spacing: 0.04em;
    opacity: 0;
    transition: opacity 0.3s;
  }
  #match-info.visible { opacity: 1; }

  /* ── Main area: three panels ─────────────────────────────────── */
  #panels {
    flex: 1;
    display: flex;
    overflow: hidden;
  }

  .panel {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    overflow: hidden;
  }
  .panel:last-child { border-right: none; }

  /* Panel headers */
  .panel-header {
    padding: 0 18px;
    height: 38px;
    min-height: 38px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    background: rgba(0,0,0,0.15);
  }
  .panel-header .panel-title {
    font-family: var(--sans);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-dim);
  }
  .panel-header .panel-badge {
    margin-left: auto;
    font-family: var(--mono);
    font-size: 10px;
    color: var(--text-mute);
    letter-spacing: 0.05em;
  }

  /* Panel bodies */
  .panel-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
  }
  .panel-body::-webkit-scrollbar { width: 5px; }
  .panel-body::-webkit-scrollbar-track { background: transparent; }
  .panel-body::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
  }

  #analysis-body {
    overflow-y: hidden;
    display: flex;
    flex-direction: column;
  }
  #analysis-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
  }

  /* ── Panel widths ────────────────────────────────────────────── */
  #panel-moves  { width: var(--panel-w); min-width: var(--panel-w); }
  #panel-board  { flex: 1; }
  #panel-detail { width: var(--panel-w); min-width: var(--panel-w); }

  /* ── Drop zone (left panel empty state) ─────────────────────── */
  #drop-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 32px;
    text-align: center;
    border: 2px dashed var(--border);
    margin: 16px;
    border-radius: 6px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    gap: 14px;
  }
  #drop-zone:hover,
  #drop-zone.drag-over {
    border-color: var(--text-mute);
    background: rgba(255,255,255,0.03);
  }
  #drop-zone .dz-icon {
    color: var(--text-mute);
    opacity: 0.7;
  }
  #drop-zone .dz-title {
    font-family: var(--sans);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-dim);
    letter-spacing: 0.04em;
  }
  #drop-zone .dz-sub {
    font-family: var(--sans);
    font-size: 11px;
    color: var(--text-mute);
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  /* ── Move list ───────────────────────────────────────────────── */
  #move-list {
    display: none;
    flex-direction: column;
    padding: 8px 0;
  }
  #move-list.visible { display: flex; }

  .move-row {
    display: flex;
    align-items: center;
    padding: 5px 16px 5px 14px;
    gap: 10px;
    cursor: pointer;
    border-left: 2px solid transparent;
    transition: background 0.1s, border-color 0.1s;
    line-height: 1.4;
  }
  .move-row:hover {
    background: rgba(255,255,255,0.04);
    border-left-color: var(--text-mute);
  }
  .move-row.active {
    background: rgba(255,255,255,0.07);
    border-left-color: var(--text-dim);
  }

  /* nav button hover states */
  #game-prev:hover, #game-next:hover {
    color: var(--accent) !important;
    background: rgba(255,255,255,0.05);
  }
  #game-prev:disabled, #game-next:disabled {
    opacity: .25;
    cursor: default;
  }
  #game-title-btn:hover {
    background: rgba(255,255,255,0.04);
  }
  #game-dropdown-arrow.open {
    transform: rotate(180deg);
  }

  /* dropdown items */
  .game-dd-item {
    padding: 9px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-dim);
    transition: background .1s;
  }
  .game-dd-item:last-child { border-bottom: none; }
  .game-dd-item:hover { background: var(--bg-light); }
  .game-dd-item.active { background: var(--border); }
  .game-dd-item .dd-game {
    font-family: var(--sans);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text);
  }
  .game-dd-item.active .dd-game { color: var(--text); }
  .game-dd-item .dd-score {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--text-dim);
    letter-spacing: .04em;
    margin-top: 2px;
  }

  /* cube rows — styled like move rows */
  .cube-row {
    display: flex;
    align-items: center;
    padding: 5px 16px 5px 14px;
    gap: 10px;
    cursor: pointer;
    border-left: 2px solid transparent;
    transition: background 0.1s, border-color 0.1s;
    line-height: 1.4;
  }
  .cube-row:hover {
    background: rgba(255,255,255,0.04);
    border-left-color: var(--text-mute);
  }
  .cube-row.active {
    background: rgba(255,255,255,0.07);
    border-left-color: var(--text-dim);
  }
  .cube-action {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text-dim);
    flex: 1;
  }
  .cube-value {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text-mute);
    flex-shrink: 0;
  }

  /* game-end row */
  .end-row {
    padding: 6px 16px 12px;
    font-family: var(--sans);
    font-size: 11px;
    color: var(--text-dim);
    letter-spacing: 0.05em;
    font-style: italic;
    justify-content: center;
  }

  /* player name chip */
  /* player chip — used everywhere instead of player names */
  .chip {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    vertical-align: middle;
    position: relative;
    top: -1px;
  }
  .chip.p1 { background: #1a1a1a; border: 1.5px solid #555; }
  .chip.p2 { background: #e8e8e8; border: 1.5px solid #aaa; }

  /* board-side label shown above/below the SVG */
  .board-side-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    font-family: var(--sans);
    font-size: 11px;
    color: var(--text-dim);
    letter-spacing: .05em;
  }
  .board-side-label.top  { border-bottom: 1px solid var(--border); }
  .board-side-label.bottom { border-top: 1px solid var(--border); }

  /* move-player: transparent container that centres the inner .chip */
  .move-player {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    flex-shrink: 0;
  }
  /* chip inside move-player fills the container */
  .move-player .chip { width: 18px; height: 18px; top: 0; }

  /* row-cube-icon: reserved slot (every move/cube row gets one, right
     after the chip) for a small severity-coloured cube glyph — solid
     for an actual cube decision, hollow for pre-move cube analysis on a
     checker-move row, empty (no svg child) when neither applies. Sized
     to match .move-player's slot so the chip and the cube glyph sit on
     the same rhythm; severity colour itself is set inline per-row (SVG
     fill/stroke), same convention as the rest of the analysis panel. */
  .row-cube-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    flex-shrink: 0;
  }

  /* dice */
  .move-dice {
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    flex-shrink: 0;
    min-width: 22px;
  }

  /* move notation */
  .move-notation {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text-dim);
    word-break: break-all;
    flex: 1;
  }
  .move-notation .no-move {
    color: var(--border);
    font-style: italic;
    justify-content: center;
  }

  /* ── Placeholder panels ──────────────────────────────────────── */
  .panel-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 12px;
    opacity: 0.25;
  }
  .panel-placeholder svg { color: var(--text-dim); }
  .panel-placeholder p {
    font-family: var(--sans);
    font-size: 12px;
    color: var(--text-dim);
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  /* ── Loading spinner ─────────────────────────────────────────── */
  #loading {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 14px;
  }
  #loading.visible { display: flex; }

  .spinner {
    width: 28px;
    height: 28px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  #loading p {
    font-family: var(--sans);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-dim);
  }

  /* ── Error toast ─────────────────────────────────────────────── */
  #error-toast {
    display: none;
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--blunder);
    color: var(--text);
    font-family: var(--sans);
    font-size: 13px;
    padding: 10px 20px;
    border-radius: 4px;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  }
  #error-toast.visible { display: block; }

  /* ── Analysis panel — two sections ──────────────────────────── */
  .analysis-section {
    border-bottom: 1px solid var(--border);
    padding-bottom: 4px;
    margin-bottom: 0;
  }
  .analysis-section:last-child { border-bottom: none; }

  .analysis-sticky-top {
    flex-shrink: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border-dim);
  }

  .alt-rows {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
  }
  .alt-rows::-webkit-scrollbar { width: 5px; }
  .alt-rows::-webkit-scrollbar-track { background: transparent; }
  .alt-rows::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
  }

  .section-label {
    padding: 10px 16px 6px;
    font-family: var(--sans);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-mute);
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .section-label .section-line {
    flex: 1; height: 1px; background: var(--border);
  }

  .na-block {
    padding: 10px 16px 14px;
    font-family: var(--sans);
    font-size: 11px;
    color: var(--border);
    font-style: italic;
    letter-spacing: 0.03em;
  }

  /* cube decision section */
  .cube-decision-grid {
    display: grid;
    gap: 1px;
    margin: 4px 16px 18px;
    border: 1px solid var(--border);
    border-radius: 3px;
  }

  /* Take/drop & cube-decision boxes: action top-left, equity top-right,
     severity bottom-left, equity-difference bottom-right. */
  .takedrop-grid {
    grid-template-columns: 1fr 1fr;
  }
  .takedrop-cell {
    position: relative;
    padding: 8px 10px;
    background: rgba(0,0,0,.2);
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  .td-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
  }
  .td-action {
    font-family: var(--sans);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--text);
  }
  .td-eq {
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-dim);
  }
  .td-sub {
    font-family: var(--sans);
    font-size: 9px;
    letter-spacing: .07em;
    text-transform: uppercase;
  }
  .td-diff {
    font-family: var(--mono);
    font-size: 10px;
  }
  .td-subgrid {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .td-action.sub {
    font-size: 10px;
    color: var(--text-dim);
    font-weight: 400;
  }
  .td-eq.sub {
    font-size: 12px;
  }
  .td-badge {
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3;
    display: flex;
    gap: 1px;
    font-size: 13px;
    line-height: 1;
    background: var(--bg);
    border-radius: 8px;
    padding: 1px 4px;
  }

  /* ── Analysis panel ─────────────────────────────────────────── */
  .analysis-header {
    padding: 14px 16px 8px;
  }
  .analysis-dice {
    font-family: var(--serif);
    font-size: 22px;
    color: var(--accent);
    letter-spacing: 0.05em;
  }
  .analysis-player {
    font-family: var(--sans);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-top: 3px;
  }

  .alt-row {
    padding: 7px 14px;
    border-left: 2px solid transparent;
    transition: background 0.1s;
  }
  .alt-row:hover {
    background: rgba(255,255,255,0.03);
  }

  .alt-rank-line {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .alt-rank {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--border);
    min-width: 16px;
    flex-shrink: 0;
  }
  .alt-marks {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    width: 14px;
    flex-shrink: 0;
    font-size: 11px;
    line-height: 1;
  }
  .alt-move {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text);
    word-break: break-all;
  }
  .alt-left-col {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    gap: 2px;
  }
  .alt-sub {
    min-height: 12px;
    line-height: 12px;
  }
  .alt-eq-col {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    min-width: 60px;
    flex-shrink: 0;
  }
  .alt-eq {
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-dim);
    text-align: right;
  }

  .alt-diff {
    font-family: var(--mono);
    font-size: 10px;
    text-align: right;
    margin-top: 1px;
  }

  .alt-prob-bar {
    display: flex;
    height: 3px;
    border-radius: 0px;
    overflow: hidden;
    margin: 4px 0 2px 24px;
    background: rgba(255,255,255,0.05);
  }
  .alt-prob-wbg { background: #249ff1; }
  .alt-prob-wg  { background: #1b7cbd; }
  .alt-prob-w   { background: #104a70; }
  .alt-prob-l   { background: #363e42; }
  .alt-prob-lg  { background: #657077; }
  .alt-prob-lbg { background: #98a9b4; }

  .alt-prob-nums {
    display: flex;
    justify-content: space-between;
    font-family: var(--mono);
    font-size: 10px;
    color: var(--text-dim);
    opacity: 0.8;
    letter-spacing: 0.02em;
    margin-left: 24px;
  }

  .alt-prob-nums-w,
  .alt-prob-nums-l {
    display: flex;
    gap: 8px;
  }

  .alt-prob-nums-w span,
  .alt-prob-nums-l span {
    min-width: 34px;
  }

  .alt-prob-nums-w { text-align: left; }
  .alt-prob-nums-l { text-align: right; }
