/* Story overlays — the narrator that floats over the visualization.
 *
 *   #context-card        where and when am I                      js/ui/contextCard.js
 *   #milestone-overlay   narration layer: milestone toasts (top-centre) and era title cards
 *                        (centre)                                 js/ui/milestoneOverlay.js
 *   #extinction-overlay  mass-extinction card + edge vignette     js/ui/extinctionOverlay.js
 *   #intro-root          intro dialog and finale card             js/ui/intro.js
 *
 * The overlays keep out of each other's way through flags the components set on <html>:
 *   data-ov-crisis     the extinction card is showing
 *   data-ov-finale     the finale card is showing
 *   data-ov-intro      the intro dialog is open
 *   data-ov-narrating  a milestone toast is up or waiting (the finale waits for it; script only)
 * so the yielding rules live here, in one place, instead of in four scripts.
 *
 * Every card that sits on the map uses --glass-strong: the map behind can be anything from a
 * black ocean to a white snowball, and muted text has to keep 4.5:1 on all of it.
 */

/* ========================================================================== */
/* Context card                                                               */
/* ========================================================================== */

#context-card {
  --cc-color: var(--accent);
  position: absolute;
  left: var(--s-5);
  bottom: var(--s-5);
  width: min(424px, calc(100% - 2 * var(--s-5)));
  z-index: var(--z-viz-ui);
  pointer-events: none;
  /* --cc-lift: set by the script while main.js's status pill would otherwise sit on the card */
  transform: translateY(calc(-1 * var(--cc-lift, 0px)));
  transition: opacity var(--dur-2) var(--ease), transform var(--dur-2) var(--ease),
    visibility 0s;
}

/* A soft pool of shadow instead of a box: densest in the container's corner, still dark enough
   under the last glyph for 4.5:1 on a white snowball, then a long eased feather above and to the
   right. The map behind is blurred so place names and markers never tangle with the text.
   While the context lines are folded the pool is only as wide as the short lines above them. */
.cc-scrim {
  --feather-x: 120px;
  --feather-y: 100px;
  --solid-w: 352px;
  position: absolute;
  top: calc(-1 * var(--feather-y) - 10px);
  right: calc(100% - var(--solid-w) - var(--feather-x));
  bottom: calc(-1 * var(--s-5) - var(--cc-lift, 0px));
  left: calc(-1 * var(--s-5));
  z-index: -1;
  background: radial-gradient(ellipse 150% 150% at 0% 100%,
    color-mix(in srgb, var(--bg-0) 88%, transparent) 0%,
    color-mix(in srgb, var(--bg-0) 79%, transparent) 62%,
    color-mix(in srgb, var(--bg-0) 77%, transparent) 100%);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  -webkit-mask-image:
    linear-gradient(to right, #000 calc(100% - var(--feather-x)), rgba(0, 0, 0, 0.84) calc(100% - 0.75 * var(--feather-x)), rgba(0, 0, 0, 0.5) calc(100% - 0.5 * var(--feather-x)), rgba(0, 0, 0, 0.16) calc(100% - 0.25 * var(--feather-x)), transparent),
    linear-gradient(to top, #000 calc(100% - var(--feather-y)), rgba(0, 0, 0, 0.84) calc(100% - 0.75 * var(--feather-y)), rgba(0, 0, 0, 0.5) calc(100% - 0.5 * var(--feather-y)), rgba(0, 0, 0, 0.16) calc(100% - 0.25 * var(--feather-y)), transparent);
  -webkit-mask-composite: source-in;
  mask-image:
    linear-gradient(to right, #000 calc(100% - var(--feather-x)), rgba(0, 0, 0, 0.84) calc(100% - 0.75 * var(--feather-x)), rgba(0, 0, 0, 0.5) calc(100% - 0.5 * var(--feather-x)), rgba(0, 0, 0, 0.16) calc(100% - 0.25 * var(--feather-x)), transparent),
    linear-gradient(to top, #000 calc(100% - var(--feather-y)), rgba(0, 0, 0, 0.84) calc(100% - 0.75 * var(--feather-y)), rgba(0, 0, 0, 0.5) calc(100% - 0.5 * var(--feather-y)), rgba(0, 0, 0, 0.16) calc(100% - 0.25 * var(--feather-y)), transparent);
  mask-composite: intersect;
  transition: right var(--dur-3) var(--ease);
}

#context-card.is-open .cc-scrim {
  --feather-x: 150px;
  right: calc(-1 * var(--feather-x) - 14px);
}

/* The rule on the left wears the period's ICS colour — the same colour as its block on the
   timeline. */
.cc-body {
  position: relative;
  padding-left: var(--s-4);
}

.cc-head {
  position: relative;
}

.cc-head::before {
  content: '';
  position: absolute;
  left: calc(-1 * var(--s-4));
  top: 3px;
  bottom: 4px;
  width: 3px;
  border-radius: 2px;
  background: var(--cc-color);
  transition: background-color var(--dur-3) ease;
}

/* Muted ink is one step brighter here than on panels: the scrim is translucent. */
.cc-kicker {
  color: var(--text-2);
}

.cc-titlewrap {
  position: relative;
  margin-top: 2px;
}

.cc-title,
.cc-title-ghost {
  font-size: var(--fs-h1);
  color: var(--text-1);
}

.cc-title {
  text-wrap: balance;
}

.cc-title-ghost {
  position: absolute;
  left: 0;
  top: 0;
  white-space: nowrap;
  opacity: 0;
}

.cc-sweep {
  position: absolute;
  left: 0;
  bottom: -2px;
  width: min(100%, 260px);
  height: 2px;
  border-radius: 1px;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 0%, transparent));
  transform-origin: left center;
  transform: scaleX(0);
  opacity: 0;
}

/* A new period: the old name lifts away, the new one rises, an amber line sweeps under it. */
.cc-titlewrap.is-changing .cc-title {
  animation: cc-title-in 560ms var(--ease) both;
}

.cc-titlewrap.is-changing .cc-title-ghost {
  animation: cc-title-out 360ms ease both;
}

.cc-titlewrap.is-changing .cc-sweep {
  animation: cc-sweep 1200ms var(--ease) both;
}

@keyframes cc-title-in {
  from { opacity: 0; transform: translateY(9px); }
  to { opacity: 1; transform: none; }
}

@keyframes cc-title-out {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateY(-9px); }
}

@keyframes cc-sweep {
  0% { transform: scaleX(0); opacity: 1; }
  50% { transform: scaleX(1); opacity: 1; }
  100% { transform: scaleX(1); opacity: 0; }
}

.cc-age {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px var(--s-2);
  margin-top: var(--s-1);
}

.cc-years {
  font-size: var(--fs-lead);
  font-weight: 600;
  color: var(--text-1);
}

.cc-ma {
  padding: 0 6px;
  border: 1px solid var(--glass-line);
  border-radius: var(--r-pill);
  font-size: var(--fs-small);
  color: var(--text-2);
  text-decoration: none;
  cursor: help;
  pointer-events: auto;
}

/* Earth clock: 4.54 billion years as one day. */
.cc-clock {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--s-2);
  width: fit-content;
  max-width: 100%;
  margin-top: var(--s-2);
  font-size: var(--fs-small);
  color: var(--text-2);
  pointer-events: auto;
}

.cc-dial {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.cc-dial circle {
  fill: none;
  stroke-width: 2.6;
}

.cc-dial-track {
  stroke: color-mix(in srgb, var(--accent) 26%, transparent);
}

.cc-dial-arc {
  stroke: var(--accent);
  stroke-linecap: round;
}

.cc-dial-tick {
  fill: none;
  stroke: var(--text-1);
  stroke-width: 1.6;
  stroke-linecap: round;
}

.cc-clock-time {
  color: var(--text-1);
  font-weight: 600;
}

.cc-info {
  position: relative;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin: -3px 0;
  padding: 0;
  border: 1px solid var(--glass-line);
  border-radius: 50%;
  background: transparent;
  color: var(--text-2);
  font: italic 600 var(--fs-micro) / 1 var(--font-display);
  transition: color var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}

/* A comfortable hit area around the small glyph. */
.cc-info::after {
  content: '';
  position: absolute;
  inset: -7px;
}

.cc-clock:hover .cc-info,
.cc-info:focus-visible {
  color: var(--accent-strong);
  border-color: var(--accent-line);
}

.cc-tip {
  position: absolute;
  left: 0;
  bottom: calc(100% + var(--s-2));
  width: min(320px, 78vw);
  padding: var(--s-3) var(--s-4);
  background: var(--glass-strong);
  border: 1px solid var(--glass-line);
  border-radius: var(--r-2);
  box-shadow: var(--shadow-2);
  font-size: var(--fs-small);
  line-height: 1.5;
  color: var(--text-2);
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: opacity var(--dur-1) ease, transform var(--dur-1) var(--ease), visibility 0s linear var(--dur-1);
  pointer-events: none;
}

.cc-clock:hover .cc-tip,
.cc-clock:focus-within .cc-tip {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition-delay: 0s;
}

.cc-clock.is-dismissed .cc-tip {
  opacity: 0;
  visibility: hidden;
}

.cc-desc {
  max-width: 330px;
  margin-top: var(--s-2);
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--fs-lead);
  line-height: 1.35;
  color: var(--text-1);
  text-wrap: balance;
}

/* Life / Climate / Land & sea — folds open while paused and for a few seconds after a period
   change. Animating grid rows 0fr → 1fr gives a height transition without measuring. */
.cc-context {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  visibility: hidden;
  transition: grid-template-rows var(--dur-3) var(--ease), opacity var(--dur-2) ease,
    visibility 0s linear var(--dur-3);
}

#context-card.is-open .cc-context {
  grid-template-rows: 1fr;
  opacity: 1;
  visibility: visible;
  transition: grid-template-rows var(--dur-3) var(--ease), opacity var(--dur-3) ease var(--dur-1),
    visibility 0s;
}

.cc-context-inner {
  min-height: 0;
  overflow: hidden;
}

.cc-lines {
  display: grid;
  gap: 6px;
  margin-top: var(--s-3);
  padding-top: var(--s-3);
  border-top: 1px solid var(--glass-line);
}

.cc-line {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  column-gap: var(--s-2);
  align-items: baseline;
}

.cc-line dt {
  color: var(--text-2);
}

.cc-line dd {
  font-size: var(--fs-body);
  line-height: 1.45;
  color: var(--text-1);
  text-wrap: pretty;
}

/* The extinction and finale cards take the lower-centre of the stage; until the viewport is
   wide enough for both, the context card bows out while they are up. */
@media (max-width: 1899px) {
  :root[data-ov-crisis] #context-card,
  :root[data-ov-finale] #context-card {
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: opacity var(--dur-2) var(--ease), transform var(--dur-2) var(--ease),
      visibility 0s linear var(--dur-2);
  }
}

/* ========================================================================== */
/* Narration layer: era title cards + milestone toasts                        */
/* ========================================================================== */

#milestone-overlay {
  position: absolute;
  inset: 0;
  z-index: var(--z-toast);
  overflow: hidden;
  pointer-events: none;
}

:root[data-ov-intro] #milestone-overlay {
  visibility: hidden;
}

/* ---- Era title card -------------------------------------------------------- */

/* The house lights dim: a veil over the whole stage, deepest behind the words, so there is no
   box and no edge — just a quieter map for three seconds. */
.era-veil {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 62% 58% at 50% 41%,
    color-mix(in srgb, var(--bg-0) 66%, transparent) 0%,
    color-mix(in srgb, var(--bg-0) 52%, transparent) 38%,
    color-mix(in srgb, var(--bg-0) 24%, transparent) 100%);
  opacity: 0;
  transition: opacity 900ms ease;
}

.era-veil.is-in {
  opacity: 1;
  transition: opacity 700ms ease;
}

.era-title {
  position: absolute;
  left: 50%;
  top: max(39%, 244px);
  width: max-content;
  max-width: min(720px, calc(100% - 2 * var(--s-4)));
  transform: translate(-50%, -50%);
  text-align: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 800ms ease, visibility 0s linear 800ms;
}

.era-title.is-in {
  opacity: 1;
  visibility: visible;
  transition: opacity 600ms ease 120ms, visibility 0s;
}

.era-kicker {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-3);
  color: var(--accent-strong);
  letter-spacing: 0.34em;
  /* letter-spacing trails the last glyph: nudge the word back to centre */
  text-indent: 0.34em;
}

.era-kicker::before,
.era-kicker::after {
  content: '';
  width: 44px;
  height: 1px;
  background: var(--accent-line);
}

.era-name {
  margin: var(--s-2) 0 var(--s-1);
  font-size: clamp(40px, 5.4vw, 66px);
  line-height: 1.05;
  color: var(--text-1);
  text-shadow: 0 2px 22px var(--bg-0);
}

.era-title.is-in .era-name {
  animation: era-settle 1500ms var(--ease) both;
}

@keyframes era-settle {
  from { letter-spacing: 0.07em; transform: translateY(6px); }
  to { letter-spacing: 0.005em; transform: none; }
}

.era-range {
  font-size: var(--fs-body);
  letter-spacing: 0.03em;
  color: var(--text-1);
}

.era-tagline {
  margin-top: var(--s-2);
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--fs-h3);
  line-height: 1.3;
  color: var(--text-1);
  text-wrap: balance;
  text-shadow: 0 1px 12px var(--bg-0);
}

/* ---- Milestone toast ------------------------------------------------------- */

/* --ms-left / --ms-right are set by the script when the legend or chapters panel is open, so
   the toast re-centres in the free space between them. */
.ms-slot {
  position: absolute;
  top: var(--s-4);
  left: var(--ms-left, var(--s-4));
  right: var(--ms-right, var(--s-4));
  display: flex;
  justify-content: center;
}

.ms-toast {
  --event-color: var(--accent);
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: var(--s-3);
  width: min(540px, 100%);
  padding: var(--s-3) var(--s-4) calc(var(--s-3) + 3px) var(--s-3);
  overflow: hidden;
  background: var(--glass-strong);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: opacity var(--dur-2) ease, transform var(--dur-2) var(--ease),
    visibility 0s linear var(--dur-2);
}

.ms-toast.is-in {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity var(--dur-3) ease, transform var(--dur-3) var(--ease), visibility 0s;
}

.ms-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  margin-top: 1px;
  border: 1px solid color-mix(in srgb, var(--event-color) 44%, transparent);
  border-radius: 50%;
  background: color-mix(in srgb, var(--event-color) 15%, transparent);
  color: color-mix(in srgb, var(--event-color) 72%, var(--text-1));
}

.ms-icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ms-icon .solid {
  fill: currentColor;
  stroke: none;
}

.ms-kicker {
  color: var(--text-3);
}

.ms-kicker .ms-cat {
  color: color-mix(in srgb, var(--event-color) 55%, var(--text-1));
}

/* A place name too long to sit beside the date gets a line of its own (set by the script). */
.ms-kicker.is-stacked .ms-place {
  display: block;
}

.ms-title {
  margin: 1px 0 3px;
  font-size: calc(var(--fs-h3) + 2px);
  color: color-mix(in srgb, var(--event-color) 34%, var(--text-1));
  text-wrap: balance;
}

.ms-body {
  font-size: var(--fs-body);
  line-height: 1.5;
  color: var(--text-2);
}

/* Remaining dwell */
.ms-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: color-mix(in srgb, var(--event-color) 16%, transparent);
}

.ms-progress-bar {
  display: block;
  height: 100%;
  background: color-mix(in srgb, var(--event-color) 70%, var(--text-1));
  transform-origin: left center;
}

/* ========================================================================== */
/* Extinction card                                                            */
/* ========================================================================== */

#extinction-overlay,
.finale {
  /* the band at the bottom of the stage where main.js's status pill appears */
  --ov-notice-clear: 64px;
}

#extinction-overlay {
  --event-color: var(--danger);
  position: absolute;
  inset: 0;
  z-index: var(--z-event);
  pointer-events: none;
  container: ext-overlay / size;
}

/* Colour at the edges only — the map itself stages the catastrophe. */
.ext-vignette {
  position: absolute;
  inset: 0;
  opacity: 0;
  background: radial-gradient(ellipse 78% 74% at 50% 46%,
    transparent 56%,
    color-mix(in srgb, var(--event-color) 30%, transparent) 100%);
  box-shadow: inset 0 0 110px 6px color-mix(in srgb, var(--event-color) 26%, transparent);
}

.ext-dock {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 6%;
  display: flex;
  justify-content: center;
  padding: 0 var(--s-4);
  transition: bottom var(--dur-2) var(--ease);
}

/* main.js's status pill (#view-notice: 16px from the bottom, ~33px tall) is stacked below the
   event layer: while it shows, the docked cards (this one and the finale) step up out of its way. */
#viz-container:has(#view-notice:not(.hidden)) .ext-dock {
  bottom: max(6%, var(--ov-notice-clear));
}

.ext-card {
  position: relative;
  width: min(640px, 100%);
  max-height: 88cqh;
  padding: 10px var(--s-5) var(--s-4);
  overflow: hidden auto;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--event-color) 13%, transparent), transparent 76px),
    var(--glass-strong);
  pointer-events: auto;
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px);
  transition: opacity 500ms ease, transform 500ms var(--ease), visibility 0s linear 500ms;
}

.ext-card.is-in {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity 500ms ease, transform 500ms var(--ease), visibility 0s;
}

/* Scrubbed straight into an event: a quick fade, the bar already full (see _reveal). */
.ext-card.is-in.is-instant {
  transition-duration: 160ms, 160ms, 0s;
}

.ext-card.is-instant .ext-meter-fill {
  transition: none;
}

/* Top rule in the event's colour */
.ext-card::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--event-color) 30%, color-mix(in srgb, var(--event-color) 35%, transparent));
}

.ext-head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-height: 30px;
}

.ext-kicker {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin-right: auto;
  color: var(--text-2);
}

/* The same diamond that marks the event on the timeline */
.ext-kicker::before {
  content: '';
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  background: color-mix(in srgb, var(--event-color) 85%, var(--text-1));
  transform: rotate(45deg);
}

.ext-continue {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  min-height: 30px;
  padding: 0 var(--s-2) 0 var(--s-1);
  border: 1px solid var(--accent-line);
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: var(--fs-small);
  font-weight: 600;
  white-space: nowrap;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}

.ext-continue:hover {
  background: color-mix(in srgb, var(--accent) 24%, transparent);
  border-color: var(--accent);
}

.ext-continue kbd {
  min-width: 0;
  padding: 0 5px;
  border-color: var(--accent-line);
  background: transparent;
  font-size: var(--fs-micro);
  color: var(--accent-strong);
}

.ext-ring {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.ext-ring circle {
  fill: none;
  stroke-width: 2.4;
}

.ext-ring-track {
  stroke: color-mix(in srgb, var(--accent) 24%, transparent);
}

.ext-ring-arc {
  stroke: var(--accent);
  stroke-linecap: round;
}

.ext-ring-glyph {
  fill: var(--accent-strong);
}

/* While the countdown waits for a reader the play glyph becomes a pause glyph. */
.ext-ring-pause,
.ext-card.is-reading .ext-ring-play {
  display: none;
}

.ext-card.is-reading .ext-ring-pause {
  display: inline;
}

.ext-card.is-reading .ext-ring-arc {
  stroke: var(--accent-strong);
}

.ext-lede {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(200px, 41%);
  column-gap: var(--s-5);
  align-items: end;
  margin-top: 2px;
}

.ext-title {
  font-size: calc(var(--fs-h2) + 2px);
  color: var(--text-1);
  text-wrap: balance;
}

.ext-formal {
  margin-top: 2px;
  font-size: var(--fs-body);
  font-style: italic;
  color: var(--text-2);
}

/* Severity meter: the fill is what was lost; the faint track of the same hue is what survived. */
.ext-meter {
  padding-bottom: 3px;
}

/* The label may run to two lines ("of marine species lost (estimates: 81–94%)"): it grows
   upward beside the number, so the bar never moves. */
.ext-meter-figure {
  display: flex;
  align-items: flex-end;
  gap: var(--s-2);
}

.ext-meter-value {
  font-size: calc(var(--fs-h2) + 2px);
  font-weight: 700;
  line-height: 1;
  color: var(--text-1);
}

.ext-meter-label {
  padding-bottom: 2px;
  font-size: var(--fs-small);
  line-height: 1.25;
  color: var(--text-2);
  text-wrap: balance;
}

.ext-meter-track {
  height: 6px;
  margin-top: 7px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--event-color) 24%, transparent);
  overflow: hidden;
}

.ext-meter-fill {
  width: 0;
  height: 100%;
  border-radius: 3px;
  background: color-mix(in srgb, var(--event-color) 84%, var(--text-1));
  transition: width 1200ms var(--ease) 320ms;
}

.ext-card.is-in .ext-meter-fill {
  width: calc(var(--ext-severity, 0) * 1%);
}

.ext-desc {
  margin-top: 10px;
  font-size: var(--fs-lead);
  line-height: 1.45;
  color: var(--text-1);
  text-wrap: pretty;
}

.ext-facts {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 6px var(--s-4);
  align-items: baseline;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--glass-line);
}

.ext-facts dt {
  color: var(--text-3);
}

.ext-facts dd {
  font-size: var(--fs-body);
  line-height: 1.45;
  color: var(--text-2);
}

.ext-facts dd.ext-cause {
  color: var(--text-1);
}

.ext-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  list-style: none;
}

.ext-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
  padding: 0 var(--s-2) 0 7px;
  border: 1px solid var(--glass-line);
  border-radius: var(--r-pill);
  background: var(--line-soft);
  font-size: var(--fs-small);
  line-height: 1.2;
  color: var(--text-1);
  white-space: nowrap;
}

button.ext-chip {
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}

button.ext-chip:hover {
  background: var(--bg-3);
  border-color: var(--line-strong);
}

/* "+N more": unfolds the rest of the list */
.ext-chip-more {
  padding-left: var(--s-2);
  border-style: dashed;
  background: transparent;
  color: var(--text-2);
}

button.ext-chip-more:hover {
  color: var(--text-1);
}

.ext-chips:focus-visible {
  outline-offset: 3px;
}

.ext-chip-dot {
  width: 7px;
  height: 7px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--chip-color, transparent);
  box-shadow: inset 0 0 0 1px var(--chip-color, var(--text-3));
}

/* Short stages (small laptops, capture clips): tighten so the middle of the map stays in view. */
@container ext-overlay (max-height: 620px) {
  .ext-dock {
    bottom: 4%;
  }

  #viz-container:has(#view-notice:not(.hidden)) .ext-dock {
    bottom: max(4%, var(--ov-notice-clear));
  }

  .ext-card {
    padding: var(--s-2) var(--s-5) var(--s-3);
  }

  .ext-title {
    font-size: var(--fs-h2);
  }

  .ext-desc {
    font-size: var(--fs-body);
  }

  .ext-facts {
    margin-top: var(--s-2);
    padding-top: var(--s-2);
    row-gap: 6px;
  }

  .ext-facts .ext-survived-row {
    display: none;
  }
}

/* Narrow stages (phones): a bottom sheet. */
@container ext-overlay (max-width: 600px) {
  .ext-dock {
    bottom: 0;
    padding: 0;
  }

  /* (separate rule: a browser without :has() drops a whole selector list) */
  #viz-container:has(#view-notice:not(.hidden)) .ext-dock {
    bottom: 0;
  }

  .ext-card {
    width: 100%;
    max-height: 68cqh;
    padding: var(--s-3) var(--s-4) var(--s-4);
    border-radius: var(--r-3) var(--r-3) 0 0;
    border-bottom: none;
  }

  .ext-lede {
    grid-template-columns: minmax(0, 1fr);
    row-gap: var(--s-3);
  }

  .ext-title {
    font-size: var(--fs-h2);
  }

  .ext-desc {
    font-size: var(--fs-body);
  }

  .ext-facts {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 2px;
  }

  .ext-facts dd {
    margin-bottom: var(--s-2);
  }

  .ext-facts dd:last-child {
    margin-bottom: 0;
  }

  /* The sheet must leave the top of the map in view: survivors are the first thing to go. */
  .ext-facts .ext-survived-row {
    display: none;
  }

  .ext-continue kbd {
    display: none;
  }

  .ext-continue {
    min-height: 36px;
    padding-right: var(--s-3);
  }
}

/* ========================================================================== */
/* Intro dialog                                                               */
/* ========================================================================== */

.intro {
  position: fixed;
  inset: 0;
  z-index: var(--z-intro);
  display: grid;
  place-items: center;
  padding: var(--s-4);
  overflow-y: auto;
}

.intro-backdrop {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg-0) 56%, transparent);
  -webkit-backdrop-filter: blur(7px) saturate(0.9);
  backdrop-filter: blur(7px) saturate(0.9);
  animation: intro-fade 500ms ease both;
}

.intro-card {
  position: relative;
  width: min(580px, 100%);
  padding: var(--s-7) var(--s-7) var(--s-6);
  text-align: center;
  background:
    radial-gradient(120% 70% at 50% 0%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 70%),
    var(--glass-strong);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-line);
  border-radius: calc(var(--r-3) + 4px);
  box-shadow: var(--shadow-3);
  animation: intro-bloom 700ms var(--ease) both;
}

@keyframes intro-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes intro-bloom {
  from { opacity: 0; transform: translateY(10px) scale(0.965); }
  to { opacity: 1; transform: none; }
}

.intro.is-leaving .intro-backdrop,
.intro.is-leaving .intro-card {
  animation: none;
  opacity: 0;
  transition: opacity var(--dur-2) ease, transform var(--dur-2) var(--ease);
}

.intro.is-leaving .intro-card {
  transform: scale(0.98);
}

/* The brand mark, grown: branches draw, then the three blooms open one by one. */
.intro-mark.brand-mark {
  width: 64px;
  height: 64px;
  overflow: visible;
}

.intro-mark path {
  stroke-dasharray: 30;
  stroke-dashoffset: 30;
  animation: intro-draw 900ms var(--ease) 250ms forwards;
}

.intro-mark .bloom {
  transform-box: fill-box;
  transform-origin: center;
  transform: scale(0);
  animation: intro-pop 520ms cubic-bezier(0.3, 1.5, 0.5, 1) forwards;
}

.intro-mark .bloom-a { animation-delay: 820ms; }
.intro-mark .bloom-b { animation-delay: 960ms; }
.intro-mark .bloom-c { animation-delay: 1100ms; }

@keyframes intro-draw {
  to { stroke-dashoffset: 0; }
}

@keyframes intro-pop {
  to { transform: scale(1); }
}

.intro-title {
  margin-top: var(--s-3);
  font-size: clamp(34px, 9.4vw, var(--fs-hero));
  line-height: 1.05;
  color: var(--text-1);
}

.intro-promise {
  max-width: 44ch;
  margin: var(--s-4) auto 0;
  font-size: calc(var(--fs-lead) + 1px);
  line-height: 1.55;
  color: var(--text-2);
  text-wrap: balance;
}

.intro-promise strong {
  color: var(--text-1);
  font-weight: 600;
}

.intro-sees {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s-4);
  margin: var(--s-5) 0 0;
  padding: var(--s-4) 0 0;
  border-top: 1px solid var(--glass-line);
  list-style: none;
  text-align: left;
}

.intro-see {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: var(--s-2);
  align-items: start;
}

.intro-see svg {
  width: 22px;
  height: 22px;
  margin-top: 1px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.intro-see strong {
  display: block;
  font-size: var(--fs-body);
  font-weight: 600;
  color: var(--text-1);
}

.intro-see span {
  display: block;
  font-size: var(--fs-small);
  line-height: 1.4;
  color: var(--text-2);
}

.intro-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--s-3);
  margin-top: var(--s-5);
}

.intro-actions .btn {
  min-height: 42px;
  padding: 0 var(--s-5);
  font-size: var(--fs-lead);
}

.intro-actions .btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.intro-hints {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--s-1) var(--s-4);
  margin-top: var(--s-4);
  font-size: var(--fs-small);
  color: var(--text-3);
}

.intro-hints kbd {
  margin-right: 2px;
}

/* Keyboard hints mean nothing on a touch-only device. */
@media (hover: none) and (pointer: coarse) {
  .intro-hints {
    display: none;
  }
}

/* ========================================================================== */
/* Finale card                                                                */
/* ========================================================================== */

/* A fixed layer laid exactly over the visualization (the script copies its rectangle into
   --viz-*), so the card can sit lower-centre of the map while living in the page-level root.
   It uses the map-overlay stacking level: above the map, below panels, drawers and dialogs. */
.finale {
  position: fixed;
  left: var(--viz-x, 0);
  top: var(--viz-y, 0);
  width: var(--viz-w, 100vw);
  height: var(--viz-h, 100vh);
  z-index: var(--z-event);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 var(--s-4) calc(var(--viz-h, 100vh) * 0.07);
  pointer-events: none;
  overflow: hidden;
  transition: padding-bottom var(--dur-2) var(--ease);
}

/* Out of the way of main.js's status pill while it shows, as the extinction card is. */
:root:has(#view-notice:not(.hidden)) .finale {
  padding-bottom: max(calc(var(--viz-h, 100vh) * 0.07), var(--ov-notice-clear));
}

.finale-card {
  position: relative;
  width: min(620px, 100%);
  max-height: calc(var(--viz-h, 100vh) * 0.86);
  padding: var(--s-4) var(--s-5) var(--s-4);
  overflow: hidden auto;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--accent) 10%, transparent), transparent 80px),
    var(--glass-strong);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 700ms ease, transform 700ms var(--ease);
}

.finale.is-in .finale-card {
  opacity: 1;
  transform: none;
}

.finale-card::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent) 30%, color-mix(in srgb, var(--accent) 30%, transparent));
}

.finale-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  min-height: 28px;
}

.finale-kicker {
  color: var(--text-2);
}

.finale-close {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-right: calc(-1 * var(--s-2));
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-3);
  transition: color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}

.finale-close:hover {
  color: var(--text-1);
  background: var(--bg-3);
}

.finale-close svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.finale-title {
  font-size: var(--fs-h1);
  color: var(--text-1);
}

.finale-lead {
  margin-top: var(--s-1);
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--fs-lead);
  line-height: 1.4;
  color: var(--text-1);
  text-wrap: pretty;
}

.finale-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s-4);
  margin: var(--s-3) 0 0;
  padding: var(--s-3) 0 0;
  border-top: 1px solid var(--glass-line);
}

.finale-stat dt {
  font-size: calc(var(--fs-h2) - 2px);
  font-weight: 700;
  line-height: 1.15;
  color: var(--text-1);
  white-space: nowrap;
}

.finale-stat dt small {
  font-size: var(--fs-body);
  font-weight: 600;
  color: var(--text-2);
}

.finale-stat dd {
  margin-top: 2px;
  font-size: var(--fs-small);
  line-height: 1.4;
  color: var(--text-2);
}

.finale-crisis {
  margin-top: var(--s-3);
  padding-left: var(--s-3);
  border-left: 2px solid var(--crisis-color, var(--danger));
  font-size: var(--fs-body);
  line-height: 1.45;
  color: var(--text-2);
}

.finale-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-top: var(--s-4);
}

.finale-actions .btn svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ========================================================================== */
/* Small screens                                                              */
/* ========================================================================== */

@media (max-width: 720px) {
  /* Kicker, title and age only: the rest lives in the Life panel and the toolbar. */
  #context-card {
    left: var(--s-4);
    bottom: var(--s-4);
    width: calc(100% - 2 * var(--s-4));
  }

  /* Full-width band: nothing to feather sideways, a shorter feather above. */
  .cc-scrim,
  #context-card.is-open .cc-scrim {
    --feather-x: 24px;
    --feather-y: 72px;
    left: calc(-1 * var(--s-4));
    right: calc(-1 * var(--s-4) - var(--feather-x));
    bottom: calc(-1 * var(--s-4) - var(--cc-lift, 0px));
  }

  .cc-body {
    padding-left: var(--s-3);
  }

  .cc-title,
  .cc-title-ghost {
    font-size: calc(var(--fs-h2) + 4px);
  }

  .cc-clock,
  .cc-desc,
  .cc-context {
    display: none;
  }

  .ms-slot {
    top: var(--s-2);
    left: var(--s-2);
    right: var(--s-2);
  }

  .ms-toast {
    padding: var(--s-3) var(--s-3) calc(var(--s-3) + 3px);
    column-gap: var(--s-2);
  }

  .ms-icon {
    width: 32px;
    height: 32px;
  }

  .ms-icon svg {
    width: 19px;
    height: 19px;
  }

  /* The kicker has room for the date or the place, not both. */
  .ms-place {
    display: none;
  }

  .ms-title {
    font-size: var(--fs-h3);
  }

  .era-title {
    top: max(45%, 300px);
  }

  .era-tagline {
    font-size: var(--fs-lead);
  }

  .intro-card {
    padding: var(--s-6) var(--s-5) var(--s-5);
  }

  .intro-sees {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--s-3);
  }

  .intro-actions {
    flex-direction: column;
  }

  .finale {
    padding: 0;
  }

  :root:has(#view-notice:not(.hidden)) .finale {
    padding-bottom: 0;
  }

  .finale-card {
    width: 100%;
    max-height: calc(var(--viz-h, 100vh) * 0.74);
    padding: var(--s-3) var(--s-4) var(--s-4);
    border-radius: var(--r-3) var(--r-3) 0 0;
    border-bottom: none;
  }

  .finale-title {
    font-size: calc(var(--fs-h2) + 2px);
  }

  .finale-stats {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--s-2);
  }

  .finale-stat {
    display: grid;
    grid-template-columns: 104px minmax(0, 1fr);
    column-gap: var(--s-3);
    align-items: baseline;
  }

  .finale-stat dt {
    font-size: var(--fs-h3);
  }

  .finale-stat dd {
    margin-top: 0;
  }

  .finale-actions .btn {
    flex: 1 1 auto;
  }
}

/* Short landscape phones: the intro must still fit. */
@media (max-height: 560px) {
  .intro {
    place-items: start center;
  }

  .intro-card {
    padding: var(--s-5);
  }

  .intro-mark.brand-mark {
    width: 44px;
    height: 44px;
  }

  .intro-sees {
    margin-top: var(--s-4);
  }

  .intro-actions {
    margin-top: var(--s-4);
  }
}

/* ========================================================================== */
/* Reduced motion                                                             */
/* ========================================================================== */

/* css/styles.css already collapses every duration under [data-motion='reduced']; delays must go
   too, or staged entrances (the intro's blooms, the severity bar) would pop in late instead of
   simply being there. */
[data-motion='reduced'] #context-card *,
[data-motion='reduced'] #milestone-overlay *,
[data-motion='reduced'] #extinction-overlay *,
[data-motion='reduced'] #intro-root * {
  animation-delay: 0s !important;
  transition-delay: 0s !important;
}

/* ========================================================================== */
/* Capture mode (js/capture.js): recorded clips want the story, not the chrome */
/* ========================================================================== */

body.capture-mode .cc-info,
body.capture-mode .cc-tip,
body.capture-mode .ext-continue,
body.capture-mode .finale {
  display: none !important;
}

/* Capture time-lapses (__capture.sweep sets body.capture-sweeping) scrub every frame, so toasts
   and the static extinction card would flash for single frames: the story overlays sit them out. */
body.capture-sweeping #milestone-overlay,
body.capture-sweeping #extinction-overlay {
  display: none !important;
}

/* Tree view: the radial tree fills the middle of the stage and its top rim sits right under the
   top-centre slot, while the corners stay empty — so on wider screens the toast tucks into the
   top-left corner, a little narrower. (The script's --ms-left still moves it clear of the legend.) */
@media (min-width: 721px) {
  #app[data-view='tree'] .ms-slot {
    justify-content: flex-start;
  }

  #app[data-view='tree'] .ms-toast {
    width: min(400px, 100%);
  }
}
