:root {
  --bg: #060913;
  --card: rgba(15, 23, 42, 0.92);
  --line: rgba(255, 255, 255, 0.12);
  --cyan: #38bdf8;
  --cyan-hi: #22d3ee;
  --red: #f43f5e;
  --amber: #fbbf24;
  --green: #4ade80;
  --text: #f8fafc;
  --muted: #94a3b8;
  --dim: #64748b;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

button { font-family: inherit; }

#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }
.dim { color: var(--dim); }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.hud-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.hud-center { flex: 1; display: flex; justify-content: center; min-width: 0; }
.hud-right { display: flex; align-items: center; gap: 8px; }
.ammo-pill { padding: 6px 12px; }
.score-pill { gap: 10px; }
/* Every element in the top bar shares one height so the row reads cleanly. */
.hud-top .pill, .hud-top .launch, .hud-top .next-sat { box-sizing: border-box; height: 44px; min-height: 44px; }
.hud-top .pill.controls .icon-btn { width: 34px; height: 34px; }
.hud-rank { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: #fde68a; white-space: nowrap; }
.hud-rank .star { width: 12px; height: 12px; color: #fbbf24; flex: none; }
.hud-rank .rk-abbr { display: none; }

.pill {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(2, 6, 23, 0.6);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.pill-label { font-size: 11px; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.pill-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 2ch; }
.pill.controls { padding: 4px; gap: 2px; pointer-events: auto; }

.ammo { display: inline-flex; gap: 5px; align-items: center; }
.ammo i { width: 7px; height: 15px; border-radius: 2px; background: #fb7185; box-shadow: 0 0 8px rgba(251, 113, 133, 0.7); transition: all 0.2s; }
.ammo .msl { width: 11px; height: 25px; overflow: visible; transition: opacity 0.2s; }
.msl .body { fill: #e2e8f0; }
.msl .nose, .msl .fin { fill: #f43f5e; }
.msl .flame { fill: #fbbf24; }
.msl.ready { filter: drop-shadow(0 0 4px rgba(251, 113, 133, 0.6)); }
.msl.off .body { fill: #334155; }
.msl.off .nose, .msl.off .fin { fill: #475569; }
.msl.off .flame, .msl.lost .flame { display: none; }
.msl.lost .body, .msl.lost .nose, .msl.lost .fin { fill: #1e293b; }
.msl.lost .x { stroke: #ef4444; stroke-width: 2.4; stroke-linecap: round; fill: none; filter: drop-shadow(0 0 3px rgba(239, 68, 68, 0.8)); }
.ammo i.off { background: #1e293b; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1); }

.icon-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #cbd5e1;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.icon-btn svg { width: 17px; height: 17px; }

/* Second HUD row: people · level · upgrade */
.hud-sub { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 8px; }
.hud-sub .pill { box-sizing: border-box; height: 32px; min-height: 32px; padding: 4px 12px; }
.people { display: inline-flex; gap: 4px; align-items: center; }
.people svg { width: 14px; height: 20px; overflow: visible; }
.people .p-body { fill: #e2e8f0; }
.people .x { stroke: #ef4444; stroke-width: 2.4; stroke-linecap: round; fill: none; display: none; }
.people .gone .p-body { fill: #334155; }
.people .gone .x { display: inline; }
.earth-sep { width: 1px; height: 16px; background: var(--line); }
.earth-hp { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-variant-numeric: tabular-nums; color: #4ade80; }
.earth-hp svg { width: 15px; height: 15px; }
.earth-hp.mid { color: #fbbf24; }
.earth-hp.low { color: #f87171; animation: blink 0.7s steps(2) infinite; }
.pulse { animation: hilite 0.9s ease-in-out infinite; }
@keyframes hilite { 50% { box-shadow: 0 0 0 3px rgba(103, 232, 249, 0.55); border-color: #67e8f9; } }
.level-pill { gap: 8px; }
.lv { font-size: 11px; font-weight: 800; letter-spacing: 0.12em; color: #c4b5fd; white-space: nowrap; font-variant-numeric: tabular-nums; }
.lv-bar { width: 64px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.lv-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #8b5cf6, #c4b5fd); transition: width 0.3s; }
/* Upgrade tree overlay */
.card.upg-card { max-width: 760px; padding: 22px; }
.upg-points { font-size: 18px; font-weight: 800; margin: 2px 0 10px; }
.upg-points b { color: #c4b5fd; }
.upg-coach { margin: -4px 0 10px; padding: 8px 12px; border-radius: 12px; background: rgba(103, 232, 249, 0.12); border: 1px solid rgba(103, 232, 249, 0.4); color: #a5f3fc; font-size: 13px; font-weight: 600; }
.upg-tree { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.upg-branch { display: flex; flex-direction: column; gap: 6px; }
.upg-branch h3 { margin: 0 0 2px; white-space: nowrap; font-size: 11px; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; color: var(--bc); }
.upg-branch[data-b="weapons"] { --bc: #fbbf24; }
.upg-branch[data-b="fleet"] { --bc: #38bdf8; }
.upg-branch[data-b="shields"] { --bc: #67e8f9; }
.upg-branch[data-b="planet"] { --bc: #a3e635; }
.upg-node {
  position: relative;
  text-align: left;
  padding: 9px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font: inherit;
  cursor: default;
  touch-action: manipulation;
}
.upg-node b { display: block; font-size: 13px; }
.upg-node span { display: block; margin-top: 2px; font-size: 11.5px; line-height: 1.35; color: var(--muted); }
.upg-node.owned { border-color: var(--bc); background: color-mix(in srgb, var(--bc) 18%, transparent); }
.upg-node.owned b::after { content: ' ✓'; color: var(--bc); }
.upg-node.available { border-color: var(--bc); cursor: pointer; box-shadow: 0 0 0 1px var(--bc) inset; }
.upg-node.available:hover { background: color-mix(in srgb, var(--bc) 12%, transparent); }
.upg-node.locked { opacity: 0.4; }
.upg-node.unlocked { opacity: 0.75; }
.upg-node.idle { opacity: 0.5; }
.upg-node i { display: block; margin-top: 4px; font-size: 10.5px; font-style: normal; font-weight: 700; color: var(--bc); }
/* Xeno-Science: endgame branch, full width under the four regular ones */
.upg-branch[data-b="science"] { --bc: #22d3ee; }
.upg-branch.upg-sci { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px 10px;
  padding: 10px; border-radius: 14px; border: 1px dashed rgba(34, 211, 238, 0.45); background: rgba(34, 211, 238, 0.06); }
.upg-sci h3 { grid-column: 1 / -1; }
.upg-sci-lock { grid-column: 1 / -1; font-size: 13px; line-height: 1.45; color: #a5f3fc; }
.badge.sci { background: rgba(34, 211, 238, 0.18); color: #67e8f9; }
.card.sci-card { max-width: 420px; }
.sci-ico { width: 56px; height: 56px; margin: 4px auto; color: #67e8f9; filter: drop-shadow(0 0 10px rgba(34, 211, 238, 0.6)); }
.sci-ico svg { width: 100%; height: 100%; }
.sci-title { margin: 4px 0 8px; font-size: 21px; }
.sci-text { margin: 0 0 18px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.sci-text b { color: #a5f3fc; }

.hud-bottom { display: flex; justify-content: center; align-items: flex-end; margin-top: auto; }

.alert.hint {
  border-color: var(--line);
  background: rgba(2, 6, 23, 0.7);
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  animation: none;
}
.hint.fade { opacity: 0; }

.launch {
  pointer-events: auto;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid rgba(74, 222, 128, 0.6);
  background: rgba(5, 46, 22, 0.75);
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
  cursor: pointer;
  box-shadow: 0 0 22px rgba(74, 222, 128, 0.3);
  animation: glow 1.4s ease-in-out infinite;
}
.launch svg { width: 16px; height: 16px; flex: none; }
.next-sat {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(2, 6, 23, 0.6);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}
.next-sat svg { width: 16px; height: 16px; color: #38bdf8; }
.next-sat b { color: var(--text); font-variant-numeric: tabular-nums; }
.launch:disabled { opacity: 0.5; animation: none; }
.queue { display: inline-flex; gap: 4px; }
.queue i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
@keyframes glow { 50% { box-shadow: 0 0 6px rgba(74, 222, 128, 0.15); } }

.alert {
  position: absolute;
  top: calc(max(14px, env(safe-area-inset-top)) + 92px);
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 16px;
  border-radius: 999px;
  border: 1px solid rgba(244, 63, 94, 0.6);
  background: rgba(76, 5, 25, 0.7);
  color: #fda4af;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  white-space: nowrap;
  animation: blink 0.7s steps(2) infinite;
}
.alert.info { border-color: rgba(74, 222, 128, 0.6); background: rgba(5, 46, 22, 0.7); color: var(--green); animation: none; }
@keyframes blink { 50% { opacity: 0.45; } }

/* ---------- Tutorial ---------- */
.coach {
  pointer-events: auto;
  width: min(420px, 100%);
  padding: 14px 18px;
  border-radius: 20px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(103, 232, 249, 0.35);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  text-align: center;
}
.coach-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.coach-step { font-size: 11px; font-weight: 700; letter-spacing: 0.16em; color: #67e8f9; }
.coach-skip { border: 0; background: none; color: var(--dim); font-size: 12px; cursor: pointer; padding: 4px; text-decoration: underline; }
.coach-title { font-size: 17px; font-weight: 700; }
.coach-sub { margin-top: 4px; font-size: 13px; line-height: 1.4; color: var(--muted); }
.coach-sub b { color: var(--text); }
.coach-list { margin: 6px auto 0; padding: 0; list-style: none; text-align: left; display: inline-block; }
.coach-list li { padding-left: 16px; position: relative; margin: 2px 0; }
.coach-list li::before { content: ''; position: absolute; left: 2px; top: 0.55em; width: 6px; height: 6px; border-radius: 50%; background: #67e8f9; }
.coach .btn-primary { margin-top: 12px; min-height: 44px; padding: 10px; }

.coach-finger {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 30;
  pointer-events: none;
  transform-origin: 15px 3px;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.6));
  will-change: transform;
}
.coach-finger svg { display: block; }
.coach-finger .ripple {
  position: absolute;
  left: 15px;
  top: 3px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.9);
  opacity: 0;
  transform: translate(-50%, -50%);
}
.btn-ghost.replay { width: 100%; margin-bottom: 12px; }

/* ---------- Overlays & cards ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
           max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background: rgba(2, 6, 23, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow-y: auto;
  touch-action: pan-y;
  animation: fade-in 0.25s ease-out;
  z-index: 10;
}
#help, #board { z-index: 20; }
@keyframes fade-in { from { opacity: 0; } }

.card {
  position: relative;
  width: 100%;
  max-width: 380px;
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  padding: 28px;
  border-radius: 24px;
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
  text-align: center;
}
.card.left { text-align: left; max-width: 420px; }

.badge {
  display: inline-block;
  margin-bottom: 12px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(6, 182, 212, 0.15);
  color: #67e8f9;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.badge.red { background: rgba(244, 63, 94, 0.18); color: #fda4af; }

h1 { margin: 4px 0 8px; font-size: 32px; font-weight: 800; letter-spacing: -0.01em; }
.sub { margin: 0 0 22px; font-size: 14px; line-height: 1.55; color: var(--muted); }
.welcome { margin: -10px 0 18px; font-size: 13px; color: #cbd5e1; }
.welcome b { color: var(--amber); }
.flame { display: inline-block; width: 1em; height: 1em; vertical-align: -0.12em; color: #fb923c; }

.btn-primary {
  width: 100%;
  min-height: 50px;
  padding: 14px;
  border: 0;
  border-radius: 16px;
  background: var(--cyan-hi);
  color: #020617;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.12em;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 10px 25px -5px rgba(6, 182, 212, 0.35);
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover { background: #67e8f9; }
.btn-primary:active { transform: scale(0.99); }
.btn-primary:disabled { opacity: 0.6; cursor: wait; }

.caption { margin-top: 10px; font-size: 12px; color: var(--dim); }

.card-footer {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.card-footer.wrap { flex-wrap: wrap; }
/* Two per row; an odd last button stretches across. */
.card-footer.wrap > .btn-ghost { flex: 1 1 40%; }
.btn-ghost {
  flex: 1;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: #cbd5e1;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.1); }
.btn-ghost:disabled { opacity: 0.5; }

.corner-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.corner-btn:hover { color: #fff; background: rgba(255, 255, 255, 0.12); }
.corner-btn.close { font-size: 20px; line-height: 1; }

/* ---------- Help ---------- */
.howto { list-style: none; margin: 4px 0 14px; padding: 0; }
.howto li { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; font-size: 13.5px; line-height: 1.5; color: #cbd5e1; }
.howto b { color: var(--text); }
.ico {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.06);
}
.ico svg { width: 16px; height: 16px; }
.ico.sat { color: var(--cyan); }
.ico.fire { color: var(--red); }
.ico.pts { color: var(--amber); }
.ico.ufo { color: #a3e635; }
.ico.warn { color: var(--red); }
.ico.go { color: var(--green); }
.ico.up { color: #c4b5fd; }
.keys { margin: 0 0 18px; font-size: 12px; color: var(--dim); }
.keys b { color: var(--muted); }
@media (hover: none) { .keys { display: none; } }

/* ---------- Leaderboard ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tab {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--dim);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}
.tab.active { color: #67e8f9; border-color: rgba(103, 232, 249, 0.35); background: rgba(6, 182, 212, 0.1); }

.leaderboard { margin: 0; padding: 0; list-style: none; font-size: 14px; text-align: left; }
.leaderboard li { display: flex; gap: 10px; padding: 8px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.06); font-variant-numeric: tabular-nums; }
.leaderboard li:last-child { border-bottom: 0; }
.leaderboard li.me { color: var(--amber); }
.leaderboard .pos { color: var(--dim); width: 1.8em; }
.leaderboard .name { flex: 1; font-weight: 600; }
.leaderboard .streak { color: var(--dim); font-size: 12px; font-weight: 400; }
.leaderboard.compact { margin: 4px 0 16px; font-size: 13px; }
.leaderboard.compact li { padding: 6px 4px; }
.leaderboard.compact:empty { display: none; }
.rank { margin: 10px 0; font-size: 13px; color: var(--amber); min-height: 1em; }

/* ---------- Game over ---------- */
.share-box {
  margin: 6px 0 14px;
  padding: 16px 14px 12px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(251, 191, 36, 0.14), rgba(249, 115, 22, 0.06));
  border: 1px solid rgba(251, 191, 36, 0.45);
}
.share-head { margin: 0 0 12px; font-size: 18px; font-weight: 800; line-height: 1.25; color: #fff; }
.share-head b { color: #fbbf24; }
.btn-share {
  width: 100%;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(135deg, #fde047 0%, #fbbf24 45%, #f97316 100%);
  color: #1c0f02;
  font-size: clamp(13px, 3.6vw, 17px);
  font-weight: 900;
  letter-spacing: 0.04em;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 12px 28px -6px rgba(249, 115, 22, 0.6);
  animation: sharepulse 2.2s ease-in-out infinite;
  transition: transform 0.1s, filter 0.15s;
}
.btn-share:hover { filter: brightness(1.08); }
.btn-share:active { transform: scale(0.98); }
.btn-share svg { width: 22px; height: 22px; flex: none; }
@keyframes sharepulse {
  50% { box-shadow: 0 12px 34px -2px rgba(251, 191, 36, 0.75), 0 0 0 4px rgba(251, 191, 36, 0.18); }
}
@media (prefers-reduced-motion: reduce) { .btn-share { animation: none; } }
@media (max-width: 370px) { .btn-share .wide-only { display: none; } .btn-share { padding: 12px 10px; } }
.share-sub { margin-top: 10px; font-size: 12.5px; line-height: 1.4; color: #fcd9a8; }
.share-msg { margin: 8px 0 0; text-align: center; }
.share-msg:empty { margin: 0; min-height: 0; }
/* Play again: still easy to hit, but second to sharing. */
.btn-secondary {
  width: 100%;
  min-height: 48px;
  padding: 12px;
  border-radius: 16px;
  border: 1.5px solid rgba(103, 232, 249, 0.6);
  background: rgba(6, 182, 212, 0.1);
  color: #67e8f9;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.12em;
  cursor: pointer;
  touch-action: manipulation;
}
.btn-secondary:hover { background: rgba(6, 182, 212, 0.2); }
.btn-secondary:disabled { opacity: 0.6; cursor: wait; }
.final { margin: 6px 0 14px; padding: 14px; border-radius: 18px; background: rgba(2, 6, 23, 0.7); border: 1px solid var(--line); }
.final-label { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.final-score { font-size: 40px; font-weight: 800; color: #67e8f9; font-variant-numeric: tabular-nums; }
.pb { font-size: 11px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--amber); }
.stat-line { display: flex; justify-content: center; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.stat-line b { color: var(--text); }

.callsign { margin: 4px 0 14px; padding: 14px; border-radius: 16px; background: rgba(251, 191, 36, 0.07); border: 1px solid rgba(251, 191, 36, 0.25); }
.callsign label { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 600; color: #fde68a; }
.callsign-row { display: flex; gap: 8px; }
.link-btn { display: block; margin: 10px auto 0; border: 0; background: none; color: var(--dim); font: inherit; font-size: 12px; text-decoration: underline; cursor: pointer; }
.edit-name { border: 0; background: none; color: var(--dim); padding: 0 2px; margin-left: 2px; cursor: pointer; vertical-align: -2px; }
.edit-name svg { width: 14px; height: 14px; }
.edit-name:hover, .link-btn:hover { color: #fff; }
.small { font-size: 12px; margin: 0; }
#rename { z-index: 25; }
.callsign input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #020617;
  color: var(--text);
  font: 600 16px var(--sans);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  user-select: text;
  -webkit-user-select: text;
}
.callsign input:focus { outline: none; border-color: var(--amber); }
.btn-save {
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: var(--amber);
  color: #1c1917;
  font-weight: 800;
  letter-spacing: 0.08em;
  cursor: pointer;
}
.msg { margin-top: 6px; font-size: 12px; min-height: 1em; color: var(--muted); }
.msg.err { color: #fda4af; }
.msg.ok { color: var(--green); }

/* ---------- Ranks / XP ---------- */
.rank-tag { display: inline-flex; align-items: center; gap: 4px; color: #fde68a; font-weight: 700; }
.rank-tag .star, .xp .star { width: 13px; height: 13px; color: #fbbf24; }
.xp { margin: 4px 0 14px; padding: 12px 14px; border-radius: 14px; background: rgba(251, 191, 36, 0.06); border: 1px solid rgba(251, 191, 36, 0.2); text-align: left; }
.xp-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.xp-gain { color: var(--green); font-weight: 700; font-variant-numeric: tabular-nums; }
.xp-bar { height: 7px; margin: 8px 0 6px; border-radius: 999px; background: #1e293b; overflow: hidden; }
.xp-bar i { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, #f59e0b, #fde68a); transition: width 1.2s cubic-bezier(0.2, 0.8, 0.2, 1) 0.3s; }
.xp-next { font-size: 12px; color: var(--muted); }
.rankup { margin-top: 8px; text-align: center; font-size: 13px; font-weight: 800; letter-spacing: 0.16em; color: #fbbf24; animation: rankup 1s ease-in-out 3; }
@keyframes rankup { 50% { transform: scale(1.08); text-shadow: 0 0 12px rgba(251, 191, 36, 0.8); } }
.leaderboard .run-date { margin-left: 4px; font-size: 10px; font-weight: 600; color: var(--dim); }
.leaderboard .rk { display: inline-block; min-width: 2.6em; margin-right: 6px; font-size: 10px; font-weight: 700; letter-spacing: 0.06em; color: #fbbf24; opacity: 0.85; }

/* ---------- Small screens ---------- */
@media (max-width: 700px) {
  .card.upg-card { padding: 18px 14px; }
  .upg-tree { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .upg-branch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .upg-branch h3 { grid-column: 1 / -1; margin: 0; }
  .upg-branch.upg-sci { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 8px; }
  .upg-node { padding: 7px 8px; }
  .upg-node b { font-size: 12px; }
  .upg-node span { font-size: 10.5px; }
}
@media (max-height: 500px) {
  .card.upg-card { padding: 12px 16px; }
  .upg-node span { font-size: 10.5px; }
  .upg-node { padding: 6px 8px; }
  .upg-tree { margin-bottom: 8px; }
}
@media (max-width: 420px) {
  .pill { padding: 6px 12px; min-height: 38px; }
  .pill-label { display: none; }
  .hud-top .pill, .hud-top .launch, .hud-top .next-sat { height: 40px; min-height: 40px; }
  .hud-top .pill.controls .icon-btn { width: 30px; height: 30px; }
  .launch { padding: 6px 12px; gap: 6px; letter-spacing: 0.06em; }
  .launch svg { display: none; }
  .score-pill { flex-direction: column; align-items: flex-start; justify-content: center; gap: 1px; padding: 3px 11px; }
  .score-pill .pill-value { font-size: 16px; line-height: 1.05; }
  .hud-rank { font-size: 9px; letter-spacing: 0.1em; gap: 3px; }
  .hud-rank .star { width: 9px; height: 9px; }
  .hud-rank .rk-full { display: none; }
  .hud-rank .rk-abbr { display: inline; }
  .ammo { gap: 4px; }
  .ammo .msl { width: 10px; height: 22px; }
  .icon-btn { width: 32px; height: 32px; }
  .alert.hint { font-size: 9.5px; padding: 7px 12px; letter-spacing: 0.05em; }
  .hud-top, .hud-right { gap: 6px; }
  .ammo-pill { padding: 6px 9px; }
  .launch { min-height: 38px; padding: 6px 12px; font-size: 12px; letter-spacing: 0.08em; gap: 6px; }
  .next-sat { min-height: 38px; padding: 6px 10px; }
  .card { padding: 22px 20px; }
  h1 { font-size: 28px; }
  .hud-sub { gap: 6px; margin-top: 6px; }
  .hud-sub .pill { height: 30px; min-height: 30px; padding: 3px 10px; }
  .lv-bar { width: 36px; }
  .people { gap: 2px; }
  .people svg { width: 12px; height: 18px; }
  .earth-hp { font-size: 11px; }
  .alert { top: calc(max(14px, env(safe-area-inset-top)) + 84px); }
}

@media (max-width: 380px) {
  #hud { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .hud-top, .hud-right { gap: 5px; }
  .hud-top > .pill:first-child { padding: 6px 10px; }
  .launch { padding: 6px 10px; gap: 5px; letter-spacing: 0.04em; }
  .launch svg { display: none; }
  .queue i { width: 6px; height: 6px; }
  .ammo-pill { padding: 6px 7px; }
  .ammo { gap: 3px; }
  .ammo .msl { width: 9px; height: 20px; }
  .hud-top .pill.controls .icon-btn { width: 28px; height: 28px; }
  .lv-bar { width: 40px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .card { padding: 18px 22px; }
  .sub { margin-bottom: 14px; }
  .final-score { font-size: 32px; }
}

/* Short screens (phones in landscape): compact tutorial card */
@media (max-height: 500px) {
  .coach { padding: 8px 14px; border-radius: 16px; }
  .coach-head { margin-bottom: 0; }
  .coach-title { font-size: 15px; }
  .coach-sub { font-size: 12px; line-height: 1.3; }
  .coach .btn-primary { margin-top: 6px; min-height: 38px; padding: 6px; }
}

/* ---------- Action buttons: LAUNCH (bottom-left) · UPGRADE (bottom-right) ---------- */
#hud { --act-h: 64px; }
.hud-actions {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
}
.act-wrap { position: relative; width: min(calc(50% - 6px), 200px); }
/* Soft pulsing glow in the screen corner behind a ready button. */
.act-wrap::before {
  content: '';
  position: absolute;
  width: 260px;
  height: 260px;
  bottom: -110px;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.act-left::before { left: -110px; background: radial-gradient(circle, rgba(74, 222, 128, 0.55), rgba(74, 222, 128, 0) 65%); }
.act-right::before { right: -110px; background: radial-gradient(circle, rgba(167, 139, 250, 0.6), rgba(167, 139, 250, 0) 65%); }
.act-wrap.ready::before { opacity: 1; animation: cornerglow 1.1s ease-in-out infinite; }
@keyframes cornerglow { 50% { opacity: 0.35; transform: scale(0.85); } }

.act-btn {
  position: relative;
  pointer-events: auto;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  gap: 10px;
  box-sizing: border-box;
  height: var(--act-h);
  width: 100%;
  padding: 0 18px 0 12px;
  border-radius: 20px;
  border: 2px solid rgba(148, 163, 184, 0.35);
  background: rgba(2, 6, 23, 0.75);
  color: #94a3b8;
  font: inherit;
  text-align: left;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.act-ico { display: flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 12px; background: rgba(255, 255, 255, 0.07); flex: none; }
.act-ico svg { width: 22px; height: 22px; }
.act-text { display: flex; flex-direction: column; line-height: 1.1; }
.act-text b { font-size: 16px; font-weight: 800; letter-spacing: 0.1em; }
.act-text small { margin-top: 3px; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; opacity: 0.85; font-variant-numeric: tabular-nums; white-space: nowrap; }
.act-badge {
  position: absolute;
  top: -10px;
  min-width: 26px;
  height: 26px;
  padding: 0 7px;
  box-sizing: border-box;
  border-radius: 13px;
  border: 2px solid #020617;
  font-size: 14px;
  font-weight: 800;
  line-height: 22px;
  text-align: center;
  color: #020617;
}

/* LAUNCH ready: solid green, flashing */
.launch-btn.ready { color: #022c22; background: #4ade80; border-color: #bbf7d0; animation: flashgreen 0.9s ease-in-out infinite; }
.launch-btn.ready .act-ico { background: rgba(2, 44, 34, 0.15); }
.launch-btn .act-badge { background: #bbf7d0; left: -6px; }
.launch-btn { transform-origin: left bottom; }
.upgrade-btn { transform-origin: right bottom; }
.launch-btn.cooling { opacity: 0.6; animation: none; }
@keyframes flashgreen {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.9), 0 0 24px rgba(74, 222, 128, 0.6); transform: scale(1); }
  50% { box-shadow: 0 0 0 10px rgba(74, 222, 128, 0), 0 0 40px rgba(74, 222, 128, 0.9); transform: scale(1.06); background: #86efac; }
}

/* UPGRADE ready: solid purple, flashing */
.upgrade-btn.ready { color: #1e1b4b; background: #a78bfa; border-color: #ddd6fe; animation: flashpurple 0.9s ease-in-out infinite; }
.upgrade-btn.ready .act-ico { background: rgba(30, 27, 75, 0.15); }
.upgrade-btn .act-badge { background: #fde047; right: -6px; }
.upgrade-btn.maxed { opacity: 0.55; }
@keyframes flashpurple {
  0%, 100% { box-shadow: 0 0 0 0 rgba(167, 139, 250, 0.9), 0 0 24px rgba(167, 139, 250, 0.6); transform: scale(1); }
  50% { box-shadow: 0 0 0 10px rgba(167, 139, 250, 0), 0 0 40px rgba(167, 139, 250, 0.9); transform: scale(1.06); background: #c4b5fd; }
}

/* Bouncing "TAP TO ..." arrow above a ready button */
.cue {
  position: absolute;
  bottom: calc(100% + 8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  pointer-events: none;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  white-space: nowrap;
  animation: cuebounce 0.7s ease-in-out infinite;
}
.cue span { font-size: 11px; padding: 5px 10px; border-radius: 999px; background: rgba(2, 6, 23, 0.85); border: 1px solid currentColor; }
.cue-arrow { width: 30px; height: 30px; filter: drop-shadow(0 0 6px currentColor); }
.cue-launch { left: 0; width: 100%; color: #4ade80; }
.cue-upgrade { right: 0; width: 100%; color: #c4b5fd; }
@keyframes cuebounce { 50% { transform: translateY(8px); } }

/* Tutorial card sits above the action buttons (and their bouncing cue) */
.hud-bottom { padding-bottom: calc(var(--act-h) + 14px); }
.hud-bottom:has(.coach:not(.hidden)) { padding-bottom: calc(var(--act-h) + 96px); }

@media (max-width: 380px) {
  .act-btn { gap: 8px; padding: 0 10px 0 8px; }
  .act-text small { font-size: 10px; letter-spacing: 0.03em; }
  .act-ico { width: 32px; height: 32px; }
  .act-text b { font-size: 14px; }
}
@media (max-height: 500px) {
  #hud { --act-h: 54px; }
  /* Landscape: buttons sit in the corners beside the play area, card stays at the bottom. */
  .hud-bottom, .hud-bottom:has(.coach:not(.hidden)) { padding-bottom: 0; }
}
/* Wide screens (landscape phones, foldables, tablets, desktop): thumbs hold
   the sides, so the buttons sit at mid-height on the left and right edges. */
#hud.side-actions .hud-actions { top: 50%; bottom: auto; transform: translateY(-50%); align-items: center; }
#hud.side-actions .act-wrap { width: 118px; }
#hud.side-actions .act-btn { flex-direction: column; justify-content: center; height: auto; min-height: 128px; padding: 14px 8px; gap: 8px; border-radius: 26px; text-align: center; }
#hud.side-actions .act-ico { width: 46px; height: 46px; border-radius: 14px; }
#hud.side-actions .act-ico svg { width: 26px; height: 26px; }
#hud.side-actions .act-text { align-items: center; }
#hud.side-actions .act-text b { font-size: 15px; letter-spacing: 0.08em; }
#hud.side-actions .act-text small { font-size: 10.5px; letter-spacing: 0.03em; white-space: normal; }
#hud.side-actions .launch-btn { transform-origin: left center; }
#hud.side-actions .upgrade-btn { transform-origin: right center; }
#hud.side-actions .act-wrap::before { bottom: auto; top: 50%; margin-top: -130px; }
#hud.side-actions .act-left::before { left: -150px; }
#hud.side-actions .act-right::before { right: -150px; }
/* Cue sits beside the button, arrow pointing at it */
#hud.side-actions .cue { bottom: auto; top: 50%; width: auto; flex-direction: row; gap: 4px; animation-name: cuebounceX; }
#hud.side-actions .cue-launch { left: calc(100% + 6px); right: auto; flex-direction: row-reverse; }
#hud.side-actions .cue-upgrade { right: calc(100% + 6px); left: auto; }
#hud.side-actions .cue-launch .cue-arrow { transform: rotate(90deg); }
#hud.side-actions .cue-upgrade .cue-arrow { transform: rotate(-90deg); }
#hud.side-actions .cue-launch { --dx: -8px; }
#hud.side-actions .cue-upgrade { --dx: 8px; }
@keyframes cuebounceX { 0%, 100% { transform: translateY(-50%); } 50% { transform: translate(var(--dx), -50%); } }
#hud.side-actions .hud-bottom, #hud.side-actions .hud-bottom:has(.coach:not(.hidden)) { padding-bottom: 0; }
#hud.side-actions .hud-bottom .coach { max-width: calc(100% - 2 * 150px); }
@media (max-height: 420px) {
  #hud.side-actions .act-btn { min-height: 104px; padding: 10px 6px; gap: 5px; }
  #hud.side-actions .act-ico { width: 38px; height: 38px; }
  #hud.side-actions .act-wrap { width: 108px; }
}

@media (prefers-reduced-motion: reduce) {
  #hud.side-actions .cue,
  .launch-btn.ready, .upgrade-btn.ready, .cue, .act-wrap.ready::before { animation: none; }
}

/* ---------- "Best on mobile" notice (computers only) ---------- */
.card.device-card { max-width: 440px; }
.device-ico { width: 52px; height: 52px; margin: 6px auto 4px; color: #67e8f9; }
.device-ico svg { width: 100%; height: 100%; }
.device-title { margin: 4px 0 8px; font-size: 22px; }
.device-sub { margin: 0 0 16px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.qr-box { display: flex; align-items: center; gap: 16px; padding: 14px; margin-bottom: 16px; border-radius: 16px; background: rgba(103, 232, 249, 0.08); border: 1px solid rgba(103, 232, 249, 0.3); text-align: left; }
.qr { width: 132px; height: 132px; flex: none; border-radius: 10px; background: #fff; padding: 4px; box-sizing: border-box; }
.qr-text { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.qr-text b { color: var(--text); font-size: 15px; }
.qr-text code { color: #67e8f9; font-size: 14px; font-weight: 700; font-family: inherit; }
.device-keys { margin-bottom: 18px; font-size: 13px; line-height: 1.5; color: var(--muted); }
.device-keys b { color: var(--text); }
.device-keys span { display: block; margin-top: 4px; }
.device-keys kbd { display: inline-block; min-width: 1.6em; padding: 1px 6px; border-radius: 6px; border: 1px solid rgba(255, 255, 255, 0.25); background: rgba(255, 255, 255, 0.06); font: inherit; font-size: 12px; font-weight: 700; color: var(--text); }
