:root {
  --bg: #050608;
  --panel: rgba(13, 15, 19, 0.88);
  --panel-solid: #0d0f13;
  --border: #2a2f38;
  --border-hi: #444b57;
  --text: #d8dde6;
  --muted: #7d8592;
  --amber: #ffb347;
  --amber-dim: #8a5a22;
  --hazard: #ffc42a;
  --danger: #ff5a4a;
  --log: #8be08b;
  --pixel: 'Silkscreen', ui-monospace, monospace;
  --mono: 'VT323', ui-monospace, monospace;
  --gutter: max(10px, env(safe-area-inset-left));
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--pixel);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#view {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

button {
  font: inherit;
  color: var(--text);
  background: #1a1e25;
  border: 2px solid var(--border);
  border-radius: 0;
  padding: 6px 10px;
  cursor: pointer;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.45), inset 0 2px 0 rgba(255, 255, 255, 0.05);
}
button:hover { border-color: var(--border-hi); }
button.active {
  color: #16110a;
  background: var(--amber);
  border-color: #ffd08a;
}
button:focus-visible { outline: 2px solid var(--amber); outline-offset: 1px; }

/* Top bar */
#topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(8px, env(safe-area-inset-top)) var(--gutter) 8px;
  background: linear-gradient(to bottom, rgba(5, 6, 8, 0.92), rgba(5, 6, 8, 0));
  pointer-events: none;
  font-size: 12px;
}
#topbar > * { pointer-events: auto; }
.brand {
  color: var(--amber);
  letter-spacing: 3px;
  font-size: 14px;
  margin-right: 6px;
}
#resources { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--panel);
  border: 2px solid var(--border);
  white-space: nowrap;
}
.chip[hidden] { display: none; }
.chip .swatch { width: 8px; height: 8px; display: inline-block; }
.chip .label { color: var(--muted); }
.chip .value { min-width: 2ch; text-align: right; font-variant-numeric: tabular-nums; }
.chip.bump { border-color: var(--amber); }
#drone-status { margin-left: auto; color: var(--muted); }
#drone-status b { color: var(--text); font-weight: normal; }
#time-controls { display: flex; }
#time-controls button { padding: 4px 8px; min-width: 36px; }
#time-controls button + button { border-left-width: 0; }

/* Tools */
#tools {
  position: fixed;
  left: var(--gutter);
  bottom: max(10px, env(safe-area-inset-bottom));
  display: flex;
  gap: 6px;
}
#tools button {
  min-width: 72px;
  min-height: 48px;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
#tools .key { font-size: 9px; color: var(--muted); }
#tools button[data-tool="cancel"] { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: none; overflow: hidden; }
#tools button[data-tool="cancel"].holding::after {
  content: ''; position: absolute; left: 0; bottom: 0; height: 100%; width: 100%;
  background: var(--danger); opacity: 0.55; pointer-events: none;
  transform-origin: left; animation: clear-hold 700ms linear forwards;
}
@keyframes clear-hold { from { transform: scaleX(0); } to { transform: scaleX(1); } }
#tools button.active .key { color: #5a3d14; }
#tools button[data-tool="cancel"].active { background: var(--danger); border-color: #ff9a8f; }

/* Tile info */
#tileinfo {
  position: fixed;
  left: var(--gutter);
  top: 52px;
  max-width: min(340px, 60vw);
  padding: 8px 10px;
  background: var(--panel);
  border: 2px solid var(--border);
  font-family: var(--mono);
  font-size: 18px;
  line-height: 1.05;
  pointer-events: none;
}
#tileinfo .name { color: var(--amber); font-family: var(--pixel); font-size: 12px; display: block; margin-bottom: 4px; }
#tileinfo .meta { color: var(--muted); }

/* WARDEN console */
#console {
  position: fixed;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  width: min(400px, 46vw);
  background: var(--panel);
  border: 2px solid var(--border);
  display: flex;
  flex-direction: column;
}
.console-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 2px solid var(--border);
  color: var(--amber);
  font-size: 12px;
  letter-spacing: 2px;
}
#warden-face {
  width: 24px;
  height: 24px;
  image-rendering: pixelated;
}
#ending {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(560px, calc(100vw - 32px));
  height: fit-content;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 20px 22px;
  z-index: 50;
  box-shadow: 0 0 0 100vmax rgba(3, 4, 6, 0.82);
}
#ending h2 { font-family: var(--pixel); font-size: 16px; color: #ffb347; margin: 0 0 12px; letter-spacing: 2px; }
#ending p { font-size: 19px; line-height: 1.25; margin: 0 0 10px; }
#ending .panel-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
#memo-image { display: block; width: 100%; max-width: 288px; margin: 8px auto 0; image-rendering: pixelated; border: 1px solid #2c4a34; }
#memo-image[hidden] { display: none; }
#console-ask { margin-left: auto; padding: 0 8px; min-height: 24px; font-size: 10px; }
#console-toggle { padding: 0 8px; min-height: 24px; }
#ask-menu { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 8px; border-bottom: 1px solid #2a2e36; }
#ask-menu[hidden] { display: none; }
#ask-menu button { min-height: 28px; padding: 0 8px; font-size: 15px; }

/* Blueprint and databank screens: faint graph paper, like bunkers sketched sideways in an exercise book. */
#build-list, #databank-tree {
  background-color: #0b1310;
  background-image:
    linear-gradient(rgba(120, 190, 150, 0.10) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 190, 150, 0.10) 1px, transparent 1px),
    linear-gradient(rgba(120, 190, 150, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 190, 150, 0.05) 1px, transparent 1px);
  background-size: 40px 40px, 40px 40px, 8px 8px, 8px 8px;
}
#build-list .card, .node { box-shadow: 2px 2px 0 rgba(120, 190, 150, 0.12); }
#console-log {
  max-height: min(34vh, 260px);
  overflow-y: auto;
  padding: 8px 10px 10px;
  font-family: var(--mono);
  font-size: 20px;
  line-height: 1.05;
  -webkit-user-select: text;
  user-select: text;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#console.collapsed #console-log { display: none; }
.line { margin: 0 0 6px; color: #ffd9a6; }
.line.system { color: var(--muted); }
.line.hint { color: var(--hazard); }
.line.log { color: var(--log); text-shadow: 0 0 6px rgba(139, 224, 139, 0.35); }
.line.glitch { color: #d9a6ff; }
.line.typing::after { content: '\2589'; animation: blink 0.8s steps(1) infinite; margin-left: 1px; }
.line.old { opacity: 0.55; }
.line.goto { cursor: pointer; }
.line.goto::before { content: '\25ce  '; color: var(--amber); }
.line.goto:hover { text-decoration: underline; text-decoration-color: var(--amber); }
@keyframes blink { 50% { opacity: 0; } }

/* Vitals chips */
.chip.full .value { color: var(--amber); }
.chip .trend { font-size: 8px; min-width: 6px; margin-left: -2px; }
.chip .trend.up { color: #7bd88f; }
.chip .trend.down { color: var(--danger); }
.chip.warn { border-color: var(--danger); }
.chip.warn .value, .chip .flag { color: var(--danger); }
.chip .bar { width: 40px; height: 6px; background: #1d2127; display: inline-block; position: relative; }
.chip .bar i { position: absolute; inset: 0 auto 0 0; background: #8fd3f0; }
.chip.warn .bar i { background: var(--danger); }
#menu-main { padding: 4px 8px; font-size: 10px; }

/* Title screen. --s is the size of one art pixel, set from the screen in splash.js. */
#splash {
  --s: 4;
  --menu-top: 352px;
  --unit: calc(var(--s) * 1px);
  position: fixed;
  inset: 0;
  z-index: 100;
  overflow: hidden;
  background: #05030c;
}
#splash.leaving { animation: splash-off 320ms steps(6) forwards; pointer-events: none; }
@keyframes splash-off {
  to { filter: brightness(3); opacity: 0; }
}
#splash canvas { position: absolute; left: 0; top: 0; image-rendering: pixelated; }
.splash-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
.splash-crt {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 62%, rgba(0, 0, 0, 0.42) 100%),
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.16) 0 1px, transparent 1px 3px);
}
.splash-box {
  position: absolute;
  z-index: 1;
  left: 50%;
  transform: translateX(-50%);
  background: #0a0a16;
  border: var(--unit) solid #ffb347;
  box-shadow: 0 0 0 var(--unit) #05030c, 0 0 0 calc(var(--unit) * 2) #8a5a22;
  font-family: var(--pixel);
}
.splash-menu, .splash-confirm {
  top: var(--menu-top);
  width: max(calc(var(--unit) * 136), 240px);
  max-width: calc(100vw - 20px);
  padding: max(calc(var(--unit) * 2), 4px);
  max-height: calc(100dvh - var(--menu-top) - 24px);
  overflow-y: auto;
}
.splash-item {
  position: relative;
  display: block;
  width: 100%;
  min-height: max(calc(var(--unit) * 15), 38px);
  padding: 0 8px 0 max(calc(var(--unit) * 10), 26px);
  border: 0;
  background: transparent;
  color: #ffdf8a;
  text-align: left;
  font-family: var(--pixel);
  font-size: max(calc(var(--unit) * 7), 14px);
  line-height: 1;
  cursor: pointer;
}
.splash-item:disabled { color: #6a6780; cursor: default; }
.splash-item:focus { outline: none; background: #ffb347; color: #17090a; }
.splash-item:focus::before {
  content: '\25B6';
  position: absolute;
  left: max(calc(var(--unit) * 3), 8px);
  top: 50%;
  transform: translateY(-50%);
  animation: splash-blink 0.7s steps(1) infinite;
}
@keyframes splash-blink {
  50% { opacity: 0; }
}
.splash-box p { margin: 0; }
.splash-warn { color: #ff7a5c; font-size: max(calc(var(--unit) * 6), 13px); padding: 4px 8px; }
.splash-note { color: #c9cede; font-family: var(--mono); font-size: max(calc(var(--unit) * 7), 17px); line-height: 1.05; padding: 2px 8px 8px; }
.splash-about {
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(640px, calc(100vw - 20px));
  max-height: calc(100dvh - 20px);
  overflow-y: auto;
  padding: 14px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  align-items: start;
}
.splash-logo { width: 156px; height: 140px; image-rendering: pixelated; border: 2px solid #49536b; }
.splash-about .splash-warn { color: #8be08b; padding: 0; }
.splash-name { color: #ffdf8a; font-size: 18px; font-weight: 700; padding: 4px 0; }
.splash-about .splash-note { padding: 0 0 8px; font-size: 19px; }
.splash-links { list-style: none; margin: 0; padding: 0; }
.splash-links a {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 28px;
  padding: 0 6px;
  color: #c8f4ff;
  text-decoration: none;
  font-family: var(--mono);
  font-size: 19px;
}
.splash-links b { width: 66px; flex: none; color: #8d94a3; font-family: var(--pixel); font-size: 10px; font-weight: 400; }
.splash-links a:focus { outline: none; background: #ffb347; color: #17090a; }
.splash-links a:focus b { color: #17090a; }
.splash-back { grid-column: 1 / -1; min-height: 36px; font-size: 14px; padding-left: 28px; }
.splash-account {
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(460px, calc(100vw - 20px));
  max-height: calc(100dvh - 20px);
  overflow-y: auto;
  padding: 12px;
}
.splash-account .splash-warn { padding: 0 0 6px; color: #ffdf8a; }
.splash-account .splash-note { padding: 0 0 8px; font-size: 18px; }
.splash-form { display: block; }
.splash-field { display: block; margin-bottom: 8px; }
.splash-field span { display: block; margin-bottom: 3px; color: #8be08b; font-size: 10px; }
.splash-field input {
  width: 100%;
  min-height: 36px;
  padding: 0 8px;
  background: #05030c;
  color: #fff;
  border: 2px solid #49536b;
  border-radius: 0;
  font-family: var(--mono);
  font-size: 20px;
  -webkit-user-select: text;
  user-select: text;
}
.splash-field input:focus { outline: none; border-color: #ffb347; }
.splash-small { min-height: 34px; font-size: 13px; padding-left: 26px; }
.splash-small:focus::before { left: 8px; }
.splash-small:hover:not(:disabled) { background: #2a2230; }
.splash-small:focus:hover { background: #ffb347; }
.splash-message { color: #ff7a5c; font-family: var(--mono); font-size: 18px; line-height: 1.1; padding: 2px 0; }
.splash-message:empty { display: none; }
.splash-message.good { color: #8be08b; }
.splash-who { margin-bottom: 2px; color: #8be08b; }
.splash-who:empty { display: none; }
.splash-save-line { margin-bottom: 2px; color: #8be08b; }
.splash-save-line.bad { color: #ffb347; }
.splash-save-line:empty { display: none; }
.splash-foot {
  position: absolute;
  z-index: 0;
  left: 0;
  right: 0;
  bottom: max(calc(var(--unit) * 2), 4px);
  text-align: center;
  color: #8d94a3;
  font-size: max(calc(var(--unit) * 4), 9px);
  letter-spacing: 1px;
  pointer-events: none;
}
@media (max-width: 520px) {
  .splash-about { grid-template-columns: 1fr; }
  .splash-logo { width: 78px; height: 70px; }
}
@media (max-height: 420px) {
  .splash-menu .splash-item { min-height: 31px; }
  .splash-who { display: none; }
  .splash-about { padding: 6px 10px; gap: 2px 12px; }
  .splash-logo { width: 78px; height: 70px; }
  .splash-name { font-size: 14px; padding: 2px 0; }
  .splash-about .splash-note { font-size: 16px; padding-bottom: 2px; }
  .splash-links a { min-height: 25px; font-size: 17px; }
  .splash-back { min-height: 28px; font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .splash-item:focus::before { animation: none; }
}

/* Panels: room details, build menu, placement bar */
.panel {
  position: fixed;
  background: var(--panel);
  border: 2px solid var(--border);
  font-family: var(--mono);
  font-size: 18px;
  line-height: 1.1;
}
.panel[hidden] { display: none; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 2px solid var(--border);
  color: var(--amber);
  font-family: var(--pixel);
  font-size: 12px;
  letter-spacing: 1px;
}
.panel-head button { padding: 0 8px; min-height: 24px; }
.panel .good { color: #7bd88f; }
.panel .warn { color: var(--hazard); }
.panel .bad { color: var(--danger); }
.panel .meta { color: var(--muted); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.danger { background: #4a1712; border-color: var(--danger); }
button.good-btn:not(:disabled) { background: #13404a; border-color: #5ad1ff; color: #bff6ff; }

#roompanel {
  left: var(--gutter);
  top: 52px;
  width: min(340px, 60vw);
}
#roompanel .panel-body { padding: 8px 10px; display: grid; gap: 4px; }
#roompanel .panel-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 10px 10px; }
#roompanel .panel-actions button { font-family: var(--pixel); font-size: 11px; min-height: 36px; }

#buildmenu {
  left: var(--gutter);
  bottom: calc(max(10px, env(safe-area-inset-bottom)) + 62px);
  width: min(560px, calc(100vw - 2 * var(--gutter)));
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  z-index: 2;
}
#build-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 6px;
  padding: 8px;
}
.card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  text-align: left;
  font-family: var(--mono);
  font-size: 17px;
  line-height: 1.05;
  padding: 8px;
  min-height: 96px;
}
.card .name { font-family: var(--pixel); font-size: 11px; color: var(--amber); }
.card .meta, .card .desc { color: var(--muted); }
.card .cost .short { color: var(--danger); }
.card .cost span + span::before { content: ' \00b7 '; color: var(--muted); }
.card.locked .name { color: var(--muted); letter-spacing: 1px; }

#placebar {
  left: 50%;
  transform: translateX(-50%);
  top: 52px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 12px;
  max-width: calc(100vw - 2 * var(--gutter));
}
#placebar b { font-weight: normal; color: var(--amber); }
#placebar button { font-family: var(--pixel); font-size: 11px; }
#place-ok:not(:disabled) { background: #1f5a2c; border-color: #7bd88f; }

/* Databank */
#tools button { position: relative; }
.badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  background: var(--log);
  box-shadow: 0 0 6px var(--log);
}
#research-chip { font-family: var(--pixel); font-size: 10px; color: var(--log); cursor: pointer; }
#research-chip .bar { width: 50px; }
#research-chip .bar i { background: var(--log); }

#databank {
  inset: 56px var(--gutter) calc(max(10px, env(safe-area-inset-bottom)) + 62px);
  display: flex;
  flex-direction: column;
  z-index: 3;
  background: rgba(8, 11, 10, 0.96);
  border-color: #2c4a34;
}
#databank .panel-head { border-color: #2c4a34; }
#databank-data { color: var(--log); margin-left: auto; font-family: var(--mono); font-size: 18px; }
.tabs { display: flex; gap: 4px; }
.tabs button { font-family: var(--pixel); font-size: 11px; padding: 4px 10px; position: relative; }
.tabs .badge { top: 2px; right: 2px; width: 6px; height: 6px; }
.tab-body { flex: 1; overflow: auto; position: relative; }

#tree-cols {
  position: relative;
  display: grid;
  grid-template-columns: 96px repeat(3, minmax(200px, 1fr));
  gap: 10px 32px;
  padding: 12px 16px 16px;
  min-width: 860px;
}
.eras { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.era { font-family: var(--pixel); font-size: 10px; padding: 3px 6px; border: 1px solid #2c4a34; color: var(--log); }
.era.bad { color: var(--muted); border-color: #2a2f38; }
.gen-head { font-family: var(--pixel); font-size: 11px; color: var(--log); border-bottom: 1px solid #2c4a34; padding-bottom: 4px; }
.line-head { font-family: var(--pixel); font-size: 10px; color: var(--amber); padding-top: 10px; border-top: 1px solid #1d2a21; }
.gen-cell { display: flex; flex-direction: column; gap: 8px; padding-top: 6px; border-top: 1px solid #1d2a21; min-height: 24px; }
#tree-edges { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
#tree-edges path { fill: none; stroke: #2c4a34; stroke-width: 2; }
#tree-edges path.lit { stroke: #5fd08a; }
.tier-head { font-family: var(--pixel); font-size: 11px; color: var(--log); margin-bottom: 4px; }
.tier-gate { color: var(--muted); font-size: 16px; margin-bottom: 8px; min-height: 1em; }
.tier-gate.bad { color: var(--hazard); }
.tier { display: flex; flex-direction: column; gap: 8px; }
.node {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  font-family: var(--mono);
  font-size: 17px;
  line-height: 1.05;
  padding: 8px;
  background: #101814;
  border-color: #2c4a34;
  position: relative;
}
.node .name { font-family: var(--pixel); font-size: 11px; color: #b6f36a; }
.node .kind { font-size: 14px; color: var(--muted); letter-spacing: 1px; }
.node .effect { color: var(--text); }
.node .status { color: var(--muted); }
.node .status.bad { color: var(--hazard); }
.node .bar { display: block; width: 100%; height: 4px; background: #1d2a18; margin-top: 4px; }
.node .bar i { display: block; height: 100%; background: var(--log); }
.node.available { border-color: #5fd08a; cursor: pointer; }
.node.available:hover { background: #16261c; }
.node.decrypted { border-color: #3d6b47; background: #0f2016; }
.node.decrypted .status { color: #7bd88f; }
.node.decrypting { border-color: var(--log); box-shadow: 0 0 10px rgba(139, 224, 139, 0.25); }
.node.static, .node.future {
  color: #3a4a3e;
  background: repeating-linear-gradient(0deg, #0d120f 0 2px, #111a14 2px 4px);
  cursor: default;
}
.node.static .name, .node.future .name { color: #3d5a44; letter-spacing: 1px; }
.node.blocked { cursor: default; }

#databank-memory { padding: 12px 16px; font-family: var(--mono); font-size: 20px; line-height: 1.1; }
.fragment { border-left: 3px solid #2c4a34; padding: 4px 0 4px 12px; margin-bottom: 14px; max-width: 70ch; }
.fragment .title { font-family: var(--pixel); font-size: 11px; color: var(--log); display: block; margin-bottom: 4px; }
.fragment .play {
  font-size: 9px;
  padding: 1px 6px;
  margin-right: 8px;
  color: var(--log);
  border-color: #2c4a34;
  background: #101814;
  vertical-align: middle;
}
.fragment .title small { color: var(--muted); font-family: var(--mono); font-size: 16px; margin-left: 6px; }
.fragment p { margin: 0; color: #cfe8d2; -webkit-user-select: text; user-select: text; }
.fragment .redact { color: #3d5a44; background: #3d5a44; letter-spacing: -1px; box-shadow: inset 0 -2px 0 #2c4a34; }
.fragment.new { border-left-color: var(--log); }
.memory-empty { color: var(--muted); }

/* Combat */
#threat-chip {
  font-family: var(--pixel);
  font-size: 10px;
  color: #ff8a8a;
  border-color: var(--danger);
  cursor: pointer;
  animation: threat-pulse 1s steps(2) infinite;
}
@keyframes threat-pulse { 50% { border-color: #5a1a14; } }
#tools button[data-tool="reinforce"].active { background: #9ac8ff; border-color: #d0e6ff; }

#stasis {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(230, 240, 255, 0.08);
  z-index: 6;
  pointer-events: none;
}
#stasis p {
  font-family: var(--pixel);
  font-size: clamp(14px, 3vw, 28px);
  letter-spacing: 4px;
  color: #0d1a2a;
  text-shadow: 0 0 12px #ffffff;
  text-align: center;
  padding: 0 16px;
}
#stasis.dark p { color: #cfe8ff; text-shadow: 0 0 12px #5ab8e6; }

/* Minimap */
#minimap {
  right: max(10px, env(safe-area-inset-right));
  top: 56px;
  padding: 3px;
  line-height: 0;
}
#minimap-canvas {
  width: 96px;
  height: 160px;
  image-rendering: pixelated;
  cursor: crosshair;
  touch-action: none;
}
@media (max-width: 760px), (max-height: 500px) {
  #minimap { display: none; }
}

/* Structural warnings */
#hazard-chip {
  font-family: var(--pixel);
  font-size: 10px;
  color: var(--amber);
  border-color: var(--amber);
  cursor: pointer;
}
#dighint {
  left: 50%;
  transform: translateX(-50%);
  top: 52px;
  padding: 6px 12px;
  max-width: calc(100vw - 2 * var(--gutter));
  pointer-events: none;
}
#dighint.over { border-color: var(--danger); color: #ffb0a8; }
#dighint.near { border-color: var(--amber); color: #ffd9a6; }

/* Fill materials */
#tools button[data-tool="fill"].active { background: #c8c0b0; border-color: #e8e0d0; }
#fillbar {
  left: var(--gutter);
  bottom: calc(max(10px, env(safe-area-inset-bottom)) + 62px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  max-width: calc(100vw - 2 * var(--gutter));
  overflow-x: auto;
  z-index: 2;
}
.fill-label { font-family: var(--pixel); font-size: 10px; color: var(--amber); white-space: nowrap; }
#fill-list { display: flex; gap: 6px; }
#fill-list button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  font-family: var(--mono);
  font-size: 16px;
  line-height: 1;
  padding: 5px 8px;
  white-space: nowrap;
}
#fill-list button .name { font-family: var(--pixel); font-size: 10px; display: flex; align-items: center; gap: 5px; }
#fill-list button .swatch { width: 10px; height: 10px; display: inline-block; border: 1px solid rgba(255, 255, 255, 0.3); }
#fill-list button .pips { letter-spacing: 1px; color: var(--muted); }
#fill-list button.active .pips, #fill-list button.active .cost { color: #2a1d0a; }
#fill-list button .short { color: var(--danger); }

/* Objective and help */
#objective {
  position: fixed;
  left: var(--gutter);
  bottom: calc(max(10px, env(safe-area-inset-bottom)) + 62px);
  max-width: min(420px, 50vw);
  font-family: var(--mono);
  font-size: 18px;
  color: var(--text);
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}
#objective::before { content: 'OBJECTIVE \203a  '; font-family: var(--pixel); font-size: 10px; color: var(--amber); }
#menu-help, #menu-sound, #menu-voice { padding: 4px 9px; font-size: 11px; }
#menu-help { min-width: 28px; }
.sound-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
.sound-controls label { display: flex; gap: 6px; align-items: center; }
#menu-sound.muted, #menu-voice.muted { color: var(--muted); text-decoration: line-through; }
#help {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 2 * var(--gutter)));
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  z-index: 5;
}
#help .panel-body { padding: 8px 14px 12px; }
#help p { margin: 6px 0; }
#help b { color: var(--amber); font-weight: normal; }
#help table { border-collapse: collapse; width: 100%; margin: 8px 0; }
#help th, #help td { text-align: left; padding: 2px 8px 2px 0; border-bottom: 1px solid var(--border); }
#help th { color: var(--muted); font-weight: normal; }
#help h3 { font-family: var(--pixel); font-size: 11px; color: var(--amber); font-weight: normal; margin: 14px 0 6px; }
#records { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 2px 14px; }
#records span { color: var(--muted); }
.save-actions { display: flex; gap: 8px; }
.save-actions button { font-family: var(--pixel); font-size: 11px; }
.save-server { flex-wrap: wrap; margin-top: 8px; }
.save-server input { width: 130px; min-height: 28px; padding: 0 6px; background: #0d0f13; color: inherit; border: 1px solid #2a2e36; font-family: var(--pixel); font-size: 11px; }

/* First surface camera feed */
#camfeed {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 2 * var(--gutter)), calc((100vh - 140px) * 16 / 9));
  z-index: 4;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
}
#camfeed-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  image-rendering: pixelated;
  filter: contrast(1.1);
}
.voice-pick { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.voice-pick label { display: flex; gap: 6px; align-items: center; }
.voice-pick select { max-width: 220px; font-family: var(--mono); font-size: 16px; background: #1a1e25; color: var(--text); border: 2px solid var(--border); }

/* Recovered memories play in their own window, with a cassette while the tape runs. */
#memo {
  left: 50%;
  top: 56px;
  transform: translateX(-50%);
  width: min(440px, calc(100vw - 2 * var(--gutter)));
  z-index: 3;
  border-color: #3d5a3d;
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.7), 0 0 12px rgba(139, 224, 139, 0.12);
}
#memo .panel-head { color: var(--log); border-bottom-color: #3d5a3d; }
#memo-tape { margin-left: auto; display: inline-flex; }
#memo-tape .reel { animation: reel 1.2s linear infinite; }
#memo-text { margin: 0; padding: 10px 12px 12px; font-family: var(--mono); font-size: 20px; line-height: 1.15; max-height: 40vh; overflow-y: auto; }
@keyframes reel { to { transform: rotate(360deg); } }

#camfeed .panel-actions { display: flex; justify-content: flex-end; padding: 8px; }
#camfeed .panel-actions button { font-family: var(--pixel); font-size: 11px; }

/* Portrait hint */
#rotate-hint {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: rgba(5, 6, 8, 0.94);
  padding: 24px 16px;
  font-size: 14px;
  z-index: 10;
}
#rotate-hint p { margin: 0 0 10px; }
#rotate-hint p:first-child { color: var(--amber); }
#rotate-hint button { margin-top: 14px; }
@media (orientation: portrait) and (max-width: 820px) {
  #rotate-hint:not(.dismissed) { display: flex; }
}

/* Mid-width screens: resource chips drop their labels (the tooltip keeps the name). */
@media (max-width: 1500px) {
  #resources .chip .label { display: none; }
  #resources .chip { padding: 4px 6px; }
  .brand { display: none; }
}
@media (max-width: 1400px) {
  #drone-status { display: none; }
  #power-chip .label, #air-chip .label { display: none; }
}
@media (max-width: 1180px) {
  #drone-status { display: none; }
  #research-chip .label { display: none; }
  #research-chip .bar { width: 30px; }
}

/* Small landscape phones */
@media (max-width: 760px), (max-height: 430px) {
  #topbar { gap: 6px; font-size: 10px; }
  .brand { display: none; }
  .chip { padding: 3px 6px; gap: 4px; }
  .chip .label { display: none; }
  #tools button { min-width: 60px; min-height: 44px; font-size: 11px; }
  #tools .key { display: none; }
  #console-log { font-size: 18px; max-height: 30vh; }
  #tileinfo, #roompanel, #placebar { top: 44px; font-size: 16px; }
  #drone-status { display: none; }
  #objective { bottom: calc(max(10px, env(safe-area-inset-bottom)) + 54px); font-size: 15px; }
  .chip .bar { width: 24px; }
  #buildmenu { bottom: calc(max(10px, env(safe-area-inset-bottom)) + 54px); max-height: calc(100vh - 110px); }
  #build-list { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .card { min-height: 0; font-size: 15px; }
  .card .desc { display: none; }
  #databank { inset: 44px var(--gutter) calc(max(10px, env(safe-area-inset-bottom)) + 54px); }
  #tree-cols { gap: 8px 20px; min-width: 760px; grid-template-columns: 80px repeat(3, minmax(180px, 1fr)); }
  .node { font-size: 15px; padding: 6px; }
  #research-chip .bar { display: none; }
}
@media (pointer: coarse) {
  #tools .key { display: none; }
}
