:root {
  color-scheme: dark;
  --background: #17212b;
  --panel: #202c38;
  --raised: #283746;
  --line: #3b4a59;
  --ink: #eff5f8;
  --muted: #afbecb;
  --accent: #8de3cf;
  --accent-ink: #112f30;
  --warning: #ffd099;
  --board-light: #dde1db;
  --board-dark: #7b919b;
  --board-arrow-played: #ffc45e;
  --board-arrow-best: #61b9ff;
  --board-arrow-user: #ffae47;
  --board-arrow-threat: #ff4646;
  font: 16px/1.45 system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scrollbar-gutter: stable; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--background); color: var(--ink); }
main { width: min(1216px, calc(100% - 48px)); margin: 22px auto 48px; }
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 1.25rem; letter-spacing: -.03em; }
h2 { font-size: 1.12rem; }
h3 { font-size: 1rem; }
h4 { font-size: .85rem; }
a { color: var(--accent); }
.page-heading { display: flex; align-items: baseline; gap: 14px; margin-bottom: 18px; }
.brand { color: var(--accent); font-size: 1rem; font-weight: 780; letter-spacing: -.02em; }
.muted { color: var(--muted); font-size: .82rem; }

.review-grid {
  display: grid;
  grid-template-columns: min(58%, max(370px, calc(100svh - 130px))) minmax(0, 1fr);
  align-items: start;
  gap: clamp(16px, 3vw, 32px);
}
.board-panel {
  --eval-width: 34px;
  --eval-gap: 8px;
  min-width: 0;
}
.board-heading, .board-footer, .game-nav, .analysis-heading, .moment-heading, .moves-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.board-heading, .board-footer { min-height: 38px; margin-left: calc(var(--eval-width) + var(--eval-gap)); }
.board-heading { margin-bottom: 7px; }
.board-footer { margin-top: 7px; }
.player { display: flex; min-width: 0; align-items: center; gap: 8px; font-size: .9rem; }
.player strong { overflow-wrap: anywhere; }
.side-dot { flex: none; width: 12px; height: 12px; border-radius: 50%; border: 1px solid #8898a5; background: #1b242f; }
.side-dot.white { background: #f1f0e8; }
.position-status { color: var(--muted); font-size: .84rem; text-align: right; }
.position-status.suggested { color: var(--accent); }

.board-with-eval {
  display: grid;
  grid-template-columns: var(--eval-width) minmax(0, 1fr);
  gap: var(--eval-gap);
}
.eval-bar { position: relative; overflow: hidden; border-radius: 5px; background: #303d4a; }
#eval-fill { position: absolute; inset: auto 0 0; height: var(--white-share, 50%); background: #f0f3ec; }
.eval-bar.flipped #eval-fill { top: 0; bottom: auto; }
#eval-value {
  position: absolute;
  inset: auto 0 6px;
  color: #17212b;
  text-align: center;
  font-size: .7rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.eval-bar.flipped #eval-value { top: 6px; bottom: auto; }
.eval-bar.black-ahead #eval-value { top: 6px; bottom: auto; color: #eff5f8; }
.eval-bar.black-ahead.flipped #eval-value { top: auto; bottom: 6px; }
@media (prefers-reduced-motion: no-preference) {
  #eval-fill { transition: height .18s ease-out; }
}
.board {
  display: grid;
  position: relative;
  min-width: 0;
  container-type: inline-size;
  grid-template: repeat(8, minmax(0, 1fr)) / repeat(8, minmax(0, 1fr));
  aspect-ratio: 1;
  border-radius: 5px;
  overflow: hidden;
  scroll-margin-top: 12px;
}
.board-square { position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; }
.square-light { background: var(--board-light); color: #405667; }
.square-dark { background: var(--board-dark); color: #142633; }
.square-from { box-shadow: inset 0 0 0 3px #fbc369; }
.square-to { background-image: linear-gradient(#fbc369ab, #fbc369ab); }
.board.suggested .square-from { box-shadow: inset 0 0 0 3px #55ddba; }
.board.suggested .square-to { background-image: linear-gradient(#55ddba9c, #55ddba9c); }
.board-piece { display: grid; width: 94%; height: 94%; z-index: 1; }
.board-piece img { width: 100%; height: 100%; pointer-events: none; }
.board-coordinate { position: absolute; z-index: 2; font-size: clamp(.57rem, 2.2cqw, .85rem); font-weight: 780; line-height: 1; pointer-events: none; }
.coordinate-rank { top: 4px; left: 4px; }
.coordinate-file { bottom: 4px; right: 4px; }

.analysis-panel { min-width: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); overflow-anchor: none; }
.analysis-heading { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.analysis-controls { padding: 10px 16px; border-bottom: 1px solid var(--line); }
summary { width: fit-content; cursor: pointer; font-size: .86rem; font-weight: 660; }
#analysis-form { margin-top: 9px; }
#analysis-form > label { display: block; margin-bottom: 5px; color: var(--muted); font-size: .8rem; }
textarea, select { border: 1px solid var(--line); border-radius: 7px; color: var(--ink); background: var(--background); padding: 7px 9px; }
textarea { display: block; width: 100%; resize: vertical; font: .78rem/1.45 ui-monospace, monospace; }
button, .button {
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 6px 10px;
  font: 680 .82rem/1.4 system-ui, sans-serif;
  cursor: pointer;
}
button:hover:not(:disabled), .button:hover { filter: brightness(1.17); }
button:disabled { opacity: .45; cursor: default; }
:focus-visible, .file-button:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.secondary { background: var(--raised); color: var(--ink); border-color: var(--line); }
.text-button { background: transparent; color: var(--accent); padding: 3px 2px; }
.import-actions, .settings-fields { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.file-button { position: relative; }
.file-button input { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; }
.settings-fields label { display: grid; gap: 3px; min-width: 76px; color: var(--muted); font-size: .78rem; }
select { font: inherit; }
#analysis-status { color: var(--muted); font-size: .83rem; }
#analysis-status:not(:empty) { margin-top: 8px; }
#analysis-status.error { color: var(--warning); }
.game-picker { display: grid; gap: 5px; padding: 10px 16px; color: var(--muted); font-size: .82rem; border-bottom: 1px solid var(--line); }

#engine-lines { padding: 10px 16px; border-bottom: 1px solid var(--line); }
#engine-lines-status { margin-top: 4px; }
#engine-line-list { list-style: none; padding: 0; margin: 4px 0 0; }
#engine-line-list:empty { margin: 0; }
#engine-line-list[aria-busy="true"] { min-height: 97px; }
.engine-line {
  display: grid;
  grid-template-columns: 3.45rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
}
.engine-line + .engine-line { border-top: 1px solid var(--line); }
.line-score {
  display: inline-grid;
  place-items: center;
  min-height: 23px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--background);
  color: var(--ink);
  font-size: .77rem;
  font-weight: 780;
  font-variant-numeric: tabular-nums;
}
.line-score[data-side="white"] { color: #17212b; background: #e7eee7; }
.line-score[data-side="black"] { color: #eff5f8; background: #303d4a; }
.engine-line-moves {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px;
}
.engine-line.expanded { align-items: start; }
.engine-line.expanded .engine-line-moves { flex-wrap: wrap; overflow: visible; }
.engine-move, .engine-line-toggle, .variation-step, .variation-return {
  border: 0;
  color: var(--ink);
  background: transparent;
  font-size: .76rem;
  white-space: nowrap;
  padding: 3px 5px;
}
.engine-move, .variation-step {
  text-decoration: underline;
  text-decoration-color: var(--muted);
  text-underline-offset: .2em;
}
.engine-move:first-child { color: var(--accent); }
.engine-move:hover, .variation-step:hover { color: var(--accent); }
.engine-move[aria-current="step"], .variation-step[aria-current="step"] {
  color: var(--accent-ink);
  background: var(--accent);
  text-decoration-color: currentColor;
}
.engine-line-toggle { min-width: 26px; color: var(--muted); }
.engine-line-toggle[aria-expanded="true"] { background: var(--raised); color: var(--accent); }

#standalone-variation { padding: 9px 16px; border-bottom: 1px solid var(--line); }
.moves .variation-row td { padding: 5px 4px 5px 48px; background: var(--background); }
.variation-trail {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 2px;
  border-left: 2px solid var(--accent);
  padding-left: 6px;
}
.variation-label { margin-right: 4px; color: var(--accent); font-size: .72rem; font-weight: 700; }
.variation-return { color: var(--accent); }

.move-detail, .moves-panel { padding: 12px 16px; }
.move-detail { border-bottom: 1px solid var(--line); }
.moment-heading { flex-wrap: wrap; }
.finding { color: var(--accent); background: #24423e; border-radius: 4px; padding: 3px 7px; font-size: .73rem; font-weight: 720; }
.finding.warning { background: #493a2f; color: var(--warning); }
.move-comparison { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin-top: 8px; }
.choice {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 2px 6px;
  text-align: left;
  background: var(--raised);
  color: var(--ink);
  border-color: var(--line);
}
.choice > span:first-child { grid-column: 1 / -1; color: var(--muted); font-size: .72rem; }
.choice strong { font-size: 1.07rem; }
.choice[aria-pressed="true"] { border-color: #ffc45e; }
#best-preview[aria-pressed="true"] { border-color: var(--accent); background: #25413e; }
.eval { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .77rem; }
.moves { width: 100%; table-layout: fixed; border-collapse: collapse; margin-top: 4px; font-size: .83rem; }
.moves th, .moves td { text-align: left; padding: 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.moves thead th, .moves th[scope=row] { color: var(--muted); font-weight: 560; }
.moves th:first-child { width: 52px; }
.move-button { display: flex; flex-wrap: wrap; align-items: baseline; gap: 1px 6px; width: 100%; background: transparent; color: var(--ink); padding: 3px 5px; text-align: left; }
.move-button[aria-current="step"] { background: var(--raised); border-color: var(--accent); }
.mate-note { color: var(--warning); font-size: .66rem; }
.game-nav { padding: 9px 16px; border-top: 1px solid var(--line); }
.game-nav button { flex: 1; font-size: 1.1rem; padding: 4px; }
.json-panel { padding: 8px 16px; border-top: 1px solid var(--line); color: var(--muted); }
.json-panel button { margin-top: 8px; }
pre { overflow: auto; max-height: 300px; padding: 10px; background: var(--background); border-radius: 6px; }

@media (max-width: 760px) {
  main { width: calc(100% - 24px); margin-top: 14px; }
  .page-heading { margin-bottom: 10px; }
  .review-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .board-panel {
    --eval-width: 28px;
    --eval-gap: 6px;
    width: min(100%, max(300px, 58svh));
    margin-inline: auto;
  }
  #eval-value { font-size: .62rem; }
  .board-heading, .board-footer { min-height: 34px; }
  .moves .variation-row td { padding-left: 24px; }
}

#live-review { padding: 10px 16px; border-bottom: 1px solid var(--line); }
#live-status { margin-top: 5px; }
.explanation {
  margin-top: 9px;
  padding: 8px 10px;
  border-left: 2px solid var(--accent);
  background: var(--background);
  border-radius: 0 5px 5px 0;
}
.explanation h4 { color: var(--accent); font-size: .73rem; }
.explanation p { margin-top: 3px; color: var(--ink); font-size: .84rem; }
.live-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.live-actions:not(:empty) button:not([hidden]) { margin-top: 6px; }
.move-button .move-grade { border-radius: 3px; padding: 1px 4px; font-size: .65rem; }
.grade-book { color: #efd3a0; background: #453c2e; }
.grade-good, .grade-excellent, .grade-best { color: #b6edc9; background: #29453a; }
.grade-great, .grade-brilliant { color: #afefff; background: #214953; }
.grade-inaccuracy, .grade-miss, .grade-mistake { color: #ffd099; background: #493a2f; }
.grade-blunder { color: #ffc2bd; background: #543337; }
.board button.board-square { border: 0; padding: 0; border-radius: 0; font: inherit; cursor: default; }
.board button.square-playable { cursor: grab; touch-action: manipulation; }
.board button.square-playable:active { cursor: grabbing; }
.board button.square-target { cursor: pointer; }
.board button.board-square:hover:not(:disabled) { filter: none; }
.board button.board-square:focus-visible { outline-offset: -3px; z-index: 6; }
.board button.square-selected { box-shadow: inset 0 0 0 4px #f7d88c; }
.board button.square-target::after {
  content: ""; position: absolute; inset: 32%; border-radius: 50%; background: #18314266; pointer-events: none;
}
.board button.square-capture-target::after {
  inset: 4%; border: 4px solid #18314277; background: transparent;
}
#promotion-dialog { border: 1px solid var(--line); border-radius: 10px; padding: 18px; background: var(--panel); color: var(--ink); }
#promotion-dialog::backdrop { background: #0e1522aa; }
#promotion-choices { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 8px; }

.popover-heading, .critical-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.board-tools { display: flex; align-items: center; gap: 4px; }
.board-tool {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  color: #b8d5f3;
  background: transparent;
  font: 1.5rem/1 "Apple Symbols", "Segoe UI Symbol", system-ui, sans-serif;
}
.board-tool:hover:not(:disabled), .board-tool[aria-pressed="true"] { background: var(--raised); color: #d8eaff; }
#open-settings { color: #aed3ff; font-size: 1.7rem; }

.review-settings {
  width: min(474px, calc(100% - 28px));
  max-height: min(650px, calc(100dvh - 28px));
  padding: 0;
  border: 1px solid #466581;
  border-radius: 19px;
  color: var(--ink);
  background: #1d2b3a;
  box-shadow: 0 26px 85px #070f1eb3;
}
.review-settings[open] { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; }
.review-settings::backdrop { background: #0a1322b3; }
.settings-header, .settings-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
}
.settings-header h2 { font-size: 1.15rem; }
.settings-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin: 0 18px;
  padding: 4px;
  background: #14202e;
  border-radius: 10px;
}
.settings-tabs button {
  min-height: 38px;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
}
.settings-tabs button[aria-selected="true"] {
  border-color: #51789b;
  color: #e0eeff;
  background: #2b4966;
}
.settings-content {
  min-height: 0;
  overflow: auto;
  padding: 12px 18px 18px;
}
.settings-content .check {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 9px 2px;
  font-size: .88rem;
  cursor: pointer;
}
.settings-content .check + .check { border-top: 1px solid var(--line); }
.settings-content small { display: block; margin-top: 3px; color: var(--muted); font-size: .76rem; }
.settings-content input[type=checkbox] {
  appearance: none;
  position: relative;
  order: 1;
  flex: none;
  width: 36px;
  height: 21px;
  margin: 0;
  border: 1px solid #657c94;
  border-radius: 999px;
  background: #14202e;
  cursor: pointer;
}
.settings-content input[type=checkbox]::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #bbcbdc;
}
.settings-content input[type=checkbox]:checked { border-color: #7bb6f2; background: #7bb6f2; }
.settings-content input[type=checkbox]:checked::before { left: 18px; background: #142942; }
.settings-content .settings-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 12px 0; }
.settings-content .settings-fields label { min-width: 0; }
.settings-content select { width: 100%; }
.settings-content #engine-pending { margin: 9px 0; color: var(--warning); }
.settings-footer { border-top: 1px solid var(--line); }
.settings-footer .text-button { color: #b6d5f7; }
.settings-done { min-width: 75px; background: #a4cbf4; color: #132b43; }

.board-move-grade {
  position: absolute;
  z-index: 5;
  right: 5%;
  top: 5%;
  display: grid;
  place-items: center;
  min-width: clamp(13px, 3.8cqw, 25px);
  height: clamp(13px, 3.8cqw, 25px);
  padding: 0 2px;
  border: 1px solid currentColor;
  border-radius: 50%;
  box-shadow: 0 1px 3px #10203169;
  font: 800 clamp(.53rem, 2.1cqw, .82rem)/1 system-ui, sans-serif;
  pointer-events: none;
}

#analysis-form > .import-format { display: flex; align-items: center; gap: 8px; }
#open-import-help { width: 28px; height: 28px; border: 1px solid var(--line); border-radius: 50%; font: inherit; }
#import-help[open] { grid-template-rows: auto minmax(0, 1fr); }
.import-help-steps { overflow-y: auto; padding: 0 18px 18px; line-height: 1.5; }
.import-help-steps h3 { margin: 12px 0 4px; font-size: 1rem; }
.import-help-steps ol { margin: 0; padding-left: 22px; }
.import-help-steps li + li { margin-top: 5px; }
.import-demo { margin-top: 12px; }
.import-demo img { display: block; width: 100%; height: auto; margin-top: 6px; border-radius: 8px; }
#expand-import-demo { margin-top: 8px; }
#import-demo-expanded {
  width: 100dvw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  padding: 0;
  border: 0;
  color: var(--ink);
  background: var(--panel);
}
#import-demo-screen {
  display: grid;
  height: 100%;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--panel);
}
#import-demo-expanded img { width: 100%; height: 100%; object-fit: contain; }
@media (prefers-reduced-motion: reduce) {
  .import-demo { display: none; }
}
.feature-panel { padding: 8px 16px; border-bottom: 1px solid var(--line); }
#start-retry, #retry-feedback:not(:empty) { margin-top: 8px; }
#retry-panel p { margin-top: 4px; }
#coaching-sides p { padding-top: 5px; }
#coaching-moments { margin: 7px 0 2px; padding-left: 19px; }
#coaching-moments button { text-align: left; }
.review-popover {
  position: fixed;
  width: min(264px, calc(100vw - 18px));
  z-index: 15;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 7px 21px #0e172199;
  font-size: .82rem;
}
.review-popover p + p, .term-highlight { margin-top: 6px; }
.term-close { padding: 2px 6px; }
.tactic-term {
  display: inline;
  font: inherit;
  color: var(--accent);
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: transparent;
  text-decoration: underline;
  text-underline-offset: 3px;
}
#engine-lines[hidden], #retry-panel[hidden] { display: none; }
#line-preview { width: min(176px, calc(100vw - 20px)); pointer-events: none; }
.variation-mini { margin-top: 4px; }
.variation-mini .board-coordinate { font-size: .43rem; }
.variation-mini .coordinate-rank { top: 2px; left: 2px; }
.variation-mini .coordinate-file { right: 2px; bottom: 2px; }
#board .board-square.tactic-focus { outline: 3px solid #39dcce; outline-offset: -3px; }
#board .board-square.threat-origin { outline: 3px dashed #d32939; outline-offset: -4px; }
#board .board-square.threat-target {
  box-shadow: inset 0 0 0 5px #d32939;
  background-image: linear-gradient(#ff464652, #ff464652);
}
.threat-caption { margin: 0 0 0 var(--eval-gutter, 42px); color: #ffb2b2; font-size: .8rem; }

.site-credit { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; padding: 12px 0 20px; text-align: center; font-size: 0.82rem; opacity: 0.7; }

.page-heading { flex-wrap: wrap; }
.account-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-left: auto; }
.account-controls button { padding: 6px 10px; }
.account-content { overflow-y: auto; padding: 0 18px 18px; }
#account-dialog[open] { grid-template-rows: auto minmax(0, 1fr); }
.account-form { display: grid; gap: 7px; }
.account-form label { margin-top: 6px; }
.account-form input {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--raised);
  color: var(--ink);
  font: inherit;
}
.account-form button { justify-self: start; margin-top: 8px; }
#account-status { margin: 8px 0 0; }
#account-status:empty, #account-header-status:empty { display: none; }

.moves-heading { margin-bottom: 8px; }
#review-view-toggle { flex: none; padding: 4px 9px; }
#game-overview { margin-top: 4px; }
#overview-stats { width: 100%; table-layout: fixed; border-collapse: collapse; margin: 8px 0 12px; font-size: .85rem; }
#overview-stats th, #overview-stats td { padding: 5px 6px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
#overview-stats th:first-child { text-align: left; }
#overview-stats td { text-align: center; font-variant-numeric: tabular-nums; }
#overview-stats tbody tr:first-child { background: var(--raised); font-weight: 750; }
#start-review { width: 100%; }
.moves-scroll { max-height: clamp(280px, 52vh, 520px); overflow: auto; }
.moves-panel .game-nav { padding: 8px 0 0; }

#recent-games-panel { margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
#recent-game-search, #recent-game-results { display: grid; gap: 6px; margin-top: 8px; }
#recent-games-panel label { color: var(--muted); font-size: .82rem; }
#recent-username { width: 100%; padding: 7px; border: 1px solid var(--line); border-radius: 6px; background: var(--raised); color: var(--ink); font: inherit; }
#recent-game-search button, #recent-game-results button { justify-self: start; }
#recent-game-select { max-width: 100%; }
#recent-games-status:not(:empty) { margin-top: 6px; }
