/* Voidfall Spire — 16-Bit Dark Eldritch Astral UI */
:root {
  --bg-void: #07050f;
  --bg-panel: #120d21;
  --bg-card: #1a1230;
  --bg-elev: #241942;
  --border-rune: #3c2b68;
  --border-bright: #7c4dff;
  --text-main: #f2ecff;
  --text-dim: #a99bc9;
  --accent-violet: #a855f7;
  --accent-magenta: #e879f9;
  --accent-cyan: #38bdf8;
  --accent-gold: #fbbf24;
  --accent-crimson: #f43f5e;
  --accent-emerald: #34d399;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  max-width: 100vw;
  min-height: 100dvh;
  overflow-x: hidden;
  background: radial-gradient(circle at 50% 0%, #1d1138 0%, #090614 60%, #05030b 100%);
  color: var(--text-main);
  font-family: 'Trebuchet MS', 'Segoe UI', system-ui, -apple-system, sans-serif;
  user-select: none;
}

#app {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 8px 10px 64px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hidden {
  display: none !important;
}

/* Top HUD Bar */
.hud-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  padding: 7px 10px;
  background: linear-gradient(180deg, rgba(28, 19, 52, 0.96), rgba(16, 11, 31, 0.96));
  border: 1.5px solid var(--border-rune);
  border-radius: 10px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(196, 165, 255, 0.14);
}

.hud-left, .hud-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
}

.brand-pill {
  font-weight: 800;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  padding: 4px 9px;
  border-radius: 7px;
  background: linear-gradient(135deg, #331d63, #1e123b);
  border: 1px solid #6b46c1;
  color: #f5d0fe;
  white-space: nowrap;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 7px;
  background: rgba(11, 8, 22, 0.8);
  border: 1px solid rgba(124, 77, 255, 0.35);
  font-weight: 800;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.stat-essence { color: #67e8f9; border-color: rgba(56, 189, 248, 0.45); }
.stat-lives { color: #fda4af; border-color: rgba(244, 63, 94, 0.45); }
.stat-wave { color: #e9d5ff; }
.stat-path { color: #c084fc; border-color: rgba(192, 132, 252, 0.5); background: rgba(65, 24, 115, 0.42); }
.stat-score { color: #fde68a; border-color: rgba(251, 191, 36, 0.4); }

.hud-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 5px 9px;
  border-radius: 7px;
  border: 1px solid var(--border-rune);
  background: linear-gradient(180deg, #281c4a, #191130);
  color: var(--text-main);
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease, background 0.15s ease;
}

.hud-btn:hover {
  border-color: var(--accent-violet);
  background: linear-gradient(180deg, #352463, #221640);
}

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

.hud-btn-call {
  background: linear-gradient(180deg, #7e22ce, #581c87);
  border-color: #c084fc;
  color: #fff;
  box-shadow: 0 0 12px rgba(168, 85, 247, 0.4);
}
.hud-btn-call:hover {
  background: linear-gradient(180deg, #9333ea, #6b21a8);
}
.hud-btn-call.pulse-ready {
  animation: pulseGlow 1.5s infinite;
}

.hud-btn-star {
  border-color: rgba(251, 191, 36, 0.55);
  color: #fde68a;
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 8px rgba(192, 132, 252, 0.45); }
  50% { box-shadow: 0 0 18px rgba(232, 121, 249, 0.9); }
}

/* Challenge Banner */
.challenge-banner {
  padding: 6px 12px;
  border-radius: 8px;
  background: linear-gradient(90deg, rgba(126, 34, 206, 0.35), rgba(56, 189, 248, 0.25));
  border: 1px solid #c084fc;
  color: #f5d0fe;
  font-size: 0.84rem;
  font-weight: 700;
  text-align: center;
}

/* Main Stage */
.stage-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.canvas-shell {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #06040d;
  border: 2px solid var(--border-rune);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.65), 0 0 24px rgba(124, 77, 255, 0.16);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  cursor: crosshair;
}

/* Floating Path Delta Banner */
.path-delta-banner {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  pointer-events: none;
  background: rgba(15, 9, 32, 0.92);
  border: 1.5px solid var(--accent-violet);
  color: #f3e8ff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
}
.path-delta-banner.gain {
  border-color: var(--accent-emerald);
  color: #a7f3d0;
  box-shadow: 0 0 16px rgba(52, 211, 153, 0.45);
}
.path-delta-banner.blocked {
  border-color: var(--accent-crimson);
  color: #fecdd3;
  background: rgba(65, 10, 26, 0.94);
  box-shadow: 0 0 16px rgba(244, 63, 94, 0.55);
}

/* Boss Banner */
.boss-banner {
  position: absolute;
  top: 44px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 16;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  border-radius: 10px;
  background: linear-gradient(90deg, rgba(136, 19, 55, 0.95), rgba(88, 28, 135, 0.95));
  border: 2px solid #fb7185;
  color: #fff1f2;
  font-weight: 900;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  box-shadow: 0 0 28px rgba(244, 63, 94, 0.7);
  pointer-events: none;
  white-space: nowrap;
}

/* Stage Toast */
.stage-toast {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 18;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(14, 9, 28, 0.94);
  border: 1.5px solid var(--accent-magenta);
  color: #fae8ff;
  font-size: 0.82rem;
  font-weight: 700;
  pointer-events: none;
  max-width: 92%;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.65);
}

/* Contextual Structure Popover (Desktop anchored; Mobile bottom-sheet) */
.tower-popover {
  position: absolute;
  z-index: 25;
  width: 248px;
  max-width: calc(100% - 16px);
  padding: 10px;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(25, 16, 48, 0.98), rgba(14, 9, 28, 0.98));
  border: 1.5px solid var(--accent-violet);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.78), 0 0 18px rgba(168, 85, 247, 0.3);
  color: var(--text-main);
  font-size: 0.8rem;
}

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

.pop-title {
  font-weight: 800;
  font-size: 0.88rem;
  color: #f5d0fe;
}

.pop-close {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--text-dim);
  border-radius: 5px;
  width: 22px;
  height: 22px;
  cursor: pointer;
  font-weight: 800;
}

.pop-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  margin-bottom: 8px;
  padding: 6px;
  border-radius: 7px;
  background: rgba(8, 5, 18, 0.72);
  font-size: 0.74rem;
  color: var(--text-dim);
}
.pop-stats strong { color: #e2e8f0; }

.pop-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px;
  margin-bottom: 6px;
}

.pop-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid var(--border-rune);
  background: #231742;
  color: var(--text-main);
  font-weight: 700;
  font-size: 0.74rem;
  cursor: pointer;
}
.pop-btn:hover:not(:disabled) {
  border-color: var(--accent-magenta);
  background: #31205c;
}
.pop-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}
.pop-btn-upg {
  width: 100%;
  flex-direction: row;
  justify-content: space-between;
  background: linear-gradient(90deg, #581c87, #7e22ce);
  border-color: #c084fc;
  margin-bottom: 5px;
}
.pop-btn-row {
  display: flex;
  gap: 5px;
}
.pop-btn-mode {
  flex: 1;
  flex-direction: row;
  background: #1b2848;
  border-color: #38bdf8;
  color: #bae6fd;
}
.pop-btn-sell {
  flex: 1;
  flex-direction: row;
  background: rgba(136, 19, 55, 0.55);
  border-color: rgba(244, 63, 94, 0.6);
  color: #fecdd3;
}

/* Bottom Command Dock */
.command-dock {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 8px;
  padding: 8px;
  background: linear-gradient(180deg, rgba(24, 16, 46, 0.96), rgba(14, 9, 28, 0.96));
  border: 1.5px solid var(--border-rune);
  border-radius: 10px;
}

.build-group {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  flex: 1;
}

.spell-group {
  display: flex;
  gap: 6px;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1.5px solid var(--border-rune);
  background: linear-gradient(180deg, #21153f, #150d29);
  color: var(--text-main);
  cursor: pointer;
  text-align: left;
  min-width: 0;
  transition: border-color 0.14s ease, transform 0.1s ease, box-shadow 0.14s ease;
}

.tool-btn:hover {
  border-color: #9333ea;
  background: linear-gradient(180deg, #2b1b52, #1b1136);
}

.tool-btn.active {
  border-color: var(--accent-magenta);
  background: linear-gradient(180deg, #3c1e70, #231144);
  box-shadow: 0 0 14px rgba(232, 121, 249, 0.4);
}

.tool-btn.unaffordable {
  opacity: 0.62;
}

.tool-sprite {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.tool-emoji {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}

.tool-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.tool-name {
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool-cost {
  font-size: 0.72rem;
  font-weight: 700;
  color: #67e8f9;
}

kbd {
  display: inline-block;
  font-family: monospace;
  font-size: 0.68rem;
  padding: 0 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.11);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #e9d5ff;
  margin-right: 2px;
}

.spell-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border-radius: 8px;
  border: 1.5px solid #6b21a8;
  background: linear-gradient(180deg, #31175c, #1a0d36);
  color: #f5d0fe;
  cursor: pointer;
  min-width: 126px;
  transition: transform 0.1s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.spell-btn:hover:not(:disabled) {
  border-color: #e879f9;
  box-shadow: 0 0 14px rgba(192, 132, 252, 0.45);
}

.spell-btn.targeting {
  border-color: #38bdf8;
  background: linear-gradient(180deg, #1d4ed8, #1e1b4b);
  box-shadow: 0 0 18px rgba(56, 189, 248, 0.75);
}

.spell-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.spell-ic { font-size: 1.25rem; }
.spell-meta { display: flex; flex-direction: column; text-align: left; }
.spell-name { font-size: 0.76rem; font-weight: 800; white-space: nowrap; }
.spell-cd { font-size: 0.7rem; font-weight: 800; color: #34d399; }
.spell-btn:disabled .spell-cd { color: #fca5a5; }

/* Fixed Full-Viewport Overlay & Modals (Zero Clipping on Mobile!) */
.overlay,
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(5, 3, 12, 0.84);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  overflow-y: auto;
}

.overlay-card,
.modal-card {
  width: 100%;
  max-width: 720px;
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  background: linear-gradient(180deg, #1c1335 0%, #100a21 100%);
  border: 2px solid var(--border-bright);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.82), 0 0 36px rgba(124, 77, 255, 0.25);
  text-align: center;
}

.ov-crest { font-size: 2rem; line-height: 1; margin-bottom: 4px; }
.ov-title {
  font-size: 1.65rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  background: linear-gradient(90deg, #e879f9, #a855f7, #38bdf8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.ov-subtitle {
  font-size: 0.86rem;
  color: var(--text-dim);
  margin: 4px 0 12px;
}

.daily-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 10px;
  background: linear-gradient(90deg, rgba(88, 28, 135, 0.42), rgba(14, 116, 144, 0.3));
  border: 1px solid rgba(192, 132, 252, 0.55);
  margin-bottom: 10px;
  text-align: left;
}
.daily-meta { display: flex; flex-direction: column; gap: 2px; }
.daily-badge { font-size: 0.76rem; font-weight: 900; color: #fde68a; letter-spacing: 0.04em; }
.daily-mod { font-size: 0.78rem; color: #e2e8f0; }
.daily-actions { display: flex; align-items: center; gap: 8px; }
.streak-pill {
  font-size: 0.76rem;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.18);
  border: 1px solid rgba(251, 191, 36, 0.5);
  color: #fde68a;
}

.ov-tip {
  font-size: 0.8rem;
  color: #ddd6fe;
  background: rgba(124, 77, 255, 0.14);
  border: 1px dashed rgba(168, 85, 247, 0.45);
  border-radius: 8px;
  padding: 7px 10px;
  margin-bottom: 12px;
}

.map-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
  text-align: left;
}

.map-card {
  position: relative;
  padding: 9px 10px;
  border-radius: 9px;
  border: 1.5px solid var(--border-rune);
  background: rgba(13, 9, 27, 0.85);
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: border-color 0.14s ease, transform 0.12s ease;
}
.map-card:hover:not(.locked) {
  border-color: var(--accent-magenta);
  transform: translateY(-1px);
}
.map-card.selected {
  border-color: var(--accent-cyan);
  background: linear-gradient(180deg, rgba(49, 25, 92, 0.9), rgba(19, 13, 39, 0.95));
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.35);
}
.map-card.locked {
  opacity: 0.48;
  cursor: not-allowed;
}
.map-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-dim);
  font-weight: 700;
}
.map-card-name {
  font-size: 0.85rem;
  font-weight: 800;
  color: #f3e8ff;
}
.map-card-desc {
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.25;
}
.map-stars {
  color: var(--accent-gold);
  letter-spacing: 1px;
}

/* Post-Run Stats */
.ov-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}
.ov-stat-box {
  padding: 8px 6px;
  border-radius: 8px;
  background: rgba(9, 6, 20, 0.8);
  border: 1px solid var(--border-rune);
}
.ov-stat-lbl { font-size: 0.7rem; color: var(--text-dim); text-transform: uppercase; }
.ov-stat-val { font-size: 1.05rem; font-weight: 900; color: #f5d0fe; margin-top: 2px; }

.cliffhanger {
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.45);
  color: #fef08a;
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.lb-submit-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.lb-submit-row input {
  padding: 7px 10px;
  border-radius: 7px;
  border: 1px solid var(--border-rune);
  background: #0d081c;
  color: var(--text-main);
  font-size: 0.84rem;
  width: 170px;
}
.lb-submit-msg {
  font-size: 0.78rem;
  color: #6ee7b7;
  font-weight: 700;
}

.share-preview {
  font-family: monospace;
  font-size: 0.75rem;
  color: #e9d5ff;
  background: rgba(8, 5, 18, 0.88);
  border: 1px solid var(--border-rune);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 12px;
  word-break: break-word;
}

/* Buttons */
.ov-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  padding: 9px 15px;
  border-radius: 8px;
  border: 1.5px solid var(--border-rune);
  background: #241845;
  color: var(--text-main);
  font-weight: 800;
  font-size: 0.86rem;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.14s ease;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(135deg, #9333ea, #6d28d9);
  border-color: #d8b4fe;
  color: #fff;
  box-shadow: 0 0 18px rgba(147, 51, 234, 0.5);
}
.btn-daily {
  padding: 6px 12px;
  font-size: 0.78rem;
  background: linear-gradient(135deg, #0284c7, #7e22ce);
  border-color: #7dd3fc;
  color: #fff;
}
.btn-gold {
  background: linear-gradient(135deg, #b45309, #92400e);
  border-color: #fcd34d;
  color: #fef3c7;
}
.btn-share {
  background: linear-gradient(135deg, #059669, #047857);
  border-color: #6ee7b7;
  color: #ecfdf5;
}
.btn-ghost {
  background: transparent;
  border-color: var(--border-rune);
  color: var(--text-dim);
}
.btn-sm { padding: 5px 10px; font-size: 0.76rem; }

/* Modal Headers & Content */
.modal-card { text-align: left; max-width: 620px; }
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.modal-header h2 {
  font-size: 1.2rem;
  color: #f5d0fe;
  letter-spacing: 0.05em;
}
.modal-sub { font-size: 0.78rem; color: var(--text-dim); margin-top: 2px; }
.modal-close {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: 1px solid var(--border-rune);
  background: #231742;
  color: var(--text-main);
  font-weight: 900;
  cursor: pointer;
}

.codex-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(9, 6, 20, 0.8);
  border: 1px solid var(--border-rune);
  margin-bottom: 12px;
  font-size: 0.82rem;
}
.codex-stars-avail strong { color: var(--accent-gold); }

.codex-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.codex-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 9px;
  background: rgba(15, 10, 31, 0.88);
  border: 1.5px solid var(--border-rune);
}
.codex-item.maxed { border-color: var(--accent-gold); }
.codex-info h3 { font-size: 0.88rem; color: #f5d0fe; margin-bottom: 2px; }
.codex-info p { font-size: 0.76rem; color: var(--text-dim); }
.codex-pips { font-size: 0.76rem; color: var(--accent-gold); margin-top: 3px; font-weight: 800; }

/* Leaderboard List */
.lb-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.lb-row {
  display: grid;
  grid-template-columns: 34px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(12, 8, 25, 0.85);
  border: 1px solid var(--border-rune);
  font-size: 0.84rem;
}
.lb-rank { font-weight: 900; color: var(--accent-gold); }
.lb-name { font-weight: 800; color: #f3e8ff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-wave { font-size: 0.76rem; color: var(--text-dim); }
.lb-score { font-weight: 900; color: #67e8f9; font-variant-numeric: tabular-nums; }
.lb-empty { text-align: center; padding: 20px 10px; color: var(--text-dim); font-size: 0.85rem; }

/* Responsive Mobile Layout (Zero Overflow at 390x844) */
@media (max-width: 820px) {
  #app { padding: 6px 6px 68px; gap: 6px; }
  .hud-bar { padding: 6px 7px; gap: 5px; }
  .brand-pill { font-size: 0.76rem; padding: 3px 7px; }
  .stat-pill { font-size: 0.74rem; padding: 3px 6px; }
  .hud-btn { font-size: 0.74rem; padding: 4px 7px; }

  .command-dock {
    flex-direction: column;
    padding: 6px;
    gap: 6px;
  }
  .build-group {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }
  .tool-btn {
    padding: 5px 6px;
    gap: 5px;
  }
  .tool-sprite, .tool-emoji { width: 24px; height: 24px; }
  .tool-name { font-size: 0.72rem; }
  .tool-cost { font-size: 0.68rem; }
  kbd { display: none; }

  .spell-group {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
  }
  .spell-btn {
    min-width: 0;
    padding: 6px 8px;
    justify-content: center;
  }

  .map-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }
  .ov-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .overlay-card, .modal-card {
    padding: 14px 12px;
  }
  .ov-title { font-size: 1.32rem; }

  /* Transform contextual popover into a clean bottom sheet on mobile (above studio-bar pill) */
  .tower-popover {
    position: fixed;
    left: 8px !important;
    right: 8px !important;
    bottom: 58px !important;
    top: auto !important;
    width: auto;
    max-width: none;
    z-index: 75;
    border-radius: 12px;
    padding: 12px;
  }
}

@media (max-width: 420px) {
  .map-grid { grid-template-columns: 1fr; }
  .brand-pill { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
}
