/* ==========================================================================
   SPACE ARCADE — design system v2
   Lowpoly-3D era: glass surfaces, nebula glows, Space Grotesk, micro-motion.
   Plain CSS, no build step. Class names are stable — game JS depends on them.
   ========================================================================== */

@font-face {
  font-family: 'Space Grotesk';
  src: url('/assets/fonts/space-grotesk.woff2') format('woff2-variations');
  font-weight: 300 700;
  font-display: swap;
}

:root {
  --bg: #04050c;
  --bg2: #0a0d1d;
  --ink: #f2f4ff;
  --muted: #8b93bb;
  --accent: #7c5cff;
  --accent2: #3ec6ff;
  --magenta: #ff5cd6;
  --good: #3ddc84;
  --bad: #ff5c7a;
  --gold: #ffd166;
  --card: rgba(255, 255, 255, 0.045);
  --card-solid: #0d1124;
  --border: rgba(255, 255, 255, 0.09);
  --border-bright: rgba(255, 255, 255, 0.18);
  --radius: 18px;
  --font: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --glow-violet: 0 0 60px rgba(124, 92, 255, 0.35);
  --glow-cyan: 0 0 60px rgba(62, 198, 255, 0.3);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  min-height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  /* layered nebula wash */
  background:
    radial-gradient(60% 45% at 85% -5%, rgba(124, 92, 255, 0.16) 0%, transparent 60%),
    radial-gradient(50% 40% at 5% 15%, rgba(62, 198, 255, 0.10) 0%, transparent 60%),
    radial-gradient(45% 35% at 60% 110%, rgba(255, 92, 214, 0.08) 0%, transparent 60%),
    var(--bg);
}

/* film grain, ultra subtle */
body::after {
  content: "";
  position: fixed;
  inset: -50%;
  z-index: 100;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.6'/%3E%3C/svg%3E");
}

main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 16px clamp(16px, 4vw, 32px); position: relative; z-index: 1; }

a { color: var(--accent2); }
::selection { background: rgba(124, 92, 255, 0.5); }

/* ---- Type ---------------------------------------------------------------- */

h1, h2, h3 { line-height: 1.08; letter-spacing: -0.02em; font-weight: 600; }

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--accent2);
}
.eyebrow::before {
  content: "";
  width: 24px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent2));
}

.display {
  font-size: clamp(2.4rem, 8vw, 4.8rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.02;
  margin: 14px 0;
}

.display .grad {
  background: linear-gradient(100deg, var(--gold) 0%, var(--magenta) 45%, var(--accent2) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.sub { color: var(--muted); font-size: clamp(1rem, 2.4vw, 1.18rem); line-height: 1.6; font-weight: 400; }

.hint { color: var(--muted); font-size: 0.9rem; }

/* ---- 3D scene canvases ---------------------------------------------------- */

.scene-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}
.scene-canvas.interactive { pointer-events: auto; }

.scene-wrap { position: relative; }

/* HTML labels projected over the 3D solar system */
.p3d-label {
  position: absolute;
  transform: translate(-50%, 8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  color: var(--ink);
  text-align: center;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(6, 8, 18, 0.66);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  transition: border-color 0.25s, box-shadow 0.25s, transform 0.25s var(--ease-spring);
  will-change: transform;
}
.p3d-label small { color: var(--accent2); font-weight: 500; }
.p3d-label:hover, .p3d-label.hot {
  border-color: var(--border-bright);
  box-shadow: var(--glow-violet);
  transform: translate(-50%, 8px) scale(1.08);
}

/* ---- Legacy CSS starfield (no-webgl fallback) ------------------------------ */

.starfield { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.star { position: absolute; border-radius: 50%; background: #fff; opacity: 0.7; animation: twinkle 3s ease-in-out infinite; }
@keyframes twinkle { 0%, 100% { opacity: 0.2; } 50% { opacity: 0.9; } }

/* ---- Header ---------------------------------------------------------------- */

.site-header {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px clamp(16px, 4vw, 32px);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 700;
  letter-spacing: 0.14em;
  font-size: 0.85rem;
}
.logo .dot {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: conic-gradient(from 210deg, var(--accent), var(--magenta), var(--gold), var(--accent2), var(--accent));
  box-shadow: var(--glow-violet);
  animation: spin 14s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.site-header nav { display: flex; gap: 8px; flex-wrap: wrap; }

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  min-height: 44px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.88rem;
  transition: border-color 0.25s, transform 0.25s var(--ease-spring), box-shadow 0.25s;
}
.nav-link:hover { border-color: var(--border-bright); transform: translateY(-2px); box-shadow: var(--glow-cyan); }
.nav-link:active { transform: scale(0.96); }

.mute-btn {
  font-size: 1.1rem;
  background: var(--card);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 999px;
  width: 44px; height: 44px;
  cursor: pointer;
  color: var(--ink);
  transition: border-color 0.25s, transform 0.25s var(--ease-spring);
}
.mute-btn:hover { border-color: var(--border-bright); transform: rotate(12deg) scale(1.08); }

/* compact header on phones: keep everything on one row */
@media (max-width: 540px) {
  .site-header { padding: 12px 14px; gap: 6px; }
  .site-header nav { gap: 6px; flex-wrap: nowrap; }
  .logo { font-size: 0; gap: 0; }   /* text hides, the spinning dot stays */
  .nav-link { padding: 9px 12px; font-size: 0.8rem; white-space: nowrap; }
  .mute-btn { width: 40px; height: 40px; flex: none; }
}

/* ---- Buttons ---------------------------------------------------------------- */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  min-height: 48px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(120deg, var(--accent) 0%, #6f79ff 50%, var(--accent2) 100%);
  background-size: 160% 100%;
  color: #fff;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  overflow: hidden;
  transition: background-position 0.45s, transform 0.25s var(--ease-spring), box-shadow 0.3s;
  box-shadow: 0 4px 24px rgba(124, 92, 255, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  will-change: transform;
}
.btn:hover { background-position: 100% 0; transform: translateY(-2px); box-shadow: 0 8px 34px rgba(62, 198, 255, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.25); }
.btn:active { transform: scale(0.96); }

/* shine sweep */
.btn::after {
  content: "";
  position: absolute;
  top: 0; left: -80%;
  width: 50%; height: 100%;
  background: linear-gradient(105deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  transform: skewX(-20deg);
  transition: left 0.6s ease;
}
.btn:hover::after { left: 130%; }

.btn.secondary {
  background: var(--card);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--ink);
  box-shadow: none;
}
.btn.secondary:hover { border-color: var(--border-bright); box-shadow: var(--glow-cyan); }

.btn.big { font-size: 1.15rem; padding: 18px 34px; border-radius: 999px; }

.btn:disabled { opacity: 0.5; cursor: default; transform: none; }

/* ---- Panels ------------------------------------------------------------------ */

.panel {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(16px, 3vw, 26px);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
/* gradient hairline on top edge */
.panel::before {
  content: "";
  position: absolute;
  top: 0; left: 10%; right: 10%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(124, 92, 255, 0.7), rgba(62, 198, 255, 0.7), transparent);
}

/* ---- Mission cards (home) ------------------------------------------------------ */

.mission-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin: 26px 0 40px;
}

.mission-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--ink);
  text-decoration: none;
  overflow: hidden;
  transition: transform 0.3s var(--ease-spring), border-color 0.3s, box-shadow 0.3s;
  transform-style: preserve-3d;
  will-change: transform;
}
.mission-card:hover { border-color: var(--border-bright); box-shadow: var(--glow-violet); }
.mission-card .planet-ball { width: 52px; height: 52px; transition: transform 0.35s var(--ease-spring); }
.mission-card:hover .planet-ball { transform: scale(1.15) rotate(-8deg); }
.mission-card b { font-size: 1.05rem; letter-spacing: -0.01em; }
.mission-card span { color: var(--muted); font-size: 0.85rem; line-height: 1.45; }
.mission-card .go {
  position: absolute;
  top: 18px; right: 18px;
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--muted);
  transition: transform 0.3s var(--ease-spring), color 0.3s, border-color 0.3s, background 0.3s;
}
.mission-card:hover .go {
  transform: rotate(-45deg);
  color: #fff;
  border-color: transparent;
  background: linear-gradient(120deg, var(--accent), var(--accent2));
}

/* ---- Game HUD -------------------------------------------------------------------- */

.hud { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin: 14px 0 18px; }

.hud .stat {
  background: var(--card);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 14px;
  padding: 10px 18px;
  text-align: center;
  min-width: 92px;
  transition: border-color 0.3s, box-shadow 0.3s;
}
.hud .stat b { display: block; font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.hud .stat span { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.18em; }
.hud .stat.pulse { border-color: rgba(61, 220, 132, 0.6); box-shadow: 0 0 24px rgba(61, 220, 132, 0.25); }

/* ---- Game page hero -------------------------------------------------------------- */

.game-hero { text-align: center; margin: 6px 0 4px; }
.game-hero h1 { font-size: clamp(1.7rem, 5.5vw, 2.6rem); margin: 6px 0 4px; }
.game-hero .hint { margin: 0; }

/* ---- Result overlay ---------------------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(3, 4, 10, 0.7);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  animation: overlayIn 0.35s ease both;
}
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }

.overlay .panel {
  width: 100%;
  max-width: 430px;
  text-align: center;
  background: rgba(13, 17, 36, 0.92);
  animation: panelPop 0.5s var(--ease-spring) both;
}
@keyframes panelPop { from { opacity: 0; transform: translateY(26px) scale(0.94); } to { opacity: 1; transform: none; } }

.result-score {
  font-size: clamp(3.2rem, 14vw, 4.6rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  margin: 4px 0 8px;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(120deg, var(--gold), var(--magenta), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 24px rgba(255, 209, 102, 0.25));
}

.submit-row { display: flex; gap: 8px; margin: 14px 0 4px; }
.submit-row input {
  flex: 1;
  min-width: 0;
  padding: 13px 16px;
  font-size: 1rem;
  font-family: var(--font);
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  transition: border-color 0.25s, box-shadow 0.25s;
}
.submit-row input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.25); }

.submit-msg { min-height: 1.4em; font-weight: 600; }
.submit-msg.good { color: var(--good); }
.submit-msg.bad { color: var(--bad); }

.result-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }

/* ---- Leaderboard --------------------------------------------------------------------- */

.leaderboard { margin: 34px 0 20px; position: relative; z-index: 1; }
.leaderboard h2 { letter-spacing: -0.02em; }

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  padding: 4px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.tab {
  flex: 1;
  padding: 10px 6px;
  min-height: 44px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: color 0.25s, background 0.3s, box-shadow 0.3s;
}
.tab:hover { color: var(--ink); }
.tab.active {
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  color: #fff;
  box-shadow: 0 2px 16px rgba(124, 92, 255, 0.4);
}

.lb-table { width: 100%; border-collapse: collapse; }
.lb-table td, .lb-table th { padding: 12px 10px; text-align: left; border-bottom: 1px solid var(--border); }
.lb-table tbody tr { transition: background 0.25s; }
.lb-table tbody tr:hover { background: rgba(255, 255, 255, 0.03); }
.lb-table th { color: var(--muted); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.18em; font-weight: 600; }
.lb-table .rank { width: 2.2em; font-weight: 700; color: var(--muted); }
.lb-table tbody tr:first-child .rank { color: var(--gold); }
.lb-table .score { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-table .when { text-align: right; color: var(--muted); font-size: 0.82rem; }

.champ-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 3px 10px;
  border-radius: 999px;
  background: linear-gradient(120deg, var(--gold), #ffb03a);
  color: #4a3200;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  vertical-align: middle;
  box-shadow: 0 0 18px rgba(255, 209, 102, 0.45);
}

.lb-note { color: var(--muted); font-size: 0.82rem; margin-top: 10px; }
.lb-empty, .lb-error { color: var(--muted); text-align: center; padding: 22px 8px; }

/* ---- Planet chips ------------------------------------------------------------------------ */

.planet-ball {
  border-radius: 50%;
  display: inline-block;
  box-shadow: inset -8px -8px 16px rgba(0, 0, 0, 0.5);
  flex: none;
}

.p-mercury { background: radial-gradient(circle at 35% 30%, #cfc7bd, #8d857c 70%); }
.p-venus   { background: radial-gradient(circle at 35% 30%, #ffd9a0, #c98b3f 70%); }
.p-earth   { background: radial-gradient(circle at 35% 30%, #7fd4ff, #1d6fd1 55%, #14509e 80%); }
.p-mars    { background: radial-gradient(circle at 35% 30%, #ff9d6e, #c1440e 70%); }
.p-jupiter { background: radial-gradient(circle at 35% 30%, #f0cfa8, #b0703c 45%, #d8a877 60%, #9c5a2e 80%); }
.p-saturn  { background: radial-gradient(circle at 35% 30%, #f5e0b0, #c9a468 70%); }
.p-uranus  { background: radial-gradient(circle at 35% 30%, #bdf3f5, #56b6c2 70%); }
.p-neptune { background: radial-gradient(circle at 35% 30%, #7aa7ff, #2f4bd1 70%); }
.p-sun     { background: radial-gradient(circle at 40% 35%, #fff3b0, #ffb703 55%, #fb8500 85%); box-shadow: 0 0 40px rgba(255, 183, 3, 0.55); }

/* ---- Footer -------------------------------------------------------------------------------- */

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 26px 16px;
  position: relative;
  z-index: 1;
  letter-spacing: 0.04em;
}

/* ---- Utility --------------------------------------------------------------------------------- */

.center { text-align: center; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); border: 0;
}

/* entrance targets: experience.js animates these in; visible without JS */
[data-animate] { will-change: transform, opacity; }

/* page fade veil for 3D fly-to-planet transitions */
.page-veil {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: var(--bg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.45s ease;
}
.page-veil.on { opacity: 1; pointer-events: auto; }

/* ---- Reduced motion ---------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
  }
  .star { animation: none; opacity: 0.6; }
  .logo .dot { animation: none; }
}
