/* Cockpit UI. Everything sits above a full-bleed canvas, so panels are
   translucent slabs with a faint scanline rather than opaque windows. */

:root {
  --bg: #05070d;
  --panel: rgba(10, 16, 27, 0.92);
  --panel-soft: rgba(18, 27, 44, 0.72);
  --line: rgba(120, 170, 220, 0.18);
  --line-strong: rgba(120, 200, 255, 0.42);
  --ink: #dce7f5;
  --ink-dim: #8397b0;
  --accent: #4ee0c0;
  --accent-2: #f2c14e;
  --danger: #ff6b6b;
  --good: #8dd96b;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

canvas#view { position: fixed; inset: 0; display: block; }

.hidden { display: none !important; }
.muted { color: var(--ink-dim); font-size: 13px; }
.k { color: var(--ink-dim); font-size: 10px; letter-spacing: .14em; margin-right: 6px; }

kbd {
  font-family: var(--mono);
  font-size: 11px;
  background: rgba(255,255,255,.07);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--ink);
}

button {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink);
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .08s;
}
button:hover:not(:disabled) { background: rgba(78, 224, 192, .14); border-color: var(--line-strong); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .38; cursor: not-allowed; }
button.primary { background: rgba(78, 224, 192, .16); border-color: rgba(78,224,192,.45); color: #d9fff6; }
button.primary:hover:not(:disabled) { background: rgba(78, 224, 192, .28); }
button.warn { background: rgba(255,107,107,.14); border-color: rgba(255,107,107,.4); }

input {
  font-family: var(--mono);
  background: rgba(0,0,0,.4);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  padding: 9px 12px;
  outline: none;
  width: 100%;
}
input:focus { border-color: var(--line-strong); }

/* ---------- full-screen layers ---------- */

.screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: radial-gradient(1200px 800px at 50% 0%, rgba(20,40,70,.55), rgba(3,5,10,.94));
  backdrop-filter: blur(9px);
}

/* ---------- boot ---------- */

#boot { align-items: center; justify-content: center; }

.boot-card {
  width: min(460px, 90vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 34px 32px;
  box-shadow: 0 30px 90px rgba(0,0,0,.7), inset 0 1px 0 rgba(255,255,255,.05);
  text-align: center;
}
.boot-card h1 {
  margin: 0 0 6px;
  font-size: 34px;
  font-weight: 300;
  letter-spacing: .04em;
}
.boot-card h1 span { color: var(--accent); font-weight: 600; margin-left: 8px; }
.tagline { color: var(--ink-dim); font-size: 13px; margin: 0 0 26px; line-height: 1.55; }
.boot-card label { display: block; text-align: left; font-size: 11px; letter-spacing: .14em; color: var(--ink-dim); margin-bottom: 7px; }
.boot-card button { width: 100%; margin-top: 14px; padding: 11px; font-size: 15px; }
#boot-status { margin: 16px 0 0; font-size: 12px; }

.boot-keys {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  justify-content: center;
  margin-top: 24px; padding-top: 20px;
  border-top: 1px solid var(--line);
  font-size: 11px; color: var(--ink-dim);
}
.boot-keys span { display: inline-flex; align-items: center; gap: 4px; }

/* ---------- flight HUD ---------- */

#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }

#hud-top {
  position: absolute; top: 14px; left: 14px;
  display: flex; gap: 8px; flex-wrap: wrap;
}
.pill {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 11px;
  font-family: var(--mono);
  font-size: 13px;
  display: flex; align-items: baseline;
}
.pill.ghost { opacity: .45; font-size: 11px; }
.pill b { font-weight: 600; }
.pill.alert b { color: var(--danger); }

#hud-target {
  position: absolute; top: 14px; right: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 13px; min-width: 190px; text-align: right;
}
#hud-target .t-name { font-size: 14px; margin-bottom: 3px; }
#hud-target .t-meta { display: flex; gap: 10px; justify-content: flex-end; font-family: var(--mono); font-size: 11px; color: var(--ink-dim); }

#dock-prompt {
  position: absolute; left: 50%; bottom: 84px; transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 10px 16px; text-align: center;
}
.dock-check { display: flex; gap: 10px; font-family: var(--mono); font-size: 11px; letter-spacing: .1em; }
.dock-check span { color: var(--danger); opacity: .55; }
.dock-check span.ok { color: var(--good); opacity: 1; }
.dock-hint { margin-top: 7px; font-size: 12px; color: var(--ink-dim); }

#manifest {
  position: absolute; right: 14px; top: 84px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 13px;
  font-family: var(--mono); font-size: 11px; min-width: 210px;
}
#manifest h4 { margin: 0 0 7px; font-size: 10px; letter-spacing: .14em; color: var(--ink-dim); font-weight: 500; }
#manifest .row { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
#manifest .row.urgent { color: var(--accent-2); }

#toasts {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%);
  display: flex; flex-direction: column-reverse; gap: 6px; align-items: center;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 7px;
  padding: 8px 15px; font-size: 13px;
  animation: toast-in .22s ease-out;
}
.toast.bad { border-left-color: var(--danger); }
.toast.good { border-left-color: var(--good); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- touch controls ---------- */

/* Everything under #touch is display-gated on .touch-mode so desktop never
   sees it, even if a stray class toggle shows the container. */
#touch { display: none; }
body.touch-mode #touch { display: block; position: fixed; inset: 0; z-index: 12; pointer-events: none; }

#joy-zone {
  position: absolute;
  left: 0; bottom: 0;
  width: 52%; height: 62%;
  pointer-events: auto;
  touch-action: none;
}

#joy-base {
  position: absolute;
  width: 140px; height: 140px;
  margin: -70px 0 0 -70px;
  border-radius: 50%;
  border: 1.5px solid rgba(120, 200, 255, 0.3);
  background: rgba(10, 16, 27, 0.35);
  pointer-events: none;
}
#joy-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 54px; height: 54px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(78, 224, 192, 0.28);
  border: 1.5px solid rgba(78, 224, 192, 0.65);
}

#touch-btns {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: auto;
}
.tbtn {
  width: 64px; height: 64px;
  border-radius: 50%;
  font-size: 11px;
  letter-spacing: .06em;
  font-family: var(--mono);
  background: rgba(10, 16, 27, 0.6);
  border: 1.5px solid var(--line-strong);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.tbtn.pressed { background: rgba(78, 224, 192, 0.3); transform: scale(0.94); }
.tbtn.ready { border-color: var(--good); color: var(--good); box-shadow: 0 0 14px rgba(141, 217, 107, 0.35); }
.tbtn.sos { border-color: rgba(255, 107, 107, 0.5); color: var(--danger); }
#tbtn-mine { border-color: rgba(255, 179, 71, 0.55); color: var(--accent-2); }

/* Touch-mode niceties: bigger tap targets, no double-tap zoom, hide
   keyboard-only chrome. */
body.touch-mode canvas#view { touch-action: none; }
body.touch-mode .boot-keys { display: none; }
body.touch-mode .qty button { padding: 9px 13px; }
body.touch-mode .dock-hint { display: none; }

/* ---------- rescue ---------- */

#rescue { align-items: center; justify-content: center; z-index: 30; }

.rescue-card {
  width: min(520px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 30px 22px;
  box-shadow: 0 30px 90px rgba(0,0,0,.7);
}
.rescue-card h2 { margin: 0 0 4px; font-size: 22px; font-weight: 400; }
.rescue-card > .muted { margin: 0 0 22px; }

.rescue-opt {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 15px 17px;
  margin-bottom: 13px;
  background: var(--panel-soft);
}
.rescue-opt.disabled { opacity: .5; }
.ro-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.ro-head h4 { margin: 0 0 6px; font-size: 15px; font-weight: 500; }
.ro-price { font-family: var(--mono); font-size: 14px; color: var(--accent-2); }
.rescue-opt .sub { color: var(--ink-dim); font-size: 12.5px; line-height: 1.55; margin: 0 0 12px; }
.rescue-opt .ro-why { font-size: 11.5px; color: var(--danger); margin: -6px 0 12px; }
.rescue-opt .ro-why:empty { display: none; }
.rescue-opt button { width: 100%; }

.ghost-btn { width: 100%; margin-top: 6px; background: transparent; border-color: transparent; color: var(--ink-dim); }
.ghost-btn:hover { background: rgba(255,255,255,.05); }

/* ---------- station ---------- */

.st-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 22px 28px 16px; border-bottom: 1px solid var(--line);
}
.st-head h2 { margin: 0 0 4px; font-size: 26px; font-weight: 400; }
.st-head p { margin: 0; }
.st-wallet { display: flex; align-items: center; gap: 20px; font-family: var(--mono); }
.st-wallet b { font-size: 17px; }
.st-wallet > div { text-align: right; }

.st-tabs { display: flex; gap: 4px; padding: 12px 28px 0; border-bottom: 1px solid var(--line); }
.st-tabs button { border-radius: 8px 8px 0 0; border-bottom-color: transparent; background: transparent; }
.st-tabs button.active { background: var(--panel-soft); border-color: var(--line); border-bottom-color: transparent; color: var(--accent); }

.st-body { flex: 1; overflow-y: auto; padding: 20px 28px 40px; }
.panel { max-width: 1080px; margin: 0 auto; }

table.grid { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 13px; }
table.grid th {
  text-align: left; font-weight: 500; font-size: 10px; letter-spacing: .14em;
  color: var(--ink-dim); padding: 8px 10px; border-bottom: 1px solid var(--line);
}
table.grid td { padding: 7px 10px; border-bottom: 1px solid rgba(120,170,220,.07); }
table.grid tr:hover td { background: rgba(120,180,255,.05); }
td.num, th.num { text-align: right; }
.swatch { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 8px; vertical-align: middle; }
.price-low { color: var(--good); }
.price-high { color: var(--accent-2); }
.qty { display: flex; gap: 4px; justify-content: flex-end; }
.qty button { padding: 4px 9px; font-size: 12px; font-family: var(--mono); }

.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.card {
  background: var(--panel-soft); border: 1px solid var(--line);
  border-radius: 11px; padding: 15px 17px;
}
.card.owned { border-color: rgba(78,224,192,.45); }
.card h4 { margin: 0 0 3px; font-size: 15px; font-weight: 500; }
.card .sub { color: var(--ink-dim); font-size: 12px; margin: 0 0 12px; line-height: 1.5; }
.card .stats { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 12px; font-family: var(--mono); font-size: 11px; color: var(--ink-dim); margin-bottom: 13px; }
.card .stats b { color: var(--ink); float: right; font-weight: 500; }
.card footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.card .price { font-family: var(--mono); font-size: 14px; }

.pips { display: flex; gap: 3px; }
.pip { width: 20px; height: 5px; border-radius: 2px; background: rgba(255,255,255,.12); }
.pip.on { background: var(--accent); }

.empty { color: var(--ink-dim); font-size: 13px; padding: 40px 0; text-align: center; }

/* ---------- map ---------- */

#map { padding: 0; }
.map-head {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 18px 26px; border-bottom: 1px solid var(--line);
}
.map-head h2 { margin: 0; font-size: 20px; font-weight: 400; }
.map-legend { display: flex; gap: 16px; align-items: center; font-size: 12px; color: var(--ink-dim); }
.lg::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.lg-you::before { background: var(--accent); }
.lg-dest::before { background: var(--accent-2); }
.lg-yard::before { background: #f2c14e; box-shadow: 0 0 0 2px rgba(242,193,78,.25); }

/* min-height:0 is load-bearing: without it the canvas's intrinsic pixel
   height (width x DPR) becomes the flex min-size and shoves #map-info off
   the bottom of the screen, growing on every resize. */
#map-canvas { flex: 1; display: block; width: 100%; min-height: 0; cursor: crosshair; }
#map-info { padding: 12px 26px; border-top: 1px solid var(--line); font-family: var(--mono); min-height: 42px; }

@media (max-width: 760px) {
  .st-head { flex-direction: column; gap: 14px; padding: 14px 16px 12px; }
  .st-head h2 { font-size: 20px; }
  .st-wallet { width: 100%; justify-content: space-between; gap: 10px; }
  .st-body { padding: 16px 12px 60px; }
  .st-tabs { padding: 10px 12px 0; overflow-x: auto; }
  .st-tabs button { white-space: nowrap; }
  #hud-target { display: none; }
  #manifest { display: none; }
  /* The market table is wider than a phone — let it scroll inside the panel
     instead of squishing the qty buttons into unusability. */
  .panel { overflow-x: auto; }
  table.grid { min-width: 560px; font-size: 12px; }
  .cards { grid-template-columns: 1fr; }
  .map-legend { display: none; }
  #map-info { font-size: 11px; padding: 10px 14px; }
  #hud-top { gap: 5px; }
  .pill { padding: 5px 8px; font-size: 11px; }
}
