/* The Deep Sky — a journey outward from Earth to the edge of the observable
   universe, in big public-domain space photographs. Self-contained dark page. */

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: #01010a;
  color: #eaf0ff;
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* deep-space gradient behind everything; JS nudges its tint per stop */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -4;
  background:
    radial-gradient(120% 80% at 50% -10%, var(--glow, rgba(40,70,140,0.25)) 0%, transparent 55%),
    #01010a;
  transition: background 0.5s linear;
}

/* generated starfield — one fixed canvas, two parallax layers drawn onto it.
   The layers wrap on the viewport height, so the field tiles forever however
   tall the page grows. (It used to be ~580 individually-animated spans, which
   cost a composited layer each; the canvas draws the same look for far less.) */
#stars {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: -3;
  pointer-events: none;
}

/* cinematic vignette that frames the view */
.vignette {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(130% 100% at 50% 50%, transparent 55%, rgba(0,0,0,0.55) 100%);
}

/* visible to screen readers only — the polite arrival announcements */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.back-link {
  position: fixed;
  top: 1rem; left: 1rem;
  z-index: 40;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  background: rgba(0,0,0,0.3);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.back-link:hover { background: rgba(0,0,0,0.5); }

/* ---- distance HUD ---- */
.hud {
  position: fixed;
  top: 0.9rem; right: 1rem;
  z-index: 40;
  text-align: right;
  text-shadow: 0 1px 8px rgba(0,0,0,0.7);
  pointer-events: none;
}
.hud-dist {
  font-family: "Fredoka", "Nunito", sans-serif;
  font-weight: 600;
  font-size: 1.7rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.hud-unit { font-size: 0.85rem; margin-left: 0.2rem; opacity: 0.85; }
.hud-place {
  margin-top: 0.2rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #cfe0ff;
}
.hud-sub { font-size: 0.68rem; letter-spacing: 0.1em; opacity: 0.55; text-transform: uppercase; }
.hud-echo { font-size: 0.66rem; letter-spacing: 0.12em; margin-top: 0.15rem; color: #8fb0ff; opacity: 0.8; min-height: 0.8rem; }

/* ---- intro ---- */
.intro {
  min-height: 100vh;
  min-height: 100svh;   /* stable on phones — doesn't jump as the URL bar hides */
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 2rem 1.5rem;
}
.intro h1 {
  margin: 0 0 0.7rem;
  font-family: "Fredoka", "Nunito", sans-serif;
  font-weight: 600;
  font-size: clamp(2.8rem, 9vw, 5rem);
  letter-spacing: -0.01em;
  background: linear-gradient(180deg, #ffffff, #9fb8ff);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 40px rgba(120,150,255,0.25);
}
.intro p {
  margin: 0 auto;
  max-width: 32rem;
  font-size: 1.15rem;
  color: #b9c6e8;
  font-weight: 600;
}
.intro .scale-note {
  margin-top: 1rem;
  max-width: 30rem;
  font-size: 0.92rem;
  font-weight: 600;
  color: #8394bd;
}
.intro .scale-note strong { color: #b9c6e8; font-weight: 700; }
.scroll-cue {
  margin-top: 2.5rem;
  font-size: 0.8rem; font-weight: 700;
  letter-spacing: 0.2em; text-transform: uppercase;
  color: #8fa3d6;
  animation: bob 1.8s ease-in-out infinite;
}
.scroll-cue span { display: block; font-size: 1.4rem; margin-top: 0.2rem; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(8px); } }

/* keyboard shortcut hint — only worth showing where there is a keyboard */
.kbd-hint { display: none; }
@media (hover: hover) and (pointer: fine) {
  .kbd-hint {
    display: block;
    margin: 2.4rem 0 0;
    font-size: 0.75rem; font-weight: 600;
    letter-spacing: 0.04em;
    color: #6b7aa4;
  }
  .kbd-hint kbd {
    font-family: inherit; font-size: 0.75rem; font-weight: 700;
    color: #a8b6dd;
    background: rgba(120,140,220,0.14);
    border: 1px solid rgba(140,160,230,0.3);
    border-radius: 5px;
    padding: 0.05rem 0.35rem;
  }
}

/* empty travel between stops — height is set inline, ∝ orders of magnitude */
.void { width: 100%; pointer-events: none; }

/* the few voids long enough to carry a line of text. They sit at even
   intervals down the gap and stay faint. */
.void[data-vast] { position: relative; }
.whisper {
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(30rem, 84vw);
  text-align: center;
  font-size: clamp(0.9rem, 2.4vw, 1.05rem);
  font-style: italic;
  line-height: 1.5;
  color: #7b88ad;
  opacity: 0;
  transition: opacity 1.6s ease;
}
.whisper.in { opacity: 0.55; }

/* ---- a stop on the journey ---- */
.stop {
  min-height: 80vh;
  min-height: 80svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.4rem;
  padding: 6vh 1.2rem 4.75rem;   /* bottom room so the control bar never sits on the caption */
  position: relative;
}
/* the image frame doubles as a button — click to enlarge */
.frame {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: zoom-in;
  opacity: 0;
  transform: scale(0.94);
  transition: opacity 1s ease, transform 1s ease;
}
.frame:focus-visible { outline: 2px solid rgba(160,190,255,0.9); outline-offset: 8px; border-radius: 14px; }
.frame:hover img { box-shadow: 0 22px 80px rgba(0,0,0,0.75), 0 0 0 1px rgba(180,200,255,0.15); }
/* little "enlarge" affordance, shown on hover/focus */
.zoom-hint {
  position: absolute;
  bottom: 0.7rem; right: 0.7rem;
  font-size: 1.5rem; line-height: 1;
  color: #fff;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  text-shadow: 0 2px 10px rgba(0,0,0,0.9);
  pointer-events: none;
}
.frame:hover .zoom-hint, .frame:focus-visible .zoom-hint { opacity: 0.9; transform: none; }
.stop.in .frame { opacity: 1; transform: none; }
/* the colored halo behind each image */
.frame::before {
  content: "";
  position: absolute;
  inset: -14%;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent, #4a7bd6) 0%, transparent 68%);
  opacity: 0.5;
  filter: blur(30px);
  z-index: -1;
}
/* Reserving the exact box before the picture loads is what keeps the measured
   stop centres — and so the rail and the distance readout — honest while lazy
   images stream in. It needs a *definite* width: `width:auto` leaves an
   unloaded image no size at all, and `max-height` cannot reserve anything.
   So each image gets its own aspect ratio inline as --ar, and the width is
   whichever of the three limits binds first. Height then follows from the
   width/height attributes, and nothing moves when the bytes arrive. */
/* The picture has to leave room for its caption and the floating control bar,
   or the last line of a long fact ends up underneath them. Subtracting a fixed
   slab from the viewport height does that smoothly at every window size,
   instead of lurching at a couple of breakpoints.
   KEEP IN SYNC with MAXH / MAXH_SHORT in deepspace.js, which describe the same
   two rules to the browser as `sizes`. */
:root { --maxh: min(66vh, calc(100vh - 400px)); }
.frame picture { display: block; line-height: 0; }
.frame img {
  display: block;
  width: min(92vw, 760px, calc(var(--maxh, 66vh) * var(--ar, 1)));
  height: auto;
  border-radius: 12px;
  box-shadow: 0 18px 70px rgba(0,0,0,0.7);
}

.caption {
  max-width: 40rem;
  text-align: center;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.9s ease 0.2s, transform 0.9s ease 0.2s;
}
.stop.in .caption { opacity: 1; transform: none; }
.caption .place {
  display: block;
  margin: 0;
  font-family: "Fredoka", "Nunito", sans-serif;
  font-weight: 600;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  color: #fff;
}
.caption .dist {
  display: inline-block;
  margin: 0.35rem 0 0.7rem;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent, #7fb0ff);
  filter: brightness(1.35);
}
.caption .echo {
  display: block;
  margin: -0.2rem 0 0.85rem;
  font-size: 0.82rem;
  font-style: italic;
  color: #92a1c8;
}
.caption .fact {
  margin: 0;
  font-size: 1.12rem;
  line-height: 1.55;
  color: #c8d4ee;
}

/* ---- finale ---- */
.edge {
  min-height: 100vh;
  min-height: 100svh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 3rem 1.5rem 2rem;
}
.edge h2 {
  margin: 0 0 0.4rem;
  font-family: "Fredoka", "Nunito", sans-serif;
  font-weight: 600;
  font-size: clamp(1.9rem, 6vw, 3rem);
  color: #eef3ff;
}
.edge .far {
  font-size: 0.8rem; font-weight: 800;
  letter-spacing: 0.16em; text-transform: uppercase;
  color: #9b8fe0;
}
.edge p.note {
  margin: 1.3rem auto 0;
  max-width: 30rem;
  color: #aeb9db;
  font-style: italic;
  line-height: 1.6;
}
/* the footnote about light-travel time vs. where things actually are now */
.edge p.note.fine {
  margin-top: 1.1rem;
  max-width: 34rem;
  font-size: 0.88rem;
  font-style: normal;
  color: #8a95b8;
}
.home-btn {
  margin-top: 2.2rem;
  font: inherit; font-weight: 700; cursor: pointer;
  color: #eaf0ff;
  background: rgba(120,150,240,0.16);
  border: 1.5px solid rgba(160,180,255,0.4);
  border-radius: 999px;
  padding: 0.7rem 1.5rem;
  transition: background 0.15s ease, transform 0.15s ease;
}
.home-btn:hover { background: rgba(120,150,240,0.3); transform: translateY(-2px); }

.credits {
  margin: 2.2rem auto 0;
  max-width: 32rem;
  text-align: left;
  background: rgba(14,18,40,0.6);
  border: 1px solid rgba(120,140,220,0.2);
  border-radius: 12px;
  padding: 0.4rem 1rem;
}
.credits summary {
  cursor: pointer; text-align: center;
  font-weight: 700; font-size: 0.82rem;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: #9fb0e0; padding: 0.5rem 0;
}
.credits ul { margin: 0.5rem 0 0; padding: 0 0 0 1.1rem; }
.credits li { font-size: 0.82rem; color: #a6b3d6; margin-bottom: 0.3rem; line-height: 1.4; }
.credits a { color: #86b0ff; text-decoration: none; font-weight: 600; }
.credits a:hover { text-decoration: underline; }
.credits-note { margin: 0.7rem 0 0.3rem; font-size: 0.76rem; color: #7f8cb0; font-style: italic; }

footer {
  text-align: center;
  padding: 2rem 1rem 3rem;
  color: #6a769c;
  font-size: 0.8rem;
}
footer p { margin: 0 0 0.6rem; }

.hit-counter { display: inline-flex; align-items: center; gap: 0.5rem; }
.hit-counter-label { font-weight: 700; }
.hit-digits { display: inline-flex; gap: 2px; }
.hit-digit {
  font-family: "Courier New", Courier, monospace;
  font-weight: 700; font-size: 0.95rem; line-height: 1;
  color: #39ff14; background: #0d0d0d; padding: 3px 5px; border-radius: 3px;
  box-shadow: inset 0 0 4px rgba(0,0,0,0.9), 0 0 2px rgba(57,255,20,0.5);
  text-shadow: 0 0 5px rgba(57,255,20,0.85);
}

/* ---- control bar (sound + auto-travel) ---- */
.controls {
  position: fixed;
  left: 50%; bottom: 1.1rem;
  transform: translateX(-50%);
  z-index: 60;
  display: flex; gap: 0.4rem;
  padding: 0.32rem;
  background: rgba(10,14,32,0.55);
  border: 1px solid rgba(140,160,230,0.22);
  border-radius: 999px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.controls.hide { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(12px); }
/* soft fade behind the bar so a caption line never clashes with it */
.controls::before {
  content: "";
  position: absolute; left: 50%; bottom: -0.6rem; transform: translateX(-50%);
  width: 140vw; height: 220%; z-index: -1; pointer-events: none;
  background: radial-gradient(58% 100% at 50% 100%, rgba(1,1,10,0.6), transparent 72%);
}
.ctrl {
  display: inline-flex; align-items: center; gap: 0.45rem;
  font: inherit; font-weight: 700; font-size: 0.82rem;
  color: #dbe4ff; cursor: pointer;
  background: transparent; border: 0;
  padding: 0.5rem 0.95rem; border-radius: 999px;
  transition: background 0.15s ease, color 0.15s ease;
}
.ctrl .ic { font-size: 0.95rem; line-height: 1; }
.ctrl:hover { background: rgba(120,150,240,0.18); }
.ctrl:focus-visible { outline: 2px solid rgba(160,190,255,0.9); outline-offset: 2px; }
.ctrl.on { background: rgba(120,150,240,0.34); color: #fff; }
#soundBtn.on .ic { animation: soundpulse 1.6s ease-in-out infinite; }
@keyframes soundpulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ---- depth rail (right edge) ---- */
.rail {
  position: fixed;
  top: 50%; right: 0.6rem;
  transform: translateY(-50%);
  height: 72vh; width: 24px;
  z-index: 40;
  pointer-events: none;
}
.rail::before {
  content: "";
  position: absolute; top: 0; bottom: 0; left: 50%;
  width: 2px; margin-left: -1px;
  background: linear-gradient(to bottom, rgba(150,170,230,0.04), rgba(150,170,230,0.26) 20%, rgba(150,170,230,0.26) 80%, rgba(150,170,230,0.04));
  border-radius: 2px;
}
.rail::after {
  content: "";
  position: absolute; left: 50%; top: var(--prog, 0%);
  width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px;
  border-radius: 50%; background: #eaf2ff;
  box-shadow: 0 0 10px rgba(180,205,255,0.9);
}
/* real anchors, so a stop can be linked, opened in a new tab, or copied */
.rail-dot {
  position: absolute; left: 50%;
  display: block;
  width: 7px; height: 7px; margin: -3.5px 0 0 -3.5px;
  padding: 0; border: 0; border-radius: 50%;
  background: rgba(180,195,240,0.35);
  text-decoration: none;
  cursor: pointer; pointer-events: auto;
  transition: background 0.2s ease, transform 0.2s ease;
}
.rail-dot:hover { background: rgba(215,228,255,0.95); transform: scale(1.5); }
.rail-dot.on { background: #cfe0ff; transform: scale(1.4); box-shadow: 0 0 8px rgba(180,205,255,0.85); }
.rail-dot:focus-visible { outline: 2px solid rgba(160,190,255,0.9); outline-offset: 3px; }
.rail-tip {
  position: absolute; right: 160%; top: 50%; transform: translateY(-50%);
  white-space: nowrap;
  font-size: 0.7rem; font-weight: 700;
  color: #dbe4ff; background: rgba(10,14,32,0.9);
  padding: 0.2rem 0.5rem; border-radius: 6px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.15s ease;
}
.rail-dot:hover .rail-tip, .rail-dot:focus-visible .rail-tip { opacity: 1; }

/* thin top progress bar (mainly for phones, where the rail is hidden) */
body::after {
  content: "";
  position: fixed; top: 0; left: 0; height: 3px;
  width: var(--prog, 0%); z-index: 50;
  background: linear-gradient(90deg, #6f86c9, #b9c6e8);
  box-shadow: 0 0 8px rgba(150,180,255,0.6);
  opacity: 0;
  transition: width 0.1s linear;
}

/* ---- lightbox ---- */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  display: none;
  align-items: center; justify-content: center;
  padding: 4vh 4vw;
  background: rgba(2,3,10,0.93);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.lightbox.show { display: flex; animation: lbfade 0.25s ease; }
@keyframes lbfade { from { opacity: 0; } to { opacity: 1; } }
body.lb-open { overflow: hidden; }
/* the figure sizes to the image; caption overlays the bottom so it never
   steals height from the image — the image fills up to 90vh / 94vw. */
.lb-fig { position: relative; margin: 0; display: flex; align-items: center; justify-content: center; }
.lb-fig img {
  max-width: 94vw; max-height: 90vh; width: auto; height: auto; object-fit: contain;
  border-radius: 10px; box-shadow: 0 24px 90px rgba(0,0,0,0.85);
}
.lb-fig img.swap { animation: lbimg 0.35s ease; }
@keyframes lbimg { from { opacity: 0.2; transform: scale(0.985); } to { opacity: 1; transform: none; } }
.lb-cap {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 3.2rem 1.4rem 1.1rem;
  text-align: center;
  border-radius: 0 0 10px 10px;
  background: linear-gradient(to top, rgba(2,3,10,0.92), rgba(2,3,10,0.55) 45%, transparent);
  text-shadow: 0 1px 8px rgba(0,0,0,0.8);
}
.lb-place { display: block; font-family: "Fredoka","Nunito",sans-serif; font-weight: 600; font-size: 1.55rem; color: #fff; }
.lb-dist { display: inline-block; margin: 0.2rem 0 0.4rem; font-size: 0.75rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: #bcd4ff; }
.lb-fact { margin: 0.2rem auto 0; max-width: 46rem; color: #dbe4f5; line-height: 1.5; }
.lb-echo { margin: 0.4rem 0 0; font-style: italic; font-size: 0.85rem; color: #aab6d6; }
.lb-credit { margin: 0.6rem 0 0; font-size: 0.72rem; color: #94a1c4; }
.lb-credit a { color: #86b0ff; text-decoration: none; }
.lb-credit a:hover { text-decoration: underline; }
/* off-screen warm-up slots for the neighbouring pictures */
.lb-preload {
  position: absolute;
  left: 0; bottom: 0;
  width: 1px; height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}
.lb-close, .lb-nav {
  position: absolute; z-index: 2;
  background: rgba(20,26,50,0.6); color: #eaf0ff;
  border: 1px solid rgba(150,170,230,0.3);
  cursor: pointer; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s ease, transform 0.15s ease;
}
.lb-close { top: 1rem; right: 1rem; width: 44px; height: 44px; font-size: 1.7rem; }
.lb-nav { top: 50%; transform: translateY(-50%); width: 48px; height: 48px; font-size: 2rem; }
.lb-prev { left: 1rem; } .lb-next { right: 1rem; }
.lb-close:hover, .lb-nav:hover { background: rgba(60,80,150,0.75); }
.lb-nav:hover { transform: translateY(-50%) scale(1.08); }
.lb-close:focus-visible, .lb-nav:focus-visible { outline: 2px solid rgba(160,190,255,0.9); outline-offset: 2px; }

/* ---- auto-travel state ---- */
body.cruising .controls { opacity: 0.65; }
body.cruising .controls:hover { opacity: 1; }

@media (max-width: 760px) {
  .rail { display: none; }
  body::after { opacity: 1; }
}
@media (max-width: 620px) {
  .hud-dist { font-size: 1.35rem; }
  .caption .fact { font-size: 1rem; }
  .controls { bottom: 0.8rem; }
  .ctrl { padding: 0.5rem 0.75rem; font-size: 0.78rem; }
  .lb-nav { width: 40px; height: 40px; font-size: 1.6rem; }
  .lb-fig img { max-height: 88vh; max-width: 96vw; }
  .lb-cap { padding: 2.6rem 1rem 0.9rem; }
  .lb-place { font-size: 1.3rem; }
  .lb-fact { font-size: 0.92rem; }
}
/* short viewports: the caption itself has to give a little too */
@media (max-height: 680px) {
  :root { --maxh: min(50vh, calc(100vh - 330px)); }
  .caption .fact { font-size: 1rem; }
  .caption .echo { margin-bottom: 0.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .scroll-cue { animation: none !important; }
  .frame, .caption { transition: opacity 0.3s ease !important; }
  .frame, .caption { transform: none !important; }
  .whisper { transition: opacity 0.3s ease !important; }
  .lightbox.show, .lb-fig img.swap, #soundBtn.on .ic { animation: none !important; }
}

/* ---- the page without JavaScript ---- */
.noscript {
  max-width: 34rem;
  margin: 18vh auto 0;
  padding: 2rem 1.5rem;
  text-align: center;
}
.noscript h1 {
  margin: 0 0 0.8rem;
  font-family: "Fredoka", "Nunito", sans-serif;
  font-weight: 600;
  font-size: clamp(2.2rem, 7vw, 3.4rem);
  color: #eef3ff;
}
.noscript p { color: #b9c6e8; line-height: 1.6; }
.noscript a { color: #86b0ff; font-weight: 700; }
