:root {
  --bg-glass: rgba(12, 20, 38, 0.66);
  --border-glass: rgba(145, 205, 255, 0.25);
  --text-main: #f3f7ff;
  --text-muted: #9eb7d9;
  --accent-cyan: #38e4ff;
  --accent-green: #42f59b;
  --accent-orange: #ff9f43;
  --accent-red: #ff5c77;
  --accent-gold: #ffd166;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  background: #081226;
  font-family: ui-rounded, 'SF Pro Rounded', 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--text-main);
}

#sim-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px 20px;
}

.hidden {
  display: none !important;
}

.glass-panel {
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid var(--border-glass);
  border-radius: 18px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

/* Top Bar */
.hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand-pill {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-glass);
  border: 1.5px solid var(--border-glass);
  border-radius: 999px;
  backdrop-filter: blur(10px);
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 10px var(--accent-green);
}

.brand-title {
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.08em;
}

.mission-stepper {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--bg-glass);
  border: 1.5px solid var(--border-glass);
  border-radius: 999px;
  backdrop-filter: blur(10px);
}

.step-item {
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0.5;
  transition: all 0.25s ease;
}

.step-item.active {
  opacity: 1;
}

.step-item.done {
  opacity: 0.92;
}

.step-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.14);
}

.step-item.active .step-num {
  background: var(--accent-cyan);
  color: #061829;
  box-shadow: 0 0 12px rgba(56, 228, 255, 0.65);
}

.step-item.done .step-num {
  background: var(--accent-green);
  color: #052616;
}

.step-label {
  font-size: 12px;
  font-weight: 700;
}

.step-line {
  width: 14px;
  height: 2px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
}

.top-actions {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.glass-btn, .glass-select {
  pointer-events: auto;
  background: var(--bg-glass);
  color: var(--text-main);
  border: 1.5px solid var(--border-glass);
  border-radius: 999px;
  padding: 8px 13px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: transform 0.12s ease, border-color 0.2s ease, background 0.2s ease;
}

.glass-btn:hover, .glass-select:hover {
  border-color: var(--accent-cyan);
  background: rgba(22, 38, 68, 0.82);
}

.glass-btn:active {
  transform: scale(0.96);
}

.glass-select option {
  background: #0d182e;
  color: var(--text-main);
}

/* Left Telemetry */
.hud-left {
  position: fixed;
  left: 20px;
  top: 76px;
  width: 215px;
  padding: 14px 16px;
}

.telem-header {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.telem-grid {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.telem-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.telem-key {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
}

.telem-val {
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.bar-track {
  width: 92px;
  height: 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  transition: width 0.08s linear;
}

.bar-orange {
  background: linear-gradient(90deg, #ff7b29, #ffd166);
}

.bar-cyan {
  background: linear-gradient(90deg, #1cb5e0, #42f59b);
}

.badge-cyan { color: var(--accent-cyan); }
.badge-green { color: var(--accent-green); }

/* Right Catch Radar */
.hud-right {
  position: fixed;
  right: 20px;
  top: 76px;
  width: 230px;
  padding: 14px 16px;
}

.catch-instruments {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.bullseye-wrap {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(66, 245, 155, 0.16) 0%, rgba(10, 20, 38, 0.7) 75%);
  border: 1.5px solid rgba(66, 245, 155, 0.35);
  overflow: hidden;
}

.bullseye-ring.outer {
  position: absolute;
  inset: 16px;
  border-radius: 50%;
  border: 1.5px dashed rgba(66, 245, 155, 0.45);
}

.bullseye-ring.inner {
  position: absolute;
  inset: 42px;
  border-radius: 50%;
  border: 2px solid var(--accent-green);
  background: rgba(66, 245, 155, 0.14);
}

.chopstick-line {
  position: absolute;
  left: 10px;
  right: 36px;
  height: 3px;
  background: rgba(255, 209, 102, 0.75);
  border-radius: 2px;
}

.chopstick-line.top { top: 44px; }
.chopstick-line.bottom { bottom: 44px; }

.radar-dot {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: var(--accent-cyan);
  border: 2px solid #ffffff;
  box-shadow: 0 0 12px var(--accent-cyan);
}

.radar-axis-label {
  position: absolute;
  left: 6px;
  bottom: 4px;
  font-size: 9px;
  font-weight: 800;
  color: var(--accent-gold);
}

.vspeed-gauge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.vspeed-label {
  font-size: 10px;
  font-weight: 800;
  color: var(--text-muted);
}

.vspeed-track {
  position: relative;
  width: 16px;
  height: 86px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.vspeed-safe-zone {
  position: absolute;
  left: 0;
  right: 0;
  top: 22%;
  height: 46%;
  background: rgba(66, 245, 155, 0.32);
  border-top: 1px solid var(--accent-green);
  border-bottom: 1px solid var(--accent-green);
}

.vspeed-needle {
  position: absolute;
  left: -2px;
  right: -2px;
  height: 5px;
  top: 50%;
  border-radius: 3px;
  background: #fff;
  box-shadow: 0 0 8px #fff;
}

.vspeed-status {
  font-size: 10px;
  font-weight: 800;
  color: var(--accent-green);
}

.catch-dist {
  margin-top: 10px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Center Banner */
.center-banner {
  position: fixed;
  left: 50%;
  top: 24%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  padding: 16px 28px;
  border-radius: 22px;
  background: rgba(10, 18, 36, 0.78);
  border: 2px solid rgba(255, 209, 102, 0.55);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  animation: popIn 0.25s ease-out;
}

.banner-title {
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: var(--accent-gold);
  text-shadow: 0 3px 18px rgba(255, 209, 102, 0.45);
}

.banner-sub {
  margin-top: 4px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
}

@keyframes popIn {
  from { opacity: 0; transform: translate(-50%, -42%) scale(0.92); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* Bottom Prompt Dock */
.hud-bottom {
  display: flex;
  justify-content: center;
}

.prompt-card {
  padding: 14px 24px;
  text-align: center;
  max-width: 650px;
}

.phase-tag {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--accent-cyan);
  margin-bottom: 6px;
}

.prompt-main {
  font-size: 18px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.keycap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 12px;
  border-radius: 10px;
  background: linear-gradient(180deg, #2b3f66, #192742);
  border: 2px solid #63a4ff;
  box-shadow: 0 4px 0 #0d182c, 0 0 14px rgba(56, 228, 255, 0.35);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 900;
  transition: transform 0.08s ease, background 0.08s ease, box-shadow 0.08s ease;
}

.keycap-space {
  min-width: 96px;
}

.keycap-sm {
  padding: 2px 7px;
  font-size: 11px;
  border-radius: 7px;
}

.keycap.pressed {
  transform: translateY(3px);
  background: linear-gradient(180deg, #42f59b, #1cb5e0);
  color: #041b26;
  border-color: #ffffff;
  box-shadow: 0 1px 0 #0d182c, 0 0 22px rgba(66, 245, 155, 0.8);
}

.prompt-arrows {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.arrow-cluster {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.arrow-bottom-row {
  display: flex;
  gap: 3px;
}

.prompt-sub {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-align: left;
  max-width: 360px;
}

/* Victory Modal */
.modal-overlay {
  pointer-events: auto;
  position: fixed;
  inset: 0;
  background: rgba(4, 10, 22, 0.56);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-card {
  max-width: 520px;
  width: 100%;
  padding: 28px 30px;
  text-align: center;
}

.modal-badge {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(66, 245, 155, 0.18);
  border: 1px solid var(--accent-green);
  color: var(--accent-green);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.modal-title {
  margin-top: 12px;
  font-size: 28px;
  font-weight: 900;
  color: var(--accent-gold);
}

.modal-desc {
  margin-top: 8px;
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.45;
}

.score-grid {
  margin-top: 20px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.score-box {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.score-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
}

.score-val {
  font-size: 20px;
  font-weight: 900;
  color: var(--text-main);
}

.rank-pill {
  margin-top: 16px;
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(56, 228, 255, 0.14);
  border: 1px solid rgba(56, 228, 255, 0.35);
  color: var(--accent-cyan);
  font-weight: 800;
  font-size: 13px;
}

.primary-btn {
  margin-top: 18px;
  width: 100%;
  padding: 13px 20px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, #42f59b, #38e4ff);
  color: #051828;
  font-family: inherit;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(56, 228, 255, 0.35);
  transition: transform 0.12s ease;
}

.primary-btn:hover {
  transform: translateY(-1px);
}

.primary-btn:active {
  transform: translateY(1px);
}

.mobile-only {
  display: none;
}

body.is-touch-device .mobile-only {
  display: inline-flex;
  align-items: center;
}

.glass-btn.active {
  border-color: var(--accent-green);
  color: var(--accent-green);
  box-shadow: 0 0 12px rgba(66, 245, 155, 0.35);
}

.mobile-controls-hint {
  display: none;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-cyan);
  line-height: 1.35;
}

body.is-touch-device .mobile-controls-hint {
  display: block;
}

/* Mobile On-Screen D-Pad */
.mobile-dpad {
  display: none;
  pointer-events: auto;
  touch-action: none;
  position: fixed;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 25;
  width: 144px;
  height: 144px;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 5px;
  padding: 6px;
  border-radius: 24px;
  background: rgba(12, 20, 38, 0.52);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1.5px solid var(--border-glass);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
}

body.is-touch-device .mobile-dpad {
  display: grid;
}

.dpad-btn {
  appearance: none;
  -webkit-appearance: none;
  border: 1.5px solid rgba(145, 205, 255, 0.35);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(43, 63, 102, 0.85), rgba(25, 39, 66, 0.9));
  color: var(--text-main);
  font-size: 16px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(7, 13, 25, 0.85);
  transition: transform 0.06s ease, background 0.06s ease, box-shadow 0.06s ease;
}

.dpad-btn.pressed {
  transform: translateY(2px);
  background: linear-gradient(180deg, #42f59b, #1cb5e0);
  color: #041b26;
  border-color: #ffffff;
  box-shadow: 0 1px 0 rgba(7, 13, 25, 0.85), 0 0 16px rgba(66, 245, 155, 0.75);
}

.dpad-up { grid-column: 2; grid-row: 1; }
.dpad-left { grid-column: 1; grid-row: 2; }
.dpad-center {
  grid-column: 2;
  grid-row: 2;
  border-radius: 50%;
  margin: 8px;
  background: rgba(145, 205, 255, 0.14);
  border: 1px solid rgba(145, 205, 255, 0.22);
}
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down { grid-column: 2; grid-row: 3; }

@media (max-width: 900px) {
  .step-label { display: none; }
  .hud-left, .hud-right { transform: scale(0.86); transform-origin: top left; }
  .hud-right { transform-origin: top right; }
}

@media (max-width: 640px) {
  #hud {
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }
  .hud-top {
    gap: 6px;
    justify-content: center;
  }
  .brand-pill { display: none; }
  .mission-stepper {
    padding: 4px 10px;
    gap: 5px;
    border-radius: 999px;
  }
  .step-num { width: 17px; height: 17px; font-size: 10px; }
  .step-line { width: 10px; }
  .top-actions {
    width: 100%;
    justify-content: center;
    gap: 5px;
    flex-wrap: wrap;
  }
  .glass-btn, .glass-select {
    padding: 5px 8px;
    font-size: 11px;
    border-radius: 10px;
  }
  .glass-select { max-width: 112px; }

  .hud-left {
    left: 8px;
    top: 84px;
    width: 146px;
    padding: 8px 10px;
    border-radius: 12px;
    transform: none;
  }
  .telem-header { font-size: 9px; margin-bottom: 5px; }
  .telem-grid { gap: 4px; }
  .telem-key { font-size: 9px; }
  .telem-val { font-size: 12px; }
  .bar-track { width: 56px; height: 6px; }

  .hud-right {
    right: 8px;
    top: 84px;
    width: 152px;
    padding: 8px 10px;
    border-radius: 12px;
    transform: none;
  }
  .catch-instruments { gap: 8px; }
  .bullseye-wrap { width: 78px; height: 78px; }
  .bullseye-ring.outer { inset: 10px; }
  .bullseye-ring.inner { inset: 27px; }
  .vspeed-track { height: 62px; }
  .catch-dist { font-size: 9px; margin-top: 5px; }

  .banner-title { font-size: 22px; }
  .banner-sub { font-size: 12px; }

  .mobile-dpad {
    left: max(10px, env(safe-area-inset-left));
    bottom: max(10px, env(safe-area-inset-bottom));
    width: 120px;
    height: 120px;
    gap: 4px;
    padding: 5px;
    border-radius: 20px;
  }
  .dpad-btn { font-size: 13px; border-radius: 10px; }

  body.is-touch-device .hud-bottom {
    justify-content: flex-end;
  }
  body.is-touch-device .prompt-card {
    max-width: calc(100vw - 146px);
    padding: 8px 10px;
    border-radius: 14px;
  }
  .phase-tag { font-size: 9px; margin-bottom: 3px; letter-spacing: 0.1em; }
  .prompt-main { font-size: 12px; gap: 4px; }
  .keycap { padding: 2px 7px; font-size: 11px; border-radius: 7px; }
  .keycap-space { min-width: 64px; }
  .prompt-arrows { margin-top: 5px; padding-top: 5px; }
  .prompt-sub { font-size: 10px; text-align: center; }
  .mobile-controls-hint { margin-top: 5px; padding-top: 5px; font-size: 9.5px; }
  body.is-touch-device .arrow-cluster { display: none; }
}
