:root {
  color-scheme: light;
  --ground: #e3dfd5;
  --panel: rgba(225, 220, 208, .86);
  --ink: #171b19;
  --muted: #606762;
  --line: rgba(23, 27, 25, .2);
  --recede: #9f4d37;
  --emerge: #e7a148;
  --ui-ink: #171b19;
  --ui-muted: rgba(23, 27, 25, .62);
  --ui-line: rgba(23, 27, 25, .24);
  --ui-surface: rgba(231, 226, 215, .58);
}

* { box-sizing: border-box; }
html, body, main { width: 100%; height: 100%; margin: 0; }
#metric[hidden], #legend[hidden] { display: none !important; }

body {
  overflow: hidden;
  background: var(--ground);
  color: var(--ink);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

main { position: relative; min-height: 560px; isolation: isolate; }
#scene, #scene canvas { display: block; width: 100%; height: 100%; }

.evidence-clean .story-header,
.evidence-clean .metric,
.evidence-clean .legend,
.evidence-clean .playback,
.evidence-clean .editorial-scrim,
.evidence-clean .about-trigger { display: none; }

.prelude {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 19px;
  padding: 40px;
  background: rgba(19, 25, 23, .58);
  color: #f0ece1;
  text-align: center;
  backdrop-filter: blur(8px);
  transition: opacity .65s ease, visibility .65s ease;
}

.prelude.dismissed { opacity: 0; visibility: hidden; pointer-events: none; }
.prelude p { margin: 0; font-size: 9px; font-weight: 700; letter-spacing: .23em; text-transform: uppercase; }
.prelude-heading { display: grid; justify-items: center; gap: 14px; }
.prelude h2 { margin: 0; font-size: clamp(48px, 7vw, 92px); font-weight: 320; letter-spacing: -.055em; line-height: .92; }
.prelude .prelude-area { font-size: clamp(14px, 1.4vw, 18px); letter-spacing: .18em; }
.prelude .prelude-years { color: #dcb775; font-size: clamp(27px, 3vw, 40px); font-weight: 320; letter-spacing: .06em; line-height: .92; }
.prelude .prelude-copy { max-width: 43ch; color: #f0ece1; font-size: clamp(13px, 1.2vw, 17px); font-weight: 430; letter-spacing: 0; line-height: 1.45; text-transform: none; }
.prelude button { margin-top: 10px; border-color: #f0ece1; background: rgba(240, 236, 225, .12); color: #f0ece1; }
.prelude button:hover, .prelude button:focus-visible { background: #f0ece1; color: #171b19; }

.editorial-scrim {
  position: absolute;
  z-index: 1;
  inset: 0 auto 0 0;
  width: 42vw;
  min-width: 420px;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(234, 230, 220, .74) 0%, rgba(234, 230, 220, .38) 19%, rgba(234, 230, 220, .1) 31%, transparent 42%);
  transition: background .85s ease, opacity .85s ease;
}

main[data-ui-theme="night"] {
  --ui-ink: #f4f0e7;
  --ui-muted: rgba(244, 240, 231, .68);
  --ui-line: rgba(244, 240, 231, .3);
  --ui-surface: rgba(8, 14, 22, .34);
}

main[data-ui-theme="night"] .editorial-scrim {
  width: 40vw;
  background: linear-gradient(90deg, rgba(5, 10, 17, .78) 0%, rgba(5, 10, 17, .56) 17%, rgba(5, 10, 17, .22) 28%, transparent 40%);
}

.story-header {
  position: absolute;
  z-index: 2;
  inset: 30px auto auto 36px;
  width: min(540px, calc(100% - 72px));
  pointer-events: none;
  color: var(--ui-ink);
  text-shadow: 0 1px 14px rgba(227, 223, 213, .18);
  transition: color .85s ease, text-shadow .85s ease;
}

.story-header p,
.metric span,
.metric small {
  margin: 0;
  color: var(--ui-muted);
  font-size: 9px;
  font-weight: 650;
  letter-spacing: .19em;
  text-transform: uppercase;
}

.story-header .location {
  color: var(--ui-muted);
  font-size: 9px;
  letter-spacing: .2em;
}

.editorial-stage {
  position: relative;
  min-height: 178px;
  margin-top: 18px;
}

.editorial-copy {
  position: absolute;
  inset: 0;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .42s ease, transform .42s ease;
}

.editorial-copy.is-active {
  opacity: 1;
  transform: none;
}

.story-header h1 {
  max-width: 12ch;
  margin: 0;
  color: var(--ui-ink);
  font-size: clamp(42px, 5.8vw, 78px);
  font-weight: 350;
  letter-spacing: -.052em;
  line-height: .94;
  text-wrap: balance;
}

.caption {
  max-width: 50ch;
  margin-top: 17px !important;
  color: var(--ui-muted) !important;
  font-size: clamp(11px, .95vw, 14px) !important;
  font-weight: 620 !important;
  letter-spacing: .055em !important;
  line-height: 1.58 !important;
  white-space: pre-line;
}

.caption:empty { display: none; }

.metric {
  position: absolute;
  z-index: 2;
  top: 34px;
  right: 36px;
  display: grid;
  gap: 5px;
  text-align: right;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .65s ease, transform .65s ease;
}

.metric.visible { opacity: 1; transform: none; }
.metric strong { font-size: clamp(38px, 4.6vw, 66px); font-weight: 350; letter-spacing: -.055em; line-height: .92; }

.legend {
  position: absolute;
  z-index: 2;
  right: 36px;
  top: 36px;
  display: flex;
  gap: 18px;
  opacity: 0;
  transition: opacity .2s ease;
  color: var(--muted);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: .16em;
}

.legend.visible { opacity: 1; }
.legend span { display: flex; gap: 7px; align-items: center; }
.legend i { width: 8px; height: 8px; border-radius: 50%; }
.legend .recede { background: var(--recede); }
.legend .emerge { background: var(--emerge); }

.playback {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 24px;
  width: min(880px, calc(100% - 84px));
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 22px;
  align-items: end;
  color: var(--ui-ink);
  opacity: .56;
  transition: opacity .25s ease, color .85s ease;
}

.playback:hover,
.playback:focus-within { opacity: 1; }

.transport {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 40px;
}

.transport-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  border: 0;
  padding: 9px 8px;
  background: transparent;
  color: var(--ui-muted);
  font-size: 8px;
  backdrop-filter: none;
}

.transport-button.primary { color: var(--ui-ink); }
.transport-button:hover,
.transport-button:focus-visible { color: var(--ui-ink); background: transparent; }
.transport-button:focus-visible { outline: 1px solid var(--ui-ink); outline-offset: 2px; }
.play-icon { width: 8px; text-align: center; }

#time-readout {
  min-width: 34px;
  margin-left: 4px;
  color: var(--ui-muted);
  font-size: 8px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .1em;
}

.timeline {
  position: relative;
  width: 100%;
  height: 42px;
}

.timeline-track {
  position: absolute;
  top: 10px;
  left: 0;
  width: 100%;
  height: 1px;
  background: var(--ui-line);
}

.timeline-progress {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--ui-ink);
  transform: scaleX(0);
  transform-origin: left;
}

.era-divider {
  position: absolute;
  top: -4px;
  left: 40.38%;
  width: 1px;
  height: 9px;
  background: var(--ui-muted);
  opacity: .7;
}

#scrubber {
  position: absolute;
  z-index: 2;
  top: 0;
  left: -7px;
  width: calc(100% + 14px);
  height: 21px;
  margin: 0;
  border: 0;
  padding: 0;
  appearance: none;
  background: transparent;
  cursor: ew-resize;
}

#scrubber::-webkit-slider-runnable-track { height: 1px; background: transparent; }
#scrubber::-webkit-slider-thumb {
  width: 6px;
  height: 6px;
  margin-top: -2.5px;
  border: 1px solid var(--ui-ink);
  border-radius: 50%;
  appearance: none;
  background: var(--ui-ink);
  box-shadow: 0 0 0 2px var(--ui-surface);
  transition: transform .2s ease, box-shadow .2s ease;
}
#scrubber:hover::-webkit-slider-thumb,
#scrubber:focus-visible::-webkit-slider-thumb { transform: scale(1.3); }
#scrubber:focus-visible { outline: none; }
#scrubber:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 2px var(--ui-surface), 0 0 0 3px var(--ui-ink); }

.chapter-markers {
  position: absolute;
  inset: 20px 0 auto;
  height: 20px;
}

.chapter-marker {
  position: absolute;
  z-index: 3;
  top: 0;
  left: var(--chapter-position);
  min-width: 0;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  color: var(--ui-muted);
  font-size: 8px;
  letter-spacing: .11em;
  white-space: nowrap;
  backdrop-filter: none;
  transform: translateX(-50%);
}

.chapter-marker:first-child { transform: none; }
.chapter-marker:last-child { transform: translateX(-100%); }
.chapter-marker::before {
  position: absolute;
  top: -13px;
  left: 50%;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  content: "";
  transform: translate(-50%, -50%);
}
.chapter-marker:first-child::before { left: 0; }
.chapter-marker:last-child::before { left: 100%; }
.chapter-marker:hover,
.chapter-marker:focus-visible,
.chapter-marker.is-current { color: var(--ui-ink); background: transparent; }
.chapter-marker:focus-visible { outline: 1px solid var(--ui-ink); outline-offset: 4px; }

.playback.is-final .chapter-marker:last-child::before {
  animation: final-night-pulse 3s ease-in-out infinite;
}

@keyframes final-night-pulse {
  0%, 100% { opacity: .68; transform: translate(-50%, -50%) scale(.92); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.18); }
}

button {
  border: 1px solid var(--ink);
  border-radius: 999px;
  padding: 12px 21px 11px;
  background: var(--panel);
  color: var(--ink);
  font: 700 9px/1 "Helvetica Neue", Helvetica, Arial, sans-serif;
  letter-spacing: .18em;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: background .2s, color .2s, opacity .2s;
}

button:hover, button:focus-visible { color: var(--ground); background: var(--ink); }
button:focus-visible { outline: 2px solid var(--ground); outline-offset: -4px; }
button[disabled] { opacity: 0; pointer-events: none; }

.about-trigger,
.about-close {
  position: absolute;
  z-index: 4;
  min-width: 0;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: 8px;
  letter-spacing: .16em;
  backdrop-filter: none;
}

.about-trigger { right: 36px; bottom: 13px; }
.about-trigger:hover,
.about-trigger:focus-visible,
.about-close:hover,
.about-close:focus-visible { color: var(--ink); background: transparent; }

dialog {
  width: min(700px, calc(100% - 48px));
  max-height: calc(100% - 48px);
  margin: auto;
  border: 0;
  padding: 0;
  background: #e7e2d6;
  color: var(--ink);
  box-shadow: 0 24px 90px rgba(23, 27, 25, .25);
}

dialog::backdrop { background: rgba(23, 27, 25, .48); backdrop-filter: blur(5px); }
.about-content { padding: 58px 62px 52px; }
.about-kicker { margin: 0 0 14px; color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: .18em; }
.about-content h2 { margin: 0; font-size: clamp(34px, 5vw, 54px); font-weight: 350; letter-spacing: -.05em; line-height: .98; }
.about-lede { margin: 25px 0 34px; max-width: 54ch; font-size: 16px; line-height: 1.5; }
.about-content dl { display: grid; gap: 0; margin: 0; }
.about-content dl div { display: grid; grid-template-columns: 130px 1fr; gap: 22px; border-top: 1px solid var(--line); padding: 14px 0; }
.about-content dt { font-size: 10px; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; line-height: 1.4; }
.about-content dd,
.method-note { margin: 0; color: #4a514d; font-size: 13px; line-height: 1.55; }
.method-note { margin-top: 21px; }
.method-note strong { color: var(--ink); }
.source-links { display: flex; flex-wrap: wrap; gap: 10px 22px; margin-top: 22px; }
.about-content a { color: var(--ink); font-size: 12px; line-height: 1.45; text-underline-offset: 3px; }
.about-close { inset: 22px 24px auto auto; }
.error { position: absolute; inset: 50% auto auto 50%; transform: translate(-50%, -50%); font-size: 11px; letter-spacing: .14em; }

@media (max-width: 720px) {
  .editorial-scrim { width: 92vw; min-width: 0; }
  main[data-ui-theme="night"] .editorial-scrim { width: 92vw; }
  .story-header { inset: 22px auto auto 22px; width: calc(100% - 44px); }
  .editorial-stage { min-height: 154px; margin-top: 14px; }
  .story-header h1 { max-width: 11ch; font-size: clamp(38px, 12vw, 62px); }
  .caption { max-width: 34ch; font-size: 10px !important; }
  .metric { top: auto; right: 22px; bottom: 116px; }
  .legend { top: auto; right: 22px; bottom: 116px; }
  .playback { bottom: 24px; width: calc(100% - 44px); grid-template-columns: 1fr; gap: 2px; }
  .transport { min-height: 28px; }
  .transport-button { padding: 6px 7px; }
  .timeline { height: 38px; }
  .chapter-marker { font-size: 7px; letter-spacing: .07em; }
  .about-trigger { top: 22px; right: 22px; bottom: auto; }
  .about-content { padding: 54px 27px 36px; }
  .about-content dl div { grid-template-columns: 1fr; gap: 7px; }
}

@media (max-height: 650px) and (min-width: 721px) {
  .story-header { inset: 22px auto auto 28px; }
  .editorial-stage { min-height: 142px; margin-top: 12px; }
  .caption { margin-top: 10px !important; }
  .playback { bottom: 17px; }
}

@media (prefers-reduced-motion: reduce) {
  .metric, .legend, .prelude, .editorial-copy, .editorial-scrim { transition: none; }
  .playback.is-final .chapter-marker:last-child::before { animation: none; }
}
