:root {
  --bg-night: #080d1e;
  --bg-sky: #111938;
  --bg-panel: rgba(11, 17, 38, 0.93);
  --bg-card: rgba(16, 25, 52, 0.96);
  --border-gold: rgba(251, 191, 36, 0.35);
  --border-teal: rgba(45, 212, 191, 0.45);
  --text-main: #fefce8;
  --text-muted: #a5b4cf;
  --gold: #fbbf24;
  --amber: #fb923c;
  --teal: #2dd4bf;
  --mint: #34d399;
  --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% 18%, #1a244f 0%, #080d1e 76%);
  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-teal { color: var(--teal); }
.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(8, 13, 30, 0.96);
  border-bottom: 1px solid var(--border-gold);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  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;
  border: 1px solid var(--border-gold);
}

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

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

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

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

.hud-telemetry {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1 1 auto;
  justify-content: center;
}

.clock-box,
.tele-cell {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 3px 8px;
  border-radius: 8px;
  background: rgba(16, 25, 52, 0.85);
  border: 1px solid rgba(251, 191, 36, 0.22);
  min-width: 0;
}

.clock-box.is-urgent {
  border-color: rgba(251, 113, 133, 0.75);
  background: rgba(80, 18, 36, 0.75);
}

.lantern-box {
  min-width: 112px;
  max-width: 165px;
  flex: 0 1 140px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 3px 8px;
  border-radius: 8px;
  background: rgba(16, 25, 52, 0.85);
  border: 1px solid rgba(45, 212, 191, 0.28);
}

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

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

.lantern-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #fb923c, #fbbf24, #2dd4bf);
  transition: width 0.2s ease-out;
}

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

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

.header-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  min-width: 0;
  max-width: 100%;
}

.hdr-btn,
.hdr-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 8px;
  border-radius: 7px;
  font-family: var(--font-mono);
  font-size: 0.69rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid rgba(165, 180, 207, 0.28);
  background: rgba(16, 25, 52, 0.92);
  color: var(--text-main);
  white-space: nowrap;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

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

.hdr-chaos.is-on {
  background: linear-gradient(135deg, rgba(251, 113, 133, 0.35), rgba(251, 146, 60, 0.35));
  border-color: var(--rose);
  color: #ffe4e6;
}

.hdr-link-accent {
  border-color: rgba(251, 191, 36, 0.55);
  color: var(--gold);
  background: rgba(251, 191, 36, 0.12);
}

/* ================= ARENA STAGE ================= */
#arena-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 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;
}

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

.toast-badge {
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(45, 212, 191, 0.22);
  color: var(--teal);
  font-weight: 800;
  flex-shrink: 0;
}

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

/* ================= OVERLAYS ================= */
.overlay-screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(6, 10, 24, 0.76);
  backdrop-filter: blur(6px);
  overflow-y: auto;
  min-width: 0;
}

.overlay-card {
  width: 100%;
  max-width: 790px;
  min-width: 0;
  max-height: 100%;
  overflow-y: auto;
  padding: 20px 22px;
  border-radius: 16px;
  background: linear-gradient(165deg, rgba(19, 28, 60, 0.97), rgba(10, 15, 34, 0.98));
  border: 1px solid rgba(251, 191, 36, 0.42);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

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

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

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

.chip-teal {
  background: rgba(45, 212, 191, 0.15);
  border: 1px solid rgba(45, 212, 191, 0.45);
  color: var(--teal);
}

.chip-rose {
  background: rgba(251, 113, 133, 0.15);
  border: 1px solid rgba(251, 113, 133, 0.45);
  color: #fecdd3;
}

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

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

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

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

.stat-pill {
  min-width: 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(8, 13, 30, 0.72);
  border: 1px solid rgba(165, 180, 207, 0.18);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

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

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

.mod-card {
  min-width: 0;
  padding: 10px 11px;
  border-radius: 11px;
  background: rgba(9, 15, 34, 0.85);
  border: 1px solid rgba(45, 212, 191, 0.25);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

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

.mod-tag {
  font-size: 0.62rem;
  font-weight: 800;
  color: var(--gold);
}

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

.upg-btn {
  min-width: 0;
  text-align: left;
  padding: 11px 12px;
  border-radius: 11px;
  background: rgba(11, 18, 40, 0.95);
  border: 1px solid rgba(251, 191, 36, 0.35);
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.upg-btn:hover:not(:disabled) {
  border-color: var(--teal);
  background: rgba(20, 34, 70, 0.96);
  transform: translateY(-1px);
}

.upg-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.upg-btn.is-maxed {
  border-color: rgba(52, 211, 153, 0.55);
}

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

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

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

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

.btn-primary-lg,
.btn-secondary-lg {
  padding: 10px 18px;
  border-radius: 10px;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.btn-primary-lg {
  background: linear-gradient(135deg, #fbbf24, #f97316);
  color: #1c0f02;
  box-shadow: 0 6px 20px rgba(249, 115, 22, 0.35);
}

.btn-secondary-lg {
  background: rgba(45, 212, 191, 0.14);
  border-color: rgba(45, 212, 191, 0.55);
  color: #ccfbf1;
}

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

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

/* ================= FOOTER CONTROLS ================= */
.desktop-controls-bar {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  padding: 6px 12px;
  background: rgba(8, 13, 30, 0.96);
  border-top: 1px solid rgba(251, 191, 36, 0.22);
  font-size: 0.72rem;
  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: 10px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  background: rgba(8, 13, 30, 0.97);
  border-top: 1px solid rgba(251, 191, 36, 0.3);
}

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

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

.touch-btn {
  border: 1px solid rgba(251, 191, 36, 0.38);
  border-radius: 10px;
  background: rgba(16, 25, 52, 0.96);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.touch-btn:active,
.touch-btn.is-pressed {
  background: rgba(251, 191, 36, 0.28);
  border-color: var(--gold);
}

.dpad-up,
.dpad-down,
.dpad-lr {
  width: 42px;
  height: 36px;
  font-size: 0.9rem;
}

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

.touch-xray,
.touch-chaos {
  padding: 8px 12px;
  min-width: 82px;
  height: 54px;
  font-size: 0.78rem;
  gap: 2px;
}

.touch-xray {
  border-color: var(--teal);
  background: rgba(45, 212, 191, 0.16);
  color: #ccfbf1;
}

.touch-chaos.is-on {
  border-color: var(--rose);
  background: rgba(251, 113, 133, 0.25);
}

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

/* ================= RESPONSIVE COMPACTNESS (630x500 & 390x844) ================= */
@media (max-height: 580px) {
  .overlay-screen {
    align-items: center;
    padding: 6px;
  }

  .overlay-card {
    padding: 10px 13px;
    gap: 6px;
  }

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

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

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

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

  .mod-card {
    padding: 6px 8px;
    font-size: 0.68rem;
    gap: 2px;
  }

  .mod-card strong {
    font-size: 0.74rem;
  }

  .stat-pill {
    padding: 4px 7px;
  }

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

  .btn-primary-lg,
  .btn-secondary-lg {
    padding: 7px 12px;
    font-size: 0.73rem;
  }

  .tiny-hint {
    font-size: 0.62rem;
  }
}

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

@media (max-width: 580px) {
  .top-bar {
    padding: 5px 8px;
    gap: 5px;
  }

  .hud-telemetry {
    order: 3;
    flex-basis: 100%;
    justify-content: space-between;
    gap: 5px;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .hide-xs {
    display: none;
  }

  .desktop-controls-bar {
    display: none;
  }

  .touch-dock {
    display: flex;
  }

  .overlay-screen {
    align-items: flex-start;
    padding: 8px;
  }

  .overlay-card {
    padding: 13px;
    gap: 9px;
  }

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

  .title-stats,
  .modifiers-trio,
  .upgrade-grid,
  .debrief-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .hdr-btn,
  .hdr-link {
    padding: 4px 7px;
    font-size: 0.64rem;
  }
}
