:root {
  --bg: #03050a;
  --panel: rgba(8, 12, 22, 0.78);
  --line: rgba(255, 140, 60, 0.22);
  --text: #d9dde8;
  --dim: #7d8598;
  --accent: #ff7a1a;
  --accent-2: #ffb26b;
  --cyan: #3fd0ff;
  --green: #6ef0c0;
  --gold: #fff07a;
  --bad: #ff4d5e;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --head: "Rajdhani", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 13px/1.4 var(--mono); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
/* every scrolling box (panel tabs, system card, dropdowns, ship paste box): thin, dark, accent on hover */
.tab, #card, .dd, textarea { scrollbar-width: thin; scrollbar-color: rgba(255, 140, 60, 0.28) transparent; }
.tab:hover, #card:hover, .dd:hover, textarea:hover { scrollbar-color: rgba(255, 140, 60, 0.55) transparent; }
#stage { position: fixed; inset: 0; touch-action: none; cursor: grab; }
#stage.drag { cursor: grabbing; }
#vignette { position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.55) 100%); }

/* ---------- HUD */
#hud { position: fixed; top: 14px; left: 14px; pointer-events: none; }
.brand { font: 600 15px var(--head); letter-spacing: 0.18em; color: var(--accent); display: flex; align-items: center; gap: 10px; }
.brand b { color: var(--text); font-weight: 600; opacity: 0.75; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent);
  animation: pulse 1.6s infinite; }
.pulse.dead { background: var(--bad); box-shadow: 0 0 10px var(--bad); animation: none; }
@keyframes pulse { 50% { opacity: 0.25; } }
/* brand + live stats on their own backing: over the bright core, white text on the bare map was unreadable */
.hudbox { width: 330px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px;
  backdrop-filter: blur(8px); }
.stats { display: flex; justify-content: space-between; gap: 14px; margin-top: 6px; }
.stats div { display: flex; flex-direction: column; }
.stats span { font-size: 20px; font-weight: 600; color: #fff; font-variant-numeric: tabular-nums; }
.stats small { color: var(--dim); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; }
.badge { font-size: 13px !important; padding: 3px 7px; border: 1px solid currentColor; border-radius: 3px; margin: 3px 0 2px; align-self: flex-start; }
.badge.ok { color: var(--green); }
.badge.warn { color: var(--bad); }

/* ---------- panel */
#panel { position: fixed; top: 14px; right: 14px; bottom: 14px; width: 380px; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; backdrop-filter: blur(8px);
}
.ready #panel { transition: transform 0.25s; }  /* .ready: not on first paint (phones start collapsed) */
#panel.hidden { transform: translateX(calc(100% + 14px)); }  /* fully off-screen; the handle stays */
#panel-handle { position: absolute; left: -28px; top: 46px; width: 28px; height: 58px; padding: 0; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); border-right: 0; border-radius: 6px 0 0 6px;
  color: var(--accent); font-size: 18px; backdrop-filter: blur(8px); }
#panel-handle:hover { color: #fff; border-color: var(--accent); }
#panel.hidden #panel-handle { transform: scaleX(-1); border-radius: 0 6px 6px 0; border: 1px solid var(--line); border-left: 0; }
#panel nav #collapse { display: none; }
#panel nav { display: flex; border-bottom: 1px solid var(--line); }
#panel nav button { flex: 1; background: none; border: 0; padding: 10px 0 8px; cursor: pointer; color: var(--dim);
  font: 600 12.5px var(--head); letter-spacing: 0.1em; text-transform: uppercase; border-bottom: 2px solid transparent; }
#panel nav button.on { color: var(--accent); border-bottom-color: var(--accent); }
#panel nav #collapse { flex: 0 0 34px; letter-spacing: 0; }
.tab { display: none; overflow-y: auto; padding: 10px 12px 14px; flex: 1; }
.tab.on { display: block; }
.hint { color: var(--dim); font-size: 11px; margin: 0 0 10px; }
.hint em { color: var(--gold); font-style: normal; }

.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 7px 8px; border-radius: 4px; cursor: pointer;
  border-left: 2px solid transparent; }
.rows li:hover { background: rgba(255, 122, 26, 0.08); border-left-color: var(--accent); }
.rows .name { color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .big { color: var(--accent-2); font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.rows .sub { color: var(--dim); font-size: 11px; grid-column: 1 / -1; }
.rows .kind { color: var(--gold); }
.rows .bar { grid-column: 1 / -1; height: 2px; background: rgba(255, 255, 255, 0.06); }
.rows .bar i { display: block; height: 100%; background: var(--accent); }
.empty { color: var(--dim); padding: 20px 8px; text-align: center; }


/* box tab */
.box-h { font: 600 13px var(--head); letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); margin: 14px 0 8px; }
.box-h:first-child { margin-top: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 12px; }
.kv dt { color: var(--dim); }
.kv dd { margin: 0; text-align: right; color: #fff; }
canvas.spark { width: 100%; height: 46px; display: block; margin-top: 4px; }
.note { color: var(--dim); font-size: 11px; margin-top: 6px; }
.note a { color: var(--accent-2); }
:where(#panel, #card) a { color: var(--accent-2); }  /* no browser-blue links; zero specificity so styled links win */

/* ---------- controls */
#controls { position: fixed; left: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 8px; width: 330px; }  /* same column as #cmdr */
.views, .toggles { display: flex; gap: 6px; flex-wrap: wrap; }
.views { width: 100%; }
.views button { flex: 1 1 auto; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 5px 8px; cursor: pointer;
  font: 600 12px var(--head); letter-spacing: 0.12em; text-transform: uppercase; }
.views button:hover, .views button.on { border-color: var(--accent); color: var(--accent); }
#zoombar { position: fixed; left: 14px; top: 0; bottom: 0; height: fit-content; margin: auto 0; display: flex; flex-direction: column;  /* centred without % (CSS zoom on 4K) */
  align-items: center; gap: 6px; padding: 6px 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; }
#zoombar button { width: 24px; height: 24px; padding: 0; background: none; border: 1px solid var(--line); border-radius: 3px;
  color: var(--dim); font: 600 15px/1 var(--head); cursor: pointer; }
#zoombar button:hover { border-color: var(--accent); color: var(--accent); }
#zoom { writing-mode: vertical-lr; direction: rtl; width: 18px; height: 200px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.toggles label { color: var(--dim); font-size: 11px; display: flex; align-items: center; gap: 4px; cursor: pointer;
  background: var(--panel); padding: 3px 8px; border-radius: 3px; }
.toggles input { accent-color: var(--accent); margin: 0; }
.search { position: relative; width: 100%; }
.search input { width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 7px 10px; outline: none; }
.search input:focus { border-color: var(--accent); }
.dd { position: absolute; top: 100%; left: 0; right: 0; list-style: none; margin: 4px 0 0; padding: 0; z-index: 20;
  background: rgba(8, 12, 22, 0.97); border: 1px solid var(--line); border-radius: 4px; display: none; max-height: 320px; overflow-y: auto; }
#results { top: auto; bottom: 100%; margin: 0 0 4px; }
.dd.on { display: block; }
.dd li { padding: 6px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.dd li:hover, .dd li.sel { background: rgba(255, 122, 26, 0.12); }
.dd li small { color: var(--dim); white-space: nowrap; }
.dd li .t { font-size: 10px; color: var(--accent-2); text-transform: uppercase; letter-spacing: 0.08em; margin-right: 6px; }
.dd li.src { color: var(--dim); font-size: 10.5px; cursor: default; padding: 4px 10px; background: rgba(255, 255, 255, 0.03); }
#legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: 10.5px; color: var(--dim); }
#legend button { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; }
#legend button:hover { color: var(--text); }
#legend button::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--c);
  margin-right: 5px; box-shadow: 0 0 6px var(--c); }
#legend button.off { opacity: 0.4; text-decoration: line-through; }
#legend button.off::before { background: none; box-shadow: none; outline: 1px solid var(--c); outline-offset: -1px; }
/* conflict-layer filters (under the layer switches while "conflicts" is on) */
.chipbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; font-size: 10.5px; color: var(--dim); }
.chipbar[hidden] { display: none; }
.chipbar button { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; }
.chipbar button:hover { color: var(--text); }
.chipbar button::before { content: ""; display: inline-block; width: 6px; height: 6px; margin: 0 7px 1px 1px; transform: rotate(45deg);
  background: var(--cf); box-shadow: 0 0 6px var(--cf); }
.chipbar button.off { opacity: 0.4; text-decoration: line-through; }
.chipbar button.off::before { background: none; box-shadow: none; outline: 1px solid var(--cf); }
#scale { display: flex; align-items: center; gap: 8px; font-size: 10.5px; color: var(--dim); }
#scale i { display: block; height: 6px; border: 1px solid var(--dim); border-top: 0; }

/* ---------- tooltip & card */
#tip { position: fixed; pointer-events: none; background: rgba(5, 8, 16, 0.92); border: 1px solid var(--line); border-radius: 4px;
  padding: 5px 8px; font-size: 11.5px; white-space: nowrap; z-index: 5; }
#tip b { color: #fff; font-weight: 600; }
#tip small { color: var(--dim); display: block; }
#card { position: fixed; right: 406px; bottom: 14px; width: 320px; max-height: calc(100vh - 28px); overflow-y: auto; background: #070b14; border: 1px solid var(--accent);  /* opaque: it can sit over the panel */
  border-radius: 6px; padding: 12px 14px; z-index: 4; box-shadow: 0 0 30px rgba(255, 122, 26, 0.15);
  backdrop-filter: blur(8px);  /* own layer, like #panel: without it Chrome blanked the map above a scrolling card */
}
.ready #card { transition: right 0.25s; }  /* slides with the panel (same duration and easing as its transform) */
#panel.hidden ~ #card { right: 48px; }  /* panel collapsed to its 34px tab */
#card h3 { margin: 0 24px 2px 0; font: 700 18px var(--head); letter-spacing: 0.04em; color: #fff; word-break: break-word; }
#card .x { position: absolute; top: 8px; right: 10px; background: none; border: 0; color: var(--dim); cursor: pointer; font-size: 16px; }
#card .links { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
#card .links a, #card .links button { background: none; border: 1px solid var(--line); border-radius: 3px; padding: 4px 9px;
  color: var(--accent-2); text-decoration: none; cursor: pointer; font-size: 11.5px; }
#card .links a:hover, #card .links button:hover { border-color: var(--accent); }
#card ul { margin: 6px 0 0; padding-left: 16px; font-size: 11.5px; color: var(--dim); }
#card ul b { color: var(--gold); font-weight: 400; }
#card .sysstate { margin-top: 8px; font-size: 11.5px; line-height: 1.55; color: var(--text); }
#card .sysstate b { color: #fff; font-weight: 600; }
#card .sysstate .hint { margin: 2px 0 0; }
#card .conflict { color: var(--cf); }
#card .conflict::before { content: "⚔ "; }
.conflict.war, [data-cf="war"] { --cf: #ff4d5e; }
.conflict.civilwar, [data-cf="civilwar"] { --cf: #ff6ec7; }
.conflict.election, [data-cf="election"] { --cf: #9ad0ff; }
.conflict.thargoid { --cf: #6effc7; }

/* ---------- commander box (always visible under the HUD stats) */
#cmdr { pointer-events: auto; margin-top: 6px; width: 330px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 10px; backdrop-filter: blur(8px); }
#cmdr.following { border-color: rgba(141, 255, 106, 0.55); }
#cmdr > .row { margin-top: 0; }
#cmdr.following #me-track { color: #8dff6a; border-color: rgba(141, 255, 106, 0.55); }
.me-line { margin-top: 6px; font-size: 11.5px; color: var(--dim); }
.me-line b { color: #fff; font-weight: 600; }
.me-line .dot { color: #8dff6a; }
.linkish { background: none; border: 0; padding: 0; color: var(--accent-2); cursor: pointer; font-size: 11.5px; text-decoration: underline; }
#me-manual-box { margin-top: 8px; }
#me-manual-box .search { width: 100%; }
#me-msg { margin: 6px 0 0; }
#me-msg:empty { display: none; }
.row { display: flex; gap: 6px; margin-top: 6px; }
.row input { flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 7px 10px; outline: none; }
.row input:focus { border-color: var(--accent); }
.row button, .form button, .actions button, .mini { background: none; border: 1px solid var(--line); border-radius: 4px;
  padding: 6px 10px; cursor: pointer; color: var(--accent-2); font-size: 12px; }
.row button:hover, .form button:hover, .actions button:hover, .mini:hover { border-color: var(--accent); }
button.primary { background: rgba(255, 122, 26, 0.14); border-color: var(--accent); color: #fff; font: 600 13px var(--head);
  letter-spacing: 0.12em; text-transform: uppercase; padding: 7px 12px; }
button.primary:disabled { opacity: 0.5; cursor: progress; }
.mini { padding: 2px 7px; font-size: 11px; }

/* ---------- bio + plan */
.seg { display: flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; margin-bottom: 8px; }
.seg button { flex: 1; background: none; border: 0; padding: 6px 0; cursor: pointer; color: var(--dim); font-size: 12px; }
.seg button.on { background: rgba(141, 255, 106, 0.12); color: #8dff6a; }
.filters { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-bottom: 8px; font-size: 11.5px; color: var(--dim); }
.filters select, .form select { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 3px; padding: 2px 4px; }
.chk { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.chk input { accent-color: var(--accent); margin: 0; }
.rows li.sysrow { display: block; cursor: default; }
.sysrow { border-left: 2px solid transparent; padding: 7px 8px 5px; border-radius: 4px; }
.sysrow:hover { background: rgba(141, 255, 106, 0.05); border-left-color: #8dff6a; }
.sysrow .head { display: flex; justify-content: space-between; gap: 8px; cursor: pointer; }
.sysrow .head .name { color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sysrow .head .big { color: #8dff6a; font-weight: 600; white-space: nowrap; }
.sysrow .sub { color: var(--dim); font-size: 11px; }
.body { margin: 5px 0 2px 8px; padding-left: 8px; border-left: 1px solid rgba(255, 255, 255, 0.08); font-size: 11.5px; }
.body .l1 { display: flex; justify-content: space-between; gap: 6px; align-items: baseline; }
.body .bn { color: #fff; }
.body .gen { color: var(--dim); }
.body .val { color: var(--gold); white-space: nowrap; }
.tag { display: inline-block; font-size: 10px; padding: 0 5px; border-radius: 3px; border: 1px solid; margin: 2px 4px 0 0; white-space: nowrap; }
.tag.ok { color: #8dff6a; border-color: rgba(141, 255, 106, 0.45); }
.tag.map { color: var(--cyan); border-color: rgba(63, 208, 255, 0.45); }
.tag.unk { color: var(--dim); border-color: rgba(255, 255, 255, 0.15); }
.tag.warn { color: #ffb347; border-color: rgba(255, 179, 71, 0.5); }
.tag.bad { color: var(--bad); border-color: rgba(255, 77, 94, 0.45); }
.cta { text-align: center; padding: 18px 8px; color: var(--dim); }
.cta button { margin-top: 8px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.box-h small { color: var(--dim); font: 400 11px var(--mono); letter-spacing: 0; text-transform: none; margin-left: 6px; }
.form { display: flex; flex-direction: column; gap: 7px; margin-bottom: 10px; }
.form > label, .pair label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--dim); }
.form input { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 6px 9px; outline: none; color: var(--text); width: 100%; }
.form input[type="checkbox"] { width: auto; }  /* not stretched: labels stay on one line */
.form input:focus { border-color: var(--accent); }
.form .search { width: 100%; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: end; }
.pair .chk { flex-direction: row; justify-content: flex-start; padding-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chips span { font-size: 11px; background: rgba(255, 255, 255, 0.06); border-radius: 3px; padding: 2px 6px; }
.chips span b { cursor: pointer; color: var(--dim); margin-left: 4px; font-weight: 400; }
.wp { list-style: none; margin: 6px 0 0; padding: 0; font-size: 11.5px; counter-reset: wp; }
.wp li { display: flex; gap: 8px; align-items: baseline; padding: 3px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.04); }
.wp li .n { color: var(--dim); width: 22px; text-align: right; flex: none; }
.wp li .s { flex: 1; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.wp li .s.neutron::after { content: " ✦"; color: var(--cyan); }
.wp li small { color: var(--dim); white-space: nowrap; }
.summary { padding: 8px 10px; border: 1px solid var(--line); border-radius: 4px; margin: 6px 0; font-size: 12px; }
.summary b { color: #fff; }
.summary a { color: var(--accent-2); }
.err { color: var(--bad); font-size: 12px; margin: 6px 0; }
.spin { color: var(--dim); font-size: 12px; margin: 8px 0; }
.spin::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 8px; border: 2px solid var(--accent);
  border-right-color: transparent; border-radius: 50%; animation: rot 0.8s linear infinite; vertical-align: -1px; }
@keyframes rot { to { transform: rotate(360deg); } }
.ship { border: 1px solid var(--line); border-radius: 4px; padding: 7px 9px; font-size: 11.5px; }
.ship-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; color: var(--dim); }
.ship-head b { color: #fff; font-weight: 600; }
.ship textarea { width: 100%; margin-top: 6px; background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 4px; padding: 6px 8px; font: 11px var(--mono); resize: vertical; outline: none; }
.ship textarea:focus { border-color: var(--accent); }
.opts { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11.5px; color: var(--dim); }
details.more { border-top: 1px solid var(--line); padding-top: 6px; }
details.more summary { cursor: pointer; color: var(--accent-2); font-size: 11.5px; margin-bottom: 6px; }
details.more[open] { display: flex; flex-direction: column; gap: 7px; }
.attrib { margin-top: 16px; padding: 8px 10px; border-left: 2px solid var(--accent); background: rgba(255, 122, 26, 0.05); }
.attrib a, a.ext { color: var(--accent-2); }
.legal { font-size: 9.5px; opacity: 0.75; line-height: 1.45; }
a.ext { font-size: 11px; align-self: flex-start; }
.ext-links { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.ext-links a { border: 1px solid var(--line); border-radius: 4px; padding: 5px 9px; color: var(--accent-2); text-decoration: none; font-size: 12px; }
.ext-links a:hover { border-color: var(--accent); }
.ext-links a::after { content: " ↗"; color: var(--dim); }
a.spansh-btn { display: inline-block; margin-top: 6px; border: 1px solid var(--accent); border-radius: 4px; padding: 5px 10px;
  color: #fff; text-decoration: none; background: rgba(255, 122, 26, 0.12); font-size: 12px; }
.credits { margin-top: 16px; line-height: 1.5; }
.privacy { padding-left: 16px; line-height: 1.5; margin: 0 0 14px; }
.privacy b { color: var(--text); font-weight: 600; }

/* 4K etc.: app.js sets --ui (1..2); the canvas gets the same scale via a smaller logical resolution */
#hud, #panel, #controls, #zoombar, #card, #tip, #toast { zoom: var(--ui, 1); }
#stage canvas { display: block; width: 100%; height: 100%; }
.credits a { color: var(--accent-2); }
#alerts-link a { color: var(--accent-2); }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: rgba(6, 10, 18, 0.95);
  border: 1px solid var(--accent); border-radius: 4px; padding: 7px 14px; z-index: 40; font-size: 12px; }
#card .bio { margin-top: 8px; }
#card .bio .body { margin-left: 0; }

#bootmsg { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); color: var(--dim); letter-spacing: 0.2em;
  font: 600 13px var(--head); text-transform: uppercase; pointer-events: none; transition: opacity 0.6s; }

/* ---------- layouts. app.js mirrors these breakpoints (SHEET_MQ, freeRect) to keep flights clear of the UI.
   desktop (>1180): panel right, system card beside it. 901-1180 and short landscape screens: the card covers
   the panel instead. Phones in portrait: the panel is a bottom sheet. */
.phone-only { display: none; }
@media (max-width: 1180px) {
  #panel { width: 340px; }
  #card { right: 14px; top: 14px; bottom: 14px; width: 340px; max-height: none; z-index: 6; }
  #panel.hidden ~ #card { right: 48px; }
}
/* landscape phones: no room for the stats or the left-hand extras */
@media (max-height: 500px) and (min-width: 601px) {
  #hud { top: 8px; left: 8px; }
  .stats { display: none; }
  .hudbox { padding: 6px 8px; }
  #cmdr { width: 330px; margin-top: 6px; padding: 6px 8px; }
  #panel { top: 8px; right: 8px; bottom: 8px; width: 300px; }
  #panel.hidden { transform: translateX(calc(100% + 8px)); }
  #card { top: 8px; right: 8px; bottom: 8px; width: 300px; }
  #controls { left: 8px; bottom: 8px; width: auto; max-width: calc(100vw - 340px); }
  .search, .views { width: 330px; }
  .views { flex-wrap: nowrap; }
  .views button { flex: 1 1 0; min-width: 0; padding: 6px 0; font-size: 11px; letter-spacing: 0.04em; }
  #zoombar, #scale { display: none; }
  #legend, .toggles { display: none; }
  .chipbar { display: none; }
  #controls.layers #legend, #controls.layers .toggles, #controls.layers .chipbar:not([hidden]) { display: flex; }
  .views .phone-only { display: block; }
}
/* portrait phones (and narrow windows): bottom sheet with a 40 px tab row; it starts collapsed */
@media (max-width: 900px) and (min-height: 501px), (max-width: 600px) {
  #hud { top: calc(8px + env(safe-area-inset-top)); left: 8px; right: 8px; }
  .brand { font-size: 13px; }
  .stats { gap: 14px; margin-top: 4px; }
  .stats span { font-size: 15px; }
  .stats small { font-size: 9px; }
  .hudbox { width: auto; max-width: 480px; padding: 6px 8px; }
  #cmdr { width: auto; max-width: 480px; margin-top: 6px; padding: 6px 8px; }
  #panel { top: auto; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); width: auto;
    height: 52vh; height: 52dvh; }
  #panel nav { height: 40px; flex: none; }
  #panel.hidden { transform: translateY(calc(100% - 41px)); }  /* the tab row (and its top border) stays visible */
  #panel.hidden .tab { visibility: hidden; }
  #panel-handle { display: none; }
  #panel nav #collapse { display: block; transform: rotate(90deg); }
  /* map controls sit on the collapsed sheet and step aside while it's open */
  #controls { left: 8px; right: 8px; bottom: calc(57px + env(safe-area-inset-bottom)); width: auto; max-width: 480px; }  /* tablets: same column as #cmdr */
  /* the sheet going down: they wait for it (0.25 s), then fade up; the sheet coming up: they fade out at once */
  .ready #controls { transition: opacity 0.2s ease-out 0.22s, transform 0.2s ease-out 0.22s, visibility 0s linear 0.22s; }
  #panel:not(.hidden) ~ #controls { visibility: hidden; opacity: 0; transform: translateY(16px); }
  .ready #panel:not(.hidden) ~ #controls { transition: opacity 0.12s, transform 0.12s, visibility 0s linear 0.12s; }
  .search, .views { width: 100%; }
  .views { flex-wrap: nowrap; }
  .views button { flex: 1 1 0; min-width: 0; padding: 8px 0; font-size: 11.5px; letter-spacing: 0.06em; }
  .views .phone-only { display: block; }
  #zoombar, #scale { display: none; }  /* phones pinch */
  #legend, .toggles { display: none; }
  .chipbar { display: none; }
  #controls.layers #legend, #controls.layers .toggles, #controls.layers .chipbar:not([hidden]) { display: flex; }
  #legend { gap: 6px; }
  #legend button { background: var(--panel); border-radius: 3px; padding: 4px 7px; }
  /* a system card belongs to the map: docked over the controls, hidden while the sheet is open */
  #card, #panel.hidden ~ #card { left: 8px; right: 8px; top: auto; bottom: calc(57px + env(safe-area-inset-bottom)); width: auto;
    max-height: 50vh; max-height: 50dvh; }
  #panel:not(.hidden) ~ #card { display: none; }
  /* it slides up into place each time it shows (display:none -> shown restarts the animation); when the sheet is
     going down at the same moment, it waits for the sheet (0.25 s) first */
  .ready #card:not([hidden]) { animation: card-in 0.24s ease-out backwards; }
  .ready #card.after-sheet:not([hidden]) { animation-delay: 0.22s; }
  .ready #card.closing:not([hidden]) { animation: card-out 0.2s ease-in forwards; pointer-events: none; }  /* the same, backwards */
  #bootmsg { top: 35%; }
}
/* wider sheet screens (small tablets, narrow windows): stats and commander box share the top row instead of
   stacking in a 480 px column that left the top right empty; the controls span the width like the sheet */
@media (min-width: 600px) and (max-width: 900px) and (min-height: 501px) {
  #hud { display: flex; gap: 6px; align-items: stretch; }
  .hudbox, #cmdr { flex: 1 1 0; min-width: 0; max-width: none; margin-top: 0; }
  #controls { max-width: none; }
}

@keyframes card-in { from { opacity: 0; transform: translateY(28px); } }
@keyframes card-out { to { opacity: 0; transform: translateY(28px); } }
@media (prefers-reduced-motion: reduce) {
  .ready #panel, .ready #card, .ready #controls, .ready #panel:not(.hidden) ~ #controls { transition: none; }
  .ready #card:not([hidden]) { animation: none; }
}
