/* The Last Question — a visual companion.
   Base rules are for phones; the wide-screen @media blocks sit at the END of
   this file on purpose (a media query adds no specificity, so an early block
   loses to later base rules). Keep them last. */

:root {
  --bg: #020306;
  --ink: #ece7db;
  --muted: #bdb8ac;
  --faint: #9a968e;
  --serif: "Newsreader", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --now: #cfd6ff;
  --glow: rgba(40, 60, 160, 1);
  --accent: #cfd6ff;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--bg);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.62;
  font-optical-sizing: auto;
  overflow-x: hidden;
}

a { color: inherit; text-decoration-color: color-mix(in srgb, var(--accent) 70%, transparent); text-underline-offset: .18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- fixed layers ---------- */

#cosmos {
  position: fixed; left: 0; top: 0;
  width: 100vw; height: 100vh; height: 100lvh;
  display: block; z-index: 0;
  background: var(--bg);
}

.ambient {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background-color: var(--glow);
  opacity: .11;
  -webkit-mask-image: radial-gradient(ellipse 75% 55% at 50% 42%, #000 0%, transparent 75%);
  mask-image: radial-gradient(ellipse 75% 55% at 50% 42%, #000 0%, transparent 75%);
  mix-blend-mode: screen;
  transition: background-color 2.5s ease;
}

.scrim { display: none; }

.labels { position: fixed; inset: 0; z-index: 2; pointer-events: none; overflow: hidden; }
.lbl {
  position: absolute; left: 0; top: 0;
  font: 500 13px/1.25 var(--mono);
  letter-spacing: .08em; text-transform: uppercase;
  color: #eef1ff; white-space: nowrap;
  opacity: 0; will-change: transform, opacity;
  text-shadow: 0 0 6px #000, 0 0 2px #000, 0 0 12px #000;
}
.lbl.ring { white-space: pre; }
/* the ring is centred on the star the label points at (18px left, 9px down) */
.lbl.ring::before {
  content: ""; position: absolute; left: -29px; top: -2px;
  width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .75);
}
.lbl.ring.flip::before { left: auto; right: -29px; }

.flash {
  position: fixed; inset: 0; z-index: 7; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at var(--fx, 50%) var(--fy, 45%), #ffffff 0%, #fffaf0 35%, #ffe7b0 100%);
}

/* ---------- top bar ---------- */

.bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 6;
  display: flex; align-items: center; gap: .75rem;
  padding: .65rem 1rem .75rem;
  padding-top: max(.65rem, env(safe-area-inset-top));
  font: 500 13px/1 var(--mono);
  letter-spacing: .06em; text-transform: uppercase;
  background: rgba(2, 3, 6, .93);
}
.bar::before {
  content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 26px; pointer-events: none;
  background: linear-gradient(rgba(2, 3, 6, .75), rgba(2, 3, 6, 0));
}
.bar a { text-decoration: none; }
.bar-title { display: none; color: var(--ink); }
.bar-era { color: var(--now); transition: color 1.2s ease; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-btn[hidden] { display: none; }
.bar-motion { margin-left: auto; }
.bar-motion:not([hidden]) + .bar-sound { margin-left: 0; }
.bar-btn {
  flex: none;
  font: inherit; letter-spacing: inherit; text-transform: inherit;
  color: var(--muted); background: rgba(3, 4, 9, .4);
  border: 1px solid rgba(255, 255, 255, .22); border-radius: 999px;
  padding: .45rem .75rem; cursor: pointer;
}
.bar-sound { margin-left: auto; }
.bar-btn[aria-pressed="true"] { color: var(--ink); border-color: var(--now); }
.meter { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: rgba(255, 255, 255, .08); }
.meter i {
  position: absolute; inset: 0; transform-origin: 0 50%;
  transform: scaleX(var(--s, .03));
  background: var(--now); box-shadow: 0 0 10px var(--now);
  transition: background-color 1.2s ease;
}

/* ---------- story column ---------- */

.story { position: relative; z-index: 3; }
section { position: relative; }

.block {
  position: relative;
  width: min(35rem, calc(100% - 2rem));
  margin: 0 auto;
}
.panel {
  background: rgba(2, 3, 6, .86);
  border-radius: 14px;
  padding: 1.05rem 1.15rem;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .05);
}
.prose p { margin: 0 0 1em; }
.prose p:last-child { margin-bottom: 0; }

.gap { height: 42vh; }
.gap.s { height: 20vh; }
.gap.l { height: 62vh; }
.gap.xl { height: 95vh; }

.small-h {
  font: 500 13.5px/1.3 var(--mono);
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 .9rem;
}

.big-line { font-size: 1.35em; line-height: 1.35; font-weight: 400; }
.quiet { color: var(--muted); font-style: italic; }

/* ---------- hero ---------- */

.hero {
  min-height: 100vh; min-height: 100svh;
  display: flex; flex-direction: column; justify-content: center;
  padding: 5rem 0 3rem;
}
.kicker {
  font: 500 13.5px/1 var(--mono); letter-spacing: .2em; text-transform: uppercase;
  color: #cfd6ff; margin: 0;
}
h1 {
  font: 300 clamp(3.3rem, 15vw, 7.8rem)/.94 var(--serif);
  letter-spacing: -.02em; margin: .32em 0 .38em;
  font-variation-settings: "opsz" 72;
}
h1 em { font-style: italic; font-weight: 300; }
.dek { font-size: clamp(1.15rem, 4.4vw, 1.42rem); line-height: 1.45; color: #e2ddd1; margin: 0 0 1.1rem; }
.note { font-size: 16px; line-height: 1.55; color: var(--muted); margin: 0; }
.cue {
  margin: 2.6rem 0 0; font: 500 13px/1 var(--mono); letter-spacing: .2em; text-transform: uppercase; color: var(--faint);
  display: flex; align-items: center; gap: .8rem;
}
.cue::after {
  content: ""; width: 54px; height: 1px; background: currentColor;
  transform-origin: 0 50%; animation: cue 2.6s ease-in-out infinite;
}
@keyframes cue { 0%, 100% { transform: scaleX(.25); opacity: .4; } 50% { transform: scaleX(1); opacity: 1; } }

.toc { list-style: none; padding: 0; margin: 0; }
.toc a {
  display: grid; grid-template-columns: 2.7rem 1fr; column-gap: .6rem; align-items: baseline;
  padding: .6rem 0; border-bottom: 1px solid rgba(255, 255, 255, .08);
  text-decoration: none; color: var(--ink);
}
.toc li:last-child a { border-bottom: 0; }
.toc .n { font: italic 400 1.2rem/1 var(--serif); color: var(--muted); }
.toc .t { font-size: 1.05rem; }
.toc .w { grid-column: 2; font: 400 13.5px/1.4 var(--mono); color: var(--muted); letter-spacing: .04em; }
.toc a:hover .t { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: .2em; }

/* ---------- eras ---------- */

.era[data-scene="1"] { --accent: #ffb347; }
.era[data-scene="2"] { --accent: #7fd8ff; }
.era[data-scene="3"] { --accent: #ffcf6e; }
.era[data-scene="4"] { --accent: #cdb8ff; }
.era[data-scene="5"] { --accent: #b3c8ff; }
.era[data-scene="6"] { --accent: #ff8a6c; }
.era[data-scene="7"] { --accent: #f3efff; }
.after-sec { --accent: #ffd98a; }

.era-head { padding-top: 1.2rem; }
.era-num {
  font: italic 300 clamp(4.4rem, 22vw, 8.5rem)/.85 var(--serif);
  color: var(--accent); margin: 0; opacity: .92;
}
.era-title {
  font: 400 clamp(2.1rem, 9vw, 3.4rem)/1.04 var(--serif);
  letter-spacing: -.01em; margin: .18em 0 .4em;
}
.era-meta {
  font: 500 13.5px/1.5 var(--mono); letter-spacing: .1em; text-transform: uppercase;
  color: var(--accent); margin: 0 0 .9rem;
}
.cast { display: flex; flex-wrap: wrap; gap: .35rem 1.5rem; margin: 0; font: 400 15px/1.45 var(--mono); }
.cast div { display: flex; gap: .55em; align-items: baseline; }
.cast dt { text-transform: uppercase; letter-spacing: .12em; font-size: 13px; color: var(--faint); }
.cast dd { margin: 0; color: var(--ink); }

/* the question */
.ask { margin-top: 0; margin-bottom: 0; }
.ask figcaption {
  font: 500 13.5px/1.4 var(--mono); letter-spacing: .1em; text-transform: uppercase;
  color: var(--accent); margin-bottom: .5rem;
}
.ask blockquote {
  margin: 0; padding-left: 1rem; border-left: 2px solid var(--accent);
  font: italic 400 clamp(1.32rem, 5.4vw, 1.75rem)/1.33 var(--serif); color: #fff;
}
.ask blockquote::before { content: "\201C"; }
.ask blockquote::after { content: "\201D"; }

/* the answer */
.reply { margin-top: 0; margin-bottom: 0; padding: 1.05rem 1.2rem 1.15rem; border-radius: 4px; }
.reply figcaption {
  font: 500 13px/1.35 var(--mono); letter-spacing: .14em; text-transform: uppercase;
  opacity: .85; margin-bottom: .65rem;
}
.tt {
  position: relative; margin: 0;
  font: 500 clamp(1.02rem, 4.3vw, 1.2rem)/1.5 var(--mono);
  letter-spacing: .06em; text-transform: uppercase;
}
.tt .ghost { visibility: hidden; }
.tt .typed { position: absolute; left: 0; top: 0; right: 0; }
.js .tt .typed { white-space: pre-wrap; }
.tt .cursor {
  display: inline-block; width: .6em; height: 1.05em; vertical-align: -.17em;
  margin-left: .08em; background: currentColor; animation: blink 1.05s steps(1) infinite;
}
.tt.done .cursor { animation: blink 1.05s steps(1) 4 forwards; }
@keyframes blink { 50% { opacity: 0; } 100% { opacity: 0; } }

.reply.paper {
  --perf: radial-gradient(circle at 9px 9px, #000 3.1px, transparent 3.7px);
  color: #2a2316;
  background:
    var(--perf) left top / 18px 18px repeat-y,
    var(--perf) right top / 18px 18px repeat-y,
    linear-gradient(#f1e9d4, #e9dfc4);
  padding-left: 2.1rem; padding-right: 2.1rem;
  box-shadow: 0 14px 50px rgba(0, 0, 0, .55), 0 0 60px rgba(255, 179, 71, .12);
}
.reply.paper figcaption { color: #6b5a3a; opacity: 1; }

.reply.film {
  color: #c9eeff;
  background:
    repeating-linear-gradient(90deg, rgba(127, 216, 255, .45) 0 7px, transparent 7px 17px) left 6px / 100% 5px no-repeat,
    repeating-linear-gradient(90deg, rgba(127, 216, 255, .45) 0 7px, transparent 7px 17px) left calc(100% - 6px) / 100% 5px no-repeat,
    linear-gradient(rgba(127, 216, 255, .13), rgba(127, 216, 255, .06)),
    rgba(3, 6, 12, .82);
  border: 1px solid rgba(127, 216, 255, .32);
  padding-top: 1.5rem; padding-bottom: 1.5rem;
}

.reply.voice {
  color: #ffe0a0;
  background: linear-gradient(90deg, rgba(20, 14, 3, .86), rgba(20, 14, 3, .6));
  border-top: 1px solid rgba(255, 207, 110, .35);
  border-bottom: 1px solid rgba(255, 207, 110, .35);
  border-radius: 0;
}
.wave { display: flex; align-items: center; gap: 3px; height: 26px; margin-top: .8rem; }
.wave i { flex: 1; max-width: 5px; height: 100%; background: rgba(255, 207, 110, .65); border-radius: 2px; transform: scaleY(.08); transition: transform .12s linear; }

.reply.thought {
  color: #efe8ff;
  background: radial-gradient(ellipse 90% 120% at 20% 50%, rgba(205, 184, 255, .16), rgba(3, 4, 9, .82) 75%);
  text-shadow: 0 0 18px rgba(205, 184, 255, .75);
  border-radius: 14px;
}
.reply.cosmic {
  color: #e3ebff;
  background: rgba(5, 7, 18, .84);
  border: 1px solid rgba(179, 200, 255, .26);
  text-shadow: 0 0 14px rgba(179, 200, 255, .5);
}
.reply.ember {
  color: #ffc2b0;
  background: rgba(14, 5, 3, .84);
  border: 1px solid rgba(255, 138, 108, .3);
  text-shadow: 0 0 14px rgba(255, 110, 70, .45);
}
.reply.light { text-align: center; background: none; color: #fff; padding-top: 2rem; padding-bottom: 2rem; }
.reply.light figcaption { color: #e9e6ff; }
.reply.light .tt {
  font-size: clamp(1.75rem, 8.4vw, 3.6rem); line-height: 1.15; letter-spacing: .07em;
  text-shadow: 0 0 26px rgba(255, 244, 214, .9), 0 0 60px rgba(255, 220, 150, .6);
}
.reply.light .tt .typed { text-align: center; }

.there-was {
  font: italic 300 clamp(2.3rem, 10vw, 5rem)/1.1 var(--serif);
  text-align: center; margin: 0 auto; color: #fffaf0;
  text-shadow: 0 0 30px rgba(255, 236, 190, .7);
}
.js .there-was { opacity: 0; transform: translateY(12px); transition: opacity 2.6s ease 1.4s, transform 2.6s ease 1.4s; }
.js body.lit .there-was, body.lit .there-was { opacity: 1; transform: none; }

/* the arithmetic aside */
.math { font-size: 16px; line-height: 1.5; }
.math p { margin: 0 0 .9rem; }
.math p:last-child { margin: .9rem 0 0; color: var(--muted); }
.math table { width: 100%; border-collapse: collapse; font: 400 14px/1.35 var(--mono); font-variant-numeric: tabular-nums; }
.math th, .math td { text-align: left; vertical-align: top; padding: .5rem .55rem .5rem 0; border-bottom: 1px solid rgba(255, 255, 255, .1); }
.math th { font-weight: 500; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.math td:last-child { color: var(--accent); padding-right: 0; }
.math .sub { display: block; color: var(--faint); font-size: 13px; }
.math sup { font-size: 12.5px; line-height: 0; }

/* afterword */
.books { list-style: none; padding: 0; margin: 0 0 .9rem; }
.books li { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: .15rem 1rem; padding: .62rem 0; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.books cite { font-style: italic; font-size: 1.05rem; }
.books .yr { font: 400 13.5px/1.4 var(--mono); color: var(--muted); }
.fine { font-size: 15px; color: var(--muted); }
.again-wrap { text-align: center; }
.again {
  font: 500 14px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase;
  color: var(--ink); background: rgba(3, 4, 9, .6);
  border: 1px solid rgba(255, 255, 255, .32); border-radius: 999px;
  padding: .95rem 1.4rem; cursor: pointer;
}
.again:hover { border-color: var(--accent); color: #fff; }

/* calm motion, chosen from the bar (html.calm) */
html.calm { scroll-behavior: auto; }
.calm .cue::after, .calm .tt .cursor { animation: none; }
.calm .there-was { transition: opacity .6s ease; transform: none; }

/* ======================================================================
   Wider screens. These blocks must stay LAST in the file.
   ====================================================================== */

@media (min-width: 640px) {
  body { font-size: 19px; }
  .bar { padding-left: 1.5rem; padding-right: 1.5rem; gap: 1.1rem; letter-spacing: .1em; }
  .bar-title { display: inline; }
  .bar-era { margin-left: auto; }
  .bar-btn { margin-left: 0; }
  .toc a { grid-template-columns: 3rem 1fr auto; }
  .toc .w { grid-column: auto; text-align: right; }
  .panel { padding: 1.35rem 1.5rem; }
}

@media (min-width: 900px) and (min-aspect-ratio: 23/20) {
  body { font-size: 19.5px; }
  .scrim {
    display: block; position: fixed; inset: 0; z-index: 1; pointer-events: none;
    background: linear-gradient(90deg, rgba(3, 4, 9, .9) 0%, rgba(3, 4, 9, .72) 32%, rgba(3, 4, 9, .25) 50%, rgba(3, 4, 9, 0) 60%);
  }
  .ambient {
    -webkit-mask-image: radial-gradient(ellipse 50% 70% at 72% 52%, #000 0%, transparent 72%);
    mask-image: radial-gradient(ellipse 50% 70% at 72% 52%, #000 0%, transparent 72%);
  }
  .block { width: min(35rem, 42vw); margin-left: 6vw; margin-right: 0; }
  .panel { background: none; box-shadow: none; padding: 0; border-radius: 0; }
  .reply { margin-left: calc(6vw - 1.2rem); width: calc(min(35rem, 42vw) + 2.4rem); }
  .reply.paper { margin-left: calc(6vw - 2.1rem); width: calc(min(35rem, 42vw) + 4.2rem); }
  .reply.light { margin-left: 0; width: 100%; padding-left: 6vw; padding-right: 6vw; }
  .there-was { width: 100%; margin-left: 0; }
  .again-wrap { text-align: left; }
  .gap { height: 48vh; }
  .gap.l { height: 70vh; }
}
