:root {
  --bg-deep: #05070b;
  --bezel-1: #4a505a;
  --bezel-2: #202329;
  --bezel-3: #34383f;
  --screen-bg: #060a12;
  --panel: #0a101c;
  --panel-2: #111a2a;
  --border: #202e47;
  --border-bright: #33507a;
  --text: #eaf1ff;
  --text-dim: #6d80a0;
  --cyan: #2ce0ff;
  --cyan-dim: #0f5c73;
  --amber: #ffb020;
  --green: #37ff9a;
  --red: #ff3b48;
  --font-display: 'Rajdhani', 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(ellipse 900px 500px at 50% -8%, #131c2c 0%, transparent 60%),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.012) 0px, rgba(255,255,255,0.012) 1px, transparent 1px, transparent 3px),
    var(--bg-deep);
  color: var(--text);
  font-family: var(--font-display);
  min-height: 100vh;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { font: inherit; }
a { color: inherit; text-decoration: none; }

/* ---------- Pilot Arcade shell ---------- */

.arcade-nav {
  width: 100%;
  min-height: 76px;
  padding: 0 clamp(18px, 5vw, 72px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid rgba(255, 176, 32, 0.25);
  background: rgba(5, 24, 35, 0.94);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
}

.arcade-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.28em;
  white-space: nowrap;
}

.arcade-brand img {
  display: block;
  width: 78px;
  height: auto;
  filter: drop-shadow(0 0 8px rgba(44, 224, 255, 0.25));
}

.arcade-brand strong {
  color: var(--amber);
}

.all-missions {
  min-height: 38px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border: 1px solid rgba(255, 176, 32, 0.5);
  border-radius: 4px;
  background: rgba(255, 176, 32, 0.08);
  color: var(--amber);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.all-missions:hover,
.all-missions:focus-visible {
  color: #161000;
  background: var(--amber);
  box-shadow: 0 0 20px rgba(255, 176, 32, 0.3);
  outline: 0;
}

.app-stage {
  width: 100%;
  min-height: calc(100vh - 76px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 34px 12px 60px;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 28%, rgba(31, 139, 174, 0.12), transparent 32%),
    linear-gradient(180deg, rgba(6, 29, 42, 0.3), transparent 42%);
}

.app-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  opacity: 0.2;
  background-image:
    linear-gradient(rgba(44, 224, 255, 0.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(44, 224, 255, 0.16) 1px, transparent 1px);
  background-size: 72px 72px;
  mask-image: radial-gradient(ellipse 72% 58% at 50% 38%, black 5%, transparent 75%);
}

.app-stage::after {
  content: "";
  position: absolute;
  z-index: -1;
  top: 130px;
  left: 50%;
  width: min(82vw, 860px);
  aspect-ratio: 1;
  transform: translateX(-50%);
  border-radius: 50%;
  opacity: 0.22;
  background:
    repeating-radial-gradient(circle, transparent 0 92px, rgba(44, 224, 255, 0.18) 93px 94px),
    conic-gradient(from 0deg, transparent 0 24.5%, rgba(255, 176, 32, 0.16) 25% 25.3%, transparent 25.5% 49.5%, rgba(44, 224, 255, 0.13) 50% 50.3%, transparent 50.5% 74.5%, rgba(44, 224, 255, 0.13) 75% 75.3%, transparent 75.5%);
  mask-image: radial-gradient(circle, black 0 48%, transparent 74%);
}

/* ---------- Open mission workspace ---------- */

.device {
  position: relative;
  width: 100%;
  max-width: 940px;
}

.device-screw {
  display: none;
}

.screen {
  position: relative;
  background: transparent;
}

.screen::before {
  display: none;
}

/* ---------- Header ---------- */

.app-header {
  padding: 26px 24px 18px;
  text-align: center;
  background: transparent;
}

.mission-id {
  margin: 0 0 8px;
  color: var(--amber);
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.app-header h1 {
  margin: 0 0 22px;
  font-size: clamp(1.15rem, 3vw, 1.65rem);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(44, 224, 255, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.brand-hair {
  flex: 1;
  max-width: 80px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--cyan-dim));
}
.app-header h1 .brand-hair:last-child {
  background: linear-gradient(90deg, var(--cyan-dim), transparent);
}

.mode-nav {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.mode-btn {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 11px 20px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

.mode-btn.active {
  color: #181000;
  background: linear-gradient(180deg, #ffd06b, var(--amber));
  border-color: var(--amber);
  box-shadow: 0 0 14px rgba(255, 176, 32, 0.42);
}

.guide-trigger {
  margin: 13px auto 0;
  padding: 4px 6px;
  border: 0;
  color: #8294ae;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  cursor: pointer;
}

.guide-trigger:hover,
.guide-trigger:focus-visible {
  color: var(--amber);
  outline: 0;
}

.first-use {
  width: min(calc(100% - 48px), 760px);
  margin: 0 auto 8px;
  padding: 11px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-left: 2px solid var(--amber);
  background: rgba(9, 22, 35, 0.76);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.16);
}

.first-use[hidden] {
  display: none;
}

.first-use strong {
  color: var(--amber);
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 0.12em;
}

.first-use p {
  margin: 3px 0 0;
  color: #8fa1ba;
  font-size: 0.76rem;
}

.first-use button {
  flex: 0 0 auto;
  padding: 7px 11px;
  border: 1px solid rgba(255, 176, 32, 0.45);
  border-radius: 3px;
  color: var(--amber);
  background: rgba(255, 176, 32, 0.08);
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
}

main {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 20px 24px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* ---------- Stats bar ---------- */

.stats-bar {
  display: flex;
  width: 100%;
  padding: 0;
}

.stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  position: relative;
}
.stat + .stat::before {
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 1px;
  background: var(--border);
}

.stat-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  font-weight: 600;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--cyan);
}

/* ---------- Mode screens ---------- */

.mode-screen {
  display: none;
  flex-direction: column;
  align-items: center;
  width: 100%;
  gap: 16px;
}
.mode-screen.active { display: flex; }

.prompt-text {
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0;
  text-align: center;
}
.prompt-text strong { color: var(--cyan); font-weight: 700; }

.atc-line {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--green);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  width: 100%;
  text-align: center;
  min-height: 1.4em;
}

.heading-display {
  font-family: var(--font-mono);
  font-size: 2.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--amber);
  text-shadow: 0 0 16px rgba(255, 176, 32, 0.35);
  letter-spacing: 0.04em;
  line-height: 1;
}

.runway-display::before {
  content: "RWY ";
  font-size: 1.2rem;
  color: var(--text-dim);
  font-family: var(--font-display);
  font-weight: 700;
}

.answer-display {
  font-family: var(--font-mono);
  font-size: 1.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border-bright);
  border-radius: 8px;
  padding: 8px 20px;
  min-width: 140px;
  text-align: center;
  letter-spacing: 0.2em;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4) inset, 0 0 16px rgba(44, 224, 255, 0.06) inset;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 430px;
}

.keypad button {
  width: 100%;
  height: 68px;
  font-family: var(--font-mono);
  font-size: 1.7rem;
  font-weight: 700;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  color: var(--text);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset;
  cursor: pointer;
}

.keypad button:active {
  background: var(--cyan);
  color: #04141a;
}

.keypad button.key-clear {
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: var(--cyan);
}

.feedback {
  min-height: 1.5em;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: center;
}
.feedback.correct { color: var(--green); text-shadow: 0 0 10px rgba(55, 255, 154, 0.4); }
.feedback.wrong { color: var(--red); text-shadow: 0 0 10px rgba(255, 59, 72, 0.4); }

.keyboard-hint {
  margin: 2px 0 0;
  color: #526885;
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 0.03em;
  text-align: center;
}

.keyboard-hint span {
  color: var(--cyan);
}

/* ---------- Compass dial ---------- */

.compass-wrap {
  width: 100%;
  max-width: 360px;
  aspect-ratio: 1 / 1;
}

#compass-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.dial-bezel { fill: none; stroke: var(--border); stroke-width: 1; }
.dial-face { fill: var(--panel); stroke: var(--border-bright); stroke-width: 2; }
.dial-groove { fill: none; stroke: rgba(255, 255, 255, 0.035); stroke-width: 1; }
.tick-major { stroke: #9fb4d6; stroke-width: 2; }
.tick-minor { stroke: #2c4568; stroke-width: 1; }
.dial-cardinal { fill: var(--cyan); font-family: var(--font-mono); font-weight: 700; }
.dial-label { fill: #b7c6e0; font-family: var(--font-mono); font-weight: 600; }
.dial-hub { fill: #5e7396; }
.heading-bug-line {
  stroke: var(--amber);
  stroke-width: 3;
  filter: drop-shadow(0 0 4px rgba(255, 176, 32, 0.6));
}
.heading-tag-box { fill: #14202f; stroke: var(--amber); stroke-width: 1.5; }
.heading-tag-text { fill: var(--amber); font-family: var(--font-mono); font-weight: 700; }
.mark-correct { fill: var(--green); filter: drop-shadow(0 0 5px rgba(55, 255, 154, 0.6)); }

/* ---------- Timed mode ---------- */

.difficulty-toggle { display: flex; gap: 8px; }

.diff-btn {
  background: var(--panel-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
}

.diff-btn.active {
  color: #181000;
  background: linear-gradient(180deg, #ffd06b, var(--amber));
  border-color: var(--amber);
  box-shadow: 0 0 10px rgba(255, 176, 32, 0.4);
}

.timer-bar-wrap {
  width: 100%;
  height: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.timer-bar {
  height: 100%;
  width: 100%;
  background: var(--green);
  transition: width 0.1s linear, background-color 0.2s;
}

.lives {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.annunciator {
  width: 24px;
  height: 14px;
  border-radius: 3px;
  background: #250b0d;
  border: 1px solid #431418;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4) inset;
}

.annunciator.lit {
  background: linear-gradient(180deg, #ff7a7a, var(--red));
  border-color: #ff9a9a;
  box-shadow: 0 0 8px rgba(255, 59, 72, 0.7);
}

.game-over {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, 0.94);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 10;
  text-align: center;
  padding: 20px;
}

.game-over:not([hidden]) { display: flex; }

.game-over h2 {
  color: var(--red);
  margin: 0;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-shadow: 0 0 12px rgba(255, 59, 72, 0.4);
}

.primary-btn {
  background: linear-gradient(180deg, #ffd06b, var(--amber));
  color: #181000;
  border: none;
  border-radius: 8px;
  padding: 12px 28px;
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  box-shadow: 0 0 14px rgba(255, 176, 32, 0.45);
}

.app-footer {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: 16px 20px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: transparent;
}

.telemetry {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 14px;
  border-top: 1px solid rgba(44, 224, 255, 0.14);
  border-bottom: 1px solid rgba(44, 224, 255, 0.14);
  background: rgba(5, 15, 25, 0.46);
}

.telemetry-label {
  color: var(--amber);
  font-family: var(--font-mono);
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  white-space: nowrap;
}

#reset-stats-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.7rem;
  letter-spacing: 0.03em;
  text-decoration: underline;
  cursor: pointer;
}

@media (min-width: 480px) {
  .heading-display { font-size: 3.4rem; }
}

@media (max-width: 560px) {
  .arcade-nav { min-height: 68px; padding: 0 14px; }
  .arcade-brand { gap: 8px; font-size: 0.61rem; letter-spacing: 0.2em; }
  .arcade-brand img { width: 58px; }
  .all-missions { padding: 0 10px; font-size: 0.58rem; }
  .app-stage { padding-top: 20px; }
  .app-header { padding-inline: 12px; }
  .first-use { width: calc(100% - 24px); align-items: flex-start; }
  .mode-btn { flex: 1 1 30%; padding: 9px 7px; font-size: 0.65rem; }
  main { padding-inline: 12px; }
  .keypad button { height: 64px; }
  .app-footer { flex-direction: column; gap: 10px; }
  .telemetry { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
