/* lab.css — the shared look of the course pages (index.html).
   Each page sets only its accent colours (--accent, --accent-2,
   --accent-soft, --grad and its level colours) in a small <style> of its own;
   lab-shop.js themes override those same variables. Everything the page
   scripts touch (ids and class names) is unchanged, so this file is pure
   presentation.

   Layout: a sidebar holding the brand, stats and tabs on wide screens; on
   narrow ones the brand and stats sit in a slim top bar and the tabs become a
   bottom navigation bar. */

/* ---------- tokens ---------- */
:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --line: #e4e7ef;
  --ink: #161a26;
  --ink-2: #545b70;
  --muted: #868ca0;
  --ok: #0f9d58;   --ok-soft: #e6f6ed;
  --bad: #d93636;  --bad-soft: #fdeaea;
  --warn: #b7791f; --warn-soft: #fdf5e3;
  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(20,24,40,.05), 0 8px 24px -10px rgba(20,24,40,.14);
  --shadow-lift: 0 2px 4px rgba(20,24,40,.06), 0 20px 40px -14px color-mix(in srgb, var(--accent) 45%, transparent);
  --side: 256px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --display: "Space Grotesk", "Plus Jakarta Sans", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0d13; --surface: #141720; --surface-2: #1b1f2b; --line: #262b39;
    --ink: #eceef5; --ink-2: #a9b0c3; --muted: #7a8196;
    --ok: #34d399; --ok-soft: #12271d; --bad: #f87171; --bad-soft: #2b1616;
    --warn: #fbbf24; --warn-soft: #2a2312;
    --shadow: 0 1px 2px rgba(0,0,0,.45), 0 10px 28px -10px rgba(0,0,0,.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0d13; --surface: #141720; --surface-2: #1b1f2b; --line: #262b39;
  --ink: #eceef5; --ink-2: #a9b0c3; --muted: #7a8196;
  --ok: #34d399; --ok-soft: #12271d; --bad: #f87171; --bad-soft: #2b1616;
  --warn: #fbbf24; --warn-soft: #2a2312;
  --shadow: 0 1px 2px rgba(0,0,0,.45), 0 10px 28px -10px rgba(0,0,0,.7);
  color-scheme: dark;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  color: var(--ink);
  font: 15px/1.6 "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1100px 520px at 105% -10%, color-mix(in srgb, var(--accent-2) 9%, transparent), transparent 70%),
    radial-gradient(900px 480px at 20% 110%, color-mix(in srgb, var(--accent) 7%, transparent), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  -webkit-text-size-adjust: 100%;
}
h1, h2 { font-family: var(--display); }
h1 { font-size: 1.85rem; font-weight: 700; margin: 0 0 .35rem; letter-spacing: -.035em; line-height: 1.15; }
h2 { font-size: 1.1rem; font-weight: 700; margin: 2.2rem 0 .8rem; letter-spacing: -.02em; }
.lede { color: var(--ink-2); max-width: 62ch; margin: 0 0 1.5rem; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
code { font-family: var(--mono); background: var(--surface-2); padding: .1em .35em; border-radius: 6px; font-size: .92em; }
kbd { font-family: var(--mono); font-size: .8em; background: var(--surface); border: 1px solid var(--line);
      border-bottom-width: 2px; border-radius: 6px; padding: .1em .4em; }
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- shell: sidebar ---------- */
.chrome {
  position: fixed; inset: 0 auto 0 0; z-index: 30; width: var(--side);
  display: flex; flex-direction: column; gap: 1.1rem; padding: 1.3rem 1rem 1rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(16px); -webkit-backdrop-filter: saturate(1.4) blur(16px);
  border-right: 1px solid var(--line); overflow-y: auto; scrollbar-width: thin;
}
body { padding-left: var(--side); }

.topbar { position: relative; display: flex; flex-direction: column; gap: 1.1rem; }
.brand { display: flex; align-items: center; gap: .7rem; padding: 0 2.6rem 0 .3rem;
         font-family: var(--display); font-weight: 700; font-size: 1.12rem; letter-spacing: -.03em; line-height: 1.2; }
.brand-mark { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 13px;
              background: var(--grad); font-size: 1.2rem; box-shadow: 0 8px 18px -8px var(--accent); }
.brand-sub { display: block; font-family: "Plus Jakarta Sans", system-ui, sans-serif; font-size: .64rem; font-weight: 700;
             color: var(--muted); letter-spacing: .08em; text-transform: uppercase; margin-top: 2px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.stat { display: flex; flex-direction: column; gap: .1rem; padding: .55rem .7rem; font-size: .74rem; color: var(--muted);
        background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.stat-v { white-space: nowrap; }
.stat b { font-family: var(--display); color: var(--ink); font-size: 1.15rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-k { color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; font-size: .64rem; }
#rank-label { grid-column: 1 / -1; }
.stat-top { display: flex; gap: .45rem; align-items: baseline; justify-content: space-between; }
.rank-bar { width: 100%; height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: .35rem; }
#rank-fill { height: 100%; width: 0; background: var(--grad); border-radius: 99px; transition: width .5s ease; }
.stats .adxp-btn { grid-column: 1 / -1; justify-content: center; height: 38px; white-space: nowrap; }

.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0; cursor: pointer;
            font-size: 1rem; line-height: 1; color: var(--ink); background: var(--surface-2);
            border: 1px solid var(--line); border-radius: 11px; transition: transform .15s ease, border-color .15s ease; }
.icon-btn:hover { border-color: var(--accent); transform: rotate(-12deg); }
#theme-btn { position: absolute; top: 2px; right: 0; }

.tabs { display: flex; flex-direction: column; gap: .2rem; }
.tab { display: flex; align-items: center; gap: .75rem; width: 100%; padding: .62rem .8rem; cursor: pointer;
       font: inherit; font-size: .9rem; font-weight: 600; text-align: left; white-space: nowrap; color: var(--ink-2);
       background: none; border: 0; border-radius: var(--radius-sm); transition: background .15s ease, color .15s ease; }
.tab-i { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; font-size: 1rem;
         background: var(--surface-2); transition: background .15s ease; }
.tab:hover { background: var(--surface-2); color: var(--ink); }
.tab:hover .tab-i { background: var(--surface); }
.tab.active { color: var(--ink); background: var(--accent-soft); }
.tab.active .tab-i { background: var(--grad); box-shadow: 0 6px 14px -6px var(--accent); }

main { max-width: 1000px; margin: 0 auto; padding: 2.2rem 2rem 3rem; }
.view:not([hidden]) { animation: rise .35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- hero ---------- */
.hero { position: relative; overflow: hidden; isolation: isolate; border-radius: 28px; padding: 2.4rem 2.2rem 2.2rem;
        margin-bottom: 1.8rem; color: #fff; background: var(--grad); box-shadow: var(--shadow-lift); }
.hero::before { content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
                background-image: radial-gradient(rgba(255,255,255,.22) 1px, transparent 1.5px); background-size: 18px 18px;
                mask-image: linear-gradient(110deg, transparent 35%, #000 90%); -webkit-mask-image: linear-gradient(110deg, transparent 35%, #000 90%); }
.hero::after { content: ""; position: absolute; z-index: -1; width: 320px; height: 320px; right: -90px; top: -130px;
               border-radius: 50%; background: rgba(255,255,255,.14); pointer-events: none; }
.hero h1 { color: #fff; font-size: clamp(1.8rem, 4.4vw, 2.6rem); }
.hero .lede { color: rgba(255,255,255,.9); margin-bottom: 0; }
.hero-eyebrow { display: inline-block; font-size: .68rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase;
                padding: .3rem .65rem; margin-bottom: .8rem; border-radius: 99px; background: rgba(255,255,255,.18); }
.hero-glyphs { position: absolute; right: 2rem; bottom: 1.2rem; font-family: var(--mono); font-size: 2.6rem; font-weight: 700;
               opacity: .2; letter-spacing: .2em; pointer-events: none; }
.hero-cells { position: absolute; inset: 0; z-index: -1; pointer-events: none; }
.hero-cells span { position: absolute; border-radius: 50%; background: rgba(255,255,255,.13); border: 2px solid rgba(255,255,255,.18);
                   animation: drift 9s ease-in-out infinite alternate; }
.hero-cells span:nth-child(1) { width: 190px; height: 120px; right: -40px; top: -40px; border-radius: 60px; }
.hero-cells span:nth-child(2) { width: 70px; height: 70px; right: 160px; bottom: -20px; animation-delay: -3s; }
.hero-cells span:nth-child(3) { width: 34px; height: 34px; right: 90px; top: 90px; animation-delay: -5s; }
.hero-cells span:nth-child(4) { width: 110px; height: 44px; right: 250px; top: 18px; border-radius: 30px; animation-delay: -1s; }
@keyframes drift { from { transform: translate(0,0) rotate(0); } to { transform: translate(-14px, 10px) rotate(8deg); } }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.8rem; }

/* ---------- learn ---------- */
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 1rem; }
.topic-card { display: flex; align-items: center; gap: 1rem; width: 100%; padding: 1.1rem 1.15rem; cursor: pointer;
              font: inherit; color: inherit; text-align: left; background: var(--surface);
              border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
              transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; }
.topic-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lift); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.topic-card.locked { opacity: .6; }
.topic-icon { flex: none; display: grid; place-items: center; width: 50px; height: 50px; border-radius: 15px;
              background: var(--accent-soft); font-size: 1.5rem; transition: background .18s ease, transform .18s ease; }
.topic-card:hover .topic-icon { background: var(--grad); transform: rotate(-6deg); }
.topic-body { flex: 1; min-width: 0; }
.topic-name { font-weight: 700; letter-spacing: -.01em; }
.topic-blurb { color: var(--ink-2); font-size: .85rem; line-height: 1.45; margin-top: .1rem; }
.topic-meta { color: var(--muted); font-size: .76rem; margin-top: .35rem; }
.topic-meta.lock { color: var(--warn); }
.ring { flex: none; }
.ring-bg { fill: none; stroke: var(--surface-2); stroke-width: 5; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 5; stroke-linecap: round;
           transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset .6s ease; }
.ring-text { fill: var(--ink-2); font-size: 11px; font-weight: 700; text-anchor: middle; dominant-baseline: central; }

/* ---------- practice ---------- */
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.chip { padding: .42rem .9rem; cursor: pointer; font: inherit; font-size: .82rem; font-weight: 600; color: var(--ink-2);
        background: var(--surface); border: 1px solid var(--line); border-radius: 999px; transition: all .15s ease; }
.chip:hover { border-color: var(--accent); color: var(--ink); }
.chip.active { color: #fff; background: var(--grad); border-color: transparent; box-shadow: 0 6px 16px -8px var(--accent); }
.problem-card { position: relative; overflow: hidden; }
.problem-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--grad); }
.card-head { display: flex; align-items: center; gap: .6rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.card-topic { font-weight: 700; font-size: .9rem; }
.level-badge { font-size: .68rem; font-weight: 800; padding: .18rem .55rem; border-radius: 999px; color: #fff; letter-spacing: .03em; }
.level-badge.lv1 { background: var(--lv1); } .level-badge.lv2 { background: var(--lv2); } .level-badge.lv3 { background: var(--lv3); }
.session { margin-left: auto; display: flex; gap: .5rem; font-size: .82rem; font-weight: 600; }
.session > span { padding: .15rem .55rem; border-radius: 99px; }
.s-ok { color: var(--ok); background: var(--ok-soft); }
.s-no { color: var(--bad); background: var(--bad-soft); }
.instruction { color: var(--ink-2); font-size: .9rem; }
.prompt { font-weight: 650; letter-spacing: -.01em; line-height: 1.45; text-align: center; word-break: break-word;
          font-size: clamp(1.1rem, 3.2vw, 1.4rem); padding: 1.5rem 1rem; margin: .5rem 0 1.3rem;
          background: var(--surface-2); border: 1px dashed color-mix(in srgb, var(--accent) 30%, var(--line)); border-radius: 16px; }
.prompt sup { font-size: .6em; }
[data-course="algebra"] .prompt { font-family: var(--mono); font-size: clamp(1.5rem, 4.5vw, 2.1rem); font-weight: 600; }
.choices[hidden] { display: none; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .55rem; margin-bottom: 1rem; }
.choice { display: flex; align-items: center; gap: .7rem; padding: .75rem .85rem; cursor: pointer; text-align: left;
          font: inherit; font-size: .92rem; color: var(--ink); background: var(--surface);
          border: 1.5px solid var(--line); border-radius: 14px; transition: border-color .15s ease, transform .12s ease, background .15s ease; }
.choice:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-1px); }
.choice:disabled { cursor: default; }
.choice-key { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 9px;
              font-weight: 800; font-size: .78rem; color: var(--ink-2); background: var(--surface-2); }
.choice.right { border-color: var(--ok); background: var(--ok-soft); }
.choice.right .choice-key { background: var(--ok); color: #fff; }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice.wrong .choice-key { background: var(--bad); color: #fff; }
.answer-row { display: flex; gap: .6rem; }
.answer-input { flex: 1; min-width: 0; padding: .75rem .95rem; outline: none; font: inherit; font-size: 1.05rem; color: var(--ink);
                background: var(--surface-2); border: 2px solid var(--line); border-radius: 14px;
                transition: border-color .15s ease, box-shadow .15s ease, background .15s ease; }
[data-course="algebra"] .answer-input { font-family: var(--mono); font-size: 1.15rem; }
.answer-input:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent); }
.answer-input.ok { border-color: var(--ok); background: var(--ok-soft); }
.answer-input.bad { border-color: var(--bad); }
.answer-input:disabled { opacity: 1; }
.format-hint { color: var(--muted); font-size: .78rem; margin-top: .45rem; }

.btn { padding: .7rem 1.1rem; cursor: pointer; white-space: nowrap; font: inherit; font-size: .9rem; font-weight: 650; color: var(--ink);
       background: var(--surface-2); border: 1px solid var(--line); border-radius: 13px;
       transition: transform .12s ease, box-shadow .15s ease, border-color .15s ease, filter .15s ease; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(.98); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { color: #fff; background: var(--grad); border-color: transparent; box-shadow: 0 8px 18px -8px var(--accent); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.07); box-shadow: 0 10px 22px -8px var(--accent); }
.btn.ghost { background: none; color: var(--ink-2); }
.btn.danger { background: none; border-color: var(--bad); color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.big { padding: .9rem 1.7rem; font-size: 1rem; }
.tools { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1.4rem; padding-top: 1.1rem; border-top: 1px solid var(--line); }

.feedback { margin-top: .9rem; font-size: .92rem; border-radius: 14px; }
.feedback.ok, .feedback.bad, .feedback.warn { padding: .75rem .95rem; font-weight: 600; }
.feedback.ok { background: var(--ok-soft); color: var(--ok); }
.feedback.bad { background: var(--bad-soft); color: var(--bad); }
.feedback.warn { background: var(--warn-soft); color: var(--warn); }
.feedback .why { display: block; font-weight: 450; color: var(--ink-2); margin-top: .3rem; }
.xp-gain { float: right; font-weight: 800; }
.hint { margin-top: .6rem; padding: .7rem .9rem; font-size: .88rem; background: var(--accent-soft);
        border-left: 3px solid var(--accent); border-radius: 0 12px 12px 0; }
.steps { margin-top: .8rem; }
.step { display: flex; gap: .75rem; padding: .65rem 0; border-bottom: 1px dashed var(--line); }
.step:last-child { border-bottom: none; }
.step-n { flex: none; display: grid; place-items: center; width: 24px; height: 24px; margin-top: .1rem; border-radius: 50%;
          font-size: .72rem; font-weight: 800; color: #fff; background: var(--grad); }
.step-title { font-size: .85rem; color: var(--ink-2); }
.step-math { font-family: var(--mono); font-size: 1rem; font-weight: 600; margin-top: .15rem; }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-6px)} 40%{transform:translateX(6px)} 60%{transform:translateX(-4px)} 80%{transform:translateX(4px)} }
.shake { animation: shake .35s; }

/* ---------- equation lab (algebra) ---------- */
.lab-card { padding: 1.8rem; }
.scale { display: flex; align-items: stretch; gap: .8rem; }
.pan { flex: 1; min-width: 0; display: grid; place-items: center; text-align: center; padding: 1.5rem .8rem;
       background: var(--surface-2); border: 2px dashed var(--line); border-radius: 18px; }
.pan-eq { font-family: var(--mono); font-size: clamp(1.2rem, 4vw, 1.8rem); font-weight: 650; word-break: break-word; }
.equals { display: grid; place-items: center; font-family: var(--mono); font-size: 2.2rem; font-weight: 700; color: var(--accent); }
.lab-status { margin-top: 1rem; padding: .75rem .95rem; border-radius: 14px; background: var(--surface-2); color: var(--ink-2); font-size: .9rem; }
.lab-status.ok { background: var(--ok-soft); color: var(--ok); }
.lab-status.bad { background: var(--bad-soft); color: var(--bad); }
.lab-controls { display: flex; align-items: center; gap: .8rem; margin-top: 1.2rem; flex-wrap: wrap; }
.lab-k-label { font-size: .82rem; color: var(--ink-2); }
.lab-k { width: 78px; padding: .55rem; outline: none; text-align: center; font-family: var(--mono); font-size: 1.05rem; color: var(--ink);
         background: var(--surface-2); border: 2px solid var(--line); border-radius: 11px; }
.lab-k:focus { border-color: var(--accent); }
.op-grid { display: flex; gap: .4rem; flex-wrap: wrap; }
.btn.op { min-width: 62px; padding: .55rem .7rem; font-family: var(--mono); font-weight: 700; border-radius: 11px; }
.lab-foot { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--line); }
[data-course="algebra"] .lab-foot .btn.primary { margin-left: auto; }
.lab-foot .spacer { flex: 1; }
.lab-history { margin-top: 1rem; }
.lab-step { display: flex; align-items: baseline; gap: .8rem; padding: .45rem .9rem; border-bottom: 1px solid var(--line); font-size: .9rem; }
.lab-op { font-family: var(--mono); font-weight: 700; color: var(--accent); min-width: 62px; }
.lab-eq { font-family: var(--mono); color: var(--ink-2); }

/* ---------- growth lab (microbe) ---------- */
.lab-grid { display: grid; grid-template-columns: 250px 1fr; gap: 1.3rem; align-items: start; }
.dish { position: relative; aspect-ratio: 1; overflow: hidden; border-radius: 50%;
        background: radial-gradient(circle at 35% 30%, #fff8e1, #f3e3b3 70%, #e2cd8e);
        border: 6px solid color-mix(in srgb, var(--line) 60%, #cfe3e0); box-shadow: inset 0 0 0 3px rgba(255,255,255,.5), var(--shadow); }
.dish canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.dish.drugged { background: radial-gradient(circle at 35% 30%, #f1f7ff, #d5e6fb 70%, #b9d2f2); }
.lab-read { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-top: .9rem; }
.read { padding: .55rem .7rem; background: var(--surface-2); border-radius: 12px; }
.read b { display: block; font-family: var(--display); font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.read span { font-size: .68rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.read.s b { color: var(--accent); } .read.r b { color: var(--res); }
.chart-wrap { position: relative; padding: .6rem; background: var(--surface-2); border-radius: 16px; }
#chart { width: 100%; height: 280px; display: block; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; margin: .5rem .2rem 0; font-size: .8rem; color: var(--ink-2); }
.legend i { display: inline-block; width: 12px; height: 3px; margin-right: .35rem; border-radius: 2px; vertical-align: middle; }
.controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .9rem 1.2rem; margin-top: 1.3rem; }
.ctl label { display: flex; justify-content: space-between; margin-bottom: .25rem; font-size: .82rem; color: var(--ink-2); }
.ctl label b { color: var(--ink); font-variant-numeric: tabular-nums; }
.ctl input[type=range] { width: 100%; accent-color: var(--accent); }
.btn.drug.on { color: #fff; background: var(--bad); border-color: var(--bad); }
.lab-note { margin-top: 1rem; padding: .8rem 1rem; font-size: .88rem; color: var(--ink-2); background: var(--accent-soft); border-radius: 14px; }
.lab-note b { color: var(--ink); }

/* ---------- quiz ---------- */
.q-head { display: flex; justify-content: space-between; align-items: center; gap: .8rem; font-size: .85rem; }
.q-progress { height: 6px; margin: .7rem 0 1.2rem; overflow: hidden; background: var(--surface-2); border-radius: 99px; }
#q-progress { height: 100%; width: 0; background: var(--grad); border-radius: 99px; transition: width .35s ease; }
.score-row { display: flex; align-items: baseline; gap: 1rem; margin: .6rem 0; }
.score-big { font-family: var(--display); font-size: 3rem; font-weight: 700; letter-spacing: -.04em;
             background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.score-pct { font-size: 1.2rem; font-weight: 700; color: var(--muted); }
.review { margin: 1.2rem 0; }
.review-row { display: flex; gap: .75rem; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.review-i { flex: none; display: grid; place-items: center; width: 24px; height: 24px; margin-top: .1rem; border-radius: 50%;
            font-size: .72rem; font-weight: 800; color: #fff; }
.review-row.ok .review-i { background: var(--ok); } .review-row.bad .review-i { background: var(--bad); }
.review-body { min-width: 0; }
.review-q { font-size: .88rem; }
[data-course="algebra"] .review-q b { font-family: var(--mono); }
.review-a { font-size: .84rem; color: var(--ink-2); margin-top: .2rem; }
.review-a b { color: var(--ink); }
[data-course="algebra"] .review-a b { font-family: var(--mono); }

/* ---------- progress ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; }
.stat-card { position: relative; overflow: hidden; padding: 1.2rem; background: var(--surface);
             border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat-card::before { content: ""; position: absolute; width: 90px; height: 90px; right: -30px; top: -30px; border-radius: 50%;
                     background: var(--accent-soft); }
.stat-num { position: relative; font-family: var(--display); font-size: 2rem; font-weight: 700; letter-spacing: -.04em; }
.stat-lbl { position: relative; color: var(--muted); font-size: .8rem; font-weight: 600; }
.mastery-bars, .quiz-history { overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.quiz-history { padding: .3rem 1.1rem; }
.mrow { display: grid; grid-template-columns: minmax(150px, 1.4fr) 3fr auto auto; gap: .8rem; align-items: center;
        padding: .75rem 1.1rem; border-bottom: 1px solid var(--line); font-size: .87rem; }
.mrow:last-child { border-bottom: none; }
.mrow-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mbar { height: 8px; overflow: hidden; background: var(--surface-2); border-radius: 99px; }
.mbar-fill { height: 100%; border-radius: 99px; background: var(--grad); transition: width .6s ease; }
.mbar-fill.lv1 { background: var(--lv1); } .mbar-fill.lv2 { background: var(--lv2); } .mbar-fill.lv3 { background: var(--lv3); }
.mrow-pct { min-width: 40px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.mrow-sub { min-width: 48px; text-align: right; color: var(--muted); font-size: .78rem; }
.qh-row { display: flex; justify-content: space-between; padding: .55rem 0; border-bottom: 1px solid var(--line); font-size: .87rem; }
.qh-row:last-child { border-bottom: none; }
.qh-score { font-family: var(--mono); font-weight: 700; }
.warn-note { padding: .75rem .95rem; font-size: .87rem; color: var(--warn); background: var(--warn-soft); border-radius: 12px; }
#reset-btn { margin-top: 1.6rem; }

/* ---------- modal (lessons, the XP promo) ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: none; }
.modal.open { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(8,10,18,.55); backdrop-filter: blur(6px); }
.modal-box { position: relative; display: flex; flex-direction: column; max-width: 680px; max-height: 92vh; margin: 4vh auto;
             background: var(--surface); border: 1px solid var(--line); border-radius: 24px; box-shadow: 0 30px 70px rgba(0,0,0,.32); }
.modal.open .modal-box { animation: pop .22s cubic-bezier(.2,.9,.3,1.2) both; }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; gap: .8rem; padding: 1.15rem 1.4rem; border-bottom: 1px solid var(--line); }
.modal-head h2 { flex: 1; margin: 0; font-size: 1.2rem; }
.modal-body { padding: 1.4rem; overflow-y: auto; }
.modal-body p { margin: .7rem 0; }
.modal-body ul, .modal-body ol { padding-left: 1.3rem; margin: .6rem 0; }
.modal-body li { margin: .3rem 0; }
.modal-foot { padding: 1rem 1.4rem; border-top: 1px solid var(--line); }
.worked, .box { margin: 1rem 0; padding: .95rem 1.15rem; background: var(--surface-2); border-radius: 16px; }
.worked-title, .box-title { margin-bottom: .3rem; font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.worked .mono { font-size: 1.05rem; font-weight: 600; }
.formula { padding: .85rem; text-align: center; font-family: var(--mono); font-size: 1.05rem; font-weight: 600; background: var(--surface-2); border-radius: 14px; }
.warn { padding: .7rem .9rem; font-size: .9rem; color: var(--warn); background: var(--warn-soft); border-radius: 12px; }
.modal-body .warn code { background: rgba(0,0,0,.08); }
.rules { width: 100%; margin: .8rem 0; border-collapse: collapse; font-size: .89rem; }
.rules th, .rules td { padding: .45rem .6rem; text-align: left; border-bottom: 1px solid var(--line); }
.rules th { color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; }
.rules .mono { font-weight: 600; }
.keys { margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.keys-title { font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.keys ul { margin: .4rem 0 0; }

/* ---------- toast ---------- */
.toast { position: fixed; left: calc(50% + var(--side) / 2); bottom: 1.5rem; z-index: 80; transform: translate(-50%, 150%);
         padding: .7rem 1.25rem; white-space: nowrap; pointer-events: none; font-size: .88rem; font-weight: 700;
         color: var(--bg); background: var(--ink); border-radius: 999px; box-shadow: 0 10px 28px rgba(0,0,0,.25);
         transition: transform .3s cubic-bezier(.2,.9,.3,1.3); }
.toast.show { transform: translate(-50%, 0); }
.toast:empty { display: none; }   /* an empty pill is too short to slide fully out of view */
.toast.ok { color: #fff; background: var(--ok); }
.toast.bad { color: #fff; background: var(--bad); }

.foot { max-width: 1000px; margin: 0 auto; padding: 0 2rem 2.5rem; text-align: center; color: var(--muted); font-size: .8rem; }
.foot a:hover { color: var(--accent) !important; }

/* ---------- narrow: top bar + bottom tabs ---------- */
@media (max-width: 960px) {
  body { padding-left: 0; padding-bottom: 76px; }
  /* No backdrop-filter here: it would make the fixed bottom tabs position against the header instead of the screen. */
  .chrome { position: sticky; inset: auto; top: 0; width: auto; display: block; padding: .65rem 1rem; overflow: visible;
            background: var(--surface); backdrop-filter: none; -webkit-backdrop-filter: none;
            border-right: 0; border-bottom: 1px solid var(--line); }
  .topbar { flex-direction: row; align-items: center; justify-content: space-between; gap: .8rem; flex-wrap: wrap; }
  .brand { padding: 0; font-size: 1rem; }
  .brand-mark { width: 34px; height: 34px; border-radius: 11px; font-size: 1.05rem; }
  .stats { display: flex; align-items: center; gap: .4rem; }
  .stat { flex-direction: row; align-items: baseline; gap: .35rem; padding: .3rem .6rem; }
  .stat b { font-size: .95rem; }
  #rank-label { flex-direction: column; gap: 0; }
  .rank-bar { width: 70px; margin-top: 2px; }
  .stats .adxp-btn { height: 34px; }
  #theme-btn { position: static; width: 34px; height: 34px; }
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; flex-direction: row; gap: 0;
          padding: .35rem .3rem calc(.35rem + env(safe-area-inset-bottom));
          background: color-mix(in srgb, var(--surface) 92%, transparent);
          backdrop-filter: saturate(1.4) blur(16px); -webkit-backdrop-filter: saturate(1.4) blur(16px);
          border-top: 1px solid var(--line); }
  .tab { flex: 1; flex-direction: column; gap: .15rem; padding: .3rem .1rem; font-size: .66rem; text-align: center; overflow: hidden; }
  .tab-t { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .tab-i { width: 34px; height: 26px; border-radius: 99px; background: none; }
  .tab:hover, .tab.active { background: none; }
  .tab.active .tab-i { box-shadow: none; }
  main { padding: 1.5rem 1.1rem 2.5rem; }
  .toast { left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); }
  .lab-grid { grid-template-columns: 1fr; }
  .dish { max-width: 250px; margin: 0 auto; }
}
@media (max-width: 620px) {
  .topbar { row-gap: .55rem; }
  .stats { width: 100%; }
  .stat { flex: 1; justify-content: center; }
  .stat-k { font-size: .58rem; }
  .rank-bar { width: 100%; }
  .hero { padding: 1.6rem 1.35rem; border-radius: 22px; }
  .hero-glyphs { display: none; }
  .card { padding: 1.25rem; }
  .mrow { grid-template-columns: 1fr auto; row-gap: .35rem; }
  .mrow .mbar { grid-column: 1 / -1; order: 3; }
  [data-course="algebra"] .lab-foot .btn.primary { margin-left: 0; width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
