/* ── CSS Custom Properties ── */
:root {
  --color-primary: #00ff88;
  --color-primary-dim: #00cc66;
  --color-border: #005533;
  --color-border-dark: #003322;
  --color-bg-dark: #0a0a1a;
  --color-bg-panel: rgba(0, 10, 5, 0.92);
  --color-bg-panel-header: rgba(0, 10, 5, 0.95);
  --color-bg-overlay: rgba(0, 10, 5, 0.88);
  --color-bg-input: rgba(0, 255, 136, 0.05);
  --color-bg-btn-hover: rgba(0, 255, 136, 0.12);
  --color-bg-btn-active: rgba(0, 255, 136, 0.25);
  --color-shadow-panel: rgba(0, 255, 136, 0.15);
  --color-shadow-focus: rgba(0, 255, 136, 0.2);
  --color-text: #ccc;
  --color-option-bg: #001a0d;

  --font-mono: 'Courier New', monospace;

  --z-hud: 9;
  --z-crosshair: 10;
  --z-help: 10;
  --z-trigger: 19;
  --z-panel: 20;
  --z-minimap: 20;
  --z-log: 15;
  --z-stats: 30;

  --panel-width: 280px;
  --transition-panel: transform 0.25s ease;
  --transition-btn: background 0.15s, box-shadow 0.15s;
}

/* ── Reset ── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--color-bg-dark);
  font-family: var(--font-mono);
  color: var(--color-text);
}

#canvas-container {
  width: 100%;
  height: 100%;
}
canvas {
  display: block;
}

/* ── HUD Overlay ── */
#hud {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: var(--z-hud);
}

/* ── Crosshair ── */
#crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  pointer-events: none;
  z-index: var(--z-crosshair);
}
#crosshair::before,
#crosshair::after {
  content: '';
  position: absolute;
  background: rgba(255, 255, 255, 0.5);
}
#crosshair::before {
  width: 2px;
  height: 100%;
  left: 50%;
  transform: translateX(-50%);
}
#crosshair::after {
  height: 2px;
  width: 100%;
  top: 50%;
  transform: translateY(-50%);
}

/* ── Hi-Res Badge (always visible when active) ── */
#hires-badge {
  position: fixed;
  top: 10px;
  right: 20px;
  padding: 4px 10px;
  font: bold 13px var(--font-mono);
  color: #00ffcc;
  background: rgba(0, 20, 10, 0.75);
  border: 1px solid #00ffcc;
  border-radius: 4px;
  pointer-events: none;
  z-index: var(--z-crosshair);
}

/* ── Help Overlay ── */
#help {
  display: none;
  position: fixed;
  bottom: 12px;
  left: 12px;
  background: rgba(0, 0, 0, 0.6);
  padding: 8px 14px;
  font-size: 12px;
  border-radius: 4px;
  line-height: 1.6;
  pointer-events: none;
  z-index: var(--z-help);
}

/* ── Panel Trigger Zone ── */
#panel-trigger {
  position: fixed;
  top: 0;
  right: 0;
  width: 20px;
  height: 100%;
  z-index: var(--z-trigger);
}

/* Touch: keep the trigger tappable above the open panel */
body.touch #panel-trigger {
  width: 28px;
  z-index: 21;
}

/* ── Boot overlay (loading + fatal-error screen) ── */
#boot-overlay {
  position: fixed;
  inset: 0;
  background: #0a0a1a;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.6s ease;
}
#boot-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  /* Hidden = fully out of sight AND out of the accessibility tree.
     `opacity: 0` alone still leaves the overlay focusable/announced, so
     VoiceOver on iPad kept reading "Initializing 3D engine…" after the app
     had already booted. `visibility: hidden` is applied only AFTER the fade
     finishes (delayed transition) so the fade still plays. */
  visibility: hidden;
  transition:
    opacity 0.6s ease,
    visibility 0s linear 0.6s;
}
/* Splash screen: aircraft hangar picker */
#splash-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, #0a1428 0%, #0a0a1a 100%);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s ease;
  overflow-y: auto;
  padding: 20px;
  padding-top: max(20px, env(safe-area-inset-top));
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}
#splash-screen.hidden {
  opacity: 0;
  pointer-events: none;
}
.splash-inner {
  text-align: center;
  font-family: 'Courier New', monospace;
  color: #7df9ff;
  max-width: 640px;
  width: 100%;
}
.splash-title {
  font-size: 34px;
  letter-spacing: 8px;
  margin-bottom: 4px;
  text-shadow: 0 0 20px rgba(125, 249, 255, 0.5);
}
.splash-subtitle {
  font-size: 14px;
  letter-spacing: 4px;
  color: #9fb3c8;
  margin-bottom: 28px;
}
.splash-section { margin-bottom: 24px; }
.splash-label {
  font-size: 12px;
  letter-spacing: 3px;
  color: #9fb3c8;
  margin-bottom: 12px;
}
#plane-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.plane-card {
  background: rgba(125, 249, 255, 0.06);
  border: 1px solid rgba(125, 249, 255, 0.25);
  border-radius: 10px;
  padding: 12px 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.plane-card:hover { background: rgba(125, 249, 255, 0.12); }
.plane-card.selected {
  border-color: #7df9ff;
  background: rgba(125, 249, 255, 0.18);
  box-shadow: 0 0 16px rgba(125, 249, 255, 0.3);
}
.plane-card .plane-name {
  font-size: 14px;
  font-weight: bold;
  color: #7df9ff;
  margin-bottom: 4px;
}
.plane-card .plane-desc {
  font-size: 10px;
  color: #9fb3c8;
  line-height: 1.4;
}
.splash-fly {
  font-family: 'Courier New', monospace;
  font-size: 18px;
  letter-spacing: 4px;
  padding: 14px 48px;
  background: transparent;
  color: #7df9ff;
  border: 2px solid #7df9ff;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.splash-fly:hover {
  background: rgba(125, 249, 255, 0.15);
  box-shadow: 0 0 24px rgba(125, 249, 255, 0.4);
}
.splash-fly:disabled {
  opacity: 0.4;
  cursor: wait;
}
.boot-inner {
  text-align: center;
  font-family: 'Courier New', monospace;
  color: #7df9ff;
}
.boot-title {
  font-size: 28px;
  letter-spacing: 6px;
  margin-bottom: 18px;
  animation: boot-pulse 1.6s ease-in-out infinite;
}
.boot-status {
  font-size: 13px;
  letter-spacing: 2px;
  color: #9fb3c8;
}
.boot-error {
  margin-top: 16px;
  max-width: 520px;
  font-size: 12px;
  line-height: 1.5;
  color: #ff7b7b;
  background: rgba(255, 60, 60, 0.08);
  border: 1px solid rgba(255, 60, 60, 0.35);
  border-radius: 6px;
  padding: 12px 16px;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
}
@keyframes boot-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* ── MFD Control Panel ── */
#control-panel {
  position: fixed;
  top: 0;
  right: 0;
  background: var(--color-bg-panel);
  background-image: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 255, 136, 0.03) 2px,
    rgba(0, 255, 136, 0.03) 4px
  );
  width: var(--panel-width);
  height: 100%;
  font-size: 12px;
  z-index: var(--z-panel);
  border-left: 2px solid var(--color-primary);
  border-radius: 0;
  box-shadow: -4px 0 20px var(--color-shadow-panel);
  transform: translateX(100%);
  transition: var(--transition-panel);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
#control-panel.visible {
  transform: translateX(0);
}

/* Scrollbar */
#control-panel::-webkit-scrollbar {
  width: 4px;
}
#control-panel::-webkit-scrollbar-track {
  background: transparent;
}
#control-panel::-webkit-scrollbar-thumb {
  background: var(--color-border);
}

/* ── MFD Header ── */
.mfd-header {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--color-bg-panel-header);
  border-bottom: 1px solid var(--color-border);
  padding: 10px 14px;
  font-size: 11px;
  color: var(--color-primary);
  letter-spacing: 2px;
  text-align: center;
}
.mfd-header span {
  opacity: 0.5;
}

.mfd-body {
  padding: 10px 14px 14px;
  flex: 1;
}

/* ── Section Labels ── */
.mfd-section-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--color-primary-dim);
  letter-spacing: 2px;
  margin: 14px 0 10px;
  text-transform: uppercase;
}
.mfd-section-label::before,
.mfd-section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-border-dark);
}

/* ── Control Groups ── */
.ctrl-group {
  margin-bottom: 8px;
}
.ctrl-group label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 2px;
  font-size: 11px;
  color: var(--color-primary-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.ctrl-group label span {
  color: var(--color-primary);
}
.ctrl-group input[type='range'] {
  width: 100%;
  cursor: pointer;
  accent-color: var(--color-primary);
  height: 4px;
}
.ctrl-group.checkbox-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ctrl-group.checkbox-group input[type='checkbox'] {
  accent-color: var(--color-primary);
  width: 14px;
  height: 14px;
  cursor: pointer;
}
.ctrl-group.checkbox-group label {
  margin-bottom: 0;
  font-size: 11px;
  cursor: pointer;
}
.ctrl-group input[type='text'],
.ctrl-group input[type='number'] {
  width: 100%;
  background: var(--color-bg-input);
  border: 1px solid var(--color-border);
  color: var(--color-primary);
  padding: 4px 8px;
  border-radius: 0;
  font-family: inherit;
  font-size: 11px;
}
.ctrl-group input[type='text']:focus,
.ctrl-group input[type='number']:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 6px var(--color-shadow-focus);
}
.ctrl-group select {
  width: 100%;
  background: var(--color-bg-input);
  border: 1px solid var(--color-border);
  color: var(--color-primary);
  padding: 4px 8px;
  border-radius: 0;
  font-family: inherit;
  font-size: 11px;
}
.ctrl-group select:focus {
  outline: none;
  border-color: var(--color-primary);
}
.ctrl-group select option {
  background: var(--color-option-bg);
  color: var(--color-primary);
}

/* ── MFD Buttons ── */
.mfd-btn {
  width: 100%;
  padding: 7px;
  margin-top: 8px;
  background: transparent;
  border: 1px solid var(--color-primary);
  color: var(--color-primary);
  border-radius: 0;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: var(--transition-btn);
}
.mfd-btn:hover {
  background: var(--color-bg-btn-hover);
  box-shadow: 0 0 10px var(--color-shadow-focus);
}
.mfd-btn:active {
  background: var(--color-bg-btn-active);
}

/* ── Search Row ── */
.search-row {
  display: flex;
  gap: 4px;
}
.search-row input {
  flex: 1;
}
#searchBtn {
  background: transparent;
  border: 1px solid var(--color-primary);
  color: var(--color-primary);
  padding: 4px 10px;
  border-radius: 0;
  cursor: pointer;
  font-size: 13px;
}
#searchBtn:hover {
  background: var(--color-bg-btn-hover);
}

/* ── Section Separator ── */
.section-separator {
  border: none;
  border-top: 1px solid var(--color-border-dark);
  margin: 12px 0;
}

/* ── Flight Plan Menu ── */
#flightplan-menu {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 400px;
  background: rgba(0, 0, 0, 0.85);
  border: 2px solid var(--color-primary);
  z-index: 25;
  display: flex;
  flex-direction: column;
  pointer-events: none;
  font-family: var(--font-mono);
}
.fp-title {
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  color: var(--color-primary);
  padding: 14px 0 10px;
}
#flightplan-list {
  padding: 0 30px 10px;
}
.fp-item {
  font-size: 14px;
  color: var(--color-primary);
  line-height: 28px;
}
.fp-empty {
  font-size: 14px;
  color: #667766;
  text-align: center;
  line-height: 28px;
}
.fp-footer {
  text-align: center;
  font-size: 12px;
  color: #667766;
  padding: 8px 0 12px;
  border-top: 1px solid var(--color-border-dark);
}

/* ── Minimap Panel ── */
#minimap-container {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 260px;
  background: var(--color-bg-overlay);
  border: 1px solid var(--color-border);
  border-right: none;
  border-bottom: none;
  z-index: var(--z-minimap);
  display: none;
  flex-direction: column;
  font-family: var(--font-mono);
  font-size: 11px;
}
#minimap-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-primary-dim);
  letter-spacing: 1px;
  font-size: 10px;
}
.minimap-zoom-btns {
  display: flex;
  gap: 4px;
}
.minimap-zoom-btns button {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-primary-dim);
  padding: 0 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  line-height: 18px;
  letter-spacing: 0;
}
.minimap-zoom-btns button:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}
/* These were 21x20, which is unusable with a thumb — smaller than a fingernail.
   On a coarse pointer (any touch screen) they get a full 44x44 target. The
   box grows outward from the same corner so the minimap itself does not move.
   A mouse can hit 21px comfortably, so desktop keeps the compact form. */
@media (pointer: coarse) {
  .minimap-zoom-btns button {
    min-width: 44px;
    min-height: 44px;
    line-height: 42px;
    font-size: 16px;
  }
}
#minimap {
  display: block;
  width: 256px;
  height: 256px;
  margin: 0 auto 2px;
}

/* ── Log Panel ── */
#log-panel-container {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 520px;
  max-height: 220px;
  background: var(--color-bg-overlay);
  border: 1px solid var(--color-border);
  border-bottom: none;
  border-left: none;
  z-index: var(--z-log);
  display: none;
  flex-direction: column;
  font-family: var(--font-mono);
  font-size: 11px;
}
#log-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-primary-dim);
  letter-spacing: 1px;
  font-size: 10px;
}
#log-panel-clear {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-primary-dim);
  padding: 1px 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 10px;
  letter-spacing: 1px;
}
#log-panel-clear:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}
#log-panel {
  overflow-y: auto;
  flex: 1;
  padding: 4px 8px;
  max-height: 186px;
  line-height: 1.4;
}
#log-panel::-webkit-scrollbar {
  width: 4px;
}
#log-panel::-webkit-scrollbar-track {
  background: transparent;
}
#log-panel::-webkit-scrollbar-thumb {
  background: var(--color-border);
}

/* ── Notifications ── */
#notification-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.notification {
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 8px 18px;
  border-radius: 4px;
  opacity: 0;
  transform: translateY(-10px);
  transition:
    opacity 0.3s,
    transform 0.3s;
  pointer-events: auto;
}
.notification.visible {
  opacity: 1;
  transform: translateY(0);
}
.notification-info {
  background: rgba(0, 40, 20, 0.9);
  color: var(--color-primary);
  border: 1px solid var(--color-border);
}
.notification-warn {
  background: rgba(40, 30, 0, 0.9);
  color: #ffaa33;
  border: 1px solid #664400;
}
.notification-error {
  background: rgba(40, 0, 0, 0.9);
  color: #ff4444;
  border: 1px solid #660000;
}

/* ---------------- Touch controls (iPad / mobile) ---------------- */
/* Shown only when JS detects a touch device (body.touch). */
#canvas-container,
#canvas-container canvas {
  touch-action: none;
}
body {
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}
#touch-ui {
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  display: none;
}
body.touch #touch-ui {
  display: block;
}
#tc-stick-base {
  position: fixed;
  display: none;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.08);
  pointer-events: none;
}
#tc-stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  margin: -27px 0 0 -27px;
  background: rgba(255, 255, 255, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.6);
  pointer-events: none;
}
#tc-buttons {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom));
  display: flex;
  gap: 14px;
  pointer-events: none;
}
#tc-buttons button {
  pointer-events: auto;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: rgba(20, 30, 40, 0.55);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  -webkit-tap-highlight-color: transparent;
}
#tc-buttons button:active {
  background: rgba(80, 140, 200, 0.6);
}

/* ── Touch throttle slider (left edge, touch devices only) ── */#throttle-slider {
  display: none;
  position: fixed;
  left: max(10px, env(safe-area-inset-left));
  top: 50%;
  transform: translateY(-50%);
  height: min(44vh, 360px);
  width: 52px;
  z-index: 26;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
body.touch #throttle-slider {
  display: flex;
}
#throttle-track {
  position: relative;
  width: 14px;
  flex: 1;
  min-height: 120px;
  border-radius: 7px;
  border: 1px solid var(--color-border);
  background: rgba(0, 20, 10, 0.6);
}
#throttle-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 30%;
  border-radius: 6px;
  background: linear-gradient(to top, rgba(0, 255, 136, 0.25), rgba(0, 255, 136, 0.65));
  pointer-events: none;
}
#throttle-knob {
  position: absolute;
  left: 50%;
  bottom: 30%;
  width: 40px;
  height: 26px;
  transform: translate(-50%, 50%);
  border-radius: 6px;
  border: 2px solid var(--color-primary);
  background: rgba(0, 40, 20, 0.9);
  box-shadow: 0 0 8px var(--color-shadow-panel);
  pointer-events: none;
}
#throttle-readout,
#throttle-label {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--color-primary);
  text-shadow: 0 0 6px rgba(0, 255, 136, 0.6);
  pointer-events: none;
}
#throttle-label {
  font-size: 10px;
  color: var(--color-text);
}

/* ── Location picker dialog ── */
#location-dialog {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  padding: 20px;
  box-sizing: border-box;
}
.loc-card {
  position: relative;
  width: min(420px, 92vw);
  background: rgba(12, 18, 26, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  padding: 18px 16px 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  font-family: inherit;
}
.loc-title {
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 2px;
  margin-bottom: 12px;
}
#loc-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: transparent;
  color: #fff;
  font-size: 15px;
  cursor: pointer;
}
.loc-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
#loc-search {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 16px;
}
#loc-search::placeholder {
  color: rgba(255, 255, 255, 0.45);
}
#loc-go {
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  background: #2f7fd0;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
#loc-go:active {
  background: #3f97e8;
}
.loc-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.loc-presets button {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}
.loc-presets button:active {
  background: rgba(80, 140, 200, 0.5);
}
#loc-status {
  margin-top: 10px;
  min-height: 18px;
  font-size: 13px;
  color: #ffcf7d;
}
