:root {
  color-scheme: dark;
  --bg-deep: #03090d;
  --bg: #071117;
  --surface: #0b1820;
  --surface-raised: #10232d;
  --surface-soft: #132b35;
  --line: #24424b;
  --line-bright: #3f6b73;
  --text: #e8f3ef;
  --text-muted: #91aaa7;
  --text-dim: #647d7b;
  --accent: #57dbc5;
  --accent-bright: #a2ffe7;
  --accent-dark: #123c3b;
  --amber: #f1bb64;
  --danger: #ff7c72;
  --good: #75e096;
  --screen-width: 840px;
  --screen-height: 504px;
  --radius: 13px;
  --shadow: 0 20px 55px rgba(0, 0, 0, 0.34);
  --font-ui: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-condensed: "Arial Narrow", "Roboto Condensed", Impact, sans-serif;
  --font-pixel: "Lucida Console", "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg-deep);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 52% -10%, rgba(55, 140, 133, 0.15), transparent 34rem),
    linear-gradient(180deg, #061117 0%, var(--bg-deep) 72%);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button,
output {
  font: inherit;
}

button {
  color: inherit;
}

button:not(:disabled) {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

button,
[tabindex] {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid var(--accent-bright);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  color: #00100d;
  background: var(--accent-bright);
  border-radius: 7px;
  font-weight: 800;
  transform: translateY(-160%);
  transition: transform 120ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: grid;
  grid-template-columns: minmax(230px, 1fr) auto minmax(280px, 1fr);
  align-items: center;
  gap: 16px;
  min-height: 48px;
  padding: 6px clamp(12px, 1.8vw, 24px);
  background: rgba(5, 15, 20, 0.94);
  border-bottom: 1px solid rgba(87, 219, 197, 0.18);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(16px);
}

.brand-block,
.utility-bar,
.session-state,
.screen-caption,
.panel-heading,
.building-title-row,
.panel-actions,
.control-heading,
.softkey-row,
.footer-note {
  display: flex;
  align-items: center;
}

.brand-block {
  min-width: 0;
  gap: 12px;
}

.brand-mark,
.start-sigil {
  display: grid;
  place-items: center;
  color: var(--accent-bright);
  border: 1px solid var(--accent);
  font-family: var(--font-condensed);
  font-weight: 900;
  letter-spacing: -0.06em;
  transform: skewX(-7deg);
}

.brand-mark {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, rgba(87, 219, 197, 0.18), rgba(87, 219, 197, 0.02));
  border-radius: 6px;
  font-size: 17px;
}

.eyebrow,
.panel-kicker,
.start-series {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.15em;
  line-height: 1.2;
  text-transform: uppercase;
}

.brand-block h1 {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-family: var(--font-condensed);
  font-size: clamp(20px, 1.5vw, 25px);
  font-stretch: condensed;
  letter-spacing: 0.025em;
  line-height: 1.05;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.brand-block h1 span {
  margin-left: 6px;
  color: var(--text-muted);
  font-size: 0.73em;
  font-weight: 500;
}

.session-state {
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-light,
.activity-led {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: var(--good);
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(117, 224, 150, 0.75);
}

.utility-bar {
  justify-content: flex-end;
  gap: 6px;
}

.utility-button,
.caption-button,
.text-button,
.panel-wide-button,
.panel-actions button {
  border: 1px solid var(--line);
  background: rgba(17, 40, 50, 0.75);
  transition: border-color 120ms ease, background-color 120ms ease, color 120ms ease, transform 80ms ease;
}

.utility-button {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 8px;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.utility-button > span:first-child {
  color: var(--accent);
  font-size: 15px;
}

.utility-button:hover,
.caption-button:hover,
.text-button:hover,
.panel-wide-button:hover,
.panel-actions button:hover {
  color: var(--text);
  background: var(--surface-soft);
  border-color: var(--line-bright);
}

.utility-button:active,
.caption-button:active,
.panel-wide-button:active,
.panel-actions button:active {
  transform: translateY(1px);
}

.dashboard {
  width: 100%;
  max-width: 1480px;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(210px, 240px) auto minmax(220px, 260px);
  grid-template-areas: "left station right";
  align-items: start;
  justify-content: center;
  gap: clamp(8px, 1.2vw, 16px);
  margin: 0 auto;
  padding: 8px clamp(10px, 1.5vw, 18px);
}

.panel-stack {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-stack-left {
  grid-area: left;
}

.panel-stack-right {
  grid-area: right;
}

.info-panel,
.control-deck {
  overflow: hidden;
  background:
    linear-gradient(145deg, rgba(18, 40, 50, 0.9), rgba(7, 19, 25, 0.96));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 25px rgba(0, 0, 0, 0.16);
}

.info-panel {
  padding: 10px 12px;
}

.panel-heading {
  min-width: 0;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 6px;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(80, 121, 124, 0.25);
}

.panel-heading h2,
.control-heading h2 {
  margin: 0;
  font-family: var(--font-condensed);
  font-size: 17px;
  letter-spacing: 0.035em;
  line-height: 1;
  text-transform: uppercase;
}

.mission-number {
  color: rgba(162, 255, 231, 0.35);
  font-family: var(--font-pixel);
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
}

.mission-objective {
  min-height: auto;
  margin: 0 0 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.progress-meta output {
  color: var(--accent-bright);
}

.progress-track {
  height: 5px;
  overflow: hidden;
  background: #041014;
  border-radius: 99px;
  box-shadow: inset 0 0 0 1px rgba(65, 105, 106, 0.34);
}

.progress-track > span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #2a9e91, var(--accent-bright));
  box-shadow: 0 0 9px rgba(87, 219, 197, 0.45);
  transition: width 180ms ease;
}

.compact-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 8px 0 0;
}

.compact-stats div,
.building-metrics div {
  min-width: 0;
  padding: 5px 6px;
  background: rgba(4, 14, 19, 0.58);
  border: 1px solid rgba(52, 86, 90, 0.32);
  border-radius: 6px;
}

.compact-stats dt,
.building-metrics dt {
  margin-bottom: 2px;
  color: var(--text-dim);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.compact-stats dd,
.building-metrics dd {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trend-legend,
.building-category,
#research-points {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.trend-legend i {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 3px;
  background: var(--good);
  border-radius: 50%;
}

.resource-list {
  display: grid;
  gap: 4px;
}

.resource-row {
  min-width: 0;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto 39px;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: rgba(3, 13, 17, 0.48);
  border: 1px solid rgba(62, 101, 104, 0.24);
  border-radius: 8px;
}

.resource-row.is-shortage {
  background: rgba(91, 24, 25, 0.2);
  border-color: rgba(255, 124, 114, 0.5);
}

.resource-symbol {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  color: var(--accent-bright);
  background: var(--accent-dark);
  border: 1px solid rgba(87, 219, 197, 0.28);
  border-radius: 6px;
  font-family: var(--font-pixel);
  font-size: 14px;
  font-weight: 700;
}

.resource-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.resource-copy > span {
  overflow: hidden;
  font-size: 13px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.resource-copy small {
  overflow: hidden;
  color: var(--text-dim);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.resource-amount {
  color: var(--text);
  font-family: var(--font-pixel);
  font-size: 14px;
  font-weight: 700;
}

.resource-delta {
  justify-self: end;
  min-width: 36px;
  padding: 2px 4px;
  border-radius: 4px;
  font-family: var(--font-pixel);
  font-size: 11px;
  text-align: center;
}

.resource-delta.is-positive {
  color: var(--good);
  background: rgba(117, 224, 150, 0.1);
}

.resource-delta.is-negative {
  color: var(--danger);
  background: rgba(255, 124, 114, 0.1);
}

.resource-delta.is-neutral {
  color: var(--text-dim);
  background: rgba(113, 139, 137, 0.08);
}

.game-station {
  grid-area: station;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 880px;
}

.screen-bezel {
  width: 100%;
  max-width: 100%;
  padding: 6px;
  background: linear-gradient(145deg, #18313b, #08141b 70%);
  border: 1px solid #31515a;
  border-radius: 10px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.screen-topline,
.screen-caption {
  color: #78928f;
  font-family: var(--font-pixel);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.screen-topline {
  display: flex;
  justify-content: space-between;
  padding: 1px 2px 4px;
}

.screen-view-info {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

#zoom-value {
  min-width: 88px;
  color: var(--accent-bright);
  text-align: right;
}

.screen-viewport {
  position: relative;
  container-type: inline-size;
  width: var(--screen-width);
  height: var(--screen-height);
  max-width: 100%;
  overflow: hidden;
  background: #000;
  border: 1px solid #28454a;
  box-shadow: 0 0 0 1px #020709, inset 0 0 22px rgba(0, 0, 0, 0.7);
  isolation: isolate;
  border-radius: 8px;
  margin: 0 auto;
}

.game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  image-rendering: auto;
  touch-action: none;
  cursor: grab;
}

.game-canvas.is-panning {
  cursor: grabbing;
}

body.is-retro .game-canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.game-canvas:focus-visible {
  outline-offset: -4px;
}

.resource-hud {
  position: absolute;
  z-index: 5;
  top: 10px;
  left: 50%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) minmax(0, 1.55fr) repeat(2, minmax(0, 1fr));
  gap: 5px;
  width: min(95%, 850px);
  padding: 5px;
  color: #effffb;
  background: rgba(3, 14, 20, 0.88);
  border: 1px solid rgba(121, 230, 215, 0.52);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
  pointer-events: none;
  transform: translateX(-50%);
}

.resource-hud-item,
.resource-hud-free {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 3px;
  border: 1px solid rgba(114, 183, 180, 0.23);
  border-radius: 6px;
  text-align: center;
}

.resource-hud-item > span,
.resource-hud-free > span {
  overflow: hidden;
  max-width: 100%;
  color: #a9d0cd;
  font-size: clamp(10px, 0.75vw, 13px);
  font-weight: 700;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.resource-hud-item output {
  color: #f5fcfa;
  font-size: clamp(17px, 1.35vw, 24px);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  line-height: 1.15;
}

.resource-hud-item small,
.resource-hud-free small {
  color: #9cb6b3;
  font-size: 10px;
  line-height: 1.1;
  white-space: nowrap;
}

.resource-hud-item small.is-positive { color: #83e4a2; }
.resource-hud-item small.is-negative { color: #ff9b91; }

.resource-hud-free {
  background: linear-gradient(180deg, rgba(22, 100, 89, 0.78), rgba(8, 53, 52, 0.94));
  border-color: rgba(163, 255, 230, 0.72);
  box-shadow: inset 0 0 13px rgba(111, 246, 210, 0.12), 0 0 16px rgba(80, 228, 190, 0.2);
}

.resource-hud-free output {
  color: #fff4b4;
  font-size: clamp(28px, 2.15vw, 38px);
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 0 14px rgba(255, 225, 124, 0.38);
}

.resource-hud-free.is-shortage {
  background: linear-gradient(180deg, rgba(117, 42, 38, 0.9), rgba(65, 21, 25, 0.96));
  border-color: #ff9587;
}

body.is-retro .resource-hud {
  display: none;
}

@container (max-width: 700px) {
  .resource-hud {
    top: 5px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 3px;
    padding: 3px;
  }

  .resource-hud-free {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .resource-hud-item > span,
  .resource-hud-free > span {
    font-size: 10px;
  }

  .resource-hud-item output { font-size: 16px; }
  .resource-hud-free output { font-size: 24px; }
}

.screen-effects {
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(180deg, transparent 0, transparent 3px, rgba(5, 19, 20, 0.06) 4px);
  mix-blend-mode: screen;
}

.screen-caption {
  min-height: 22px;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 0;
}

.screen-caption > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.activity-led {
  width: 5px;
  height: 5px;
}

.caption-button {
  min-height: 24px;
  padding: 2px 9px;
  color: var(--text-muted);
  border-radius: 5px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.start-overlay {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 40%, rgba(45, 136, 128, 0.3), transparent 45%),
    linear-gradient(180deg, rgba(3, 12, 20, 0.96), rgba(1, 5, 8, 0.98));
}

.start-overlay::after {
  content: "";
  position: absolute;
  z-index: -1;
  right: -18%;
  bottom: -30%;
  width: 75%;
  aspect-ratio: 1;
  border: 1px solid rgba(87, 219, 197, 0.18);
  border-radius: 50%;
  box-shadow: 0 0 60px rgba(54, 172, 155, 0.14), inset 0 0 40px rgba(54, 172, 155, 0.08);
}

.pixel-stars {
  position: absolute;
  z-index: -2;
  inset: 0;
  opacity: 0.65;
  background-image:
    radial-gradient(circle, #b7fff1 0 1px, transparent 1px),
    radial-gradient(circle, #619b99 0 1px, transparent 1px);
  background-position: 13px 17px, 41px 7px;
  background-size: 67px 53px, 89px 71px;
}

.start-content {
  width: min(78%, 350px);
  padding: 10px;
  text-align: center;
}

.start-sigil {
  width: 41px;
  height: 41px;
  margin: 0 auto 11px;
  background: rgba(17, 55, 54, 0.56);
  border-radius: 4px;
  font-size: 20px;
}

.start-series {
  color: var(--amber);
}

.start-content h2 {
  margin: 4px 0 10px;
  font-family: var(--font-condensed);
  font-size: clamp(22px, 4.3vw, 45px);
  font-weight: 900;
  letter-spacing: 0.01em;
  line-height: 0.85;
  text-transform: uppercase;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.5);
}

.start-content h2 span {
  color: var(--accent);
  font-size: 0.55em;
  letter-spacing: 0.12em;
}

.start-content > p:not(.start-series) {
  margin: 0 auto 12px;
  color: var(--text-muted);
  font-size: clamp(10px, 1.4vw, 14px);
}

.start-actions {
  display: grid;
  gap: 6px;
  width: min(190px, 100%);
  margin: 0 auto 8px;
}

.start-button,
.continue-button {
  min-height: 31px;
  padding: 6px 12px;
  color: #00120f;
  background: linear-gradient(180deg, var(--accent-bright), var(--accent));
  border: 0;
  border-radius: 4px;
  box-shadow: 0 4px 14px rgba(30, 170, 150, 0.25);
  font-family: var(--font-condensed);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.continue-button {
  color: var(--text);
  background: rgba(13, 40, 47, 0.9);
  border: 1px solid var(--line-bright);
}

.start-content small {
  color: var(--text-dim);
  font-family: var(--font-pixel);
  font-size: clamp(8px, 1vw, 11px);
}

/* RTS Build Dock & Command Station */
.build-dock {
  width: 100%;
  background: linear-gradient(180deg, rgba(14, 32, 40, 0.95), rgba(7, 18, 24, 0.98));
  border: 1px solid rgba(87, 219, 197, 0.25);
  border-radius: 10px;
  padding: 6px 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(162, 255, 231, 0.1);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dock-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(87, 219, 197, 0.15);
}

.dock-title {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.dock-title h2 {
  margin: 0;
  font-family: var(--font-condensed);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent-bright);
}

.dock-quick-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dock-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: rgba(18, 44, 54, 0.85);
  border: 1px solid rgba(87, 219, 197, 0.3);
  border-radius: 5px;
  color: var(--text);
  font-family: var(--font-condensed);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: all 120ms ease;
  user-select: none;
}

.dock-action-btn:hover {
  background: rgba(30, 75, 90, 0.9);
  border-color: var(--accent-bright);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(87, 219, 197, 0.2);
}

.dock-action-btn:active {
  transform: translateY(1px);
}

.dock-action-btn.is-active {
  background: linear-gradient(180deg, #ff7c72, #a82e26);
  border-color: #ffb4ac;
  color: #fff;
  box-shadow: 0 0 14px rgba(255, 124, 114, 0.5);
}

.dock-btn-cancel:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.dock-cards {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 5px;
  width: 100%;
}

.dock-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px 4px;
  background: rgba(10, 25, 33, 0.85);
  border: 1px solid rgba(63, 107, 115, 0.4);
  border-radius: 6px;
  cursor: pointer;
  transition: all 140ms ease;
  overflow: hidden;
  text-align: center;
  min-height: 94px;
  user-select: none;
}

.dock-card:hover:not(:disabled) {
  background: rgba(18, 48, 62, 0.95);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4), 0 0 12px rgba(87, 219, 197, 0.25);
}

.dock-card.is-selected {
  background: rgba(20, 60, 75, 0.95);
  border: 2px solid var(--accent-bright);
  box-shadow: 0 0 18px rgba(87, 219, 197, 0.5), inset 0 0 12px rgba(87, 219, 197, 0.2);
  transform: translateY(-2px);
}

.dock-card:disabled,
.dock-card.is-locked {
  opacity: 0.38;
  filter: grayscale(80%);
  cursor: not-allowed;
}

.dock-card-thumb {
  width: 40px;
  height: 40px;
  background-size: contain;
  background-position: center bottom;
  background-repeat: no-repeat;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.5));
  transition: transform 140ms ease;
}

.dock-card:hover:not(:disabled) .dock-card-thumb {
  transform: scale(1.08);
}

.dock-card-name {
  font-family: var(--font-condensed);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.dock-card-costs {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  margin-top: 2px;
}

.dock-card-costs span {
  font-family: var(--font-pixel);
  font-size: 9.5px;
  font-weight: 400;
  line-height: 1.1;
  padding: 0 1px;
  border-radius: 2px;
}

.cost-c {
  color: #f7d96c;
  background: rgba(247, 217, 108, 0.08);
}

.cost-e {
  color: #f16a91;
  background: rgba(241, 106, 145, 0.08);
}

.cost-i {
  color: #68cedb;
  background: rgba(104, 206, 219, 0.08);
}

.dock-card-costs span.insufficient {
  color: #ff7c72 !important;
  background: rgba(255, 124, 114, 0.2) !important;
  text-decoration: line-through;
}

.building-category {
  max-width: 45%;
  overflow: hidden;
  color: var(--accent);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.building-empty {
  min-height: 90px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 5px;
  color: var(--text-dim);
  text-align: center;
}

.building-empty > span {
  color: rgba(87, 219, 197, 0.45);
  font-size: 26px;
}

.building-empty p {
  max-width: 180px;
  margin: 0;
  font-size: 12px;
}

.building-title-row {
  gap: 10px;
  margin-bottom: 11px;
}

.building-preview {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  background: #030b0f;
  border: 1px solid var(--line);
  border-radius: 6px;
  image-rendering: pixelated;
}

.building-title-row h3,
.building-title-row p {
  margin: 0;
}

.building-title-row h3 {
  font-size: 15px;
}

.building-title-row p {
  color: var(--text-muted);
  font-size: 11px;
}

.building-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin: 0 0 11px;
}

.building-role {
  margin: -3px 0 10px;
  padding: 8px 9px;
  color: var(--text-muted);
  background: rgba(5, 18, 23, 0.62);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.35;
}

.panel-actions {
  gap: 7px;
}

.panel-actions button,
.panel-wide-button {
  min-height: 38px;
  padding: 7px 10px;
  border-radius: 7px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
}

.panel-actions button {
  flex: 1;
}

.panel-actions .danger-action:hover {
  color: var(--danger);
  border-color: rgba(255, 124, 114, 0.55);
}

.research-current {
  padding: 10px;
  margin-bottom: 10px;
  background: rgba(3, 13, 17, 0.48);
  border: 1px solid rgba(62, 101, 104, 0.24);
  border-radius: 7px;
}

.panel-wide-button {
  width: 100%;
}

.research-cta {
  color: #031014;
  background: linear-gradient(135deg, var(--accent-bright), #6ee7c7);
  border-color: rgba(155, 255, 228, 0.9);
  box-shadow: 0 0 16px rgba(87, 219, 197, 0.25);
  font-size: 13px;
}

.research-cta:hover {
  color: #02090c;
  border-color: #fff;
  box-shadow: 0 0 22px rgba(87, 219, 197, 0.42);
}

.text-button {
  padding: 3px 6px;
  color: var(--text-dim);
  background: transparent;
  border-color: transparent;
  border-radius: 4px;
  font-size: 11px;
}

.event-log {
  max-height: 110px;
  display: flex;
  flex-direction: column-reverse;
  gap: 0;
  padding: 0;
  margin: 0;
  overflow: auto;
  list-style: none;
  scrollbar-color: var(--line) transparent;
  scrollbar-width: thin;
}

.event-log li {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 6px;
  padding: 4px 2px;
  color: var(--text-muted);
  border-bottom: 1px solid rgba(70, 108, 110, 0.16);
  font-size: 10.5px;
}

.event-log time {
  color: var(--accent);
  font-family: var(--font-pixel);
  font-size: 9.5px;
}

.event-log .is-warning {
  color: var(--amber);
}

.event-log .is-danger {
  color: var(--danger);
}

.footer-note {
  justify-content: space-between;
  gap: 12px;
  min-height: 26px;
  padding: 4px clamp(12px, 1.8vw, 24px);
  color: var(--text-dim);
  border-top: 1px solid rgba(62, 101, 104, 0.14);
  font-size: 10.5px;
}

.footer-note p {
  margin: 0;
}

.toast-region {
  position: fixed;
  z-index: 100;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  width: min(340px, calc(100vw - 32px));
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.agent-config {
  display: grid;
  grid-template-columns: auto minmax(6.5rem, 1fr);
  gap: .35rem .65rem;
  align-items: center;
  width: min(17rem, 100%);
  margin: .85rem auto;
  text-align: left;
}

.agent-config label {
  color: var(--muted, #9aadb4);
  font-size: 0.845rem;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.agent-config input,
.agent-config select {
  min-width: 0;
  border: 1px solid rgba(129, 206, 220, .34);
  border-radius: .25rem;
  background: #061014;
  color: #eaf4f2;
  padding: .38rem .48rem;
  font: inherit;
}

.research-dialog {
  width: min(42rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  border: 1px solid rgba(114, 221, 226, .42);
  border-radius: .65rem;
  background: #071319;
  color: #e9f4f1;
  padding: 0;
  box-shadow: 0 1.5rem 5rem rgba(0, 0, 0, .72);
}

.research-dialog::backdrop {
  background: rgba(0, 4, 7, .78);
  backdrop-filter: blur(3px);
}

.research-dialog-card { padding: 1.15rem; }
.research-dialog-card > header,
.research-dialog-card > footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.research-dialog-card > header button {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  font-size: 1.475rem;
}

.research-category-list {
  display: grid;
  gap: .55rem;
  margin: 1rem 0;
}

.research-choice {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr) auto;
  gap: .7rem;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: .7rem;
  border: 1px solid rgba(108, 191, 202, .22);
  border-radius: .4rem;
  background: rgba(15, 41, 49, .75);
  color: inherit;
}

.research-choice:hover:not(:disabled),
.research-choice.is-active { border-color: #70dce1; background: rgba(29, 73, 80, .82); }
.research-choice:disabled { opacity: .48; }
.research-choice strong { color: #f0d47b; }
.research-choice span { display: grid; gap: .15rem; }
.research-choice small { color: #9eb2b5; }
.research-choice output { color: #79d7dc; white-space: nowrap; }

@media (max-width: 520px) {
  .agent-config { grid-template-columns: 1fr; }
  .research-choice { grid-template-columns: 1.7rem minmax(0, 1fr); }
  .research-choice output { grid-column: 2; }
}

.toast {
  padding: 12px 14px;
  color: var(--text);
  background: rgba(12, 33, 41, 0.97);
  border: 1px solid var(--line-bright);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 13px;
}

.noscript-message {
  position: fixed;
  z-index: 200;
  right: 15px;
  bottom: 15px;
  left: 15px;
  padding: 14px;
  color: #241100;
  background: var(--amber);
  border-radius: 8px;
  font-weight: 800;
  text-align: center;
}

body.is-playing .status-light,
body.is-playing .activity-led {
  animation: activity-pulse 1.7s ease-in-out infinite;
}

body.is-paused .status-light,
body.is-paused .activity-led {
  background: var(--amber);
  box-shadow: 0 0 10px rgba(241, 187, 100, 0.7);
  animation: none;
}

body.has-alert .screen-bezel {
  border-color: rgba(255, 124, 114, 0.66);
  box-shadow: var(--shadow), 0 0 25px rgba(255, 124, 114, 0.13);
}

@keyframes activity-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

/* Very large / 4K / maximized 1080p without browser chrome */
@media (min-width: 1700px) and (min-height: 980px) {
  :root {
    --screen-width: 960px;
    --screen-height: 576px;
  }

  .dashboard {
    max-width: 1650px;
    grid-template-columns: minmax(230px, 260px) auto minmax(240px, 280px);
  }

  .dock-cards {
    gap: 7px;
  }

  .dock-card {
    min-height: 104px;
    padding: 5px 3px;
  }

  .dock-card-thumb {
    width: 46px;
    height: 46px;
  }
}

body.is-retro {
  --screen-width: 528px;
  --screen-height: 624px;
}

/* Web/tablet command deck: construction on the left, live colony in the
   center, mission and technical information on the right. */
body:not(.is-retro) .dashboard {
  width: 100%;
  max-width: 1900px;
  height: calc(100vh - 56px);
  height: calc(100dvh - 56px);
  grid-template-columns: minmax(270px, 320px) minmax(600px, 1fr) minmax(270px, 320px);
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-areas: none;
  align-items: stretch;
  gap: 12px;
  padding: 10px 14px 14px;
  overflow: hidden;
}

body:not(.is-retro) .game-station {
  grid-column: 2;
  grid-row: 1 / 3;
  align-self: start;
  justify-self: center;
  width: min(100%, calc((100dvh - 96px) * 4 / 3));
  max-width: 1100px;
}

body:not(.is-retro) .build-dock {
  grid-column: 1;
  grid-row: 1 / 3;
  height: 80%;
  align-self: start;
  min-height: 0;
  max-height: 100%;
  overflow: auto;
  scrollbar-width: thin;
}

body:not(.is-retro) .build-dock .dock-header {
  align-items: stretch;
  flex-direction: column;
}

body:not(.is-retro) .build-dock .dock-quick-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

body:not(.is-retro) .build-dock .dock-action-btn {
  justify-content: center;
  min-width: 0;
  padding-inline: 4px;
}

body:not(.is-retro) .panel-stack-left {
  grid-column: 3;
  grid-row: 1;
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
}

body:not(.is-retro) .panel-stack-right {
  grid-column: 3;
  grid-row: 2;
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
}

body:not(.is-retro) .screen-viewport {
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
}

body:not(.is-retro) .screen-bezel {
  padding: 8px;
}

@media (max-width: 1180px) {
  body:not(.is-retro) .dashboard {
    height: auto;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: auto;
    overflow: visible;
  }

  body:not(.is-retro) .game-station {
    grid-column: 1 / 3;
    grid-row: auto;
    width: 100%;
  }

  body:not(.is-retro) .build-dock,
  body:not(.is-retro) .panel-stack-left,
  body:not(.is-retro) .panel-stack-right {
    grid-row: auto;
    max-height: none;
    overflow: visible;
  }

  body:not(.is-retro) .build-dock {
    grid-column: 1;
    height: auto;
  }

  body:not(.is-retro) .panel-stack-left,
  body:not(.is-retro) .panel-stack-right {
    grid-column: 2;
  }
}

/* Height-constrained desktop window (browser with tabs + address bar + bookmarks + taskbar on 1080p) */
@media (max-height: 840px) and (min-width: 1100px) {
  :root {
    --screen-width: 760px;
    --screen-height: 456px;
  }

  body.is-retro {
    --screen-width: 440px;
    --screen-height: 520px;
  }

  .topbar {
    min-height: 44px;
    padding-block: 4px;
  }

  .dashboard {
    padding-block: 6px;
  }

  .dock-card {
    min-height: 86px;
  }

  .dock-card-thumb {
    width: 36px;
    height: 36px;
  }

  .dock-card-name {
    font-size: 11.5px;
  }

  .event-log {
    max-height: 90px;
  }
}

/* Windowed desktop with narrower width (1100px - 1320px) */
@media (max-width: 1320px) and (min-width: 981px) {
  :root {
    --screen-width: 720px;
    --screen-height: 432px;
  }

  .dashboard {
    grid-template-columns: minmax(190px, 220px) auto minmax(200px, 230px);
    gap: 10px;
  }

  .dock-card {
    min-height: 88px;
  }

  .dock-card-thumb {
    width: 36px;
    height: 36px;
  }
}

@media (max-width: 1230px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .session-state {
    display: none;
  }
}

@media (max-width: 980px) {
  :root {
    --screen-width: 100%;
    --screen-height: auto;
  }

  .screen-viewport {
    aspect-ratio: 5 / 3;
    height: auto;
  }

  .topbar {
    position: static;
  }

  .utility-button > span:last-child {
    display: none;
  }

  .utility-button {
    min-width: 40px;
    justify-content: center;
    padding-inline: 8px;
  }

  .dashboard {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "station"
      "left"
      "right";
    justify-items: stretch;
  }

  .panel-stack {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .panel-stack-right {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .game-station {
    width: 100%;
  }

  .dock-cards {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .dock-cards {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
  }

  .dock-card {
    min-height: 90px;
    padding: 4px 2px;
  }

  .dock-card-thumb {
    width: 40px;
    height: 40px;
  }

  .dock-card-name {
    font-size: 11px;
  }

  body {
    font-size: 15px;
  }

  .topbar {
    grid-template-columns: 1fr;
    gap: 9px;
    padding-block: 9px;
  }

  .brand-block {
    justify-content: center;
  }

  .brand-block h1 span {
    display: block;
    margin: 2px 0 0;
  }

  .utility-bar {
    justify-content: center;
  }

  .utility-button {
    min-width: 46px;
    min-height: 42px;
  }

  .dashboard {
    gap: 12px;
    padding: 10px max(6px, env(safe-area-inset-left)) 18px;
  }

  .screen-bezel {
    padding: 5px;
  }

  .screen-topline {
    padding-bottom: 5px;
  }

  .panel-stack,
  .panel-stack-right {
    grid-template-columns: 1fr;
  }

  .event-log {
    max-height: 180px;
  }

  .footer-note {
    justify-content: center;
    text-align: center;
  }
}

@media (max-width: 375px) {
  :root {
    --screen-width: 176px;
    --screen-height: 208px;
  }

  .screen-bezel {
    padding: 6px;
  }

  .start-content {
    width: 92%;
    padding: 4px;
  }

  .start-overlay {
    align-items: start;
    overflow-y: auto;
  }

  .agent-config {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 3px 5px;
    margin: 5px auto;
  }

  .agent-config label,
  .agent-config input,
  .agent-config select {
    font-size: 10px;
  }

  .agent-config input,
  .agent-config select {
    padding: 2px 3px;
  }

  .start-sigil {
    width: 28px;
    height: 28px;
    margin-bottom: 5px;
    font-size: 14px;
  }

  .start-content h2 {
    margin-block: 2px 5px;
    font-size: 23px;
  }

  .start-content > p:not(.start-series) {
    margin-bottom: 6px;
    font-size: 9px;
  }

  .start-actions {
    margin-bottom: 4px;
  }

  .start-button,
  .continue-button {
    min-height: 27px;
    padding: 3px 6px;
    font-size: 11px;
  }

  .softkey {
    min-width: 46%;
  }

  .brand-mark {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (forced-colors: active) {
  .game-key,
  .utility-button,
  .info-panel,
  .control-deck,
  .screen-bezel {
    border: 1px solid ButtonText;
  }

  .screen-effects {
    display: none;
  }
}

/* Large, touchable construction palette for the primary web presentation. */
body:not(.is-retro) .dock-cards {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

body:not(.is-retro) .dock-card {
  min-height: 112px;
  padding: 9px 7px;
  justify-content: flex-start;
  gap: 4px;
}

body:not(.is-retro) .dock-card-thumb {
  width: 54px;
  height: 54px;
}

body:not(.is-retro) .dock-card-name {
  font-size: 17px;
  line-height: 1.05;
  margin-top: 0;
}

body:not(.is-retro) .dock-card-costs span {
  font-family: var(--font-condensed);
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0.01em;
  line-height: 1.05;
}

body:not(.is-retro) .dock-card-costs {
  gap: 1px;
  margin-top: 0;
}

@media (min-width: 1181px) {
  body:not(.is-retro) .panel-stack-left,
  body:not(.is-retro) .panel-stack-right {
    overflow: hidden;
  }

  body:not(.is-retro) .build-dock {
    overflow-y: auto;
  }

  body:not(.is-retro) .dock-cards {
    min-height: 0;
    flex: 1 1 auto;
    grid-template-rows: repeat(5, 112px);
    align-content: start;
  }

  body:not(.is-retro) .dock-card {
    min-height: 112px;
    padding: 4px;
    gap: 3px;
  }

  body:not(.is-retro) .dock-card-thumb {
    width: 38px;
    height: 38px;
  }

  body:not(.is-retro) .dock-card-name {
    font-size: 15px;
  }

  body:not(.is-retro) .dock-card-costs span {
    font-size: 13px;
  }

  body:not(.is-retro) .panel-stack {
    gap: 7px;
  }

  body:not(.is-retro) .info-panel {
    padding: 9px;
  }

  body:not(.is-retro) .research-current {
    padding: 7px;
    margin-bottom: 7px;
  }

  body:not(.is-retro) .event-log {
    max-height: 92px;
  }
}

@media (min-width: 1181px) and (max-height: 840px) {
  body:not(.is-retro) .dock-cards {
    grid-template-rows: repeat(5, 88px);
  }

  body:not(.is-retro) .dock-card {
    min-height: 88px;
    gap: 1px;
  }

  body:not(.is-retro) .dock-card-thumb {
    width: 30px;
    height: 30px;
  }

  body:not(.is-retro) .dock-card-name {
    font-size: 13px;
  }

  body:not(.is-retro) .dock-card-costs span {
    font-size: 11px;
  }
}

body:not(.is-retro) .screen-topline,
body:not(.is-retro) .screen-caption {
  font-size: 13px;
}

body:not(.is-retro) .screen-effects {
  display: none;
}

@media (max-width: 760px) {
  body:not(.is-retro) .dashboard {
    grid-template-columns: minmax(0, 1fr);
  }

  body:not(.is-retro) .game-station,
  body:not(.is-retro) .build-dock,
  body:not(.is-retro) .panel-stack-left,
  body:not(.is-retro) .panel-stack-right {
    grid-column: 1;
  }

  body:not(.is-retro) .dock-cards {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.biome-picker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.biome-picker select {
  min-height: 32px;
  max-width: 160px;
  padding: 4px 7px;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--line-bright);
  border-radius: 6px;
  font: inherit;
}

.utility-bar {
  flex-wrap: wrap;
}
