:root {
  color-scheme: light dark;
  --paper: #f7f4e9;
  --ink: #1e211b;
  --ink-strong: #14160f;
  --ink-hover: #363b30;
  --muted: #77796c;
  --line: #dcdcd0;
  --hover: #edece1;
  --accent: #528b94;
  --ball-outline: #353a32;
  --message: #4b7160;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #191b17;
    --ink: #e9e7dc;
    --ink-strong: #f4f2e8;
    --ink-hover: #d3d1c5;
    --muted: #9a9c8f;
    --line: #363932;
    --hover: #24271f;
    --accent: #7fb9c2;
    --ball-outline: #0f110e;
    --message: #8fb9a2;
  }
}

* { box-sizing: border-box; }
body { margin: 0; }
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.experiment {
  width: min(880px, calc(100% - 40px));
  min-height: 100svh;
  margin-inline: auto;
  padding-block: 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.heading { width: 100%; margin-bottom: 18px; text-align: center; }
h1 {
  margin: 0;
  font-family: Impact, Haettenschweiler, "Arial Narrow", "Liberation Sans Narrow", sans-serif;
  font-size: clamp(27px, 6.8vw, 56px);
  font-weight: 900;
  line-height: 1.08;
  letter-spacing: -.018em;
  color: var(--ink-strong);
}
h1 span { display: block; }

.arena {
  width: min(100%, max(280px, calc(100svh - 400px)), 650px);
  aspect-ratio: 1;
}
canvas { display: block; width: 100%; height: 100%; cursor: crosshair; touch-action: manipulation; }

.dashboard { width: min(590px, 100%); margin-top: 20px; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 18px 22px; }
.population {
  display: flex;
  align-items: baseline;
  gap: 7px;
  min-width: 86px;
  white-space: nowrap;
}
.population output {
  font-size: 30px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: -.055em;
  font-variant-numeric: tabular-nums;
}
.population span { font-size: 13px; color: var(--muted); }
.buttons { display: flex; gap: 8px; }
.button {
  height: 46px;
  padding-inline: 17px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background 140ms ease, transform 140ms ease;
}
.button:active { transform: translateY(1px); }
.button:disabled { opacity: .45; cursor: default; transform: none; }
.button-primary { color: var(--paper); background: var(--ink); min-width: 112px; }
.button-primary:hover { background: var(--ink-hover); }
.button-secondary { color: var(--ink); background: transparent; border-color: var(--line); }
.button-secondary:hover { background: var(--hover); }
.button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.button .play-icon { fill: currentColor; stroke-width: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

/* The two sliders share a row of their own under the buttons. */
.speed-control { flex: 1 1 calc(50% - 11px); min-width: 100px; }
.speed-label { display: flex; justify-content: space-between; gap: 20px; font-size: 12px; }
.speed-label label { color: var(--muted); }
.speed-label output { font-weight: 600; font-variant-numeric: tabular-nums; }
input[type="range"] {
  --progress: 27.2727%;
  appearance: none;
  -webkit-appearance: none;
  display: block;
  width: 100%;
  height: 24px;
  margin: 4px 0 -4px;
  background: transparent;
  cursor: pointer;
  touch-action: pan-y;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--ink) var(--progress), var(--line) var(--progress));
}
input[type="range"]::-moz-range-track { height: 3px; border-radius: 3px; background: var(--line); }
input[type="range"]::-moz-range-progress { height: 3px; background: var(--ink); }
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  margin-top: -5px;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
}
input[type="range"]::-moz-range-thumb { width: 13px; height: 13px; border: 0; border-radius: 50%; background: var(--ink); }

.next-collision {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px 16px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.section-label { margin: 0 0 5px; font-size: 12px; color: var(--muted); }
#next-collision { display: block; font-size: 29px; font-weight: 700; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
#next-collision:not([data-state="ready"]) { font-size: 17px; letter-spacing: -.025em; }
#prediction-hint { grid-column: 1 / -1; margin: 0; font-size: 11px; line-height: 1.5; color: var(--muted); }
#skip { padding-inline: 13px; }
#skip svg { stroke-width: 1.3; }
.skip-message { margin: 10px 0 0; font-size: 12px; line-height: 1.5; color: var(--message); overflow-wrap: anywhere; }
.skip-message:empty { display: none; }
.share {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px 16px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
#run-seed { display: block; font-size: 20px; font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
#share-hint { grid-column: 1 / -1; margin: 0; font-size: 11px; line-height: 1.5; color: var(--muted); }
#share { padding-inline: 13px; }
.collision-forecast {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px 16px;
  margin-top: 18px;
}
.forecast-label p { margin: 0; font-size: 13px; font-weight: 600; }
.forecast-label #chance-window { margin-top: 5px; color: var(--muted); font-size: 11px; line-height: 1.5; font-weight: 400; }
.estimate-tag { margin-left: 5px; color: var(--muted); font-size: 10px; font-weight: 400; }
#collision-chance { font-size: 20px; font-weight: 700; letter-spacing: -.04em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.forecast-details { grid-column: 1 / -1; font-size: 11px; line-height: 1.6; color: var(--muted); }
.forecast-details summary { width: fit-content; cursor: pointer; }
.forecast-details p { margin: 8px 0 0; }

.growth { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.stats-header { display: flex; align-items: center; gap: 30px; }
.stat { display: flex; flex-direction: column; gap: 5px; }
.stat > span { font-size: 11px; color: var(--muted); }
.stat output { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.trail-toggle { margin-left: auto; min-height: 44px; display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font-size: 12px; }
.trail-toggle input { width: 16px; height: 16px; margin: 0; accent-color: var(--ink); cursor: pointer; }
.growth-chart { margin: 16px 0 0; }
.growth-chart figcaption, .chart-axis { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 10px; }
#growth-chart { width: 100%; height: 66px; display: block; margin-top: 8px; overflow: visible; }
.chart-baseline { fill: none; stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-area { fill: #78bdd0; fill-opacity: .12; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 1.6; vector-effect: non-scaling-stroke; stroke-linejoin: round; }

.caption {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
}
.caption p { margin: 0; }
.status { display: inline-flex; align-items: center; gap: 6px; text-align: right; }
.status-dot { flex: 0 0 auto; width: 5px; height: 5px; border-radius: 50%; background: #63866a; }
.status[data-state="paused"] .status-dot { background: #999688; }
.status[data-state="capacity"] .status-dot { background: #c18a42; }
noscript { margin-top: 16px; text-align: center; font-size: 14px; }

@media (max-width: 540px) {
  .experiment { width: calc(100% - 32px); padding-block: 28px; }
  .heading { margin-bottom: 24px; }
  .dashboard { width: calc(100% - 12px); margin-top: 26px; }
  .controls { flex-wrap: wrap; justify-content: space-between; gap: 22px 12px; }
  .buttons { gap: 6px; }
  .button { padding-inline: 13px; }
  .button-primary { min-width: 108px; }
  .population { min-width: 72px; }
  .speed-control { flex-basis: 100%; padding-left: 0; }
  .caption { margin-top: 14px; }
  .stats-header { gap: 20px; }
  .next-collision, .share { gap: 8px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .button { transition: none; }
}
