@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('site/fonts/jetbrains-mono-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Space Grotesk';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('site/fonts/space-grotesk-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* Matches the site's "ink" and "paper" palettes from index.html. */
:root {
  --bg-0: #0B0B0C;
  --bg-1: #0B0B0C;
  --bg-2: #131314;
  --bg-3: #1b1b1d;
  --bg-4: #2a2a2c;
  --line: #1c1c1e;
  --line-strong: #2a2a2c;
  --fg-0: #EDECE6;
  --fg-1: #cac8c2;
  --fg-2: #918f89;
  --fg-3: #6b6963;
  --accent: oklch(0.78 0.15 75);
  --accent-2: oklch(0.78 0.15 75);
  --accent-hot: oklch(0.78 0.15 75);
  --accent-lime: oklch(0.78 0.15 75);
  --accent-amber: oklch(0.78 0.15 75);
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', 'Fira Code', monospace;
  --sans: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --plot-bg: #0B0B0C;
  --plot-grid: rgba(237,236,230,0.08);
  --plot-border: rgba(237,236,230,0.22);
  --plot-axis: #EDECE6;
  --plot-tick: #918f89;
}
[data-theme="light"] {
  --bg-0: #FAFAF7;
  --bg-1: #FAFAF7;
  --bg-2: #ffffff;
  --bg-3: #f3eee2;
  --bg-4: #e1d9c7;
  --line: #e7e6e0;
  --line-strong: #d8d6cd;
  --fg-0: #111111;
  --fg-1: #3a3a36;
  --fg-2: #6e6d68;
  --fg-3: #91908a;
  --accent: oklch(0.62 0.17 32);
  --accent-2: oklch(0.62 0.17 32);
  --accent-hot: oklch(0.62 0.17 32);
  --accent-lime: oklch(0.62 0.17 32);
  --accent-amber: oklch(0.62 0.17 32);
  --plot-bg: #ffffff;
  --plot-grid: rgba(17,17,17,0.07);
  --plot-border: rgba(17,17,17,0.28);
  --plot-axis: #111111;
  --plot-tick: #6e6d68;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100vh; }
body {
  font-family: var(--sans);
  background: var(--bg-0);
  transition: background-color 0.25s ease, color 0.25s ease;
  color: var(--fg-0);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 24px 20px 40px;
  font-feature-settings: 'ss01','cv11';
  -webkit-font-smoothing: antialiased;
}

header.app-bar {
  width: 100%;
  max-width: 1560px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
  position: relative; z-index: 1;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand .mark {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--line);
  position: relative;
  display: grid; place-items: center;
  cursor: pointer;
}
.brand .mark svg { width: 28px; height: 28px; }

/* Rest state: detuned DQD — more population in the right dot.
   Hover triggers Rabi oscillation starting exactly from this state:
       P_L(τ) = ½ + ½(a² − b²) cos(2tτ/ℏ)
   with a² = 0.3, b² = 0.7, so P_L swings 0.3 ↔ 0.7 and P_R is antiphase. */
.brand .mark svg path.psi-L {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  transform: scaleY(0.3);
  transition: transform 0.25s ease;
}
.brand .mark svg path.psi-R {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  transform: scaleY(0.7);
  transition: transform 0.25s ease;
}
@media (hover: hover) {
  .brand .mark:hover svg path.psi-L { animation: rabi-L 1.2s linear infinite; }
  .brand .mark:hover svg path.psi-R { animation: rabi-R 1.2s linear infinite; }
}
@keyframes rabi-L {
  0%   { transform: scaleY(0.30); }
  25%  { transform: scaleY(0.50); }
  50%  { transform: scaleY(0.70); }
  75%  { transform: scaleY(0.50); }
  100% { transform: scaleY(0.30); }
}
@keyframes rabi-R {
  0%   { transform: scaleY(0.70); }
  25%  { transform: scaleY(0.50); }
  50%  { transform: scaleY(0.30); }
  75%  { transform: scaleY(0.50); }
  100% { transform: scaleY(0.70); }
}

/* Wavefunction collapse (click = measurement). Outcome is Born-sampled
   from the rest-state probabilities. Three phases: (1) fast projection
   to the measured eigenstate, (2) brief hold in the now-definite state,
   (3) coherent Rabi evolution — the eigenstate is no longer stationary
   under the tunneling Hamiltonian, so it swings to the opposite peak
   and damps back to the rest superposition. */
.brand .mark[data-collapse="L"] svg path.psi-L { animation: collapse-L-peak 1.4s cubic-bezier(0.22, 0.8, 0.3, 1); }
.brand .mark[data-collapse="L"] svg path.psi-R { animation: collapse-L-fade 1.4s cubic-bezier(0.22, 0.8, 0.3, 1); }
.brand .mark[data-collapse="R"] svg path.psi-L { animation: collapse-R-fade 1.4s cubic-bezier(0.22, 0.8, 0.3, 1); }
.brand .mark[data-collapse="R"] svg path.psi-R { animation: collapse-R-peak 1.4s cubic-bezier(0.22, 0.8, 0.3, 1); }
.brand .mark[data-collapse] { animation: collapse-flash 0.9s ease-out; }

@keyframes collapse-L-peak {
  0%   { transform: scaleY(0.30); filter: brightness(1); }
  6%   { transform: scaleY(1.00); filter: brightness(2.5); }
  35%  { transform: scaleY(1.00); filter: brightness(1.2); }
  55%  { transform: scaleY(0.50); filter: brightness(1); }
  75%  { transform: scaleY(0.15); filter: brightness(1); }
  100% { transform: scaleY(0.30); filter: brightness(1); }
}
@keyframes collapse-L-fade {
  0%   { transform: scaleY(0.70); opacity: 1; }
  6%   { transform: scaleY(0.00); opacity: 0.2; }
  35%  { transform: scaleY(0.02); opacity: 0.3; }
  55%  { transform: scaleY(0.50); opacity: 1; }
  75%  { transform: scaleY(0.85); opacity: 1; }
  100% { transform: scaleY(0.70); opacity: 1; }
}
@keyframes collapse-R-peak {
  0%   { transform: scaleY(0.70); filter: brightness(1); }
  6%   { transform: scaleY(1.00); filter: brightness(2.5); }
  35%  { transform: scaleY(1.00); filter: brightness(1.2); }
  55%  { transform: scaleY(0.50); filter: brightness(1); }
  75%  { transform: scaleY(0.15); filter: brightness(1); }
  100% { transform: scaleY(0.70); filter: brightness(1); }
}
@keyframes collapse-R-fade {
  0%   { transform: scaleY(0.30); opacity: 1; }
  6%   { transform: scaleY(0.00); opacity: 0.2; }
  35%  { transform: scaleY(0.02); opacity: 0.3; }
  55%  { transform: scaleY(0.50); opacity: 1; }
  75%  { transform: scaleY(0.85); opacity: 1; }
  100% { transform: scaleY(0.30); opacity: 1; }
}
@keyframes collapse-flash {
  0%   { box-shadow: 0 0 0 0 color-mix(in oklab, var(--accent) 55%, transparent); }
  25%  { box-shadow: 0 0 0 6px color-mix(in oklab, var(--accent) 25%, transparent); }
  100% { box-shadow: 0 0 0 16px color-mix(in oklab, var(--accent) 0%, transparent); }
}

.brand .title-wrap { display: flex; flex-direction: column; line-height: 1.1; }
.brand h1 {
  font-family: var(--sans);
  font-size: clamp(24px, 3.2vw, 40px);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.02;
  color: var(--fg-0);
}
.brand .subtitle {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--fg-2);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 6px;
}
.home-link {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-1);
  text-decoration: none;
  position: relative;
  padding-bottom: 2px;
  transition: color 0.25s ease;
}
.home-link::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.35s cubic-bezier(.2,.7,.1,1);
}
.home-link:hover,
.home-link:focus-visible { color: var(--accent); }
.home-link:hover::after,
.home-link:focus-visible::after { transform: scaleX(1); }
.home-link:focus-visible { outline: none; }
.home-link .psi-glyph {
  font-family: "Instrument Serif", "Times New Roman", serif;
  font-size: 1.2em;
  letter-spacing: 0;
  text-transform: none;
  vertical-align: -0.03em;
}
.app-bar-right { display: flex; align-items: center; gap: 14px; }

/* Keyboard-only focus indicator. Matches index.html. */
button:focus-visible,
.zero-btn:focus-visible,
.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}
.theme-toggle {
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--line);
  cursor: pointer;
  color: var(--fg-0);
  padding: 0;
  transition: border-color 0.2s ease, transform 0.2s ease, color 0.2s ease, background-color 0.2s ease;
}
@media (hover: hover) {
  .theme-toggle:hover { border-color: var(--fg-0); transform: rotate(30deg); }
}
.theme-toggle svg { width: 14px; height: 14px; display: block; }
.theme-toggle .icon-sun { display: none; }
[data-theme="light"] .theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun { display: block; }

#app {
  display: flex;
  gap: 18px;
  max-width: 1560px;
  width: 100%;
  flex-wrap: wrap;
  justify-content: center;
  position: relative; z-index: 1;
}
.panel {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 14px;
}
#plot-container {
  padding: 14px;
  flex: 1 1 760px;
  min-width: 520px;
  display: flex; flex-direction: column;
  overflow: hidden;
  position: relative;
}
canvas {
  width: 100%;
  display: block;
  border-radius: 14px;
  background: var(--plot-bg);
  border: 1px solid var(--line);
  transition: background 0.25s ease;
}
/* Tab bar — title + mono equation caption, with a single sliding indicator
   that translates between active tabs (no per-tab border, so the indicator
   has nothing to fight). */
.tab-bar {
  position: relative;
  display: flex;
  gap: 0;
  margin: -4px 0 14px;
  border-bottom: 1px solid var(--line);
}
.tab-btn {
  appearance: none;
  background: none;
  border: 0;
  padding: 8px 18px 10px;
  color: var(--fg-2);
  font-family: var(--sans);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1.1;
  transition: color 0.18s ease;
}
.tab-btn:hover { color: var(--fg-0); }
.tab-btn:hover .tab-caption { color: var(--fg-2); }
.tab-btn.active { color: var(--fg-0); }
.tab-btn.active .tab-caption { color: var(--accent); }
.tab-title {
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}
.tab-caption {
  font-family: var(--mono);
  font-size: 0.62rem;
  color: var(--fg-3);
  letter-spacing: 0.04em;
  transition: color 0.18s ease;
}
.tab-indicator {
  position: absolute;
  bottom: -1px;
  left: 0;
  height: 2px;
  width: 0;
  background: var(--accent);
  transform: translateX(0);
  transition: transform 0.28s cubic-bezier(0.4, 0.0, 0.2, 1),
              width 0.28s cubic-bezier(0.4, 0.0, 0.2, 1);
  pointer-events: none;
  border-radius: 1px;
}

/* Tab-scoped controls. JS sets `body.tab-<active>` and matching elements stay
   visible. An element with `data-tabs="spectrum spectroscopy"` shows on both;
   one with no `data-tabs` attribute is always visible (shared physics inputs). */
body.tab-spectrum     [data-tabs~="spectroscopy"]:not([data-tabs~="spectrum"])     { display: none !important; }
body.tab-spectroscopy [data-tabs~="spectrum"]:not([data-tabs~="spectroscopy"])     { display: none !important; }

.plot-frame {
  position: relative;
  width: 100%;
}
.plot-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  border-radius: 14px;
}
.plot-labels .pl {
  position: absolute;
  white-space: nowrap;
  color: var(--plot-axis);
  font-family: 'Space Grotesk', -apple-system, sans-serif;
  font-weight: 500;
  line-height: 1;
}
.plot-labels .pl.tick {
  color: var(--plot-tick);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}
#controls {
  padding: 18px 16px 18px 18px;
  flex: 0 0 360px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-4) transparent;
}
#controls::-webkit-scrollbar { width: 8px; }
#controls::-webkit-scrollbar-track { background: transparent; }
#controls::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 8px; }
#controls::-webkit-scrollbar-thumb:hover { background: #2f3a4d; }

.section-title {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--fg-2);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin: 18px 0 10px 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px;
}
.section-title:first-child { margin-top: 0; }
.section-title::before {
  content: "";
  width: 12px; height: 1px;
  background: var(--accent);
  flex-shrink: 0;
}

/* Collapsible control sections via <details>/<summary> */
details.section { margin: 0; }
details.section > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::marker { content: ""; }
.section-title .caret {
  margin-left: auto;
  font-size: 0.75em;
  color: var(--fg-3);
  transition: transform 0.15s ease;
  line-height: 1;
}
details.section:not([open]) > summary .caret { transform: rotate(-90deg); }
details.section:not([open]) > summary { margin-bottom: 0; padding-bottom: 10px; }

.slider-row {
  display: flex;
  align-items: center;
  margin-bottom: 9px;
  gap: 10px;
}
.slider-row label {
  flex: 0 0 94px;
  font-size: 0.77rem;
  color: var(--fg-1);
  text-align: right;
  font-weight: 400;
}
.slider-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: linear-gradient(to right, var(--bg-4), var(--bg-3));
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}
.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px; height: 14px;
  background: var(--bg-1);
  border: 2px solid var(--accent);
  border-radius: 50%;
  cursor: grab;
  transition: transform 0.08s;
}
.slider-row input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}
.slider-row input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  background: var(--bg-1);
  border: 2px solid var(--accent);
  border-radius: 50%;
  cursor: grab;
}
.slider-row .val {
  flex: 0 0 62px;
  font-size: 0.73rem;
  color: var(--accent);
  text-align: left;
  font-family: var(--mono);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  padding: 3px 6px;
  background: color-mix(in oklab, var(--accent) 6%, transparent);
  border: 1px solid color-mix(in oklab, var(--accent) 18%, transparent);
  border-radius: 4px;
}
.slider-row .val:not(.note) {
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.slider-row .val:not(.note):hover {
  background: color-mix(in oklab, var(--accent) 14%, transparent);
  border-color: color-mix(in oklab, var(--accent) 32%, transparent);
}
/* Inline editor that replaces a .val pill while the user types a value. */
.val-edit {
  flex: 0 0 62px;
  font-size: 0.73rem;
  color: var(--accent);
  font-family: var(--mono);
  font-weight: 500;
  padding: 3px 6px;
  background: var(--bg-2);
  border: 1px solid var(--accent);
  border-radius: 4px;
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 14%, transparent);
  -moz-appearance: textfield;
}
.val-edit::-webkit-outer-spin-button,
.val-edit::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
@keyframes valFlash {
  0%   { background: color-mix(in oklab, var(--accent) 35%, transparent); border-color: var(--accent); color: var(--fg-0); }
  100% { background: color-mix(in oklab, var(--accent) 6%, transparent); border-color: color-mix(in oklab, var(--accent) 18%, transparent); color: var(--accent); }
}
.slider-row .val.flash { animation: valFlash 0.45s ease-out; }
.slider-row .val.note {
  flex: 1;
  font-size: 0.72rem;
  color: var(--fg-3);
  background: transparent;
  border: none;
  padding: 0;
  font-family: var(--sans);
  font-weight: 400;
}

input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  position: relative;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 5px; top: 1px;
  width: 5px; height: 10px;
  border: solid var(--bg-0);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

select {
  flex: 1;
  padding: 7px 30px 7px 10px;
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  color: var(--fg-0);
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: var(--sans);
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%237dd3fc' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color 0.12s, background-color 0.12s;
}
select:hover, select:focus { border-color: var(--accent); outline: none; }
select option { background: var(--bg-2); color: var(--fg-0); }

input[type="text"] {
  flex: 1;
  padding: 7px 10px;
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  color: var(--fg-0);
  border-radius: 6px;
  font-size: 0.76rem;
  font-family: var(--mono);
  transition: border-color 0.12s;
}
input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 14%, transparent);
}

.range-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 9px;
  font-size: 0.77rem;
}
.range-row label {
  flex: 0 0 94px;
  text-align: right;
  color: var(--fg-1);
}
.range-row input[type="number"] {
  width: 72px;
  padding: 5px 8px;
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  color: var(--accent);
  border-radius: 5px;
  font-size: 0.74rem;
  font-family: var(--mono);
  font-weight: 500;
  transition: border-color 0.12s;
}
.range-row input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 14%, transparent);
}
.range-row span { color: var(--fg-3); font-size: 0.7rem; font-family: var(--mono); }

#legend-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--fg-1);
  padding: 2px 8px 2px 4px;
  background: var(--bg-2);
  border-radius: 999px;
  border: 1px solid var(--line);
}
.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}


.zero-btn {
  padding: 6px 12px;
  font-size: 0.72rem;
  font-family: var(--mono);
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  cursor: pointer;
  color: var(--fg-1);
  transition: all 0.12s;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.zero-btn:hover {
  background: var(--bg-3);
  border-color: var(--accent);
  color: var(--accent);
}

.hidden { display: none !important; }

@media (max-width: 1100px) {
  #controls { flex: 1 1 100%; max-height: none; }
  #plot-container { flex: 1 1 100%; min-width: 0; }
}

.colophon {
  width: 100%;
  max-width: 1560px;
  margin-top: 18px;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  color: var(--fg-2);
  text-align: center;
  position: relative; z-index: 1;
}
.colophon a {
  color: inherit;
  text-decoration: none;
  position: relative;
  padding-bottom: 2px;
  transition: color 0.25s ease;
}
.colophon a::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.35s cubic-bezier(.2,.7,.1,1);
}
.colophon a:hover,
.colophon a:focus-visible { color: var(--accent); }
.colophon a:hover::after,
.colophon a:focus-visible::after { transform: scaleX(1); }
.colophon a:focus-visible { outline: none; }

/* Mobile — kept at the end of the stylesheet so its overrides beat any
   base rule (same specificity, later wins). */
@media (max-width: 640px) {
  body { padding: 14px 12px 28px; }
  header.app-bar { margin-bottom: 14px; gap: 12px; }
  .brand { gap: 10px; }
  .brand .mark { width: 44px; height: 44px; }
  .brand .mark svg { width: 26px; height: 26px; }
  .brand h1 { font-size: clamp(20px, 6.5vw, 28px); }
  .brand .subtitle { font-size: 0.62rem; margin-top: 4px; }

  .app-bar-right { gap: 10px; }
  .home-link { font-size: 0.64rem; }

  #app { gap: 12px; }
  #plot-container { padding: 10px; }
  #controls { padding: 14px 10px 14px 12px; flex: 0 0 100%; }

  .section-title { font-size: 0.64rem; margin: 14px 0 8px; letter-spacing: 0.12em; }
  .slider-row { gap: 8px; margin-bottom: 10px; }
  .slider-row label { flex: 0 0 82px; font-size: 0.72rem; }
  .slider-row .val { flex: 0 0 58px; font-size: 0.7rem; padding: 4px 6px; }

  /* Touch-friendly slider thumbs */
  .slider-row input[type="range"] { height: 4px; }
  .slider-row input[type="range"]::-webkit-slider-thumb { width: 20px; height: 20px; }
  .slider-row input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; }

  .range-row { gap: 5px; font-size: 0.72rem; margin-bottom: 10px; flex-wrap: wrap; }
  .range-row label { flex: 0 0 82px; }
  .range-row input[type="number"] { width: 62px; padding: 6px 7px; font-size: 0.72rem; }

  select { font-size: 0.76rem; padding: 8px 28px 8px 10px; }
  input[type="checkbox"] { width: 20px; height: 20px; }

  .colophon { font-size: 0.64rem; line-height: 1.7; padding: 0 8px; }
  .legend-item { font-size: 0.66rem; padding: 2px 8px 2px 4px; }
}
