/* Title Page crawl. Palette follows callings/lds.css (navy/amber, blue
   accent for the intro line); see org/theme-registry.md. */

:root {
  --space:      #03070f;
  --space-low:  #0f2848;
  --amber:      #e0b553;   /* brighter than --lds-accent #c8a24a, for text on black */
  --amber-dim:  #c8a24a;
  --blue:       #70c4f0;
  --text:       #ddeaf8;
  --text-dim:   rgba(185, 220, 250, 0.55);
  --font:       "Inter", system-ui, sans-serif;

  /* Timeline, in seconds from page load. */
  --t-intro:    0.6s;
  --d-intro:    7s;
  --t-logo:     7.8s;
  --d-logo:     11s;
  --t-crawl:    10.5s;
  --d-crawl:    100s;
  /* The ending is one continuous move, each piece starting before the last
     one finishes: the crawl fades as the view tilts down, the barge enters
     during the tilt, the promise rises as the barge leaves. */
  --t-fade:     80s;     /* the last line is passing the middle */
  --t-tilt:     80.5s;   /* view tilts down to a world, under the fade */
  --d-tilt:     8s;
  --t-barge:    84s;     /* enters mid-tilt, cruises, then swoops off on the sting */
  --d-barge:    11.4s;
  --t-promise:  94.6s;   /* the sting: Mars's last big chord lands at 94.67 s */
  --t-cta:      97s;
  --d-total:    100s;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: radial-gradient(ellipse at 50% 140%, var(--space-low) 0%, var(--space) 60%);
  background-color: var(--space);
  color: var(--amber);
  font-family: var(--font);
  overflow: hidden;
}

/* Taller than the screen, so the ending's tilt never shows a bottom edge.
   Scenery only: in the flat reading view it sits over the end-card links. */
.stars {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 135%;
  pointer-events: none;
}

.scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

/* --- Blue opening line -------------------------------------------------- */

.intro {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(34rem, calc(100% - 32px));
  margin: 0;
  transform: translate(-50%, -50%);
  color: var(--blue);
  font-size: clamp(1.15rem, 3.6vw, 1.9rem);
  font-weight: 500;
  line-height: 1.45;
  opacity: 0;
  animation: intro var(--d-intro) ease-in-out var(--t-intro) forwards;
}

@keyframes intro {
  0%   { opacity: 0; }
  15%  { opacity: 1; }
  80%  { opacity: 1; }
  100% { opacity: 0; }
}

/* --- Outlined title, receding ------------------------------------------- */

.logo {
  position: absolute;
  top: 50%;
  left: 50%;
  margin: 0;
  /* Stroke painted under an opaque fill: only the outer half shows, which
     hides the variable font's overlapping contours inside each letter. */
  color: var(--space);
  -webkit-text-stroke: 0.07em var(--amber);
  paint-order: stroke fill;
  font-size: clamp(2.4rem, 12.5vw, 10rem);
  font-weight: 900;
  line-height: 0.92;
  letter-spacing: -0.02em;
  text-align: center;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, -50%) scale(1.15);
  animation: logo var(--d-logo) cubic-bezier(0.2, 0, 0.6, 1) var(--t-logo) forwards;
}

.logo span { display: block; }

@keyframes logo {
  0%   { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  85%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.04); }
}

/* --- The crawl ---------------------------------------------------------- */

/* A tall plane tipped back from its bottom edge; the text rides up it.
   The vanishing line sits at perspective × cot(tilt) above the bottom:
   42vh × cot(24°) ≈ 94vh, just under the top of the screen. Sizes are in
   vh so every screen gets the same picture. The mask fades text into the
   stars over the far half of the plane (about 55–70% of the way up). */
.plane {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: min(21em, calc(100vw - 32px));
  height: 300vh;
  font-size: clamp(1.1rem, min(4.4vw, 3.4vh), 3rem);
  transform: translateX(-50%) perspective(42vh) rotateX(24deg);
  transform-origin: 50% 100%;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 50%);
          mask-image: linear-gradient(to bottom, transparent 0%, #000 50%);
  animation: fade-out 6s ease-in-out var(--t-fade) forwards;
}

@keyframes fade-out {
  to { opacity: 0; }
}

.crawl {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  font-weight: 600;
  line-height: 1.5;
  text-align: justify;
  hyphens: auto;
  animation: crawl var(--d-crawl) linear var(--t-crawl) forwards;
}

/* The last line stops about 180vh up the plane (roughly 60% up the
   screen) and the whole crawl fades, as in the films. */
@keyframes crawl {
  94%  { opacity: 1; }
  to   { opacity: 0; transform: translateY(calc(-100% - 180vh)); }
}

.crawl p { margin: 0 0 1.4em; }

.crawl-kicker,
.crawl-title,
.crawl-sign {
  text-align: center;
  text-transform: uppercase;
}

.crawl .crawl-kicker {
  margin-bottom: 0.3em;
  letter-spacing: 0.08em;
}

.crawl-title {
  margin: 0 0 1.4em;
  font-size: 1.7em;
  font-weight: 800;
  line-height: 1.15;
}

.crawl .crawl-sign {
  margin-top: 2em;
  letter-spacing: 0.06em;
}

/* --- Controls ----------------------------------------------------------- */

.controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 16px calc(0.75rem + env(safe-area-inset-bottom));
  opacity: 0.35;
  transition: opacity 0.3s;
}

.controls:hover,
.controls:focus-within,
body.ended .controls { opacity: 1; }

body.idle:not(.ended):not(.still):not(.paused) .controls:not(:focus-within) {
  opacity: 0;
  transition-duration: 1.2s;
}

.controls button {
  padding: 0.45rem 0.9rem;
  border: 1px solid rgba(200, 162, 74, 0.45);
  border-radius: 999px;
  background: rgba(3, 7, 15, 0.7);
  color: var(--text);
  font: 500 0.85rem var(--font);
  text-decoration: none;
  cursor: pointer;
}

.controls button:hover { border-color: var(--amber); }

/* Full row, centered: the side margins take up whatever 40rem leaves. */
.timeline {
  display: flex;
  flex-basis: 100%;
  align-items: center;
  gap: 0.6rem;
  max-width: 40rem;
  margin: 0 calc(50% - min(20rem, 50%)) 0.2rem;
}

.scrub-track {
  position: relative;
  flex: 1;
  display: flex;
}

.scrub {
  flex: 1;
  margin: 0;
  accent-color: var(--amber);
  cursor: pointer;
}

.scrub-time {
  color: var(--text-dim);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Rides above the handle while dragging; left is set by script.js. */
.scrub-bubble {
  position: absolute;
  bottom: calc(100% + 6px);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: var(--amber);
  color: var(--space);
  font-size: 0.75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  opacity: 0;
  transform: translateX(-50%);
  transition: opacity 0.15s;
}

.scrub-track.scrubbing .scrub-bubble { opacity: 1; }

.credit {
  display: none;
  flex-basis: 100%;
  max-width: 40rem;
  margin: 0.25rem calc(50% - min(20rem, 50%)) 0;
  color: var(--text-dim);
  font-size: 0.75rem;
  line-height: 1.4;
  text-align: center;
}

body.ended .credit,
body.still .credit { display: block; }

/* On a phone the closing card needs the room: the music credit moves to the
   text view, but the not-official note stays. */
@media (max-width: 600px) {
  body.ended .credit:not(.legal) { display: none; }
}

.controls :focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

body.paused .scene *,
body.waiting .scene * { animation-play-state: paused; }

/* --- Ending: tilt down, a barge passes, Moroni's promise ---------------- */

/* Runs the full length of the timeline; script.js reads the time from it. */
.clock {
  position: absolute;
  width: 0;
  height: 0;
  animation: clock var(--d-total) linear forwards;
}

@keyframes clock {
  to { transform: translateX(0); }
}

.scene .stars { animation: tilt var(--d-tilt) ease-in-out var(--t-tilt) forwards; }

@keyframes tilt {
  to { transform: translateY(-30vh); }
}

.world {
  position: absolute;
  top: 70vh;
  left: 50%;
  width: 320vmax;
  height: 320vmax;
  margin-left: -160vmax;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 0%, #3d6398 0, #16304f 1.4%, #0a1528 6%, var(--space) 20%);
  box-shadow: 0 -2px 30px rgba(112, 196, 240, 0.45), 0 -12px 140px rgba(112, 196, 240, 0.16);
  transform: translateY(50vh);
  animation: world var(--d-tilt) ease-in-out var(--t-tilt) forwards;
}

@keyframes world {
  to { transform: translateY(0); }
}

/* Ether 2:17: "tight like unto a dish ... the ends thereof were peaked."
   Ether 6:2: a shining stone "in each end thereof." */
.barge {
  position: absolute;
  top: 36vh;
  left: 0;
  width: min(40vw, 460px);
  opacity: 0;
  animation: barge var(--d-barge) linear var(--t-barge) forwards;
}

/* A slow cruise to 78% (about 92.9 s), then it speeds up and swells toward
   the camera, at the right edge and nearly twice its size on the sting. */
@keyframes barge {
  0%   { opacity: 0; transform: translate(-35vw, 10vh) scale(0.5); animation-timing-function: cubic-bezier(0.3, 0, 0.7, 1); }
  8%   { opacity: 1; }
  78%  { transform: translate(62vw, 2vh) scale(0.95); animation-timing-function: cubic-bezier(0.55, 0, 1, 1); }
  100% { opacity: 1; transform: translate(150vw, -30vh) scale(3); }
}

.hull {
  fill: #221f1b;
  stroke: rgba(224, 181, 83, 0.55);
  stroke-width: 1.2;
}

.hull-seam,
.hull-door {
  fill: none;
  stroke: rgba(224, 181, 83, 0.28);
  stroke-width: 1;
}

.stone {
  transform-box: fill-box;
  transform-origin: center;
  animation: shine 2.4s ease-in-out infinite alternate;
}

@keyframes shine {
  from { opacity: 0.75; transform: scale(0.9); }
  to   { opacity: 1;    transform: scale(1.1); }
}

.nowrap { white-space: nowrap; }

.barge-cite {
  position: absolute;
  top: 58vh;
  left: 50%;
  width: min(40rem, calc(100% - 32px));
  margin: 0;
  transform: translateX(-50%);
  color: var(--text);
  font-size: clamp(0.8rem, 0.75rem + 0.3vw, 1rem);
  line-height: 1.4;
  text-align: center;
  text-shadow: 0 1px 6px var(--space);
  opacity: 0;
  animation: cite 8s ease-in-out calc(var(--t-barge) + 1.5s) forwards;
}

@keyframes cite {
  0%, 100% { opacity: 0; }
  15%, 85% { opacity: 1; }
}

.promise {
  position: absolute;
  top: 41%;
  left: 50%;
  z-index: 1;
  width: min(38rem, calc(100% - 32px));
  transform: translate(-50%, -50%);
  text-align: center;
  opacity: 0;
  visibility: hidden;
  animation: reveal 1.6s ease-out var(--t-promise) forwards;
}

@keyframes reveal {
  to { opacity: 1; visibility: visible; }
}

.promise blockquote { margin: 0; }

.promise blockquote p {
  margin: 0 0 0.8em;
  text-wrap: pretty;
  color: var(--blue);
  font-size: clamp(0.95rem, 0.8rem + 0.6vw, 1.35rem);
  font-weight: 500;
  line-height: 1.5;
}

.promise cite {
  display: block;
  color: var(--amber-dim);
  font-size: 0.8rem;
  font-style: normal;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.cta-lede,
.cta {
  opacity: 0;
  visibility: hidden;
  animation: reveal 2s ease var(--t-cta) forwards;
}

.cta-lede {
  margin: 1.8rem 0 0.8rem;
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
}

.cta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
}

.cta a,
.cta button {
  padding: 0.65rem 1.2rem;
  border: 1px solid rgba(200, 162, 74, 0.6);
  border-radius: 999px;
  background: rgba(3, 7, 15, 0.7);
  color: var(--text);
  font: 600 0.95rem var(--font);
  text-decoration: none;
  cursor: pointer;
}

.cta a:hover,
.cta button:hover { border-color: var(--amber); }

.cta .cta-main {
  border-color: var(--amber);
  background: var(--amber);
  color: var(--space);
}

.cta .cta-main:hover { background: #ecc76e; }

.cta :focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* Short screens (a phone held sideways): tighten the closing card so it
   clears the controls, and let the end state drop the credits and bar. */
@media (max-height: 520px) {
  .promise { top: 42%; }
  .promise blockquote p {
    margin-bottom: 0.4em;
    font-size: 0.85rem;
    line-height: 1.4;
  }
  .promise cite { font-size: 0.7rem; }
  .cta-lede { margin: 0.6rem 0 0.4rem; font-size: 0.85rem; }
  .cta { gap: 0.4rem; }
  .cta a,
  .cta button { padding: 0.4rem 0.9rem; font-size: 0.8rem; }
  body.ended .credit,
  body.ended .timeline { display: none; }
}

/* --- Begin card (browsers allow sound only after a tap) ------------------ */

.begin-card { display: none; }

body.waiting .begin-card {
  position: fixed;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
}

.begin {
  padding: 0.8rem 2.4rem;
  border: 2px solid var(--amber);
  border-radius: 999px;
  background: rgba(3, 7, 15, 0.6);
  color: var(--amber);
  font: 800 1.3rem var(--font);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.begin:hover,
.begin:focus-visible {
  background: var(--amber);
  color: var(--space);
  outline: none;
}

.begin-card .begin-lede {
  margin: 0 0 0.6rem;
  padding: 0 16px;
  color: var(--text);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  text-align: center;
}

.begin-card p {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.85rem;
  letter-spacing: 0.06em;
}

body.waiting .controls,
body.waiting .sound { display: none; }

/* --- Sound: mute button, top right; volume slider on hover --------------- */

.sound {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  right: 12px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.mute {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid rgba(200, 162, 74, 0.6);
  border-radius: 50%;
  background: rgba(3, 7, 15, 0.7);
  color: var(--amber);
  cursor: pointer;
}

.mute:hover { border-color: var(--amber); }

.mute svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mute .speaker { fill: currentColor; }
.mute .cross,
.mute.muted .waves { display: none; }
.mute.muted .cross { display: inline; }
.mute.muted { color: var(--text-dim); }

.volume {
  width: 0;
  opacity: 0;
  accent-color: var(--amber);
  transition: width 0.25s, opacity 0.25s;
}

@media (hover: hover) {
  .sound:hover .volume,
  .sound:focus-within .volume {
    width: 7rem;
    opacity: 1;
  }
}

.sound :focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

body.still .sound { display: none; }

/* --- Still reading: same text, flat and scrollable ----------------------- */

body.still { overflow: auto; }

body.still .scene {
  position: relative;
  inset: auto;
  overflow: visible;
  padding: 3rem 16px 6rem;
}

body.still .intro,
body.still .logo,
body.still .plane,
body.still .crawl {
  position: static;
  width: auto;
  max-width: 40rem;
  height: auto;
  margin: 0 auto;
  opacity: 1;
  transform: none;
  animation: none;
  -webkit-mask-image: none;
          mask-image: none;
}

body.still .intro {
  margin-bottom: 2rem;
  font-size: 1.2rem;
  text-align: center;
}

body.still .logo {
  margin-bottom: 2.5rem;
  font-size: clamp(2.6rem, 12vw, 5.5rem);
  white-space: normal;
}

body.still .crawl {
  font-size: 1.15rem;
  text-align: left;
}

body.still .scene { padding-bottom: 1rem; }

body.still .controls {
  position: static;
  padding-bottom: 2rem;
}

body.still #pause,
body.still .timeline,
body.still .ending { display: none; }

body.still .scene .stars,
body.still .clock { animation: none; transform: none; }

body.still .scene .stars { height: 100%; }

body.still .promise,
body.still .cta-lede,
body.still .cta {
  position: static;
  width: auto;
  max-width: 38rem;
  margin-left: auto;
  margin-right: auto;
  opacity: 1;
  visibility: visible;
  transform: none;
  animation: none;
}

body.still .promise { margin-top: 3.5rem; }

body.still .cta-lede { margin-top: 1.8rem; }

@media (prefers-reduced-motion: reduce) {
  .controls { opacity: 1; }
}
