/* ==========================================================================
   BESS Lab — shared styles (OptiLab look: light, calm, academic, playful)
   Colour always carries a meaning:
   blue = primary/action/charge · green = correct/success · amber = sliders, labs, energy
   red = errors/danger · teal = ions/constraints · purple = special quantities
   ========================================================================== */

:root {
  --bg: #f7f8fb;
  --bg-2: #eef1f5;        /* hover / track */
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --line: #e5e7eb;
  --line-2: #cbd5e1;
  --grid: #eef2f7;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #64748b;

  --accent: #2563eb;      /* blue: primary */
  --accent-soft: #eff6ff;
  --accent-ink: #ffffff;
  --green: #16a34a;
  --green-soft: #f0fdf4;
  --warn: #d97706;        /* amber */
  --warn-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --ion: #0d9488;         /* teal */
  --electron: #d97706;    /* amber: electrons / energy */
  --violet: #7c3aed;
  --pink: #db2777;

  --r: 14px;
  --r-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .05);
  --f-head: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --f-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--f-body); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--f-mono); font-size: .92em; }
code { background: var(--bg-2); border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; }
h1, h2, h3, h4 { font-family: var(--f-head); line-height: 1.2; letter-spacing: -.01em; margin: 0 0 .5em; color: var(--text); }
h1 { font-size: clamp(1.75rem, 3vw, 2.4rem); font-weight: 800; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
h4 { font-size: .95rem; font-weight: 700; }
p { margin: 0 0 .9em; }
ul, ol { padding-left: 1.3em; margin: 0 0 1em; }
li { margin: .2em 0; }
strong { font-weight: 600; color: var(--text); }
small, .small { font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: #dbeafe; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; height: 56px; display: flex; align-items: center; gap: 12px;
  padding: 0 18px; background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--accent); color: #fff; font: 800 15px var(--f-head); }
.brand-name { font: 800 19px var(--f-head); letter-spacing: -.01em; }
.crumbs { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 12px; border-left: 1px solid var(--line); }
.crumbs a { color: var(--muted); }
.crumbs b { color: var(--text); font-weight: 500; }
.topbar .spacer { flex: 1; }
.read-progress { position: absolute; left: 0; bottom: -1px; height: 2px; background: var(--accent); width: 0; }
.icon-btn {
  height: 36px; min-width: 36px; padding: 0 10px; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: #fff; color: var(--text); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: 500 13px var(--f-body);
}
.icon-btn:hover { background: var(--bg-2); }
@media (max-width: 520px) { .crumbs { display: none; } }

/* ---------- Side menu (slides in on hover / button, can be pinned) ---------- */
.sidebar {
  position: fixed; top: 56px; left: 0; bottom: 0; width: 300px; z-index: 25; overflow-y: auto;
  background: #fff; border-right: 1px solid var(--line); box-shadow: var(--shadow);
  padding: 14px 12px 24px; display: flex; flex-direction: column; gap: 16px;
  transform: translateX(-102%); transition: transform .22s ease; scrollbar-width: thin;
}
body.nav-open .sidebar, body.nav-pinned .sidebar { transform: none; }
body.nav-pinned .sidebar { box-shadow: none; }
.nav-hotzone { position: fixed; top: 56px; left: 0; bottom: 0; width: 10px; z-index: 24; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 0 6px; }
.side-top span { font: 600 12px var(--f-body); color: var(--muted); }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch i { width: 30px; height: 18px; border-radius: 99px; background: var(--line-2); position: relative; transition: background .2s; flex: none; }
.switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(15, 23, 42, .25); transition: transform .2s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(12px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }
.side-group h4 { font: 600 11px var(--f-body); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 0 8px 6px; }
.side-list { list-style: none; margin: 0; padding: 0; }
.side-list li { margin: 0; }
.side-link { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 6px; padding: 7px 8px; border-radius: var(--r-sm); color: var(--text-2); font-size: 14px; line-height: 1.3; }
.side-link:hover { background: var(--bg-2); text-decoration: none; color: var(--text); }
.side-link .num { font: 600 12px var(--f-mono); color: var(--muted); }
.side-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-link.active .num { color: var(--accent); }
.side-link.soon { opacity: .6; cursor: default; }
.side-link.soon:hover { background: none; color: var(--text-2); }
.pill-soon { font: 600 10px var(--f-body); letter-spacing: .04em; text-transform: uppercase; background: var(--bg-2); border-radius: 99px; padding: 2px 7px; color: var(--muted); }
.side-toc { list-style: none; margin: 2px 0 8px 20px; padding: 0 0 0 10px; border-left: 2px solid var(--accent-soft); }
.side-toc a { display: block; font-size: 13px; color: var(--muted); padding: 3px 6px; border-radius: 6px; line-height: 1.35; }
.side-toc a:hover { color: var(--text); text-decoration: none; background: var(--bg-2); }
.side-toc a.on { color: var(--accent); font-weight: 500; }

/* ---------- Main column ---------- */
.main { min-width: 0; overflow-x: clip; transition: padding-left .22s ease; }
@media (min-width: 1100px) { body.nav-pinned .main { padding-left: 300px; } }
.page { max-width: 1320px; margin: 0 auto; padding: 22px; display: flex; flex-direction: column; gap: 18px; }
.page > * { margin-top: 0; margin-bottom: 0; }
@media (max-width: 520px) { .page { padding: 14px; gap: 14px; } }

/* ---------- Page header ---------- */
.mod-head { padding: 6px 2px 0; }
.eyebrow { font: 600 13px var(--f-body); color: var(--accent); margin-bottom: 6px; }
.mod-head h1 { margin-bottom: 8px; }
.mod-head h1 .pg { color: var(--muted); font-weight: 500; }
.lede { font-size: 16px; color: var(--text-2); max-width: 820px; margin-bottom: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip { font-size: 13px; color: var(--text-2); border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 3px 10px; }
.chip b { color: var(--accent); font-weight: 600; }

/* ---------- Cards (sections) ---------- */
.card-box, .section { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px 18px; }
.section > h2 { display: flex; align-items: baseline; gap: 10px; font-size: 16px; font-weight: 700; margin: 0 0 12px; }
.section > h2 .sn { font: 600 13px var(--f-mono); color: #fff; background: var(--accent); border-radius: 7px; padding: 1px 7px; }
.section h3 { margin-top: 1.1em; }
.section > :last-child { margin-bottom: 0; }
.prose { max-width: 860px; color: var(--text-2); }
.two-col { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 22px; align-items: start; }
@media (max-width: 820px) { .two-col { grid-template-columns: 1fr !important; } }

/* Idea card */
.idea { background: linear-gradient(180deg, var(--accent-soft), #fff 70%); border: 1px solid #dbeafe; border-radius: var(--r); box-shadow: var(--shadow); padding: 16px 18px; display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 20px; }
.idea h2 { font-size: 16px; color: var(--accent); margin-bottom: 6px; }
.idea p { color: var(--text-2); }
.idea ul { margin: 0; color: var(--text-2); }
.idea li::marker { color: var(--accent); }
.keyf { background: #fff; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 14px; align-self: start; }
.keyf .kt { font: 600 11px var(--f-body); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.keyf .katex-display { margin: .3em 0; }
.keyf .kl { font-size: 13px; color: var(--muted); }
@media (max-width: 820px) { .idea { grid-template-columns: 1fr; } }

/* Callouts: info (default), good (.key), warn, bad */
.callout { border: 1px solid #bfdbfe; background: var(--accent-soft); border-radius: var(--r-sm); padding: 11px 14px; margin: 0 0 1em; font-size: 14px; color: var(--text-2); }
.callout.key, .callout.good { border-color: #bbf7d0; background: var(--green-soft); }
.callout.warn { border-color: #fde68a; background: var(--warn-soft); }
.callout.bad { border-color: #fecaca; background: var(--danger-soft); }
.callout .ct { display: block; font: 600 12px var(--f-body); letter-spacing: .04em; text-transform: uppercase; color: var(--accent); margin-bottom: 2px; }
.callout.key .ct, .callout.good .ct { color: var(--green); }
.callout.warn .ct { color: var(--warn); }
.callout.bad .ct { color: var(--danger); }

.eq { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 16px; margin: 0 0 1em; overflow-x: auto; }
.eq .katex-display { margin: .3em 0; }
.eq-legend { font-size: 13px; color: var(--muted); margin-top: 4px; }
.eq-legend span { margin-right: 14px; display: inline-block; }

.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-sm); margin: 0 0 1em; background: #fff; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--text-2); background: var(--bg-2); white-space: nowrap; }
td { color: var(--text-2); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-family: var(--f-mono); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin: 0 0 1em; }
.card { border: 1px solid var(--line); background: #fff; border-radius: var(--r-sm); padding: 12px 14px; }
.card h4 { font-size: 15px; margin-bottom: 4px; }
.card p { font-size: 13.5px; color: var(--text-2); margin: 0; }
.card .tag { display: inline-block; font: 600 11px var(--f-body); letter-spacing: .06em; text-transform: uppercase; color: var(--accent); margin-bottom: 4px; }

.figure { margin: 0 0 1em; border: 1px solid var(--line); background: #fff; border-radius: var(--r-sm); padding: 12px; }
.figure figcaption { font-size: 13px; color: var(--muted); margin-top: 8px; }

/* ---------- Explainer (auto-looping, no controls) ---------- */
.explainer { background: #fff; border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; position: relative; }
.ex-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; }
.ex-stage { position: relative; background: linear-gradient(180deg, #fbfcfe, #f3f6fa); aspect-ratio: 16 / 8; }
.ex-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.ex-caption { padding: 20px 22px; border-left: 1px solid var(--line); display: flex; flex-direction: column; justify-content: center; }
.ex-kicker { font: 600 12px var(--f-body); color: var(--warn); margin-bottom: 6px; }
.ex-caption h3 { font-size: 18px; font-weight: 800; margin: 0 0 8px; }
.ex-caption p { color: var(--text-2); font-size: 14px; margin: 0; }
.ex-text { transition: opacity .35s ease, transform .35s ease; }
.ex-text.fade { opacity: 0; transform: translateY(6px); }
.ex-dots { position: absolute; left: 14px; bottom: 10px; display: flex; gap: 6px; }
.ex-dot { width: 34px; height: 14px; border: 0; padding: 0; background: none; cursor: pointer; position: relative; }
.ex-dot::before { content: ""; position: absolute; left: 0; right: 0; top: 5px; height: 4px; border-radius: 4px; background: rgba(15, 23, 42, .12); }
.ex-dot i { position: absolute; left: 0; top: 5px; height: 4px; border-radius: 4px; background: var(--warn); width: 0; }
.ex-dot.done i { width: 100%; }
.ex-paused { position: absolute; right: 12px; bottom: 8px; font: 600 11px var(--f-body); color: var(--muted); opacity: 0; transition: opacity .2s; }
.explainer:hover .ex-paused { opacity: 1; }
@media (max-width: 1100px) {
  .ex-grid { grid-template-columns: 1fr; }
  .ex-caption { border-left: 0; border-top: 1px solid var(--line); min-height: 150px; }
}

/* ---------- Interactive labs ("game cards") ---------- */
.lab { border: 1px solid #fcd34d; border-radius: var(--r); background: linear-gradient(180deg, var(--warn-soft), #fff 140px); margin: 4px 0 1em; box-shadow: var(--shadow); }
.page > .lab { margin: 0; }
.lab-head { padding: 14px 18px 10px; display: flex; flex-direction: column; }
.lab-tag { display: inline-flex; gap: 6px; align-items: center; font: 600 12px var(--f-body); color: var(--warn); margin-bottom: 2px; }
.lab-tag::before { content: "▶"; font-size: 9px; }
.lab-head h3 { margin: 0 0 2px; font-size: 16px; }
.lab-head p { margin: 0; font-size: 13.5px; color: var(--text-2); }
.lab-body { padding: 6px 18px 18px; }
.lab-grid { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 18px; }
@media (max-width: 1100px) { .lab-grid { grid-template-columns: 1fr; } }
.controls { display: flex; flex-direction: column; gap: 12px; }
.ctl label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13.5px; color: var(--text-2); margin-bottom: 3px; }
.ctl output, .ctl .val { font: 600 13px var(--f-mono); color: var(--text); }
input[type=range] { width: 100%; accent-color: var(--warn); }
select, input[type=number], input[type=text] {
  width: 100%; padding: 7px 10px; border-radius: 7px; border: 1px solid var(--line-2); background: #fff; color: var(--text); font: 400 14px var(--f-body);
}
input[type=number], input[type=text] { font-family: var(--f-mono); text-align: right; }
select:focus, input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .18); }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: #fff; color: var(--text); cursor: pointer; font: 600 14px var(--f-body); text-decoration: none;
}
.btn:hover { background: var(--bg-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 2px; background: var(--bg-2); border-radius: var(--r-sm); padding: 3px; }
.seg button { border: 0; background: transparent; color: var(--text-2); padding: 6px 12px; border-radius: 8px; cursor: pointer; font: 500 13.5px var(--f-body); }
.seg button.on { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(15, 23, 42, .08), 0 1px 6px rgba(15, 23, 42, .06); }
.readouts { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.readout { background: #fff; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 12px; display: flex; flex-direction: column-reverse; justify-content: flex-end; }
.readout span { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.readout b { display: block; font: 600 20px var(--f-mono); color: var(--text); line-height: 1.2; }
.readout b small { font-size: 12px; color: var(--muted); font-weight: 400; }
.canvas-box { position: relative; background: #fff; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.canvas-box canvas { display: block; width: 100%; height: 100%; }
.chart-box { position: relative; height: 340px; background: #fff; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px; }
.hint { font-size: 13px; color: var(--muted); }
.toggle-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tchip { border: 1px solid var(--line); background: #fff; color: var(--text-2); border-radius: 99px; padding: 4px 10px; font: 500 13px var(--f-body); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.tchip:hover { background: var(--bg-2); }
.tchip i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.tchip.off { opacity: .45; }

/* ---------- Worked examples (hand calculation) ---------- */
.worked { border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff; padding: 14px 16px; margin: 0 0 12px; }
.worked:last-child { margin-bottom: 0; }
.worked-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.worked-head .badge { font: 600 12px var(--f-body); color: var(--violet); }
.worked-head h3 { margin: 0; font-size: 15px; }
.worked .problem { color: var(--text-2); }
.worked .steps { counter-reset: step; list-style: none; padding: 0; margin: 0 0 10px; }
.worked .steps li { counter-increment: step; position: relative; padding: 9px 12px 9px 42px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--panel-2); margin: 7px 0; color: var(--text-2); animation: rise .35s ease; }
.worked .steps li::before { content: counter(step); position: absolute; left: 12px; top: 9px; width: 21px; height: 21px; border-radius: 50%; background: var(--violet); color: #fff; font: 600 12px var(--f-mono); display: grid; place-items: center; }
.worked .steps li.hidden, .worked .answer.hidden { display: none; }
.worked .answer { border: 1px solid #bbf7d0; background: var(--green-soft); border-radius: var(--r-sm); padding: 10px 14px; color: var(--text); animation: rise .35s ease; }
.worked .w-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* ---------- Check yourself (quiz) ---------- */
.quiz-top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.quiz-score { font: 600 14px var(--f-mono); color: var(--green); }
.qcard { border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff; padding: 14px 16px; margin-bottom: 10px; }
.qcard:last-child { margin-bottom: 0; }
.qcard .qn { font: 600 12px var(--f-body); color: var(--muted); margin-bottom: 4px; display: flex; gap: 8px; }
.qcard .qn .qt { color: var(--accent); }
.qcard .qq { font-weight: 500; margin-bottom: 10px; }
.qopts { display: grid; gap: 7px; }
.qopt { text-align: left; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: var(--r-sm); padding: 8px 12px; cursor: pointer; font: 400 14px var(--f-body); }
.qopt:hover:not(:disabled) { background: var(--bg-2); border-color: var(--line-2); }
.qopt.right { border-color: var(--green); background: var(--green-soft); }
.qopt.wrong { border-color: var(--danger); background: var(--danger-soft); }
.qopt:disabled { cursor: default; }
.qnum { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.qnum input { max-width: 170px; }
.qfb { margin-top: 10px; font-size: 14px; color: var(--text-2); border-radius: var(--r-sm); padding: 9px 12px; background: var(--panel-2); border: 1px solid var(--line); display: none; }
.qfb.show { display: block; animation: rise .3s ease; }
.qfb b.ok { color: var(--green); }
.qfb b.no { color: var(--danger); }

/* ---------- Pager ---------- */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pager a, .pager span { border: 1px solid var(--line); border-radius: var(--r); padding: 12px 16px; background: #fff; color: var(--text); display: block; box-shadow: var(--shadow); font-weight: 600; }
.pager a:hover { border-color: var(--accent); text-decoration: none; color: var(--accent); }
.pager small { display: block; color: var(--muted); font-size: 12px; font-weight: 500; }
.pager .next { text-align: right; }
.pager span { opacity: .55; box-shadow: none; }
.pager span:empty { visibility: hidden; }
@media (max-width: 520px) { .pager { grid-template-columns: 1fr; } }

/* ---------- Home ---------- */
.hero { position: relative; border-radius: var(--r); overflow: hidden; border: 1px solid var(--line); background: #fff; min-height: 380px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); box-shadow: var(--shadow); }
.hero-copy { padding: clamp(20px, 4vw, 44px); display: flex; flex-direction: column; justify-content: center; }
.hero-copy .eyebrow { margin-bottom: 10px; }
.hero-3d { position: relative; min-height: 340px; background: linear-gradient(180deg, #f8fafc, #eef2f7); border-left: 1px solid var(--line); }
.hero-3d canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
@media (max-width: 820px) { .hero { grid-template-columns: 1fr; } .hero-3d { min-height: 260px; border-left: 0; border-top: 1px solid var(--line); } }
.mod-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.mod-card { border: 1px solid var(--line); background: #fff; border-radius: var(--r); padding: 14px 16px; display: flex; flex-direction: column; gap: 5px; color: var(--text); transition: transform .15s ease, border-color .15s ease; min-height: 140px; box-shadow: var(--shadow); }
a.mod-card:hover { transform: translateY(-2px); border-color: var(--accent); text-decoration: none; }
.mod-card .mn { font: 600 12px var(--f-mono); color: var(--accent); display: flex; justify-content: space-between; align-items: center; }
.mod-card h3 { font-size: 16px; margin: 0; }
.mod-card p { font-size: 13px; color: var(--muted); margin: 0; }
.mod-card.soon { opacity: .65; box-shadow: none; }
.mod-card .score { font-size: 12px; color: var(--green); margin-top: auto; font-weight: 600; }
.steps-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.lvl { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }

.foot { padding: 6px 2px 20px; font-size: 13px; color: var(--muted); }

/* Tooltip */
.tip { position: absolute; pointer-events: none; background: #fff; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 10px; font-size: 13px; color: var(--text); box-shadow: var(--shadow); z-index: 5; max-width: 250px; display: none; }
.tip b { color: var(--accent); }

/* 3D viewers */
.three-box { position: relative; border-radius: var(--r-sm); overflow: hidden; border: 1px solid var(--line); background: linear-gradient(180deg, #f8fafc, #e9eef5); }
.three-box canvas { display: block; width: 100%; height: 100%; }
.three-hud { position: absolute; right: 10px; top: 10px; text-align: right; font: 600 12px var(--f-mono); color: var(--text-2); background: rgba(255, 255, 255, .9); border: 1px solid var(--line); padding: 8px 10px; border-radius: var(--r-sm); box-shadow: var(--shadow); z-index: 2; }
.three-hud .big { font-size: 22px; color: var(--accent); }
.three-note { position: absolute; left: 10px; bottom: 8px; font-size: 12px; color: var(--muted); z-index: 2; }
.lbl3d { font: 600 11px var(--f-body); color: var(--text); background: rgba(255, 255, 255, .92); border: 1px solid var(--line); padding: 2px 7px; border-radius: 6px; white-space: nowrap; box-shadow: 0 1px 2px rgba(15, 23, 42, .06); }

/* ---------- Chemistry cards (Module 2) ---------- */
.chem { border: 1px solid var(--line); background: #fff; border-radius: var(--r-sm); padding: 14px 16px; margin: 0 0 12px; }
.chem.star { border-color: #93c5fd; background: linear-gradient(180deg, var(--accent-soft), #fff 120px); }
.chem-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.chem-head h3 { margin: 0; font-size: 16px; }
.chem-head .fam { font: 600 12px var(--f-body); color: var(--ion); }
.chem-head .star-badge { font: 600 11px var(--f-body); color: #fff; background: var(--accent); padding: 2px 8px; border-radius: 99px; }
.spec-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin: 8px 0 10px; }
.spec { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; display: flex; flex-direction: column-reverse; justify-content: flex-end; }
.spec span { display: block; font-size: 12px; color: var(--muted); }
.spec b { display: block; font: 600 14px var(--f-mono); color: var(--text); }
.pc { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; font-size: 13.5px; color: var(--text-2); }
.pc h5 { margin: 0 0 3px; font: 600 12px var(--f-body); text-transform: uppercase; letter-spacing: .04em; }
.pc .pro h5 { color: var(--green); }
.pc .con h5 { color: var(--danger); }
.pc ul { margin: 0; padding-left: 1.1em; }
.chem .rx { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 12px; overflow-x: auto; margin-bottom: 8px; }
.chem .apps { font-size: 13px; color: var(--muted); margin-top: 8px; }
.chem .apps b { color: var(--text-2); }
@media (max-width: 820px) { .pc { grid-template-columns: 1fr; } }
tr.sel td { background: var(--accent-soft); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--bg-2); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.stackbar { display: flex; height: 26px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.stackbar div { display: grid; place-items: center; font: 600 12px var(--f-mono); color: #fff; transition: flex-grow .4s ease; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Step-by-step calculator (Module 10, capstone) ---------- */
.calc-steps { counter-reset: step; list-style: none; padding: 0; margin: 0; }
.calc-steps li { counter-increment: step; position: relative; padding: 9px 12px 9px 42px; border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff; margin: 7px 0; color: var(--text-2); overflow-x: auto; }
.calc-steps li::before { content: counter(step); position: absolute; left: 12px; top: 10px; width: 21px; height: 21px; border-radius: 50%; background: var(--warn); color: #fff; font: 600 12px var(--f-mono); display: grid; place-items: center; }
.calc-steps li .what { display: block; font-weight: 600; color: var(--text); margin-bottom: 2px; }
.calc-steps li .katex-display { margin: 4px 0; text-align: left; }
.calc-steps li .katex-display > .katex { text-align: left; }

/* ---------- Toolkit pages: glossary, formula sheet, capstone ---------- */
.tool-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; position: sticky; top: 56px; z-index: 5; background: var(--bg); padding: 10px 0; border-bottom: 1px solid var(--line); }
.tool-bar input[type=search] { flex: 1 1 260px; min-width: 0; padding: 10px 14px; border-radius: var(--r-sm); border: 1px solid var(--line-2); background: #fff; color: var(--text); font: 400 15px var(--f-body); }
.tool-bar input[type=search]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .18); }
.tool-bar .count { font: 600 13px var(--f-mono); color: var(--muted); }
.letters { display: flex; flex-wrap: wrap; gap: 4px; }
.letters button { min-width: 30px; padding: 4px 7px; border-radius: 7px; border: 1px solid var(--line); background: #fff; font: 600 13px var(--f-mono); color: var(--text-2); cursor: pointer; }
.letters button:hover { background: var(--bg-2); }
.letters button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.letters button:disabled { opacity: .35; cursor: default; }
.gl-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; margin: 0; }
.gl-letter { grid-column: 1 / -1; font: 800 24px var(--f-head); color: var(--accent); margin: 14px 0 0; scroll-margin-top: 130px; }
.gl-item { background: #fff; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 14px; }
.gl-item dt { font: 700 16px var(--f-head); color: var(--text); display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.gl-item dd { margin: 4px 0 0; color: var(--text-2); font-size: 14.5px; line-height: 1.5; }
.mref { font: 600 11px var(--f-mono); color: var(--accent); background: var(--accent-soft); border-radius: 99px; padding: 2px 8px; white-space: nowrap; text-decoration: none; }
.mref:hover { text-decoration: none; background: #dbeafe; }
mark { background: #fef3c7; color: inherit; padding: 0 1px; border-radius: 2px; }
.empty-note { color: var(--muted); padding: 20px 0; text-align: center; }
.fs-group { scroll-margin-top: 130px; }
.fs-group > h2 { display: flex; align-items: baseline; gap: 10px; }
.fs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px; }
.fs-card { background: #fff; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.fs-card h3 { font: 700 15px var(--f-head); margin: 0; color: var(--text); }
.fs-card .fx { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.fs-card .fx .katex-display { margin: 6px 0; }
.fs-card .sym { font-size: 13px; color: var(--muted); line-height: 1.45; }
@media (max-width: 520px) { .gl-list, .fs-grid { grid-template-columns: 1fr; } .tool-bar { top: 56px; } }
/* capstone */
.cap-steps { counter-reset: cap; display: grid; gap: 14px; }
.cap-step { scroll-margin-top: 80px; }
.cap-step > h2 .sn { background: var(--violet); }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.kv { background: #fff; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 12px; }
.kv span { display: block; font-size: 12px; color: var(--muted); }
.kv b { display: block; font: 600 17px var(--f-mono); color: var(--text); }
@media print { .sidebar, .topbar, .nav-hotzone, .explainer, .tool-bar, .controls, .pager { display: none !important; } .main { padding-left: 0 !important; } }

/* KaTeX's hidden MathML (for screen readers) is absolutely positioned; anchor it to its formula so it can't widen the page on phones */
.katex { position: relative; }
.katex .katex-mathml { left: 0; top: 0; }
.main { overflow-x: clip; }
