:root {
  --bg: #05060f;
  --panel: rgba(16, 20, 44, 0.72);
  --line: rgba(150, 165, 255, 0.16);
  --line-strong: rgba(150, 165, 255, 0.32);
  --text: #e9ecff;
  --muted: #98a1c8;
  --accent: #8b6cff;
  --accent-2: #22d3ee;
  --gold: #ffd166;
  --danger: #ff5d73;
  --ok: #4ade80;
  --radius: 18px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: 'Space Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
  line-height: 1.5;
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(139, 108, 255, 0.22), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(34, 211, 238, 0.14), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

#starfield {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.topbar, main { position: relative; z-index: 1; }

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px 20px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: rgba(5, 6, 15, 0.72);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-size: 14px;
  letter-spacing: 0;
}

.nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }

.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.95rem;
  transition: color 0.15s, background 0.15s;
}
.nav a:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.nav a.active { color: var(--text); background: rgba(139, 108, 255, 0.28); }

.dust-pill {
  color: var(--gold);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 6px 14px;
  border: 1px solid rgba(255, 209, 102, 0.35);
  border-radius: 999px;
  white-space: nowrap;
}
.dust-pill.bump { animation: bump 0.4s ease; }

@media (max-width: 640px) {
  .topbar { padding: 10px 16px; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .nav a { white-space: nowrap; }
  .dust-pill { margin-left: auto; }
}

/* ---------- Layout ---------- */

main { max-width: 1060px; margin: 0 auto; padding: 36px 16px 72px; }

h1 { font-size: clamp(2.1rem, 6vw, 3.6rem); line-height: 1.05; margin: 0.15em 0 0.3em; letter-spacing: -0.02em; }
h2 { font-size: 1.4rem; margin: 0 0 0.6em; }
h3 { margin: 0 0 0.3em; font-size: 1.1rem; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.eyebrow { text-transform: uppercase; letter-spacing: 0.2em; font-size: 0.78rem; color: var(--accent-2); font-weight: 700; }
.gradient-text {
  background: linear-gradient(90deg, #fff, #c8b9ff 40%, var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.section { margin-top: 40px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  backdrop-filter: blur(6px);
}

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.split { display: grid; gap: 20px; grid-template-columns: 1.2fr 1fr; align-items: center; }
@media (max-width: 780px) { .split { grid-template-columns: 1fr; } }

.card {
  display: block;
  color: inherit;
  text-decoration: none;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
a.card:hover {
  transform: translateY(-4px);
  border-color: var(--line-strong);
  box-shadow: 0 16px 40px -20px rgba(139, 108, 255, 0.8);
}
.card .icon { font-size: 1.8rem; margin-bottom: 8px; display: block; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- Controls ---------- */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s, background 0.15s, box-shadow 0.15s;
}
.btn:hover { background: rgba(255, 255, 255, 0.09); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), #5b8cff);
  border-color: transparent;
  box-shadow: 0 8px 24px -8px rgba(139, 108, 255, 0.8);
}
.btn.gold {
  background: linear-gradient(135deg, #ffd166, #ff9f43);
  color: #1b1300;
  border-color: transparent;
}
.btn.danger { border-color: rgba(255, 93, 115, 0.5); color: #ffb3bd; }
.btn.small { padding: 6px 14px; font-size: 0.9rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

input[type="text"] {
  font: inherit;
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 11px 14px;
  min-width: 0;
  flex: 1;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="text"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(139, 108, 255, 0.25); }

kbd {
  font: inherit;
  font-size: 0.85em;
  padding: 1px 7px;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.06);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  padding: 12px 20px;
  border-radius: 999px;
  background: #1a1f45;
  border: 1px solid var(--line-strong);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  transition: opacity 0.25s, transform 0.25s;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Home ---------- */

.hero-ship { width: 100%; height: 300px; display: block; }
.stat-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 20px; }
.stat { padding: 14px 16px; }
.stat b { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 0.85rem; }
.transmission { border-left: 3px solid var(--accent-2); }

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

.game-wrap {
  position: relative;
  height: min(72vh, 640px);
  min-height: 420px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line-strong);
  background: rgba(3, 4, 14, 0.65);
}
#game { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  background: rgba(5, 6, 15, 0.62);
  backdrop-filter: blur(3px);
}
.overlay[hidden] { display: none; }
.overlay-inner { max-width: 440px; }
.overlay .big-score { font-size: 3rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  background: linear-gradient(135deg, #ffd166, #ff7ab6);
  color: #1b0f00;
  animation: bump 0.6s ease;
}
.run-stats { display: flex; justify-content: center; gap: 24px; margin: 16px 0 20px; color: var(--muted); }
.run-stats b { display: block; color: var(--text); font-size: 1.2rem; }

/* ---------- Hangar ---------- */

.ship-card { text-align: center; }
.ship-card canvas { width: 100%; height: 150px; display: block; }
.ship-card.selected { border-color: var(--accent-2); box-shadow: 0 0 0 1px var(--accent-2) inset; }
.ship-card p { min-height: 3em; font-size: 0.92rem; }

.upgrade { display: grid; grid-template-columns: auto 1fr auto; gap: 16px; align-items: center; }
.upgrade + .upgrade { margin-top: 12px; }
.upgrade .icon { font-size: 1.8rem; }
.pips { display: flex; gap: 5px; margin-top: 6px; }
.pip { width: 26px; height: 7px; border-radius: 4px; background: rgba(255, 255, 255, 0.12); }
.pip.on { background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
@media (max-width: 520px) {
  .upgrade { grid-template-columns: auto 1fr; }
  .upgrade .btn { grid-column: 1 / -1; }
}

/* ---------- Oracle ---------- */

.orb {
  width: 210px;
  height: 210px;
  margin: 10px auto 28px;
  border-radius: 50%;
  position: relative;
  background: radial-gradient(circle at 35% 30%, #fff 0 3%, #d9ceff 9%, #8b6cff 34%, #2a1a6e 70%, #0b0720 100%);
  box-shadow: 0 0 70px rgba(139, 108, 255, 0.55), inset -20px -30px 60px rgba(0, 0, 0, 0.55);
  animation: float 6s ease-in-out infinite;
}
.orb::after {
  content: '';
  position: absolute;
  inset: -16px;
  border-radius: 50%;
  border: 1px dashed rgba(200, 190, 255, 0.35);
  animation: spin 20s linear infinite;
}
.orb.thinking { animation: wobble 0.18s ease-in-out infinite; filter: saturate(1.6) brightness(1.25); }

.fortune { min-height: 7.5em; text-align: center; }
.fortune .opener { color: var(--muted); font-style: italic; }
.fortune .answer { font-size: 1.45rem; font-weight: 600; margin: 6px 0 10px; }
.fortune .reveal { animation: fadeUp 0.6s ease both; }

.alien { display: flex; gap: 16px; align-items: center; }
.alien-face { font-size: 3rem; line-height: 1; filter: drop-shadow(0 0 12px rgba(34, 211, 238, 0.5)); }
.alien-name { font-size: 1.3rem; font-weight: 700; }

/* ---------- Logbook ---------- */

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; }
td.num, th.num { text-align: right; }
tr.top td:first-child { color: var(--gold); }
.table-scroll { overflow-x: auto; }
.empty { color: var(--muted); text-align: center; padding: 28px 8px; }
.crew-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }

/* ---------- Animations ---------- */

@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes wobble { 0%, 100% { transform: translate(0, 0); } 25% { transform: translate(-4px, 2px); } 75% { transform: translate(4px, -2px); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
