:root {
  --bg-deep: #050819;
  --bg-sky: #0d1436;
  --bg-panel: rgba(8, 12, 32, 0.94);
  --bg-card: rgba(15, 22, 54, 0.95);
  --border-cyan: rgba(56, 189, 248, 0.42);
  --border-gold: rgba(253, 224, 71, 0.4);
  --border-mint: rgba(52, 211, 153, 0.38);
  --text-main: #f8fafc;
  --text-muted: #9eb3d6;
  --cyan: #38bdf8;
  --mint: #34d399;
  --amber: #fbbf24;
  --gold: #fde047;
  --rose: #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% 10%, #1d154a 0%, #050819 82%);
  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-rose { color: var(--rose); }

#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(5, 8, 25, 0.96);
  border-bottom: 1px solid var(--border-cyan);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.52);
  min-width: 0;
  flex-wrap: wrap;
}

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

.brand-icon {
  flex-shrink: 0;
  border-radius: 7px;
  box-shadow: 0 0 12px rgba(253, 224, 71, 0.35);
}

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

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

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

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

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

.tele-box,
.tele-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  background: rgba(13, 20, 48, 0.9);
  border: 1px solid rgba(56, 189, 248, 0.28);
  border-radius: 8px;
  padding: 3px 8px;
  min-width: 0;
}

.tele-k {
  font-size: 0.56rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  line-height: 1.1;
}

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

.meter-box {
  width: 112px;
  background: rgba(13, 20, 48, 0.9);
  border: 1px solid rgba(56, 189, 248, 0.28);
  border-radius: 8px;
  padding: 3px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

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

.bar-track {
  width: 100%;
  height: 5px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.18);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  transition: width 0.12s linear;
}

.bar-mint {
  background: linear-gradient(90deg, #34d399, #fde047);
}

.bar-cyan {
  background: linear-gradient(90deg, #38bdf8, #fde047);
}

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

.hdr-btn,
.hdr-link {
  border: 1px solid rgba(56, 189, 248, 0.36);
  background: rgba(14, 24, 54, 0.95);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 5px 9px;
  border-radius: 7px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.hdr-btn:hover,
.hdr-link:hover {
  border-color: var(--gold);
  color: var(--gold);
}

/* ================= STAGE & CANVAS ================= */
#arena-stage {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
  display: flex;
  overflow: hidden;
}

#canvas-wrap {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
}

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

.toast-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 18;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(8, 12, 32, 0.92);
  border: 1px solid var(--border-gold);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  font-size: 0.74rem;
  pointer-events: none;
  max-width: calc(100% - 24px);
}

.toast-badge {
  color: #091129;
  background: var(--gold);
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.66rem;
  white-space: nowrap;
}

.toast-msg {
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ================= OVERLAYS ================= */
.overlay-screen {
  position: absolute;
  inset: 0;
  z-index: 22;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(4, 7, 20, 0.74);
  backdrop-filter: blur(5px);
  overflow-y: auto;
}

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

.compact-card {
  max-width: 460px;
  text-align: center;
  align-items: center;
}

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

.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.chip-cyan {
  background: rgba(56, 189, 248, 0.16);
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: var(--cyan);
}

.chip-mint {
  background: rgba(52, 211, 153, 0.16);
  border: 1px solid rgba(52, 211, 153, 0.45);
  color: var(--mint);
}

.chip-amber {
  background: rgba(251, 191, 36, 0.16);
  border: 1px solid rgba(251, 191, 36, 0.45);
  color: var(--gold);
}

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

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

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

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

.stat-pill {
  background: var(--bg-card);
  border: 1px solid rgba(56, 189, 248, 0.26);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.stat-k {
  font-size: 0.62rem;
  color: var(--text-muted);
}

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

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

.mech-card {
  background: var(--bg-card);
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 10px;
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  font-size: 0.74rem;
  color: var(--text-muted);
}

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

.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;
  min-width: 0;
}

.upg-item {
  background: var(--bg-card);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 7px;
  min-width: 0;
}

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

.upg-name {
  font-weight: 800;
  font-size: 0.86rem;
  color: var(--text-main);
}

.upg-lv {
  font-size: 0.68rem;
  color: var(--mint);
  font-weight: 800;
}

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

.upg-btn {
  border: 1px solid rgba(253, 224, 71, 0.45);
  background: rgba(253, 224, 71, 0.14);
  color: var(--gold);
  border-radius: 8px;
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 800;
  cursor: pointer;
}

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

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

.btn-primary-lg,
.btn-secondary-lg {
  flex: 1 1 200px;
  border-radius: 10px;
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  border: none;
  transition: transform 0.12s ease;
}

.btn-primary-lg {
  background: linear-gradient(135deg, #fde047, #38bdf8);
  color: #061028;
  box-shadow: 0 8px 20px rgba(56, 189, 248, 0.28);
}

.btn-secondary-lg {
  background: rgba(15, 25, 56, 0.96);
  color: var(--text-main);
  border: 1px solid rgba(56, 189, 248, 0.45);
}

.btn-primary-lg:hover,
.btn-secondary-lg:hover {
  transform: translateY(-1px);
}

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

/* ================= FOOTERS ================= */
.desktop-controls-bar {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
  padding: 5px 12px;
  background: rgba(5, 8, 25, 0.96);
  border-top: 1px solid rgba(56, 189, 248, 0.24);
  font-size: 0.68rem;
  color: var(--text-muted);
}

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

.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(5, 8, 25, 0.98);
  border-top: 1px solid var(--border-cyan);
  min-width: 0;
}

.touch-move {
  display: flex;
  gap: 6px;
}

.touch-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  flex: 1 1 auto;
  max-width: 245px;
  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-lr {
  width: 48px;
  height: 44px;
  font-size: 0.96rem;
}

.touch-jump,
.touch-hook,
.touch-spark {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  font-size: 0.72rem;
  line-height: 1.1;
}

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

.touch-spark {
  border-color: var(--gold);
  background: rgba(253, 224, 71, 0.18);
  color: var(--gold);
}

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

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

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

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

  .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.73rem;
  }
}

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

@media (max-width: 580px) {
  .hide-sm {
    display: none;
  }
  .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: 5px;
  }
  .meter-box {
    width: 84px;
    padding: 3px 6px;
  }
  .brand-title {
    font-size: 0.82rem;
  }
  .title-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }
  .stat-v {
    font-size: 0.84rem;
  }
}
