/* Chess Coach — one page, dark, built to be read at a glance. */
:root {
  --bg: #15161a;
  --bg-2: #1c1e24;
  --bg-3: #23262e;
  --line: #2f333d;
  --line-2: #3d424e;
  --ink: #e8e9ec;
  --ink-2: #a8adb8;
  --ink-3: #72777f;
  --accent: #7aa2f7;
  --accent-2: #5b7fd4;

  --brilliant: #1bc4a8;
  --great: #4b9cf0;
  --best: #7bbf5e;
  --book: #a98adf;
  --excellent: #7bbf5e;
  --good: #8a9a7a;
  --inaccuracy: #e6c35c;
  --mistake: #e8914a;
  --blunder: #e05c5c;
  --miss: #d4568c;

  --win: #7bbf5e;
  --loss: #e05c5c;
  --draw: #9aa0ab;

  --light-sq: #ebe4d0;
  --dark-sq: #8a9a6b;
  --hl: rgba(255, 221, 92, 0.45);
  --hl-move: rgba(122, 162, 247, 0.38);

  --radius: 10px;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* No padding reset on <html>: hosts may pad it for phone safe areas. */
html { background: var(--bg); }

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- chrome */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  height: 56px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; letter-spacing: -0.01em; }
.brand-mark { font-size: 24px; color: var(--accent); line-height: 1; }
.brand-text { font-size: 16px; }

.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.tabs a {
  padding: 7px 13px;
  border-radius: 7px;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}
.tabs a:hover { background: var(--bg-3); color: var(--ink); text-decoration: none; }
.tabs a.active { background: var(--accent); color: #0f1115; }

.whoami { color: var(--ink-3); font-size: 13px; font-family: var(--mono); }

.app { max-width: 1240px; margin: 0 auto; padding: 24px 20px 60px; }
.loading { color: var(--ink-3); padding: 60px 0; text-align: center; }

.foot {
  max-width: 1240px;
  margin: 0 auto;
  padding: 18px 20px 40px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--ink-3);
  font-size: 12px;
  border-top: 1px solid var(--line);
}
.foot a { color: var(--ink-2); }

/* ------------------------------------------------------------- primitives */

h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 17px; margin: 0 0 12px; letter-spacing: -0.01em; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
p { margin: 0 0 10px; }
.sub { color: var(--ink-3); font-size: 13px; margin-bottom: 20px; }

.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card + .card { margin-top: 14px; }

.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid.c3, .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 620px) { .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; } }

.stat { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat-label { color: var(--ink-3); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.stat-value { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-note { color: var(--ink-3); font-size: 12px; margin-top: 2px; }
.stat-value small { font-size: 15px; color: var(--ink-2); font-weight: 500; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left;
  color: var(--ink-3);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  padding: 6px 10px 6px 0;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 7px 10px 7px 0; border-bottom: 1px solid var(--bg-3); font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; padding-right: 14px; }
.t-scroll { overflow-x: auto; }

.pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.02em;
  background: var(--bg-3);
  color: var(--ink-2);
}
.pill.win { background: rgba(123, 191, 94, 0.17); color: var(--win); }
.pill.loss { background: rgba(224, 92, 92, 0.17); color: var(--loss); }
.pill.draw { background: rgba(154, 160, 171, 0.17); color: var(--draw); }

.bar { height: 7px; border-radius: 4px; background: var(--bg-3); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

button, .btn {
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--line-2);
  background: var(--bg-3);
  color: var(--ink);
  cursor: pointer;
}
button:hover, .btn:hover { border-color: var(--accent); text-decoration: none; }
button.primary { background: var(--accent); color: #0f1115; border-color: var(--accent); }
button.primary:hover { background: var(--accent-2); }
button:disabled { opacity: 0.45; cursor: default; }
button.ghost { background: transparent; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

select, input[type="text"], input[type="search"] {
  font: inherit;
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--line-2);
  background: var(--bg-3);
  color: var(--ink);
}

.empty { color: var(--ink-3); padding: 24px 0; text-align: center; font-size: 14px; }
.mono { font-family: var(--mono); }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }

/* --------------------------------------------------------- move labels */

.lbl {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 5px;
  text-transform: capitalize;
}
.lbl-brilliant { background: rgba(27, 196, 168, 0.18); color: var(--brilliant); }
.lbl-great { background: rgba(75, 156, 240, 0.18); color: var(--great); }
.lbl-best { background: rgba(123, 191, 94, 0.16); color: var(--best); }
.lbl-book { background: rgba(169, 138, 223, 0.18); color: var(--book); }
.lbl-excellent { background: rgba(123, 191, 94, 0.14); color: var(--excellent); }
.lbl-good { background: rgba(138, 154, 122, 0.16); color: var(--good); }
.lbl-inaccuracy { background: rgba(230, 195, 92, 0.18); color: var(--inaccuracy); }
.lbl-mistake { background: rgba(232, 145, 74, 0.2); color: var(--mistake); }
.lbl-blunder { background: rgba(224, 92, 92, 0.2); color: var(--blunder); }
.lbl-miss { background: rgba(212, 86, 140, 0.2); color: var(--miss); }

/* ------------------------------------------------------------- the board */

.board-wrap { width: 100%; max-width: 520px; }
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--line-2);
  user-select: none;
  touch-action: manipulation;
}
.sq { position: relative; display: flex; align-items: center; justify-content: center; }
.sq.light { background: var(--light-sq); }
.sq.dark { background: var(--dark-sq); }
.sq.hl::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--hl);
}
.sq.lastmove::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--hl-move);
}
.sq.sel::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(122, 162, 247, 0.5);
}
.sq.check::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(224, 92, 92, 0.85) 10%, rgba(224, 92, 92, 0) 72%);
}
.sq .dot {
  position: absolute;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: rgba(20, 22, 26, 0.3);
  z-index: 3;
}
.sq.occupied .dot {
  width: 86%;
  height: 86%;
  background: transparent;
  border: 5px solid rgba(20, 22, 26, 0.28);
  box-sizing: border-box;
}
.pc {
  position: relative;
  z-index: 2;
  font-size: min(8.4vw, 60px);
  line-height: 1;
  cursor: grab;
  pointer-events: none;
}
/* Both colours use the solid glyphs; the outline separates them. */
.pc.w { color: #fffefa; -webkit-text-stroke: 1.7px #23232a; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4); }
.pc.b { color: #15161a; -webkit-text-stroke: 0.9px #eceff4; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35); }

.coord {
  position: absolute;
  font-size: 9.5px;
  font-weight: 700;
  opacity: 0.55;
  z-index: 4;
  font-family: var(--mono);
}
.coord.file { bottom: 1px; right: 3px; }
.coord.rank { top: 1px; left: 3px; }
.sq.light .coord { color: #6b7355; }
.sq.dark .coord { color: #e6e2d2; }

.board-arrows { position: absolute; inset: 0; z-index: 5; pointer-events: none; }

.board-side { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 8px 0; font-size: 13px; }

/* ---------------------------------------------------------- review view */

.review { display: grid; grid-template-columns: minmax(0, 520px) minmax(300px, 1fr); gap: 20px; align-items: start; }
@media (max-width: 980px) { .review { grid-template-columns: 1fr; } }

.movelist {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-2);
}
.ml-row { display: grid; grid-template-columns: 42px 1fr 1fr; border-bottom: 1px solid var(--bg-3); }
.ml-row:last-child { border-bottom: none; }
.ml-no { color: var(--ink-3); font-size: 12px; padding: 5px 8px; font-family: var(--mono); background: var(--bg-3); }
.ml-mv {
  padding: 5px 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  font-weight: 550;
  border-left: 1px solid var(--bg-3);
}
.ml-mv:hover { background: var(--bg-3); }
.ml-mv.cur { background: var(--accent); color: #0f1115; }
.ml-mv.cur .lbl { background: rgba(15, 17, 21, 0.2); color: #0f1115; }
.ml-mv .ico { font-size: 11px; font-weight: 800; }

.evalgraph { width: 100%; height: 76px; display: block; background: var(--bg-3); border-radius: 8px; cursor: crosshair; }

.annot { border-left: 3px solid var(--line-2); padding-left: 12px; }
.annot.blunder { border-color: var(--blunder); }
.annot.mistake { border-color: var(--mistake); }
.annot.inaccuracy { border-color: var(--inaccuracy); }
.annot.brilliant { border-color: var(--brilliant); }
.annot.great { border-color: var(--great); }
.annot.book { border-color: var(--book); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }

.accbar { display: flex; height: 26px; border-radius: 7px; overflow: hidden; font-size: 11px; font-weight: 700; }
.accbar > div { display: flex; align-items: center; justify-content: center; color: #11131a; min-width: 0; }

/* --------------------------------------------------------- puzzle view */

.puzzle { display: grid; grid-template-columns: minmax(0, 520px) minmax(280px, 1fr); gap: 20px; align-items: start; }
@media (max-width: 980px) { .puzzle { grid-template-columns: 1fr; } }
.verdict { padding: 10px 14px; border-radius: 8px; font-weight: 600; font-size: 14px; }
.verdict.ok { background: rgba(123, 191, 94, 0.15); color: var(--best); }
.verdict.no { background: rgba(224, 92, 92, 0.15); color: var(--blunder); }
.verdict.hint { background: var(--bg-3); color: var(--ink-2); }

.streak { display: flex; gap: 3px; }
.streak i { width: 9px; height: 9px; border-radius: 50%; background: var(--bg-3); display: block; }
.streak i.ok { background: var(--best); }
.streak i.no { background: var(--blunder); }

/* -------------------------------------------------------- openings view */

.optree { font-family: var(--mono); font-size: 13px; }
.opmove {
  display: grid;
  grid-template-columns: 58px 1fr 92px 130px;
  gap: 10px;
  align-items: center;
  padding: 6px 8px;
  border-radius: 7px;
  cursor: pointer;
}
.opmove:hover { background: var(--bg-3); }
.opmove.yours { outline: 1px solid var(--accent); }
.wdl { display: flex; height: 16px; border-radius: 4px; overflow: hidden; font-size: 9px; font-weight: 700; }
.wdl .w { background: #e8e6df; color: #22242a; }
.wdl .d { background: #8c919c; color: #16181d; }
.wdl .b { background: #33363d; color: #d8dae0; }
.wdl span { display: flex; align-items: center; justify-content: center; min-width: 0; overflow: hidden; }

.crumbs { display: flex; gap: 6px; flex-wrap: wrap; font-family: var(--mono); font-size: 13px; }
.crumbs button { padding: 3px 8px; font-size: 12.5px; }

/* --------------------------------------------------------- library view */

.lesson { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-2); padding: 16px 18px; }
.lesson h2 { margin-bottom: 2px; }
.lesson .src { color: var(--ink-3); font-size: 12.5px; font-style: italic; margin-bottom: 10px; }
.lesson ul { margin: 8px 0 0; padding-left: 20px; }
.lesson li { margin-bottom: 5px; }
.because {
  background: var(--bg-3);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  margin: 10px 0 0;
  border-left: 3px solid var(--accent);
}

/* ---------------------------------------------------------- games list */

.gamerow { display: grid; grid-template-columns: 86px 26px 1fr 72px 62px 96px 56px; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13.5px; }
.gamerow:hover { background: var(--bg-3); }
.gamerow .opp { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gamerow .side { font-size: 16px; }
@media (max-width: 760px) {
  .gamerow { grid-template-columns: 70px 22px 1fr 56px 56px; }
  .gamerow .hide-sm { display: none; }
}

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
