/* Simulations by AD: shared look for every simulation page.
   Follows the blog's theme (themes/cactus-ad): the blue-grey ramp, Menlo / Meslo,
   the dotted page texture, and the same light/dark switch (assets/theme.js).
   The diagram itself sits on a light "figure" panel in both modes.
   Pages are plain HTML + one steps file; assets/sim.js builds the layout from the page's config. */
@font-face { font-family: "Meslo LG"; font-style: normal; font-weight: 400; font-display: swap; src: local("Meslo LG S"), url("fonts/MesloLGS-Regular-latin.woff2") format("woff2"); }
@font-face { font-family: "Meslo LG"; font-style: normal; font-weight: 700; font-display: swap; src: local("Meslo LG S Bold"), url("fonts/MesloLGS-Bold-latin.woff2") format("woff2"); }
@font-face { font-family: "Meslo Fallback"; src: local("DejaVu Sans Mono"), local("Courier New"), local("Droid Sans Mono"), local("Liberation Mono"); size-adjust: 100%; ascent-override: 97.7%; descent-override: 28.5%; line-gap-override: 0%; }

/* dark (the site's default palette when the reader picked dark) */
:root {
  --bg: #071522; --card: #0b1c2d; --sheet: #102a43; --chip: #16324f;
  --ink: #f0f4f8; --ink-2: #bcccdc; --muted: #829ab1;
  --line: #1d3a57; --line-2: #486581; --on-ink: #071522;
  --dots: rgba(130,154,177,.22); --bar-bg: rgba(7,21,34,.92);
  --stage: #0d2033; --stage-line: rgba(188,204,220,.075); --stage-edge: #1d3a57;
  --text: #bcccdc; --fab-bg: #bcccdc; --fab-ink: #102a43;
  --mono: Menlo, "Meslo LG", "Meslo Fallback", ui-monospace, monospace;
  color-scheme: dark;
}
/* light (the site's default) */
[data-theme="light"] {
  --bg: #f0f4f8; --card: #f7f9fb; --sheet: #ffffff; --chip: #e1e8ef;
  --ink: #102a43; --ink-2: #243b53; --muted: #486581;
  --line: #bcccdc; --line-2: #829ab1; --on-ink: #f0f4f8;
  --dots: rgba(72,101,129,.19); --bar-bg: rgba(240,244,248,.94);
  --stage: #e6edf4; --stage-line: rgba(16,42,67,.07); --stage-edge: #bcccdc;
  --text: #102a43; --fab-bg: #102a43; --fab-ink: #bcccdc;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background-color: var(--bg); background-image: radial-gradient(var(--dots) 1px, transparent 1.2px); background-size: 22px 22px; color: var(--ink-2); font-family: var(--mono); font-size: 13px; -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; -webkit-font-smoothing: antialiased; }
a { color: inherit; } button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
h1, h2, h3, b, strong { color: var(--ink); }

/* desktop header: the blog's own (themes/cactus-ad header.ejs), measured from the built blog:
   page box max(1120px, min(85%, 100% - 540px)) with 80px side rails, header 64px from the top,
   50px round avatar, 24/32px bold title, 14px routes, and the round theme button fixed in the right rail. */
:root { --box: max(1120px, min(85vw, 100vw - 540px)); }
.site-hd { max-width: var(--box); margin: 0 auto; padding: 64px 80px 0; margin-bottom: 32px; min-height: 60px; }
.site-id { display: block; text-decoration: none; }
.site-id img { float: left; width: 50px; height: 50px; margin-right: 20px; border-radius: 50%; object-fit: cover; }
.site-name { display: block; font-size: 24px; line-height: 32px; font-weight: 700; letter-spacing: .01em; color: var(--text); }
.site-nav { font-size: 14px; font-weight: 200; letter-spacing: .01em; }
.site-nav ul { margin: 0; padding: 0; list-style: none; line-height: 16px; }
.site-nav li { display: inline-block; margin-right: 21.6px; vertical-align: middle; } .site-nav li:last-child { margin-right: 0; }
.site-nav a { display: inline-block; padding: 6px 2px; color: var(--muted); text-decoration: none; }
.site-nav a:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 5px; }
.site-theme { position: fixed; z-index: 20; top: 69px; right: max(12px, calc((100vw - var(--box)) / 2 + 12px)); width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--muted); background: var(--fab-bg); color: var(--fab-ink); box-shadow: 0 1px 3px rgba(0,0,0,.18); display: flex; align-items: center; justify-content: center; padding: 0; }
.site-theme svg { width: 18px; height: 18px; }
.i-moon, .i-sun { display: inline-flex; } .i-moon { display: none; } [data-theme="light"] .i-moon { display: inline-flex; } [data-theme="light"] .i-sun { display: none; }
.iconbtn { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border-radius: 4px; border: 1px solid var(--line-2); background: var(--sheet); color: var(--ink); font-size: 12.5px; text-decoration: none; }

/* phones and touch tablets: app bar (same rule as the blog's site shell) */
.ta { display: none; }
.ta-btn { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 44px; height: 44px; border: 0; border-radius: 50%; background: none; color: var(--ink-2); padding: 0; text-decoration: none; }
.ta-btn:active { background: rgba(128,128,128,.18); }
.ta-title { flex: 1; min-width: 0; font-weight: 700; font-size: 15px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* page grid */
.page { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; padding: 0 80px 24px; max-width: var(--box); margin: 0 auto; align-items: start; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 6px; }
.lesson { padding: 18px 18px 14px; display: grid; gap: 12px; min-width: 0; }
.crumb { font-size: 12px; color: var(--muted); } .crumb a { text-decoration: none; } .crumb a:hover { text-decoration: underline; }
.titlerow { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
h1 { font-size: clamp(20px, 2.3vw, 26px); font-weight: 700; letter-spacing: .01em; margin: 0; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; padding: 3px 8px; border-radius: 4px; border: 1px solid var(--line-2); color: var(--muted); white-space: nowrap; letter-spacing: .04em; text-transform: uppercase; }
.sub { color: var(--muted); margin: 0; font-size: 12.5px; line-height: 1.6; }

/* metric chips */
.metrics { display: flex; gap: 8px; flex-wrap: wrap; min-height: 44px; }
.metric { min-width: 96px; padding: 6px 10px 7px; border-radius: 4px; border: 1px solid var(--line); background: var(--sheet); transition: background .3s, border-color .3s; }
.metric small { display: block; font-size: 9.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.metric b { display: block; font-size: 14px; margin-top: 2px; white-space: nowrap; }
.metric.on { background: var(--chip); border-color: var(--ink); }

/* stage: a light figure panel in both modes */
.stagewrap { position: relative; border-radius: 6px; border: 1px solid var(--stage-edge); background: var(--stage); overflow: hidden; color: #102a43; }
.stagewrap canvas { display: block; width: 100%; height: clamp(360px, calc(100vh - 380px), 760px); touch-action: pan-y; }
.legend { position: absolute; left: 12px; bottom: 10px; display: flex; gap: 12px; flex-wrap: wrap; font-size: 11px; color: #486581; pointer-events: none; max-width: calc(100% - 110px); }
.legend span { display: inline-flex; align-items: center; gap: 5px; } .legend i { width: 9px; height: 9px; border-radius: 50%; border: 1px solid #102a43; background: var(--c); }
.ctl { position: absolute; right: 10px; bottom: 8px; display: flex; gap: 6px; }
.ctl button { width: 34px; height: 34px; border-radius: 4px; border: 1px solid #829ab1; background: #ffffff; color: #102a43; display: grid; place-items: center; }
.ctl button:hover { border-color: #102a43; }
.ctl svg { width: 16px; height: 16px; }

/* stepper */
.stepper { padding: 12px 14px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--sheet); }
.stepper .hd { display: flex; justify-content: space-between; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink); margin-bottom: 10px; } .stepper .hd span { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--muted); }
.dots { position: relative; display: flex; justify-content: space-between; align-items: center; padding: 0 2px; }
.dots::before { content: ""; position: absolute; left: 14px; right: 14px; top: 50%; height: 1px; background: var(--line-2); }
.dots .bar { position: absolute; left: 14px; top: 50%; height: 2px; margin-top: -.5px; background: var(--ink); transition: width .35s ease; }
.dots button { position: relative; z-index: 1; width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line-2); background: var(--sheet); color: var(--muted); font-size: 11px; padding: 0; }
.dots button.done { border-color: var(--ink); color: var(--ink); background: var(--chip); }
.dots button.now { background: var(--ink); border-color: var(--ink); color: var(--on-ink); font-weight: 700; transform: scale(1.1); }
.steplabel { margin-top: 8px; font-size: 11.5px; font-weight: 700; color: var(--ink); min-height: 16px; }

/* right column */
.side { display: grid; gap: 14px; position: sticky; top: 16px; }
.stepcard { padding: 16px; display: grid; gap: 12px; }
.stephd { display: flex; align-items: center; justify-content: space-between; font-size: 11px; font-weight: 700; letter-spacing: .06em; color: var(--muted); }
.tag { font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; padding: 2px 8px; border-radius: 4px; border: 1px solid var(--line-2); color: var(--ink); }
.tag.try, .tag.recap { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
h2 { margin: 0; font-size: 17px; font-weight: 700; line-height: 1.35; }
.body { font-size: 12.5px; line-height: 1.7; color: var(--ink-2); display: grid; gap: 10px; } .body p { margin: 0; }
.body ol, .body ul { margin: 0; padding-left: 20px; }
.body code, .body .k { font-size: 11.5px; padding: 1px 6px; border-radius: 4px; background: var(--chip); color: var(--ink); }
.note { display: grid; grid-template-columns: 22px 1fr; gap: 10px; padding: 10px 12px; border-radius: 4px; border: 1px solid var(--line); border-left: 3px solid var(--ink); background: var(--chip); font-size: 12px; line-height: 1.6; color: var(--ink-2); }
.note .ic { width: 22px; height: 22px; display: grid; place-items: center; font-size: 13px; color: var(--ink); }
.note small { display: block; font-size: 10px; font-weight: 700; letter-spacing: .08em; color: var(--muted); margin-bottom: 2px; }
.nav { display: grid; grid-template-columns: auto 1fr; gap: 10px; }
.btn { min-height: 42px; padding: 0 14px; border-radius: 4px; border: 1px solid var(--line-2); background: var(--sheet); color: var(--ink); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:hover { border-color: var(--ink); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.next { background: var(--ink); color: var(--on-ink); border-color: var(--ink); justify-content: space-between; text-align: left; line-height: 1.2; }
.btn.next:hover { opacity: .9; }
.keys { font-size: 10.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.keys kbd { font: inherit; font-size: 10px; padding: 1px 5px; border-radius: 3px; border: 1px solid var(--line-2); background: var(--sheet); color: var(--ink); }
.choice { display: flex; flex-wrap: wrap; gap: 6px; }
.choice button { min-height: 36px; padding: 0 11px; border-radius: 4px; border: 1px solid var(--line-2); background: var(--sheet); color: var(--ink-2); font-size: 12px; }
.choice button:hover { border-color: var(--ink); }
.choice button.on { background: var(--ink); border-color: var(--ink); color: var(--on-ink); font-weight: 700; }
.choice-l { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; }

.learn { padding: 14px 16px; } .learn h3, .more h3 { margin: 0 0 10px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.learn ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; font-size: 12px; color: var(--muted); }
.learn li { display: grid; grid-template-columns: 16px 1fr; gap: 9px; line-height: 1.45; }
.learn li i { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--line-2); margin-top: 1px; }
.learn li.ok { color: var(--ink); } .learn li.ok i { background: var(--ink); border-color: var(--ink); position: relative; }
.learn li.ok i::after { content: ""; position: absolute; left: 4px; top: 1px; width: 3px; height: 7px; border: solid var(--on-ink); border-width: 0 2px 2px 0; transform: rotate(45deg); }

/* below the fold: notes on the left, the quiz on the right; cards are only as tall as their content */
.more { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; max-width: var(--box); margin: 0 auto; padding: 0 80px 18px; }
.more-notes { display: grid; gap: 18px; }
.more .card { padding: 16px; font-size: 12.5px; line-height: 1.7; color: var(--ink-2); }
.more .card p { margin: 0 0 8px; }
.quiz .q { padding: 10px 0; border-top: 1px dashed var(--line-2); } .quiz .q p { margin: 0 0 8px; color: var(--ink); }
.quiz .opts { display: grid; gap: 6px; } .quiz .opts button { text-align: left; min-height: 38px; padding: 7px 10px; border-radius: 4px; border: 1px solid var(--line-2); background: var(--sheet); color: var(--ink-2); font-size: 12px; line-height: 1.4; }
.quiz .opts button.right { background: var(--ink); color: var(--on-ink); border-color: var(--ink); } .quiz .opts button.wrong { text-decoration: line-through; opacity: .6; }
.quiz .why { margin-top: 6px; font-size: 12px; color: var(--muted); } .quiz .score { margin-top: 10px; font-weight: 700; color: var(--ink); }
.foot { max-width: var(--box); margin: 0 auto; font-size: 11px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; padding: 6px 0 calc(10px + env(safe-area-inset-bottom)); }

/* narrow windows: one column */
@media (min-width: 481px) and (max-width: 1023px) { .site-nav { font-size: 13px; } .site-nav ul { display: flex; flex-wrap: nowrap; gap: 0 12px; } .site-nav li { margin-right: 0; } }
@media (max-width: 1023px) {
  .page { grid-template-columns: 1fr; gap: 12px; }
  .side { position: static; }
  .lesson { padding: 14px 12px 12px; }
  .metrics { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -2px; padding: 0 2px 4px; } .metrics::-webkit-scrollbar { display: none; }
  .stagewrap canvas { height: min(92vw, 56vh); min-height: 280px; }
  .more { grid-template-columns: 1fr; gap: 12px; } .more-notes { gap: 12px; }
  .dots button { flex: 0 1 24px; width: auto; height: auto; min-width: 0; aspect-ratio: 1; font-size: 10px; }
  .stepper { padding: 12px 10px 10px; }
}
.mbar { display: none; }
/* phones and touch tablets behave like an app: app bar on top, Back / Next in a thumb bar at the bottom */
@media (max-width: 768px), (min-width: 769px) and (max-width: 1199px) and (hover: none) and (pointer: coarse) {
  .site-hd { display: none; }
  .page, .more, .hero, .grid { padding-left: 10px; padding-right: 10px; }
  .hero { padding-top: 18px; }
  .ta { display: flex; align-items: center; gap: 4px; position: sticky; top: 0; z-index: 40; height: calc(48px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 6px 0; background: var(--bg); border-bottom: 1px solid var(--line); }
  .sub, .keys, .stepcard .nav { display: none; }
  .page { padding-top: 10px; }
  .foot { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .mbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: auto 1fr; gap: 10px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--bar-bg); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); border-top: 1px solid var(--line); }
  .mbar .btn { min-height: 48px; }
  .btn, .choice button, .quiz .opts button { min-height: 44px; }
  .ctl button { width: 44px; height: 44px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* landing page */
.hero { padding: 16px 80px 10px; max-width: var(--box); margin: 0 auto; }
.hero h1 { font-size: clamp(24px, 3.4vw, 34px); margin: 14px 0 10px; }
.hero .sub { display: block; max-width: none; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 22px; padding: 18px 80px; max-width: var(--box); margin: 0 auto 40px; }
.simcard { display: grid; text-decoration: none; overflow: hidden; transition: border-color .15s; }
.simcard:hover { border-color: var(--ink); }
.simcard img { width: 100%; height: auto; aspect-ratio: 1200 / 750; object-fit: cover; display: block; border-bottom: 1px solid var(--line); background: var(--stage); }
.simcard .in { padding: 14px 16px 16px; display: grid; gap: 8px; } .simcard h3 { margin: 0; font-size: 15px; } .simcard p { margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.simcard:hover h3 { text-decoration: underline; text-underline-offset: 4px; }
[hidden] { display: none !important; }
.body pre.code { margin: 0; padding: 10px 12px; border-radius: 4px; background: var(--chip); color: var(--ink); font: inherit; font-size: 11.5px; line-height: 1.65; overflow-x: auto; white-space: pre; }
.body pre.code b { color: var(--ink); } .body pre.code .cm { color: var(--muted); }
.stagewrap canvas { cursor: grab; } .stagewrap canvas.grab { cursor: grabbing; }
.hint3d { position: absolute; top: 10px; left: 12px; font-size: 10.5px; letter-spacing: .04em; color: #486581; background: rgba(248,250,252,.85); border: 1px solid #bcccdc; border-radius: 4px; padding: 3px 8px; pointer-events: none; transition: opacity .4s; }
.hint3d.gone { opacity: 0; }

/* ---- details of our own (not the inspiration's): path location, readouts, a segmented track,
   comment-style notes and route-style buttons, all from the blog's terminal-ish vocabulary ---- */
.crumb { font-size: 12.5px; } .crumb a { color: var(--muted); } .crumb span { color: var(--ink); }
.crumb .crumb-x { color: var(--muted); margin-left: 14px; } .crumb .crumb-x::before { content: "# "; }
.meta { margin: -4px 0 0; font-size: 12px; color: var(--muted); letter-spacing: .02em; }

.readout { position: absolute; top: 10px; left: 12px; display: grid; gap: 2px; min-height: 0; max-width: 46%; pointer-events: none; }
.readout .metric { display: grid; grid-template-columns: auto auto; justify-content: start; gap: 10px; min-width: 0; padding: 2px 8px 2px 10px; border: 0; border-left: 2px solid transparent; border-radius: 0; background: rgba(248,250,252,.78); color: #486581; }
.readout .metric small { font-size: 10.5px; letter-spacing: .02em; text-transform: none; color: #486581; }
.readout .metric small::after { content: ":"; }
.readout .metric b { font-size: 12px; margin: 0; color: #102a43; font-weight: 700; }
.readout .metric.on { background: rgba(248,250,252,.95); border-left-color: #102a43; }
.hint3d { left: auto; right: 12px; }
.ctl button { width: auto; height: 32px; padding: 0 10px; gap: 6px; display: inline-flex; align-items: center; font-size: 11px; background: rgba(248,250,252,.9); }
.ctl svg { width: 13px; height: 13px; }

.track { padding: 10px 12px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--sheet); }
.track-hd { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; font-size: 12px; }
#stepLabel { font-weight: 700; color: var(--ink); }
#stepLabel::after { content: ""; display: inline-block; width: .5em; height: 1em; margin-left: .3em; vertical-align: -.15em; background: var(--ink); animation: blink 1.15s steps(1) infinite; }
#stepCount { color: var(--muted); }
.segs { display: flex; gap: 3px; }
.segs button { flex: 1 1 0; min-width: 0; height: 26px; padding: 0; border: 1px solid var(--line-2); border-radius: 2px; background: transparent; color: var(--muted); font-size: 10px; }
.segs button:hover { border-color: var(--ink); color: var(--ink); }
.segs button.done { background: var(--chip); border-color: var(--line-2); color: var(--ink); }
.segs button.now { background: var(--ink); border-color: var(--ink); color: var(--on-ink); font-weight: 700; }
@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { #stepLabel::after { animation: none; } }

.stephd { justify-content: flex-start; gap: 10px; font-size: 12px; letter-spacing: .02em; }
.tag, .tag.try, .tag.recap { padding: 0; border: 0; background: none; color: var(--muted); font-size: 12px; font-weight: 400; letter-spacing: .02em; text-transform: none; }
.tag::before { content: "· "; }
.note, .note.know, .note.watch { display: block; padding: 2px 0 2px 12px; border: 0; border-left: 2px solid var(--ink); border-radius: 0; background: none; color: var(--ink-2); }
.note small { display: block; font-size: 11px; font-weight: 400; letter-spacing: .02em; color: var(--muted); margin-bottom: 3px; }
.btn.js-back { border-color: transparent; background: none; color: var(--muted); text-decoration: underline; text-underline-offset: 4px; padding: 0 10px; }
.btn.js-back:hover { color: var(--ink); }
.btn.js-back::before { content: "cd .."; text-decoration: none; display: none; }
.btn.next { justify-content: flex-start; gap: 12px; font-weight: 700; }
.btn.next .go { font-weight: 400; opacity: .7; }
.btn.next::after { content: "⏎"; margin-left: auto; opacity: .7; font-weight: 400; }

.learn h3::before, .more h3::before, .quiz h3::before { content: "## "; color: var(--muted); }
.learn h3, .more h3 { text-transform: none; letter-spacing: .01em; font-size: 13px; }
.learn li { grid-template-columns: 26px 1fr; gap: 6px; }
.learn li i, .learn li.ok i { width: auto; height: auto; border: 0; background: none; margin: 0; }
.learn li i::before { content: "[ ]"; color: var(--line-2); }
.learn li.ok i::before { content: "[x]"; color: var(--ink); }
.learn li.ok i::after { display: none; }
@media (max-width: 1023px) { .readout { max-width: 70%; } .readout .metric small, .readout .metric b { font-size: 10.5px; } .hint3d { display: none; } }
.legend { max-width: calc(100% - 190px); }
.hero .crumb { margin-bottom: 4px; } .hero .meta { margin: 0 0 12px; }
.choice-l { text-transform: lowercase; font-weight: 400; letter-spacing: .02em; font-size: 11.5px; } .choice-l::before { content: "# "; }

/* full-page mode */
.fspanel { display: none; }
#fsbtn svg { width: 13px; height: 13px; }
body.full { overflow: hidden; }
body.full .stagewrap { position: fixed; inset: 0; z-index: 60; border: 0; border-radius: 0; }
body.full .stagewrap canvas { height: 100vh; height: 100dvh; }
body.full .ctl { top: calc(10px + env(safe-area-inset-top)); bottom: auto; right: 12px; }
body.full .hint3d { display: none; }
body.full .readout { top: calc(10px + env(safe-area-inset-top)); }
body.full .legend { bottom: 14px; max-width: calc(100% - 440px); }
body.full .fspanel { display: grid; gap: 8px; position: absolute; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); width: min(400px, calc(100% - 28px)); max-height: 60%; overflow: auto; padding: 14px 16px; background: var(--card); color: var(--ink-2); border: 1px solid var(--line-2); border-radius: 6px; box-shadow: 0 10px 30px -12px rgba(16,42,67,.35); }
.fs-hd { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); white-space: pre; }
.fs-more { border: 0; background: none; color: var(--muted); text-decoration: underline; text-underline-offset: 4px; font-size: 12px; padding: 4px 0; min-height: 0; }
.fspanel h2 { font-size: 16px; }
.fs-body { font-size: 12.5px; line-height: 1.65; display: grid; gap: 8px; } .fs-body p { margin: 0; } .fs-body ol { margin: 0; padding-left: 18px; }
.fs-body pre.code { margin: 0; padding: 8px 10px; border-radius: 4px; background: var(--chip); color: var(--ink); font: inherit; font-size: 11px; overflow-x: auto; }
body.full .mbar { display: none; }
@media (max-width: 768px), (min-width: 769px) and (max-width: 1199px) and (hover: none) and (pointer: coarse) {
  body.full .legend { display: none; }
  body.full .fspanel { left: 10px; right: 10px; width: auto; bottom: calc(10px + env(safe-area-inset-bottom)); max-height: 50%; }
  body.full .fspanel .nav { display: grid; } body.full .fspanel .btn { min-height: 46px; }
  body.full .readout { max-width: 60%; }
  .ctl #fsbtn span, .ctl #replay span, .ctl #pause span { display: none; }
}

/* ===== full-window "lab" layout (default on every simulation page), modelled on the site's experiments:
   thin top bar, the 3D view fills the window, a side panel with Step / Learn / More tabs that scrolls on
   its own; on phones and touch tablets the panel is a bottom sheet that peeks above the view. ===== */
body.app { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; display: flex; flex-direction: column; overscroll-behavior: none; --panel: 380px; --peek: calc(130px + env(safe-area-inset-bottom)); }
.appbar { flex: none; position: relative; z-index: 20; display: flex; align-items: center; gap: 12px; height: calc(52px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left)); background: var(--bg); border-bottom: 1px solid var(--line); }
.appbar .back { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: 4px; font-size: 12.5px; color: var(--ink-2); text-decoration: none; white-space: nowrap; }
.appbar .back:hover { color: var(--ink); border-color: var(--ink); }
.appbar .brand { min-width: 0; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); } .appbar .brand b { color: var(--ink); }
.appbar .spacer { flex: 1; }
.ab-crumb { font-size: 12px; color: var(--muted); white-space: nowrap; } .ab-crumb::before { content: "# "; }
.ab-theme { flex: none; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--muted); background: var(--fab-bg); color: var(--fab-ink); display: flex; align-items: center; justify-content: center; padding: 0; }
.ab-theme svg { width: 17px; height: 17px; }

.lab { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) var(--panel); }
body.app .stagewrap { border: 0; border-radius: 0; min-width: 0; min-height: 0; }
body.app .stagewrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
body.app .readout { top: 12px; left: 14px; z-index: 2; }
body.app .ctl { top: 12px; right: 14px; bottom: auto; z-index: 3; }
body.app .hint3d { top: 52px; right: 14px; }
.stage-ft { position: absolute; left: 14px; right: 14px; bottom: 14px; z-index: 2; display: grid; gap: 8px; pointer-events: none; }
body.app .legend { position: static; max-width: none; }
body.app .track { pointer-events: auto; background: rgba(248,250,252,.88); border-color: #bcccdc; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); color: #102a43;
  --ink: #102a43; --muted: #486581; --line-2: #829ab1; --chip: #d9e2ec; --on-ink: #f0f4f8; }
.lab-panel { display: flex; flex-direction: column; min-height: 0; background: var(--card); border-left: 1px solid var(--line); }
.lab-handle { display: none; }
.lab-quick { flex: none; display: grid; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.lab-quick h2 { font-size: 16px; }
.lab-tabs { flex: none; display: flex; gap: 4px; padding: 4px 10px 0; border-bottom: 1px solid var(--line); }
.lab-tabs button { flex: 1; min-height: 40px; padding: 8px 4px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); font-size: 12.5px; }
.lab-tabs button::before { content: "./"; opacity: .6; }
.lab-tabs button:hover { color: var(--ink); }
.lab-tabs button.on { color: var(--ink); font-weight: 700; border-bottom-color: var(--ink); }
.lab-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 16px; }
.lab-pane { display: none; gap: 14px; align-content: start; } .lab-pane.on { display: grid; }
.lab-pane h1 { font-size: 20px; line-height: 1.3; }
.lab-pane .meta { margin: 0; } .lab-pane .learn { padding: 4px 0 0; }
.lab-pane.more { font-size: 12.5px; line-height: 1.7; color: var(--ink-2); grid-template-columns: minmax(0, 1fr); gap: 14px; max-width: none; margin: 0; padding: 0; } /* undo the old page-layout .more grid (two columns, 80px gutters), which squeezed this pane to 87px columns */
.lab-pane.more p { margin: 0 0 8px; } .lab-pane.more h3 { margin: 0 0 8px; }
.more-c + .more-c, .lab-pane .quiz { padding-top: 14px; border-top: 1px dashed var(--line-2); }
.lab-pane .foot { padding: 6px 0 0; justify-content: flex-start; }
body.app .mbar, body.app .site-hd, body.app .ta { display: none; }

/* focus mode (F / the focus button): hide the bar and panel; the step text floats over the view */
body.app.full .appbar, body.app.full .lab-panel { display: none; }
body.app.full .lab { grid-template-columns: 1fr; }
body.app.full .stagewrap { position: relative; inset: auto; z-index: auto; }
body.app.full .stagewrap canvas { height: 100%; }
body.app.full .stage-ft { right: calc(14px + min(400px, 100% - 28px) + 14px); }
body.app.full .fspanel { bottom: calc(14px + env(safe-area-inset-bottom)); max-height: calc(100% - 80px); }
body.app.full .legend { max-width: none; }

@media (max-width: 1023px) { body.app { --panel: 340px; } .ab-crumb { display: none; } }
@media (max-width: 860px) {
  .lab { display: block; position: relative; }
  body.app .stagewrap { position: absolute; inset: 0 0 var(--peek) 0; }
  .lab-panel { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; height: min(74dvh, 640px); transform: translateY(calc(100% - var(--peek))); transition: transform .3s cubic-bezier(.2,.8,.2,1); border-left: 0; border-top: 1px solid var(--line-2); border-radius: 14px 14px 0 0; box-shadow: 0 -10px 30px -12px rgba(16,42,67,.35); padding-bottom: env(safe-area-inset-bottom); }
  body[data-sheet="open"] .lab-panel { transform: none; }
  .lab-handle { display: block; flex: none; width: 100%; height: 20px; min-height: 20px; border: 0; background: none; position: relative; }
  .lab-handle::after { content: ""; position: absolute; left: 50%; top: 7px; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--line-2); }
  .lab-quick { padding: 0 12px 10px; gap: 8px; border-bottom: 0; }
  .lab-quick h2 { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .lab-quick .nav .btn { min-height: 44px; }
  body.app .stepcard .nav, body.app .lab-quick .nav { display: grid; }
  body.app .sub { display: block; } body.app .keys { display: none; }
  .stage-ft { left: 8px; right: 8px; bottom: 8px; } body.app .legend { display: none; }
  body.app .track { padding: 6px 8px 8px; } body.app .track-hd { margin-bottom: 5px; font-size: 11px; }
  body.app .readout { left: 8px; top: 8px; } body.app .ctl { right: 8px; top: 8px; } body.app .ctl button { width: 40px; height: 40px; padding: 0; justify-content: center; }
  .ctl #fsbtn span, .ctl #replay span, .ctl #pause span { display: none; }
  .appbar { height: calc(48px + env(safe-area-inset-top)); } .appbar .back-t, .appbar .brand-p { display: none; } .appbar .brand { font-size: 14px; font-weight: 700; }
  body.app.full .stagewrap { position: absolute; inset: 0; }
  body.app.full .stage-ft { display: none; }
  body.app.full .fspanel { left: 8px; right: 8px; width: auto; bottom: calc(8px + env(safe-area-inset-bottom)); max-height: 50%; }
}
@media (max-width: 860px) { .lab-quick .stephd, .lab-quick h2 { cursor: pointer; } }

/* blog nav (themes/cactus-ad header.styl): the "/explore-more" dropdown group, and search as a round
   button just left of the theme toggle, level with it, scrolling away with the header */
/* "/explore-more" opens as a second nav row (the blog's "Row" style, header.styl): click or Enter only,
   a dashed-ruled line under the nav that reads like a shell listing. Desktop only: the app shell hides .site-hd. */
.site-hd { position: relative; }
.site-nav li.has-sub { position: static; }
.nav-sub-toggle { margin: 0; padding: 6px 2px; border: 0; background: none; color: var(--muted); font: inherit; letter-spacing: inherit; line-height: inherit; cursor: pointer; -webkit-appearance: none; appearance: none; }
.nav-sub-toggle:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 5px; }
.nav-sub-toggle:focus-visible { color: var(--ink); }
.nav-sub-toggle::after { content: ""; display: inline-block; margin-left: .45em; border: .3em solid transparent; border-top-color: currentColor; border-bottom-width: 0; vertical-align: .1em; }
.site-nav li.has-sub.open > .nav-sub-toggle::after { border-top-width: 0; border-bottom: .3em solid currentColor; border-top-color: transparent; }
.site-nav li.current > .nav-sub-toggle { color: var(--ink); font-weight: 700; }
.site-nav ul.nav-sub { display: none; position: absolute; top: calc(100% + 6.4px); left: 80px; right: 80px; z-index: 30; margin: 0; padding: 7.2px 0; border-top: 1px dashed var(--line-2); border-bottom: 1px dashed var(--line-2); background: var(--bg); white-space: nowrap; }
.site-nav ul.nav-sub::before { content: attr(data-group) "/ $ ls"; margin-right: 20px; color: var(--muted); opacity: .7; }
.site-nav ul.nav-sub li { display: inline-block; margin: 0 21.6px 0 0; }
.site-nav ul.nav-sub a { display: inline-block; padding: 0; }
.site-nav li.has-sub.open > ul.nav-sub { display: block; }
.site-nav li.current > a { color: var(--ink); font-weight: 700; }
.site-nav li.current > a::after { content: ""; display: inline-block; width: .5em; height: 1em; margin-left: .3em; vertical-align: -.15em; background: var(--ink); animation: blink 1.15s steps(1) infinite; }
@media (prefers-reduced-motion: reduce) { .site-nav li.current > a::after { animation: none; } }
@media (min-width: 481px) { .site-hd { padding-right: 128px; } }
.site-search { position: fixed; z-index: 20; top: 69px; right: calc(max(12px, calc((100vw - var(--box)) / 2 + 12px)) + 48px); width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--muted); background: var(--fab-bg); color: var(--fab-ink); box-shadow: 0 1px 3px rgba(0,0,0,.18); display: flex; align-items: center; justify-content: center; padding: 0; text-decoration: none; }
.site-search svg { display: block; pointer-events: none; }
@media (max-width: 768px), (min-width: 769px) and (max-width: 1199px) and (hover: none) and (pointer: coarse) { .hero, .grid { padding-left: 10px; padding-right: 10px; } .hero { padding-top: 18px; } }
.ab-search { text-decoration: none; margin-right: -4px; }

/* dark mode: the figure goes dark with the page. Overlays on the stage take the dark ramp too. */
:root:not([data-theme="light"]) .stagewrap { color: var(--ink-2); }
:root:not([data-theme="light"]) .legend { color: #9fb3c8; }
:root:not([data-theme="light"]) .legend i { border-color: #071522; }
:root:not([data-theme="light"]) .readout .metric { background: rgba(7,21,34,.72); color: #9fb3c8; }
:root:not([data-theme="light"]) .readout .metric small { color: #9fb3c8; }
:root:not([data-theme="light"]) .readout .metric b { color: #f0f4f8; }
:root:not([data-theme="light"]) .readout .metric.on { background: rgba(7,21,34,.9); border-left-color: #f0f4f8; }
:root:not([data-theme="light"]) .ctl button { background: rgba(16,42,67,.88); border-color: #486581; color: #f0f4f8; }
:root:not([data-theme="light"]) .ctl button:hover { border-color: #bcccdc; }
:root:not([data-theme="light"]) .hint3d { background: rgba(7,21,34,.8); border-color: #2a4a69; color: #9fb3c8; }
:root:not([data-theme="light"]) body.app .track { background: rgba(7,21,34,.85); border-color: #2a4a69; color: #f0f4f8;
  --ink: #f0f4f8; --muted: #9fb3c8; --line-2: #486581; --chip: #1d3a57; --on-ink: #071522; }

/* desktop right lane holds two fixed round buttons (search + theme), like the blog's $rail-pair:
   40 + 8 + 40 + 12 + 12 = 112px of right padding, so neither button covers text while scrolling */
@media (min-width: 1200px), (min-width: 769px) and (hover: hover) and (pointer: fine) {
  .hero, .grid { padding-right: 112px; }
  .site-hd { padding-right: 160px; }
  .site-nav ul.nav-sub { right: 112px; }
}

/* the blog's site footer (themes/cactus-ad footer.styl + connect.styl, values as the blog renders them
   with its 16px rem): the "Let's Connect" panel on the landing page, then the 12px meta-colour copyright
   row, with the content's 64px bottom padding below. Desktop only: on phones and touch tablets the blog's
   app shell hides its whole footer, and so does this. Colours are the blog's own tokens. */
.site-ft { --ft-text: #102a43; --ft-meta: #486581; --ft-border: #829ab1; --ft-accent: #102a43; --ft-icon: #486581; --ft-pri-bg: #bcccdc; --ft-pri-ink: #102a43; --ft-status: #1c7a63; --ft-ring: rgba(28,122,99,.22);
  max-width: var(--box); margin: 0 auto; padding: 0 80px 64px; }
:root:not([data-theme="light"]) .site-ft { --ft-text: #bcccdc; --ft-meta: #829ab1; --ft-border: #486581; --ft-accent: #f0f4f8; --ft-icon: #829ab1; --ft-pri-bg: #bcccdc; --ft-pri-ink: #071522; --ft-status: #4fbfa0; --ft-ring: rgba(79,191,160,.22); }
.site-ft .footer-meta { margin-top: 32px; color: var(--ft-meta); font-size: 12px; text-align: left; }
.site-ft .site-connect + .footer-meta { margin-top: 40px; }
.site-ft .footer-left { height: 20px; line-height: 20px; }
.site-connect { margin-top: 48px; padding-top: 32px; border-top: 1px dashed var(--ft-border); color: var(--ft-text); text-align: left; font-size: 16px; }
.site-connect-head { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.site-connect-title { margin: 0; font-size: 21.6px; color: var(--ft-accent); }
.site-connect-lede { margin: 0; font-size: 15.2px; line-height: 1.6; }
.connect-doors { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 36px; margin: 24px 0 0; padding: 0; list-style: none; }
.connect-door { display: flex; flex-direction: column; }
.door-label { color: var(--ft-meta); text-transform: uppercase; letter-spacing: .1em; font-size: 11.2px; line-height: 1.3; }
.door-title { margin: 7.2px 0; color: var(--ft-accent); font-size: 16px; line-height: 1.35; }
.door-body { margin: 0; font-size: 13.6px; line-height: 1.65; }
.site-connect-status { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 24px 0 0; font-size: 13.6px; }
.status-state { display: inline-flex; align-items: center; gap: 8px; }
.status-dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--ft-status); box-shadow: 0 0 0 3px var(--ft-ring); animation: status-pulse 2.6s ease-in-out infinite; }
@keyframes status-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .status-dot { animation: none; } }
.connect-links { display: flex; flex-wrap: wrap; gap: 9.6px; margin: 12px 0 0; padding: 0; list-style: none; }
.connect-links a { display: inline-flex; align-items: center; gap: 7.2px; padding: 7.2px 14.4px; border: 1px solid var(--ft-border); border-radius: 4px; background: transparent; color: var(--ft-text); text-decoration: none; font-size: 14.4px; transition: color .2s, border-color .2s, background-color .2s, transform .2s; }
.connect-links a svg { color: var(--ft-icon); transition: color .2s; }
.connect-links a:hover { border-color: var(--ft-accent); color: var(--ft-accent); transform: translateY(-2px); } .connect-links a:hover svg { color: var(--ft-accent); }
.connect-links a:focus-visible { outline: 2px solid var(--ft-accent); outline-offset: 2px; }
.connect-links a.is-primary { border-color: var(--ft-pri-bg); background: var(--ft-pri-bg); color: var(--ft-pri-ink); font-weight: 700; } .connect-links a.is-primary svg { color: var(--ft-pri-ink); }
.connect-links a.is-primary:hover { border-color: var(--ft-accent); background: transparent; color: var(--ft-accent); } .connect-links a.is-primary:hover svg { color: var(--ft-accent); }
@media (min-width: 1200px), (min-width: 769px) and (hover: hover) and (pointer: fine) { .site-ft { padding-right: 112px; } }
@media (max-width: 1023px) { .connect-doors { gap: 24px; } }
.lab-pane .site-ft { max-width: none; margin: 0; padding: 0; }
.lab-pane .site-ft .footer-meta { margin-top: 14px; }
@media (max-width: 768px), (min-width: 769px) and (max-width: 1199px) and (hover: none) and (pointer: coarse) { .site-ft { display: none; } }

/* the blog's floating buttons (post-fab.styl as rendered, 16px rem): back to top + share, bottom right,
   on the theme button's lane. 900px and up only; the app layout on phones and touch tablets drops them. */
#post-fab { display: none; position: fixed; z-index: 20; right: max(12px, 12px + min(50vw - 560px, max(7.5vw, 270px))); bottom: 32px; flex-direction: column; align-items: center; gap: 12px; }
@media (min-width: 900px) { #post-fab { display: flex; } }
@media print { #post-fab { display: none; } }
#post-fab #back-to-top, #post-fab #share-toggle { align-items: center; justify-content: center; width: 40px; height: 40px; padding: 0; border: 1px solid #829ab1; border-radius: 50%; background: #bcccdc; box-shadow: 0 1px 3px rgba(0,0,0,.18); color: #102a43; font-size: 16.8px; line-height: 1; cursor: pointer; transition: color .2s, border-color .2s, background-color .2s, transform .2s; }
#post-fab #back-to-top { display: none; } #post-fab #back-to-top.is-visible { display: flex; } #post-fab #share-toggle { display: flex; }
#post-fab #back-to-top:hover, #post-fab #share-toggle:hover { border-color: #102a43; transform: scale(1.08); }
#post-fab #back-to-top:focus-visible, #post-fab #share-toggle:focus-visible { outline: 2px solid #102a43; outline-offset: 2px; }
[data-theme="light"] #post-fab #back-to-top, [data-theme="light"] #post-fab #share-toggle { border-color: #486581; background: #102a43; color: #bcccdc; }
[data-theme="light"] #post-fab #back-to-top:hover, [data-theme="light"] #post-fab #share-toggle:hover { color: #f0f4f8; border-color: #f0f4f8; }
[data-theme="light"] #post-fab #back-to-top:focus-visible, [data-theme="light"] #post-fab #share-toggle:focus-visible { outline-color: #f0f4f8; }
#post-fab svg { pointer-events: none; }
#post-fab #share-wrap { position: relative; display: flex; }
#post-fab #share-panel { position: absolute; right: 0; bottom: calc(100% + 9.6px); width: 224px; padding: 12px; border: 1px solid #486581; border-radius: 4px; background: #102a43; box-shadow: 0 4px 16px rgba(0,0,0,.22); }
[data-theme="light"] #post-fab #share-panel { border-color: #829ab1; background: #bcccdc; }
#post-fab #share-panel[hidden] { display: none; }
#post-fab #share-panel ul { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
#post-fab #share-panel li { margin: 0; }
#post-fab #share-panel a { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 1px solid #486581; border-radius: 4px; color: #bcccdc; font-size: 15.2px; text-decoration: none; }
#post-fab #share-panel a:hover { border-color: #f0f4f8; color: #f0f4f8; }
[data-theme="light"] #post-fab #share-panel a { border-color: #829ab1; color: #102a43; }
[data-theme="light"] #post-fab #share-panel a:hover { border-color: #102a43; color: #102a43; }
@media (max-width: 768px), (min-width: 769px) and (max-width: 1199px) and (hover: none) and (pointer: coarse) { #post-fab { display: none !important; } }
.connect-links a svg.fa { font-size: 15.2px; }
