:root {
  --brand: #ea4593;
  --brand-ink: #fff;
  --accent: #8a63d2;
  --bg: #fbf8ff;
  --surface: #ffffff;
  --ink: #1d1530;
  --muted: #6d6585;
  --line: #e7e0f3;
  --good: #1f9d6b;
  --mid: #c98a12;
  --low: #d0434a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(29, 21, 48, .06), 0 6px 18px rgba(29, 21, 48, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #130f1d;
    --surface: #1d182b;
    --ink: #efeaf8;
    --muted: #a59dbb;
    --line: #322a47;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: clamp(1.6rem, 3.5vw, 2.3rem); line-height: 1.2; margin: .4em 0 .3em; }
h2 { font-size: 1.25rem; margin: 1.6em 0 .6em; }
img { max-width: 100%; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.top {
  position: sticky; top: 0; z-index: 10; display: flex; gap: 1rem; align-items: center; flex-wrap: wrap;
  padding: .6rem max(16px, calc((100vw - 1080px) / 2)); background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; font-size: 1.15rem; color: var(--ink); text-decoration: none; }
.brand img { image-rendering: pixelated; }
#nav { display: flex; gap: .2rem; flex-wrap: wrap; margin-left: auto; }
#nav a { padding: .35rem .7rem; border-radius: 999px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: .95rem; }
#nav a:hover, #nav a.active { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); }
main { max-width: 1080px; margin: 0 auto; padding: 1rem 16px 3rem; min-height: 70vh; }
footer { border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem; text-align: center; padding: 1.5rem 16px; }

.btn {
  display: inline-flex; align-items: center; gap: .35rem; padding: .55rem 1rem; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none;
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { padding: .3rem .7rem; font-size: .88rem; }
.btn.danger { color: var(--low); }
.btn.video { color: #c4302b; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin: .8rem 0; }

.hero { display: grid; grid-template-columns: 1fr auto; gap: 2rem; align-items: center; padding: 2rem 0 1rem; }
.hero .lead { font-size: 1.12rem; color: var(--muted); max-width: 60ch; }
.hero .mascot { image-rendering: pixelated; filter: drop-shadow(0 10px 20px rgba(234, 69, 147, .25)); }
.stats { color: var(--muted); }
@media (max-width: 700px) { .hero { grid-template-columns: 1fr; } .hero .mascot { width: 140px; order: -1; } }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .8rem; }
.card {
  position: relative; display: block; padding: 1rem; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow); color: var(--ink); text-decoration: none;
}
.card:hover { border-color: var(--brand); }
.card h3 { margin: .2rem 0; font-size: 1.02rem; padding-right: 2.2rem; }
.card.muted { opacity: .62; }
.card .group { position: absolute; top: .8rem; right: .8rem; font-size: .75rem; font-weight: 700; color: var(--accent); }
.meta { color: var(--muted); font-size: .92rem; margin: .2rem 0; }
.crumbs { color: var(--muted); font-size: .9rem; margin: .4rem 0 0; }
.note, .empty { padding: 1rem; border-radius: var(--radius); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.empty { text-align: center; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; margin: 1rem 0; box-shadow: var(--shadow); }
.panel label { display: grid; gap: .25rem; margin: .6rem 0; font-weight: 600; font-size: .92rem; }
.hint { color: var(--muted); font-size: .9rem; }
.error { color: var(--low); }
.big { font-size: 1.4rem; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: .5rem .65rem; width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 55%, transparent); border-color: transparent; }

.unit { margin-top: 1.4rem; }
.topics { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.topics li { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .7rem .9rem; }
.topic-head { display: flex; gap: .6rem; align-items: baseline; flex-wrap: wrap; }
.topic-head .title { font-weight: 650; }
.subtopics { color: var(--muted); font-size: .85rem; margin: .25rem 0 0; }
.topic-actions { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; margin-top: .45rem; }
.topic-actions:empty { display: none; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; color: var(--accent); white-space: nowrap; }

.chip {
  display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 650;
  background: color-mix(in srgb, var(--ink) 7%, transparent); color: var(--ink); white-space: nowrap;
}
.chip.code { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.chip.d1 { background: #d9f3e7; color: #146b49; } .chip.d2 { background: #dceafd; color: #1f4f9a; }
.chip.d3 { background: #fdebd0; color: #8a5a0b; } .chip.d4 { background: #fbd9dc; color: #9b1c24; }
.chip.nocalc { background: color-mix(in srgb, var(--brand) 15%, transparent); color: var(--brand); }
.chip.ct { background: transparent; border: 1px solid var(--line); }
.qmeta { display: flex; gap: .3rem; flex-wrap: wrap; align-items: center; }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .5rem; margin: 1rem 0; align-items: center; }
.qlist { list-style: none; padding: 0; display: grid; gap: .5rem; }
.qlist a { display: block; padding: .8rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; color: var(--ink); text-decoration: none; }
.qlist a:hover { border-color: var(--brand); }
.qpreview { color: var(--muted); font-size: .92rem; margin-top: .35rem; }
.score { margin-left: auto; font-weight: 800; font-size: .85rem; }
.score.good { color: var(--good); } .score.mid { color: var(--mid); } .score.low { color: var(--low); }

.question { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.3rem; margin: 1rem 0; box-shadow: var(--shadow); }
.question h2 { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-top: 0; }
.context { margin: .8rem 0; padding: .2rem 1rem; border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 5%, transparent); border-radius: 0 10px 10px 0; }
.part { border-top: 1px dashed var(--line); padding-top: .8rem; margin-top: .8rem; }
.part-head .marks { float: right; color: var(--muted); font-weight: 700; }
.markscheme { margin-top: .6rem; padding: .7rem .9rem; border-radius: 12px; background: color-mix(in srgb, var(--good) 8%, var(--surface)); border: 1px solid color-mix(in srgb, var(--good) 30%, transparent); }
.markscheme ul { list-style: none; padding: 0; margin: 0; display: grid; gap: .35rem; }
.markscheme label { display: flex; gap: .55rem; align-items: flex-start; cursor: pointer; }
.markscheme input { width: auto; margin-top: .35rem; }
.markscheme .pts { flex: none; display: inline-grid; place-items: center; min-width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--good); color: #fff; font-weight: 800; font-size: .8rem; }
.markscheme .prose p { margin: 0; }
.ai-reason { color: var(--muted); font-size: .85rem; margin-left: 2.6rem; }
.answer { margin: .6rem 0 0; }
.total #total { font-size: 1.3rem; font-weight: 800; margin-right: auto; }
.explanation { margin-top: 1rem; }
.explanation summary { cursor: pointer; font-weight: 700; color: var(--accent); }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }

.prose p { margin: .45rem 0; }
.prose pre { background: #1d1530; color: #f1ecfb; padding: .8rem 1rem; border-radius: 10px; overflow-x: auto; font-size: .88rem; }
.prose code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; }
.prose :not(pre) > code { background: color-mix(in srgb, var(--ink) 8%, transparent); padding: .05rem .3rem; border-radius: 5px; }
.prose ol.options { list-style: none; padding-left: .2rem; }
.prose ol.options li { margin: .25rem 0; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; margin: .6rem 0; font-size: .92rem; }
th, td { border: 1px solid var(--line); padding: .35rem .65rem; text-align: left; }
th { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.math { overflow-x: auto; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: .2rem 0; }

.bar { display: inline-block; width: 110px; height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; vertical-align: middle; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--accent)); }
table.progress { width: 100%; }
table.progress select { width: auto; padding: .2rem .4rem; }

.flashcard { max-width: 640px; margin: 1rem auto; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 1.4rem; box-shadow: var(--shadow); text-align: center; }
.flashcard .front { font-size: 1.2rem; font-weight: 650; }
.flashcard .back { border-top: 1px dashed var(--line); margin-top: 1rem; padding-top: 1rem; }
.ratings { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; margin-top: 1rem; }
.ratings .btn { flex-direction: column; justify-content: center; gap: 0; }
.ratings small { color: var(--muted); font-weight: 500; }
.ratings .r0 { color: var(--low); } .ratings .r3 { color: var(--good); }

.timer { position: sticky; top: 3.6rem; z-index: 5; float: right; background: var(--ink); color: var(--bg); padding: .35rem .8rem; border-radius: 999px; font-weight: 800; font-variant-numeric: tabular-nums; }
.timer.late { background: var(--low); color: #fff; }

.chat { display: grid; gap: .6rem; margin: 1rem 0; max-height: 62vh; overflow-y: auto; padding: .2rem; }
.bubble { padding: .6rem .9rem; border-radius: 14px; max-width: 85%; border: 1px solid var(--line); }
.bubble.user { justify-self: end; background: color-mix(in srgb, var(--brand) 12%, var(--surface)); }
.bubble.assistant { justify-self: start; background: var(--surface); }
.composer { display: flex; gap: .5rem; align-items: flex-end; }
.chip.ctx { font-size: .85rem; }
.loading { color: var(--muted); }

/* ---------- v2: hub, topic tabs, bank, dashboard, tools ---------- */
.btn.big { padding: .75rem 1.3rem; font-size: 1.05rem; }
.btn.ghost { background: transparent; }
.row.tight { margin: .5rem 0 0; }
.row.center { justify-content: center; }
.lead.small { font-size: 1rem; color: var(--muted); max-width: 70ch; }
label.inline { display: inline-flex; gap: .4rem; align-items: center; font-weight: 600; font-size: .9rem; }
label.inline select { width: auto; }
kbd { font: 600 .7rem ui-monospace, monospace; border: 1px solid currentColor; border-radius: 4px; padding: 0 .3rem; opacity: .7; margin-left: .3rem; }
.navbtn, .navicon { background: none; border: 0; font-size: 1.05rem; cursor: pointer; padding: .3rem .5rem; border-radius: 999px; color: var(--muted); text-decoration: none; }
.navbtn:hover, .navicon:hover, .navicon.active { background: color-mix(in srgb, var(--brand) 14%, transparent); }

.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .8rem; margin: 1rem 0 2rem; }
.feature { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.feature span { font-size: 1.6rem; }
.feature h3 { margin: .3rem 0 .2rem; font-size: 1rem; }
.feature p { margin: 0; color: var(--muted); font-size: .9rem; }

.res-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }
.res-groups h4 { margin: .2rem 0 .5rem; color: var(--muted); text-transform: uppercase; font-size: .75rem; letter-spacing: .08em; }
.res { display: flex; gap: .8rem; align-items: flex-start; padding: .8rem 1rem; margin-bottom: .5rem; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; color: var(--ink); text-decoration: none; }
.res:hover { border-color: var(--brand); }
.res.muted { opacity: .55; }
.res .ri { font-size: 1.5rem; line-height: 1; }
.res h3 { margin: 0; font-size: 1rem; }
.res p { margin: .1rem 0 0; color: var(--muted); font-size: .85rem; }
.res b { display: inline-block; margin-top: .2rem; font-size: .85rem; color: var(--brand); }
table.assess td:first-child { white-space: nowrap; }
.topic-links { list-style: none; padding: 0; margin: 0; display: grid; gap: .2rem; }
.topic-links li { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; padding: .35rem .2rem; border-bottom: 1px solid var(--line); }
.topic-links li.muted a { color: var(--muted); }
.topic-links a { text-decoration: none; color: var(--ink); font-weight: 550; }
.topic-links a:hover { color: var(--brand); }
.bar.small { width: 60px; height: 6px; margin-left: auto; }
.unit h3 { margin: 1.2rem 0 .4rem; }

.with-drawer { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 1.4rem; align-items: start; }
.main-col { min-width: 0; }
.drawer { position: sticky; top: 4.2rem; max-height: calc(100vh - 5rem); overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .7rem; font-size: .88rem; }
.drawer summary { cursor: pointer; font-weight: 700; padding: .2rem; }
.dunit p { margin: .8rem 0 .2rem; font-weight: 700; color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; }
.dunit ul { list-style: none; margin: 0; padding: 0; }
.dunit a { display: block; padding: .25rem .4rem; border-radius: 8px; text-decoration: none; color: var(--ink); }
.dunit a.muted { color: var(--muted); opacity: .7; }
.dunit a.on, .dunit a:hover { background: color-mix(in srgb, var(--brand) 12%, transparent); }
.dunit small { float: right; color: var(--brand); font-weight: 700; }
@media (max-width: 979px) { .with-drawer { grid-template-columns: 1fr; } .drawer { position: static; max-height: 60vh; } }

.tabs { display: flex; gap: .2rem; overflow-x: auto; border-bottom: 1px solid var(--line); margin: 1rem 0; }
.tabs a { padding: .55rem .9rem; text-decoration: none; color: var(--muted); font-weight: 650; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--brand); border-color: var(--brand); }
.guide h3, .guide h4 { margin-top: 1.4em; }
.guide { max-width: 78ch; }
.prose pre.mermaid { background: var(--surface); color: var(--ink); text-align: center; border: 1px solid var(--line); }
.video { position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; background: #000; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
.defs { display: grid; gap: .5rem; margin: 0; }
.defs > div { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .6rem .9rem; }
.defs dt { font-weight: 750; color: var(--accent); }
.defs dd { margin: .15rem 0 0; }
.defs dd p { margin: 0; }
.defsec h2 a { text-decoration: none; color: var(--ink); }
.sheets { columns: 2 380px; column-gap: 1rem; }
.sheets .panel { break-inside: avoid; margin-top: 0; }

.filters label { display: grid; gap: .15rem; font-size: .78rem; font-weight: 700; color: var(--muted); }
.bank-bar { display: flex; justify-content: space-between; align-items: center; margin: .4rem 0; }
.qlist-inline .question { margin: .8rem 0; }
.qhead { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.qhead h3 { margin: 0; font-size: 1rem; }
.qfoot { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; border-top: 1px solid var(--line); margin-top: .9rem; padding-top: .7rem; }
.qtotal { font-weight: 800; margin-right: auto; }
.answer-box { margin-top: .5rem; padding: .5rem .8rem; border-radius: 10px; background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.answer-box p { display: inline; }
.explanation { margin-top: .7rem; padding: .7rem 1rem; border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 5%, transparent); border-radius: 0 10px 10px 0; }
.options { display: grid; gap: .45rem; margin: .6rem 0; }
.option { display: flex; gap: .7rem; align-items: flex-start; text-align: left; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: .55rem .8rem; cursor: pointer; }
.option:hover { border-color: var(--brand); }
.option > b { flex: none; display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%; background: color-mix(in srgb, var(--ink) 8%, transparent); }
.option .prose p { margin: .15rem 0; }
.answered .option { cursor: default; }
.option.is-right { border-color: var(--good); background: color-mix(in srgb, var(--good) 12%, var(--surface)); }
.option.is-right > b { background: var(--good); color: #fff; }
.option.is-wrong { border-color: var(--low); background: color-mix(in srgb, var(--low) 10%, var(--surface)); }
.option.is-wrong > b { background: var(--low); color: #fff; }
.mcq-why ul { list-style: none; }
.mcq-why input, .mcq-why .pts, .mcq-why .hint { display: none; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .8rem; margin: 1rem 0; }
.stat { display: flex; flex-direction: column; gap: .2rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; color: var(--ink); text-decoration: none; }
.stat b { font-size: 1.6rem; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat input { width: auto; padding: .1rem .3rem; font-size: .8rem; margin-top: .2rem; }
.heatmap { display: flex; gap: 3px; overflow-x: auto; padding-bottom: .2rem; }
.heatmap div { display: grid; gap: 3px; }
.heatmap i { width: 13px; height: 13px; border-radius: 3px; background: var(--line); }
.heatmap .l1 { background: color-mix(in srgb, var(--brand) 30%, var(--line)); }
.heatmap .l2 { background: color-mix(in srgb, var(--brand) 55%, var(--line)); }
.heatmap .l3 { background: color-mix(in srgb, var(--brand) 80%, var(--line)); }
.heatmap .l4 { background: var(--brand); }
.heatmap .lx { background: transparent; }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
.weak { list-style: none; padding: 0; display: grid; gap: .4rem; }
.weak li { display: flex; gap: .8rem; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .5rem .8rem; }
.weak a { flex: 1; text-decoration: none; color: var(--ink); }
.grid.tools .tool { text-align: center; }
.tool span, .trophy span { font-size: 2rem; }
.trophy { text-align: center; opacity: .45; filter: grayscale(1); }
.trophy.on { opacity: 1; filter: none; border-color: var(--brand); }
.plan { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: .8rem; }
.plan h3 { margin: 0 0 .4rem; text-transform: capitalize; }
.plan ul { padding-left: 1rem; margin: 0; display: grid; gap: .35rem; }
.focus { text-align: center; padding: 2rem 1rem; border-radius: 24px; background: color-mix(in srgb, var(--brand) 10%, var(--surface)); border: 1px solid var(--line); max-width: 520px; margin: 1rem auto; }
.focus.break { background: color-mix(in srgb, var(--good) 12%, var(--surface)); }
.focus .mode { font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.focus .clock { font-size: clamp(3.5rem, 15vw, 6rem); font-weight: 800; margin: .2rem 0; font-variant-numeric: tabular-nums; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .3rem 1rem; align-items: end; }
.blurt-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }
.blurt-grid .good h3 { color: var(--good); }
.blurt-grid .low h3 { color: var(--low); }
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(10, 6, 20, .55); display: grid; place-items: start center; padding-top: 12vh; }
.palette { width: min(640px, 92vw); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); overflow: hidden; }
.palette input { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 1rem; font-size: 1.05rem; background: var(--surface); }
.palette ul { list-style: none; margin: 0; padding: .3rem; max-height: 55vh; overflow-y: auto; }
.palette li a { display: block; padding: .5rem .7rem; border-radius: 10px; text-decoration: none; color: var(--ink); }
.palette li small { display: block; color: var(--muted); }
.palette li.on a, .palette li a:hover { background: color-mix(in srgb, var(--brand) 14%, transparent); }
.topic-index { display: grid; gap: .3rem; }
@media print { .top, footer, .row, .tabs, .drawer { display: none !important; } .sheets { columns: 2; } }

/* ---------- v3: HUD, mastery levels, flow mode, tips, calculator ---------- */
.hud { display: inline-flex; gap: .15rem; background: color-mix(in srgb, var(--ink) 5%, transparent); border-radius: 999px; padding: .1rem; }
.hudbtn { background: none; border: 0; font: 700 .85rem system-ui, sans-serif; color: var(--ink); padding: .3rem .55rem; border-radius: 999px; cursor: pointer; }
.hudbtn:hover { background: color-mix(in srgb, var(--brand) 14%, transparent); }
.pop { position: absolute; z-index: 40; width: min(320px, 92vw); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 16px 40px rgba(0, 0, 0, .25); padding: 1rem; }
.pop-hero { display: flex; flex-direction: column; margin-bottom: .6rem; }
.pop-hero b { font-size: 1.5rem; }
.pop-hero span { color: var(--muted); font-size: .85rem; }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: .3rem; text-align: center; font-size: .75rem; color: var(--muted); }
.week span { display: grid; gap: .2rem; justify-items: center; }
.week i { font-style: normal; display: grid; place-items: center; width: 1.8rem; height: 1.8rem; border-radius: 50%; background: var(--line); color: var(--muted); }
.week .on i { background: linear-gradient(135deg, #ff9a3c, var(--brand)); color: #fff; }
.bar.wide { width: 100%; height: 8px; display: block; margin: .3rem 0 .8rem; }
.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: .3rem; height: 90px; align-items: end; text-align: center; font-size: .72rem; color: var(--muted); margin-bottom: .6rem; }
.bars span { display: flex; flex-direction: column; justify-content: flex-end; height: 100%; gap: .2rem; }
.bars i { display: block; min-height: 3px; border-radius: 4px 4px 0 0; background: linear-gradient(180deg, var(--accent), var(--brand)); }

.lvl { flex: none; display: inline-block; width: .8rem; height: .8rem; border-radius: 4px; border: 2px solid var(--line); vertical-align: -1px; margin-right: .35rem; }
.lvl.mastered { background: #8a63d2; border-color: #8a63d2; }
.lvl.proficient { background: #1f9d6b; border-color: #1f9d6b; }
.lvl.familiar { background: #8cc63f; border-color: #8cc63f; }
.lvl.learning { background: #f0a020; border-color: #f0a020; }
.lvl.unfamiliar { background: #e0565e; border-color: #e0565e; }
.legend { display: flex; flex-wrap: wrap; gap: .3rem 1rem; color: var(--muted); font-size: .82rem; }

.ct-term { text-decoration: underline dotted var(--accent); text-underline-offset: 3px; cursor: help; position: relative; font-weight: 650; }
.ct-term:hover::after, .ct-term:focus::after {
  content: "✎ " attr(data-tip); position: absolute; left: 0; bottom: calc(100% + 6px); z-index: 20; width: min(300px, 80vw);
  background: var(--ink); color: var(--bg); font: 500 .82rem/1.4 system-ui, sans-serif; padding: .55rem .7rem; border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}
.calc { display: flex; gap: .5rem; align-items: center; margin-top: .6rem; flex-wrap: wrap; }
.calc [data-calc] { flex: 1; min-width: 180px; font-family: ui-monospace, monospace; }
.calc label { font-size: .8rem; color: var(--muted); display: flex; gap: .2rem; align-items: center; }
.calc label input { width: auto; }
.calc output { font: 700 1rem ui-monospace, monospace; color: var(--brand); min-width: 6ch; }

.flow-cta { display: flex; justify-content: space-between; align-items: center; gap: .8rem; padding: .6rem .9rem; border-radius: 12px; background: color-mix(in srgb, var(--accent) 12%, var(--surface)); margin: .4rem 0 .8rem; font-weight: 600; font-size: .92rem; }
.flow { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 1.2rem; align-items: start; }
.flow-side { position: sticky; top: 4.2rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .9rem; max-height: calc(100vh - 5rem); display: flex; flex-direction: column; overflow: hidden; }
.flow-side .tabs { margin: 0 0 .5rem; }
.flow-side #side-tutor { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.flow-side #side-tutor[hidden] { display: none; }
.flow-side .chat { flex: 1; max-height: none; min-height: 160px; overflow-y: auto; margin: .3rem 0; }
.flow-side #side-ms { overflow-y: auto; }
.quick { display: flex; flex-wrap: wrap; gap: .3rem; margin: .4rem 0; }
.chipbtn { font: 600 .82rem system-ui, sans-serif; border: 1px solid color-mix(in srgb, var(--brand) 40%, transparent); color: var(--brand); background: color-mix(in srgb, var(--brand) 7%, transparent); border-radius: 999px; padding: .3rem .7rem; cursor: pointer; }
@media (max-width: 979px) { .flow { grid-template-columns: 1fr; } .flow-side { position: static; max-height: none; } }

.saved-item .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; }
.deckpick { margin: .6rem 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .5rem .8rem; }
.deckpick summary { cursor: pointer; font-weight: 650; }
.deckgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .25rem .8rem; margin: .6rem 0; }
.deckgrid label { display: flex; gap: .4rem; align-items: center; font-size: .9rem; }
.deckgrid input { width: auto; }
.deckgrid small { color: var(--muted); margin-left: auto; }

/* ---------- v4: weekly calendar, notes ---------- */
.spacer { flex: 1; }
.cal-bar { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin: .6rem 0; }
.cal-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.cal { display: grid; grid-template-columns: 52px repeat(7, minmax(120px, 1fr)); min-width: 900px; }
.cal-head { height: 38px; display: grid; place-items: center; font-weight: 700; font-size: .88rem; border-bottom: 1px solid var(--line); text-transform: capitalize; }
.cal-allday, .cal-allday-h { min-height: 34px; border-bottom: 1px solid var(--line); padding: 3px; display: grid; gap: 3px; align-content: start; }
.cal-allday-h { font-size: .7rem; color: var(--muted); place-items: center; }
.cal-hours .cal-h { height: var(--px); font-size: .7rem; color: var(--muted); text-align: right; padding-right: 6px; transform: translateY(-.5em); }
.cal-col { border-left: 1px solid var(--line); }
.cal-col.is-today .cal-head { color: var(--brand); }
.cal-col.is-today { background: color-mix(in srgb, var(--brand) 4%, transparent); }
.cal-body { position: relative; cursor: cell; background-image: repeating-linear-gradient(to bottom, var(--line) 0 1px, transparent 1px var(--px)); }
.ev, .ev-chip { font: inherit; text-align: left; border: 0; cursor: pointer; color: var(--ink); border-radius: 8px; border-left: 4px solid var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--surface)); }
.ev { position: absolute; left: 3px; right: 3px; padding: 2px 6px; overflow: hidden; display: flex; flex-direction: column; font-size: .78rem; line-height: 1.25; }
.ev b { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev small { color: var(--muted); }
.ev-chip { font-size: .74rem; padding: 2px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev.fixed, .ev-chip.fixed { border-color: var(--muted); background: color-mix(in srgb, var(--muted) 14%, var(--surface)); }
.ev.deadline, .ev-chip.deadline { border-color: var(--low); background: color-mix(in srgb, var(--low) 14%, var(--surface)); }
.ev.task, .ev-chip.task { border-color: var(--mid); background: color-mix(in srgb, var(--mid) 14%, var(--surface)); }
.ev.study { border-color: var(--good); background: color-mix(in srgb, var(--good) 15%, var(--surface)); }
.ev.done, .ev-chip.done { opacity: .5; text-decoration: line-through; }
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink); width: min(560px, 94vw); padding: 1.2rem; }
dialog::backdrop { background: rgba(10, 6, 20, .5); }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid label { display: grid; gap: .25rem; font-weight: 600; font-size: .9rem; }
.form-grid label.inline { display: flex; }

.notes .drawer.static { position: sticky; }
.notes .drawer .btn { width: 100%; justify-content: center; margin-bottom: .4rem; }
.note-head { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.ntitle { flex: 1 1 260px; font-size: 1.5rem; font-weight: 800; border: 0; background: transparent; padding: .2rem 0; }
.note-head select { width: auto; }
.note-split { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.note-split textarea { min-height: 62vh; font: .95rem/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; }
.note-preview { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .4rem 1rem; min-height: 62vh; overflow: auto; }
details.check { border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); border-radius: 10px; padding: .4rem .7rem; margin: .4rem 0; background: color-mix(in srgb, var(--accent) 6%, transparent); }
details.check summary { cursor: pointer; font-weight: 650; }
details.check summary::before { content: "❓ "; }
details.check[open] summary::before { content: "💡 "; }
@media (max-width: 860px) { .note-split { grid-template-columns: 1fr; } .note-split textarea, .note-preview { min-height: 40vh; } }
