/* =========================================================
   Science Simulations: component system (see DESIGN.md)
   Requires tokens.css first. Vanilla CSS, no imports.
   Light topic worlds. Shape rule: interactive = pill; shell 28 / core 22 / small 14.
   Motion rule: custom easings only, transform and opacity (plus filter on reveal).
   Blur rule: backdrop-filter only on fixed or sticky things. Scrolling = opaque.
   ========================================================= */

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--nav-h) + 32px);
  scrollbar-gutter: stable;
  background: var(--paper);
}
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  font-weight: 400;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, p, figure, blockquote, dl, dd, ul, ol { margin: 0; }
ul[role="list"], ol[role="list"] { list-style: none; padding: 0; }
img, svg, video, canvas { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration-color: var(--hairline-2); text-underline-offset: 0.2em; }
[hidden] { display: none !important; }
::selection { background: var(--accent); color: var(--accent-ink); }

/* ---------- Base typography ---------- */
h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
  text-wrap: balance;
}
p { text-wrap: pretty; }
.display-1 { font-size: var(--fs-d1); line-height: 0.98; }
.display-2 { font-size: var(--fs-d2); line-height: 1; }
.display-3 { font-size: var(--fs-d3); line-height: 1.08; letter-spacing: -0.02em; font-weight: 700; }
.lead { font-size: var(--fs-body-lg); color: var(--ink-2); max-width: var(--measure); line-height: 1.55; }
.prose { max-width: var(--measure); color: var(--ink-2); }
.prose > * + * { margin-top: 1em; }
.prose strong { color: var(--ink); font-weight: 600; }
.text-2 { color: var(--ink-2); }
.text-3 { color: var(--ink-3); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
/* The one small label. Use at most one per three sections. */
.label {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Layout ---------- */
.wrap {
  width: 100%;
  max-width: var(--wrap-max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}
.stack > * + * { margin-top: var(--stack, 1rem); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap, 0.75rem); }

/* ---------- Shadow tint: every surface shadow is the world shade, darkened, never black ---------- */
.glass, .shell, .island, .world-panel, .float-chip, .sim-stage, .sim-panel, .sim-tabbar,
.modal__panel, .toast, .site-footer {
  --tint: color-mix(in oklab, color-mix(in oklab, var(--world-1) 62%, var(--ink)) 55%, transparent);
}

/* ---------- Layers: grain (z-grain) ---------- */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: var(--z-grain);
  pointer-events: none;
  opacity: 0.07;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-size: 220px 220px;
}

/* ---------- World: two offset radial gradients over the field. Never a flat linear gradient. ---------- */
.world {
  position: relative;
  isolation: isolate;
  min-height: 100dvh;
  overflow-x: clip;
  background:
    radial-gradient(60% 50% at 78% 14%, var(--world-2), transparent 72%),
    radial-gradient(55% 60% at 10% 92%, color-mix(in oklab, var(--world-1) 80%, transparent), transparent 72%),
    var(--world-0);
}
/* A world used as a band inside a longer page */
.world--band { min-height: 0; padding-block: clamp(72px, 10vw, 140px); }
/* The giant word behind the subject. Decorative, so aria-hidden in markup. */
.world__word {
  position: absolute;
  z-index: -1;
  inset-inline: 0;
  top: var(--word-top, 8%);
  margin: 0;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--fs-giant);
  line-height: 0.8;
  letter-spacing: -0.04em;
  color: var(--world-word);
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}

/* ---------- Skip link ---------- */
.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: var(--z-toast);
  padding: 12px 20px;
  border-radius: var(--r-pill);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform var(--t-med) var(--ease-out);
}
.skip-link:focus-visible { transform: translateY(0); }

/* ---------- Focus: 2px ink ring with a 2px marigold halo between it and the control ---------- */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--accent);
}
svg :focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
svg :focus-visible { box-shadow: none; }
/* Dark specimen windows: the ring turns light so it still reads */
.specimen, .window { --focus: #ffe3a8; }

/* ---------- Icons ---------- */
.icon { width: 1.25em; height: 1.25em; flex: none; fill: currentColor; }
.icon--sm { width: 1em; height: 1em; }
.icon--lg { width: 1.6em; height: 1.6em; }

/* ---------- Shell / core: the double bezel (28 / 6 / 22) ---------- */
.shell {
  padding: var(--bezel);
  border-radius: var(--r-shell);
  background: rgb(255 255 255 / 0.38);
  border: 1px solid var(--hairline);
  box-shadow:
    inset 0 1px 0 var(--glass-edge),
    0 30px 60px -30px var(--tint);
}
.shell > .core, .core {
  border-radius: var(--r-core);
  background: linear-gradient(170deg, rgb(255 255 255 / 0.92), rgb(255 255 255 / 0.7));
  box-shadow: inset 0 1px 0 #fff, 0 0 0 1px var(--hairline);
  padding: clamp(1.25rem, 2.4vw, 2rem);
  min-width: 0;
}
.core--flush { padding: 0; overflow: hidden; }

/* ---------- Glass (light). Blur ONLY on fixed or sticky things. ---------- */
.glass {
  background:
    linear-gradient(160deg, rgb(255 255 255 / 0.32), rgb(255 255 255 / 0) 60%),
    var(--glass-fill);
  border: 1px solid var(--hairline);
  box-shadow:
    inset 0 1px 0 var(--glass-edge),
    0 24px 56px -24px var(--tint);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  backdrop-filter: blur(22px) saturate(160%);
}
/* Same look, opaque, no blur: anything inside scrolling content. Declared AFTER .glass and
   with no compound selector, so it always wins (this was the .shell.glass bug). */
.glass--solid {
  background:
    linear-gradient(160deg, rgb(255 255 255 / 0.6), rgb(255 255 255 / 0) 60%),
    color-mix(in oklab, var(--world-2) 45%, #fff);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* ---------- Buttons ---------- */
.btn {
  --btn-h: 48px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: var(--btn-h);
  padding: 0 22px;
  border-radius: var(--r-pill);
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.005em;
  white-space: nowrap;
  text-decoration: none;
  color: var(--ink);
  transition:
    transform var(--t-fast) var(--ease-out),
    background-color var(--t-med) var(--ease-out),
    box-shadow var(--t-med) var(--ease-out),
    border-color var(--t-med) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }

.btn__icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgb(18 23 34 / 0.12);
  transition: transform var(--t-med) var(--ease-spring), background-color var(--t-med) var(--ease-out);
}
.btn__icon .icon { width: 18px; height: 18px; }
.btn:has(.btn__icon) { padding-right: 7px; }

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.55),
    inset 0 -1px 0 rgb(150 90 0 / 0.25),
    0 14px 30px -14px rgb(214 140 10 / 0.7);
}
.btn--ghost {
  background: rgb(255 255 255 / 0.55);
  border: 1px solid var(--hairline-2);
  box-shadow: inset 0 1px 0 #fff;
}
.btn--ghost .btn__icon { background: rgb(18 23 34 / 0.08); }
.btn--quiet {
  min-height: 44px;
  padding: 0 6px;
  color: var(--ink-2);
}
.btn--quiet::after {
  content: "";
  position: absolute;
  left: 6px; right: 6px; bottom: 9px;
  height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--t-med) var(--ease-out);
}
.btn--icon {
  width: 44px;
  min-height: 44px;
  padding: 0;
}
.btn--icon .icon { width: 20px; height: 20px; }

@media (hover: hover) and (pointer: fine) {
  .btn--primary:hover { box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.6), inset 0 -1px 0 rgb(150 90 0 / 0.25), 0 18px 36px -14px rgb(214 140 10 / 0.85); }
  .btn:hover .btn__icon { transform: translate(2px, -1px) scale(1.06); }
  .btn--ghost:hover { background: rgb(255 255 255 / 0.85); border-color: rgb(18 23 34 / 0.32); }
  .btn--quiet:hover { color: var(--ink); }
  .btn--quiet:hover::after { transform: scaleX(1); }
}

/* ---------- Chip ---------- */
.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 14px;
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  color: var(--ink-2);
  background: rgb(255 255 255 / 0.62);
  border: 1px solid var(--hairline);
  box-shadow: inset 0 1px 0 #fff;
  transition: transform var(--t-fast) var(--ease-out), background-color var(--t-med) var(--ease-out), color var(--t-med) var(--ease-out), border-color var(--t-med) var(--ease-out);
}
button.chip::after, a.chip::after { content: ""; position: absolute; inset: -5px 0; } /* 44px hit area */
button.chip:active, a.chip:active { transform: scale(0.97); }
a.chip { text-decoration: none; }
.chip[aria-pressed="true"] {
  color: var(--accent-ink);
  font-weight: 600;
  background: var(--accent);
  border-color: var(--accent-edge);
}
@media (hover: hover) and (pointer: fine) {
  button.chip:hover, a.chip:hover { color: var(--ink); border-color: var(--hairline-2); background: #fff; }
  .chip[aria-pressed="true"]:hover { color: var(--accent-ink); background: #ffc462; }
}

/* ---------- Segmented control (thumb driven by site.js) ---------- */
.seg {
  --thumb-x: 0px;
  --thumb-w: 0px;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: var(--r-pill);
  background: rgb(18 23 34 / 0.07);
  border: 1px solid var(--hairline);
  box-shadow: inset 0 1px 2px rgb(18 23 34 / 0.1);
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg::before {
  content: "";
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 0;
  width: var(--thumb-w);
  border-radius: var(--r-pill);
  background: var(--accent);
  border: 1px solid var(--accent-edge);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.6), 0 6px 14px -8px rgb(214 140 10 / 0.8);
  transform: translateX(var(--thumb-x));
  opacity: 0;
}
.seg[data-ready]::before { opacity: 1; }
.seg[data-animate]::before {
  transition: transform var(--t-med) var(--ease-spring), width var(--t-med) var(--ease-spring);
}
.seg__btn {
  position: relative;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  font-weight: 500;
  white-space: nowrap;
  color: var(--ink-2);
  transition: color var(--t-med) var(--ease-out), transform var(--t-fast) var(--ease-out);
}
.seg__btn:active { transform: scale(0.97); }
.seg__btn[aria-pressed="true"], .seg__btn[aria-selected="true"] { color: var(--accent-ink); font-weight: 600; }
/* The seg scrolls, so an outside ring would be clipped: draw it INSIDE the button */
.seg__btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
  box-shadow: inset 0 0 0 4px var(--accent);
}
@media (hover: hover) and (pointer: fine) {
  .seg__btn:hover { color: var(--ink); }
}
/* Inside the island the track blends into the glass */
.island .seg { background: rgb(18 23 34 / 0.05); }

/* ---------- Island nav (z-nav). One line at 1024px and up, never taller than 72px. ---------- */
.island {
  position: fixed;
  top: 16px;
  left: 50%;
  z-index: var(--z-nav);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  width: max-content;
  max-width: calc(100vw - 2 * var(--gutter));
  min-height: var(--nav-h);
  max-height: var(--nav-h);
  padding: 8px 8px 8px 12px;
  border-radius: var(--r-pill);
  /* A little more opaque than .glass: it floats over dark specimen windows too */
  background:
    linear-gradient(160deg, rgb(255 255 255 / 0.4), rgb(255 255 255 / 0) 60%),
    rgb(255 255 255 / 0.72);
  border: 1px solid var(--hairline);
  box-shadow:
    inset 0 1px 0 var(--glass-edge),
    0 20px 44px -20px var(--tint);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  backdrop-filter: blur(22px) saturate(160%);
}
.island[data-open] { z-index: calc(var(--z-sheet) + 1); }
.island__brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding-right: 10px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  text-decoration: none;
  white-space: nowrap;
}
.island__brand img, .island__brand svg { width: 32px; height: 32px; border-radius: 10px; }
.island__links { display: none; align-items: center; gap: 2px; }
.island__link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink-2);
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--t-med) var(--ease-out), background-color var(--t-med) var(--ease-out), transform var(--t-fast) var(--ease-out);
}
.island__link:active { transform: scale(0.97); }
.island__link[aria-current="page"] { color: var(--accent-ink); background: var(--accent); font-weight: 600; }
@media (hover: hover) and (pointer: fine) {
  .island__link:hover { color: var(--ink); background: rgb(18 23 34 / 0.06); }
  .island__link[aria-current="page"]:hover { background: #ffc462; }
}
.island__name {
  display: none;
  padding: 0 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.island__sep { width: 1px; align-self: stretch; margin: 10px 4px; background: var(--hairline-2); flex: none; }
.island__tools { display: none; align-items: center; gap: 6px; min-width: 0; }
@media (max-width: 767.98px) { .island__sep { display: none; } }
.island--static { position: relative; top: auto; left: auto; transform: none; margin-inline: auto; }
.island__toggle {
  position: relative;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-left: auto;
  border-radius: 50%;
  background: rgb(18 23 34 / 0.06);
  border: 1px solid var(--hairline);
  transition: transform var(--t-fast) var(--ease-out), background-color var(--t-med) var(--ease-out);
}
.island__toggle:active { transform: scale(0.94); }
.burger { position: relative; width: 20px; height: 20px; }
.burger i {
  position: absolute;
  left: 1px; right: 1px;
  height: 1.5px;
  border-radius: 2px;
  background: currentColor;
  transition: transform var(--t-med) var(--ease-spring);
}
.burger i:nth-child(1) { top: 6px; }
.burger i:nth-child(2) { top: 12px; }
.island__toggle[aria-expanded="true"] .burger i:nth-child(1) { transform: translateY(3px) rotate(45deg); }
.island__toggle[aria-expanded="true"] .burger i:nth-child(2) { transform: translateY(-3px) rotate(-45deg); }

@media (min-width: 1024px) { .island__name { display: block; } }
@media (min-width: 768px) {
  .island { padding-right: 10px; }
  .island__links, .island__tools { display: flex; }
  .island__toggle { display: none; }
}

/* Mobile sheet (z-sheet) */
.sheet {
  position: fixed;
  inset: 0;
  z-index: var(--z-sheet);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  padding: calc(var(--nav-h) + 56px) var(--gutter) 40px;
  background:
    radial-gradient(70% 45% at 80% 15%, color-mix(in oklab, var(--world-2) 80%, transparent), transparent 70%),
    rgb(238 241 244 / 0.86);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  backdrop-filter: blur(28px) saturate(160%);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--t-med) var(--ease-out), visibility 0s linear var(--t-med);
}
.sheet[data-open] { opacity: 1; visibility: visible; transition-delay: 0s; }
.sheet__link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--hairline);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--fs-d2);
  letter-spacing: -0.03em;
  line-height: 1;
  text-decoration: none;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity var(--t-med) var(--ease-out), transform var(--t-med) var(--ease-out);
}
.sheet__link .icon { width: 28px; height: 28px; color: var(--ink-3); }
.sheet__link[aria-current="page"] { text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 6px; text-underline-offset: 8px; }
.sheet[data-open] .sheet__link {
  opacity: 1;
  transform: none;
  transition-duration: var(--t-slow);
  transition-delay: calc(80ms + var(--i, 0) * 60ms);
}
@media (min-width: 768px) { .sheet { display: none; } }

/* ---------- Reading window and specimen core: always DARK (#0d1420), in every world ---------- */
.window, .specimen {
  position: relative;
  background: radial-gradient(75% 70% at 50% 42%, var(--specimen-lift), var(--specimen) 100%);
  color: var(--specimen-line);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.08), inset 0 0 60px rgb(0 0 0 / 0.35);
}
.window {
  border-radius: var(--r-sm);
  border: 1px solid rgb(18 23 34 / 0.5);
  overflow: hidden;
}
.window__label {
  position: absolute;
  top: 12px;
  left: 14px;
  z-index: var(--z-raised);
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--specimen-muted);
  pointer-events: none;
}
.window > svg, .window > canvas, .window > img { width: 100%; height: auto; }
.specimen { border-radius: var(--r-core); overflow: hidden; min-width: 0; }
.specimen > svg, .specimen > canvas { width: 100%; height: auto; }
.specimen--pad { padding: clamp(1rem, 2vw, 1.5rem); }
/* Figure tag, top left of a specimen: <span class="specimen__fig">Fig. 1</span> */
.specimen__fig {
  position: absolute;
  top: 12px;
  left: 14px;
  z-index: var(--z-raised);
  font-family: var(--font-mono);
  font-size: var(--fs-ui-min);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--specimen-muted);
  pointer-events: none;
}

/* ---------- Readout ---------- */
.readout {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  min-width: 112px;
  padding: 12px 16px;
  border-radius: var(--r-sm);
  background: rgb(255 255 255 / 0.7);
  border: 1px solid var(--hairline);
  box-shadow: inset 0 1px 0 #fff;
}
.readout__value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.6rem;
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.readout__unit { font-size: 0.8rem; font-weight: 400; color: var(--ink-2); margin-left: 3px; letter-spacing: 0; }
.readout__label { font-size: var(--fs-xs); color: var(--ink-2); line-height: 1.2; }
.readout--live { border-color: var(--accent-edge); background: var(--accent-soft); }
.readout--live .readout__value { font-weight: 600; }
/* On dark specimens */
.window .readout, .specimen .readout { background: rgb(255 255 255 / 0.06); border-color: rgb(255 255 255 / 0.14); box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.06); }
.window .readout__value, .specimen .readout__value { color: #eef1f6; }
.window .readout__unit, .specimen .readout__unit, .window .readout__label, .specimen .readout__label { color: rgb(238 241 246 / 0.78); }
.window .readout--live, .specimen .readout--live { background: rgb(255 180 55 / 0.16); border-color: rgb(255 180 55 / 0.55); }
.window .readout--live .readout__value, .specimen .readout--live .readout__value { color: var(--accent); }
.specimen .chip { color: rgb(238 241 246 / 0.86); background: rgb(255 255 255 / 0.07); border-color: rgb(255 255 255 / 0.16); box-shadow: none; }

/* ---------- Range slider (--p set by site.js, 0 to 100) ---------- */
.field { display: grid; gap: 10px; }
.field__row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: var(--fs-sm); }
.field__row label { font-weight: 500; }
.field__row output { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }
.range {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 44px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  --p: 50%;
}
.range::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: var(--r-pill);
  background: linear-gradient(to right, var(--accent) var(--p), rgb(18 23 34 / 0.2) var(--p));
  box-shadow: inset 0 0 0 1px rgb(18 23 34 / 0.16);
}
.range::-moz-range-track {
  height: 6px;
  border-radius: var(--r-pill);
  background: linear-gradient(to right, var(--accent) var(--p), rgb(18 23 34 / 0.2) var(--p));
  box-shadow: inset 0 0 0 1px rgb(18 23 34 / 0.16);
}
.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -8px;
  border-radius: 50%;
  background: linear-gradient(160deg, #fff, #e4e9ef);
  border: 2px solid var(--ink);
  box-shadow: 0 4px 10px -2px rgb(18 23 34 / 0.35), inset 0 1px 0 #fff;
  transition: transform var(--t-fast) var(--ease-out), box-shadow var(--t-med) var(--ease-out);
}
.range::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(160deg, #fff, #e4e9ef);
  border: 2px solid var(--ink);
  box-shadow: 0 4px 10px -2px rgb(18 23 34 / 0.35), inset 0 1px 0 #fff;
}
.range:active::-webkit-slider-thumb { transform: scale(1.12); }
.range:focus-visible { outline: none; box-shadow: none; }
.range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--accent), 0 0 0 5px var(--focus), 0 4px 10px -2px rgb(18 23 34 / 0.35); }
.range:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 3px var(--accent), 0 0 0 5px var(--focus); }
.specimen .range::-webkit-slider-runnable-track { background: linear-gradient(to right, var(--accent) var(--p), rgb(255 255 255 / 0.22) var(--p)); box-shadow: none; }
.specimen .range::-moz-range-track { background: linear-gradient(to right, var(--accent) var(--p), rgb(255 255 255 / 0.22) var(--p)); box-shadow: none; }

/* ---------- Toggle switch ---------- */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  font-size: var(--fs-sm);
  font-weight: 500;
  text-align: left;
  color: var(--ink);
}
.switch__track {
  position: relative;
  flex: none;
  width: 46px;
  height: 28px;
  border-radius: var(--r-pill);
  background: rgb(18 23 34 / 0.12);
  border: 1px solid rgb(18 23 34 / 0.45);
  box-shadow: inset 0 1px 2px rgb(18 23 34 / 0.18);
  transition: background-color var(--t-med) var(--ease-out), border-color var(--t-med) var(--ease-out);
}
.switch__thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 2px 6px rgb(18 23 34 / 0.3);
  transition: transform var(--t-med) var(--ease-spring), background-color var(--t-med) var(--ease-out);
}
.switch[aria-checked="true"] .switch__track { background: var(--accent); border-color: var(--ink); }
.switch[aria-checked="true"] .switch__thumb { transform: translateX(18px); }
.switch:active .switch__thumb { transform: scale(0.94); }
.switch[aria-checked="true"]:active .switch__thumb { transform: translateX(18px) scale(0.94); }

/* ---------- Modal (z-modal) ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgb(18 23 34 / 0.34);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity var(--t-med) var(--ease-out);
}
.modal.is-open { opacity: 1; }
.modal__panel {
  width: min(560px, 100%);
  max-height: calc(100dvh - 32px);
  display: flex;
  background:
    linear-gradient(160deg, rgb(255 255 255 / 0.4), rgb(255 255 255 / 0) 60%),
    rgb(255 255 255 / 0.78);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  backdrop-filter: blur(22px) saturate(160%);
  box-shadow: inset 0 1px 0 var(--glass-edge), 0 40px 80px -30px rgb(18 23 34 / 0.45);
  transform: scale(0.95) translateY(8px);
  opacity: 0;
  transition: transform var(--t-med) var(--ease-spring), opacity var(--t-med) var(--ease-out);
}
.modal.is-open .modal__panel { transform: none; opacity: 1; }
.modal__panel > .core { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.modal__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 1rem; }
.modal__close { flex: none; margin: -6px -6px 0 0; }

/* ---------- Toast (z-toast). The live region is created by site.js at load. ---------- */
.toast-region {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: var(--z-toast);
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 2 * var(--gutter));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 20px 0 16px;
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink);
  background: rgb(255 255 255 / 0.86);
  opacity: 0;
  transform: translateY(12px) scale(0.97);
  transition: opacity var(--t-med) var(--ease-out), transform var(--t-med) var(--ease-spring);
}
.toast[data-show] { opacity: 1; transform: none; }

/* =========================================================
   New components
   ========================================================= */

/* ---------- Float chip: small white glass chip for a live reading ----------
   <span class="float-chip"><svg class="icon" aria-hidden="true">...</svg>
     <span class="float-chip__label">Heart rate</span><span class="float-chip__value">66 bpm</span></span>
   Add .float-chip--blur ONLY over fixed or hero imagery. Add style="--x:62%;--y:18%" with
   .float-chip--pos inside a positioned parent to place it. Use <a> for a link chip. */
.float-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 16px 0 12px;
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  color: var(--ink);
  text-decoration: none;
  background: linear-gradient(160deg, rgb(255 255 255 / 0.9), rgb(255 255 255 / 0.72));
  border: 1px solid rgb(255 255 255 / 0.85);
  box-shadow:
    inset 0 1px 0 #fff,
    0 0 0 1px var(--hairline),
    0 16px 32px -14px var(--tint);
}
.float-chip .icon { width: 20px; height: 20px; color: var(--ink-2); }
.float-chip__label { color: var(--ink-2); }
.float-chip__value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); letter-spacing: -0.01em; }
.float-chip--blur {
  background: rgb(255 255 255 / 0.58); /* about 58% so it survives a projector */
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  backdrop-filter: blur(18px) saturate(160%);
}
.float-chip--pos { position: absolute; left: min(var(--x, 50%), calc(100% - 13.5rem)); top: var(--y, 50%); z-index: var(--z-raised); }
a.float-chip { position: relative; min-height: 44px; transition: transform var(--t-fast) var(--ease-out); }
a.float-chip:active { transform: scale(0.97); }
a.float-chip.float-chip--pos { position: absolute; }
.float-chip--live .float-chip__value { background: var(--accent); border-radius: var(--r-pill); padding: 5px 9px; margin-right: -6px; }
@media (hover: hover) and (pointer: fine) {
  a.float-chip:hover { background: #fff; }
}
@media (prefers-reduced-motion: no-preference) {
  @keyframes chip-bob { from { translate: 0 -3px; } to { translate: 0 3px; } }
  .float-chip--bob { animation: chip-bob 4.8s var(--ease-spring) infinite alternate; animation-delay: calc(var(--i, 0) * -1.3s); }
}

/* ---------- Quiz feedback: amber fill + a text label. Never green or red. ----------
   <div class="quiz-feedback quiz-feedback--correct" role="status">
     <svg class="icon" aria-hidden="true"><use href="...#i-check"/></svg>
     <p><strong>Correct.</strong> Why it is right.</p></div>
   Wrong answer: .quiz-feedback--incorrect, icon i-question, <strong>Not quite. The answer is: ...</strong> */
.quiz-feedback {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  line-height: 1.5;
  color: var(--ink);
  border: 1px solid var(--accent-edge);
}
.quiz-feedback .icon { width: 22px; height: 22px; margin-top: 1px; }
.quiz-feedback strong { font-weight: 700; }
.quiz-feedback--correct { background: var(--accent); }
.quiz-feedback--incorrect { background: rgb(255 180 55 / 0.16); border-style: dashed; }

/* ---------- Site footer ----------
   <footer class="site-footer"><div class="wrap site-footer__grid">
     <div><p class="site-footer__name">Made by Ms Poh Xiu Wen</p><p class="site-footer__note">...</p></div>
     <nav class="site-footer__links" aria-label="Footer"><a class="site-footer__link" href="...">...</a></nav>
   </div></footer> */
.site-footer {
  position: relative;
  padding-block: clamp(40px, 6vw, 72px) calc(clamp(32px, 5vw, 56px) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--hairline);
  background: linear-gradient(to bottom, rgb(255 255 255 / 0.5), rgb(255 255 255 / 0.8));
  color: var(--ink-2);
}
.site-footer__grid { display: grid; gap: 28px; align-items: start; }
.site-footer__name { font-family: var(--font-display); font-weight: 800; font-size: var(--fs-d3); letter-spacing: -0.03em; line-height: 1.05; color: var(--ink); }
.site-footer__note { margin-top: 10px; max-width: 52ch; font-size: var(--fs-sm); line-height: 1.55; color: var(--ink-2); }
.site-footer__links { display: flex; flex-wrap: wrap; gap: 4px 8px; }
.site-footer__link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
  transition: background-color var(--t-med) var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .site-footer__link:hover { background: rgb(18 23 34 / 0.07); }
}
@media (min-width: 768px) {
  .site-footer__grid { grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 48px; }
  .site-footer__links { justify-content: flex-end; }
}

/* ---------- World panel: a framed, scrolling world card (no blur) ----------
   <section class="world-panel" data-world="acids" aria-labelledby="id">
     <p class="world-panel__word" aria-hidden="true">pH</p>
     <div class="world-panel__object">svg or img</div>
     <div class="world-panel__body"><h2 id="id">...</h2><p>...</p>...links...</div>
     <span class="float-chip float-chip--pos" style="--x:64%;--y:20%">...</span>
   </section>
   Modifiers: --right moves the body to the bottom right; --tall adds height. Tune the object
   with --obj-w, --obj-top, --obj-x (custom properties on the panel). */
.world-panel {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: clamp(20px, 3vw, 36px);
  border-radius: var(--r-shell);
  border: 1px solid var(--hairline);
  background:
    radial-gradient(60% 55% at 62% 22%, var(--world-2), transparent 72%),
    radial-gradient(60% 60% at 8% 100%, color-mix(in oklab, var(--world-1) 85%, transparent), transparent 72%),
    var(--world-0);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.75), 0 40px 70px -40px var(--tint);
}
.world-panel__word {
  position: absolute;
  z-index: -1;
  inset-inline: 0;
  top: var(--word-top, 6%);
  margin: 0;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(5rem, 34vw, 11rem); /* fallback where container units are missing */
  font-size: clamp(5rem, 31cqi, 20rem);
  line-height: 0.8;
  letter-spacing: -0.04em;
  color: var(--world-word);
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}
.world-panel__object {
  position: relative;
  display: grid;
  grid-template: 100% / 100%; /* a definite row, so the child can size to the slot */
  height: clamp(220px, 62cqi, 340px);
  margin-top: clamp(16px, 4vw, 40px);
}
.world-panel__object > svg, .world-panel__object > img, .world-panel__object > canvas { width: 100%; height: 100%; max-width: none; object-fit: contain; }
.world-panel__body { position: relative; display: grid; gap: 14px; max-width: 40ch; }
.world-panel__body h2, .world-panel__body h3 { font-size: var(--fs-d2); }
.world-panel__body p { color: var(--ink-2); font-size: var(--fs-body); }
.world-panel__body .cluster { margin-top: 6px; }
@media (min-width: 900px) {
  .world-panel { display: block; min-height: clamp(560px, 46vw, 700px); padding: clamp(28px, 3.4vw, 48px); }
  .world-panel__object {
    position: absolute;
    left: var(--obj-x, 50%);
    top: var(--obj-top, 5%);
    width: var(--obj-w, 36%);
    height: var(--obj-h, 64%);
    margin: 0;
    transform: translateX(-50%);
  }
  .world-panel__body { position: absolute; left: clamp(28px, 3.4vw, 48px); bottom: clamp(28px, 3.4vw, 48px); }
  .world-panel--right .world-panel__body { left: auto; right: clamp(28px, 3.4vw, 48px); }
  .world-panel--tall { min-height: clamp(640px, 54vw, 800px); }
}

/* ---------- Simulation page layout ----------
   <body> or wrapper: <main class="world sim-page" data-world="heart"> (island nav above it)
     <div class="wrap sim-layout">
       <section class="sim-stage" aria-labelledby="stage-title">
         <div class="sim-stage__head"><h1 id="stage-title" class="display-3">...</h1><p id="stage-sub" class="small text-2">...</p></div>
         <div class="specimen">svg / canvas (always dark)</div>
       </section>
       <aside class="sim-panel panel" aria-label="Controls">...</aside>
     </div>
   </main>
   <nav class="sim-tabbar" aria-label="Activities"><div class="seg" role="tablist">...</div></nav> */
.sim-page { padding-top: calc(var(--nav-h) + 16px + 24px); padding-bottom: 48px; }
.sim-layout { display: grid; gap: 20px; align-items: start; }
.sim-stage {
  min-width: 0;
  padding: var(--bezel);
  border-radius: var(--r-shell);
  background: rgb(255 255 255 / 0.55); /* scrolling: no blur */
  border: 1px solid var(--hairline);
  box-shadow: inset 0 1px 0 var(--glass-edge), 0 30px 60px -28px var(--tint);
}
.sim-stage__head { padding: 14px 18px 14px; }
.sim-stage__head > * + * { margin-top: 4px; }
.sim-stage .specimen { border-radius: var(--r-core); }
.sim-panel {
  min-width: 0;
  padding: clamp(1.1rem, 2.2vw, 1.5rem);
  border-radius: var(--r-shell);
  background:
    linear-gradient(160deg, rgb(255 255 255 / 0.6), rgb(255 255 255 / 0) 60%),
    color-mix(in oklab, var(--world-2) 45%, #fff);
  border: 1px solid var(--hairline);
  box-shadow: inset 0 1px 0 #fff, 0 24px 56px -28px var(--tint);
}
@media (min-width: 1024px) {
  .sim-layout { grid-template-columns: minmax(0, 1fr) 380px; gap: 24px; }
  /* Sticky, so the blur is allowed here */
  .sim-panel {
    position: sticky;
    top: calc(var(--nav-h) + 16px + 16px);
    max-height: calc(100dvh - var(--nav-h) - 64px);
    overflow-y: auto;
    overscroll-behavior: contain;
    background:
      linear-gradient(160deg, rgb(255 255 255 / 0.32), rgb(255 255 255 / 0) 60%),
      rgb(255 255 255 / 0.62);
    -webkit-backdrop-filter: blur(22px) saturate(160%);
    backdrop-filter: blur(22px) saturate(160%);
  }
}
.sim-tabbar {
  display: none;
}
@media (max-width: 767.98px) {
  .sim-page { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  /* with a footer under the page, the footer clears the fixed bar instead */
  .sim-page:has(+ .site-footer) { padding-bottom: 32px; }
  body:has(.sim-tabbar) .site-footer { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .sim-tabbar {
    position: fixed;
    z-index: var(--z-raised);
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    display: block;
    padding: 5px;
    border-radius: var(--r-pill);
    background:
      linear-gradient(160deg, rgb(255 255 255 / 0.4), rgb(255 255 255 / 0) 60%),
      rgb(255 255 255 / 0.74);
    border: 1px solid var(--hairline);
    box-shadow: inset 0 1px 0 var(--glass-edge), 0 18px 40px -16px var(--tint);
    -webkit-backdrop-filter: blur(22px) saturate(160%);
    backdrop-filter: blur(22px) saturate(160%);
  }
  .sim-tabbar .seg { display: flex; width: 100%; background: transparent; border: 0; box-shadow: none; }
  .sim-tabbar .seg__btn { flex: 1 0 auto; min-height: 44px; padding: 0 12px; }
  body:has(.sim-tabbar) .toast-region { bottom: calc(84px + env(safe-area-inset-bottom)); }
}
/* Text floor inside simulations */
.sim-page .xs, .sim-page .readout__label, .sim-page .window__label, .sim-page .label { font-size: var(--fs-ui-min); }

/* ---------- Hero heart (hero-heart.js drives the canvas) ----------
   <div class="hero-heart" data-hero-heart><canvas id="heart3d" aria-hidden="true"></canvas>
     <img class="hero-heart__poster" src="assets/img/heart-hero.webp" alt=""></div> */
.hero-heart {
  position: relative;
  width: min(100%, 640px);
  aspect-ratio: 1 / 1;
  margin-inline: auto;
}
.hero-heart canvas, .hero-heart__poster {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}
.hero-heart canvas { touch-action: pan-y; cursor: grab; }
.hero-heart.is-dragging canvas { cursor: grabbing; }
.hero-heart__poster { object-fit: contain; pointer-events: none; user-select: none; transition: opacity 0.7s var(--ease-out); }
.hero-heart.is-live .hero-heart__poster { opacity: 0; }
/* Soft contact shadow under the floating heart, tinted by the world */
.hero-heart::before {
  content: "";
  position: absolute;
  z-index: -1;
  left: 22%;
  right: 22%;
  bottom: 2%;
  height: 7%;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in oklab, color-mix(in oklab, var(--world-1) 55%, var(--ink)) 38%, transparent), transparent);
  filter: blur(6px);
}

/* ---------- Reveal (IntersectionObserver adds .is-in; stagger with --i) ---------- */
@media (prefers-reduced-motion: no-preference) and (scripting: enabled) {
  .reveal {
    opacity: 0;
    transform: translateY(24px);
    filter: blur(6px);
    transition:
      opacity var(--t-slow) var(--ease-out),
      transform var(--t-slow) var(--ease-out),
      filter var(--t-slow) var(--ease-out);
    transition-delay: calc(min(var(--i, 0), 8) * 70ms);
  }
  .reveal.is-in { opacity: 1; transform: none; filter: none; }
}

/* ---------- Accessibility fallbacks ---------- */
@media (prefers-reduced-transparency: reduce) {
  .glass, .island, .modal__panel, .sim-tabbar, .toast, .float-chip--blur, .sim-panel {
    background: #fff;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .sheet { background: var(--paper); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .modal { background: rgb(18 23 34 / 0.6); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .island, .glass, .sim-tabbar, .sim-panel { border-color: var(--hairline-2); }
  .shell { background: #fff; }
  .sim-stage { background: #fff; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }
  .btn:active, .chip:active, .seg__btn:active, .island__link:active, .island__toggle:active, a.float-chip:active { transform: none; }
  .btn:hover .btn__icon { transform: none; }
  .range:active::-webkit-slider-thumb { transform: none; }
  .switch:active .switch__thumb { transform: none; }
  .switch[aria-checked="true"]:active .switch__thumb { transform: translateX(18px); }
}
