:root {
  --topbar-height: 57px;
  --ticker-height: 30px;
  --footer-height: 38px;
  --bx-blue: #1c6fe0;
  --bx-blue-dark: #0b2f66;
  --bx-blue-light: #cfe6ff;
  --bx-white: #f4f8ff;
  --bx-gold: #ffcf40;

  /* Epic neon palette -- glassy dark chrome with punchy neon accents.
     P1 = neon green/black, P2 = neon orange/black, global accents = neon
     pink/gray, brand/finish highlights = neon cyan. */
  --neon-green: #39ff88;
  --neon-green-soft: rgba(57, 255, 136, 0.35);
  --neon-orange: #ff8a1e;
  --neon-orange-soft: rgba(255, 138, 30, 0.35);
  --neon-pink: #ff2fd0;
  --neon-pink-soft: rgba(255, 47, 208, 0.35);
  --neon-cyan: #00e5ff;
  --neon-cyan-soft: rgba(0, 229, 255, 0.35);
  --neon-gray: #aab3c5;

  --glass-bg: rgba(16, 18, 26, 0.55);
  --glass-bg-strong: rgba(8, 9, 14, 0.72);
  --glass-border: rgba(255, 255, 255, 0.10);

  --panel-bg: rgba(16, 18, 26, 0.55);
  --panel-bg-2: rgba(255, 255, 255, 0.05);
  --text-main: #eef2ff;
  --text-dim: #9aa5c0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background:
    radial-gradient(circle at 12% 18%, rgba(57, 255, 136, 0.12), transparent 40%),
    radial-gradient(circle at 88% 22%, rgba(255, 138, 30, 0.12), transparent 40%),
    radial-gradient(circle at 50% 85%, rgba(255, 47, 208, 0.10), transparent 45%),
    #050609;
  color: var(--text-main);
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  overflow: hidden;
}

/* Fullscreen layout: #app is just a positioning root. The 3D scene fills the
   entire viewport edge-to-edge (`.center-stage`); every other piece of UI
  (topbar, player panels, HUD, launch button, finish banner)
   floats on top of it as a fixed-position glass overlay, so the scene always
   reads as the fullscreen centerpiece rather than being boxed into a grid
   column. */
#app { position: relative; width: 100vw; height: 100vh; overflow: hidden; }

#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 31;
  min-height: var(--topbar-height);
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: 0 6px 30px rgba(255, 47, 208, 0.12);
}
.brand { display: flex; align-items: baseline; gap: 8px; color: inherit; text-decoration: none; }
.brand-bx {
  font-size: 26px; font-weight: 900; letter-spacing: 1px;
  color: var(--neon-pink); text-shadow: 0 0 10px var(--neon-pink), 0 0 24px rgba(255, 47, 208, 0.5);
}
.brand-arena {
  font-size: 20px; font-weight: 800; letter-spacing: 3px;
  color: var(--neon-cyan); text-shadow: 0 0 8px rgba(0, 229, 255, 0.6);
}
.brand-sub { font-size: 11px; color: var(--text-dim); margin-left: 10px; }
.topbar-actions { display: flex; align-items: center; }

.mobile-menu-toggle { display: none; }

.ghost-btn {
  background: rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(8px);
  border: 1px solid var(--neon-cyan-soft);
  color: var(--text-main); padding: 6px 12px; border-radius: 20px;
  cursor: pointer; font-size: 12px; margin-left: 8px;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}
.ghost-btn:hover { border-color: var(--neon-cyan); box-shadow: 0 0 14px rgba(0, 229, 255, 0.45); }
.ghost-btn.active { color: #030a0d; background: var(--neon-cyan); border-color: var(--neon-cyan); }
#btn-record-battle.recording {
  color: #fff; background: #c81f3f; border-color: #ff5571;
  box-shadow: 0 0 16px rgba(255, 85, 113, 0.5);
}

#sponsor-ticker {
  position: fixed; top: var(--topbar-height); left: 0; right: 0; z-index: 30;
  height: var(--ticker-height); overflow: hidden; display: flex; align-items: center;
  color: #d8e6f7; background: rgba(4, 7, 13, 0.92);
  border-bottom: 1px solid rgba(0, 229, 255, 0.24);
  box-shadow: 0 5px 18px rgba(0, 229, 255, 0.08);
}
#sponsor-ticker::before, #sponsor-ticker::after {
  content: ""; position: absolute; top: 0; bottom: 0; z-index: 2; width: 54px; pointer-events: none;
}
#sponsor-ticker::before { left: 0; background: linear-gradient(90deg, #04070d, transparent); }
#sponsor-ticker::after { right: 0; background: linear-gradient(-90deg, #04070d, transparent); }
.sponsor-track { display: flex; width: max-content; will-change: transform; }
#sponsor-ticker.ready .sponsor-track { animation: sponsor-scroll 20s linear infinite; }
.sponsor-group { display: flex; align-items: center; flex: 0 0 auto; padding-right: 42px; }
.sponsor-item { display: inline-flex; align-items: center; white-space: nowrap; font-size: 11px; font-weight: 700; }
.sponsor-item::before { content: "/"; margin: 0 18px; color: var(--neon-pink); font-weight: 900; }
.sponsor-item a { color: #d8e6f7; text-decoration: none; }
.sponsor-item a:hover, .sponsor-item a:focus-visible { color: var(--neon-cyan); text-decoration: underline; outline: none; }
#sponsor-ticker:hover .sponsor-track, #sponsor-ticker:focus-within .sponsor-track { animation-play-state: paused; }
#sponsor-ticker.ticker-error { justify-content: center; color: var(--neon-orange); font-size: 11px; }
@keyframes sponsor-scroll { to { transform: translateX(-50%); } }

#site-footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 27;
  min-height: var(--footer-height); display: grid; place-items: center;
  padding: 7px 16px; background: rgba(4, 6, 11, 0.94);
  border-top: 1px solid rgba(255, 47, 208, 0.24); color: var(--text-dim);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.footer-inner { display: flex; align-items: center; justify-content: center; gap: 14px; font-size: 11px; text-align: center; }
.footer-inner strong { color: #fff; }
.footer-inner a { color: var(--neon-cyan); font-weight: 800; text-decoration: none; }
.footer-inner a::after { content: "  ›"; color: var(--neon-pink); }
.footer-inner .collaborator-link::after { content: none; }
.footer-inner a:hover, .footer-inner a:focus-visible { text-decoration: underline; outline: none; }

#sound-toggle {
  position: fixed; right: 12px; bottom: calc(var(--footer-height) + 12px); z-index: 28;
  width: 110px; min-height: 42px; padding: 8px 12px;
  color: #03130a; background: var(--neon-green); border: 1px solid var(--neon-green);
  border-radius: 6px; box-shadow: 0 0 18px rgba(57, 255, 136, 0.3);
  font-size: 11px; font-weight: 900; text-transform: uppercase; cursor: pointer;
}
#sound-toggle::before { content: "♪"; margin-right: 6px; font-size: 15px; }
#sound-toggle.muted {
  color: #fff; background: rgba(5, 8, 15, 0.92); border-color: var(--neon-orange);
  box-shadow: 0 0 14px rgba(255, 138, 30, 0.2);
}
#sound-toggle:focus-visible { outline: 2px solid var(--neon-cyan); outline-offset: 2px; }
#sound-toggle:disabled { opacity: 0.5; cursor: not-allowed; }

#simulation-speed {
  position: fixed; left: 12px; bottom: calc(var(--footer-height) + 12px); z-index: 28;
  width: 110px; min-height: 42px; padding: 8px 12px;
  color: #031014; background: var(--neon-cyan); border: 1px solid #b9f8ff;
  border-radius: 6px; box-shadow: 0 0 18px rgba(0, 229, 255, 0.28);
  font-size: 11px; font-weight: 900; text-transform: uppercase; cursor: pointer;
}
#simulation-speed:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

#statistics-view {
  position: fixed;
  inset: calc(var(--topbar-height) + var(--ticker-height)) 0 var(--footer-height);
  z-index: 29; overflow: auto;
  background:
    linear-gradient(rgba(0, 229, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 229, 255, 0.025) 1px, transparent 1px),
    #06080d;
  background-size: 34px 34px;
}
.statistics-shell { width: min(1240px, calc(100% - 40px)); margin: 0 auto; padding: 42px 0 64px; }
.statistics-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.statistics-kicker { color: var(--neon-cyan); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.statistics-heading h1 { margin: 4px 0 6px; color: #fff; font-size: 36px; letter-spacing: 0; }
#statistics-summary { margin: 0; color: var(--text-dim); font-size: 13px; }
.statistics-close {
  width: 38px; height: 38px; flex: 0 0 auto; border: 1px solid var(--glass-border); border-radius: 50%;
  color: #fff; background: #05070c; font-size: 24px; cursor: pointer;
}
.statistics-close:hover { border-color: var(--neon-cyan); color: var(--neon-cyan); }
.statistics-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin: 28px 0 12px; border-bottom: 1px solid var(--glass-border);
}
.statistics-scope { display: flex; gap: 2px; }
.statistics-scope button {
  min-width: 100px; padding: 10px 14px; border: 0; border-bottom: 2px solid transparent;
  color: var(--text-dim); background: transparent; font-weight: 800; cursor: pointer;
}
.statistics-scope button.active { color: var(--neon-cyan); border-bottom-color: var(--neon-cyan); }
#statistics-generated { color: var(--text-dim); font-size: 11px; }
#statistics-status { min-height: 24px; padding: 4px 0; color: var(--neon-orange); font-size: 12px; }
#tournament-statistics-status { min-height: 24px; padding: 4px 0; color: var(--neon-cyan); font-size: 12px; }
#tournament-statistics-view {
  position: fixed; inset: 0; z-index: 40; overflow: auto; padding: 28px;
  background: rgba(3, 5, 10, 0.97); backdrop-filter: blur(10px);
}
.tournament-statistics-table { min-width: 900px; }
.statistics-table-wrap { overflow-x: auto; border-top: 1px solid var(--glass-border); }
.statistics-table { width: 100%; border-collapse: collapse; min-width: 940px; font-size: 13px; }
.statistics-table th {
  position: sticky; top: 0; z-index: 1; padding: 12px 10px; color: var(--text-dim);
  background: #080b12; text-align: left; text-transform: uppercase; font-size: 10px;
}
.statistics-table td { padding: 13px 10px; border-bottom: 1px solid var(--glass-border); color: #dbe4f5; }
.statistics-table tbody tr:hover { background: rgba(0, 229, 255, 0.05); }
.statistics-table tbody tr.meta-rank { background: linear-gradient(90deg, rgba(57, 255, 136, 0.07), transparent 42%); }
.rank-cell { width: 64px; color: var(--neon-cyan) !important; font-weight: 900; }
.combo-cell { min-width: 230px; color: #fff !important; font-weight: 800; }
.numeric-cell { text-align: right; font-variant-numeric: tabular-nums; }
.wins-cell, .win-rate-cell { color: var(--neon-green) !important; font-weight: 900; }
.draws-cell { color: var(--neon-orange) !important; }
.finish-cell { min-width: 190px; color: var(--text-dim) !important; font-variant-numeric: tabular-nums; }

#camera-controls {
  position: fixed; top: calc(var(--topbar-height) + var(--ticker-height) + 11px); left: 50%; z-index: 28;
  transform: translateX(-50%); display: flex; gap: 4px;
  padding: 4px; background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border); border-radius: 8px;
  backdrop-filter: blur(12px);
}
.camera-btn {
  min-width: 76px; padding: 6px 10px; border: 1px solid transparent;
  border-radius: 5px; background: transparent; color: var(--text-dim);
  font-size: 11px; font-weight: 700; cursor: pointer;
}
.camera-btn.active {
  color: #030a0d; background: var(--neon-cyan); border-color: #b9f8ff;
  box-shadow: 0 0 14px rgba(0, 229, 255, 0.65);
}

#team-match-score {
  position: fixed; top: calc(var(--topbar-height) + var(--ticker-height) + 58px); left: 50%; z-index: 28;
  transform: translateX(-50%); display: grid; grid-template-columns: minmax(110px, 1fr) auto minmax(110px, 1fr);
  align-items: center; gap: 12px; width: min(520px, calc(100vw - 20px)); min-height: 46px; padding: 6px 12px;
  background: rgba(5, 8, 15, 0.92); border: 1px solid var(--neon-cyan-soft); border-radius: 7px;
  backdrop-filter: blur(10px); box-shadow: 0 5px 20px rgba(0, 0, 0, 0.35);
}
.team-score-player { display: flex; align-items: center; gap: 9px; min-width: 0; }
.team-score-player span { overflow: hidden; color: #fff; font-size: 11px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.team-score-player strong { color: var(--neon-green); font-size: 25px; line-height: 1; }
.team-score-responder { justify-content: flex-end; }
.team-score-responder strong { color: var(--neon-orange); }
.team-score-round { display: grid; gap: 2px; text-align: center; }
.team-score-round span { color: var(--neon-cyan); font-size: 9px; font-weight: 900; text-transform: uppercase; }
.team-score-round strong { color: var(--text-dim); font-size: 10px; white-space: nowrap; }
body.team-replay-active #hud-overlay { padding-top: calc(var(--topbar-height) + var(--ticker-height) + 116px); }

main#setup-view {
  position: absolute; inset: 0; z-index: 0;
}

/* The scene is the fullscreen base layer; every panel below floats above it
   as a fixed-position overlay (no more grid track pinning needed, since
   nothing shares layout flow with the canvas anymore). */
.player-panel {
  position: fixed;
  top: calc(var(--topbar-height) + var(--ticker-height) + 51px);
  bottom: calc(var(--footer-height) + 6px); z-index: 15;
  width: 280px;
  background: var(--glass-bg);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  border: 1px solid var(--glass-border);
  border-radius: 14px; padding: 12px; overflow-y: auto;
  box-sizing: border-box;
}
#panel-p1 { left: 16px; }
#panel-p2 { right: 16px; }
.player-panel h2 { margin: 0 0 8px; font-size: 15px; }
/* Player 1 = neon green / black glass */
#panel-p1 {
  border-color: var(--neon-green-soft);
  box-shadow: 0 0 26px rgba(57, 255, 136, 0.10), inset 0 0 40px rgba(57, 255, 136, 0.03);
}
#panel-p1 h2 { color: var(--neon-green); text-shadow: 0 0 10px rgba(57, 255, 136, 0.7); }
#panel-p1 input[type=range] { accent-color: var(--neon-green); }
#panel-p1 .spin-btn.active, #panel-p1 .launch-style-btn.active, #panel-p1 .launcher-btn.active {
  background: rgba(57, 255, 136, 0.18); border-color: var(--neon-green); color: var(--neon-green);
  box-shadow: 0 0 12px rgba(57, 255, 136, 0.55);
}
/* Player 2 = neon orange / black glass */
#panel-p2 {
  border-color: var(--neon-orange-soft);
  box-shadow: 0 0 26px rgba(255, 138, 30, 0.10), inset 0 0 40px rgba(255, 138, 30, 0.03);
}
#panel-p2 h2 { color: var(--neon-orange); text-shadow: 0 0 10px rgba(255, 138, 30, 0.7); }
#panel-p2 input[type=range] { accent-color: var(--neon-orange); }
#panel-p2 .spin-btn.active, #panel-p2 .launch-style-btn.active, #panel-p2 .launcher-btn.active {
  background: rgba(255, 138, 30, 0.18); border-color: var(--neon-orange); color: var(--neon-orange);
  box-shadow: 0 0 12px rgba(255, 138, 30, 0.55);
}

.preset-row, .part-row { display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; }
.player-panel label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.player-panel select, .player-panel input[type=range] { width: 100%; }
select {
  background: #05070c;
  backdrop-filter: blur(6px);
  color: #fff; border: 1px solid var(--neon-gray);
  border-radius: 8px; padding: 5px; font-size: 13px;
  color-scheme: dark;
}
select option { background: #05070c; color: #fff; }
#panel-p1 select:focus { outline: none; border-color: var(--neon-cyan); box-shadow: 0 0 10px rgba(0, 229, 255, 0.65); }
#panel-p2 select:focus { outline: none; border-color: var(--neon-pink); box-shadow: 0 0 10px rgba(255, 47, 208, 0.65); }
#panel-p1 select option:checked { background: var(--neon-cyan) linear-gradient(0deg, var(--neon-cyan), var(--neon-cyan)); color: #02060a; }
#panel-p2 select option:checked { background: var(--neon-pink) linear-gradient(0deg, var(--neon-pink), var(--neon-pink)); color: #050208; }
.weight-summary {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: baseline;
  margin: 2px 0 8px; padding: 7px 8px; color: #dce8fa; font-size: 10px;
  background: rgba(0, 0, 0, 0.45); border: 1px solid var(--glass-border); border-radius: 6px;
}
.weight-parts { display: block; }
.weight-total { color: #fff; font-size: 14px; white-space: nowrap; }
.weight-summary small { grid-column: 1 / -1; color: var(--text-dim); font-size: 9px; }
#panel-p1 .weight-total { color: var(--neon-green); }
#panel-p2 .weight-total { color: var(--neon-orange); }
.radar-canvas, .preview-canvas, .part-detail-canvas {
  width: 100%; display: block; margin: 6px 0;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 10px; border: 1px solid var(--glass-border);
}

.launch-panel { margin-top: 8px; border-top: 1px dashed var(--glass-border); padding-top: 8px; }
.spin-toggle, .launch-style-toggle, .launcher-toggle { display: flex; gap: 6px; margin-bottom: 8px; }
.blade-spin, .team-spin {
  display: block; margin-bottom: 8px; padding: 6px 8px; border: 1px solid var(--neon-gray);
  border-radius: 6px; color: var(--text); background: rgba(255, 255, 255, 0.04);
}
.spin-btn, .launch-style-btn, .launcher-btn {
  flex: 1; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--neon-gray);
  color: var(--text-dim); padding: 6px; border-radius: 6px; cursor: pointer; font-size: 12px;
  transition: box-shadow 0.15s ease;
}

.center-stage {
  position: fixed; inset: 0; z-index: 0;
}
#scene-background { position: absolute; inset: 0; overflow: hidden; background-color: #03050b; }
#scene-background::before, #scene-background::after { content: ""; position: absolute; pointer-events: none; }
#scene-background[data-background="neon-grid"] {
  background:
    radial-gradient(circle at 50% 43%, rgba(255, 47, 208, 0.16), transparent 18%),
    linear-gradient(to bottom, #010207 0 48%, #07101b 52%, #020309 100%);
}
#scene-background[data-background="neon-grid"]::before {
  inset: 0 0 48%;
  background:
    linear-gradient(to bottom, transparent 94%, rgba(0, 229, 255, 0.95) 96%, transparent 100%),
    repeating-linear-gradient(90deg, transparent 0 12%, rgba(0, 229, 255, 0.62) 12.2%, transparent 12.5% 24%);
  filter: drop-shadow(0 0 8px rgba(0, 229, 255, 0.7));
}
#scene-background[data-background="neon-grid"]::after {
  left: -15%; right: -15%; top: 48%; bottom: -20%;
  background:
    repeating-linear-gradient(90deg, transparent 0 12%, rgba(255, 47, 208, 0.62) 12.2%, transparent 12.7% 24%),
    repeating-linear-gradient(0deg, transparent 0 9%, rgba(0, 229, 255, 0.18) 9.3%, transparent 9.8% 18%);
  transform: perspective(520px) rotateX(58deg); transform-origin: top;
  filter: drop-shadow(0 0 8px rgba(255, 47, 208, 0.65));
}
#scene-background[data-background="midnight"] {
  background: radial-gradient(circle at 50% 60%, #17233d 0, #090d17 38%, #020308 78%);
}
#scene-background[data-background="solar"] {
  background:
    radial-gradient(circle at 70% 38%, rgba(255, 199, 82, 0.52), transparent 16%),
    linear-gradient(145deg, #1b0a12, #42131a 48%, #08050a 100%);
}
#scene-background[data-background="ice"] {
  background:
    linear-gradient(120deg, transparent 48%, rgba(189, 246, 255, 0.2) 49%, transparent 51%),
    repeating-linear-gradient(30deg, transparent 0 12%, rgba(64, 181, 210, 0.12) 12.2% 12.7%, transparent 13% 24%),
    radial-gradient(circle at 50% 55%, #24516a, #07151e 62%, #02070a);
}
#scene-background[data-background="custom"] { background-position: center; background-size: cover; background-repeat: no-repeat; }
#scene-canvas {
  position: relative; z-index: 1; width: 100%; height: 100%; display: block;
  touch-action: none; overscroll-behavior: contain; user-select: none; -webkit-user-select: none;
}

.background-dialog { width: min(760px, calc(100vw - 28px)); }
.background-choices { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.background-choice {
  display: grid; gap: 8px; padding: 7px; border: 1px solid var(--glass-border); border-radius: 7px;
  color: var(--text-dim); background: #05070c; text-align: left; cursor: pointer;
}
.background-choice.active { color: var(--neon-cyan); border-color: var(--neon-cyan); box-shadow: 0 0 14px rgba(0, 229, 255, 0.22); }
.background-swatch { height: 88px; border-radius: 4px; border: 1px solid rgba(255, 255, 255, 0.12); background-size: cover; }
.swatch-neon-grid {
  background:
    linear-gradient(155deg, transparent 50%, rgba(255, 47, 208, 0.8) 51%, transparent 53%),
    repeating-linear-gradient(90deg, transparent 0 22%, rgba(0, 229, 255, 0.7) 23%, transparent 24% 44%),
    #030711;
}
.swatch-midnight { background: radial-gradient(circle at 50% 60%, #334b79, #060a12 70%); }
.swatch-solar { background: radial-gradient(circle at 70% 35%, #ffc752, #551b22 30%, #0b0508 72%); }
.swatch-ice { background: repeating-linear-gradient(30deg, transparent 0 20%, #3ba6c4 21%, transparent 22% 40%), #092536; }
.swatch-custom { display: grid; place-items: center; color: var(--neon-cyan); background: #090d16; font-size: 34px; }
#background-status { min-height: 20px; margin-top: 10px; color: var(--neon-cyan); font-size: 12px; }

#pre-launch-bar {
  position: absolute; bottom: calc(var(--footer-height) + 14px); left: 50%; z-index: 12; transform: translateX(-50%);
}
.launch-btn {
  background: linear-gradient(135deg, rgba(255, 47, 208, 0.92), rgba(255, 16, 90, 0.85));
  backdrop-filter: blur(6px);
  color: white; font-weight: 800; font-size: 18px; letter-spacing: 2px;
  border: 2px solid rgba(255, 255, 255, 0.35); border-radius: 30px; padding: 12px 34px;
  cursor: pointer; box-shadow: 0 0 26px rgba(255, 47, 208, 0.7), 0 0 60px rgba(255, 47, 208, 0.25);
  text-shadow: 0 0 8px rgba(0, 0, 0, 0.5);
  transition: box-shadow 0.15s ease, transform 0.1s ease;
}
.launch-btn:hover { box-shadow: 0 0 36px rgba(255, 47, 208, 0.9), 0 0 90px rgba(255, 47, 208, 0.35); transform: translateY(-1px); }
.launch-btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }

#hud-overlay {
  position: absolute; inset: 0; z-index: 26; pointer-events: none;
  padding: calc(var(--topbar-height) + var(--ticker-height) + 58px) 10px calc(var(--footer-height) + 10px);
}
.hud-player-status { display: flex; justify-content: space-between; gap: 8px; }
.hud-bar {
  display: grid; grid-template-columns: 76px 1fr; align-items: center; gap: 5px;
  width: min(240px, calc(50vw - 14px)); padding: 5px 7px;
  background: rgba(5, 8, 15, 0.88); border: 1px solid var(--glass-border); border-radius: 7px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.32);
}
.hud-name { overflow: hidden; font-weight: 700; font-size: 10px; white-space: nowrap; text-overflow: ellipsis; text-shadow: 0 0 6px black; }
.hud-A .hud-name { color: var(--neon-green); text-shadow: 0 0 8px rgba(57, 255, 136, 0.8); }
.hud-B .hud-name { color: var(--neon-orange); text-shadow: 0 0 8px rgba(255, 138, 30, 0.8); }
.meter {
  height: 6px; border-radius: 3px; overflow: hidden;
  background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.08);
}
.meter-fill { height: 100%; width: 100%; transition: width 0.15s linear; }
.power-fill { background: linear-gradient(90deg, #7c3cff, #d56bff); box-shadow: 0 0 10px rgba(184, 92, 255, 0.75); }

#event-panel {
  position: absolute; left: 10px; bottom: calc(var(--footer-height) + 70px); width: 360px; height: 160px;
  overflow: hidden; color: #eaf1ff; text-shadow: 0 0 3px black; pointer-events: auto;
  background: rgba(5, 6, 10, 0.35); backdrop-filter: blur(6px);
  border: 1px solid var(--glass-border); border-radius: 8px;
}
.event-panel-heading { display: flex; align-items: center; justify-content: space-between; padding: 4px 5px 2px 10px; }
.event-panel-heading span { color: var(--neon-cyan); font-size: 9px; font-weight: 900; text-transform: uppercase; }
#btn-event-panel-close {
  width: 26px; height: 26px; padding: 0; border: 0; border-radius: 4px;
  color: #fff; background: transparent; font-size: 19px; line-height: 1; cursor: pointer;
}
#btn-event-panel-close:hover, #btn-event-panel-close:focus-visible { color: var(--neon-pink); outline: 1px solid var(--neon-cyan); }
#event-log { max-height: 126px; overflow: hidden; padding: 0 10px 6px; font-size: 11px; }
#event-log div { opacity: 0.9; margin-bottom: 2px; }

#finish-banner {
  position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%);
  text-align: center;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(22px) saturate(180%);
  border: 2px solid var(--neon-pink);
  border-radius: 18px; padding: 24px 40px; pointer-events: all;
  box-shadow: 0 0 40px rgba(255, 47, 208, 0.5), 0 0 100px rgba(255, 47, 208, 0.18);
}
#finish-title {
  font-size: 30px; font-weight: 900; letter-spacing: 2px;
  background: linear-gradient(90deg, var(--neon-pink), var(--neon-cyan));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 10px rgba(255, 47, 208, 0.5));
}
#finish-sub { font-size: 15px; color: var(--text-main); margin: 8px 0 16px; }
#finish-banner button {
  background: linear-gradient(135deg, var(--neon-green), #0aff6b);
  color: #04170c; border: none; border-radius: 20px;
  padding: 10px 22px; font-size: 14px; cursor: pointer; font-weight: 800;
  box-shadow: 0 0 18px rgba(57, 255, 136, 0.6);
}
.finish-actions, .social-share, .dialog-actions {
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.social-share { margin-top: 10px; }
.social-share button {
  min-width: 40px; padding: 7px 10px !important; border-radius: 6px !important;
  color: #fff !important; background: #080b12 !important;
  border: 1px solid var(--neon-cyan-soft) !important; box-shadow: none !important;
}
.social-share button:hover { border-color: var(--neon-cyan) !important; }
#finish-share-status { min-height: 16px; margin-top: 6px; color: var(--neon-cyan); font-size: 11px; }

.hidden { display: none !important; }

.app-dialog {
  width: min(920px, calc(100vw - 28px)); max-height: calc(100vh - 40px);
  padding: 18px; overflow: auto; color: var(--text-main);
  background: rgba(8, 10, 16, 0.96); border: 1px solid var(--neon-cyan-soft);
  border-radius: 8px; box-shadow: 0 0 42px rgba(0, 229, 255, 0.24);
  pointer-events: auto;
}
.app-dialog[open], .app-dialog[open] * { pointer-events: auto; }
.app-dialog::backdrop { background: rgba(1, 3, 8, 0.78); backdrop-filter: blur(8px); pointer-events: auto; }
body:has(.app-dialog[open]) #scene-canvas { pointer-events: none; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.dialog-heading h2 { margin: 2px 0 14px; font-size: 22px; color: #fff; }
.dialog-kicker { color: var(--neon-cyan); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.dialog-close {
  width: 34px; height: 34px; border: 1px solid var(--glass-border); border-radius: 50%;
  color: #fff; background: #05070c; font-size: 22px; cursor: pointer;
}
.contact-dialog { width: min(620px, calc(100vw - 28px)); }
.contact-intro { margin: 0 0 16px; color: var(--text-dim); font-size: 13px; line-height: 1.5; }
.contact-captcha {
  padding: 14px; border: 1px solid var(--glass-border); border-radius: 7px;
  background: rgba(255, 255, 255, 0.035);
}
.contact-captcha-track {
  position: relative; height: 108px; overflow: hidden;
  border: 1px solid rgba(199, 206, 216, 0.24); border-radius: 6px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px) 0 0 / 32px 100%,
    #05070c;
  touch-action: none; user-select: none;
}
.contact-captcha-piece, .contact-captcha-target {
  position: absolute; top: 50%; width: 68px; height: 68px;
}
.contact-captcha-piece {
  left: 0; z-index: 2; padding: 0; border: 0; border-radius: 50%;
  color: inherit; background: transparent; cursor: grab;
  filter: drop-shadow(0 0 10px rgba(255, 47, 208, 0.48));
  transition: filter 0.16s ease;
}
.contact-captcha-piece.dragging { cursor: grabbing; filter: drop-shadow(0 0 16px rgba(0, 229, 255, 0.8)); }
.contact-captcha-piece.missed { animation: captcha-miss 0.28s ease; }
.contact-captcha-piece.matched { filter: drop-shadow(0 0 15px rgba(57, 255, 136, 0.85)); }
.contact-captcha-piece:focus-visible { outline: 2px solid var(--neon-cyan); outline-offset: 3px; }
.contact-captcha-piece img, .contact-captcha-target img { display: block; width: 100%; height: 100%; pointer-events: none; }
.contact-captcha-target {
  transform: translateY(-50%); opacity: 0.32;
  filter: grayscale(1) drop-shadow(0 0 8px rgba(0, 229, 255, 0.65));
}
.contact-captcha-target.matched { opacity: 0.72; filter: drop-shadow(0 0 12px rgba(57, 255, 136, 0.8)); }
.contact-captcha-status { min-height: 18px; margin: 10px 0 0; color: var(--neon-cyan); font-size: 12px; }
.contact-reveal {
  display: grid; gap: 6px; margin-top: 14px; padding: 14px;
  border-left: 3px solid var(--neon-green); background: rgba(57, 255, 136, 0.08);
}
.contact-reveal span { color: var(--text-dim); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.contact-reveal a { width: fit-content; color: var(--neon-green); font-size: 20px; font-weight: 900; text-decoration: none; }
.contact-reveal a:hover { text-decoration: underline; }
@keyframes captcha-miss { 25%, 75% { margin-left: -5px; } 50% { margin-left: 5px; } }
.gamertag-field { display: grid; gap: 5px; color: var(--text-dim); font-size: 11px; text-transform: uppercase; }
.gamertag-field input, #challenge-link-output {
  width: 100%; padding: 9px 10px; color: #fff; background: #05070c;
  border: 1px solid var(--neon-gray); border-radius: 6px; font-size: 13px;
}
#team-slots { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 14px 0; }
.team-slot { padding: 10px; border: 1px solid var(--glass-border); border-radius: 7px; background: rgba(255, 255, 255, 0.035); }
.team-slot h3 { margin: 0 0 8px; color: var(--neon-pink); font-size: 14px; }
.team-slot label { display: grid; gap: 3px; color: var(--text-dim); font-size: 10px; text-transform: uppercase; }
.team-slot select { min-width: 0; width: 100%; }
.team-part-grid { display: grid; gap: 7px; margin-top: 8px; }
.team-battle-settings { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--glass-border); }
.team-battle-settings label { min-width: 0; }
.team-power-label { grid-column: 1 / -1; }
.team-power-label output { color: var(--neon-cyan); font-weight: 900; }
.team-power { width: 100%; }
.team-weight {
  margin-top: 8px; padding-top: 7px; border-top: 1px solid var(--glass-border);
  color: var(--neon-green); font-size: 11px; font-weight: 800; text-align: right;
}
#team-status { min-height: 20px; margin: 8px 0; color: var(--neon-cyan); font-size: 12px; }
#challenge-link-output, #team-result-link-output {
  width: 100%; margin-bottom: 10px; padding: 9px 10px; color: #fff; background: #05070c;
  border: 1px solid var(--neon-gray); border-radius: 6px; font-size: 12px;
}
.dialog-actions { flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.dialog-actions button {
  padding: 9px 14px; border: 1px solid var(--neon-cyan-soft); border-radius: 6px;
  color: #fff; background: #080b12; cursor: pointer; font-weight: 700;
}
.dialog-actions .primary-action { color: #03130a; background: var(--neon-green); border-color: var(--neon-green); }
.result-dialog { width: min(640px, calc(100vw - 28px)); }
#team-result-score { margin: 6px 0 16px; color: var(--neon-green); font-size: 26px; font-weight: 900; }
#team-result-seed { margin: -10px 0 12px; color: var(--neon-cyan); font-size: 11px; font-variant-numeric: tabular-nums; }
#team-round-results { display: grid; gap: 7px; padding: 0; list-style: none; }
#team-round-results li { display: grid; gap: 3px; padding: 9px 0; border-bottom: 1px solid var(--glass-border); }
#team-round-results strong { color: #fff; font-size: 13px; }
#team-round-results span { color: var(--text-dim); font-size: 12px; }

@media (max-width: 800px) {
  :root { --topbar-height: 63px; --footer-height: 50px; }
  #topbar { padding: 10px 14px; }
  .brand-sub { display: none; }
  .brand { gap: 6px; }
  .brand-bx { font-size: 24px; }
  .brand-arena { font-size: 18px; }
  .mobile-menu-toggle {
    display: grid; place-content: center; gap: 5px; flex: 0 0 42px;
    width: 42px; height: 42px; padding: 0; color: #fff;
    background: rgba(4, 7, 13, 0.9); border: 1px solid var(--neon-cyan-soft);
    border-radius: 6px; cursor: pointer;
  }
  .mobile-menu-toggle span {
    display: block; width: 20px; height: 2px; background: currentColor;
    transition: transform 0.16s ease, opacity 0.16s ease;
  }
  .mobile-menu-toggle.active span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .mobile-menu-toggle.active span:nth-child(2) { opacity: 0; }
  .mobile-menu-toggle.active span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
  .mobile-menu-toggle:focus-visible { outline: 2px solid var(--neon-cyan); outline-offset: 2px; }
  .topbar-actions {
    position: absolute; top: calc(100% + 8px); right: 10px;
    display: none; align-items: stretch; flex-direction: column; gap: 6px;
    width: min(260px, calc(100vw - 20px)); padding: 8px;
    background: rgba(5, 8, 15, 0.98); border: 1px solid var(--neon-cyan-soft);
    border-radius: 7px; box-shadow: 0 14px 32px rgba(0, 0, 0, 0.62);
  }
  .topbar-actions.mobile-open { display: flex; }
  .topbar-actions .ghost-btn {
    display: block; width: 100%; min-height: 44px; margin: 0; padding: 10px 12px;
    border-radius: 5px; text-align: left;
  }
  .contact-captcha-track { height: 96px; }
  .contact-captcha-piece, .contact-captcha-target { width: 60px; height: 60px; }
  .contact-reveal a { font-size: 17px; }
  .spin-btn, .launch-style-btn, .launcher-btn { min-width: 0; min-height: 44px; }
  .launch-style-toggle, .launcher-toggle { display: grid; grid-template-columns: 1fr; }
  .weight-summary { grid-template-columns: 1fr; }
  .weight-total { white-space: normal; }
  .weight-summary small { grid-column: 1; }
  .statistics-shell { width: calc(100% - 20px); padding-top: 24px; }
  .statistics-heading h1 { font-size: 28px; }
  .statistics-toolbar { align-items: flex-end; }
  #statistics-generated { max-width: 130px; text-align: right; }
  .background-choices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .background-swatch { height: 76px; }
  #camera-controls {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
    width: calc(100vw - 20px);
  }
  .camera-btn {
    min-width: 0; min-height: 48px; padding: 6px 3px;
    line-height: 1.15; white-space: normal; overflow-wrap: anywhere;
  }
  #hud-overlay {
    padding-top: calc(var(--topbar-height) + var(--ticker-height) + 82px);
  }
  #event-panel { width: calc(100vw - 20px); }
  #team-slots { grid-template-columns: 1fr; }
  #team-match-score { grid-template-columns: minmax(72px, 1fr) auto minmax(72px, 1fr); gap: 6px; top: calc(var(--topbar-height) + var(--ticker-height) + 72px); padding: 5px 8px; }
  .team-score-player span { font-size: 9px; }
  .team-score-player strong { font-size: 21px; }
  body.team-replay-active #hud-overlay { padding-top: calc(var(--topbar-height) + var(--ticker-height) + 144px); }
  .app-dialog {
    width: calc(100vw - 16px); max-height: calc(100dvh - 16px); padding: 14px;
    overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  }
  .dialog-actions { align-items: stretch; flex-direction: column; }
  .dialog-actions button { min-height: 44px; }
}

@media (max-width: 900px) {
  /* Narrow screens: keep the scene fullscreen behind everything, but shrink
     the floating panels into smaller bottom-corner overlays instead of the
     old stacked grid rows (which no longer apply now that nothing shares
     layout flow with the canvas). */
  .player-panel {
    top: calc(var(--topbar-height) + var(--ticker-height) + 132px);
    bottom: calc(var(--footer-height) + 84px); height: auto; width: 45vw;
  }
  #panel-p1 { left: 8px; }
  #panel-p2 { right: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  #sponsor-ticker.ready .sponsor-track { animation-duration: 80s; }
}
