:root {
  --bg-dark: #1b1716;
  --iron-dark: #25272c;
  --iron-mid: #363a42;
  --iron-light: #4e5563;
  --brass-dark: #855a24;
  --brass-mid: #c88b32;
  --brass-bright: #f2be5c;
  --parchment: #f5ebd4;
  --parchment-muted: #c8bca4;
  --ink: #120e0c;
  --steam-cyan: #67d3e0;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-dark);
  color: var(--parchment);
  font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  font-size: 13px;
}

#stage-root {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#canvas-3d {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

#blood-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  box-shadow: inset 0 0 84px rgba(215, 36, 28, 0.72), inset 0 0 22px rgba(255, 66, 52, 0.55);
  animation: bloodPulse 0.75s ease-in-out infinite alternate;
}

@keyframes bloodPulse {
  from { opacity: 0.65; }
  to { opacity: 1.0; }
}

#float-texts-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 12;
  overflow: hidden;
}

.float-combat-txt {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 12.5px;
  font-weight: 900;
  font-family: ui-monospace, "Consolas", monospace;
  text-shadow: 2px 2px 0 #120e0c, -1px -1px 0 #120e0c, 1px -1px 0 #120e0c, -1px 1px 0 #120e0c;
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

.brass-frame {
  background: rgba(27, 29, 36, 0.90);
  border: 2px solid var(--brass-mid);
  box-shadow:
    0 0 0 2px var(--ink),
    inset 2px 2px 0 rgba(242, 190, 92, 0.25),
    inset -2px -2px 0 rgba(14, 12, 11, 0.55),
    4px 4px 0 rgba(12, 9, 8, 0.72);
}

.hud-panel {
  position: absolute;
  z-index: 10;
  padding: 8px 10px;
}

.panel-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--brass-bright);
  text-shadow: 2px 2px 0 var(--ink);
}

.brass-btn {
  background: #9c6520;
  color: #fff6e0;
  border: 2px solid var(--brass-bright);
  box-shadow:
    inset 0 2px 0 rgba(255, 226, 138, 0.35),
    inset 0 -2px 0 rgba(70, 40, 10, 0.65),
    2px 2px 0 var(--ink);
  font-weight: 700;
  cursor: pointer;
  padding: 4px 9px;
  font-size: 12px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.brass-btn:hover:not(:disabled) {
  filter: brightness(1.14);
}

.brass-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.brass-btn.ready-glow {
  animation: pulseBrass 0.9s steps(2) infinite alternate;
}

@keyframes pulseBrass {
  from { border-color: var(--brass-bright); background: #9c6520; }
  to { border-color: #fff2a6; background: #c4842b; }
}

.brass-btn.active-toggle {
  background: #2f7d94;
  border-color: #9ceeff;
}

.small-btn { padding: 2px 7px; font-size: 11px; }
.micro-btn { padding: 3px 5px; font-size: 10.5px; white-space: nowrap; }
.icon-btn { padding: 2px 6px; font-size: 12px; }

.primary-brass-btn {
  background: #c9862c;
  color: #1c1208;
  border: 2px solid #ffe08a;
  box-shadow:
    inset 0 3px 0 rgba(255, 240, 180, 0.5),
    inset 0 -3px 0 rgba(120, 65, 14, 0.65),
    3px 3px 0 var(--ink);
  font-weight: 900;
  font-size: 14px;
  padding: 9px 18px;
  cursor: pointer;
}

.primary-brass-btn:hover {
  filter: brightness(1.1);
}

/* Top-Left */
#hud-top-left {
  top: 10px;
  left: 10px;
  width: 282px;
}

.core-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
  gap: 6px;
}

.core-title {
  display: flex;
  align-items: center;
  gap: 5px;
}

.badge-lv {
  background: var(--brass-bright);
  color: var(--ink);
  font-weight: 900;
  font-size: 11px;
  padding: 1px 5px;
  border: 2px solid var(--ink);
  font-family: ui-monospace, "Consolas", monospace;
}

.grid-size-tag {
  font-size: 11px;
  color: var(--parchment-muted);
  font-weight: 700;
  font-family: ui-monospace, "Consolas", monospace;
}

.hp-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
}

.hp-bar-wrap {
  position: relative;
  flex: 1;
  height: 18px;
  background: #141418;
  border: 2px solid var(--ink);
  overflow: hidden;
}

.hp-bar-fill {
  height: 100%;
  width: 100%;
  background: #44b562;
  box-shadow: inset 0 3px 0 #70db89, inset 0 -3px 0 #2b7a41;
  transition: width 0.12s linear;
}

.hp-bar-fill.low {
  background: #d64238;
  box-shadow: inset 0 3px 0 #f2746b, inset 0 -3px 0 #8a211a;
}

.hp-bar-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  font-family: ui-monospace, "Consolas", monospace;
  color: #fff;
  text-shadow: 1px 1px 0 var(--ink);
}

.meters-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.analog-meter-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #17191f;
  border: 2px solid var(--brass-dark);
  padding: 3px 4px;
}

.meter-caption {
  display: flex;
  gap: 5px;
  font-size: 10px;
  color: var(--parchment-muted);
}

.meter-caption strong {
  color: var(--steam-cyan);
}

.status-stats {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
}

.stat-line {
  display: flex;
  justify-content: space-between;
  color: var(--parchment-muted);
}

.stat-line strong {
  color: var(--parchment);
}

.wave-line {
  margin-top: 2px;
  padding: 2px 5px;
  background: #14151a;
  border: 1px solid var(--iron-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--parchment-muted);
  white-space: nowrap;
}

.wave-line strong {
  color: #ffd57a;
}

.wave-line.warning {
  border-color: #ff4f3d;
  background: rgba(140, 25, 20, 0.65);
  color: #ffd5cc;
  animation: pulseWarn 0.8s infinite alternate;
}

@keyframes pulseWarn {
  from { opacity: 0.75; }
  to { opacity: 1; }
}

/* Top-Center */
#hud-top-center {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 14;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  width: min(560px, calc(100vw - 580px));
}

#design-banner,
#tutorial-banner,
#boss-bar {
  position: static;
  width: 100%;
  pointer-events: auto;
}

#design-banner {
  background: rgba(18, 30, 40, 0.96);
  border-color: var(--steam-cyan);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
}

.design-only-util {
  display: none;
}

/* Tutorial Guidance Bar */
#tutorial-banner {
  background: rgba(25, 28, 34, 0.94);
  border-color: var(--brass-bright);
  padding: 7px 10px;
}

.tut-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.tut-title-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

#tut-title {
  font-size: 12.5px;
  color: #ffe89e;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tut-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.tut-complete-btn {
  padding: 4px 10px;
  font-size: 12px;
}

.tut-skip-btn {
  background: #3a3f4a;
  border-color: #8f9bb0;
  color: #e6ecf5;
}

.tut-desc {
  font-size: 11.5px;
  color: var(--parchment);
  line-height: 1.35;
  margin-bottom: 5px;
}

.tut-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tut-chip {
  font-size: 10px;
  font-weight: 800;
  padding: 1px 7px;
  background: #14161c;
  border: 1px solid var(--iron-light);
  color: var(--parchment-muted);
}

.tut-chip.done {
  background: #1a3826;
  border-color: #6fe38c;
  color: #a8ffc0;
}

.tut-facility-status {
  margin-top: 5px;
  padding: 4px 7px;
  background: #13161c;
  border: 1px solid #3c4556;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tut-fac-line {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  line-height: 1.3;
  color: var(--parchment);
}

.tut-fac-line.running { color: #9effb8; }
.tut-fac-line.idle { color: #b7e8f5; }
.tut-fac-line.warning { color: #ffd975; }
.tut-fac-line.stopped { color: #ff9c94; font-weight: 700; }

#drive-part-status {
  position: static;
  width: 100%;
  pointer-events: auto;
  padding: 5px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11.5px;
  background: rgba(20, 24, 32, 0.94);
  border-color: var(--steam-cyan);
}

.status-pill-tag {
  display: inline-block;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 800;
  border: 1px solid currentColor;
  flex-shrink: 0;
}

.status-pill-tag.running { background: #183a24; color: #8dffad; border-color: #5ce07f; }
.status-pill-tag.idle { background: #192d3a; color: #9ceeff; border-color: #54b8d4; }
.status-pill-tag.warning { background: #423012; color: #ffe07d; border-color: #f0b94b; }
.status-pill-tag.stopped { background: #471816; color: #ffb2aa; border-color: #ff6254; }

.drive-status-main {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  flex: 1;
}

.drive-status-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drive-status-sub {
  font-size: 10px;
  color: var(--parchment-muted);
}

/* Rival Boss Bar */
#boss-bar {
  border-color: #e05344;
  padding: 6px 10px;
}

.boss-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 900;
  font-size: 12px;
  color: #ff9c8a;
  margin-bottom: 4px;
}

.boss-sub {
  margin-left: auto;
  font-size: 10px;
  color: var(--parchment-muted);
}

.boss-fill {
  background: #d64238;
  box-shadow: inset 0 3px 0 #f2746b, inset 0 -3px 0 #8a211a;
}

.design-banner-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.design-badge {
  font-size: 13px;
  font-weight: 900;
  color: #9ceeff;
  text-shadow: 2px 2px 0 var(--ink);
}

.pause-pill {
  background: #14222c;
  border: 1px solid #4ba5bc;
  color: #dff9ff;
  padding: 1px 6px;
  font-size: 10.5px;
  font-weight: 800;
}

.design-banner-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.design-exit-btn {
  padding: 5px 12px;
  font-size: 12.5px;
  white-space: nowrap;
}

.key-hint {
  font-size: 10px;
  opacity: 0.85;
  font-family: ui-monospace, "Consolas", monospace;
}

#toast-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

.toast-msg {
  background: #201d1b;
  border: 2px solid var(--brass-bright);
  box-shadow: 0 0 0 2px var(--ink), 3px 3px 0 rgba(0, 0, 0, 0.7);
  color: var(--parchment);
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.toast-msg.danger { border-color: #ff5244; color: #ffd1cc; }
.toast-msg.blueprint { border-color: #5ee6ff; color: #d4faff; }

/* Top-Right */
#hud-top-right {
  top: 10px;
  right: 10px;
  width: 266px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.minimap-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tier-badge {
  background: var(--iron-light);
  border: 2px solid var(--brass-mid);
  color: var(--brass-bright);
  font-weight: 900;
  font-size: 10px;
  font-family: ui-monospace, "Consolas", monospace;
  padding: 1px 5px;
  flex-shrink: 0;
}

.tier-dist {
  font-size: 9.5px;
  font-weight: 800;
  color: #e9c97b;
  font-family: ui-monospace, "Consolas", monospace;
  white-space: nowrap;
  flex-shrink: 0;
}

.biome-name {
  font-size: 11px;
  font-weight: 800;
  color: var(--parchment);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-2d-link {
  text-decoration: none;
  font-size: 10px;
  font-weight: 800;
  color: #ffe28a;
  background: #3d2c19;
  border: 1px solid var(--brass-mid);
  padding: 1px 5px;
}

.mini-2d-link:hover { filter: brightness(1.2); }

.minimap-ring {
  padding: 3px;
  background: #2b1d0c;
  border: 2px solid var(--brass-bright);
  box-shadow: 0 0 0 2px var(--ink);
}

#minimap-canvas {
  display: block;
  background: #12181d;
  cursor: pointer;
}

.biome-effect {
  font-size: 10px;
  color: var(--parchment-muted);
  text-align: center;
}

.hud-quick-actions {
  width: 100%;
  display: grid;
  grid-template-columns: 1.25fr 0.85fr 0.85fr 0.52fr 0.52fr;
  gap: 4px;
}

.quality-row {
  width: 100%;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding-top: 4px;
  border-top: 1px solid rgba(242, 190, 92, 0.22);
  font-size: 10px;
}

.quality-label {
  color: var(--parchment-muted);
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.quality-select {
  background: #16181f;
  color: var(--brass-bright);
  border: 1px solid var(--brass-mid);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 3px;
  cursor: pointer;
  flex-shrink: 0;
}

.bloom-toggle-btn {
  padding: 1px 5px;
  font-size: 9.5px;
  background: #272b35;
  border-width: 1px;
  border-color: #7d89a0;
  color: #d7e0ef;
  white-space: nowrap;
  flex-shrink: 0;
}

.bloom-toggle-btn.active-toggle {
  background: #523b16;
  border-color: #ffd875;
  color: #fff3c4;
}

.quality-readout {
  margin-left: auto;
  font-size: 9px;
  color: var(--steam-cyan);
  font-family: ui-monospace, "Consolas", monospace;
  white-space: nowrap;
}

/* Mode Visibility */
#stage-root:not(.design-mode) #hud-bottom-center,
#stage-root:not(.design-mode) #design-banner {
  display: none !important;
}

#stage-root.design-mode #hud-drive-bar,
#stage-root.design-mode #mobile-joystick,
#stage-root.design-mode #mobile-actions,
#stage-root.design-mode #mobile-res-strip,
#stage-root:not(.game-started) #hud-drive-bar,
#stage-root:not(.game-started) #mobile-joystick,
#stage-root:not(.game-started) #mobile-actions,
#stage-root:not(.game-started) #mobile-res-strip {
  display: none !important;
}

/* Driving Action Bar */
#hud-drive-bar {
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: calc(100vw - 580px);
}

.drive-design-btn { padding: 8px 16px; font-size: 14px; white-space: nowrap; }
.drive-sub-btns { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.drive-hint-note { font-size: 10.5px; color: var(--parchment-muted); white-space: nowrap; }
.drive-hint-short { display: none; }

@media (max-width: 1180px) {
  .drive-hint-full { display: none; }
  .drive-hint-short { display: inline; }
}

.offscreen-castle-arrow {
  position: absolute;
  z-index: 22;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 5px 8px;
  background: rgba(34, 24, 15, 0.92);
  border: 2px solid var(--brass-bright);
  box-shadow: 0 0 0 2px var(--ink), 0 3px 8px rgba(0, 0, 0, 0.7);
  color: var(--brass-bright);
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  border-radius: 6px;
}

.offscreen-castle-arrow:hover { filter: brightness(1.18); }
.offscreen-castle-arrow .arrow-tri {
  display: inline-block;
  font-size: 13px;
  line-height: 1;
}
.offscreen-castle-arrow .arrow-home {
  font-size: 13px;
  line-height: 1;
}

@keyframes waveAlertPulse {
  0%, 100% { box-shadow: 0 0 0 2px #ff5244, 0 0 10px rgba(255, 82, 68, 0.85); border-color: #ff8278; }
  50% { box-shadow: 0 0 0 3px #ffd24d, 0 0 18px rgba(255, 210, 77, 1); border-color: #ffe36e; background: #6b281e; }
}

.wave-alert-glow {
  animation: waveAlertPulse 0.45s ease-in-out infinite;
}

/* Design Hotbar */
#hud-bottom-center {
  bottom: 10px;
  left: 12px;
  right: 290px;
  width: auto;
  min-width: 0;
  transform: none;
  padding: 6px 8px;
}

.hotbar-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 5px;
  flex-wrap: wrap;
}

.category-tabs { display: flex; gap: 3px; flex-wrap: wrap; }

.cat-tab {
  background: var(--iron-dark);
  color: var(--parchment-muted);
  border: 2px solid var(--iron-light);
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.cat-tab.active {
  background: var(--brass-dark);
  color: #fff6df;
  border-color: var(--brass-bright);
}

.tool-mode-pills { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }

.tool-pill {
  background: #202229;
  color: var(--parchment);
  border: 2px solid var(--iron-light);
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.tool-pill.tool-rotate-btn {
  background: #5a3e17;
  border-color: var(--brass-bright);
  color: #fff6dc;
}

.tool-pill.active {
  background: #3d6d82;
  border-color: #8ee6ff;
  color: #fff;
}

.tool-pill.erase-active {
  background: #87312c;
  border-color: #ff9c94;
}

.zoom-step-pill { padding: 2px 7px; font-weight: 900; }

.design-info-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 8px;
  background: #14171d;
  border: 1px solid #3a4250;
  padding: 3px 8px;
  margin-bottom: 5px;
  font-size: 11px;
  color: var(--parchment-muted);
  min-height: 24px;
}

.design-info-strip strong { color: var(--brass-bright); }
.design-info-actions { display: flex; gap: 5px; flex-shrink: 0; }

.part-palette {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--brass-mid) var(--iron-dark);
}

@media (min-width: 1041px) and (min-height: 760px) {
  #stage-root.design-mode:not(.palette-1row) .part-palette {
    display: grid;
    grid-auto-flow: column;
    grid-template-rows: repeat(2, 108px);
    grid-auto-columns: 100px;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
  }
}

.part-card {
  flex: 0 0 auto;
  width: 100px;
  height: 108px;
  background: #22252d;
  border: 2px solid var(--iron-light);
  box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.08), 2px 2px 0 var(--ink);
  padding: 3px 4px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  position: relative;
}

.part-card:hover { border-color: var(--brass-mid); }
.part-card.selected {
  border-color: #7ee8ff;
  box-shadow: inset 0 0 0 1px #c9fbff, 2px 2px 0 var(--ink);
  background: #273947;
}
.part-card.locked { opacity: 0.42; border-style: dashed; }
.part-card.unaffordable { border-color: #6b3632; }

.part-icon-img {
  width: 60px;
  height: 60px;
  object-fit: contain;
  display: block;
}

.part-card-name {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--parchment);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  line-height: 1.15;
}

.part-card-cost {
  font-size: 10.5px;
  color: var(--brass-bright);
  font-weight: 700;
  line-height: 1.05;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.part-size-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(18, 14, 12, 0.85);
  color: #ffd57a;
  font-size: 8.5px;
  font-weight: 900;
  padding: 0 3px;
}

.part-tier-badge {
  position: absolute;
  top: 2px;
  left: 2px;
  font-size: 8px;
  font-weight: 800;
  color: var(--parchment-muted);
}

.design-rotate-hint {
  margin-top: 5px;
  padding: 3px 8px;
  background: rgba(18, 28, 38, 0.92);
  border: 1px solid #3f6f85;
  color: #cdeff7;
  font-size: 11px;
  text-align: center;
}

.design-rotate-hint b { color: #ffe388; }

/* Bottom-Right Gain Log */
#gain-log {
  position: absolute;
  right: 10px;
  width: 266px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  pointer-events: none;
  z-index: 14;
}

.gain-row {
  height: 18px;
  line-height: 18px;
  padding: 0 7px;
  background: rgba(20, 17, 15, 0.82);
  border-left: 2px solid var(--brass-mid);
  color: var(--parchment);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.65);
  transition: background-color 0.12s;
}

.gain-row.flash {
  background: rgba(68, 54, 34, 0.94);
  border-left-color: #ffe388;
}

.gain-row-src {
  color: var(--parchment-muted);
  flex-shrink: 0;
}

.gain-row-items {
  display: flex;
  align-items: center;
  gap: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.gain-item {
  font-family: ui-monospace, "Consolas", monospace;
  font-weight: 800;
  flex-shrink: 0;
}

.gain-more {
  color: var(--parchment-muted);
  font-size: 10.5px;
  flex-shrink: 0;
}

/* Bottom-Right Stockpile */
#hud-bottom-right {
  bottom: 10px;
  right: 10px;
  width: 266px;
}

.res-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}

.autosave-tag { font-size: 10px; color: #88d99a; font-weight: 700; }

.resource-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 6px;
}

.res-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #14151a;
  border: 1px solid #353944;
  padding: 2px 5px;
  font-size: 11px;
}

.res-name-dot {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--parchment-muted);
  font-size: 10px;
  white-space: nowrap;
}

.res-dot {
  width: 8px;
  height: 8px;
  border: 1px solid var(--ink);
  flex-shrink: 0;
}

.res-val-col {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.05;
  font-family: ui-monospace, "Consolas", monospace;
}

.res-amount { font-weight: 800; color: var(--parchment); font-size: 11px; }
.res-rate { font-size: 9px; font-weight: 700; }
.res-rate.pos { color: #6fe38c; }
.res-rate.neg { color: #f0756e; }
.res-rate.zero { color: #7e8491; }

.meta-footer {
  margin-top: 5px;
  padding-top: 4px;
  border-top: 1px solid #3c404b;
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--parchment-muted);
}

/* Mining Node Indicator */
#node-indicator {
  position: absolute;
  z-index: 12;
  transform: translate(-50%, -100%);
  background: rgba(20, 15, 14, 0.9);
  border: 1px solid var(--brass-mid);
  padding: 4px 8px;
  min-width: 118px;
  pointer-events: none;
}

.node-ind-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 3px;
}

.node-ind-bar {
  height: 5px;
  background: #2a2d35;
  border: 1px solid #0e0b0a;
}

#node-ind-fill {
  height: 100%;
  width: 100%;
}

/* Tooltip */
#hover-tooltip {
  pointer-events: none;
  z-index: 25;
  max-width: 264px;
  padding: 7px 10px;
  font-size: 11.5px;
  line-height: 1.35;
}

.tt-title {
  font-weight: 900;
  color: var(--brass-bright);
  margin-bottom: 2px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.tt-desc { color: var(--parchment); margin-bottom: 4px; }
.tt-status { margin-bottom: 4px; padding: 2px 5px; font-size: 10.5px; font-weight: 700; border-left: 3px solid currentColor; background: #14171f; }
.tt-status.running { color: #8dffad; }
.tt-status.idle { color: #9ceeff; }
.tt-status.warning { color: #ffe07d; }
.tt-status.stopped { color: #ff9c94; }
.tt-meta { color: var(--steam-cyan); font-size: 10.5px; }
.tt-synergy { color: #ffd866; font-size: 10.5px; margin-top: 2px; }

/* Modals & Title */
.modal-backdrop,
.title-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(12, 10, 10, 0.64);
  display: flex;
  align-items: center;
  justify-content: center;
}

.title-card {
  width: min(520px, 92vw);
  padding: 26px 28px;
  text-align: center;
}

.title-gears {
  font-size: 28px;
  color: var(--brass-bright);
  letter-spacing: 8px;
  text-shadow: 2px 2px 0 var(--ink);
}

.game-logo {
  margin: 4px 0 6px;
  font-size: 38px;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--brass-bright);
  text-shadow: 4px 4px 0 var(--ink), 2px 2px 0 #855a24;
}

.game-subtitle {
  margin: 0 0 14px;
  color: var(--parchment-muted);
  font-size: 13px;
  font-weight: 700;
}

.title-controls-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 10px;
  margin-bottom: 18px;
  padding: 10px;
  background: #14151a;
  border: 2px solid var(--iron-light);
  font-size: 11.5px;
}

.title-controls-summary b { color: var(--brass-bright); }

.title-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.title-back-link {
  background: #353b46;
  border-color: #8d9bb3;
  color: #ecf2fa;
  padding: 7px 14px;
}

.modal-card {
  width: min(460px, 92vw);
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  padding: 14px 16px;
}

.modal-card.wide-modal { width: min(680px, 94vw); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid var(--brass-dark);
  padding-bottom: 8px;
  margin-bottom: 10px;
}

.modal-header h2 { margin: 0; font-size: 17px; color: var(--brass-bright); }

.close-modal-btn {
  background: #3a2320;
  color: #ffd0c9;
  border: 2px solid #c45649;
  padding: 2px 8px;
  cursor: pointer;
  font-weight: 900;
}

.help-body { overflow-y: auto; padding-right: 4px; line-height: 1.45; }

.help-section {
  margin-bottom: 12px;
  background: #14151a;
  border: 2px solid var(--iron-light);
  padding: 8px 10px;
}

.help-section h3 { margin: 0 0 5px; font-size: 13px; color: var(--brass-bright); }

.pause-card,
.gameover-card {
  text-align: center;
}

.pause-sub {
  margin: 0 0 12px;
  color: var(--parchment-muted);
  font-size: 12px;
  line-height: 1.4;
}

.pause-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pause-sub-panel {
  margin-top: 10px;
  max-height: 200px;
  overflow-y: auto;
  text-align: left;
  background: #14151a;
  border: 2px solid var(--iron-light);
  padding: 8px;
  font-size: 11.5px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pause-gain-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  padding: 2px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.title-best-record {
  background: #14171d;
  border: 1px solid var(--brass-mid);
  color: var(--brass-bright);
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 800;
}

.gameover-records {
  margin: 8px 0 4px;
  padding: 7px 10px;
  background: #14171d;
  border: 1px solid var(--iron-light);
  font-size: 12px;
  color: var(--parchment);
  line-height: 1.5;
}

.new-record-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  background: #8a5612;
  border: 1px solid #ffe066;
  color: #fff6c2;
  font-size: 10.5px;
  font-weight: 900;
}

.records-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(115px, 1fr));
  gap: 6px;
  margin-bottom: 10px;
}

.rec-stat-box {
  background: #14151a;
  border: 1px solid var(--brass-dark);
  padding: 5px 8px;
  text-align: center;
}

.rec-stat-label {
  font-size: 10px;
  color: var(--parchment-muted);
}

.rec-stat-val {
  font-size: 14px;
  font-weight: 900;
  color: var(--brass-bright);
}

.ach-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 6px;
}

.ach-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--iron-light);
  background: #1a1d24;
  font-size: 11.5px;
}

.ach-row.unlocked {
  border-color: var(--brass-bright);
  background: #282319;
}

.ach-row.locked {
  opacity: 0.62;
  color: #9ba0ab;
  filter: grayscale(0.75);
}

.ach-name {
  font-weight: 900;
  color: var(--brass-bright);
}

.ach-row.locked .ach-name {
  color: #aeb3be;
}

.ach-desc {
  font-size: 10.5px;
  color: var(--parchment-muted);
}

.ach-prog {
  font-family: ui-monospace, "Consolas", monospace;
  font-size: 11px;
  font-weight: 800;
  flex-shrink: 0;
  color: #88e6a0;
}

.ach-row.locked .ach-prog {
  color: #9ba0ab;
}

.gameover-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
}

.title-skip-btn {
  padding: 7px 14px;
  font-size: 12.5px;
  background: #353b46;
  border-color: #8d9bb3;
  color: #ecf2fa;
}

/* Mobile Virtual Joystick & Large Touch Action Buttons */
.mobile-joystick {
  position: absolute;
  bottom: 12px;
  left: 14px;
  width: 122px;
  height: 122px;
  z-index: 16;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.joy-ring {
  position: relative;
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background: rgba(24, 27, 34, 0.78);
  border: 3px solid var(--brass-mid);
  box-shadow: 0 0 0 2px var(--ink), inset 0 0 14px rgba(0, 0, 0, 0.65);
  touch-action: none;
}

.joy-dir {
  position: absolute;
  font-size: 10px;
  color: rgba(242, 190, 92, 0.65);
  font-weight: 900;
  pointer-events: none;
}
.joy-up { top: 4px; left: 50%; transform: translateX(-50%); }
.joy-down { bottom: 4px; left: 50%; transform: translateX(-50%); }
.joy-left { left: 6px; top: 50%; transform: translateY(-50%); }
.joy-right { right: 6px; top: 50%; transform: translateY(-50%); }

.joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin-left: -23px;
  margin-top: -23px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffe38f, #c88b32 68%, #704714);
  border: 2px solid var(--ink);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.7);
  pointer-events: none;
}

.mobile-actions {
  position: absolute;
  bottom: 12px;
  right: 12px;
  width: 148px;
  z-index: 16;
  display: flex;
  flex-direction: column;
  gap: 7px;
  touch-action: none;
}

.mob-design-btn {
  width: 100%;
  min-height: 50px;
  padding: 8px 10px;
  font-size: 15px;
}

.mob-sub-row {
  display: grid;
  grid-template-columns: 1fr 48px;
  gap: 6px;
}

.mob-sub-btn {
  min-height: 42px;
  padding: 6px 8px;
  font-size: 12px;
}

.mob-cam-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.mob-cam-btn {
  min-height: 32px;
  padding: 4px 5px;
  font-size: 11px;
  white-space: nowrap;
}

#mobile-res-strip {
  bottom: 8px;
  left: 146px;
  right: 170px;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 6px;
  font-size: 10.5px;
  font-family: ui-monospace, "Consolas", monospace;
}

.mob-res-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.mob-res-pill strong { color: var(--parchment); }

body:not(.touch-ui) #mobile-joystick,
body:not(.touch-ui) #mobile-actions,
body:not(.touch-ui) #mobile-res-strip {
  display: none;
}

body.touch-ui .cat-tab,
body.touch-ui .tool-pill {
  min-height: 36px;
  padding: 5px 10px;
  font-size: 12px;
}

body.touch-ui #btn-rotate-preview {
  min-height: 40px;
  padding: 6px 13px;
  font-size: 12.5px;
  font-weight: 800;
}

body.touch-ui .design-info-actions .tool-pill {
  min-height: 34px;
  padding: 4px 10px;
  font-size: 11.5px;
}

@media (max-width: 1040px) {
  #hud-bottom-center {
    left: 10px;
    right: 282px;
    width: auto;
    min-width: 0;
    transform: none;
  }
  .part-card { width: 88px; height: 96px; }
  .part-icon-img { width: 50px; height: 50px; }
  .part-card-name { font-size: 11px; }
  .part-card-cost { font-size: 10px; }
  #btn-palette-rows { display: none; }
}

@media (min-width: 921px) and (min-height: 541px) {
  body.touch-ui #hud-drive-bar {
    display: none !important;
  }
  body.touch-ui #mobile-actions {
    bottom: 206px;
    right: 10px;
  }
  body.touch-ui #mobile-res-strip {
    overflow-x: auto;
  }
}

@media (max-width: 920px), (max-height: 540px) {
  body #mobile-joystick:not(.hidden),
  body #mobile-actions:not(.hidden),
  body #mobile-res-strip:not(.hidden) {
    display: flex;
  }

  #hud-drive-bar {
    display: none !important;
  }

  #hud-top-left {
    top: 6px;
    left: 6px;
    width: 214px;
    padding: 5px 7px;
  }

  .core-header { margin-bottom: 3px; }
  .hp-row { margin-bottom: 4px; }
  .hp-bar-wrap { height: 15px; }

  #steam-gauge-canvas {
    width: 56px;
    height: 34px;
  }

  .status-stats { font-size: 10px; gap: 1px; }
  .wave-line { font-size: 9.5px; padding: 1px 4px; }

  #hud-top-right {
    top: 6px;
    right: 6px;
    width: 178px;
    padding: 5px 6px;
    gap: 3px;
    overflow: hidden;
  }

  .minimap-header { gap: 3px; }
  .tier-badge { font-size: 9px; padding: 0 3px; }
  .tier-dist { font-size: 8.5px; }
  .biome-name { font-size: 10px; }

  #minimap-canvas {
    width: 78px;
    height: 78px;
  }

  .biome-effect { display: none; }
  .hud-quick-actions { gap: 2px; }
  .micro-btn { padding: 3px 2px; font-size: 9.5px; }
  .quality-row { padding-top: 3px; gap: 3px; font-size: 9px; }
  .quality-select { font-size: 9px; padding: 1px 2px; max-width: 76px; }
  .bloom-toggle-btn { font-size: 8.5px; padding: 1px 4px; }
  .quality-readout { font-size: 8.5px; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

  #hud-top-center {
    top: 6px;
    left: 226px;
    right: 190px;
    width: auto;
    transform: none;
    gap: 4px;
  }

  #tutorial-banner { padding: 4px 7px; }
  #tut-title { font-size: 11px; }
  .tut-desc { font-size: 10px; margin-bottom: 3px; }
  .tut-chip { font-size: 9.5px; padding: 0 5px; }

  #stage-root:not(.design-mode) #hud-bottom-right {
    display: none;
  }

  #stage-root.design-mode #hud-top-right {
    display: none;
  }

  #stage-root.design-mode #hud-top-left {
    width: 192px;
    padding: 4px 6px;
  }

  #stage-root.design-mode #hud-top-left .stat-line,
  #stage-root.design-mode #hud-top-left .wave-line {
    display: none;
  }

  #stage-root.design-mode #hud-top-center {
    left: 204px;
    right: 186px;
  }

  #stage-root.design-mode .design-only-util {
    display: inline-flex;
  }

  #design-banner { padding: 4px 7px; }
  .design-badge { font-size: 11.5px; }
  .pause-pill { display: none; }
  .design-exit-btn { padding: 4px 8px; font-size: 11px; }

  #stage-root.design-mode #hud-bottom-right {
    top: 6px;
    right: 6px;
    bottom: auto;
    width: 174px;
    padding: 5px 6px;
  }

  #stage-root.design-mode .res-item { padding: 1px 4px; font-size: 10px; }
  #stage-root.design-mode .res-amount { font-size: 10px; }
  #stage-root.design-mode .res-rate { font-size: 8px; }
  #stage-root.design-mode .meta-footer { margin-top: 3px; padding-top: 2px; font-size: 9.5px; }

  #hud-bottom-center {
    left: 6px;
    right: 6px;
    bottom: 6px;
    width: auto;
    min-width: 0;
    transform: none;
    padding: 4px 6px;
  }

  .hotbar-top-row { margin-bottom: 3px; gap: 4px; }
  .cat-tab, .tool-pill { min-height: 32px; padding: 4px 8px; font-size: 11px; }
  #btn-rotate-preview { min-height: 38px; padding: 5px 12px; font-size: 12px; font-weight: 800; }
  .design-info-strip { padding: 3px 6px; margin-bottom: 3px; font-size: 10.5px; min-height: 24px; }
  .design-info-actions .tool-pill { min-height: 32px; padding: 4px 9px; font-size: 11px; }
  .design-rotate-hint { margin-top: 3px; padding: 3px 6px; font-size: 10px; line-height: 1.25; }
  .part-card { width: 68px; height: 64px; }
  .part-icon-img { width: 36px; height: 36px; }
  .part-card-name { font-size: 9.5px; }
  .part-card-cost { font-size: 9px; }
  #btn-palette-rows { display: none; }

  .gain-row {
    height: 16px;
    line-height: 16px;
    font-size: 10.5px;
    padding: 0 5px;
    gap: 4px;
  }

  .title-card { padding: 12px 16px; max-height: 94vh; overflow-y: auto; }
  .title-gears { font-size: 20px; }
  .game-logo { font-size: 28px; margin: 2px 0; }
  .game-subtitle { margin: 0 0 8px; font-size: 11.5px; }
  .title-controls-summary { padding: 6px 8px; margin-bottom: 10px; font-size: 10.5px; gap: 4px 8px; }
  .primary-brass-btn { padding: 8px 14px; font-size: 13.5px; }
}

@media (max-height: 540px) {
  #design-banner, #tutorial-banner { padding: 3px 6px; }
  .tut-head { margin-bottom: 2px; }
  .tut-desc { font-size: 9.5px; line-height: 1.2; margin-bottom: 2px; }
  .cat-tab, .tool-pill,
  body.touch-ui .cat-tab,
  body.touch-ui .tool-pill {
    min-height: 28px;
    padding: 3px 7px;
    font-size: 10.5px;
  }
  #btn-rotate-preview,
  body.touch-ui #btn-rotate-preview {
    min-height: 34px;
    padding: 4px 11px;
    font-size: 11.5px;
  }
  .design-info-strip { padding: 2px 6px; margin-bottom: 2px; font-size: 10px; min-height: 22px; }
  .design-info-actions .tool-pill,
  body.touch-ui .design-info-actions .tool-pill {
    min-height: 24px;
    padding: 2px 7px;
    font-size: 10px;
  }
  .part-card { width: 64px; height: 58px; padding: 2px; }
  .part-icon-img { width: 30px; height: 30px; }
  .part-card-name { font-size: 9px; line-height: 1.05; }
  .part-card-cost { font-size: 8.5px; line-height: 1.05; }
  .design-rotate-hint { margin-top: 2px; padding: 2px 6px; font-size: 9.5px; }
  .mobile-actions { bottom: 8px; gap: 4px; }
  .mob-design-btn { min-height: 40px; padding: 5px 8px; font-size: 13.5px; }
  .mob-sub-btn { min-height: 34px; padding: 4px 6px; font-size: 11.5px; }
  .mob-cam-btn { min-height: 28px; padding: 3px 4px; font-size: 10.5px; }
}

@media (max-width: 680px) {
  #hud-top-left {
    width: calc(52% - 8px);
    padding: 4px 5px;
    overflow: hidden;
  }

  #hud-top-left .core-title {
    gap: 3px;
    min-width: 0;
  }

  #hud-top-left .panel-label {
    font-size: 9.5px;
    letter-spacing: 0.02em;
    white-space: nowrap;
  }

  #hud-top-left .grid-size-tag {
    font-size: 9.5px;
  }

  #hud-top-left .small-btn {
    padding: 1px 4px;
    font-size: 9.5px;
    white-space: nowrap;
  }

  #steam-gauge-canvas {
    width: 44px;
    height: 28px;
  }

  .analog-meter-box {
    padding: 2px 3px;
  }

  .meter-caption {
    font-size: 8.5px;
    gap: 2px;
  }

  .meters-row {
    gap: 4px;
  }

  .status-stats {
    min-width: 0;
    font-size: 9.5px;
  }

  .wave-line {
    font-size: 8.5px;
    gap: 3px;
    padding: 1px 3px;
    overflow: hidden;
  }

  .wave-line span {
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
  }

  #hud-top-right {
    width: calc(48% - 8px);
    padding: 4px 5px;
    overflow: hidden;
  }

  #hud-top-right .quality-label {
    display: none;
  }

  #hud-top-right .quality-select {
    max-width: 82px;
    font-size: 9px;
  }

  #minimap-canvas {
    width: 68px;
    height: 68px;
  }

  #hud-top-center {
    top: 178px;
    left: 6px;
    right: 6px;
    width: auto;
  }

  #mobile-res-strip {
    left: 6px;
    right: 6px;
    bottom: 148px;
    flex-wrap: wrap;
    justify-content: center;
    padding: 3px 6px;
  }

  #stage-root.design-mode #hud-top-left {
    width: calc(50% - 9px);
  }

  #stage-root.design-mode #hud-bottom-right {
    width: calc(50% - 9px);
  }

  #stage-root.design-mode #hud-top-center {
    top: 162px;
    left: 6px;
    right: 6px;
  }
}

#difficulty-modal { width: min(680px, 92vw); max-height: 90dvh; overflow: auto; }
#difficulty-modal::backdrop, #preset-modal::backdrop { background: #100d0bd9; }
.difficulty-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 8px; margin-bottom: 12px; }
.difficulty-cards button { text-align: left; }
.difficulty-cards button[aria-pressed="true"] { border-color: var(--brass-bright); background: #51402a; }
.difficulty-cards span, .difficulty-cards small, #difficulty-body label { display: block; }
.phase-danger { color: #ff837a; }
.phase-wave-row { display: flex; align-items: center; gap: 4px; }
.phase-wave-row #wave-box { flex: 1; }
#difficulty-tag { color: var(--brass-bright); font-weight: 700; white-space: nowrap; }

.phase-tabs { display: flex; flex-wrap: wrap; gap: 4px; }
#preset-modal { width: min(620px, 92vw); max-height: 88dvh; overflow: auto; }
.preset-row { border-top: 1px solid #7e66464d; padding: 8px 0; }
.preset-row p { margin: 0 0 4px; }
.preset-row button, #swap-popover button, #preset-modal > button { margin: 2px; }
#swap-popover { position: fixed; z-index: 32; bottom: 110px; left: 50%; transform: translateX(-50%); width: min(430px, 92vw); max-height: 65dvh; overflow: auto; padding: 10px; }
#swap-progress { align-self: center; padding: 5px 8px; pointer-events: auto; }
#prod-panel { position: fixed; z-index: 30; top: var(--prod-top, 155px); left: 12px; width: 260px; max-height: 55dvh; overflow: auto; padding: 8px; font-size: 12px; }
#prod-panel header { margin-bottom: 4px; }
#prod-rates > div { padding: 4px 0; }
#prod-facilities button { display: block; width: 100%; text-align: left; margin-top: 3px; }
#unit-counts, #mobile-unit-counts { display: inline-flex; gap: 4px; white-space: nowrap; }
@media (max-width: 920px), (pointer: coarse) {
  #prod-panel { left: 50%; transform: translateX(-50%); top: 54px; width: min(260px, 90vw); }
  #prod-panel .prod-desktop-only { display: none; }
  #swap-popover { bottom: 150px; }
  #mobile-res-strip { overflow-x: auto; justify-content: flex-start; }
  #mobile-unit-counts { margin-left: auto; }
}
#difficulty-modal:not([open]), #preset-modal:not([open]) { display: none; }
#difficulty-modal, #preset-modal { margin: auto; color: var(--parchment); }
#records-modal { z-index: 41; }

.local-res-popup {
  position: fixed;
  right: 0;
  min-width: 12rem;
  padding: .55rem;
  background: #1c222c;
  border: 1px solid #73624f;
  z-index: 2;
  pointer-events: auto;
}
.local-res-popup > div { display: flex; justify-content: space-between; gap: 1rem; }

.phase-dialog {
  width: min(64rem, calc(100vw - 2rem));
  margin: auto;
  max-height: 88dvh;
  overflow: auto;
  color: #f2e4cd;
  background: #1c222c;
  padding: 1rem;
}
.phase-dialog::backdrop { background: #090b10b8; }
.phase-card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); gap: .75rem; margin-top: .75rem; }
.phase-card-grid section { border: 1px solid #63513e; border-top-width: 3px; padding: .75rem; }
.phase-dialog button { margin: .25rem; }
.phase-shortage { color: #ff9084; }
.contract-edge { position: fixed; pointer-events: none; z-index: 9; font-size: 1.3rem; }
#contract-tracker { font-size: .8rem; line-height: 1.45; }
#btn-board[hidden], #btn-mobile-board[hidden], #btn-research[hidden],
#btn-board-ammo[hidden], #btn-mobile-board-ammo[hidden] { display: none; }

.phase2-dialog {
  max-width: min(640px, 92vw);
  max-height: 84vh;
  margin: auto;
  background: #271e18;
  color: #f5dfb6;
  padding: 1rem;
  overflow: auto;
}
.phase2-dialog::backdrop { background: #100d0bd9; }
.phase2-dialog nav { display: flex; flex-wrap: wrap; gap: .35rem; }
.phase2-dialog button, .phase2-dialog select { margin: .15rem; }
.phase2-grid { display: grid; width: min(500px, 100%); }
.phase2-grid button { min-width: 0; padding: .1rem; aspect-ratio: 1; }
.phase2-map { display: block; width: min(420px, 100%); height: auto; }

#photo-controls[hidden], #photo-watermark[hidden], #trial-tracker[hidden] { display: none; }
.photo-mode #stage-root > :not(#canvas-3d, #photo-controls, #photo-watermark) { visibility: hidden !important; pointer-events: none !important; }
#photo-controls {
  position: absolute;
  inset: max(8px, env(safe-area-inset-top)) auto auto max(8px, env(safe-area-inset-left));
  z-index: 80;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 6px;
  max-width: calc(100vw - 30px);
  color: #ffecd3;
  background: #211815df;
}
#photo-watermark {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  color: #ffecd3;
  text-shadow: 0 2px 6px #14100e;
  pointer-events: none;
}
