:root {
  --bg-deep: #04070c;
  --bg-slate: #070b12;
  --panel-bg: rgba(11, 18, 30, 0.9);
  --panel-solid: #0f1726;
  --border-dim: rgba(148, 163, 184, 0.24);
  --border-bright: rgba(56, 189, 248, 0.45);
  --cryo: #38bdf8;
  --rail: #f59e0b;
  --arc: #10b981;
  --danger: #f43f5e;
  --ink: #f1f5f9;
  --muted: #94a3b8;
  --font-display: "Bahnschrift", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "Cascadia Mono", "Consolas", "SFMono-Regular", ui-monospace, monospace;
}

* {
  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-deep);
  color: var(--ink);
  font-family: var(--font-display);
}

#app-shell {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, #0e182b 0%, #04070c 100%);
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

#stage-root {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-slate);
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#flash-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: #38bdf8;
  transition: opacity 90ms ease-out;
  z-index: 4;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

.ui-screen {
  position: absolute;
  inset: 0;
  z-index: 10;
}

button {
  font-family: var(--font-display);
  cursor: pointer;
  border: 1px solid transparent;
  color: var(--ink);
  transition: transform 90ms ease-out, background-color 120ms ease, border-color 120ms ease;
}

button:active:not(:disabled) {
  transform: scale(0.97);
}

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

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--cryo);
  outline-offset: 2px;
}

/* HUD */
#screen-hud {
  pointer-events: none;
}

.hud-frame {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px 16px;
}

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

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

.hud-panel {
  pointer-events: auto;
  background: var(--panel-bg);
  border: 1px solid var(--border-dim);
  border-radius: 6px;
  padding: 7px 11px;
  backdrop-filter: blur(6px);
}

.hud-wave-panel {
  min-width: 245px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
}

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

.badge-cryo {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 3px;
  background: rgba(56, 189, 248, 0.16);
  color: var(--cryo);
  border: 1px solid rgba(56, 189, 248, 0.42);
}

.badge-arc {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 3px;
  background: rgba(16, 185, 129, 0.16);
  color: var(--arc);
  border: 1px solid rgba(16, 185, 129, 0.45);
}

.badge-danger {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 3px;
  background: rgba(244, 63, 94, 0.18);
  color: #fb7185;
  border: 1px solid rgba(244, 63, 94, 0.45);
}

.hud-wave-num {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

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

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

.bar-track {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: rgba(30, 41, 59, 0.9);
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.2);
}

.bar-fill {
  height: 100%;
  width: 100%;
  transition: width 120ms ease;
}

.core-fill {
  background: linear-gradient(90deg, #10b981, #38bdf8);
}

.hud-core-val {
  font-size: 12px;
  font-weight: 700;
  min-width: 54px;
  text-align: right;
}

.hud-salvage-panel {
  min-width: 118px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.salvage-val-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.salvage-hex {
  color: var(--rail);
  font-size: 16px;
}

.hud-cores-num {
  font-size: 20px;
  font-weight: 700;
  color: #fde68a;
}

.hud-center-panel {
  display: flex;
  align-items: center;
}

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

.score-block {
  display: flex;
  flex-direction: column;
}

.hud-score-num {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.1;
}

.synergy-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
}

.syn-tag {
  padding: 1px 6px;
  border-radius: 3px;
  background: rgba(15, 23, 42, 0.85);
}

.syn-tag.cryo {
  color: var(--rail);
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.syn-tag.arc {
  color: var(--arc);
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.wave-call-btn {
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: #e0f2fe;
  padding: 7px 10px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
}

.wave-call-btn:hover:not(:disabled) {
  background: rgba(56, 189, 248, 0.25);
}

.emp-btn {
  pointer-events: auto;
  min-width: 130px;
  background: var(--panel-bg);
  border: 1px solid var(--border-dim);
  border-radius: 6px;
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
}

.emp-btn.is-ready {
  border-color: var(--cryo);
  background: rgba(14, 34, 56, 0.92);
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.25);
}

.emp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.emp-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
}

.emp-track {
  width: 100%;
  height: 6px;
}

.emp-fill {
  background: linear-gradient(90deg, #38bdf8, #10b981);
}

.emp-pct {
  font-size: 11px;
  color: var(--cryo);
  font-weight: 700;
}

.hud-tool-group {
  pointer-events: auto;
  display: flex;
  align-items: stretch;
  gap: 5px;
}

.tool-btn {
  background: var(--panel-bg);
  border: 1px solid var(--border-dim);
  border-radius: 6px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tool-btn:hover {
  border-color: var(--cryo);
}

.tool-btn.is-fast {
  border-color: var(--rail);
  color: var(--rail);
}

.kbd-chip {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.35);
  color: var(--muted);
}

.hud-banner {
  align-self: center;
  background: rgba(8, 16, 30, 0.92);
  border: 1px solid rgba(56, 189, 248, 0.6);
  color: #e0f2fe;
  padding: 6px 16px;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

/* BOTTOM TACTICAL DECK */
.hud-bottom-bar {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 12px;
}

.turret-deck {
  pointer-events: auto;
  display: flex;
  gap: 8px;
}

.turret-card {
  width: 196px;
  background: var(--panel-bg);
  border: 1px solid var(--border-dim);
  border-radius: 6px;
  padding: 8px 11px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.turret-card.is-selected {
  border-color: var(--cryo);
  background: rgba(16, 28, 46, 0.96);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.18);
}

.turret-card-top {
  display: flex;
  align-items: center;
  gap: 7px;
}

.turret-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.turret-dot.cryo { background: var(--cryo); }
.turret-dot.rail { background: var(--rail); }
.turret-dot.arc { background: var(--arc); }

.turret-name {
  font-size: 12px;
  font-weight: 700;
  flex: 1;
}

.turret-card-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
}

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

.turret-role {
  color: var(--muted);
}

.hud-inspector-panel {
  pointer-events: auto;
  flex: 1;
  max-width: 620px;
  background: var(--panel-bg);
  border: 1px solid var(--border-dim);
  border-radius: 6px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.inspector-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--cryo);
}

.inspector-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.inspector-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.insp-btn {
  padding: 7px 10px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
}

.insp-btn.upgrade {
  background: rgba(16, 185, 129, 0.18);
  border-color: rgba(16, 185, 129, 0.5);
  color: #a7f3d0;
}

.insp-btn.salvage {
  background: rgba(244, 63, 94, 0.16);
  border-color: rgba(244, 63, 94, 0.45);
  color: #fecdd3;
}

/* TITLE & MODALS */
.screen-title {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  background: radial-gradient(circle at 50% 42%, rgba(7, 11, 18, 0.34), rgba(4, 7, 12, 0.72));
}

.title-grid {
  width: min(1040px, 100%);
  display: grid;
  grid-template-columns: 1.35fr 0.9fr;
  gap: 18px;
  align-items: stretch;
}

.title-card,
.briefing-card,
.modal-shell {
  background: rgba(11, 18, 30, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 8px;
  padding: 24px 26px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}

.title-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--cryo);
  letter-spacing: 0.06em;
}

.kicker-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cryo);
}

.game-title {
  margin: 10px 0 12px;
  line-height: 0.96;
}

.title-main {
  display: block;
  font-size: 46px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #f8fafc;
}

.title-sub {
  display: block;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--rail);
  margin-top: 4px;
}

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

.title-actions,
.modal-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-primary {
  background: var(--cryo);
  color: #04111d;
  font-weight: 800;
  padding: 10px 18px;
  border-radius: 5px;
  font-size: 14px;
}

.btn-secondary {
  background: rgba(245, 158, 11, 0.16);
  border-color: rgba(245, 158, 11, 0.55);
  color: #fde68a;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 5px;
  font-size: 14px;
}

.btn-ghost {
  background: rgba(30, 41, 59, 0.72);
  border-color: rgba(148, 163, 184, 0.35);
  color: var(--ink);
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 5px;
  font-size: 13px;
}

.title-records {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--muted);
}

.studio-links {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.studio-links a {
  color: var(--cryo);
  text-decoration: none;
}

.studio-links a:hover {
  text-decoration: underline;
}

.sep {
  color: var(--muted);
}

.briefing-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
}

.briefing-head {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.08em;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  padding-bottom: 8px;
}

.brief-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 5px;
  padding: 9px 11px;
}

.brief-k {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
}

.brief-k.cryo { color: var(--cryo); }
.brief-k.arc { color: var(--arc); }
.brief-k.warn { color: var(--rail); }

.brief-v {
  font-size: 11px;
  color: #cbd5e1;
}

.modal-backdrop {
  background: rgba(4, 7, 12, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.end-shell,
.pause-shell {
  width: min(640px, 100%);
}

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

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

.modal-subtitle {
  margin: 0 0 16px;
  color: #cbd5e1;
  font-size: 14px;
}

.pb-pill {
  font-size: 11px;
  font-weight: 700;
  background: rgba(245, 158, 11, 0.18);
  color: #fde68a;
  border: 1px solid rgba(245, 158, 11, 0.5);
  padding: 4px 8px;
  border-radius: 4px;
}

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

.end-stat {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 5px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.stat-v {
  font-size: 19px;
  font-weight: 700;
  color: var(--ink);
}

.settings-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 14px 0 18px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: rgba(15, 23, 42, 0.78);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 5px;
  padding: 10px 12px;
}

.setting-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.setting-name {
  font-size: 13px;
  font-weight: 700;
}

.setting-desc {
  font-size: 12px;
  color: var(--muted);
}

.setting-ctrl {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.setting-val {
  font-size: 12px;
  min-width: 38px;
  text-align: right;
}

.toggle-input {
  width: 18px;
  height: 18px;
  accent-color: var(--cryo);
}

@media (max-width: 960px) {
  .title-grid {
    grid-template-columns: 1fr;
  }
  .hud-center-panel {
    display: none;
  }
  .turret-card {
    width: 140px;
  }
  .end-stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 780px), (max-height: 560px) {
  .screen-title {
    padding: 16px;
    align-items: flex-end;
  }
  .briefing-card {
    display: none;
  }
  .title-card {
    padding: 18px 20px;
    background: rgba(11, 18, 30, 0.9);
  }
  .title-main {
    font-size: 32px;
  }
  .title-sub {
    font-size: 18px;
  }
  .title-lead {
    font-size: 12.5px;
    margin-bottom: 12px;
  }
  .title-records {
    margin-top: 10px;
    padding-top: 9px;
  }
}
