:root {
  --bg-deep: #060a12;
  --bg-surface: rgba(12, 20, 34, 0.86);
  --bg-card: rgba(16, 27, 46, 0.92);
  --border-subtle: rgba(56, 189, 248, 0.22);
  --border-strong: rgba(56, 189, 248, 0.55);
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --cyan: #38bdf8;
  --teal: #2dd4bf;
  --amber: #f59e0b;
  --emerald: #10b981;
  --rose: #f43f5e;
  --violet: #a855f7;
  --font-sans: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 45%, #0d1729 0%, #060a12 75%);
  color: var(--text-main);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  touch-action: manipulation;
}

.mono {
  font-family: var(--font-mono);
}

.hidden {
  display: none !important;
}

#app-shell {
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#stage-root {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow: hidden;
}

#canvas-wrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

/* HUD LAYER */
.ui-screen {
  position: absolute;
  inset: 0;
  z-index: 10;
}

#screen-hud {
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px 16px;
}

.hud-top-bar,
.hud-bottom-bar {
  pointer-events: auto;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 10px;
}

.hud-group {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.hud-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 7px 12px;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.42);
}

.hud-wave-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-width: 210px;
}

.hud-meta-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.badge-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: var(--cyan);
}

.badge-tag.overdrive {
  background: rgba(245, 158, 11, 0.16);
  border-color: rgba(245, 158, 11, 0.55);
  color: var(--amber);
}

.badge-tag.danger {
  background: rgba(244, 63, 94, 0.16);
  border-color: rgba(244, 63, 94, 0.55);
  color: var(--rose);
}

.badge-tag.victory {
  background: rgba(16, 185, 129, 0.16);
  border-color: rgba(16, 185, 129, 0.55);
  color: var(--emerald);
}

.hud-wave-val {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-main);
}

.hud-core-line {
  display: flex;
  align-items: center;
  gap: 7px;
}

.hud-lbl {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.bar-track {
  flex: 1;
  height: 7px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.25);
  overflow: hidden;
}

.bar-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #10b981, #38bdf8);
  transition: width 0.2s ease, background 0.2s ease;
}

.bar-fill.low {
  background: linear-gradient(90deg, #f43f5e, #f59e0b);
}

.hud-core-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--emerald);
  min-width: 48px;
  text-align: right;
}

.hud-salvage-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 96px;
}

.salvage-line {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.salvage-gem {
  color: var(--amber);
  font-size: 14px;
}

.salvage-num {
  font-size: 18px;
  font-weight: 700;
  color: #fde68a;
}

.hud-center-card {
  display: flex;
  align-items: center;
  gap: 14px;
}

.center-metrics {
  display: flex;
  align-items: center;
  gap: 14px;
}

.metric-cell {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.metric-num {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
}

.conduit-num {
  color: var(--teal);
}

.wave-btn {
  border: 1px solid rgba(56, 189, 248, 0.6);
  background: linear-gradient(135deg, rgba(14, 116, 144, 0.55), rgba(37, 99, 235, 0.45));
  color: #f8fafc;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, filter 0.15s ease;
}

.wave-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--cyan);
  filter: brightness(1.15);
}

.wave-btn:disabled {
  opacity: 0.58;
  cursor: default;
  background: rgba(15, 23, 42, 0.72);
  border-color: rgba(148, 163, 184, 0.25);
}

.hud-right {
  align-items: center;
}

.tool-btn {
  height: 40px;
  min-width: 40px;
  padding: 0 10px;
  border-radius: 9px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: border-color 0.14s ease, background 0.14s ease, transform 0.1s ease;
}

.tool-btn:hover {
  border-color: var(--cyan);
  background: rgba(20, 35, 58, 0.94);
}

.tool-btn.is-active {
  border-color: var(--amber);
  color: var(--amber);
  background: rgba(120, 53, 15, 0.45);
}

.hud-banner {
  position: absolute;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #e0f2fe;
  background: rgba(12, 24, 42, 0.9);
  border: 1px solid rgba(56, 189, 248, 0.55);
  box-shadow: 0 0 24px rgba(56, 189, 248, 0.25);
  white-space: nowrap;
}

/* BOTTOM TURRET DECK & INSPECTOR */
.turret-deck {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.turret-card {
  width: 176px;
  text-align: left;
  padding: 8px 11px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-main);
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: border-color 0.14s ease, transform 0.12s ease, background 0.14s ease;
}

.turret-card:hover {
  transform: translateY(-2px);
  border-color: rgba(148, 163, 184, 0.55);
}

.turret-card.is-selected {
  border-color: var(--cyan);
  background: rgba(14, 34, 58, 0.94);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.35), 0 8px 22px rgba(56, 189, 248, 0.18);
}

.turret-card.is-unaffordable .t-cost {
  color: var(--rose);
}

.turret-head {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 4px;
}

.t-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.t-swatch.rail {
  background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
}

.t-swatch.cryo {
  background: var(--teal);
  box-shadow: 0 0 8px var(--teal);
}

.t-swatch.arc {
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
}

.t-name {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  flex: 1;
}

.kbd-pill {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.32);
  color: var(--text-muted);
}

.turret-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  gap: 6px;
}

.t-cost {
  color: #fde68a;
  font-weight: 700;
}

.t-role {
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inspector-card {
  flex: 1;
  max-width: 560px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 13px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  backdrop-filter: blur(10px);
}

.inspector-copy {
  min-width: 0;
}

.inspector-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--cyan);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inspector-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inspector-btns {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}

.insp-btn {
  padding: 7px 11px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.85);
  color: var(--text-main);
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease, background 0.15s ease;
}

.insp-btn.upgrade:not(:disabled) {
  border-color: rgba(16, 185, 129, 0.65);
  background: rgba(6, 78, 59, 0.55);
  color: #a7f3d0;
}

.insp-btn.sell:not(:disabled) {
  border-color: rgba(245, 158, 11, 0.55);
  background: rgba(120, 53, 15, 0.45);
  color: #fde68a;
}

.insp-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

/* OVERLAYS: TITLE / PAUSE / END */
.screen-title,
.modal-backdrop {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 45%, rgba(8, 15, 28, 0.72), rgba(5, 8, 15, 0.9));
  backdrop-filter: blur(6px);
}

.title-layout {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: 1.25fr 0.95fr;
  gap: 18px;
  align-items: stretch;
}

.title-panel,
.tactics-panel,
.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.6);
}

.kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--cyan);
  margin-bottom: 10px;
}

.kicker-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 10px var(--emerald);
}

.hero-title {
  margin: 0 0 12px;
  line-height: 0.95;
  letter-spacing: -0.02em;
}

.hero-main {
  display: block;
  font-size: clamp(36px, 5vw, 54px);
  font-weight: 800;
  color: #f8fafc;
}

.hero-sub {
  display: block;
  font-size: clamp(24px, 3.2vw, 34px);
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--cyan);
}

.hero-desc {
  margin: 0 0 18px;
  font-size: 14px;
  line-height: 1.55;
  color: #cbd5e1;
}

.title-cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.btn-primary,
.btn-secondary,
.btn-ghost {
  border-radius: 9px;
  padding: 11px 18px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s ease, border-color 0.15s ease;
}

.btn-primary {
  border: 1px solid rgba(56, 189, 248, 0.75);
  background: linear-gradient(135deg, #0284c7, #0d9488);
  color: #f8fafc;
  box-shadow: 0 8px 24px rgba(14, 165, 233, 0.32);
}

.btn-secondary {
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: rgba(30, 41, 59, 0.85);
  color: var(--text-main);
}

.btn-ghost {
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: transparent;
  color: var(--text-muted);
}

.btn-primary:hover,
.btn-secondary:hover,
.btn-ghost:hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
}

.best-strip {
  display: flex;
  gap: 18px;
  font-size: 12px;
  color: var(--text-muted);
  padding-top: 12px;
  border-top: 1px solid rgba(148, 163, 184, 0.18);
}

.best-strip strong {
  color: var(--amber);
}

.tactics-panel {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
}

.tactics-head {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}

.tactic-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(148, 163, 184, 0.14);
}

.t-badge {
  font-size: 11px;
  font-weight: 700;
}

.t-badge.rail {
  color: var(--cyan);
}

.t-badge.cryo {
  color: var(--teal);
}

.t-badge.arc {
  color: var(--amber);
}

.t-badge.conduit {
  color: var(--emerald);
}

.t-badge.controls {
  color: #cbd5e1;
}

.t-note {
  font-size: 11px;
  color: var(--text-muted);
}

/* MODALS */
.modal-card {
  width: min(520px, 100%);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.modal-title {
  margin: 6px 0 4px;
  font-size: 24px;
  font-weight: 800;
}

.modal-sub {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.record-pill {
  font-size: 10px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.18);
  border: 1px solid rgba(245, 158, 11, 0.6);
  color: var(--amber);
}

.pause-controls-grid,
.end-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-bottom: 18px;
}

.pause-controls-grid > div,
.stat-box {
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.18);
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
}

.pause-controls-grid > div span:first-child,
.stat-k {
  color: var(--cyan);
  font-weight: 700;
  font-size: 10px;
}

.stat-v {
  font-size: 20px;
  font-weight: 700;
  color: #f8fafc;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

/* SUBTLE NON-INTRUSIVE PORTAL FOOTER */
.portal-footer {
  height: 24px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 11px;
  color: rgba(148, 163, 184, 0.65);
  background: rgba(5, 9, 16, 0.94);
  border-top: 1px solid rgba(56, 189, 248, 0.12);
  flex-shrink: 0;
}

.portal-footer a {
  color: rgba(125, 211, 252, 0.8);
  text-decoration: none;
}

.portal-footer a:hover {
  color: var(--cyan);
  text-decoration: underline;
}

.footer-sep {
  opacity: 0.4;
}

/* RESPONSIVE MOBILE LAYOUT (390x844 & narrow viewports) */
@media (max-width: 900px) {
  .title-layout {
    grid-template-columns: 1fr;
    max-height: 100%;
    overflow-y: auto;
  }

  .inspector-sub {
    display: none;
  }
}

@media (max-width: 768px) {
  #stage-root {
    display: flex;
    flex-direction: column;
  }

  #screen-hud {
    display: contents;
  }

  .hud-top-bar {
    order: 1;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 8px 6px;
    background: rgba(7, 11, 18, 0.94);
    border-bottom: 1px solid var(--border-subtle);
  }

  .hud-left {
    width: 100%;
    justify-content: space-between;
  }

  .hud-wave-card {
    flex: 1;
    min-width: 0;
    padding: 6px 9px;
  }

  .hud-salvage-card {
    min-width: 82px;
    padding: 6px 9px;
  }

  .hud-center-card {
    flex: 1 1 100%;
    min-width: 0;
    padding: 5px 9px;
    gap: 8px;
    justify-content: space-between;
  }

  .center-metrics {
    gap: 10px;
  }

  .metric-num {
    font-size: 13px;
  }

  .wave-btn {
    padding: 7px 10px;
    font-size: 10px;
    white-space: nowrap;
  }

  .hud-right {
    flex: 1 1 100%;
    justify-content: flex-end;
    gap: 6px;
  }

  .tool-btn {
    height: 32px;
    min-width: 34px;
    padding: 0 8px;
  }

  #canvas-wrap {
    order: 2;
    position: relative;
    inset: auto;
    flex: 1;
    min-height: 260px;
  }

  #hud-banner {
    position: absolute;
    top: 158px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 12;
    white-space: nowrap;
    font-size: 10px;
    padding: 4px 10px;
  }

  .hud-bottom-bar {
    order: 3;
    flex-direction: column;
    gap: 6px;
    padding: 6px 8px 8px;
    background: rgba(7, 11, 18, 0.94);
    border-top: 1px solid var(--border-subtle);
  }

  .turret-deck {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .turret-card {
    width: auto;
    padding: 7px 7px;
  }

  .t-name {
    font-size: 10px;
  }

  .kbd-pill {
    display: none;
  }

  .turret-meta {
    font-size: 10px;
  }

  .t-role {
    display: none;
  }

  .inspector-card {
    max-width: none;
    padding: 6px 9px;
  }

  .inspector-title {
    font-size: 11px;
  }

  .insp-btn {
    padding: 6px 9px;
    font-size: 10px;
  }

  .screen-title,
  .modal-backdrop {
    align-items: flex-start;
    overflow-y: auto;
    padding: 12px;
  }

  .title-panel,
  .tactics-panel,
  .modal-card {
    padding: 16px;
  }

  .hero-desc {
    font-size: 13px;
  }
}
