:root {
  --bg: #050507;
  --lav: #C4BBE0;
  --blue: #2B2BFF;
  --amber: #FFA500;
  --red: #ff3b54;
  --green: #57e6a0;
  --ink: rgba(255, 255, 255, 0.94);
  --mute: rgba(196, 187, 224, 0.62);
  --line: rgba(196, 187, 224, 0.18);
  --panel: rgba(8, 9, 16, 0.72);
  --disp: "Chakra Petch", "Space Grotesk", system-ui, sans-serif;
  --body: "Space Grotesk", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

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

html, body {
  height: 100%;
  background: #000;
  color: var(--ink);
  font-family: var(--body);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
}

#stage { position: fixed; inset: 0; z-index: 0; }
#stage canvas { display: block; }
#hud { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; }

/* Damage / event vignette */
#vignette {
  position: fixed; inset: 0; z-index: 3; pointer-events: none; opacity: 0;
  box-shadow: inset 0 0 220px 40px rgba(255, 59, 84, 0.0);
  transition: opacity 0.08s ease;
}
#vignette.hit { opacity: 1; box-shadow: inset 0 0 240px 60px rgba(255, 59, 84, 0.75); }
#vignette.pick { opacity: 1; box-shadow: inset 0 0 240px 60px rgba(87, 230, 160, 0.55); }
#vignette.warn { opacity: 1; box-shadow: inset 0 0 260px 70px rgba(255, 165, 0, 0.5); }

/* Warp / hyperspace transition */
#warp {
  position: fixed; inset: 0; z-index: 30; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at center, rgba(43,43,255,0.18), rgba(0,0,0,0.96) 70%);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.35s ease;
}
#warp.on { opacity: 1; pointer-events: auto; }
.warp-streaks {
  position: absolute; inset: 0;
  background:
    repeating-linear-gradient(90deg, transparent 0 6px, rgba(196,187,224,0.05) 6px 7px),
    radial-gradient(circle at center, rgba(255,255,255,0.9) 0, transparent 2px);
  -webkit-mask-image: radial-gradient(circle at center, #000 0, transparent 60%);
  mask-image: radial-gradient(circle at center, #000 0, transparent 60%);
  opacity: 0;
}
#warp.on .warp-streaks { animation: warp 1.1s ease-in forwards; }
@keyframes warp {
  0% { opacity: 0; transform: scale(0.6); filter: blur(0px); }
  35% { opacity: 1; }
  100% { opacity: 0; transform: scale(3.4); filter: blur(4px); }
}
.warp-label {
  position: relative; font-family: var(--mono); font-size: 13px; letter-spacing: 0.4em;
  color: var(--lav); text-transform: uppercase; text-shadow: 0 0 18px rgba(43,43,255,0.8);
}

/* ── Screen overlay system ─────────────────────────────────── */
.screen {
  position: fixed; inset: 0; z-index: 20;
  display: none; align-items: center; justify-content: center; text-align: center;
  padding: 28px;
  background:
    radial-gradient(ellipse at 50% 35%, rgba(20,16,34,0.55), rgba(0,0,0,0.86) 75%);
  backdrop-filter: blur(2px);
}
.screen.show { display: flex; animation: fade 0.4s ease both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.screen-inner { width: 100%; max-width: 720px; animation: rise 0.5s cubic-bezier(.2,.7,.2,1) both; }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }

.eyebrow {
  font-family: var(--mono); font-size: 12px; letter-spacing: 0.34em; text-transform: uppercase;
  color: var(--lav); opacity: 0.85; margin-bottom: 1.1em;
}
.game-title {
  font-family: var(--disp); font-weight: 700; line-height: 0.92;
  font-size: clamp(58px, 13vw, 150px); letter-spacing: 0.04em;
  background: linear-gradient(180deg, #fff 0%, var(--lav) 70%, #8d83b8 100%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 30px rgba(43,43,255,0.35));
}
.game-title.win { font-size: clamp(34px, 7vw, 78px); filter: drop-shadow(0 0 30px rgba(255,165,0,0.4)); }
.tagline { color: var(--mute); font-size: clamp(14px, 1.8vw, 18px); margin: 1em auto 2.2em; max-width: 32em; letter-spacing: 0.01em; }

.menu-nav { display: flex; flex-direction: column; gap: 12px; max-width: 360px; margin: 0 auto; }
.menu-foot { margin-top: 2.6em; font-family: var(--mono); font-size: 10px; letter-spacing: 0.4em; color: var(--mute); }

/* Buttons */
.btn {
  font-family: var(--mono); font-size: 13px; font-weight: 600; letter-spacing: 0.22em;
  color: var(--lav); background: rgba(196,187,224,0.06);
  border: 1px solid var(--line); padding: 16px 26px; cursor: pointer;
  transition: transform 0.12s ease, background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
  text-transform: uppercase; pointer-events: auto;
}
.btn:hover { background: rgba(196,187,224,0.14); border-color: rgba(196,187,224,0.5); transform: translateY(-1px); }
.btn-primary { color: #07060c; background: var(--lav); border-color: var(--lav); }
.btn-primary:hover { background: #fff; border-color: #fff; }
.btn-ghost { color: var(--mute); }
.danger { color: var(--red); }

/* Briefing */
.brief-inner { max-width: 640px; text-align: left; }
.brief-tag { font-family: var(--mono); font-size: 12px; letter-spacing: 0.32em; color: var(--amber); margin-bottom: 0.7em; }
.brief-name { font-family: var(--disp); font-weight: 700; font-size: clamp(34px, 7vw, 64px); letter-spacing: 0.03em; line-height: 1; }
.brief-sub { color: var(--mute); font-family: var(--mono); font-size: 13px; letter-spacing: 0.12em; margin: 0.5em 0 1.6em; }
.brief-text { color: rgba(255,255,255,0.82); font-size: 16px; line-height: 1.6; margin-bottom: 1.8em; }
.brief-obj { border-left: 2px solid var(--amber); padding: 4px 0 4px 16px; margin-bottom: 2em; display: flex; flex-direction: column; gap: 6px; }
.brief-obj-label { font-family: var(--mono); font-size: 11px; letter-spacing: 0.2em; color: var(--amber); }
.brief-obj-text { font-size: 17px; color: var(--ink); }
.brief-actions { display: flex; gap: 12px; }

/* Panels (controls / pause) */
.panel-title { font-family: var(--disp); font-weight: 700; font-size: clamp(28px, 5vw, 46px); letter-spacing: 0.06em; margin-bottom: 1em; }
.controls-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 26px; max-width: 460px; margin: 0 auto 2em;
  font-family: var(--mono); font-size: 13px; color: var(--mute); text-align: left;
}
.controls-grid div { display: flex; align-items: baseline; gap: 12px; }
.controls-grid span { color: var(--amber); font-weight: 700; letter-spacing: 0.06em; min-width: 78px; display: inline-block; }
.controls-touch-list { display: none; }
body.touch .controls-touch-list { display: grid; }

/* Mission complete */
.cleared-kicker { font-family: var(--mono); font-size: 13px; letter-spacing: 0.36em; color: var(--green); margin-bottom: 0.8em; }
.cleared-name { font-family: var(--disp); font-weight: 700; font-size: clamp(30px, 6vw, 56px); letter-spacing: 0.03em; margin-bottom: 1em; }
.cleared-stats {
  display: grid; grid-auto-flow: row; gap: 8px; justify-content: center; margin: 0 auto 2em;
  font-family: var(--mono); font-size: 14px; color: var(--mute); text-align: left;
}
.cleared-stats b { color: var(--ink); font-weight: 700; }

.victory-inner { max-width: 760px; }

/* Fallback */
.fallback {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center; padding: 40px; text-align: center;
  background: var(--bg); color: var(--mute);
  font-family: var(--mono); font-size: 13px; letter-spacing: 0.04em;
}
.fallback[hidden] { display: none; }

/* ── Touch controls ────────────────────────────────────────── */
#touch { position: fixed; inset: 0; z-index: 5; display: none; touch-action: none; }
#touch.show { display: block; }
body:not(.touch) #touch { display: none; }
#touch > * { pointer-events: auto; }
.t-steer { position: absolute; inset: 0; touch-action: none; }
.t-stick {
  position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px;
  border: 1.5px solid rgba(196,187,224,0.45); border-radius: 50%; display: none; pointer-events: none;
}
.t-stick.on { display: block; }
.t-stick-knob {
  position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px;
  border-radius: 50%; background: rgba(196,187,224,0.22); border: 1.5px solid var(--lav);
}
.t-throttle {
  position: absolute; left: 16px; top: 24%; width: 56px; height: 46%;
  border: 1.5px solid rgba(196,187,224,0.4); border-radius: 30px; overflow: hidden;
  display: flex; align-items: flex-start; justify-content: center; touch-action: none;
  background: rgba(8,8,14,0.4);
}
.t-fill { position: absolute; left: 0; bottom: 0; width: 100%; height: 0%; background: rgba(196,187,224,0.4); }
.t-throttle span { position: relative; margin-top: 10px; font-family: var(--mono); font-size: 10px; font-weight: 700; letter-spacing: 0.14em; color: var(--lav); }
.t-col-left { position: absolute; left: 14px; bottom: 24px; display: flex; flex-direction: column; gap: 12px; }
.t-col-right { position: absolute; right: 16px; bottom: 24px; display: flex; flex-direction: column; gap: 12px; align-items: flex-end; }
.t-btn {
  font-family: var(--mono); font-weight: 700; font-size: 12px; letter-spacing: 0.12em;
  color: var(--lav); background: rgba(8,8,14,0.5); border: 1.5px solid rgba(196,187,224,0.4);
  border-radius: 12px; min-width: 66px; min-height: 56px; padding: 0 12px; touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.t-btn:active, .t-btn.on { background: rgba(196,187,224,0.9); color: #050507; }
.t-fire { min-width: 96px; min-height: 96px; border-radius: 50%; color: var(--amber); border-color: rgba(255,165,0,0.55); font-size: 14px; }
.t-fire:active, .t-fire.on { background: var(--amber); border-color: var(--amber); color: #050507; }
