:root,
:root[data-theme="dark"] {
  --bg: #15130f;
  --surface: #1d1a15;
  --surface-2: #26221b;
  --line: #363027;
  --ink: #f0e9dc;
  --ink-2: #c2b9a9;
  --ink-3: #958c7d;
  --accent: #e2aa4c;
  --accent-ink: #1a1408;
  --accent-tint: rgba(226, 170, 76, 0.10);
  --ok: #67c487;
  --ok-tint: rgba(103, 196, 135, 0.12);
  --bad: #ea7466;
  --bad-tint: rgba(234, 116, 102, 0.12);
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.25), 0 8px 24px rgba(8, 6, 3, 0.35);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f6f2ea;
  --surface: #fffdf8;
  --surface-2: #efe9de;
  --line: #ddd4c4;
  --ink: #1d1a14;
  --ink-2: #474035;
  --ink-3: #686052;
  --accent: #8a5800;
  --accent-ink: #ffffff;
  --accent-tint: rgba(138, 88, 0, 0.08);
  --ok: #1d7540;
  --ok-tint: rgba(29, 117, 64, 0.09);
  --bad: #b0352a;
  --bad-tint: rgba(176, 53, 42, 0.08);
  --shadow: 0 1px 0 rgba(60, 45, 20, 0.05), 0 8px 24px rgba(60, 45, 20, 0.06);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 17px/1.65 Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button { font: inherit; color: inherit; }
h1, h2, h3, h4 { font-family: Archivo, Inter, sans-serif; line-height: 1.15; margin: 0; letter-spacing: -0.01em; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { font-family: Archivo, sans-serif; font-weight: 900; font-size: 18px; text-decoration: none; letter-spacing: -0.02em; }
.clock { margin-left: auto; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.clock b { color: var(--accent); font-weight: 700; }
.theme {
  background: none; border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 10px; font-size: 13px; color: var(--ink-2); cursor: pointer;
}

/* ---------- layout ---------- */
main { max-width: 1080px; margin: 0 auto; padding: 24px 16px 96px; }
.narrow { max-width: 760px; margin: 0 auto; }
.label {
  font-family: "Courier Prime", monospace; font-size: 13px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink-3);
  display: inline-flex; align-items: center; gap: 10px;
}
.label::before { content: ""; width: 24px; height: 1px; background: var(--accent); }
.crumb { display: inline-block; margin-bottom: 18px; font-size: 14px; color: var(--ink-2); text-decoration: none; }
.crumb:hover { color: var(--ink); }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }

/* ---------- home ---------- */
.hero { display: grid; gap: 28px; padding: 8px 0 36px; border-bottom: 1px solid var(--line); }
.hero h1 { font-size: clamp(34px, 7vw, 60px); font-weight: 900; letter-spacing: -0.03em; margin: 12px 0 16px; }
.hero h1 span { color: var(--accent); }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; display: grid; gap: 10px; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 28px 1fr; gap: 8px; color: var(--ink-2); }
.steps li::before { content: counter(s); font-family: Archivo, sans-serif; font-weight: 800; color: var(--accent); }
.steps b { color: var(--ink); font-weight: 600; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 20px; box-shadow: var(--shadow);
}
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
.stat b { display: block; font-family: Archivo, sans-serif; font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--ink-3); }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface-2);
  font-weight: 600; font-size: 15px; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: 0.45; cursor: default; }
.btn .n { font-variant-numeric: tabular-nums; opacity: 0.75; font-weight: 500; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 36px 0 14px; }
.section-head h2 { font-size: 24px; font-weight: 800; }

.courses { display: grid; gap: 10px; }
.course-row {
  display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; align-items: center;
  padding: 16px 18px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); text-decoration: none;
}
.course-row:hover { border-color: var(--ink-3); }
.course-row h3 { font-size: 19px; font-weight: 800; }
.course-row .meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--ink-3); }
.course-row .pct { font-family: Archivo, sans-serif; font-weight: 800; font-size: 20px; font-variant-numeric: tabular-nums; }
.bar { grid-column: 1 / -1; height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }
.pending { opacity: 0.55; }

/* ---------- course ---------- */
.course-head h1 { font-size: clamp(30px, 6vw, 46px); font-weight: 900; letter-spacing: -0.02em; margin: 10px 0 14px; }
.intro { font-size: 18px; color: var(--ink-2); max-width: 62ch; }
.actions { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; margin: 22px 0 8px; }
.tips { margin: 0; padding-left: 20px; color: var(--ink-2); }
.tips li { margin: 6px 0; }
.units { display: grid; gap: 8px; }
.unit-row {
  display: grid; grid-template-columns: 44px 1fr; gap: 4px 14px; align-items: start;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
.unit-row .no { font-family: Archivo, sans-serif; font-weight: 900; font-size: 26px; color: var(--accent); line-height: 1; padding-top: 2px; }
.unit-row h3 { font-size: 18px; font-weight: 700; }
.unit-row p { margin: 4px 0 10px; font-size: 15px; color: var(--ink-2); }
.unit-row .btns .btn { min-height: 38px; padding: 6px 12px; font-size: 14px; }
.unit-row .info { font-size: 13px; color: var(--ink-3); margin-bottom: 8px; }
.done-mark { color: var(--ok); font-weight: 600; }

/* ---------- unit / prose ---------- */
.unit-head h1 { font-size: clamp(28px, 6vw, 42px); font-weight: 900; margin: 8px 0 10px; }
.oneliner { font-size: 18px; color: var(--ink-2); margin: 0 0 20px; }
.tabs { position: sticky; top: 49px; z-index: 5; display: flex; gap: 4px; padding: 8px 0; background: var(--bg); border-bottom: 1px solid var(--line); margin-bottom: 24px; overflow-x: auto; }
.tab {
  flex: 0 0 auto; border: 0; background: none; padding: 8px 12px; border-radius: 6px;
  font-weight: 600; font-size: 15px; color: var(--ink-2); cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--surface-2); color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }
.prose h2 { font-size: 23px; font-weight: 800; margin: 36px 0 12px; }
.prose h2:first-child { margin-top: 0; }
.prose h4 { font-size: 18px; margin: 22px 0 8px; }
.prose p { margin: 0 0 14px; }
.prose ul, .prose ol { margin: 0 0 16px; padding-left: 22px; }
.prose li { margin: 5px 0; }
.prose strong { font-weight: 700; color: var(--ink); }
.prose code { font-family: "Courier Prime", monospace; font-size: 0.95em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.prose pre {
  margin: 0 0 18px; padding: 14px 16px; overflow-x: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  font-family: "Courier Prime", monospace; font-size: 15px; line-height: 1.5;
}
.prose pre code { background: none; padding: 0; }
.tablewrap { overflow-x: auto; margin: 0 0 18px; border: 1px solid var(--line); border-radius: 8px; }
.prose table { border-collapse: collapse; width: 100%; font-size: 15px; }
.prose th, .prose td { text-align: left; vertical-align: top; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.prose th { background: var(--surface-2); font-weight: 700; white-space: nowrap; }
.prose tr:last-child td { border-bottom: 0; }
.tip {
  margin: 0 0 18px; padding: 12px 16px; border-left: 3px solid var(--accent);
  background: var(--accent-tint); border-radius: 0 8px 8px 0;
}
.tip b { display: block; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); margin-bottom: 2px; font-family: "Courier Prime", monospace; }
.tip p { margin: 0; }
.sec { padding-bottom: 6px; }

.must { list-style: none; margin: 0 0 28px; padding: 0; counter-reset: m; }
.must li {
  counter-increment: m; display: grid; grid-template-columns: 34px 1fr; gap: 6px;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.must li::before { content: counter(m, decimal-leading-zero); font-family: "Courier Prime", monospace; color: var(--ink-3); font-size: 14px; padding-top: 2px; }
.box-title { font-size: 20px; font-weight: 800; margin: 28px 0 10px; }
.trap { padding: 10px 14px; border: 1px solid var(--line); border-left: 3px solid var(--bad); border-radius: 0 8px 8px 0; margin-bottom: 8px; background: var(--surface); }
.memo { padding: 10px 14px; border: 1px solid var(--line); border-left: 3px solid var(--ok); border-radius: 0 8px 8px 0; margin-bottom: 8px; background: var(--surface); }
.pager { display: flex; justify-content: space-between; gap: 8px; margin-top: 36px; padding-top: 18px; border-top: 1px solid var(--line); }

/* ---------- quiz ---------- */
.qtop { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.qtop .count { font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 14px; white-space: nowrap; }
.qbar { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; margin-bottom: 22px; }
.qbar i { display: block; height: 100%; background: var(--accent); transition: width .25s ease; }
.qcard { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); }
.qmeta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 10px; font-family: "Courier Prime", monospace; font-size: 13px; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.06em; }
.qmeta .hot { color: var(--accent); font-weight: 700; }
.stem { font-size: 19px; font-weight: 600; line-height: 1.5; margin: 0 0 18px; white-space: pre-line; }
.opts { display: grid; gap: 8px; }
.opt {
  display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: start; text-align: left;
  width: 100%; min-height: 50px; padding: 12px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-size: 16px; line-height: 1.45;
}
.opt:hover:not([disabled]) { border-color: var(--ink-3); }
.opt .k { font-family: Archivo, sans-serif; font-weight: 800; color: var(--ink-3); }
.opt[disabled] { cursor: default; }
.opt.right { border-color: var(--ok); background: var(--ok-tint); }
.opt.right .k { color: var(--ok); }
.opt.wrong { border-color: var(--bad); background: var(--bad-tint); }
.opt.wrong .k { color: var(--bad); }
.explain { margin-top: 16px; padding: 14px 16px; border-radius: 8px; background: var(--surface-2); font-size: 16px; }
.explain .verdict { font-family: Archivo, sans-serif; font-weight: 800; font-size: 18px; margin-bottom: 4px; }
.verdict.ok { color: var(--ok); }
.verdict.no { color: var(--bad); }
.qnav { display: flex; gap: 8px; margin-top: 16px; }
.qnav .btn { flex: 1; }
.result { text-align: left; }
.result .big { font-family: Archivo, sans-serif; font-size: 64px; font-weight: 900; line-height: 1; margin: 14px 0 6px; font-variant-numeric: tabular-nums; }

/* ---------- flashcards ---------- */
.fc {
  min-height: 240px; display: flex; flex-direction: column; justify-content: center;
  padding: 26px 22px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; box-shadow: var(--shadow); user-select: none;
}
.fc .side { font-family: "Courier Prime", monospace; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); margin-bottom: 12px; }
.fc .txt { font-size: 21px; font-weight: 600; line-height: 1.45; }
.fc.flipped { border-color: var(--accent); }
.fc.flipped .txt { font-weight: 500; font-size: 19px; }
.fc-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }

.empty { padding: 40px 0; color: var(--ink-2); }

@media (min-width: 860px) {
  .hero { grid-template-columns: 1.25fr 1fr; align-items: end; gap: 48px; }
  .courses { grid-template-columns: 1fr 1fr; }
  main { padding-top: 40px; }
}
@media (max-width: 420px) {
  .stat b { font-size: 24px; }
  .clock .long { display: none; }
}
@media print {
  .top, .tabs, .pager, .btns, .actions { display: none !important; }
  body { background: #fff; color: #000; }
}
