* {
  box-sizing: border-box;
}

/* ---- Cockpit Menu + Ship Status: authoritative integration ---- */
#ui-layer > #playerStats {
  width: 220px;
  min-width: 0;
  max-width: calc(100vw - 32px - env(safe-area-inset-left) - env(safe-area-inset-right));
  padding: 10px 12px 9px;
  overflow: visible;
  pointer-events: none;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 11px;
  background: var(--cockpit-glass-surface);
  border: 1px solid var(--cockpit-edge);
  border-radius: var(--cockpit-radius);
  box-shadow: inset 0 1px rgba(218, 245, 252, .12), inset 0 -10px 22px rgba(0, 3, 10, .24), 0 0 14px var(--cockpit-glow);
}
#playerStats::before {
  content: "";
  position: absolute;
  top: 7px;
  bottom: 7px;
  left: 7px;
  width: 36px;
  border-top: 2px solid var(--cockpit-edge-bright);
  border-bottom: 2px solid var(--cockpit-edge-bright);
  border-left: 2px solid var(--cockpit-edge-bright);
  filter: drop-shadow(0 0 5px var(--cockpit-glow));
  pointer-events: none;
}
#playerStats::after {
  left: 100%;
  top: 50%;
  width: max(16px, env(safe-area-inset-right));
  height: 1px;
  background: linear-gradient(90deg, var(--cockpit-edge-bright), transparent);
}
#playerStats .ps-title {
  margin: 0 0 8px;
  padding-left: 4px;
  color: var(--cockpit-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .14em;
}
#playerStats .ps-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto 6px;
  gap: 3px 8px;
  margin: 0 0 7px;
}
#playerStats .ps-label {
  grid-column: 1;
  grid-row: 1;
  width: auto;
  color: var(--cockpit-muted);
  font-weight: 700;
}
#playerStats .ps-value {
  grid-column: 2;
  grid-row: 1;
  width: auto;
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--cockpit-text);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
#playerStats .ps-bar-track {
  grid-column: 1 / -1;
  grid-row: 2;
  width: 100%;
  height: 6px;
  background: rgba(2, 10, 20, .72);
  border: 1px solid rgba(79, 178, 211, .25);
  border-radius: 2px;
}
#playerStats .ps-bar-fill { border-radius: 1px; }
#playerStats .ps-speed {
  min-width: 0;
  margin-top: 2px;
  overflow-wrap: anywhere;
  color: var(--cockpit-muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .06em;
}

#sidePanel { background: var(--cockpit-glass-surface); }

#mainMenu.menu-overlay {
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow: auto;
  overscroll-behavior: contain;
  background: rgba(1, 5, 12, .82);
  backdrop-filter: blur(8px) saturate(.9);
}
#mainMenu.menu-overlay.menu-boot {
  overflow: hidden;
  background: #05070f;
  backdrop-filter: none;
}
#mainMenu .menu-box {
  position: relative;
  width: min(360px, calc(100vw - 32px));
  max-width: 100%;
  max-height: calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  min-height: 0;
  padding: 28px 24px;
  overflow-x: hidden;
  overflow-y: auto;
  color: var(--cockpit-text);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  background: var(--cockpit-glass-surface);
  border: 1px solid var(--cockpit-edge);
  border-radius: var(--cockpit-radius);
  box-shadow: inset 0 1px rgba(218, 245, 252, .12), inset 0 -16px 32px rgba(0, 3, 10, .32), 0 0 24px var(--cockpit-glow), 0 18px 48px rgba(0, 0, 0, .55);
  scrollbar-color: var(--cockpit-edge) rgba(2, 10, 20, .55);
}
#mainMenu .menu-box::before,
#mainMenu .menu-box::after {
  content: "";
  position: absolute;
  z-index: 2;
  top: 7px;
  bottom: 7px;
  width: 38px;
  border-top: 2px solid var(--cockpit-edge-bright);
  border-bottom: 2px solid var(--cockpit-edge-bright);
  filter: drop-shadow(0 0 6px var(--cockpit-glow));
  pointer-events: none;
}
#mainMenu .menu-box::before { left: 7px; border-left: 2px solid var(--cockpit-edge-bright); }
#mainMenu .menu-box::after { right: 7px; border-right: 2px solid var(--cockpit-edge-bright); }
#mainMenu .menu-box > * { position: relative; z-index: 3; }
#mainMenu .menu-title { color: var(--cockpit-text); text-shadow: 0 0 14px var(--cockpit-glow); }
#mainMenu .menu-subtitle,
#mainMenu .menu-last-flight-label { color: var(--cockpit-edge-bright); }
#mainMenu .menu-description,
#mainMenu .menu-note,
#mainMenu .menu-last-flight-meta,
#mainMenu .menu-slot-info span { color: var(--cockpit-muted); }
#mainMenu .menu-setting,
#mainMenu .menu-last-flight,
#mainMenu .menu-slot-row {
  background: rgba(3, 13, 25, .54);
  border-color: rgba(79, 178, 211, .38);
  border-radius: var(--cockpit-radius);
}
#mainMenu .menu-buttons { gap: 10px; }
#mainMenu .menu-btn {
  min-height: 44px;
  padding: 9px 14px;
  border-color: var(--cockpit-edge);
  border-radius: var(--cockpit-radius);
  background: rgba(21, 66, 83, .32);
  color: var(--cockpit-text);
  font-family: inherit;
}
#mainMenu .menu-btn:hover:not(:disabled) {
  border-color: var(--cockpit-edge-bright);
  background: var(--cockpit-surface-hover);
  color: #effcff;
}
#mainMenu .menu-btn:active:not(:disabled) { transform: translateY(1px); }
#mainMenu .menu-btn:focus-visible,
#mainMenu .menu-volume:focus-visible {
  outline: 2px solid var(--cockpit-edge-bright);
  outline-offset: 2px;
}
#mainMenu .menu-btn-danger { border-color: rgba(255, 117, 109, .68); color: #ffaaa5; }
#mainMenu .menu-volume { min-height: 44px; margin: 4px 0 0; accent-color: var(--cockpit-edge-bright); }
#mainMenu .menu-slot-action { min-width: 72px; min-height: 44px; }

#mainMenu.menu-boot .menu-hero,
#mainMenu.menu-boot .menu-box {
  height: min(78dvh, 620px);
  max-height: calc(100dvh - 48px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}
#mainMenu.menu-boot .menu-hero {
  width: min(58vw, 650px);
  min-width: 0;
  border-color: var(--cockpit-edge);
  border-radius: var(--cockpit-radius) 0 0 var(--cockpit-radius);
}
#mainMenu.menu-boot .menu-box {
  width: min(360px, 34vw);
  justify-content: center;
  border-left-color: rgba(170, 229, 245, .55);
  border-radius: 0 var(--cockpit-radius) var(--cockpit-radius) 0;
}

@media (max-width: 1099px), (max-height: 600px) {
  #ui-layer > #playerStats { width: 180px; right: max(8px, env(safe-area-inset-right)); bottom: max(8px, env(safe-area-inset-bottom)); }
}
@media (max-width: 560px) {
  #mainMenu.menu-overlay.menu-boot {
    display: flex;
    align-items: stretch;
    justify-content: flex-start;
    flex-direction: column;
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    overflow-y: auto;
  }
  #mainMenu.menu-boot .menu-hero {
    width: 100%;
    height: 32dvh;
    min-height: 160px;
    max-height: 220px;
    flex: 0 0 auto;
    border-right: 1px solid var(--cockpit-edge);
    border-bottom: 0;
    border-radius: var(--cockpit-radius) var(--cockpit-radius) 0 0;
  }
  #mainMenu.menu-boot .menu-box {
    width: 100%;
    height: auto;
    max-height: none;
    flex: 0 0 auto;
    justify-content: flex-start;
    overflow: visible;
    padding: 22px 18px;
    border-top: 0;
    border-left: 1px solid var(--cockpit-edge);
    border-radius: 0 0 var(--cockpit-radius) var(--cockpit-radius);
  }
}
@media (max-width: 480px) {
  #ui-layer > #playerStats {
    width: min(150px, calc(100vw - 68px - env(safe-area-inset-left) - env(safe-area-inset-right)));
    padding: 8px 9px 7px;
  }
  #playerStats .ps-title { margin-bottom: 6px; font-size: 9px; }
  #playerStats .ps-row { gap: 2px 6px; margin-bottom: 6px; }
  #mainMenu .menu-slot-row { align-items: stretch; flex-direction: column; }
  #mainMenu .menu-slot-action { width: 100%; }
}
@media (max-height: 600px) and (min-width: 561px) {
  #mainMenu.menu-boot .menu-hero,
  #mainMenu.menu-boot .menu-box {
    height: calc(100dvh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    max-height: none;
  }
  #mainMenu.menu-boot .menu-box { justify-content: flex-start; padding: 18px 22px; }
  #mainMenu .menu-title { margin-bottom: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  #mainMenu *, #mainMenu *::before, #mainMenu *::after, #playerStats, #playerStats * {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}

:root {
  --cockpit-surface: rgba(5, 15, 27, 0.88);
  --cockpit-surface-hover: rgba(14, 38, 56, 0.94);
  --cockpit-edge: rgba(79, 178, 211, 0.58);
  --cockpit-edge-bright: rgba(170, 229, 245, 0.82);
  --cockpit-glow: rgba(59, 190, 226, 0.22);
  --cockpit-text: #ccebf4;
  --cockpit-muted: #82aeba;
  --cockpit-danger: #ff756d;
  --cockpit-radius: 5px;
  --cockpit-safe-x: max(16px, env(safe-area-inset-left));
  --cockpit-safe-y: max(16px, env(safe-area-inset-top));
  --cockpit-control-step: 52px;
  --cockpit-control-step-2: 104px;
  --cockpit-glass-surface: linear-gradient(145deg, rgba(16, 39, 55, .58), rgba(3, 10, 21, .78) 42%, rgba(5, 15, 27, .68));
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #05070f;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
}

/* Prefer the dynamic viewport on mobile browsers, with a legacy fallback. */
html, body, #ui-layer, #gameCanvas { min-height: 100vh; }
@supports (height: 100dvh) {
  html, body, #ui-layer, #gameCanvas { min-height: 100dvh; }
}

#gameCanvas {
  display: block;
  width: 100vw;
  height: 100vh;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
@supports (height: 100dvh) {
  #gameCanvas { height: 100dvh; }
}

#ui-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

#ui-layer > * {
  pointer-events: auto;
}

#criticalDamageCanvas {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: block;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  touch-action: none;
  user-select: none;
}
@supports (height: 100dvh) {
  #criticalDamageCanvas { height: 100dvh; }
}

.hidden {
  display: none !important;
}

#dockingBackdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  pointer-events: auto;
  background: rgba(2, 5, 12, .58);
  backdrop-filter: blur(2px);
}

/* ---- Game startup hand-off ---- */
.startup-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #03050c;
  color: #d8e7ff;
  opacity: 1;
  transition: opacity .28s ease;
}
.startup-overlay.is-complete { opacity: 0; pointer-events: none; }
.startup-grid {
  position: absolute;
  inset: -30%;
  opacity: .32;
  background-image: linear-gradient(rgba(73, 139, 218, .15) 1px, transparent 1px), linear-gradient(90deg, rgba(73, 139, 218, .15) 1px, transparent 1px);
  background-size: 42px 42px;
  transform: perspective(360px) rotateX(58deg) translateY(22%);
  animation: startup-grid-drift 2.4s linear infinite;
}
.startup-scanline {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(transparent 48%, rgba(116, 192, 255, .08) 50%, transparent 52%);
  background-size: 100% 9px;
  opacity: .45;
}
.startup-panel {
  position: relative;
  width: min(360px, calc(100vw - 40px));
  padding: 28px 26px 24px;
  text-align: center;
  border: 1px solid rgba(91, 157, 232, .48);
  background: radial-gradient(circle at 50% 25%, rgba(42, 102, 184, .2), rgba(5, 8, 18, .96) 65%);
  box-shadow: 0 0 50px rgba(35, 123, 226, .15), inset 0 0 30px rgba(64, 141, 235, .08);
}
.startup-kicker, .startup-detail { font: 10px/1.4 monospace; letter-spacing: .14em; color: #7898c7; }
.startup-kicker { margin-bottom: 10px; }
.startup-ship {
  display: block;
  width: 96px;
  height: 96px;
  margin: 0 auto 12px;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 18px rgba(104, 218, 255, .7));
  animation: startup-ship-launch 1.35s ease-in-out infinite;
}
.startup-status { color: #bde4ff; font: 700 18px/1.2 monospace; letter-spacing: .18em; text-shadow: 0 0 12px rgba(116, 210, 255, .65); }
.startup-progress { height: 4px; margin: 18px 0 10px; overflow: hidden; background: rgba(91, 132, 188, .2); }
.startup-progress span { display: block; width: var(--startup-progress, 0%); height: 100%; background: #64c8ff; box-shadow: 0 0 12px #64c8ff; transition: width .3s ease; }
.startup-detail { letter-spacing: .05em; }
.startup-overlay[data-mode="load"] .startup-ship,
.startup-overlay[data-mode="recovery"] .startup-ship { animation-duration: 2.2s; opacity: .72; }
@keyframes startup-ship-launch { 0%, 100% { transform: translateY(5px) scale(.94); opacity: .72; } 50% { transform: translateY(-8px) scale(1.04); opacity: 1; } }
@keyframes startup-grid-drift { from { transform: perspective(360px) rotateX(58deg) translateY(22%); } to { transform: perspective(360px) rotateX(58deg) translateY(28%); } }
@media (max-width: 480px) {
  .startup-panel { width: min(330px, calc(100vw - 28px)); padding: 22px 18px 20px; }
  .startup-ship { width: 78px; height: 78px; }
  .startup-status { font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  .startup-overlay, .startup-progress span { transition: none; }
  .startup-grid, .startup-ship { animation: none; }
}

/* Окремий клас від .hidden навмисно — перемикач "Сховати UI" толкає саме цей
   клас на прямих дітях #ui-layer, а .hidden лишається виключно "своїм" станом
   відкрито/закрито кожної панелі (інакше показ UI назад міг би випадково
   відкрити панель, що мала лишатись закритою). */
.ui-force-hidden {
  display: none !important;
}

/* ---- Back button ---- */
#backButton {
  position: absolute;
  top: var(--cockpit-safe-y);
  left: var(--cockpit-safe-x);
  min-height: 44px;
  padding: 7px 12px;
  background: linear-gradient(145deg, rgba(16, 42, 58, .9), var(--cockpit-surface));
  color: var(--cockpit-text);
  border: 1px solid var(--cockpit-edge);
  border-radius: var(--cockpit-radius);
  box-shadow: inset 0 1px rgba(218, 245, 252, .08), 0 0 12px var(--cockpit-glow);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: background 0.15s ease, border-color 0.15s ease;
}
#backButton:hover {
  background: var(--cockpit-surface-hover);
  border-color: var(--cockpit-edge-bright);
}
#backButton:active { transform: translateY(1px); }
#backButton:focus-visible { outline: 2px solid var(--cockpit-edge-bright); outline-offset: 2px; }

/* При "Сховати UI" #hud (причина, чому вузькі/низькі viewport-и відсувають
   кнопку вниз) сам сховано — піднімаємо кнопку назад у кут. Вища специфічність
   (ID+клас), ніж голий #backButton у медіа-запитах нижче — перебиває їх
   незалежно від ширини/висоти екрана. */
#backButton.ui-hidden-mode { top: var(--cockpit-safe-y); }

@media (max-width: 480px) {
  /* Портретний мобільний вигляд: на вузьких екранах (перевірено живцем на
     393px) #hud реально переноситься у 3 рядки, не 2 — сягає ~111px заввишки
     (не 100px, як тут вважалось раніше) — тому базовий top:100px давав ~11px
     накладання HUD на кнопку. */
  /* --hud-bottom публікує UI._observeHudHeight() з реального getBoundingClientRect:
     HUD тут переноситься на 2-3 рядки, і сталі top-и застарівали щоразу, як він ріс. */
  #backButton { top: calc(var(--hud-bottom, 111px) + 8px); left: 16px; }
}

/* ---- HUD (credits + cargo) ---- */
#hud {
  position: absolute;
  top: var(--cockpit-safe-y);
  right: max(16px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(155deg, rgba(14, 37, 52, .9), var(--cockpit-surface) 62%);
  border: 1px solid var(--cockpit-edge);
  border-radius: var(--cockpit-radius);
  padding: 8px 58px 8px 14px;
  color: var(--cockpit-text);
  font-size: 13px;
  letter-spacing: 0.03em;
  box-shadow: inset 0 1px rgba(218, 245, 252, .09), inset 0 -8px 18px rgba(0, 4, 12, .24), 0 0 15px var(--cockpit-glow);
}
#hudProgression {
  display: flex; align-items: center; gap: 8px; min-height: 44px; min-width: 44px;
  padding: 4px 9px; border: 1px solid var(--cockpit-edge); border-radius: var(--cockpit-radius);
  background: rgba(5, 15, 27, .78); color: #e4ecff; font: inherit; cursor: pointer; text-align: left;
}
#hudProgression:hover, #hudProgression[aria-expanded="true"] { border-color: var(--rank-color, #6f9dff); background: #152440; }
#hudProgression:focus-visible, #closePilotProgress:focus-visible, .pilot-progress-body:focus-visible { outline: 2px solid #a7caff; outline-offset: 3px; }
.rank-badge { display: inline-grid; place-items: center; width: 28px; height: 30px; flex-shrink: 0; color: var(--rank-color, #8fa4d1); border: 1px solid currentColor; border-radius: 4px 4px 11px 11px; font-weight: 700; letter-spacing: 0; }
.xp-hud-content { display: block; min-width: 105px; }
.xp-level { font-size: 11px; font-weight: 700; }
.xp-rank-name { font-size: 10px; color: var(--rank-color, #8fa4d1); }
.xp-track { display: block; position: relative; height: 5px; border-radius: 4px; overflow: hidden; background: #202d47; margin: 4px 0; }
.xp-fill { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--rank-color, #6f9dff); transition: width 450ms ease; }
.xp-hud-detail { display: block; font-size: 10px; color: #b9c8ef; }
#pilotProgressPanel { position: absolute; z-index: 130; right: 16px; top: calc(var(--hud-bottom, 90px) + 8px); width: min(390px, calc(100vw - 32px)); max-height: calc(100dvh - var(--hud-bottom, 90px) - 24px); display: flex; flex-direction: column; border: 1px solid #3a5a9a; border-radius: 12px; background: rgba(5, 7, 15, .97); color: #e4ecff; box-shadow: 0 16px 45px #0009; overflow: hidden; pointer-events: auto; }
#pilotProgressPanel { background: #05070f; }
.pilot-progress-header { display: flex; flex-shrink: 0; align-items: center; justify-content: space-between; padding: 8px 12px 8px 18px; border-bottom: 1px solid #283e66; }
#xpPanelNotice { flex-shrink: 0; padding: 10px 18px; border-bottom: 1px solid #35486b; color: #ffe1a6; background: #142035; font-size: 12px; line-height: 1.5; }
.pilot-progress-header h2 { margin: 0; font-size: 16px; }
#closePilotProgress { min-width: 44px; min-height: 44px; color: #b9c8ef; background: transparent; border: 0; font-size: 26px; cursor: pointer; }
.pilot-progress-body { padding: 18px; overflow-y: auto; min-height: 0; overscroll-behavior: contain; scrollbar-width: thin; }
.pilot-progress-body h3 { font-size: 14px; margin: 16px 0 10px; }
.pilot-progress-body p { font-size: 12px; line-height: 1.6; margin: 6px 0; }
.xp-hero { display: flex; align-items: center; gap: 15px; }
.xp-hero h3 { color: var(--rank-color); margin: 0; font-size: 20px; }
.rank-badge-large { width: 54px; height: 62px; font-size: 23px; }
.xp-panel-track { height: 8px; margin-top: 18px; }
.xp-muted { color: #a0b1d2; }
.xp-next-rank { padding: 10px; background: #111d34; border-radius: 5px; }
.xp-history, .xp-level-list { list-style: none; padding: 0; margin: 0; font-size: 12px; }
.xp-history li, .xp-level-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 8px; border-bottom: 1px solid #1e2b43; }
.xp-history li > span { overflow-wrap: anywhere; }
.xp-history strong { white-space: nowrap; color: #91daca; font-size: 11px; }
.xp-level-list li > span:last-child { white-space: nowrap; }
.xp-rank-milestone { display: block; padding-top: 5px; }
.xp-level-reward { display: block; padding-top: 6px; color: #c5d4ee; line-height: 1.5; overflow-wrap: anywhere; }
.xp-reward-status { display: block; padding-top: 4px; color: #96accd; font-size: 10px; }
.xp-achieved .xp-reward-status, .xp-current .xp-reward-status { color: #91daca; }
.xp-bonus-summary, .xp-next-reward { padding: 10px; border: 1px solid #2b4268; border-radius: 5px; background: #101a2c; }
#xpNotice, #xpPanelNotice { white-space: pre-line; overflow-wrap: anywhere; }
.xp-current { background: #172a49; border-left: 3px solid var(--rank-color); border-radius: 4px; }
.xp-achieved { color: #b9d7ee; }
.xp-locked { color: #8c9ab5; }
#xpNotice { position: absolute; top: calc(var(--hud-bottom, 90px) + 12px); left: 50%; transform: translateX(-50%); z-index: 140; max-width: min(420px, calc(100vw - 32px)); padding: 12px 18px; border: 1px solid #40678e; border-radius: 8px; background: #0b1729f5; color: #c9e9ff; font-size: 13px; text-align: center; pointer-events: none; }
#xpNotice.xp-level-up { border-color: #cfa765; color: #ffe1a6; }
@media (max-width: 1100px) {
  #hud { flex-wrap: wrap; max-width: calc(100vw - 32px); box-sizing: border-box; }
  .xp-rank-name { display: none; }
  .xp-hud-content { min-width: 66px; }
}
@media (max-width: 600px), (max-height: 500px) {
  #hudProgression { padding: 2px 5px; gap: 5px; }
  .xp-hud-detail { display: none; }
  .xp-hud-content { min-width: 42px; }
  #pilotProgressPanel { right: 8px; width: min(390px, calc(100vw - 16px)); }
  .pilot-progress-body { padding: 12px; }
}
@media (prefers-reduced-motion: reduce) { .xp-fill { transition: none; } }
.hud-divider {
  width: 1px;
  height: 13px;
  background: var(--cockpit-edge);
  box-shadow: 0 0 5px var(--cockpit-glow);
}
/* Верхній лівий стек — ЄДИНЕ місце, де задається позиція цього кута.
   #backButton живе на top:16px;left:16px (style.css:50-53) і видимий одночасно
   зі стеком у system view, тому стек відсунуто нижче нього. Усе, що сюди
   додається, стає ще одним flex-елементом і нічого не перекриває. */
#topLeftStack {
  position: absolute;
  top: 68px;
  left: var(--cockpit-safe-x);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  max-width: 260px;
}

/* Трекер іде ПЕРШИМ: він постійний, і поява/зникнення транзитних оголошень
   під ним не змушує його стрибати. */
#questTracker {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}
.quest-tracker-item {
  background: linear-gradient(145deg, rgba(13, 35, 50, .88), var(--cockpit-surface));
  border: 1px solid var(--cockpit-edge);
  border-radius: var(--cockpit-radius);
  padding: 6px 10px;
  box-shadow: inset 0 1px rgba(218, 245, 252, .07), 0 0 10px var(--cockpit-glow);
}
.quest-tracker-title {
  font-size: 12px;
  font-weight: 700;
  color: #6f9dff;
  margin-bottom: 2px;
}
.quest-tracker-desc {
  font-size: 11px;
  color: #b9c8ef;
}

.hud-stat {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
#hudCredits,
#hudCargo,
#hudHealth,
#hudArmor,
#hudFuel {
  padding: 3px 6px;
  border: 1px solid rgba(79, 178, 211, .24);
  border-radius: 3px;
  background: rgba(2, 10, 20, .42);
  box-shadow: inset 0 1px rgba(218, 245, 252, .04);
}
.hud-health { color: #70e080; }
.hud-armor  { color: #6090e0; }
.hud-fuel   { color: #70c0ff; }
.hud-warmode {
  color: #ff8060;
  border: 1px solid #c04040;
  border-radius: 4px;
  padding: 1px 6px;
}
.hud-autoattack {
  color: #70e0a0;
  border: 1px solid #40a070;
  border-radius: 4px;
  padding: 1px 6px;
}
.hud-warmode, .hud-autoattack {
  min-width: 44px;
  min-height: 44px;
  background: rgba(3, 12, 22, .62);
  font: inherit;
  cursor: pointer;
  opacity: 0.45;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.hud-warmode:hover, .hud-autoattack:hover { opacity: 0.7; }
.hud-warmode.active, .hud-autoattack.active { opacity: 1; }
.hud-warmode:active, .hud-autoattack:active { transform: translateY(1px); }
.hud-warmode:focus-visible, .hud-autoattack:focus-visible { outline: 2px solid var(--cockpit-edge-bright); outline-offset: 2px; opacity: 1; }

@media (max-width: 480px) {
  #hud { flex-wrap: wrap; row-gap: 6px; }
  .hud-warmode, .hud-autoattack { padding: 4px 9px; font-size: 13px; }
  .quest-tracker-title { font-size: 11px; }
  .quest-tracker-desc { font-size: 10px; }
}
@media (max-height: 600px) and (min-width: 481px) {
  /* Ландшафтний мобільний екран: вузька висота, але не вузька ширина —
     max-width:480px тут не спрацьовує, а HUD і так розтягується майже
     на весь екран і перекриває назви систем під ним. Підказки клавіш
     (I/O/C/A/F1) на дотик безглузді — прибираємо, решту стискаємо. */
  #hud { top: 8px; padding: 5px 10px; gap: 6px; font-size: 12px; }
  .hud-stat { font-size: 11px; }
  .hud-key { display: none; }
  .quest-tracker-title { font-size: 11px; }
  .quest-tracker-desc { font-size: 10px; }
}
.hud-bank {
  color: #4ad0ff;
  border: 1px solid #2a7aa0;
  border-radius: 4px;
  padding: 1px 6px;
}

.hud-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: 1px solid #3a5a9a;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 700;
  color: #7f93c2;
  letter-spacing: 0;
  cursor: default;
  user-select: none;
}

/* ---- Hint text ---- */
#hint {
  position: absolute;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  color: #7f93c2;
  font-size: 13px;
  background: rgba(10, 16, 32, 0.6);
  padding: 6px 14px;
  border-radius: 20px;
  letter-spacing: 0.02em;
  pointer-events: none;
}

@media (max-height: 600px) {
  /* Відцентрований текст на короткому екрані може дотягуватись до
     SHIP STATUS у правому нижньому куті — звужуємо, щоб не заходив туди. */
  #hint { max-width: 55vw; font-size: 12px; text-align: center; }
}

@media (max-width: 480px) {
  /* Нижній ряд на портреті зайнятий: STATS ліворуч, SHIP STATUS праворуч (~82px
     висоти). Центрована підказка на 390px лізе на обидва — піднімаємо її над ними.
     Правило мусить стояти ПІСЛЯ базового #hint: специфічність однакова, виграє пізніше. */
  #hint { bottom: 106px; max-width: calc(100vw - 32px); text-align: center; }
}

/* ---- Mission arrival toast ---- */
#missionAlert {
  /* fixed, а не absolute: елемент лежить усередині #topLeftStack (position:absolute),
     і absolute центрував би його по стеку, а не по екрану. */
  position: fixed;
  /* .alert-widget (top:70px) і цей тост обидва спрацьовують одночасно при
     старті нової гри (_maybeShowOnboardingWelcome + _enterSystemView) —
     130px дає ~10px запасу під типову висоту .alert-widget на будь-якій
     ширині екрана (перевірено живцем: desktop/portrait/landscape). */
  top: 130px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30, 80, 40, 0.95);
  border: 1px solid #4caf7d;
  border-radius: 6px;
  color: #a0ffcc;
  font-size: 13px;
  padding: 8px 18px;
  letter-spacing: 0.03em;
  white-space: normal;
  max-width: min(620px, calc(100vw - 24px));
  text-align: center;
}

@media (max-width: 480px) {
  /* Портретний вигляд: .alert-widget тут теж переноситься нижче (свій
     override нижче) — цей тост стоїть під ним, з запасом під довший
     wrap-текст на вузькій ширині. */

}

/* ---- Shared panel styles ---- */
#planetPanel,
#tradePanel,
#npcTradePanel,
#stationPanel,
#helpPanel,
#sectorBaronPanel,
.missions-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 340px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  background: rgba(8, 12, 24, 0.96);
  border: 1px solid #3a5a9a;
  border-radius: 10px;
  color: #e4ecff;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}
#planetPanel { z-index: 90; }

.missions-panel {
  width: 380px;
  max-height: 80vh;
  max-height: min(80vh, calc(100dvh - 24px));
  display: flex;
  flex-direction: column;
}

/* Capstone-мілстоун (дизайн-аудит п.3, "Sector Baron") — одноразове diegetic
   визнання, тому трохи виділене акцентним золотим кольором на тлі решти
   нейтрально-синьої HUD-палітри. */
#sectorBaronPanel { width: 360px; }
#sectorBaronPanel .panel-header {
  background: rgba(154, 122, 58, 0.3);
  border-bottom-color: #d4af6a;
  color: #ffd680;
  justify-content: center;
  letter-spacing: 0.12em;
}
#sectorBaronPanel .panel-body { text-align: center; padding: 18px 20px; }
#sectorBaronPanel .panel-footer { justify-content: center; }

/* New Game+ бейдж на бут-екрані — суто статусний, без впливу на баланс нової гри */
.sector-baron-badge {
  display: block;
  text-align: center;
  color: #ffd680;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  margin-bottom: 4px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: rgba(58, 90, 154, 0.25);
  border-bottom: 1px solid #3a5a9a;
  font-weight: 600;
  letter-spacing: 0.08em;
  font-size: 14px;
  flex-shrink: 0;
}

/* :not() виключає .tab-btn/.gs-zoom-btn — у #sidePanel вони теж лежать у .panel-header
   і мають власну повну стилізацію (фон/рамка/колір), яку це правило інакше перебивало б
   вищою специфічністю (елемент+клас проти самого класу). */
.panel-header button:not(.tab-btn):not(.gs-zoom-btn) {
  background: transparent;
  border: none;
  color: #cfe0ff;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}
.panel-header button:not(.tab-btn):not(.gs-zoom-btn):hover { color: #ff8a8a; }

.panel-body {
  padding: 14px 16px;
  font-size: 13px;
}

/* Keep compact dialogs usable on short phones. Dedicated scrolling bodies
   (missions/station/bank) keep their own sizing rules below. */
@media (max-height: 600px) {
  .panel-body:not(.missions-body):not(.station-body):not(.bank-body) {
    max-height: calc(100vh - 150px);
    overflow-y: auto;
  }
}

.missions-body {
  overflow-y: auto;
  flex: 1;
}

.panel-body .row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  color: #b9c8ef;
}

.panel-body .label { color: #7f93c2; }

.section-title {
  margin-top: 10px;
  margin-bottom: 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #6f9dff;
  border-top: 1px solid rgba(111, 157, 255, 0.2);
  padding-top: 8px;
}

.hud-module {
  background: rgba(15, 20, 40, 0.4);
  border: 1px solid rgba(58, 90, 154, 0.35);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
}
.hud-module .section-title,
.hud-module .missions-section-title {
  margin-top: 0;
  border-top: none;
  padding-top: 0;
}

.credits-readout {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  background: rgba(60, 45, 10, 0.35);
  border: 1px solid rgba(220, 170, 60, 0.4);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #f0cc60;
  text-shadow: 0 0 8px rgba(240, 204, 96, 0.35);
}
.credits-readout span:first-child {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: #c8a832;
  text-shadow: none;
}

.rep-pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.rep-pill-good    { background: rgba(40, 130, 80, 0.3);  border: 1px solid #4caf7d; color: #70d080; }
.rep-pill-bad     { background: rgba(140, 40, 40, 0.3);  border: 1px solid #c85a5a; color: #f07070; }
.rep-pill-neutral { background: rgba(60, 80, 120, 0.3);  border: 1px solid #4e6ebe; color: #a0b0c8; }

.panel-footer {
  padding: 12px 16px;
  border-top: 1px solid #3a5a9a;
  text-align: center;
  flex-shrink: 0;
}

.inv-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 4px 0 8px;
}

.inv-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  background: rgba(20, 30, 60, 0.55);
  border: 1px solid #3a5a9a;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
}

.inv-tier-dot {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  pointer-events: none;
}

.inv-cell.filled { cursor: grab; }
.inv-cell.filled:active { cursor: grabbing; }
.inv-cell.tap-selected { border-color: #7fc4ff; box-shadow: 0 0 0 2px rgba(127,196,255,.2), 0 0 10px rgba(127,196,255,.45); background: rgba(50,90,160,.55); }

.inv-cell.drag-over {
  border-color: #7fc4ff;
  background: rgba(50, 90, 160, 0.5);
}

.inv-icon {
  font-size: 20px;
  line-height: 1;
}

img.inv-icon {
  width: 22px;
  height: 22px;
  object-fit: contain;
  display: block;
}

.inv-qty {
  font-size: 11px;
  color: #b9c8ef;
  margin-top: 2px;
}

.ship-schematic {
  position: relative;
  width: 100%;
  height: clamp(180px, 34vw, 210px);
  margin: 4px 0 10px;
  background: #080d18 url("assets/ship-schematic-blueprint.png") center / cover no-repeat;
  border: 1px solid rgba(174, 211, 244, 0.32);
  box-shadow: inset 0 0 22px rgba(82, 126, 170, 0.12);
  border-radius: 6px;
  overflow: hidden;
}

.schematic-corner {
  position: absolute;
  width: 12px;
  height: 12px;
  border: 1px solid #6f9dff;
  opacity: 0.5;
  pointer-events: none;
  display: none;
}
.corner-tl { top: 2px;    left: 2px;    border-right: none;  border-bottom: none; }
.corner-tr { top: 2px;    right: 2px;   border-left: none;   border-bottom: none; }
.corner-bl { bottom: 2px; left: 2px;    border-right: none;  border-top: none; }
.corner-br { bottom: 2px; right: 2px;   border-left: none;   border-top: none; }

.ship-outline {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  pointer-events: none;
  shape-rendering: geometricPrecision;
  display: none;
}

.ship-structure { opacity: 0.94; }

.hull-silhouette {
  fill: none;
  stroke: rgba(218, 239, 255, 0.88);
  stroke-width: 1.15;
  stroke-linejoin: round;
}

.hull-inner {
  fill: none;
  stroke: rgba(160, 202, 235, 0.72);
  stroke-width: 0.8;
}

.blueprint-major { fill: none; stroke: rgba(195, 229, 255, 0.68); stroke-width: 0.7; }
.blueprint-secondary { fill: none; stroke: rgba(135, 180, 214, 0.48); stroke-width: 0.55; }
.blueprint-panel { fill: none; stroke: rgba(124, 169, 204, 0.42); stroke-width: 0.6; }

.hull-wing {
  fill: none;
  stroke: rgba(218, 239, 255, 0.82);
  stroke-width: 1;
  stroke-linejoin: round;
}

.hull-wing-panel {
  fill: none;
  stroke: rgba(145, 193, 226, 0.54);
  stroke-width: 0.65;
}

.hull-wing-highlight {
  fill: none;
  stroke: rgba(224, 244, 255, 0.78);
  stroke-width: 0.75;
  stroke-linecap: round;
}

.hull-wing-rib {
  fill: none;
  stroke: rgba(143, 190, 222, 0.54);
  stroke-width: 0.55;
  stroke-linecap: round;
}

.hull-nacelle {
  fill: none;
  stroke: rgba(191, 226, 249, 0.7);
  stroke-width: 0.75;
}

.hull-wing-light {
  fill: rgba(220, 244, 255, 0.78);
}

.hull-hardpoint {
  fill: none;
  stroke: rgba(220, 244, 255, 0.82);
  stroke-width: 0.7;
}

.hull-cockpit {
  fill: none;
  stroke: rgba(207, 237, 255, 0.82);
  stroke-width: 0.85;
}

.hull-module {
  fill: none;
  stroke: rgba(145, 193, 226, 0.58);
  stroke-width: 0.7;
}

.module-core {
  stroke: rgba(185, 221, 245, 0.72);
}

.hull-reactor {
  fill: none;
  stroke: rgba(222, 245, 255, 0.88);
  stroke-width: 0.85;
}

.blueprint-reactor-ring { fill: none; stroke: rgba(128, 176, 211, 0.58); stroke-width: 0.55; stroke-dasharray: 2 2; }
.blueprint-reactor-mark { fill: none; stroke: rgba(217, 242, 255, 0.75); stroke-width: 0.65; }

.hull-connector {
  fill: none;
  stroke: rgba(123, 171, 207, 0.48);
  stroke-width: 0.6;
  stroke-linecap: round;
}

.blueprint-wing-grid, .blueprint-strut { fill: none; stroke: rgba(128, 177, 211, 0.56); stroke-width: 0.55; }

.hull-engine {
  fill: none;
  stroke: rgba(196, 229, 249, 0.76);
  stroke-width: 0.85;
}

.equip-slot {
  position: absolute;
  /* CSS zoom scales the whole body panel. Keep the actual touch target >=44px. */
  width: max(44px, var(--side-control-min, 44px));
  height: max(44px, var(--side-control-min, 44px));
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: transparent;
  border: 0;
  border-radius: 0;
  opacity: .92;
  touch-action: manipulation;
  user-select: none;
}

.equip-slot::before {
  content: '';
  position: absolute;
  inset: 7px;
  border-radius: 3px;
  background:
    linear-gradient(rgba(205, 235, 255, .78), rgba(205, 235, 255, .78)) left 3px top 3px / 9px 1px no-repeat,
    linear-gradient(rgba(205, 235, 255, .78), rgba(205, 235, 255, .78)) left 3px top 3px / 1px 9px no-repeat,
    linear-gradient(rgba(205, 235, 255, .78), rgba(205, 235, 255, .78)) right 3px top 3px / 9px 1px no-repeat,
    linear-gradient(rgba(205, 235, 255, .78), rgba(205, 235, 255, .78)) right 3px top 3px / 1px 9px no-repeat,
    linear-gradient(rgba(205, 235, 255, .78), rgba(205, 235, 255, .78)) left 3px bottom 3px / 9px 1px no-repeat,
    linear-gradient(rgba(205, 235, 255, .78), rgba(205, 235, 255, .78)) left 3px bottom 3px / 1px 9px no-repeat,
    linear-gradient(rgba(205, 235, 255, .78), rgba(205, 235, 255, .78)) right 3px bottom 3px / 9px 1px no-repeat,
    linear-gradient(rgba(205, 235, 255, .78), rgba(205, 235, 255, .78)) right 3px bottom 3px / 1px 9px no-repeat,
    #0b192a;
  border: 1px solid rgba(174, 211, 244, .62);
  z-index: 0;
}

.equip-slot > * {
  position: relative;
  z-index: 1;
}

.equip-icon {
  font-size: 15px;
  line-height: 1;
  color: #d8f1ff;
  filter: grayscale(.7) brightness(1.25);
  z-index: 1;
}

.equip-icon.has-img {
  display: inline-block;
  width: 20px;
  height: 20px;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
}

.equip-tag {
  font-size: 6.5px;
  letter-spacing: 0.06em;
  color: #b8d9ee;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-weight: 600;
  line-height: 1.05;
  white-space: nowrap;
  z-index: 1;
}

.equip-slot .equip-tag { display: none; }

.slot-shield   { top: 74%; left: 50%; }
.slot-weapon-l { top: 50%; left: 20%; }
.slot-weapon-r { top: 50%; left: 80%; }
.slot-weapon-c { top: 43%; left: 50%; }
.slot-fuel     { top: 86%; left: 38%; }
.slot-ammo     { top: 58%; left: 50%; }
.slot-engine   { top: 86%; left: 62%; }

.slot-weapon-l::before,
.slot-weapon-r::before,
.slot-weapon-c::before {
  border-radius: 50%;
  background: #0b192a;
  border-color: rgba(205, 235, 255, .78);
  box-shadow: inset 0 0 7px rgba(127, 196, 255, .12);
}

.equip-slot.filled.slot-weapon-l::before,
.equip-slot.filled.slot-weapon-r::before,
.equip-slot.filled.slot-weapon-c::before {
  background: #102b43;
  border-color: rgba(220, 244, 255, .92);
}

.equip-tier-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  pointer-events: none;
}

.equip-slot.filled {
  border-color: transparent;
  background: transparent;
  opacity: 1;
  cursor: grab;
}
.equip-slot.filled::before {
  border-color: rgba(220, 244, 255, .9);
  background: #102b43;
  box-shadow: inset 0 0 8px rgba(127, 196, 255, .12), 0 0 5px rgba(127, 196, 255, .2);
}
.equip-slot.filled:active { cursor: grabbing; }

.equip-slot.drag-over {
  border-color: transparent;
  background: transparent;
}
.equip-slot.drag-over::before {
  border-color: #e1f5ff;
  background: #244f6c;
}

.panel-footer-multi {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* planetPanel footer тепер має 4 кнопки (Trade/Missions/Hangar/Close) —
   при базовій ширині 340px і padding 8px 20px вони вже не влазять в один
   рядок навіть на десктопі (не лише мобільний breakpoint нижче) — тож wrap
   і трохи вужчий padding саме тут, без зачіпання інших .panel-footer-multi
   панелей (напр. pirate dialogue). */
#planetPanel .panel-footer-multi {
  flex-wrap: wrap;
}
#planetPanel .panel-footer-multi button {
  flex: 1 1 calc(50% - 4px);
  padding: 8px 10px;
}

.panel-footer button {
  background: #3a5a9a;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 20px;
  font-size: 13px;
  letter-spacing: 0.08em;
  cursor: pointer;
}
.panel-footer button:hover { background: #4d72c2; }

.btn-secondary {
  background: rgba(58, 90, 154, 0.3) !important;
  border: 1px solid #3a5a9a !important;
  color: #cfe0ff !important;
}
.btn-secondary:hover { background: rgba(78, 110, 190, 0.5) !important; }

.planet-table-wrap {
  background: rgba(58, 90, 154, 0.12);
  border: 1px solid rgba(58, 90, 154, 0.35);
  border-radius: 6px;
  padding: 2px 10px;
  margin-bottom: 8px;
}
.planet-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.planet-table td { padding: 5px 2px; border-bottom: 1px solid rgba(58, 90, 154, 0.2); }
.planet-table tr:last-child td { border-bottom: none; }
.planet-table tr:nth-child(even) { background: rgba(58, 90, 154, 0.08); }
.planet-table td:first-child { color: #7f93c2; }
.planet-table td:last-child  { color: #e4ecff; font-weight: 600; text-align: right; }

/* ---- Planet Port: greeting overlaid on the port photo ---- */
.planet-port-scene-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #3a5a9a;
  background: rgba(0, 0, 0, 0.3);
  margin: 0 0 10px;
}
.planet-greeting {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: 18px 12px 10px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  color: #ffffff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  background: linear-gradient(to top, rgba(4, 8, 20, 0.85) 0%, rgba(4, 8, 20, 0.5) 55%, rgba(4, 8, 20, 0) 100%);
}

.planet-panel-tabs {
  display: flex;
  gap: 6px;
  margin: 0 0 10px;
  padding: 3px;
  border: 1px solid rgba(58, 90, 154, 0.45);
  border-radius: 6px;
  background: rgba(14, 22, 48, 0.72);
}
.planet-panel-tab {
  flex: 1;
  padding: 7px 8px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: #7f93c2;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
}
.planet-panel-tab.tab-active {
  border-color: #6f9dff;
  background: rgba(111, 157, 255, 0.18);
  color: #e4ecff;
}
.planet-quests-view {
  display: grid;
  gap: 8px;
}
.planet-quest-item {
  padding: 9px 10px;
  border: 1px solid rgba(58, 90, 154, 0.55);
  border-radius: 6px;
  background: rgba(30, 45, 80, 0.42);
}
.planet-quest-item.status-completed { opacity: 0.72; }
.planet-quest-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: #e4ecff;
}
.planet-quest-status {
  color: #7fc4ff;
  font-size: 9px;
  letter-spacing: 0.08em;
}
.status-completed .planet-quest-status { color: #82d99b; }
.planet-quest-description {
  margin: 6px 0;
  color: #b7c7eb;
  font-size: 12px;
  line-height: 1.35;
}
.planet-quest-objective {
  margin-bottom: 7px;
  color: #7fc4ff;
  font-size: 11px;
}
.planet-quest-item button { width: 100%; }

/* Second visual tier — population/government/economy stay useful but
   step back behind the greeting/quest-offer (smaller, dimmer). */
.planet-secondary-info { opacity: 0.82; }
.planet-secondary-info .planet-table { font-size: 12px; }

/* Вбудований планетний діалог (showPlanetDialogue/hidePlanetDialogue) — той самий
   вигляд тексту/кнопок, що й у #pirateDialogueText/#pirateDialogueChoices, лишень
   всередині planetPanel .panel-body замість floating pirateDialoguePanel. */
#planetDialogueText {
  margin: 0 0 10px;
  font-size: 13px;
  line-height: 1.4;
  color: #e4ecff;
}
#planetDialogueChoices.panel-footer-multi {
  flex-wrap: wrap;
  margin-bottom: 4px;
}
#planetDialogueChoices button { min-width: 40%; }

@media (max-width: 480px) {
  #planetPanel { width: min(340px, 92vw); }
  #planetPanel .panel-body {
    max-height: calc(100dvh - 150px);
    overflow-y: auto;
  }
  #planetPanel .panel-footer-multi { flex-wrap: wrap; }
  #planetPanel .panel-footer button { padding: 11px 14px; }
  .planet-panel-tab { padding: 9px 8px; }
  #pirateDialoguePanel { width: min(320px, 92vw); }
  #pirateDialoguePanel .panel-footer-multi { flex-wrap: wrap; }
  #pirateDialoguePanel .panel-footer button { padding: 11px 14px; }
}
@media (max-height: 600px) {
  #planetPanel .panel-body { max-height: 60vh; overflow-y: auto; }
}

/* ---- Mission badge in planet panel ---- */
.mission-badge {
  margin-top: 10px;
  padding: 6px 10px;
  background: rgba(30, 80, 40, 0.6);
  border: 1px solid #4caf7d;
  border-radius: 5px;
  color: #a0ffcc;
  font-size: 12px;
  text-align: center;
}

/* ---- Trade panel ---- */
.trade-balance-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #b9c8ef;
  margin-bottom: 12px;
}

.trade-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  color: #b9c8ef;
}

.trade-table th {
  text-align: left;
  color: #7f93c2;
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 4px 4px 8px;
  border-bottom: 1px solid rgba(111, 157, 255, 0.2);
}

.trade-table td {
  padding: 7px 4px;
  border-bottom: 1px solid rgba(58, 90, 154, 0.2);
  vertical-align: middle;
}

.trade-table tr:last-child td { border-bottom: none; }

.trade-actions {
  display: flex;
  gap: 5px;
  white-space: nowrap;
}

.trade-btn {
  border: none;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 11px;
  cursor: pointer;
  letter-spacing: 0.04em;
  font-weight: 600;
  transition: opacity 0.1s;
}
.trade-btn:hover { opacity: 0.8; }

.buy-btn  { background: #2a6a3a; color: #a0ffc0; }
.sell-btn { background: #6a2a2a; color: #ffb0b0; }

/* Compact goods rows on narrow screens. The DOM and delegated trade handlers stay unchanged. */
@media (max-width: 480px) {
  #tradePanel, #npcTradePanel { width: calc(100vw - 24px); max-height: calc(100dvh - 24px); }
  #tradePanel .panel-body, #npcTradePanel .panel-body { padding: 11px 12px; }
  .trade-balance-row { gap: 4px; margin-bottom: 8px; font-size: 11px; }
  .trade-table { table-layout: fixed; font-size: 10px; }
  .trade-table th { padding: 3px 2px 5px; font-size: 9px; letter-spacing: .03em; }
  .trade-table td { padding: 5px 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #tradePanel .trade-table th:nth-child(1), #tradePanel .trade-table td:nth-child(1) { width: 25%; }
  #tradePanel .trade-table th:nth-child(2), #tradePanel .trade-table td:nth-child(2),
  #tradePanel .trade-table th:nth-child(3), #tradePanel .trade-table td:nth-child(3),
  #tradePanel .trade-table th:nth-child(4), #tradePanel .trade-table td:nth-child(4) { width: 15%; }
  #tradePanel .trade-table th:nth-child(5), #tradePanel .trade-table td:nth-child(5) { width: 30%; }
  #npcTradePanel .trade-table th:nth-child(1), #npcTradePanel .trade-table td:nth-child(1) { width: 19%; }
  #npcTradePanel .trade-table th:nth-child(2), #npcTradePanel .trade-table td:nth-child(2),
  #npcTradePanel .trade-table th:nth-child(3), #npcTradePanel .trade-table td:nth-child(3),
  #npcTradePanel .trade-table th:nth-child(4), #npcTradePanel .trade-table td:nth-child(4),
  #npcTradePanel .trade-table th:nth-child(5), #npcTradePanel .trade-table td:nth-child(5) { width: 14%; }
  #npcTradePanel .trade-table th:nth-child(6), #npcTradePanel .trade-table td:nth-child(6) { width: 23%; }
  .trade-actions { gap: 2px; }
  .trade-btn { min-width: 0; flex: 1 1 0; padding: 5px 3px; font-size: 9px; letter-spacing: 0; }
  .trade-qty-row { margin-top: 8px; }
}

@media (max-height: 600px) and (min-width: 481px) {
  #tradePanel, #npcTradePanel { max-height: calc(100dvh - 16px); }
  #tradePanel .panel-body, #npcTradePanel .panel-body { padding: 9px 12px; }
  .trade-table th { padding-bottom: 4px; }
  .trade-table td { padding-top: 4px; padding-bottom: 4px; }
  .trade-btn { padding: 3px 7px; font-size: 10px; }
}

/* ---- Missions panel ---- */
.missions-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #6f9dff;
  border-top: 1px solid rgba(111, 157, 255, 0.2);
  padding-top: 8px;
  margin-bottom: 6px;
}

.mission-item {
  background: rgba(20, 30, 60, 0.5);
  border: 1px solid rgba(58, 90, 154, 0.4);
  border-radius: 6px;
  padding: 9px 12px;
  margin-bottom: 7px;
  font-size: 12px;
}

.mission-item.completable {
  border-color: #4caf7d;
  background: rgba(20, 60, 35, 0.5);
}

.mission-item.escort-mission {
  border-color: #a05cff;
  background: rgba(70, 45, 110, 0.35);
}

.mission-desc {
  color: #c8d8ff;
  margin-bottom: 5px;
}

.mission-meta {
  display: flex;
  justify-content: space-between;
  color: #7f93c2;
  font-size: 11px;
  margin-bottom: 7px;
}

.mission-reward { color: #7dffb2; }

.mission-accept-btn,
.mission-complete-btn {
  border: none;
  border-radius: 4px;
  padding: 5px 14px;
  font-size: 11px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.mission-accept-btn   { background: #3a5a9a; color: #fff; }
.mission-accept-btn:hover { background: #4d72c2; }

.mission-complete-btn { background: #2a6a3a; color: #a0ffc0; }
.mission-complete-btn:hover { background: #3a8a50; }

.no-missions {
  color: #4a5a7a;
  font-size: 12px;
  font-style: italic;
  padding: 4px 0;
  margin: 0;
}

.quest-title {
  font-weight: 700;
  font-size: 12px;
  color: #6f9dff;
  margin-bottom: 3px;
}
.completed-mission .quest-title { color: #7f93c2; }

/* ---- Side panels (Inventory + Missions Log) ---- */
.side-panel {
  position: absolute;
  top: calc(var(--hud-bottom, 52px) + 8px);
  right: 16px;
  width: 360px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - var(--hud-bottom, 52px) - 20px);
  max-height: calc(100dvh - var(--hud-bottom, 52px) - 20px);
  background: rgba(8, 12, 24, 0.96);
  border: 1px solid #3a5a9a;
  border-radius: 10px;
  color: #e4ecff;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  transform-origin: top right;
}

.tab-row {
  display: flex;
  gap: 4px;
  flex: 1;
}

.tab-btn {
  background: transparent;
  border: none;
  border-radius: 5px 5px 0 0;
  border-bottom: 2px solid transparent;
  color: #7f93c2;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  white-space: nowrap;
  cursor: pointer;
  padding: 4px 10px 5px;
  transition: color 0.15s, background 0.15s;
}
.tab-btn:hover { color: #cfe0ff; }
.tab-btn.tab-active {
  color: #cfe0ff;
  background: rgba(111, 157, 255, 0.18);
  border-bottom-color: #6f9dff;
}

#sideInventory,
#sideMissions {
  max-height: calc(100vh - var(--hud-bottom, 52px) - 88px);
  max-height: calc(100dvh - var(--hud-bottom, 52px) - 88px);
  overflow-y: auto;
}

.sp-open-btn {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  z-index: 85;
  min-width: 44px;
  min-height: 44px;
  background: linear-gradient(145deg, rgba(14, 37, 52, .92), var(--cockpit-surface));
  border: 1px solid var(--cockpit-edge);
  border-radius: var(--cockpit-radius);
  color: var(--cockpit-text);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 6px 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  box-shadow: inset 0 1px rgba(218, 245, 252, .08), 0 0 11px var(--cockpit-glow);
}
.sp-open-btn:hover { background: var(--cockpit-surface-hover); color: #effcff; border-color: var(--cockpit-edge-bright); }
.sp-open-btn:active { transform: translateY(1px); }
.sp-open-btn:focus-visible { outline: 2px solid var(--cockpit-edge-bright); outline-offset: 2px; }
#spOpenInventoryBtn { top: calc(var(--hud-bottom, 52px) + 8px); }
#spOpenMissionsBtn  { top: calc(var(--hud-bottom, 52px) + 8px + var(--cockpit-control-step)); }
#mmOpenMenuBtn       { top: calc(var(--hud-bottom, 52px) + 8px + var(--cockpit-control-step-2)); }

@media (max-width: 480px) {
  .side-panel { width: min(360px, 92vw); }
}
@media (max-height: 600px) and (min-width: 481px) {
  #sideInventory, #sideMissions { max-height: 50vh; }
}

.equip-slot.tap-eligible { border-color: transparent; opacity: 1; }
.equip-slot.tap-eligible::before { border-color: #7fc4ff; box-shadow: 0 0 0 2px rgba(127,196,255,.2), 0 0 10px rgba(127,196,255,.45); }
.equip-slot.tap-invalid { border-color: transparent; animation: schematic-shake 180ms ease-in-out; }
.equip-slot.tap-invalid::before { border-color: #ff7f92; }
.equip-slot.hover-eligible::before {
  border-color: #b8eaff;
  box-shadow: 0 0 0 1px rgba(184,234,255,.28), 0 0 9px rgba(127,196,255,.65);
}
.schematic-readout { display: grid; gap: 3px; margin: 0 2px 4px; padding: 7px 8px; border: 1px solid rgba(78,110,190,.45); border-radius: 5px; background: rgba(14,22,48,.68); color: #aebde4; font-size: 10px; line-height: 1.25; }
.schematic-readout-row { display: flex; gap: 6px; min-width: 0; }
.schematic-readout-label { flex: 0 0 62px; color: #6f9dff; font-size: 8px; letter-spacing: .08em; }
.schematic-readout-value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.schematic-readout-hint { color: #7fc4ff; font-size: 9px; }
@keyframes schematic-shake { 0%,100% { transform: translate(-50%,-50%); } 50% { transform: translate(calc(-50% + 3px),-50%); } }
@media (max-width: 480px) { .schematic-readout { font-size: 9px; } }

.key-badge {
  display: inline-block;
  padding: 1px 5px;
  margin-left: 6px;
  background: rgba(58, 90, 154, 0.4);
  border: 1px solid #3a5a9a;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  color: #7f93c2;
  vertical-align: middle;
  letter-spacing: 0;
}

.completed-mission {
  opacity: 0.6;
  border-color: rgba(58, 90, 154, 0.25) !important;
}

.completed-mission .mission-reward {
  color: #7dffb2;
}

/* ---- Planet reputation badge ---- */
.reputation-badge {
  margin-top: 8px;
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 12px;
  text-align: center;
}
.rep-warning { background: rgba(180,140,0,0.25); border: 1px solid #c8a832; color: #f0cc60; }
.rep-bad     { background: rgba(180,80,0,0.25);  border: 1px solid #c86432; color: #f09060; }
.rep-hostile { background: rgba(140,20,20,0.25); border: 1px solid #aa3333; color: #ff8080; }

/* ---- Abandon mission button ---- */
.mission-abandon-btn {
  border: none;
  border-radius: 4px;
  padding: 5px 14px;
  font-size: 11px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: rgba(120,30,30,0.7);
  color: #ff9090;
  margin-left: 6px;
}
.mission-abandon-btn:hover { background: rgba(160,40,40,0.9); }

/* ---- Build & Factory panels ---- */
.build-panel {
  position: absolute;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  width: 280px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 96px);
  max-height: calc(100dvh - 96px);
  background: rgba(8, 12, 24, 0.96);
  border: 1px solid #8a5a2a;
  border-radius: 10px;
  color: #e4dccc;
  box-shadow: 0 6px 30px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

.trade-station-panel {
  width: 320px;
  border-color: rgba(90, 200, 140, 0.55);
  background: rgba(6, 16, 12, 0.96);
}
.trade-station-panel .panel-header { color: #b8ffcf; }
.trade-station-panel .panel-body { max-height: 360px; overflow-y: auto; }
.trade-stats-line {
  font-size: 11px;
  color: #8fdca8;
  background: rgba(90, 200, 140, 0.1);
  border: 1px solid rgba(90, 200, 140, 0.25);
  border-radius: 6px;
  padding: 5px 8px;
  margin: 6px 0 10px;
}
.trade-missions-list, .trade-traders-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 8px;
}
.trader-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
  background: rgba(20, 30, 60, 0.5);
  border: 1px solid rgba(58, 90, 154, 0.4);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  color: #c8d8ff;
}
.trader-row-top { display: flex; justify-content: space-between; align-items: center; }
.trader-row .trader-credits { color: #7dffb2; font-weight: 600; }
.trader-activity { font-size: 10.5px; color: #8098c0; font-style: italic; }
.trader-count-badge {
  font-size: 11px;
  color: #7f93c2;
  font-weight: normal;
  text-transform: none;
  letter-spacing: 0;
}
.btn-build, .btn-collect {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 9px;
  border: none;
  border-radius: 6px;
  background: #7a4a18;
  color: #f0c880;
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: background 0.15s;
}
.btn-build:hover:not(:disabled), .btn-collect:hover:not(:disabled) { background: #9a6228; }
.btn-build:disabled, .btn-collect:disabled { opacity: 0.4; cursor: not-allowed; }

.station-tabs { padding: 0 8px; border-bottom: 1px solid #3a5a9a; }
.station-body {
  max-height: 70vh;
  max-height: min(70vh, calc(100dvh - 150px));
  overflow-y: auto;
}
.station-pane .section-title:first-child { margin-top: 0; border-top: none; padding-top: 0; }

.upg-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid rgba(111, 157, 255, 0.08);
  font-size: 12px;
}
.upg-row .label { color: #7f93c2; }
.upg-row:last-of-type { border-bottom: none; }

/* ---- Hangar (Inventory panel reused from planet docking) ---- */
.hangar-back-btn {
  width: 100%;
  margin-bottom: 10px;
  padding: 7px 10px;
}
.hangar-hint {
  color: #4a5a7a;
  font-size: 11px;
  font-style: italic;
  margin-top: 4px;
}

.station-table-wrap {
  background: rgba(58, 90, 154, 0.12);
  border: 1px solid rgba(58, 90, 154, 0.35);
  border-radius: 6px;
  padding: 2px 10px;
  margin-bottom: 8px;
}
.station-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.station-table td { padding: 5px 2px; border-bottom: 1px solid rgba(58, 90, 154, 0.2); }
.station-table tr:last-child td { border-bottom: none; }
.station-table tr:nth-child(even) { background: rgba(58, 90, 154, 0.08); }
.station-table td:first-child { color: #7f93c2; }
.station-table td:last-child  { color: #e4ecff; font-weight: 600; text-align: right; }
.station-table-note { color: #d4aa50 !important; font-weight: normal !important; text-align: center !important; font-size: 12px; }

@media (max-width: 480px) {
  #stationPanel { width: min(340px, 92vw); }
  #stationPanel .station-tabs { flex-wrap: wrap; }
  #stationPanel .tab-btn { padding: 7px 8px 8px; font-size: 11px; }
  #stationPanel .panel-footer button { padding: 11px 14px; }
  #stationPanel .btn-build-sm { padding: 8px 12px; }
}
@media (max-height: 600px) {
  #stationPanel .station-body { max-height: 55vh; }
}

.btn-build-sm {
  padding: 5px 10px;
  border: none;
  border-radius: 5px;
  background: #7a4a18;
  color: #f0c880;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.btn-build-sm:hover:not(:disabled) { background: #9a6228; }
.btn-build-sm:disabled { opacity: 0.4; cursor: not-allowed; }

.station-weapons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  margin: 6px 0;
}
.station-weapon-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
  padding: 10px 6px;
  background: rgba(20, 30, 60, 0.55);
  border: 1px solid #3a5a9a;
  border-radius: 8px;
}

/* ---- Docking cockpit station redesign ---- */
#stationPanel,
.station-compact-panel,
.trade-station-panel {
  top: 50%;
  bottom: auto;
  width: min(760px, calc(100vw - 24px));
  max-height: min(86dvh, 760px);
  transform: translate(-50%, -50%);
  border-color: rgba(103, 190, 255, .55);
  border-radius: 12px;
  background: linear-gradient(150deg, rgba(8, 17, 34, .98), rgba(5, 9, 19, .98));
  box-shadow: 0 18px 70px rgba(0, 0, 0, .72), 0 0 34px rgba(40, 138, 222, .12), inset 0 0 0 1px rgba(148, 211, 255, .05);
  z-index: 95;
}
#stationPanel .panel-header,
.station-compact-panel .panel-header,
.trade-station-panel .panel-header {
  min-height: 64px;
  padding: 10px 16px;
  background: linear-gradient(90deg, rgba(24, 65, 110, .52), rgba(17, 28, 56, .28));
  border-bottom-color: rgba(103, 190, 255, .35);
}
.station-scene {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: linear-gradient(135deg, rgba(22, 53, 92, .7), rgba(4, 9, 19, .95));
  border-bottom: 1px solid rgba(103, 190, 255, .25);
  filter: saturate(.9) contrast(1.04);
}
.trade-station-panel .station-scene { border-bottom-color: rgba(90, 200, 140, .28); filter: saturate(.85) hue-rotate(25deg); }
.station-compact-panel[data-station-type="exploration"] .station-scene { border-bottom-color: rgba(183, 135, 255, .3); filter: saturate(.85) hue-rotate(285deg); }
.station-heading { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.station-heading > span:last-child { color: #d7edff; font-size: 15px; letter-spacing: .12em; }
.station-kicker { color: #6ca7d4; font: 9px/1.2 monospace; letter-spacing: .14em; }
.station-resource-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  padding: 7px 12px;
  background: rgba(4, 10, 22, .82);
  border-bottom: 1px solid rgba(86, 157, 218, .22);
}
.station-resource-bar > div { display: flex; justify-content: space-between; gap: 8px; padding: 4px 8px; border-right: 1px solid rgba(86, 157, 218, .16); }
.station-resource-bar > div:last-child { border-right: 0; }
.station-resource-bar span { color: #6687ae; font: 9px/1.2 monospace; letter-spacing: .1em; }
.station-resource-bar strong { color: #bce6ff; font: 600 11px/1.2 monospace; white-space: nowrap; }
#stationPanel .station-tabs { gap: 2px; padding: 7px 12px 0; background: rgba(10, 22, 43, .5); }
#stationPanel .tab-btn { flex: 1; min-height: 34px; color: #7592b8; border: 1px solid transparent; border-bottom: 2px solid transparent; }
#stationPanel .tab-btn:hover { color: #d7edff; background: rgba(74, 158, 222, .12); }
#stationPanel .tab-btn.tab-active { color: #bceaff; background: rgba(63, 158, 224, .2); border-color: rgba(82, 177, 241, .26); border-bottom-color: #69cbff; }
.station-body { padding: 16px; scrollbar-color: #315a86 rgba(5, 11, 24, .6); }
.station-pane { animation: station-pane-in .18s ease-out; }
.station-pane .section-title { margin-top: 14px; padding: 8px 0 6px; color: #75c9ff; border-top-color: rgba(103, 190, 255, .23); }
.station-pane .section-title:first-child { margin-top: 0; }
.station-table-wrap { padding: 7px 12px; background: rgba(21, 51, 87, .25); border-color: rgba(91, 169, 226, .3); border-radius: 8px; }
.station-table td { padding: 8px 3px; border-bottom-color: rgba(91, 169, 226, .16); }
.station-table tr:nth-child(even) { background: rgba(80, 157, 218, .07); }
.station-table td:last-child { color: #d8f1ff; }
.station-body .trade-qty-row { margin: 12px 0 4px; padding: 9px 11px; background: rgba(5, 12, 26, .5); border: 1px solid rgba(91, 169, 226, .2); border-radius: 7px; }
#stationPanel .btn-build { background: linear-gradient(90deg, #17638a, #2386a7); color: #d9f5ff; border: 1px solid rgba(129, 218, 255, .45); box-shadow: 0 0 14px rgba(45, 174, 222, .15); }
#stationPanel .btn-build:hover:not(:disabled) { background: linear-gradient(90deg, #217ba7, #2b9dbd); }
.station-weapon-card { min-height: 142px; padding: 12px 8px; background: linear-gradient(160deg, rgba(22, 52, 88, .65), rgba(10, 22, 43, .76)); border-color: rgba(91, 169, 226, .32); transition: transform .15s, border-color .15s, background .15s; }
.station-weapon-card:hover { transform: translateY(-2px); border-color: rgba(113, 210, 255, .7); background: rgba(32, 74, 119, .72); }
.station-weapon-card .btn-build-sm { margin-top: auto; background: rgba(37, 111, 151, .7); color: #d8f3ff; }
.station-compact-panel { width: min(420px, calc(100vw - 24px)); }
.trade-station-panel { width: min(520px, calc(100vw - 24px)); }
.station-compact-panel .panel-body, .trade-station-panel .panel-body { padding: 16px; }
.station-compact-panel .row { padding: 10px 12px; background: rgba(21, 51, 87, .25); border-bottom: 1px solid rgba(91, 169, 226, .15); }
.trade-station-panel { border-color: rgba(90, 200, 140, .6); background: linear-gradient(150deg, rgba(7, 25, 22, .98), rgba(5, 12, 17, .98)); }
.trade-station-panel .panel-header { background: linear-gradient(90deg, rgba(24, 103, 79, .5), rgba(17, 48, 51, .25)); border-bottom-color: rgba(90, 200, 140, .35); }
.trade-station-panel .station-heading > span:last-child { color: #d0ffe1; }
.trade-station-panel .station-kicker { color: #77bc96; }
.trade-station-panel .section-title { color: #82e7a7; border-top-color: rgba(90, 200, 140, .25); }
.trade-station-panel .mission-item, .trade-station-panel .trader-row { padding: 10px 12px; border-color: rgba(90, 200, 140, .25); background: rgba(19, 67, 53, .28); border-radius: 8px; }
.trade-station-panel .trade-stats-line { padding: 9px 11px; border-color: rgba(90, 200, 140, .35); background: rgba(90, 200, 140, .13); }
.station-compact-panel[data-station-type="exploration"] { border-color: rgba(183, 135, 255, .58); background: linear-gradient(150deg, rgba(24, 14, 48, .98), rgba(8, 8, 21, .98)); }
.station-compact-panel[data-station-type="exploration"] .panel-header { background: linear-gradient(90deg, rgba(89, 53, 145, .48), rgba(34, 25, 66, .25)); border-bottom-color: rgba(183, 135, 255, .35); }
.station-compact-panel[data-station-type="exploration"] .station-kicker { color: #b48ce5; }
.station-compact-panel[data-station-type="exploration"] .station-heading > span:last-child { color: #f0e4ff; }
.station-compact-panel[data-station-type="exploration"] .btn-collect { background: linear-gradient(90deg, #6542a0, #8e5ac0); color: #f1e6ff; border: 1px solid rgba(215, 184, 255, .42); }
@keyframes station-pane-in { from { opacity: .45; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }
@media (max-width: 560px) {
  #stationPanel, .station-compact-panel, .trade-station-panel { width: calc(100vw - 24px); max-height: calc(100dvh - 30px); }
  #stationPanel .station-tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  #stationPanel .station-tabs::-webkit-scrollbar { display: none; }
  #stationPanel .tab-btn { flex: 0 0 auto; min-width: 112px; min-height: 42px; padding: 8px 10px; }
  .station-resource-bar { grid-template-columns: repeat(2, 1fr); gap: 4px; }
  .station-resource-bar > div { border-right: 0; padding: 6px 7px; background: rgba(17, 42, 70, .24); }
  .station-body { padding: 12px; }
  .station-weapons-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .station-weapon-card { min-height: 132px; }
  .station-compact-panel .panel-body, .trade-station-panel .panel-body { padding: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .station-pane, .station-weapon-card { animation: none; transition: none; }
  .station-weapon-card:hover { transform: none; }
}
.swc-icon-wrap { position: relative; display: inline-flex; }
.skin-swatch {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid #3a5a9a;
  box-shadow: 0 0 6px 1px rgba(0, 0, 0, 0.4) inset;
}
.swc-name   { font-size: 11px; font-weight: 600; color: #e4ecff; }
.swc-status { font-size: 10px; color: #7f93c2; }

.bank-panel { border-color: #2a7aa0; width: 300px; }
.bank-panel .panel-header { background: rgba(20, 50, 70, 0.9); color: #4ad0ff; }
.bank-tabs { padding: 0 8px; border-bottom: 1px solid #2a5a70; }
.bank-body {
  max-height: 70vh;
  max-height: min(70vh, calc(100dvh - 150px));
  overflow-y: auto;
}
.bank-panel .tab-btn.tab-active { border-bottom-color: #4ad0ff; background: rgba(74, 208, 255, 0.15); }
.bank-sparkline {
  display: block;
  width: 100%;
  height: 50px;
  margin: 8px 0;
  background: rgba(10, 30, 45, 0.6);
  border: 1px solid #2a5a70;
  border-radius: 4px;
}
.bank-qty-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.bank-qty-row input[type="range"] { flex: 1; }
.bank-btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 8px;
}
.bank-btn-row button {
  padding: 8px;
  border: none;
  border-radius: 6px;
  background: #1a5a7a;
  color: #a0e0ff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.bank-btn-row button:hover { background: #2a7aa0; }
.bank-log-list {
  max-height: 90px;
  overflow-y: auto;
  font-size: 11px;
  color: #8ab8d0;
  margin-top: 4px;
}
.bank-log-row { padding: 2px 0; border-bottom: 1px solid rgba(74, 208, 255, 0.1); }
.bank-table-wrap {
  background: rgba(20, 50, 70, 0.35);
  border: 1px solid rgba(74, 208, 255, 0.18);
  border-radius: 6px;
  padding: 2px 10px;
  margin-bottom: 8px;
}
.bank-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.bank-table td { padding: 5px 2px; border-bottom: 1px solid rgba(74, 208, 255, 0.12); }
.bank-table tr:last-child td { border-bottom: none; }
.bank-table tr:nth-child(even) { background: rgba(74, 208, 255, 0.05); }
.bank-table td:first-child { color: #7f93c2; }
.bank-table td:last-child  { color: #a0e0ff; font-weight: 600; text-align: right; }
.bank-table-note { color: #8ab8d0 !important; font-weight: normal !important; text-align: left !important; font-size: 11px; padding-top: 6px !important; }
.bank-visitors-list { display: flex; flex-direction: column; gap: 5px; margin-bottom: 8px; }
.bank-visitor-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(20, 50, 70, 0.5);
  border: 1px solid rgba(74, 208, 255, 0.3);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  color: #a0e0ff;
}
.bank-visitor-label { font-size: 10.5px; color: #6fa8c0; font-style: italic; }

@media (max-width: 480px) {
  .bank-panel { width: min(300px, 92vw); }
  .bank-panel .tab-btn { padding: 7px 10px 8px; font-size: 12.5px; }
  .bank-panel .bank-btn-row button { padding: 11px; }
  /* .build-panel прив'язує панель до низу екрана (bottom:60px) — на
     портреті це потрапляє в зону "Fly here"/SHIP STATUS/підказок, і вони
     лягають поверх контенту банку. Піднімаємо панель вище цієї зони й
     трохи зменшуємо прокручувану область, щоб усе влізло без обрізання. */
  .bank-panel { bottom: 170px; }
  .bank-panel .bank-body { max-height: 50vh; }
}
@media (max-height: 600px) {
  .bank-panel .bank-body { max-height: 60vh; }
}
.build-desc { font-size: 11px; color: #9a8a6a; margin: 6px 0 0; }

/* ---- NPC hover tooltip ---- */
.npc-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(8, 20, 14, 0.93);
  border: 1px solid rgba(80, 180, 100, 0.4);
  border-radius: 7px;
  padding: 9px 13px;
  min-width: 150px;
  max-width: calc(100vw - 24px);
  z-index: 50;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}
.ntt-name {
  font-weight: 700;
  font-size: 12px;
  color: #d0f0d0;
  margin-bottom: 6px;
  letter-spacing: 0.07em;
}
.ntt-head { display: flex; gap: 8px; align-items: flex-start; }
.ntt-head-text { min-width: 0; }
.ntt-portrait {
  width: 128px;
  height: 128px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid rgba(80, 180, 100, 0.5);
}
.ntt-desc {
  margin-top: 7px;
  padding-top: 6px;
  border-top: 1px solid rgba(80, 180, 100, 0.25);
  font-size: 11px;
  font-style: italic;
  color: #9fd0af;
  max-width: 220px;
}

/* ---- Pirate rank badge (портрет-куточок) + текстова позначка тіру ---- */
.portrait-wrap { position: relative; display: inline-block; }
.pirate-dialogue-panel .portrait-wrap,
.loot-panel .portrait-wrap,
#planetDialogueBlock .portrait-wrap {
  display: block;
  width: fit-content;
  margin: 0 auto;
}
.tier-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #05070f;
  border: 1.5px solid #05070f;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
.tier-badge-sm {
  width: 14px;
  height: 14px;
  font-size: 8px;
  border-width: 1px;
  bottom: -1px;
  right: -1px;
}
.tier-label {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #05070f;
  padding: 1px 7px;
  border-radius: 10px;
  margin-bottom: 4px;
}
.cp-meta   { margin-bottom: 4px; display: flex; gap: 8px; align-items: center; }
.cp-id     { font-size: 10px; color: #607090; font-family: monospace; }
.cp-status { font-size: 10px; color: #60c090; font-weight: 600; }

/* ---- Loot hover tooltip ---- */
.loot-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(24, 18, 4, 0.93);
  border: 1px solid rgba(220, 180, 68, 0.4);
  border-radius: 7px;
  padding: 9px 13px;
  min-width: 150px;
  z-index: 50;
  max-width: calc(100vw - 24px);
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}
.ltt-name {
  font-weight: 700;
  font-size: 12px;
  color: #ffe4a0;
  margin-bottom: 6px;
  letter-spacing: 0.07em;
}
.loot-tooltip .ntt-portrait { border-color: rgba(220, 180, 68, 0.5); }
.loot-tooltip .ntt-desc { border-top-color: rgba(220, 180, 68, 0.3); color: #e8c878; }

/* ---- System hover tooltip (Galaxy map) ---- */
.system-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(8, 14, 30, 0.92);
  border: 1px solid rgba(100, 160, 220, 0.4);
  border-radius: 7px;
  padding: 9px 13px;
  min-width: 190px;
  max-width: 260px;
  white-space: normal;
  z-index: 50;
  max-width: calc(100vw - 24px);
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}
.stt-name {
  font-weight: 700;
  font-size: 12px;
  color: #e8f4ff;
  margin-bottom: 6px;
  letter-spacing: 0.07em;
}

/* ---- Item hover tooltip (Inventory grid + Ship Schematic slots) ---- */
.item-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(8, 14, 30, 0.92);
  border: 1px solid rgba(100, 160, 220, 0.4);
  border-radius: 7px;
  padding: 9px 13px;
  max-width: 220px;
  z-index: 200;
  max-width: min(260px, calc(100vw - 24px));
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}
.it-title {
  font-weight: 700;
  font-size: 12px;
  color: #e8f4ff;
  margin-bottom: 4px;
  letter-spacing: 0.05em;
}
.it-desc {
  font-size: 11px;
  color: #b9c8ef;
  line-height: 1.4;
}

.it-stats:not(:empty) {
  margin-top: 6px;
  padding-top: 5px;
  border-top: 1px solid rgba(58, 90, 154, 0.3);
}
.it-stat-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 11px;
  color: #e4ecff;
}
.it-stat-label { color: #7f93c2; }
.it-stat-value { font-weight: 600; }

.station-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(8, 14, 30, 0.92);
  border: 1px solid rgba(100, 160, 220, 0.4);
  border-radius: 7px;
  padding: 9px 13px;
  min-width: 150px;
  z-index: 50;
  max-width: calc(100vw - 24px);
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

/* ---- Planet hover tooltip ---- */
.planet-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(8, 14, 30, 0.92);
  border: 1px solid rgba(100, 160, 220, 0.4);
  border-radius: 7px;
  padding: 9px 13px;
  min-width: 170px;
  z-index: 50;
  max-width: calc(100vw - 24px);
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}
.tooltip-name {
  font-weight: 700;
  font-size: 12px;
  color: #e8f4ff;
  margin-bottom: 6px;
  letter-spacing: 0.07em;
}
.tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: #b9c8ef;
  margin-bottom: 3px;
}
.tooltip-label { color: #7f93c2; }
.tooltip-missions {
  margin-top: 6px;
  padding-top: 5px;
  border-top: 1px solid rgba(58, 90, 154, 0.3);
  font-size: 11px;
}
.tooltip-missions.mission-avail    { color: #6f9dff; }
.tooltip-missions.mission-complete { color: #6cda8c; font-weight: 600; }
.tooltip-missions.mission-none     { color: #4a5a7a; font-style: italic; }

/* ---- Debug panel ---- */
.debug-panel {
  position: absolute;
  bottom: 60px;
  right: 16px;
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid #3a5a9a;
  border-radius: 6px;
  padding: 8px 12px;
  color: #7f93c2;
  font-size: 11px;
  font-family: monospace;
  width: 210px;
  z-index: 100;
  pointer-events: none;
  line-height: 1.6;
}

/* ---- ТИМЧАСОВИЙ debug-інструмент підбору MIN_ZOOM (прибрати разом із index.html/main.js/Game.js) ---- */
.debug-zoom-tool {
  position: absolute;
  top: 16px;
  left: 16px;
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid #3a5a9a;
  border-radius: 6px;
  padding: 8px 12px;
  color: #b9c8ef;
  font-size: 11px;
  font-family: monospace;
  z-index: 100;
  pointer-events: auto;
}

.debug-zoom-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0;
}

.debug-zoom-row label {
  min-width: 100px;
}

.debug-zoom-row input[type="range"] {
  width: 110px;
}

.debug-zoom-row input[type="number"] {
  width: 56px;
  background: #05070f;
  border: 1px solid #3a5a9a;
  color: #e4ecff;
  font-family: monospace;
  font-size: 11px;
  border-radius: 3px;
  padding: 2px 4px;
}

/* ---- Events panel: компактні бейджі, розгортаються по кліку ---- */
/* Позиція — від #topLeftStack; власного absolute немає, інакше панель
   знову вилізла б поверх трекера. Кожна подія — окрема кнопка-піґулка
   (event-badge), а не завжди-розгорнутий текстовий рядок, як раніше —
   тому pointer-events тут, на відміну від старої версії, УВІМКНЕНІ. */
.events-panel {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 100%;
  z-index: 90;
}
.event-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px; /* touch-target — той самий мінімум, що й #backButton/.menu-btn/.hud-warmode тощо в усьому проєкті */
  padding: 5px 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.82);
  border: 1px solid #5a3a9a;
  color: #c8d8ef;
  font: 700 11px/1 ui-monospace, "Cascadia Mono", Consolas, monospace;
  cursor: pointer;
  text-align: left;
  max-width: 240px;
}
.event-badge:hover { border-color: #8a6ac0; }
.event-badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 6px currentColor;
}
.event-badge-detail {
  display: none;
  width: 100%;
  margin-top: 4px;
  font-weight: 400;
  white-space: normal;
  line-height: 1.4;
  color: #b9c8ef;
}
.event-badge.expanded { flex-wrap: wrap; }
.event-badge.expanded .event-badge-detail { display: block; }

/* ---- Pirate Base panel ---- */
.pirate-base-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(620px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  background: rgba(14, 4, 4, 0.97);
  border: 1px solid #8a1a1a;
  border-radius: 10px;
  color: #e4cccc;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
  overflow: hidden;
}
.pirate-base-panel .panel-body { max-height: min(62dvh, 590px); overflow-y: auto; }
.pirate-base-panel .panel-header {
  background: rgba(120, 20, 20, 0.35);
  border-bottom-color: #8a1a1a;
  color: #ff7070;
}
.pirate-base-tabs {
  display: flex;
  gap: 2px;
  padding: 7px 10px 0;
  background: rgba(70, 10, 10, .35);
  border-bottom: 1px solid rgba(180, 55, 45, .35);
}
.pirate-base-tabs button {
  flex: 1;
  min-height: 34px;
  border: 1px solid transparent;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: #dba2a2;
  font: 700 10px/1 ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
}
.pirate-base-tabs button:hover { background: rgba(160, 35, 30, .18); color: #ffe0d8; }
.pirate-base-tabs button.tab-active { border-color: rgba(230, 90, 75, .35); border-bottom-color: #ff7060; background: rgba(130, 25, 20, .34); color: #ffe0d8; }
.pirate-base-hero {
  position: relative;
  display: flex;
  align-items: end;
  height: 104px;
  overflow: hidden;
  border-bottom: 1px solid rgba(180, 55, 45, .35);
  background: radial-gradient(ellipse at 50% 20%, rgba(115, 18, 18, .5), rgba(10, 3, 5, .94) 70%);
}
.pirate-base-hero::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(30, 2, 3, .88), transparent 45%, rgba(30, 2, 3, .76)), repeating-linear-gradient(0deg, transparent 0 4px, rgba(255, 110, 95, .05) 4px 5px);
  pointer-events: none;
}
.pirate-base-hero img {
  position: absolute;
  right: 4%;
  bottom: -57%;
  width: 230px;
  max-width: 52%;
  filter: saturate(.7) sepia(.22) hue-rotate(325deg) drop-shadow(0 0 12px rgba(220, 45, 32, .5));
}
.pirate-base-hero span {
  position: relative;
  z-index: 1;
  padding: 0 12px 10px;
  color: #ffada1;
  font: 700 10px/1 ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: .12em;
}
.pirate-base-readout {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 14px;
  padding: 9px 10px;
  border: 1px solid rgba(182, 58, 48, .35);
  background: rgba(60, 8, 8, .34);
  color: #d9a6a0;
  font-size: 12px;
}
.pirate-base-readout b { color: #ffd0bd; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.pirate-market-note { margin: 0 0 10px; color: #d7a19a; font-size: 12px; font-style: italic; }
.pirate-base-pane .section-title { color: #ff8f80; }
.pirate-market-grid { margin-bottom: 13px; }
.pirate-base-panel .station-weapon-card {
  min-height: 150px;
  border-color: rgba(183, 58, 48, .42);
  background: linear-gradient(155deg, rgba(74, 15, 14, .7), rgba(22, 6, 7, .85));
}
.pirate-base-panel .station-weapon-card:hover { border-color: #ff8575; background: rgba(93, 20, 18, .78); }
.pirate-base-panel .station-weapon-card .btn-build-sm { background: rgba(130, 28, 24, .85); color: #ffe0d8; }
.pirate-base-panel .station-weapon-card .btn-build-sm:hover:not(:disabled) { background: #9f332a; }
@media (min-width: 700px) {
  .pirate-base-panel { width: min(760px, calc(100vw - 32px)); }
  .pirate-base-panel .panel-body { max-height: min(58dvh, 590px); padding: 14px 18px; }
  .pirate-base-hero { height: 122px; }
  .pirate-base-hero img { width: 280px; bottom: -61%; }
  .pirate-market-grid { grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)); }
}
@media (max-width: 480px) {
  .pirate-base-panel { width: min(360px, calc(100vw - 16px)); }
  .pirate-base-panel .panel-body { max-height: calc(100dvh - 252px); }
  .pirate-base-tabs { padding-inline: 6px; }
  .pirate-base-tabs button { font-size: 9px; }
  .pirate-base-hero { height: 78px; }
  .pirate-base-hero img { width: 168px; bottom: -60%; }
  .pirate-base-hero span { padding: 0 8px 7px; font-size: 8px; letter-spacing: .07em; }
  .pirate-base-panel .station-weapon-card { min-height: 126px; padding: 7px 5px; }
  .pirate-market-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
}
@media (max-height: 600px) and (min-width: 481px) {
  .pirate-base-panel { width: min(720px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); }
  .pirate-base-panel .panel-header { min-height: 36px; }
  .pirate-base-tabs { padding-top: 2px; }
  .pirate-base-tabs button { min-height: 30px; }
  .pirate-base-hero { display: none; }
  .pirate-base-panel .panel-body { max-height: calc(100dvh - 124px); padding: 8px 14px; }
  .pirate-base-panel .station-weapon-card { min-height: 112px; padding: 7px 5px; }
  .pirate-market-grid { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 6px; }
  .pirate-market-note { margin-bottom: 6px; }
  .pirate-base-pane .section-title { margin-block: 6px 3px; }
}
.btn-pirate {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 9px;
  border: none;
  border-radius: 6px;
  background: #6a1010;
  color: #ffaaaa;
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: background 0.15s;
}
.btn-pirate:hover:not(:disabled) { background: #8a2020; }
.btn-pirate:disabled { opacity: 0.4; cursor: not-allowed; }
.pirate-close-btn {
  background: #4a1010 !important;
  color: #ff9090 !important;
}
.pirate-close-btn:hover { background: #6a2020 !important; }

/* ---- Ranger HQ panel (структура копіює .pirate-base-panel, без табів, зелена ідентичність Ranger — той самий колір, що й _drawRangerBase на мапі) ---- */
/* flex-column, а не фіксований calc(100dvh - Npx) на .panel-body (як у
   .pirate-base-panel) — з трьома завжди-видимими секціями (Repair+Bounty+Fuel,
   без табів) в цієї панелі об'єктивно більше контенту, ніж у Pirate Base
   (де одночасно видно лише один таб), і фіксований px-бюджет на panel-body
   на вузьких/низьких viewport'ах (320×568) залишав panel-footer (кнопку
   Leave) фізично відрізаною outer-контейнерівським overflow:hidden. Flex
   гарантує header/hero/footer їхній природний розмір, а panel-body
   (flex:1 1 auto; min-height:0) забирає рівно те, що лишилось. */
.ranger-base-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(620px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  background: rgba(4, 14, 4, 0.97);
  border: 1px solid #1a8a1a;
  border-radius: 10px;
  color: #cce4cc;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.ranger-base-panel .panel-header,
.ranger-base-panel .ranger-base-hero,
.ranger-base-panel .panel-footer { flex: 0 0 auto; }
.ranger-base-panel .panel-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 10px 14px; }
.ranger-base-panel .panel-header {
  background: rgba(20, 80, 20, 0.35);
  border-bottom-color: #1a8a1a;
  color: #80ff80;
}
.ranger-base-panel .section-title { color: #80ff80; }
.ranger-base-hero {
  position: relative;
  display: flex;
  align-items: end;
  height: 104px;
  overflow: hidden;
  border-bottom: 1px solid rgba(48, 200, 55, .35);
  background: radial-gradient(ellipse at 50% 20%, rgba(20, 115, 18, .5), rgba(3, 10, 5, .94) 70%);
}
.ranger-base-hero::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(2, 30, 3, .88), transparent 45%, rgba(2, 30, 3, .76)), repeating-linear-gradient(0deg, transparent 0 4px, rgba(110, 255, 95, .05) 4px 5px);
  pointer-events: none;
}
.ranger-base-hero img {
  position: absolute;
  right: 4%;
  bottom: -57%;
  width: 230px;
  max-width: 52%;
  filter: saturate(.7) sepia(.25) hue-rotate(70deg) drop-shadow(0 0 12px rgba(60, 220, 45, .5));
}
.ranger-base-hero span {
  position: relative;
  z-index: 1;
  padding: 0 12px 10px;
  color: #a1ffad;
  font: 700 10px/1 ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: .12em;
}
@media (min-width: 700px) {
  .ranger-base-panel { width: min(760px, calc(100vw - 32px)); }
  .ranger-base-panel .panel-body { padding: 14px 18px; }
  .ranger-base-hero { height: 122px; }
  .ranger-base-hero img { width: 280px; bottom: -61%; }
}
@media (max-width: 480px) {
  .ranger-base-panel { width: min(360px, calc(100vw - 16px)); }
  .ranger-base-hero { height: 78px; }
  .ranger-base-hero img { width: 168px; bottom: -60%; }
  .ranger-base-hero span { padding: 0 8px 7px; font-size: 8px; letter-spacing: .07em; }
}
@media (max-height: 600px) and (min-width: 481px) {
  .ranger-base-panel { width: min(720px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); }
  .ranger-base-panel .panel-header { min-height: 36px; }
  .ranger-base-hero { display: none; }
  .ranger-base-panel .panel-body { padding: 8px 14px; }
}
.btn-ranger {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 9px;
  border: none;
  border-radius: 6px;
  background: #0f5a0f;
  color: #a0ffa0;
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: background 0.15s;
}
.btn-ranger:hover:not(:disabled) { background: #1a7a1a; }
.btn-ranger:disabled { opacity: 0.4; cursor: not-allowed; }
.ranger-close-btn {
  background: #0a4a0a !important;
  color: #90ff90 !important;
}
.ranger-close-btn:hover { background: #1a6a1a !important; }

/* ---- Mining Factory panel (структура копіює .pirate-base-panel, без табів, нейтральна UI-акцентна тема) ---- */
/* flex-column з тієї самої причини, що й .ranger-base-panel вище — panel-body
   забирає рівно те, що лишилось після header/hero/footer, footer завжди
   гарантовано видимий, без крихкого calc(100dvh - Npx)-бюджету. */
.mining-factory-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  background: rgba(5, 9, 18, 0.97);
  border: 1px solid #3a5a9a;
  border-radius: 10px;
  color: #b9c8ef;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.mining-factory-panel .panel-header,
.mining-factory-panel .mining-factory-hero,
.mining-factory-panel .panel-footer { flex: 0 0 auto; }
.mining-factory-panel .panel-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 10px 14px; }
.mining-factory-panel .panel-header {
  background: rgba(20, 40, 90, 0.35);
  border-bottom-color: #3a5a9a;
  color: #6f9dff;
}
.mining-factory-panel .section-title { color: #6f9dff; }
.mining-factory-hero {
  position: relative;
  display: flex;
  align-items: end;
  height: 104px;
  overflow: hidden;
  border-bottom: 1px solid rgba(58, 90, 154, .35);
  background: radial-gradient(ellipse at 50% 20%, rgba(30, 55, 130, .5), rgba(3, 5, 12, .94) 70%);
}
.mining-factory-hero::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(2, 4, 15, .88), transparent 45%, rgba(2, 4, 15, .76)), repeating-linear-gradient(0deg, transparent 0 4px, rgba(111, 157, 255, .05) 4px 5px);
  pointer-events: none;
}
.mining-factory-hero img {
  position: absolute;
  right: 4%;
  bottom: -57%;
  width: 230px;
  max-width: 52%;
  filter: saturate(.7) sepia(.2) hue-rotate(175deg) drop-shadow(0 0 12px rgba(111, 157, 255, .5));
}
.mining-factory-hero span {
  position: relative;
  z-index: 1;
  padding: 0 12px 10px;
  color: #b9c8ef;
  font: 700 10px/1 ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: .12em;
}
@media (min-width: 700px) {
  .mining-factory-panel { width: min(680px, calc(100vw - 32px)); }
  .mining-factory-panel .panel-body { padding: 14px 18px; }
  .mining-factory-hero { height: 122px; }
  .mining-factory-hero img { width: 280px; bottom: -61%; }
}
@media (max-width: 480px) {
  .mining-factory-panel { width: min(360px, calc(100vw - 16px)); }
  .mining-factory-hero { height: 78px; }
  .mining-factory-hero img { width: 168px; bottom: -60%; }
  .mining-factory-hero span { padding: 0 8px 7px; font-size: 8px; letter-spacing: .07em; }
}
@media (max-height: 600px) and (min-width: 481px) {
  .mining-factory-panel { width: min(640px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); }
  .mining-factory-panel .panel-header { min-height: 36px; }
  .mining-factory-hero { display: none; }
  .mining-factory-panel .panel-body { padding: 8px 14px; }
}

/* ---- Loot (wreckage) panel ---- */
.loot-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 300px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  background: rgba(20, 16, 4, 0.97);
  border: 1px solid #8a6a1a;
  border-radius: 10px;
  color: #e4d8b0;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
  overflow: hidden;
}
.loot-panel .panel-header {
  background: rgba(140, 110, 20, 0.35);
  border-bottom-color: #8a6a1a;
  color: #ffcc44;
}
.loot-panel .pirate-portrait { border: 1px solid #8a6a1a; }
.btn-loot {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 9px;
  border: none;
  border-radius: 6px;
  background: #6a5010;
  color: #ffe4a0;
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: background 0.15s;
}
.btn-loot:hover { background: #8a6a20; }
.loot-close-btn {
  background: #4a3a10 !important;
  color: #ffcc80 !important;
}
.loot-close-btn:hover { background: #6a5020 !important; }

/* ---- Pirate Dialogue panel (node-based) — одна генерична панель для
   здирництва (.hostile, червона) і союзу Рейдера (.friendly, синьо-золота),
   тема тоглиться класом у UI.js:openPirateDialogue ---- */
.pirate-dialogue-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 300px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
  overflow: auto;
  z-index: 95;
  /* Дефолт для нейтральних тем (civilianDistress, traderHaggle, minerClaim), які не
     отримують .hostile/.friendly — без цього панель була прозорою (немає фону). */
  background: rgba(8, 12, 24, 0.96);
  border: 1px solid #3a5a9a;
  color: #e4ecff;
}
.pirate-dialogue-panel .panel-body { text-align: center; }

.pirate-dialogue-panel.hostile {
  background: rgba(30, 10, 10, 0.97);
  border: 1px solid #8a1a1a;
  color: #e4cccc;
}
.pirate-dialogue-panel.hostile .panel-header {
  background: rgba(120, 20, 20, 0.35);
  border-bottom-color: #8a1a1a;
  color: #ff7070;
}
.pirate-dialogue-panel.hostile .pirate-portrait { border-color: #8a1a1a; }

.pirate-dialogue-panel.friendly {
  background: rgba(12, 18, 32, 0.97);
  border: 1px solid #c89a3a;
  color: #e4e8f4;
}
.pirate-dialogue-panel.friendly .panel-header {
  background: rgba(58, 90, 154, 0.35);
  border-bottom-color: #c89a3a;
  color: #ffd878;
}
.pirate-dialogue-panel.friendly .pirate-portrait { border-color: #c89a3a; }
.pirate-dialogue-panel.friendly .btn-pirate {
  background: #7a5a10;
  color: #ffe4a0;
}
.pirate-dialogue-panel.friendly .btn-pirate:hover:not(:disabled) { background: #9a7620; }

.pirate-portrait {
  display: block;
  width: 96px;
  height: 96px;
  margin: 0 auto 10px;
  border-radius: 50%;
  object-fit: cover;
  background: rgba(0, 0, 0, 0.3);
}
.planet-dialogue-scene {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #3a5a9a;
  background: rgba(0, 0, 0, 0.3);
  margin: 0 0 10px;
}
.planet-port-scene {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  margin: 0;
  border: none;
  border-radius: 0;
}
.pirate-dialogue-scene {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #8a1a1a;
  background: rgba(0, 0, 0, 0.3);
  margin: 0 0 10px;
}
.pirate-desc {
  font-size: 11px;
  font-style: italic;
  opacity: 0.85;
  margin: -4px 0 10px;
}
#pirateDialogueText {
  margin: 0 0 4px;
  font-size: 13px;
  line-height: 1.4;
}
.dialogue-typing { cursor: pointer; }
.dialogue-typing::after {
  content: '▍';
  display: inline-block;
  margin-left: 2px;
  color: #8fb4ff;
  animation: dialogue-caret 0.8s steps(1, end) infinite;
}
@keyframes dialogue-caret { 50% { opacity: 0; } }
.pirate-dialog-timer {
  font-family: 'Courier New', monospace;
  font-size: 13px;
  font-weight: 700;
  color: #ffcc44;
  letter-spacing: 0;
}
/* Дерево може показати 2-3 варіанти в одній ноді (не лише Agree/Refuse) —
   на відміну від інших .panel-footer-multi, тут wrap потрібен завжди, не лише mobile */
#pirateDialogueChoices.panel-footer-multi { flex-wrap: wrap; }
#pirateDialogueChoices button { min-width: 40%; }

/* Retro terminal dialogue shell: every visual transition uses clipping, opacity,
   and translation only, so the panel never scales or shifts the surrounding UI. */
.dialogue-terminal {
  --dialogue-accent: #b8fff2;
  --dialogue-alert: #e45a4f;
  --dialogue-surface: rgba(8, 16, 17, .98);
  position: relative;
  border: 2px solid var(--dialogue-accent);
  border-radius: 0;
  clip-path: polygon(0 16px, 16px 0, calc(100% - 16px) 0, 100% 16px, 100% calc(100% - 16px), calc(100% - 16px) 100%, 16px 100%, 0 calc(100% - 16px));
  background: var(--dialogue-surface);
  color: var(--dialogue-accent);
  box-shadow: 0 0 18px color-mix(in srgb, var(--dialogue-accent) 22%, transparent), inset 0 0 28px rgba(0, 0, 0, .35);
}
.pirate-dialogue-panel.dialogue-terminal { overflow: hidden; }
.dialogue-terminal::before,
.dialogue-terminal::after {
  content: '';
  position: absolute;
  pointer-events: none;
  z-index: 2;
}
.dialogue-terminal::before {
  top: 0; left: 18px; right: 18px; height: 4px;
  background: var(--dialogue-alert);
  opacity: .85;
}
.dialogue-terminal::after {
  left: 16px; right: 16px; bottom: 8px; height: 1px;
  background: repeating-linear-gradient(90deg, var(--dialogue-alert) 0 8px, transparent 8px 14px);
  opacity: .78;
  animation: dialogue-service-line 2.1s linear infinite;
}
.dialogue-terminal-header {
  position: relative;
  min-height: 34px;
  padding: 9px 16px 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--dialogue-accent) 45%, transparent);
  background: rgba(17, 31, 31, .95);
  color: var(--dialogue-accent);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .11em;
  text-transform: uppercase;
}
.dialogue-terminal-status {
  float: right;
  color: var(--dialogue-alert);
  font-size: 9px;
  letter-spacing: .14em;
}
.dialogue-terminal .panel-body {
  min-height: 0;
  overflow-y: auto;
  scrollbar-color: var(--dialogue-accent) rgba(0, 0, 0, .35);
}
.dialogue-terminal .portrait-wrap:has(img[style*="display: none"]),
.dialogue-terminal.dialogue-no-media .portrait-wrap { display: none; }
.dialogue-terminal.dialogue-no-media .pirate-dialogue-scene,
.dialogue-terminal.dialogue-no-media .planet-dialogue-scene { display: none !important; }
.dialogue-terminal .pirate-portrait {
  border: 1px solid var(--dialogue-accent);
  border-radius: 0;
  clip-path: polygon(0 9px, 9px 0, calc(100% - 9px) 0, 100% 9px, 100% calc(100% - 9px), calc(100% - 9px) 100%, 9px 100%, 0 calc(100% - 9px));
}
.dialogue-terminal .pirate-dialogue-scene,
.dialogue-terminal .planet-dialogue-scene {
  border-color: color-mix(in srgb, var(--dialogue-accent) 65%, transparent);
  border-radius: 0;
  clip-path: polygon(0 8px, 8px 0, calc(100% - 8px) 0, 100% 8px, 100% calc(100% - 8px), calc(100% - 8px) 100%, 8px 100%, 0 calc(100% - 8px));
}
.dialogue-terminal #pirateDialogueText,
.dialogue-terminal #planetDialogueText {
  max-height: min(23dvh, 176px);
  margin: 10px 4px 4px;
  padding: 10px;
  overflow-y: auto;
  border: 1px solid color-mix(in srgb, var(--dialogue-accent) 40%, transparent);
  background: rgba(2, 9, 10, .72);
  color: var(--dialogue-accent);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  letter-spacing: .035em;
  line-height: 1.55;
  text-align: left;
  scrollbar-color: var(--dialogue-accent) rgba(0, 0, 0, .35);
}
.dialogue-terminal-planet { margin: 8px 0 12px; padding: 0 10px 16px; }
.dialogue-terminal-planet .dialogue-terminal-header { margin: 0 -10px 8px; }
.dialogue-skip-hint {
  padding: 5px 10px 8px;
  color: color-mix(in srgb, var(--dialogue-accent) 68%, transparent);
  font: 700 9px/1.2 ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: .1em;
  text-align: left;
}
.dialogue-terminal .panel-footer,
#planetDialogueChoices.panel-footer-multi {
  position: relative;
  z-index: 3;
  padding: 10px 16px 18px;
  border-top: 1px solid color-mix(in srgb, var(--dialogue-accent) 30%, transparent);
  background: rgba(4, 12, 13, .96);
}
.dialogue-terminal .panel-footer button,
#planetDialogueChoices.panel-footer-multi button {
  min-height: 38px;
  border: 1px solid color-mix(in srgb, var(--dialogue-accent) 72%, transparent) !important;
  border-radius: 0;
  clip-path: polygon(0 6px, 6px 0, calc(100% - 6px) 0, 100% 6px, 100% calc(100% - 6px), calc(100% - 6px) 100%, 6px 100%, 0 calc(100% - 6px));
  background: rgba(22, 42, 42, .96) !important;
  color: var(--dialogue-accent) !important;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
}
.dialogue-terminal .panel-footer button:first-child,
#planetDialogueChoices.panel-footer-multi button:first-child {
  background: var(--dialogue-accent) !important;
  color: #071011 !important;
}
.dialogue-terminal .panel-footer button:hover:not(:disabled),
#planetDialogueChoices.panel-footer-multi button:hover:not(:disabled) {
  background: color-mix(in srgb, var(--dialogue-accent) 26%, #111b1b) !important;
  box-shadow: 0 0 12px color-mix(in srgb, var(--dialogue-accent) 45%, transparent);
}
.dialogue-terminal .panel-footer button:first-child:hover:not(:disabled),
#planetDialogueChoices.panel-footer-multi button:first-child:hover:not(:disabled) { background: #e4fff8 !important; }
.dialogue-terminal button:focus-visible,
.dialogue-typing:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.pirate-dialogue-panel.hostile { --dialogue-accent: #ff8f86; --dialogue-alert: #e45a4f; --dialogue-surface: rgba(28, 10, 10, .98); }
.pirate-dialogue-panel.friendly { --dialogue-accent: #ffe09a; --dialogue-alert: #e6a84f; --dialogue-surface: rgba(22, 18, 10, .98); }
.dialogue-terminal-planet { --dialogue-accent: #b8fff2; --dialogue-alert: #e45a4f; }
#planetDialogueChoices { --dialogue-accent: #b8fff2; --dialogue-alert: #e45a4f; }
.dialogue-typing::after { color: var(--dialogue-accent); }
.dialogue-opening .dialogue-terminal-header { animation: dialogue-header-arrive .24s ease-out both; }
.dialogue-opening .panel-body > *,
.dialogue-opening > .planet-dialogue-scene,
.dialogue-opening > .portrait-wrap,
.dialogue-opening > #planetDialogueText { opacity: 0; }
.dialogue-opening::before { animation: dialogue-outline-arrive .34s ease-out both; }
.dialogue-opening::after { opacity: 0; }
.dialogue-ready .panel-body > *,
.dialogue-ready > .planet-dialogue-scene,
.dialogue-ready > .portrait-wrap,
.dialogue-ready > #planetDialogueText { animation: dialogue-content-arrive .16s steps(3, end) both; }
@keyframes dialogue-header-arrive { from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes dialogue-outline-arrive { from { transform: translateX(-100%); } to { transform: translateX(0); } }
@keyframes dialogue-content-arrive { from { clip-path: inset(0 100% 0 0); opacity: 0; } to { clip-path: inset(0 0 0 0); opacity: 1; } }
@keyframes dialogue-service-line { to { background-position: -56px 0; } }
@media (prefers-reduced-motion: reduce) {
  .dialogue-terminal::after,
  .dialogue-typing::after { animation: none; }
  .dialogue-opening .dialogue-terminal-header,
  .dialogue-opening::before { animation: none; }
}
.loot-row {
  justify-content: flex-start;
  gap: 8px;
}
.loot-row .label { flex: 0 0 78px; }
.loot-slider { flex: 1; accent-color: #c89020; }
.loot-amt { flex: 0 0 56px; text-align: right; }

/* ---- Galaxy Stats panel ---- */
.galaxy-stats {
  --gs-content-scale: 1;
  position: absolute;
  left: var(--cockpit-safe-x);
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - var(--hud-bottom, 60px) - 32px);
  color: var(--cockpit-text);
  font-size: 11px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  background: var(--cockpit-glass-surface);
  border: 1px solid var(--cockpit-edge);
  border-radius: var(--cockpit-radius);
  z-index: 85;
  overflow: hidden;
  box-shadow: inset 0 1px rgba(218, 245, 252, .12), inset 0 -16px 30px rgba(0, 3, 10, .28), 0 0 18px var(--cockpit-glow), 0 12px 34px rgba(0, 0, 0, .52);
  isolation: isolate;
}
.galaxy-stats::before,
.galaxy-stats::after {
  content: "";
  position: absolute;
  z-index: 3;
  top: 7px;
  bottom: 7px;
  width: 38px;
  border-top: 2px solid var(--cockpit-edge-bright);
  border-bottom: 2px solid var(--cockpit-edge-bright);
  filter: drop-shadow(0 0 6px var(--cockpit-glow));
  pointer-events: none;
}
.galaxy-stats::before { left: 7px; border-left: 2px solid var(--cockpit-edge-bright); }
.galaxy-stats::after { right: 7px; border-right: 2px solid var(--cockpit-edge-bright); }

.gs-header {
  position: relative;
  z-index: 4;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex: 0 0 auto;
  min-height: 58px;
  gap: 12px;
  padding: 7px 8px 7px 14px;
  background: linear-gradient(90deg, rgba(24, 75, 94, .34), rgba(4, 15, 27, .48));
  border-bottom: 1px solid rgba(79, 178, 211, .34);
}
.gs-heading { min-width: 0; }
.gs-heading h2 {
  margin: 2px 0 0;
  overflow: hidden;
  color: var(--cockpit-text);
  font-size: 13px;
  line-height: 1.1;
  letter-spacing: .16em;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gs-eyebrow {
  display: block;
  color: var(--cockpit-edge-bright);
  font-size: 8px;
  letter-spacing: .12em;
  opacity: .72;
}

.gs-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 1px solid rgba(79, 178, 211, .36);
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  color: var(--cockpit-muted);
  cursor: default;
  user-select: none;
}

.gs-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}

.gs-zoom-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  background: rgba(4, 15, 27, .62);
  border: 1px solid rgba(79, 178, 211, .34);
  border-radius: 3px;
  color: var(--cockpit-text);
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
  pointer-events: auto;
}
.gs-zoom-btn:hover:not(:disabled) {
  background: var(--cockpit-surface-hover);
  border-color: var(--cockpit-edge-bright);
  color: #effcff;
}
.gs-zoom-btn:focus-visible { outline: 2px solid var(--cockpit-edge-bright); outline-offset: -3px; }
.gs-zoom-btn:disabled { opacity: .34; cursor: default; }

.gs-body {
  position: relative;
  z-index: 2;
  min-height: 0;
  padding: 10px;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-color: var(--cockpit-edge) rgba(2, 10, 20, .55);
  overscroll-behavior: contain;
}
.gs-body > * { font-size: calc(11px * var(--gs-content-scale)); }
.gs-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.gs-card {
  min-width: 0;
  overflow: hidden;
  background: rgba(3, 13, 25, .48);
  border: 1px solid rgba(79, 178, 211, .22);
  border-radius: 3px;
}
.gs-card dl { margin: 0; }
.gs-card-fleet { grid-row: span 2; }
.gs-card-galaxy { grid-row: span 2; }

.gs-section {
  margin: 0;
  padding: 7px 9px 5px;
  font-size: .82em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--cockpit-edge-bright);
  background: rgba(28, 83, 101, .16);
  border-bottom: 1px solid rgba(79, 178, 211, .16);
}

.gs-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  min-width: 0;
  padding: 4px 9px;
  line-height: 1.45;
  gap: 8px;
}
.gs-row dd { min-width: 0; max-width: 100%; margin: 0 0 0 auto; color: var(--cockpit-text); text-align: right; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.gs-session { margin-bottom: 8px; padding: 7px 10px; background: rgba(24, 75, 94, .18); border: 1px solid rgba(79, 178, 211, .2); border-radius: 3px; }

.gs-label {
  color: var(--cockpit-muted);
  flex-shrink: 0;
  min-width: 68px;
}

.gs-total-row { border-top: 1px solid rgba(79, 178, 211, .16); border-bottom: 1px solid rgba(79, 178, 211, .16); }
.gs-total-row .gs-label { color: var(--cockpit-text); }
.gs-total-row dd { color: #ffffff; font-weight: 700; }

.gs-trader-row .gs-label { color: #a89050; }
.gs-trader-row dd { color: #f0d060; }

.gs-civilian-row .gs-label { color: #4a7aa0; }
.gs-civilian-row dd { color: #70b0f0; }

.gs-miner-row .gs-label { color: #8a6a40; }
.gs-miner-row dd { color: #c89050; }

.gs-pirate-row .gs-label { color: #9a4a4a; }
.gs-pirate-row dd { color: #f07070; }

.gs-ranger-row .gs-label { color: #4a8a4a; }
.gs-ranger-row dd { color: #80ff80; }

.gs-stalker-row .gs-label { color: #7a4a9a; }
.gs-stalker-row dd { color: #c080ff; }

.gs-timer {
  font-size: 1.18em;
  font-weight: 700;
  color: #aee8f7;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.gs-open-btn {
  position: absolute;
  bottom: 16px;
  left: 16px;
  z-index: 85;
  background: rgba(4, 7, 18, 0.93);
  border: 1px solid rgba(50, 100, 180, 0.45);
  border-radius: 6px;
  color: #6ab0f0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 6px 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.gs-open-btn:hover { background: rgba(20, 50, 110, 0.5); color: #cfe0ff; }
.galaxy-stats-open #backButton,
.galaxy-stats-open #topLeftStack { visibility: hidden; pointer-events: none; }

@media (max-width: 560px) {
  .galaxy-stats {
    top: calc(var(--hud-bottom, 125px) + 8px);
    left: max(8px, env(safe-area-inset-left));
    bottom: calc(max(8px, env(safe-area-inset-bottom)) + 108px);
    width: calc(100vw - 68px - env(safe-area-inset-left) - env(safe-area-inset-right));
    max-height: none;
  }
  .gs-grid { grid-template-columns: minmax(0, 1fr); }
  .gs-card-fleet, .gs-card-galaxy { grid-row: auto; }
}

@media (max-width: 360px) {
  .gs-header { gap: 6px; padding-left: 10px; }
  .gs-eyebrow { display: none; }
  .gs-heading h2 { font-size: 10px; letter-spacing: .04em; }
  .gs-key { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .galaxy-stats, .galaxy-stats * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

.toggle-ui-btn {
  position: fixed;
  top: var(--cockpit-safe-y);
  right: max(16px, env(safe-area-inset-right));
  z-index: 90;
  min-width: 44px;
  min-height: 44px;
  background: linear-gradient(145deg, rgba(14, 37, 52, .92), var(--cockpit-surface));
  border: 1px solid var(--cockpit-edge);
  border-radius: var(--cockpit-radius);
  color: var(--cockpit-text);
  font-size: 16px;
  padding: 6px 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  box-shadow: inset 0 1px rgba(218, 245, 252, .08), 0 0 11px var(--cockpit-glow);
}
.toggle-ui-btn:hover { background: var(--cockpit-surface-hover); color: #effcff; border-color: var(--cockpit-edge-bright); }
.toggle-ui-btn:active { transform: translateY(1px); }
.toggle-ui-btn:focus-visible { outline: 2px solid var(--cockpit-edge-bright); outline-offset: 2px; }
.docking-modal-open .toggle-ui-btn { z-index: 70; pointer-events: none; opacity: .35; }
.docking-modal-open .sp-open-btn,
.docking-modal-open #backButton,
.docking-modal-open .gs-open-btn { visibility: hidden; pointer-events: none; }

/* Medium-width tablets need bounded HUD/dialogs, but should not use the
   cramped phone layout. */
@media (min-width: 481px) and (max-width: 800px) {
  #hud { max-width: calc(100vw - 32px); }
  #planetPanel, #tradePanel, #npcTradePanel, #stationPanel,
  #helpPanel, #sectorBaronPanel, .missions-panel,
  .pirate-base-panel, .loot-panel, .pirate-dialogue-panel {
    max-width: calc(100vw - 24px);
  }
  .side-panel { width: min(360px, calc(100vw - 24px)); }
}

@media (max-width: 480px) {
  .gs-open-btn  { padding: 9px 12px; font-size: 12px; }
}
@media (max-height: 600px) and (min-width: 561px) {
  .galaxy-stats { max-height: min(60dvh, calc(100dvh - var(--hud-bottom, 60px) - 24px)); }
}

/* ---- Qty slider row (Trade + Refinery) ---- */
.trade-qty-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 12px;
  color: #b9c8ef;
}
.trade-qty-row input[type="range"] {
  flex: 1;
  accent-color: #6f9dff;
  cursor: pointer;
}

/* ---- Player Stats Widget ---- */
.player-stats {
  position: absolute;
  bottom: calc(16px + env(safe-area-inset-bottom));
  right: 16px;
  background: rgba(8, 14, 30, 0.88);
  border: 1px solid #2a4a7a;
  border-radius: 6px;
  padding: 8px 10px;
  min-width: 180px;
  max-width: calc(100vw - 24px);
  font-family: monospace;
  font-size: 11px;
  color: #a0b8d8;
  pointer-events: none;
  z-index: 10;
}
.ps-title {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: #5080b0;
  margin-bottom: 6px;
}
.ps-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.ps-label { width: 16px; color: #6080a8; }
.ps-value { width: 52px; text-align: right; color: #a0b8d8; }
.ps-bar-track {
  flex: 1;
  height: 6px;
  background: #1a2a4a;
  border-radius: 3px;
  overflow: hidden;
}
.ps-bar-fill {
  height: 100%;
  width: 100%;
  border-radius: 3px;
  transition: width 0.15s ease, background-color 0.3s ease;
}
.ps-hp { background: #70e080; }
.ps-ar { background: #6090e0; }
.ps-speed {
  margin-top: 4px;
  font-size: 10px;
  color: #7090c0;
  text-align: center;
  letter-spacing: 0.04em;
}

@media (max-height: 600px) {
  /* Той самий випадок, що й #hud — ландшафтний мобільний екран: панель
     перекриває назви сусідніх систем у правому нижньому куті, стискаємо. */
  .player-stats { padding: 5px 8px; min-width: 140px; font-size: 10px; }
  .ps-title { margin-bottom: 3px; }
  .ps-row   { margin-bottom: 2px; }
  .ps-value { width: 44px; }
}

/* ---- Move Panel ---- */
.move-panel {
  position: absolute;
  bottom: calc(60px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(8, 20, 40, 0.92);
  border: 1px solid #2a7a9a;
  border-radius: 6px;
  padding: 7px 12px;
  font-family: monospace;
  font-size: 11px;
  color: #80d0f0;
  z-index: 10;
  max-width: calc(100vw - 24px);
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.mp-label { color: #60c0e0; letter-spacing: 0.05em; }
.mp-fuel  { color: #70c0ff; font-size: 12px; margin-top: 2px; }
.mp-actions { display: flex; gap: 6px; }
.btn-go {
  background: #0a4060;
  color: #80e0ff;
  border: 1px solid #2090c0;
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
  font-family: monospace;
  font-size: 11px;
  transition: background 0.1s;
}
.btn-go:hover { background: #1060a0; }
.mp-cancel {
  background: transparent;
  color: #406080;
  border: 1px solid #204050;
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  font-family: monospace;
  font-size: 11px;
}
.mp-cancel:hover { color: #60a0c0; border-color: #406080; }

@media (max-height: 600px) {
  /* Ландшафт: ширини тут вистачає, щоб відцентрована панель не
     дотягувалась до SHIP STATUS праворуч — опускаємо на той самий
     рівень, що й STATS/SHIP STATUS знизу. */
  .move-panel { bottom: calc(16px + env(safe-area-inset-bottom)); }
}
@media (max-width: 480px) {
  /* Портрет: вузька ширина — відцентрована панель дотягується до SHIP
     STATUS праворуч. Піднімаємо й обмежуємо ширину, щоб фізично не
     могла туди дотягнутись. */
  .move-panel { bottom: calc(140px + env(safe-area-inset-bottom)); max-width: 55vw; }
}

/* ---- Combat Panel ---- */
.combat-panel {
  position: absolute;
  bottom: calc(120px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30, 8, 8, 0.92);
  border: 1px solid #7a2a2a;
  border-radius: 6px;
  padding: 8px 12px;
  min-width: 200px;
  max-width: calc(100vw - 24px);
  font-family: monospace;
  font-size: 11px;
  color: #d0a8a8;
  z-index: 10;
  pointer-events: auto;
}
.cp-title {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: #804040;
  margin-bottom: 2px;
}
.cp-name {
  color: #e08080;
  font-weight: bold;
  margin-bottom: 6px;
}
.cp-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.btn-attack {
  flex: 1;
  background: #7a1a1a;
  color: #ffc0c0;
  border: 1px solid #c04040;
  border-radius: 4px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 11px;
  font-family: monospace;
  transition: background 0.1s;
}
.btn-attack:hover:not(:disabled) { background: #9a2a2a; }
.btn-attack:disabled { opacity: 0.4; cursor: default; }
.btn-torpedo {
  background: #7a4a1a;
  color: #ffd8a0;
  border-color: #c08040;
}
.btn-torpedo:hover:not(:disabled) { background: #9a5f22; }
.cp-cancel {
  background: transparent;
  color: #804040;
  border: 1px solid #5a2a2a;
  border-radius: 4px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 11px;
  font-family: monospace;
}
.cp-cancel:hover { color: #c06060; border-color: #804040; }

@media (max-height: 600px) {
  /* Ландшафтний мобільний екран: бойова панель по центру завелика й
     заходить надто високо, перекриваючи майже весь ігровий вигляд —
     опускаємо ближче до низу й стискаємо. */
  .combat-panel {
    bottom: calc(16px + env(safe-area-inset-bottom));
    padding: 6px 9px;
    min-width: 170px;
    max-width: 70vw;
    font-size: 10px;
  }
  .cp-actions { gap: 5px; margin-top: 5px; }
  .btn-attack, .btn-trade, .cp-cancel { padding: 4px 6px; font-size: 10px; }
}
@media (max-width: 480px) {
  /* Портрет: та сама бойова панель по центру опиняється вище SHIP STATUS —
     опускаємо на той самий рівень і звужуємо під вузьку ширину. */
  .combat-panel {
    bottom: calc(16px + env(safe-area-inset-bottom));
    padding: 6px 9px;
    width: 180px;
    font-size: 10px;
  }
  .cp-actions { gap: 5px; margin-top: 5px; flex-wrap: wrap; }
  .btn-attack, .btn-trade, .cp-cancel { padding: 4px 6px; font-size: 10px; }
}

/* ---- Alert Widget ---- */
.alert-widget {
  position: fixed; /* див. коментар у #missionAlert */
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(120, 10, 10, 0.92);
  border: 1.5px solid #e03030;
  border-radius: 6px;
  padding: 8px 20px;
  max-width: min(620px, calc(100vw - 24px));
  white-space: normal;
  text-align: center;
  font-family: monospace;
  font-size: 13px;
  color: #ffb0b0;
  letter-spacing: 0.1em;
  pointer-events: none;
  z-index: 20;
  animation: alertPulse 0.5s ease-in-out infinite alternate;
}
.alert-icon { margin-right: 8px; }
@media (max-width: 480px) {
  /* Обидва алерти живуть у #topLeftStack. На вузьких/низьких екранах вони просто
     стають у чергу: центрований блок ~195px не влазить між лівою колонкою і
     кнопками праворуч (вільна смуга ~66px на 390px).
     ВАЖЛИВО: це правило мусить стояти ПІСЛЯ базових #missionAlert і .alert-widget —
     специфічність однакова, тож інакше базове position:fixed перебиває його. */
  #missionAlert, .alert-widget {
    position: static;
    transform: none;
    width: 100%;
    max-width: none;
    white-space: normal;
    text-align: center;
  }
}

@media (max-height: 600px) {
  /* Обидва алерти живуть у #topLeftStack. На вузьких/низьких екранах вони просто
     стають у чергу: центрований блок ~195px не влазить між лівою колонкою і
     кнопками праворуч (вільна смуга ~66px на 390px).
     ВАЖЛИВО: це правило мусить стояти ПІСЛЯ базових #missionAlert і .alert-widget —
     специфічність однакова, тож інакше базове position:fixed перебиває його. */
  #missionAlert, .alert-widget {
    position: static;
    transform: none;
    width: 100%;
    max-width: none;
    white-space: normal;
    text-align: center;
  }
}
@keyframes alertPulse {
  from { border-color: #e03030; box-shadow: 0 0 4px #a02020; }
  to   { border-color: #ff6060; box-shadow: 0 0 14px #e04040; }
}

@media (max-width: 480px) {
  /* Портретний вигляд: базовий top:70px лягає прямо на згорнутий HUD
     (переноситься у 3 рядки, до ~111px) — опускаємо нижче нього; #missionAlert
     стоїть ще нижче (свій override у секції "Mission arrival toast"). */
  /* .alert-widget тепер у стеку — див. правило поряд із #missionAlert вище. */
}

/* ---- NPC trade: кнопка в combat-панелі ---- */
.btn-trade {
  flex: 1;
  background: #1a5a2a;
  color: #a0ffa0;
  border: 1px solid #2f9a4a;
  border-radius: 4px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 11px;
  font-family: monospace;
  transition: background 0.1s;
}
.btn-trade:hover:not(:disabled) { background: #2a7a3a; }
.btn-trade:disabled { opacity: 0.4; cursor: default; }

/* ---- NPC trade panel ---- */
.npt-id-row {
  font-family: monospace;
  font-size: 10px;
  color: #6a8aa8;
  letter-spacing: 1px;
  margin-bottom: 6px;
}
#npcTradePanel .npt-npc-credits { color: #ffd060; }
#npcTradePanel .npt-stock       { color: #80c0ff; }
.npt-table th, .npt-table td { padding: 3px 4px; font-size: 11px; }

/* ---- Controls manual (#helpPanel) ---- */
.help-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(58, 90, 154, 0.15);
}
.help-row:last-child { border-bottom: none; }
.help-row .hud-key { flex-shrink: 0; width: auto; min-width: 20px; padding: 0 5px; }
.help-row .label { color: #b9c8ef; font-size: 13px; }

/* ---- Main Menu / Pause (#mainMenu) ---- */
.menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 7, 15, 0.92);
}

/* До старту гри позаду ще немає живого кадру — лише статичний
   плейсхолдер-розмітки HUD, тому оверлей тут суцільний, без
   просвічування (на паузі ж просвічує реальний застиглий кадр гри). */
.menu-overlay.menu-boot {
  background: #05070f;
}

.menu-box {
  width: 320px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  background: rgba(8, 12, 24, 0.96);
  border: 1px solid #3a5a9a;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  color: #e4ecff;
  padding: 24px 20px;
  text-align: center;
}

.menu-title {
  margin: 0 0 20px;
  font-size: 22px;
  letter-spacing: 0.14em;
  color: #cfe0ff;
  text-shadow: 0 0 12px rgba(111, 157, 255, 0.5);
}

.menu-subtitle {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #6f9dff;
  margin-bottom: 12px;
}

.menu-note {
  color: #7f93c2;
  font-size: 12px;
  margin: 0 0 14px;
}

.menu-setting {
  padding: 10px 12px 12px;
  border: 1px solid rgba(58, 90, 154, 0.55);
  border-radius: 8px;
  background: rgba(20, 31, 62, 0.45);
  text-align: left;
}

.menu-setting-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #cfe0ff;
  font-size: 13px;
}

.menu-setting-header output {
  color: #7fc4ff;
  font-variant-numeric: tabular-nums;
}

.menu-volume {
  width: 100%;
  margin-top: 10px;
  accent-color: #6f9dff;
  cursor: pointer;
}

.menu-setting-checkbox {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #cfe0ff;
  font-size: 13px;
  margin-bottom: 14px;
}

.menu-setting-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #6f9dff;
  cursor: pointer;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.menu-btn {
  padding: 10px 14px;
  background: rgba(58, 90, 154, 0.25);
  border: 1px solid #3a5a9a;
  border-radius: 8px;
  color: #e4ecff;
  font-size: 14px;
  letter-spacing: 0.04em;
  cursor: pointer;
}
.menu-btn:hover:not(:disabled) { background: rgba(58, 90, 154, 0.45); }
.menu-btn:disabled { opacity: 0.4; cursor: default; }

.menu-btn-danger {
  border-color: #a05050;
  color: #ff8a8a;
}
.menu-btn-danger:hover:not(:disabled) { background: rgba(140, 40, 40, 0.3); }

.menu-slot-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 6px;
}

.menu-slot-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(20, 30, 60, 0.55);
  border: 1px solid rgba(58, 90, 154, 0.5);
  border-radius: 8px;
  text-align: left;
}

.menu-slot-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.menu-slot-info strong { font-size: 13px; color: #cfe0ff; }
.menu-slot-info span { font-size: 11px; color: #7f93c2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.menu-slot-action {
  flex-shrink: 0;
  width: auto;
  padding: 6px 12px;
  font-size: 12px;
}

/* ---- Cinematic boot menu ---- */
.menu-hero {
  display: none;
  position: relative;
  width: min(58vw, 650px);
  height: min(78vh, 620px);
  min-height: 420px;
  overflow: hidden;
  border: 1px solid rgba(58, 90, 154, 0.5);
  border-right: 0;
  border-radius: 14px 0 0 14px;
  background:
    radial-gradient(circle at 55% 45%, rgba(59, 92, 170, 0.2), transparent 34%),
    linear-gradient(145deg, #0d1830 0%, #070b18 55%, #05070f 100%);
  box-shadow: inset 0 0 70px rgba(39, 76, 150, 0.16), 0 10px 40px rgba(0, 0, 0, 0.55);
}

.menu-stars,
.menu-stars::before,
.menu-stars::after {
  position: absolute;
  inset: 0;
  content: "";
  background-image:
    radial-gradient(circle, rgba(220, 235, 255, .8) 0 1px, transparent 1.5px),
    radial-gradient(circle, rgba(130, 175, 255, .55) 0 1px, transparent 1.5px);
  background-size: 97px 113px, 151px 139px;
  background-position: 12px 28px, 64px 8px;
  opacity: .48;
}
.menu-stars::before { transform: translate(37px, 51px); opacity: .32; }
.menu-stars::after { transform: translate(-22px, 12px); opacity: .22; animation: menu-stars-drift 18s linear infinite; }

.menu-nebula {
  position: absolute;
  width: 70%;
  height: 55%;
  border-radius: 50%;
  filter: blur(32px);
  opacity: .22;
  pointer-events: none;
}
.menu-nebula-one { top: 8%; left: 4%; background: #274dba; transform: rotate(-20deg); }
.menu-nebula-two { right: -15%; bottom: 3%; background: #148f9f; transform: rotate(25deg); opacity: .13; }

.menu-station-art {
  position: absolute;
  width: min(66%, 430px);
  aspect-ratio: 1;
  object-fit: contain;
  left: 4%;
  top: 7%;
  opacity: .8;
  filter: drop-shadow(0 0 22px rgba(113, 181, 255, .34));
  transform: rotate(-11deg);
}
.menu-ship-art {
  position: absolute;
  width: min(30%, 190px);
  aspect-ratio: 1;
  object-fit: contain;
  right: 12%;
  bottom: 17%;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 16px rgba(117, 229, 255, .55));
  transform: rotate(18deg);
  animation: menu-ship-hover 5s ease-in-out infinite;
}
.menu-orbit-ring {
  position: absolute;
  width: 64%;
  aspect-ratio: 2.7;
  left: 19%;
  bottom: 19%;
  border: 1px solid rgba(111, 157, 255, .36);
  border-radius: 50%;
  transform: rotate(-19deg);
  box-shadow: 0 0 18px rgba(81, 167, 255, .14);
}
.menu-hero-label {
  position: absolute;
  left: 24px;
  bottom: 22px;
  color: rgba(159, 191, 255, .72);
  font: 700 10px/1.2 monospace;
  letter-spacing: .16em;
}

@keyframes menu-ship-hover {
  0%, 100% { transform: translateY(0) rotate(18deg); }
  50% { transform: translateY(-9px) rotate(15deg); }
}
@keyframes menu-stars-drift {
  from { transform: translate(-22px, 12px); }
  to { transform: translate(18px, -12px); }
}

.menu-overlay.menu-boot {
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 24px;
  background: #05070f;
}
.menu-overlay.menu-boot .menu-hero { display: block; }
.menu-overlay:not(.menu-boot) .menu-tagline,
.menu-overlay:not(.menu-boot) .menu-description,
.menu-overlay:not(.menu-boot) .menu-last-flight { display: none; }
.menu-overlay.menu-boot .menu-box {
  width: min(360px, 34vw);
  height: min(78vh, 620px);
  max-width: none;
  max-height: none;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 34px 30px;
  border-radius: 0 14px 14px 0;
  border-left-color: rgba(111, 157, 255, .5);
  box-shadow: 10px 10px 40px rgba(0, 0, 0, .6);
}
.menu-tagline {
  margin: -12px 0 12px;
  color: #7fc4ff;
  font: 700 10px/1.2 monospace;
  letter-spacing: .2em;
}
.menu-tagline span { color: #4ad0ff; padding: 0 5px; }
.menu-description {
  margin: 0 auto 24px;
  max-width: 260px;
  color: #8098c0;
  font-size: 12px;
  line-height: 1.45;
}
.menu-last-flight {
  margin: -2px 0 12px;
  padding: 10px 12px;
  border: 1px solid rgba(58, 90, 154, .58);
  border-radius: 8px;
  background: rgba(20, 31, 62, .4);
  text-align: left;
}
.menu-last-flight.has-save { border-color: rgba(74, 208, 255, .58); background: rgba(18, 49, 70, .32); }
.menu-last-flight-label { color: #6f9dff; font: 700 10px/1.2 monospace; letter-spacing: .12em; }
.menu-last-flight-status { margin-top: 5px; overflow: hidden; color: #d8e5ff; font-size: 12px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.menu-last-flight-meta { margin-top: 3px; overflow: hidden; color: #7f93c2; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.menu-overlay.menu-boot #mmNewGame { border-color: #6f9dff; background: rgba(70, 108, 190, .42); box-shadow: 0 0 16px rgba(111, 157, 255, .16); }
.menu-overlay.menu-boot #mmNewGame:hover { background: rgba(86, 130, 220, .6); }

@media (max-width: 800px) {
  .menu-overlay.menu-boot { padding: 16px; }
  .menu-overlay.menu-boot .menu-hero { width: 48vw; }
  .menu-overlay.menu-boot .menu-box { width: 40vw; padding: 28px 22px; }
  .menu-title { font-size: 19px; }
}
@media (max-width: 560px) {
  .menu-overlay.menu-boot { align-items: stretch; flex-direction: column; overflow-y: auto; padding: 10px; }
  .menu-overlay.menu-boot .menu-hero { width: 100%; height: 34vh; min-height: 190px; flex-shrink: 0; border-right: 1px solid rgba(58, 90, 154, .5); border-bottom: 0; border-radius: 12px 12px 0 0; }
  .menu-overlay.menu-boot .menu-box { width: 100%; height: auto; min-height: 0; flex: 1; justify-content: flex-start; padding: 22px 18px; border-left: 1px solid rgba(111, 157, 255, .5); border-top: 0; border-radius: 0 0 12px 12px; }
  .menu-overlay.menu-boot .menu-description { margin-bottom: 16px; }
  .menu-overlay.menu-boot .menu-buttons { gap: 8px; }
  .menu-overlay.menu-boot .menu-btn { min-height: 44px; }
  .menu-station-art { width: 42%; left: 11%; top: 3%; }
  .menu-ship-art { width: 25%; right: 18%; bottom: 12%; }
  .menu-hero-label { left: 14px; bottom: 12px; font-size: 8px; }
}
@media (max-height: 600px) and (min-width: 561px) {
  .menu-overlay.menu-boot { padding: 10px 18px; }
  .menu-overlay.menu-boot .menu-hero,
  .menu-overlay.menu-boot .menu-box { height: calc(100vh - 20px); min-height: 0; }
  .menu-overlay.menu-boot .menu-box { padding: 20px 24px; }
  .menu-overlay.menu-boot .menu-description { margin-bottom: 12px; }
}

/* ---- Кольорова класифікація квестів і місій ----
   Самі значення --cat-* проставляє UI._applyCategoryColors() із
   src/QuestCategories.js — CSS не вміє імпортувати JS, тож реєстр залишається
   єдиним джерелом, а тут лише описано, ЯК цей колір застосовується.
   Фолбеки нижче потрібні лише на випадок, якщо стилі відмалюються до ініціалізації UI. */

/* Смужка зліва — навмисно окремо від border-color, який уже фарбують стани
   .completable (зелений) і .escort-mission (бурштиновий): вони позначають СТАН
   місії, а смужка — її ТИП, і ці дві осі не мають перетирати одна одну. */
.mission-item.cat-main     { border-left: 3px solid var(--cat-main,     #ffcc00); }
.mission-item.cat-side     { border-left: 3px solid var(--cat-side,     #6f9dff); }
.mission-item.cat-delivery { border-left: 3px solid var(--cat-delivery, #2fe8b0); }
.mission-item.cat-bounty   { border-left: 3px solid var(--cat-bounty,   #ff2d2d); }
.mission-item.cat-escort   { border-left: 3px solid var(--cat-escort,   #a05cff); }

.quest-tracker-item.cat-main { border-left: 3px solid var(--cat-main, #ffcc00); }
.quest-tracker-item.cat-side { border-left: 3px solid var(--cat-side, #6f9dff); }

.planet-quest-item.cat-main     { border-left: 3px solid var(--cat-main,     #ffcc00); }
.planet-quest-item.cat-side     { border-left: 3px solid var(--cat-side,     #6f9dff); }
.planet-quest-item.cat-delivery { border-left: 3px solid var(--cat-delivery, #2fe8b0); }
.planet-quest-item.cat-bounty   { border-left: 3px solid var(--cat-bounty,   #ff2d2d); }
.planet-quest-item.cat-escort   { border-left: 3px solid var(--cat-escort,   #a05cff); }

/* Легенда в довідці F1 */
.help-legend-title {
  margin: 12px 0 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #7f93c2;
}
.help-legend .legend-row { align-items: center; }
.legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  transform: rotate(45deg);   /* та сама форма, що й ромб на карті */
  border-radius: 2px;
  margin-right: 4px;
}
.legend-swatch.cat-main     { background: var(--cat-main,     #ffcc00); }
.legend-swatch.cat-side     { background: var(--cat-side,     #6f9dff); }
.legend-swatch.cat-delivery { background: var(--cat-delivery, #2fe8b0); }
.legend-swatch.cat-bounty   { background: var(--cat-bounty,   #ff2d2d); }
.legend-swatch.cat-escort   { background: var(--cat-escort,   #a05cff); }

.cat-marker { flex: 0 0 10px; margin-right: 5px; vertical-align: -1px; }

/* Final viewport-safe docking layout. The panel owns the scroll, never the page. */
#stationPanel,
.station-compact-panel,
.trade-station-panel {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 24px);
}
#stationPanel .station-body,
.station-compact-panel .panel-body,
.trade-station-panel .panel-body {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overscroll-behavior: contain;
}
#stationPanel .panel-footer,
.station-compact-panel .panel-footer,
.trade-station-panel .panel-footer {
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

@media (max-width: 480px) {
  #stationPanel,
  .station-compact-panel,
  .trade-station-panel {
    max-height: calc(100dvh - 16px);
  }
  #stationPanel .panel-header,
  .station-compact-panel .panel-header,
  .trade-station-panel .panel-header {
    min-height: 52px;
    padding: 8px 12px;
  }
  .station-heading > span:last-child { font-size: 13px; }
  .station-kicker { font-size: 8px; }
  .station-scene { aspect-ratio: 2.1 / 1; }
  #stationPanel .station-tabs { padding: 4px 8px 0; }
  #stationPanel .tab-btn { min-height: 38px; }
  #stationPanel .station-body,
  .station-compact-panel .panel-body,
  .trade-station-panel .panel-body { padding: 10px; }
  .station-weapon-card { min-height: 112px; padding: 8px 6px; }
}

@media (max-height: 700px) {
  #stationPanel,
  .station-compact-panel,
  .trade-station-panel {
    top: 50%;
    max-height: calc(100dvh - 12px);
  }
  #stationPanel .station-resource-bar { padding-top: 4px; padding-bottom: 4px; }
  #stationPanel .station-tabs { padding-top: 3px; }
  #stationPanel .station-body { padding-top: 9px; padding-bottom: 9px; }
  .station-weapon-card { min-height: 108px; }
}

@media (max-height: 600px) and (min-width: 481px) {
  #stationPanel,
  .station-compact-panel,
  .trade-station-panel {
    top: 6px;
    transform: translateX(-50%);
    max-height: calc(100dvh - 12px);
  }
  #stationPanel .station-resource-bar > div { padding-top: 3px; padding-bottom: 3px; }
  #stationPanel .tab-btn { min-height: 30px; padding-top: 5px; padding-bottom: 5px; }
  #stationPanel .station-body { padding-top: 7px; padding-bottom: 7px; }
  #stationPanel .panel-footer,
  .station-compact-panel .panel-footer,
  .trade-station-panel .panel-footer { padding-top: 7px; padding-bottom: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  .station-pane { animation: none; }
}

/* Station shop details and compact mobile presentation */
.station-upgrade-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
#stPaneUpgrades .station-table-wrap { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 8px; background: transparent; border: 0; }
.station-garage-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.station-garage-card { display: flex; flex-direction: column; gap: 8px; min-width: 0; padding: 12px; border: 1px solid rgba(91, 169, 226, .32); border-radius: 8px; background: linear-gradient(160deg, rgba(22, 52, 88, .55), rgba(10, 22, 43, .76)); }
.station-garage-card h3 { margin: 0; color: #d8f1ff; font-size: 13px; letter-spacing: .04em; }
.station-garage-card .row { padding: 6px 0; border-bottom: 1px solid rgba(91, 169, 226, .15); }
.station-garage-card .btn-build-sm { margin-top: auto; }
#stPaneUpgrades .upg-row.station-upgrade-card { min-width: 0; display: flex; flex-direction: column; align-items: stretch; gap: 6px; border: 1px solid rgba(91, 169, 226, .32); }
.upg-row.station-upgrade-card .label { grid-column: auto; }
.upg-row.station-upgrade-card .upgrade-card-info { display: none; }
.station-upgrade-card { position: relative; display: flex; flex-direction: column; gap: 7px; padding: 10px; border: 1px solid rgba(91, 169, 226, .32); border-radius: 8px; background: linear-gradient(160deg, rgba(22, 52, 88, .55), rgba(10, 22, 43, .76)); }
.station-upgrade-card .label, .upgrade-card-title { color: #d8f1ff; font-weight: 700; }
.upgrade-card-info { color: #7fafd1; font-size: 11px; }
.upgrade-card-values { display: flex; align-items: center; gap: 7px; color: #bce6ff; font: 600 14px/1.2 monospace; }
.upgrade-card-values .upgrade-card-next { color: #82e7a7; }
.upgrade-arrow { color: #6687ae; }
.upgrade-levels { display: flex; gap: 3px; }
.upgrade-levels span { flex: 1; height: 4px; border-radius: 2px; background: rgba(91, 169, 226, .2); }
.upgrade-levels span.is-filled { background: #69cbff; box-shadow: 0 0 5px rgba(105, 203, 255, .45); }
.station-upgrade-card .upgrade-card-action, .station-upgrade-card > button { width: 100%; margin-top: auto; }
.fuel-service-value { display: flex; justify-content: space-between; color: #bce6ff; font: 600 12px/1.2 monospace; }
.fuel-progress { height: 5px; overflow: hidden; border-radius: 3px; background: rgba(91, 169, 226, .2); }
.fuel-progress span { display: block; height: 100%; border-radius: inherit; background: #82e7a7; transition: width .2s ease; }
.station-loadout { margin-bottom: 10px; padding: 9px; border: 1px solid rgba(91, 169, 226, .28); border-radius: 8px; background: rgba(12, 32, 58, .55); }
.loadout-title { margin-bottom: 7px; color: #75c9ff; font: 10px/1.2 monospace; letter-spacing: .14em; }
.loadout-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
.loadout-slot { min-width: 0; padding: 5px 6px; border: 1px solid rgba(91, 169, 226, .24); border-radius: 5px; background: rgba(5, 12, 26, .5); }
.loadout-slot.is-empty { opacity: .55; }
.loadout-slot-name { display: block; color: #6687ae; font: 9px/1.1 monospace; letter-spacing: .08em; }
.loadout-slot strong { display: block; overflow: hidden; color: #d8f1ff; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.station-weapon-card { min-height: 190px; }
.swc-desc { display: -webkit-box; overflow: hidden; color: #7899bd; font-size: 10px; line-height: 1.25; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.swc-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; gap: 3px; }
.swc-stats span { min-width: 0; padding: 3px 2px; border-radius: 3px; background: rgba(5, 12, 26, .42); }
.swc-stats small, .swc-stats b { display: block; overflow: hidden; font-size: 9px; line-height: 1.15; text-overflow: ellipsis; white-space: nowrap; }
.swc-stats small { color: #6687ae; }
.swc-stats b { color: #bce6ff; }

@media (max-width: 560px) {
  .station-scene { height: 145px; aspect-ratio: auto; }
  .station-upgrade-list { gap: 6px; }
  .station-upgrade-card { padding: 8px; gap: 5px; }
  .station-upgrade-card .upgrade-card-info { display: none; }
  .station-weapon-card { min-height: 176px; padding: 9px 6px; }
  .swc-desc { font-size: 9px; }
  .loadout-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-height: 600px) {
  .station-scene { height: 112px; }
  .station-weapon-card { min-height: 150px; }
  .swc-desc { display: none; }
  .station-upgrade-card { padding: 7px; }
}

/* ---- Cockpit context consoles: navigation and target ---- */
.move-panel,
.combat-panel {
  --context-accent: var(--cockpit-edge-bright);
  --context-glow: var(--cockpit-glow);
  position: absolute;
  z-index: 84;
  left: 50%;
  bottom: max(20px, calc(env(safe-area-inset-bottom) + 12px));
  box-sizing: border-box;
  transform: translateX(-50%);
  border: 1px solid var(--context-accent);
  border-radius: 10px 10px 4px 4px;
  background:
    linear-gradient(135deg, transparent 7px, rgba(4, 14, 27, .94) 0) top left,
    linear-gradient(225deg, transparent 7px, rgba(4, 14, 27, .94) 0) top right;
  background-size: 51% 100%;
  background-repeat: no-repeat;
  box-shadow: inset 0 1px rgba(218, 245, 252, .1), inset 0 -12px 26px rgba(1, 7, 15, .5), 0 0 18px var(--context-glow);
  color: var(--cockpit-text);
  font-family: monospace;
  pointer-events: auto;
}
.move-panel::before,
.combat-panel::before {
  content: '';
  position: absolute;
  inset: 4px;
  z-index: -1;
  border: 1px solid color-mix(in srgb, var(--context-accent) 34%, transparent);
  border-radius: 6px 6px 2px 2px;
  pointer-events: none;
}

.move-panel {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  width: min(560px, calc(100vw - 380px));
  max-width: calc(100vw - 24px);
  min-width: 360px;
  gap: 5px 16px;
  align-items: center;
  padding: 10px 12px 11px;
  font-size: 11px;
}
.mp-heading {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--cockpit-muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .14em;
}
.mp-signal {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--context-accent);
  box-shadow: 0 0 8px var(--context-accent);
}
.mp-mode {
  margin-left: auto;
  padding: 1px 5px;
  border: 1px solid color-mix(in srgb, var(--context-accent) 45%, transparent);
  border-radius: 2px;
  color: var(--context-accent);
  letter-spacing: .08em;
}
.mp-readout { min-width: 0; }
.mp-caption { display: block; color: var(--cockpit-muted); font-size: 8px; letter-spacing: .12em; }
.mp-label {
  overflow: hidden;
  margin-top: 2px;
  color: var(--cockpit-text);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .03em;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mp-fuel { margin-top: 3px; color: #85dcb8; font-size: 10px; }
.move-panel[data-fuel-state="insufficient"] { --context-accent: #e56b6f; --context-glow: rgba(229, 107, 111, .22); }
.move-panel[data-fuel-state="insufficient"] .mp-fuel { color: #ff9c9f; }
.mp-actions { display: flex; gap: 7px; align-items: stretch; }
.btn-go,
.mp-cancel,
.cp-cancel {
  min-height: 40px;
  border-radius: 5px;
  font: 700 11px/1 monospace;
  cursor: pointer;
}
.btn-go {
  min-width: 112px;
  padding: 7px 12px;
  border: 1px solid var(--context-accent);
  background: color-mix(in srgb, var(--context-accent) 20%, rgba(3, 14, 27, .9));
  color: #dff9ff;
  box-shadow: inset 0 1px rgba(255, 255, 255, .08);
}
.btn-go kbd { margin-left: 5px; color: var(--cockpit-muted); font: 700 8px/1 monospace; }
.btn-go:hover:not(:disabled) { background: color-mix(in srgb, var(--context-accent) 34%, rgba(3, 14, 27, .9)); }
.btn-go:disabled { opacity: .52; cursor: not-allowed; }
.mp-cancel,
.cp-cancel {
  min-width: 40px;
  padding: 7px 10px;
  border: 1px solid rgba(122, 174, 196, .34);
  background: rgba(4, 13, 25, .72);
  color: var(--cockpit-muted);
}
.mp-cancel:hover,
.cp-cancel:hover { border-color: var(--context-accent); color: var(--cockpit-text); }

.combat-panel {
  display: grid;
  grid-template-columns: minmax(150px, 1.15fr) minmax(180px, .9fr);
  width: min(700px, calc(100vw - 380px));
  max-width: calc(100vw - 24px);
  min-width: 460px;
  gap: 4px 16px;
  padding: 11px 12px 12px;
  --context-accent: #7dc8de;
  --context-glow: rgba(75, 184, 218, .2);
}
.combat-panel[data-target-kind="friendly"] { --context-accent: #70d6b0; --context-glow: rgba(73, 204, 160, .2); }
.combat-panel[data-target-kind="hostile"] { --context-accent: #ef7377; --context-glow: rgba(235, 69, 76, .24); }
.combat-panel[data-target-kind="object"] { --context-accent: #d9a45f; --context-glow: rgba(217, 164, 95, .22); }
.cp-identity { grid-row: 1 / 3; min-width: 0; padding-right: 12px; border-right: 1px solid rgba(103, 166, 190, .2); }
.cp-title { display: flex; align-items: center; gap: 7px; margin: 0 0 4px; color: var(--context-accent); font-size: 9px; font-weight: 700; letter-spacing: .14em; }
.cp-reticle { width: 7px; height: 7px; border: 1px solid var(--context-accent); border-radius: 50%; box-shadow: 0 0 7px var(--context-accent); }
.cp-kind { margin-left: auto; padding: 1px 5px; border: 1px solid color-mix(in srgb, var(--context-accent) 50%, transparent); border-radius: 2px; font-size: 8px; }
.cp-name { overflow: hidden; margin: 0 0 4px; color: var(--cockpit-text); font-size: 15px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.cp-meta { display: flex; min-width: 0; gap: 8px; color: var(--cockpit-muted); font-size: 9px; }
.cp-id { flex: 0 0 auto; color: var(--context-accent); }
.cp-status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combat-panel .cp-telemetry { display: grid; grid-template-columns: 22px minmax(80px, 1fr) 58px; gap: 6px; align-items: center; margin: 0; }
.combat-panel .cp-telemetry .ps-value { width: auto; color: var(--cockpit-text); text-align: right; }
.combat-panel .ps-bar-track { height: 7px; }
.cp-actions { grid-column: 1 / -1; display: flex; gap: 7px; margin: 5px 0 0; }
.btn-attack,
.btn-trade {
  flex: 1 1 120px;
  min-width: 0;
  min-height: 40px;
  padding: 7px 9px;
  border: 1px solid color-mix(in srgb, var(--context-accent) 70%, transparent);
  border-radius: 5px;
  background: color-mix(in srgb, var(--context-accent) 17%, rgba(8, 14, 25, .9));
  color: var(--cockpit-text);
  font: 700 10px/1.15 monospace;
  cursor: pointer;
}
.btn-attack:hover:not(:disabled),
.btn-trade:hover:not(:disabled) { background: color-mix(in srgb, var(--context-accent) 30%, rgba(8, 14, 25, .9)); }
.btn-attack[data-weapon-state="approaching"] { border-style: dashed; color: #ffd690; }
.btn-attack[data-weapon-state="empty"],
.btn-attack:disabled { opacity: .45; cursor: not-allowed; filter: saturate(.45); }
.btn-torpedo { border-color: #d69d59; background: rgba(90, 53, 18, .66); color: #ffe0ae; }
.move-panel button:focus-visible,
.combat-panel button:focus-visible { outline: 2px solid #e5faff; outline-offset: 2px; }

@media (max-width: 1099px), (max-height: 600px) {
  .move-panel { width: min(520px, calc(100vw - 220px)); min-width: 340px; }
  .combat-panel { width: min(620px, calc(100vw - 220px)); min-width: 440px; }
}
@media (max-width: 480px) {
  .move-panel,
  .combat-panel {
    bottom: max(112px, calc(env(safe-area-inset-bottom) + 104px));
    width: calc(100vw - 16px);
    max-width: none;
    min-width: 0;
    border-radius: 8px 8px 3px 3px;
  }
  .move-panel { grid-template-columns: minmax(0, 1fr) auto; gap: 5px 8px; padding: 9px; }
  .mp-label { font-size: 12px; }
  .mp-actions { gap: 5px; }
  .btn-go { min-width: 96px; }
  .mp-cancel, .cp-cancel { min-width: 44px; }
  .btn-go, .mp-cancel, .cp-cancel, .btn-attack, .btn-trade { min-height: 44px; }
  .combat-panel { grid-template-columns: 1fr; gap: 5px; padding: 9px; }
  .cp-identity { grid-row: auto; padding: 0 0 6px; border-right: 0; border-bottom: 1px solid rgba(103, 166, 190, .2); }
  .combat-panel .cp-telemetry { grid-template-columns: 20px minmax(70px, 1fr) 54px; }
  .cp-actions { grid-column: 1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)) 44px; gap: 5px; }
  .cp-actions .cp-cancel { grid-column: 3; grid-row: 1; }
}
@media (max-height: 600px) and (min-width: 481px) {
  .move-panel,
  .combat-panel { bottom: max(8px, env(safe-area-inset-bottom)); }
  .move-panel { width: min(460px, calc(100vw - 380px)); min-width: 350px; }
  .combat-panel { width: min(450px, calc(100vw - 400px)); min-width: 450px; grid-template-columns: minmax(125px, .8fr) minmax(145px, .7fr); padding: 7px 9px 8px; }
  .cp-actions { gap: 5px; margin-top: 2px; }
  .btn-attack, .btn-trade, .cp-cancel, .btn-go, .mp-cancel { min-height: 36px; padding-block: 5px; }
}
@media (prefers-reduced-motion: reduce) {
  .move-panel, .move-panel *, .combat-panel, .combat-panel * { transition: none !important; animation: none !important; }
}

@media (max-width: 380px) {
  .station-upgrade-list { grid-template-columns: 1fr; }
  #stPaneUpgrades .station-table-wrap { grid-template-columns: 1fr; }
  .station-garage-grid { grid-template-columns: 1fr; }
  .station-weapon-card { min-height: 160px; }
}

/* Final station stacking fix: tabs and footer stay in flow; only body scrolls. */
#stationPanel {
  height: min(86dvh, 760px);
  min-height: 0;
  overflow: hidden;
}
#stationPanel .panel-header,
#stationPanel .station-scene,
#stationPanel .station-resource-bar,
#stationPanel .station-tabs,
#stationPanel .panel-footer {
  flex: 0 0 auto;
}
#stationPanel .station-tabs {
  position: relative;
  z-index: 2;
  min-height: 44px;
  align-items: stretch;
  overflow-x: auto;
  overflow-y: hidden;
  background: rgba(7, 16, 32, .98);
}
#stationPanel .station-tabs .tab-btn {
  min-height: 40px;
  line-height: 1.1;
  flex: 1 0 0;
}

/* ---- Cockpit UI completion: authoritative persistent HUD layout ---- */
.cockpit-control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 44px;
  min-height: 44px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
.cockpit-icon { display: inline-grid; width: 16px; height: 16px; flex: 0 0 16px; place-items: center; }
.cockpit-icon svg { display: block; width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.cockpit-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#hud {
  top: var(--cockpit-safe-y);
  left: 152px;
  right: max(16px, env(safe-area-inset-right));
  width: auto;
  max-width: none;
  min-height: 44px;
  padding: 7px 58px 7px 12px;
  flex-wrap: nowrap;
  gap: 8px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
#hudCredits, #hudCargo, #hudHealth, #hudArmor, #hudFuel {
  min-width: 0;
  padding: 3px 5px;
  border: 0;
  border-bottom: 1px solid rgba(79, 178, 211, .28);
  background: rgba(2, 10, 20, .25);
  box-shadow: none;
  white-space: nowrap;
}
#hudProgression { flex: 0 1 160px; min-width: 118px; }
#hud .hud-divider { flex: 0 0 1px; }
.hud-warmode, .hud-autoattack { opacity: 1; color: var(--cockpit-muted); }
.hud-warmode.active { color: var(--cockpit-danger); border-color: currentColor; background: rgba(110, 20, 24, .36); box-shadow: 0 0 10px rgba(255, 75, 70, .22); }
.hud-autoattack.active { color: #72e8b0; border-color: currentColor; background: rgba(20, 105, 72, .30); box-shadow: 0 0 10px rgba(70, 230, 165, .20); }

#backButton {
  width: 120px;
  padding-inline: 5px;
  gap: 4px;
  font-size: 10px;
  letter-spacing: 0;
}
#backButton .cockpit-label { overflow: visible; text-overflow: clip; }
#topLeftStack { top: max(68px, calc(var(--hud-bottom, 60px) + 8px)); max-width: min(260px, calc(100vw - 180px)); }
.sp-open-btn { width: 120px; }

#backButton::before, .gs-open-btn::before,
.sp-open-btn::after, .player-stats::after {
  content: "";
  position: absolute;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--cockpit-edge-bright));
  pointer-events: none;
  opacity: .55;
}
#backButton::before, .gs-open-btn::before { right: 100%; top: 50%; width: max(8px, env(safe-area-inset-left)); }
.sp-open-btn::after, .player-stats::after { left: 100%; top: 50%; width: max(16px, env(safe-area-inset-right)); background: linear-gradient(90deg, var(--cockpit-edge-bright), transparent); }

.gs-open-btn {
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  min-width: 96px;
  min-height: 44px;
  background: linear-gradient(145deg, rgba(14, 37, 52, .92), var(--cockpit-surface));
  border: 1px solid var(--cockpit-edge);
  border-radius: var(--cockpit-radius);
  color: var(--cockpit-text);
  box-shadow: inset 0 1px rgba(218, 245, 252, .08), 0 0 11px var(--cockpit-glow);
}
.gs-open-btn:hover { background: var(--cockpit-surface-hover); border-color: var(--cockpit-edge-bright); color: #effcff; }
.gs-open-btn:active { transform: translateY(1px); }
.gs-open-btn:focus-visible { outline: 2px solid var(--cockpit-edge-bright); outline-offset: 2px; }

.player-stats {
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  background: linear-gradient(145deg, rgba(14, 37, 52, .9), var(--cockpit-surface));
  border: 1px solid var(--cockpit-edge);
  border-radius: var(--cockpit-radius);
  color: var(--cockpit-text);
  box-shadow: inset 0 1px rgba(218, 245, 252, .08), 0 0 12px var(--cockpit-glow);
}
.ps-title, .ps-label, .ps-speed { color: var(--cockpit-muted); }
.ps-value { color: var(--cockpit-text); }
.ps-bar-track { background: rgba(2, 10, 20, .72); border: 1px solid rgba(79, 178, 211, .18); }

.quest-tracker-item, .event-badge, .alert-widget, #missionAlert { border-color: var(--cockpit-edge); }

@media (max-width: 1099px), (max-height: 600px) {
  :root { --cockpit-safe-x: max(8px, env(safe-area-inset-left)); --cockpit-safe-y: max(8px, env(safe-area-inset-top)); }
  #hud {
    top: var(--cockpit-safe-y);
    left: 128px;
    right: max(60px, calc(env(safe-area-inset-right) + 52px));
    max-width: none;
    padding: 5px 8px;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 11px;
  }
  #hud .hud-key, #hud .hud-divider { display: none; }
  #hudCredits, #hudCargo, #hudHealth, #hudArmor, #hudFuel { padding-inline: 3px; }
  #hudProgression { flex-basis: 110px; min-width: 96px; }
  #backButton { top: calc(var(--hud-bottom, 52px) + 8px); left: var(--cockpit-safe-x); width: 112px; }
  #topLeftStack { top: calc(var(--hud-bottom, 52px) + 60px); left: var(--cockpit-safe-x); max-width: min(260px, calc(100vw - 132px)); }
  .sp-open-btn { right: max(8px, env(safe-area-inset-right)); width: 44px; padding: 0; }
  .sp-open-btn .cockpit-label { display: none; }
  #spOpenInventoryBtn { top: calc(var(--hud-bottom, 52px) + 8px); }
  #spOpenMissionsBtn { top: calc(var(--hud-bottom, 52px) + 60px); }
  #mmOpenMenuBtn { top: calc(var(--hud-bottom, 52px) + 112px); }
  .toggle-ui-btn { top: var(--cockpit-safe-y); right: max(8px, env(safe-area-inset-right)); }
  .gs-open-btn { left: var(--cockpit-safe-x); bottom: max(8px, env(safe-area-inset-bottom)); }
  .player-stats { right: max(8px, env(safe-area-inset-right)); bottom: max(8px, env(safe-area-inset-bottom)); min-width: 140px; padding: 5px 8px; }
}

@media (max-width: 480px) {
  #hud {
    left: var(--cockpit-safe-x);
    right: max(8px, env(safe-area-inset-right));
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-template-rows: minmax(27px, auto) minmax(27px, auto) 44px;
    gap: 8px;
    min-height: 0;
    padding: 7px 52px 7px 7px;
    font-size: 10px;
  }
  #hudCredits { grid-column: 1 / 4; grid-row: 1; }
  #hudCargo { grid-column: 4 / 7; grid-row: 1; }
  #hudHealth { grid-column: 1 / 3; grid-row: 2; }
  #hudArmor { grid-column: 3 / 5; grid-row: 2; }
  #hudFuel { grid-column: 5 / 7; grid-row: 2; }
  #hudProgression { grid-column: 1 / 3; grid-row: 3; min-width: 0; padding: 3px 5px; }
  #warModeBadge { grid-column: 3 / 5; grid-row: 3; min-width: 0; padding: 3px; }
  #autoAttackBadge { grid-column: 5 / 7; grid-row: 3; min-width: 0; padding: 3px; }
  #hudBank { grid-column: 1 / 7; min-width: 0; overflow-wrap: anywhere; }
  #hudProgression .rank-badge, #hudProgression .xp-rank-name, #hudProgression .xp-hud-detail { display: none; }
  #hudProgression .xp-hud-content { min-width: 0; width: 100%; }
  #hudProgression .xp-level { font-size: 10px; }
  #hudProgression .xp-track { margin: 4px 0 0; }
  #hud .cockpit-icon { width: 14px; height: 14px; flex-basis: 14px; }
  #hud .cockpit-control { gap: 4px; }

  #backButton { top: calc(var(--hud-bottom, 125px) + 8px); left: var(--cockpit-safe-x); width: 104px; padding: 5px; }
  #topLeftStack { top: calc(var(--hud-bottom, 125px) + 60px); left: var(--cockpit-safe-x); max-width: calc(100vw - 68px); }
  .quest-tracker-desc { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
  #spOpenInventoryBtn { top: calc(var(--hud-bottom, 125px) + 8px); }
  #spOpenMissionsBtn { top: calc(var(--hud-bottom, 125px) + 60px); }
  #mmOpenMenuBtn { top: calc(var(--hud-bottom, 125px) + 112px); }
  .gs-open-btn { width: 44px; min-width: 44px; padding: 0; }
  .gs-open-btn .cockpit-label { display: none; }
  .player-stats { width: min(150px, calc(100vw - 68px)); min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .cockpit-control, #hud, .player-stats, .ps-bar-fill { transition: none !important; animation: none !important; }
}

/* ---- Inventory / Missions cockpit console ---- */
#sidePanel {
  --side-content-scale: 1;
  --side-control-min: 44px;
  z-index: 85;
  top: calc(var(--hud-bottom, 52px) + 8px);
  right: max(8px, env(safe-area-inset-right));
  bottom: max(112px, calc(env(safe-area-inset-bottom) + 104px));
  width: min(380px, calc(100vw - 24px));
  max-width: none;
  max-height: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--cockpit-edge);
  border-radius: var(--cockpit-radius);
  /* One controlled glass layer keeps the scene visible through the console. */
  background: linear-gradient(145deg, rgba(16, 39, 55, .58), rgba(3, 10, 21, .78) 42%, rgba(5, 15, 27, .68));
  box-shadow:
    inset 0 1px rgba(218, 245, 252, .12),
    inset 0 -12px 26px rgba(0, 3, 10, .28),
    0 0 18px var(--cockpit-glow),
    -7px 0 20px rgba(0, 0, 0, .36);
  color: var(--cockpit-text);
  transform: none;
  transform-origin: top right;
}

#sidePanel::before,
#sidePanel::after {
  content: "";
  position: absolute;
  z-index: 3;
  left: 7px;
  width: 42px;
  height: 16px;
  border-left: 2px solid var(--cockpit-edge-bright);
  pointer-events: none;
  filter: drop-shadow(0 0 5px var(--cockpit-glow));
}
#sidePanel::before { top: 7px; border-top: 2px solid var(--cockpit-edge-bright); }
#sidePanel::after { bottom: 7px; border-bottom: 2px solid var(--cockpit-edge-bright); }

#sidePanel > .panel-header {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 44px;
  gap: 8px;
  min-height: 52px;
  padding: 4px 5px 4px 12px;
  flex: 0 0 auto;
  overflow: hidden;
  border-bottom: 1px solid var(--cockpit-edge);
  background: linear-gradient(90deg, rgba(24, 66, 83, .58), rgba(4, 15, 27, .88));
}
#sidePanel > .panel-header::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 0;
  width: 9px;
  height: 2px;
  background: var(--cockpit-edge-bright);
  box-shadow: 0 0 7px var(--cockpit-glow);
  pointer-events: none;
}
#sidePanel .tab-row { min-width: 0; gap: 6px; align-self: stretch; overflow: hidden; }
#sidePanel .tab-btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: 7px 8px;
  border: 1px solid rgba(79, 178, 211, .18);
  border-radius: 3px;
  color: var(--cockpit-muted);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  overflow: hidden;
}
#sidePanel .tab-btn .key-badge { margin-left: 3px; padding-inline: 3px; font-size: 9px; }
#sidePanel .tab-btn:hover { color: var(--cockpit-text); background: rgba(79, 178, 211, .1); }
#sidePanel .tab-btn.tab-active {
  color: #e5f8fc;
  border-color: rgba(79, 178, 211, .42);
  border-bottom-color: var(--cockpit-edge-bright);
  background: rgba(43, 116, 143, .22);
  box-shadow: inset 0 -4px 9px rgba(79, 178, 211, .08);
}
#sidePanel .tab-btn:focus-visible,
#sidePanel .gs-zoom-btn:focus-visible,
#sidePanel #closeSidePanel:focus-visible,
#sidePanel .panel-body button:focus-visible {
  outline: 2px solid var(--cockpit-edge-bright);
  outline-offset: -3px;
}
#sidePanel .gs-controls { display: flex; gap: 4px; align-items: center; }
#sidePanel .gs-zoom-btn,
#sidePanel #closeSidePanel {
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  border: 1px solid rgba(79, 178, 211, .32);
  border-radius: 3px;
  color: var(--cockpit-text);
  background: rgba(4, 15, 27, .62);
}
#sidePanel .gs-zoom-btn:hover:not(:disabled),
#sidePanel #closeSidePanel:hover { border-color: var(--cockpit-edge-bright); background: var(--cockpit-surface-hover); }
#sidePanel .gs-zoom-btn:disabled { opacity: .34; cursor: default; }

#sidePanel > .panel-body {
  min-width: 0;
  min-height: 0;
  max-height: none;
  padding: 12px 14px 18px;
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--cockpit-edge) rgba(2, 8, 17, .55);
  scrollbar-width: thin;
  zoom: var(--side-content-scale);
}
#sidePanel > .panel-body.hidden { display: none !important; }
#sidePanel .panel-body button { min-height: var(--side-control-min); }
#sidePanel .hud-module {
  min-width: 0;
  border-color: rgba(79, 178, 211, .3);
  background: rgba(2, 10, 20, .42);
  box-shadow: inset 0 1px rgba(218, 245, 252, .04);
}
#sidePanel .section-title,
#sidePanel .missions-section-title { color: #9bd9e9; letter-spacing: .08em; }
#sidePanel .credits-readout { border-color: rgba(79, 178, 211, .34); background: rgba(3, 13, 25, .58); }
#sidePanel .mission-item { overflow-wrap: anywhere; }
#sidePanel .mission-meta { flex-wrap: wrap; gap: 5px 10px; }
#sidePanel .wr-entry,
#sidePanel .btn-secondary,
#sidePanel .btn-build-sm,
#sidePanel .mission-abandon-btn { border-color: rgba(79, 178, 211, .4); }

@media (max-width: 1099px), (max-height: 600px) {
  #sidePanel {
    top: calc(var(--hud-bottom, 52px) + 8px);
    bottom: max(88px, calc(env(safe-area-inset-bottom) + 80px));
    width: min(360px, calc(100vw - 16px));
  }
}

@media (max-width: 480px) {
  #sidePanel {
    top: calc(var(--hud-bottom, 125px) + 8px);
    right: max(8px, env(safe-area-inset-right));
    left: max(8px, env(safe-area-inset-left));
    bottom: max(96px, calc(env(safe-area-inset-bottom) + 88px));
    width: auto;
  }
  #sidePanel > .panel-header {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: 44px 44px;
    min-height: 96px;
    padding: 4px 5px 4px 9px;
  }
  #sidePanel .tab-row { grid-column: 1 / 3; grid-row: 1; }
  #sidePanel .tab-btn { flex: 1 1 50%; }
  #sidePanel .gs-controls { grid-column: 1; grid-row: 2; }
  #sidePanel #closeSidePanel { grid-column: 2; grid-row: 2; }
  #sidePanel > .panel-body { padding: 9px 10px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  #sidePanel, #sidePanel * { transition: none !important; animation: none !important; }
}
#stationPanel .station-body {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-x: hidden;
  overflow-y: auto;
  padding-bottom: max(18px, calc(18px + env(safe-area-inset-bottom)));
  scroll-padding-bottom: 24px;
}
#stationPanel .panel-footer {
  position: relative;
  z-index: 3;
  min-height: 74px;
  background: rgba(4, 9, 19, .98);
  padding-top: 12px;
  padding-bottom: max(12px, calc(12px + env(safe-area-inset-bottom)));
}

@media (max-width: 560px) {
  #stationPanel {
    height: calc(100dvh - 16px);
    max-height: calc(100dvh - 16px);
  }
  #stationPanel .station-scene {
    height: 132px;
    aspect-ratio: auto;
  }
  #stationPanel .station-tabs {
    min-height: 46px;
  }
  #stationPanel .station-tabs .tab-btn {
    flex: 0 0 auto;
    min-width: 108px;
    min-height: 42px;
    padding-inline: 9px;
  }
  #stationPanel .panel-footer {
    min-height: 78px;
  }
}

@media (max-height: 600px) {
  #stationPanel {
    height: calc(100dvh - 12px);
    max-height: calc(100dvh - 12px);
  }
  #stationPanel .station-scene { height: 104px; }
  #stationPanel .station-tabs { min-height: 36px; }
  #stationPanel .station-tabs .tab-btn { min-height: 34px; padding-block: 5px; }
  #stationPanel .panel-footer { min-height: 58px; padding-block: 7px; }
}

@media (min-width: 561px) and (min-height: 601px) {
  #stationPanel {
    height: min(90dvh, 920px);
    max-height: min(90dvh, 920px);
  }
  #stationPanel .station-scene {
    height: min(320px, 38dvh);
    aspect-ratio: auto;
  }
}
