/* LRO Lunar Explorer — game styles (Tailwind utilities are in tailwind.css) */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #050811;
  color: #e2e8f0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.font-mono-tech {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
}

#canvas-container {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Matte Deep-Space HUD Panels */
.hud-panel {
  background: rgba(11, 16, 28, 0.84);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.hud-btn {
  transition: all 0.16s ease;
}
.hud-btn:hover {
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(244, 213, 141, 0.45);
}
.hud-btn:active {
  transform: scale(0.97);
}

/* Custom Scrollbars for Drawers & Modals */
.custom-scroll::-webkit-scrollbar {
  width: 6px;
}
.custom-scroll::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.4);
}
.custom-scroll::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.28);
  border-radius: 9999px;
}

/* Range Sliders */
input[type="range"].lunar-slider {
  -webkit-appearance: none;
  appearance: none;
  height: 5px;
  background: rgba(51, 65, 85, 0.85);
  border-radius: 999px;
  outline: none;
}
input[type="range"].lunar-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #f4d58d;
  border: 2px solid #0b101c;
  cursor: pointer;
}

/* Dropzone highlight */
.drop-active {
  border-color: #f4d58d !important;
  background: rgba(244, 213, 141, 0.12) !important;
}

/* Touch Flight Pad Buttons */
.touch-key {
  background: rgba(15, 23, 42, 0.86);
  border: 1px solid rgba(148, 163, 184, 0.26);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
  transition: transform 0.08s ease, background 0.08s ease;
  touch-action: none;
}
.touch-key.pressed, .touch-key:active {
  background: rgba(244, 213, 141, 0.26);
  border-color: #f4d58d;
  transform: scale(0.94);
}

/* Impact Flash Overlay */
#impact-flash {
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.22s ease;
  background: radial-gradient(circle, rgba(217, 130, 108, 0.06) 30%, rgba(217, 130, 108, 0.42) 100%);
}

@keyframes pulseSoft {
  0%, 100% { opacity: 0.72; }
  50% { opacity: 1; }
}
.pulse-soft {
  animation: pulseSoft 2.2s ease-in-out infinite;
}
/* =====================================================================
   CONTEXT-AWARE HUD LAYOUT (safe-area aware, thumb zones on touch)
   ===================================================================== */
:root {
  --sa-t: env(safe-area-inset-top, 0px);
  --sa-r: env(safe-area-inset-right, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px);
  --sa-l: env(safe-area-inset-left, 0px);
}
#hud-root { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud-root button, #menu-sheet button { -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

#ui-top-left {
  position: fixed; z-index: 20; pointer-events: none;
  top: calc(var(--sa-t) + 8px); left: calc(var(--sa-l) + 8px);
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px; max-width: 46vw;
}
#ui-top-right {
  position: fixed; z-index: 25; pointer-events: none;
  top: calc(var(--sa-t) + 8px); right: calc(var(--sa-r) + 8px);
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
}
#ui-top-right #overlay-legend { pointer-events: auto; }
.ui-round-btn {
  height: 44px; min-width: 44px; padding: 0 11px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  color: #e2e8f0; cursor: pointer;
}
.ui-round-label { font: 600 12px 'JetBrains Mono', monospace; }

/* Challenge / docking panels: centred, but never further left than the widest readouts (~430px) */
#mission-slot {
  --ms-w: clamp(260px, calc(100vw - 690px), 470px);
  position: fixed; z-index: 20; pointer-events: none;
  left: max(calc(var(--sa-l) + 450px), calc(50% - var(--ms-w) / 2)); width: var(--ms-w);
  top: calc(var(--sa-t) + 8px);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
/* Touch screens: stack it under the readouts, clear of the top-right buttons */
/* Touch screens: stack it under the readouts, ending before the middle of the screen where the craft is */
body.touch-ui #mission-slot { left: calc(var(--sa-l) + 8px); top: calc(var(--sa-t) + 100px); width: min(380px, calc(50vw - 80px)); align-items: flex-start; }
/* Short landscape phones: trim challenge panels and the map legend to their essentials */
@media (max-height: 460px) {
  body.touch-ui #mission-slot .run-pills, body.touch-ui #hadley-target-hint, body.touch-ui #ice-target-hint { display: none; }
  body.touch-ui #overlay-legend .legend-note { display: none; }
  body.touch-ui #mission-slot > div { padding-top: 8px !important; padding-bottom: 8px !important; }
  body.touch-ui #mission-slot .mt-2 { margin-top: 5px !important; }
  body.touch-ui #mission-slot .run-tag, body.touch-ui #a11-slope-btn { display: none; }
  body.touch-ui #a11-hint { font-size: 10px; }
  /* Long Houston lines: three lines max on short screens (the voice still says it all) */
  body.touch-ui #radio-caption-text { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  body.touch-ui #radio-caption { padding: 6px 12px; font-size: 12px; }
}
#mission-slot > div { margin-bottom: 0 !important; }

#readouts .ro { display: flex; flex-direction: column; align-items: flex-start; min-width: 52px; }
#readouts .ro-l { font: 600 10px 'JetBrains Mono', monospace; letter-spacing: .08em; color: #94a3b8; }
#readouts .ro-v { font: 700 15px 'JetBrains Mono', monospace; color: #f1f5f9; white-space: nowrap; }

#details-panel {
  position: fixed; z-index: 26; top: calc(var(--sa-t) + 104px); left: calc(var(--sa-l) + 8px);
  width: 270px; max-height: calc(100vh - var(--sa-t) - var(--sa-b) - 200px); overflow-y: auto;
}

#msg-rail {
  position: fixed; z-index: 21; pointer-events: none; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--sa-b) + 12px); width: min(440px, calc(100vw - 400px)); min-width: 220px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
/* Desktop: messages sit in the empty bottom-left corner, clear of the action buttons */
body:not(.touch-ui) #msg-rail { left: calc(var(--sa-l) + 16px); transform: none; align-items: flex-start; bottom: calc(var(--sa-b) + 76px); width: min(460px, calc(100vw - 640px)); min-width: 280px; }
body:not(.touch-ui) #ui-bottom-center { left: calc(var(--sa-l) + 16px); transform: none; align-items: flex-start; max-width: calc(100vw - 560px); }
body:not(.touch-ui) #key-hints { justify-content: flex-start; }
/* Landscape phones: keep messages between the thumbstick and the action buttons */
@media (orientation: landscape) {
  body.touch-ui #msg-rail { left: calc(var(--sa-l) + 170px); right: calc(var(--sa-r) + 118px); width: auto; min-width: 0; transform: none; }
  body.touch-ui #ui-actions { max-width: min(46vw, calc(50vw - 40px)); }
}

#ui-bottom-center {
  position: fixed; z-index: 20; pointer-events: none; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--sa-b) + 12px); display: flex; flex-direction: column; align-items: center; gap: 6px;
  max-width: calc(100vw - 560px);
}
#ui-bottom-center > * { pointer-events: auto; }
body.touch-ui #ui-bottom-center { max-width: calc(100vw - 24px); bottom: calc(var(--sa-b) + 96px); }
#key-hints { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 12px; font: 500 12px 'JetBrains Mono', monospace; color: #cbd5e1; }
#key-hints kbd, .help-group kbd, .kb {
  display: inline-block; padding: 1px 6px; border-radius: 6px; margin-right: 4px;
  background: #111827; border: 1px solid #334155; color: #f4d58d; font: 600 11px 'JetBrains Mono', monospace;
}
body.touch-ui #key-hints { display: none !important; }

/* Context actions */
#ui-actions {
  position: fixed; z-index: 22; pointer-events: none;
  right: calc(var(--sa-r) + 12px); bottom: calc(var(--sa-b) + 12px);
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px; max-width: 46vw;
}
#act-secondary, #act-prompt, #act-holds { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; pointer-events: none; }
#act-secondary > *, #act-prompt > *, #act-holds > * { pointer-events: auto; }
.prompt-btn {
  min-height: 48px; padding: 0 20px; border-radius: 999px; cursor: pointer;
  font: 700 15px Inter, system-ui, sans-serif; color: #050811; background: #f4d58d;
  box-shadow: 0 8px 24px rgba(244, 213, 141, 0.28); display: inline-flex; align-items: center; gap: 8px;
  animation: promptIn .22s ease-out;
}
.prompt-btn.sage { background: #7ec4a0; box-shadow: 0 8px 24px rgba(126, 196, 160, 0.28); }
.prompt-btn.dim { background: #1e293b; color: #e2e8f0; border: 1px solid #475569; box-shadow: none; }
.prompt-btn .kb { background: rgba(5, 8, 17, 0.18); border-color: rgba(5, 8, 17, 0.25); color: inherit; margin: 0; }
.chip-btn {
  min-height: 40px; padding: 0 14px; border-radius: 999px; cursor: pointer;
  font: 600 13px Inter, system-ui, sans-serif; color: #e2e8f0;
  background: rgba(11, 16, 28, 0.86); border: 1px solid rgba(148, 163, 184, 0.3);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); display: inline-flex; align-items: center; gap: 6px;
}
.chip-btn .kb { margin: 0; }
.chip-btn.on { color: #050811; background: #7ec4a0; border-color: #7ec4a0; }
@keyframes promptIn { from { transform: translateY(6px) scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.hold-btn {
  width: 66px; height: 66px; border-radius: 50%; cursor: pointer; touch-action: none;
  font: 700 12px 'JetBrains Mono', monospace; color: #e2e8f0; letter-spacing: .02em;
  background: rgba(15, 23, 42, 0.78); border: 1.5px solid rgba(148, 163, 184, 0.35);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45); display: inline-flex; align-items: center; justify-content: center; text-align: center; line-height: 1.1;
  transition: transform .06s ease, background .06s ease;
}
.hold-btn.big { width: 78px; height: 78px; color: #f4d58d; border-color: rgba(244, 213, 141, 0.55); }
.hold-btn.pressed { background: rgba(244, 213, 141, 0.3); border-color: #f4d58d; transform: scale(0.93); }
body:not(.touch-ui) #act-holds { display: none; }

/* Floating thumbstick */
#joy-zone {
  position: fixed; z-index: 19; left: 0; bottom: 0; touch-action: none; pointer-events: auto;
  width: min(46vw, 360px); height: min(62vh, 340px);
}
#joy-base {
  position: absolute; width: 124px; height: 124px; margin: -62px 0 0 -62px; border-radius: 50%;
  border: 2px solid rgba(148, 163, 184, 0.32); background: rgba(15, 23, 42, 0.28); transition: opacity .15s ease;
  opacity: .55;
}
#joy-zone.active #joy-base { opacity: 1; background: rgba(15, 23, 42, 0.45); }
#joy-knob {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%;
  background: rgba(244, 213, 141, 0.78); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

/* Menu */
#menu-sheet {
  position: fixed; z-index: 35; top: calc(var(--sa-t) + 60px); right: calc(var(--sa-r) + 8px);
  width: min(330px, calc(100vw - 16px)); max-height: calc(100vh - var(--sa-t) - var(--sa-b) - 72px);
  overflow-y: auto; padding: 12px;
}
.menu-section { font: 600 11px 'JetBrains Mono', monospace; letter-spacing: .14em; text-transform: uppercase; color: #64748b; margin: 12px 4px 6px; }
.menu-item {
  width: 100%; min-height: 44px; margin-bottom: 6px; padding: 0 12px; border-radius: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; text-align: left;
  background: rgba(17, 24, 39, 0.9); border: 1px solid rgba(51, 65, 85, 0.9); color: #e2e8f0; font: 500 14px Inter, system-ui, sans-serif;
}
.menu-item:hover { border-color: rgba(244, 213, 141, 0.45); }
.menu-kb { font: 600 12px 'JetBrains Mono', monospace; color: #94a3b8; white-space: nowrap; }
.help-group { background: #111827; border: 1px solid #1e293b; border-radius: 14px; padding: 10px 12px; color: #cbd5e1; line-height: 1.9; }
.help-title { font: 600 12px 'JetBrains Mono', monospace; color: #f4d58d; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 2px; }


/* Field Journal */
.journal-tab { flex: none; min-height: 36px; padding: 0 12px; border-radius: 999px; cursor: pointer; white-space: nowrap;
  font: 600 13px Inter, system-ui, sans-serif; color: #cbd5e1; background: #111827; border: 1px solid #334155; }
.journal-tab.on { color: #050811; background: #7ec4a0; border-color: #7ec4a0; }
.journal-tab .jt-count { font: 600 11px 'JetBrains Mono', monospace; opacity: .75; margin-left: 4px; }
.journal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.journal-card { --cat: #94a3b8; position: relative; border-radius: 16px; padding: 12px 12px 12px 14px; background: #0b111d;
  border: 1px dashed #334155; color: #cbd5e1; display: flex; flex-direction: column; gap: 4px; min-height: 120px; }
.journal-card.found { border: 1px solid color-mix(in srgb, var(--cat) 45%, transparent); background: #101827; cursor: pointer; }
.journal-card.found::before { content: ''; position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px; border-radius: 3px; background: var(--cat); }
.journal-card.found:hover { border-color: var(--cat); }
.jc-cat { font: 600 10.5px 'JetBrains Mono', monospace; letter-spacing: .12em; color: var(--cat); }
.jc-name { font: 700 15px Inter, system-ui, sans-serif; color: #fff; }
.jc-name.unknown { color: #475569; letter-spacing: .2em; }
.jc-hook { font-size: 13px; color: #cbd5e1; line-height: 1.4; }
.jc-hint { font-size: 13px; color: #94a3b8; line-height: 1.45; font-style: italic; flex: 1; }
.jc-meta { margin-top: auto; font: 500 11px 'JetBrains Mono', monospace; color: #64748b; }
.jc-track { align-self: flex-start; margin-top: 4px; min-height: 32px; padding: 0 12px; border-radius: 999px; cursor: pointer;
  font: 600 12px Inter, system-ui, sans-serif; color: #7dd3fc; background: rgba(125, 211, 252, .08); border: 1px solid rgba(125, 211, 252, .4); }
.jc-track.on { color: #050811; background: #7dd3fc; }
.journal-detail { --cat: #94a3b8; max-width: 640px; margin: 0 auto; padding: 4px 4px 12px; }
.jc-back { min-height: 36px; padding: 0 12px; margin-bottom: 12px; border-radius: 999px; cursor: pointer; font: 600 13px Inter, sans-serif;
  color: #cbd5e1; background: #111827; border: 1px solid #334155; }
.jd-name { font: 800 26px Inter, system-ui, sans-serif; color: #fff; margin: 2px 0 4px; }
.jd-hook { font: 600 16px Inter, system-ui, sans-serif; color: var(--cat); margin-bottom: 10px; }
.jd-body { font-size: 16px; line-height: 1.6; color: #e2e8f0; }
.jd-meta { margin-top: 12px; font: 500 12px 'JetBrains Mono', monospace; color: #64748b; }
.jd-go { margin-top: 14px; min-height: 44px; padding: 0 18px; border-radius: 999px; cursor: pointer;
  font: 700 14px Inter, sans-serif; color: #050811; background: #f4d58d; }
#signal-pill { pointer-events: none; }

/* Device-specific copy */
body.touch-ui .only-desktop, body:not(.touch-ui) .only-touch { display: none; }
#rotate-hint { display: none; }
@media (orientation: portrait) { body.touch-ui #rotate-hint { display: block; } }

/* Portrait / narrow phones: mission HUD under the top bar, messages above the thumb zone */
@media (max-width: 699px) and (orientation: portrait) {
  #mission-slot, body.touch-ui #mission-slot { left: calc(var(--sa-l) + 8px); top: calc(var(--sa-t) + 104px); width: calc(100vw - 16px); }
  #readouts { flex-wrap: wrap; row-gap: 4px; }
  #ui-top-left { max-width: calc(100vw - 130px); }
  #msg-rail { width: calc(100vw - 24px); bottom: calc(var(--sa-b) + 196px); }
  body.touch-ui #ui-bottom-center { bottom: calc(var(--sa-b) + 196px); }
  .ui-round-label { display: none; }
  #details-panel { width: calc(100vw - 16px); }
}
/* Short landscape phones: tighter vertical rhythm */
@media (max-height: 460px) {
  #readouts .ro-v { font-size: 14px; }
  .hold-btn { width: 60px; height: 60px; }
  .hold-btn.big { width: 70px; height: 70px; }
  .prompt-btn { min-height: 44px; font-size: 14px; }
  #details-panel { top: calc(var(--sa-t) + 96px); max-height: calc(100vh - var(--sa-t) - var(--sa-b) - 110px); }
}

/* Touch screens: nothing below 12px */
body.touch-ui .text-\[9px\], body.touch-ui .text-\[10px\], body.touch-ui .text-\[10\.5px\], body.touch-ui .text-\[11px\] {
  font-size: 12px !important; line-height: 1.35;
}
body.touch-ui #readouts .ro-l { font-size: 12px; }

/* Mission Control radio subtitles */
#radio-caption {
  display: flex; align-items: baseline; gap: 10px; max-width: 100%;
  padding: 8px 14px; border-radius: 14px;
  background: rgba(8, 14, 24, 0.9); border: 1px solid rgba(126, 196, 160, 0.45);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  color: #f1f5f9; font: 500 13px/1.4 'Inter', system-ui, sans-serif;
  opacity: 0; transform: translateY(6px); transition: opacity 0.18s ease, transform 0.18s ease;
}
#radio-caption.on { opacity: 1; transform: none; }
#radio-caption .radio-tag {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  font: 600 10px 'JetBrains Mono', monospace; letter-spacing: 0.08em; color: #7ec4a0;
}
#radio-caption .radio-dot { width: 6px; height: 6px; border-radius: 50%; background: #7ec4a0; animation: radio-blink 1s ease-in-out infinite; }
@keyframes radio-blink { 50% { opacity: 0.25; } }
body.touch-ui #radio-caption { font-size: 13px; }
#radio-caption.hidden { display: none; }

/* Phone THRUST: hold to hover, slide up to climb, down to descend */
.thrust-btn { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; transition: transform 0.06s linear, border-color 0.12s, box-shadow 0.12s; touch-action: none; }
.thrust-btn .thrust-hint { font: 600 8px 'JetBrains Mono', monospace; letter-spacing: 0.04em; color: #94a3b8; white-space: nowrap; }
.thrust-btn.pressed { box-shadow: 0 0 0 3px rgba(244, 213, 141, 0.25); }
.thrust-btn.rising { border-color: #7ec4a0 !important; box-shadow: 0 -10px 18px -6px rgba(126, 196, 160, 0.55); }
.thrust-btn.lowering { border-color: #7dd3fc !important; box-shadow: 0 10px 18px -6px rgba(125, 211, 252, 0.55); }
