/* ============================================================
   THE LIFE & DEATH OF A STAR — stylesheet
   ============================================================ */

:root {
  --bg: #05060f;
  --bg-2: #0a0d1f;
  --ink: #eaf0ff;
  --muted: #9aa4c8;
  --accent: #7c5cff;
  --maxw: 1180px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Space Grotesk', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
  line-height: 1.7;
}

h1, h2, h3, .stage-number, .eyebrow { font-family: 'Orbitron', sans-serif; }

/* ---------- Starfield background ---------- */
#starfield {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  background: radial-gradient(ellipse at 50% 0%, #0d1233 0%, var(--bg) 55%);
}

/* ---------- Scroll progress ---------- */
#progress-bar {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0%;
  z-index: 100;
  background: linear-gradient(90deg, #7c5cff, #ffd84d, #ff3d77, #5ce1ff);
  box-shadow: 0 0 12px rgba(255,255,255,.4);
  transition: width .1s linear;
}

main, .hero, footer { position: relative; z-index: 2; }

/* ============================================================
   HERO
   ============================================================ */
.hero {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  position: relative;
}

.hero-star {
  position: relative;
  width: 220px; height: 220px;
  margin-bottom: 2.5rem;
}
.hero-star .core,
.hero-star .glow,
.hero-star .corona {
  position: absolute; inset: 0; margin: auto; border-radius: 50%;
}
.hero-star .core {
  width: 110px; height: 110px;
  background: radial-gradient(circle at 35% 35%, #fff 0%, #ffe9a8 35%, #ffb347 70%, #ff7b2e 100%);
  box-shadow: 0 0 60px 20px rgba(255,180,80,.7), 0 0 120px 50px rgba(255,120,40,.35);
  animation: pulse 4s ease-in-out infinite;
}
.hero-star .glow {
  width: 220px; height: 220px;
  background: radial-gradient(circle, rgba(255,180,80,.25) 0%, transparent 65%);
  animation: pulse 4s ease-in-out infinite reverse;
}
.hero-star .corona {
  width: 180px; height: 180px;
  border: 2px solid rgba(255,200,120,.18);
  animation: spin 22s linear infinite;
}
.hero-star .corona::after {
  content: ''; position: absolute; inset: -18px;
  border-radius: 50%;
  border: 1px dashed rgba(255,200,120,.12);
}

@keyframes pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.08); opacity: .92; } }
@keyframes spin { to { transform: rotate(360deg); } }

.hero-content { max-width: 760px; }
.eyebrow {
  letter-spacing: .35em;
  text-transform: uppercase;
  font-size: .72rem;
  color: var(--accent);
  margin-bottom: 1.2rem;
}
.hero h1 {
  font-size: clamp(2.6rem, 8vw, 5.4rem);
  line-height: 1.02;
  font-weight: 900;
  letter-spacing: 2px;
}
.hero h1 span {
  background: linear-gradient(90deg, #ffd84d, #ff7b2e, #ff3d77);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.subtitle {
  color: var(--muted);
  font-size: clamp(1rem, 2.2vw, 1.25rem);
  margin: 1.6rem auto 2.4rem;
  max-width: 620px;
}
.scroll-cue {
  display: inline-flex; flex-direction: column; align-items: center; gap: .6rem;
  color: var(--ink); text-decoration: none;
  border: 1px solid rgba(255,255,255,.18);
  padding: .9rem 1.8rem; border-radius: 100px;
  font-size: .95rem; letter-spacing: .04em;
  background: rgba(255,255,255,.03);
  backdrop-filter: blur(4px);
  transition: .3s;
}
.scroll-cue:hover { background: rgba(255,255,255,.1); transform: translateY(-3px); }
.scroll-cue .arrow { animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(6px); } }

/* ============================================================
   TIMELINE NAV
   ============================================================ */
#timeline-nav {
  position: fixed;
  right: 22px; top: 50%;
  transform: translateY(-50%);
  z-index: 50;
}
#timeline-nav ul { list-style: none; display: flex; flex-direction: column; gap: 14px; }
#timeline-nav a {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 50%;
  font-family: 'Orbitron', sans-serif;
  font-size: .8rem;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(10,13,31,.6);
  backdrop-filter: blur(4px);
  position: relative;
  transition: .3s;
}
#timeline-nav a::before {
  content: attr(data-label);
  position: absolute; right: 46px; top: 50%;
  transform: translateY(-50%) translateX(8px);
  white-space: nowrap;
  font-family: 'Space Grotesk', sans-serif;
  font-size: .78rem;
  color: var(--ink);
  background: rgba(10,13,31,.9);
  padding: 4px 10px; border-radius: 6px;
  opacity: 0; pointer-events: none;
  transition: .25s;
  border: 1px solid rgba(255,255,255,.1);
}
#timeline-nav a:hover, #timeline-nav a.active {
  color: #fff; border-color: var(--accent);
  box-shadow: 0 0 14px rgba(124,92,255,.6);
  background: var(--accent);
}
#timeline-nav a:hover::before { opacity: 1; transform: translateY(-50%) translateX(0); }

/* ============================================================
   STAGES (generic layout)
   ============================================================ */
.stage {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 9vh 1.5rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3.5rem;
  align-items: center;
  min-height: 92vh;
}
.stage:nth-child(even) .stage-visual { order: 2; }

.stage-number {
  display: inline-block;
  font-size: .8rem; letter-spacing: .3em;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 1rem;
}
.stage h2 {
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 700;
  margin-bottom: 1rem;
  line-height: 1.05;
}
.stage .lead {
  font-size: 1.25rem;
  color: var(--accent);
  margin-bottom: 1.3rem;
  font-weight: 500;
}
.stage p { color: #c4cce8; margin-bottom: 1rem; }
.stage strong { color: #fff; }
.stage em { color: var(--accent); font-style: normal; }

.facts {
  list-style: none;
  margin-top: 1.8rem;
  border-top: 1px solid rgba(255,255,255,.1);
}
.facts li {
  display: flex; justify-content: space-between;
  padding: .85rem 0;
  border-bottom: 1px solid rgba(255,255,255,.08);
  font-size: .95rem;
}
.facts .k { color: var(--muted); letter-spacing: .03em; }
.facts .v { color: #fff; font-weight: 500; text-align: right; }

/* reveal on scroll */
.stage-text, .stage-visual, .path, .remnant, .outro > * {
  opacity: 0; transform: translateY(40px);
  transition: opacity .9s ease, transform .9s ease;
}
.reveal .stage-text, .reveal .stage-visual,
.reveal .path, .reveal .remnant, .reveal.outro > * {
  opacity: 1; transform: none;
}
.reveal .path:nth-child(2) { transition-delay: .15s; }
.reveal .remnant:nth-child(2) { transition-delay: .12s; }
.reveal .remnant:nth-child(3) { transition-delay: .24s; }

/* ============================================================
   VISUALS
   ============================================================ */
.viz {
  position: relative;
  width: 100%;
  aspect-ratio: 1/1;
  max-width: 440px;
  margin: 0 auto;
  display: grid; place-items: center;
}

/* --- Stage 1: Nebula --- */
.nebula-viz { filter: blur(.2px); }
.nebula-viz .cloud {
  position: absolute; border-radius: 50%;
  filter: blur(34px); mix-blend-mode: screen;
  animation: drift 14s ease-in-out infinite;
}
.nebula-viz .c1 { width: 60%; height: 60%; background: #7c5cff; top: 8%; left: 6%; }
.nebula-viz .c2 { width: 55%; height: 55%; background: #ff5a9e; bottom: 6%; right: 4%; animation-delay: -4s; }
.nebula-viz .c3 { width: 45%; height: 45%; background: #3da9ff; top: 30%; left: 35%; animation-delay: -8s; }
.nebula-viz .dust {
  position: absolute; inset: 0; border-radius: 50%;
  background:
    radial-gradient(2px 2px at 20% 30%, #fff, transparent),
    radial-gradient(1px 1px at 70% 60%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 40% 80%, #fff, transparent),
    radial-gradient(1px 1px at 85% 25%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 55% 15%, #fff, transparent);
  opacity: .8;
}
@keyframes drift {
  0%,100% { transform: translate(0,0) scale(1); }
  50% { transform: translate(8%, -6%) scale(1.12); }
}

/* --- Stage 2: Protostar --- */
.protostar-viz .accretion {
  position: absolute; width: 90%; height: 90%; border-radius: 50%;
  background: conic-gradient(from 0deg, transparent, rgba(255,155,61,.25), transparent 60%);
  animation: spin 6s linear infinite;
  filter: blur(6px);
}
.protostar-viz .proto-core {
  width: 90px; height: 90px; border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, #fff5e0, #ff9b3d 55%, #b5400d 100%);
  box-shadow: 0 0 50px 12px rgba(255,120,40,.6);
  animation: pulse 2.4s ease-in-out infinite;
  z-index: 2;
}
.protostar-viz .infall {
  position: absolute; width: 8px; height: 8px; border-radius: 50%;
  background: #ffd9a0; box-shadow: 0 0 10px #ffae5c;
}
.protostar-viz .p1 { animation: infall1 3s linear infinite; }
.protostar-viz .p2 { animation: infall2 3.6s linear infinite .4s; }
.protostar-viz .p3 { animation: infall3 3.2s linear infinite .9s; }
.protostar-viz .p4 { animation: infall4 4s linear infinite 1.3s; }
@keyframes infall1 { 0% { transform: translate(-160px,-120px); opacity:0;} 20%{opacity:1;} 100% { transform: translate(0,0); opacity:0; } }
@keyframes infall2 { 0% { transform: translate(150px,-130px); opacity:0;} 20%{opacity:1;} 100% { transform: translate(0,0); opacity:0; } }
@keyframes infall3 { 0% { transform: translate(170px,110px); opacity:0;} 20%{opacity:1;} 100% { transform: translate(0,0); opacity:0; } }
@keyframes infall4 { 0% { transform: translate(-150px,140px); opacity:0;} 20%{opacity:1;} 100% { transform: translate(0,0); opacity:0; } }

/* --- Stage 3: Main Sequence --- */
.mainseq-viz .ms-star {
  position: relative; width: 200px; height: 200px; border-radius: 50%;
  z-index: 2;
}
.mainseq-viz .ms-surface {
  position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle at 38% 38%, #fffce0 0%, #ffe55c 40%, #ffb330 75%, #ff8a1e 100%);
  box-shadow: 0 0 70px 24px rgba(255,210,80,.55), inset -18px -18px 40px rgba(180,70,0,.5);
  animation: pulse 3.5s ease-in-out infinite;
}
.mainseq-viz .ms-core {
  position: absolute; inset: 0; margin: auto; width: 70px; height: 70px; border-radius: 50%;
  background: radial-gradient(circle, #fff, rgba(255,255,255,0) 70%);
  animation: pulse 1.6s ease-in-out infinite;
  z-index: 3;
}
.mainseq-viz .flare {
  position: absolute; border-radius: 50%;
  border: 2px solid rgba(255,220,120,.5);
  inset: 0;
  animation: flareOut 3s ease-out infinite;
}
.mainseq-viz .f2 { animation-delay: 1s; }
.mainseq-viz .f3 { animation-delay: 2s; }
@keyframes flareOut { 0% { transform: scale(.6); opacity: .8; } 100% { transform: scale(1.5); opacity: 0; } }
.mainseq-viz .balance {
  position: absolute; font-family: 'Orbitron'; font-size: .7rem; letter-spacing: .15em;
  color: var(--muted);
}
.mainseq-viz .left { left: 0; }
.mainseq-viz .right { right: 0; }

/* --- Stage 4: Red Giant --- */
.giant-viz .giant-body {
  width: 92%; height: 92%; border-radius: 50%;
  background: radial-gradient(circle at 40% 38%, #ffb37a 0%, #ff6a4d 45%, #c4261f 80%, #7a1410 100%);
  box-shadow: 0 0 90px 30px rgba(255,80,50,.45), inset -30px -30px 70px rgba(90,10,10,.6);
  animation: giantPulse 6s ease-in-out infinite;
}
@keyframes giantPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.05); } }
.giant-viz .old-sun-ref {
  position: absolute; width: 16px; height: 16px; border-radius: 50%;
  background: #ffd84d; box-shadow: 0 0 8px #ffd84d;
  bottom: 8%; right: 10%;
}
.giant-viz .old-sun-ref::after {
  content: 'today\'s Sun, to scale';
  position: absolute; left: 22px; top: 0;
  font-family: 'Space Grotesk'; font-size: .65rem; color: var(--muted); white-space: nowrap;
}

/* --- Stage 5: Fork --- */
.stage.fork {
  grid-template-columns: 1fr;
  text-align: center;
}
.stage-text.full { max-width: 760px; margin: 0 auto; }
.fork-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 2rem;
  margin-top: 2.5rem; text-align: left;
}
.path {
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 18px;
  padding: 2rem;
}
.path .viz { max-width: 200px; margin-bottom: 1.2rem; }
.path h3 { font-size: 1.5rem; margin-bottom: .3rem; }
.path-sub { color: var(--accent); font-size: .9rem; margin-bottom: 1rem !important; }

.dwarf-viz .pn-shell {
  position: absolute; width: 100%; height: 100%; border-radius: 50%;
  background: radial-gradient(circle, transparent 30%, rgba(92,225,255,.3) 45%, rgba(124,92,255,.15) 60%, transparent 72%);
  animation: pnExpand 6s ease-in-out infinite;
}
@keyframes pnExpand { 0%,100% { transform: scale(.85); opacity: .7; } 50% { transform: scale(1.05); opacity: 1; } }
.dwarf-viz .white-dwarf {
  width: 36px; height: 36px; border-radius: 50%;
  background: radial-gradient(circle, #fff, #cfe8ff 60%, #8ab4ff);
  box-shadow: 0 0 30px 8px rgba(180,220,255,.8);
  z-index: 2;
}

.supernova-viz .sn-core {
  width: 30px; height: 30px; border-radius: 50%;
  background: radial-gradient(circle, #fff, #ffd84d);
  box-shadow: 0 0 40px 12px rgba(255,220,80,.8);
  z-index: 3;
}
.supernova-viz .sn-flash {
  position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.9) 0%, rgba(255,90,120,.4) 30%, transparent 60%);
  animation: snFlash 4s ease-in-out infinite;
}
@keyframes snFlash { 0%,100% { transform: scale(.4); opacity: 0; } 15% { opacity: 1; } 60% { transform: scale(1.3); opacity: 0; } }
.supernova-viz .sn-ring {
  position: absolute; width: 60px; height: 60px; border-radius: 50%;
  border: 3px solid rgba(255,90,120,.7);
  animation: snRing 4s ease-out infinite;
}
@keyframes snRing { 0% { transform: scale(.3); opacity: 1; } 100% { transform: scale(2.4); opacity: 0; } }

#detonate {
  margin-top: 2.5rem;
  font-family: 'Orbitron', sans-serif;
  font-size: 1rem;
  padding: 1rem 2.4rem;
  color: #fff;
  background: linear-gradient(90deg, #ff3d77, #ff9b3d);
  border: none; border-radius: 100px;
  cursor: pointer;
  letter-spacing: .04em;
  box-shadow: 0 8px 30px rgba(255,61,119,.4);
  transition: transform .2s, box-shadow .2s;
}
#detonate:hover { transform: translateY(-3px) scale(1.03); box-shadow: 0 12px 40px rgba(255,61,119,.6); }
#detonate:active { transform: scale(.97); }

/* fullscreen supernova flash overlay */
#flash-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: radial-gradient(circle, #fff 0%, #ffd84d 20%, #ff3d77 45%, transparent 70%);
  opacity: 0; pointer-events: none;
}
#flash-overlay.boom { animation: bigBoom 1.8s ease-out forwards; }
@keyframes bigBoom {
  0% { opacity: 0; transform: scale(.2); }
  12% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(2.6); }
}

/* --- Stage 6: Remnants --- */
.remnant-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.6rem;
  margin-top: 2.5rem;
}
.remnant {
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 18px;
  padding: 2rem 1.6rem;
  text-align: center;
  transition: transform .3s, border-color .3s;
}
.remnant:hover { transform: translateY(-6px); border-color: rgba(92,225,255,.4); }
.r-viz {
  width: 90px; height: 90px; margin: 0 auto 1.3rem;
  border-radius: 50%; position: relative;
  display: grid; place-items: center;
}
.white-dwarf-r {
  background: radial-gradient(circle at 40% 40%, #fff, #bfe0ff 60%, #6f9fff);
  box-shadow: 0 0 30px 6px rgba(160,200,255,.7);
}
.neutron-r {
  background: radial-gradient(circle, #eaf6ff, #6cc8ff 70%);
  box-shadow: 0 0 26px 6px rgba(108,200,255,.7);
}
.neutron-r .spin {
  position: absolute; inset: -10px; border-radius: 50%;
  background: conic-gradient(from 0deg, transparent, rgba(180,240,255,.9), transparent 25%);
  animation: spin 1.2s linear infinite;
}
.blackhole-r { background: #000; box-shadow: inset 0 0 14px rgba(255,255,255,.15); }
.blackhole-r .hole {
  width: 44px; height: 44px; border-radius: 50%; background: #000;
  box-shadow: 0 0 0 3px rgba(0,0,0,.9), 0 0 22px 4px rgba(120,90,255,.5);
  z-index: 2;
}
.blackhole-r .disk {
  position: absolute; inset: -6px; border-radius: 50%;
  background: conic-gradient(from 0deg, #ff9b3d, #ffd84d, #7c5cff, #ff9b3d);
  animation: spin 3s linear infinite;
  -webkit-mask: radial-gradient(circle, transparent 40%, #000 42%, #000 60%, transparent 62%);
          mask: radial-gradient(circle, transparent 40%, #000 42%, #000 60%, transparent 62%);
}
.remnant h3 { font-size: 1.3rem; margin-bottom: .6rem; }
.remnant p { font-size: .92rem; color: #b6c0e0; }

/* ============================================================
   OUTRO
   ============================================================ */
.outro {
  max-width: 760px; margin: 0 auto;
  padding: 12vh 1.5rem 8vh;
  text-align: center;
}
.recycle-ring {
  width: 120px; height: 120px; margin: 0 auto 2rem;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 2.6rem;
  border: 2px dashed rgba(124,92,255,.5);
  animation: spin 30s linear infinite;
}
.recycle-ring span { animation: spin 30s linear infinite reverse; }
.outro h2 { font-size: clamp(1.8rem,5vw,2.8rem); margin-bottom: 1.2rem; }
.outro p { color: #c4cce8; margin-bottom: 1rem; }
.carl {
  margin-top: 2.4rem !important;
  font-style: italic; font-size: 1.2rem; color: var(--ink);
}
.carl span { display: block; margin-top: .6rem; color: var(--accent); font-style: normal; font-size: .95rem; }
.restart {
  display: inline-block; margin-top: 2.6rem;
  color: var(--ink); text-decoration: none;
  border: 1px solid rgba(255,255,255,.2);
  padding: .8rem 1.8rem; border-radius: 100px;
  transition: .3s;
}
.restart:hover { background: rgba(255,255,255,.08); transform: translateY(-3px); }

footer {
  text-align: center;
  padding: 2.6rem 1.5rem;
  color: var(--muted);
  font-size: .85rem;
  border-top: 1px solid rgba(255,255,255,.08);
}
footer .powered-by { margin-top: .6rem; font-size: .9rem; }
footer .powered-by a {
  color: var(--ink);
  text-decoration: none;
  font-weight: 500;
  background: linear-gradient(90deg, #ffd84d, #ff7b2e, #ff3d77);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  transition: opacity .25s;
}
footer .powered-by a:hover { opacity: .8; text-decoration: underline; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 860px) {
  .stage { grid-template-columns: 1fr; gap: 2.5rem; padding: 7vh 1.4rem; min-height: auto; }
  .stage:nth-child(even) .stage-visual { order: 0; }
  .stage-visual { order: 0; }
  .fork-grid { grid-template-columns: 1fr; }
  .remnant-grid { grid-template-columns: 1fr; }
  #timeline-nav { right: 10px; }
  #timeline-nav a::before { display: none; }
  .viz { max-width: 300px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
  html { scroll-behavior: auto; }
}
