/* ---------- tokens (from validated reference palette) ---------- */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --border: rgba(11,11,11,.10);
  --accent: #2a78d6;            /* series-1 blue */
  --s1: #2a78d6; --s2: #008300; --s3: #e87ba4; --s4: #eda100;
  --heat-0: #efeeea;
  --heat-1: #cde2fb; --heat-2: #9ec5f4; --heat-3: #5598e7; --heat-4: #256abf; --heat-5: #104281;
  --good: #006300;
  --cloze-bg: #fdf0d7;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --border: rgba(255,255,255,.10);
    --accent: #3987e5;
    --s1: #3987e5; --s2: #008300; --s3: #d55181; --s4: #c98500;
    --heat-0: #232322;
    --heat-1: #0d366b; --heat-2: #184f95; --heat-3: #2a78d6; --heat-4: #6da7ec; --heat-5: #b7d3f6;
    --good: #0ca30c;
    --cloze-bg: #3a3320;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --ink: #fff; --ink-2: #c3c2b7;
  --muted: #898781; --grid: #2c2c2a; --border: rgba(255,255,255,.10);
  --accent: #3987e5;
  --s1: #3987e5; --s2: #008300; --s3: #d55181; --s4: #c98500;
  --heat-0: #232322;
  --heat-1: #0d366b; --heat-2: #184f95; --heat-3: #2a78d6; --heat-4: #6da7ec; --heat-5: #b7d3f6;
  --good: #0ca30c;
  --cloze-bg: #3a3320;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }

/* ---------- chrome ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { color: var(--ink); font-size: 17px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.search { flex: 1; max-width: 480px; margin-left: auto; }
.search input {
  width: 100%; padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--grid); background: var(--page); color: var(--ink);
  font: inherit; font-size: 14px;
}
.icon-btn {
  background: none; border: 1px solid var(--grid); border-radius: 8px;
  color: var(--ink-2); font-size: 16px; padding: 5px 10px; cursor: pointer;
}
.icon-btn:hover { color: var(--ink); }
main { max-width: 1080px; margin: 0 auto; padding: 24px 16px 64px; }
.foot {
  max-width: 1080px; margin: 0 auto; padding: 16px;
  color: var(--muted); font-size: 13px; border-top: 1px solid var(--border);
}
.loading { color: var(--muted); padding: 48px 0; text-align: center; }

/* ---------- home ---------- */
.hero { margin: 8px 0 20px; }
.hero h1 { font-size: 28px; margin: 0 0 6px; }
.hero p { color: var(--ink-2); margin: 0; max-width: 60ch; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 12px; margin: 20px 0; }
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px;
}
.tile .v { font-size: 26px; font-weight: 650; }
.tile .l { color: var(--muted); font-size: 13px; margin-top: 2px; }

.card-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px; margin: 16px 0;
}
.card-panel h2 { margin: 0 0 12px; font-size: 17px; }

/* heatmap */
.hm-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.hm-years { display: flex; gap: 4px; margin-left: auto; }
.hm-years button {
  border: 1px solid var(--grid); background: none; color: var(--ink-2);
  border-radius: 6px; padding: 3px 9px; font: inherit; font-size: 13px; cursor: pointer;
}
.hm-years button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.hm-scroll { overflow-x: auto; padding-bottom: 4px; }
.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 12px); gap: 3px; width: max-content; }
.hm-cell { width: 12px; height: 12px; border-radius: 3px; background: var(--heat-0); }
.hm-cell[data-lv="1"] { background: var(--heat-1); }
.hm-cell[data-lv="2"] { background: var(--heat-2); }
.hm-cell[data-lv="3"] { background: var(--heat-3); }
.hm-cell[data-lv="4"] { background: var(--heat-4); }
.hm-cell[data-lv="5"] { background: var(--heat-5); }
.hm-legend { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; margin-top: 8px; }
.hm-legend .hm-cell { display: inline-block; }

/* subject grid */
.subjects { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px,1fr)); gap: 12px; }
.subj {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; display: flex; flex-direction: column; gap: 8px;
}
.subj h3 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.subj .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.subj .meta { color: var(--muted); font-size: 13px; }
.subj .actions { display: flex; gap: 8px; margin-top: auto; }

.btn {
  display: inline-block; border: 1px solid var(--grid); border-radius: 8px;
  padding: 6px 12px; font: inherit; font-size: 14px; cursor: pointer;
  background: none; color: var(--ink);
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

/* bar chart */
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 160px 1fr; gap: 10px; align-items: center; font-size: 14px; }
.bar-row .name { color: var(--ink-2); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { position: relative; height: 22px; }
.bar-fill { position: absolute; inset: 0 auto 0 0; border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-val { position: absolute; left: calc(var(--w) + 8px); top: 0; line-height: 22px; color: var(--ink-2); font-size: 13px; }

/* ---------- group / deck pages ---------- */
.crumbs { color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.deck-list { display: grid; gap: 8px; }
.deck-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 14px;
}
.deck-row .dn { font-weight: 550; }
.deck-row .dc { color: var(--muted); font-size: 13px; }
.deck-row .sp { flex: 1; }

/* browse list */
.qa-list { display: grid; gap: 10px; margin-top: 12px; }
.qa {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 16px; overflow-x: auto;
}
.qa .q { font-weight: 550; }
.qa .a { border-top: 1px dashed var(--grid); margin-top: 8px; padding-top: 8px; color: var(--ink-2); }
.qa .tags { margin-top: 8px; }
.tag {
  display: inline-block; font-size: 12px; color: var(--muted);
  border: 1px solid var(--grid); border-radius: 999px; padding: 1px 8px; margin-right: 4px;
}
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin: 16px 0; }
.pager .pg { color: var(--muted); font-size: 14px; }
.filter-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.filter-row input {
  flex: 1; min-width: 200px; padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--grid); background: var(--surface); color: var(--ink); font: inherit; font-size: 14px;
}

mark { background: var(--cloze-bg); color: inherit; border-radius: 3px; padding: 0 2px; }

/* ---------- study mode ---------- */
.study { max-width: 760px; margin: 0 auto; }
.study-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.study-top .prog { color: var(--muted); font-size: 14px; }
.pbar { height: 4px; background: var(--grid); border-radius: 2px; overflow: hidden; margin-bottom: 16px; }
.pbar i { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.scard {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 26px; min-height: 260px; cursor: pointer;
  display: flex; flex-direction: column; gap: 14px; overflow-x: auto;
}
.scard .front { font-size: 19px; font-weight: 550; }
.scard .back { border-top: 1px dashed var(--grid); padding-top: 14px; font-size: 17px; }
.scard .hint { color: var(--muted); font-size: 13px; margin-top: auto; text-align: center; }
.scard .extra { color: var(--ink-2); font-size: 14px; }
.study-btns { display: flex; gap: 10px; justify-content: center; margin: 16px 0; }
.study-btns[hidden] { display: none; }
.study-btns .btn { font-size: 15px; padding: 9px 22px; }
.btn.again { border-color: #d03b3b; color: #d03b3b; }
.btn.good { border-color: var(--good); color: var(--good); }
.study-done { text-align: center; padding: 40px 0; }
.study-done .big { font-size: 42px; }
kbd {
  font: 12px ui-monospace, monospace; border: 1px solid var(--grid);
  border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; color: var(--muted);
}

/* cloze */
.cloze { background: var(--cloze-bg); border-radius: 4px; padding: 0 6px; font-weight: 600; }
.cloze-answer { background: var(--cloze-bg); border-radius: 4px; padding: 0 4px; font-weight: 600; color: var(--accent); }

/* image occlusion */
.io-wrap { position: relative; display: inline-block; max-width: 100%; }
.io-wrap .io-mask { position: absolute; inset: 0; width: 100%; height: 100%; }
.io-wrap.revealed .io-mask { display: none; }

/* anki content tables */
.qa table, .scard table { border-collapse: collapse; font-size: 14px; max-width: 100%; }
.qa td, .qa th, .scard td, .scard th { border: 1px solid var(--grid); padding: 4px 8px; }

/* tooltip */
.tip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--ink); color: var(--page);
  font-size: 12.5px; line-height: 1.4; padding: 5px 9px; border-radius: 6px;
  max-width: 260px;
}

@media (max-width: 640px) {
  .bar-row { grid-template-columns: 1fr; gap: 2px; }
  .bar-row .name { text-align: left; }
  .topbar { flex-wrap: wrap; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
}
