/* ─── Variables ─── */
:root {
  --void:          #00010A;
  --deep:          #050B1A;
  --star:          #FFFFFF;
  --star-dim:      #8892B0;
  --earth:         #1A6FBF;
  --hud-primary:   #00E5FF;
  --hud-alert:     #FF3D3D;
  --hud-warn:      #FFB300;
  --hud-text:      #E0F7FA;
  --cockpit:       #1C1C28;
  --cockpit-edge:  #2A2A3E;
  --glass:         rgba(0,229,255,0.04);
  --font-hud:      'Share Tech Mono', monospace;
  --font-title:    'Orbitron', sans-serif;
  --cockpit-inset: 3%;
  --hud-pad:       16px;
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--void);
  overflow: hidden;
  font-family: var(--font-hud);
  color: var(--hud-primary);
  user-select: none;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

/* ─── Star field ─── */
#starfield {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s ease;
}
#starfield.visible { opacity: 1; }

/* ─── Earth container + clouds ─── */
#earth-container {
  position: fixed;
  left: 50%;
  bottom: -8%;
  transform: translateX(-50%);
  width: clamp(260px, 40vw, 520px);
  aspect-ratio: 1;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.4s ease, transform 0.4s ease;
}
#earth-container.visible {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

#earth {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
  animation: rotateEarth 60s linear infinite;
  transform-origin: center;
  box-shadow:
    0 0 80px rgba(26,111,191,0.45),
    0 0 120px rgba(26,111,191,0.2),
    inset -20px -10px 60px rgba(0,0,0,0.5);
}

#earth-clouds {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  animation: rotateClouds 90s linear infinite;
  transform-origin: center;
  /* Cloud texture: procedurally clipped circle with subtle white radial */
  background:
    radial-gradient(circle at 35% 30%, rgba(255,255,255,0.18) 0%, transparent 22%),
    radial-gradient(circle at 62% 45%, rgba(255,255,255,0.14) 0%, transparent 18%),
    radial-gradient(circle at 28% 60%, rgba(255,255,255,0.12) 0%, transparent 15%),
    radial-gradient(circle at 75% 25%, rgba(255,255,255,0.10) 0%, transparent 12%),
    radial-gradient(circle at 50% 70%, rgba(255,255,255,0.08) 0%, transparent 20%);
  pointer-events: none;
}

/* ─── Cockpit frame ─── */
#cockpit-frame {
  position: fixed;
  inset: var(--cockpit-inset);
  z-index: 2;
  border-radius: 12px 12px 48px 48px;
  background: transparent;
  box-shadow:
    inset 0 0 50px rgba(0,229,255,0.12),
    0 0 0 1.5px var(--cockpit-edge),
    0 0 100px rgba(0,0,0,0.85);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}
#cockpit-frame::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(0,229,255,0.025) 0%, transparent 35%);
}
#cockpit-frame::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  /* Vignette: darker at edges of cockpit */
  background: radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(0,0,0,0.35) 100%);
  pointer-events: none;
}
#cockpit-frame.visible { opacity: 1; }

/* ─── HUD wrapper ─── */
#hud {
  position: fixed;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: calc(var(--hud-pad) + 2%);
  pointer-events: none;
  /* parallax gets applied via transform — transition softens it */
  transition: transform 0.08s linear;
}

/* ─── HUD bars ─── */
#hud-top,
#hud-btm {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  opacity: 0;
  transition: opacity 0.3s ease;
}
#hud-top { transform: translateY(-12px); }
#hud-btm  { transform: translateY(12px); }
#hud-top.visible,
#hud-btm.visible { opacity: 1; transform: translateY(0); }

/* ─── HUD block ─── */
.hud-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-image: linear-gradient(90deg, var(--hud-primary) 0%, transparent 100%) 1;
  position: relative;
  pointer-events: auto;
  cursor: default;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}
.hud-block:first-child { border-left-color: rgba(0,229,255,0.3); }
.hud-block:last-child  { border-right-color: rgba(0,229,255,0.3); }

.hud-block:hover,
.hud-block:focus-visible {
  background: var(--glass);
  box-shadow: inset 0 0 20px rgba(0,229,255,0.08);
  outline: none;
}

.hud-block dt {
  font-size: 9px;
  letter-spacing: 0.2em;
  color: var(--hud-primary);
  opacity: 0.55;
}
.hud-block dd {
  font-size: 13px;
  color: var(--hud-primary);
  line-height: 1.2;
}
.hud-unit {
  font-size: 9px !important;
  opacity: 0.5;
  letter-spacing: 0.1em;
}

/* ─── RSSI ─── */
.rssi-container {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
}
.rssi-bar {
  width: 4px;
  background: var(--hud-primary);
  border-radius: 1px;
  opacity: 0.15;
}
.rssi-bar:nth-child(1) { height: 25%; }
.rssi-bar:nth-child(2) { height: 50%; }
.rssi-bar:nth-child(3) { height: 75%; }
.rssi-bar:nth-child(4) { height: 100%; }
.rssi-bar:nth-child(5) { height: 100%; }
.rssi-bar.rssi-active { opacity: 1; }
.rssi-weak .rssi-bar { background: var(--hud-alert); opacity: 1 !important; }

/* ─── Battery ─── */
#hud-bat { transition: color 0.3s; }
#hud-bat.battery-ok   { color: var(--hud-primary); }
#hud-bat.battery-warn { color: var(--hud-warn); }
#hud-bat.battery-low  { color: var(--hud-alert); animation: batteryPulse 0.8s ease-in-out infinite; }

/* ─── Status ─── */
.status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #00FF88;
  margin-right: 6px;
  vertical-align: middle;
  position: relative;
  top: -1px;
}
.status-dot.pulse { animation: statusPulse 2s ease-in-out infinite; }

#hud-status.status-nominal  { color: var(--hud-primary); }
#hud-status.status-warning { color: var(--hud-warn); }
#hud-status.status-alert    { color: var(--hud-alert); }

/* ─── Corner brackets ─── */
#hud-corners {
  position: fixed;
  inset: var(--cockpit-inset);
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}
#hud-corners.visible { opacity: 1; }

.bracket {
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: var(--hud-primary);
  border-style: solid;
  opacity: 0.5;
  transition: opacity 0.15s ease;
}
.bracket:hover { opacity: 0.85; }
.bracket-tl { top: 0; left: 0; border-width: 2px 0 0 2px; border-radius: 4px 0 0 0; }
.bracket-tr { top: 0; right: 0; border-width: 2px 2px 0 0; border-radius: 0 4px 0 0; }
.bracket-bl { bottom: 0; left: 0; border-width: 0 0 2px 2px; border-radius: 0 0 0 4px; }
.bracket-br { bottom: 0; right: 0; border-width: 0 2px 2px 0; border-radius: 0 0 4px 0; }

/* ─── Idle ─── */
#hud.idle .hud-block { opacity: 0.7; transition: opacity 1s ease; }

/* ─── Animations ─── */
@keyframes rotateEarth {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
@keyframes rotateClouds {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
@keyframes statusPulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 4px #00FF88; }
  50%      { opacity: 0.4; box-shadow: 0 0 8px #00FF88; }
}
@keyframes batteryPulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.5; }
}

/* ─── Reduced motion ─── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  #earth, #earth-clouds { animation: none; }
  .status-dot.pulse, #hud-bat.battery-low { animation: none; }
  #hud { transition: none; }
}

/* ─── Responsive: Mobile ─── */
@media (max-width: 767px) {
  :root {
    --cockpit-inset: 1%;
    --hud-pad: 10px;
  }
  #earth-container {
    width: clamp(180px, 70vw, 300px);
    bottom: -12%;
  }
  .hud-block { padding: 6px 8px; }
  .hud-block dt { font-size: 7px; letter-spacing: 0.15em; }
  .hud-block dd { font-size: 10px; }
  #hud-top,
  #hud-btm { grid-template-columns: repeat(2, 1fr); }
  /* last row: span 2 for coord+time on left / mode+status on right */
  #hud-top .hud-block:last-child,
  #hud-btm .hud-block:last-child { /* natural grid is fine */ }
}

@media (max-width: 400px) {
  .hud-block dd { font-size: 9px; }
  .hud-block dt { font-size: 6px; }
}
