/* =============================================================================
   The Living Planet — interface (v2: light, playful, cartoon)
   Frosted white "widget" cards floating over a per-era colour gradient.
   Type: system SF Pro (-apple-system) with Inter as the cross-platform fallback.
   ========================================================================== */

:root {
  --accent: #ff7a3a;          /* per-era, set by JS */
  --bg1: #3a1410;             /* per-era gradient top */
  --bg2: #120406;             /* per-era gradient bottom */

  --ink: #19212e;
  --ink-dim: #5b6679;
  --ink-faint: #8a93a4;
  --card: rgba(255, 255, 255, 0.82);
  --card-2: rgba(255, 255, 255, 0.7);
  --hair: rgba(20, 30, 55, 0.08);
  --danger: #ff4d4d;

  --r-lg: 24px;
  --r-md: 16px;
  --r-sm: 11px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --shadow: 0 22px 60px rgba(15, 25, 55, 0.22);
  --shadow-sm: 0 8px 24px rgba(15, 25, 55, 0.14);

  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
          "Inter", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Roboto Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  font-family: var(--sans);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
  overflow: hidden;
}
body {
  position: fixed; inset: 0;
  background: linear-gradient(165deg, var(--bg1), var(--bg2));
  transition: background 1.5s var(--ease);
}
/* airy light wash + playful soft glow that picks up the era accent */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(70% 55% at 50% 16%, rgba(255,255,255,0.30), transparent 70%),
    radial-gradient(60% 60% at 82% 78%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%);
  transition: background 1.5s var(--ease);
}

#scene {
  position: fixed; inset: 0; width: 100%; height: 100%;
  display: block; z-index: 1; touch-action: none;
}

button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 3px; border-radius: 8px; }
.hidden { display: none !important; }

/* generic frosted widget */
.widget {
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.7);
  box-shadow: var(--shadow-sm);
  border-radius: var(--r-md);
  backdrop-filter: blur(20px) saturate(1.3);
  -webkit-backdrop-filter: blur(20px) saturate(1.3);
}

/* --- masthead ------------------------------------------------------------- */
.masthead {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; pointer-events: none;
}
.masthead > * { pointer-events: auto; }
.brand {
  display: flex; align-items: center; gap: 11px;
  background: var(--card); border: 1px solid rgba(255,255,255,0.7);
  box-shadow: var(--shadow-sm); border-radius: 999px;
  padding: 8px 16px 8px 9px; backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
}
.brand-mark {
  width: 30px; height: 30px; border-radius: 50%;
  background: radial-gradient(circle at 33% 30%, color-mix(in srgb, var(--accent) 60%, white), var(--accent) 55%, color-mix(in srgb, var(--accent) 50%, #1a2740) 100%);
  box-shadow: 0 3px 12px color-mix(in srgb, var(--accent) 50%, transparent);
  transition: background 1.2s var(--ease), box-shadow 1.2s var(--ease);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.12; }
.brand-title { font-size: 15px; font-weight: 700; letter-spacing: -0.02em; }
.brand-sub { font-size: 10.5px; color: var(--ink-faint); font-weight: 500; letter-spacing: 0.04em; }

.masthead-actions { display: flex; align-items: center; gap: 10px; }
.chapter-count {
  font-family: var(--mono); font-size: 12px; font-weight: 600;
  color: var(--ink-dim); font-variant-numeric: tabular-nums;
  background: var(--card); border: 1px solid rgba(255,255,255,0.7);
  box-shadow: var(--shadow-sm); border-radius: 999px; padding: 8px 13px;
  backdrop-filter: blur(18px);
}
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.7); background: var(--card); color: var(--ink-dim);
  box-shadow: var(--shadow-sm); backdrop-filter: blur(18px);
  transition: color 0.2s, transform 0.15s var(--ease);
}
.icon-btn:hover { color: var(--ink); transform: translateY(-1px); }

/* --- era headline pill ---------------------------------------------------- */
.era-head {
  position: fixed; left: 20px; top: 84px; z-index: 9;
  display: inline-flex; flex-direction: column; gap: 1px;
  padding: 12px 18px; border-radius: var(--r-md);
  background: var(--card); border: 1px solid rgba(255,255,255,0.7);
  box-shadow: var(--shadow-sm); backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
}
.era-age {
  font-size: clamp(30px, 4.6vw, 46px); font-weight: 800; line-height: 0.95;
  letter-spacing: -0.03em; color: var(--ink);
}
.era-eon {
  font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
  color: color-mix(in srgb, var(--accent) 70%, var(--ink) 30%);
}

/* --- snapshot panel widget ------------------------------------------------ */
.panel {
  position: fixed; z-index: 9; top: 50%; right: 20px; transform: translateY(-50%);
  width: min(380px, 37vw); max-height: min(76vh, 740px);
  overflow-y: auto; overflow-x: hidden;
  background: var(--card); border: 1px solid rgba(255,255,255,0.7);
  border-radius: var(--r-lg); box-shadow: var(--shadow);
  backdrop-filter: blur(24px) saturate(1.4); -webkit-backdrop-filter: blur(24px) saturate(1.4);
  scrollbar-width: thin; scrollbar-color: var(--hair) transparent;
}
.panel::-webkit-scrollbar { width: 7px; }
.panel::-webkit-scrollbar-thumb { background: rgba(20,30,55,0.18); border-radius: 8px; }
.panel-inner { padding: 22px; }

@keyframes panelIn { from { opacity: 0; transform: translateY(12px) scale(0.99); } to { opacity: 1; transform: none; } }
.panel-anim { animation: panelIn 0.55s var(--ease) both; }

.era-tag {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: #fff; background: var(--accent);
  padding: 5px 12px; border-radius: 999px; margin-bottom: 12px;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 40%, transparent);
}
.era-title { font-size: 26px; font-weight: 800; line-height: 1.1; letter-spacing: -0.025em; margin: 0 0 5px; }
.era-sub { font-size: 12.5px; color: var(--ink-dim); font-weight: 500; margin: 0 0 14px; }
.era-narrative { font-size: 14px; line-height: 1.6; color: #2c3543; margin: 0 0 18px; }

/* meters */
.meters {
  display: flex; flex-direction: column; gap: 13px;
  padding: 15px; margin-bottom: 4px; border-radius: var(--r-md);
  background: rgba(20, 30, 55, 0.04);
}
.meter-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.meter-name { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-faint); }
.meter-val { font-family: var(--mono); font-size: 12.5px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.meter-bar { height: 7px; border-radius: 7px; background: rgba(20,30,55,0.10); overflow: hidden; }
.meter-fill { display: block; height: 100%; width: 0%; border-radius: 7px; transition: width 1.1s var(--ease); }
.meter-fill--temp { background: linear-gradient(90deg, #59a6ff, #ffd23f 55%, #ff5a3c); }
.meter-fill--co2 { background: linear-gradient(90deg, #8a96ad, #c9863c); }
.meter-fill--o2 { background: linear-gradient(90deg, #36a87f, #5fd0a0); }
.meter-note { display: block; margin-top: 5px; font-size: 11px; color: var(--ink-faint); font-weight: 500; }

/* extinction badge */
.ext-badge {
  display: flex; gap: 10px; align-items: flex-start; margin-top: 16px;
  padding: 12px 14px; border-radius: var(--r-md);
  background: color-mix(in srgb, var(--danger) 10%, white);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
}
.ext-badge svg { color: var(--danger); flex: 0 0 auto; margin-top: 1px; }
.ext-label { display: block; font-weight: 700; font-size: 13px; color: #b3261e; }
.ext-detail { display: block; font-size: 12px; color: #7a2c26; line-height: 1.45; margin-top: 2px; }

/* snapshot list */
.snapshot { margin: 18px 0 0; display: flex; flex-direction: column; gap: 13px; }
.snap-row dt { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: color-mix(in srgb, var(--accent) 60%, var(--ink) 40%); margin-bottom: 3px; }
.snap-row dd { margin: 0; font-size: 13px; line-height: 1.5; color: #3a4250; }
.snap-row--turn { padding: 12px 14px; border-radius: var(--r-md); background: color-mix(in srgb, var(--accent) 9%, white); border: 1px solid color-mix(in srgb, var(--accent) 18%, transparent); }
.snap-row--turn dd { color: #2c3543; font-weight: 500; }

/* --- bottom dock ---------------------------------------------------------- */
.dock {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 9;
  width: min(720px, calc(100% - 32px));
  padding: 12px 16px 14px; border-radius: var(--r-lg);
  background: var(--card); border: 1px solid rgba(255,255,255,0.7);
  box-shadow: var(--shadow); backdrop-filter: blur(22px) saturate(1.3);
  -webkit-backdrop-filter: blur(22px) saturate(1.3);
  display: flex; flex-direction: column; gap: 11px;
}
.controls { display: flex; align-items: center; gap: 9px; justify-content: center; }
.ctrl-btn {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--hair); background: rgba(255,255,255,0.6); color: var(--ink);
  transition: transform 0.15s var(--ease), background 0.2s, box-shadow 0.2s;
}
.ctrl-btn:hover { background: #fff; transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.ctrl-btn:active { transform: translateY(0) scale(0.95); }
.ctrl-btn--play {
  width: 50px; height: 50px; background: var(--accent); border-color: transparent; color: #fff;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 45%, transparent);
}
.ctrl-btn--play:hover { background: color-mix(in srgb, var(--accent) 88%, white); }
.ctrl-btn--play .ic-pause { display: none; }
.ctrl-btn--play.is-playing .ic-play { display: none; }
.ctrl-btn--play.is-playing .ic-pause { display: block; }
.ctrl-btn--text { width: auto; border-radius: 999px; padding: 0 16px 0 13px; gap: 7px; font-size: 12.5px; font-weight: 600; color: var(--ink-dim); }
.ctrl-btn--text:hover { color: var(--ink); }
.ctrl-btn--text span { white-space: nowrap; }

/* timeline */
.timeline { position: relative; }
.timeline-rail { position: absolute; left: 4px; right: 4px; top: 9px; height: 3px; background: rgba(20,30,55,0.10); border-radius: 3px; z-index: 0; }
.timeline-fill { position: absolute; left: 0; top: 0; height: 100%; width: 0%; background: var(--accent); border-radius: 3px; transition: width 0.8s var(--ease), background 1s var(--ease); }
.timeline-track { position: relative; z-index: 1; display: flex; gap: 4px; overflow-x: auto; padding: 2px 2px 4px; scrollbar-width: none; scroll-snap-type: x proximity; }
.timeline-track::-webkit-scrollbar { display: none; }
.tl-node {
  --node-accent: var(--accent);
  flex: 1 0 auto; min-width: 58px; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 3px 5px 2px; background: none; border: none; color: var(--ink-faint);
  scroll-snap-align: center; transition: color 0.2s;
}
.tl-dot {
  width: 12px; height: 12px; border-radius: 50%; background: #fff;
  border: 2.5px solid rgba(20,30,55,0.22);
  transition: transform 0.2s var(--spring), background 0.2s, box-shadow 0.2s, border-color 0.2s;
}
.tl-dot--ext { border-radius: 3px; transform: rotate(45deg); border-color: color-mix(in srgb, var(--danger) 65%, transparent); }
.tl-label { font-size: 11px; font-weight: 600; white-space: nowrap; }
.tl-age { font-family: var(--mono); font-size: 9.5px; font-weight: 600; color: var(--ink-faint); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tl-node:hover { color: var(--ink-dim); }
.tl-node:hover .tl-dot { transform: scale(1.2); }
.tl-node.is-active { color: var(--ink); }
.tl-node.is-active .tl-dot { background: var(--node-accent); border-color: var(--node-accent); transform: scale(1.45); box-shadow: 0 0 0 4px color-mix(in srgb, var(--node-accent) 22%, transparent); }
.tl-node.is-active.is-extinction .tl-dot { transform: scale(1.4) rotate(45deg); }
.tl-node.is-active .tl-label { font-weight: 700; }
.timeline-foot { margin: 0; text-align: center; font-size: 10.5px; font-weight: 500; color: var(--ink-faint); }

/* --- intro overlay -------------------------------------------------------- */
.intro {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(60% 60% at 50% 38%, rgba(255,255,255,0.18), rgba(255,255,255,0.05));
  backdrop-filter: blur(3px);
  transition: opacity 0.7s var(--ease), visibility 0.7s;
}
.intro.hidden { opacity: 0; visibility: hidden; pointer-events: none; display: grid !important; }
.intro-inner {
  max-width: 600px; text-align: center; padding: 40px 36px;
  background: rgba(255,255,255,0.74); border: 1px solid rgba(255,255,255,0.8);
  border-radius: 32px; box-shadow: var(--shadow);
  backdrop-filter: blur(26px) saturate(1.3); -webkit-backdrop-filter: blur(26px) saturate(1.3);
}
.intro-kicker { font-size: 12px; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; color: color-mix(in srgb, var(--accent) 75%, var(--ink) 25%); }
.intro-title { font-size: clamp(50px, 10vw, 92px); font-weight: 800; line-height: 0.94; margin: 14px 0 18px; letter-spacing: -0.04em; color: var(--ink); }
.intro-lede { font-size: clamp(15px, 1.6vw, 17px); line-height: 1.62; color: var(--ink-dim); max-width: 480px; margin: 0 auto 28px; font-weight: 450; }
.intro-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.btn-primary {
  border: none; background: var(--accent); color: #fff; font-size: 14.5px; font-weight: 700;
  padding: 14px 28px; border-radius: 999px; transition: transform 0.15s var(--spring), box-shadow 0.2s, background 0.2s;
  box-shadow: 0 10px 26px color-mix(in srgb, var(--accent) 40%, transparent);
}
.btn-primary:hover { transform: translateY(-2px) scale(1.02); }
.btn-ghost {
  border: 1px solid var(--hair); background: rgba(255,255,255,0.7); color: var(--ink);
  font-size: 14.5px; font-weight: 600; padding: 14px 26px; border-radius: 999px;
  transition: background 0.2s, transform 0.15s var(--ease);
}
.btn-ghost:hover { background: #fff; transform: translateY(-1px); }
.intro-note { margin-top: 30px; font-size: 12px; color: var(--ink-faint); }
.intro-note em { font-style: italic; color: var(--ink-dim); }

/* --- info dialog ---------------------------------------------------------- */
.info-dialog {
  border: 1px solid rgba(255,255,255,0.8); background: rgba(255,255,255,0.92); color: var(--ink);
  border-radius: var(--r-lg); max-width: 560px; width: calc(100% - 40px); padding: 0;
  box-shadow: var(--shadow); backdrop-filter: blur(24px);
}
.info-dialog::backdrop { background: rgba(20,30,55,0.35); backdrop-filter: blur(4px); }
.info-body { padding: 28px; }
.info-body h2 { font-size: 23px; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 14px; }
.info-body p { font-size: 14px; line-height: 1.62; color: #3a4250; margin: 0 0 13px; }
.info-source { font-size: 12.5px !important; color: var(--ink-faint) !important; }
.info-body .btn-primary { margin-top: 6px; }

/* --- fallback ------------------------------------------------------------- */
.fallback { position: fixed; inset: 0; z-index: 40; display: grid; place-content: center; text-align: center; padding: 40px; background: linear-gradient(165deg, #bfe4fb, #3a6a8c); color: var(--ink); }
.fallback h1 { font-size: 38px; font-weight: 800; margin: 0 0 12px; }
.fallback p { color: var(--ink-dim); max-width: 420px; line-height: 1.6; }

/* --- responsive ----------------------------------------------------------- */
@media (max-width: 920px) {
  .panel { top: auto; bottom: 150px; right: 12px; left: 12px; width: auto; transform: none; max-height: 44vh; }
  .era-head { top: 74px; }
  .dock { bottom: 12px; }
}
@media (max-width: 620px) {
  .masthead { padding: 12px; }
  .brand-sub { display: none; }
  .era-head { left: 12px; top: 68px; padding: 9px 13px; }
  .panel { bottom: 168px; max-height: 40vh; }
  .panel-inner { padding: 18px; }
  .ctrl-btn--text span { display: none; }
  .ctrl-btn--text { width: 42px; border-radius: 50%; padding: 0; }
  .era-title { font-size: 22px; }
}
@media (max-width: 620px) and (max-height: 720px) { .panel { display: none; } }

/* --- reduced motion ------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.12s !important; scroll-behavior: auto !important; }
  .panel-anim { animation: none; }
}
