:root {
  --bg: #000;
  --paper: #0a0a0b;
  --ink: #d7d7d9;
  --ink-dim: #8a8a8f;
  --ink-faint: #56565c;
  --rule: #1e1e21;
  --accent: #fff;
  --serif: ui-serif, Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---------------------------------------------------------------- stage -- */

.stage {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #000;
}

#stage {
  display: block;
  width: 100%;
  height: 100%;
  /* The lens tracks the finger, so the canvas must not also scroll the page. */
  touch-action: none;
  cursor: crosshair;
}

.overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: max(1.25rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right))
           max(1.25rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
}

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.masthead-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.masthead h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(0.95rem, 2.4vw, 1.2rem);
  font-weight: 400;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.9);
}

.source {
  pointer-events: auto;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.9);
  transition: color 0.15s, border-color 0.15s;
}

.source:hover { color: var(--accent); border-bottom-color: var(--ink-faint); }

.hint {
  margin: auto auto 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.6;
  color: var(--ink-dim);
  text-align: center;
  max-width: 30ch;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.95);
  transition: opacity 0.6s ease;
}

.hint.is-hidden { opacity: 0; }

.hint-touch { display: none; }

@media (hover: none) and (pointer: coarse) {
  .hint-desktop { display: none; }
  .hint-touch { display: inline; }
}

.panel {
  margin: 1.1rem auto 2.8rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  max-width: min(46rem, 100%);
}

.picker {
  pointer-events: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
}

.picker button {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  color: var(--ink-dim);
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.42rem 0.8rem;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: color 0.15s, border-color 0.15s;
}

.picker button:hover { color: var(--ink); border-color: var(--ink-faint); }

.picker button.is-on {
  color: #000;
  background: var(--ink);
  border-color: var(--ink);
}

.picker button:focus-visible { outline: 1px solid var(--ink-dim); outline-offset: 3px; }

.sliders {
  pointer-events: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.control {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
}

.control label { text-transform: uppercase; }

.control output {
  min-width: 3.2ch;
  text-align: right;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.credit,
.notice {
  margin: 0;
  max-width: 44ch;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.62rem;
  line-height: 1.6;
  color: var(--ink-faint);
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.95);
}

.credit { pointer-events: auto; }
.credit a { color: var(--ink-dim); text-decoration: none; border-bottom: 1px solid var(--rule); }
.credit a:hover { color: var(--ink); }

.notice { color: var(--ink-dim); }

.credit[hidden],
.notice[hidden] { display: none; }

.loading,
.failure {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  max-width: 34ch;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.7;
  color: var(--ink-dim);
}

.loading[hidden],
.failure[hidden] { display: none; }

.scroll-cue {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(1rem, env(safe-area-inset-bottom));
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.6rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  text-decoration: none;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.95);
  transition: color 0.15s;
}

.scroll-cue:hover { color: var(--ink); }

/* -------------------------------------------------------------- physics -- */

.physics {
  background: var(--paper);
  border-top: 1px solid var(--rule);
  padding: clamp(3rem, 9vw, 6rem) 1.25rem clamp(4rem, 10vw, 7rem);
}

.column {
  max-width: 34rem;
  margin: 0 auto;
}

.physics h2 {
  margin: 0 0 2rem;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.5rem, 4.5vw, 2rem);
  letter-spacing: -0.01em;
}

.physics h3 {
  margin: 2.75rem 0 0.9rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.physics p {
  margin: 0 0 1.1rem;
  font-family: var(--serif);
  font-size: clamp(1rem, 2.6vw, 1.05rem);
  line-height: 1.72;
  color: var(--ink);
}

.physics em { font-style: italic; }

.physics abbr { text-decoration: none; border-bottom: 1px dotted var(--ink-faint); }

.equation {
  font-family: var(--mono) !important;
  font-size: 0.95rem !important;
  text-align: center;
  padding: 1.15rem 0.5rem;
  margin: 1.5rem 0 !important;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  color: var(--accent) !important;
  overflow-x: auto;
}

.physics a { color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--ink-faint); }
.physics a:hover { border-bottom-color: var(--accent); }

.controls-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 0.78rem;
  margin-top: 0.5rem;
}

.controls-table th,
.controls-table td {
  text-align: left;
  padding: 0.65rem 0.75rem 0.65rem 0;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

.controls-table th {
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
  font-size: 0.68rem;
}

.controls-table td { color: var(--ink); }
.controls-table td:first-child { color: var(--ink-dim); }

.credits {
  margin: 1.5rem 0 1.1rem;
  padding: 0;
  list-style: none;
  font-family: var(--mono);
  font-size: 0.74rem;
  line-height: 1.65;
}

.credits li {
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--rule);
  color: var(--ink-dim);
}

.credits li:first-child { border-top: 1px solid var(--rule); }
.credits a { color: var(--ink); }

.fine {
  font-family: var(--mono) !important;
  font-size: 0.72rem !important;
  line-height: 1.7 !important;
  color: var(--ink-dim) !important;
}

.physics code {
  font-family: var(--mono);
  font-size: 0.9em;
  color: var(--accent);
}

.colophon {
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.colophon a { color: var(--ink-faint); border-bottom: none; }
.colophon a:hover { color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .hint { transition: none; }
}

.pill {
  pointer-events: auto;
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.32rem 0.75rem;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: color 0.15s, border-color 0.15s;
}

.pill:hover { color: var(--ink); border-color: var(--ink-faint); }
.pill:focus-visible { outline: 1px solid var(--ink-dim); outline-offset: 3px; }

/* ---- ambient mode ------------------------------------------------------ */

/* Everything but the simulation gets out of the way. */
.overlay,
.scroll-cue {
  transition: opacity 0.7s ease;
}

body.is-ambient .overlay,
body.is-ambient .scroll-cue {
  opacity: 0;
  pointer-events: none;
}

/* The children re-enable pointer events for themselves, so they have to be
   disabled explicitly or invisible controls stay clickable. */
body.is-ambient .overlay * { pointer-events: none; }

body.is-ambient #stage { cursor: none; }

.exit-hint {
  position: absolute;
  left: 50%;
  bottom: max(2.2rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  margin: 0;
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-faint);
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.95);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.7s ease;
}

body.show-exit-hint .exit-hint { opacity: 1; }

#ambient-toggle[aria-pressed="true"] {
  color: #000;
  background: var(--ink);
  border-color: var(--ink);
}


/* ---- Kerr mode ------------------------------------------------------- */

#kerr-stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  background: #000;
  z-index: 40;
}

.kerr-ui {
  position: fixed;
  inset: 0;
  display: none;
  pointer-events: none;
  z-index: 41;
}

body.is-kerr #kerr-stage,
body.is-kerr .kerr-ui { display: block; }

/* The 2D scene keeps its masthead so the mode can be left again. */
body.is-kerr .panel,
body.is-kerr .hint,
body.is-kerr .scroll-cue { opacity: 0; pointer-events: none; }

body.is-kerr .overlay { z-index: 42; }

#kerr-hud {
  position: absolute;
  left: 22px;
  bottom: 22px;
  margin: 0;
  font: 12px/1.55 ui-monospace, "SF Mono", Menlo, monospace;
  color: rgba(206, 216, 232, 0.72);
  text-shadow: 0 0 8px rgba(0, 0, 0, 0.9);
  white-space: pre;
}

.kerr-controls {
  position: absolute;
  right: 22px;
  bottom: 22px;
  width: 260px;
  pointer-events: auto;
  display: grid;
  gap: 10px;
}

.kerr-controls .control {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  font: 11px/1.4 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(206, 216, 232, 0.6);
}

.kerr-controls input[type="range"] { width: 100%; }

.kerr-keys {
  position: absolute;
  right: 22px;
  bottom: 96px;
  margin: 0;
  font: 11px/1.5 ui-monospace, "SF Mono", Menlo, monospace;
  color: rgba(160, 176, 198, 0.5);
}

@media (max-width: 640px) {
  .kerr-controls { left: 22px; right: 22px; width: auto; }
  #kerr-hud { bottom: 150px; }
  .kerr-keys { display: none; }
}
