:root {
  --bg: #02040d;
  --panel: rgba(7, 13, 28, 0.74);
  --panel-strong: rgba(7, 13, 28, 0.92);
  --line: rgba(112, 225, 255, 0.22);
  --cyan: #67eaff;
  --cyan-bright: #b8f7ff;
  --magenta: #ff4bd8;
  --orange: #ffad52;
  --danger: #ff526d;
  --good: #70ffb2;
  --text: #ecfaff;
  --muted: #8ca3ba;
  --shadow: 0 20px 70px rgba(0, 0, 0, 0.56);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--bg); color: var(--text); }
body { user-select: none; }
button, select, input { font: inherit; }
button { color: inherit; }

#app { position: relative; width: 100%; height: 100%; isolation: isolate; background: radial-gradient(circle at 50% 45%, #0b1740 0%, #030612 45%, #010207 100%); }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; }
#scanlines { position: absolute; inset: 0; pointer-events: none; z-index: 3; opacity: .1; background: repeating-linear-gradient(to bottom, transparent 0 3px, rgba(80, 205, 255, .17) 4px); mix-blend-mode: screen; }
#vignette { position: absolute; inset: 0; pointer-events: none; z-index: 4; background: radial-gradient(ellipse at center, transparent 35%, rgba(0, 2, 10, .28) 70%, rgba(0, 1, 5, .75) 100%); }

.screen { position: absolute; inset: 0; z-index: 20; display: none; align-items: center; justify-content: center; padding: clamp(18px, 4vw, 54px); background: linear-gradient(135deg, rgba(1, 4, 14, .16), rgba(2, 6, 18, .62)); backdrop-filter: blur(3px); }
.screen-visible { display: flex; }
.hidden { display: none !important; }

.glass-panel { border: 1px solid var(--line); background: linear-gradient(145deg, rgba(12, 23, 48, .86), rgba(4, 9, 24, .74)); box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.07); backdrop-filter: blur(18px) saturate(135%); border-radius: 22px; }
.boot-card { min-width: 270px; padding: 38px; text-align: center; letter-spacing: .15em; }
.boot-card h1 { margin: 12px 0 0; font-size: 74px; line-height: .9; color: var(--cyan); text-shadow: 0 0 25px rgba(103,234,255,.65); }
.boot-card p { margin: 15px 0 20px; color: var(--cyan-bright); font-size: 12px; }
.boot-card small { color: var(--muted); letter-spacing: .06em; }
.boot-spinner { width: 36px; height: 36px; margin: auto; border-radius: 50%; border: 2px solid rgba(103,234,255,.18); border-top-color: var(--cyan); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#main-menu { align-items: stretch; justify-content: stretch; }
.hero-panel { align-self: center; width: min(710px, calc(100vw - 44px)); padding: clamp(30px, 5vw, 58px); margin-left: clamp(0px, 6vw, 90px); }
.hero-panel h1 { display: flex; gap: 5px; margin: 8px 0 0; font-size: clamp(78px, 11vw, 150px); line-height: .78; font-weight: 950; letter-spacing: -.08em; }
.hero-panel h1 span:first-child { color: var(--cyan); text-shadow: 0 0 35px rgba(103,234,255,.85); }
.hero-panel h1 span:last-child { color: var(--magenta); text-shadow: 0 0 35px rgba(255,75,216,.72); }
.hero-panel h2 { margin: 25px 0 12px; font-size: clamp(19px, 2.3vw, 34px); letter-spacing: .12em; }
.eyebrow { color: var(--cyan); font-size: 11px; font-weight: 800; letter-spacing: .2em; text-transform: uppercase; }
.hero-copy { max-width: 610px; margin: 0 0 28px; color: #b5cce0; line-height: 1.65; }
.menu-actions { display: grid; gap: 10px; max-width: 430px; }
.menu-footer { display: flex; flex-wrap: wrap; gap: 8px 25px; margin-top: 25px; padding-top: 18px; border-top: 1px solid rgba(103,234,255,.12); color: var(--muted); font-size: 12px; }
.highscore-panel { position: absolute; right: clamp(24px, 5vw, 72px); top: 50%; transform: translateY(-50%); width: min(320px, 27vw); padding: 24px; }
.panel-title { color: var(--cyan); font-size: 11px; font-weight: 800; letter-spacing: .16em; }
#highscore-list { margin: 16px 0 0; padding-left: 28px; color: #cde9f7; }
#highscore-list li { margin: 10px 0; padding-left: 6px; }
#highscore-list li::marker { color: var(--magenta); font-weight: 800; }
.score-line { display: flex; justify-content: space-between; gap: 15px; }
.score-line span:last-child { color: var(--cyan-bright); font-variant-numeric: tabular-nums; }

.btn { appearance: none; border: 1px solid rgba(103,234,255,.24); border-radius: 12px; background: rgba(12,31,58,.78); padding: 13px 18px; cursor: pointer; font-size: 12px; font-weight: 850; letter-spacing: .1em; transition: transform .15s ease, border-color .15s ease, background .15s ease, box-shadow .15s ease; }
.btn:hover, .btn:focus-visible { transform: translateY(-1px); border-color: rgba(103,234,255,.75); background: rgba(20,54,86,.88); box-shadow: 0 0 22px rgba(103,234,255,.14); outline: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { color: #04111a; border-color: transparent; background: linear-gradient(90deg, var(--cyan), #b8fff0); box-shadow: 0 0 25px rgba(103,234,255,.2); }
.btn-primary:hover, .btn-primary:focus-visible { background: linear-gradient(90deg, #9ff3ff, #d6fff7); }
.btn-danger { border-color: rgba(255,82,109,.34); color: #ffc0ca; background: rgba(88,14,34,.55); }
.btn-small { padding: 10px 13px; font-size: 10px; }
.icon-btn { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 50%; background: rgba(7,18,40,.72); color: var(--cyan-bright); font-size: 26px; line-height: 1; cursor: pointer; }

.modal-panel { width: min(820px, calc(100vw - 34px)); max-height: calc(100vh - 36px); overflow: auto; padding: clamp(24px, 4vw, 42px); }
.modal-panel.wide { width: min(1050px, calc(100vw - 34px)); }
.modal-panel.compact { width: min(430px, calc(100vw - 34px)); display: grid; gap: 12px; text-align: center; }
.modal-panel h2 { margin: 5px 0 0; font-size: clamp(28px, 4vw, 46px); }
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 26px; }
.modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; margin-top: 25px; }
.settings-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
fieldset { min-width: 0; border: 1px solid rgba(103,234,255,.14); border-radius: 14px; padding: 18px; background: rgba(2,8,23,.42); }
legend { padding: 0 8px; color: var(--cyan); font-size: 11px; font-weight: 850; letter-spacing: .13em; text-transform: uppercase; }
label { display: grid; gap: 7px; margin: 14px 0; color: #bed4e3; font-size: 12px; }
select, input[type="range"] { width: 100%; }
select { appearance: none; border: 1px solid rgba(103,234,255,.2); border-radius: 9px; background: #071428; color: var(--text); padding: 10px 34px 10px 11px; background-image: linear-gradient(45deg, transparent 50%, var(--cyan) 50%), linear-gradient(135deg, var(--cyan) 50%, transparent 50%); background-position: calc(100% - 15px) 14px, calc(100% - 10px) 14px; background-size: 5px 5px; background-repeat: no-repeat; }
input[type="range"] { accent-color: var(--cyan); }
output { justify-self: end; margin-top: -4px; color: var(--cyan-bright); font-variant-numeric: tabular-nums; }
.toggle-row { grid-template-columns: auto 1fr; align-items: center; gap: 10px; cursor: pointer; }
.toggle-row input { width: 18px; height: 18px; accent-color: var(--cyan); }
.controller-map { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 18px; }
.controller-slot { display: flex; flex-direction: column; gap: 3px; padding: 11px; border: 1px solid rgba(103,234,255,.13); border-radius: 10px; background: rgba(2,8,23,.4); font-size: 11px; color: var(--muted); }
.controller-slot b { color: var(--cyan); }
.controller-slot.connected { border-color: rgba(112,255,178,.38); box-shadow: inset 0 0 18px rgba(112,255,178,.04); }
.controller-slot.connected b { color: var(--good); }
.help-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; }
.help-grid article { border: 1px solid rgba(103,234,255,.13); border-radius: 14px; padding: 18px; background: rgba(2,8,23,.42); }
.help-grid h3 { margin: 0 0 14px; color: var(--cyan-bright); }
.help-grid p { color: #aec4d6; font-size: 13px; line-height: 1.55; }
.key-row { display: flex; align-items: center; gap: 8px; margin: 9px 0; color: #b9ccdc; font-size: 12px; }
kbd { display: inline-grid; place-items: center; min-width: 32px; height: 27px; padding: 0 8px; border: 1px solid rgba(103,234,255,.28); border-bottom-width: 3px; border-radius: 6px; background: rgba(10,29,54,.9); color: var(--cyan-bright); font: 800 10px/1 ui-monospace, SFMono-Regular, Consolas, monospace; }

.hud { position: absolute; inset: 0; z-index: 10; pointer-events: none; }
#hud-top-center { position: absolute; top: max(16px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); text-align: center; text-shadow: 0 2px 10px #000; }
#wave-label { color: var(--cyan-bright); font-size: 16px; font-weight: 950; letter-spacing: .12em; }
#objective-label { margin-top: 4px; color: var(--muted); font-size: 10px; letter-spacing: .08em; }
#player-huds { position: absolute; inset: 0; }
.player-hud { position: absolute; width: min(280px, 32vw); padding: 12px 14px; border: 1px solid color-mix(in srgb, var(--player-color) 40%, transparent); border-radius: 12px; background: linear-gradient(145deg, rgba(3,8,20,.78), rgba(4,13,30,.56)); box-shadow: 0 0 24px color-mix(in srgb, var(--player-color) 10%, transparent); backdrop-filter: blur(8px); }
.player-hud[data-slot="0"] { left: 14px; top: 14px; }
.player-hud[data-slot="1"] { right: 14px; top: 14px; }
.player-hud[data-slot="2"] { left: 14px; bottom: 14px; }
.player-hud[data-slot="3"] { right: 14px; bottom: 14px; }
.player-hud-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.player-name { color: var(--player-color); font-size: 11px; font-weight: 900; letter-spacing: .1em; }
.player-score { font-size: 17px; font-weight: 900; font-variant-numeric: tabular-nums; }
.player-sub { display: flex; justify-content: space-between; gap: 8px; margin-top: 5px; color: var(--muted); font-size: 9px; letter-spacing: .05em; }
.meter { height: 5px; margin-top: 8px; border-radius: 99px; overflow: hidden; background: rgba(255,255,255,.07); }
.meter > i { display: block; width: 100%; height: 100%; background: var(--player-color); box-shadow: 0 0 9px var(--player-color); transition: width .08s linear; }
.meter.shield > i { background: #8af7ff; }
.player-weapon { margin-top: 6px; color: #d9f8ff; font-size: 10px; font-weight: 750; }
.debug-chip { position: absolute; right: 12px; bottom: 12px; color: rgba(174,225,241,.55); font: 10px/1.2 ui-monospace, monospace; }

.wave-banner { position: absolute; z-index: 15; left: 50%; top: 50%; width: min(640px, 85vw); transform: translate(-50%, -50%); text-align: center; pointer-events: none; text-shadow: 0 0 25px rgba(103,234,255,.75); animation: waveIn 2.4s ease both; }
.wave-banner span, .wave-banner em { display: block; color: var(--muted); font-size: 11px; font-style: normal; font-weight: 800; letter-spacing: .3em; }
.wave-banner strong { display: block; margin: 7px 0; color: var(--cyan-bright); font-size: clamp(44px, 9vw, 96px); line-height: .95; letter-spacing: .04em; }
@keyframes waveIn { 0% { opacity: 0; transform: translate(-50%, -45%) scale(.86); } 15%, 72% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -55%) scale(1.06); } }

#toast-layer { position: absolute; z-index: 30; left: 50%; bottom: 7vh; transform: translateX(-50%); display: grid; gap: 8px; pointer-events: none; }
.toast { min-width: 260px; max-width: 70vw; padding: 11px 16px; border: 1px solid rgba(103,234,255,.3); border-radius: 10px; background: rgba(3,11,28,.9); box-shadow: 0 10px 35px rgba(0,0,0,.42); color: #dffaff; text-align: center; font-size: 11px; font-weight: 750; letter-spacing: .05em; animation: toastLife 2.8s ease both; }
.toast.good { border-color: rgba(112,255,178,.42); color: #b9ffd9; }
.toast.danger { border-color: rgba(255,82,109,.45); color: #ffd0d8; }
@keyframes toastLife { 0% { opacity: 0; transform: translateY(12px); } 10%, 75% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-8px); } }

#final-scoreboard { display: grid; gap: 8px; margin: 24px 0; }
.final-row { display: grid; grid-template-columns: 60px 1fr auto; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid rgba(103,234,255,.13); border-radius: 10px; background: rgba(2,8,23,.46); }
.final-row b { color: var(--pcolor); }
.final-row span { color: var(--muted); font-size: 12px; }
.final-row strong { font-size: 20px; font-variant-numeric: tabular-nums; }
.fatal-error { position: absolute; z-index: 100; inset: 20px; display: grid; place-items: center; padding: 30px; border: 1px solid rgba(255,82,109,.55); border-radius: 16px; background: rgba(18,2,9,.95); color: #ffd3dc; white-space: pre-wrap; text-align: center; }

@media (max-width: 1050px) {
  .highscore-panel { display: none; }
  .hero-panel { margin: auto; }
  .settings-grid { grid-template-columns: 1fr 1fr; }
  .settings-grid fieldset:last-child { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
  .settings-grid, .help-grid { grid-template-columns: 1fr; }
  .settings-grid fieldset:last-child { grid-column: auto; }
  .controller-map { grid-template-columns: 1fr 1fr; }
  .hero-panel { padding: 28px; }
  .player-hud { width: 42vw; padding: 9px; }
  .player-score { font-size: 14px; }
  #hud-top-center { top: 48%; opacity: .72; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
