:root {
  --accent: #f6c85f;
  --ink: #e8ecf4;
  --dim: #9aa3b5;
  --faint: #5d667a;
  --glass: rgba(10, 14, 24, 0.55);
  --line: rgba(255, 255, 255, 0.09);
  --display: 'Space Grotesk', system-ui, sans-serif;
  --text: 'Inter', system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #05070d; color: var(--ink); font-family: var(--text); }
body { -webkit-tap-highlight-color: transparent; }
button, select, input { font: inherit; color: inherit; }

#tunnel { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
#tunnel.grab { cursor: grab; }
#tunnel.grabbing { cursor: grabbing; }

.glass { background: var(--glass); backdrop-filter: blur(14px) saturate(140%); -webkit-backdrop-filter: blur(14px) saturate(140%); }

/* The title, over the flow for the first seconds. */
.title-card {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none; text-align: center; transition: opacity 1.6s ease, transform 1.6s ease; z-index: 5;
}
.title-card h1 {
  font-family: var(--display); font-weight: 500; font-size: clamp(32px, 6.4vw, 84px); line-height: 1.02;
  letter-spacing: -0.03em; margin: 0.25em 0 0; text-shadow: 0 4px 40px rgba(0, 0, 0, 0.8);
}
.title-card.gone { opacity: 0; transform: translateY(-12px) scale(0.98); }
.eyebrow { font-size: 12px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--accent); font-weight: 600; }

/* What the dial says, top left. */
.hud {
  position: fixed; top: max(18px, env(safe-area-inset-top)); left: max(22px, env(safe-area-inset-left));
  max-width: min(440px, calc(100vw - 120px)); pointer-events: none; z-index: 3;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.9);
}
.brand { font-family: var(--display); font-size: 13px; letter-spacing: 0.24em; text-transform: uppercase; color: var(--dim); }
.brand span { color: var(--ink); }
.readout { display: flex; align-items: baseline; gap: 14px; margin-top: 4px; }
.re-label { font-family: var(--display); font-size: 28px; color: var(--accent); font-weight: 500; transition: color 0.6s; }
.re-value {
  font-family: var(--display); font-weight: 500; font-size: clamp(48px, 7vw, 88px); line-height: 1;
  letter-spacing: -0.04em; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.regime-name {
  display: inline-block; margin-top: 10px; font-family: var(--display); font-size: 15px; font-weight: 700;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); transition: color 0.6s;
}
.regime-line { margin: 6px 0 0; font-size: 15px; line-height: 1.5; color: #cfd5e2; max-width: 400px; }
.clamp-note { margin: 8px 0 0; font-size: 12.5px; line-height: 1.45; color: var(--dim); max-width: 380px; }

/* The toolbar, down the right. */
.toolbar {
  position: fixed; top: max(16px, env(safe-area-inset-top)); right: max(16px, env(safe-area-inset-right));
  display: flex; flex-direction: column; gap: 10px; z-index: 4;
}
.group {
  display: flex; flex-direction: column; gap: 2px; padding: 4px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--glass);
  backdrop-filter: blur(14px) saturate(140%); -webkit-backdrop-filter: blur(14px) saturate(140%);
}
.tool {
  display: flex; align-items: center; gap: 9px; padding: 7px 12px 7px 9px; border: 0; border-radius: 10px;
  background: transparent; cursor: pointer; font-size: 13px; color: var(--dim); white-space: nowrap;
  transition: background 0.2s, color 0.2s;
}
.tool svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tool:hover { background: rgba(255, 255, 255, 0.06); color: var(--ink); }
.tool[aria-checked='true'] { background: rgba(255, 255, 255, 0.1); color: var(--ink); box-shadow: inset 2px 0 0 var(--accent); }
.tool.accent { color: var(--accent); }
.tool.on { color: var(--accent); background: rgba(255, 255, 255, 0.08); }
.tool:focus-visible, .ladder button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* The un-stirring experiment's own controls, above the dial; and what of the tunnel it hides. */
.unstir-panel { display: none; }
body.exp-unstir .unstir-panel {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(118px + env(safe-area-inset-bottom)); z-index: 4;
  display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); white-space: nowrap;
}
body.exp-unstir #shapes, body.exp-unstir #modes, body.exp-unstir #tools, body.exp-unstir .stats, body.exp-unstir #hint, body.exp-unstir #pause { display: none; }
body.exp-unstir #tunnel { cursor: copy; }
.unstir-panel .big { padding: 10px 18px; border-radius: 12px; border: 0; background: var(--accent); color: #0a0d14; font-weight: 600; font-size: 15px; cursor: pointer; }
.unstir-panel .big:disabled, .unstir-panel .small-btn:disabled { opacity: 0.35; cursor: default; }
.unstir-panel .small-btn { padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: transparent; color: var(--dim); cursor: pointer; font-size: 13px; }
.seg { display: flex; padding: 3px; border-radius: 11px; background: rgba(255,255,255,0.05); }
.seg button { border: 0; background: none; color: var(--dim); padding: 7px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.seg button[aria-checked='true'] { background: rgba(255,255,255,0.14); color: var(--ink); }
.unstir-status { font-family: var(--display); font-size: 13px; color: var(--dim); min-width: 90px; font-variant-numeric: tabular-nums; }

/* The measurements, bottom right above the dial. */
.stats {
  position: fixed; left: max(22px, env(safe-area-inset-left)); bottom: 150px; width: 264px; padding: 12px 12px 10px;
  border-radius: 14px; border: 1px solid var(--line); background: var(--glass); z-index: 3;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px;
}
.stat { display: flex; flex-direction: column; }
.stat .k { font-size: 11px; color: var(--dim); letter-spacing: 0.04em; }
.stat .v { font-family: var(--display); font-size: 22px; font-variant-numeric: tabular-nums; }
#spark { grid-column: 1 / -1; width: 100%; height: 56px; margin-top: 6px; }
.spark-label { grid-column: 1 / -1; font-size: 10.5px; color: var(--faint); }

/* The dial: the whole Reynolds scale, and who lives where on it. */
.dial {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; padding: 0 max(22px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(22px, env(safe-area-inset-left));
  background: linear-gradient(to top, rgba(3, 5, 10, 0.92), rgba(3, 5, 10, 0.55) 60%, transparent);
}
.dial-inner { position: relative; max-width: 1400px; margin: 0 auto; padding-top: 52px; }
.ladder { position: absolute; left: 0; right: 0; top: 0; height: 48px; }
.ladder button {
  position: absolute; bottom: 4px; transform: translateX(-50%); border: 0; background: none; cursor: pointer;
  font-size: 24px; line-height: 1; padding: 4px; border-radius: 10px; filter: saturate(0.85) drop-shadow(0 2px 6px rgba(0,0,0,.7));
  transition: transform 0.25s, filter 0.25s;
}
.ladder button:hover, .ladder button.near { transform: translateX(-50%) translateY(-4px) scale(1.18); filter: saturate(1.1) drop-shadow(0 0 10px rgba(255,255,255,.25)); }
.ladder button::after {
  content: attr(data-name); position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%); white-space: nowrap;
  font-size: 11px; color: var(--ink); opacity: 0; transition: opacity 0.2s; pointer-events: none; font-family: var(--text);
}
.ladder button:hover::after, .ladder button.near::after { opacity: 0.9; }
.track-wrap { position: relative; height: 34px; }
.bands { position: absolute; left: 0; right: 0; top: 14px; height: 6px; border-radius: 3px; overflow: hidden; display: flex; opacity: 0.85; }
.bands div { height: 100%; }
.tunnel-range {
  position: absolute; top: 9px; height: 16px; border: 1px solid rgba(255, 255, 255, 0.28); border-radius: 9px; pointer-events: none;
}
.tunnel-range span {
  position: absolute; top: 100%; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--dim);
  letter-spacing: 0.12em; text-transform: uppercase; margin-top: 3px; white-space: nowrap;
}
#re { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; touch-action: none; }
#re::-webkit-slider-runnable-track { height: 34px; background: transparent; }
#re::-moz-range-track { height: 34px; background: transparent; }
#re::-webkit-slider-thumb {
  -webkit-appearance: none; width: 26px; height: 26px; margin-top: 4px; border-radius: 50%; background: #fff;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 55%, transparent), 0 0 24px var(--accent);
}
#re::-moz-range-thumb {
  width: 26px; height: 26px; border: 0; border-radius: 50%; background: #fff;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 55%, transparent), 0 0 24px var(--accent);
}
.ticks { position: relative; height: 26px; margin-top: 4px; font-family: var(--display); font-size: 11px; color: var(--faint); }
.ticks span { position: absolute; transform: translateX(-50%); top: 8px; }

.hint {
  position: fixed; left: 50%; bottom: 150px; transform: translateX(-50%); padding: 9px 16px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); font-size: 13px; color: var(--ink);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); z-index: 3; transition: opacity 0.8s; pointer-events: none; white-space: nowrap;
}
.hint.gone { opacity: 0; }
.toast {
  position: fixed; left: 50%; top: 22px; transform: translate(-50%, -20px); padding: 12px 18px; border-radius: 14px; max-width: min(520px, 92vw);
  background: rgba(14, 18, 30, 0.88); border: 1px solid var(--line); font-size: 14px; line-height: 1.45; z-index: 6;
  opacity: 0; transition: opacity 0.35s, transform 0.35s; pointer-events: none;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast b { color: var(--accent); }
.fail { position: fixed; inset: 0; display: grid; place-items: center; padding: 32px; text-align: center; z-index: 10; background: #05070d; font-size: 17px; line-height: 1.6; color: var(--dim); }

/* What it all means: a panel from the left. */
.explain {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(520px, 100vw); z-index: 8; overflow-y: auto;
  background: rgba(7, 10, 18, 0.9); border-right: 1px solid var(--line);
  backdrop-filter: blur(20px) saturate(140%); -webkit-backdrop-filter: blur(20px) saturate(140%);
  transform: translateX(-100%); transition: transform 0.45s cubic-bezier(.2,.8,.2,1);
}
.explain.open { transform: none; }
.explain-body { padding: 44px 36px 60px; }
.explain h2 { font-family: var(--display); font-weight: 500; font-size: 36px; letter-spacing: -0.02em; margin: 10px 0 14px; }
.explain h3 { font-family: var(--display); font-weight: 500; font-size: 20px; margin: 34px 0 10px; }
.explain p, .explain li { font-size: 15px; line-height: 1.62; color: #c9cfdc; }
.explain b { color: var(--ink); font-weight: 600; }
.explain .small { font-size: 13px; color: var(--dim); }
.close { position: absolute; top: 14px; right: 16px; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255,255,255,.04); font-size: 22px; cursor: pointer; }
.formula { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 22px 0; font-family: var(--display); font-size: 18px; }
.formula .re { font-size: 30px; color: var(--accent); }
.formula .eq { color: var(--faint); }
.frac { display: inline-flex; flex-direction: column; align-items: center; }
.frac span:first-child { border-bottom: 1px solid var(--dim); padding: 0 6px 3px; }
.frac span:last-child { padding: 3px 6px 0; }
.calc { display: grid; gap: 12px; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.03); }
.calc label { display: grid; grid-template-columns: 56px 1fr 92px; align-items: center; gap: 10px; font-size: 13px; color: var(--dim); }
.calc label:first-child { grid-template-columns: 56px 1fr; }
.calc select { background: #0d1220; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.calc input[type=range] { accent-color: var(--accent); }
.calc output { font-family: var(--display); color: var(--ink); text-align: right; font-size: 13px; }
.calc-result { font-family: var(--display); font-size: 22px; }
.calc-result b { color: var(--accent); font-weight: 500; }
.primary { justify-self: start; padding: 9px 16px; border-radius: 10px; border: 0; background: var(--accent); color: #0a0d14; font-weight: 600; cursor: pointer; }
.tries { padding-left: 18px; }
.tries li { margin-bottom: 10px; }

@media (max-width: 760px), (max-height: 520px) {
  .hud { max-width: calc(100vw - 32px); left: 16px; }
  .re-value { font-size: 52px; }
  .regime-line { font-size: 13.5px; max-width: 92vw; }
  .toolbar { top: auto; bottom: calc(118px + env(safe-area-inset-bottom)); right: 0; left: 0; flex-direction: row; flex-wrap: wrap; justify-content: center; padding: 0 8px; gap: 6px; }
  .group { flex-direction: row; flex: none; padding: 3px; }
  .tool { padding: 7px 8px; }
  .ladder button.minor { display: none; }
  /* The readout over the flow's start, made readable. */
  body::before { content: ''; position: fixed; left: 0; right: 0; top: 0; height: 190px; z-index: 2; pointer-events: none;
    background: linear-gradient(to bottom, rgba(3, 5, 10, 0.85), rgba(3, 5, 10, 0.4) 60%, transparent); }
  .tool span { display: none; }
  .tool[aria-checked='true'] { box-shadow: inset 0 -2px 0 var(--accent); }
  .stats { display: none; }
  .hint { bottom: calc(222px + env(safe-area-inset-bottom)); font-size: 12px; }
  body.exp-unstir .unstir-panel { bottom: calc(170px + env(safe-area-inset-bottom)); gap: 6px; padding: 6px; flex-wrap: wrap; justify-content: center; white-space: normal; width: calc(100vw - 24px); }
  .unstir-panel .big { padding: 9px 13px; font-size: 14px; }
  .unstir-status { min-width: 0; }
  .ladder button { font-size: 18px; }
  .dial-inner { padding-top: 44px; }
  .ladder { height: 40px; }
  .explain-body { padding: 40px 22px 60px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .regime-line { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .title-card, .explain, .toast { transition: none; }
}
