:root {
  --ink: #e9f5ec;
  --muted: #839891;
  --lime: #b8ff3d;
  --lime-soft: rgba(184, 255, 61, .18);
  --amber: #ffad32;
  --danger: #ff4f56;
  --panel: rgba(8, 15, 18, .88);
  --line: rgba(169, 203, 188, .18);
  --bg: #03070a;
  --display: "Oxanium", sans-serif;
  --tech: "Chakra Petch", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 15% 20%, rgba(40, 91, 78, .14), transparent 35%),
    linear-gradient(135deg, #020406 0%, #071013 45%, #030609 100%);
  color: var(--ink);
  font-family: var(--tech);
}

button, input { font: inherit; }
button { color: inherit; }

.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .1;
  z-index: 20;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.92' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.3'/%3E%3C/svg%3E");
}

.shell {
  width: min(1180px, calc(100% - 32px));
  height: 100dvh;
  margin: 0 auto;
  padding: 0;
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr) 34px;
}

.topbar, .footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar { height: 58px; }

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: flex;
  gap: 3px;
  align-items: flex-end;
  justify-content: center;
  padding: 9px;
  border: 1px solid var(--line);
  transform: skew(-7deg);
}

.brand-mark i {
  width: 5px;
  background: var(--lime);
  box-shadow: 0 0 12px var(--lime);
}
.brand-mark i:nth-child(1) { height: 12px; }
.brand-mark i:nth-child(2) { height: 23px; }
.brand-mark i:nth-child(3) { height: 17px; }

.brand > span:last-child { display: grid; line-height: 1; }
.brand b { font: 800 21px var(--display); letter-spacing: .16em; }
.brand small { margin-top: 5px; color: var(--muted); font-size: 9px; letter-spacing: .22em; text-transform: uppercase; }

.mission-clock { text-align: center; font-size: 9px; letter-spacing: .2em; }
.mission-clock span { display: block; color: var(--muted); }
.mission-clock strong { display: block; margin-top: 5px; color: var(--lime); font-size: 10px; }
.mission-clock strong::before { content: ""; display: inline-block; width: 5px; height: 5px; margin-right: 7px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 8px var(--lime); }

.icon-button, .close-button {
  border: 1px solid var(--line);
  background: rgba(10, 20, 22, .6);
  cursor: pointer;
}

.icon-button { width: 42px; height: 42px; }
.sound-waves { height: 20px; display: flex; gap: 3px; align-items: center; justify-content: center; }
.sound-waves i { width: 2px; background: var(--lime); }
.sound-waves i:nth-child(1) { height: 7px; }
.sound-waves i:nth-child(2) { height: 15px; }
.sound-waves i:nth-child(3) { height: 10px; }
.muted .sound-waves i { background: var(--muted); height: 2px; }

.game-frame {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: min(100%, calc((100dvh - 92px) * 1.6));
  height: auto;
  aspect-ratio: 16 / 10;
  min-height: 0;
  max-height: 100%;
  place-self: center;
  border: 1px solid rgba(184, 255, 61, .2);
  background: #04090d;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55), inset 0 0 80px rgba(0, 0, 0, .5);
}

.game-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(255,255,255,.018) 0, rgba(255,255,255,.018) 1px, transparent 1px, transparent 4px);
  mix-blend-mode: screen;
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

.corner {
  position: absolute;
  z-index: 10;
  width: 34px;
  height: 34px;
  pointer-events: none;
  border-color: var(--lime);
  opacity: .75;
}
.corner-tl { top: 10px; left: 10px; border-top: 2px solid; border-left: 2px solid; }
.corner-tr { top: 10px; right: 10px; border-top: 2px solid; border-right: 2px solid; }
.corner-bl { bottom: 10px; left: 10px; border-bottom: 2px solid; border-left: 2px solid; }
.corner-br { bottom: 10px; right: 10px; border-bottom: 2px solid; border-right: 2px solid; }

.screen {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  padding: clamp(45px, 6vw, 80px);
  background: linear-gradient(90deg, rgba(3, 8, 10, .96) 0%, rgba(3, 8, 10, .78) 48%, rgba(3, 8, 10, .23) 100%);
}
.screen.active { display: block; animation: screen-in .45s cubic-bezier(.2,.8,.2,1) both; }

@keyframes screen-in {
  from { opacity: 0; transform: scale(1.015); }
  to { opacity: 1; transform: scale(1); }
}

.menu-grid {
  display: grid;
  grid-template-columns: 1.2fr .8fr;
  gap: clamp(40px, 7vw, 100px);
  height: calc(100% - 46px);
  align-items: center;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--lime);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .24em;
}
.eyebrow > span { display: inline-block; width: 26px; height: 1px; margin: 0 8px 3px 0; background: var(--lime); }

h1, h2 { font-family: var(--display); text-transform: uppercase; }
h1 {
  margin: 0;
  font-size: clamp(48px, 7vw, 94px);
  line-height: .82;
  letter-spacing: -.065em;
  text-shadow: 0 0 40px rgba(228, 248, 237, .08);
}
h1 em { color: transparent; font-style: normal; -webkit-text-stroke: 1px var(--lime); text-shadow: 0 0 20px rgba(184, 255, 61, .12); }
.briefing { max-width: 490px; margin: 28px 0 22px; color: #a5b7b0; font-size: 14px; line-height: 1.55; }
.mission-tags { display: flex; gap: 8px; flex-wrap: wrap; }
.mission-tags span { padding: 7px 10px; border: 1px solid var(--line); color: var(--muted); font-size: 9px; letter-spacing: .12em; }

.command-card {
  position: relative;
  padding: 22px;
  border: 1px solid var(--line);
  background: linear-gradient(145deg, rgba(14, 26, 28, .92), rgba(5, 10, 12, .88));
  box-shadow: 18px 18px 0 rgba(1, 3, 4, .38);
}
.command-card::before { content: ""; position: absolute; top: -1px; left: 22px; width: 64px; height: 2px; background: var(--lime); box-shadow: 0 0 15px var(--lime); }
.card-heading { display: flex; justify-content: space-between; padding-bottom: 16px; color: var(--muted); font-size: 9px; letter-spacing: .14em; border-bottom: 1px solid var(--line); }
.card-heading small { color: var(--lime); }
fieldset { margin: 18px 0; padding: 0; border: 0; }
legend { margin-bottom: 10px; color: #d4dfda; font-size: 9px; letter-spacing: .18em; }
.difficulty-grid { display: grid; gap: 7px; }
.difficulty-grid button {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 9px 12px;
  text-align: left;
  border: 1px solid var(--line);
  background: rgba(3, 7, 9, .65);
  cursor: pointer;
  transition: .2s ease;
}
.difficulty-grid button:hover { border-color: rgba(184, 255, 61, .55); transform: translateX(3px); }
.difficulty-grid button.selected { border-color: var(--lime); background: var(--lime-soft); }
.difficulty-grid button > b { color: var(--muted); font: 700 20px var(--display); }
.difficulty-grid button.selected > b { color: var(--lime); }
.difficulty-grid button span { display: grid; }
.difficulty-grid strong { font-size: 11px; letter-spacing: .14em; }
.difficulty-grid small { margin-top: 2px; color: var(--muted); font-size: 9px; }

.primary-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 45px;
  padding: 0 7px 0 16px;
  border: 0;
  background: var(--lime);
  color: #071007;
  font-weight: 700;
  font-size: 10px;
  letter-spacing: .16em;
  cursor: pointer;
  transition: filter .2s, transform .2s;
}
.primary-button:hover { filter: brightness(1.15); transform: translateY(-2px); }
.primary-button i { display: grid; place-items: center; width: 32px; height: 32px; background: rgba(5, 12, 5, .12); font-size: 19px; font-style: normal; }
.text-button { display: block; margin: 13px auto 0; border: 0; background: transparent; color: var(--muted); font-size: 9px; letter-spacing: .14em; cursor: pointer; }
.text-button:hover { color: var(--lime); }

.secondary-button {
  display: grid;
  grid-template-columns: 28px 1fr 18px;
  align-items: center;
  width: 100%;
  min-height: 38px;
  margin-top: 8px;
  padding: 0 10px;
  border: 1px solid rgba(184,255,61,.32);
  background: rgba(184,255,61,.045);
  color: #b8c9c1;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: .13em;
  cursor: pointer;
  transition: .2s ease;
}
.secondary-button i { color: var(--lime); font: normal 18px var(--display); }
.secondary-button b { color: var(--lime); font-size: 14px; }
.secondary-button:hover { border-color: var(--lime); color: var(--ink); background: var(--lime-soft); }

.controls-strip {
  position: absolute;
  left: clamp(45px, 6vw, 80px);
  right: clamp(45px, 6vw, 80px);
  bottom: 24px;
  display: flex;
  gap: 25px;
  color: var(--muted);
  font-size: 8px;
  letter-spacing: .12em;
}
kbd { display: inline-grid; min-width: 19px; height: 18px; padding: 0 4px; place-items: center; margin-right: 3px; border: 1px solid var(--line); background: rgba(0,0,0,.5); color: var(--ink); font: 8px var(--tech); }

.hud {
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 19px 28px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(2, 6, 8, .9), transparent);
}
.hidden { display: none !important; }
.hud-cell { display: grid; gap: 2px; }
.hud-cell span { color: var(--muted); font-size: 8px; letter-spacing: .2em; }
.hud-cell strong { font: 700 18px var(--display); letter-spacing: .08em; }
.hud-center { justify-items: center; }
.hud-right { justify-items: end; }
.hud-right strong { color: var(--lime); font-size: 14px; }
.progress-track { width: 130px; height: 2px; margin-top: 7px; background: rgba(255,255,255,.12); }
.progress-track i { display: block; width: 0; height: 100%; background: var(--lime); box-shadow: 0 0 10px var(--lime); transition: width .2s; }

.compact-screen {
  padding: 0;
  text-align: center;
  place-content: center;
  background: rgba(3, 8, 10, .9);
  backdrop-filter: blur(7px);
}
.compact-screen.active { display: grid; }
.compact-screen h2, .ranking-screen h2 { margin: 0; font-size: clamp(32px, 5vw, 58px); letter-spacing: -.04em; }
.compact-screen > p:not(.eyebrow) { color: var(--muted); }
.compact-screen .primary-button { width: 270px; margin: 20px auto 0; }
.exit-actions { width: 280px; margin: 5px auto 0; }
.exit-actions .primary-button { width: 100%; }
.danger-button {
  width: 100%;
  min-height: 40px;
  margin-top: 9px;
  border: 1px solid rgba(255,79,86,.55);
  background: rgba(255,79,86,.08);
  color: #ff858a;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .15em;
  cursor: pointer;
}
.danger-button:hover { background: var(--danger); color: #fff; }
.result-score, .final-score { display: grid; margin: 18px 0 5px; }
.result-score span, .final-score span { color: var(--muted); font-size: 8px; letter-spacing: .2em; }
.result-score strong, .final-score strong { color: var(--lime); font: 700 30px var(--display); }

#score-form { width: min(470px, 80vw); margin-top: 16px; }
#score-form label { display: block; margin-bottom: 7px; text-align: left; color: var(--muted); font-size: 8px; letter-spacing: .18em; }
.input-row { display: grid; grid-template-columns: 1fr 160px; gap: 8px; }
.input-row input { min-width: 0; border: 1px solid var(--line); outline: 0; background: rgba(0,0,0,.45); padding: 0 14px; color: var(--ink); text-transform: uppercase; letter-spacing: .12em; }
.input-row input:focus { border-color: var(--lime); box-shadow: 0 0 0 2px var(--lime-soft); }

.ranking-screen {
  padding: clamp(28px, 5vw, 58px) clamp(35px, 8vw, 100px);
  background: rgba(3, 8, 10, .95);
  backdrop-filter: blur(10px);
}
.ranking-header { display: flex; align-items: flex-start; justify-content: space-between; }
.close-button { width: 42px; height: 42px; color: var(--muted); font-size: 23px; }
.close-button:hover { color: var(--lime); border-color: var(--lime); }
.ranking-labels, .ranking-screen li {
  display: grid;
  grid-template-columns: 1.7fr .8fr .45fr .75fr;
  gap: 10px;
  align-items: center;
}
.ranking-labels { margin-top: 25px; padding: 0 15px 9px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 8px; letter-spacing: .16em; }
.ranking-labels span:last-child { text-align: right; }
.ranking-screen ol { margin: 0; padding: 0; list-style: none; counter-reset: rank; }
.ranking-screen li { counter-increment: rank; min-height: 37px; padding: 0 15px; border-bottom: 1px solid rgba(169,203,188,.09); font-size: 10px; letter-spacing: .1em; }
.ranking-screen li::before { content: counter(rank, decimal-leading-zero); color: var(--lime); }
.ranking-screen li .pilot { margin-left: -28px; font-weight: 700; }
.ranking-screen li .points { text-align: right; color: var(--lime); font: 600 13px var(--display); }
.ranking-screen li span:not(.pilot):not(.points) { color: var(--muted); }
.ranking-status { text-align: center; color: var(--muted); font-size: 9px; letter-spacing: .14em; }

.touch-controls {
  position: absolute;
  z-index: 4;
  inset: 0;
  pointer-events: none;
}
.fire-touch {
  position: absolute;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: max(18px, env(safe-area-inset-left));
  width: 76px;
  height: 76px;
  border: 1px solid rgba(255,79,86,.65);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,79,86,.24), rgba(4,12,13,.88) 66%);
  color: #ff8186;
  box-shadow: inset 0 0 0 7px rgba(255,79,86,.06), 0 0 22px rgba(255,79,86,.15);
  font: 700 8px var(--display);
  letter-spacing: .14em;
  pointer-events: auto;
  z-index: 2;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.fire-touch:active {
  background: var(--danger);
  color: #fff;
  transform: scale(.93);
}

.joystick-zone {
  position: absolute;
  z-index: 1;
  top: 0;
  right: 0;
  bottom: 0;
  width: 50%;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.joystick {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  width: 94px;
  height: 94px;
  border: 1px solid rgba(184,255,61,.35);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(184,255,61,.06), rgba(3,10,11,.82) 68%);
  box-shadow: inset 0 0 0 9px rgba(184,255,61,.025), 0 0 25px rgba(184,255,61,.1);
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.joystick.floating {
  right: auto;
  bottom: auto;
  transform: translate(-50%, -50%);
}
.joystick::before, .joystick::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 7px;
  height: 7px;
  border-color: rgba(184,255,61,.55);
  transform: translateY(-50%) rotate(45deg);
}
.joystick::before { left: 12px; border-left: 1px solid; border-bottom: 1px solid; }
.joystick::after { right: 12px; border-right: 1px solid; border-top: 1px solid; }
.joystick-ring { position: absolute; inset: 18px; border: 1px dashed rgba(184,255,61,.18); border-radius: 50%; }
.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 38px;
  height: 38px;
  border: 1px solid var(--lime);
  border-radius: 50%;
  background: radial-gradient(circle at 38% 35%, #d7ff8f, #75a91f 18%, #14220e 72%);
  box-shadow: 0 0 18px rgba(184,255,61,.28);
  transform: translate(-50%, -50%);
  transition: transform .08s ease-out;
  pointer-events: none;
}
.joystick.active .joystick-knob { transition: none; }
.swap-controls {
  position: absolute;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(169,203,188,.18);
  background: rgba(3,10,11,.7);
  color: var(--muted);
  font-size: 8px;
  letter-spacing: .12em;
  pointer-events: auto;
  z-index: 2;
  touch-action: manipulation;
}
.swap-controls:active { color: var(--lime); border-color: var(--lime); }
.touch-controls.swapped .fire-touch { left: auto; right: max(18px, env(safe-area-inset-right)); }
.touch-controls.swapped .joystick-zone { left: 0; right: auto; }
.touch-controls.swapped .joystick { right: auto; left: max(14px, env(safe-area-inset-left)); }

.orientation-gate {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: none;
  place-content: center;
  justify-items: center;
  padding: 35px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 35%, rgba(184,255,61,.12), transparent 35%),
    rgba(2,7,9,.98);
}
.orientation-gate h2 { margin: 0; font-size: clamp(30px, 10vw, 48px); }
.orientation-gate > p:last-child { max-width: 310px; color: var(--muted); font-size: 13px; }
.phone-rotate { position: relative; width: 92px; height: 70px; margin-bottom: 24px; }
.phone-rotate span {
  position: absolute;
  left: 29px;
  top: 8px;
  width: 34px;
  height: 56px;
  border: 2px solid var(--lime);
  border-radius: 6px;
  box-shadow: 0 0 20px rgba(184,255,61,.2);
  animation: rotate-phone 2.2s ease-in-out infinite;
}
.phone-rotate span::after {
  content: "";
  position: absolute;
  bottom: 4px;
  left: 50%;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--lime);
  transform: translateX(-50%);
}
.phone-rotate i {
  position: absolute;
  right: 0;
  bottom: -2px;
  color: var(--lime);
  font: 28px var(--display);
}
@keyframes rotate-phone {
  0%, 20% { transform: rotate(0); }
  65%, 100% { transform: rotate(90deg); }
}

.footer { height: 34px; color: #52635d; font-size: 7px; letter-spacing: .2em; }

@media (max-width: 850px) {
  .shell { width: 100%; }
  .topbar, .footer { padding: 0 15px; }
  .game-frame { width: min(100%, calc((100dvh - 92px) * 1.6)); min-height: 0; border-left: 0; border-right: 0; }
  .menu-grid { grid-template-columns: 1fr; align-content: center; gap: 25px; }
  .hero-copy { display: none; }
  .command-card { width: min(410px, 100%); margin: auto; }
  .screen { padding: 50px 28px; }
  .controls-strip { display: none; }
  .coordinates { display: none; }
}

@media (pointer: coarse), (max-width: 700px) {
  .touch-controls:not(.hidden) { display: flex; }
  .hud { padding: 15px; }
  .ranking-screen { padding: 35px 18px; }
  .ranking-labels, .ranking-screen li { grid-template-columns: 1.5fr .7fr .35fr .75fr; }
}

@media (max-height: 660px) and (min-width: 700px) {
  .shell { grid-template-rows: 44px minmax(0, 1fr) 24px; }
  .topbar { height: 44px; }
  .footer { height: 24px; }
  .game-frame { width: min(100%, calc((100dvh - 68px) * 1.6)); min-height: 0; }
  .screen { padding-top: 32px; padding-bottom: 32px; }
  .briefing { margin: 18px 0 14px; }
  .command-card { padding: 15px; }
  .difficulty-grid button { padding: 6px 10px; }
  .controls-strip { bottom: 14px; }
}

@media (pointer: coarse) and (orientation: portrait) {
  .orientation-gate {
    position: fixed;
    display: grid;
    width: 100vw;
    height: 100dvh;
  }
}

@media (pointer: coarse) and (orientation: landscape), (max-width: 950px) and (max-height: 500px) {
  .shell {
    width: 100%;
    height: 100dvh;
    display: block;
  }
  .topbar, .footer { display: none; }
  .game-frame {
    width: 100%;
    height: 100dvh;
    max-height: none;
    aspect-ratio: auto;
    border: 0;
  }
  canvas {
    left: 50%;
    width: min(100%, calc(100dvh * 1.6));
    transform: translateX(-50%);
  }
  .screen {
    padding: 12px max(86px, env(safe-area-inset-left));
    background: rgba(3,8,10,.86);
  }
  .menu-grid {
    height: 100%;
    grid-template-columns: 1fr;
    gap: 0;
  }
  .hero-copy, .controls-strip { display: none; }
  .command-card {
    width: min(390px, calc(100vw - 190px));
    max-height: calc(100dvh - 20px);
    margin: auto;
    padding: 12px 15px;
    overflow: auto;
    box-shadow: 10px 10px 0 rgba(1,3,4,.3);
  }
  .card-heading { padding-bottom: 8px; }
  fieldset { margin: 9px 0; }
  legend { margin-bottom: 6px; }
  .difficulty-grid { gap: 4px; }
  .difficulty-grid button { min-height: 42px; padding: 4px 9px; }
  .primary-button { min-height: 40px; }
  .text-button { margin-top: 8px; }
  .secondary-button { min-height: 34px; margin-top: 5px; }
  .hud { left: 50%; width: min(100%, calc(100dvh * 1.6)); transform: translateX(-50%); }
  .ranking-screen { padding: 20px max(80px, env(safe-area-inset-left)); }
  .compact-screen { padding-left: 90px; padding-right: 90px; }
}
