:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --border: #e2e0db;
  --accent: #2f6f4f;
  --accent-text: #ffffff;
  --light-sq: #f0d9b5;
  --dark-sq: #b58863;
  --highlight: rgba(255, 213, 79, 0.55);
  --best: #2e8b57;
  --good: #8a9a8a;
  --inaccuracy: #d4a017;
  --mistake: #e07a1f;
  --blunder: #d0342c;
  --arrow-best: rgba(40, 160, 60, 0.9);
  --arrow-played: rgba(208, 52, 44, 0.8);
  --arrow-last: rgba(245, 190, 25, 0.9);
  --arrow-reply: rgba(142, 68, 173, 0.8);
  --arrow-neutral: rgba(90, 90, 90, 0.75);
  --arrow-user: rgba(255, 145, 0, 0.85);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161618;
    --surface: #222225;
    --text: #ececef;
    --muted: #9a9aa2;
    --border: #36363b;
    --accent: #4fae7f;
    --accent-text: #0d1f16;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.screen { max-width: 1180px; margin: 0 auto; padding: 24px 16px 40px; }
h1 { margin: 0 0 4px; font-size: 28px; }
h2 { margin: 0 0 6px; font-size: 20px; }
h3 { margin: 18px 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.center { text-align: center; justify-content: center; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
.narrow { max-width: 640px; margin: 6vh auto 0; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-top: 14px; }
.grow { flex: 1; min-width: 200px; }
textarea, input[type="text"], select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px;
}
textarea { width: 100%; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; resize: vertical; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.file { cursor: pointer; margin-top: 6px; }
.file input { display: none; }
.file span { color: var(--accent); text-decoration: underline; }

button {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.warn { background: var(--blunder); color: #fff; border-color: var(--blunder); font-weight: 600; }
button.big { width: 100%; margin-top: 18px; padding: 12px; font-size: 16px; }
button:disabled { opacity: 0.5; cursor: default; }

.error { color: var(--blunder); margin: 12px 0 0; }

.progress { height: 10px; margin: 20px 0 8px; background: var(--bg); border-radius: 5px; overflow: hidden; }
.progress .bar { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

#side-buttons { margin-top: 16px; }
#side-buttons button { min-width: 200px; padding: 14px; }

/* Walkthrough */
.walk-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.walk-head .muted { margin-left: 8px; }

.timeline { display: flex; gap: 2px; margin: 14px 0; height: 18px; }
.timeline button {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: var(--border);
}
.timeline button.mine { background: var(--good); opacity: 0.55; }
.timeline button.t-inaccuracy { background: var(--inaccuracy); opacity: 1; }
.timeline button.t-mistake { background: var(--mistake); opacity: 1; }
.timeline button.t-blunder { background: var(--blunder); opacity: 1; }
.timeline button.current { outline: 2px solid var(--text); outline-offset: 1px; }

.walk {
  display: grid;
  grid-template-columns: minmax(0, 480px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}
@media (max-width: 860px) {
  .walk { grid-template-columns: minmax(0, 1fr); }
}

.player { font-weight: 600; padding: 6px 0; }
.board-wrap { display: flex; gap: 8px; }

.evalbar { position: relative; width: 22px; background: #403d39; border-radius: 4px; overflow: hidden; flex: none; }
.evalbar .white-fill { position: absolute; left: 0; right: 0; bottom: 0; background: #f2f2f2; transition: height 0.25s; }
.evalbar.flipped .white-fill { top: 0; bottom: auto; }
.eval-text { position: absolute; left: 0; right: 0; bottom: 2px; text-align: center; font-size: 9px; font-weight: 700; color: #888; writing-mode: vertical-rl; transform: rotate(180deg); }

.board-area { position: relative; flex: 1; min-width: 0; }
.board { display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); aspect-ratio: 1; border-radius: 4px; overflow: hidden; user-select: none; }
.sq { position: relative; display: flex; align-items: center; justify-content: center; aspect-ratio: 1; min-width: 0; min-height: 0; overflow: hidden; }
.sq.light { background: var(--light-sq); }
.sq.dark { background: var(--dark-sq); }
.sq.hl::before { content: ""; position: absolute; inset: 0; background: var(--highlight); }
.sq .coord { position: absolute; z-index: 2; font-size: 11px; font-weight: 600; }
.sq.light .coord { color: var(--dark-sq); }
.sq.dark .coord { color: var(--light-sq); }
.sq .coord.file { right: 3px; bottom: 1px; }
.sq .coord.rank { left: 3px; top: 1px; }
.piece { position: relative; z-index: 1; width: 100%; height: 100%; display: block; }

.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
.arrows polyline { fill: none; stroke-width: 0.16; stroke-linecap: round; stroke-linejoin: round; }
.arrow-best { stroke: var(--arrow-best); }
.arrow-played { stroke: var(--arrow-played); }
.arrow-best-head { fill: var(--arrow-best); }
.arrow-played-head { fill: var(--arrow-played); }
.arrow-last { stroke: var(--arrow-last); }
.arrow-last-head { fill: var(--arrow-last); }
.arrow-reply { stroke: var(--arrow-reply); }
.arrow-reply-head { fill: var(--arrow-reply); }
.arrow-neutral { stroke: var(--arrow-neutral); }
.arrow-neutral-head { fill: var(--arrow-neutral); }
.arrow-user { stroke: var(--arrow-user); }
.arrow-user-head { fill: var(--arrow-user); }
.board-tabs { display: flex; gap: 6px; margin-top: 8px; }
.idea-controls { display: flex; gap: 6px; margin-top: 8px; }
.idea-controls button { min-width: 44px; }
.idea .row { margin-top: 10px; }
.idea-list { list-style: none; padding: 0; margin: 12px 0 0; }
.idea-list li { margin: 0; }
.idea-move { width: 100%; text-align: left; border-color: transparent; background: none; padding: 5px 8px; }
.idea-list li.done .idea-move { opacity: 0.6; }
.idea-list li.current .idea-move { background: var(--bg); border-color: var(--accent); }
.idea-move .sub { display: block; font-size: 13px; color: var(--text); margin-top: 2px; }
.tab.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.caption { margin-top: 8px; font-size: 13px; }

.step .who { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.step .san { font-size: 30px; font-weight: 700; margin: 4px 0 2px; }
.chip { border: 1px solid var(--border); border-radius: 999px; padding: 1px 10px; }
.chip.you { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.badge { display: inline-block; border-radius: 4px; padding: 1px 8px; font-size: 12px; font-weight: 600; color: #fff; text-transform: capitalize; }
.c-best { background: var(--best); }
.c-good { background: var(--good); }
.c-inaccuracy { background: var(--inaccuracy); }
.c-mistake { background: var(--mistake); }
.c-blunder { background: var(--blunder); }
.callout { border-left: 4px solid var(--accent); padding: 8px 12px; background: var(--bg); border-radius: 0 8px 8px 0; margin-top: 10px; }
.callout.c-warn { border-color: var(--blunder); }
.line { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; color: var(--muted); }
.table-wrap { overflow-x: auto; margin-top: 12px; }
.players { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.players th, .players td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.players th:first-child, .players td:first-child { text-align: left; }
.players th { font-size: 12px; color: var(--muted); font-weight: 600; }
.players tr.me td { font-weight: 600; }
.list-item { display: block; width: 100%; text-align: left; margin-top: 6px; }
.list-item .sub { display: block; font-size: 13px; color: var(--muted); }

.stepper { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 20px; }
.stepper button { min-width: 120px; padding: 10px 16px; }
.keys { font-size: 12px; text-align: center; margin-top: 10px; }

/* Site navigation */
.site-nav { display: flex; align-items: center; gap: 18px; max-width: 1180px; margin: 0 auto; padding: 14px 16px 0; }
.site-nav a { color: var(--muted); text-decoration: none; font-weight: 600; }
.site-nav a:hover { color: var(--text); }
.site-nav a.active { color: var(--text); border-bottom: 2px solid var(--accent); }
.site-nav .brand { color: var(--text); font-size: 18px; margin-right: auto; }

/* Home: playable board */
.home { max-width: 1180px; margin: 0 auto; padding: 20px 16px 40px; }
.play { width: min(100%, 640px); margin: 0 auto; }
.board.playable { touch-action: none; }
.board.playable .piece { cursor: grab; }
.sq.selected::before { content: ""; position: absolute; inset: 0; background: rgba(20, 85, 30, 0.45); }
.sq.target::after { content: ""; position: absolute; inset: 0; margin: auto; z-index: 2; width: 28%; height: 28%; border-radius: 50%; background: rgba(20, 85, 30, 0.45); pointer-events: none; }
.sq.target.capture::after { width: 100%; height: 100%; background: none; border-radius: 50%; box-shadow: inset 0 0 0 5px rgba(20, 85, 30, 0.45); }
.piece.lifted { opacity: 0.3; }
.ghost { position: fixed; z-index: 1000; pointer-events: none; cursor: grabbing; }
.glide { position: fixed; z-index: 900; pointer-events: none; }
.sq.premove::before, .sq.marked::before { content: ""; position: absolute; inset: 0; background: rgba(200, 60, 50, 0.45); }
.promotion { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; gap: 8px; background: rgba(0, 0, 0, 0.45); }
.promotion button { width: 18%; aspect-ratio: 1; padding: 6px; display: flex; align-items: center; justify-content: center; }
.promotion img { width: 100%; height: 100%; }
.play-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.play-bar .row { gap: 6px; }

/* Per-move accuracy */
.move-accuracy { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 6px 0 8px; }
.move-accuracy .meter { width: 120px; height: 8px; border-radius: 4px; background: var(--bg); border: 1px solid var(--border); overflow: hidden; }
.move-accuracy .fill { height: 100%; }
.small { font-size: 13px; }

/* Home: opponent setup */
.setup { margin-bottom: 12px; }
.setup label { margin-top: 10px; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button.active { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.elo { flex: 1; min-width: 220px; }
.elo .row { align-items: center; flex-wrap: nowrap; }
.elo input[type="range"] { flex: 1; accent-color: var(--accent); }
/* Fixed widths so the slider never resizes under the pointer as the value changes. */
.elo #elo-value { width: 5ch; text-align: right; font-variant-numeric: tabular-nums; }
.elo-note { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: opacity 0.2s; }
.elo-note.off { opacity: 0; }
.setup #opponent { margin: 8px 0 0; }

/* Openings */
.screen > .segmented { margin: 16px 0; }
.opening-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.opening-card { display: flex; flex-direction: column; gap: 6px; text-align: left; padding: 14px; border-radius: 12px; background: var(--surface); }
.opening-card strong { font-size: 17px; }
.opening-card .summary { font-size: 14px; }
.small-progress { height: 6px; margin: 10px 0 16px; }
.board-buttons { margin-top: 8px; gap: 6px; }
.coach { display: flex; flex-direction: column; gap: 10px; padding: 16px; }
.log { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; }
.entry { border-radius: 8px; padding: 10px 12px; background: var(--bg); font-size: 14px; }
.entry-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.entry.info { background: none; border: 1px dashed var(--border); color: var(--muted); }
.entry.you { border-left: 4px solid var(--best); }
.entry.you.miss { border-left-color: var(--mistake); }
.entry.them { border-left: 4px solid var(--arrow-reply); }
.entry .expected { margin-top: 6px; font-weight: 600; }
.entry.recap { background: var(--surface); border: 1px solid var(--accent); }
.entry.recap .row { margin-top: 10px; gap: 6px; }
.small-button { margin-top: 8px; padding: 4px 10px; font-size: 13px; }
.prompt { border-top: 1px solid var(--border); padding-top: 10px; }
.prompt .row { gap: 6px; }
.hint { color: var(--accent); }

/* Move-quality icons */
:root {
  --i-brilliant: #1baca6;
  --i-great: #5c8bb0;
  --i-best: #81b64c;
  --i-good: #77a36d;
  --i-book: #a88865;
  --i-inaccuracy: #e6b422;
  --i-mistake: #f08a24;
  --i-blunder: #d9362b;
}
.mv-icon { width: 18px; height: 18px; flex: none; vertical-align: middle; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35)); }
.mv-icon text { fill: #fff; font-weight: 800; font-family: system-ui, sans-serif; letter-spacing: -0.5px; }
.mv-icon path { fill: #fff; }
.mv-icon path.stroke { fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.i-brilliant circle { fill: var(--i-brilliant); }
.i-great circle { fill: var(--i-great); }
.i-best circle { fill: var(--i-best); }
.i-good circle { fill: var(--i-good); }
.i-book circle { fill: var(--i-book); }
.i-inaccuracy circle { fill: var(--i-inaccuracy); }
.i-mistake circle { fill: var(--i-mistake); }
.i-blunder circle { fill: var(--i-blunder); }
.sq .sq-icon { position: absolute; z-index: 3; top: 3%; right: 3%; width: 36%; height: 36%; pointer-events: none; }
.with-icon { display: inline-flex; align-items: center; gap: 5px; }
.class-label { font-size: 13px; font-weight: 700; text-transform: none; }
.class-label.t-brilliant { color: var(--i-brilliant); }
.class-label.t-great { color: var(--i-great); }
.class-label.t-best { color: var(--i-best); }
.class-label.t-good { color: var(--i-good); }
.class-label.t-book { color: var(--i-book); }
.class-label.t-inaccuracy { color: var(--i-inaccuracy); }
.class-label.t-mistake { color: var(--i-mistake); }
.class-label.t-blunder { color: var(--i-blunder); }
.players th .mv-icon { width: 20px; height: 20px; }
#moves { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.move-item { display: inline-flex; align-items: center; gap: 3px; }
.move-item .mv-icon { width: 15px; height: 15px; }

/* Analysis move panel: fixed to the board column's height (set in analysis.js). */
.walk > .step { overflow-y: auto; }
.walk .board-col .caption {
  height: 2.9em; margin-bottom: 0; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.san-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 2px 0 6px; }
.san-row .san { margin: 0; }
.step h3 { margin: 12px 0 4px; }
.step p { margin: 0 0 6px; }
.step .callout { margin-top: 4px; }
.step .idea .row { margin-top: 6px; }
.step .idea-list { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.step .idea-move { width: auto; padding: 3px 8px; font-size: 13px; }
.step .list-item { display: inline-flex; align-items: center; gap: 6px; width: auto; margin: 6px 6px 0 0; }
.step .list-item .sub { display: inline; margin-left: 4px; }
.san-row .row { gap: 6px; }

/* Larger board on the Analysis and Openings pages */
#screen-walk.screen, #screen-drill.screen { max-width: 1320px; }
#screen-walk .walk, #screen-drill .walk { grid-template-columns: minmax(0, 600px) minmax(0, 1fr); }
@media (max-width: 860px) {
  #screen-walk .walk, #screen-drill .walk { grid-template-columns: minmax(0, 1fr); }
}

/* Captured pieces next to player names */
.player { display: flex; align-items: center; gap: 10px; min-height: 34px; }
.captured { display: inline-flex; align-items: center; flex-wrap: wrap; }
.captured .piece { width: 18px; height: 18px; margin-right: -5px; }
.captured .lead { margin-left: 9px; font-size: 13px; font-weight: 600; color: var(--muted); }
.pgn-tools { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.pgn-tools .small-button { margin-top: 6px; }
