@import url('https://fonts.googleapis.com/css2?family=Bangers&family=Nunito:wght@600;700;800&display=swap');

:root {
  --red: #e53935;
  --blue: #1e88e5;
  --ink: #0f1a28;
  --cream: #f7f3ea;
  --accent: #ff9f1c;
  --line: rgba(255, 255, 255, 0.16);
  --glass: rgba(12, 20, 32, 0.55);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: #0d1622;
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--cream);
  user-select: none;
  touch-action: none;
}
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

/* ——— Screens ——— */
.screen {
  position: fixed; inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.screen.dim-over {
  background: rgba(8, 12, 20, 0.62);
  backdrop-filter: blur(4px);
}

/* ——— Full-bleed menu shell ——— */
.menu-shell {
  display: grid;
  grid-template-columns: minmax(160px, 220px) 1fr minmax(160px, 220px);
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "top top top"
    "red hero blue";
  gap: 12px 16px;
  padding: clamp(12px, 2vw, 28px);
  background: #0d1622;
  align-items: stretch;
}
.menu-bg {
  position: absolute; inset: 0; z-index: 0; overflow: hidden;
  pointer-events: none;
}
.menu-bg img {
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: center 42%;
  transform: scale(1.04);
  /* Soft plate under live 3D — keep art vibe without hiding the arena */
  opacity: 0.28;
  filter: saturate(1.1) contrast(1.05);
}
.menu-bg-shade {
  position: absolute; inset: 0;
  background:
    linear-gradient(180deg, rgba(8, 14, 24, 0.42) 0%, rgba(8, 14, 24, 0.08) 40%, rgba(8, 14, 24, 0.55) 100%),
    linear-gradient(90deg, rgba(180, 40, 30, 0.22) 0%, transparent 30%, transparent 70%, rgba(20, 90, 180, 0.22) 100%);
}

.menu-top {
  grid-area: top;
  position: relative; z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.menu-conn-pill {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.icon-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--glass);
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: transform 0.15s ease, filter 0.15s ease;
}
.icon-btn:hover { filter: brightness(1.15); transform: translateY(-2px); }

.menu-hero {
  grid-area: hero;
  position: relative; z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 0;
  padding: 8px 12px 20px;
}
.menu-ball {
  width: clamp(56px, 9vw, 88px);
  height: auto;
  margin-bottom: 4px;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.45));
}
.brand-hero {
  font-family: 'Bangers', system-ui, sans-serif;
  font-weight: 400;
  font-size: clamp(3.4rem, 11vw, 6.2rem);
  letter-spacing: 0.06em;
  line-height: 0.92;
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.35), 0 18px 40px rgba(0, 0, 0, 0.45);
}
.brand-hero .red { color: var(--red); }
.brand-hero .blue { color: var(--blue); }
.brand-hero .dim { color: #fff; margin-left: 0.12em; }
.tagline {
  margin: 8px 0 22px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.82rem;
  opacity: 0.82;
}

.menu-actions, .lobby-actions {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lobby-meta {
  font-size: 0.95rem;
  opacity: 0.8;
  margin: -2px 0 4px;
}
.lobby-countdown {
  font-family: 'Bangers', sans-serif;
  font-size: 1.6rem;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin: 4px 0 8px;
}

/* Quick wait */
.quick-wait, .public-rooms {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-radius: 18px;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.quick-wait h2, .public-rooms h2 {
  font-family: 'Bangers', sans-serif;
  font-size: 2rem;
  letter-spacing: 0.05em;
}
.qw-count {
  font-family: 'Bangers', sans-serif;
  font-size: 4rem;
  line-height: 1;
  color: var(--accent);
  text-shadow: 0 4px 0 rgba(0,0,0,0.25);
}
.qw-sub, .pr-sub, .qw-code { opacity: 0.8; font-weight: 700; font-size: 0.92rem; }
.qw-pulse {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent);
  animation: qwPulse 1.2s ease-in-out infinite;
}
@keyframes qwPulse {
  0%, 100% { transform: scale(0.85); opacity: 0.6; }
  50% { transform: scale(1.25); opacity: 1; }
}

.pr-list {
  list-style: none;
  width: 100%;
  max-height: 240px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 4px 0 8px;
}
.pr-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255,255,255,0.06);
  text-align: left;
}
.pr-row strong { display: block; font-size: 1rem; }
.pr-row span { font-size: 0.8rem; opacity: 0.7; font-weight: 700; }
.pr-row .btn { padding: 8px 14px; font-size: 0.95rem; box-shadow: none; }
.pr-empty { opacity: 0.55; text-align: center; padding: 16px; font-weight: 700; }
.public-rooms .btn { width: 100%; }
.code-row {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.code-row strong {
  font-family: 'Bangers', sans-serif;
  font-size: 1.9rem;
  letter-spacing: 0.22em;
}

/* Team rails */
.team-rail {
  position: relative; z-index: 2;
  align-self: center;
  width: 100%;
  max-height: min(70vh, 520px);
  padding: 14px 12px;
  border-radius: 18px;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  overflow: hidden;
}
.team-rail.red {
  grid-area: red;
  box-shadow: inset 3px 0 0 var(--red);
}
.team-rail.blue {
  grid-area: blue;
  box-shadow: inset -3px 0 0 var(--blue);
}
.team-rail-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.team-label {
  font-family: 'Bangers', sans-serif;
  font-size: 1.55rem;
  letter-spacing: 0.08em;
}
.team-rail.red .team-label { color: #ff7b73; }
.team-rail.blue .team-label { color: #7cbcf5; }
.team-points {
  font-family: 'Bangers', sans-serif;
  font-size: 2.4rem;
  line-height: 1;
}
.roster {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 340px;
  overflow: auto;
}
.roster li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 0.9rem;
  font-weight: 700;
}
.roster li.empty {
  opacity: 0.45;
  font-weight: 600;
  justify-content: center;
}
.roster .ready-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #58d68d;
  box-shadow: 0 0 0 3px rgba(88, 214, 141, 0.2);
  flex-shrink: 0;
}
.roster .slot-tag {
  font-size: 0.72rem;
  opacity: 0.55;
  font-weight: 700;
}

/*
 * Float only decorative rails / ball — NOT buttons.
 * Transform animations on .btn steal hit-targets and break clicks.
 */
.float-rail.red { animation: floatRail 5.2s ease-in-out infinite; }
.float-rail.blue { animation: floatRail 5.2s ease-in-out infinite reverse; }
.float-ball { animation: floatBall 2.8s ease-in-out infinite; }

@keyframes floatRail {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
@keyframes floatBall {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-10px) rotate(4deg); }
}

@media (prefers-reduced-motion: reduce) {
  .float-rail, .float-ball { animation: none !important; }
}

/* Ensure menu controls always receive clicks above the WebGL canvas */
.menu-shell {
  pointer-events: auto;
  z-index: 30;
}
.menu-hero,
.menu-actions,
.lobby-actions,
.quick-wait,
.public-rooms,
.menu-top,
.team-rail {
  pointer-events: auto;
  position: relative;
  z-index: 3;
}
.menu-bg { z-index: 0; pointer-events: none; }
.btn, .row input, .icon-btn {
  position: relative;
  z-index: 4;
  pointer-events: auto;
  touch-action: manipulation;
}

/* Buttons / inputs */
.btn-col { display: flex; flex-direction: column; gap: 10px; }
.btn {
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  border: none;
  border-radius: 14px;
  padding: 13px 16px;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(180deg, #3a4d66, #273548);
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.28);
  transition: filter 0.12s ease, transform 0.12s ease;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(2px); box-shadow: 0 4px 0 rgba(0, 0, 0, 0.28); }
.btn.primary {
  background: linear-gradient(180deg, #ffb347, #ff8c1a);
  color: #2a1600;
}
.btn.red { background: linear-gradient(180deg, #ef5350, #c62828); }
.btn.blue { background: linear-gradient(180deg, #42a5f5, #1565c0); }
.btn.ghost {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  box-shadow: none;
}

.row { display: flex; gap: 8px; }
.row input {
  flex: 1;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 700;
}

/* Compact sheets (settings / pause / results) */
.sheet {
  position: relative; z-index: 2;
  width: min(440px, 100%);
  background: rgba(14, 22, 34, 0.92);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px 22px;
  backdrop-filter: blur(12px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}
.brand-sm {
  font-family: 'Bangers', sans-serif;
  font-size: 2.2rem;
  letter-spacing: 0.06em;
  text-align: center;
  margin-bottom: 14px;
}
.settings label { display: block; margin: 10px 0; font-weight: 700; }
.settings input[type="range"] { width: 100%; margin-top: 6px; }

/* Onboarding */
#onboarding {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 10, 18, 0.72);
  backdrop-filter: blur(6px);
  padding: 20px;
  pointer-events: auto;
}
.ob-card {
  width: min(420px, 100%);
  background: rgba(14, 22, 34, 0.95);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 26px 24px;
  text-align: center;
  animation: fadeIn 0.25s ease;
}
.ob-card h2 {
  font-family: 'Bangers', sans-serif;
  font-size: 2.4rem;
  letter-spacing: 0.06em;
  margin-bottom: 14px;
}
.ob-list {
  list-style: none;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
  font-weight: 700;
}
.ob-list kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 2px 7px;
  margin: 0 2px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 800;
}
.ob-tip {
  opacity: 0.75;
  font-size: 0.9rem;
  margin-bottom: 16px;
}

/* HUD */
#hud {
  position: fixed; inset: 0; pointer-events: none; z-index: 15;
}
#click-to-play {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 16, 24, 0.45);
  pointer-events: auto;
  cursor: pointer;
  z-index: 40;
}
#click-to-play .click-card {
  background: rgba(20, 28, 38, 0.92);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 14px;
  padding: 22px 28px;
  text-align: center;
}
#click-to-play strong {
  display: block;
  font-family: 'Bangers', sans-serif;
  font-size: 2rem;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
#click-to-play span {
  opacity: 0.75;
  font-size: 0.95rem;
}
#hud-top {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 18px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 22px;
  font-family: 'Bangers', sans-serif;
  font-size: 1.6rem;
  letter-spacing: 0.04em;
  backdrop-filter: blur(8px);
}
#hud-red { color: var(--red); }
#hud-blue { color: var(--blue); }
#hud-timer { min-width: 64px; text-align: center; }

#hp-wrap {
  position: absolute; left: 18px; bottom: 22px;
  width: 220px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  backdrop-filter: blur(8px);
}
#hp-bar {
  height: 12px;
  background: rgba(255,255,255,0.1);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 6px;
}
#hp-fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #e74c3c, #f39c12);
  transform-origin: left;
  transition: width 0.15s linear;
}
#throw-wrap {
  position: absolute; right: 18px; bottom: 22px;
  width: 160px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  backdrop-filter: blur(8px);
}
#throw-cd {
  display: block; height: 8px; margin-top: 6px;
  background: var(--accent);
  border-radius: 999px;
  transform-origin: left;
}

#crosshair {
  position: absolute; left: 50%; top: 50%;
  width: 18px; height: 18px;
  transform: translate(-50%, -50%);
}
#crosshair::before, #crosshair::after {
  content: ''; position: absolute; background: rgba(255,255,255,0.85);
}
#crosshair::before { left: 7px; top: 0; width: 2px; height: 18px; }
#crosshair::after { left: 0; top: 7px; width: 18px; height: 2px; }

#kill-feed {
  position: absolute; top: 70px; right: 16px;
  display: flex; flex-direction: column; gap: 6px;
  font-size: 0.85rem;
  font-weight: 700;
}
.kill-row {
  background: rgba(0,0,0,0.45);
  padding: 6px 10px;
  border-radius: 8px;
  animation: fadeIn 0.2s ease;
}
.dmg-popup {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: 'Bangers', sans-serif;
  font-size: 1.8rem;
  color: #ff5252;
  text-shadow: 0 2px 8px rgba(0,0,0,0.7);
  pointer-events: none;
  animation: dmgFloat 0.7s ease forwards;
  z-index: 30;
}
@keyframes dmgFloat {
  from { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  to { opacity: 0; transform: translate(-50%, -120%) scale(1.4); }
}
#conn-status {
  position: absolute; top: 16px; left: 16px;
  font-size: 0.8rem;
  font-weight: 700;
  opacity: 0.7;
  background: var(--glass);
  padding: 6px 10px;
  border-radius: 8px;
}
#conn-status.online { color: #58d68d; }

#scoreboard {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(14, 22, 34, 0.92);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 22px;
  min-width: 360px;
  pointer-events: none;
}
#scoreboard table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
#scoreboard th, #scoreboard td { padding: 6px 8px; text-align: left; }
#scoreboard .red { color: var(--red); }
#scoreboard .blue { color: var(--blue); }

.result-title { font-family: 'Bangers', sans-serif; font-size: 2.6rem; text-align: center; letter-spacing: 0.04em; }
.result-title.red { color: var(--red); }
.result-title.blue { color: var(--blue); }
#result-score {
  text-align: center;
  font-family: 'Bangers', sans-serif;
  font-size: 2.2rem;
  margin: 8px 0 16px;
}
#result-stats { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
#result-stats td, #result-stats th { padding: 6px; text-align: left; border-bottom: 1px solid var(--line); }

/* Mobile */
#mobile-controls {
  position: fixed; inset: 0; z-index: 16; pointer-events: none;
}
#joy-base {
  position: absolute; left: 28px; bottom: 36px;
  width: 110px; height: 110px;
  border-radius: 50%;
  background: rgba(0,0,0,0.3);
  border: 2px solid rgba(255,255,255,0.25);
  pointer-events: auto;
}
#joy-stick {
  position: absolute; left: 50%; top: 50%;
  width: 46px; height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: rgba(255,255,255,0.45);
}
#look-pad {
  position: absolute; right: 0; top: 0; width: 50%; height: 70%;
  pointer-events: auto;
}
.m-btn {
  position: absolute; pointer-events: auto;
  width: 64px; height: 64px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
  background: rgba(0,0,0,0.35);
  color: #fff; font-family: 'Nunito', sans-serif; font-weight: 800;
}
#btn-throw { right: 28px; bottom: 40px; background: rgba(240,162,2,0.55); }
#btn-throw-low { right: 28px; bottom: 115px; background: rgba(52,152,219,0.5); }
#btn-crouch { right: 110px; bottom: 40px; }
#btn-dodge { right: 110px; bottom: 115px; }

#no-webgl {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: #111; color: #fff; padding: 24px; text-align: center;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 900px) {
  .menu-shell {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      "top top"
      "hero hero"
      "red blue";
    gap: 10px;
  }
  .team-rail { max-height: 180px; align-self: stretch; }
  .brand-hero { font-size: clamp(2.8rem, 14vw, 4.2rem); }
  .roster { max-height: 110px; }
}

@media (max-width: 640px) {
  #hp-wrap { width: 160px; }
  .menu-shell { padding: 10px; }
  .team-points { font-size: 1.8rem; }
}
