:root {
  --cyan: #51e9ff;
  --magenta: #ff3df0;
  --void: #b06bff;
  --gold: #ffd447;
  --danger: #ff3b6b;
  --xp: #7cffb2;
  --bg0: #05060f;
  --panel: rgba(12, 16, 38, 0.82);
  --panel-border: rgba(81, 233, 255, 0.35);
  --text: #dfe8ff;
  --muted: #8aa0c8;
  --font: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  background: var(--bg0);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app { position: fixed; inset: 0; }

#game {
  display: block;
  width: 100%; height: 100%;
  background: var(--bg0);
  cursor: crosshair;
}

.hidden { display: none !important; }

/* ---------------------------------------------------------------- HUD */
#hud {
  position: absolute; inset: 0;
  pointer-events: none;
  padding: 14px clamp(12px, 3vw, 36px);
  display: flex; flex-direction: column; justify-content: space-between;
  font-variant-numeric: tabular-nums;
}
.hud-top { display: flex; justify-content: space-between; align-items: flex-start; }
.hud-left { display: flex; gap: 10px; }
.chip {
  background: var(--panel); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px; padding: 6px 10px; display: flex; flex-direction: column;
  line-height: 1.1; min-width: 64px;
}
.chip-label { font-size: 9px; letter-spacing: 2px; color: var(--muted); }
.chip span:last-child { font-size: 18px; font-weight: 700; }
.chip.revive { border-color: rgba(255,106,61,0.55); box-shadow: 0 0 14px -4px var(--fire, #ff6a3d); }
.chip.revive .chip-label { color: #ff8a5d; }
.chip.revive span:last-child { color: #ff6a3d; }

.hud-center { text-align: center; }
#timer {
  font-size: clamp(26px, 5vw, 42px); font-weight: 800; letter-spacing: 2px;
  color: #fff; text-shadow: 0 0 18px rgba(81,233,255,0.6);
}
/* Boss bar is taken out of the HUD flex row and absolutely centred under the
   timer (relative to #hud, which is position:absolute inset:0). In portrait the
   old in-flow min(76vw,520px) block was pushed partly off-screen by the left/right
   HUD columns; centring on #hud keeps it fully on-screen at every aspect ratio. */
#boss-bar {
  position: absolute; left: 50%; transform: translateX(-50%);
  top: clamp(54px, 7.5vh, 78px);
  width: min(76vw, 520px); max-width: calc(100vw - 24px);
  animation: boss-pulse 1.4s ease-in-out infinite;
}
#boss-name {
  font-size: 13px; font-weight: 800; letter-spacing: 4px; color: var(--danger);
  text-shadow: 0 0 10px rgba(255,59,107,0.8), 0 0 22px rgba(255,59,107,0.4);
}
.boss-track {
  height: 11px; background: rgba(0,0,0,0.55); border: 1px solid var(--danger); border-radius: 7px;
  overflow: hidden; margin-top: 3px; position: relative;
  box-shadow: 0 0 14px rgba(255,59,107,0.45), inset 0 0 8px rgba(0,0,0,0.6);
}
.boss-track i {
  display: block; height: 100%; width: 100%;
  background: linear-gradient(90deg, #ff2d5e, #ff6a3d 60%, #ffd447);
  box-shadow: 0 0 12px rgba(255,120,80,0.8);
  transition: width 0.1s;
}
/* Segment ticks + a travelling sheen so the gauge reads as a heavy boss meter. */
.boss-track::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(90deg, transparent 0, transparent calc(25% - 1px), rgba(6,10,22,0.85) calc(25% - 1px), rgba(6,10,22,0.85) 25%);
}
@keyframes boss-pulse {
  0%, 100% { filter: drop-shadow(0 0 2px rgba(255,59,107,0.4)); }
  50% { filter: drop-shadow(0 0 8px rgba(255,59,107,0.85)); }
}

.hud-right { text-align: right; }
#score { font-size: clamp(22px, 4vw, 34px); font-weight: 800; color: var(--gold); text-shadow: 0 0 14px rgba(255,212,71,0.5); }
.mult { font-size: 16px; font-weight: 700; color: var(--magenta); }
.hiscore { font-size: 10px; letter-spacing: 2px; color: var(--muted); margin-top: 2px; }

.hud-bottom { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; }
.bars { flex: 1; max-width: 520px; display: flex; flex-direction: column; gap: 8px; }
.bar {
  position: relative; height: 20px; border-radius: 10px;
  background: rgba(0,0,0,0.45); border: 1px solid rgba(255,255,255,0.1);
  overflow: hidden;
}
.bar i { position: absolute; inset: 0; width: 100%; transform-origin: left; border-radius: 10px; transition: width 0.12s ease-out; }
.bar.health i { background: linear-gradient(90deg, #ff3b6b, #ff8a3d); box-shadow: 0 0 12px rgba(255,59,107,0.6); }
.bar.xp { height: 14px; }
.bar.xp i { background: linear-gradient(90deg, #7cffb2, #51e9ff); box-shadow: 0 0 12px rgba(124,255,178,0.6); }
.bar.overdrive { height: 12px; }
.bar.overdrive i { background: linear-gradient(90deg, #ffd447, #ff8a3d); box-shadow: 0 0 10px rgba(255,212,71,0.5); }
.bar.overdrive span { font-size: 9px; letter-spacing: 2px; }
.bar.overdrive.ready i { animation: odpulse 0.7s infinite; }
.bar.overdrive.active { box-shadow: 0 0 18px rgba(255,138,61,0.9); }
.bar.overdrive.active i { background: linear-gradient(90deg, #fff, #ffd447, #ff3b6b); animation: odpulse 0.35s infinite; }
@keyframes odpulse { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.6); } }

/* Weapon loadout strip */
.loadout { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.loadout .w {
  position: relative; width: 30px; height: 30px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.14);
}
.loadout .w.evolved { border-color: var(--gold); box-shadow: 0 0 10px rgba(255,212,71,0.6); }
.loadout .w b {
  position: absolute; right: -3px; bottom: -4px; font-size: 9px; font-weight: 800;
  color: #fff; background: rgba(0,0,0,0.7); border-radius: 6px; padding: 0 3px; line-height: 13px;
}
.bar span {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; letter-spacing: 1px; text-shadow: 0 1px 2px #000;
}

.abilities { display: flex; gap: 12px; }
.ability { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.ability .ring { position: relative; width: 48px; height: 48px; }
.ability svg { width: 48px; height: 48px; transform: rotate(-90deg); }
.ability .track { fill: rgba(0,0,0,0.5); stroke: rgba(255,255,255,0.12); stroke-width: 4; }
.ability .arc { fill: none; stroke: var(--cyan); stroke-width: 4; stroke-linecap: round; stroke-dasharray: 119.4; stroke-dashoffset: 119.4; transition: stroke-dashoffset 0.1s; }
#ability-sing .arc { stroke: var(--void); }
.ability .ico { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.ability.ready .ico { animation: pulse 1s infinite; }
.ability.ready svg .arc { filter: drop-shadow(0 0 6px currentColor); }
.ability .key { font-size: 8px; letter-spacing: 1px; color: var(--muted); }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.18); } }

#combo-pop {
  position: absolute; top: 26%; left: 50%; transform: translateX(-50%);
  font-size: 40px; font-weight: 900; color: var(--magenta);
  text-shadow: 0 0 20px rgba(255,61,240,0.8); opacity: 0; pointer-events: none;
}
#combo-pop.show { animation: comboPop 0.6s ease-out; }
@keyframes comboPop { 0% { opacity: 0; transform: translateX(-50%) scale(0.5); } 30% { opacity: 1; transform: translateX(-50%) scale(1.2); } 100% { opacity: 0; transform: translateX(-50%) scale(1) translateY(-30px); } }

/* ---------------------------------------------------------- Overlays */
.overlay {
  position: absolute; inset: 0; z-index: 10;
  /* flex-start + margin:auto on the panel keeps short panels centred while
     letting tall panels (many commendations, the level-up draft, the Hangar)
     scroll from the top instead of overflowing off-screen with unreachable
     buttons. Vertical padding respects notch / home-indicator safe areas. */
  display: flex; align-items: flex-start; justify-content: center;
  overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  background: radial-gradient(circle at 50% 40%, rgba(10,14,40,0.75), rgba(3,4,12,0.94));
  backdrop-filter: blur(3px);
  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));
}
.panel {
  width: min(560px, 94vw);
  margin: auto; /* centre within the scroll area; top stays reachable when tall */
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: clamp(20px, 4vw, 38px);
  text-align: center;
  box-shadow: 0 0 60px rgba(81,233,255,0.12), inset 0 0 40px rgba(81,233,255,0.04);
}

/* Auto-fit overlays: never page-scroll — the panel is centred and scaled down
   just enough (never up) to fit the viewport, so everything is always on screen.
   The Hangar is intentionally NOT a .fit overlay: it keeps its own internal
   scroll (see .hangar-body) because its content is meant to be browsed. The
   scale factor itself is applied from main.js (fitOverlays); this only sets up
   the absolute, centred, transform-friendly positioning. */
.overlay.fit { display: block; overflow: hidden; }
.overlay.fit .panel {
  position: absolute; top: 50%; left: 50%; margin: 0;
  transform: translate(-50%, -50%);
  transform-origin: center center;
  will-change: transform;
}
.title {
  font-size: clamp(30px, 7vw, 54px); font-weight: 900; letter-spacing: 3px;
  background: linear-gradient(90deg, #51e9ff, #b06bff, #ff3df0);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 24px rgba(176,107,255,0.5));
  line-height: 1.05;
}
.tagline { color: var(--muted); margin: 8px 0 22px; font-size: clamp(13px, 2.5vw, 16px); letter-spacing: 1px; }
.features { display: grid; gap: 10px; margin-bottom: 24px; text-align: left; }
.features > div { background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.07); border-radius: 10px; padding: 10px 14px; }
.features b { color: var(--cyan); font-size: 15px; }
.features span { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }

.btn {
  display: inline-block; cursor: pointer; pointer-events: auto;
  font-family: var(--font); font-weight: 800; letter-spacing: 2px;
  font-size: clamp(16px, 3vw, 20px);
  color: #04121a; background: linear-gradient(90deg, #51e9ff, #7cffb2);
  border: none; border-radius: 12px; padding: 14px 40px; margin: 6px;
  box-shadow: 0 0 24px rgba(81,233,255,0.4); transition: transform 0.1s, box-shadow 0.2s;
}
.btn:hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 0 36px rgba(81,233,255,0.7); }
.btn:active { transform: scale(0.97); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid rgba(255,255,255,0.15); box-shadow: none; }
.btn-ghost:hover { color: #fff; box-shadow: none; }

.controls-hint { display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: center; margin-top: 20px; color: var(--muted); font-size: 12px; }
kbd { background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2); border-radius: 5px; padding: 1px 7px; font-size: 11px; color: #fff; }
.settings-row { display: flex; gap: 18px; justify-content: center; margin-top: 18px; color: var(--muted); font-size: 13px; }
.settings-row label { display: flex; align-items: center; gap: 6px; cursor: pointer; pointer-events: auto; }
.lang-field { gap: 8px; }
.lang-select {
  pointer-events: auto;
  appearance: none;
  background: rgba(12, 18, 38, 0.85);
  color: var(--text, #eaf0ff);
  border: 1px solid rgba(120, 150, 220, 0.35);
  border-radius: 8px;
  padding: 5px 28px 5px 10px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 12px center, right 7px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.lang-select:hover { border-color: rgba(150, 180, 255, 0.6); }
.lang-select:focus-visible { outline: none; border-color: var(--gold, #ffd447); box-shadow: 0 0 0 2px rgba(255, 212, 71, 0.3); }
.lang-select option { background: #0c1226; color: var(--text, #eaf0ff); }

/* Level up */
.levelup-panel { width: min(900px, 96vw); }
.levelup-title { font-size: clamp(26px, 5vw, 40px); font-weight: 900; letter-spacing: 4px; color: var(--gold); text-shadow: 0 0 20px rgba(255,212,71,0.5); }
.levelup-sub { color: var(--muted); margin: 4px 0 20px; letter-spacing: 1px; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.card {
  cursor: pointer; pointer-events: auto;
  background: rgba(255,255,255,0.03);
  border: 2px solid var(--rarity, #51e9ff); border-radius: 14px;
  padding: 20px 14px; text-align: center;
  transition: transform 0.12s, box-shadow 0.2s, background 0.2s;
  box-shadow: 0 0 0 rgba(0,0,0,0);
}
.card:hover { transform: translateY(-6px); background: rgba(255,255,255,0.07); box-shadow: 0 0 30px var(--rarity); }
.card .icon { font-size: 40px; }
.card .name { font-weight: 800; font-size: 16px; margin: 8px 0 4px; }
.card .desc { color: var(--muted); font-size: 12.5px; min-height: 48px; }
.card .rarity { font-size: 10px; letter-spacing: 2px; font-weight: 700; color: var(--rarity); margin-top: 8px; text-transform: uppercase; }
.card .num { position: absolute; }
.card .kind {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  font-size: 9px; letter-spacing: 2px; font-weight: 800; text-transform: uppercase;
  color: var(--bg0); background: var(--rarity); border-radius: 20px; padding: 2px 10px;
}
.card { position: relative; padding-top: 28px; }
.card.evolve {
  border-width: 3px;
  background: linear-gradient(180deg, rgba(255,212,71,0.12), rgba(255,255,255,0.03));
  animation: evoglow 1.4s infinite;
}
@keyframes evoglow { 0%,100% { box-shadow: 0 0 10px var(--rarity); } 50% { box-shadow: 0 0 28px var(--rarity); } }
.card .lvl { font-size: 11px; color: var(--xp); font-weight: 700; letter-spacing: 1px; }
.draft-tools { display: flex; gap: 12px; justify-content: center; margin-top: 18px; }
.btn-sm { padding: 8px 16px; font-size: 13px; letter-spacing: 1px; }
.btn-sm b { color: var(--gold); }
.btn-sm:disabled { opacity: 0.4; pointer-events: none; }
.cards.banish-mode .card { border-style: dashed; }
.cards.banish-mode .card:hover { box-shadow: 0 0 30px var(--danger); border-color: var(--danger); }
.draft-hint { margin-top: 18px; color: var(--muted); font-size: 12px; }

.run-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 20px; margin: 18px auto; max-width: 320px; text-align: left; color: var(--muted); font-size: 14px; }
.run-stats b { color: #fff; float: right; }
.go-score { font-size: clamp(40px, 9vw, 68px); font-weight: 900; color: var(--gold); text-shadow: 0 0 24px rgba(255,212,71,0.5); }
#go-title { font-size: clamp(24px, 5vw, 38px); font-weight: 900; letter-spacing: 3px; color: var(--danger); }
.newbest { color: var(--gold); font-weight: 900; letter-spacing: 3px; animation: pulse 0.8s infinite; margin-top: 6px; }

/* Stardust + ship picker + hangar */
.stardust-pill {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--gold); font-weight: 700; font-size: 13px; letter-spacing: 1px;
  background: rgba(255,212,71,0.08); border: 1px solid rgba(255,212,71,0.35);
  border-radius: 20px; padding: 5px 14px; margin-bottom: 12px;
}
.stardust-pill b { color: #fff; }
.stardust-pill.big { font-size: 15px; padding: 7px 16px; margin: 0; }

.ship-pick {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px; padding: 10px 14px; margin: 0 0 18px;
}
.ship-nav {
  cursor: pointer; pointer-events: auto; background: rgba(255,255,255,0.06);
  color: var(--cyan); border: 1px solid rgba(255,255,255,0.12); border-radius: 10px;
  font-size: 18px; width: 40px; height: 40px; flex: none; transition: background 0.15s, transform 0.1s;
}
.ship-nav:hover { background: rgba(81,233,255,0.15); transform: scale(1.06); }
.ship-nav:active { transform: scale(0.94); }
.ship-pick-mid { display: flex; align-items: center; gap: 12px; min-width: 240px; }
.ship-pick-icon { font-size: 34px; line-height: 1; filter: drop-shadow(0 0 10px currentColor); }
.ship-pick-info { text-align: left; }
.ship-pick-name { font-weight: 800; font-size: 18px; color: #fff; }
.ship-pick-tag { color: var(--muted); font-size: 12px; margin-top: 2px; }
.start-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.go-stardust { color: var(--gold); font-weight: 700; letter-spacing: 1px; margin: 6px 0 2px; font-size: 16px; }
.go-stardust.none { opacity: 0.5; }

/* Hangar overlay */
.hangar-panel {
  width: min(760px, 96vw);
  max-height: 92vh; /* fallback for browsers without dvh */
  max-height: 92dvh; /* dynamic viewport: fits the *visible* area on mobile so
                        the panel never overflows behind the URL bar (which made
                        the Hangar look stretched/cut off in portrait) */
  display: flex; flex-direction: column;
}
.hangar-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.hangar-title { font-size: clamp(22px, 4vw, 34px); font-weight: 900; letter-spacing: 3px; color: var(--cyan); text-shadow: 0 0 20px rgba(81,233,255,0.4); }
/* Tabs wrap instead of overflowing: on a narrow phone the row reflows to two
   lines (each stretched to fill) rather than being clipped off-screen. */
.hangar-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.pilot-record {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px;
}
.pilot-record .rec {
  flex: 1; min-width: 72px; display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 8px 6px; border-radius: 10px;
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.08);
}
.pilot-record .rec-k {
  font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted);
}
.pilot-record .rec b { font-size: 17px; font-weight: 900; color: #fff; }
.tab {
  flex: 1 1 auto; min-width: 116px; cursor: pointer; pointer-events: auto; font-family: var(--font);
  font-weight: 800; letter-spacing: 2px; font-size: 13px; color: var(--muted);
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px; padding: 10px; transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.tab.active { color: var(--bg0); background: linear-gradient(90deg, #51e9ff, #7cffb2); border-color: transparent; }
/* flex:1 + min-height:0 lets this scroll region actually shrink inside the capped
   column panel; without min-height:0 the default min-height:auto keeps it at full
   content height, pushing the DONE button off-screen on phones (the mobile bug). */
.hangar-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 2px; margin-bottom: 14px; }

.ship-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.ship-card {
  text-align: left; background: rgba(255,255,255,0.03);
  border: 2px solid rgba(255,255,255,0.1); border-radius: 14px; padding: 14px;
  transition: border-color 0.15s, box-shadow 0.2s, background 0.2s;
}
.ship-card.selected { border-color: var(--accent); box-shadow: 0 0 24px -6px var(--accent); background: rgba(255,255,255,0.05); }
.ship-card.locked { opacity: 0.82; }
.ship-card-head { display: flex; align-items: center; gap: 8px; }
.ship-ico { font-size: 26px; filter: drop-shadow(0 0 8px var(--accent)); }
.ship-name { font-weight: 800; font-size: 17px; color: #fff; }
.ship-tag { color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: 1px; margin: 4px 0 6px; text-transform: uppercase; }
.ship-desc { color: var(--muted); font-size: 12.5px; min-height: 52px; }
.ship-weapon { color: var(--muted); font-size: 12px; margin: 6px 0 10px; }
.ship-weapon b { color: var(--cyan); }
.ship-action { display: flex; justify-content: flex-end; }
.ship-badge { color: var(--accent); font-weight: 800; letter-spacing: 1px; font-size: 13px; align-self: center; }

.meta-grid { display: flex; flex-direction: column; gap: 8px; }
.meta-row {
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px; padding: 10px 14px;
}
.meta-row.maxed { border-color: rgba(255,212,71,0.4); background: rgba(255,212,71,0.06); }
.meta-ico { font-size: 24px; flex: none; width: 30px; text-align: center; }
.meta-main { flex: 1; min-width: 0; }
.meta-name { font-weight: 800; color: #fff; font-size: 14.5px; }
.meta-lvl { color: var(--muted); font-weight: 700; font-size: 11px; margin-left: 6px; }
.meta-desc { color: var(--muted); font-size: 12px; margin: 2px 0 6px; }
.meta-pips { display: flex; gap: 4px; }
.meta-pips .pip { width: 16px; height: 5px; border-radius: 3px; background: rgba(255,255,255,0.12); }
.meta-pips .pip.on { background: linear-gradient(90deg, var(--cyan), var(--xp)); }
.meta-action { flex: none; }
.meta-max { color: var(--gold); font-weight: 800; letter-spacing: 1px; font-size: 13px; }

/* Directives — opt-in challenge modifiers */
.directive-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.directive-note { grid-column: 1 / -1; color: var(--muted); font-size: 12.5px; text-align: center; padding: 0 0 4px; }
.directive-note b { color: var(--gold); }
.directive-card {
  text-align: left; cursor: pointer; pointer-events: auto;
  background: rgba(255,255,255,0.03); border: 2px solid rgba(255,255,255,0.1);
  border-radius: 12px; padding: 12px; transition: border-color 0.15s, box-shadow 0.2s, background 0.2s;
}
.directive-card.active { border-color: var(--danger); box-shadow: 0 0 22px -8px var(--danger); background: rgba(255,59,107,0.08); }
.dir-head { display: flex; align-items: center; gap: 8px; }
.dir-ico { font-size: 22px; }
.dir-name { font-weight: 800; color: #fff; font-size: 14.5px; flex: 1; }
.dir-reward { color: var(--gold); font-weight: 800; font-size: 12px; }
.dir-desc { color: var(--muted); font-size: 12.5px; margin: 6px 0 8px; min-height: 34px; }
.dir-foot { display: flex; align-items: center; justify-content: space-between; }
.dir-risk { color: var(--danger); font-size: 11px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; }
.dir-toggle { font-size: 11px; font-weight: 800; letter-spacing: 1.5px; color: var(--muted); border: 1px solid rgba(255,255,255,0.15); border-radius: 6px; padding: 3px 8px; }
.directive-card.active .dir-toggle { color: var(--bg0); background: var(--danger); border-color: transparent; }

/* HUD directive chip */
.chip.directive { border-color: rgba(255,59,107,0.5); }
.chip.directive .chip-label { color: #ff7a9b; }
.chip.directive span:last-child { color: var(--danger); }

/* Start-screen directive summary */
.start-directives {
  display: inline-flex; align-items: center; gap: 7px; flex-wrap: wrap; justify-content: center;
  margin: 0 0 12px; padding: 6px 14px; border-radius: 20px;
  background: rgba(255,59,107,0.08); border: 1px solid rgba(255,59,107,0.3);
}
.start-directives .sd-label { font-size: 10px; font-weight: 800; letter-spacing: 2px; color: #ff7a9b; }
.start-directives .sd-ico { font-size: 15px; }
.start-directives .sd-mult { color: var(--gold); font-weight: 800; font-size: 12px; }

/* Codex — commendation gallery */
.codex-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.codex-progress { grid-column: 1 / -1; color: var(--muted); font-size: 13px; text-align: center; padding: 2px 0 6px; }
.codex-progress b { color: var(--gold); font-size: 16px; }
.codex-cell {
  display: flex; align-items: center; gap: 10px; text-align: left;
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px; padding: 10px 12px;
}
.codex-cell.earned { border-color: rgba(255,212,71,0.4); background: rgba(255,212,71,0.06); }
.codex-cell.locked { opacity: 0.6; }
.cx-ico { font-size: 22px; flex: none; width: 28px; text-align: center; }
.cx-main { flex: 1; min-width: 0; }
.cx-name { font-weight: 800; color: #fff; font-size: 13.5px; }
.codex-cell.locked .cx-name { color: var(--muted); }
.cx-desc { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.cx-reward { flex: none; color: var(--gold); font-weight: 800; font-size: 12px; }

/* Game-over commendation strip */
.go-commends { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 2px; }
.go-commends .commend {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  background: rgba(255,212,71,0.08); border: 1px solid rgba(255,212,71,0.3);
  border-radius: 10px; padding: 6px 12px;
}
.go-commends .c-ico { font-size: 18px; }
.go-commends .c-name { font-weight: 800; color: #fff; font-size: 13px; }
.go-commends .c-rew { color: var(--gold); font-weight: 800; font-size: 12px; }

/* Nebula (idle) accents — a cool violet to contrast Stardust's gold */
.go-nebula { color: var(--void); font-weight: 700; font-size: 13.5px; margin: 2px 0 4px; }
.go-nebula b { color: #fff; }
.start-pills { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 12px; }
.start-pills .stardust-pill { margin-bottom: 0; }
.nebula-pill {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--void); font-weight: 700; font-size: 13px; letter-spacing: 1px;
  background: rgba(176,107,255,0.08); border: 1px solid rgba(176,107,255,0.35);
  border-radius: 20px; padding: 5px 14px;
  cursor: pointer; pointer-events: auto; transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.nebula-pill:hover { background: rgba(176,107,255,0.16); border-color: rgba(176,107,255,0.6); transform: translateY(-1px); }
.nebula-pill:active { transform: scale(0.97); }
.nebula-pill:focus-visible { outline: 2px solid var(--void); outline-offset: 2px; }
.nebula-pill b { color: #fff; }
.nebula-pill .nb-rate { color: var(--xp); font-weight: 700; font-size: 11px; letter-spacing: 0; }

/* Orbital Station — its own standalone overlay (not a Hangar tab). A capped-height
   flex column: a fixed top bar + tap zone, a scrolling store, then a DONE button. */
.station-panel {
  position: relative; /* anchor for the absolute Surge-orb overlay layer */
  width: min(560px, 96vw);
  max-height: 92vh;   /* fallback for browsers without dvh */
  max-height: 92dvh;  /* fit the *visible* area on mobile so nothing is clipped */
  display: flex; flex-direction: column;
}
/* Station tab bar — mirrors the Hangar tabs; wraps on narrow phones. */
.station-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; flex: none; }
.station-tabs .tab { min-width: 84px; padding: 9px 8px; font-size: 12px; letter-spacing: 1px; }
/* The MINE tab keeps the tap button + laser centred; it never needs to scroll as
   hard as the lists, but still shrinks gracefully on short screens. */
.station-mine { align-items: stretch; }
.station-topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 10px 12px; margin-bottom: 10px; flex: none;
}
.station-title {
  font-size: clamp(18px, 4.2vw, 26px); font-weight: 900; letter-spacing: 2px;
  color: var(--cyan); text-shadow: 0 0 18px rgba(81,233,255,0.4);
}
.station-cash { display: flex; gap: 8px; }
.station-cash .st-cur { flex: 0 1 auto; min-width: 88px; padding: 6px 12px; }
.station-cash .st-cur b { font-size: 17px; }

/* Tap zone — the Cookie-Clicker "big cookie": a juicy MINE button plus an overlay
   layer for the floating "+N" numbers that drift up from each tap. */
.station-tapzone {
  position: relative; display: flex; flex-direction: column; align-items: center;
  margin: 2px 0 12px; flex: none;
}
.station-tap {
  position: relative; cursor: pointer; pointer-events: auto; font-family: var(--font);
  width: min(190px, 46vw); height: min(190px, 46vw); max-height: 26dvh; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: #eafcff; touch-action: manipulation; user-select: none; -webkit-user-select: none;
  background: radial-gradient(circle at 50% 36%, rgba(176,107,255,0.55), rgba(81,233,255,0.16) 58%, rgba(12,16,38,0.65));
  border: 2px solid rgba(176,107,255,0.6);
  box-shadow: 0 0 40px -6px rgba(176,107,255,0.7), inset 0 0 42px rgba(81,233,255,0.2);
  transition: box-shadow 0.2s ease, transform 0.08s ease;
}
.station-tap::before {
  content: ''; position: absolute; inset: -6px; border-radius: 50%; pointer-events: none;
  border: 2px solid rgba(81,233,255,0.4); animation: tapRing 2.6s ease-out infinite;
}
.station-tap:hover { box-shadow: 0 0 54px -4px rgba(176,107,255,0.95), inset 0 0 48px rgba(81,233,255,0.28); }
.station-tap.punch { animation: tapPunch 0.2s ease; }
.station-tap .tap-core { font-size: clamp(32px, 10vw, 50px); line-height: 1; filter: drop-shadow(0 0 10px rgba(12,16,38,0.9)); }
.station-tap .tap-label { font-weight: 900; letter-spacing: 3px; font-size: 12px; opacity: 0.9; }
.station-tap .tap-gain { font-weight: 800; font-size: 14px; color: var(--xp); }
.station-tapfx { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.tap-pop {
  position: absolute; font-weight: 900; font-size: 18px; color: var(--xp); white-space: nowrap;
  text-shadow: 0 0 10px rgba(124,255,178,0.7); pointer-events: none;
  animation: tapPop 0.76s ease-out forwards;
}
@keyframes tapRing { 0% { transform: scale(0.96); opacity: 0.7; } 70% { transform: scale(1.14); opacity: 0; } 100% { opacity: 0; } }
@keyframes tapPunch { 0% { transform: scale(0.9); } 45% { transform: scale(1.05); } 100% { transform: scale(1); } }
@keyframes tapPop { 0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); } 20% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -160%) scale(1.1); } }

/* The scrolling store. flex:1 + min-height:0 lets it shrink and scroll inside the
   capped panel instead of pushing the DONE button off-screen (the mobile bug). */
.station-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 2px; margin-bottom: 12px; display: flex; flex-direction: column; gap: 10px;
}
#station-close { flex: none; }
.click-buy { flex: none; display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 96px; line-height: 1.15; }
.click-buy .gb-q { font-size: 10px; letter-spacing: 0.5px; opacity: 0.85; }
.click-buy .gb-c { font-weight: 800; }
.st-cur {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px; padding: 8px 10px;
}
.st-cur b { color: #fff; font-size: 20px; line-height: 1.1; }
.st-cur .st-k { font-size: 11px; letter-spacing: 1px; font-weight: 700; }
.st-cur .st-sub { color: var(--muted); font-size: 11px; }
.st-neb { border-color: rgba(176,107,255,0.4); } .st-neb .st-k { color: var(--void); }
.st-core { border-color: rgba(81,233,255,0.35); } .st-core .st-k { color: var(--cyan); }
.station-note { color: var(--muted); font-size: 12px; line-height: 1.45; text-align: center; }
.station-note b { color: var(--text); }
.prestige-row {
  display: flex; align-items: center; gap: 12px;
  background: linear-gradient(90deg, rgba(176,107,255,0.1), rgba(81,233,255,0.06));
  border: 1px solid rgba(176,107,255,0.4); border-radius: 12px; padding: 10px 14px;
}
.prestige-info { flex: 1; min-width: 0; text-align: left; }
.prestige-title { font-weight: 800; color: #fff; font-size: 14px; }
.prestige-sub { color: var(--muted); font-size: 12px; margin: 2px 0 6px; }
.prestige-sub b { color: var(--void); }
.prestige-bar { height: 5px; border-radius: 3px; background: rgba(255,255,255,0.12); overflow: hidden; }
.prestige-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--void), var(--cyan)); }
.prestige-btn { flex: none; padding: 9px 16px; }
.station-sec {
  display: flex; align-items: center; justify-content: space-between;
  color: var(--cyan); font-weight: 800; font-size: 12px; letter-spacing: 1.5px;
  margin: 2px 2px -2px; text-transform: uppercase;
}
.st-sec-sub { color: var(--muted); font-weight: 600; font-size: 11px; letter-spacing: 0.5px; text-transform: none; }
.st-sec-head { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-qtyrow { display: flex; gap: 4px; }
.st-qty { padding: 3px 9px; font-size: 11px; }
.st-qty.active { color: var(--bg0); background: linear-gradient(90deg, #51e9ff, #7cffb2); border-color: transparent; }
.gen-list, .special-list { display: flex; flex-direction: column; gap: 8px; }
.gen-row {
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px; padding: 10px 14px;
}
.gen-row.owned { border-color: rgba(176,107,255,0.3); background: rgba(176,107,255,0.05); }
.gen-ico { font-size: 24px; flex: none; width: 30px; text-align: center; }
.gen-main { flex: 1; min-width: 0; }
.gen-name { font-weight: 800; color: #fff; font-size: 14.5px; }
.gen-owned { color: var(--void); font-weight: 700; font-size: 12px; margin-left: 4px; }
.gen-desc { color: var(--muted); font-size: 12px; margin: 2px 0; }
.gen-rate { color: var(--xp); font-size: 11.5px; font-weight: 700; }
.gen-mile { color: var(--muted); font-size: 11px; font-weight: 600; margin-top: 2px; }
.gen-mile b { color: var(--void); }
.gen-buy { flex: none; display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 76px; line-height: 1.15; }
.gen-buy .gb-q { font-size: 10px; letter-spacing: 0.5px; opacity: 0.85; }
.gen-buy .gb-c { font-weight: 800; }
.special-row {
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px; padding: 10px 14px;
}
.special-row.maxed { border-color: rgba(81,233,255,0.4); background: rgba(81,233,255,0.06); }
.special-row .meta-desc b { color: var(--xp); }
.perk-list { display: flex; flex-direction: column; gap: 8px; }
.perk-buy { flex: none; }

/* Active-Surge buff banner (shown above the tabs while a frenzy is running). */
.station-buffs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; flex: none; }
.station-buffs.hidden { display: none; }
.buff-chip {
  display: flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 800; color: #fff;
  border: 1px solid rgba(255,212,71,0.5); background: rgba(255,212,71,0.12);
  animation: buffPulse 1.6s ease-in-out infinite;
}
.buff-chip.buff-click { border-color: rgba(124,255,178,0.55); background: rgba(124,255,178,0.12); }
.buff-ico { font-size: 15px; }
.buff-txt { letter-spacing: 0.3px; }
.buff-time { color: var(--gold); font-variant-numeric: tabular-nums; }
.buff-chip.buff-click .buff-time { color: var(--xp); }
@keyframes buffPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255,212,71,0); } 50% { box-shadow: 0 0 14px -2px rgba(255,212,71,0.6); } }

/* Nebula Surge orbs — golden-cookie-style RNG. They float over the whole panel;
   the host layer ignores pointers so only the orb itself is clickable. */
.station-surge { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 6; border-radius: inherit; }
.surge-orb {
  position: absolute; pointer-events: auto; cursor: pointer;
  width: 56px; height: 56px; border-radius: 50%; font-size: 26px; line-height: 1;
  display: flex; align-items: center; justify-content: center; font-family: var(--font);
  color: #1a1030; background: radial-gradient(circle at 50% 38%, #fff3b0, #ffcf3f 55%, #ff9b2f);
  border: 2px solid rgba(255,243,176,0.9);
  box-shadow: 0 0 26px -2px rgba(255,207,63,0.9), inset 0 0 14px rgba(255,255,255,0.5);
  animation: surgeFade linear forwards, surgeBob ease-in-out infinite;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.surge-orb.surge-prod { background: radial-gradient(circle at 50% 38%, #fff0c2, #ffb347 55%, #ff7b2f); }
.surge-orb.surge-click { background: radial-gradient(circle at 50% 38%, #d6ffe8, #7cffb2 55%, #32d58a); border-color: rgba(214,255,232,0.9); box-shadow: 0 0 26px -2px rgba(124,255,178,0.9), inset 0 0 14px rgba(255,255,255,0.5); }
.surge-orb.surge-core { background: radial-gradient(circle at 50% 38%, #e8f6ff, #51e9ff 55%, #7c9bff); border-color: rgba(232,246,255,0.9); box-shadow: 0 0 30px -2px rgba(81,233,255,0.95), inset 0 0 14px rgba(255,255,255,0.5); }
.surge-orb:hover { filter: brightness(1.08); }
/* The two animations share the orb: surgeFade (duration = SURGE_LIFETIME) telegraphs
   the orb expiring; surgeBob gives it a gentle idle drift. */
@keyframes surgeFade { 0% { opacity: 0; transform: scale(0.4); } 8% { opacity: 1; transform: scale(1); } 82% { opacity: 1; } 100% { opacity: 0; transform: scale(0.75); } }
@keyframes surgeBob { 0%, 100% { margin-top: 0; } 50% { margin-top: -10px; } }
@media (prefers-reduced-motion: reduce) { .surge-orb { animation: surgeFade linear forwards; } }

/* Transient commendation toasts */
.toast-wrap {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 50;
  pointer-events: none; width: min(360px, 92vw);
}
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid rgba(255,212,71,0.45);
  border-radius: 12px; padding: 10px 14px; box-shadow: 0 8px 30px -10px rgba(0,0,0,0.8);
  backdrop-filter: blur(6px);
  animation: toastIn 0.3s ease, toastOut 0.4s ease 2.6s forwards;
}
.toast .t-ico { font-size: 24px; }
.toast .t-body { display: flex; flex-direction: column; line-height: 1.25; }
.toast .t-body b { color: var(--gold); font-size: 14px; }
.toast .t-body span { color: var(--muted); font-size: 11.5px; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px); } }

@media (max-width: 560px) {
  .ship-grid { grid-template-columns: 1fr; }
  .ship-desc { min-height: 0; }
  .directive-grid, .codex-grid { grid-template-columns: 1fr; }
  .dir-desc { min-height: 0; }
  /* On phones the currency pills take the full width under the title and split
     the row evenly, and the tap button shrinks a touch to leave room to scroll. */
  .station-cash { width: 100%; }
  .station-cash .st-cur { flex: 1 1 auto; }
  .station-tap { width: min(168px, 52vw); height: min(168px, 52vw); }
}

/* Mobile controls */
#touch-controls { position: absolute; inset: 0; pointer-events: none; z-index: 8; }

/* Dynamic joystick: a faint "home" hint on the left, and a live ring+knob that
   snaps to wherever the thumb lands (driven per-frame from input.joy). */
.joy-hint {
  position: absolute; left: calc(env(safe-area-inset-left, 0px) + 92px);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 104px);
  width: 128px; height: 128px; margin: 0 0 -64px -64px; border-radius: 50%;
  border: 2px dashed rgba(81,233,255,0.28);
  display: flex; align-items: center; justify-content: center;
  color: rgba(81,233,255,0.5); font: 700 12px/1 system-ui, sans-serif; letter-spacing: 2px;
  pointer-events: none; transition: opacity 0.2s;
}
.joy-hint.off { opacity: 0; }
.joy-ring {
  position: absolute; left: 0; top: 0; width: 132px; height: 132px; margin: -66px 0 0 -66px;
  border-radius: 50%; border: 2px solid rgba(81,233,255,0.55);
  background: radial-gradient(circle, rgba(81,233,255,0.14), rgba(81,233,255,0.04));
  box-shadow: 0 0 24px -4px rgba(81,233,255,0.5);
  pointer-events: none; display: none;
}
.joy-ring.active { display: block; }
.joy-knob {
  position: absolute; left: 50%; top: 50%; width: 60px; height: 60px; margin: -30px 0 0 -30px;
  border-radius: 50%; background: rgba(81,233,255,0.4); border: 2px solid rgba(81,233,255,0.9);
  box-shadow: 0 0 20px rgba(81,233,255,0.6); will-change: transform;
}

.touch-btn {
  position: absolute; width: 84px; height: 84px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 34px;
  background: rgba(81,233,255,0.14); border: 2px solid rgba(81,233,255,0.45);
  pointer-events: auto; backdrop-filter: blur(4px); user-select: none;
  -webkit-user-select: none; touch-action: none;
}
/* Action buttons live in a vertical stack at the right edge, clear of the
   centre HUD bars (health/XP/overdrive) which occupy the bottom-left. */
#btn-dash {
  right: calc(env(safe-area-inset-right, 0px) + 26px);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 100px);
}
#btn-sing {
  right: calc(env(safe-area-inset-right, 0px) + 26px);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 200px);
  border-color: rgba(176,107,255,0.55); background: rgba(176,107,255,0.16);
}
/* Pause sits in the top-right corner (standard mobile placement). It is smaller
   than the action buttons and the HUD score column is nudged clear of it on
   touch devices (see the pointer:coarse block below). */
.touch-pause {
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: calc(env(safe-area-inset-right, 0px) + 12px);
  width: 52px; height: 52px; font-size: 22px;
  border-color: rgba(255,255,255,0.4); background: rgba(10,14,32,0.5);
}
.touch-btn:active { transform: scale(0.9); background: rgba(255,255,255,0.28); }

/* On touch devices the big action buttons replace the small desktop cooldown
   indicators, so hide the redundant .abilities row to avoid clutter/overlap. */
@media (pointer: coarse) {
  .abilities { display: none; }
  /* Reserve a right-hand gutter so the status bars never run under the
     right-edge action button column. */
  .bars { max-width: min(520px, calc(100% - 150px)); }
  /* Keep the score column clear of the top-right pause button. */
  .hud-right { margin-right: 58px; }
}

@media (max-width: 760px) {
  .cards { grid-template-columns: 1fr; }
  .card .desc { min-height: 0; }
  .features { display: none; }
}
