/* Mathcraft (forked from Cosmocraft, same brand) — layout: a reading column (~68ch) with full-bleed "lab bench" sims that break wider.
   Palette: the Eureka night. The accent token keeps the name --copper so shared code works, but here it is chalk teal;
   amber marks what is new, cyan and rose are the two "sides" in a lab (positive and negative, x and y). */
:root {
  --bg: #f2f4f8;
  --surface: #ffffff;
  --surface-2: #e9edf4;
  --ink: #131a2b;
  --muted: #586379;
  --line: #d6dce7;
  --copper: #0f8a78;
  --copper-soft: #dcf3ee;
  --electron: #0b84c6;
  --hole: #c2367a;
  --high: #e58a12;
  --high-glow: rgba(229, 138, 18, .35);
  --fire: #d9431e;
  --low: #8b95a8;
  --good: #1d8a4e;
  --good-soft: #dcf2e5;
  --bad: #c7353b;
  --bad-soft: #fbe2e3;
  --focus: #2b62d9;
  --shadow: 0 1px 2px rgba(19, 26, 43, .06), 0 6px 24px rgba(19, 26, 43, .06);

  --f-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --f-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  --step--1: .875rem;
  --step-0: 1.0625rem;
  --step-1: 1.25rem;
  --step-2: 1.6rem;
  --step-3: 2.2rem;
  --step-4: clamp(2.4rem, 6vw, 3.8rem);

  --radius: 10px;
  --col: 44rem;
  --wide: 62rem;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #070b16; --surface: #0e1424; --surface-2: #161e33; --ink: #f1ece3; --muted: #a3abc3; --line: #252e49;
    --copper: #5fdcc4; --copper-soft: #10302c; --electron: #4cc3f5; --hole: #f07ab3; --high: #ffb13d; --high-glow: rgba(255, 177, 61, .35); --fire: #ff6a3d;
    --low: #56617a; --good: #4cc884; --good-soft: #15301f; --bad: #ff6b70; --bad-soft: #3a1a1d; --focus: #7aa5ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 30px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #070b16; --surface: #0e1424; --surface-2: #161e33; --ink: #f1ece3; --muted: #a3abc3; --line: #252e49;
  --copper: #5fdcc4; --copper-soft: #10302c; --electron: #4cc3f5; --hole: #f07ab3; --high: #ffb13d; --high-glow: rgba(255, 177, 61, .35); --fire: #ff6a3d;
  --low: #56617a; --good: #4cc884; --good-soft: #15301f; --bad: #ff6b70; --bad-soft: #3a1a1d; --focus: #7aa5ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 30px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--f-body); font-size: var(--step-0); line-height: 1.6;
}
a { color: var(--copper); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3, h4 { font-family: var(--f-display); line-height: 1.15; text-wrap: balance; margin: 0; letter-spacing: -.01em; }
code, .mono, kbd { font-family: var(--f-mono); font-size: .9em; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { max-width: var(--wide); margin: 0 auto; padding: .6rem 16px; display: flex; align-items: center; gap: .75rem; }
.brand { display: flex; align-items: center; gap: .55rem; text-decoration: none; color: var(--ink); font-family: var(--f-display); font-weight: 700; font-size: 1.15rem; }
.brand-mark { fill: var(--copper); transition: transform .8s cubic-bezier(.3,1.4,.5,1); flex: none; }
.brand-mark circle { fill: var(--bg); }
.topbar .spacer { flex: 1; }
.xp-pill { font-family: var(--f-mono); font-size: var(--step--1); padding: .25rem .6rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); white-space: nowrap; }
.icon-btn { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .35rem .6rem; cursor: pointer; font-size: var(--step--1); white-space: nowrap; }
.icon-btn:hover { border-color: var(--copper); }
/* Language picker: shows the short code; the invisible native select on top opens the full list. */
.lang-pick { position: relative; display: inline-block; font-family: var(--f-mono); }
.lang-pick select { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; font-size: 16px; }
.lang-pick:focus-within { outline: 2px solid var(--copper); outline-offset: 2px; }
.nav-link { text-decoration: none; color: var(--muted); font-size: var(--step--1); font-weight: 700; }
.nav-link:hover, .nav-link[aria-current="page"] { color: var(--ink); }
@media (max-width: 520px) { .hide-sm { display: none; } .topbar-inner { gap: .5rem; } .topbar .icon-btn { padding-inline: .45rem; } }
/* Longer French labels: let the sign-in button wrap, and tighten the bar on the narrowest phones. */
@media (max-width: 520px) { .topbar .acct-btn { white-space: normal; max-width: 5.6rem; line-height: 1.15; } }
@media (max-width: 380px) { .topbar-inner { gap: .4rem; padding-inline: 12px; } .brand { font-size: 1rem; gap: .4rem; } .topbar .icon-btn { padding-inline: .35rem; } .topbar .acct-btn { max-width: 4.9rem; } .topbar-inner .nav-link { font-size: .8rem; } }
@media (max-width: 340px) { .brand-mark { display: none; } }

main { padding-inline: 16px; padding-block: 0 5rem; }
.col { max-width: var(--col); margin-inline: auto; }
.wide { max-width: var(--wide); margin-inline: auto; }

/* ---------- Home ---------- */
.hero { max-width: var(--wide); margin: 0 auto; padding-block: 3rem 2rem; display: grid; grid-template-columns: 1.1fr .9fr; gap: 2.5rem; align-items: center; }
@media (max-width: 820px) { .hero { grid-template-columns: 1fr; padding-block: 2rem 1rem; gap: 1.5rem; } }
.hero h1 { font-size: var(--step-4); font-weight: 800; letter-spacing: -.03em; }
.hero h1 em { font-style: normal; color: var(--copper); }
.hero p.lede { font-size: var(--step-1); color: var(--muted); max-width: 34rem; margin: 1rem 0 1.5rem; }
.eyebrow { font-family: var(--f-mono); font-size: .78rem; letter-spacing: .12em; text-transform: uppercase; color: var(--copper); font-weight: 600; }
.cta-row { display: flex; gap: .75rem; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; gap: .4rem; border-radius: 8px; padding: .65rem 1.1rem; font-weight: 700; cursor: pointer; text-decoration: none; border: 1px solid transparent; font-size: var(--step-0); }
.btn-primary { background: var(--ink); color: var(--bg); }
.btn-primary:hover { background: var(--copper); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--copper); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { padding: .35rem .7rem; font-size: var(--step--1); }

.byte-toy { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 1.25rem; box-shadow: var(--shadow); }
.byte-toy .label { font-size: var(--step--1); color: var(--muted); }
.switch-row { display: grid; grid-template-columns: repeat(8, 1fr); gap: .4rem; margin: .8rem 0; }
.bit-switch { aspect-ratio: 1 / 1.6; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; position: relative; display: grid; place-items: center; font-family: var(--f-mono); font-weight: 700; font-size: 1.1rem; color: var(--low); transition: background .15s, color .15s, box-shadow .15s; max-width: 100%; }
.bit-switch.on { background: var(--high); color: #1d1300; box-shadow: 0 0 18px var(--high-glow); border-color: var(--high); }
.bit-switch small { position: absolute; bottom: 4px; font-size: .62rem; font-weight: 500; color: inherit; opacity: .75; }
.readouts { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.readout { background: var(--surface-2); border-radius: 8px; padding: .5rem .6rem; min-width: 0; }
.readout b { display: block; font-family: var(--f-mono); font-size: 1.35rem; line-height: 1.2; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.readout span { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin: 2.5rem 0 1rem; }
.section-head h2 { font-size: var(--step-2); }
.section-head p { margin: 0; color: var(--muted); }

/* ---------- Course map ---------- */
.map { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 2rem; }
@media (max-width: 820px) { .map { grid-template-columns: 1fr; } }
.track-title { font-family: var(--f-mono); font-size: .78rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: .6rem; }
.trunk { position: relative; display: grid; gap: .5rem; }
.trunk::before { content: ""; position: absolute; left: 19px; top: 10px; bottom: 10px; width: 2px; background: repeating-linear-gradient(var(--copper) 0 6px, transparent 6px 10px); opacity: .5; }
.node { position: relative; display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: .75rem; align-items: center; text-decoration: none; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .8rem .6rem .5rem; transition: border-color .15s, transform .15s; }
.node:hover { border-color: var(--copper); transform: translateX(2px); }
.node .num { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-family: var(--f-mono); font-weight: 700; font-size: .85rem; background: var(--surface-2); border: 2px solid var(--line); margin-left: 4px; z-index: 1; }
.node.done .num { background: var(--high); border-color: var(--high); color: #1d1300; box-shadow: 0 0 10px var(--high-glow); }
.node.started .num { border-color: var(--high); }
.node h3 { font-size: 1.02rem; font-weight: 700; }
.node p { margin: 0; color: var(--muted); font-size: var(--step--1); line-height: 1.4; }
.node .meta { font-family: var(--f-mono); font-size: .72rem; color: var(--muted); white-space: nowrap; }
.node.soon { opacity: .55; pointer-events: none; }
.node.soon .meta { color: var(--copper); }
.branches { display: grid; gap: .75rem; align-content: start; }
.branch { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; }
.branch h3 { font-size: 1.05rem; display: flex; align-items: center; gap: .5rem; }
.branch .from { font-family: var(--f-mono); font-size: .72rem; color: var(--copper); }
.branch ul { margin: .4rem 0 0; padding-left: 1.1rem; color: var(--muted); font-size: var(--step--1); }
.branch .node { margin-top: .5rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--copper); display: inline-block; flex: none; }

/* ---------- Lesson page ---------- */
.lesson-head { max-width: var(--col); margin: 0 auto; padding-block: 2.5rem 1rem; }
.lesson-head h1 { font-size: var(--step-3); font-weight: 800; letter-spacing: -.02em; margin: .3rem 0 .6rem; }
.lesson-head .tagline { color: var(--muted); font-size: var(--step-1); margin: 0; }
.progress-track { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 1.25rem; }
.progress-track i { display: block; height: 100%; background: var(--high); width: 0; transition: width .4s; }
.lesson-tools { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: .9rem; font-size: var(--step--1); color: var(--muted); }
.toggle { display: inline-flex; align-items: center; gap: .45rem; cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--copper); width: 1rem; height: 1rem; }

.step { max-width: var(--col); margin: 0 auto; padding-block: 1.5rem; border-top: 1px solid var(--line); animation: rise .45s ease both; }
.step:first-of-type { border-top: 0; }
.step h2 { font-size: var(--step-2); margin-bottom: .75rem; display: flex; gap: .6rem; align-items: baseline; }
.step h2 .sn { font-family: var(--f-mono); font-size: .8rem; color: var(--copper); font-weight: 600; }
.step p { margin: .7rem 0; }
.step ul, .step ol { padding-left: 1.3rem; }
.step li { margin: .3rem 0; }
@keyframes rise { from { opacity: .001; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .step { animation: none; } * { transition: none !important; } }

.callout { border-radius: var(--radius); padding: .9rem 1.1rem; margin: 1rem 0; background: var(--surface); border: 1px solid var(--line); }
.callout > :first-child { margin-top: 0; }
.callout > :last-child { margin-bottom: 0; }
.callout .tag { font-family: var(--f-mono); font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; font-weight: 700; display: block; margin-bottom: .3rem; }
.callout.key { background: var(--copper-soft); border-color: transparent; }
.callout.key .tag { color: var(--copper); }
.callout.analogy .tag { color: var(--electron); }
.callout.myth .tag { color: var(--hole); }
details.deeper { border: 1px dashed var(--line); border-radius: var(--radius); margin: 1rem 0; background: var(--surface); }
details.deeper summary { cursor: pointer; padding: .7rem 1rem; font-weight: 700; font-size: var(--step--1); list-style: none; display: flex; align-items: center; gap: .5rem; color: var(--muted); }
details.deeper summary::-webkit-details-marker { display: none; }
details.deeper summary::before { content: "+"; font-family: var(--f-mono); width: 1.2rem; height: 1.2rem; display: grid; place-items: center; border-radius: 4px; background: var(--surface-2); color: var(--copper); }
details.deeper[open] summary::before { content: "−"; }
details.deeper .body { padding: 0 1rem .8rem; }
details.deeper .body > :first-child { margin-top: 0; }

/* Lab bench: sims break out wider than the text column */
.bench { max-width: var(--wide); margin: 1.25rem auto; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.step .bench { margin-inline: calc((min(var(--wide), 100vw - 32px) - min(var(--col), 100vw - 32px)) / -2); }
.bench-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .6rem 1rem; border-bottom: 1px solid var(--line); background: var(--surface-2); flex-wrap: wrap; }
.bench-head .title { font-family: var(--f-mono); font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; color: var(--muted); }
.bench-body { padding: 1rem; }
.bench canvas { display: block; width: 100%; border-radius: 8px; touch-action: pan-x pan-y; }
.canvas-scroll { overflow-x: auto; max-width: 100%; }
@media (max-width: 640px) { .canvas-scroll canvas { min-width: 580px; } }
.task { display: flex; gap: .6rem; align-items: flex-start; padding: .7rem 1rem; border-top: 1px solid var(--line); font-size: var(--step--1); background: var(--surface); }
.task .badge { flex: none; font-family: var(--f-mono); font-size: .7rem; font-weight: 700; padding: .15rem .45rem; border-radius: 4px; background: var(--surface-2); color: var(--muted); letter-spacing: .06em; }
.task.done .badge { background: var(--good); color: #fff; }
.task.done { background: var(--good-soft); }

.controls { display: flex; flex-wrap: wrap; gap: .75rem 1.25rem; align-items: center; margin-top: .8rem; }
.ctrl { display: grid; gap: .15rem; min-width: 10rem; flex: 1 1 10rem; }
.ctrl label { font-size: .78rem; color: var(--muted); display: flex; justify-content: space-between; gap: .5rem; }
.ctrl label b { font-family: var(--f-mono); color: var(--ink); font-weight: 600; }
input[type="range"] { width: 100%; accent-color: var(--copper); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button { background: var(--surface); border: 0; border-right: 1px solid var(--line); padding: .4rem .75rem; cursor: pointer; font-size: var(--step--1); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.stats { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
.stat { background: var(--surface-2); border-radius: 8px; padding: .35rem .7rem; font-size: .8rem; color: var(--muted); }
.stat b { font-family: var(--f-mono); color: var(--ink); font-variant-numeric: tabular-nums; margin-left: .3rem; }
.two-up { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; }
@media (max-width: 700px) { .two-up { grid-template-columns: 1fr; } }
.hint { font-size: .8rem; color: var(--muted); margin-top: .4rem; }

/* ---------- Quiz ---------- */
.quiz { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; margin: 1.25rem 0; }
.quiz .qtag { font-family: var(--f-mono); font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--copper); font-weight: 700; }
.quiz .q { font-weight: 700; margin: .25rem 0 .7rem; }
.choices { display: grid; gap: .45rem; }
.choice { text-align: left; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .55rem .8rem; cursor: pointer; display: flex; gap: .6rem; align-items: flex-start; line-height: 1.4; }
.choice:hover:not(:disabled) { border-color: var(--copper); }
.choice .k { font-family: var(--f-mono); font-size: .8rem; color: var(--muted); flex: none; padding-top: .1rem; }
.choice.right { border-color: var(--good); background: var(--good-soft); }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice:disabled { cursor: default; }
.feedback { margin-top: .7rem; font-size: var(--step--1); padding: .6rem .8rem; border-radius: 8px; }
.feedback.ok { background: var(--good-soft); }
.feedback.no { background: var(--bad-soft); }
.num-input { display: flex; gap: .5rem; flex-wrap: wrap; }
.num-input input { font: inherit; font-family: var(--f-mono); padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); width: 12rem; max-width: 100%; }

.continue-row { max-width: var(--col); margin: 0 auto; padding-block: 1rem 2rem; display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.continue-row .why { color: var(--muted); font-size: var(--step--1); }

/* Checkpoint */
.checkpoint { max-width: var(--col); margin: 1rem auto; border: 2px solid var(--ink); border-radius: 14px; padding: 1.25rem; background: var(--surface); }
.checkpoint h2 { font-size: var(--step-2); }
.score { font-family: var(--f-display); font-size: var(--step-3); font-weight: 800; }
.chapter-nav { max-width: var(--col); margin: 2rem auto 0; display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%) translateY(150%); background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; font-weight: 700; z-index: 50; transition: transform .3s; max-width: calc(100vw - 32px); }
.toast.show { transform: translateX(-50%) translateY(0); }

/* Tables */
.tbl-wrap { overflow-x: auto; margin: 1rem 0; }
table.tt { border-collapse: collapse; font-family: var(--f-mono); font-size: .9rem; }
table.tt th, table.tt td { border: 1px solid var(--line); padding: .3rem .7rem; text-align: center; }
table.tt th { background: var(--surface-2); font-weight: 700; }
table.tt tr.hl td { background: var(--copper-soft); }
table.tt td.v1 { color: var(--high); font-weight: 700; }
table.tt tr.pass td:last-child { color: var(--good); }
table.tt tr.fail td:last-child { color: var(--bad); }

.footer { max-width: var(--wide); margin: 4rem auto 0; padding-top: 1.5rem; border-top: 1px solid var(--line); color: var(--muted); font-size: var(--step--1); display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

/* misc sim bits */
.lamp-big { width: 64px; height: 64px; border-radius: 50%; background: var(--surface-2); border: 2px solid var(--ink); transition: background .15s, box-shadow .15s; }
.lamp-big.on { background: var(--high); box-shadow: 0 0 30px var(--high-glow); }
.text-input { font: inherit; padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); width: 100%; }
.text-input.mono { font-family: var(--f-mono); }

/* ---------- Motion ---------- */
.rv { opacity: 0; transform: translateY(16px); transition: opacity .6s ease, transform .6s cubic-bezier(.2,.7,.2,1); }
.rv.in { opacity: 1; transform: none; }
.choice.right { animation: pop .38s cubic-bezier(.3,1.6,.5,1); }
.choice.wrong { animation: shake .35s ease; }
.feedback { animation: rise .3s ease both; }
@keyframes pop { 0% { transform: scale(1); } 45% { transform: scale(1.035); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: none; } 20% { transform: translateX(-6px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
.task.just { animation: taskdone .9s ease; }
.task.just .badge { animation: pop .45s cubic-bezier(.3,1.6,.5,1); }
@keyframes taskdone { 0% { background: var(--surface); } 30% { background: var(--good-soft); box-shadow: inset 0 0 0 2px var(--good); } 100% { box-shadow: inset 0 0 0 0 transparent; } }
.continue-row .btn-primary:not(:disabled) { animation: ready 1.6s ease-in-out 3; }
@keyframes ready { 0%, 100% { box-shadow: 0 0 0 0 transparent; } 50% { box-shadow: 0 0 0 6px var(--copper-soft); } }
.xp-pill.bump { animation: xpbump .6s cubic-bezier(.3,1.6,.5,1); border-color: var(--high); }
@keyframes xpbump { 0% { transform: scale(1); } 35% { transform: scale(1.22); background: var(--high); color: #1d1300; } 100% { transform: scale(1); } }
.trunk .node, .branch { animation: rise .5s ease both; }
.trunk .node:nth-child(2) { animation-delay: .04s } .trunk .node:nth-child(3) { animation-delay: .08s } .trunk .node:nth-child(4) { animation-delay: .12s } .trunk .node:nth-child(5) { animation-delay: .16s } .trunk .node:nth-child(6) { animation-delay: .2s } .trunk .node:nth-child(7) { animation-delay: .24s } .trunk .node:nth-child(8) { animation-delay: .28s } .trunk .node:nth-child(9) { animation-delay: .32s } .trunk .node:nth-child(10) { animation-delay: .36s } .trunk .node:nth-child(11) { animation-delay: .4s }
.branch:nth-child(2) { animation-delay: .1s } .branch:nth-child(3) { animation-delay: .2s } .branch:nth-child(4) { animation-delay: .3s } .branch:nth-child(5) { animation-delay: .4s }
.score.count { font-variant-numeric: tabular-nums; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; width: 100%; height: 100%; }
.hero h1 em { background: linear-gradient(90deg, var(--copper), var(--high), var(--copper)); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 6s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  .rv { opacity: 1; transform: none; }
  .choice.right, .choice.wrong, .feedback, .task.just, .task.just .badge, .continue-row .btn-primary, .xp-pill.bump, .trunk .node, .branch, .hero h1 em { animation: none !important; }
}
.swipe-hint { font-size: .75rem; color: var(--copper); font-weight: 700; margin-bottom: .35rem; transition: opacity .4s; }
.swipe-hint.seen { opacity: .35; }
.canvas-scroll { scroll-snap-type: x proximity; }

/* ---------- Accounts ---------- */
.topbar-inner { position: relative; }
.acct-btn.in { width: 2rem; height: 2rem; padding: 0; border-radius: 50%; background: var(--copper); color: #fff; border-color: var(--copper); font-weight: 800; }
.acct-menu { position: absolute; right: 16px; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: .8rem; display: grid; gap: .5rem; min-width: 240px; max-width: calc(100vw - 32px); z-index: 40; animation: rise .2s ease both; }
.acct-email { font-weight: 700; overflow-wrap: anywhere; }
dialog.signin { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink); padding: 1.5rem; width: min(420px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog.signin::backdrop { background: rgba(10, 14, 24, .55); }
dialog.signin h2 { font-size: var(--step-2); margin-bottom: .3rem; }
dialog.signin form { display: grid; gap: .6rem; margin-top: 1rem; }
dialog.signin .or { text-align: center; color: var(--muted); font-size: var(--step--1); margin: .6rem 0; }
dialog.signin .btn { justify-content: center; }
dialog.signin .dlg-links { margin: .8rem 0 0; font-size: var(--step--1); color: var(--muted); text-align: center; }
.linkish { border: 0; background: none; padding: 0; color: var(--copper); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.dlg-x { position: absolute; right: .8rem; top: .7rem; border: 0; background: none; color: var(--muted); font-size: 1rem; cursor: pointer; }
.locked { max-width: var(--col); margin: 0 auto; padding-block: 4rem 3rem; display: grid; gap: .8rem; }
.locked h1 { font-size: var(--step-4); }
.lock-peek { border: 1px solid var(--line, rgba(255,255,255,.12)); border-radius: 14px; padding: 1rem 1.2rem; margin-top: .4rem; }
.lock-peek ol { margin: .2rem 0 0; padding: 0; list-style: none; display: grid; gap: .45rem; counter-reset: s; }
.lock-peek li { display: flex; gap: .6rem; align-items: baseline; opacity: .85; }
.lock-ic { font-size: .75em; opacity: .6; }
.lock-k { font-size: .75rem; letter-spacing: .14em; text-transform: uppercase; opacity: .7; margin: 0; }
.lock-sims { margin: .8rem 0 0; font-size: .92em; opacity: .8; }
.lock-price { font-size: .95em; opacity: .85; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .8rem; margin: 1rem 0 1.5rem; }
.stat-tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; display: grid; gap: .3rem; }
.stat-tile span { color: var(--muted); font-size: var(--step--1); }
.stat-tile b { font-family: var(--f-display); font-size: var(--step-3); font-variant-numeric: tabular-nums; }
.admin-table td { font-variant-numeric: tabular-nums; }
.meter { display: inline-block; width: 70px; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; vertical-align: middle; margin-right: .4rem; }
.meter i { display: block; height: 100%; background: var(--good); }

/* ---------- Enginecraft additions ---------- */
@media (max-width: 720px) { .hide-md { display: none; } }
.engine-toy .controls { margin-top: .6rem; }
.callout.safety { background: var(--bad-soft); border-color: transparent; }
.callout.safety .tag { color: var(--bad); }
.callout.history { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .9rem; align-items: start; border-left: 4px solid var(--copper); background: var(--surface); }
.callout.history .tag { color: var(--copper); }
.hist-year { font-family: var(--f-display); font-weight: 800; font-size: 1.35rem; line-height: 1.1; color: var(--copper); min-width: 4.2rem; padding-top: .1rem; }
.hist-who { display: block; font-family: var(--f-display); font-size: 1.05rem; margin-bottom: .15rem; }
@media (max-width: 480px) { .callout.history { grid-template-columns: 1fr; gap: .2rem; } }
.hist-strip { display: flex; gap: .5rem; overflow-x: auto; padding: .2rem .1rem .8rem; scroll-snap-type: x proximity; }
.hist-chip { flex: none; display: grid; gap: .1rem; min-width: 8.5rem; max-width: 11rem; padding: .6rem .75rem; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--ink); scroll-snap-align: start; transition: border-color .15s, transform .15s; }
.hist-chip:hover { border-color: var(--copper); transform: translateY(-2px); }
.hist-chip b { font-family: var(--f-display); color: var(--copper); font-size: 1.1rem; }
.hist-chip span { font-size: .8rem; color: var(--muted); line-height: 1.3; }
.timeline { list-style: none; padding: 0; margin: 1.5rem 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 5.6rem; top: .5rem; bottom: .5rem; width: 2px; background: repeating-linear-gradient(var(--copper) 0 6px, transparent 6px 10px); opacity: .5; }
.timeline li { display: grid; grid-template-columns: 5rem minmax(0, 1fr); gap: 1.4rem; margin-bottom: .9rem; position: relative; animation: rise .5s ease both; }
.timeline li::before { content: ""; position: absolute; left: calc(5.6rem - 5px); top: .55rem; width: 12px; height: 12px; border-radius: 50%; background: var(--copper); box-shadow: 0 0 0 4px var(--bg); }
.timeline li.ahead { opacity: .5; }
.timeline li.ahead::before { background: var(--low); }
.tl-year { font-family: var(--f-display); font-weight: 800; font-size: 1.05rem; color: var(--copper); text-align: right; padding-top: .2rem; }
.tl-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .9rem; }
.tl-card b { font-family: var(--f-display); display: block; }
.tl-card p { margin: .3rem 0; }
.tl-ch { font-family: var(--f-mono); font-size: .74rem; display: inline-block; margin-top: .3rem; }
@media (max-width: 520px) { .timeline::before { left: .3rem; } .timeline li { grid-template-columns: 1fr; gap: .25rem; padding-left: 1.3rem; } .timeline li::before { left: -2px; } .tl-year { text-align: left; } }
.build { background: var(--surface); border: 2px solid var(--copper); border-radius: 14px; padding: 1.1rem 1.2rem; margin: 1.5rem 0; box-shadow: var(--shadow); }
.build-head .tag { font-family: var(--f-mono); font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; font-weight: 700; color: var(--copper); }
.build-head h3 { font-size: var(--step-1); margin: .2rem 0 .5rem; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip { font-family: var(--f-mono); font-size: .72rem; padding: .15rem .5rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.chip.lvl-kid, .chip.lvl-easy { background: var(--good-soft); color: var(--good); }
.chip.lvl-medium { background: var(--copper-soft); color: var(--copper); }
.chip.lvl-advanced { background: var(--bad-soft); color: var(--bad); }
table.parts { border-collapse: collapse; width: 100%; font-size: var(--step--1); }
table.parts th, table.parts td { border-bottom: 1px solid var(--line); padding: .45rem .5rem; text-align: left; vertical-align: top; }
table.parts th { font-family: var(--f-mono); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
table.parts td:first-child { font-weight: 700; width: 34%; }
.build-steps li { margin: .35rem 0; }
.build-result { background: var(--good-soft); border-radius: 8px; padding: .55rem .8rem; font-size: var(--step--1); }
.build-foot { display: flex; gap: .7rem; align-items: center; flex-wrap: wrap; margin-top: .6rem; }
.build-foot .built { border-color: var(--good); color: var(--good); }
.ws-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .8rem; margin-top: 1.5rem; }
.ws-card { display: grid; gap: .4rem; align-content: start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; text-decoration: none; color: var(--ink); transition: border-color .15s, transform .15s; }
.ws-card:hover { border-color: var(--copper); transform: translateY(-2px); }
.ws-card h3 { font-size: 1.05rem; }
.ws-card p { margin: 0; color: var(--muted); font-size: var(--step--1); }
.ws-card.built { border-color: var(--good); }
.seg button:disabled { opacity: .45; cursor: not-allowed; }
.step-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.hero > * { min-width: 0; }
.engine-toy canvas { display: block; width: 100%; min-width: 0 !important; border-radius: 8px; touch-action: pan-x pan-y; }

/* Take-apart engine: one button per part */
.part-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .4rem; margin: .4rem 0 .6rem; }
.part-btn { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem; font-size: var(--step--1); cursor: pointer; text-align: left; color: var(--ink); }
.part-btn::before { content: "✓ "; color: var(--good); font-weight: 800; }
.part-btn[aria-pressed="true"] { background: var(--bad-soft); border-color: var(--bad); text-decoration: line-through; }
.part-btn[aria-pressed="true"]::before { content: "✕ "; color: var(--bad); }

/* ---------- Mathcraft additions ---------- */
.brand-mark { fill: none; stroke: var(--copper); stroke-width: 1.6; }
.brand-mark .axis { stroke: var(--muted); stroke-width: 1; opacity: .7; }
.brand-mark .orbiter { transform-origin: 16px 16px; transition: transform .8s cubic-bezier(.3,1.4,.5,1); }
.brand-mark .orbiter line { stroke: var(--high); stroke-width: 1.6; }
.brand-mark .orbiter circle { fill: var(--high); stroke: none; }
/* Faint graph paper behind the pages, night theme only */
:root[data-theme="dark"] body, :root:not([data-theme]) body { background-image: linear-gradient(rgba(95,220,196,.035) 1px, transparent 1px), linear-gradient(90deg, rgba(95,220,196,.035) 1px, transparent 1px); background-size: 28px 28px; }
@media (prefers-color-scheme: light) { :root:not([data-theme]) body { background-image: none; } }
.callout.scale { border-left: 4px solid var(--electron); }
.callout.scale .tag { color: var(--electron); }
/* The question the old tools can't answer */
.callout.question { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .9rem; align-items: start; border-left: 4px solid var(--high); background: linear-gradient(135deg, color-mix(in srgb, var(--high) 10%, var(--surface)), var(--surface)); }
.callout.question .tag { color: var(--high); }
.qmark { display: grid; place-items: center; width: 2.1rem; height: 2.1rem; border-radius: 50%; background: var(--high); color: var(--bg); font-family: var(--f-display); font-weight: 800; font-size: 1.25rem; }
/* A new tool in the Toolbox */
.callout.tool { border: 1px solid color-mix(in srgb, var(--copper) 45%, var(--line)); background: linear-gradient(135deg, var(--copper-soft), var(--surface)); }
.callout.tool .tag { color: var(--copper); }
.tool-name { font-size: var(--step-1); margin: .15rem 0 .3rem; }
/* Display formulas */
.formula { margin: 1.25rem 0; padding: .9rem 1rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); text-align: center; overflow-x: auto; }
.formula .hint { margin: .3rem 0 0; }
.mathd { overflow-x: auto; overflow-y: hidden; padding: .2rem 0; }
.katex { font-size: 1.08em; }
.katex-display { margin: .4em 0; }
/* Proofs and worked examples, one step at a time */
.stepper { margin: 1.5rem 0; padding: 1rem 1.15rem; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.stepper > .tag { font-family: var(--f-mono); font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; font-weight: 700; color: var(--electron); }
.stepper.proof > .tag { color: var(--copper); }
.stepper-q { font-weight: 700; margin: .3rem 0 .2rem; }
.stepper ol { margin: .5rem 0 .6rem; padding-left: 1.4rem; display: grid; gap: .45rem; }
.stepper li { opacity: 0; transform: translateY(6px); transition: opacity .35s, transform .35s; }
.stepper li.in { opacity: 1; transform: none; }
.stepper li::marker { color: var(--copper); font-weight: 700; font-family: var(--f-mono); }
.stepper-end { margin-top: .6rem; padding: .6rem .8rem; border-radius: 8px; background: var(--good-soft); color: var(--ink); }
.stepper.proof .stepper-end::after { content: " ∎"; color: var(--copper); font-weight: 800; }
/* New on the number line */
.rung { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); margin: 1.5rem 0; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }
.step .rung { margin-inline: calc((min(var(--wide), 100vw - 32px) - min(var(--col), 100vw - 32px)) / -2); }
.rung-art { background: #060a14; min-height: 100%; display: flex; align-items: center; }
.rung-art > * { width: 100%; }
.rung-art .controls, .rung-art .stats { display: none; }
.rung-body { padding: 1rem 1.2rem; }
.rung-body .tag { font-family: var(--f-mono); font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; font-weight: 700; color: var(--high); }
.rung-body h3 { font-size: var(--step-2); margin: .15rem 0 .3rem; }
.rung-body p { margin: .4rem 0; }
@media (max-width: 700px) { .rung { grid-template-columns: 1fr; } }
.rung-list { list-style: none; padding: 0; margin: 1.5rem 0 0; display: grid; gap: .5rem; }
.rung-list a { display: grid; grid-template-columns: 3.6rem minmax(0, 1fr); gap: .8rem; align-items: center; padding: .7rem .9rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.rung-list li.lit a { border-color: color-mix(in srgb, var(--high) 55%, var(--line)); }
.rung-sym { display: grid; place-items: center; height: 2.6rem; border-radius: 10px; background: var(--surface-2); font-family: var(--f-display); font-weight: 800; font-size: 1.1rem; color: var(--muted); }
.rung-list li.lit .rung-sym { background: var(--high); color: var(--bg); }
.rung-list b { display: block; font-family: var(--f-display); }
.rung-list span { display: block; font-size: var(--step--1); color: var(--muted); }
.rung-list small { font-size: .75rem; color: var(--copper); }
/* Toolbox */
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .6rem; margin-top: .6rem; }
.tool-card { display: grid; gap: .25rem; align-content: start; padding: .8rem .9rem; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--ink); transition: transform .2s, border-color .2s; }
.tool-card:hover { transform: translateY(-2px); border-color: var(--copper); }
.tool-card.done { border-color: color-mix(in srgb, var(--copper) 50%, var(--line)); }
.tool-card b { font-family: var(--f-display); font-size: 1.02rem; }
.tool-card span { font-size: var(--step--1); color: var(--muted); }
.tool-card small { font-size: .72rem; color: var(--copper); font-family: var(--f-mono); }
.toolkit { display: grid; gap: .5rem; margin: 0; }
.tk-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .9rem; }
.tk-item dt { font-family: var(--f-display); font-weight: 700; font-size: 1.05rem; }
.tk-item dd { margin: .2rem 0 0; color: var(--muted); font-size: var(--step--1); }
.tk-item dd > span { color: var(--ink); }
.tk-find { max-width: 22rem; }
/* Home: the hero toy and the number-line strip */
.math-toy { padding: 0; overflow: hidden; background: #060a14; border-color: var(--line); }
.math-toy .label { padding: .9rem 1.1rem 0; color: #a3abc3; }
.math-toy .controls, .math-toy .stats { padding: 0 1rem 1rem; margin-top: .4rem; }
.math-toy .ctrl label, .math-toy .ctrl label b, .math-toy .stat { color: #e6e1f5; }
.math-toy .seg button { color: #e6e1f5; }
.math-toy canvas, .rung-art canvas { display: block; width: 100%; min-width: 0 !important; border-radius: 0 !important; }
.journey-row { list-style: none; padding: 0 0 .6rem; margin: 0; display: flex; gap: .6rem; overflow-x: auto; scroll-snap-type: x proximity; }
.journey-row li { flex: none; width: 12.5rem; scroll-snap-align: start; position: relative; }
.journey-row li::before { content: ""; position: absolute; left: 0; right: -.6rem; top: 15px; height: 2px; background: var(--line); }
.journey-row li.lit::before { background: var(--high); }
.journey-row a { position: relative; display: grid; gap: .2rem; text-decoration: none; color: var(--ink); padding-top: 2.4rem; }
.journey-row .j-when { position: absolute; left: 0; top: 0; display: grid; place-items: center; min-width: 32px; height: 32px; padding: 0 .4rem; border-radius: 99px; background: var(--surface-2); border: 2px solid var(--line); font-family: var(--f-display); font-size: .9rem; font-weight: 800; color: var(--muted); }
.journey-row li.lit .j-when { background: var(--high); border-color: var(--high); color: var(--bg); box-shadow: 0 0 12px var(--high-glow); }
.journey-row b { font-family: var(--f-display); font-size: 1rem; }
.j-text { font-size: .8rem; color: var(--muted); line-height: 1.4; font-style: italic; }
/* Sims: tappable tiles, number pads and small tables */
.tiles { display: flex; flex-wrap: wrap; gap: .35rem; }
.tile { min-width: 2.4rem; padding: .4rem .55rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); font-family: var(--f-mono); font-weight: 700; cursor: pointer; color: var(--ink); }
.tile[aria-pressed="true"] { background: var(--copper); color: var(--bg); border-color: var(--copper); }
.tbl-math { border-collapse: collapse; font-family: var(--f-mono); font-size: .9rem; margin: .5rem 0; }
.tbl-math td, .tbl-math th { border: 1px solid var(--line); padding: .3rem .6rem; text-align: center; }
.choice .katex, .quiz .q .katex { font-size: 1.25em; }

/* Continue: name what is left, and jump to it */
.continue-row { flex-wrap: wrap; }
.continue-row .why { display: grid; gap: .45rem; }
.continue-row .why b { color: var(--ink); font-weight: 600; }
.continue-row .todo { display: flex; flex-wrap: wrap; gap: .4rem; }
.continue-row .todo-item { display: inline-flex; align-items: center; gap: .45rem; max-width: 100%; padding: .38rem .7rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); color: var(--ink); font: 500 var(--step--1) var(--f-body); text-align: left; cursor: pointer; }
.continue-row .todo-item:hover { border-color: var(--copper); }
.continue-row .todo-item i { font: 700 .62rem var(--f-mono); letter-spacing: .06em; text-transform: uppercase; font-style: normal; color: var(--copper); }
.btn.is-locked { opacity: .55; }
.nudge { animation: nudge 1.6s ease-out; border-radius: 14px; }
@keyframes nudge { 0%, 40% { box-shadow: 0 0 0 3px var(--copper); } 100% { box-shadow: 0 0 0 3px transparent; } }
@media (prefers-reduced-motion: reduce) { .nudge { animation: none; outline: 3px solid var(--copper); outline-offset: 2px; } }
