:root {
  color-scheme: dark;
  --ink: #f4f7ff;
  --muted: #a9b6d2;
  --panel: rgba(9, 13, 36, 0.88);
  --cyan: #2cf6ff;
  --cyan-2: #00b8ff;
  --violet: #8a5cff;
  --pink: #ff4fa3;
  --gold: #ffd75a;
  --green: #49f2a7;
  --danger: #ff637e;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

html {
  min-height: 100%;
  background: #040611;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 16% 18%, rgba(0, 209, 255, 0.14), transparent 31rem),
    radial-gradient(circle at 84% 10%, rgba(131, 68, 255, 0.2), transparent 34rem),
    linear-gradient(150deg, #03050e 0%, #080923 54%, #100628 100%);
  overflow-x: hidden;
  touch-action: manipulation;
  overscroll-behavior: none;
}

button, a, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

.space-backdrop,
.space-backdrop::before,
.space-backdrop::after {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
}

.space-backdrop {
  z-index: -1;
  opacity: .46;
  background-image:
    radial-gradient(circle, rgba(255,255,255,.8) 0 1px, transparent 1.5px),
    radial-gradient(circle, rgba(44,246,255,.75) 0 1px, transparent 1.4px);
  background-position: 0 0, 37px 63px;
  background-size: 113px 113px, 191px 191px;
}

.space-backdrop::before {
  background: linear-gradient(115deg, transparent 24%, rgba(44,246,255,.06) 50%, transparent 76%);
  transform: translateX(-50%);
  animation: nebula-drift 18s linear infinite;
}

.space-backdrop::after {
  background: repeating-linear-gradient(90deg, transparent 0 119px, rgba(111,132,255,.035) 120px);
  mask-image: linear-gradient(to bottom, transparent, #000 55%, transparent);
}

@keyframes nebula-drift { to { transform: translateX(50%); } }

.game-header {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: min(1480px, calc(100% - 2rem));
  min-height: 72px;
  margin: max(.75rem, env(safe-area-inset-top)) auto 0;
  padding: .65rem .8rem;
  border: 1px solid rgba(122, 154, 222, .28);
  border-radius: 24px;
  background: rgba(5, 10, 27, .7);
  box-shadow: 0 16px 55px rgba(0, 0, 0, .24), inset 0 1px rgba(255,255,255,.05);
  backdrop-filter: blur(18px);
}

.brand-link,
.exit-link {
  color: inherit;
  text-decoration: none;
}

.brand-link { display: flex; align-items: center; gap: .7rem; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  aspect-ratio: 1;
  border-radius: 15px;
  font-size: 1.45rem;
  font-weight: 900;
  background: linear-gradient(140deg, var(--cyan), #3778ff 52%, var(--violet));
  box-shadow: 0 0 24px rgba(44, 246, 255, .34);
}

.brand-copy { display: grid; line-height: 1.05; }
.brand-copy strong { font-size: 1.05rem; letter-spacing: -.02em; }
.brand-copy small { margin-top: .25rem; color: var(--cyan); font-size: .68rem; letter-spacing: .13em; text-transform: uppercase; }

.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: .55rem; min-width: 0; }

.game-select-pills {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: rgba(10, 15, 40, 0.7);
  border: 1px solid rgba(121, 148, 204, 0.32);
  border-radius: 9999px;
  padding: 3px;
}

.game-pill {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 9999px;
  transition: all 0.2s ease;
}

.game-pill:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.game-pill.active {
  color: #fff;
  background: linear-gradient(135deg, var(--cyan-2), var(--violet));
  box-shadow: 0 0 10px rgba(44, 246, 255, 0.4);
}

.access-chip,
.icon-button,
.exit-link {
  min-height: 43px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .42rem;
  padding: .55rem .85rem;
  border: 1px solid rgba(121, 148, 204, .32);
  border-radius: 14px;
  background: rgba(16, 22, 49, .78);
  color: #dce7ff;
  font-size: .82rem;
  font-weight: 700;
}

.access-chip {
  border-color: rgba(44,246,255,.34);
  color: var(--cyan);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-button { cursor: pointer; }
.icon-button:hover, .exit-link:hover { border-color: var(--cyan); color: #fff; }

.game-page {
  width: min(1480px, calc(100% - 2rem));
  margin: 1.35rem auto max(2rem, env(safe-area-inset-bottom));
}

.intro-copy {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  margin: 0 auto 1rem;
  padding: 0 .5rem;
}

.eyebrow,
.mission-tag {
  margin: 0 0 .42rem;
  color: var(--gold);
  font-size: clamp(.63rem, 1vw, .78rem);
  font-weight: 850;
  letter-spacing: .19em;
}

.intro-copy h1 {
  margin: 0;
  font-size: clamp(1.55rem, 4vw, 3.4rem);
  line-height: .95;
  letter-spacing: -.04em;
  text-shadow: 0 0 24px rgba(255,255,255,.1);
}

.intro-copy h1 span { color: var(--cyan); text-shadow: 0 0 25px rgba(44,246,255,.42); }
.intro-copy > p { max-width: 42rem; margin: 0 0 .2rem; color: var(--muted); font-size: .92rem; text-align: right; }

.arena-frame {
  position: relative;
  width: 100%;
  min-height: min(77vh, 840px);
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid rgba(44, 246, 255, .4);
  border-radius: 28px;
  background: #050719;
  box-shadow:
    0 0 0 1px rgba(125, 72, 255, .18),
    0 30px 80px rgba(0, 0, 0, .55),
    0 0 50px rgba(36, 209, 255, .08);
  isolation: isolate;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: inherit;
  outline: none;
  cursor: crosshair;
  touch-action: none;
}

#gameCanvas:focus-visible { box-shadow: inset 0 0 0 3px var(--gold); }

.scanlines {
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
  opacity: .08;
  background: repeating-linear-gradient(to bottom, transparent 0 4px, rgba(255,255,255,.16) 5px);
  mix-blend-mode: overlay;
}

.hud {
  position: absolute;
  z-index: 8;
  inset: 1rem 1rem auto;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr) auto;
  align-items: start;
  gap: .65rem;
  pointer-events: none;
}

.hud[hidden] { display: none; }

.hud-card,
.hud-center {
  min-height: 58px;
  padding: .62rem .75rem;
  border: 1px solid rgba(117, 137, 201, .25);
  border-radius: 13px;
  background: rgba(4, 7, 25, .74);
  box-shadow: inset 0 1px rgba(255,255,255,.04);
  backdrop-filter: blur(9px);
}

.hud-card { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .55rem; }
.hud-label { color: var(--muted); font-size: .63rem; font-weight: 900; letter-spacing: .15em; }
.meter { height: 8px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.09); }
.meter span { display: block; width: 100%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--green), var(--cyan)); box-shadow: 0 0 12px rgba(44,246,255,.6); transition: width .18s ease; }
.hull-card strong { color: var(--green); font-size: .78rem; }
.hud-center { display: flex; align-items: center; gap: .85rem; color: var(--muted); font-size: .67rem; letter-spacing: .1em; }
.hud-center strong { color: var(--ink); font-size: .92rem; }
.score-card { grid-template-columns: auto 1fr; justify-self: end; min-width: 180px; text-align: right; }
.score-card > strong { color: var(--gold); letter-spacing: .08em; }
.score-card small { grid-column: 1 / -1; color: var(--muted); font-size: .6rem; }
.score-card b { color: var(--pink); }

.pause-button {
  width: 48px;
  height: 48px;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 13px;
  background: rgba(4,7,25,.78);
  cursor: pointer;
  pointer-events: auto;
}
.pause-button:hover { border-color: var(--cyan); }

.game-overlay {
  position: absolute;
  z-index: 12;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: clamp(1rem, 3vw, 2.5rem);
  background:
    radial-gradient(circle at 50% 30%, rgba(86, 42, 174, .26), transparent 45%),
    rgba(3, 5, 18, .82);
  backdrop-filter: blur(5px);
}

.game-overlay[hidden] { display: none; }

.overlay-card {
  width: min(780px, 100%);
  padding: clamp(1.15rem, 3vw, 2.1rem);
  border: 1px solid rgba(82, 224, 255, .35);
  border-radius: 24px;
  background: linear-gradient(145deg, rgba(12, 16, 43, .94), rgba(20, 10, 49, .9));
  box-shadow: 0 25px 80px rgba(0,0,0,.48), inset 0 1px rgba(255,255,255,.06);
  text-align: center;
}

.overlay-card h2 { margin: 0; font-size: clamp(1.35rem, 3vw, 2.35rem); letter-spacing: -.025em; }
.overlay-card > p:not(.mission-tag, .fair-play-note) { color: var(--muted); }
.access-message { min-height: 1.35em; margin: .65rem 0 1rem; color: var(--cyan) !important; font-weight: 700; }

.difficulty-fieldset {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .65rem;
  margin: 1rem 0;
  padding: 0;
  border: 0;
}

.difficulty-fieldset legend { width: 100%; margin-bottom: .55rem; color: var(--muted); font-size: .78rem; font-weight: 750; text-align: left; }
.difficulty-option { position: relative; cursor: pointer; }
.difficulty-option input { position: absolute; opacity: 0; }
.difficulty-option > span {
  display: grid;
  min-height: 74px;
  place-content: center;
  padding: .65rem;
  border: 1px solid rgba(111, 132, 192, .27);
  border-radius: 15px;
  background: rgba(5, 9, 30, .72);
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}
.difficulty-option b { color: #fff; font-size: .82rem; letter-spacing: .12em; }
.difficulty-option small { margin-top: .25rem; color: var(--muted); font-size: .7rem; }
.difficulty-option input:checked + span { border-color: var(--cyan); background: rgba(20, 86, 112, .32); box-shadow: 0 0 22px rgba(44,246,255,.13); transform: translateY(-2px); }
.difficulty-option input:focus-visible + span { outline: 3px solid var(--gold); outline-offset: 2px; }

.control-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .55rem;
  margin: .85rem 0;
}

.control-grid > div {
  min-height: 62px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: .22rem;
  padding: .55rem;
  border: 1px solid rgba(125, 143, 193, .2);
  border-radius: 13px;
  background: rgba(5,8,25,.6);
}
.control-grid span { flex-basis: 100%; color: var(--muted); font-size: .67rem; }
kbd, .mouse-icon { min-width: 25px; padding: .2rem .34rem; border: 1px solid rgba(255,255,255,.28); border-bottom-width: 3px; border-radius: 6px; color: var(--gold); background: rgba(255,255,255,.07); font-size: .65rem; font-weight: 850; }

.comfort-option { display: flex; align-items: center; justify-content: center; gap: .55rem; margin: .8rem 0; color: var(--muted); font-size: .76rem; }
.comfort-option input { width: 18px; height: 18px; accent-color: var(--cyan); }

.primary-action,
.secondary-action,
.login-link {
  width: min(340px, 100%);
  min-height: 54px;
  display: grid;
  place-content: center;
  margin: .8rem auto 0;
  padding: .65rem 1rem;
  border-radius: 14px;
  text-decoration: none;
  cursor: pointer;
}

.primary-action {
  border: 1px solid var(--cyan);
  background: linear-gradient(110deg, rgba(0, 160, 208, .34), rgba(102, 56, 255, .38));
  box-shadow: 0 0 25px rgba(44,246,255,.18), inset 0 1px rgba(255,255,255,.1);
}
.primary-action span { font-weight: 900; letter-spacing: .09em; }
.primary-action small { margin-top: .18rem; color: #bce9f1; font-size: .67rem; }
.primary-action:not(:disabled):hover { transform: translateY(-2px); box-shadow: 0 0 38px rgba(44,246,255,.32); }
.primary-action:disabled { border-color: rgba(146,157,186,.3); background: rgba(62,68,88,.28); color: #8d98ad; cursor: not-allowed; box-shadow: none; }
.secondary-action, .login-link { min-height: 44px; color: #dce7ff; border: 1px solid rgba(141,159,205,.32); background: rgba(255,255,255,.045); font-weight: 700; }
.secondary-action:hover, .login-link:hover { border-color: var(--cyan); }
.secondary-action[aria-disabled="true"] { opacity: .46; pointer-events: none; cursor: wait; }
.fair-play-note { max-width: 38rem; margin: .8rem auto 0; color: #8290ad; font-size: .66rem; }

.compact-overlay { background: rgba(3,5,18,.7); }
.compact-card { width: min(520px, 100%); }
.trophy { margin: .45rem 0; font-size: clamp(2.6rem, 7vw, 5rem); filter: drop-shadow(0 0 20px rgba(255,215,90,.38)); }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin: 1.1rem 0; }
.result-grid span { display: grid; gap: .2rem; padding: .75rem; border: 1px solid rgba(120,141,193,.2); border-radius: 13px; background: rgba(4,7,24,.56); }
.result-grid small { color: var(--muted); font-size: .68rem; }
.result-grid strong { color: var(--gold); font-size: 1.25rem; }

.upgrade-card { width: min(920px, 100%); }
.upgrade-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; margin-top: 1rem; }
.upgrade-choice {
  min-height: 180px;
  display: grid;
  place-content: center;
  gap: .5rem;
  padding: 1rem;
  border: 1px solid rgba(104, 134, 203, .3);
  border-radius: 18px;
  background: linear-gradient(155deg, rgba(18, 26, 61, .88), rgba(29, 12, 53, .85));
  cursor: pointer;
}
.upgrade-choice:hover, .upgrade-choice:focus-visible { border-color: var(--cyan); transform: translateY(-3px); }
.upgrade-choice .upgrade-icon { font-size: 2.2rem; }
.upgrade-choice strong { color: var(--cyan); }
.upgrade-choice small { color: var(--muted); line-height: 1.45; }
.upgrade-choice kbd { justify-self: center; }

.touch-controls {
  position: absolute;
  z-index: 15;
  inset: auto 1rem max(1rem, env(safe-area-inset-bottom));
  display: flex;
  align-items: end;
  justify-content: space-between;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.touch-controls[hidden] { display: none; }
.touch-pad {
  position: relative;
  width: 160px;
  height: 160px;
  pointer-events: auto;
  touch-action: none;
}
.touch-pad button {
  position: absolute;
  width: 54px;
  height: 54px;
  border: 1.5px solid rgba(255,255,255,.36);
  border-radius: 16px;
  background: rgba(12,20,54,.82);
  backdrop-filter: blur(10px);
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  font-size: 1.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  transition: transform 0.08s ease, background-color 0.08s ease, border-color 0.08s ease;
}
.touch-pad button[data-touch-key="KeyW"] { left: 53px; top: 0; }
.touch-pad button[data-touch-key="KeyA"] { left: 0; top: 53px; }
.touch-pad button[data-touch-key="KeyS"] { left: 53px; top: 106px; }
.touch-pad button[data-touch-key="KeyD"] { left: 106px; top: 53px; }
.touch-pad button.active {
  border-color: var(--cyan);
  background: rgba(44,246,255,.35);
  box-shadow: 0 0 22px rgba(44,246,255,.6);
  transform: scale(0.94);
}
.fire-button {
  position: relative;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  border: 2px solid var(--pink);
  background: rgba(255, 42, 132, .24);
  box-shadow: 0 0 28px rgba(255,79,163,.28);
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  backdrop-filter: blur(10px);
  transition: transform 0.08s ease, background-color 0.08s ease, box-shadow 0.08s ease;
}
.fire-button span { display: block; font-weight: 900; letter-spacing: .1em; font-size: 1.15rem; }
.fire-button small { color: #ffc4df; font-size: 0.72rem; }
.fire-button.active {
  background: rgba(255,79,163,.55);
  box-shadow: 0 0 35px rgba(255,79,163,.7);
  transform: scale(0.92);
}

/* Fullscreen Mode Layout Rules */
:fullscreen, ::backdrop {
  background-color: #040611;
}
:fullscreen .game-header,
body.is-fullscreen .game-header {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  z-index: 20;
  background: rgba(8, 14, 40, 0.75);
  backdrop-filter: blur(12px);
  min-height: 48px;
  margin-bottom: 0;
  border-radius: 14px;
}
:fullscreen .game-page,
body.is-fullscreen .game-page {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  padding: 0;
  max-width: none;
}
:fullscreen .intro-copy,
:fullscreen .safety-strip,
body.is-fullscreen .intro-copy,
body.is-fullscreen .safety-strip {
  display: none !important;
}
:fullscreen .arena-frame,
body.is-fullscreen .arena-frame {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  border-radius: 0;
  border: none;
  margin: 0;
}

.screen-reader-status { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.safety-strip { display: flex; justify-content: center; flex-wrap: wrap; gap: .65rem 1.2rem; padding: 1rem; color: #8796b2; font-size: .72rem; }
.noscript-message { margin: 1rem auto; padding: 1rem; text-align: center; color: var(--danger); }

@media (max-width: 900px) {
  .game-header, .game-page { width: min(100% - 1rem, 1480px); }
  .game-header { min-height: 60px; border-radius: 18px; }
  .wide-label, .brand-copy small { display: none; }
  .access-chip { max-width: 42vw; }
  .intro-copy { display: block; }
  .intro-copy > p { margin-top: .6rem; text-align: left; }
  .arena-frame { min-height: 70vh; aspect-ratio: auto; border-radius: 20px; }
  .difficulty-fieldset { grid-template-columns: 1fr; }
  .difficulty-option > span { min-height: 56px; }
  .control-grid { grid-template-columns: repeat(2, 1fr); }
  .hud { grid-template-columns: 1fr auto auto; inset: .55rem .55rem auto; }
  .hud-center { display: none; }
  .hud-card { min-height: 48px; }
  .score-card { min-width: 130px; }
  .upgrade-grid { grid-template-columns: 1fr; }
  .upgrade-choice { min-height: 105px; }
}

@media (max-height: 760px) and (min-width: 700px) {
  .game-header { min-height: 58px; }
  .game-page { margin-top: .7rem; }
  .intro-copy { display: none; }
  .arena-frame { min-height: calc(100dvh - 88px); }
  .launch-card { padding: .9rem 1.2rem; }
  .launch-card h2 { font-size: 1.4rem; }
  .difficulty-option > span { min-height: 58px; }
  .control-grid > div { min-height: 48px; }
  .fair-play-note { margin-top: .45rem; }
}

@media (hover: none), (pointer: coarse) {
  #gameCanvas { cursor: default; }
  .control-grid { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .scanlines { display: none; }
}
