:root {
  --bg-space: #070b1a;
  --bg-indigo: #111836;
  --bg-panel: rgba(9, 15, 34, 0.92);
  --bg-card: rgba(14, 22, 48, 0.96);
  --border-mint: rgba(52, 211, 153, 0.35);
  --border-strong: rgba(56, 189, 248, 0.65);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --mint: #34d399;
  --cyan: #38bdf8;
  --amber: #fbbf24;
  --violet: #c084fc;
  --pink: #f472b6;
  --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% 20%, #17234d 0%, #070b1a 78%);
  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-mint { color: var(--mint); }
.accent-cyan { color: var(--cyan); }
.accent-amber { color: var(--amber); }
.accent-violet { color: var(--violet); }
.accent-pink { color: var(--pink); }

#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(7, 11, 26, 0.96);
  border-bottom: 1px solid var(--border-mint);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  min-width: 0;
}

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

.brand-icon {
  flex-shrink: 0;
  border-radius: 7px;
}

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

.brand-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  line-height: 1.05;
  white-space: nowrap;
}

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

.brand-city {
  font-size: 0.64rem;
  color: var(--amber);
  letter-spacing: 0.07em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.trust-box {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 112px;
}

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

.trust-pct {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--mint);
}

.trust-track {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(52, 211, 153, 0.35);
  overflow: hidden;
}

.trust-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #38bdf8, #34d399, #fde047);
  transition: width 120ms ease;
}

.tele-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.1;
  min-width: 0;
}

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

.tele-v {
  font-size: 0.8rem;
  font-weight: 800;
}

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

.hdr-btn,
.hdr-link {
  padding: 5px 8px;
  border-radius: 7px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(15, 23, 42, 0.88);
  color: var(--text-main);
  font-size: 0.66rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 140ms ease, background 140ms ease;
}

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

.hdr-link-accent {
  border-color: rgba(251, 191, 36, 0.45);
  color: #fde68a;
}

.hdr-btn.is-muted {
  color: #fca5a5;
  border-color: rgba(244, 114, 182, 0.45);
}

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

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

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

/* ================= STATUS BANNER & BEAM DOCK ================= */
.status-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(12, 18, 42, 0.92);
  border: 1px solid rgba(244, 114, 182, 0.65);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
  max-width: calc(100% - 20px);
  pointer-events: none;
}

.banner-badge {
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 800;
  background: rgba(244, 114, 182, 0.25);
  color: #fbcfe8;
}

.banner-msg {
  font-size: 0.72rem;
  font-weight: 700;
  color: #fef08a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.beam-dock {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  z-index: 15;
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 6px;
  border-radius: 12px;
  background: rgba(7, 11, 26, 0.88);
  border: 1px solid rgba(148, 163, 184, 0.26);
  backdrop-filter: blur(8px);
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.24);
  background: rgba(15, 23, 42, 0.85);
  color: var(--text-main);
  cursor: pointer;
  text-align: left;
  min-width: 0;
  transition: transform 110ms ease, border-color 140ms ease, background 140ms ease;
}

.mode-btn:hover {
  transform: translateY(-1px);
}

.mode-key {
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.62rem;
  font-weight: 800;
  background: rgba(30, 41, 59, 0.95);
  color: #cbd5e1;
  white-space: nowrap;
}

.mode-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.mode-name {
  font-size: 0.7rem;
  font-weight: 800;
  white-space: nowrap;
}

.mode-sub {
  font-size: 0.58rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.mode-gift.is-active {
  border-color: var(--mint);
  background: rgba(52, 211, 153, 0.16);
}

.mode-bubble.is-active {
  border-color: var(--violet);
  background: rgba(192, 132, 252, 0.18);
}

.mode-calm.is-active {
  border-color: var(--cyan);
  background: rgba(56, 189, 248, 0.16);
}

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

.overlay-card {
  width: 100%;
  max-width: 720px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 20px 22px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.65);
  min-width: 0;
}

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

.eyebrow-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

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

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

.chip-amber {
  background: rgba(251, 191, 36, 0.16);
  color: #fde68a;
  border: 1px solid rgba(251, 191, 36, 0.42);
}

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

.chip-violet {
  background: rgba(192, 132, 252, 0.18);
  color: #e9d5ff;
  border: 1px solid rgba(192, 132, 252, 0.42);
}

.hero-title {
  margin: 0 0 8px;
  font-size: 1.65rem;
  font-weight: 900;
  letter-spacing: 0.03em;
  line-height: 1.1;
}

.modal-title {
  margin: 8px 0 6px;
  font-size: 1.35rem;
  font-weight: 800;
}

.hero-copy,
.modal-sub {
  margin: 0 0 12px;
  font-size: 0.86rem;
  color: #cbd5e1;
  line-height: 1.45;
}

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

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

.stat-pill {
  background: rgba(9, 14, 30, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 10px;
  padding: 7px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

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

.stat-v {
  font-size: 0.9rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.mech-card {
  background: rgba(9, 14, 30, 0.88);
  border: 1px solid rgba(56, 189, 248, 0.24);
  border-radius: 10px;
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.75rem;
  color: #cbd5e1;
  min-width: 0;
}

.mech-key {
  font-size: 0.62rem;
  color: var(--amber);
  font-weight: 700;
}

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

.upg-item {
  background: rgba(9, 14, 30, 0.9);
  border: 1px solid rgba(52, 211, 153, 0.28);
  border-radius: 11px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

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

.upg-name {
  font-size: 0.84rem;
  font-weight: 800;
  color: #f8fafc;
}

.upg-lv {
  font-size: 0.66rem;
  color: var(--cyan);
  font-weight: 700;
}

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

.upg-buy {
  margin-top: auto;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(52, 211, 153, 0.55);
  background: rgba(52, 211, 153, 0.16);
  color: #a7f3d0;
  font-weight: 800;
  font-size: 0.72rem;
  cursor: pointer;
}

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

.cta-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-primary-lg,
.btn-secondary-lg {
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  border: none;
  cursor: pointer;
  transition: transform 110ms ease, filter 130ms ease;
}

.btn-primary-lg {
  background: linear-gradient(135deg, #34d399, #38bdf8);
  color: #04131c;
}

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

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

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

/* ================= FOOTER CONTROLS & MOBILE DOCK ================= */
.desktop-controls-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 5px 12px;
  background: rgba(7, 11, 26, 0.96);
  border-top: 1px solid rgba(148, 163, 184, 0.18);
  font-size: 0.68rem;
  color: var(--text-muted);
}

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

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

.touch-dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.dpad-mid {
  display: flex;
  gap: 3px;
}

.touch-btn {
  border-radius: 9px;
  border: 1px solid rgba(56, 189, 248, 0.38);
  background: rgba(15, 23, 42, 0.95);
  color: var(--text-main);
  font-weight: 800;
  font-size: 0.72rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: none;
}

.dpad-up,
.dpad-down,
.dpad-lr {
  width: 38px;
  height: 32px;
}

.touch-modes {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.touch-mode-btn {
  padding: 5px 8px;
  border-radius: 7px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(15, 23, 42, 0.9);
  color: #cbd5e1;
  font-size: 0.64rem;
  font-weight: 800;
  cursor: pointer;
}

.touch-mode-btn.is-active {
  border-color: var(--mint);
  background: rgba(52, 211, 153, 0.2);
  color: #ecfdf5;
}

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

.touch-beam,
.touch-parry {
  min-width: 60px;
  height: 68px;
  padding: 0 7px;
}

.touch-beam {
  border-color: rgba(52, 211, 153, 0.65);
  background: rgba(52, 211, 153, 0.18);
  color: #a7f3d0;
}

.touch-parry {
  border-color: rgba(192, 132, 252, 0.65);
  background: rgba(192, 132, 252, 0.18);
  color: #f3e8ff;
}

.touch-sub {
  font-size: 0.52rem;
  opacity: 0.86;
  margin-top: 2px;
}

/* ================= RESPONSIVE VIEWPORTS (630x500 & 390x844) ================= */
@media (max-width: 820px), (pointer: coarse) {
  .beam-dock {
    display: none;
  }
  .desktop-controls-bar {
    display: none;
  }
  .touch-dock {
    display: flex;
  }
}

@media (max-width: 720px) {
  .top-bar {
    padding: 5px 8px;
    gap: 6px;
    flex-wrap: wrap;
  }
  .hide-sm {
    display: none;
  }
  .hud-telemetry {
    gap: 8px;
  }
  .trust-box {
    min-width: 90px;
  }
  .hdr-btn,
  .hdr-link {
    padding: 4px 6px;
    font-size: 0.6rem;
  }
  .title-stats,
  .mechanics-trio,
  .upgrade-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .debrief-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-height: 540px) {
  .top-bar {
    padding: 4px 8px;
    gap: 6px;
  }
  .brand-city {
    display: none;
  }
  .hide-sm {
    display: none;
  }
  .overlay-screen {
    align-items: flex-start;
    padding: 8px;
  }
  .overlay-card {
    padding: 11px 14px;
  }
  .eyebrow-row {
    margin-bottom: 5px;
  }
  .hero-title {
    font-size: 1.18rem;
    margin-bottom: 4px;
  }
  .hero-copy {
    font-size: 0.74rem;
    margin-bottom: 7px;
    line-height: 1.35;
  }
  .title-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: 7px;
    gap: 6px;
  }
  .stat-pill {
    padding: 4px 7px;
  }
  .mechanics-trio {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: 8px;
    gap: 6px;
  }
  .mech-card {
    padding: 6px 8px;
    font-size: 0.68rem;
  }
  .btn-primary-lg,
  .btn-secondary-lg {
    padding: 7px 14px;
    font-size: 0.76rem;
  }
  .tiny-hint {
    margin-top: 6px;
    font-size: 0.58rem;
  }
  .touch-dock {
    display: none;
  }
  .beam-dock {
    display: flex;
    bottom: 6px;
    padding: 4px;
    gap: 5px;
  }
  .mode-btn {
    padding: 4px 7px;
  }
  .mode-sub {
    display: none;
  }
}

@media (max-width: 440px) {
  .hide-xs {
    display: none;
  }
  .brand-title {
    font-size: 0.8rem;
  }
  .header-actions {
    width: 100%;
    justify-content: space-between;
  }
  .overlay-screen {
    align-items: flex-start;
    padding: 8px;
  }
  .overlay-card {
    padding: 12px;
  }
  .hero-title {
    font-size: 1.24rem;
  }
  .title-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
