/* Theme packs: data-theme on <html> — cobalt (default) | coffee | lcars */
:root,
[data-theme="cobalt"] {
  --wall: #060A14;
  --raised: #0C1424;
  --line: #1E3A5F;
  --type: #D6E4F5;
  --dim: #8FA6C4;
  --mute: #5A7394;
  --ember: #2F6FED; /* accent (kept name for less churn) */
  --sage: #2FA4A0;
  --accent-soft: rgba(47, 111, 237, 0.22);
  --map-bg: #04070F;
  --map-here: #2F6FED;
  --map-sel: #D6E4F5;
  --map-reach: #9BB4D4;
  --map-far: #33445C;
  --map-label: #D6E4F5;
  --map-mute: #5A7394;
  --map-grid: rgba(30, 58, 95, 0.65);
  --map-ring: rgba(47, 111, 237, 0.55);
  --map-link: rgba(47, 164, 160, 0.55);
  --map-link-dim: rgba(30, 58, 95, 0.4);
  --radius: 0px;
  --font: ui-sans-serif, system-ui, -apple-system, sans-serif;
  --h2-track: 0.12em;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --tab-h: 56px;
}

[data-theme="coffee"] {
  --wall: #0C0A09;
  --raised: #1C1917;
  --line: #3F3A36;
  --type: #E7E0D6;
  --dim: #A8A29E;
  --mute: #78716C;
  --ember: #D97757;
  --sage: #6B8F7A;
  --accent-soft: rgba(217, 119, 87, 0.2);
  --map-bg: #0C0A09;
  --map-here: #D97757;
  --map-sel: #E7E0D6;
  --map-reach: #C4B9AC;
  --map-far: #57534E;
  --map-label: #E7E0D6;
  --map-mute: #78716C;
  --map-grid: rgba(63, 58, 54, 0.55);
  --map-ring: rgba(217, 119, 87, 0.45);
  --map-link: rgba(107, 143, 122, 0.55);
  --map-link-dim: rgba(63, 58, 54, 0.35);
  --radius: 0px;
  --font: ui-sans-serif, system-ui, -apple-system, sans-serif;
  --h2-track: 0.12em;
}

[data-theme="lcars"] {
  --wall: #000000;
  --raised: #0A0A0A;
  --line: #FF9900;
  --type: #FFCC99;
  --dim: #FF9966;
  --mute: #CC6666;
  --ember: #FF9900;
  --sage: #9999FF;
  --accent-soft: rgba(255, 153, 0, 0.25);
  --map-bg: #000000;
  --map-here: #FF9900;
  --map-sel: #FFCC99;
  --map-reach: #9999FF;
  --map-far: #444466;
  --map-label: #FFCC99;
  --map-mute: #CC6666;
  --map-grid: rgba(255, 153, 0, 0.25);
  --map-ring: rgba(255, 153, 0, 0.55);
  --map-link: rgba(153, 153, 255, 0.55);
  --map-link-dim: rgba(68, 68, 102, 0.4);
  --radius: 18px;
  --font: "Helvetica Neue", Helvetica, Arial, ui-sans-serif, sans-serif;
  --h2-track: 0.18em;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--wall);
  color: var(--type);
  font-family: var(--font);
  line-height: 1.35;
  overflow: hidden;
}
.shell {
  height: 100dvh;
  height: 100svh;
  max-width: 920px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding:
    calc(8px + var(--safe-t))
    calc(10px + var(--safe-r))
    calc(6px + var(--safe-b))
    calc(10px + var(--safe-l));
  gap: 8px;
}
.topbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.brand {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.brand strong { letter-spacing: 0.04em; }
.brand span, #ver { font-size: 12px; color: var(--mute); }
.status-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  background: var(--raised);
  border: 1px solid var(--line);
  padding: 8px 6px;
}
.status-strip label {
  display: block;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--mute);
}
.status-strip span {
  display: block;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.panels {
  min-height: 0;
  overflow: hidden;
  position: relative;
}
.panel {
  height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
}
.panel[hidden] { display: none !important; }
.panel h2 {
  font-size: 13px;
  letter-spacing: var(--h2-track);
  text-transform: uppercase;
  color: var(--ember);
  margin-bottom: 8px;
}
.hint { font-size: 12px; color: var(--dim); margin-bottom: 8px; }
.log {
  font-size: 13px;
  color: var(--type);
  background: var(--raised);
  border: 1px solid var(--line);
  padding: 10px;
  margin: 8px 0 12px;
  min-height: 3.2em;
}
.dock-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.card-block {
  background: var(--raised);
  border: 1px solid var(--line);
  padding: 12px;
}
.sub {
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mute);
  margin: 12px 0 8px;
}
.market { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 6px;
  align-items: center;
  font-size: 13px;
  background: var(--raised);
  border: 1px solid var(--line);
  padding: 8px;
}
.row .good strong { font-size: 14px; }
.row .have {
  color: var(--type);
  font-size: 14px;
  font-weight: 600;
  margin-top: 2px;
}
.qty { display: inline-flex; align-items: center; gap: 4px; }
.qty-val { min-width: 1.4em; text-align: center; font-weight: 700; font-size: 14px; }
.qty-btn { padding: 6px 8px; min-width: 32px; }

.btn, .chip, .tab, .seg-btn {
  font: inherit; font-size: 13px; font-weight: 600;
  background: var(--type); color: var(--wall);
  border: 1px solid var(--type);
  padding: 10px 12px; cursor: pointer;
}
.btn.ghost, .ghost, .chip.ghost, .tab, .seg-btn {
  background: transparent; color: var(--type); border-color: var(--line);
}
.btn.ember { background: var(--ember); border-color: var(--ember); color: var(--wall); }
.btn:disabled, .chip:disabled { opacity: 0.4; cursor: not-allowed; }

.chart-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.chart-toolbar h2 { margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); }
.seg-btn { padding: 8px 12px; border: 0; border-right: 1px solid var(--line); }
.seg-btn:last-child { border-right: 0; }
.seg-btn.active { background: var(--ember); color: var(--wall); }
.map-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: min(52dvh, 520px);
  background: var(--map-bg);
  border: 1px solid var(--line);
  margin-bottom: 8px;
  border-radius: var(--radius);
}
#map {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
.target-card {
  background: var(--raised);
  border: 1px solid var(--line);
  padding: 10px;
}
.target-title { font-weight: 700; margin-bottom: 4px; }
.peek {
  font-size: 12px;
  color: var(--type);
  line-height: 1.45;
  margin: 6px 0 10px;
}
.target-actions { display: flex; gap: 8px; }
.target-actions .btn { flex: 1; }

.ship-name { font-weight: 700; margin-bottom: 4px; }
.yard-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
  font-size: 13px;
  background: var(--raised);
  border: 1px solid var(--line);
  padding: 10px;
}
.crew-actions { display: flex; gap: 8px; margin: 10px 0 4px; }
.disclaimer { font-size: 12px; color: var(--mute); margin-top: 14px; }

.tabbar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  min-height: var(--tab-h);
  padding-top: 4px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.tab {
  padding: 10px 4px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.tab.active {
  background: var(--accent-soft);
  border-color: var(--ember);
  color: var(--ember);
}

dialog {
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--type);
  padding: 16px;
  max-width: 90vw;
  width: 340px;
}
dialog::backdrop { background: rgba(0,0,0,.72); }
.enc-actions { display: flex; gap: 8px; margin-top: 12px; }
.enc-actions .btn { flex: 1; }

/* Unfolded / wide: two-pane chart feel */
@media (min-width: 700px) {
  .shell { max-width: 1100px; }
  #tab-chart.active {
    display: grid;
    grid-template-columns: 1.2fr 0.9fr;
    grid-template-rows: auto auto 1fr;
    gap: 10px;
    overflow: hidden;
  }
  #tab-chart .chart-toolbar { grid-column: 1 / -1; }
  #tab-chart #chart-hint { grid-column: 1 / -1; margin: 0; }
  #tab-chart .map-wrap {
    max-height: none;
    height: 100%;
    aspect-ratio: auto;
    min-height: 0;
  }
  #tab-chart .target-card { align-self: start; }
  .status-strip span { font-size: 13px; }
  .tab { font-size: 12px; }
}

/* Narrow cover-ish */
@media (max-width: 360px) {
  .status-strip { grid-template-columns: repeat(3, 1fr); }
  .status-strip > :nth-child(4),
  .status-strip > :nth-child(5) { display: none; }
  .tab { font-size: 10px; padding: 8px 2px; }
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}
.panel-head h2 { margin: 0; }
.market-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: flex-end;
}

/* theme surface radius */
.status-strip, .log, .row, .yard-row, .target-card, .card-block, .btn, .chip, .tab, dialog {
  border-radius: var(--radius);
}
.theme-packs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0 16px;
}
.theme-packs .seg { width: 100%; }
.theme-packs .seg-btn { flex: 1; }
[data-theme="lcars"] .brand strong {
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
[data-theme="lcars"] .tabbar {
  border-top-width: 3px;
  border-top-color: var(--ember);
}
[data-theme="lcars"] .status-strip {
  border-width: 2px;
  border-color: var(--ember);
}

.ship-art {
  margin: 0 0 12px;
  padding: 14px 16px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(232,238,246,.08), rgba(0,0,0,.25));
  border: 1px solid rgba(154,168,188,.35);
}
.hull-art {
  line-height: 0;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,.45));
}
.hull-art .hull-svg {
  width: 100%;
  max-width: 300px;
  height: auto;
  display: block;
}
.hull-art--owned .hull-svg { max-width: 340px; }
.hull-art--thumb {
  padding: 6px 4px;
  border-radius: 8px;
  background: rgba(0,0,0,.22);
}
.hull-art--thumb .hull-svg { max-width: 132px; }
.hull-art--thumb .plates-loud { display: none; }
.hull-art--owned .plates-loud { display: block; }
.yard-row {
  grid-template-columns: 1fr auto;
}
.yard-info {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 10px;
  align-items: center;
}
@media (max-width: 420px) {
  .yard-info { grid-template-columns: 1fr; }
}

.dossier {
  font-size: 12px;
  line-height: 1.45;
  color: var(--dim);
  margin: 6px 0;
  padding: 8px;
  background: var(--wall);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.margin-line {
  font-size: 13px;
  font-weight: 700;
  color: var(--type);
  margin: 4px 0 8px;
}
.margin-line.good { color: var(--sage); }
.margin-line.bad { color: #C44C4C; }
.chart-legend { margin: 0 0 8px; }

.pilot-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  margin: 0 0 6px;
  background: var(--accent-soft);
  border: 1px solid var(--ember);
  border-radius: var(--radius);
  color: var(--type);
  font-size: 13px;
  font-weight: 600;
}
.pilot-banner[hidden] { display: none !important; }
.shell.is-agent-pilot #tab-market,
.shell.is-agent-pilot #tab-chart .target-actions,
.shell.is-agent-pilot #tab-yard .crew-actions,
.shell.is-agent-pilot #tab-yard .yard-row .chip,
.shell.is-agent-pilot #tab-dock .dock-actions {
  pointer-events: none;
  opacity: 0.55;
}
.shell.is-agent-pilot #btn-take-stick,
.shell.is-agent-pilot [data-pilot-pick],
.shell.is-agent-pilot [data-theme-pick],
.shell.is-agent-pilot #btn-reset {
  pointer-events: auto;
  opacity: 1;
}

/* Captain agent action log (spectator feed) */
.agent-action-log {
  max-height: 10rem;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.4;
  padding: 8px;
  margin: 6px 0 12px;
  background: var(--wall);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
}
.agent-action-log .agent-act {
  margin: 0 0 4px;
  color: var(--dim);
}
.agent-action-log .agent-act .op {
  color: var(--type);
  font-weight: 600;
  margin-right: 6px;
}


/* Captain prefs */
.pref-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 4px;
  cursor: pointer;
  user-select: none;
}
.pref-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--ember, #e86);
}
body.bridge-mode #ver::after {
  content: " · bridge";
  opacity: 0.65;
  font-weight: 500;
}

/* Dock Press */
.press-edition {
  margin-top: 10px;
  font-size: 13px;
  background: var(--wall);
  border: 1px dashed var(--line);
  padding: 10px;
}
.press-edition ul {
  margin: 8px 0 0;
  padding-left: 1.1em;
}
.press-edition li { margin-bottom: 6px; color: var(--type); }


/* Market buy/avoid cues */
.row { border-left: 3px solid transparent; }
.row.cue-buy { border-left-color: #2FA4A0; }
.row.cue-avoid { border-left-color: #C44C4C; }
.row.cue-fair { border-left-color: var(--line); }
.cue-label { font-size: 11px; font-weight: 700; letter-spacing: 0.03em; margin-top: 2px; }
.cue-label--buy { color: #2FA4A0; }
.cue-label--avoid { color: #C44C4C; }
.cue-label--fair { color: var(--mute); }

/* Short / cramped viewports */
@media (max-height: 720px) {
  .shell { gap: 4px; padding-top: calc(4px + var(--safe-t)); }
  .status-strip { padding: 6px 4px; }
  .map-wrap { max-height: min(38dvh, 420px); }
  .log { min-height: 2.4em; padding: 8px; margin: 6px 0 8px; }
  .panel h2 { margin-bottom: 4px; }
}
@media (max-height: 560px) {
  .map-wrap { max-height: min(32dvh, 280px); }
  .brand span, #ver { display: none; }
  .hint { margin-bottom: 4px; }
}
.shell {
  max-height: 100dvh;
  box-sizing: border-box;
}

.press-edition .press-link {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 0.15rem 0;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.press-edition .press-link:hover,
.press-edition .press-link:focus-visible {
  color: var(--ember, #e8a06a);
}

.waypoint-list { margin-top: 0.4rem; }
.waypoint-list button.wp-jump {
  margin: 0 0.25rem 0.25rem 0;
}

.skills-box { display: flex; flex-wrap: wrap; gap: 0.35rem 0.75rem; margin: 0.35rem 0 0.75rem; }
.skills-box span { white-space: nowrap; }

.skill-bar { display: grid; grid-template-columns: 5.5rem 1fr 3.6rem; gap: 0.4rem; align-items: center; width: 100%; font-size: 0.78rem; }
.skill-id { text-transform: capitalize; opacity: .85; }
.skill-track { height: 7px; border-radius: 99px; background: color-mix(in srgb, currentColor 18%, transparent); overflow: hidden; }
.skill-fill { display: block; height: 100%; border-radius: 99px; background: currentColor; }
.skill-n { text-align: right; font-variant-numeric: tabular-nums; opacity: .8; }
.crew-card { font-size: 0.78rem; opacity: .85; margin: 0.15rem 0; }

.chart-find { display: flex; gap: 8px; margin: 0 0 8px; }
.chart-find input {
  flex: 1; min-width: 0; padding: 8px 10px; border-radius: 8px;
  border: 1px solid color-mix(in srgb, currentColor 28%, transparent);
  background: color-mix(in srgb, currentColor 6%, transparent);
  color: inherit; font: inherit;
}
@media (min-height: 780px) {
  .map-wrap { min-height: min(46dvh, 560px); }
}
