:root {
  --bg-deep: #040714;
  --bg-sky: #0b1431;
  --bg-panel: rgba(6, 10, 26, 0.94);
  --bg-card: rgba(13, 21, 48, 0.95);
  --border-cyan: rgba(56, 189, 248, 0.42);
  --border-amber: rgba(251, 191, 36, 0.44);
  --border-mint: rgba(52, 211, 153, 0.4);
  --text-main: #f8fafc;
  --text-muted: #9eb3d6;
  --cyan: #38bdf8;
  --mint: #34d399;
  --amber: #fbbf24;
  --gold: #fde047;
  --coral: #fb7185;
  --font-sans: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, 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% 12%, #131f47 0%, #040714 84%);
  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);
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

.accent-gold { color: var(--gold); }
.accent-amber { color: var(--amber); }
.accent-cyan { color: var(--cyan); }
.accent-mint { color: var(--mint); }
.accent-coral { color: var(--coral); }

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

/* ================= TOP TELEMETRY BAR ================= */
.top-bar {
  flex-shrink: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(4, 7, 20, 0.96);
  border-bottom: 1px solid var(--border-cyan);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
  min-width: 0;
  flex-wrap: wrap;
}

.brand-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand-icon {
  flex-shrink: 0;
  border-radius: 7px;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.35);
}

.brand-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.1;
  white-space: nowrap;
}

.title-accent {
  color: var(--amber);
}

.brand-sub {
  font-size: 0.64rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.tele-box,
.tele-cell,
.meter-box {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 3px 8px;
  border-radius: 7px;
  background: rgba(11, 20, 48, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.22);
  min-width: 0;
}

.tele-box.urgent-flash {
  border-color: rgba(251, 113, 133, 0.88);
  background: rgba(127, 29, 29, 0.48);
}

.meter-box {
  width: 102px;
  gap: 3px;
}

.meter-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
}

.tele-k {
  font-size: 0.55rem;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 700;
  white-space: nowrap;
}

.tele-v {
  font-size: 0.76rem;
  font-weight: 800;
  line-height: 1.1;
  white-space: nowrap;
}

.meter-prog {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  border: 0;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.2);
  overflow: hidden;
  display: block;
}

.meter-prog::-webkit-progress-bar {
  background: rgba(148, 163, 184, 0.2);
  border-radius: 999px;
}

.meter-mint::-webkit-progress-value {
  background: linear-gradient(90deg, #10b981, #34d399);
  border-radius: 999px;
}

.meter-cyan::-webkit-progress-value {
  background: linear-gradient(90deg, #0284c7, #38bdf8);
  border-radius: 999px;
}

.meter-mint::-moz-progress-bar {
  background: linear-gradient(90deg, #10b981, #34d399);
  border-radius: 999px;
}

.meter-cyan::-moz-progress-bar {
  background: linear-gradient(90deg, #0284c7, #38bdf8);
  border-radius: 999px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hdr-btn,
.hdr-link {
  border: 1px solid rgba(56, 189, 248, 0.36);
  background: rgba(13, 22, 48, 0.92);
  color: var(--text-main);
  border-radius: 7px;
  padding: 5px 8px;
  font-family: inherit;
  font-size: 0.66rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.hdr-btn:hover,
.hdr-link:hover {
  border-color: var(--cyan);
  background: rgba(24, 38, 82, 0.96);
}

.hdr-btn.is-muted {
  border-color: rgba(251, 113, 133, 0.6);
  color: var(--coral);
}

/* ================= STAGE & CANVAS ================= */
#arena-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#canvas-wrap {
  position: relative;
  width: 100%;
  height: 100%;
}

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

.toast-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(6, 11, 30, 0.94);
  border: 1px solid var(--border-amber);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  font-size: 0.72rem;
  white-space: nowrap;
  pointer-events: none;
  max-width: calc(100% - 20px);
}

.toast-badge {
  color: #061028;
  background: var(--amber);
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.62rem;
}

.toast-msg {
  color: var(--text-main);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ================= OVERLAY SCREENS ================= */
.overlay-screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  background: rgba(3, 6, 18, 0.78);
  backdrop-filter: blur(5px);
}

.overlay-card {
  width: min(760px, 100%);
  max-height: calc(100% - 8px);
  overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border-cyan);
  border-radius: 16px;
  padding: 16px 20px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.68);
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.compact-card {
  width: min(460px, 100%);
  text-align: center;
  align-items: center;
}

.eyebrow-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  font-size: 0.63rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.chip-amber {
  color: var(--amber);
  background: rgba(251, 191, 36, 0.14);
  border-color: rgba(251, 191, 36, 0.42);
}

.chip-cyan {
  color: var(--cyan);
  background: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.42);
}

.chip-mint {
  color: var(--mint);
  background: rgba(52, 211, 153, 0.14);
  border-color: rgba(52, 211, 153, 0.42);
}

.hero-title,
.modal-title {
  margin: 0;
  font-size: 1.48rem;
  font-weight: 900;
  letter-spacing: 0.02em;
  line-height: 1.15;
}

.hero-copy,
.modal-sub {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.hero-copy strong {
  color: var(--text-main);
}

.title-stats,
.debrief-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.debrief-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-pill {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(13, 21, 50, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.22);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-k {
  font-size: 0.58rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
}

.stat-v {
  font-size: 1.04rem;
  font-weight: 800;
}

.mechanics-trio {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.mech-card {
  padding: 10px 11px;
  border-radius: 10px;
  background: rgba(10, 17, 42, 0.92);
  border: 1px solid rgba(56, 189, 248, 0.24);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.74rem;
  color: var(--text-muted);
}

.mech-tag {
  font-size: 0.58rem;
  color: var(--cyan);
  font-weight: 700;
}

.mech-card strong {
  color: var(--text-main);
  font-size: 0.82rem;
}

.upgrade-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.upg-btn {
  text-align: left;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid var(--border-cyan);
  background: rgba(13, 22, 52, 0.94);
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: inherit;
  transition: border-color 0.14s ease, transform 0.12s ease;
}

.upg-btn:hover:not(:disabled) {
  border-color: var(--amber);
  transform: translateY(-1px);
}

.upg-btn:disabled {
  opacity: 0.52;
  cursor: not-allowed;
}

.upg-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 0.84rem;
}

.upg-cost {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--gold);
}

.upg-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.upg-lvl {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  color: var(--mint);
}

.cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
}

.btn-primary-lg,
.btn-secondary-lg {
  flex: 1 1 200px;
  padding: 11px 16px;
  border-radius: 11px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-primary-lg {
  background: linear-gradient(135deg, #38bdf8, #34d399);
  color: #031120;
  box-shadow: 0 8px 24px rgba(56, 189, 248, 0.34);
}

.btn-primary-lg:hover {
  filter: brightness(1.06);
}

.btn-secondary-lg {
  background: rgba(15, 24, 56, 0.96);
  color: var(--amber);
  border-color: rgba(251, 191, 36, 0.5);
}

.btn-secondary-lg:hover {
  border-color: var(--amber);
  background: rgba(24, 36, 76, 0.96);
}

.tiny-hint {
  margin: 0;
  text-align: center;
  font-size: 0.65rem;
  color: var(--text-muted);
}

/* ================= CONTROLS BARS ================= */
.desktop-controls-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
  padding: 6px 12px;
  background: rgba(4, 7, 20, 0.97);
  border-top: 1px solid rgba(56, 189, 248, 0.25);
  font-size: 0.67rem;
  color: var(--text-muted);
}

.desktop-controls-bar strong {
  color: var(--amber);
}

.touch-dock {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
  background: rgba(4, 7, 20, 0.98);
  border-top: 1px solid var(--border-cyan);
  min-width: 0;
}

.touch-pad {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.touch-ud {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.touch-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  flex: 1 1 auto;
  max-width: 224px;
  min-width: 0;
}

.touch-btn {
  border: 1px solid rgba(56, 189, 248, 0.42);
  background: rgba(14, 24, 54, 0.95);
  color: var(--text-main);
  font-family: inherit;
  font-weight: 800;
  border-radius: 9px;
  cursor: pointer;
  touch-action: manipulation;
}

.touch-btn.is-active {
  transform: scale(0.96);
  filter: brightness(1.18);
}

.touch-dir {
  width: 40px;
  height: 46px;
  font-size: 0.9rem;
}

.touch-dir-sm {
  width: 40px;
  height: 22px;
  font-size: 0.72rem;
  line-height: 1;
  padding: 0;
}

.touch-lock,
.touch-pulse,
.touch-rewind {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 7px 4px;
  font-size: 0.68rem;
  line-height: 1.1;
}

.touch-lock {
  border-color: var(--cyan);
  background: rgba(56, 189, 248, 0.2);
}

.touch-pulse {
  border-color: var(--mint);
  background: rgba(52, 211, 153, 0.18);
}

.touch-rewind {
  border-color: var(--amber);
  background: rgba(251, 191, 36, 0.18);
  color: var(--amber);
}

.touch-sub {
  font-size: 0.5rem;
  color: var(--text-muted);
}

/* ================= RESPONSIVE BREAKPOINTS ================= */
@media (max-height: 560px), (max-width: 720px) {
  .top-bar {
    padding: 4px 10px;
    gap: 5px;
  }

  .overlay-card {
    padding: 10px 14px;
    gap: 8px;
  }

  .hero-title,
  .modal-title {
    font-size: 1.12rem;
  }

  .hero-copy,
  .modal-sub {
    font-size: 0.75rem;
    line-height: 1.32;
  }

  .mechanics-trio,
  .tiny-hint {
    display: none;
  }

  .stat-pill {
    padding: 5px 8px;
  }

  .stat-v {
    font-size: 0.88rem;
  }

  .btn-primary-lg,
  .btn-secondary-lg {
    padding: 8px 10px;
    font-size: 0.72rem;
  }
}

@media (max-width: 860px) {
  .meter-box {
    width: 92px;
  }
}

@media (max-width: 660px) {
  .hide-sm {
    display: none;
  }
}

@media (max-width: 580px) {
  .desktop-controls-bar {
    display: none;
  }
  .touch-dock {
    display: flex;
  }
  .upgrade-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 460px) {
  .hide-xs {
    display: none;
  }
  .top-bar {
    padding: 5px 8px;
    gap: 5px;
  }
  .hud-telemetry {
    gap: 4px;
  }
  .meter-box {
    width: 78px;
    padding: 3px 6px;
  }
  .tele-box,
  .tele-cell {
    padding: 3px 6px;
  }
  .brand-title {
    font-size: 0.8rem;
  }
  .hdr-link {
    display: none;
  }
  .title-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }
  .stat-v {
    font-size: 0.82rem;
  }
}
