/* Prep: dark + gold. Tokens follow the original brand (static/app.css on main). */

/* ── tokens ─────────────────────────────────────────────────────────────── */
:root {
  color-scheme: dark;
  --bg: #181818; --surface: #202020; --surface2: #2a2a2a; --sidebar: #1c1c1c;
  --border: #2e2e2e; --border-soft: #242424;
  --text: #e4e4e4; --muted: #8a8a8a; --faint: #4a4a4a;
  --gold: #c9a35a; --gold-dim: #5a4828; --gold-glow: rgba(201,163,90,.12); --on-gold: #1a1200;
  --good: #769656; --bad: #c94f4f;
  --inacc: #c8a84b; --mistake: #d9803f; --blunder: #c94f4f;
  --board-light: #b8a070; --board-dark: #6b4f2a;
  --display: 'Fraunces', Georgia, serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --sidebar-w: 184px;
}
[data-theme="light"] {
  color-scheme: light;
  --bg: #faf9f6; --surface: #ffffff; --surface2: #f1efe9; --sidebar: #f4f2ec;
  --border: #e4e1d8; --border-soft: #ece9e0;
  --text: #2a2825; --muted: #7a7670; --faint: #b5b0a5;
  --gold: #8a6a22; --gold-dim: #d4c088; --gold-glow: rgba(138,106,34,.09); --on-gold: #ffffff;
  --good: #4d6b38; --bad: #b23b3b;
  --inacc: #a37c1b; --mistake: #b85f1f; --blunder: #b23b3b;
  --board-light: #e8d9b2; --board-dark: #a88a5c;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; }
[hidden] { display: none !important; }
a { color: var(--gold); }
kbd { font: 11px var(--mono); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; color: var(--text); }

/* ── wordmark ───────────────────────────────────────────────────────────── */
.wordmark { display: flex; align-items: center; gap: 10px; color: var(--gold); text-decoration: none; }
.wordmark .glyph { width: 22px; height: 26px; flex: none; }
.wordmark span { color: var(--text); font-weight: 700; font-size: 13px; letter-spacing: .24em; }

/* ── sidebar (desktop) / drawer (mobile) ────────────────────────────────── */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 400;
  display: flex; flex-direction: column; gap: 4px; padding: 18px 10px 14px;
  background: var(--sidebar); border-right: 1px solid var(--border);
}
.sidebar .wordmark { padding: 0 8px 16px; margin-bottom: 8px; border-bottom: 1px solid var(--border-soft); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--muted); text-decoration: none; font-size: 13.5px; }
.nav-link svg { width: 16px; height: 16px; flex: none; }
.nav-link:hover { color: var(--text); background: var(--surface2); }
.nav-link.active { color: var(--text); background: var(--gold-glow); }
.nav-link.active svg { color: var(--gold); }
.nav-link.soon { color: var(--faint); cursor: default; background: none; }
.nav-link small { margin-left: auto; font: 10px var(--mono); }
.side-toggle { margin-top: auto; justify-content: flex-start; background: none; border: 0; color: var(--muted); font-weight: 500; padding: 8px 10px; }
.side-toggle:hover { color: var(--text); background: var(--surface2); }
.topbar, .backdrop { display: none; }

/* ── page ───────────────────────────────────────────────────────────────── */
.main { margin-left: var(--sidebar-w); padding: 26px 28px 60px; max-width: calc(var(--sidebar-w) + 1320px); }
.page-head h1 { font: 500 30px/1.1 var(--display); letter-spacing: -.01em; margin: 0 0 6px; }
.page-head h1 em { color: var(--gold); }
.sub { color: var(--muted); margin: 0 0 20px; max-width: 64ch; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.stat b { display: block; font: 600 22px/1.2 var(--mono); }
.stat span { color: var(--muted); font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; }

.workspace { display: grid; grid-template-columns: clamp(300px, 34vw, 460px) minmax(0, 1fr); gap: 22px; align-items: start; }
.board-col { position: sticky; top: 18px; }

/* ── tabs ───────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 22px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs button {
  background: none; border: 0; border-radius: 0; padding: 8px 0 10px; margin-bottom: -1px;
  color: var(--muted); font-size: 11.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  border-bottom: 2px solid transparent;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--gold); border-bottom-color: var(--gold); }

/* ── cards + form ───────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; margin-bottom: 14px; }
.label { font-size: 10.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 0 0 12px; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.card-head .label { flex: 1; margin: 0; }
.setup-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 0 14px; align-items: start; }

label { display: block; color: var(--muted); font-size: 12px; margin: 12px 0 5px; }
input[type=text], input[type=number], select {
  width: 100%; background: var(--surface2); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; font: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--gold); }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checks label { display: flex; gap: 6px; align-items: center; margin: 0; color: var(--text); font-size: 13px; }
input[type=checkbox] { accent-color: var(--gold); }

button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
button:hover:not(:disabled) { border-color: var(--faint); }
button:disabled { opacity: .45; cursor: default; }
button:focus-visible, .tabs button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
button.primary { background: var(--gold); border-color: var(--gold); color: var(--on-gold); }
button.primary:hover:not(:disabled) { filter: brightness(1.08); border-color: var(--gold); }
button.small { padding: 5px 10px; font-size: 12px; }
button.ghost.small { font-weight: 500; }
.row { display: flex; gap: 8px; align-items: end; }
.row > * { flex: 1; }
.row > button { flex: 0 0 auto; }
.actions { margin-top: 16px; }
.actions > button { flex: 1; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { flex: 1; background: transparent; color: var(--muted); border: 0; border-radius: 0; font-weight: 500; }
.seg button.on { background: var(--gold-glow); color: var(--gold); font-weight: 600; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.log { font: 12px var(--mono); color: var(--muted); white-space: pre-wrap; margin-top: 10px; }
.log .err { color: var(--bad); }

/* ── tree ───────────────────────────────────────────────────────────────── */
.legend { color: var(--muted); font-size: 12px; margin: -4px 0 12px; line-height: 1.7; }
.legend b { color: var(--gold); }
.v-mistake { color: var(--mistake); }
.tree { font-size: 13px; overflow-x: auto; }
.node { padding-left: 14px; border-left: 1px solid var(--border); margin-left: 6px; }
.rowline { display: grid; grid-template-columns: 14px minmax(0, 1fr) 44px 60px 44px; align-items: baseline; gap: 10px; padding: 4px 6px; border-radius: 5px; }
.rowline:hover { background: var(--surface2); }
.toggle { color: var(--muted); user-select: none; cursor: pointer; }
.chain { min-width: 0; font-family: var(--mono); font-size: 12.5px; line-height: 1.75; }
.chip { padding: 1px 3px; border-radius: 3px; cursor: pointer; white-space: nowrap; }
.chip:hover { background: var(--gold-glow); }
.chip.online { background: var(--surface2); box-shadow: inset 0 -1px 0 var(--gold-dim); }
.chip.sel { background: var(--gold); color: var(--on-gold) !important; box-shadow: none; }
.chip.mine { color: var(--gold); font-weight: 600; }
.chip.opp { color: var(--muted); }
.chip.shaky { text-decoration: underline wavy var(--inacc); text-underline-offset: 3px; }
.chip.v-inaccuracy { color: var(--inacc); }
.chip.v-mistake { color: var(--mistake); }
.chip.v-blunder { color: var(--blunder); }
.n { color: var(--muted); text-align: right; font: 12px var(--mono); }
.bar { height: 5px; background: var(--surface2); border-radius: 3px; overflow: hidden; align-self: center; }
.bar.none { background: transparent; }
.bar i { display: block; height: 100%; background: var(--muted); }
.score { text-align: right; font: 12px var(--mono); }
.note { font-size: 12px; color: var(--muted); padding: 0 6px 4px 30px; }
.note.warn { color: var(--inacc); }
.note.warn::before { content: '⚠ '; }
.note.bad { color: var(--mistake); }
.note.bad::before { content: '✗ '; }
.empty { color: var(--muted); padding: 30px; text-align: center; }
.empty b { color: var(--text); }

/* ── analysis + report ──────────────────────────────────────────────────── */
.progress { height: 4px; background: var(--surface2); border-radius: 2px; overflow: hidden; margin-top: 10px; }
.progress i { display: block; height: 100%; width: 0; background: var(--gold); transition: width .2s; }
.report-summary { margin: 14px 0 4px; }
.report-section h3 { font: 500 18px/1.2 var(--display); margin: 22px 0 2px; }
.report-list { margin: 8px 0 0; padding-left: 22px; }
.report-list li { padding: 7px 8px; border-radius: 6px; cursor: pointer; }
.report-list li::marker { color: var(--faint); font: 12px var(--mono); }
.report-list li:hover { background: var(--surface2); }
.report-line { font-family: var(--mono); font-size: 12px; color: var(--muted); line-height: 1.7; }
.report-line .mark { font-weight: 600; padding: 0 3px; border-radius: 3px; background: var(--surface2); }
.report-line .mark.v-inaccuracy { color: var(--inacc); }
.report-line .mark.v-mistake { color: var(--mistake); }
.report-line .mark.v-blunder { color: var(--blunder); }
.report-what { font-size: 13px; }
.report-empty { color: var(--muted); font-size: 13px; margin: 6px 0 0; }

/* ── board + detail ─────────────────────────────────────────────────────── */
.board-wrap { width: 100%; aspect-ratio: 1; border-radius: 4px; overflow: hidden; }
.board-wrap .cg-wrap { width: 100% !important; height: 100% !important; }
/* brand board colours: 2×2 conic tile repeated 4×4 (a8 light) */
.board-wrap cg-board {
  background: conic-gradient(var(--board-dark) 0 90deg, var(--board-light) 0 180deg, var(--board-dark) 0 270deg, var(--board-light) 0) 0 0 / 25% 25%;
}
.board-wrap cg-board square.last-move { background-color: rgba(240, 196, 80, .45); }
.board-wrap coords { font: 600 10px var(--mono); opacity: .9; }
/* same alternation as chessground.brown.css: first group sits on light squares */
.cg-wrap coords:nth-child(odd) coord:nth-child(even),
.cg-wrap coords.squares:nth-child(even) coord:nth-child(odd),
.cg-wrap.orientation-black coords.files:nth-child(even) coord:nth-child(odd),
.cg-wrap coords.files:nth-child(even) coord:nth-child(even) { color: var(--board-dark); }
.cg-wrap coords:nth-child(odd) coord:nth-child(odd),
.cg-wrap coords.squares:nth-child(even) coord:nth-child(even),
.cg-wrap.orientation-black coords.files:nth-child(even) coord:nth-child(even),
.cg-wrap coords.files:nth-child(even) coord:nth-child(odd) { color: var(--board-light); }
.strip { margin-top: 10px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; font: 12px/1.9 var(--mono); max-height: 110px; overflow-y: auto; }
.strip .chip.after { opacity: .4; }
.detail { margin-top: 12px; font-size: 13px; }
.detail .line { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-bottom: 8px; word-break: break-word; }
.detail p { margin: 4px 0; }
.saved { list-style: none; padding: 0; margin: 10px 0 0; }
.saved li { display: flex; gap: 6px; align-items: center; padding: 6px 0; border-top: 1px solid var(--border-soft); }
.saved li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── narrower desktop: board column shrinks ─────────────────────────────── */
@media (max-width: 1080px) {
  .workspace { grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: 18px; }
  .main { padding: 22px 20px 60px; }
}

/* ── mobile ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .topbar {
    display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 300;
    height: 48px; padding: 0 8px; background: var(--sidebar); border-bottom: 1px solid var(--border);
  }
  .topbar .wordmark { flex: 1; }
  .topbar .glyph { width: 19px; height: 22px; }
  .icon-btn { background: none; border: 0; color: var(--muted); padding: 0; width: 40px; height: 40px; font-size: 17px; font-weight: 400; }
  .icon-btn svg { width: 18px; height: 18px; }
  .sidebar { transform: translateX(-100%); transition: transform .25s ease; width: 230px; }
  .sidebar.open { transform: none; }
  .backdrop { display: block; position: fixed; inset: 0; z-index: 350; background: rgba(0,0,0,.6); opacity: 0; pointer-events: none; transition: opacity .25s; }
  .backdrop.open { opacity: 1; pointer-events: auto; }
  .main { margin-left: 0; padding: 16px 14px calc(40px + env(safe-area-inset-bottom)); }
  .page-head h1 { font-size: 24px; }
  .page-head h1 { margin-bottom: 14px; }
  .sub { display: none; }
  .stats { gap: 6px; margin-bottom: 14px; }
  .stat { padding: 7px 8px; border-radius: 8px; }
  .stat b { font-size: 16px; }
  .stat span { font-size: 9px; letter-spacing: .04em; }
  .workspace { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .board-col { position: static; }
  .tabs { position: sticky; top: 48px; z-index: 200; background: var(--bg); gap: 0; margin: 0 -14px 12px; padding: 0 14px; }
  .tabs button { flex: 1; padding: 12px 0; }
  .card { padding: 14px; }
  .legend .keys { display: none; }
  .rowline { grid-template-columns: 12px minmax(0, 1fr) 34px 36px 38px; gap: 6px; padding: 4px 2px; }
  .node { padding-left: 8px; margin-left: 4px; }
  .note { padding-left: 20px; }
  input[type=text], input[type=number], select { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar, .backdrop, .progress i { transition: none; }
}
