/* ══════════════════════════════════════════
   APOPHIS 99942 — Terminal Observatory
   ══════════════════════════════════════════ */

:root {
  --black: #0b0c0e;
  --black-warm: #0e0f11;
  --surface: #131416;
  --surface-up: #1a1b1f;
  --border: #222328;
  --border-light: #2e2f35;
  --text: #c8cad0;
  --text-dim: #6e7179;
  --text-muted: #44464d;
  --white: #eaebf0;
  --amber: #e8a849;
  --amber-dim: rgba(232, 168, 73, 0.12);
  --green: #5fdd6e;
  --green-dim: rgba(95, 221, 110, 0.1);
  --red: #ef5350;
  --cyan: #56c8d8;

  --mono: 'IBM Plex Mono', 'Menlo', monospace;
  --serif: 'Instrument Serif', Georgia, serif;

  --fs-xs: 0.65rem;
  --fs-sm: 0.78rem;
  --fs-base: 0.88rem;
  --fs-lg: 1.1rem;
  --fs-xl: 1.5rem;
  --fs-2xl: clamp(1.8rem, 4vw, 3rem);
  --fs-hero-cd: clamp(2.8rem, 7vw, 5.5rem);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--mono);
  font-size: var(--fs-base);
  background: var(--black);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--amber);
  color: var(--black);
}

a { color: var(--amber); text-decoration: none; }
a:hover { text-decoration: underline; }
strong { color: var(--white); font-weight: 600; }
em { color: var(--amber); font-style: normal; }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 clamp(1.2rem, 4vw, 3rem);
}

/* ── HERO ─────────────────────────────── */

.hero {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--black);
}

#hero-asteroid {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.hero-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  background:
    radial-gradient(ellipse 70% 60% at 50% 50%, transparent 30%, var(--black) 100%),
    linear-gradient(to bottom, transparent 60%, var(--black) 100%);
  pointer-events: none;
}

.hero-content {
  position: relative;
  z-index: 3;
  text-align: center;
  width: 100%;
  max-width: 900px;
  padding: 0 1.5rem;
}

.hero-top-bar {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.terminal-tag {
  font-size: var(--fs-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 0.2em 0.8em;
  border: 1px solid var(--border);
  border-radius: 2px;
}

.blink-slow {
  animation: blink-slow 2.5s ease-in-out infinite;
  color: var(--green);
  border-color: var(--green-dim);
}

@keyframes blink-slow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ── ASCII Title ── */

.ascii-title {
  font-family: var(--mono);
  font-size: clamp(0.35rem, 1.1vw, 0.7rem);
  line-height: 1.15;
  color: #fff;
  text-shadow:
    0 0 20px rgba(255, 255, 255, 0.4),
    0 0 60px rgba(86, 200, 216, 0.2);
  margin-bottom: 1.5rem;
  white-space: pre;
  overflow: hidden;
  text-align: center;
  min-height: 6em;
}

.ascii-title .ascii-char {
  display: inline;
  opacity: 0;
  animation: ascii-reveal 0.04s ease forwards;
}

@keyframes ascii-reveal {
  from { opacity: 0; }
  to { opacity: 1; }
}

.hero-sub {
  font-family: var(--serif);
  font-size: var(--fs-xl);
  color: #d0d2da;
  font-weight: 400;
  letter-spacing: -0.01em;
  margin-bottom: 3rem;
  text-shadow:
    0 1px 3px rgba(0, 0, 0, 0.9),
    0 0 40px rgba(0, 0, 0, 0.7);
  opacity: 0;
  animation: fade-up 0.5s ease 0.3s forwards;
}

/* ── Countdown ── */

.countdown {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: clamp(0.3rem, 1.5vw, 1rem);
  margin-bottom: 2.5rem;
  opacity: 0;
  animation: fade-up 0.5s ease 0.1s forwards;
}

.cd-group { text-align: center; }

.cd-val {
  font-family: var(--mono);
  font-size: var(--fs-hero-cd);
  font-weight: 700;
  line-height: 1;
  color: var(--white);
  /* High contrast backing — reads over any 3D content */
  text-shadow:
    0 0 40px rgba(0, 0, 0, 0.95),
    0 0 80px rgba(0, 0, 0, 0.8),
    0 2px 4px rgba(0, 0, 0, 0.9);
  letter-spacing: -0.02em;
}

.cd-lbl {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  letter-spacing: 0.15em;
  margin-top: 0.3rem;
}

.cd-sep {
  font-size: var(--fs-hero-cd);
  color: var(--text-muted);
  line-height: 1;
  opacity: 0.3;
  animation: sep-pulse 1s ease-in-out infinite;
}

@keyframes sep-pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.8; }
}

.hero-meta {
  display: flex;
  justify-content: center;
  gap: 2rem;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  letter-spacing: 0.08em;
  opacity: 0;
  animation: fade-up 0.4s ease 0.5s forwards;
}

.hero-meta span {
  padding: 0.2em 0;
  border-bottom: 1px solid var(--border);
}

.scroll-cue {
  position: absolute;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  opacity: 0;
  animation: fade-up 0.4s ease 0.7s forwards;
}

.scroll-line {
  width: 1px;
  height: 40px;
  background: linear-gradient(to bottom, var(--text-muted), transparent);
  animation: scroll-pulse 2s ease-in-out infinite;
}

@keyframes scroll-pulse {
  0%, 100% { transform: scaleY(1); opacity: 0.6; }
  50% { transform: scaleY(0.5); opacity: 0.2; }
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── NAV ──────────────────────────────── */

nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(11, 12, 14, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 0.7rem 0;
}

.nav-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 clamp(1.2rem, 4vw, 3rem);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-logo {
  font-weight: 700;
  font-size: var(--fs-sm);
  color: var(--amber);
  letter-spacing: 0.1em;
}

.nav-links {
  display: flex;
  gap: 1.5rem;
}

.nav-links a {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  letter-spacing: 0.08em;
  text-decoration: none;
  transition: color 0.2s;
}

.nav-links a:hover { color: var(--white); text-decoration: none; }

/* ── SECTIONS ─────────────────────────── */

.sect {
  padding: clamp(4rem, 10vh, 8rem) 0;
  border-top: 1px solid var(--border);
}

.sect-label {
  font-size: var(--fs-xs);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.8rem;
}

.sect-title {
  font-family: var(--serif);
  font-size: var(--fs-2xl);
  font-weight: 400;
  color: var(--white);
  margin-bottom: 2.5rem;
  letter-spacing: -0.02em;
}

/* ── Prose ── */

.prose p {
  color: var(--text);
  line-height: 1.85;
  margin-bottom: 1.2rem;
  max-width: 680px;
  font-size: var(--fs-base);
}

/* ── Data Grid ── */

.data-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  margin-bottom: 3rem;
}

.data-cell {
  background: var(--surface);
  padding: 1.5rem;
}

.data-val {
  font-size: var(--fs-2xl);
  font-weight: 700;
  color: var(--white);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.data-unit {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: 0.3rem;
}

.data-note {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 0.8rem;
  line-height: 1.5;
}

/* ── Distance Scale ── */

.comparison-block {
  margin-top: 3rem;
  border: 1px solid var(--line);
  padding: 1.5rem 2rem 1.25rem;
}

.dist-header {
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  margin-bottom: 1.25rem;
}

.dist-scale {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.dist-row {
  display: grid;
  grid-template-columns: 10rem 1fr 7rem;
  align-items: center;
  gap: 1rem;
  font-family: var(--mono);
  font-size: 0.78rem;
}

.dist-label {
  color: var(--text-dim);
  text-align: right;
  white-space: nowrap;
}

.dist-bar-wrap {
  position: relative;
  height: 6px;
  background: var(--line);
  border-radius: 1px;
  overflow: visible;
}

.dist-bar {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background: var(--text-dim);
  border-radius: 1px;
  opacity: 0.35;
}

.dist-bar--apophis {
  background: var(--amber);
  opacity: 1;
  box-shadow: 0 0 8px rgba(232, 168, 73, 0.4);
}

.dist-bar--moon {
  background: var(--text-dim);
  opacity: 0.18;
}

.dist-break {
  position: absolute;
  right: -2px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--mono);
  font-size: 0.6rem;
  color: var(--text-dim);
  letter-spacing: -1px;
}

.dist-km {
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  text-align: right;
  white-space: nowrap;
}

.dist-row--apophis .dist-label {
  color: var(--amber);
  font-weight: 600;
}

.dist-row--apophis .dist-km {
  color: var(--amber);
  font-weight: 600;
}

.dist-row--moon {
  margin-top: 0.4rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--line);
}

.dist-footnote {
  margin-top: 1.25rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  opacity: 0.6;
}

.dist-footnote em {
  color: var(--amber);
  font-style: normal;
}

@media (max-width: 640px) {
  .comparison-block {
    padding: 1.25rem 1rem 1rem;
  }

  .dist-row {
    grid-template-columns: 7rem 1fr 6rem;
    gap: 0.5rem;
    font-size: 0.68rem;
  }

  .dist-label {
    font-size: 0.62rem;
  }
}

/* ── VIEWER ───────────────────────────── */

.viewer-wrap {
  position: relative;
  max-width: 1100px;
  margin: 0 auto;
  aspect-ratio: 16 / 9;
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
}

.viewer-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.viewer-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 0.8rem;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border-light);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.viewer-hud {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1rem;
  background: rgba(11, 12, 14, 0.85);
  border-top: 1px solid var(--border);
  z-index: 10;
}

.viewer-hud-left, .viewer-hud-right {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.hud-btn {
  font-family: var(--mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.1em;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border);
  padding: 0.25rem 0.7rem;
  cursor: pointer;
  transition: all 0.15s;
}

.hud-btn:hover {
  color: var(--text);
  border-color: var(--border-light);
}

.hud-btn.active {
  color: var(--amber);
  border-color: var(--amber);
  background: var(--amber-dim);
}

.hud-data {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.hud-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  letter-spacing: 0.1em;
}

.hud-value {
  font-size: var(--fs-sm);
  color: var(--amber);
  font-weight: 500;
}

/* ── SPEC TABLE ───────────────────────── */

.spec-table {
  border: 1px solid var(--border);
  background: var(--surface);
}

.spec-row {
  display: flex;
  align-items: baseline;
  padding: 0.6rem 1.2rem;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-sm);
  gap: 0.5rem;
}

.spec-row:last-child { border-bottom: none; }

.spec-key {
  color: var(--text-muted);
  letter-spacing: 0.1em;
  font-size: var(--fs-xs);
  flex-shrink: 0;
  min-width: 140px;
}

.spec-dots {
  flex: 1;
  border-bottom: 1px dotted var(--border);
  min-width: 20px;
  margin-bottom: 0.2em;
}

.spec-val {
  color: var(--text);
  flex-shrink: 0;
  text-align: right;
}

/* ── MISSIONS ─────────────────────────── */

.mission-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
}

.mission-block {
  background: var(--surface);
  padding: 2rem;
}

.mission-header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 1rem;
}

.mission-agency {
  font-size: var(--fs-xs);
  letter-spacing: 0.15em;
  color: var(--amber);
  padding: 0.1em 0.5em;
  border: 1px solid var(--amber-dim);
}

.mission-name {
  font-family: var(--serif);
  font-size: var(--fs-lg);
  color: var(--white);
}

.mission-block p {
  font-size: var(--fs-sm);
  color: var(--text-dim);
  line-height: 1.7;
  margin-bottom: 1.2rem;
}

.mission-stats {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.mission-stats > div {
  display: flex;
  justify-content: space-between;
  font-size: var(--fs-xs);
}

.ms-k { color: var(--text-muted); letter-spacing: 0.1em; }
.ms-v { color: var(--text); }

/* ── SAFETY ───────────────────────────── */

.safety-box {
  border: 1px solid var(--green-dim);
  background: var(--surface);
  padding: 2rem;
  margin-bottom: 3rem;
}

.safety-ascii {
  font-family: var(--mono);
  font-size: clamp(0.6rem, 1.1vw, 0.78rem);
  color: var(--green);
  white-space: pre;
  line-height: 1.5;
  margin-bottom: 1.5rem;
  overflow-x: auto;
}

.safety-box p {
  font-size: var(--fs-sm);
  color: var(--text-dim);
  line-height: 1.7;
  max-width: 600px;
}

.torino-history {
  max-width: 600px;
}

.torino-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-xs);
}

.t-yr {
  color: var(--text-muted);
  min-width: 36px;
}

.t-lvl {
  font-weight: 700;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  border-radius: 2px;
  flex-shrink: 0;
}

.t-4 { background: var(--red); color: var(--black); }
.t-1 { background: var(--amber); color: var(--black); }
.t-0 { background: var(--green); color: var(--black); }

.t-bar {
  height: 3px;
  background: var(--red);
  border-radius: 1px;
  flex-shrink: 0;
}

.t-desc {
  color: var(--text-dim);
  flex: 1;
}

/* ── API ──────────────────────────────── */

.api-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
}

.api-block {
  background: var(--surface);
  padding: 1.5rem;
  position: relative;
}

.api-title {
  font-size: var(--fs-xs);
  letter-spacing: 0.15em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.api-pre {
  font-family: var(--mono);
  font-size: clamp(0.6rem, 1vw, 0.72rem);
  color: var(--text-dim);
  white-space: pre;
  line-height: 1.6;
  overflow-x: auto;
}

.copy-btn {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  font-family: var(--mono);
  font-size: var(--fs-xs);
  color: var(--text-muted);
  background: var(--surface-up);
  border: 1px solid var(--border);
  padding: 0.15rem 0.5rem;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: all 0.15s;
}

.copy-btn:hover {
  color: var(--amber);
  border-color: var(--amber-dim);
}

/* ── CARBON ADS ──────────────────────── */

.carbon-wrap {
  padding: 1.5rem 0;
  border-top: 1px solid var(--border);
}

#carbonads {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: var(--fs-xs);
  max-width: 480px;
  margin: 0 auto;
}

#carbonads a {
  color: var(--text);
  text-decoration: none;
}

#carbonads a:hover {
  color: var(--amber);
}

#carbonads .carbon-img img {
  display: block;
  width: 100px;
  height: auto;
  border-radius: 2px;
}

#carbonads .carbon-text {
  color: var(--text-dim);
  line-height: 1.5;
}

#carbonads .carbon-poweredby {
  font-size: 0.55rem;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 0.4rem;
  display: block;
}

/* ── FOOTER ───────────────────────────── */

footer {
  border-top: 1px solid var(--border);
  padding: 2.5rem 0;
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.footer-links {
  display: flex;
  gap: 1.5rem;
}

.footer-links a {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-decoration: none;
}

.footer-links a:hover { color: var(--text); }

.footer-note {
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

/* ── REVEAL ANIMATION ─────────────────── */

.reveal {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── RESPONSIVE ───────────────────────── */

@media (max-width: 768px) {
  .nav-links { display: none; }

  .data-grid,
  .mission-grid,
  .api-grid {
    grid-template-columns: 1fr;
  }

  .hero-meta {
    flex-direction: column;
    gap: 0.5rem;
  }

  .countdown { gap: 0.2rem; }
  .cd-sep { font-size: clamp(1.5rem, 8vw, 2.5rem); }

  .spec-row {
    flex-wrap: wrap;
    gap: 0.2rem;
  }
  .spec-dots { display: none; }
  .spec-val { width: 100%; text-align: left; color: var(--amber); }

  .footer-inner { flex-direction: column; gap: 1rem; text-align: center; }
  .footer-links { flex-wrap: wrap; justify-content: center; }

  .viewer-wrap { aspect-ratio: 4/3; }
}

@media (max-width: 480px) {
  .ascii-title { font-size: clamp(0.22rem, 0.9vw, 0.4rem); }
  .cd-val { font-size: clamp(2rem, 12vw, 3rem); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .reveal { opacity: 1; transform: none; }
}
