* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a1a2a;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  display: block;
}

.overlay {
  position: fixed;
  inset: 0;
  /* Explicit size: a canvas is a replaced element and would otherwise be laid
     out at its intrinsic (attribute) size, which is viewport x devicePixelRatio. */
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#minimap {
  position: fixed;
  left: 24px;
  bottom: 24px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 12;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
}

#crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  pointer-events: none;
  opacity: 0.75;
}
#crosshair::before, #crosshair::after {
  content: '';
  position: absolute;
  background: #d7f3ff;
}
#crosshair::before { left: 8px; top: 0; width: 2px; height: 18px; }
#crosshair::after { top: 8px; left: 0; width: 18px; height: 2px; }

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  color: #d7f3ff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
  font-variant-numeric: tabular-nums;
}

.center-readout {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 22px;
  padding: 8px 20px;
  background: rgba(6, 18, 28, 0.45);
  border: 1px solid rgba(215, 243, 255, 0.35);
  border-radius: 8px;
  font-size: 14px;
  letter-spacing: 1px;
  white-space: nowrap;
}

#gearReadout.gear-warn {
  color: #ffb347;
  animation: blink 0.9s steps(2, start) infinite;
}

#hintPanel {
  position: fixed;
  top: 24px;
  left: 24px;
  max-width: 320px;
  padding: 10px 14px;
  background: rgba(6, 18, 28, 0.55);
  border: 1px solid rgba(215, 243, 255, 0.35);
  border-radius: 8px;
  color: #eaf6ff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
  pointer-events: none;
  backdrop-filter: blur(2px);
  transition: opacity 0.25s ease;
}
#hintPanel.hidden { display: none; }
.hint-keys {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}
.hint-keys .key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  border-radius: 6px;
  border: 1px solid rgba(215, 243, 255, 0.6);
  background: rgba(215, 243, 255, 0.12);
  font-weight: 700;
  font-size: 14px;
}
.hint-text {
  font-size: 13px;
  line-height: 1.35;
  opacity: 0.92;
}

/* Emergency drill styling — deliberately louder than a normal tip, and wider,
   because it carries an ordered checklist rather than one line of advice. */
#hintPanel.hint-emergency {
  max-width: 400px;
  border-color: rgba(255, 120, 120, 0.75);
  background: rgba(48, 10, 10, 0.72);
  box-shadow: 0 0 22px rgba(255, 60, 60, 0.28);
}
.hint-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: #ff8b8b;
  margin-bottom: 5px;
}
.hint-lead { opacity: 0.9; margin-bottom: 8px; }
.hint-steps {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.hint-steps li { line-height: 1.4; }
.hint-steps li .key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  margin-right: 4px;
  vertical-align: middle;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.14);
  font-weight: 700;
  font-size: 12px;
}
.hint-steps li span { vertical-align: middle; }

#flightLogPanel {
  position: fixed;
  top: 24px;
  right: 24px;
  width: 360px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: rgba(6, 18, 28, 0.78);
  border: 1px solid rgba(215, 243, 255, 0.35);
  border-radius: 10px;
  color: #eaf6ff;
  backdrop-filter: blur(3px);
  z-index: 15;
  overflow: hidden;
}
#flightLogPanel.hidden { display: none; }
.flog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(215, 243, 255, 0.2);
}
.flog-header h2 { margin: 0; font-size: 15px; letter-spacing: 1px; font-weight: 600; }
#flogClose {
  background: none;
  border: none;
  color: #eaf6ff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.7;
}
#flogClose:hover { opacity: 1; }
.flog-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(215, 243, 255, 0.2);
}
.flog-stats div { display: flex; flex-direction: column; align-items: center; }
.flog-stats b { font-size: 17px; font-weight: 700; }
.flog-stats span { font-size: 10px; opacity: 0.65; letter-spacing: 0.5px; text-transform: uppercase; }
.flog-list {
  overflow-y: auto;
  padding: 6px 0;
}
.flog-row {
  display: flex;
  gap: 10px;
  padding: 7px 14px;
  font-size: 12.5px;
  line-height: 1.4;
  border-left: 3px solid transparent;
}
.flog-t { opacity: 0.55; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.flog-good { border-left-color: #5ad26e; }
.flog-bad { border-left-color: #ff5f5f; background: rgba(255, 95, 95, 0.08); }
.flog-warn { border-left-color: #ffb347; }
.flog-info { border-left-color: rgba(215, 243, 255, 0.4); opacity: 0.85; }

#plainReadout {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  display: flex;
  gap: 18px;
  padding: 6px 16px;
  background: rgba(6, 18, 28, 0.5);
  border: 1px solid rgba(215, 243, 255, 0.28);
  border-radius: 7px;
  font-size: 12px;
  white-space: nowrap;
  letter-spacing: 0.3px;
}
#plainReadout b { font-weight: 700; font-size: 13px; }
#plainReadout .aoa-note { opacity: 0.55; font-size: 11px; }

.warn {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 4px;
  color: #ff5252;
  text-shadow: 0 0 12px rgba(255,0,0,0.7);
  animation: blink 0.8s steps(2, start) infinite;
}
.hidden { display: none; }
@keyframes blink { 50% { opacity: 0.15; } }

#startScreen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: radial-gradient(ellipse at 50% 30%, #1c3652 0%, #060d17 75%);
  color: #eaf6ff;
  text-align: center;
  z-index: 20;
  padding: 20px;
}
#startScreen h1 { margin: 0; font-weight: 600; font-size: 32px; letter-spacing: 1px; }
#startScreen p { margin: 0 0 10px; opacity: 0.75; max-width: 480px; }

.controls-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 8px 24px;
  margin-bottom: 12px;
}
.controls-grid div { display: flex; flex-direction: column; align-items: flex-start; font-size: 13px; }
.controls-grid b { color: #7fd7ff; font-size: 14px; }
.controls-grid span { opacity: 0.7; }

.region-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
  font-size: 13px;
  opacity: 0.85;
}
.region-row select {
  padding: 7px 12px;
  border-radius: 7px;
  border: 1px solid rgba(127, 215, 255, 0.5);
  background: rgba(6, 18, 28, 0.85);
  color: #eaf6ff;
  font-size: 13px;
  cursor: pointer;
}

#startBtn {
  padding: 12px 34px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 1px;
  border-radius: 999px;
  border: 1px solid #7fd7ff;
  background: linear-gradient(180deg, #2c86c9, #1a5a8c);
  color: white;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 18px rgba(44, 134, 201, 0.5);
}
#startBtn:hover { transform: translateY(-1px); box-shadow: 0 6px 24px rgba(44, 134, 201, 0.7); }
#startBtn:active { transform: translateY(1px); }

#fatalError {
  max-width: 560px;
  margin-top: 18px;
  padding: 14px 18px;
  border: 1px solid rgba(255, 120, 120, 0.6);
  border-radius: 8px;
  background: rgba(120, 20, 20, 0.35);
  color: #ffe8e8;
  font-size: 13px;
  line-height: 1.5;
  text-align: left;
}
#fatalError.floating {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 40;
  background: rgba(70, 12, 12, 0.94);
  backdrop-filter: blur(3px);
}
#fatalError p { margin: 8px 0 0; }
#fatalError .hint { opacity: 0.85; }
#fatalError kbd {
  padding: 1px 5px;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 4px;
  background: rgba(255,255,255,0.1);
  font-size: 12px;
}

.credits {
  max-width: 560px;
  margin: 14px 0 0;
  font-size: 11px;
  line-height: 1.5;
  opacity: 0.5;
}
.credits a { color: #7fd7ff; }

#startScreen.fading { animation: fadeOut 0.5s ease forwards; }
@keyframes fadeOut { to { opacity: 0; visibility: hidden; } }
