/* Chanki — quiet, Anki-like interface. Tokens first; everything else reads from them. */

:root {
  color-scheme: light;
  --page: #f5f5f3;
  --surface: #ffffff;
  --surface-2: #f0f0ed;
  --hover: #ebebe7;
  --line: #e3e2dd;
  --line-strong: #cfcec8;
  --ink: #1c1c1a;
  --ink-2: #55544f;
  --muted: #84837d;
  --accent: #2463c7;
  --accent-ink: #ffffff;
  --accent-soft: #e6eefb;
  --focus: #2463c7;
  --danger: #b4322a;
  --danger-soft: #fbeceb;
  --ok: #1f7a37;
  --bad: #b4322a;

  /* Anki's answer colours */
  --again: #d93025;
  --hard: #c26401;
  --good: #188038;
  --easy: #1a73e8;

  /* Anki's queue colours */
  --c-new: #1f63c4;
  --c-learn: #c0392b;
  --c-due: #1d7f39;

  /* Chart slots (validated: blue, orange, aqua, violet) */
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #6250d6;
  --grid: #e8e7e2;
  --axis: #c9c8c1;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(20, 20, 18, 0.05), 0 4px 16px rgba(20, 20, 18, 0.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #161615;
    --surface: #1f1f1d;
    --surface-2: #282826;
    --hover: #2e2e2b;
    --line: #33332f;
    --line-strong: #45443f;
    --ink: #ecebe6;
    --ink-2: #bdbcb4;
    --muted: #8c8b84;
    --accent: #5b9bf0;
    --accent-ink: #0d1b2e;
    --accent-soft: #1d2b40;
    --focus: #7cb0f5;
    --danger: #ef7469;
    --danger-soft: #3a1f1d;
    --ok: #57c06f;
    --bad: #ef7469;
    --c-new: #6aa6f2;
    --c-learn: #f07d6b;
    --c-due: #5cc275;
    --again: #f28b82;
    --hard: #fbbc5d;
    --good: #81c995;
    --easy: #8ab4f8;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s4: #9085e9;
    --grid: #2c2c29;
    --axis: #3d3d39;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #161615;
  --surface: #1f1f1d;
  --surface-2: #282826;
  --hover: #2e2e2b;
  --line: #33332f;
  --line-strong: #45443f;
  --ink: #ecebe6;
  --ink-2: #bdbcb4;
  --muted: #8c8b84;
  --accent: #5b9bf0;
  --accent-ink: #0d1b2e;
  --accent-soft: #1d2b40;
  --focus: #7cb0f5;
  --danger: #ef7469;
  --danger-soft: #3a1f1d;
  --ok: #57c06f;
  --bad: #ef7469;
  --c-new: #6aa6f2;
  --c-learn: #f07d6b;
  --c-due: #5cc275;
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #9085e9;
  --grid: #2c2c29;
  --axis: #3d3d39;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.ink-2 { color: var(--ink-2); }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 52px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 16px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  justify-self: start;
  font-weight: 650;
  font-size: 16px;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 2px; }
.nav a {
  color: var(--ink-2);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 14.5px;
}
.nav a:hover { color: var(--ink); background: var(--hover); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--ink); background: var(--surface-2); font-weight: 550; }
.topbar-right { justify-self: end; display: flex; align-items: center; gap: 8px; }

.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--ink-2);
  font-size: 13px; font-weight: 600; text-transform: uppercase;
  border: 1px solid var(--line);
}
.menu > summary:hover .avatar { background: var(--hover); color: var(--ink); }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px);
  min-width: 190px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.12);
  z-index: 40;
}
.menu-panel .menu-head { padding: 8px 10px 6px; font-size: 13px; color: var(--muted); }
.menu-panel a, .menu-panel button {
  display: block; width: 100%; text-align: left;
  padding: 7px 10px; border-radius: 6px;
  font: inherit; font-size: 14px; color: var(--ink);
  background: none; border: 0; cursor: pointer;
}
.menu-panel a:hover, .menu-panel button:hover { background: var(--hover); text-decoration: none; }
.menu-panel hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.menu-panel .danger { color: var(--danger); }

/* ---------------------------------------------------------------- layout */
main { flex: 1; width: 100%; }
.page { max-width: 760px; margin: 0 auto; padding: 32px 16px 64px; }
.page.wide { max-width: 1080px; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { color: var(--muted); font-size: 14px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card + .card, .section + .section { margin-top: 16px; }
.card-body { padding: 20px; }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.card-sub { font-size: 13.5px; color: var(--muted); margin-bottom: 14px; }
.notice {
  max-width: 760px; margin: 16px auto 0; padding: 10px 14px;
  border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--ink);
  font-size: 14px;
}
.error {
  padding: 10px 14px; border-radius: var(--radius-sm);
  background: var(--danger-soft); color: var(--danger); font-size: 14px; margin-bottom: 14px;
}

/* ---------------------------------------------------------------- buttons & forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 38px; padding: 0 16px;
  border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: 14.5px; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.btn:hover { background: var(--hover); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--hover); color: var(--ink); }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 13.5px; }
.btn.large { min-height: 48px; padding: 0 28px; font-size: 16px; }
.btn[disabled] { opacity: 0.55; cursor: progress; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row.center { justify-content: center; }
.btn-row.end { justify-content: flex-end; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > label, .field > .label { font-size: 13.5px; font-weight: 550; color: var(--ink-2); }
.field .hint { font-size: 13px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; min-height: 40px; padding: 8px 12px;
  font: inherit; font-size: 15px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px;
}
textarea.input { min-height: 140px; font-family: var(--mono); font-size: 13px; resize: vertical; }
.input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.input.narrow { max-width: 140px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14.5px; cursor: pointer; }
.check input { margin-top: 3px; width: 17px; height: 17px; accent-color: var(--accent); flex-shrink: 0; }
.check small { display: block; color: var(--muted); font-size: 13px; }

.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: 9px; border: 1px solid var(--line); }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.segmented span { display: block; padding: 6px 14px; border-radius: 7px; font-size: 14px; color: var(--ink-2); }
.segmented input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); font-weight: 550; }
.segmented input:focus-visible + span { outline: 2px solid var(--focus); }

.swatches { display: flex; gap: 12px; }
.swatch { position: relative; cursor: pointer; text-align: center; font-size: 13px; color: var(--ink-2); }
.swatch input { position: absolute; opacity: 0; }
.swatch .chip {
  display: block; width: 56px; height: 56px; border-radius: 8px; margin-bottom: 4px;
  border: 2px solid transparent; background-size: cover;
}
.swatch input:checked + .chip { border-color: var(--accent); }
.swatch input:focus-visible + .chip { outline: 2px solid var(--focus); outline-offset: 2px; }
.chip.brown { background-image: url(/static/boards/brown.svg); }
.chip.blue { background-image: url(/static/boards/blue.svg); }
.chip.green { background-image: url(/static/boards/green.svg); }

details.disclosure > summary { cursor: pointer; color: var(--ink-2); font-size: 14px; padding: 4px 0; }
details.disclosure[open] > summary { margin-bottom: 12px; }

dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 0;
  background: var(--surface); color: var(--ink);
  width: min(440px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22);
}
dialog::backdrop { background: rgba(10, 10, 10, 0.35); }
dialog .dialog-body { padding: 22px; }
dialog h2 { margin-bottom: 6px; }
dialog p { color: var(--ink-2); font-size: 14.5px; margin-bottom: 16px; }

/* ---------------------------------------------------------------- deck list */
.decks { width: 100%; border-collapse: collapse; }
.decks th {
  font-size: 12.5px; font-weight: 550; color: var(--muted); text-align: right;
  padding: 0 10px 10px; border-bottom: 1px solid var(--line);
}
.decks th:first-child { text-align: left; padding-left: 16px; }
.decks td { padding: 0 10px; height: 44px; border-bottom: 1px solid var(--line); }
.decks tr:last-child td { border-bottom: 0; }
.decks td.n { text-align: right; width: 64px; font-variant-numeric: tabular-nums; font-weight: 550; }
.decks td.n.zero { color: var(--line-strong); font-weight: 400; }
.decks td.n.new { color: var(--c-new); }
.decks td.n.learn { color: var(--c-learn); }
.decks td.n.due { color: var(--c-due); }
.decks td.menu-cell { width: 44px; padding: 0 8px 0 0; text-align: right; }
.decks tbody tr { transition: background 0.1s; }
.decks tbody tr:hover { background: var(--surface-2); }
.decks tbody tr.drop-target { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.decks tbody tr.dragging { opacity: 0.4; }
.deck-name { display: flex; align-items: center; gap: 4px; min-width: 0; }
.deck-name a { color: var(--ink); font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deck-name a:hover { text-decoration: none; color: var(--accent); }
.deck-name .depth-1 { padding-left: 22px; }
.toggle {
  width: 24px; height: 24px; flex-shrink: 0;
  display: grid; place-items: center; border: 0; background: none; border-radius: 6px;
  color: var(--muted); cursor: pointer; padding: 0;
}
.toggle:hover { background: var(--hover); color: var(--ink); }
.toggle svg { transition: transform 0.15s; }
.toggle[aria-expanded="false"] svg { transform: rotate(-90deg); }
.toggle-spacer { width: 24px; flex-shrink: 0; }
.icon-btn {
  width: 30px; height: 30px; border-radius: 7px; display: inline-grid; place-items: center;
  color: var(--muted); background: none; border: 0; cursor: pointer;
}
.icon-btn:hover, details[open] > .icon-btn { background: var(--hover); color: var(--ink); }
@media (hover: hover) {
  .decks tbody tr .row-menu { opacity: 0; }
  .decks tbody tr:hover .row-menu, .decks tbody tr .row-menu[open], .decks tbody tr:focus-within .row-menu { opacity: 1; }
}
.root-drop {
  margin-top: 10px; padding: 10px; border: 1.5px dashed var(--line-strong); border-radius: var(--radius-sm);
  text-align: center; color: var(--muted); font-size: 13.5px;
}
.root-drop.drop-target { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.decks-foot { margin-top: 22px; text-align: center; color: var(--muted); font-size: 14px; }
.decks-foot .btn-row { margin-top: 16px; }

/* ---------------------------------------------------------------- overview */
.overview { text-align: center; padding: 48px 16px 64px; max-width: 520px; margin: 0 auto; }
.crumbs { color: var(--muted); font-size: 14px; margin-bottom: 6px; }
.crumbs span + span::before { content: "/"; margin: 0 8px; color: var(--line-strong); }
.overview h1 { font-size: 26px; margin-bottom: 28px; }
.overview-counts { display: inline-grid; grid-template-columns: auto auto; gap: 8px 28px; text-align: left; margin-bottom: 32px; font-size: 15.5px; }
.overview-counts dt { color: var(--ink-2); }
.overview-counts dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.overview .congrats { font-size: 17px; margin-bottom: 8px; }
.overview .sub { color: var(--muted); margin-bottom: 28px; }
.overview .links { margin-top: 28px; font-size: 14px; display: flex; gap: 20px; justify-content: center; }
.overview .links a { color: var(--muted); }

/* ---------------------------------------------------------------- study */
.study { display: flex; flex-direction: column; align-items: center; padding: 14px 16px 28px; gap: 12px; }
.study-deck { color: var(--muted); font-size: 13.5px; min-height: 20px; text-align: center; }
.board-wrap { width: min(100%, 560px); position: relative; }
.board-wrap.board-sized { width: auto; }
.board { aspect-ratio: 1; width: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }
.board.cg-wrap { box-sizing: content-box; }
.board-frame {
  border-radius: 4px; overflow: hidden;
  box-shadow: 0 1px 2px rgba(0,0,0,.12), 0 6px 24px rgba(0,0,0,.08);
}
.caption {
  min-height: 28px; display: flex; align-items: baseline; justify-content: center; gap: 10px;
  font-size: 17px; color: var(--ink-2); text-align: center;
}
.caption .opp { color: var(--ink-2); }
.caption .prompt { color: var(--muted); font-size: 15px; }
.caption .answer { color: var(--ink); font-weight: 650; }
.caption .answer.right { color: var(--ok); }
.caption .answer.wrong { color: var(--bad); }
.caption .played { color: var(--muted); font-size: 14px; }
button.caption-replay { all: unset; cursor: pointer; border-radius: 4px; }
button.caption-replay:hover { color: var(--ink); }
button.caption-replay:focus-visible { outline: 2px solid var(--focus); }

.counts { display: flex; gap: 14px; justify-content: center; font-size: 15px; font-variant-numeric: tabular-nums; font-weight: 550; min-height: 24px; }
.counts span { padding-bottom: 1px; border-bottom: 2px solid transparent; }
.counts .new { color: var(--c-new); }
.counts .learn { color: var(--c-learn); }
.counts .due { color: var(--c-due); }
.counts .current { border-bottom-color: currentColor; }

.answer-area { width: min(100%, 560px); min-height: 92px; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; }
.show-answer { width: min(100%, 300px); }
.show-answer kbd { margin-left: 4px; }
.grades { width: 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; animation: rise 0.16s ease-out; }
.grade { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.grade .ivl { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.grade button {
  position: relative; width: 100%; min-height: 48px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--grade);
  font: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s, transform 0.08s;
}
.grade button:hover { background: color-mix(in srgb, var(--grade) 7%, var(--surface)); border-color: color-mix(in srgb, var(--grade) 45%, var(--line-strong)); }
.grade button:active, .grade button.chosen { transform: scale(0.97); background: color-mix(in srgb, var(--grade) 12%, var(--surface)); }
.grade button.default { border-color: var(--grade); box-shadow: inset 0 0 0 1px var(--grade); }
.grade .space { display: none; }
.grade button.default .space { display: inline-block; }
.g-again { --grade: var(--again); }
.g-hard { --grade: var(--hard); }
.g-good { --grade: var(--good); }
.g-easy { --grade: var(--easy); }
kbd {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 5px;
  font: 600 11px/17px var(--font); text-align: center; color: inherit; opacity: 0.75;
  border: 1px solid color-mix(in srgb, currentColor 40%, transparent); background: transparent;
}
.inferred { margin: 6px 0 0; font-size: 15px; display: flex; gap: 8px; align-items: baseline; animation: rise 0.16s ease-out; }
.inferred .g-again, .inferred .g-hard, .inferred .g-good, .inferred .g-easy { color: var(--grade); font-weight: 600; }
.inferred .ivl { color: var(--muted); font-size: 13.5px; }
.answer-note { margin-top: 10px; font-size: 13px; color: var(--muted); min-height: 18px; text-align: center; }
@keyframes rise { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
@media (hover: none) { kbd { display: none !important; } }
.study-empty { text-align: center; padding: 64px 16px; }

/* Board themes & move highlights (override chessground defaults) */
.board-theme-blue cg-board { background-image: url(/static/boards/blue.svg); }
.board-theme-green cg-board { background-image: url(/static/boards/green.svg); }
cg-board square.last-move { background-color: rgba(155, 199, 0, 0.36); }
.board-theme-blue cg-board square.last-move { background-color: rgba(20, 85, 160, 0.26); }
cg-board square.move-dest { background: radial-gradient(rgba(20, 30, 85, 0.3) 19%, rgba(0, 0, 0, 0) 20%); }
cg-board square.move-dest:hover { background: rgba(20, 85, 30, 0.25); }
cg-board square.oc.move-dest { background: radial-gradient(transparent 0%, transparent 79%, rgba(20, 30, 85, 0.3) 80%); }
cg-board square.selected { background-color: rgba(20, 85, 30, 0.45); }
cg-board square.glow-right { animation: glow-right 0.9s ease-out forwards; }
cg-board square.mark-wrong { background-color: rgba(205, 60, 50, 0.34); }
@keyframes glow-right { from { background-color: rgba(52, 168, 83, 0.55); } to { background-color: rgba(52, 168, 83, 0.16); } }
.board-frame { transition: opacity 0.15s ease; }
.board-frame.fading { opacity: 0; }
.cg-wrap coords { font-family: var(--font); font-weight: 600; }

/* ---------------------------------------------------------------- browse */
.browse { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.browse-tools { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.browse-tools .input { flex: 1; min-width: 180px; }
.browse-tools select.input { flex: 0 1 240px; }
.table-scroll { overflow: auto; max-height: calc(100svh - 210px); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface); text-align: left; font-weight: 550; color: var(--muted); font-size: 12.5px;
  padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table td.r, .table th.r { text-align: right; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--surface-2); }
.table tbody tr[aria-selected="true"] { background: var(--accent-soft); }
.table .line { color: var(--muted); font-size: 13px; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .move { font-weight: 600; white-space: nowrap; }
.table .deckcol { color: var(--ink-2); white-space: nowrap; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.pill { display: inline-block; font-size: 12.5px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill.new { color: var(--c-new); }
.pill.due { color: var(--c-due); }
.pill.bad { color: var(--danger); }
.preview { position: sticky; top: 72px; }
.preview .card-body { padding: 14px; }
.preview .board-frame { margin-bottom: 12px; }
.preview dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13.5px; margin: 0; }
.preview dt { color: var(--muted); }
.preview dd { margin: 0; overflow-wrap: anywhere; }
.preview-empty { color: var(--muted); font-size: 14px; text-align: center; padding: 40px 10px; }

/* ---------------------------------------------------------------- stats */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.tile { padding: 14px 16px; }
.tile .k { font-size: 13px; color: var(--muted); }
.tile .v { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; }
.tile .v small { font-size: 14px; color: var(--muted); font-weight: 500; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { font-family: var(--font); font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .hit { fill: transparent; }
.chart .hit:hover, .chart .hit:focus { fill: var(--hover); opacity: 0.6; outline: none; }
.chart .k-due, .chart .k-ok, .chart .k-full { fill: var(--s1); }
.chart .k-again, .chart .k-prior { fill: var(--s2); }
.chart .k-base { fill: var(--s3); }
.chart .l-full { stroke: var(--s1); }
.chart .l-prior { stroke: var(--s2); }
.chart .l-base { stroke: var(--s3); }
.chart polyline.series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart circle.pt { stroke: var(--surface); stroke-width: 2; }
.chart .diag { stroke: var(--axis); stroke-width: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; color: var(--ink-2); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend i.k-new, .legend i.k-due, .legend i.k-ok, .legend i.k-full { background: var(--s1); }
.legend i.k-learning, .legend i.k-again, .legend i.k-prior { background: var(--s2); }
.legend i.k-young, .legend i.k-base { background: var(--s3); }
.legend i.k-mature { background: var(--s4); }
.stack { display: flex; height: 14px; border-radius: 4px; overflow: hidden; gap: 2px; background: var(--surface); }
.stack div { height: 100%; }
.stack .k-new { background: var(--s1); }
.stack .k-learning { background: var(--s2); }
.stack .k-young { background: var(--s3); }
.stack .k-mature { background: var(--s4); }
.state-list { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.state-list div { font-size: 13px; color: var(--ink-2); display: flex; flex-direction: column; gap: 2px; }
.state-list b { font-size: 18px; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.state-list b small { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.hbars { display: grid; grid-template-columns: 56px 1fr 72px; gap: 10px 12px; align-items: center; font-size: 14px; }
.hbar { height: 12px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar div { height: 100%; background: var(--s1); border-radius: 0 4px 4px 0; }
.hbars .r { text-align: right; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.table-view { margin-top: 10px; }
.table-view summary { font-size: 13px; color: var(--muted); cursor: pointer; }
.table-view table { margin-top: 8px; }
.tip {
  position: fixed; z-index: 60; pointer-events: none;
  background: var(--ink); color: var(--page); font-size: 12.5px;
  padding: 6px 9px; border-radius: 6px; max-width: 260px; line-height: 1.35;
  box-shadow: 0 6px 18px rgba(0,0,0,.2);
}
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ---------------------------------------------------------------- import */
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 132px; padding: 18px; text-align: center;
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface-2);
  color: var(--ink-2); cursor: pointer; transition: border-color .12s, background .12s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop strong { color: var(--ink); font-weight: 600; }
.drop .file-name { font-size: 13.5px; color: var(--accent); }

/* ---------------------------------------------------------------- auth */
.auth { flex: 1; display: grid; place-items: center; padding: 32px 16px; }
.auth .card { width: min(400px, 100%); }
.auth .card-body { padding: 28px; }
.auth .logo { font-size: 22px; font-weight: 650; text-align: center; margin-bottom: 4px; letter-spacing: -0.01em; }
.auth .lede { text-align: center; color: var(--muted); font-size: 14px; margin-bottom: 22px; }
.auth .btn.primary { width: 100%; min-height: 44px; }
.auth .foot { text-align: center; font-size: 13px; color: var(--muted); margin-top: 18px; }
.consent { font-size: 13.5px; color: var(--ink-2); background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 14px; }
.consent p + p { margin-top: 6px; }

/* ---------------------------------------------------------------- console */
.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 12px; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; font-size: 14.5px; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--ink); font-weight: 550; }
.filters { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; font-size: 14px; }
.filters select.input { width: auto; min-height: 34px; padding: 4px 10px; font-size: 14px; }
.filters .check { font-size: 14px; align-items: center; }
.filters .check input { margin-top: 0; }
.best { font-size: 11.5px; padding: 1px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); margin-left: 6px; font-weight: 550; }
.desc { display: block; font-size: 12.5px; color: var(--muted); font-weight: 400; }
.delta-good { color: var(--ok); }
.delta-bad { color: var(--danger); }
.copy-box { display: flex; gap: 8px; }
.copy-box .input { font-family: var(--mono); font-size: 13px; }
.inspector-grid { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 20px; align-items: start; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.meter { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; min-width: 80px; }
.meter div { height: 100%; background: var(--s1); }
.meter.k-prior div { background: var(--s2); }
.meter.k-base div { background: var(--s3); }
.meter.target div { background: var(--accent); }
code, .mono { font-family: var(--mono); font-size: 0.92em; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 900px) {
  .browse { grid-template-columns: 1fr; }
  .preview { position: static; order: -1; }
  .preview.empty-preview { display: none; }
  .inspector-grid { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  .topbar { grid-template-columns: auto 1fr auto; padding: 0 10px; gap: 6px; }
  .brand { display: none; }
  .nav { justify-self: start; }
  .nav a { padding: 6px 10px; font-size: 14.5px; }
  .page { padding: 20px 16px 48px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .state-list { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .decks td.n { width: 44px; padding: 0 6px; font-size: 14px; }
  .decks th { padding: 0 6px 10px; }
  .table .line, .table .deckcol { display: none; }
  .study { padding: 10px 8px 24px; gap: 10px; }
  .grades { gap: 6px; }
  .grade button { min-height: 50px; font-size: 14.5px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

/* ---------------------------------------------------------------- additions */
[hidden] { display: none !important; }
.deck-name.d-1 { padding-left: 24px; }
.deck-name.d-2 { padding-left: 48px; }
.deck-name.d-3 { padding-left: 72px; }
.deck-name.d-4 { padding-left: 96px; }
.deck-name.d-5 { padding-left: 120px; }
@media (max-width: 640px) {
  .deck-name.d-1 { padding-left: 14px; }
  .deck-name.d-2 { padding-left: 28px; }
  .deck-name.d-3 { padding-left: 42px; }
  .deck-name.d-4, .deck-name.d-5 { padding-left: 56px; }
}
.decks td:first-child { padding-left: 8px; }
.board-host { width: 100%; }
.board-host .board-frame { width: fit-content; margin: 0 auto; }
.overview-counts dd.new { color: var(--c-new); }
.overview-counts dd.learn { color: var(--c-learn); }
.overview-counts dd.due { color: var(--c-due); }
.chart-scroll { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
.chart-scroll .chart { min-width: 520px; }
.today-line { color: var(--ink-2); margin-bottom: 16px; }
.section-gap { margin-top: 16px; }
.inline-form { display: inline; }
.menu-panel form { margin: 0; }
.empty-state { text-align: center; padding: 56px 16px; }
.empty-state h2 { margin-bottom: 6px; }
.empty-state p { color: var(--muted); margin-bottom: 20px; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }

.tiles > .card, .split > .card, .split > section { margin-top: 0 !important; }
.notice { width: min(760px, calc(100% - 32px)); }
.decks { table-layout: fixed; }
.decks th { padding-top: 12px; }
.decks th:nth-child(2), .decks th:nth-child(3), .decks th:nth-child(4) { width: 64px; }
.decks th:last-child { width: 48px; }
.decks td:first-child { overflow: hidden; }
.chart.square { max-width: 340px; margin: 0 auto; }
.preview .board-host { margin-bottom: 14px; }
.tile .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
@media (max-width: 640px) {
  .decks th:nth-child(2), .decks th:nth-child(3), .decks th:nth-child(4) { width: 48px; }
  .decks th:last-child { width: 40px; }
}
.drop { font-weight: 400; }
.check.field { flex-direction: row; gap: 10px; }
.preview .board-host { margin-bottom: 18px; }
