:root {
  color-scheme: dark;
  --space: #05070d;
  --panel: #0b1020;
  --line: #25304a;
  --text: #f7fafc;
  --muted: #93a4bf;
  --mint: #55f6bd;
  --coral: #ff6577;
  --amber: #ffc857;
  --cyan: #55d6ff;
}

* { box-sizing: border-box; }

.game-shell, .game-shell * {
  -webkit-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
}

.game-shell input, .game-shell textarea {
  -webkit-user-select: text !important;
  user-select: text !important;
}

html, body { margin: 0; min-height: 100%; background: var(--space); }

body {
  min-height: 100dvh;
  overflow: hidden;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  letter-spacing: 0;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  overflow-y: auto;
  background: var(--space);
}

.auth-gate[hidden] { display: none; }

.login-panel {
  width: min(100%, 410px);
  padding: 28px;
  display: grid;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: 0 18px 60px rgba(0, 0, 0, .42);
}

.login-panel .pixel-mark { margin: 0 auto 4px; }
.login-panel .eyebrow { margin: 0; text-align: center; }
.login-panel h1 { margin: 0 0 6px; text-align: center; text-transform: uppercase; }
.login-panel > p:not(.eyebrow, .login-message) { margin: 0 0 10px; color: var(--muted); font-size: 12px; line-height: 1.5; text-align: center; }
.login-panel label { margin-top: 3px; color: var(--muted); font-size: 10px; text-transform: uppercase; }
.login-panel input { min-height: 46px; padding: 0 12px; border: 1px solid var(--line); border-radius: 4px; color: var(--text); background: #080b14; font: inherit; }
.login-panel input:focus { border-color: var(--mint); outline: 2px solid rgba(85, 246, 189, .18); }
.login-panel button { min-height: 46px; margin-top: 5px; border: 0; border-radius: 4px; color: #04110d; background: var(--mint); font-weight: 800; text-transform: uppercase; cursor: pointer; }
.login-panel button:disabled { opacity: .55; cursor: wait; }
.login-panel a { margin-top: 5px; color: var(--cyan); font-size: 11px; text-align: center; }
.login-message { min-height: 16px; margin: 2px 0 0; color: var(--coral); font-size: 11px; text-align: center; }

button { font: inherit; letter-spacing: 0; }

.game-shell {
  width: min(100%, 760px);
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  background: var(--space);
}

.hud {
  min-height: 68px;
  padding: max(12px, env(safe-area-inset-top)) 18px 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: end;
  border-bottom: 1px solid var(--line);
  background: #080b14;
}

.hud > div { display: grid; gap: 3px; }
.hud > div:not(:first-child) { text-align: center; }
.hud > div:last-child { text-align: right; }
.hud-label { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.hud strong { min-width: 6ch; font-size: 20px; color: var(--mint); font-variant-numeric: tabular-nums; }
.hud-center strong { color: var(--amber); }
.hud > div:nth-child(3) strong { color: var(--coral); }
.hud > div:last-child strong { color: var(--coral); }

.telemetry-hidden { display: none; }

.stage {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #05070d;
}

canvas {
  display: block;
  width: min(100%, calc((100dvh - 196px) * .8));
  max-height: 100%;
  aspect-ratio: 4 / 5;
  image-rendering: pixelated;
  outline: none;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px;
  overflow-y: auto;
  text-align: center;
  background: rgba(5, 7, 13, .9);
}

.overlay[hidden] { display: none; }
.overlay.menu-open { justify-content: flex-start; }
.overlay.profile-open { justify-content: flex-start; }
.overlay.profile-open .pixel-mark, .overlay.profile-open .eyebrow, .overlay.profile-open .coin-balance, .overlay.profile-open .key-hint, .overlay.profile-open .weapon-message { display: none; }
.eyebrow { margin: 18px 0 7px; color: var(--mint); font-size: 12px; text-transform: uppercase; }
.overlay h1 { margin: 0; font-size: clamp(31px, 7vw, 58px); line-height: 1; text-transform: uppercase; }
.overlay > p:not(.eyebrow, .key-hint) { max-width: 500px; margin: 18px 0 24px; color: var(--muted); line-height: 1.55; }

.overlay-actions > button {
  min-height: 48px;
  padding: 0 24px;
  border: 0;
  border-radius: 4px;
  color: #04110d;
  background: var(--mint);
  font-weight: 800;
  text-transform: uppercase;
  cursor: pointer;
}

.overlay-actions > button:hover, .overlay-actions > button:focus-visible { background: #8affe0; outline: 2px solid var(--text); outline-offset: 3px; }
.overlay-actions { display: flex; justify-content: center; gap: 10px; }
.overlay-actions[hidden] { display: none; }
.overlay-actions .secondary-button { color: var(--text); border: 1px solid var(--line); background: var(--panel); }
.overlay-actions .secondary-button:hover { background: #18233a; }
.key-hint { margin: 20px 0 0; color: var(--muted); font-size: 11px; }
kbd { display: inline-grid; min-width: 23px; height: 23px; place-items: center; border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 3px; color: var(--text); background: var(--panel); }

.pixel-mark { width: 72px; height: 45px; position: relative; color: var(--coral); }
.pixel-mark i { position: absolute; width: 12px; height: 12px; background: currentColor; box-shadow: 12px 0 currentColor, 24px 0 currentColor; }
.pixel-mark i:nth-child(1) { left: 18px; top: 0; }
.pixel-mark i:nth-child(2) { left: 6px; top: 12px; box-shadow: 12px 0 currentColor, 24px 0 currentColor, 36px 0 currentColor, 48px 0 currentColor; }
.pixel-mark i:nth-child(3) { left: 0; top: 24px; box-shadow: 12px 0 currentColor, 24px 0 var(--space), 36px 0 var(--space), 48px 0 currentColor, 60px 0 currentColor; }
.pixel-mark i:nth-child(4) { left: 12px; top: 36px; box-shadow: 36px 0 currentColor; }
.pixel-mark i:nth-child(5) { display: none; }

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  background: rgba(11, 16, 32, .86);
  cursor: pointer;
}

.pause-button { position: absolute; z-index: 1; top: 12px; right: 12px; }
.home-button { position: absolute; z-index: 1; top: 12px; left: 12px; }
.profile-button { position: absolute; z-index: 3; left: 12px; bottom: 12px; color: var(--mint); font-size: 0; }
.profile-button::before { content: ""; width: 12px; height: 12px; position: absolute; top: 8px; left: 14px; border-radius: 50%; background: currentColor; }
.profile-button::after { content: ""; width: 22px; height: 11px; position: absolute; left: 9px; bottom: 7px; border-radius: 11px 11px 3px 3px; background: currentColor; }
.leaderboard-button { position: absolute; z-index: 3; right: 12px; bottom: 12px; color: var(--amber); font-size: 20px; }
.profile-back-button { width: 42px; height: 42px; position: absolute; z-index: 4; top: 12px; left: 12px; border: 1px solid var(--line); border-radius: 4px; color: var(--text); background: var(--panel); font-size: 24px; cursor: pointer; }
.profile-back-button[hidden] { display: none; }

.weapon-menu { width: min(100%, 540px); margin: -8px 0 18px; }
.weapon-menu[hidden] { display: none; }
.coin-balance { margin: 0 0 10px; color: var(--amber); text-transform: uppercase; }
.coin-balance strong { color: var(--text); font-size: 20px; font-variant-numeric: tabular-nums; }
.loadout-tabs { margin-bottom: 8px; display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: 4px; }
.loadout-tabs[hidden] { display: none; }
.loadout-tabs button { min-height: 34px; border: 0; color: var(--muted); background: transparent; cursor: pointer; }
.loadout-tabs button.active { color: #04110d; background: var(--mint); font-weight: 800; }
.weapon-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.weapon-grid[hidden] { display: none; }
.weapon-card {
  min-width: 0;
  min-height: 82px;
  padding: 10px;
  display: grid;
  gap: 4px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  background: var(--panel);
  cursor: pointer;
}
.weapon-card strong { color: var(--cyan); font-size: 13px; }
.weapon-card span { color: var(--muted); font-size: 10px; }
.weapon-card .formation-map { min-height: 22px; color: var(--mint); line-height: 1.15; text-align: center; }
.weapon-card small { color: var(--amber); font-size: 10px; }
.weapon-card.selected { border-color: var(--mint); background: #10251f; }
.weapon-card.selected strong, .weapon-card.selected small { color: var(--mint); }
.weapon-card:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.weapon-message { min-height: 16px; margin: 9px 0 0 !important; color: var(--muted); font-size: 10px; }

.pilot-panel { display: grid; gap: 8px; text-align: left; }
.pilot-panel[hidden] { display: none; }
.skins-panel[hidden] { display: none; }
.pilot-panel label, .pilot-panel > p { margin: 0; color: var(--muted); font-size: 10px; text-transform: uppercase; }
.profile-heading { min-height: 54px; display: flex; align-items: center; gap: 11px; }
.profile-heading > div:last-child { display: grid; gap: 2px; }
.profile-heading strong { color: var(--text); font-size: 16px; }
.profile-heading span { color: var(--muted); font-size: 9px; text-transform: uppercase; }
.profile-avatar { width: 48px; height: 48px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 4px; background: var(--panel); }
.profile-avatar img { width: 100%; height: 100%; border-radius: 3px; object-fit: cover; }
.profile-avatar i { width: 25px; height: 25px; border: 5px solid var(--skin-accent, var(--cyan)); background: var(--skin-base, var(--mint)); transform: rotate(45deg); }
.profile-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.profile-stats div { min-width: 0; padding: 8px; display: grid; gap: 3px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel); }
.profile-stats span { color: var(--muted); font-size: 8px; text-transform: uppercase; }
.profile-stats strong { overflow: hidden; color: var(--amber); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pilot-panel input { width: 100%; min-height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 4px; color: var(--text); background: var(--panel); font: inherit; }
.pilot-panel input:focus { border-color: var(--mint); outline: 2px solid rgba(85, 246, 189, .2); }
.profile-section-title { display: flex; align-items: end; justify-content: space-between; gap: 8px; }
.profile-section-title p { margin: 0; color: var(--muted); font-size: 10px; text-transform: uppercase; }
.profile-section-title span { color: var(--muted); font-size: 8px; }
.control-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.control-grid button { min-width: 0; min-height: 58px; padding: 6px; display: grid; place-items: center; gap: 2px; border: 1px solid var(--line); border-radius: 4px; color: var(--text); background: var(--panel); cursor: pointer; }
.control-grid button span { color: var(--muted); font-size: 8px; text-transform: uppercase; }
.control-grid button strong { max-width: 100%; overflow: hidden; color: var(--cyan); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.control-grid button small { color: var(--amber); font-size: 7px; }
.control-grid button.listening { border-color: var(--amber); background: #29210f; }
.control-grid button.listening strong { color: var(--amber); }
.motion-control { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; }
.motion-control > label { min-height: 48px; padding: 7px 10px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel); cursor: pointer; }
.motion-control label > span { min-width: 0; display: grid; gap: 3px; }
.motion-control strong { color: var(--text); font-size: 10px; text-transform: uppercase; }
.motion-control small { overflow: hidden; color: var(--muted); font-size: 8px; text-overflow: ellipsis; white-space: nowrap; }
.motion-control input { width: 42px; height: 23px; flex: 0 0 auto; accent-color: var(--mint); cursor: pointer; }
.motion-control > button { min-height: 48px; padding: 0 10px; border: 1px solid var(--line); border-radius: 4px; color: var(--cyan); background: var(--panel); font-size: 9px; font-weight: 700; cursor: pointer; }
.motion-control > button:disabled { color: var(--muted); opacity: .5; cursor: default; }
.motion-control.enabled > label { border-color: var(--mint); }
.motion-control.enabled small { color: var(--mint); }
.save-profile-button { min-height: 42px; border: 0; border-radius: 4px; color: #04110d; background: var(--mint); font-weight: 800; text-transform: uppercase; cursor: pointer; }
.logout-button { min-height: 38px; border: 1px solid var(--line); border-radius: 4px; color: var(--coral); background: transparent; font-weight: 700; text-transform: uppercase; cursor: pointer; }
.skin-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.skin-card { min-width: 0; min-height: 58px; padding: 7px; display: grid; grid-template-columns: 24px minmax(0, 1fr); align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 4px; color: var(--text); background: var(--panel); cursor: pointer; }
.skin-card.selected { border-color: var(--mint); background: #10251f; }
.skin-card span { min-width: 0; overflow: hidden; display: grid; gap: 3px; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.skin-card small { overflow: hidden; color: var(--amber); font-size: 8px; text-overflow: ellipsis; }
.skin-card.selected small { color: var(--mint); }
.skin-swatch { width: 22px; height: 22px; border: 4px solid var(--skin-accent); background: var(--skin-base); transform: rotate(45deg); }
.skin-swatch.mint { --skin-base: #55f6bd; --skin-accent: #55d6ff; }
.skin-swatch.solar { --skin-base: #ffc857; --skin-accent: #ff6577; }
.skin-swatch.ice { --skin-base: #dff7ff; --skin-accent: #55d6ff; }
.skin-swatch.crimson { --skin-base: #ff6577; --skin-accent: #ffc857; }
.skin-swatch.violet { --skin-base: #a78bfa; --skin-accent: #55d6ff; }
.skin-swatch.stealth { --skin-base: #c7cbd1; --skin-accent: #596275; }
.skin-swatch.ember { --skin-base: #ff8a4c; --skin-accent: #ffe08a; }
.skin-swatch.aurora { --skin-base: #34d399; --skin-accent: #c084fc; }
.skin-swatch.neon { --skin-base: #22d3ee; --skin-accent: #f472b6; }

.purchase-confirm {
  width: min(100%, 440px);
  padding: 18px;
  margin-bottom: 18px;
  border: 1px solid var(--amber);
  border-radius: 4px;
  color: var(--text);
  background: #111725;
}
.purchase-confirm[hidden] { display: none; }
.purchase-confirm > strong { color: var(--amber); text-transform: uppercase; }
.purchase-confirm > p { margin: 10px 0 15px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.purchase-confirm > div { display: flex; justify-content: center; gap: 8px; }
.purchase-confirm button { min-height: 40px; padding: 0 16px; border: 0; border-radius: 4px; color: #04110d; background: var(--mint); font-weight: 800; cursor: pointer; }
.purchase-confirm .secondary-button { color: var(--text); border: 1px solid var(--line); background: var(--panel); }

.intro-panel { width: min(100%, 480px); margin: 0 0 18px; display: grid; gap: 8px; text-align: left; }
.intro-panel[hidden], .leaderboard-panel[hidden] { display: none; }
.intro-panel > p { margin: 0 0 5px; color: var(--text); font-size: 12px; line-height: 1.55; }
.intro-panel > div { padding: 9px 10px; display: grid; gap: 3px; border-left: 3px solid var(--mint); background: var(--panel); }
.intro-panel strong { color: var(--cyan); font-size: 10px; text-transform: uppercase; }
.intro-panel span, .intro-panel small { color: var(--muted); font-size: 10px; line-height: 1.4; }
.intro-panel > small { padding: 8px 10px; color: var(--amber); border: 1px solid var(--line); }

.leaderboard-panel { width: min(100%, 480px); display: grid; gap: 12px; }
.leaderboard-panel ol { margin: 0; padding: 0; display: grid; gap: 5px; list-style: none; counter-reset: rank; }
.leaderboard-panel li { min-height: 38px; padding: 7px 10px; display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel); counter-increment: rank; }
.leaderboard-panel li::before { content: counter(rank) "."; color: var(--amber); font-weight: 800; }
.leaderboard-panel li strong { overflow: hidden; color: var(--text); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard-panel li span { color: var(--mint); font-size: 10px; font-variant-numeric: tabular-nums; }
.leaderboard-panel .empty-score { display: block; padding: 20px; color: var(--muted); text-align: center; }
.leaderboard-panel > button { min-height: 42px; border: 1px solid var(--line); border-radius: 4px; color: var(--text); background: var(--panel); cursor: pointer; }

.touch-controls {
  min-height: 108px;
  padding: 8px 14px;
  display: grid;
  grid-template-columns: minmax(132px, 1fr) minmax(150px, 1fr);
  align-items: center;
  gap: 14px;
  border-top: 1px solid var(--line);
  background: #080b14;
  touch-action: none;
}
.touch-controls[hidden] { display: none; }

.mobile-dpad { width: 132px; height: 92px; justify-self: center; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); gap: 5px; }
.mobile-dpad #upButton { grid-column: 2; grid-row: 1; }
.mobile-dpad #leftButton { grid-column: 1; grid-row: 2; }
.mobile-dpad #downButton { grid-column: 2; grid-row: 2; }
.mobile-dpad #rightButton { grid-column: 3; grid-row: 2; }
.mobile-actions { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 7px; }

.touch-controls button {
  min-width: 0;
  height: 56px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--cyan);
  background: var(--panel);
  font-size: 30px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.touch-controls button:active, .touch-controls button.active { border-color: var(--mint); color: var(--mint); background: #111a2d; }
.touch-controls .fire-button { color: var(--coral); }
.touch-controls .bomb-button { color: var(--amber); }
.touch-controls .special-button { color: var(--mint); }
.fire-button span { display: inline-block; width: 8px; height: 27px; background: currentColor; box-shadow: 0 -8px 0 -2px currentColor; }

.ability-status {
  min-height: 30px;
  padding: 5px 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  text-transform: uppercase;
  border-bottom: 1px solid var(--line);
  background: #080b14;
}

.ability-status > * { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ability-status strong { color: var(--text); font-variant-numeric: tabular-nums; }
.ability-status > :first-child strong { color: var(--amber); }
.ability-status > :nth-child(2) strong { color: var(--mint); }
.ability-status > :first-child { text-align: left; }
.ability-status > :last-child { text-align: right; }

@media (hover: hover) and (pointer: fine) {
  .touch-controls { min-height: 60px; max-width: 540px; width: 100%; justify-self: center; border: 0; background: transparent; }
  .mobile-dpad { height: 56px; grid-template-rows: 1fr; grid-template-columns: repeat(4, 1fr); }
  .mobile-dpad #upButton, .mobile-dpad #leftButton, .mobile-dpad #downButton, .mobile-dpad #rightButton { grid-row: 1; grid-column: auto; }
  .touch-controls button { height: 46px; }
}

@media (max-height: 650px) {
  .hud { min-height: 52px; padding-top: max(7px, env(safe-area-inset-top)); }
  .touch-controls { min-height: 92px; padding-block: 5px; }
  .touch-controls button { height: 46px; }
  .ability-status { min-height: 28px; }
  canvas { width: min(100%, calc((100dvh - 150px) * .8)); }
}

@media (max-width: 520px) {
  .key-hint { display: none; }
  .overlay { padding: 22px; }
  .overlay h1 { font-size: 30px; }
  .overlay > p:not(.eyebrow, .key-hint) { margin: 10px 0 14px; font-size: 12px; }
  .pixel-mark { display: none; }
  .eyebrow { margin-top: 0; }
  .weapon-card { min-height: 72px; padding: 8px; }
  .profile-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .skin-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .control-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .motion-control { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
