@font-face { font-family: "Barlow"; font-weight: 400; font-display: swap; src: url("../fonts/barlow-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 500; font-display: swap; src: url("../fonts/barlow-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 600; font-display: swap; src: url("../fonts/barlow-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 500; font-display: swap; src: url("../fonts/barlow-condensed-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 700; font-display: swap; src: url("../fonts/barlow-condensed-latin-700-normal.woff2") format("woff2"); }

/* ---------- tokens ---------- */
:root {
  --bg: #e9edf2;
  --surface: #ffffff;
  --surface-2: #f4f6f9;
  --ink: #1b2433;
  --muted: #5a6576;
  --line: #d3d9e2;
  --brass: #b5841f;
  --brass-ink: #7c5810;
  --brass-soft: #f3e6c6;
  --good: #2b8a57;
  --good-soft: #d8efe1;
  --bad: #c0392f;
  --bad-soft: #f6dcd9;
  --focus: #2f6fd6;
  --shadow: 0 1px 2px rgba(27, 36, 51, 0.08), 0 6px 18px rgba(27, 36, 51, 0.06);
  --radius: 10px;
  --font: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-c: "Barlow Condensed", "Barlow", system-ui, sans-serif;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #111722;
  --surface: #1a2230;
  --surface-2: #212b3b;
  --ink: #e5e9f0;
  --muted: #98a2b3;
  --line: #2d394b;
  --brass: #d6a63e;
  --brass-ink: #e7bf62;
  --brass-soft: #3a3121;
  --good: #4cc282;
  --good-soft: #1d3a2c;
  --bad: #ec6a5f;
  --bad-soft: #43231f;
  --focus: #7aa7ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--brass-ink); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { font-family: var(--font-c); font-weight: 700; line-height: 1.1; margin: 0 0 0.4em; letter-spacing: 0.01em; }
h1 { font-size: 2rem; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.15rem; }
p { margin: 0 0 0.8em; }
.muted { color: var(--muted); }
.small { font-size: 0.88rem; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-family: var(--font-c); font-weight: 700; font-size: 1.3rem; letter-spacing: 0.02em; }
.brand img { width: 28px; height: 28px; }
.topbar .spacer { flex: 1; }
.icon-btn { background: none; border: 0; padding: 8px; border-radius: 8px; cursor: pointer; color: var(--muted); display: grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 22px; height: 22px; }
main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 16px; }
.footer { text-align: center; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); color: var(--muted); font-size: 0.85rem; }
.footer a { color: var(--muted); }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: 0.95rem; margin-bottom: 8px; }
.back:hover { color: var(--ink); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px;
  border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
  font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }
[data-theme="dark"] .btn.primary { background: var(--brass); color: #1a1407; border-color: var(--brass); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); background: var(--surface-2); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- home ---------- */
.today {
  background: var(--ink); color: var(--surface);
  border-radius: 14px; padding: 20px; margin-bottom: 20px;
  display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center;
}
[data-theme="dark"] .today { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); }
.today h2 { font-size: 1.7rem; margin: 0; }
.today p { margin: 4px 0 0; opacity: 0.8; }
.today .btn.primary { background: var(--brass); color: #1a1407; border-color: var(--brass); }
.today-count { font-family: var(--font-c); font-weight: 700; font-size: 3.2rem; line-height: 1; color: var(--brass); text-align: right; }

.sections { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.section-link {
  display: grid; grid-template-columns: 52px 1fr auto; gap: 14px; align-items: center;
  padding: 14px 16px; background: var(--surface); color: var(--ink); text-decoration: none;
}
.section-link:hover { background: var(--surface-2); }
.section-link img { width: 48px; height: 48px; }
.section-link .t { font-family: var(--font-c); font-weight: 700; font-size: 1.3rem; line-height: 1.1; }
.section-link .d { color: var(--muted); font-size: 0.92rem; line-height: 1.35; }
.section-link .meta { font-family: var(--font-c); font-weight: 500; color: var(--muted); font-size: 1rem; text-align: right; white-space: nowrap; }

/* ---------- lists ---------- */
.group { margin: 0 0 24px; }
.group-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.group-intro { color: var(--muted); max-width: 70ch; }
.rows { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center;
  padding: 12px 14px; background: var(--surface); color: var(--ink); text-decoration: none; min-height: 56px;
}
.row:hover { background: var(--surface-2); }
.row .name { font-weight: 600; }
.row .tag { color: var(--muted); font-size: 0.88rem; }
.pill { font-size: 0.8rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.pill.due { background: var(--brass-soft); color: var(--brass-ink); border-color: transparent; }
.pill.learning { background: var(--surface-2); color: var(--ink); }
.pill.mastered, .pill.solved { background: var(--good-soft); color: var(--good); border-color: transparent; }
.pill.failed { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 10px; margin-bottom: 16px; width: fit-content; max-width: 100%; overflow-x: auto; }
.tab { border: 0; background: transparent; padding: 8px 14px; border-radius: 7px; cursor: pointer; font-weight: 600; color: var(--muted); white-space: nowrap; }
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- trainer layout ---------- */
.train { display: grid; gap: 16px; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 900px) { .train { grid-template-columns: minmax(0, 560px) minmax(0, 1fr); gap: 24px; } }
.board-wrap { width: 100%; max-width: 560px; margin: 0 auto; position: relative; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.panel + .panel { margin-top: 12px; }
.title-line { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.title-line h1 { margin: 0; font-size: 1.7rem; }
.status { font-family: var(--font-c); font-weight: 700; font-size: 1.35rem; line-height: 1.2; margin: 0 0 6px; display: flex; align-items: center; gap: 8px; }
.status .dot-ind { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }
.status.white .dot-ind { background: #fff; border: 2px solid var(--ink); }
.status.black .dot-ind { background: #222; border: 2px solid var(--muted); }
.status.good { color: var(--good); }
.status.bad { color: var(--bad); }
.note { min-height: 3.2em; max-width: 65ch; }
.note .san { font-weight: 600; }
.plan { background: var(--brass-soft); border-radius: 10px; padding: 12px 14px; margin-top: 10px; }
.plan h3 { color: var(--brass-ink); margin-bottom: 4px; }
.avoid { background: var(--surface-2); border-left: 3px solid var(--brass); padding: 10px 14px; border-radius: 6px; margin-top: 10px; }
.controls { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.controls .btn { flex: 1 1 auto; }
.stepper { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 12px; }
.stepper .btn { padding: 8px; }
.btn svg { width: 20px; height: 20px; flex: none; }

.movelist { display: flex; flex-wrap: wrap; gap: 2px 4px; margin-top: 12px; font-size: 0.95rem; line-height: 1.8; max-height: 9.5em; overflow-y: auto; }
.movelist .num { color: var(--muted); margin-left: 4px; }
.movelist button { border: 0; background: none; padding: 0 5px; border-radius: 4px; cursor: pointer; }
.movelist button.cur { background: var(--ink); color: var(--surface); }
.movelist button.has-note { text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }
.movelist .hidden { color: var(--line); }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin: 8px 0 12px; }
.progress > div { height: 100%; background: var(--brass); transition: width 200ms; }
.result { text-align: center; padding: 6px 0; }
.result .big { font-family: var(--font-c); font-weight: 700; font-size: 2.6rem; line-height: 1; }

/* ---------- board ---------- */
.board {
  --light: #f0d9b5; --dark: #b58863;
  --sel: rgba(20, 85, 30, 0.5); --last: rgba(205, 210, 106, 0.6);
  position: relative;
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1 / 1; width: 100%;
  border-radius: 6px; overflow: hidden;
  box-shadow: var(--shadow);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.board[data-theme="brown"] { --light: #f0d9b5; --dark: #b58863; }
.board[data-theme="green"] { --light: #eeeed2; --dark: #769656; }
.board[data-theme="blue"] { --light: #dee3e6; --dark: #8ca2ad; --last: rgba(155, 199, 0, 0.45); }
.board[data-theme="slate"] { --light: #c8ced8; --dark: #6b7a90; --last: rgba(230, 200, 90, 0.5); }
.board[data-theme="walnut"] { --light: #e6c99a; --dark: #8b5a2b; }
.board[data-theme="rose"] { --light: #ecdcdc; --dark: #b47c86; --last: rgba(240, 210, 120, 0.55); }
.sq { position: relative; display: grid; place-items: center; }
.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }
.sq.last::before, .sq.selected::before, .sq.hint::before, .sq.good::before, .sq.bad::before, .sq.check::before, .sq.target::before, .sq.pick::before { content: ""; position: absolute; inset: 0; }
.sq.last::before { background: var(--last); }
.sq.selected::before { background: var(--sel); }
.sq.hint::before { background: rgba(47, 111, 214, 0.45); box-shadow: inset 0 0 0 3px rgba(47, 111, 214, 0.9); }
.sq.good::before { background: rgba(43, 138, 87, 0.6); }
.sq.bad::before { background: rgba(192, 57, 47, 0.6); }
.sq.target::before { box-shadow: inset 0 0 0 4px var(--brass); }
.sq.pick::before { background: rgba(214, 166, 62, 0.55); }
.sq.check::before { background: radial-gradient(circle, rgba(255, 0, 0, 0.9) 0%, rgba(231, 0, 0, 0.5) 30%, rgba(169, 0, 0, 0) 70%); }
.sq.dim { filter: saturate(0.5) brightness(0.75); }
.sq.flash-bad::after { content: ""; position: absolute; inset: 0; background: rgba(192, 57, 47, 0.55); animation: fade 450ms ease-out forwards; }
@keyframes fade { from { opacity: 1; } to { opacity: 0; } }
.piece { position: absolute; inset: 0; background-size: 88%; background-position: center; background-repeat: no-repeat; z-index: 2; pointer-events: none; }
.piece.ghost { position: fixed; left: 0; top: 0; inset: auto; z-index: 1000; background-size: 95%; filter: drop-shadow(0 4px 6px rgba(0,0,0,0.3)); }
.dot { width: 30%; height: 30%; border-radius: 50%; background: rgba(20, 30, 20, 0.28); z-index: 3; pointer-events: none; }
.cap-ring { position: absolute; inset: 0; border-radius: 50%; box-shadow: inset 0 0 0 5px rgba(20, 30, 20, 0.28); z-index: 3; pointer-events: none; }
.coord { position: absolute; font-family: var(--font-c); font-weight: 700; font-size: clamp(9px, 2.4vw, 13px); line-height: 1; z-index: 4; pointer-events: none; }
.coord.file { right: 3px; bottom: 2px; }
.coord.rank { left: 3px; top: 3px; }
.sq.light .coord { color: var(--dark); }
.sq.dark .coord { color: var(--light); }
.sq-label { position: absolute; z-index: 4; font-family: var(--font-c); font-weight: 700; font-size: clamp(14px, 4vw, 22px); color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.7); pointer-events: none; }
.board.shake { animation: shake 280ms; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.promo-overlay { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45); display: grid; place-items: center; z-index: 50; }
.promo-box { background: var(--surface); padding: 12px; border-radius: 10px; text-align: center; }
.promo-title { font-weight: 600; margin-bottom: 6px; }
.promo-row { display: flex; gap: 6px; }
.promo-btn { width: 56px; height: 56px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2) center/85% no-repeat; cursor: pointer; }

/* ---------- squares trainer ---------- */
.readout {
  font-family: var(--font-c); font-weight: 700; line-height: 1;
  font-size: clamp(3.4rem, 16vw, 5.5rem); text-align: center; letter-spacing: 0.02em;
  margin: 4px 0 8px;
}
.readout.good { color: var(--good); }
.readout.bad { color: var(--bad); }
.hud { display: flex; justify-content: space-between; font-family: var(--font-c); font-weight: 500; font-size: 1.2rem; color: var(--muted); }
.hud b { color: var(--ink); font-weight: 700; }
.keypad { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin-top: 8px; }
.keypad button { min-height: 46px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 7px; font-family: var(--font-c); font-weight: 700; font-size: 1.3rem; cursor: pointer; }
.keypad button.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.keypad button:disabled { opacity: 0.4; }
.choice-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.choice-row .btn { min-height: 64px; font-size: 1.2rem; }
.swatch-light { background: #f0d9b5 !important; color: #3a2a12 !important; }
.swatch-dark { background: #7a5432 !important; color: #fff !important; }
.option-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.option { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 12px; text-align: left; cursor: pointer; }
.option[aria-pressed="true"] { border-color: var(--brass); box-shadow: inset 0 0 0 1px var(--brass); background: var(--brass-soft); }
.option .t { font-weight: 600; display: block; }
.option .d { font-size: 0.85rem; color: var(--muted); }
.heat { display: grid; grid-template-columns: repeat(8, 1fr); max-width: 320px; aspect-ratio: 1; border-radius: 6px; overflow: hidden; margin-top: 8px; }
.heat div { display: grid; place-items: center; font-family: var(--font-c); font-size: 0.75rem; color: rgba(0,0,0,0.55); }
.field { margin: 0 0 16px; }
.field > label:not(.toggle), .field > .label { display: block; font-weight: 600; margin-bottom: 6px; }

/* ---------- settings ---------- */
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch-btn { border: 2px solid transparent; border-radius: 10px; padding: 3px; background: none; cursor: pointer; text-align: center; font-size: 0.8rem; color: var(--muted); }
.swatch-btn[aria-pressed="true"] { border-color: var(--brass); color: var(--ink); }
.mini-board { display: grid; grid-template-columns: repeat(2, 26px); grid-template-rows: repeat(2, 26px); border-radius: 6px; overflow: hidden; margin-bottom: 3px; }
.piece-prev { display: flex; gap: 0; background: var(--surface-2); border-radius: 6px; margin-bottom: 3px; }
.piece-prev span { width: 34px; height: 34px; background: center/90% no-repeat; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.toggle:last-child { border-bottom: 0; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 15px; transition: background 150ms; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; background: #fff; border-radius: 50%; transition: transform 150ms; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 7px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.changelog li { margin-bottom: 4px; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 8px; z-index: 100; font-weight: 600; box-shadow: var(--shadow); }

/* ---------- review ---------- */
.steps-bar { display: flex; gap: 6px; margin-bottom: 12px; }
.steps-bar div { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.steps-bar div.done { background: var(--good); }
.steps-bar div.cur { background: var(--brass); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
@media (max-width: 480px) {
  main { padding: 12px; }
  h1 { font-size: 1.7rem; }
  .today { padding: 16px; }
  .today-count { font-size: 2.6rem; }
}
