/*
 * ZeroToModel lesson pages (and the old journey page).
 * Builds on theme.css, the shared design system the course home uses: the same dark glassy
 * canvas, Geist type, thin-bordered glass cards and soft glows. Dark is the default; light
 * follows the system or <html data-theme>. Every class name here is one engine.js, the lesson
 * HTML or the tests rely on: restyle freely, rename nothing.
 *
 * Extra tokens this file adds on top of theme.css (lesson scripts read several of them):
 *   --ok-soft, --bad-soft, --flash          tinted fills for passed / wrong / "this just changed"
 *   --code-muted, --code-active, --code-chrome, --code-line   the editor window (dark in both themes)
 *   --stage-bg, --stage-dot                 the diagram canvas behind every animation
 *   --prose                                 body text: a touch softer than headings for long reading
 *   --shadow, --radius, --measure           older names lesson scripts still use
 */

@import url("theme.css");
@import url("sections.css");
@import url("https://fonts.googleapis.com/css2?family=Geist:wght@300..600&family=Geist+Mono:wght@400;500&display=swap");

:root {
  --prose: #cddcee;
  --ok-soft: var(--pass-soft);
  --bad-soft: rgba(255, 143, 134, 0.12);
  --flash: rgba(255, 210, 122, 0.3);
  --code-muted: #7d8ba5;
  --code-active: rgba(134, 200, 255, 0.15);
  --code-chrome: #0c1528;
  --code-line: rgba(150, 196, 255, 0.14);
  --code-kw: #86c8ff;
  --stage-bg: #060c18;
  --stage-dot: rgba(150, 196, 255, 0.1);
  --shadow: var(--shadow-1);
  --radius: var(--r);
  --measure: 760px;
  --fs-read: 17.5px;
  --bar-h: 58px;
  --pass-ink: var(--pass);
  --shaky-ink: var(--shaky);
  /* syntax colours for read-only code (assets/highlight.js). Code boxes are dark in both themes,
     so these stay the same in light mode; each is >= 4.5:1 on --code-bg and the tracer's active line. */
  --syn-kw: #8cc4ff;
  --syn-str: #8fe3bd;
  --syn-num: #ffbf80;
  --syn-com: #8a9ab3;
  --syn-fn: #f2d58a;
  --syn-bi: #7fd6e0;
  --syn-const: #ff9e94;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --prose: #1d2f4b;
    --bad-soft: rgba(176, 58, 46, 0.08);
    --flash: #ffe9a3;
    --code-line: rgba(255, 255, 255, 0.06);
    --code-chrome: #172238;
    --stage-bg: #fbfdff;
    --stage-dot: rgba(16, 52, 104, 0.1);
    --pass-ink: #086a48;
    --shaky-ink: #8a4400;
  }
}
:root[data-theme="light"] {
  --prose: #1d2f4b;
  --bad-soft: rgba(176, 58, 46, 0.08);
  --flash: #ffe9a3;
  --code-line: rgba(255, 255, 255, 0.06);
  --code-chrome: #172238;
  --stage-bg: #fbfdff;
  --stage-dot: rgba(16, 52, 104, 0.1);
  --pass-ink: #086a48;
  --shaky-ink: #8a4400;
}

/* ================================================================== base */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--bar-h) + 32px); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--prose);
  font: 400 var(--fs-read)/1.72 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  /* the dashboard's atmosphere: a blue glow top-right, a mint one top-left, then plain canvas */
  background:
    radial-gradient(900px 520px at 82% -120px, var(--glow-a), transparent 70%) no-repeat,
    radial-gradient(640px 420px at 6% -60px, var(--glow-b), transparent 70%) no-repeat,
    linear-gradient(180deg, var(--bg-2), var(--bg) 900px) no-repeat,
    var(--bg);
}
/* film grain, very faint (same as .zm-page) */
body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 100; opacity: var(--noise-op);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
::selection { background: color-mix(in srgb, var(--accent) 32%, transparent); color: var(--ink); }

main { display: block; }

h1, h2, h3, h4 { color: var(--ink); text-wrap: balance; }
h1, h2 { font-weight: 300; }
h1 {
  font-size: clamp(38px, 5.4vw, 66px); line-height: 1.04; letter-spacing: var(--ls-display);
  margin: 0.15em 0 0.35em;
}
h2 {
  font-size: clamp(28px, 3.4vw, 40px); line-height: 1.12; letter-spacing: -0.032em;
  margin: 1.6em 0 0.55em;
}
h3 { font-size: 21px; font-weight: 500; line-height: 1.3; letter-spacing: -0.012em; margin: 2em 0 0.55em; }
h4 { font-size: 18px; font-weight: 500; margin: 1.6em 0 0.4em; }
p, ul, ol { margin: 0 0 1.05em; }
ul, ol { padding-left: 1.35em; }
li { margin: 0.35em 0; }
li::marker { color: var(--ink-3); }
strong, b { color: var(--ink); font-weight: 560; }
em { font-style: italic; }
hr { border: 0; height: 1px; background: var(--line); margin: 2.5rem 0; }

a { color: var(--accent); text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent); text-underline-offset: 3px; text-decoration-thickness: 1px; transition: text-decoration-color var(--dur-1); }
a:hover { text-decoration-color: currentColor; }

code, pre, kbd, samp, textarea.z-code { font-family: var(--mono); font-variant-ligatures: none; }
:not(pre) > code {
  font-size: 0.86em;
  padding: 0.12em 0.4em;
  border-radius: 6px;
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 9%, transparent);
  border: 1px solid var(--line);
  overflow-wrap: anywhere;
}
kbd {
  font-size: 0.82em; padding: 0.1em 0.45em; border-radius: 6px;
  color: var(--ink); background: var(--surface); border: 1px solid var(--line-2); border-bottom-width: 2px;
}

img, svg { max-width: 100%; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 6px; }

.z-sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.z-muted { color: var(--ink-2); }
.z-ok { color: var(--pass-ink); }
.z-bad { color: var(--bad); }

/* ================================================================== layout */

.z-lesson, .z-home {
  position: relative;
  max-width: calc(var(--measure) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 12px var(--gutter) 7rem;
  counter-reset: zsec;
}

.z-section { margin: clamp(4rem, 9vw, 7rem) 0 0; }
.z-section > h2:first-child { margin-top: 0; }
/* numbered mono kicker above each section heading, like the dashboard's "● How it works" */
.z-section:not(.z-gate) > h2:first-child { counter-increment: zsec; }
.z-section:not(.z-gate) > h2:first-child::before {
  content: counter(zsec, decimal-leading-zero);
  display: flex; align-items: center; gap: 10px; width: 100%;
  margin-bottom: 18px;
  font: 400 12.5px/1 var(--mono); letter-spacing: 0.06em; color: var(--ink-3);
  /* dot + number + hairline */
  background:
    radial-gradient(circle, var(--accent) 3px, transparent 3.6px) 0 50% / 7px 7px no-repeat,
    linear-gradient(var(--line), var(--line)) 54px 50% / calc(100% - 54px) 1px no-repeat;
  padding-left: 18px;
}
.z-section:target > h2:first-child,
.z-section [id]:target { animation: z-target 2.2s var(--ease-out) 1; border-radius: 8px; }

/* Reveal on scroll, pure CSS (scroll-driven animation): each section rises in over its first
   ~220 px of entering the viewport. Browsers without view timelines simply show it; never
   under reduced motion. */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .z-lesson > .z-section {
      animation: z-reveal linear both;
      animation-timeline: view();
      animation-range: entry 0px entry 220px;
    }
  }
}
@keyframes z-reveal { from { opacity: 0.001; transform: translateY(28px); } to { opacity: 1; transform: none; } }

/* Plain <pre> and <table> written directly in lesson text: never let them widen the page on a phone.
   :where() keeps these weak so every engine-drawn pre/table keeps its own styling. */
:where(.z-section) pre:not([class]) {
  max-width: 100%; overflow-x: auto; margin: 1.1rem 0 1.4rem; padding: 16px 18px;
  background: var(--code-bg); color: var(--code-text); border: 1px solid var(--code-line);
  border-radius: var(--r); font-size: 15px; line-height: 1.65;
}
:where(.z-section) table:not([class]) {
  display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin: 1.4rem 0;
  font-size: 16px; line-height: 1.5;
}
:where(.z-section) table:not([class]) :where(th, td) { border-bottom: 1px solid var(--line); padding: 10px 16px 10px 0; text-align: left; vertical-align: top; }
:where(.z-section) table:not([class]) th { color: var(--ink); font: 500 12px/1.3 var(--mono); letter-spacing: 0.06em; text-transform: uppercase; border-bottom-color: var(--line-2); }
@keyframes z-target { from { background: var(--flash); } to { background: transparent; } }

/* ================================================================== hero */

/* display: contents lets the top bar stay sticky for the whole lesson (its sticky range is <main>) */
.z-hero { display: contents; }

/* the engine-drawn top row is the SAME bar as the course home (.zd-nav-inner):
   same height, padding, radius, glass and sticky offset, so the two never drift */
.z-hero-top {
  position: sticky; top: 12px; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  height: 60px; min-height: 0;
  margin: 0 0 clamp(36px, 7vw, 76px);
  padding: 0 10px 0 18px;
  border: 1px solid var(--line); border-radius: 14px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  -webkit-backdrop-filter: blur(16px) saturate(1.3); backdrop-filter: blur(16px) saturate(1.3);
  transition: border-color 0.4s var(--ease-out), background-color 0.4s var(--ease-out);
}
.z-hero-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; flex: none; }
.z-hero-top .z-theme-toggle, .z-pill {
  display: inline-flex; align-items: center; height: 38px; min-height: 0; padding: 0 14px; border-radius: 10px; cursor: pointer; white-space: nowrap;
  font: 400 13px var(--mono); color: var(--ink-2); background: transparent; border: 1px solid var(--line-2); text-decoration: none;
  transition: color 0.25s, border-color 0.25s, transform 0.25s var(--ease-out);
}
.z-hero-top .z-theme-toggle:hover, .z-pill:hover { color: var(--ink); border-color: var(--accent); }
.z-pill--solid { background: var(--cta-bg); color: var(--cta-ink); border-color: transparent; }
.z-pill--solid:hover { color: var(--cta-ink); transform: translateY(-1px); }
.z-account { position: relative; }
.z-account:empty { display: none; }
.z-avatar { display: inline-grid; place-items: center; width: 22px; height: 22px; margin-right: 8px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font: 600 11px var(--font); }
.z-acct-menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 240px; padding: 14px; z-index: 60;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px;
  box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.5);
  transform-origin: top right; animation: z-pop 0.28s var(--ease-out);
  font-size: 14px; text-align: left;
}
.z-acct-menu p { margin: 0 0 10px; overflow-wrap: anywhere; }
.z-acct-menu .z-small { color: var(--ink-2); font-size: 13px; }
.z-acct-menu .z-btn--sm { min-height: 34px; padding: 0 12px; font-size: 13px; }
@keyframes z-pop { from { opacity: 0; transform: translateY(-6px) scale(0.97); } }
/* reading progress: a 2 px line along the bottom edge that fills as you scroll (transform only = no jank) */
.z-readbar { position: absolute; left: 14px; right: 14px; bottom: -1px; height: 2px; border-radius: 2px; overflow: hidden; pointer-events: none; }
.z-readbar span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transform: scaleX(0); transform-origin: left; will-change: transform; }
.z-crumb-pos { display: none; }
.z-crumbs {
  display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; min-width: 0;
  font: 400 13.5px/1.35 var(--mono); letter-spacing: 0.005em;
}
.z-crumbs a { color: var(--ink-2); text-decoration: none; padding: 6px 0; border-radius: 6px; transition: color var(--dur-1); }
.z-crumbs a:hover { color: var(--ink); }
/* the brand mark (five dots, as on the dashboard) in front of "Journey map" */
.z-crumbs > a:first-child { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); }
.z-crumb-mark { display: inline-flex; flex: none; }
.z-crumb-mark svg { width: 26px; height: 26px; fill: var(--accent); }
.z-crumb-mark .z-mark-core { fill: var(--ink); }
.z-crumbs > a:first-child:hover circle:not(.z-mark-core) { animation: z-mark-in 0.7s var(--ease-out); }
@keyframes z-mark-in { from { transform: translateX(-3px); opacity: 0.3; } }
.z-sep { color: var(--ink-3); }

.z-theme-toggle {
  display: inline-flex; align-items: center; min-height: 42px; padding: 0 14px;
  font: 400 13px var(--mono); color: var(--ink-2);
  border-radius: 10px; border: 1px solid var(--line-2); background: transparent; cursor: pointer;
  transition: color var(--dur-1), border-color var(--dur-1), background-color var(--dur-1);
}
.z-theme-toggle:hover { color: var(--ink); border-color: var(--accent); background: var(--accent-soft); }

.z-hero h1 { max-width: none; text-wrap: pretty; }
.z-hero-meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 26px; }
.z-lede {
  font-size: clamp(18px, 1.7vw, 21px); line-height: 1.6; font-weight: 300;
  color: var(--ink-2); max-width: 36em; margin-bottom: 0;
}
.z-lede strong { font-weight: 450; }

.z-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: var(--r-pill);
  font: 400 12.5px/1.3 var(--mono); letter-spacing: 0.01em;
  color: var(--ink-2); background: color-mix(in srgb, var(--glass) 60%, transparent);
  border: 1px solid var(--line-2);
}
.z-chip--passed { color: var(--pass-ink); border-color: color-mix(in srgb, var(--pass) 45%, transparent); background: var(--pass-soft); }
.z-chip--open { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: var(--accent-soft); }
.z-chip--locked { color: var(--shaky-ink); border-color: color-mix(in srgb, var(--shaky) 45%, transparent); background: var(--shaky-soft); }

.z-banner, .z-notice {
  margin: 1.2rem 0 1rem; padding: 14px 18px;
  border-radius: var(--r); border: 1px solid color-mix(in srgb, var(--shaky) 35%, transparent);
  background: var(--shaky-soft); color: var(--ink);
  font-size: 16px; line-height: 1.6;
}
.z-banner { margin-top: 28px; }
.z-notice--warn { background: var(--shaky-soft); }

/* ================================================================== callouts */

.z-analogy, .z-note, .z-see {
  position: relative;
  margin: 1.6rem 0 1.8rem;
  padding: 18px 22px 18px 24px;
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--accent-soft), color-mix(in srgb, var(--accent-soft) 40%, transparent));
  color: var(--prose);
}
.z-analogy::after, .z-note::after, .z-see::after {
  content: ""; position: absolute; left: -1px; top: 18px; bottom: 18px; width: 2px; border-radius: 2px;
  background: var(--accent);
}
.z-analogy::before, .z-see::before {
  content: "Everyday picture"; display: block; margin-bottom: 8px;
  font: 500 var(--fs-label)/1.2 var(--mono); letter-spacing: 0.09em; text-transform: uppercase; color: var(--accent);
}
.z-see { background: linear-gradient(180deg, var(--pass-soft), color-mix(in srgb, var(--pass-soft) 40%, transparent)); }
.z-see::after { background: var(--pass); }
.z-see::before { content: "What you should see, and why"; color: var(--pass-ink); }
.z-note { background: linear-gradient(180deg, var(--glass-hi), var(--glass)); }
.z-note::after { background: var(--ink-3); }
.z-analogy > :last-child, .z-note > :last-child, .z-see > :last-child { margin-bottom: 0; }
.z-see pre:not([class]) { margin: 0.6rem 0 0.9rem; }

.z-mistake {
  position: relative;
  margin: 1.4rem 0;
  padding: 20px 22px 20px 24px;
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--glass-hi), var(--glass));
  box-shadow: var(--shadow-1);
}
.z-mistake::after {
  content: ""; position: absolute; left: -1px; top: 20px; bottom: 20px; width: 2px; border-radius: 2px; background: var(--bad);
}
.z-mistake h3 { margin-top: 0; font-size: 19px; }
.z-mistake > :last-child { margin-bottom: 0; }

.z-glossary {
  display: grid; grid-template-columns: minmax(8rem, max-content) minmax(0, 1fr);
  gap: 0; margin: 0; line-height: 1.6;
  border-top: 1px solid var(--line);
}
.z-glossary dt, .z-glossary dd { padding: 13px 0; border-bottom: 1px solid var(--line); }
.z-glossary dt { padding-right: 28px; }
.z-glossary dt { color: var(--ink); font-weight: 500; max-width: 15rem; }
.z-glossary dd { margin: 0; }
.z-glossary dd > :last-child { margin-bottom: 0; }
@media (max-width: 560px) {
  .z-glossary { grid-template-columns: minmax(0, 1fr); }
  .z-glossary dt { padding-bottom: 2px; border-bottom: 0; max-width: none; }
  .z-glossary dd { padding-top: 2px; }
}

/* ================================================================== term tooltips */

.term {
  color: inherit;
  border-bottom: 1.5px dotted color-mix(in srgb, var(--accent) 80%, transparent);
  cursor: help; border-radius: 3px;
  transition: background-color var(--dur-1);
}
.term:hover, .term[aria-expanded="true"] { background: var(--accent-soft); border-bottom-style: solid; }

.z-tip {
  position: absolute; z-index: 50;
  max-width: min(340px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: var(--r);
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line-2);
  font: 400 15px/1.5 var(--font);
  box-shadow: 0 18px 50px -18px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(0, 0, 0, 0.02);
  pointer-events: none;
  animation: z-tip-in var(--dur-1) var(--ease-out);
}
@keyframes z-tip-in { from { opacity: 0; transform: translateY(4px); } }

/* ================================================================== buttons */

.z-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; min-width: 44px; padding: 0 18px;
  font: 400 14px/1.25 var(--mono); letter-spacing: 0.01em;
  color: var(--ink); background: transparent;
  border: 1px solid var(--line-2); border-radius: 10px;
  cursor: pointer; text-decoration: none;
  transition: transform 0.35s var(--ease-spring), background-color var(--dur-1), border-color var(--dur-1), box-shadow 0.35s var(--ease-out), color var(--dur-1);
}
.z-btn:hover { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-1px); }
.z-btn:active { transform: none; transition-duration: 0.08s; }
.z-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; background: transparent; border-color: var(--line-2); }
.z-btn--primary { background: var(--cta-bg); color: var(--cta-ink); border-color: transparent; }
.z-btn--primary:hover { background: var(--cta-bg); border-color: transparent; box-shadow: 0 10px 34px -10px var(--glow-a); }
.z-btn--primary:disabled { background: var(--cta-bg); }
.z-btn--icon { padding: 0 12px; font: 400 16px/1 var(--font); }
.z-btn--big { min-height: 52px; padding: 0 24px; font-size: 15px; margin-top: 0.6rem; }
.z-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 14px 0; }

/* ================================================================== cards */

.z-card {
  margin: 1.2rem 0;
  padding: clamp(18px, 3vw, 26px);
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--glass-hi), var(--glass));
  box-shadow: var(--shadow-1);
  -webkit-backdrop-filter: blur(14px) saturate(1.2); backdrop-filter: blur(14px) saturate(1.2);
  transition: border-color var(--dur-2), box-shadow var(--dur-2) var(--ease-out);
}
.z-card > :last-child { margin-bottom: 0; }

/* ================================================================== wide blocks */
/* Animations, tracers and code boxes step out of the text column a little on big screens. */
@media (min-width: 1100px) {
  .z-anim, .z-trace { margin-left: -56px; margin-right: -56px; }
}

/* ================================================================== step player */

.z-anim, .z-trace { margin: 2rem 0; }

.z-player {
  padding: clamp(14px, 2.2vw, 20px);
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--glass-hi), var(--glass));
  box-shadow: var(--shadow-1), 0 40px 80px -60px var(--glow-a);
  -webkit-backdrop-filter: blur(14px) saturate(1.2); backdrop-filter: blur(14px) saturate(1.2);
}
.z-player-title {
  display: flex; align-items: center; gap: 10px;
  margin: 2px 4px 14px;
  font-size: 17px; font-weight: 500; color: var(--ink); line-height: 1.35;
}
.z-player-title::before {
  content: ""; flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--pass);
  box-shadow: 0 0 0 4px var(--pass-soft);
}
.z-stage {
  min-height: 180px;
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  overflow-x: auto;
  background:
    radial-gradient(circle, var(--stage-dot) 1px, transparent 1.4px) 0 0 / 22px 22px,
    var(--stage-bg);
  color: var(--ink);
  font-size: 16px; line-height: 1.55;
}
.z-stage svg { display: block; margin: 0 auto; height: auto; }
.z-stage svg text { fill: var(--text); font-family: var(--font); }
.z-stage svg .mono { font-family: var(--mono); }
.z-say {
  position: relative;
  margin: 14px 0 4px;
  padding: 14px 18px 14px 20px;
  min-height: 3.6em;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--ink);
  font-size: 17px; line-height: 1.62;
}
.z-say::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 2px; border-radius: 2px; background: var(--accent); }
.z-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; }
.z-step-count { margin: 0 8px; font: 400 13px var(--mono); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.z-speed-label { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; font: 400 13px var(--mono); color: var(--ink-2); }
.z-speed {
  min-height: 44px; padding: 0 10px; border-radius: 10px;
  font: 400 13px var(--mono); color: var(--ink);
  border: 1px solid var(--line-2); background: var(--surface);
}
.z-progress-mini { height: 3px; margin-top: 12px; border-radius: 3px; overflow: hidden; background: var(--line); }
.z-progress-mini > span {
  display: block; height: 100%; border-radius: 3px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.4s var(--ease-out);
}

/* Shapes animations commonly draw with ZTM.h (HTML frames). */
.z-box {
  display: inline-flex; flex-direction: column; align-items: center;
  min-width: 5rem; margin: 0.3rem; padding: 0.45rem 0.85rem;
  border: 1.5px solid var(--accent); border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 8px 24px -16px var(--glow-a);
}
.z-box-label { font: 400 12px var(--mono); color: var(--ink-2); }
.z-box-value { font-family: var(--mono); font-size: 1.1rem; color: var(--ink); }
.z-fade-in { animation: z-fade 0.5s var(--ease-out); }
@keyframes z-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* tracer */
.z-trace-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 12px; }
@media (max-width: 640px) { .z-trace-grid { grid-template-columns: minmax(0, 1fr); } }
.z-trace-code {
  list-style: none; margin: 0; padding: 12px 0;
  background: var(--code-bg); color: var(--code-text);
  border: 1px solid var(--code-line); border-radius: 12px;
  overflow-x: auto; font-size: 15px; line-height: 1.7;
}
.z-trace-code li { display: flex; margin: 0; padding: 1px 14px 1px 0; white-space: pre; border-left: 2px solid transparent; transition: background-color var(--dur-1); }
.z-trace-code li.is-active { background: var(--code-active); border-left-color: var(--focus); }
.z-trace-code li.is-active .z-ln { color: var(--code-text); }
.z-trace-code code { background: none; border: 0; padding: 0; color: inherit; font-size: inherit; }
.z-ln { display: inline-block; width: 2.6em; flex: none; padding-right: 1em; text-align: right; color: var(--code-muted); user-select: none; }
.z-vars {
  width: 100%; border-collapse: separate; border-spacing: 0; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  font-size: 15.5px;
}
.z-vars caption { text-align: left; padding: 0 2px 8px; font: 500 var(--fs-label)/1.2 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.z-vars th, .z-vars td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; color: var(--ink); }
.z-vars tr:last-child > * { border-bottom: 0; }
.z-vars th { width: 40%; font-family: var(--mono); font-weight: 500; color: var(--accent); }
.z-vars code { background: none; border: 0; padding: 0; color: inherit; }
.z-vars tr.z-changed { animation: z-flash 1.6s ease-out 1; }
@keyframes z-flash { 0%, 30% { background: var(--flash); } 100% { background: transparent; } }
.z-trace-out { margin-top: 12px; }
.z-trace-label { margin-bottom: 8px; font: 500 var(--fs-label)/1.2 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.z-trace-out pre {
  margin: 0; min-height: 2.8em; padding: 10px 14px;
  background: var(--code-bg); color: var(--code-text);
  border: 1px solid var(--code-line); border-radius: 12px;
  overflow-x: auto; font-size: 15px; line-height: 1.6;
}

/* ================================================================== code boxes */
/* An editor window: a dark title bar (traffic-light dots, language, Run/Reset), then the code.
   The window is dark in both themes, so its own text and buttons use fixed code colours. */

.z-run { margin: 1.8rem 0 0.6rem; }
.z-run, .z-ex .z-editor { min-width: 0; }
.z-run-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.z-run-label { margin-right: auto; font: 500 var(--fs-label)/1.2 var(--mono); letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-3); }
.z-status { font: 400 13px/1.4 var(--mono); color: var(--ink-2); }

.z-run > .z-run-bar {
  margin: 0; padding: 8px 8px 8px 14px; gap: 6px;
  background: var(--code-chrome);
  border: 1px solid var(--code-line); border-bottom: 0;
  border-radius: 14px 14px 0 0;
}
.z-run > .z-run-bar .z-run-label { display: inline-flex; align-items: center; gap: 12px; color: var(--code-muted); }
.z-run > .z-run-bar .z-run-label::before {
  content: ""; width: 44px; height: 10px; flex: none;
  background:
    radial-gradient(circle, #ff8f86 4px, transparent 4.5px) 0 0 / 10px 10px,
    radial-gradient(circle, #ffd27a 4px, transparent 4.5px) 17px 0 / 10px 10px,
    radial-gradient(circle, #74e0b4 4px, transparent 4.5px) 34px 0 / 10px 10px;
  background-repeat: no-repeat; opacity: 0.85;
}
.z-run > .z-run-bar .z-status { color: #a8b6cc; order: 0; }
.z-run > .z-run-bar .z-btn { min-height: 38px; padding: 0 14px; font-size: 13.5px; color: #dbe7f5; border-color: rgba(150, 196, 255, 0.22); }
.z-run > .z-run-bar .z-btn:hover { background: rgba(134, 200, 255, 0.12); border-color: #86c8ff; }
.z-run > .z-run-bar .z-btn--primary { background: #dff0ff; color: #04070f; border-color: transparent; }
.z-run > .z-run-bar .z-btn--primary:hover { background: #ffffff; box-shadow: 0 8px 26px -8px rgba(79, 157, 255, 0.55); }
.z-run > .z-run-bar .z-btn:focus-visible { outline-color: #ffd27a; }
.z-run > .z-editor { border-radius: 0 0 14px 14px; }

.z-editor {
  display: flex;
  overflow: hidden;
  background: var(--code-bg);
  border: 1px solid var(--code-line);
  border-radius: 14px;
  box-shadow: 0 24px 60px -40px rgba(0, 0, 0, 0.7);
  transition: border-color var(--dur-1), box-shadow var(--dur-2) var(--ease-out);
}
.z-gutter {
  flex: none; min-width: 3em; padding: 14px 0;
  text-align: right; color: var(--code-muted);
  font: 400 15px/1.65 var(--mono);
  user-select: none; overflow: hidden;
  border-right: 1px solid rgba(150, 196, 255, 0.07);
}
.z-gutter span { display: block; padding: 0 0.9em 0 0.5em; }
.z-gutter span.is-error { background: #b03a2e; color: #fff; }
textarea.z-code {
  flex: 1; min-width: 0;
  margin: 0; border: 0; resize: vertical;
  padding: 14px 16px;
  background: transparent; color: var(--code-text);
  font-size: 15px; line-height: 1.65;
  white-space: pre; overflow-x: auto; overflow-y: hidden;
  tab-size: 4; caret-color: #ffd27a;
}
textarea.z-code::selection { background: rgba(134, 200, 255, 0.28); color: #fff; }
textarea.z-code:focus { outline: none; }
.z-editor:focus-within { outline: 2px solid var(--focus); outline-offset: 3px; border-color: rgba(134, 200, 255, 0.4); }

.z-output:empty { display: none; }
.z-output { margin-top: 10px; }
.z-stdout, .z-code-view {
  margin: 0 0 0.6rem;
  padding: 14px 18px;
  background: var(--code-bg); color: var(--code-text);
  border: 1px solid var(--code-line);
  border-radius: 12px;
  overflow-x: auto;
  font-size: 15px; line-height: 1.65;
}
.z-code-view { margin: 1.1rem 0 1.4rem; }
.z-stdout { position: relative; padding-left: 20px; }
.z-stdout::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 2px; border-radius: 2px; background: #74e0b4; }
.z-plot { display: block; max-width: 100%; height: auto; background: #fff; border-radius: 12px; margin: 0.6rem 0; border: 1px solid var(--line); }

.z-pyerror {
  margin: 0.6rem 0; padding: 14px 18px;
  border-radius: 12px;
  background: var(--bad-soft);
  border: 1px solid color-mix(in srgb, var(--bad) 45%, transparent);
  color: var(--ink);
}
.z-pyerror-head { font-weight: 600; color: var(--bad); }
.z-pyerror-last {
  margin: 8px 0; padding: 8px 12px;
  background: var(--code-bg); color: #ffb3ab; border-radius: 8px;
  overflow-x: auto; font-family: var(--mono); font-size: 14.5px; font-weight: 500;
}
.z-pyerror-help { margin: 6px 0 8px; }
.z-pyerror-full summary { cursor: pointer; min-height: 32px; font: 400 13px/32px var(--mono); color: var(--ink-2); }
.z-pyerror-full pre { overflow-x: auto; font-size: 13.5px; padding: 10px 12px; border-radius: 8px; background: var(--code-bg); color: var(--code-text); }
.z-pyerror-full mark { background: #ffe58a; color: #04070f; font-weight: 700; border-radius: 3px; }
.z-error-inline { color: var(--bad); }

/* syntax colouring (highlight.js wraps tokens; text stays identical) */
.zh-kw { color: var(--syn-kw); }
.zh-str { color: var(--syn-str); }
.zh-num { color: var(--syn-num); }
.zh-com { color: var(--syn-com); font-style: italic; }
.zh-fn { color: var(--syn-fn); }
.zh-bi { color: var(--syn-bi); }
.zh-const { color: var(--syn-const); }
.zh-dec { color: var(--syn-fn); }

/* ================================================================== exercises */

.z-ex { position: relative; }
.z-ex.is-done { border-color: color-mix(in srgb, var(--pass) 55%, transparent); box-shadow: var(--shadow-1), 0 30px 70px -50px var(--pass); }
.z-ex-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.z-ex-head h3 { margin: 0; font-size: 20px; }
.z-ex-badge {
  padding: 4px 10px; border-radius: var(--r-pill); white-space: nowrap;
  font: 400 12px/1.3 var(--mono); color: var(--ink-2); border: 1px solid var(--line-2);
}
.z-ex.is-done .z-ex-badge { color: var(--pass-ink); border-color: color-mix(in srgb, var(--pass) 45%, transparent); background: var(--pass-soft); }
.z-ex-prompt { margin: 12px 0 16px; }
.z-ex-prompt > :last-child { margin-bottom: 0; }
.z-steps { margin: 10px 0 16px; }
.z-steps code { overflow-wrap: anywhere; }
.z-confirm { display: flex; gap: 12px; align-items: flex-start; padding: 8px 0; cursor: pointer; color: var(--ink); }
.z-confirm input { width: 1.3rem; height: 1.3rem; flex: none; margin-top: 0.2rem; accent-color: var(--pass); }
.z-hints { margin: 10px 0; padding-left: 1.4em; }
.z-hints:empty { display: none; }
.z-hints li { margin: 8px 0; padding: 10px 14px; border-radius: 10px; background: var(--shaky-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--shaky) 25%, transparent); }
.z-solution { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--line-2); }
.z-solution-label { margin-bottom: 8px; font: 500 var(--fs-label)/1.2 var(--mono); letter-spacing: 0.09em; text-transform: uppercase; color: var(--pass-ink); }
.z-solution .z-code-view { margin-top: 0; }
.z-ex-feedback p { margin: 8px 0; }

/* ================================================================== quiz */

.z-q { outline: none; }
.z-q-count { font: 400 13px var(--mono); letter-spacing: 0.02em; color: var(--ink-2); }
.z-q-text { margin: 12px 0 16px; font-size: 20px; font-weight: 450; line-height: 1.45; color: var(--ink); letter-spacing: -0.01em; }
.z-choices { border: 0; margin: 0; padding: 0; min-width: 0; }
.z-choice {
  display: flex; gap: 14px; align-items: flex-start;
  min-height: 52px; margin: 8px 0; padding: 13px 16px;
  border-radius: 12px;
  border: 1px solid var(--line-2);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  color: var(--ink);
  cursor: pointer;
  transition: border-color var(--dur-1), background-color var(--dur-1), transform 0.3s var(--ease-out);
}
.z-choice:hover { border-color: var(--accent); }
.z-choice input { width: 1.15rem; height: 1.15rem; margin-top: 0.3rem; flex: none; accent-color: var(--accent); }
.z-choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.z-choice.is-right { border-color: var(--pass); background: var(--pass-soft); box-shadow: inset 0 0 0 1px var(--pass); }
.z-choice.is-wrong { border-color: var(--bad); background: var(--bad-soft); box-shadow: inset 0 0 0 1px var(--bad); }
.z-choice.is-right .z-choice-text::after { content: "  ✓ correct"; color: var(--pass-ink); font: 500 13px var(--mono); }
.z-choice-text { min-width: 0; overflow-wrap: anywhere; }
.z-mis { margin: 10px 0; padding: 12px 16px; border-radius: 12px; background: var(--bad-soft); border: 1px solid color-mix(in srgb, var(--bad) 30%, transparent); color: var(--ink); }
.z-mis p { margin: 6px 0; }
.z-explain { margin: 12px 0; }
.z-quiz-result.is-pass { border-color: color-mix(in srgb, var(--pass) 55%, transparent); box-shadow: var(--shadow-1), 0 30px 70px -45px var(--pass); }
.z-quiz-result.is-fail { border-color: color-mix(in srgb, var(--shaky) 55%, transparent); }
.z-quiz-result h3 { margin-top: 0; font-size: 24px; font-weight: 400; letter-spacing: -0.02em; }
.z-quiz-result:focus { outline: none; }

/* ================================================================== gate */

.z-gate {
  position: relative;
  padding: clamp(22px, 4vw, 36px);
  border-radius: 18px;
  border: 1px dashed var(--line-2);
  background: linear-gradient(180deg, var(--glass-hi), var(--glass));
  overflow: hidden;
}
.z-gate.is-open {
  border-style: solid; border-color: color-mix(in srgb, var(--pass) 55%, transparent);
  background:
    radial-gradient(70% 120% at 100% 0%, var(--pass-soft), transparent 70%),
    linear-gradient(180deg, var(--glass-hi), var(--glass));
  box-shadow: 0 40px 90px -60px var(--pass);
}
.z-gate h2 { margin-top: 0; font-size: clamp(26px, 3vw, 34px); border: 0 !important; }
.z-checklist { list-style: none; padding: 0; margin: 0 0 1rem; font-family: var(--mono); font-size: 15px; }
.z-checklist li { padding: 10px 0; border-bottom: 1px solid var(--line); color: var(--ink-2); margin: 0; }
.z-checklist li.is-done { color: var(--pass-ink); }

/* ================================================================== journey map (old index page) */

.z-topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 0; }
.z-brand { font-weight: 500; font-size: 18px; letter-spacing: -0.03em; color: var(--ink); }
.z-topbar-actions { display: flex; gap: 8px; align-items: center; }

.z-steps-how { counter-reset: how; list-style: none; padding: 0; display: grid; gap: 10px; }
.z-steps-how li {
  counter-increment: how; display: flex; gap: 12px; align-items: flex-start; margin: 0; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: var(--r); background: linear-gradient(180deg, var(--glass-hi), var(--glass));
}
.z-steps-how li::before {
  content: counter(how); flex: none; width: 1.8rem; height: 1.8rem; border-radius: 50%;
  display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font: 500 13px var(--mono);
}

.z-summary { margin: 1.5rem 0; }
.z-summary-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.z-bar { height: 8px; margin: 8px 0 12px; border-radius: 999px; overflow: hidden; background: var(--line); }
.z-bar > span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--pass), var(--accent)); }

.z-stage-card {
  margin: 12px 0; border-radius: var(--r-lg); border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--glass-hi), var(--glass)); box-shadow: var(--shadow-1);
}
.z-stage-card.is-done { border-color: color-mix(in srgb, var(--pass) 50%, transparent); }
.z-stage-card > summary {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  min-height: 56px; padding: 14px 18px; cursor: pointer; list-style: none;
}
.z-stage-card > summary::-webkit-details-marker { display: none; }
.z-stage-num { font: 500 var(--fs-label) var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); white-space: nowrap; }
.z-stage-title { font-weight: 500; color: var(--ink); min-width: 0; }
.z-stage-count { font: 400 13px var(--mono); color: var(--ink-2); white-space: nowrap; }
.z-stage-goal { padding: 0 18px; color: var(--ink-2); margin-bottom: 8px; }
.z-lesson-list { list-style: none; margin: 0; padding: 0 8px 12px; }
.z-lesson-row { margin: 0; }
.z-lesson-row a {
  display: grid; grid-template-columns: 1.6rem 1.8rem 1fr auto; align-items: center; gap: 8px;
  min-height: 48px; padding: 6px 10px; border-radius: 10px; color: var(--ink); text-decoration: none;
}
.z-lesson-row a:hover { background: var(--accent-soft); }
.z-lesson-row.is-locked a { color: var(--ink-2); }
.z-lesson-row.is-passed .z-lesson-icon { color: var(--pass); font-weight: 700; }
.z-lesson-row.is-open .z-lesson-icon { color: var(--accent); }
.z-lesson-row.is-current a { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.z-lesson-icon { text-align: center; }
.z-lesson-num { font: 400 13px var(--mono); color: var(--ink-2); text-align: right; }
.z-lesson-title { min-width: 0; overflow-wrap: anywhere; }
.z-lesson-min { font: 400 13px var(--mono); color: var(--ink-2); white-space: nowrap; }

.z-form { display: grid; gap: 6px; max-width: 24rem; }
.z-form label { font-weight: 500; color: var(--ink); margin-top: 6px; }
.z-form input {
  width: 100%; min-height: 46px; padding: 0 14px; font: inherit; color: var(--ink);
  border: 1px solid var(--line-2); border-radius: 10px; background: var(--surface);
}
.z-form input:focus { border-color: var(--accent); }
.z-form .z-btn { margin-top: 10px; justify-self: start; }
.z-form-msg { min-height: 1.4em; margin: 6px 0 0; }

.z-footer { margin-top: 4rem; padding-top: 1.2rem; border-top: 1px solid var(--line); color: var(--ink-2); font-size: 14px; }

/* ================================================================== tutor panel */
/* tutor-panel.css loads after this file and already reads our tokens; these `html`-prefixed
   rules only bring its launcher, panel and help card into the glass look. */

html .zt-launch {
  padding: 0 18px 0 8px; min-height: 48px;
  font: 400 14px/1.2 var(--mono); letter-spacing: 0.01em;
  color: var(--cta-ink); background: var(--cta-bg); border: 1px solid transparent; border-radius: 12px;
  box-shadow: 0 14px 40px -12px var(--glow-a), 0 2px 10px rgba(0, 0, 0, 0.25);
  transition: transform 0.35s var(--ease-spring), box-shadow 0.35s var(--ease-out);
}
html .zt-launch:hover { filter: none; transform: translateY(-2px); box-shadow: 0 18px 48px -10px var(--glow-a), 0 2px 10px rgba(0, 0, 0, 0.25); }
html .zt-launch-icon { width: 32px; height: 32px; border-radius: 9px; background: var(--cta-ink); color: var(--cta-bg); font: 500 15px var(--mono); }
html .zt-panel {
  background: linear-gradient(180deg, var(--surface-2), var(--surface) 220px);
  border-left-color: var(--line-2);
  box-shadow: -30px 0 80px -30px rgba(0, 0, 0, 0.55);
  transition: transform 0.45s var(--ease-out);
}
html .zt-title { font-weight: 400; font-size: 20px; letter-spacing: -0.02em; }
html .zt-status { font-family: var(--mono); font-size: 12px; }
html .zt-head, html .zt-ctx, html .zt-compose { border-color: var(--line); }
html .zt-ctx { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
html .zt-chip-btn { font: 400 12.5px/1.2 var(--mono); border-color: var(--line-2); background: transparent; }
html .zt-chip-btn:hover { background: var(--accent-soft); }
html .zt-msg--tutor .zt-msg-body { background: linear-gradient(180deg, var(--glass-hi), var(--glass)); border-color: var(--line); }
html .zt-msg--me .zt-msg-body { border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
html .zt-msg-body pre { border: 1px solid var(--code-line); font-family: var(--mono); }
html .zt-input, html .zt-field { background: var(--bg); border-color: var(--line-2); border-radius: 10px; }
html .zt-input:focus, html .zt-field:focus { outline: 2px solid var(--focus); outline-offset: 2px; }
html .zt-icon-btn:hover, html .zt-rate:hover { background: var(--accent-soft); }
html .zt-help {
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border-color: var(--line-2); border-radius: var(--r-lg);
  box-shadow: 0 30px 70px -30px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--line);
}
html .zt-help::before { content: ""; position: absolute; left: 18px; right: 18px; top: -1px; height: 1px; background: linear-gradient(90deg, transparent, var(--accent), transparent); }
html .zt-backdrop { background: rgba(2, 5, 12, 0.5); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
@media (max-width: 700px) {
  html .zt-panel { border-radius: 18px 18px 0 0; border-top-color: var(--line-2); }
  html .zt-launch { min-height: 44px; padding: 0 14px 0 6px; font-size: 13px; }
}
/* Small phones: the launcher shrinks to a round icon so it never sits on top of player controls;
   its visible text stays in the DOM (visually hidden), so its name is still "Ask the tutor". */
@media (max-width: 600px) {
  html .zt-launch { width: 52px; height: 52px; min-height: 0; padding: 0; gap: 0; justify-content: center; border-radius: 50%; right: 12px; bottom: 12px; }
  html .zt-launch-icon { width: 100%; height: 100%; border-radius: 50%; background: transparent; color: var(--cta-ink); font-size: 20px; }
  html .zt-launch-text { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
  .z-lesson { padding-bottom: calc(7rem + 76px); }
}

/* ---- "Got it" tick on each common-mistake card ---- */
.z-got { display: flex; gap: 10px; align-items: center; margin: 14px 0 0; padding: 8px 12px; border-radius: 10px; border: 1px dashed var(--line-2); cursor: pointer; color: var(--ink-2); font-size: 14px; transition: border-color 0.25s, background-color 0.25s, color 0.25s; }
.z-got input { width: 1.15rem; height: 1.15rem; flex: none; accent-color: var(--pass); }
.z-got:hover { border-color: var(--accent); color: var(--ink); }
.z-got.is-done { border-style: solid; border-color: var(--pass); background: var(--pass-soft); color: var(--pass-ink, var(--ink)); }
.z-lesson .z-mistake > .z-mistake-fix > .z-got { margin-left: 0; }
.z-checklist li.z-check-soft { color: var(--ink-3); }
.z-checklist li.z-check-soft.is-done { color: var(--pass-ink); }

/* ---- "Fix it" panel (lesson.html#fix=<concept>) ---- */
.z-fix { margin: 0 0 clamp(28px, 5vw, 48px); padding: 18px 20px; border: 1px solid var(--shaky); border-radius: 14px; background: var(--shaky-soft); }
.z-fix-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.z-fix-head h2 { margin: 0; font-size: clamp(20px, 2.4vw, 26px); border: 0 !important; flex: 1 1 auto; }
.z-chip--shaky { background: var(--shaky); color: var(--accent-ink); }
.z-fix-close { margin-left: auto; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line-2); background: transparent; color: var(--ink-2); font-size: 20px; cursor: pointer; }
.z-fix-close:hover { color: var(--ink); border-color: var(--accent); }
.z-fix-why { margin: 8px 0 14px; color: var(--ink-2); font-size: 15px; }
.z-fix-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.z-fix-steps li { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); }
.z-fix-n { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--shaky); color: var(--accent-ink); font: 600 13px var(--font); }
.z-fix .z-btn--sm { min-height: 34px; padding: 0 12px; font-size: 13px; white-space: nowrap; }
.z-fix.is-fixed { border-color: var(--pass); background: var(--pass-soft, var(--glass)); }
.z-fix.is-fixed .z-fix-n, .z-fix.is-fixed .z-chip--shaky { background: var(--pass); }
.z-fix-glow { outline: 2px solid var(--shaky); outline-offset: 6px; border-radius: 12px; transition: outline-color 0.6s; }
@media (max-width: 600px) { .z-fix-steps li { grid-template-columns: 28px minmax(0, 1fr); } .z-fix .z-btn--sm { grid-column: 2; justify-self: start; } }

/* ================================================================== phones */

/* the bar shrinks at exactly the same width as the home bar (dashboard.css, 520px) */
@media (max-width: 520px) {
  .z-hero-top { top: 8px; height: 56px; padding: 0 6px 0 12px; gap: 8px; }
  .z-crumb-mark svg { width: 22px; height: 22px; }
  .z-crumbs > a:first-child { gap: 8px; }
  .z-hero-top .z-theme-toggle, .z-pill { height: 36px; padding: 0 10px; font-size: 12px; }
  .z-acct-name { display: none; }
  .z-avatar { margin-right: 0; }
  .z-readbar { left: 12px; right: 12px; }
}

@media (max-width: 600px) {
  :root { --fs-read: 17px; --bar-h: 52px; }
  .z-crumbs { font-size: 12.5px; flex-wrap: nowrap; }
  /* phone: logo + "Stage 0 · 3/20" (tap = back to that stage on the journey map) */
  .z-crumb-word, .z-crumb-stage, .z-crumbs > .z-sep { display: none; }
  .z-crumb-pos { display: inline; }

  .z-analogy, .z-note, .z-see, .z-mistake { padding: 16px 16px 16px 18px; }
  .z-player { padding: 12px; border-radius: 16px; }
  .z-stage { padding: 8px; }
  .z-stage .z-trace-code, .z-stage .z-vars { font-size: 14px; }
  .z-speed-label { margin-left: 0; }
  textarea.z-code, .z-gutter, .z-stdout, .z-code-view, .z-trace-code { font-size: 14px; }
}

/* ================================================================== motion preferences */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .z-lesson > .z-section { animation: none !important; opacity: 1 !important; transform: none !important; }
  .z-btn:hover, html .zt-launch:hover { transform: none; }
  /* Keep "this changed" visible without movement: a steady highlight instead of a flash. */
  .z-vars tr.z-changed { background: var(--flash); }
}

/* ================================================================== print */

@media print {
  .z-controls, .z-run-bar, .z-actions, .z-theme-toggle, .z-gate { display: none !important; }
  body { background: #fff; color: #000; }
  body::after { display: none; }
  .z-hero-top { position: static; }
  .z-lesson > .z-section { animation: none !important; opacity: 1; transform: none; }
}

/* ---- Python run boxes: instant press feedback + warm-up status (py-worker) ---- */
.z-run .z-btn, .z-ex .z-btn { transition: background-color 0.12s, border-color 0.12s, color 0.12s; }
.z-run .z-btn:hover, .z-ex .z-btn:hover { transform: none; box-shadow: none; }
.z-run .z-btn:active:not(:disabled), .z-ex .z-btn:active:not(:disabled) { transform: translateY(1px); transition: none; }
.z-btn.is-running, .z-btn.is-running:disabled { opacity: 0.75; cursor: progress; }
.z-py-warming .z-status:empty::before { content: "Python is getting ready…"; opacity: 0.7; }
.z-output .z-running { margin: 0; }

/* ================================================================== step player: smooth playback (speed slider, progress, ghost layer) */
.z-stage-ghost { z-index: 0; }
/* Keyed morph owns step-to-step motion: entrance animations would re-fade persistent boxes. */
.z-stage.z-morph .z-fade-in { animation: none !important; }
.z-progress-mini > span { width: 100% !important; transform-origin: left center; transform: scaleX(0); transition: none; }
.z-speed-range { width: 120px; accent-color: var(--accent); min-height: 44px; cursor: pointer; }
.z-speed-value { min-width: 4.2em; text-align: right; font: 400 13px var(--mono); color: var(--ink); font-variant-numeric: tabular-nums; }
.z-player.is-playing .z-progress-mini { background: color-mix(in srgb, var(--accent) 18%, var(--line)); }
@media (max-width: 640px) { .z-speed-range { width: 100px; } }
.z-stage { contain: paint; }
.z-say { contain: layout paint; }

/* ===== BEGIN diagram fit (assets/diagram-fit.js): readable diagram text on phones ===== */
.zfit-frame { position: relative; }
.zfit-scroll { max-width: 100%; overflow-x: auto; }
.zfit-frame.is-wide > .zfit-scroller {
  overflow: hidden; touch-action: pan-y pinch-zoom; cursor: grab; min-height: 0;
}
.zfit-frame.is-drag > .zfit-scroller { cursor: grabbing; }
/* The picture slides with a transform only (one CSS variable set by the script): no layout work per frame. */
.zfit-frame.is-wide > .zfit-scroller svg:not(svg svg) {
  transform: translate3d(var(--zfit-x, 0px), 0, 0); will-change: transform;
  transition: transform 0.55s var(--ease-out, cubic-bezier(0.22, 1, 0.36, 1));
}
.zfit-frame.is-drag > .zfit-scroller svg:not(svg svg) { transition: none; }
.zfit-frame.is-wide > .zfit-scroller.zfit-one > svg {
  width: var(--zfit-w) !important; min-width: var(--zfit-w) !important; max-width: none !important; flex-shrink: 0;
  margin-top: var(--zfit-mt, 0) !important; margin-bottom: var(--zfit-mb, 0) !important;
}
.zfit-frame.is-wide > .zfit-scroller:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.zfit-frame::before, .zfit-frame::after {
  content: ""; position: absolute; top: 1px; bottom: 51px; width: 28px; pointer-events: none; z-index: 2;
  opacity: 0; transition: opacity 0.2s;
}
.zfit-frame::before { left: 1px; border-radius: 12px 0 0 12px; background: linear-gradient(90deg, var(--stage-bg), transparent); }
.zfit-frame::after { right: 1px; border-radius: 0 12px 12px 0; background: linear-gradient(270deg, var(--stage-bg), transparent); }
.zfit-frame.zfit-l::before, .zfit-frame.zfit-r::after { opacity: 0.95; }
.zfit-bar { display: none; align-items: center; justify-content: space-between; gap: 8px; height: 44px; margin-top: 6px; }
.zfit-frame.is-wide > .zfit-bar { display: flex; }
.zfit-expand {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--stage-bg); color: var(--ink); font: 500 14px/1 var(--font); cursor: pointer;
}
.zfit-expand:hover { border-color: var(--accent); }
.zfit-expand:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.zfit-hint {
  pointer-events: none; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line);
  background: color-mix(in srgb, var(--stage-bg) 88%, transparent); color: var(--ink);
  font: 500 12.5px/1.4 var(--font); white-space: nowrap; transition: opacity 0.25s;
}
.zfit-frame.is-seen .zfit-hint, .zfit-frame.is-wide:not(.zfit-r):not(.zfit-l) .zfit-hint { opacity: 0; }
.zfit-arrow { display: inline-block; animation: zfit-nudge 1.6s ease-in-out infinite; }
@keyframes zfit-nudge { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(4px); } }
@media (max-width: 340px) { .zfit-hint { font-size: 12px; padding: 3px 8px; } }

/* full-screen view */
html.zfit-ov-on { overflow: hidden; }
.zfit-ov {
  position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0; background: var(--bg, var(--stage-bg)); color: var(--ink);
}
.zfit-ov[open] { display: flex; flex-direction: column; }
.zfit-ov::backdrop { background: rgba(0, 0, 0, 0.6); }
.zfit-ov-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
}
.zfit-ov-title { flex: 1; min-width: 0; font-weight: 500; font-size: 15px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zfit-ov-pan {
  flex: 1; min-height: 0; overflow: auto; touch-action: pan-x pan-y; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch; background: var(--stage-bg);
}
.zfit-ov-pan:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.zfit-ov-stage.z-stage {
  display: inline-block; min-width: 100%; box-sizing: border-box; overflow: visible; contain: none;
  border: 0; border-radius: 0; min-height: 0; padding: 12px;
}
.zfit-ov-foot {
  padding: 8px 12px; padding-bottom: max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line);
  background: var(--bg, var(--stage-bg));
}
.zfit-ov-say { max-height: 26vh; overflow-y: auto; margin: 0 0 8px; }
.zfit-ov-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
@media (orientation: landscape) and (max-height: 520px) {
  .zfit-ov-head { padding-top: 4px; padding-bottom: 4px; }
  .zfit-ov-foot { display: flex; gap: 12px; align-items: center; padding-top: 4px; padding-bottom: 4px; }
  .zfit-ov-say { flex: 1; max-height: 22vh; margin: 0; font-size: 14px; }
  .zfit-ov-controls { flex: none; flex-wrap: nowrap; }
}
@media (prefers-reduced-motion: reduce) {
  .zfit-arrow { animation: none !important; }
  .zfit-frame::before, .zfit-frame::after, .zfit-hint, .zfit-frame.is-wide > .zfit-scroller svg:not(svg svg) { transition: none !important; }
}
/* ===== END diagram fit ===== */
