:root {
  color-scheme: light;
  --bg: #f5f4f0;
  --surface: #fcfcfa;
  --surface-2: #ecebe5;
  --border: #dad8cf;
  --text: #121417;
  --text-2: #4c5058;
  --text-3: #767a82;
  --accent: #2a6fc4;
  --accent-ink: #1d559b;
  --accent-soft: #e2ebf7;
  --grid: #e3e1d9;
  --muted-mark: #b9bcc2;
  --warn: #b4441f;
  --sq-light: #ecdab9;
  --sq-dark: #ae7d55;
  --sq-last: rgb(246 214 74 / .55);
  --sq-sel: rgb(42 111 196 / .45);
  --hero-from: #1d2a3a;
  --hero-to: #2b3d52;
  --code-bg: #ecebe5;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .05);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111315;
    --surface: #191b1e;
    --surface-2: #22252a;
    --border: #33373d;
    --text: #eef0f2;
    --text-2: #c0c4ca;
    --text-3: #8d929a;
    --accent: #5b9be6;
    --accent-ink: #8dbaf0;
    --accent-soft: #1d2b3d;
    --grid: #2a2d32;
    --muted-mark: #5a5f67;
    --warn: #ec8a63;
    --sq-light: #d9c4a0;
    --sq-dark: #96694a;
    --hero-from: #141c27;
    --hero-to: #1d2a3a;
    --code-bg: #22252a;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 6px 20px rgb(0 0 0 / .3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111315;
  --surface: #191b1e;
  --surface-2: #22252a;
  --border: #33373d;
  --text: #eef0f2;
  --text-2: #c0c4ca;
  --text-3: #8d929a;
  --accent: #5b9be6;
  --accent-ink: #8dbaf0;
  --accent-soft: #1d2b3d;
  --grid: #2a2d32;
  --muted-mark: #5a5f67;
  --warn: #ec8a63;
  --sq-light: #d9c4a0;
  --sq-dark: #96694a;
  --hero-from: #141c27;
  --hero-to: #1d2a3a;
  --code-bg: #22252a;
  --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 6px 20px rgb(0 0 0 / .3);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 64px; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.6 var(--sans); -webkit-font-smoothing: antialiased; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.01em; }
h2 { font-size: clamp(1.6rem, 3.5vw, 2.1rem); }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
a { color: var(--accent-ink); }
code { font-family: var(--mono); font-size: .88em; background: var(--code-bg); padding: .1em .35em; border-radius: 4px; }
b { font-weight: 650; }
.muted { color: var(--text-3); }
.small { font-size: .86rem; }

/* ---- nav */
.nav { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.nav .wrap { display: flex; align-items: center; gap: 20px; height: 56px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; color: var(--text); text-decoration: none; }
.nav-links { display: flex; gap: 18px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.nav-links a { color: var(--text-2); text-decoration: none; font-size: .93rem; white-space: nowrap; }
.nav-links a:hover { color: var(--text); }
.theme-btn { background: none; border: 1px solid var(--border); color: var(--text-2); border-radius: 8px; width: 34px; height: 34px; display: grid; place-items: center; cursor: pointer; flex: none; }
@media (max-width: 720px) { .nav-links { display: none; } .theme-btn { margin-left: auto; } }

/* ---- hero */
.hero { background: linear-gradient(135deg, var(--hero-from), var(--hero-to)); color: #f1f3f6; padding: 72px 0 56px; position: relative; overflow: hidden; }
.hero::after { content: ""; position: absolute; right: -80px; top: -40px; width: 420px; height: 420px; opacity: .07;
  background: conic-gradient(#fff 25%, transparent 0 50%, #fff 0 75%, transparent 0) 0 0 / 105px 105px; transform: rotate(12deg); pointer-events: none; }
.hero .eyebrow { color: #a9c3e4; }
.hero h1 { font-size: clamp(2.6rem, 7vw, 4rem); margin-bottom: .25em; }
.lede { font-size: 1.15rem; max-width: 720px; color: #d3d9e1; }
.cta { display: flex; gap: 12px; flex-wrap: wrap; margin: 26px 0 40px; }
.hero .btn:not(.primary) { color: #f1f3f6; border-color: rgb(255 255 255 / .3); background: transparent; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stat { border-top: 2px solid rgb(255 255 255 / .2); padding-top: 12px; }
.stat .num { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .lbl { font-size: .86rem; color: #b8c1cd; }
.stat code { background: rgb(255 255 255 / .1); color: inherit; }
@media (max-width: 820px) { .stats { grid-template-columns: repeat(2, 1fr); } }

/* ---- sections */
section { padding: 72px 0; }
section.alt { background: var(--surface); border-block: 1px solid var(--border); }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .78rem; font-weight: 650; color: var(--accent-ink); margin-bottom: 8px; }
.section-lede { color: var(--text-2); max-width: 760px; font-size: 1.05rem; margin-bottom: 32px; }

.btn { font: inherit; font-size: .93rem; font-weight: 600; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.btn:hover { border-color: var(--text-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; font-weight: 500; padding: 6px 10px; font-size: .84rem; }

/* ---- play */
.play { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 28px; align-items: start; }
@media (max-width: 900px) { .play { grid-template-columns: 1fr; } }
.board-wrap { display: flex; gap: 10px; }
.board-frame { position: relative; flex: 1; max-width: 620px; aspect-ratio: 1; border-radius: 6px; overflow: hidden; box-shadow: var(--shadow); }
.board { display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); width: 100%; height: 100%; touch-action: none; user-select: none; }
.sq { position: relative; display: grid; place-items: center; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.last::before, .sq.selected::before { content: ""; position: absolute; inset: 0; background: var(--sq-last); }
.sq.selected::before { background: var(--sq-sel); }
.sq.check { background: radial-gradient(circle, #ff4d3d 0%, rgb(230 40 30 / .6) 40%, transparent 72%), var(--sq-light); }
.sq.dark.check { background: radial-gradient(circle, #ff4d3d 0%, rgb(230 40 30 / .6) 40%, transparent 72%), var(--sq-dark); }
.sq.target::after { content: ""; position: absolute; width: 30%; height: 30%; border-radius: 50%; background: rgb(20 30 40 / .28); pointer-events: none; }
.sq.target.capture::after { width: 92%; height: 92%; background: none; border: 5px solid rgb(20 30 40 / .28); box-sizing: border-box; }
.sq img { position: relative; width: 92%; height: 92%; cursor: grab; z-index: 1; }
.ghost { position: fixed; z-index: 100; pointer-events: none; cursor: grabbing; filter: drop-shadow(0 6px 8px rgb(0 0 0 / .35)); }
.coord { position: absolute; font-size: clamp(9px, 1.6vw, 12px); font-weight: 650; pointer-events: none; z-index: 2; }
.coord.rank { top: 2px; left: 3px; }
.coord.file { bottom: 1px; right: 4px; }
.sq.light .coord { color: var(--sq-dark); }
.sq.dark .coord { color: var(--sq-light); }

.evalbar { width: 22px; flex: none; border-radius: 4px; background: #33363b; position: relative; overflow: hidden; box-shadow: var(--shadow); }
.evalbar .fill { position: absolute; left: 0; right: 0; bottom: 0; background: #f2f2ef; transition: height .5s ease; }
.evalbar .val { position: absolute; left: 0; right: 0; font-size: 9px; font-weight: 700; text-align: center; writing-mode: vertical-rl; transform: rotate(180deg); padding: 4px 0; font-variant-numeric: tabular-nums; }
.evalbar .val[data-side="w"] { bottom: 0; color: #33363b; }
.evalbar .val[data-side="b"] { top: 0; color: #f2f2ef; }

.promo { position: absolute; inset: 0; z-index: 30; background: rgb(0 0 0 / .45); display: flex; align-items: center; justify-content: center; gap: 8px; }
.promo[hidden] { display: none; }
.promo button { width: 18%; aspect-ratio: 1; background: var(--surface); border: none; border-radius: 50%; cursor: pointer; display: grid; place-items: center; box-shadow: var(--shadow); color: var(--text); font-size: 1.3rem; }
.promo button img { width: 85%; }
.promo button.cancel { width: 10%; }
.promo button:hover { outline: 3px solid var(--accent); }

.loader { position: absolute; inset: 0; z-index: 25; display: none; align-items: center; justify-content: center; gap: 10px; background: rgb(0 0 0 / .35); color: #fff; font-weight: 600; }
.play.loading .loader { display: flex; }
.spinner { width: 18px; height: 18px; border: 3px solid rgb(255 255 255 / .3); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.status { margin: 14px 0 0 32px; font-weight: 600; min-height: 1.6em; display: flex; align-items: center; gap: 8px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.status[data-kind="you"]::before { background: #2a9d63; }
.status[data-kind="think"]::before { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.status[data-kind="over"]::before { background: var(--text); }
.status[data-kind="error"] { color: var(--warn); }
@keyframes pulse { 50% { opacity: .25; } }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); }
section.alt .panel { background: var(--bg); }
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.controls label { display: grid; gap: 4px; font-size: .8rem; font-weight: 600; color: var(--text-2); }
.controls label:nth-child(2) { grid-column: span 2; order: -1; }
.controls select { font: inherit; font-size: .9rem; padding: 7px 8px; border-radius: 7px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.controls p { grid-column: span 2; margin: 0; }
.btn-row { display: flex; gap: 8px; grid-column: span 2; }
.btn-row .btn { flex: 1; }
.small-btns { margin-top: 8px; }
.panel-h { font-size: .78rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-3); margin: 20px 0 8px; }
.movelist { list-style: none; margin: 0; padding: 6px; height: 170px; overflow-y: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; font-variant-numeric: tabular-nums; font-size: .9rem; }
.movelist li { display: grid; grid-template-columns: 34px 1fr 1fr; padding: 1px 4px; border-radius: 4px; }
.movelist li:nth-child(even) { background: var(--surface-2); }
.movelist .no { color: var(--text-3); }
.movelist .empty, .movelist .result { display: block; color: var(--text-3); text-align: center; padding: 8px; }
.movelist .result { color: var(--text); font-weight: 700; background: none !important; }
.engine-info { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; font-size: .9rem; }
.engine-info > .muted, .engine-info p { grid-column: span 2; margin: 0; }
.engine-info dt { font-size: .74rem; color: var(--text-3); }
.engine-info dd { margin: 0; font-weight: 650; font-variant-numeric: tabular-nums; }
.engine-info .pv { grid-column: span 2; }
.engine-info .pv dd { font-weight: 500; font-family: var(--mono); font-size: .84rem; word-spacing: .2em; }
.play.thinking .board { cursor: progress; }

/* ---- architecture */
.pipeline { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0; margin: 0 0 36px; counter-reset: s; }
.step { align-content: start; position: relative; padding: 14px 16px 14px 14px; background: var(--bg); border: 1px solid var(--border); margin-right: -1px; display: grid; gap: 3px; }
.step:first-child { border-radius: 10px 0 0 10px; }
.step:last-child { border-radius: 0 10px 10px 0; }
.step .n { font-family: var(--mono); font-size: .75rem; color: var(--accent-ink); }
.step small { color: var(--text-2); font-size: .82rem; line-height: 1.4; }
@media (max-width: 900px) {
  .pipeline { grid-template-columns: 1fr 1fr; gap: 8px; }
  .step, .step:first-child, .step:last-child { border-radius: 10px; margin: 0; }
}
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.cards.three { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1000px) { .cards { grid-template-columns: repeat(2, 1fr); } .cards.three { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .cards, .cards.three { grid-template-columns: 1fr; } }
.card { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 18px; }
section:not(.alt) .card { background: var(--surface); }
.card p { color: var(--text-2); font-size: .92rem; margin: 0; }
.tag { display: inline-block; font-size: .76rem; font-weight: 650; background: var(--accent-soft); color: var(--accent-ink); padding: 1px 7px; border-radius: 99px; white-space: nowrap; }

/* ---- evaluation */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; gap: 24px; } }
.two-col > div { min-width: 0; }
.two-col > div > p { color: var(--text-2); }
.formula, .code { font-family: var(--mono); font-size: .86rem; background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; overflow-x: auto; line-height: 1.55; margin: 0 0 1em; }
.code .c { color: var(--text-3); }
.result-line .big { font-size: 1.4rem; font-weight: 700; color: var(--text); margin-right: 4px; }
.sub { margin-top: 4px; }
.terms { list-style: none; padding: 0; margin: 0 0 28px; display: grid; gap: 10px; }
.terms li { display: grid; gap: 1px; padding-left: 14px; border-left: 2px solid var(--accent); }
.terms span { color: var(--text-2); font-size: .9rem; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
th { font-size: .78rem; color: var(--text-3); font-weight: 600; background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.warn { color: var(--warn); font-weight: 650; }

/* ---- charts */
.chart-card { margin: 0 0 24px; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 18px 18px 8px; }
.chart-card figcaption { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; margin-bottom: 8px; }
.chart-card figcaption span { color: var(--text-3); font-size: .85rem; }
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .zero { stroke: var(--text-3); stroke-width: 1; }
.chart .axis { fill: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .axis.faint { font-size: 11px; opacity: .8; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart .dot { fill: var(--accent); stroke: var(--bg); stroke-width: 2; transition: r .12s; }
.chart .dot.on { r: 7; }
.chart .label { fill: var(--text); font-size: 13px; font-weight: 650; }
.chart .hit { fill: transparent; cursor: default; }
.chart .bar { fill: var(--accent); }
.chart .dropped .bar { fill: var(--muted-mark); }
.chart .err { stroke: var(--text-2); stroke-width: 1.5; opacity: .55; }
.chart .name { fill: var(--text-2); font-size: 12.5px; }
.chart .dropped .name { fill: var(--text-3); }
.chart .val { fill: var(--text-2); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart .row.on .name, .chart .row.on .val { fill: var(--text); }
.chart .row.on .bar { filter: brightness(1.1); }
.tip { position: absolute; z-index: 5; pointer-events: none; background: var(--surface); color: var(--text-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: .8rem; line-height: 1.45; box-shadow: var(--shadow); max-width: 260px; }
.tip b { color: var(--text); }
.tip .big { font-size: 1.05rem; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
@media (max-width: 640px) { #gainsChart { overflow-x: auto; } #gainsChart svg { min-width: 600px; } }

.lessons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 8px; }
@media (max-width: 860px) { .lessons { grid-template-columns: 1fr; } }
.lesson { border-top: 2px solid var(--accent); padding-top: 12px; }
.lesson p { color: var(--text-2); font-size: .92rem; }

.footer { padding: 32px 0 48px; font-size: .88rem; color: var(--text-2); }
.footer p { margin: 0 0 .4em; }
