/* ==========================================================================
   MDS Prep — stylesheet

   Colour: the study-state palette is an ordinal blue ramp (learning -> done)
   plus two reserved status colours (revise = warning, perfect = good) and a
   neutral for "not started". Both modes were validated with the data-viz
   palette checker: the ordinal ramp passes monotonic lightness, step gap,
   single hue and light-end contrast in light and dark; the five-state set
   passes CVD and normal-vision separation. Two light-mode steps sit below
   3:1 against the surface, so every state also carries a visible text label
   (chips, legend counts, and the topic table) — colour is never the only channel.

   Charts are a hybrid: the plot line/area is SVG on a normalised 0-100 viewBox
   with non-scaling strokes, while gridlines, axis labels, markers and hover
   zones are HTML positioned by percentage. That keeps stroke weights and type
   sizes exact at any container width with no resize handling.
   ========================================================================== */

:root {
  color-scheme: light;

  --page:        #f9f9f7;
  --surface:     #fcfcfb;
  --surface-2:   #f1f0ec;
  --ink:         #0b0b0b;
  --ink-2:       #52514e;
  --muted:       #898781;
  --grid:        #e1e0d9;
  --axis:        #c3c2b7;
  --border:      rgba(11, 11, 11, .10);
  --border-2:    rgba(11, 11, 11, .06);
  --shadow-sm:   0 1px 2px rgba(11, 11, 11, .05);
  --shadow:      0 1px 2px rgba(11, 11, 11, .05), 0 10px 28px rgba(11, 11, 11, .07);

  --accent:      #2a78d6;
  --accent-soft: #86b6ef;
  --accent-wash: rgba(42, 120, 214, .10);
  --accent-ink:  #1c5cab;

  --good:        #0ca30c;
  --warn:        #fab219;
  --serious:     #ec835a;
  --critical:    #d03b3b;
  --good-text:   #006300;

  /* study states — validated ordinal ramp + reserved status colours */
  --st-not:      #898781;
  --st-learning: #86b6ef;
  --st-done:     #2a78d6;
  --st-revise:   #fab219;
  --st-perfect:  #0ca30c;

  --radius:      12px;
  --radius-sm:   9px;
  --sidebar-w:   250px;
  --rail-w:      66px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:        #0d0d0d;
    --surface:     #1a1a19;
    --surface-2:   #242423;
    --ink:         #ffffff;
    --ink-2:       #c3c2b7;
    --muted:       #898781;
    --grid:        #2c2c2a;
    --axis:        #383835;
    --border:      rgba(255, 255, 255, .10);
    --border-2:    rgba(255, 255, 255, .06);
    --shadow-sm:   0 1px 2px rgba(0, 0, 0, .4);
    --shadow:      0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .4);
    --accent:      #3987e5;
    --accent-soft: #256abf;
    --accent-wash: rgba(57, 135, 229, .16);
    --accent-ink:  #86b6ef;
    --good-text:   #0ca30c;
    --st-learning: #256abf;
    --st-done:     #3987e5;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page:        #0d0d0d;
  --surface:     #1a1a19;
  --surface-2:   #242423;
  --ink:         #ffffff;
  --ink-2:       #c3c2b7;
  --muted:       #898781;
  --grid:        #2c2c2a;
  --axis:        #383835;
  --border:      rgba(255, 255, 255, .10);
  --border-2:    rgba(255, 255, 255, .06);
  --shadow-sm:   0 1px 2px rgba(0, 0, 0, .4);
  --shadow:      0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .4);
  --accent:      #3987e5;
  --accent-soft: #256abf;
  --accent-wash: rgba(57, 135, 229, .16);
  --accent-ink:  #86b6ef;
  --good-text:   #0ca30c;
  --st-learning: #256abf;
  --st-done:     #3987e5;
}

/* ------------------------------------------------------------------ base */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--sans);
  background: var(--page);
  color: var(--ink);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; font-weight: 600; }
h1 { font-size: 1.28rem; }
h2 { font-size: 1.02rem; }
h3 { font-size: .94rem; }
p  { margin: 0 0 .8em; }
a  { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .88em; }
small { font-size: .82rem; }

.muted     { color: var(--muted); }
.secondary { color: var(--ink-2); }
.tnum      { font-variant-numeric: tabular-nums; }
.spacer    { margin-left: auto; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 5px; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 200;
  background: var(--surface); color: var(--ink); padding: .6rem 1rem;
  border: 1px solid var(--border); border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

/* ---------------------------------------------------------------- shell */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}
:root[data-rail="1"] .app { grid-template-columns: var(--rail-w) minmax(0, 1fr); }

.sidebar {
  position: sticky; top: 0; align-self: start;
  height: 100vh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.sidebar-head {
  display: flex; align-items: center; gap: .4rem;
  padding: .85rem .8rem .7rem .9rem;
  border-bottom: 1px solid var(--border-2);
}

.brand { display: flex; align-items: center; gap: .6rem; min-width: 0; flex: 1; }
.brand:hover { text-decoration: none; }

.brand-mark {
  display: grid; place-items: center;
  width: 32px; height: 32px; flex: none;
  background: var(--accent); color: #fff;
  border-radius: 9px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: .92rem; color: var(--ink); letter-spacing: -.01em; }
.brand-text small  { color: var(--muted); font-size: .7rem; }

.rail-toggle { flex: none; }
:root[data-rail="1"] .rail-toggle svg { transform: rotate(180deg); }

.side-nav { padding: .7rem .5rem .3rem; }

.nav-label {
  display: flex; align-items: center; gap: .3rem;
  padding: 0 .55rem .35rem;
  font-size: .68rem; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted);
}
.nav-label-count { font-weight: 500; letter-spacing: 0; text-transform: none; }

.side-nav a {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .55rem;
  margin-bottom: 1px;
  border-radius: var(--radius-sm);
  color: var(--ink-2); font-size: .875rem; font-weight: 500;
  text-decoration: none; white-space: nowrap;
}
.side-nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.side-nav a[aria-current="page"] { background: var(--accent-wash); color: var(--accent-ink); font-weight: 600; }
.side-nav a[aria-current="page"] .nav-ico { color: var(--accent); }
.nav-ico { flex: none; opacity: .85; }
.nav-badge {
  margin-left: auto; flex: none;
  min-width: 20px; padding: 0 .3rem;
  font-size: .7rem; font-weight: 700; text-align: center;
  border-radius: 999px;
  background: var(--warn); color: #0b0b0b;
  font-variant-numeric: tabular-nums;
}
.nav-badge:empty { display: none; }

.side-subjects {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  padding: .5rem .5rem 0;
  border-top: 1px solid var(--border-2);
  margin-top: .5rem;
}
.side-subject-list { overflow-y: auto; padding-bottom: .5rem; }
.side-subject-list::-webkit-scrollbar { width: 6px; }
.side-subject-list::-webkit-scrollbar-thumb { background: var(--grid); border-radius: 3px; }

.side-subject {
  display: block; width: 100%;
  padding: .38rem .55rem;
  border: 0; background: none; border-radius: var(--radius-sm);
  color: var(--ink-2); font: inherit; text-align: left; cursor: pointer;
}
.side-subject:hover { background: var(--surface-2); }
.side-subject[aria-current="page"] { background: var(--accent-wash); }
.side-subject-top { display: flex; align-items: baseline; gap: .4rem; font-size: .78rem; }
.side-subject-code { font-weight: 700; letter-spacing: .02em; color: var(--ink); }
.side-subject-pct { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); }
.side-subject .bar-track { display: block; height: 4px; margin-top: .25rem; border-radius: 0 2px 2px 0; }
.side-subject .bar-fill  { display: block; height: 100%; border-radius: 0 2px 2px 0; }

.sidebar-foot {
  padding: .6rem .9rem .8rem;
  border-top: 1px solid var(--border-2);
  font-size: .76rem; color: var(--muted);
}
.foot-row { display: flex; align-items: center; gap: .4rem; }
.foot-row strong { color: var(--ink); font-variant-numeric: tabular-nums; }

/* Rail (collapsed) mode — icons only */
:root[data-rail="1"] .brand-text,
:root[data-rail="1"] .nav-text,
:root[data-rail="1"] .nav-label,
:root[data-rail="1"] .side-subjects,
:root[data-rail="1"] .sidebar-foot { display: none; }
:root[data-rail="1"] .side-nav a { justify-content: center; padding: .55rem 0; }
:root[data-rail="1"] .sidebar-head { justify-content: center; padding: .85rem .4rem .7rem; }
:root[data-rail="1"] .brand { flex: none; }
:root[data-rail="1"] .nav-badge {
  position: absolute; margin: 0; min-width: 8px; height: 8px; padding: 0;
  transform: translate(10px, -10px); font-size: 0;
}
:root[data-rail="1"] .side-nav a { position: relative; }

.sidebar-scrim {
  position: fixed; inset: 0; z-index: 39;
  background: rgba(11, 11, 11, .5);
}
.sidebar-scrim[hidden] { display: none; }

/* ---------------------------------------------------------------- topbar */

.content { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: .9rem;
  padding: .7rem 1.25rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
@supports not (backdrop-filter: blur(4px)) {
  .topbar { background: var(--surface); }
}

.nav-toggle { display: none; }

.page-head { min-width: 0; flex: 1; }
.page-head h1 { margin: 0; font-size: 1.05rem; letter-spacing: -.01em; }
.page-sub { margin: 0; font-size: .78rem; color: var(--muted); }
.page-sub:empty { display: none; }

.topbar-tools { display: flex; align-items: center; gap: .5rem; flex: none; }

.search-wrap { position: relative; display: flex; align-items: center; }
.search-ico { position: absolute; left: .6rem; color: var(--muted); pointer-events: none; }

#search {
  width: 210px; max-width: 40vw;
  padding: .45rem .7rem .45rem 1.9rem;
  font: inherit; font-size: .85rem;
  color: var(--ink); background: var(--page);
  border: 1px solid var(--border); border-radius: 999px;
}
#search::placeholder { color: var(--muted); }
#search:focus { background: var(--surface); }

.search-results {
  position: absolute; top: calc(100% + .45rem); right: 0;
  width: min(430px, 88vw); max-height: 62vh; overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); z-index: 40;
}
.search-results button {
  display: block; width: 100%; text-align: left;
  padding: .55rem .8rem;
  background: none; border: 0; border-bottom: 1px solid var(--border-2);
  color: var(--ink); font: inherit; font-size: .86rem; cursor: pointer;
}
.search-results button:last-child { border-bottom: 0; }
.search-results button:hover, .search-results button:focus { background: var(--accent-wash); }
.search-results .sr-sub { display: block; color: var(--muted); font-size: .76rem; }

.icon-btn {
  display: grid; place-items: center;
  width: 32px; height: 32px; flex: none;
  background: transparent; color: var(--ink-2);
  border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* Inline SVG rather than a ☾ / ☀ glyph, which is missing from plenty of
   system font stacks and falls back to a tofu box. */
.ico-sun { display: none; }
:root[data-theme="dark"] .ico-sun  { display: block; }
:root[data-theme="dark"] .ico-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .ico-sun  { display: block; }
  :root:where(:not([data-theme="light"])) .ico-moon { display: none; }
}

/* ------------------------------------------------------------------ main */

.main { padding: 1.15rem 1.25rem 3rem; width: 100%; max-width: 1500px; margin: 0 auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-tight { padding: .85rem .9rem; }

.card-head {
  display: flex; align-items: center; gap: .6rem;
  margin-bottom: .85rem; flex-wrap: wrap;
}
.card-head h2, .card-head h3 { margin: 0; }
.card-sub { font-size: .78rem; color: var(--muted); }

.grid { display: grid; gap: 1rem; margin-bottom: 1rem; }
.grid-2  { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3  { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
/* Explicit column counts, so a set of N cards never leaves a lone card
   stranded beside empty columns. */
/* Analytic cards size to their content; uniform card grids keep stretching. */
.grid-2-up, .grid-3-up, .grid-2-1 { align-items: start; }
.grid-2-up { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3-up { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1240px) { .grid-3-up { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 820px)  {
  .grid-2-up, .grid-3-up { grid-template-columns: minmax(0, 1fr); }
}
.grid > .card { margin-bottom: 0; }

@media (max-width: 1080px) {
  .grid-2-1 { grid-template-columns: minmax(0, 1fr); }
}

.error-card { border-color: var(--critical); }
.empty { padding: 1.5rem 1rem; text-align: center; color: var(--muted); font-size: .9rem; }

/* Refetch: hold the previous render, dimmed — never a skeleton flash. */
.is-stale { opacity: .45; transition: opacity .15s ease; pointer-events: none; }

/* --------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .48rem .85rem;
  font: inherit; font-size: .85rem; font-weight: 500;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.07); }
.btn-danger { color: var(--critical); border-color: var(--critical); }
.btn-sm { padding: .28rem .55rem; font-size: .78rem; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; }

.segmented {
  display: inline-flex; gap: 2px; padding: 2px; flex: none;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px;
}
.segmented button {
  padding: .28rem .6rem;
  font: inherit; font-size: .78rem; font-weight: 500;
  color: var(--ink-2); background: none; border: 0; border-radius: 7px;
  cursor: pointer;
}
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"] {
  background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-sm);
}

/* One filter row above everything it scopes — never inside a chart card. */
.filter-row {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  margin-bottom: 1rem;
}
.filter-row .filter-label { font-size: .8rem; color: var(--muted); }

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  font: inherit; font-size: .88rem;
  color: var(--ink); background: var(--page);
  border: 1px solid var(--border); border-radius: 8px;
  padding: .48rem .6rem; width: 100%;
}
textarea { resize: vertical; min-height: 84px; line-height: 1.55; }
label.field { display: block; margin-bottom: .8rem; }
label.field > span { display: block; font-size: .8rem; color: var(--ink-2); margin-bottom: .3rem; }
.field-row { display: flex; gap: .6rem; flex-wrap: wrap; }
.field-row > label.field { flex: 1 1 160px; }

/* -------------------------------------------------------- first-run screen */

.welcome { background: linear-gradient(180deg, var(--accent-wash), transparent); }

.steps { margin: 0; padding-left: 1.35rem; }
.steps li { margin-bottom: .9rem; font-size: .87rem; color: var(--ink-2); }
.steps li:last-child { margin-bottom: 0; }
.steps li strong { color: var(--ink); }
.steps li::marker { color: var(--accent); font-weight: 700; }

.subject-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.subject-chip {
  display: flex; flex-direction: column; align-items: flex-start; gap: .05rem;
  padding: .4rem .6rem;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; cursor: pointer;
}
.subject-chip:hover { border-color: var(--accent); background: var(--accent-wash); }
.subject-chip strong { font-size: .8rem; letter-spacing: .02em; }
.subject-chip span   { font-size: .7rem; color: var(--muted); }

/* ----------------------------------------------------------- KPI figures */

.kpis { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); margin-bottom: 1rem; }

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .8rem .85rem;
}
.kpi-label { display: flex; align-items: center; gap: .3rem; font-size: .76rem; color: var(--ink-2); margin-bottom: .3rem; }
.kpi-value { font-size: 1.6rem; font-weight: 620; line-height: 1.05; letter-spacing: -.02em; }
.kpi-unit  { font-size: .95rem; font-weight: 600; color: var(--ink-2); }
.kpi-foot  { display: flex; align-items: baseline; gap: .4rem; margin-top: .25rem; font-size: .74rem; color: var(--muted); }
.delta { font-weight: 700; font-variant-numeric: tabular-nums; }
.delta.up   { color: var(--good-text); }
.delta.flat { color: var(--muted); }

/* Hero figure — exactly one per view, proportional figures, system sans */
.hero { display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap; }
.hero-figure { display: flex; align-items: baseline; gap: .3rem; }
.hero-value { font-size: 2.9rem; font-weight: 650; letter-spacing: -.025em; line-height: 1; }
.hero-unit  { font-size: 1.2rem; font-weight: 600; color: var(--ink-2); }
.hero-label { color: var(--ink-2); font-size: .86rem; }
.hero-ring  { flex: none; }

/* ------------------------------------------------------- bars & meters */

.bar-track {
  position: relative; height: 10px;
  background: var(--surface-2);
  border-radius: 0 4px 4px 0;
  overflow: hidden;
}
.bar-fill {
  height: 100%; background: var(--accent);
  border-radius: 0 4px 4px 0; min-width: 3px;
}
/* At zero there is no data-end to round, and a 3px stub reads as a rendering
   artefact rather than a value — so draw nothing. */
.bar-fill.is-empty { min-width: 0; }
.bar-fill.is-good     { background: var(--good); }
.bar-fill.is-warn     { background: var(--warn); }
.bar-fill.is-critical { background: var(--critical); }
/* Emphasis form: the series that matters keeps the accent, the rest recede. */
.bar-fill.is-muted    { background: var(--axis); }

.bar-row {
  display: grid;
  grid-template-columns: minmax(8rem, 15rem) minmax(0, 1fr) auto;
  align-items: center; gap: .7rem;
  padding: .28rem 0;
}
.bar-row + .bar-row { border-top: 1px solid var(--border-2); }
.bar-row .bar-name { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar-name a { color: var(--ink); }
.bar-row .bar-name button {
  background: none; border: 0; padding: 0; font: inherit; color: var(--ink);
  cursor: pointer; text-align: left; width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bar-row .bar-name button:hover { color: var(--accent); }
.bar-row .bar-value {
  font-size: .8rem; font-variant-numeric: tabular-nums;
  color: var(--ink-2); min-width: 4.2rem; text-align: right;
}

/* In a narrow card the label eats the track, so stack the bar under it. */
.bar-compact .bar-row {
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "name value" "bar bar";
  gap: .2rem .6rem; padding: .35rem 0;
}
.bar-compact .bar-row .bar-name  { grid-area: name; }
.bar-compact .bar-row .bar-value { grid-area: value; min-width: 0; }
.bar-compact .bar-row .bar-track { grid-area: bar; }
.bar-compact .bar-row + .bar-row { border-top: 0; }

/* Stacked status bar — 2px surface gaps, no strokes */
.stack {
  display: flex; gap: 2px; height: 13px;
  background: var(--surface); border-radius: 4px; overflow: hidden;
}
.stack-sm { height: 8px; }
.stack-seg { height: 100%; min-width: 0; }
.stack-seg:first-child { border-radius: 4px 0 0 4px; }
.stack-seg:last-child  { border-radius: 0 4px 4px 0; }
.stack-seg.st-not      { background: var(--st-not); }
.stack-seg.st-learning { background: var(--st-learning); }
.stack-seg.st-done     { background: var(--st-done); }
.stack-seg.st-revise   { background: var(--st-revise); }
.stack-seg.st-perfect  { background: var(--st-perfect); }

.legend {
  display: flex; flex-wrap: wrap; gap: .3rem .9rem;
  margin-top: .65rem; font-size: .8rem; color: var(--ink-2);
}
.legend-item { display: inline-flex; align-items: center; gap: .35rem; }
.legend-swatch { width: 10px; height: 10px; flex: none; border-radius: 3px; box-shadow: 0 0 0 2px var(--surface); }
.legend-line { width: 14px; height: 2px; flex: none; border-radius: 1px; }
.legend-count { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }

/* ---------------------------------------------------------------- charts */

/* Four children in a 2x2 grid: y-axis + plot, then a spacer + x-axis. That
   keeps the y labels the exact height of the plot while the x labels stay
   aligned to it, and the card grows to include the axis band (no nested
   scrollbar). */
.chart-body {
  display: grid; grid-template-columns: auto minmax(0, 1fr);
  column-gap: .45rem; row-gap: 0;
}
.chart-yaxis {
  display: flex; flex-direction: column; justify-content: space-between;
  font-size: .7rem; color: var(--muted); text-align: right;
  font-variant-numeric: tabular-nums;
  padding-bottom: 0;
}
.chart-plot { position: relative; height: 172px; }
.chart-plot.is-short { height: 128px; }

.chart-grid { position: absolute; inset: 0; pointer-events: none; }
.chart-grid i { position: absolute; left: 0; right: 0; height: 1px; background: var(--grid); }
.chart-grid i:last-child { background: var(--axis); }

.chart-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; overflow: visible; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: var(--accent); opacity: .10; stroke: none; }

.chart-zones { position: absolute; inset: 0; display: flex; }
.chart-zone { flex: 1 1 0; min-width: 0; border: 0; background: none; padding: 0; cursor: default; }
.chart-zone:hover, .chart-zone:focus-visible { background: var(--accent-wash); outline: none; }

.chart-dot {
  position: absolute; width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px var(--surface);
  transform: translate(-50%, -50%); pointer-events: none;
}
.chart-endlabel {
  position: absolute; transform: translate(-50%, -175%);
  font-size: .74rem; font-weight: 700; color: var(--ink);
  background: var(--surface); padding: 0 .2rem; border-radius: 3px;
  white-space: nowrap; pointer-events: none;
}
.chart-xaxis {
  display: flex; justify-content: space-between;
  font-size: .7rem; color: var(--muted); margin-top: .4rem;
}
.chart-note { margin: .6rem 0 0; font-size: .76rem; color: var(--muted); }

/* Columns — 24px cap, 4px rounded data-end, full-height hit zone */
.cols { display: flex; align-items: stretch; gap: 2px; height: 150px; }
.cols.is-short { height: 108px; }
.col-zone {
  flex: 1 1 0; min-width: 0;
  display: flex; align-items: flex-end; justify-content: center;
  border: 0; background: none; padding: 0; cursor: default;
}
.col-zone:hover, .col-zone:focus-visible { background: var(--accent-wash); outline: none; }
.col-bar {
  width: 100%; max-width: 24px;
  border-radius: 4px 4px 0 0;
  background: var(--accent-soft);
  min-height: 2px;
}
.col-bar.is-accent   { background: var(--accent); }
.col-bar.is-zero     { background: var(--grid); }
.col-bar.is-warn     { background: var(--warn); }
.cols-axis { display: flex; justify-content: space-between; font-size: .7rem; color: var(--muted); margin-top: .4rem; }

.chart-tip {
  position: fixed; z-index: 90;
  background: var(--ink); color: var(--page);
  padding: .35rem .55rem; border-radius: 6px;
  font-size: .77rem; line-height: 1.35;
  pointer-events: none; white-space: nowrap;
  box-shadow: var(--shadow);
}

/* Table-view twin, so no value is reachable only via a tooltip */
.table-toggle { font-size: .76rem; }
.chart-table { margin-top: .7rem; max-height: 230px; overflow-y: auto; }
.chart-table[hidden] { display: none; }

/* --------------------------------------------------------------- chips */

.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .14rem .48rem;
  font-size: .73rem; font-weight: 600;
  border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2);
  border: 1px solid var(--border); white-space: nowrap;
}
.chip-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.chip.st-not      .chip-dot { background: var(--st-not); }
.chip.st-learning .chip-dot { background: var(--st-learning); }
.chip.st-done     .chip-dot { background: var(--st-done); }
.chip.st-revise   .chip-dot { background: var(--st-revise); }
.chip.st-perfect  .chip-dot { background: var(--st-perfect); }
.chip-hy  { border-color: var(--warn); }
.chip-due { border-color: var(--warn); color: var(--ink); background: rgba(250, 178, 25, .16); }

.hy-dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--warn); flex: none; box-shadow: 0 0 0 2px var(--surface);
  vertical-align: middle;
}

.scope-grid { display: grid; gap: .55rem; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); }
.scope-btn {
  /* Buttons vertically centre their content by default, which misaligns the
     codes across a row of stretched cards — pin the content to the top. */
  display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-start;
  text-align: left; padding: .6rem .7rem;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; font: inherit;
}
.scope-btn:hover { background: var(--surface-2); border-color: var(--accent); }
.scope-btn strong { display: block; font-size: .86rem; }
.scope-btn span   { font-size: .76rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.scope-btn:disabled { opacity: .45; cursor: not-allowed; }

/* --------------------------------------------------------------- lists */

.subject-card { cursor: pointer; }
.subject-card:hover { border-color: var(--accent); }
.subject-top { display: flex; align-items: baseline; gap: .5rem; margin-bottom: .5rem; }
.subject-code {
  font-size: .68rem; font-weight: 700; letter-spacing: .04em;
  color: var(--ink-2); background: var(--surface-2);
  padding: .1rem .35rem; border-radius: 4px; flex: none;
}
.subject-name { font-size: .92rem; font-weight: 600; }
.subject-pct  { margin-left: auto; font-size: .95rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.subject-meta { display: flex; gap: .8rem; flex-wrap: wrap; margin-top: .5rem; font-size: .76rem; color: var(--muted); }

.topic-list { border-top: 1px solid var(--border-2); }
.topic-row {
  display: flex; align-items: center; gap: .6rem;
  width: 100%; padding: .55rem .2rem;
  background: none; border: 0; border-bottom: 1px solid var(--border-2);
  color: var(--ink); font: inherit; text-align: left; cursor: pointer;
}
.topic-row:hover { background: var(--accent-wash); }
.topic-row .t-name { flex: 1 1 auto; min-width: 0; font-size: .86rem; }
.topic-row .t-meta { display: flex; align-items: center; gap: .4rem; flex: none; }
.topic-qcount { font-size: .74rem; color: var(--muted); font-variant-numeric: tabular-nums; }

table.tbl { width: 100%; border-collapse: collapse; font-size: .84rem; }
table.tbl th, table.tbl td { padding: .42rem .5rem; text-align: left; border-bottom: 1px solid var(--border-2); }
table.tbl th {
  color: var(--ink-2); font-weight: 600; font-size: .77rem;
  position: sticky; top: 0; background: var(--surface);
}
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
/* A row of outlined buttons reads as noise in a dense table — link styling. */
.link-btn {
  background: none; border: 0; padding: 0; font: inherit;
  color: var(--ink); text-align: left; cursor: pointer;
}
.link-btn:hover { color: var(--accent); text-decoration: underline; }
.tbl-wrap { overflow-x: auto; }

/* -------------------------------------------------------- topic sheet */

.sheet[hidden] { display: none; }
.sheet { position: fixed; inset: 0; z-index: 70; display: flex; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(11, 11, 11, .45); }
.sheet-panel {
  position: relative; margin-left: auto;
  width: min(640px, 100%); height: 100%; overflow-y: auto;
  background: var(--surface); border-left: 1px solid var(--border);
  padding: 1.1rem 1.15rem 3rem; box-shadow: var(--shadow);
}
.sheet-close { position: absolute; top: .8rem; right: .9rem; }

.status-picker { display: flex; flex-wrap: wrap; gap: .4rem; }
.status-btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .4rem .68rem;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 999px;
  font: inherit; font-size: .82rem; cursor: pointer;
}
.status-btn:hover { background: var(--surface-2); }
.status-btn[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-wash); font-weight: 600; }
.status-btn .chip-dot { width: 9px; height: 9px; }

.slider-row { display: flex; align-items: center; gap: .7rem; }
input[type="range"] { flex: 1; accent-color: var(--accent); }
.slider-val { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 3rem; text-align: right; }

.notes-block { margin-top: 1rem; }
.ai-notes h4 { margin: .85rem 0 .3rem; font-size: .82rem; color: var(--ink-2); }
.ai-notes ul { margin: 0; padding-left: 1.1rem; }
.ai-notes li { margin-bottom: .28rem; font-size: .85rem; }

.qbank { margin-top: .6rem; }
.qbank-item {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .6rem .7rem; margin-bottom: .5rem; background: var(--page);
}
.qbank-stem { font-size: .86rem; font-weight: 500; margin-bottom: .35rem; }
.qbank-opts { list-style: none; margin: 0 0 .4rem; padding: 0; font-size: .82rem; }
.qbank-opts li { padding: .08rem 0; color: var(--ink-2); }
.qbank-opts li.is-answer { color: var(--ink); font-weight: 600; }
.qbank-opts li.is-answer::after { content: " ✓"; color: var(--good-text); }
.qbank-expl { font-size: .8rem; color: var(--ink-2); border-top: 1px solid var(--border-2); padding-top: .35rem; }
.qbank-foot { display: flex; align-items: center; gap: .45rem; margin-top: .4rem; font-size: .74rem; color: var(--muted); flex-wrap: wrap; }

/* --------------------------------------------------------------- quiz */

.quiz-head { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin-bottom: .9rem; }
.quiz-progress { flex: 1 1 160px; }
.quiz-counter { font-size: .82rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.quiz-timer {
  font-variant-numeric: tabular-nums; font-weight: 700;
  padding: .22rem .55rem; border-radius: 8px;
  background: var(--surface-2); font-size: .88rem;
}
.quiz-timer.is-low { background: rgba(208, 59, 59, .14); color: var(--critical); }

.q-stem { font-size: 1rem; line-height: 1.5; margin-bottom: .9rem; }

.options { display: grid; gap: .5rem; }
.option {
  display: flex; align-items: flex-start; gap: .6rem;
  width: 100%; padding: .62rem .72rem;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; font-size: .9rem; text-align: left; cursor: pointer;
}
.option:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-wash); }
.option:disabled { cursor: default; }
.option .opt-key {
  display: grid; place-items: center; flex: none;
  width: 21px; height: 21px; border-radius: 6px;
  background: var(--surface-2); color: var(--ink-2);
  font-size: .76rem; font-weight: 700;
}
.option[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-wash); }
.option[aria-pressed="true"] .opt-key { background: var(--accent); color: #fff; }
.option.is-correct { border-color: var(--good); background: rgba(12, 163, 12, .10); }
.option.is-correct .opt-key { background: var(--good); color: #fff; }
.option.is-wrong { border-color: var(--critical); background: rgba(208, 59, 59, .10); }
.option.is-wrong .opt-key { background: var(--critical); color: #fff; }

.verdict {
  margin-top: .9rem; padding: .7rem .8rem;
  border-radius: var(--radius-sm); background: var(--page); border: 1px solid var(--border);
}
.verdict-head { font-weight: 650; font-size: .88rem; margin-bottom: .3rem; }
.verdict-head.ok  { color: var(--good-text); }
.verdict-head.bad { color: var(--critical); }
.verdict p { margin: 0; font-size: .86rem; color: var(--ink-2); }

.quiz-foot { display: flex; gap: .5rem; align-items: center; margin-top: 1rem; flex-wrap: wrap; }

/* --------------------------------------------------------------- jobs */

.jobs-dock {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 60;
  width: min(330px, calc(100vw - 2rem));
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: .7rem .8rem; font-size: .83rem;
}
.jobs-dock h4 { margin: 0 0 .4rem; font-size: .8rem; color: var(--ink-2); }
.job-line { display: flex; align-items: center; gap: .45rem; padding: .18rem 0; }
.job-line .job-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-state { font-size: .73rem; font-weight: 600; }
.job-state.queued  { color: var(--muted); }
.job-state.running { color: var(--accent); }
.job-state.done    { color: var(--good-text); }
.job-state.failed  { color: var(--critical); }

.spinner {
  width: 11px; height: 11px; flex: none;
  border: 2px solid var(--grid); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

.toast {
  position: fixed; left: 50%; bottom: 1.4rem; transform: translateX(-50%);
  z-index: 95; max-width: min(540px, calc(100vw - 2rem));
  background: var(--ink); color: var(--page);
  padding: .6rem .9rem; border-radius: 9px;
  font-size: .86rem; box-shadow: var(--shadow);
}
.toast.is-error { background: var(--critical); color: #fff; }

/* --------------------------------------------------------------- mobile */

.mobile-tabs { display: none; }

@media (max-width: 1000px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  :root[data-rail="1"] .app { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 40;
    width: min(285px, 84vw); height: 100vh;
    transform: translateX(-102%);
    transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.is-open { transform: none; }
  /* Rail mode is a desktop affordance only. */
  :root[data-rail="1"] .brand-text,
  :root[data-rail="1"] .nav-text,
  :root[data-rail="1"] .nav-label,
  :root[data-rail="1"] .side-subjects,
  :root[data-rail="1"] .sidebar-foot { display: revert; }
  :root[data-rail="1"] .side-nav a { justify-content: flex-start; padding: .5rem .55rem; }
  :root[data-rail="1"] .sidebar-head { justify-content: space-between; padding: .85rem .8rem .7rem .9rem; }
  :root[data-rail="1"] .nav-badge { position: static; transform: none; min-width: 20px; height: auto; padding: 0 .3rem; font-size: .7rem; }
  .rail-toggle { display: none; }

  .nav-toggle { display: grid; }
  .topbar { padding: .6rem .85rem; }
  #search { width: 44px; padding-left: 1.9rem; padding-right: .4rem; transition: width .15s ease; }
  #search:focus { width: min(230px, 46vw); }
  .main { padding: .9rem .85rem 5.5rem; }

  .mobile-tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    display: flex; justify-content: space-between;
    padding: .28rem .3rem calc(.28rem + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .mobile-tabs a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: .1rem;
    padding: .3rem .2rem; border-radius: 8px;
    color: var(--muted); font-size: .63rem; font-weight: 500; text-decoration: none;
  }
  .mobile-tabs a[aria-current="page"] { color: var(--accent); background: var(--accent-wash); }

  .bar-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "name value" "bar bar"; gap: .2rem .6rem; }
  .bar-row .bar-name  { grid-area: name; }
  .bar-row .bar-value { grid-area: value; }
  .bar-row .bar-track { grid-area: bar; }

  .sheet-panel { width: 100%; border-left: 0; }
  .hero-value { font-size: 2.5rem; }
  .jobs-dock { left: .85rem; right: .85rem; bottom: 4.4rem; width: auto; }
  .toast { bottom: 4.6rem; }
  .chart-plot { height: 150px; }
}

@media print {
  .sidebar, .topbar, .mobile-tabs, .jobs-dock, .toast, .sheet, .sidebar-scrim { display: none !important; }
  .app { grid-template-columns: 1fr; }
  body { background: #fff; color: #000; }
  .card { break-inside: avoid; border-color: #999; }
  .chart-table[hidden] { display: block !important; }
}

/* ------------------------------------------------------- ratings & plan */

/* Importance is ordinal, so it gets an ordinal meter rather than a status
   colour — amber stays reserved for "due". */
.imp { display: inline-flex; align-items: flex-end; gap: 1.5px; height: 11px; flex: none; vertical-align: middle; }
.imp i { width: 3px; background: var(--grid); border-radius: 1px; display: block; }
.imp i:nth-child(1) { height: 5px; }
.imp i:nth-child(2) { height: 8px; }
.imp i:nth-child(3) { height: 11px; }
.imp i.on { background: var(--accent-soft); }
.imp-3 i.on { background: var(--accent); }

.chip-diff { font-weight: 500; border-color: var(--border-2); background: transparent; }
.diff-3 { color: var(--ink); border-color: var(--axis); font-weight: 600; }
.chip-planned { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-wash); }

.targets { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.target-top { display: flex; align-items: baseline; gap: .5rem; font-size: .8rem; color: var(--ink-2); margin-bottom: .3rem; }
.target-top strong { margin-left: auto; color: var(--ink); font-size: .92rem; }
.target-sub { font-size: .72rem; color: var(--muted); margin-top: .25rem; }
.target .bar-track { height: 8px; }

.plan-list { border-top: 1px solid var(--border-2); }
.plan-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .1rem; border-bottom: 1px solid var(--border-2);
}
.plan-item.is-done .plan-name { text-decoration: line-through; color: var(--muted); }

.plan-check {
  width: 20px; height: 20px; flex: none;
  display: grid; place-items: center;
  border: 1.5px solid var(--axis); border-radius: 5px;
  background: none; color: #fff; cursor: pointer;
}
.plan-check[aria-pressed="true"] { background: var(--good); border-color: var(--good); }

.plan-main {
  flex: 1 1 auto; min-width: 0; text-align: left;
  background: none; border: 0; padding: 0; font: inherit; color: var(--ink); cursor: pointer;
}
.plan-main:hover .plan-name { color: var(--accent); }
.plan-name { display: block; font-size: .87rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-meta { display: block; font-size: .73rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-tags { display: flex; align-items: center; gap: .35rem; flex: none; flex-wrap: wrap; justify-content: flex-end; }
.plan-remove { width: 26px; height: 26px; flex: none; border-color: transparent; }
.plan-item:hover .plan-remove { border-color: var(--border); }

@media (max-width: 720px) {
  .plan-item { flex-wrap: wrap; }
  .plan-main { flex: 1 1 100%; order: 2; padding-left: 1.7rem; margin-top: -1.4rem; }
  .plan-tags { order: 3; flex: 1 1 100%; justify-content: flex-start; padding-left: 1.7rem; margin-top: .3rem; }
  .plan-check { order: 1; }
  .plan-remove { order: 1; margin-left: auto; }
  /* Seven destinations need a little more room per label. */
  .mobile-tabs a { font-size: .58rem; padding: .3rem .1rem; }
}

.rating-key {
  display: flex; align-items: center; gap: .5rem 1rem; flex-wrap: wrap;
  padding: 0 0 .6rem; font-size: .74rem; color: var(--muted);
}
.rating-key .legend-item { gap: .3rem; }
.rating-key .chip { font-size: .68rem; padding: .05rem .35rem; }
.rating-key-sep { opacity: .5; }
