/* Axiom design system — minimal by intent.
   Ink + warm off-white + one electric indigo accent. Data colours (lime/cyan/
   coral) are reserved for inside simulators only, so the brand stays calm.

   THEMING: every colour is a token on :root. Dark mode overrides the tokens via
   [data-theme="dark"] on <html>. Nothing below hard-codes a colour, so both
   themes stay consistent. The theme is applied by an inline <head> script before
   first paint (no flash) and persisted in localStorage as light|dark|system. */

:root {
  color-scheme: light;

  /* surfaces */
  --ink: #14161a;
  --ink-soft: #3d424b;
  --muted: #6b7280;
  --line: #e6e6e2;
  --line-strong: #cfcfc9;
  --paper: #fbfaf7;
  --card: #ffffff;
  --surface-2: #f1f1ec;
  --surface-3: #eeece6;

  /* accent */
  --accent: #4f46e5;
  --accent-soft: #eeecff;
  --accent-ink: #3730a3;
  --accent-solid: #4f46e5;
  --accent-solid-hover: #4338ca;
  --on-accent: #ffffff;

  /* solid (ink) buttons — deliberately NOT var(--ink) so dark mode stays legible */
  --solid-bg: #14161a;
  --solid-bg-hover: #000000;
  --solid-fg: #ffffff;

  /* semantic */
  --good: #16a34a;
  --good-soft: #eafaf0;
  --good-ink: #14803c;
  --bad: #dc2626;
  --bad-soft: #fdecec;
  --bad-ink: #9b1c1c;
  --warn: #d97706;
  --warn-soft: #fff8e6;
  --warn-ink: #92610a;

  /* data colours (simulator only) */
  --data-lime: #a3e635;
  --data-cyan: #22d3ee;
  --data-coral: #fb7185;
  --data-amber: #fbbf24;

  /* chrome */
  --header-bg: rgba(251, 250, 247, 0.85);
  --footer-bg: #ffffff;
  --stage-1: #fcfcfa;
  --stage-2: #f7f6f2;
  --dot: #eceae4;
  --edge: #c8c9c2;
  --node-border: #dcdcd6;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20, 22, 26, 0.04), 0 8px 24px rgba(20, 22, 26, 0.06);
  --shadow-sm: 0 1px 2px rgba(20, 22, 26, 0.06);
  --maxw: 1080px;
  --font: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
}

/* ---------------------------------------------------------------- dark theme */
:root[data-theme="dark"] {
  color-scheme: dark;

  --ink: #f2f3f5;
  --ink-soft: #c2c6cf;
  --muted: #8b93a1;
  --line: #2a2d35;
  --line-strong: #3a3e48;
  --paper: #0e1014;
  --card: #16181e;
  --surface-2: #1e2128;
  --surface-3: #23262e;

  --accent: #7c7cff;
  --accent-soft: #23233f;
  --accent-ink: #b6b4ff;
  --accent-solid: #6366f1;
  --accent-solid-hover: #7c7cff;
  --on-accent: #ffffff;

  --solid-bg: #f2f3f5;
  --solid-bg-hover: #ffffff;
  --solid-fg: #0e1014;

  --good: #34d399;
  --good-soft: #10261d;
  --good-ink: #6ee7b7;
  --bad: #f87171;
  --bad-soft: #2a1414;
  --bad-ink: #fca5a5;
  --warn: #fbbf24;
  --warn-soft: #2a2110;
  --warn-ink: #fcd34d;

  --header-bg: rgba(14, 16, 20, 0.85);
  --footer-bg: #12141a;
  --stage-1: #14161c;
  --stage-2: #101218;
  --dot: #23262e;
  --edge: #3a3e48;
  --node-border: #343843;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
  transition: background .2s ease, color .2s ease;
}

h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 0.4em; letter-spacing: -0.02em; font-weight: 700; }
h1 { font-size: clamp(1.9rem, 4vw, 3rem); }
h2 { font-size: clamp(1.4rem, 2.6vw, 2rem); }
h3 { font-size: 1.15rem; }
p { margin: 0 0 1rem; }

a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 22px; width: 100%; }

.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.center { text-align: center; }
.mono { font-family: var(--mono); font-size: 0.85rem; }

.skip-link {
  position: absolute; left: -999px; top: 0; background: var(--solid-bg); color: var(--solid-fg);
  padding: 10px 14px; border-radius: 0 0 8px 0; z-index: 50;
}
.skip-link:focus { left: 0; }

/* ---------------------------------------------------------------- header */
.site-header {
  position: sticky; top: 0; z-index: 30;
  background: var(--header-bg);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  display: flex; align-items: center;
  gap: 8px 14px; min-height: 62px; flex-wrap: wrap; padding: 8px 0;
}
.brand { order: 1; display: inline-flex; align-items: center; gap: 9px; min-height: 40px; color: var(--ink); font-weight: 700; letter-spacing: -0.02em; }
.brand:hover { text-decoration: none; }
.brand svg { color: var(--accent); }
.brand-name { font-size: 1.15rem; }
/* Desktop: brand …… nav tools. `.nav` is pushed right by its auto margin. */
.nav { order: 2; margin-left: auto; display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.nav > a { color: var(--ink-soft); font-size: 0.94rem; font-weight: 500; padding: 10px 2px; }
.nav > a:hover { color: var(--ink); text-decoration: none; }
.nav-auth { order: 4; display: inline-flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------------------------------------------------------------- theme switch */
.theme-switch {
  order: 3;
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
}
.theme-switch button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; padding: 0; border: 0; border-radius: 7px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.theme-switch button:hover { color: var(--ink); }
.theme-switch button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow-sm); }
.theme-switch svg { width: 16px; height: 16px; display: block; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; min-height: 42px; border-radius: 10px; font-weight: 600; font-size: 0.92rem;
  border: 1px solid transparent; cursor: pointer; transition: transform .08s ease, background .15s ease, border-color .15s ease;
  font-family: inherit; line-height: 1.15;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-solid { background: var(--solid-bg); color: var(--solid-fg); }
.btn-solid:hover { background: var(--solid-bg-hover); }
.btn-accent { background: var(--accent-solid); color: var(--on-accent); }
.btn-accent:hover { background: var(--accent-solid-hover); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--line-strong); background: var(--card); }
.btn-lg { padding: 13px 22px; font-size: 1rem; border-radius: 12px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------------------------------------------------------------- hero */
.hero { padding: 72px 0 40px; }
.hero-kicker {
  display: inline-flex; align-items: center; gap: 8px; font-size: 0.8rem; font-weight: 600;
  color: var(--accent-ink); background: var(--accent-soft); padding: 5px 12px; border-radius: 100px; margin-bottom: 18px;
}
.hero h1 { max-width: 15ch; }
.hero .lede { font-size: 1.15rem; color: var(--ink-soft); max-width: 56ch; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 26px; }

/* ---------------------------------------------------------------- sections */
.section { padding: 54px 0; }
.section-head { margin-bottom: 28px; max-width: 60ch; }
.section-head .eyebrow { color: var(--accent-ink); font-weight: 600; font-size: 0.82rem; text-transform: uppercase; letter-spacing: .08em; }

/* ---------------------------------------------------------------- grid + cards */
.grid { display: grid; gap: 16px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 860px) { .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 620px) { .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow-sm);
}
.card-hover { transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease; }
.card-hover:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--line-strong); }

/* ---------------------------------------------------------------- lesson cards */
.lesson-card { display: flex; flex-direction: column; gap: 10px; height: 100%; color: var(--ink); }
.lesson-card:hover { text-decoration: none; }
.lesson-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.lesson-emoji { font-size: 1.5rem; line-height: 1; }
.lesson-no { font-family: var(--mono); font-size: 0.75rem; color: var(--muted); }
.lesson-title { font-size: 1.02rem; font-weight: 650; margin: 0; }
.lesson-sub { font-size: 0.9rem; color: var(--muted); margin: 0; flex: 1; }
.lesson-meta { display: flex; align-items: center; gap: 10px; font-size: 0.78rem; color: var(--muted); }
.lesson-meta .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--line-strong); }

.tag {
  display: inline-flex; align-items: center; gap: 5px; font-size: 0.72rem; font-weight: 600;
  padding: 3px 9px; border-radius: 100px; background: var(--surface-2); color: var(--ink-soft);
}
.tag-free { background: var(--good-soft); color: var(--good-ink); }
.tag-pro { background: var(--accent-soft); color: var(--accent-ink); }
.tag-sim { background: var(--warn-soft); color: var(--warn-ink); }

/* ---------------------------------------------------------------- filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }
.chip {
  padding: 8px 14px; min-height: 40px; display: inline-flex; align-items: center;
  border-radius: 100px; border: 1px solid var(--line); background: var(--card);
  font-size: 0.85rem; font-weight: 500; color: var(--ink-soft); cursor: pointer; font-family: inherit;
}
.chip:hover { border-color: var(--line-strong); }
.chip[aria-pressed="true"] { background: var(--solid-bg); color: var(--solid-fg); border-color: var(--solid-bg); }

/* ---------------------------------------------------------------- lesson page */
.lesson-layout { display: grid; grid-template-columns: minmax(0,1fr) 300px; gap: 40px; padding: 40px 0 70px; align-items: start; }
.lesson-layout > * { min-width: 0; } /* let the column shrink so inner diagrams can scroll */
@media (max-width: 900px) { .lesson-layout { grid-template-columns: 1fr; gap: 28px; } }
.lesson-header { border-bottom: 1px solid var(--line); padding-bottom: 22px; margin-bottom: 26px; }
.lesson-header .crumbs { font-size: 0.82rem; color: var(--muted); margin-bottom: 12px; }
.crumbs a, .center a { display: inline-block; padding: 11px 2px; } /* comfortable tap area for text links */
.lesson-header h1 { margin: 6px 0 8px; }
.lesson-header .sub { color: var(--ink-soft); font-size: 1.05rem; }

.level-toggle { display: inline-flex; padding: 4px; background: var(--surface-2); border-radius: 11px; margin: 4px 0 26px; max-width: 100%; flex-wrap: wrap; }
.level-toggle button {
  border: 0; background: transparent; padding: 8px 16px; min-height: 40px; border-radius: 8px; cursor: pointer;
  font-weight: 600; font-size: 0.88rem; color: var(--muted); font-family: inherit;
}
.level-toggle button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow-sm); }

.hook { font-size: 1.25rem; font-weight: 600; color: var(--ink); margin-bottom: 14px; letter-spacing: -0.01em; }
.story { font-size: 1.05rem; color: var(--ink-soft); }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin: 22px 0; }
.panel h3 { display: flex; align-items: center; gap: 8px; }
.takeaways { list-style: none; padding: 0; margin: 14px 0 0; }
.takeaways li { position: relative; padding: 0 0 12px 30px; }
.takeaways li::before {
  content: ""; position: absolute; left: 4px; top: 7px; width: 8px; height: 8px; border-radius: 2px;
  background: var(--accent); transform: rotate(45deg);
}
.pitfalls li::before { background: var(--data-coral); }

.cheat {
  border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 14px 18px; font-weight: 600; color: var(--accent-ink);
}

/* ---------------------------------------------------------------- quiz */
.quiz-q { margin-bottom: 20px; }
.quiz-q .q { font-weight: 600; margin-bottom: 10px; }
.quiz-opt {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 11px 14px; margin-bottom: 8px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--card); cursor: pointer; font: inherit; color: var(--ink);
}
.quiz-opt:hover { border-color: var(--line-strong); }
.quiz-opt.correct { border-color: var(--good); background: var(--good-soft); }
.quiz-opt.wrong { border-color: var(--bad); background: var(--bad-soft); }

/* ---------------------------------------------------------------- sidebar */
.side-card { position: sticky; top: 82px; }
.progress-bar { height: 8px; background: var(--surface-3); border-radius: 100px; overflow: hidden; margin: 12px 0; }
.progress-bar > span { display: block; height: 100%; background: var(--accent); border-radius: 100px; transition: width .4s ease; }

/* ---------------------------------------------------------------- comments */
.comment { border-bottom: 1px solid var(--line); padding: 16px 0; }
.comment:last-child { border-bottom: 0; }
.comment-head { display: flex; align-items: center; gap: 9px; margin-bottom: 5px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.78rem;
}
.comment-name { font-weight: 600; font-size: 0.9rem; }
.comment-time { font-size: 0.78rem; color: var(--muted); }
.comment-body { margin: 0 0 6px; font-size: 0.96rem; }
.comment-actions { display: flex; gap: 12px; font-size: 0.8rem; }
.linklike { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 8px 0; min-height: 40px; display: inline-flex; align-items: center; }
.linklike:hover { color: var(--ink); text-decoration: underline; }

.badge-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; background: var(--card); border: 1px solid var(--line); border-radius: 100px; padding: 4px 11px; font-weight: 600; }

/* ---------------------------------------------------------------- forms */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; font-size: 0.88rem; margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font: inherit; background: var(--card); color: var(--ink);
}
.field input::placeholder, .field textarea::placeholder { color: var(--muted); }
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.note { font-size: 0.82rem; color: var(--muted); }
.alert { padding: 11px 14px; border-radius: var(--radius-sm); font-size: 0.9rem; margin-bottom: 16px; }
.alert-error { background: var(--bad-soft); color: var(--bad-ink); }
.alert-ok { background: var(--good-soft); color: var(--good-ink); }
.alert-info { background: var(--accent-soft); color: var(--accent-ink); }

.auth-wrap { max-width: 420px; margin: 60px auto; }

/* ---------------------------------------------------------------- simulators */
.sim {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); overflow: hidden;
  box-shadow: var(--shadow-sm); min-width: 0;
}
/* grid/flex parents must be allowed to shrink below their content, otherwise a
   wide diagram (or any long line) forces the whole page to scroll sideways */
.sim-list { display: grid; gap: 22px; }
.sim-list > * { min-width: 0; }
.sim-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sim-title { font-weight: 700; display: flex; align-items: center; gap: 9px; }
.sim-stage { padding: 22px; background: linear-gradient(180deg, var(--stage-1), var(--stage-2)); }
.sim-controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.sim-canvas { width: 100%; display: block; }
.sim-readout { display: flex; gap: 22px; flex-wrap: wrap; padding: 14px 20px; border-top: 1px solid var(--line); font-size: 0.85rem; }
.metric { display: flex; flex-direction: column; }
.metric b { font-size: 1.3rem; font-family: var(--mono); }
.metric span { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: .05em; }

.flow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.node {
  padding: 9px 14px; border-radius: 10px; border: 2px solid var(--line); background: var(--card); font-size: 0.84rem; font-weight: 600;
  transition: all .25s ease;
}
.node.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); transform: scale(1.04); }
.node.ok { border-color: var(--good); background: var(--good-soft); color: var(--good-ink); }
.node.bad { border-color: var(--bad); background: var(--bad-soft); color: var(--bad-ink); }
.node.pending { border-color: var(--data-amber); background: var(--warn-soft); color: var(--warn-ink); }
.arrow { color: var(--muted); }

.pipeline { display: grid; gap: 10px; }
.pipe-row { display: grid; grid-template-columns: 84px 1fr 44px; gap: 10px; align-items: center; font-size: 0.82rem; }
.pipe-track { height: 22px; background: var(--surface-3); border-radius: 6px; overflow: hidden; position: relative; }
.pipe-fill { height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }

.token {
  display: inline-flex; align-items: center; justify-content: center; min-width: 40px; height: 30px; padding: 0 8px;
  border-radius: 8px; font-family: var(--mono); font-size: 0.72rem; font-weight: 600; margin: 3px;
  background: var(--card); border: 1px solid var(--line);
}

/* ---------------------------------------------------------------- flow diagrams */
.sim-note { margin: 14px 0 0; }

.flow-svg {
  width: 100%; height: auto; display: block; max-height: 340px;
  background:
    radial-gradient(circle at 1px 1px, var(--dot) 1px, transparent 0) 0 0 / 22px 22px;
  border-radius: var(--radius-sm);
}

.flow-edge { stroke: var(--edge); stroke-width: 2; }
.flow-edge-label {
  font-family: var(--font); font-size: 11px; font-weight: 600;
  fill: var(--muted); paint-order: stroke; stroke: var(--stage-1); stroke-width: 4px;
}

.flow-node rect {
  fill: var(--card); stroke: var(--node-border); stroke-width: 2;
  transition: fill .25s ease, stroke .25s ease, transform .2s ease;
}
.flow-node { transform-box: fill-box; transform-origin: center; transition: transform .2s ease; }
.flow-node-label {
  font-family: var(--font); font-size: 13px; font-weight: 650; fill: var(--ink);
}
.flow-node-sub {
  font-family: var(--mono); font-size: 10.5px; fill: var(--muted);
}
.flow-node.active rect { stroke: var(--accent); fill: var(--accent-soft); }
.flow-node.ok rect { stroke: var(--good); fill: var(--good-soft); }
.flow-node.bad rect { stroke: var(--bad); fill: var(--bad-soft); }
.flow-node.pending rect { stroke: var(--data-amber); fill: var(--warn-soft); }
.flow-node.pulse { animation: nodePulse .5s ease; }
@keyframes nodePulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }

.packet { fill: var(--accent); stroke: var(--card); stroke-width: 2; filter: drop-shadow(0 2px 5px rgba(20,22,26,.22)); }
.packet-label {
  font-family: var(--mono); font-size: 10.5px; font-weight: 700; fill: var(--ink-soft);
  paint-order: stroke; stroke: var(--stage-1); stroke-width: 4px;
}

.retry-timeline { display: grid; gap: 6px; margin-top: 14px; }
.retry-row {
  display: flex; align-items: center; gap: 12px; font-size: 0.86rem;
  padding: 7px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--card);
}
.ok-tag { color: var(--good); font-weight: 700; }
.bad-tag { color: var(--bad); font-weight: 700; }

/* ---------------------------------------------------------------- dashboard */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
@media (max-width: 720px) { .stat-grid { grid-template-columns: 1fr 1fr; } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.stat b { font-size: 1.9rem; display: block; font-family: var(--mono); letter-spacing: -0.02em; }
.stat span { color: var(--muted); font-size: 0.82rem; }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.badge-card { text-align: center; padding: 16px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.badge-card.locked { opacity: .45; filter: grayscale(1); }
.badge-icon { font-size: 1.6rem; }

/* ---------------------------------------------------------------- footer */
.site-footer { border-top: 1px solid var(--line); margin-top: 40px; padding: 30px 0; background: var(--footer-bg); }
.footer-inner { display: flex; flex-direction: column; gap: 6px; }
.footer-brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; color: var(--ink); }
.footer-brand svg { color: var(--accent); }

/* ---------------------------------------------------------------- misc */
.hide { display: none !important; }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.rail { display: flex; gap: 6px; }
.rail .seg { flex: 1; height: 10px; border-radius: 4px; background: var(--surface-3); }
.rail .seg.done { background: var(--good); }
.rail .seg.cur { background: var(--accent); }

/* ================================================================ MOBILE
   Phones are a first-class target, not an afterthought. Everything below
   only tightens spacing / re-flows the header / keeps diagrams legible —
   no colour or component behaviour changes. */
img, svg { max-width: 100%; }
body { overflow-wrap: break-word; word-break: break-word; }
.comment-body, .story, .hook { overflow-wrap: anywhere; }

@media (max-width: 720px) {
  /* tighter page gutters */
  .wrap { padding: 0 16px; }

  /* header: brand + theme + auth on row 1, primary nav on its own row */
  .header-inner { gap: 8px 10px; min-height: 56px; }
  .theme-switch { order: 2; margin-left: auto; }
  .nav-auth { order: 3; }
  .nav {
    order: 4; flex-basis: 100%; margin-left: 0; justify-content: flex-start;
    gap: 16px; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 2px;
  }
  .nav > a { padding: 10px 0; }

  /* let the auth buttons shrink rather than force the header wide */
  .nav-auth .btn { padding: 8px 12px; font-size: 0.88rem; }

  /* vertical rhythm */
  .hero { padding: 40px 0 26px; }
  .hero .lede { font-size: 1.05rem; }
  .section { padding: 36px 0; }
  .section-head { margin-bottom: 20px; }
  .lesson-layout { padding: 22px 0 46px; }
  .side-card { position: static; top: auto; }
  .panel { padding: 18px 16px; }
  .card { padding: 18px; }
  .auth-wrap { margin: 28px auto; }

  /* full-width primary actions read better on a phone */
  .hero-actions { gap: 10px; }
  .hero-actions .btn { flex: 1 1 auto; }

  /* simulators: keep the flow diagram legible by letting it scroll
     horizontally at a readable size instead of shrinking to nothing */
  .sim-head { padding: 14px 16px; }
  .sim-stage { padding: 14px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .flow-svg { min-width: 620px; }
  .sim-controls { gap: 8px; width: 100%; }
  .sim-controls .btn { flex: 1 1 auto; }
  .sim-readout { gap: 16px; padding: 12px 16px; }
  .metric b { font-size: 1.15rem; }

  /* dashboard + forms */
  .stat { padding: 14px; }
  .stat b { font-size: 1.6rem; }
  .field input, .field textarea { font-size: 16px; } /* stops iOS zoom-on-focus */
}

@media (max-width: 380px) {
  .wrap { padding: 0 13px; }
  .nav { gap: 12px; }
  .brand-name { font-size: 1.05rem; }
  .stat-grid { grid-template-columns: 1fr; }
  .flow-svg { min-width: 560px; }
}
