:root {
  color-scheme: light;
  --bg: #f6f5f3; --panel: #eceae6; --ink: #1f1d1a; --soft: #5e5a54; --line: #d9d6d0;
  --accent: #1a66a6; --sq-light: #f0d9b5; --sq-dark: #b58863; --sq-hi: #cdd26a; --sq-hi-d: #aaa23a;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --m-book: #8a6b45; --m-best: #4f7f22; --m-excellent: #5a7f28; --m-good: #5e7050; --m-miss: #c94f3a; --m-blunder: #d12f20; --m-mistake: #b8610f; --m-inaccuracy: #8a7400; --m-great: #4a6f9c; --m-brilliant: #0d8a75;
  --win: #16784f; --loss: #b3261e; --draw: #5e5a54;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #161512; --panel: #262421; --ink: #ebe9e5; --soft: #aaa69f; --line: #3b3834;
    --accent: #6cb2ec;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --m-book: #c7a27a; --m-best: #8cc054; --m-excellent: #8cbb55; --m-good: #93a884; --m-miss: #fe866e; --m-blunder: #f34c3c; --m-mistake: #fdad66; --m-inaccuracy: #edcd2d; --m-great: #7c9cc3; --m-brilliant: #2ac7ac;
    --win: #62cfa0; --loss: #f4877f; --draw: #aaa69f;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 17px/1.55 "Atkinson Hyperlegible", system-ui, sans-serif; }
a { color: var(--accent); }
a:focus-visible, button:focus-visible, select:focus-visible, input:focus-visible, main:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
main:focus { outline: none; }
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 700; }
h2 { font-size: 1.35rem; margin-bottom: .5rem; }
p { margin: 0 0 .8rem; }
.top { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; max-width: 1080px; margin: auto; padding: 18px 16px 6px; }
.brand { font-weight: 700; font-size: 1.3rem; color: var(--accent); text-decoration: none; }
nav { display: flex; flex-wrap: wrap; justify-content: flex-end; }
nav a { display: inline-block; padding: 8px 6px; margin-left: 4px; color: var(--soft); text-decoration: none; }
nav a[aria-current] { color: var(--ink); font-weight: 700; border-bottom: 2px solid var(--accent); }
main { max-width: 1080px; margin: auto; padding: 8px 16px 48px; }
footer { max-width: 1080px; margin: auto; padding: 0 16px 32px; color: var(--soft); font-size: .88rem; }
section { margin-top: 44px; }
.loading, .note { color: var(--soft); }
.hint { color: var(--soft); max-width: 62ch; }

.game-head { display: grid; grid-template-columns: minmax(0, 460px) minmax(0, 1fr); gap: 32px; align-items: start; margin-top: 12px; }
.game-head h1 { font-size: clamp(1.4rem, 3vw, 1.9rem); margin-bottom: 8px; }
.meta { color: var(--soft); margin-bottom: 14px; }
.verdict { font-weight: 700; }
.verdict.win { color: var(--win); } .verdict.loss { color: var(--loss); } .verdict.draw { color: var(--draw); }
.headline { font-weight: 700; font-size: 1.12rem; }
.line { margin: -.2rem 0 .9rem; }
.moveref { display: inline; min-height: 0; padding: 1px 2px; margin: 0 -2px; background: none; border: 0; border-radius: 3px; color: var(--accent); font: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.moveref:hover { background: var(--panel); }
.linkline { background: none; border: 0; padding: 2px 0; min-height: 36px; font-weight: 700; text-align: left; text-decoration: underline; text-underline-offset: 3px; }
.review h3 { font-size: 1.08rem; margin: 18px 0 4px; }
.focus { background: var(--panel); border-left: 4px solid var(--accent); padding: 12px 14px; margin-top: 16px; }
.focus h3 { margin-top: 0; }
.focus p { margin: 0; }
.review { margin-bottom: 16px; }
.board { display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); width: 100%; aspect-ratio: 1; border-radius: 6px; overflow: hidden; }
.sq { min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; container-type: inline-size; }
.sq.l { background: var(--sq-light); } .sq.d { background: var(--sq-dark); }
.sq.l.hi { background: var(--sq-hi); } .sq.d.hi { background: var(--sq-hi-d); }
.pc { display: block; width: 100%; height: 100%; pointer-events: none; user-select: none; }
.board-row { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 6px; align-items: stretch; }
.board-slot { min-width: 0; position: relative;  touch-action: manipulation; }
#board .sq { cursor: pointer; }
#board .sq:has(.pc), #pz-board .sq:has(.pc) { touch-action: none; }
.drag-piece { position: fixed; z-index: 10; pointer-events: none; }
.board .sq.in-check { background-image: radial-gradient(ellipse at center, #ff0000 0%, #e70000 25%, rgba(169, 0, 0, 0) 89%, rgba(158, 0, 0, 0) 100%); }
.sq.selected { box-shadow: inset 0 0 0 100px rgba(90, 160, 70, .55); }
.sq.can-move::after { content: ""; position: absolute; width: 28%; height: 28%; border-radius: 50%; background: rgba(40, 90, 30, .55); }
.sq.can-take::after { content: ""; position: absolute; inset: 4%; border-radius: 50%; border: 5px solid rgba(40, 90, 30, .55); }
.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
.arrow line { stroke-width: 18; } .arrow-1 line { stroke: rgba(40, 110, 200, .72); } .arrow-1 polygon { fill: rgba(40, 110, 200, .72); }
.arrow-better line { stroke: rgba(46, 160, 67, .8); } .arrow-better polygon { fill: rgba(46, 160, 67, .8); }
.arrow-2 line { stroke: rgba(120, 120, 120, .6); } .arrow-2 polygon { fill: rgba(120, 120, 120, .6); }
.promote { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0; }
.variation { margin: 8px 0; padding: 10px; background: var(--panel); border-radius: 6px; }
.variation[hidden], .promote[hidden] { display: none; }
.variation-line { line-height: 2.2; }
.variation-line button { min-height: 34px; padding: 2px 8px; background: none; border: 0; }
.variation-line button.on { background: var(--accent); color: var(--bg); }
.play-panel { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin: 8px 0; }
.play-status { margin: 8px 0; font-weight: 700; }
.play-status[hidden] { display: none; }
.tabs { display: flex; gap: 4px; overflow-x: auto; margin: 8px 0 16px; border-bottom: 1px solid var(--line); }
.tabs button { flex: 0 0 auto; background: none; border: 0; border-bottom: 3px solid transparent; border-radius: 0; color: var(--soft); padding: 10px 12px; }
.tabs button[aria-selected="true"] { color: var(--ink); font-weight: 700; border-bottom-color: var(--accent); }
.week-list { list-style: none; margin: 0 0 10px; padding: 0; }
.week-list li { padding: 6px 0; }
.page-title { font-size: clamp(1.5rem, 3vw, 2rem); margin: 12px 0 8px; }
.button-link { display: inline-flex; align-items: center; min-height: 44px; padding: 9px 13px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); text-decoration: none; }
a.plain { color: inherit; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.more-filters { margin: 8px 0 12px; }
.more-filters summary { cursor: pointer; min-height: 40px; color: var(--accent); }
.more-filters .filters { align-items: center; }
.more-filters input[type=date], .more-filters input[type=number] { width: 9.5rem; }
.checks label { display: inline-flex; gap: 6px; align-items: center; min-height: 40px; margin-right: 8px; }
.checks input { min-height: 0; }
.focus-list { list-style: none; margin: 0; padding: 0; }
.focus-list li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.focus-list h3 { display: flex; align-items: center; justify-content: space-between; font-size: 1.02rem; margin-bottom: 4px; }
.focus-list p { margin: 0; }
.trend { width: 90px; height: 24px; color: var(--accent); flex: none; }
.engine-panel { margin: 8px 0; }
.engine-panel .note { margin: 8px 0 0; }
.engine-line { margin: 8px 0 0; font-size: .94rem; overflow-wrap: anywhere; }
.bar-slot { position: relative; }
.evalbar { position: absolute; inset: 0; overflow: hidden; border-radius: 3px; background: #3a3a3a; }
.white-fill { position: absolute; left: 0; right: 0; background: #f2f2f2; transition: height .15s; }
.evalbar .val { position: absolute; left: 0; right: 0; text-align: center; font-size: 10px; font-weight: 700; line-height: 1; }
.evalbar .val.low { bottom: 3px; } .evalbar .val.high { top: 3px; }
.evalbar .val.on-white { color: #222; } .evalbar .val.on-black { color: #f2f2f2; }
.sub-head { margin: 18px 0 6px; font-size: 1rem; }
.player { display: flex; align-items: baseline; gap: 8px; padding: 6px 2px; min-width: 0; }
.player .score { font-weight: 700; color: var(--soft); width: 1.1rem; text-align: center; }
.player .score.won { color: var(--win); }
.player .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .rating { color: var(--soft); }
.player .clock { margin-left: auto; flex: none; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--soft); padding: 1px 7px; border-radius: 4px; }
.player .clock:empty { display: none; }
.player .clock.active { color: var(--ink, inherit); background: var(--panel); }
.player .gain { color: var(--win); } .player .lost { color: var(--loss); }
.controls svg { display: block; width: 18px; height: 18px; fill: currentColor; }
.controls button:has(svg) { display: flex; align-items: center; justify-content: center; min-width: 48px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; align-items: center; }
button, select, input { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 9px 13px; min-height: 44px; }
button { cursor: pointer; }
button[aria-pressed="true"] { background: var(--accent); color: var(--bg); border-color: var(--accent); }
input { min-width: 0; }
.position { color: var(--soft); margin-left: auto; font-size: .94rem; }

.moments { list-style: none; padding: 0; margin: 0; }
.moments li { border-top: 1px solid var(--line); }
.moments button { display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 0; padding: 11px 2px; }
.moments b { display: block; }
.moments .why { color: var(--soft); display: block; font-size: .94rem; }
.tag-blunder { color: var(--loss); } .tag-mistake { color: var(--accent); } .tag-inaccuracy { color: var(--soft); }

.movetable { max-height: 260px; overflow-y: auto; margin-top: 12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); overscroll-behavior: contain; }
.movetable table { table-layout: fixed; }
.movetable th { width: 2.6rem; padding: 0 8px 0 4px; border: 0; font-weight: 400; text-align: right; color: var(--soft); vertical-align: middle; }
.movetable td { padding: 0; border: 0; }
.movetable button { display: block; width: 100%; min-height: 40px; padding: 6px 10px; background: none; border: 0; border-radius: 4px; text-align: left; font-variant-numeric: tabular-nums; }
.movetable button:hover { background: var(--panel); }
.movetable button.on, .movetable button.on[class*="tone-"] { background: var(--accent); color: var(--bg); font-weight: 700; }
.fig { font-family: "Noto Sans Symbols2", "Segoe UI Symbol", "Apple Symbols", "DejaVu Sans", sans-serif; font-size: 1.12em; margin-right: 1px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.mark { margin-left: 2px; font-weight: 700; }
.tone-blunder { color: var(--m-blunder); font-weight: 700; } .tone-mistake { color: var(--m-mistake); font-weight: 700; }
.tone-inaccuracy { color: var(--m-inaccuracy); font-weight: 700; } .tone-great { color: var(--m-great); font-weight: 700; }
.tone-brilliant { color: var(--m-brilliant); font-weight: 700; } .tone-miss { color: var(--m-miss); font-weight: 700; }
.tone-book { color: var(--m-book); } .tone-best { color: var(--m-best); } .tone-excellent { color: var(--m-excellent); } .tone-good { color: var(--m-good); }
.tight { margin-top: 24px; }
.badge { position: absolute; top: 2%; right: 2%; width: 42cqw; height: 42cqw; min-width: 16px; min-height: 16px; display: flex; align-items: center; justify-content: center; border-radius: 50%; color: #fff; text-shadow: 0 1px 1px rgba(0,0,0,.45); font: 700 max(10px, 23cqw)/1 "Atkinson Hyperlegible", sans-serif; box-shadow: 0 0 0 1.5px #fff, 0 1px 3px rgba(0,0,0,.45); z-index: 1; }
.cat-blunder { background: #f34c3c; } .cat-mistake { background: #fdad66; } .cat-inaccuracy { background: #edcd2d; }
.cat-great { background: #7c9cc3; } .cat-brilliant { background: #2ac7ac; } .cat-miss { background: #fe866e; }
.movetable button.on .mark { color: inherit; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th { text-align: left; font-weight: 700; color: var(--soft); font-size: .92rem; }
th, td { padding: 9px 12px 9px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
td.num, th.num { text-align: right; padding-right: 16px; }
.goal-met { color: var(--win); font-weight: 700; }

.chart svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart text { fill: var(--soft); font: 12px "Atkinson Hyperlegible", sans-serif; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .goal { stroke: var(--ink); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .hair { stroke: var(--soft); stroke-width: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 4px 0 8px; color: var(--soft); font-size: .94rem; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.tip { position: fixed; z-index: 5; pointer-events: none; background: var(--ink); color: var(--bg); padding: 7px 10px; border-radius: 6px; font-size: .86rem; line-height: 1.4; max-width: 220px; }
.eval { display: block; width: 100%; height: 68px; cursor: pointer; border-radius: 4px; touch-action: pan-y; }
.eval .area { fill: #f2f2f2; }
.you-black .eval { background: #f2f2f2; }
.you-black .eval .area { fill: #3a3a3a; }
.you-white .eval { background: #3a3a3a; }
.eval .mid { stroke: #8b8b8b; stroke-width: 1; }
.eval .now { stroke: var(--accent); stroke-width: 2; }

.eval-wrap { position: relative; margin: 0 0 6px; }
.eval-dot { position: absolute; width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px; border-radius: 50%; box-shadow: 0 0 0 1.5px #fff; pointer-events: none; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.filters input { flex: 1 1 180px; }
.rows { list-style: none; margin: 0; padding: 0; }
.rows a { display: grid; grid-template-columns: 5.2rem minmax(0, 1fr) auto; gap: 2px 12px; padding: 11px 2px; color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--line); }
.rows a:hover { background: var(--panel); }
.rows .res { font-weight: 700; }
.res.win { color: var(--win); } .res.loss { color: var(--loss); } .res.draw { color: var(--draw); }
.rows .sub { grid-column: 2 / 4; color: var(--soft); font-size: .92rem; }
.rows .opp { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .dt { grid-row: 2; color: var(--soft); font-size: .86rem; }
.rows .acc { color: var(--soft); }

@media (max-width: 760px) {
  .game-head { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  body { font-size: 16px; }
  section { margin-top: 34px; }
  .goal-table th:nth-child(5), .goal-table td:nth-child(5) { display: none; }
}
@media (prefers-reduced-motion: reduce) { .white-fill { transition: none; } }
@media (prefers-reduced-motion: no-preference) {
  .sq .pc { transition: opacity .08s; }
}

/* Scale and shared pieces */
section { margin-top: 36px; }
.tight { margin-top: 22px; }
th { font-size: .85rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 12px 16px; margin: 6px 0 14px; padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stat b { display: block; font-size: 1.55rem; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat span { color: var(--soft); font-size: .82rem; line-height: 1.25; display: block; }
.week-list li { padding: 3px 0; }

/* Navigation */
.nav-icon { display: none; width: 22px; height: 22px; fill: currentColor; }

/* Games list */
.rows .game-card { grid-template-columns: 4.6rem minmax(0, 1fr) 4.2rem; border-bottom: 0; border-left: 4px solid var(--line); margin-bottom: 6px; padding: 9px 10px; background: var(--panel); border-radius: 4px; }
.game-card.result-win { border-left-color: var(--win); }
.game-card.result-loss { border-left-color: var(--loss); }
.rows a.game-card:hover { filter: brightness(1.08); background: var(--panel); }
.opp small { color: var(--soft); font-size: .84rem; font-weight: 400; }
.game-card .dt { white-space: nowrap; font-size: .82rem; }
.acc-box { text-align: right; font-variant-numeric: tabular-nums; font-size: .92rem; }
.acc-bar { display: block; height: 4px; margin-top: 3px; border-radius: 2px; background: var(--line); overflow: hidden; }
.acc-bar i { display: block; height: 100%; background: var(--accent); }
.speed-icon { width: 13px; height: 13px; fill: currentColor; vertical-align: -2px; margin-right: 4px; }

/* Road to goal */
.goal-list { list-style: none; margin: 0; padding: 0; }
.goal-list li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.goal-top, .goal-note { display: flex; justify-content: space-between; gap: 12px; }
.goal-top b { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.goal-note { color: var(--soft); font-size: .85rem; }
.goal-bar { height: 7px; margin: 5px 0; border-radius: 4px; background: var(--line); overflow: hidden; }
.goal-bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.goal-bar.met i { background: var(--win); }

/* Practice */
.pz-good { color: var(--win); font-weight: 600; }
.pz-bad { color: var(--loss); font-weight: 600; }
#pz-board { border-radius: 6px; }
.flash-good { animation: flash-good .7s ease-out; }
.flash-bad { animation: flash-bad .7s ease-out; }
@keyframes flash-good { 0% { box-shadow: 0 0 0 6px var(--win); } 100% { box-shadow: 0 0 0 0 transparent; } }
@keyframes flash-bad { 0% { box-shadow: 0 0 0 6px var(--loss); } 100% { box-shadow: 0 0 0 0 transparent; } }

@media (max-width: 760px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  main { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
  footer { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
  .top { padding-bottom: 0; }
  nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; margin: 0; padding: 8px 2px 7px; font-size: .72rem; }
  nav a[aria-current] { border-bottom: 0; color: var(--accent); }
  .nav-icon { display: block; }

  /* Keep the board in view while reading on phones */
  .game-head { gap: 6px; }
  .game-head > div:first-child { display: contents; }
  .board-sticky { position: sticky; top: 0; z-index: 10; background: var(--bg); padding: 4px 0; }
  .board-sticky .board-row { max-width: calc(46vh + 28px); margin: 0 auto; }
  .game-head .player { padding: 2px; }
  .controls button:has(svg) { min-width: 44px; }
  .movetable { max-height: 210px; }
  .movetable button { min-height: 36px; }
  .game-head h1 { margin-top: 10px; }
}
@media (prefers-reduced-motion: reduce) { .flash-good, .flash-bad { animation: none; } }
