:root {
  --bg: #080b11;
  --bg2: #0d1219;
  --panel: #10161f;
  --panel2: #161e2a;
  --line: #222c3b;
  --line2: #2f3d52;
  --text: #dfe6ef;
  --muted: #7b889b;
  --dim: #4a5566;

  /* one action color: bright = you can do this now */
  --act: #f0a63c;
  --act-hi: #ffbe5c;
  --act-ink: #1b1206;
  --off: #1f2632;
  --off-ink: #5d6878;

  --good: #5fd38d;
  --warn: #ffcc4d;
  --sev1: #f1e8a6; --sev2: #d8a623; --quiet: #8590a0; --story: #c9a7ff;   /* chat: notices, warnings, quiet outage news, story beats */
  --bad: #ff5f6d;
  --tan: #7fe3c4;
  --margin: #ff9bd2;
  --remote-ink: #d3b8ff;
  --remote-line: #9270c7;
  --remote-bg: #231635;

  /* one color per resource, used everywhere that resource appears */
  --c-credits: #e9c46a;
  --c-parts: #a9b8c9;
  --c-water: #4fb7ff;
  --c-h2: #b18cff;
  --c-power: #ffd84d;
  --c-heat: #ff7a45;
  --c-mun: #ff9f6b;
  --c-def: #5fd3b0;
  --c-rep: #f1f1f1; --c-med: #ff8f8f; --oscar: #f0b36a;

  --radius: 10px;
  --mono: "Cascadia Mono", "Consolas", "SFMono-Regular", Menlo, monospace;
  --sans: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --heading: "Bahnschrift", "Segoe UI", sans-serif;
  --topbar: rgba(8, 11, 17, .94);
  --hover: #1c2635; --hover-line: #4a6283; --active-bg: #2a2312;
  --chart-bg: #080b11;
  --bp-bg: #0c2c4d; --bp-ink: #e6f7ff; --bp-line: #9fe4ff;
  --bp-grid: #1f5d91; --bp-grid-minor: #174a78; --bp-muted: #8fc7e8;
  --bp-active: #155a8f;
}
:root[data-ui-theme="terminal"] {
  --bg: #07120d; --bg2: #0b1b13; --panel: #10251a; --panel2: #173322;
  --line: #244733; --line2: #37674b; --text: #d5f3d8; --muted: #94b69e; --dim: #73947d;
  --act: #86d69c; --act-hi: #b2f0c1; --act-ink: #092314; --off: #182a1e; --off-ink: #71947b;
  --good: #8ce0a8; --warn: #e4ca83; --bad: #ff9a86; --tan: #a2edb4; --margin: #e8d593;
  --remote-ink: #b9d8f0; --remote-line: #719bb9; --remote-bg: #142c39;
  --sans: "Consolas", "Courier New", monospace; --mono: "Courier New", monospace; --heading: "Consolas", monospace;
  --topbar: #07120df0; --hover: #1c402a; --hover-line: #7aa68a; --active-bg: #244633;
  --bp-bg: #0b2417; --bp-ink: #dcf7dd; --bp-line: #81c89c; --bp-grid: #234d34; --bp-grid-minor: #173b26;
  --bp-muted: #96bfa3; --bp-active: #2b5a3a;
}
:root[data-ui-theme="parchment"] {
  --bg: #e9dfcb; --bg2: #f8f0df; --panel: #f3ead6; --panel2: #e7dbc2;
  --line: #c9b99a; --line2: #ac9874; --text: #322b22; --muted: #655746; --dim: #766955;
  --act: #2c6b67; --act-hi: #225853; --act-ink: #fff8e9; --off: #ded3be; --off-ink: #796f60;
  --sev1: #857a25; --sev2: #8d6208; --quiet: #8a8070; --story: #6b4aa0;
  --good: #276548; --warn: #85500f; --bad: #a02f35; --tan: #22645d; --margin: #80425b;
  --remote-ink: #5d427b; --remote-line: #8568a2; --remote-bg: #e8dcf0;
  --c-credits: #805a16; --c-parts: #5c5143; --c-water: #23648a; --c-h2: #6d4a8b;
  --c-power: #85620e; --c-heat: #a44823; --c-mun: #87501d; --c-def: #2c705c; --c-rep: #4d473f; --c-med: #a3342f; --oscar: #8a5a1c;
  --sans: "Georgia", "Palatino Linotype", serif; --mono: "Courier New", monospace; --heading: "Georgia", serif;
  --topbar: #f3ead6f5; --hover: #e5d5b7; --hover-line: #8b7553; --active-bg: #d7e3d8;
  --bp-bg: #ece3cf; --bp-ink: #362d22; --bp-line: #6d5a3d; --bp-grid: #c3b296; --bp-grid-minor: #d6c9b1;
  --bp-muted: #6c5c45; --bp-active: #c3d7cf;
}
:root[data-ui-theme="orbital"] {
  --bg: #100e1b; --bg2: #171323; --panel: #1d182f; --panel2: #29213d;
  --line: #3b3052; --line2: #55426f; --text: #ece5fb; --muted: #b5a6cc; --dim: #9687b0;
  --act: #b8a0f0; --act-hi: #d4c0ff; --act-ink: #211333; --off: #2a2338; --off-ink: #978ba9;
  --good: #82d6bd; --warn: #f4c782; --bad: #fa93b0; --tan: #9edccc; --margin: #e1a1df;
  --remote-ink: #a3e1f2; --remote-line: #6896bb; --remote-bg: #162e47;
  --sans: "Trebuchet MS", "Verdana", sans-serif; --mono: "Lucida Console", "Monaco", monospace; --heading: "Trebuchet MS", sans-serif;
  --topbar: #100e1bf2; --hover: #382a4d; --hover-line: #8b71b0; --active-bg: #3c2b55;
  --bp-bg: #201a36; --bp-ink: #eee5ff; --bp-line: #ac98dd; --bp-grid: #413456; --bp-grid-minor: #302740;
  --bp-muted: #b7a8cc; --bp-active: #483266;
}
* { box-sizing: border-box; }
/* min-height, not height: a body fixed at one screen tall ends where the screen does, and anything
   sticky inside it (the top bar, the pinned 3D view) is carried off once you scroll past that */
html { height: 100%; }
body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }

button {
  font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line2);
  border-radius: 8px; padding: 7px 12px; cursor: pointer; transition: background .12s, border-color .12s, transform .05s;
}
button:hover:not(:disabled) { border-color: var(--hover-line); background: var(--hover); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { background: var(--off); color: var(--off-ink); border-color: var(--line); cursor: not-allowed; }
button.primary { background: var(--act); color: var(--act-ink); border-color: var(--act); font-weight: 700; }
button.primary:hover:not(:disabled) { background: var(--act-hi); border-color: var(--act-hi); }
button.primary:disabled { background: var(--off); color: var(--off-ink); border-color: var(--line); font-weight: 600; }
button.ghost { background: transparent; }
button.small { padding: 4px 9px; font-size: 12px; }
button.on { border-color: var(--good); color: var(--good); }
button.danger { border-color: var(--bad); color: var(--bad); background: transparent; }
input[type="text"], input[type="number"], input[type="password"] { font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--line2); border-radius: 8px; padding: 7px 10px; width: 100%; }
select { font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--line2); border-radius: 8px; padding: 7px 10px; max-width: 100%; }
.modal-box select { width: 100%; }
input[type="range"] { width: 100%; accent-color: var(--act); }
input[type="color"] { width: 38px; height: 30px; border: 1px solid var(--line2); border-radius: 6px; background: none; padding: 1px; cursor: pointer; }
a { color: var(--c-water); }
.muted { color: var(--muted); }
.small-note { font-size: 12px; color: var(--muted); margin-top: 8px; }
.warnline { font-size: 12px; color: var(--warn); margin-top: 6px; min-height: 0; }
.hidden { display: none !important; }
.ta { width: 100%; height: 140px; background: var(--bg2); color: var(--text); border: 1px solid var(--line2); border-radius: 8px; font: 11px var(--mono); }

/* ---------- top bar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px;
  padding: 8px 16px; background: var(--topbar); border-bottom: 1px solid var(--line); backdrop-filter: blur(6px);
}
.brand { font-weight: 900; letter-spacing: .18em; font-size: 14px; white-space: nowrap; }
.brand-mark { color: var(--act); }
/* salvage bot rings (Ore Hold) */
.bot-rings { display: flex; flex-wrap: wrap; gap: 10px; }
.bot-ring { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px; background: none; border: 1px solid transparent; border-radius: 10px; cursor: pointer; }
.bot-ring:hover, .bot-ring:focus-visible { border-color: var(--line2); background: var(--panel); }
.bot-ring svg { width: 40px; height: 40px; transform: rotate(-90deg); }
.br-track { fill: none; stroke: #ffffff14; stroke-width: 4; }
.br-fill { fill: none; stroke-width: 4; stroke-linecap: round; transition: stroke-dashoffset .1s linear; }
.br-num { font: 600 12px var(--mono); fill: var(--text); transform: rotate(90deg); transform-origin: 20px 20px; }
.br-lbl { font: 10px var(--mono); color: var(--muted); }
.bot-ring.idle .br-fill { stroke: #ffffff30 !important; }
.bot-ring.idle .br-num { fill: var(--dim); }
.reduce-motion .br-fill { transition: none; }
.bot-ring.jam { border-color: var(--bad); background: #ff5f6d14; }
.bot-ring.jam .br-track { stroke: #ff5f6d55; }
.bot-ring.jam .br-fill { stroke: var(--bad) !important; }
.bot-ring.jam .br-num { fill: var(--bad); }
.bot-ring.jam .br-lbl { color: var(--bad); font-weight: 700; }
.bot-ring.jam:not(.whack) svg { animation: jam-shake 1.6s infinite; }
.bot-ring.whack svg { animation: whack .18s; }
@keyframes jam-shake { 0%, 88%, 100% { transform: rotate(-90deg); } 92% { transform: rotate(-96deg); } 96% { transform: rotate(-84deg); } }
@keyframes whack { 50% { transform: rotate(-90deg) scale(.86); } }
.reduce-motion .bot-ring svg { animation: none !important; }
.hold-stats { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 10px; font-size: 12px; }
.popover { position: fixed; z-index: 60; min-width: 220px; max-width: 280px; padding: 10px 12px; background: var(--bg2); border: 1px solid var(--line2); border-radius: 10px; box-shadow: 0 8px 24px #0009; }
.pop-h { font-weight: 700; margin-bottom: 2px; }
.pop-st { font-size: 12px; margin-bottom: 8px; }
.pop-jobs { display: grid; gap: 4px; margin-bottom: 6px; }
.pop-jobs button { display: flex; flex-direction: column; align-items: stretch; gap: 2px; text-align: left; }
.pj-top { display: flex; align-items: center; gap: 8px; }
.pj-top .muted { margin-left: auto; font: 11px var(--mono); }
.pj-traits { font: 10.5px var(--mono); line-height: 1.3; color: var(--muted); white-space: pre; }
.pop-jobs .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
/* Stow Bay 1 */
.bay-layout { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.bay-col { flex: none; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.bay-side { flex: 1 1 240px; min-width: 0; }
.bay-grid { display: grid; grid-template-columns: repeat(5, 22px); grid-auto-rows: 22px; gap: 2px; padding: 4px; border: 2px solid var(--line2); border-radius: 6px; background: #00000040; }
.bay-grid i { display: block; border-radius: 2px; }
.bay-grid i.open { background: #ffffff08; box-shadow: inset 0 0 0 1px #ffffff12; }
.bay-grid i.full { background: var(--ic); cursor: pointer; }
.bay-grid i.moving { background: repeating-linear-gradient(45deg, var(--ic) 0 3px, transparent 3px 6px); opacity: .8; }
.bay-grid i.self { opacity: .3; }
.bay-grid.placing i { cursor: crosshair; }
.bay-grid i.ghost-ok { box-shadow: inset 0 0 0 2px #7dff9c; background: #7dff9c55; }
.bay-grid i.ghost-bad { box-shadow: inset 0 0 0 2px var(--bad); background: #ff5f6d66; }
.bay-doors { font-size: 10px; letter-spacing: .1em; }
.place-bar { border: 1px solid var(--act); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; background: #ffffff06; }
.place-bar .row { margin-top: 6px; }
.order-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12px; }
.bi-ord { font: 700 11px var(--mono); color: var(--muted); min-width: 14px; }
.bi-acts { margin-top: 6px; gap: 4px; }
.bay-item.flash { animation: item-flash .6s; }
@keyframes item-flash { 30% { box-shadow: 0 0 0 2px var(--ic); } }
.bay-item, .buoy { border: 1px solid var(--line); border-left: 3px solid var(--ic); border-radius: 8px; padding: 8px 10px; margin-top: 8px; background: var(--panel); }
.bi-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bi-sw { width: 10px; height: 10px; border-radius: 2px; background: var(--ic); display: inline-block; flex: none; }
.bi-meta { font: 11px var(--mono); margin-left: auto; }
.bi-mix { font: 11px var(--mono); margin: 2px 0 6px; }
.bi-add { font-weight: 700; padding: 2px 10px; }
.tag { font-size: 10px; border: 1px solid var(--line2); border-radius: 4px; padding: 0 5px; color: var(--muted); }
.ring-row { margin-top: 10px; }
.ring-row:first-child { margin-top: 0; }
.ring-h { font-size: 12px; margin-bottom: 4px; }
.buoy-slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(230px, 100%), 1fr)); gap: 8px; }
.buoy { margin-top: 0; }
.buoy .row { margin-top: 4px; }
.buoy.empty { border-style: dashed; border-left-width: 1px; color: var(--dim); font-size: 12px; display: flex; align-items: center; justify-content: center; min-height: 44px; background: none; }
.sect { display: flex; align-items: center; gap: 8px; font-size: 11px; margin-bottom: 4px; }
.sect .track { flex: 1; height: 5px; background: #0008; border-radius: 3px; overflow: hidden; }
.sect .track i { display: block; height: 100%; width: 0; background: #7fd0f5; }
.bot-ring.grey .br-track { stroke: #ffffff40; stroke-dasharray: 3 3; }
.bot-ring.grey .br-lbl { color: var(--warn); }
/* Workshop printer: one card per named part, and the stores */
.recipes { display: grid; gap: 8px; }
.recipe { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--panel); }
.rc-name { display: flex; align-items: center; gap: 8px; }
.rc-icon { font-size: 15px; width: 18px; text-align: center; color: var(--c-parts); }
.rc-have { margin-left: auto; font: 12px var(--mono); color: var(--muted); }
.rc-opts { font: 11.5px var(--mono); margin: 3px 0 6px 26px; }
.rc-opts i { font-style: normal; color: var(--dim); }
.rc-acts { margin-left: 26px; gap: 10px; }
.rc-acts label { font-size: 12px; }
.rc-acts input { width: 56px; padding: 2px 6px; }
.stores { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.st-h { font-size: 12px; font-weight: 700; margin-bottom: 4px; }
.st-row { display: flex; justify-content: space-between; font-size: 12px; padding: 2px 0; border-bottom: 1px solid var(--line); }
.st-row b { font: 12px var(--mono); }
/* Dock: the Pier, expansion bays */
.dock-wrap > .box { min-width: 0; }
.dock-wrap > .box > h3 { flex-wrap: wrap; }
.dock-wrap section + section { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; }
.dock-wrap section > h4 { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 8px; margin: 0 0 8px; font-size: 13px; }
.dock-wrap h4 .right { margin-left: auto; font-weight: 400; }
.pier-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 12.5px; }
.pier-row:first-child { border-top: none; }
.pier-row.on b { color: var(--act); }
.pier-row .muted { font-size: 12px; }
.pier-bot-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 12px; }
.pier-bot-row progress { width: 64px; height: 6px; accent-color: var(--act); }
#dock-fittings { display: grid; gap: 6px; }
.dock-fitting { display: grid; grid-template-columns: 48px minmax(0, 1fr); align-items: center; gap: 8px; }
.dock-fitting label { color: var(--muted); font-size: 12px; }
.dock-fitting select { width: 100%; min-width: 0; text-overflow: ellipsis; }
.pr-icon { color: var(--muted); }
.pr-act { margin-left: auto; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.spire-scroll { margin-top: 12px; max-height: 420px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; background: #0a1420; }
.spire-plan { --spire-label: #d9e7eb; --spire-note: #94b3c7; display: block; width: 100%; max-width: 640px; height: auto; margin: 0 auto; font-family: var(--mono); }
.spire-plan .bp-datum { stroke: #94c8df; }
.spire-project { padding: 12px 0; margin-bottom: 8px; border-bottom: 1px solid var(--line); }
.spire-project .row { justify-content: space-between; }
.spire-project b { font-size: 12px; color: var(--muted); }
.spire-project .c { margin-top: 8px; }
/* Bridge: one button per trip job */
.trip-jobs { display: grid; gap: 6px; margin-top: 10px; }
.trip-job { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.trip-job .muted { font-size: 12px; }
.trip-job .warnline { flex-basis: 100%; margin-top: 0; }
/* Stasis: the whole game greys out, STASIS blinks over it, the timer in the top bar counts */
.stasis-timer { font: 700 12px var(--mono); color: #9fe4ff; background: #0d2a44; border: 1px solid #3f86b8; border-radius: 6px; padding: 3px 10px; cursor: pointer; white-space: nowrap; }
.stasis-timer.over { color: var(--good, #7dff9c); border-color: currentColor; cursor: default; }
body.in-stasis #layout { filter: grayscale(1) brightness(.5); pointer-events: none; user-select: none; }
.stasis-overlay { position: fixed; inset: var(--top-h) 0 0 0; z-index: 15; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.stasis-overlay { flex-direction: column; gap: 18px; }
.stasis-overlay p { margin: 0; max-width: min(620px, 90vw); text-align: center; font: 14px/1.45 var(--mono); color: #cfefff; background: #0d2a44cc; border: 1px solid #3f86b8; border-radius: 8px; padding: 10px 14px; }
.stasis-overlay div { font: 900 72px var(--heading); letter-spacing: .4em; color: #9fe4ff; text-shadow: 0 0 24px #3fb6ff; animation: stasis-blink 2.4s ease-in-out infinite; }
@keyframes stasis-blink { 0%, 100% { opacity: .85; } 50% { opacity: .2; } }
.reduce-motion .stasis-overlay div { animation: none; opacity: .7; }
/* Dust Thermal Tank readout */
.tank-lab { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; margin-bottom: 4px; }
.tank-lab b { font: 11px var(--mono); color: var(--muted); font-weight: 400; }
.tank-row { display: flex; align-items: center; gap: 10px; }
.tank-row .track { flex: 1; height: 10px; background: #0008; border-radius: 5px; overflow: hidden; }
.tank-row .track i { display: block; height: 100%; transition: width .3s, background .6s; }
.tank-temp { font: 700 15px var(--mono); min-width: 74px; text-align: right; }
/* Ore Hold */
.ore-capacity { width: max-content; }
.lower-deck-column > section + section { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 14px; }
.hold-tabs { display: flex; flex-wrap: wrap; flex: none; gap: 6px; margin-bottom: 12px; }
.hold-tabs button[aria-selected="true"] { border-color: var(--act); color: var(--act-hi); background: var(--active-bg); }
.salvage-bot { display: flex; align-items: center; gap: 8px; }
.bay-grid.tether-slots { grid-template-columns: repeat(2, 22px); width: max-content; margin: 6px 0; }
.tether-slots i.full { display: grid; place-items: center; color: #10151c; font: 700 10px var(--mono); cursor: default; }
.buoy-load { border-top: 1px solid var(--line); margin-top: 7px; padding-top: 6px; }
/* assign-bots popover */
.popover.assign { min-width: 280px; max-width: 340px; }
.assign-list { display: grid; gap: 4px; max-height: 260px; overflow: auto; margin: 6px 0 8px; }
.assign-row { display: flex; gap: 8px; align-items: center; justify-content: flex-start; text-align: left; }
.assign-row .muted { margin-left: auto; font-size: 11px; }
.assign-row.on { border-color: var(--act); }
.ar-box { width: 14px; height: 14px; border: 1px solid var(--line2); border-radius: 3px; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; flex: none; }
.assign-confirm { font-size: 12px; padding: 4px 6px; display: flex; gap: 8px; align-items: center; background: #ffb34714; border-radius: 6px; }
.names-grid { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center; max-width: 360px; }
.names-grid label { margin: 0; }
.brand-wrap { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.captain-line { font: 11px var(--sans); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; padding-left: 1.3em; }
.resbar { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.res {
  display: flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line);
  font: 12px var(--mono); white-space: nowrap; border-left: 3px solid var(--rc);
}
.res .ico { color: var(--rc); font-size: 12px; }
.res .lbl { font: 11px var(--sans); color: var(--muted); }
.res .bar { width: 36px; height: 4px; border-radius: 3px; background: #0008; overflow: hidden; }
.res .bar > i { display: block; height: 100%; background: var(--rc); }
.res-base { align-self: center; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 2px; font: 700 11px var(--sans); letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.res.warn { border-color: var(--warn); border-left-color: var(--warn); }
.res.bad { border-color: var(--bad); border-left-color: var(--bad); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 3px #ff5f6d33; } }
.top-right { display: flex; align-items: center; gap: 8px; }
.clock { font: 12px var(--mono); color: var(--muted); white-space: nowrap; }
.build { font: 11px var(--mono); color: var(--dim); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }

/* ---------- layout ---------- */
#layout { display: flex; flex-direction: column; gap: 16px; padding: 16px; margin: 0 auto; }
#workspace { min-width: 0; display: flex; flex-direction: column; gap: 12px; }
/* --top-h is the top bar's real height, measured in ui.js (it wraps onto more rows on narrow screens) */
:root { --top-h: 62px; }
.control-surface { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 16px; height: clamp(440px, 60vh, 700px); min-width: 0; }
#ai-panel {
  min-width: 0; min-height: 0; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}

/* Both windows stay together while room controls scroll on taller desktop screens. */
@media (min-height: 850px) and (min-width: 761px) {
  .control-surface { position: sticky; top: calc(var(--top-h) + 12px); z-index: 6; background: var(--bg); box-shadow: 0 10px 14px -10px #000c; }
}
/* ---------- shared visual display: 3D or location map ---------- */
.stage { display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; padding: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.display-tabs { display: flex; gap: 6px; flex: none; }
.display-tabs button { min-width: 64px; }
.display-tabs button.active { border-color: var(--act); color: var(--act-hi); background: var(--active-bg); }
.display-tabs button:focus-visible { outline: 2px solid var(--act); outline-offset: 2px; }
.stage > .viewer, .stage > .locbox { flex: 1 1 0; min-height: 0; }
/* Landscape exposes the same two visual panels as separate grid columns.
   Fractions divide the space after padding and gaps: 25% AI, 37.5% each visual. */
@media (min-width: 761px) and (orientation: landscape) {
  :root { --surface-height: min(360px, 40vh); }
  .control-surface {
    height: var(--surface-height); max-height: var(--surface-height);
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr) minmax(0, 3fr);
  }
  .stage { display: contents; }
  .display-tabs { display: none; }
  .stage > .locbox { padding: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
  /* Fit a true 16:9 canvas inside the fixed-height pane, allowing for its border.
     The canvas observer resizes the renderer and camera to these dimensions. */
  .stage > .viewer .viewer-canvas {
    inset: auto; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: min(100%, calc((var(--surface-height) - 2px) * 16 / 9));
    height: auto; max-height: 100%; aspect-ratio: 16 / 9;
  }
}
.viewer { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: #04060b; min-height: 0; }
.viewer-canvas { position: absolute; inset: 0; cursor: grab; touch-action: none; }
.viewer-canvas:active { cursor: grabbing; }
.viewer-hud { position: absolute; left: 12px; top: 12px; right: 130px; pointer-events: none; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.chip { font: 12px var(--mono); background: var(--panel); border: 1px solid var(--line2); padding: 4px 10px; border-radius: 999px; }
.hud-progress { width: 220px; max-width: 100%; height: 4px; background: #ffffff15; border-radius: 3px; overflow: hidden; }
.hud-progress > div { height: 100%; width: 0; background: var(--act); transition: width .2s linear; }
.viewer-btn { position: absolute; right: 12px; top: 12px; background: var(--panel); }
.viewer-hint { position: absolute; right: 12px; bottom: 8px; font-size: 11px; color: #ffffff4d; pointer-events: none; }

.locbox { display: flex; flex-direction: column; gap: 6px; min-height: 0; }
.loc-tabs { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.loc-tabs button { padding: 2px 10px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.loc-tabs button.active { border-color: var(--act); color: var(--act-hi); background: var(--active-bg); }
.loc-tabs button.remote-link { color: var(--remote-ink); }
.loc-tabs button.remote-link.active { border-color: var(--remote-line); background: var(--remote-bg); }
.loc-where { margin-left: auto; font-size: 11px; color: var(--muted); text-align: right; }
.loc-where b { color: var(--text); font-weight: 600; }
.loc-where.remote-link { color: var(--remote-ink); }
.locmap { flex: 1; width: 100%; min-height: 0; border-radius: 6px; background: var(--bp-bg); }

/* blueprint sheet */
.bp-title { font: 700 13px "Bahnschrift", "DIN Alternate", "Segoe UI", sans-serif; letter-spacing: .12em; fill: #e6f7ff; }
.bp-subtitle { font: 400 8.5px "Bahnschrift", "Segoe UI", sans-serif; letter-spacing: .16em; fill: #9fd8f5; }
.bp-status { font: 600 7.5px var(--sans); letter-spacing: .06em; fill: #ffc861; }
.bp-tk { font: 600 6.5px "Bahnschrift", "Segoe UI", sans-serif; letter-spacing: .08em; fill: #cfefff; }
.bp-tv { font: 400 6.5px var(--sans); fill: #e6f7ff; }
.bp-lbl { font-family: "Bahnschrift", "Segoe UI", sans-serif; font-weight: 600; letter-spacing: .06em; fill: #e6f7ff; pointer-events: none; }
.bp-dim { font: 400 5.5px var(--sans); fill: #8fc7e8; pointer-events: none; }
.bp-note { font: 600 5px "Bahnschrift", "Segoe UI", sans-serif; letter-spacing: .1em; fill: #8fc7e8; pointer-events: none; }
.bp-dimline { stroke: #9fe4ff; stroke-width: 0.7; fill: none; }
.bp-dimtxt { font: 500 7px "Bahnschrift", "Segoe UI", sans-serif; fill: #e6f7ff; }
.bp-scale { stroke: #9fe4ff; stroke-width: 0.9; }
.bp-datum { stroke: var(--bp-line); stroke-width: 1.2; }
.bp-wall { fill: none; stroke: #9fe4ff; stroke-width: 3; stroke-linejoin: miter; }
.bp-wallcore { fill: none; stroke: #0c2c4d; stroke-width: 1; stroke-linejoin: miter; }
.bp-hullband { fill: #0f3a63; }
.bp-hullline { fill: none; stroke: #bfefff; stroke-width: 1.6; }
.bp-gap { stroke: #103f6b; stroke-width: 4.2; }
.bp-jamb { stroke: #9fe4ff; stroke-width: 0.9; }
.bp-hidden { fill: none; stroke: #6fb8e0; stroke-width: 0.8; stroke-dasharray: 3 2; }
.bp-thin { stroke: #9fe4ff; stroke-width: 0.6; }
.bp-fin { fill: #0f3a63; stroke: #9fe4ff; stroke-width: 0.7; }
.bp-bell { fill: #0f3a63; stroke: #bfefff; stroke-width: 1; }
.bp-furn { fill: none; stroke: #7fd0f5; stroke-width: 0.7; pointer-events: none; }
.bp-thumb { fill: none; stroke: #9fe4ff; stroke-width: 0.8; }
.bp-pip { fill: #ffb347; }
.bp-stamp { font: 800 30px "Bahnschrift", "Segoe UI", sans-serif; letter-spacing: .25em; fill: #ffc861; opacity: .18; pointer-events: none; }
.bp-click { cursor: pointer; }
.bp-click:not(.sealed):hover .bp-fill { fill: #12497a; }
.bp-room.cur .bp-lbl { fill: #fff3c4; }
.bp-paper { fill: var(--bp-bg); }
.bp-title, .bp-tv, .bp-lbl { fill: var(--bp-ink); font-family: var(--heading); }
.bp-subtitle, .bp-tk, .bp-status, .bp-note, .bp-dimtxt, .bp-stamp { font-family: var(--heading); }
.bp-status, .bp-stamp, .bp-pip { fill: var(--warn); }
.bp-subtitle, .bp-tk, .bp-dim, .bp-note, .bp-dimtxt { fill: var(--bp-muted); }
.bp-grid-minor { stroke: var(--bp-grid-minor); }
.bp-grid-major { stroke: var(--bp-grid); }
.bp-frame, .bp-wall, .bp-hullline, .bp-scale, .bp-dimline, .bp-jamb, .bp-hidden, .bp-thin { stroke: var(--bp-line); }
.bp-wallcore, .bp-gap { stroke: var(--bp-bg); }
.bp-room:not(.sealed):not(.cur) > .bp-fill { fill: var(--bp-bg); }
.bp-room.cur:not(.sealed) > .bp-fill { fill: var(--bp-active); }
.bp-room.cur .bp-lbl { fill: var(--bp-ink); }
.bp-room:not(.sealed):hover > .bp-fill { fill: var(--bp-active); }
.bp-remote .bp-paper,
.bp-remote .bp-room:not(.sealed) > .bp-fill { fill: var(--remote-bg); }
.bp-remote .bp-grid-minor { stroke: var(--remote-line); opacity: .25; }
.bp-remote .bp-grid-major { stroke: var(--remote-line); opacity: .4; }
.bp-remote .bp-frame { stroke: var(--remote-line); }
.bp-remote .bp-status { fill: var(--remote-ink); }
.bp-remote .bp-wallcore { stroke: var(--remote-bg); }
.bp-remote .bp-room-glow { fill: var(--remote-line); }
.bp-remote .bp-room.cur:not(.sealed) > .bp-fill { fill: var(--bp-active); }
.bp-remote .bp-click:not(.sealed):hover > .bp-fill { fill: var(--bp-active); }
.bp-no-contact { filter: grayscale(1); opacity: .6; }
[data-sheet].no-contact { color: var(--muted); background: #25282d; border-color: #51555c; }
.sheet-modal { width: min(1100px, 96vw) !important; padding: 12px !important; }
.sheet-modal svg { width: 100%; height: auto; display: block; border-radius: 8px; }

/* ---------- room header & panel ---------- */
.room-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; padding: 2px 2px 0; }
.rh-name { font-size: 20px; font-weight: 800; letter-spacing: .02em; }
.rh-tag { font: 700 10px var(--mono); letter-spacing: .12em; color: var(--c-water); border: 1px solid var(--c-water); border-radius: 4px; padding: 1px 5px; vertical-align: middle; }
.rh-desc { color: var(--muted); font-size: 13px; }
.panel { display: flex; flex-direction: column; gap: 12px; }
.panel.remote .box:not(.sealed-box) { border-color: var(--remote-line); }
.panel.no-contact .box { color: #b5b8bd; background: #202329; border-color: #51555c; }
/* Highlighted so it can't be missed: remote-control purple while linked, alert red once the link is lost */
.link-remote { margin-left: auto; font: 700 10px var(--mono); letter-spacing: .12em; padding: 3px 10px; border: 1px solid; border-radius: 999px; white-space: nowrap; color: var(--remote-ink); background: var(--remote-bg); border-color: var(--remote-line); box-shadow: 0 0 8px -2px var(--remote-line); }
.link-remote.no-contact { color: var(--bad); background: #ff5f6d1f; border-color: var(--bad); box-shadow: 0 0 8px -2px var(--bad); }
.link-remote:not(.hidden) + #ai-control-mode { margin-left: 8px; }
:root[data-ui-theme="parchment"] [data-sheet].no-contact,
:root[data-ui-theme="parchment"] .panel.no-contact .box { color: #42454b; background: #d7d8da; border-color: #91959b; }
.box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.box h3 { margin: 0 0 10px; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 700; display: flex; align-items: center; gap: 8px; }
.box h3 .right { margin-left: auto; letter-spacing: 0; text-transform: none; font-weight: 400; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13px; }
.kv .k { color: var(--muted); }
.kv .v { font-family: var(--mono); text-align: right; }

.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.act { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 12px 14px; text-align: left; min-height: 62px; border-left: 3px solid var(--act); }
.act:disabled { border-left-color: var(--line); }
.act b { font-size: 14px; }
.act span { font: 11px var(--mono); color: var(--muted); }
.act.flash { animation: flash .25s; }
@keyframes flash { from { background: #3a3220; } }

.meter { margin: 6px 0 10px; }
.meter .lab { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 4px; gap: 8px; }
.meter .lab b { color: var(--text); font: 12px var(--mono); text-align: right; }
.meter .track { height: 8px; border-radius: 4px; background: #0008; overflow: hidden; position: relative; }
.meter .track > i { display: block; height: 100%; border-radius: 4px; transition: width .25s; }
.meter .track > .mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: #fff9; }

.pipe { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; gap: 6px; align-items: center; }
.pipe > div:not(.arrow) { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; text-align: center; }
.pipe .arrow { color: var(--dim); font-size: 18px; }
.pipe .n { font: 600 16px var(--mono); }
.pipe .n.sm { font-size: 13px; }
.pipe .l { font-size: 11px; color: var(--muted); }
.pipe .r { font: 10px var(--mono); color: var(--muted); }

.upgs { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.workshop-toolbar { display: flex; align-items: end; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.workshop-picker { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: min(220px, 100%); }
.workshop-picker label { font-size: 12px; color: var(--muted); }
.workshop-picker select { width: 100%; font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--line2); border-radius: 7px; padding: 8px 10px; }
.workshop-pager { display: flex; align-items: center; gap: 12px; }
.workshop-pager output { min-width: 4ch; text-align: center; font: 12px var(--mono); }
.workshop-card { margin: 14px 0 0; }
.workshop-card > .upg { padding: 14px; gap: 10px; }
/* Workshop card template: header, where, description, now/after, materials, special requirements, actions */
.wcard .wc-where, .wcard .wc-crow, .wcard .wc-row { display: grid; grid-template-columns: 4.6em minmax(0, 1fr); gap: 4px 8px; align-items: baseline; }
.wcard .wc-where { font-size: 12px; }
.wcard .wc-rl { font: 10px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.wcard .wc-desc { line-height: 1.45; }
.wcard .wc-change { display: grid; gap: 3px; padding: 8px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); font: 12px var(--mono); }
.wcard .wc-pct { color: var(--act-hi); font-weight: 700; white-space: nowrap; }
.wcard .wc-h { font: 700 10px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: 5px; }
.wcard .wc-mats { display: grid; gap: 4px; }
.wcard .wc-row { grid-template-columns: 4.6em repeat(3, minmax(0, 1fr)); align-items: center; }
.wcard .wc-special { border: 1px solid var(--story); border-radius: 8px; background: #c9a7ff10; padding: 8px 10px; }
.wcard .wc-special .wc-h { color: var(--story); }
.wcard .wc-special ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; font-size: 12px; }
.wcard .wc-special li { display: flex; gap: 6px; }
.wcard .wc-special li.ok, .wcard .wc-special li.bonus { color: var(--good); }
.wcard .wc-special li.no { color: var(--bad); }
.wcard .wc-special li.none { color: var(--muted); }
.wcard .wc-mk { flex: none; width: 1em; text-align: center; font-weight: 700; }
.wcard .wc-actions { margin-top: auto; padding-top: 4px; }
.wcard .wc-actions button { margin-top: 0; }
/* Requirement chips: applied/needed, +N more that could be applied now. A symbol or number always backs up the colour. */
.req { position: relative; overflow: hidden; font: 11px var(--mono); padding: 3px 6px; border: 1px solid var(--line2); border-radius: 5px; background: #ffffff0a; text-align: center; white-space: nowrap; }
.req i { position: absolute; left: 0; top: 0; bottom: 0; background: #ffffff1f; }
.req b { position: relative; font-weight: 500; }
.req.done { color: var(--good); border-color: var(--good); background: #5fd38d2e; }
.req.done i { background: #5fd38d33; }
.req.ready { color: var(--good); border-color: var(--good); }
.req.ready i { background: #5fd38d1f; }
.req.part { color: var(--warn); border-color: var(--warn); }
.req.part i { background: #ffcc4d26; }
.req.stall { color: var(--text); border-color: var(--text); }
.req.none { color: var(--bad); border-color: var(--bad); }
.req.empty { color: var(--dim); border: 1px dashed var(--line); background: transparent; opacity: .7; }
/* Workshop panes: three columns in landscape (Printer, upgrades, bots), in the Bridge's split, each scrolling inside
   its own box so the page stays the height of the screen; a single stacked column otherwise. */
.workshop-wrap { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
@media (min-width: 761px) and (orientation: landscape) {
  .workshop-wrap { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr) minmax(0, 3fr); }
  .ws-printer { order: -1; }
  .workshop-wrap > .box { height: clamp(380px, calc(100vh - var(--top-h) - 12px - var(--surface-height) - 66px), 760px); overflow-y: auto; overscroll-behavior: contain; }
}
.upg { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 11px; display: flex; flex-direction: column; gap: 6px; }
.upg.new { border-color: var(--act); }
.upg.maxed { opacity: .6; }
.upg .t { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; }
.upg .lv { font: 11px var(--mono); color: var(--muted); white-space: nowrap; }
.upg .d { font-size: 12px; color: var(--muted); }
.upg .e { font: 11px var(--mono); color: var(--text); }
.upg .c { display: flex; flex-wrap: wrap; gap: 4px; }
.cost { font: 11px var(--mono); padding: 1px 6px; border-radius: 5px; background: #ffffff0a; }
.cost.ok { color: var(--text); }
.cost.no { color: var(--bad); }
.upg .bp { font: 10px var(--mono); color: var(--good); }
.cost.prog { position: relative; overflow: hidden; padding: 2px 7px; border: 1px solid var(--line); }
.cost.prog i { position: absolute; left: 0; top: 0; bottom: 0; background: #f0a63c33; }
.cost.prog b { position: relative; font-weight: 500; }
.cost.prog.done { border-color: var(--good); color: var(--good); }
.cost.prog.done i { background: #5fd38d33; }
.bp-plan-fill { fill: #0f3a63; opacity: .55; }
.bp-plan-line { fill: none; stroke: #ffc861; stroke-width: 1.2; stroke-dasharray: 4 3; }
.bp-planned:hover .bp-plan-fill { opacity: .9; }
.upg button { margin-top: auto; }

/* sealed room */
.sealed-box p { color: var(--bad); }
.blast { position: relative; height: 120px; border-radius: 8px; overflow: hidden; border: 1px solid var(--bad); margin-bottom: 10px; display: flex; }
.blast-l, .blast-r { flex: 1; background: repeating-linear-gradient(45deg, #2a1a10 0 14px, #c9a227 14px 28px); }
.blast-r { border-left: 3px solid #111; }
.blast-lbl { position: absolute; inset: auto 0 50% 0; transform: translateY(50%); text-align: center; font: 800 14px var(--sans); letter-spacing: .2em; color: #fff; text-shadow: 0 0 8px #000, 0 0 2px #000; }

/* cards */
.card { border-radius: var(--radius); border: 1px solid var(--act); background: linear-gradient(180deg, var(--panel2), var(--panel)); padding: 14px 16px; box-shadow: 0 6px 24px #0008; animation: slidein .3s ease-out; }
.card.story { border-color: var(--tan); }
.card.threat { border-color: var(--bad); }
@keyframes slidein { from { opacity: 0; transform: translateY(-8px); } }
.card h4 { margin: 0 0 6px; font-size: 16px; display: flex; gap: 8px; align-items: center; }
.card .tag { font: 10px var(--mono); letter-spacing: .1em; padding: 2px 7px; border-radius: 999px; background: #ffffff14; color: var(--muted); }
.card p { margin: 0 0 10px; white-space: pre-line; color: var(--text); }
.card .choices { display: flex; flex-direction: column; gap: 6px; }
.card .choice { text-align: left; display: flex; flex-direction: column; gap: 1px; }
.card .choice small { color: var(--muted); font-size: 12px; }
.card .choice .why { color: var(--bad); }
.card .timer { height: 3px; background: #ffffff14; border-radius: 2px; overflow: hidden; margin-top: 10px; }
.card .timer > i { display: block; height: 100%; background: var(--warn); }
.card .timer-lab { font: 11px var(--mono); color: var(--muted); margin-top: 4px; }

/* console */
.console-head { padding: 10px 14px; border-bottom: 1px solid var(--line); font-weight: 800; letter-spacing: .12em; font-size: 12px; display: flex; align-items: center; gap: 8px; }
.link-ai { display: inline-flex; align-items: center; gap: 5px; letter-spacing: .08em; --lc: var(--tan); }
#link-oscar { --lc: var(--oscar); }
.link-led { width: 9px; height: 9px; border-radius: 50%; background: var(--lc); box-shadow: 0 0 10px var(--lc); animation: breathe 3s infinite; }
.link-ai small { font: 10px var(--mono); letter-spacing: 0; color: var(--muted); }
.link-ai.off { color: var(--muted); }
.link-ai.off .link-led { background: transparent; box-shadow: none; animation: none; border: 2px solid var(--dim); }
@keyframes breathe { 50% { opacity: .45; } }
.console { flex: 1 1 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 10px 14px 20px; display: flex; flex-direction: column; gap: 9px; font-size: 13px; }
.console-head { flex: none; }
#ai-control-mode { margin-left: auto; letter-spacing: 0; font: 10px var(--mono); }
.ai-tabs { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--line); flex: none; }
/* Stacked layouts (a phone, a window narrower than 761px, or any portrait screen): the Link panel would otherwise
   swallow every swipe and wheel turn that lands on it, so it stops scrolling by touch or wheel and the arrows
   beside the tabs scroll it instead. Landscape keeps the ordinary scrolling panel. */
.ai-scroll { display: none; margin-left: auto; gap: 6px; }
.ai-tabs .active, .autonomy-controls .on { color: var(--act-hi); border-color: var(--act); background: var(--active-bg); }
#ai-conversation { display: flex; flex: 1 1 0; min-height: 0; }
.ai-objectives { flex: 1 1 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 10px; }
/* After both panel rules above so it wins. overscroll-behavior goes back to auto here too: "contain" would still stop
   a swipe that starts on the panel from reaching the page, even though the panel itself no longer scrolls. */
@media (max-width: 760px), (orientation: portrait) {
  .ai-scroll { display: inline-flex; }
  .console, .ai-objectives { overflow-y: hidden; overscroll-behavior: auto; touch-action: pan-y; }
}
#objective-list { display: flex; flex-direction: column; gap: 10px; }
/* MISSIONS and PRIORITIES tabs */
#mission-list, #priority-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.mission, .priority { border: 1px solid var(--line); border-radius: 8px; background: var(--bg2); padding: 8px 10px; }
.mission.story { border-left: 3px solid var(--story); }
.mission.side { border-left: 3px solid var(--act); }
.mission-head, .priority-head { display: flex; align-items: center; gap: 6px; }
.mission-head b, .priority-head b { flex: 1; min-width: 0; }
.mission .tag { font: 700 9px var(--mono); letter-spacing: .12em; color: var(--muted); }
#priority-list > h4 { margin: 0 0 6px; font: 700 10px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.priority-needs { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.need { font: 11px var(--mono); padding: 3px 7px; border: 1px solid var(--line2); border-radius: 5px; background: #ffffff0a; }
.need.ok { color: var(--good); border-color: var(--good); }
.need.short { color: var(--warn); border-color: var(--warn); cursor: pointer; }
.need.short:hover, .need.short:focus-visible { background: #ffcc4d1f; outline: none; }
.priority-ready { color: var(--good); margin: 6px 0; }
.objective { padding: 10px; border: 1px solid var(--line2); border-radius: 8px; }
.objective-head { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; }
.objective-head b { flex: 1; }
.objective-head button { padding: 2px 6px; }
.objective-thresholds { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; font-size: 12px; }
.objective-thresholds input { width: 58px; padding: 3px 5px; }
.objective-status { margin-top: 8px; font: 11px var(--mono); color: var(--tan); }
.msg { animation: fadein .35s; }
@keyframes fadein { from { opacity: 0; } }
.msg .who { font: 700 10px var(--mono); letter-spacing: .1em; margin-right: 6px; }
.msg .ts { font: 10px var(--mono); color: var(--muted); margin-left: 4px; }
.msg.TAN .who { color: var(--tan); }
.msg.MARGIN .who { color: var(--margin); }
.msg.OSCAR .who { color: var(--oscar); }
.msg.SYSTEM .who { color: var(--act); }
.msg.unlock { color: var(--act); }
/* chat severity: white is chatter, pale yellow a notice, mustard a real warning (an outage); a glyph backs up the colour */
.msg.sev-1 .body { color: var(--sev1); }
.msg.sev-1 .body::before { content: '△ '; }
.msg.sev-2 .body, .msg.alert .body { color: var(--sev2); font-weight: 600; }
.msg.sev-2 .body::before, .msg.alert .body::before { content: '▲ '; }
.msg.quiet .body { color: var(--quiet); }
/* decision cards in the chat: a pending one is a clickable red line with a timer under it; an answered one keeps just the choice */
.msg.card-alert { cursor: pointer; border-radius: 8px; padding: 6px 8px; margin: 0 -8px; border-left: 3px solid var(--bad); background: #ff5f6d12; }
.msg.card-alert:hover, .msg.card-alert:focus-visible { background: #ff5f6d24; outline: none; }
.msg.card-alert .body { color: var(--bad); font-weight: 600; }
.msg.card-alert .hint { font-weight: 400; color: var(--muted); font-size: 11px; }
.msg.card-alert .timer { height: 3px; background: #ffffff14; border-radius: 2px; overflow: hidden; margin-top: 6px; }
.msg.card-alert .timer > i { display: block; height: 100%; background: var(--bad); }
.msg.card-alert .timer-lab { font: 11px var(--mono); color: var(--muted); margin-top: 3px; }
.msg.card-story { border-left-color: var(--story); background: #c9a7ff14; }
.msg.card-story:hover, .msg.card-story:focus-visible { background: #c9a7ff26; }
.msg.card-story .body { color: var(--story); }
.msg.card-story .timer > i { background: var(--story); }
.msg.card-event { border-left-color: var(--act); background: #ffffff0a; }
.msg.card-event:hover, .msg.card-event:focus-visible { background: #ffffff18; }
.msg.card-event .body { color: var(--act-hi); }
.msg.card-event .timer > i { background: var(--act); }
.msg.card-done .body { color: var(--muted); }
/* a status line pinned under the decisions: short, clickable, gone when the cause is */
.msg.pin { cursor: pointer; border-radius: 8px; padding: 6px 8px; margin: 0 -8px; border-left: 3px solid var(--sev2); background: #d8a62314; }
.msg.pin:hover, .msg.pin:focus-visible { background: #d8a62326; outline: none; }
#update-banner { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 60; display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--bg2); border: 1px solid var(--act); border-radius: 10px; box-shadow: 0 6px 24px #0008; font-size: 13px; max-width: calc(100vw - 24px); }
.msg.CAPTAIN .who { color: var(--text); }
.msg.card-action .body { font-weight: 600; }
.msg.suggest[data-open="1"] { cursor: pointer; border-radius: 8px; padding: 6px 8px; margin: 0 -8px; border-left: 3px solid var(--act); background: var(--active-bg); }
.msg.suggest[data-open="1"]:hover, .msg.suggest[data-open="1"]:focus-visible { outline: none; filter: brightness(1.15); }
.msg.suggest .hint { color: var(--muted); font-size: 11px; }
.msg.card-waiting { cursor: default; opacity: .7; }
.msg.card-waiting:hover { background: inherit; }
.msg.story { color: var(--text); }
.msg .body { white-space: pre-line; }

/* bridge map */
/* Line up room columns with the chat, 3D view and deck plan above; stack in portrait. */
.bridge-wrap, .hold-columns, .dock-wrap { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.bridge-wrap { grid-template-areas: "map" "contact" "room"; }
.bw-map { grid-area: map; }
.bw-contact { grid-area: contact; }
.bw-room { grid-area: room; min-width: 0; }
.tug-room-subhead { margin: 0 0 8px; font-size: 13px; }
.bw-room .hold-canvas { margin-top: 10px; }
.bw-map > h3 { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.belt-count { margin-left: auto; font-weight: 400; letter-spacing: 0; white-space: nowrap; }
.belt-view { --belt-height: clamp(280px, 60vh, 560px); position: relative; background: var(--chart-bg); border-radius: 8px; height: var(--belt-height); }
.belt-view .belt { display: block; width: 100%; height: 100%; aspect-ratio: auto; touch-action: none; cursor: grab; user-select: none; }
@media (min-width: 761px) and (orientation: landscape) {
  .bridge-wrap, .hold-columns, .dock-wrap { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr) minmax(0, 3fr); }
  .bridge-wrap { grid-template-areas: "room map contact"; }
  /* what is left under the pinned strip: top bar, strip and the room heading and padding take the rest */
  .belt-view { --belt-height: clamp(300px, calc(100vh - var(--top-h) - 12px - var(--surface-height) - 125px), 720px); }
  /* the card scrolls inside the map's height instead of making the row taller */
  .bw-contact, .bw-room { contain: size; min-height: 0; }
  .bw-contact { display: flex; flex-direction: column; }
  .bw-room { overflow-y: auto; overscroll-behavior: contain; }
  .belt-detail { flex: 1; min-height: 0; }
}
/* Fill the space below the pinned display and room heading on desktop. */
@media (min-width: 761px) and (min-height: 700px) and (orientation: landscape) {
  #layout:has(:is(.hold-columns, .dock-wrap)) { height: calc(100dvh - var(--top-h)); }
  #workspace:has(:is(.hold-columns, .dock-wrap)), #panel:has(> :is(.hold-columns, .dock-wrap)), .hold-columns, .dock-wrap { flex: 1; min-height: 0; }
  .hold-columns, .dock-wrap { grid-template-rows: minmax(0, 1fr); }
  .hold-columns > .box, .dock-wrap > .box { overflow-y: auto; overscroll-behavior: contain; }
  .hold-columns > .lower-deck-holds { display: flex; flex-direction: column; overflow: hidden; }
  .hold-tab-panels { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
}
/* Quarters: three columns in landscape, one on a phone or in portrait; each column is a stack of boxes */
.quarters-wrap { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.qw-col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
@media (min-width: 761px) and (orientation: landscape) {
  .quarters-wrap { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr) minmax(0, 3fr); }
}
.belt-view .belt:active { cursor: grabbing; }
.belt-zoom { position: absolute; left: 8px; top: 8px; display: flex; flex-direction: column; gap: 4px; }
.belt-zoom button { width: 30px; padding: 3px 0; font-weight: 700; background: var(--panel); }
button.belt-home, button.belt-scan {
  position: absolute; right: 8px; width: min(152px, 36%, calc(var(--belt-height) / 2 - 12px)); aspect-ratio: 1;
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 7px; padding: 5px;
  background: #0e1830bd; border-radius: 14px;
  font-size: clamp(13px, 1.2vw, 22px); font-weight: 700; line-height: 1; overflow: hidden;
}
button.belt-home { top: 8px; color: #ffcf91; border-color: #ffb34780; letter-spacing: .06em; }
button.belt-home:hover:not(:disabled) { background: #35251bd9; border-color: #ffb347; }
button.belt-home:focus-visible { outline: 2px solid #ffb347; outline-offset: 2px; }
button.belt-home:disabled { color: #8d99aa; border-color: #6e7b8a80; }
.belt-home-icon { font: clamp(34px, 4vw, 72px)/1 "Segoe UI Symbol", "DejaVu Sans", sans-serif; letter-spacing: 0; }
.belt-ranges { position: absolute; left: 8px; bottom: 8px; margin: 0; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; pointer-events: none; }
.belt-ranges dd { margin: 0; }
button.belt-scan { bottom: 8px; color: #bdeaff; border-color: #5cc8ff80; }
button.belt-scan:hover:not(:disabled) { background: #183650d9; border-color: #8cdcff; }
button.belt-scan:focus-visible { outline: 2px solid #8cdcff; outline-offset: 2px; }
button.belt-scan:active:not(:disabled), button.belt-scan:disabled { background: #163552c7; border-color: #8cdcff; box-shadow: 0 0 12px #5cc8ff88, inset 0 0 8px #5cc8ff30; }
.belt-scan-icon {
  flex: none; width: 64%; aspect-ratio: 1; border: 2px solid currentColor; border-radius: 50%;
  background: radial-gradient(circle closest-side, currentColor 7%, transparent 12%),
    radial-gradient(circle closest-side, transparent 47%, currentColor 48% 51%, transparent 53%),
    conic-gradient(from -12deg, transparent, #8cdcff99 55deg, currentColor 56deg, transparent 60deg);
}
.belt-scan-progress { position: absolute; left: 0; bottom: 0; height: 3px; width: 0; background: #8cdcff; pointer-events: none; }
.belt-detail { position: relative; overflow-y: auto; }
.belt-detail .bd-close { position: absolute; right: 0; top: -2px; }
.bd-empty { font-size: 13px; line-height: 1.5; }
.belt-hint { margin-top: 8px; font-size: 11px; line-height: 1.5; }
.belt-local { margin-top: 8px; }
.belt-local .warnline { margin-top: 0; }
.belt { width: 100%; aspect-ratio: 1; background: radial-gradient(circle, #0e1830 0%, #070a10 70%); border-radius: 10px; border: 1px solid var(--line); touch-action: manipulation; }
.belt-contact { cursor: pointer; outline: none; }
.belt-contact text, .belt-contact-ring { pointer-events: none; }
.belt-radio-range { pointer-events: none; }
.belt-radio-label { paint-order: stroke; stroke: var(--chart-bg); stroke-width: .12px; stroke-linejoin: round; }
:root[data-ui-theme="parchment"] .belt { --remote-ink: #d3b8ff; }
.belt-contact-ring, .belt-contact-label { opacity: 0; }
.belt-contact-label { paint-order: stroke; stroke: #070a10; stroke-width: .12px; stroke-linejoin: round; }
.belt-contact-label.visible,
.belt-contact:hover .belt-contact-label, .belt-contact:focus .belt-contact-label, .belt-contact.sel .belt-contact-label,
.belt-contact:hover .belt-contact-ring, .belt-contact:focus .belt-contact-ring, .belt-contact.sel .belt-contact-ring { opacity: 1; }

/* trade */
.trow { display: grid; grid-template-columns: 1fr auto auto auto; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.trow:last-child { border-bottom: none; }
.trow .p { font: 12px var(--mono); color: var(--c-credits); text-align: right; min-width: 90px; }
.margin-head { display: flex; gap: 12px; align-items: center; }
.margin-av { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 24px; background: linear-gradient(135deg, #3b2457, #6b2f5e); border: 1px solid #ff9bd255; }

table.t { width: 100%; border-collapse: collapse; font-size: 12px; }
table.t th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px; border-bottom: 1px solid var(--line); }
table.t td { padding: 6px; border-bottom: 1px dashed var(--line); font-family: var(--mono); }
table.t td:first-child { font-family: var(--sans); }

.arch { border: 1px solid var(--line); border-radius: 8px; background: var(--bg2); }
.arch summary { padding: 9px 12px; cursor: pointer; font-weight: 600; }
.arch div { padding: 0 12px 12px; white-space: pre-line; color: var(--text); font-size: 13px; }

.hold-canvas { width: 100%; height: 150px; display: block; border-radius: 8px; background: #0b0f17; border: 1px solid var(--line); }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(3, 5, 9, .78); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box { background: var(--panel); border: 1px solid var(--line2); border-radius: 14px; padding: 22px; width: min(520px, 100%); max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px #000c; }
.modal-box h2 { margin: 0 0 6px; }
.modal-box label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
.modal-box .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--act); padding: 9px 16px; border-radius: 999px; z-index: 60; font-size: 13px; }

/* editor */
#editor { padding: 0; align-items: stretch; justify-content: stretch; background: #04060b; }
.ed-view { position: relative; flex: 1; min-width: 0; touch-action: none; }
.ed-view canvas { display: block; }
.ed-hint { position: absolute; left: 16px; top: 14px; right: 16px; font-size: 13px; color: #ffffffaa; pointer-events: none; z-index: 2; }
.ed-hint.armed { color: var(--act); font-weight: 700; }
.ed-viewbtns { position: absolute; left: 16px; bottom: 14px; display: flex; gap: 8px; z-index: 2; flex-wrap: wrap; }
.ed-viewbtns button { background: var(--panel); }
.ed-panel { width: 380px; max-width: 100%; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.ed-panel h2 { margin: 0; font-size: 18px; display: flex; align-items: center; justify-content: space-between; }
.ed-sec h4 { margin: 0 0 8px; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.ed-selects { display: grid; grid-template-columns: 1fr minmax(0, 1.6fr); gap: 6px 10px; align-items: center; }
.ed-selects select { width: 100%; min-width: 0; font: inherit; font-size: 12px; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 5px; }
.ed-accessory { min-width: 0; border: 1px solid var(--line); border-radius: 6px; margin: 8px 0; padding: 8px; }
.ed-accessory legend { color: var(--muted); padding: 0 4px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { display: flex; align-items: center; gap: 6px; padding: 4px 8px 4px 4px; font-size: 12px; }
.swatch i { display: flex; width: 34px; height: 18px; border-radius: 4px; overflow: hidden; }
.swatch i b { flex: 1; }
.colors { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; font-size: 13px; }
.decal-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.decal-tile { padding: 6px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 10px; line-height: 1.2; text-align: center; min-height: 78px; justify-content: center; }
.decal-tile img { max-width: 100%; max-height: 42px; object-fit: contain; background: repeating-conic-gradient(#ffffff10 0% 25%, transparent 0% 50%) 50% / 12px 12px; border-radius: 4px; }
.decal-tile.armed { border-color: var(--act); background: var(--active-bg); }
.placed { display: flex; flex-direction: column; gap: 4px; max-height: 150px; overflow-y: auto; }
.placed button { text-align: left; font-size: 12px; padding: 5px 8px; }
.placed button.sel { border-color: var(--act); }
.photo .ed-panel, .photo .ed-hint { display: none; }

/* settings */
.set-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; }
.set-row:first-of-type { margin-top: 0; }
body.reduce-motion *, body.reduce-motion *::before, body.reduce-motion *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
/* colorblind-friendly status palette (Okabe-Ito): no red/green dependence */
body.cb { --good: #56b4e9; --warn: #f0e442; --bad: #e69f00; --c-heat: #e69f00; --c-def: #56b4e9; --c-mun: #cc79a7; }
.msg.dog .who { color: var(--c-credits); }
.msg.dog .body { font-style: italic; color: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  #layout { padding: 12px 16px; }
}
@media (max-width: 760px) {
  .control-surface { grid-template-columns: 1fr; height: auto; }
  .stage { grid-row: 1; height: clamp(320px, 48vh, 480px); }
  #ai-panel { height: 440px; }
}
@media (max-width: 640px) {
  #topbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .resbar { order: 3; flex-basis: 100%; }
  .res .bar, .res .lbl { display: none; }
  .viewer-hint { display: none; }
  #editor { flex-direction: column; }
  .ed-view { flex: none; height: 45vh; }
  .ed-panel { width: 100%; border-left: none; border-top: 1px solid var(--line); flex: 1; }
  .pipe { grid-template-columns: 1fr; }
  .pipe .arrow { transform: rotate(90deg); text-align: center; }
  .trow { grid-template-columns: 1fr auto; }
}
