:root {
  --bg: #070b13;
  --panel: rgba(11, 16, 26, 0.88);
  --panel-solid: rgba(9, 13, 22, 0.96);
  --panel-hi: rgba(18, 26, 40, 0.94);
  --border: rgba(196, 214, 238, 0.16);
  --border-gold: rgba(242, 188, 78, 0.48);
  --border-cyan: rgba(74, 234, 255, 0.48);
  --text: #f3f7fc;
  --soft: rgba(218, 230, 245, 0.84);
  --muted: rgba(154, 174, 198, 0.68);
  --amber: #f4bd4f;
  --amber-deep: #d96b2b;
  --cyan: #4aeaff;
  --green: #58f0a4;
  --red: #ff5b6b;
  --violet: #b670ff;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

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

html, body {
  width: 100%; height: 100%; height: 100dvh; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased; user-select: none; -webkit-user-select: none;
  overscroll-behavior: none;
}

#app { position: relative; width: 100%; height: 100%; height: 100dvh; overflow: hidden; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }
.sub { font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.mobile-only { display: none !important; }

button { font-family: inherit; touch-action: manipulation; }
button:active:not(:disabled) { transform: scale(0.96); }

/* ==================== STREAMLINED TOP HUD ==================== */
.hud-top {
  position: fixed;
  top: calc(10px + var(--sat));
  left: calc(12px + var(--sal));
  right: calc(12px + var(--sar));
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  pointer-events: none; z-index: 20;
}

.resource-ribbon {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 2px;
  height: 40px; padding: 3px 6px 3px 4px; border-radius: 13px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.48), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  max-width: calc(100vw - 140px);
}

.age-crest {
  display: inline-flex; align-items: center; gap: 7px;
  height: 32px; padding: 0 10px 0 4px; border-radius: 9px;
  background: linear-gradient(135deg, rgba(244, 189, 79, 0.16), rgba(217, 107, 43, 0.08));
  border: 1px solid rgba(244, 189, 79, 0.36);
  margin-right: 4px;
}
.age-num {
  font-size: 10px; font-weight: 900; padding: 3px 6px; border-radius: 6px;
  background: linear-gradient(135deg, #f8cb66, #d9822b); color: #160c02;
  letter-spacing: 0.08em; white-space: nowrap;
}
.age-name { font-size: 12.5px; font-weight: 800; color: #fff7e2; white-space: nowrap; }

.stat-seg {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 0 8px; height: 28px; border-radius: 8px;
  font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums;
  position: relative; white-space: nowrap;
}
.stat-seg + .stat-seg::before {
  content: ''; position: absolute; left: 0; top: 5px; bottom: 5px;
  width: 1px; background: rgba(255, 255, 255, 0.1);
}
.stat-hq .ico { color: var(--green); }
.stat-gold .ico { color: var(--amber); }
.stat-rp { color: #c4f8ff; }
.stat-rp .ico { color: var(--cyan); }
.stat-unit { font-size: 10px; font-weight: 800; color: var(--muted); letter-spacing: 0.05em; }

.hud-actions {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
}

.icon-pill, .cta-pill {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  height: 40px; min-width: 40px; padding: 0 11px; border-radius: 11px;
  background: var(--panel); border: 1px solid var(--border);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  color: var(--text); font-size: 12px; font-weight: 800; cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}
.icon-pill:hover, .cta-pill:hover { border-color: var(--border-gold); background: var(--panel-hi); }
.icon-pill[aria-pressed="true"]#btn-grid,
.icon-pill[aria-pressed="true"]#btn-autowave {
  color: var(--green); border-color: rgba(88, 240, 164, 0.65); background: rgba(16, 42, 34, 0.88);
}

.tech-btn {
  border-color: var(--border-cyan); color: #d6fbff;
  background: linear-gradient(135deg, rgba(16, 46, 66, 0.9), rgba(20, 26, 52, 0.92));
}
.tech-btn kbd {
  font-family: inherit; font-size: 10px; padding: 1px 5px; border-radius: 4px;
  background: rgba(0, 0, 0, 0.38); color: var(--cyan); margin-left: 2px;
}

.badge {
  position: absolute; top: -5px; right: -5px; width: 19px; height: 19px; border-radius: 50%;
  display: grid; place-items: center; background: #ff4757; color: #fff; font-size: 11px; font-weight: 900;
  border: 2px solid #0b101a; box-shadow: 0 0 12px rgba(255, 71, 87, 0.9);
  animation: pulseBadge 1.6s infinite;
}
@keyframes pulseBadge { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.14); } }

/* FLOATING ADVANCE-AGE CALLOUT */
.advance-callout {
  position: fixed;
  top: calc(58px + var(--sat)); left: 50%; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 18px; border-radius: 999px;
  background: linear-gradient(135deg, #f9cc5f, #e56d2c); color: #1a0c02;
  border: 1.5px solid #ffecb3; font-size: 12.5px; font-weight: 900;
  letter-spacing: 0.05em; text-transform: uppercase; cursor: pointer; z-index: 23;
  box-shadow: 0 10px 30px rgba(229, 109, 44, 0.52), 0 0 22px rgba(249, 204, 95, 0.45);
  animation: pulseFloat 2s ease-in-out infinite;
}
@keyframes pulseFloat {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-2px); }
}

.cam-hint {
  position: fixed; left: calc(14px + var(--sal)); top: calc(58px + var(--sat));
  padding: 5px 11px; border-radius: 8px;
  background: rgba(9, 14, 24, 0.68); border: 1px solid var(--border);
  backdrop-filter: blur(8px); font-size: 11px; color: var(--soft); pointer-events: none; z-index: 15;
}

/* 3D VERTICAL ALTITUDE / SPACE DECK SWITCHER */
.layer-switcher {
  position: fixed; left: calc(12px + var(--sal)); top: 50%; transform: translateY(-50%);
  padding: 7px; border-radius: 14px; background: var(--panel);
  border: 1px solid var(--border-cyan); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.52), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  z-index: 22;
}
.layer-heading { font-size: 9.5px; font-weight: 900; letter-spacing: 0.12em; color: var(--cyan); text-align: center; margin-bottom: 5px; }
.layer-buttons { display: flex; flex-direction: column; gap: 5px; }
.layer-btn {
  min-height: 36px; padding: 6px 10px; border-radius: 9px; border: 1px solid var(--border);
  background: rgba(18, 28, 44, 0.8); color: var(--soft); font-size: 11px; font-weight: 800;
  cursor: pointer; white-space: nowrap; text-align: left; transition: all 0.15s ease;
}
.layer-btn:hover { border-color: var(--cyan); color: #fff; }
.layer-btn.active {
  background: linear-gradient(135deg, rgba(74, 234, 255, 0.28), rgba(164, 108, 255, 0.22));
  border-color: var(--cyan); color: #fff; box-shadow: 0 0 14px rgba(74, 234, 255, 0.38);
}

.boss-bar {
  position: fixed; top: calc(58px + var(--sat)); left: 50%; transform: translateX(-50%);
  width: min(420px, calc(100vw - 28px)); padding: 8px 14px; border-radius: 12px;
  background: rgba(26, 10, 16, 0.9); border: 1px solid rgba(255, 91, 107, 0.65);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55); z-index: 19; pointer-events: none;
}
.boss-meta { display: flex; justify-content: space-between; font-size: 11px; font-weight: 800; letter-spacing: 0.08em; color: #ffbac2; margin-bottom: 5px; }
.boss-track { height: 7px; border-radius: 4px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.boss-fill { height: 100%; background: linear-gradient(90deg, #ff3e55, #ff9f43); transition: width 0.12s linear; }

.banner-toast {
  position: fixed; top: calc(62px + var(--sat)); left: 50%; transform: translateX(-50%);
  max-width: calc(100vw - 28px); text-align: center;
  padding: 9px 18px; border-radius: 12px;
  background: rgba(10, 16, 26, 0.94); border: 1px solid var(--border-gold);
  color: var(--amber); font-size: 12px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase;
  pointer-events: none; z-index: 30; box-shadow: 0 12px 34px rgba(0, 0, 0, 0.6);
}

/* ==================== THUMB-ZONE BOTTOM COMMAND DECK ==================== */
.hud-bottom {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(10px + var(--sab));
  width: min(1120px, calc(100vw - 20px - var(--sal) - var(--sar)));
  display: flex; flex-direction: column; align-items: stretch; gap: 7px;
  pointer-events: none; z-index: 21;
}

/* Contextual Placement Bar */
.placement-bar {
  pointer-events: auto; align-self: center;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: min(500px, 100%); padding: 7px 10px 7px 12px; border-radius: 13px;
  background: var(--panel-solid); border: 1px solid var(--border-gold);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.58), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
}
.pl-info { display: flex; align-items: center; gap: 9px; min-width: 0; }
.pl-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.pl-text { min-width: 0; }
.pl-name { font-size: 12.5px; font-weight: 800; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-hint { font-size: 11px; color: var(--soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.pl-confirm {
  height: 38px; padding: 0 15px; border-radius: 10px; border: 1px solid #a8ffd0;
  background: linear-gradient(135deg, #42e896, #1db872); color: #051c11;
  font-size: 12.5px; font-weight: 900; letter-spacing: 0.04em; cursor: pointer;
  box-shadow: 0 4px 18px rgba(66, 232, 150, 0.42);
}
.pl-cancel {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid rgba(255, 91, 107, 0.48);
  background: rgba(255, 91, 107, 0.16); color: #ffb4bc; font-size: 15px; font-weight: 800; cursor: pointer;
}

/* Unlocked-Only Active Ability Strip */
.ability-bar {
  pointer-events: auto; align-self: flex-start;
  display: inline-flex; align-items: center; gap: 6px; padding: 5px; border-radius: 13px;
  background: var(--panel); border: 1px solid var(--border);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
.ability-bar::-webkit-scrollbar { display: none; }

.ab-btn {
  position: relative; flex: 0 0 auto; min-width: 78px; height: 48px; padding: 5px 9px;
  border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: rgba(18, 28, 44, 0.9); border: 1px solid rgba(190, 215, 240, 0.22);
  color: var(--text); cursor: pointer; overflow: hidden; transition: border-color 0.15s ease, transform 0.12s ease;
}
.ab-btn:hover:not(:disabled) { border-color: var(--cyan); }
.ab-btn:disabled { opacity: 0.52; cursor: not-allowed; }
.ab-head-row { display: flex; align-items: center; gap: 5px; }
.ab-key { font-size: 9.5px; font-weight: 900; color: var(--cyan); opacity: 0.85; }
.ab-dot { width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 8px currentColor; }
.ab-name { font-size: 10.5px; font-weight: 800; line-height: 1.1; white-space: nowrap; }
.ab-cd { font-size: 10px; font-weight: 800; color: var(--amber); }

/* Primary Bottom Command Row */
.command-row {
  pointer-events: auto;
  display: flex; align-items: stretch; gap: 8px; width: 100%;
}

.arsenal-shell {
  flex: 1 1 auto; min-width: 0;
  display: flex; flex-direction: column; gap: 6px; padding: 7px 9px; border-radius: 15px;
  background: var(--panel); border: 1px solid var(--border);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.52), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.arsenal-shell.collapsed .weapon-dock { display: none; }
.arsenal-shell.collapsed { padding-bottom: 6px; }

.arsenal-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.arsenal-filters {
  display: flex; gap: 4px; align-items: center; overflow-x: auto; scrollbar-width: none;
}
.arsenal-filters::-webkit-scrollbar { display: none; }
.flt-btn {
  flex: 0 0 auto; height: 28px; padding: 0 10px; border-radius: 7px; border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04); color: var(--muted); font-size: 11px; font-weight: 700; cursor: pointer;
}
.flt-btn.active { background: rgba(74, 234, 255, 0.16); border-color: rgba(74, 234, 255, 0.45); color: var(--cyan); }

.dock-toggle-btn {
  flex: 0 0 auto; width: 30px; height: 28px; border-radius: 7px; border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06); color: var(--soft); font-size: 13px; cursor: pointer;
  display: grid; place-items: center;
}

.weapon-dock {
  display: flex; align-items: stretch; gap: 6px; overflow-x: auto; padding-bottom: 2px;
  touch-action: pan-x; -webkit-overflow-scrolling: touch;
  scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}
.w-card {
  position: relative; flex: 0 0 auto; width: 108px; min-height: 64px; padding: 6px 8px; border-radius: 11px;
  display: flex; flex-direction: column; justify-content: space-between; text-align: left;
  background: linear-gradient(160deg, rgba(22, 33, 49, 0.9), rgba(14, 21, 33, 0.94));
  border: 1px solid rgba(196, 216, 240, 0.16);
  color: var(--text); cursor: pointer; transition: border-color 0.14s ease, transform 0.12s ease, box-shadow 0.14s ease;
}
.w-card:hover { border-color: var(--border-gold); transform: translateY(-1px); }
.w-card.selected {
  border-color: var(--amber); border-width: 1.5px;
  background: linear-gradient(160deg, rgba(56, 48, 28, 0.95), rgba(24, 30, 44, 0.96));
  box-shadow: 0 0 18px rgba(244, 189, 79, 0.38);
}
.w-card.cant-afford { opacity: 0.46; }
.w-top { display: flex; justify-content: space-between; align-items: center; gap: 4px; }
.w-ico { font-size: 13px; line-height: 1; }
.w-arch { font-size: 9px; font-weight: 800; text-transform: uppercase; color: var(--muted); letter-spacing: 0.04em; }
.w-name { font-size: 11.5px; font-weight: 800; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.w-foot { display: flex; justify-content: space-between; align-items: center; }
.w-cost { font-size: 11.5px; font-weight: 900; color: var(--amber); font-variant-numeric: tabular-nums; }
.w-age-tag { font-size: 9px; font-weight: 800; color: var(--muted); }

.wave-btn {
  flex: 0 0 auto; min-width: 152px; padding: 10px 16px; border-radius: 15px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 1.5px solid rgba(255, 228, 158, 0.72);
  background: linear-gradient(145deg, #f8c653, #dd622c);
  color: #190b02; cursor: pointer;
  box-shadow: 0 10px 28px rgba(221, 98, 44, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.38);
}
.wave-btn.in-wave {
  background: var(--panel); border-color: var(--border); color: var(--soft); box-shadow: none;
}
.wave-main { font-size: 13px; font-weight: 900; letter-spacing: 0.05em; text-transform: uppercase; white-space: nowrap; }
.wave-sub { font-size: 10.5px; font-weight: 700; opacity: 0.85; white-space: nowrap; }

.thumb-tech-btn {
  position: relative; flex: 0 0 auto; width: 64px; border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: linear-gradient(150deg, rgba(16, 48, 68, 0.94), rgba(18, 24, 48, 0.96));
  border: 1.5px solid var(--border-cyan); color: #d8fbff; cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.tt-ico { font-size: 18px; line-height: 1; color: var(--cyan); }
.tt-lbl { font-size: 10.5px; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; }

/* ==================== TOWER INSPECTOR (Card -> Mobile Bottom Sheet) ==================== */
.inspector {
  position: fixed; right: calc(16px + var(--sar)); bottom: calc(136px + var(--sab));
  width: 296px; padding: 14px; border-radius: 16px;
  background: var(--panel-solid); border: 1px solid var(--border-gold);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 20px 52px rgba(0, 0, 0, 0.68), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  z-index: 26;
}
.sheet-handle { display: none; width: 40px; height: 4px; border-radius: 99px; background: rgba(255, 255, 255, 0.24); margin: 0 auto 10px; }
.insp-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.insp-title-block { min-width: 0; }
.insp-tier { font-size: 10px; font-weight: 900; color: var(--amber); letter-spacing: 0.1em; }
.insp-head h3 { font-size: 16px; font-weight: 800; color: #fff; margin-top: 2px; }
.insp-role { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.close-x {
  flex-shrink: 0; width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--border); background: rgba(255, 255, 255, 0.07);
  color: var(--text); font-size: 15px; font-weight: 700; cursor: pointer; display: grid; place-items: center;
}
.insp-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.stat-box { padding: 7px 9px; border-radius: 9px; background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.06); }
.stat-box-val { font-size: 13.5px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat-delta { color: var(--green); font-size: 11px; margin-left: 4px; }
.insp-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.seg-group { display: flex; gap: 3px; background: rgba(0, 0, 0, 0.4); padding: 3px; border-radius: 9px; flex: 1; }
.seg-btn {
  flex: 1; min-height: 32px; padding: 4px 6px; border: none; border-radius: 7px;
  background: transparent; color: var(--muted); font-size: 11px; font-weight: 800; cursor: pointer;
}
.seg-btn.active { background: rgba(74, 234, 255, 0.24); color: var(--cyan); }
.insp-actions { display: flex; gap: 8px; }
.upgrade-btn {
  flex: 1; min-height: 44px; display: flex; justify-content: space-between; align-items: center;
  padding: 0 14px; border-radius: 11px;
  border: 1px solid rgba(244, 189, 79, 0.65);
  background: linear-gradient(135deg, rgba(244, 189, 79, 0.32), rgba(74, 234, 255, 0.16));
  color: #fff; font-size: 13px; font-weight: 800; cursor: pointer;
}
.upgrade-btn:disabled { opacity: 0.42; cursor: not-allowed; }
.sell-btn {
  min-width: 84px; min-height: 44px; padding: 4px 12px; border-radius: 11px;
  border: 1px solid rgba(255, 91, 107, 0.45); background: rgba(255, 91, 107, 0.14);
  color: #ffb4bc; font-size: 11.5px; font-weight: 800; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.sell-btn.confirm-armed {
  background: rgba(255, 65, 85, 0.85); color: #fff; border-color: #ffc2c8;
}

/* ==================== OVERLAYS, TITLE, PAUSE & SETTINGS ==================== */
.overlay {
  position: fixed; inset: 0; display: grid; place-items: center;
  padding: calc(16px + var(--sat)) calc(16px + var(--sar)) calc(16px + var(--sab)) calc(16px + var(--sal));
  z-index: 40; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: radial-gradient(circle at 50% 42%, rgba(8, 16, 28, 0.44), rgba(4, 7, 14, 0.86));
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.title-panel, .modal-panel {
  width: min(640px, 100%); max-height: calc(100dvh - 32px - var(--sat) - var(--sab));
  overflow-y: auto; padding: 26px 26px 24px; border-radius: 22px; text-align: center;
  background: linear-gradient(165deg, rgba(13, 21, 35, 0.92), rgba(7, 11, 20, 0.97));
  border: 1px solid rgba(244, 189, 79, 0.26);
  box-shadow: 0 32px 96px rgba(0, 0, 0, 0.78), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.modal-panel { width: min(440px, 100%); }
.eyebrow { font-size: 10.5px; font-weight: 800; letter-spacing: 0.2em; text-transform: uppercase; color: var(--amber); margin-bottom: 8px; }
.brand-title {
  font-size: clamp(34px, 7vw, 56px); font-weight: 900; letter-spacing: 0.22em; padding-left: 0.22em; margin-bottom: 10px;
  background: linear-gradient(180deg, #ffffff 10%, #c6f4ff 54%, #f4bd4f 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-copy { font-size: 13.5px; line-height: 1.54; color: var(--soft); max-width: 520px; margin: 0 auto 14px; }
.era-strip { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; margin-bottom: 16px; }
.era-strip span { font-size: 10.5px; font-weight: 700; padding: 4px 9px; border-radius: 999px; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12); color: var(--soft); }

.seed-row { display: flex; align-items: center; justify-content: center; gap: 7px; flex-wrap: wrap; margin-bottom: 16px; }
.seed-input {
  height: 38px; width: 146px; padding: 0 11px; border-radius: 9px;
  border: 1px solid var(--border); background: rgba(5, 9, 16, 0.85); color: var(--text);
  font-family: ui-monospace, monospace; font-size: 13px; text-align: center; outline: none;
}
.small-pill {
  height: 38px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--border);
  background: rgba(22, 32, 48, 0.88); color: var(--soft); font-size: 12px; font-weight: 700; cursor: pointer;
}
.small-pill.accent { color: var(--cyan); border-color: var(--border-cyan); }

.cta-row { display: flex; flex-direction: column; align-items: center; gap: 9px; }
.cta-sub-row { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; width: 100%; }
.primary-cta, .secondary-cta {
  min-height: 46px; padding: 11px 24px; border-radius: 12px;
  font-size: 13px; font-weight: 800; letter-spacing: 0.07em; text-transform: uppercase; cursor: pointer;
}
.primary-cta {
  width: min(340px, 100%);
  border: 1.5px solid rgba(255, 232, 168, 0.78);
  background: linear-gradient(135deg, #f8c653, #dd622c); color: #190b02;
  box-shadow: 0 10px 28px rgba(221, 98, 44, 0.42);
}
.secondary-cta {
  flex: 1 1 150px; max-width: 220px;
  border: 1px solid var(--border); background: rgba(20, 32, 48, 0.88); color: var(--text);
}
.modal-h2 { font-size: 24px; font-weight: 800; margin-bottom: 6px; }
.modal-sub { font-size: 13px; color: var(--soft); margin-bottom: 16px; }

.settings-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 18px;
}
.setting-tile {
  min-height: 52px; padding: 8px 12px; border-radius: 12px;
  background: rgba(20, 30, 46, 0.84); border: 1px solid var(--border);
  color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 6px;
}
.setting-tile[aria-pressed="true"] {
  border-color: rgba(88, 240, 164, 0.65); background: rgba(16, 44, 38, 0.88);
}
.st-ico { font-size: 15px; color: var(--cyan); }
.st-lbl { flex: 1; text-align: left; font-size: 12px; font-weight: 800; }
.st-val { font-size: 11px; font-weight: 800; color: var(--amber); text-transform: uppercase; }

/* ==================== INTERACTIVE TECH TREE & CODEX MODAL ==================== */
.tech-modal {
  width: min(1160px, 96vw); height: min(740px, 92dvh);
  display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; border-radius: 20px;
  background: linear-gradient(165deg, rgba(11, 17, 29, 0.97), rgba(6, 10, 18, 0.99));
  border: 1px solid rgba(140, 210, 255, 0.25); box-shadow: 0 32px 96px rgba(0, 0, 0, 0.84);
  overflow: hidden;
}
.tech-modal-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-shrink: 0; }
.tech-head-title { min-width: 0; }
.tech-head-title h2 { font-size: 18px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tech-head-right { display: flex; align-items: center; gap: 7px; flex-shrink: 0; }
.rp-chip {
  display: inline-flex; align-items: center; gap: 5px; height: 38px; padding: 0 11px; border-radius: 10px;
  background: rgba(14, 34, 48, 0.9); border: 1px solid var(--border-cyan);
  color: #c8f9ff; font-size: 13px; font-weight: 900; font-variant-numeric: tabular-nums;
}
.rp-chip .ico { color: var(--cyan); }

/* Single-Row Swipeable Age Pills */
.age-tabs {
  flex-shrink: 0; display: flex; flex-wrap: nowrap; gap: 6px;
  overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 2px;
}
.age-tabs::-webkit-scrollbar { display: none; }
.age-tab {
  flex: 0 0 auto; min-height: 36px; padding: 6px 12px; border-radius: 9px;
  border: 1px solid var(--border); background: rgba(18, 26, 40, 0.78);
  color: var(--soft); font-size: 11.5px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.age-tab.active { border-color: var(--cyan); background: rgba(30, 62, 92, 0.94); color: #fff; }
.age-tab.locked { opacity: 0.52; }

.route-bar {
  flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  padding: 8px 12px; border-radius: 11px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--border);
  font-size: 11.5px;
}
.route-pills { display: flex; flex-wrap: nowrap; overflow-x: auto; gap: 5px; scrollbar-width: none; max-width: 100%; }
.route-pills::-webkit-scrollbar { display: none; }
.route-pill {
  flex: 0 0 auto; padding: 3px 9px; border-radius: 999px; font-size: 10.5px; font-weight: 700;
  background: rgba(255, 255, 255, 0.06); color: var(--muted); border: 1px solid rgba(255, 255, 255, 0.1);
}
.route-pill.done { background: rgba(88, 240, 164, 0.2); color: var(--green); border-color: rgba(88, 240, 164, 0.55); }

/* Pan & Pinch-to-Zoom Tree Canvas */
.tree-shell { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; overflow: hidden; }
.tree-viewport-wrap { position: relative; flex: 1; min-height: 190px; display: flex; overflow: hidden; border-radius: 14px; border: 1px solid rgba(120, 195, 255, 0.22); }
.tree-viewport {
  position: relative; flex: 1; overflow: auto; cursor: grab; touch-action: none;
  background:
    radial-gradient(circle at 1px 1px, rgba(120, 185, 240, 0.14) 1px, transparent 0) 0 0 / 26px 26px,
    linear-gradient(180deg, rgba(8, 14, 24, 0.95), rgba(6, 10, 18, 0.99));
  scrollbar-width: thin; scrollbar-color: rgba(74, 234, 255, 0.35) rgba(0, 0, 0, 0.25);
}
.tree-viewport.dragging { cursor: grabbing; }
.tree-zoom-stage { position: relative; }
.tree-canvas { position: relative; transform-origin: 0 0; height: 344px; }
.tree-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.tree-nodes { position: absolute; inset: 0; }

.tree-zoom-controls {
  position: absolute; right: 10px; top: 10px; display: flex; gap: 4px; z-index: 8;
  padding: 4px; border-radius: 10px; background: rgba(8, 13, 22, 0.86); border: 1px solid var(--border);
  backdrop-filter: blur(10px);
}
.tz-btn {
  min-width: 34px; height: 32px; padding: 0 8px; border-radius: 7px; border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.06); color: var(--text); font-size: 12px; font-weight: 800; cursor: pointer;
}
.tz-btn:hover { border-color: var(--cyan); color: var(--cyan); }

.era-band { position: absolute; top: 0; bottom: 0; pointer-events: none; border-right: 1px dashed rgba(140, 195, 245, 0.16); }
.era-band.future { background: rgba(4, 7, 14, 0.38); }
.era-band-title { position: absolute; top: 10px; left: 16px; font-size: 11px; font-weight: 900; letter-spacing: 0.16em; text-transform: uppercase; color: rgba(244, 189, 79, 0.86); }
.era-band-sub { position: absolute; top: 25px; left: 16px; font-size: 10px; color: var(--muted); }

.tree-node {
  position: absolute; transform: translate(-50%, -50%);
  width: 152px; min-height: 64px; padding: 8px 10px; border-radius: 12px;
  background: rgba(15, 23, 37, 0.95); border: 1.5px solid rgba(165, 200, 235, 0.24);
  color: var(--text); text-align: left; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.48);
  transition: transform 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}
.tree-node:hover { transform: translate(-50%, -52%) scale(1.03); border-color: var(--cyan); z-index: 4; }
.tree-node.selected { border-color: var(--amber); border-width: 2px; box-shadow: 0 0 22px rgba(244, 189, 79, 0.45); z-index: 5; }
.tree-node.researched { border-color: rgba(88, 240, 164, 0.82); background: linear-gradient(155deg, rgba(16, 46, 40, 0.95), rgba(11, 26, 28, 0.97)); }
.tree-node.available { border-color: rgba(74, 234, 255, 0.88); box-shadow: 0 0 18px rgba(74, 234, 255, 0.28); }
.tree-node.locked-era { opacity: 0.56; }
.tree-node.keystone { border-width: 2px; }

.tn-head { display: flex; justify-content: space-between; align-items: center; gap: 4px; font-size: 9.5px; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; }
.tn-name { font-size: 12px; font-weight: 800; color: #fff; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tn-foot { display: flex; justify-content: space-between; align-items: center; gap: 4px; margin-top: 2px; font-size: 10px; font-weight: 700; color: var(--soft); }

.tree-root, .tree-gateway {
  position: absolute; transform: translate(-50%, -50%);
  width: 82px; height: 82px; border-radius: 18px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: linear-gradient(145deg, rgba(24, 34, 52, 0.96), rgba(12, 18, 30, 0.98));
  border: 2px solid rgba(244, 189, 79, 0.48); color: var(--amber); cursor: pointer;
  text-align: center; padding: 6px; box-shadow: 0 10px 26px rgba(0, 0, 0, 0.55);
}
.tree-gateway.reached { border-color: var(--green); color: var(--green); background: rgba(14, 44, 38, 0.95); }
.tree-gateway.ready { border-color: var(--amber); box-shadow: 0 0 26px rgba(244, 189, 79, 0.65); color: #ffe699; }
.tree-gateway.locked { opacity: 0.52; border-color: rgba(160, 185, 215, 0.25); color: var(--muted); }
.gw-num { font-size: 10px; font-weight: 900; letter-spacing: 0.1em; }
.gw-name { font-size: 10.5px; font-weight: 800; line-height: 1.1; }

.tree-inspector {
  flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px; border-radius: 13px;
  background: rgba(14, 22, 36, 0.96); border: 1px solid rgba(140, 205, 255, 0.26);
}
.ti-left { flex: 1 1 320px; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.ti-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ti-name { font-size: 15px; font-weight: 800; color: #fff; }
.ti-desc { font-size: 12px; color: var(--soft); line-height: 1.38; }
.node-unlocks { display: flex; gap: 5px; flex-wrap: wrap; }
.ti-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.unlock-chip { font-size: 10.5px; font-weight: 700; padding: 3px 8px; border-radius: 6px; background: rgba(255, 255, 255, 0.08); color: #e6f4ff; white-space: nowrap; }
.unlock-chip.ab { background: rgba(244, 189, 79, 0.22); color: #ffe394; }
.unlock-chip.sky-chip { background: rgba(74, 234, 255, 0.22); border: 1px solid rgba(74, 234, 255, 0.55); color: #b4fcff; }
.unlock-chip.locked-chip { background: rgba(255, 255, 255, 0.04); border: 1px dashed rgba(190, 215, 240, 0.24); color: var(--muted); }

.node-btn {
  min-height: 44px; padding: 0 18px; border-radius: 11px; border: 1.5px solid rgba(74, 234, 255, 0.72);
  background: linear-gradient(135deg, rgba(74, 234, 255, 0.3), rgba(88, 160, 255, 0.2));
  color: #ecfeff; font-size: 13px; font-weight: 800; cursor: pointer; white-space: nowrap;
}
.node-btn:disabled { opacity: 0.45; cursor: not-allowed; border-color: var(--border); background: transparent; color: var(--muted); }
.node-done { font-size: 12.5px; font-weight: 800; color: var(--green); }

/* 234-ENTRY CODEX */
.codex-body { display: flex; flex-direction: column; gap: 8px; overflow: hidden; flex: 1; min-height: 0; }
.codex-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.codex-input { flex: 1 1 200px; text-align: left; font-family: inherit; }
.codex-filters { display: flex; gap: 4px; overflow-x: auto; }
.codex-count-bar { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: 0.05em; text-transform: uppercase; }
.codex-grid { overflow-y: auto; -webkit-overflow-scrolling: touch; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; padding-right: 2px; }
.codex-item {
  padding: 11px 12px; border-radius: 11px; background: rgba(16, 24, 38, 0.88); border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 4px;
}
.codex-item.unlocked { border-color: rgba(88, 240, 164, 0.52); }
.codex-item.mystery-item { background: rgba(10, 14, 24, 0.76); border: 1px dashed rgba(180, 200, 225, 0.2); opacity: 0.8; }
.mystery-name { color: var(--muted); letter-spacing: 0.04em; }
.codex-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 800; }
.codex-meta { font-size: 10.5px; color: var(--amber); font-weight: 700; }
.codex-desc { font-size: 11.5px; color: var(--soft); line-height: 1.38; }

/* ==================== MOBILE PORTRAIT & TABLET (<= 860px) ==================== */
@media (max-width: 860px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: inline-flex !important; }
  .cam-hint { display: none !important; }

  .hud-top {
    top: calc(8px + var(--sat));
    left: calc(8px + var(--sal));
    right: calc(8px + var(--sar));
    gap: 6px;
  }
  .resource-ribbon {
    height: 38px; padding: 2px 5px 2px 3px; border-radius: 11px;
    max-width: calc(100vw - 148px); overflow-x: auto; scrollbar-width: none;
  }
  .resource-ribbon::-webkit-scrollbar { display: none; }
  .age-crest { padding: 0 5px 0 3px; margin-right: 2px; height: 30px; }
  .age-name { display: none; }
  .stat-seg { padding: 0 6px; font-size: 12.5px; gap: 3px; }
  .stat-unit { display: none; }

  .hud-actions { gap: 5px; }
  .icon-pill { height: 38px; min-width: 38px; padding: 0 9px; font-size: 12.5px; border-radius: 10px; }

  .advance-callout {
    top: calc(52px + var(--sat)); height: 36px; padding: 0 14px; font-size: 11.5px;
  }
  .boss-bar { top: calc(52px + var(--sat)); padding: 7px 12px; }
  .banner-toast { top: calc(54px + var(--sat)); font-size: 11px; padding: 7px 14px; }

  /* Compact vertical 3D layer switcher tucked cleanly on top-left below HUD */
  .layer-switcher {
    left: calc(8px + var(--sal)); top: calc(54px + var(--sat)); transform: none;
    padding: 5px; border-radius: 12px;
  }
  .layer-heading { font-size: 8.5px; margin-bottom: 4px; }
  .layer-btn { min-height: 34px; padding: 5px 8px; font-size: 10.5px; }

  /* Mobile Thumb-Zone Bottom Command Deck */
  .hud-bottom {
    bottom: calc(6px + var(--sab));
    width: calc(100vw - 12px - var(--sal) - var(--sar));
    gap: 5px;
  }
  .placement-bar { width: 100%; padding: 6px 8px 6px 10px; }
  .ab-btn { min-width: 72px; height: 44px; padding: 4px 8px; }
  .ab-key { display: none; }

  .command-row {
    display: grid;
    grid-template-columns: 64px 1fr 112px;
    grid-template-rows: auto auto;
    gap: 6px;
    align-items: stretch;
  }
  .arsenal-shell {
    grid-column: 1 / -1; grid-row: 1;
    padding: 6px 8px; border-radius: 14px;
  }
  .thumb-tech-btn {
    grid-column: 1; grid-row: 2;
    width: 100%; min-height: 48px;
  }
  .wave-btn {
    grid-column: 2 / 4; grid-row: 2;
    min-width: 0; min-height: 48px; padding: 6px 12px; border-radius: 14px;
    flex-direction: row; justify-content: center; gap: 8px;
  }
  .wave-main { font-size: 13px; }
  .wave-sub { font-size: 11px; margin-top: 0; }

  .w-card { width: 104px; min-height: 60px; padding: 6px 7px; }

  /* Mobile Slide-Up Bottom Sheet Inspector */
  .inspector {
    left: 0; right: 0; bottom: 0; width: 100%;
    border-radius: 20px 20px 0 0; border-bottom: none;
    padding: 10px calc(14px + var(--sar)) calc(14px + var(--sab)) calc(14px + var(--sal));
    z-index: 32;
    animation: slideUpSheet 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  }
  @keyframes slideUpSheet {
    from { transform: translateY(36px); opacity: 0.4; }
    to { transform: translateY(0); opacity: 1; }
  }
  .sheet-handle { display: block; }
  .insp-stats { grid-template-columns: repeat(4, 1fr); gap: 5px; }
  .stat-box { padding: 6px 6px; text-align: center; }
  .stat-box-val { font-size: 12.5px; }
  .insp-actions { gap: 8px; }
  .upgrade-btn { min-height: 48px; font-size: 13.5px; }
  .sell-btn { min-height: 48px; min-width: 96px; }

  /* Full-Screen Edge-to-Edge Tech Tree & Codex on Mobile */
  .overlay-full { padding: 0; }
  .tech-modal {
    width: 100%; height: 100dvh; max-height: 100dvh; border-radius: 0; border: none;
    padding: calc(10px + var(--sat)) calc(10px + var(--sar)) calc(10px + var(--sab)) calc(10px + var(--sal));
    gap: 6px;
  }
  .tech-head-title h2 { font-size: 15.5px; }
  .route-bar { padding: 6px 9px; gap: 6px; }
  .route-title-line { display: none; }
  .tree-inspector { padding: 9px 10px; gap: 8px; }
  .ti-left { flex: 1 1 100%; }
  .ti-name { font-size: 14px; }
  .ti-desc { font-size: 11.5px; }
  .node-unlocks { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .node-unlocks::-webkit-scrollbar { display: none; }
  .ti-right { width: 100%; }
  .node-btn { width: 100%; min-height: 46px; }

  .codex-grid { grid-template-columns: 1fr; }

  .title-panel, .modal-panel { padding: 22px 18px 20px; border-radius: 18px; }
  .brand-copy { font-size: 13px; }
  .era-strip span { font-size: 9.5px; padding: 3px 7px; }
}

/* ==================== MOBILE LANDSCAPE (Short Height <= 500px) ==================== */
@media (max-height: 500px) and (orientation: landscape) {
  .desktop-only { display: none !important; }
  .mobile-only { display: inline-flex !important; }
  .cam-hint { display: none !important; }

  .hud-top { top: calc(6px + var(--sat)); }
  .resource-ribbon { height: 34px; }
  .icon-pill { height: 34px; min-width: 34px; }

  .hud-bottom { bottom: calc(4px + var(--sab)); gap: 4px; }
  .command-row {
    display: flex; align-items: stretch; gap: 6px;
  }
  .thumb-tech-btn { width: 58px; min-height: 44px; }
  .arsenal-shell { flex: 1 1 auto; padding: 4px 7px; gap: 4px; }
  .w-card { width: 96px; min-height: 50px; padding: 4px 6px; }
  .wave-btn { min-width: 118px; min-height: 44px; flex-direction: column; gap: 1px; padding: 4px 10px; }

  .title-panel { padding: 14px 18px; }
  .brand-title { font-size: 28px; margin-bottom: 6px; }
  .brand-copy { font-size: 12px; margin-bottom: 8px; }
  .era-strip { margin-bottom: 8px; }
  .seed-row { margin-bottom: 10px; }
}
