:root {
  --bg: oklch(1 0 0);
  --surface: oklch(0.972 0.008 258);
  --surface-2: oklch(0.945 0.012 258);
  --ink: oklch(0.21 0.025 258);
  --muted: oklch(0.47 0.025 258);
  --border: oklch(0.89 0.012 258);
  --primary: oklch(0.42 0.15 260);
  --primary-ink: oklch(1 0 0);
  --primary-soft: oklch(0.94 0.035 258);
  --ok: oklch(0.52 0.13 152);
  --ok-soft: oklch(0.95 0.045 152);
  --bad: oklch(0.53 0.18 27);
  --bad-soft: oklch(0.95 0.035 27);
  --warn: oklch(0.6 0.13 70);
  --warn-soft: oklch(0.96 0.05 85);
  --k-ask: oklch(0.9 0.07 258);
  --k-context: oklch(0.91 0.07 190);
  --k-constraint: oklch(0.92 0.09 85);
  --k-term: oklch(0.91 0.06 305);
  --k-trap: oklch(0.92 0.06 27);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --z-sticky: 10;
  --z-nav: 20;
  --z-toast: 40;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: oklch(0.18 0.015 258);
    --surface: oklch(0.22 0.018 258);
    --surface-2: oklch(0.26 0.02 258);
    --ink: oklch(0.94 0.01 258);
    --muted: oklch(0.72 0.02 258);
    --border: oklch(0.33 0.02 258);
    --primary: oklch(0.72 0.12 258);
    --primary-ink: oklch(0.16 0.02 258);
    --primary-soft: oklch(0.3 0.06 258);
    --ok: oklch(0.75 0.14 152);
    --ok-soft: oklch(0.29 0.05 152);
    --bad: oklch(0.73 0.15 27);
    --bad-soft: oklch(0.3 0.06 27);
    --warn: oklch(0.8 0.12 80);
    --warn-soft: oklch(0.31 0.05 80);
    --k-ask: oklch(0.38 0.09 258);
    --k-context: oklch(0.38 0.07 190);
    --k-constraint: oklch(0.4 0.08 85);
    --k-term: oklch(0.38 0.07 305);
    --k-trap: oklch(0.38 0.08 27);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--font); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; text-wrap: balance; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .8em; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
.topbar { position: sticky; top: 0; z-index: var(--z-sticky); display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 56px; background: var(--bg); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--surface); text-decoration: none; color: var(--ink); }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
main { max-width: 1040px; margin: 0 auto; padding: 24px 20px 64px; outline: none; }
.boot { color: var(--muted); padding: 40px 0; }

@media (max-width: 720px) {
  .topbar { height: 50px; padding: 0 14px; }
  .nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-nav); justify-content: space-around; gap: 0; background: var(--bg); border-top: 1px solid var(--border); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  .nav a { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; flex: 1; text-align: center; }
  .nav a.active { background: none; }
  .nav svg { width: 22px; height: 22px; }
  main { padding: 16px 14px calc(84px + env(safe-area-inset-bottom)); }
  body.in-session .nav { display: none; }
  body.in-session main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
}

/* ---------- primitives ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 16px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--ink); font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s; white-space: nowrap; }
.btn:hover { background: var(--surface); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spread { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.panel { background: var(--surface); border-radius: var(--radius); padding: 18px; }
.section { margin: 28px 0; }
.section > h2 { margin-bottom: 12px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.above { background: var(--ok-soft); color: var(--ok); }
.badge.target { background: var(--primary-soft); color: var(--primary); }
.badge.below { background: var(--warn-soft); color: var(--warn); }
.badge.needs { background: var(--bad-soft); color: var(--bad); }
.empty { padding: 28px; text-align: center; color: var(--muted); background: var(--surface); border-radius: var(--radius); }
.input, select.input, textarea.input { width: 100%; min-height: 42px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
textarea.input { min-height: 84px; resize: vertical; }
.err { color: var(--bad); }

/* ---------- login ---------- */
.login { max-width: 380px; margin: 10vh auto 0; }
.login form { display: grid; gap: 12px; margin-top: 20px; }

/* ---------- home ---------- */
.hello { margin-bottom: 20px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.stats > div { background: var(--bg); padding: 14px 16px; }
.stats b { display: block; font-size: 1.45rem; line-height: 1.2; }
.stats span { color: var(--muted); font-size: 13px; }
@media (max-width: 720px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.plan { display: grid; gap: 10px; }
.plan-item { display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: center; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); }
.plan-item .num { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: 14px; }
.plan-item h3 { margin: 0 0 2px; font-size: 15px; }
.plan-item p { margin: 0; color: var(--muted); font-size: 13px; }
@media (max-width: 560px) { .plan-item { grid-template-columns: 30px 1fr; } .plan-item .actions { grid-column: 1 / -1; } }
.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.quick button { text-align: left; padding: 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg); cursor: pointer; }
.quick button:hover { border-color: var(--primary); }
.quick b { display: block; }
.quick span { color: var(--muted); font-size: 13px; }

/* ---------- bars & tables ---------- */
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.bar.ok > i { background: var(--ok); } .bar.warn > i { background: var(--warn); } .bar.bad > i { background: var(--bad); }
.dom-row { display: grid; grid-template-columns: minmax(150px, 220px) 1fr 110px; gap: 14px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.dom-row:last-child { border-bottom: 0; }
@media (max-width: 560px) { .dom-row { grid-template-columns: 1fr auto; } .dom-row .bar { grid-column: 1 / -1; grid-row: 2; } }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl-wrap { overflow-x: auto; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid-line { stroke: var(--border); }
.chart .line { fill: none; stroke: var(--primary); stroke-width: 2; }
.chart .line-2 { fill: none; stroke: var(--warn); stroke-width: 1.5; stroke-dasharray: 4 3; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .dot { fill: var(--primary); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 5px; background: var(--primary); }
.legend i.l2 { background: var(--warn); }

/* ---------- practice setup ---------- */
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.mode { position: relative; display: block; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.mode input { position: absolute; opacity: 0; pointer-events: none; }
.mode b { display: block; margin-bottom: 2px; }
.mode span { color: var(--muted); font-size: 13px; }
.mode:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.mode:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }
.mode.disabled { opacity: .5; }
.opts { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.field label, .field .label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg label { padding: 7px 12px; cursor: pointer; font-size: 14px; border-right: 1px solid var(--border); }
.seg label:last-child { border-right: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--primary); color: var(--primary-ink); }
.seg label:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: -2px; }
.task-pick { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.task-pick fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; margin: 0; }
.task-pick legend { font-weight: 700; padding: 0 4px; }
.task-pick label { display: flex; gap: 8px; align-items: flex-start; padding: 5px 0; font-size: 14px; cursor: pointer; }
.task-pick input { margin-top: 3px; }
.startbar { position: sticky; bottom: 0; background: var(--bg); padding: 14px 0; border-top: 1px solid var(--border); margin-top: 20px; }
@media (max-width: 720px) { .startbar { bottom: calc(58px + env(safe-area-inset-bottom)); } }

/* ---------- session ---------- */
.sess-head { position: sticky; top: 56px; z-index: var(--z-sticky); background: var(--bg); padding: 10px 0; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
@media (max-width: 720px) { .sess-head { top: 50px; } }
.sess-head .meta { display: flex; gap: 12px; align-items: center; font-size: 14px; color: var(--muted); }
.sess-head .timer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ink); }
.sess-head .timer.low { color: var(--bad); }
.progress-thin { height: 3px; background: var(--surface-2); margin-top: 8px; border-radius: 99px; overflow: hidden; }
.progress-thin i { display: block; height: 100%; background: var(--primary); }
.q-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tools { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 14px; }
.stem { font-size: 17px; line-height: 1.65; margin-bottom: 14px; max-width: 75ch; }
.stem mark { background: none; color: inherit; border-radius: 3px; }
.kw-on .stem mark { padding: 0 2px; cursor: help; }
.exam-mode .q-tags { display: none; }
.kw-on .stem mark.kw-ask { background: var(--k-ask); font-weight: 700; }
.kw-on .stem mark.kw-context { background: var(--k-context); }
.kw-on .stem mark.kw-constraint { background: var(--k-constraint); }
.kw-on .stem mark.kw-term { background: var(--k-term); }
.kw-on .stem mark.kw-trap { background: var(--k-trap); text-decoration: underline wavy var(--bad); text-underline-offset: 3px; }
.kw-list { display: grid; gap: 6px; margin: 0 0 14px; padding: 12px 14px; background: var(--surface); border-radius: var(--radius); font-size: 14px; }
.kw-list div { display: grid; grid-template-columns: 92px 1fr; gap: 8px; }
.kw-type { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px; text-align: center; align-self: start; color: var(--ink); }
.kw-type.ask { background: var(--k-ask); } .kw-type.context { background: var(--k-context); } .kw-type.constraint { background: var(--k-constraint); } .kw-type.term { background: var(--k-term); } .kw-type.trap { background: var(--k-trap); }
.vi { color: var(--muted); font-size: 14.5px; line-height: 1.6; }
.vi-block { padding: 12px 14px; background: var(--surface); border-radius: var(--radius); margin-bottom: 14px; max-width: 75ch; }
.hint { padding: 12px 14px; background: var(--warn-soft); border-radius: var(--radius); margin-bottom: 14px; font-size: 14.5px; max-width: 75ch; }
.choose-n { font-size: 13px; font-weight: 600; color: var(--primary); margin-bottom: 8px; }
.options { display: grid; gap: 10px; margin-bottom: 18px; max-width: 80ch; }
.opt { display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: start; width: 100%; text-align: left; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); cursor: pointer; transition: border-color .15s, background .15s; }
.opt:hover:not(:disabled) { border-color: var(--primary); }
.opt:disabled { cursor: default; }
.opt .letter { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--border); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.opt.multi .letter { border-radius: 6px; }
.opt.sel { border-color: var(--primary); background: var(--primary-soft); }
.opt.sel .letter { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.right .letter { background: var(--ok); border-color: var(--ok); color: var(--bg); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .letter { background: var(--bad); border-color: var(--bad); color: var(--bg); }
.opt .txt { padding-top: 3px; }
.opt .vi { display: block; margin-top: 4px; }
.opt .why { display: block; margin-top: 6px; font-size: 13.5px; color: var(--ink); }
.verdict { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; margin-bottom: 10px; }
.verdict.ok { color: var(--ok); } .verdict.bad { color: var(--bad); }
.explain { border-top: 1px solid var(--border); padding-top: 16px; margin-top: 4px; max-width: 80ch; }
.explain h3 { font-size: 14px; color: var(--muted); margin: 16px 0 6px; font-weight: 600; }
.explain .mindset { padding: 10px 14px; background: var(--primary-soft); border-radius: var(--radius); }
.sess-foot { position: sticky; bottom: 0; background: var(--bg); border-top: 1px solid var(--border); padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); margin-top: 18px; display: flex; gap: 10px; justify-content: space-between; }
@media (max-width: 720px) { .sess-foot .btn { flex: 1; } .sess-foot .kbd { display: none; } }
.kbd { font-size: 12px; color: var(--muted); align-self: center; }
.navgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 6px; margin: 10px 0 0; }
.navgrid button { height: 36px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); cursor: pointer; font-size: 13px; position: relative; }
.navgrid button.ans { background: var(--surface-2); }
.navgrid button.cur { border-color: var(--primary); border-width: 2px; }
.navgrid button.flag::after { content: ""; position: absolute; top: 3px; right: 3px; width: 6px; height: 6px; border-radius: 50%; background: var(--warn); }
.navgrid button.r { background: var(--ok-soft); border-color: var(--ok); }
.navgrid button.w { background: var(--bad-soft); border-color: var(--bad); }
details.nav-panel summary { cursor: pointer; font-size: 14px; color: var(--muted); }
.breakscreen { text-align: center; padding: 60px 20px; }
.breakscreen b { font-size: 2.4rem; display: block; font-variant-numeric: tabular-nums; margin: 10px 0 20px; }

/* ---------- result ---------- */
.score { display: flex; gap: 28px; align-items: center; flex-wrap: wrap; margin: 10px 0 20px; }
.score .big { font-size: 3rem; font-weight: 800; line-height: 1; }
.qlist { display: grid; gap: 8px; }
.qlist a { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; color: var(--ink); }
.qlist a:hover { border-color: var(--primary); text-decoration: none; }
.qlist .mk { font-weight: 800; }
.qlist .mk.ok { color: var(--ok); } .qlist .mk.bad { color: var(--bad); }
.clip { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* ---------- learn ---------- */
.task-list { display: grid; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.task-list a { display: grid; grid-template-columns: 52px 1fr auto; gap: 12px; padding: 12px 14px; background: var(--bg); color: var(--ink); align-items: center; }
.task-list a:hover { background: var(--surface); text-decoration: none; }
.task-list .tid { font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.prose { max-width: 75ch; font-size: 15.5px; line-height: 1.7; text-wrap: pretty; }
.prose h1 { font-size: 1.45rem; margin-top: .5em; }
.prose h2 { font-size: 1.2rem; margin-top: 1.6em; }
.prose h3 { font-size: 1.05rem; margin-top: 1.3em; }
.prose img { max-width: 100%; height: auto; border-radius: 8px; }
.prose table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; }
.prose th, .prose td { border: 1px solid var(--border); padding: 6px 10px; }
.prose blockquote { margin: 0 0 1em; padding: 10px 16px; background: var(--surface); border-radius: 8px; }
.prose code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .92em; }
.prose ul, .prose ol { padding-left: 1.3em; }
.article-list { display: grid; gap: 8px; }
.article-list a { display: block; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; color: var(--ink); }
.article-list a:hover { border-color: var(--primary); text-decoration: none; }
.article-list .snip { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.article-list .read { color: var(--ok); font-size: 12px; font-weight: 600; margin-left: 6px; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.layout-2 { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 32px; align-items: start; }
@media (max-width: 900px) { .layout-2 { grid-template-columns: 1fr; } }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); z-index: var(--z-toast); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (max-width: 720px) { #toast { bottom: calc(80px + env(safe-area-inset-bottom)); } }

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

/* ---------- learning hub ---------- */
.quick a.tile { display: block; padding: 14px; border-radius: var(--radius); border: 1px solid var(--border); color: var(--ink); }
.quick a.tile:hover { border-color: var(--primary); text-decoration: none; }
.quick a.tile b { display: block; }
.quick a.tile span { color: var(--muted); font-size: 13px; }
.aside-sticky { position: sticky; top: 72px; }
@media (max-width: 900px) { .aside-sticky { position: static; } }
.lesson-nav { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--border); }
.lesson-nav .btn { white-space: normal; text-align: left; max-width: 48%; }
.flash { max-width: 640px; min-height: 230px; padding: 24px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; }
.flash.flipped { cursor: default; background: var(--bg); border-color: var(--primary); }
.flash-term { font-size: 1.5rem; font-weight: 700; margin: 8px 0 10px; text-wrap: balance; }
.flash-ex { font-style: italic; color: var(--muted); }
.flash-back { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; }
.flash-vi { font-size: 1.15rem; font-weight: 700; color: var(--primary); margin-bottom: 6px; }
