/* ---------- Tokens (light) ---------- */
:root {
  color-scheme: light;
  --page: #f5f5f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);

  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-wash: #e6f0fc;

  /* categorical slots (validated reference palette) */
  --s1: #2a78d6; /* blue   */
  --s2: #eb6834; /* orange */
  --s3: #1baf7a; /* aqua   */
  --s7: #4a3aa7; /* violet */
  --neutral-mark: #c3c2b7;

  /* sequential blue for the activity heatmap */
  --seq-0: #ecebe6;
  --seq-1: #b7d3f6;
  --seq-2: #6da7ec;
  --seq-3: #2a78d6;
  --seq-4: #184f95;

  --good: #006300;
  --bad: #d03b3b;
  --warn-bg: #fdf5ea;
  --warn-line: #e6cfa8;

  --radius: 14px;
  --radius-sm: 9px;
  font-family: 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: #232322;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --shadow: none;
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --accent-wash: #16263a;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s7: #9085e9;
    --neutral-mark: #52514e;
    --seq-0: #262625;
    --seq-1: #184f95;
    --seq-2: #256abf;
    --seq-3: #3987e5;
    --seq-4: #86b6ef;
    --good: #0ca30c;
    --bad: #e66767;
    --warn-bg: #2a2418;
    --warn-line: #5c4a26;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --shadow: none;
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --accent-wash: #16263a;
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s7: #9085e9;
  --neutral-mark: #52514e;
  --seq-0: #262625;
  --seq-1: #184f95;
  --seq-2: #256abf;
  --seq-3: #3987e5;
  --seq-4: #86b6ef;
  --good: #0ca30c;
  --bad: #e66767;
  --warn-bg: #2a2418;
  --warn-line: #5c4a26;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 26px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 17px; font-weight: 620; }
h3 { font-size: 14px; font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { display: block; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sub { color: var(--text-2); }
.row { display: flex; align-items: center; }
.gap { gap: 10px; }
.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }

.container { max-width: 1180px; margin: 0 auto; padding: 24px 20px 64px; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--page) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; white-space: nowrap; }
.brand-mark svg { width: 28px; height: 28px; }
.brand-mark rect { fill: var(--accent); }
.brand-mark path { fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.brand-text { font-size: 16px; font-weight: 500; }
.brand-text b { font-weight: 700; }
.tabs { display: flex; gap: 4px; margin: 0 auto; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.tabs a {
  text-decoration: none; padding: 7px 14px; border-radius: 9px;
  font-size: 14px; font-weight: 520; color: var(--text-2); white-space: nowrap;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow), 0 0 0 1px var(--border); }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px;
  background: transparent; border: 1px solid transparent; border-radius: 10px; cursor: pointer; color: var(--text-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .tabs a { flex: 1; text-align: center; padding: 7px 8px; font-size: 13px; }
  .topbar-actions { margin-left: auto; }
  .container { padding: 18px 14px 56px; }
}

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 6px 0 0; color: var(--text-2); }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.stack > *, .layout > *, .home-grid > * { min-width: 0; }

.layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; align-items: start; }
.layout > .form-card { position: sticky; top: 76px; }
@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .layout > .form-card { position: static; }
}

/* ---------- Home ---------- */
.hero-strip { display: flex; gap: 16px; align-items: stretch; margin-bottom: 16px; flex-wrap: wrap; }
.countdown { display: flex; align-items: center; gap: 14px; padding: 14px 18px; }
.countdown .big { font-size: 34px; font-weight: 650; line-height: 1; }
.modules { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
@media (max-width: 900px) { .modules { grid-template-columns: 1fr; } }
.module-card {
  display: flex; flex-direction: column; gap: 14px; text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  position: relative; overflow: hidden; min-height: 230px;
}
.module-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--mc);
}
.module-card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--mc) 45%, var(--border)); }
.module-card .mc-top { display: flex; align-items: center; gap: 12px; }
.mc-icon { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; background: color-mix(in srgb, var(--mc) 14%, transparent); }
.mc-icon svg { width: 21px; height: 21px; fill: none; stroke: var(--mc); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mc-title { font-size: 17px; font-weight: 640; }
.mc-desc { font-size: 13px; color: var(--muted); }
.mc-hero { font-size: 44px; font-weight: 680; line-height: 1; letter-spacing: -0.02em; }
.mc-hero small { font-size: 14px; font-weight: 500; color: var(--text-2); letter-spacing: 0; margin-left: 6px; }
.mc-stats { display: flex; gap: 18px; font-size: 13px; color: var(--text-2); margin-top: auto; flex-wrap: wrap; }
.mc-stats b { color: var(--text); font-weight: 620; }
.mc-cta { font-size: 13px; font-weight: 600; color: var(--accent-ink); }
.mc-spark { height: 36px; }

/* ---------- Stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px; box-shadow: var(--shadow); }
.tile-label { font-size: 12.5px; color: var(--text-2); }
.tile-value { font-size: 26px; font-weight: 650; margin-top: 4px; line-height: 1.1; }
.tile-value small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.tile-delta { font-size: 12.5px; margin-top: 4px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.tile-delta.up { color: var(--good); }
.tile-delta.down { color: var(--bad); }
.tile.hero-tile { background: var(--accent-wash); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.tile.hero-tile .tile-value { font-size: 48px; font-weight: 700; letter-spacing: -0.02em; }

/* ---------- Forms ---------- */
.form { display: grid; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.field { display: grid; gap: 5px; font-size: 12.5px; color: var(--text-2); font-weight: 520; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--page);
  font-size: 15px; font-weight: 450; color: var(--text); outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.field textarea { resize: vertical; min-height: 60px; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.field input[type="number"] { font-variant-numeric: tabular-nums; }
.field.c-correct input { border-left: 3px solid var(--s1); }
.field.c-incorrect input { border-left: 3px solid var(--s2); }
.hint { font-size: 12.5px; color: var(--muted); margin: 0; }
.preview {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  background: var(--surface-2); border-radius: 10px; padding: 10px;
}
.preview div { text-align: center; }
.preview span { display: block; font-size: 11.5px; color: var(--muted); }
.preview b { font-size: 16px; font-weight: 640; font-variant-numeric: tabular-nums; }
.form-error { color: var(--bad); font-size: 13px; min-height: 0; margin: 0; }
details.more summary { cursor: pointer; font-size: 13px; color: var(--text-2); font-weight: 560; list-style: none; }
details.more summary::before { content: "+ "; }
details.more[open] summary::before { content: "− "; }
details.more .form { margin-top: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-size: 14px; font-weight: 580; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
:root[data-theme="dark"] .btn-primary:hover { color: #0b0b0b; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.file-btn { position: relative; }

/* ---------- Segmented controls (filter row) ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 8px;
  font-size: 13px; font-weight: 560; color: var(--text-2); cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--border); }
.select-sm { padding: 7px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-size: 13px; }

/* ---------- Charts ---------- */
.chart { position: relative; width: 100%; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 8px; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .end-label { fill: var(--text); font-size: 12px; font-weight: 620; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .col:hover, .chart .col.hot { opacity: 0.82; }
.empty {
  display: grid; place-items: center; text-align: center; gap: 6px;
  color: var(--muted); font-size: 14px; padding: 36px 12px;
  border: 1px dashed var(--grid); border-radius: 12px;
}
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key-rect { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.key-line { width: 14px; height: 2px; border-radius: 1px; display: inline-block; }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.14);
  padding: 9px 11px; font-size: 12.5px; min-width: 140px;
}
.tooltip .tt-title { color: var(--muted); font-size: 11.5px; margin-bottom: 5px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; }
.tooltip .tt-row b { font-weight: 650; font-variant-numeric: tabular-nums; min-width: 38px; }
.tooltip .tt-row span { color: var(--text-2); }

/* heatmap */
.heat-wrap { overflow-x: auto; }
.heat-legend { display: flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--muted); }
.heat-legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

/* topic bars (question bank) */
.topic-list { display: grid; gap: 2px; }
.topic-row {
  display: grid; grid-template-columns: minmax(120px, 210px) 1fr 64px 64px; gap: 12px; align-items: center;
  padding: 7px 8px; border-radius: 8px; font-size: 13.5px;
}
.topic-row:hover { background: var(--surface-2); }
.topic-row.head { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.topic-row.head:hover { background: none; }
.topic-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topic-bar { height: 12px; background: var(--surface-2); border-radius: 0 4px 4px 0; overflow: hidden; }
.topic-bar i { display: block; height: 100%; background: var(--s1); border-radius: 0 4px 4px 0; }
.topic-row .num { text-align: right; }
.topic-row.untouched { color: var(--muted); }
@media (max-width: 600px) { .topic-row { grid-template-columns: 1fr 80px 52px 52px; gap: 8px; } }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; font-size: 11.5px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em; padding: 8px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap;
}
td { padding: 9px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.title-cell { white-space: normal; min-width: 140px; font-weight: 540; }
td.actions { text-align: right; width: 1%; }
td.actions button { opacity: 0.55; }
tr:hover td.actions button { opacity: 1; }
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 560;
  background: var(--surface-2); color: var(--text-2);
}
.acc { display: inline-flex; align-items: center; gap: 8px; }
.acc-bar { width: 44px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.acc-bar i { display: block; height: 100%; background: var(--s1); }
.editing td { background: var(--accent-wash) !important; }

/* recent activity */
.recent { display: grid; gap: 2px; }
.recent-row { display: grid; grid-template-columns: 10px 1fr auto; gap: 10px; align-items: center; padding: 8px 6px; border-radius: 8px; font-size: 13.5px; }
.recent-row:hover { background: var(--surface-2); }
.recent-row .when { color: var(--muted); font-size: 12.5px; }

/* ---------- Dialog ---------- */
.dialog {
  border: 1px solid var(--border); border-radius: 16px; padding: 0; width: min(480px, calc(100vw - 24px));
  background: var(--surface); color: var(--text); box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}
.dialog::backdrop { background: rgba(10, 10, 10, 0.4); backdrop-filter: blur(2px); }
.dialog-inner { display: grid; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 6px; }
.dialog-section { padding: 12px 18px; display: grid; gap: 8px; border-bottom: 1px solid var(--grid); }
.dialog-section:last-of-type { border-bottom: 0; }
.dialog-foot { padding: 12px 18px 18px; display: flex; justify-content: flex-end; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 60; }
.toast {
  background: var(--text); color: var(--page); padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 520;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); animation: toast-in 0.18s ease-out;
}
.toast.error { background: var(--bad); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
@media (max-width: 980px) { .home-grid { grid-template-columns: minmax(0, 1fr); } }
