:root {
  --bg: #f6f7f5; --surface: #fff; --text: #1b1f1d; --muted: #6a726e; --line: #dfe4e1;
  --accent: #1f7a5c; --accent-text: #fff; --ok: #2f7d4f; --bad: #c0392b; --sel: #dcefe6;
  --code-bg: #eef1ef;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, "SF Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121514; --surface: #1a1e1c; --text: #e5ebe7; --muted: #8f9993; --line: #2c3330;
    --accent: #4cc596; --accent-text: #0d1a14; --ok: #5cbf86; --bad: #ef6a5b; --sel: #1d3a2e;
    --code-bg: #232927;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.6 system-ui, sans-serif; }
a { color: var(--accent); }
nav { display: flex; gap: 4px; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
nav a { text-decoration: none; color: var(--text); padding: 4px 10px; border-radius: 6px; }
nav a:hover { background: var(--sel); }
nav .brand { font-weight: 700; color: var(--accent); margin-right: auto; font-family: var(--mono); }
nav .home { color: var(--muted); }
main { max-width: 820px; margin: 0 auto; padding: 16px; }
main.wide { max-width: 1200px; }
h1, h2 { line-height: 1.3; }
.muted { color: var(--muted); } .small { font-size: 13px; } .center { text-align: center; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
kbd { font-size: 11px; opacity: .6; margin-left: 4px; }
code, pre, .editor, .options.mono button { font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0; }
code { font-family: var(--mono); font-size: .9em; background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
pre { font-family: var(--mono); font-size: 14px; line-height: 1.45; background: var(--code-bg); padding: 10px 12px; border-radius: 8px; overflow-x: auto; text-align: left; margin: 8px 0; }
pre code { background: none; padding: 0; font-size: inherit; }
ul { margin: 4px 0; padding-left: 22px; }

.btn { display: inline-block; padding: 9px 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.small { padding: 3px 10px; font-size: 13px; }
.btn.again { border-color: var(--bad); color: var(--bad); } .btn.good { border-color: var(--ok); color: var(--ok); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0; }
.actions.center { justify-content: center; }

.hero { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px; text-align: center; }
.stat b { display: block; font-size: 28px; font-variant-numeric: tabular-nums; } .stat span { color: var(--muted); font-size: 13px; }
table { width: 100%; border-collapse: collapse; }
td, th { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.off td { opacity: .45; }
.bar-cell { width: 40%; }
.bar { position: relative; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.bar i, .bar u { position: absolute; left: 0; top: 0; bottom: 0; }
.bar i { background: color-mix(in srgb, var(--accent) 40%, transparent); } .bar u { background: var(--accent); }
.bar.acc u { background: var(--accent); }
.bar.acc.low u { background: var(--bad); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px 22px; min-height: 200px; }
.card .topic { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.card .q { font-size: 19px; font-weight: 600; margin: 6px 0 4px; }
.card .a { border-top: 1px dashed var(--line); margin-top: 16px; padding-top: 14px; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.tabs a, .tabs button { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 20px; padding: 5px 12px; cursor: pointer; font: inherit; font-size: 14px; text-decoration: none; }
.tabs .on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; }
.options button { padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; cursor: pointer; text-align: left; }
.options.mono button { font-family: var(--mono); font-size: 14px; }
.options button:hover:not(:disabled) { border-color: var(--accent); }
.right { background: color-mix(in srgb, var(--ok) 20%, var(--bg)) !important; border-color: var(--ok) !important; }
.wrong { background: color-mix(in srgb, var(--bad) 20%, var(--bg)) !important; border-color: var(--bad) !important; }
.answer-row { display: flex; gap: 8px; margin-top: 18px; }
.answer-row input { flex: 1; min-width: 0; padding: 10px; font: 16px var(--mono); border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.answer-row .unit { align-self: center; color: var(--muted); }
.feedback { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.verdict { font-weight: 700; } .verdict.ok { color: var(--ok); } .verdict.no { color: var(--bad); }
.explain { color: var(--muted); }

.steps { list-style: none; padding: 0; display: grid; gap: 8px; }
.steps a { display: flex; flex-direction: column; padding: 12px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); text-decoration: none; }
.steps a span { color: var(--muted); font-size: 14px; }
.steps li.now a { border: 2px solid var(--accent); }
.steps li.now a > b:first-child::after { content: "  ← now"; color: var(--accent); font-weight: 400; font-size: 14px; }
.steps li.done a { opacity: .6; }
.countdown { padding: 12px 16px; margin-bottom: 12px; border-radius: 10px; background: var(--accent); color: var(--accent-text); }
.countdown b { font-size: 26px; }
.banner { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 16px; margin-bottom: 12px; border: 2px solid var(--accent); border-radius: 10px; background: var(--sel); }
.warn { padding: 12px 16px; margin-bottom: 12px; border: 1px solid var(--bad); border-radius: 10px; }

.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.ok { border-color: var(--ok); color: var(--ok); }
.lvl { letter-spacing: 1px; color: var(--accent); white-space: nowrap; }

/* problem editor */
.split { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 16px; align-items: start; }
.spec { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.spec h1 { font-size: 22px; margin: 0 0 6px; }
details { margin: 10px 0; } summary { cursor: pointer; font-weight: 600; }
.editor { width: 100%; min-height: 420px; resize: vertical; font: 14px/1.5 var(--mono); tab-size: 2; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); white-space: pre; overflow-wrap: normal; overflow-x: auto; }
.editor:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.output { min-height: 60px; max-height: 360px; overflow: auto; white-space: pre-wrap; }
.output.pass { border-left: 4px solid var(--ok); } .output.fail { border-left: 4px solid var(--bad); }

/* card browser */
.search { width: 100%; padding: 10px; font: inherit; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); margin-bottom: 8px; }
.cardlist details { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 8px 12px; margin: 6px 0; }
.cardlist summary { font-weight: 500; display: flex; gap: 8px; align-items: baseline; justify-content: space-between; }
.cardlist .body { padding-top: 8px; border-top: 1px dashed var(--line); margin-top: 8px; }

.settings { display: flex; flex-direction: column; gap: 14px; max-width: 460px; }
.settings label { display: flex; flex-direction: column; gap: 4px; }
.settings label.check { flex-direction: row; align-items: center; gap: 8px; }
.settings select, .settings input[type=number], .settings input[type=date] { padding: 8px; font: inherit; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--text); }
fieldset { border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column; gap: 4px; }

@media (max-width: 860px) {
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .hero { grid-template-columns: repeat(2, 1fr); }
  .options { grid-template-columns: 1fr; }
  .bar-cell { display: none; }
  pre { font-size: 12.5px; }
}
.steps .bar { margin-top: 6px; }
.tabs .group { width: 100%; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 6px; }
.goal-line { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.options.mono button { white-space: pre-wrap; }

/* ---------- analog additions ---------- */
:root { --new: #c2571a; --ref: #8a8f8c; }
@media (prefers-color-scheme: dark) { :root { --new: #f2994a; --ref: #6b736f; } }
.bad { color: var(--bad); }
.schem { margin: 10px 0; overflow-x: auto; text-align: center; }
.schem svg { max-width: 100%; height: auto; font-family: var(--mono); }
.sch .probe line { stroke: var(--accent); } .sch .probe polygon { fill: var(--accent); }
.sch text.probe-t { fill: var(--accent); font-weight: 700; }
.card .q b { color: var(--accent); }
.explain b { color: var(--text); }

.lab .change { font-size: 19px; margin: 6px 0; }
.lab .change b { color: var(--new); }
.plot { width: 100%; height: auto; display: block; margin: 8px 0; touch-action: none; user-select: none; font-family: var(--mono); }
#mag { cursor: crosshair; }
.plot text { font-size: 11px; fill: var(--muted); }
.plot .grid { stroke: var(--line); stroke-width: 1; } .plot .grid.minor { stroke-opacity: .45; } .plot .grid.zero { stroke: var(--muted); }
.plot polyline { fill: none; stroke-width: 2.4; stroke-linejoin: round; }
.plot .c-old { stroke: var(--accent); }
.plot .c-new { stroke: var(--new); stroke-dasharray: 7 4; }
.plot .c-ref { stroke: var(--ref); stroke-width: 1.6; stroke-dasharray: 3 3; }
.plot .k-old { fill: var(--accent); } .plot .k-new { fill: var(--new); }
.plot .guess line { stroke: var(--new); stroke-width: 1; stroke-dasharray: 4 3; }
.plot .guess circle { fill: none; stroke: var(--new); stroke-width: 2.5; }
.readout { font-variant-numeric: tabular-nums; }
table.chain, table.summary { margin-top: 10px; }
.explore { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: center; }
.sliders { display: flex; flex-direction: column; gap: 8px; }
.sliders label { display: flex; flex-direction: column; font-size: 14px; }
.sliders label span { display: flex; justify-content: space-between; gap: 8px; }
.sliders input { width: 100%; accent-color: var(--accent); }
@media (max-width: 700px) { .explore { grid-template-columns: 1fr; } }

/* reading */
.today-lesson { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border: 2px solid var(--accent); border-radius: 12px; background: var(--surface); color: var(--text); text-decoration: none; }
.today-lesson b { font-size: 19px; }
.today-lesson .pill { align-self: flex-start; }
table.lessons tr.cur td { background: var(--sel); }
.lesson-title { font-size: 26px; margin: 8px 0 12px; }
article.lesson { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 8px 22px 18px; line-height: 1.7; }
article.lesson h3 { margin: 22px 0 6px; color: var(--accent); }
.card.adi { min-height: 0; }
.quiz-q { min-height: 0; margin-bottom: 12px; }
.quiz-q .q { font-size: 17px; }
.quiz-q .explain { margin-top: 10px; }
.add-article { max-width: none; }
.add-article input, .add-article textarea { padding: 8px; font: inherit; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--text); width: 100%; }
.library { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; margin: 16px 0; }
.library .group { grid-column: 1 / -1; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.library a, .library div:not(.group) { display: flex; flex-direction: column; gap: 2px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); text-decoration: none; }
.library a:hover { border-color: var(--accent); }
.library a b { color: var(--accent); }
.library span { color: var(--muted); font-size: 13px; }
.keyidea { border: 2px solid var(--accent); border-left-width: 6px; border-radius: 12px; background: var(--sel); padding: 4px 18px 14px; margin: 18px 0; }
.keyidea-tag { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); margin-top: 8px; }
.keyidea h3 { margin-top: 4px !important; }
figure.photo { margin: 14px 0; text-align: center; }
figure.photo img { max-width: 100%; max-height: 520px; border-radius: 10px; border: 1px solid var(--line); }
figure.photo figcaption { font-size: 14px; color: var(--muted); text-align: left; margin-top: 6px; }
figure.photo .credit { font-size: 12px; }
article.lesson table { margin: 8px 0; }
.studied { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: baseline; padding: 10px 16px; margin: 8px 0 4px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); text-decoration: none; }
.studied:hover { border-color: var(--accent); }
.studied span:last-child { margin-left: auto; }

/* progress page: chart tokens (series validated with the dataviz palette checker, light and dark) */
:root { --series-1: #2a78d6; --series-2: #eb6834; --seq-0: #e6eaee; --seq-1: #c6dbf5; --seq-2: #8fb8ea; --seq-3: #4f8fdc; --seq-4: #1f5fae; --grid: #e7ebe9; }
@media (prefers-color-scheme: dark) {
  :root { --series-1: #3987e5; --series-2: #d95926; --seq-0: #252b29; --seq-1: #1f3550; --seq-2: #27528a; --seq-3: #3471c2; --seq-4: #6aa5f2; --grid: #2a312e; }
}
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tile { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.tile .label { font-size: 13px; color: var(--muted); }
.tile b { font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tile .sub { font-size: 12px; color: var(--muted); }
.ms-strip { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 0; }
.ms { padding: 4px 10px; border: 1px solid var(--line); border-radius: 16px; font-size: 14px; background: var(--surface); }
.ms.got { border-color: var(--accent); }
.viz { margin-top: 8px; }
.chart-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; overflow-x: auto; }
.chart { width: 100%; height: auto; display: block; font-family: system-ui, sans-serif; }
#cal { min-width: 520px; }
.chart .ax { font-size: 10px; fill: var(--muted); }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .s1 { fill: var(--series-1); } .chart .s2 { fill: var(--series-2); }
.chart path.s1:hover, .chart rect:hover { opacity: .85; }
.chart .est { opacity: .55; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.s1 { stroke: var(--series-1); } .chart .line.s2 { stroke: var(--series-2); }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .end { font-size: 11px; fill: var(--text); }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.chart .ms-mark { font-size: 12px; fill: var(--text); }
.chart .ms-day { stroke: var(--text); stroke-width: 2; }
.chart .seq-0, .scale .seq-0 { fill: var(--seq-0); background: var(--seq-0); }
.chart .seq-1, .scale .seq-1 { fill: var(--seq-1); background: var(--seq-1); }
.chart .seq-2, .scale .seq-2 { fill: var(--seq-2); background: var(--seq-2); }
.chart .seq-3, .scale .seq-3 { fill: var(--seq-3); background: var(--seq-3); }
.chart .seq-4, .scale .seq-4 { fill: var(--seq-4); background: var(--seq-4); }
.scale { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); margin: 6px 0; flex-wrap: wrap; }
.scale .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin: 4px 0 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 14px; height: 2px; border-radius: 1px; }
.key.s1 { background: var(--series-1); } .key.s2 { background: var(--series-2); }
.tip { position: absolute; z-index: 20; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.18); max-width: 280px; }
.tip-title { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-row b { font-variant-numeric: tabular-nums; }
.tip-row span { color: var(--muted); }
.milestones { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; }
.milestone { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.milestone > div { display: flex; flex-direction: column; flex: 1; }
.milestone .ms-icon { font-size: 18px; color: var(--muted); line-height: 1.3; }
.milestone.got { border-color: var(--accent); }
.milestone.got .ms-icon { color: var(--accent); }
.milestone .bar { margin-top: 6px; }
.chart .leader { stroke: var(--muted); stroke-width: 1; }

/* hub */
.hub { display: grid; gap: 10px; }
.hub .subject { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); text-decoration: none; }
.hub .subject:hover { border-color: var(--accent); }
.hub .subject b { font-size: 20px; color: var(--accent); }
