:root {
  --bg: #0b1224;
  --panel: #0f172a;
  --panel-2: #111827;
  --accent: #38bdf8;
  --accent-2: #06b6d4;
  --hot: #f472b6;
  --glow: rgba(103, 232, 249, 0.7);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --danger: #f43f5e;
  --shadow: rgba(0, 0, 0, 0.35);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 20% 20%, #1f2937, #0b1224 55%);
  color: var(--text);
  font-family: "Segoe UI", "Trebuchet MS", Arial, sans-serif;
  position: relative;
  overflow: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: -20%;
  background: conic-gradient(from 120deg, rgba(56, 189, 248, 0.1), rgba(244, 114, 182, 0.12), rgba(56, 189, 248, 0.08), transparent 55%);
  filter: blur(70px);
  opacity: 0.65;
  pointer-events: none;
  animation: aurora 18s ease-in-out infinite alternate;
}

body::after {
  animation-duration: 22s;
  animation-direction: alternate-reverse;
  opacity: 0.45;
}

.shell {
  width: min(960px, 96vw);
  background: linear-gradient(145deg, var(--panel), var(--panel-2));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  padding: 28px;
  box-shadow: 0 16px 50px var(--shadow);
  position: relative;
  overflow: hidden;
}

.shell::before {
  content: "";
  position: absolute;
  inset: -30%;
  background: radial-gradient(circle at 40% 30%, rgba(56, 189, 248, 0.08), transparent 40%),
    radial-gradient(circle at 70% 70%, rgba(244, 114, 182, 0.08), transparent 40%);
  filter: blur(40px);
  opacity: 0.5;
  pointer-events: none;
  animation: floaty 12s ease-in-out infinite alternate;
}

.top h1 {
  margin: 0 0 6px;
  letter-spacing: 0.02em;
}

.top p {
  margin: 0;
  color: var(--muted);
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 10px 30px var(--shadow);
  position: relative;
  overflow: hidden;
  animation: floaty 8s ease-in-out infinite alternate;
}

.label {
  margin: 0;
  color: var(--muted);
}

.value {
  margin: 6px 0 0;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
}

.cta {
  margin-top: 22px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.note {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.leaderboard {
  margin-top: 18px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  max-height: 480px;
  overflow-y: auto;
  overflow-x: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(4px);
}

.lb-row {
  display: grid;
  grid-template-columns: 80px 1fr 90px;
  gap: 12px;
  padding: 12px 16px;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: linear-gradient(90deg, rgba(56, 189, 248, 0.07), transparent 35%, transparent 70%, rgba(244, 114, 182, 0.06));
  opacity: 0;
  transform: translateY(8px) scale(0.98);
  animation: riseIn 0.65s cubic-bezier(0.18, 0.9, 0.2, 1.04) forwards;
  animation-delay: var(--delay, 0ms);
}

.lb-row:last-child {
  border-bottom: none;
}

.lb-rank {
  font-weight: 700;
  color: var(--accent);
}

.lb-name {
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.lb-flag {
  font-size: 1.05rem;
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.15));
}

.lb-score {
  text-align: right;
  font-weight: 700;
}

.tabs {
  display: inline-flex;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  overflow: hidden;
  margin: 14px 0;
}

.tab-btn {
  background: transparent;
  color: var(--text);
  padding: 10px 16px;
  border: none;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: background 0.2s ease, color 0.2s ease;
}

.tab-btn.active {
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  color: #0b1224;
}

.hidden {
  display: none !important;
}

.team-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin: 6px 0 10px;
}

.card.small {
  gap: 8px;
}

.card.small h3 {
  margin: 0 0 8px;
}

input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font-size: 1rem;
}

.team-info {
  align-self: center;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.team-row {
  display: grid;
  grid-template-columns: 70px 1fr 140px 110px;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: linear-gradient(90deg, rgba(244, 114, 182, 0.07), transparent 30%, transparent 70%, rgba(56, 189, 248, 0.06));
  opacity: 0;
  transform: translateY(8px) scale(0.98);
  animation: riseIn 0.65s cubic-bezier(0.18, 0.9, 0.2, 1.04) forwards;
  animation-delay: var(--delay, 0ms);
}

.team-row:last-child {
  border-bottom: none;
}

.team-rank {
  font-weight: 700;
  color: var(--hot);
}

.team-name {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.team-title {
  font-weight: 700;
}

.team-code {
  color: var(--muted);
  font-size: 0.9rem;
}

.team-meta {
  color: var(--muted);
  font-weight: 600;
}

.team-score {
  text-align: right;
  font-weight: 800;
  color: var(--accent);
  font-size: 1.1rem;
}

.hud {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  flex-wrap: wrap;
  background: rgba(255, 255, 255, 0.03);
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  margin-top: 14px;
}

.stat {
  font-weight: 600;
  color: var(--text);
}

.stat span {
  margin-left: 8px;
  color: var(--accent);
  font-size: 1.2rem;
}

.spacer {
  flex: 1;
}

button,
.button-link,
.play-button {
  border: none;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  color: #0b1224;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
  box-shadow: 0 8px 20px rgba(56, 189, 248, 0.3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  position: relative;
}

button:hover,
.button-link:hover,
.play-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 26px rgba(56, 189, 248, 0.4), 0 0 0 3px rgba(56, 189, 248, 0.15);
}

button:active,
.button-link:active,
.play-button:active {
  transform: translateY(0);
  box-shadow: 0 6px 14px rgba(56, 189, 248, 0.25);
}

.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: none;
}

.button-link {
  color: inherit;
}

.play-button {
  padding: 12px 18px;
  font-size: 1.05rem;
  animation: pulseGlow 3.8s ease-in-out infinite;
}

.message {
  margin: 14px 0 18px;
  color: var(--muted);
}

.arena {
  position: relative;
  height: 60vh;
  min-height: 320px;
  background: radial-gradient(circle at 30% 40%, rgba(56, 189, 248, 0.07), transparent 40%),
    radial-gradient(circle at 70% 20%, rgba(6, 182, 212, 0.07), transparent 38%),
    radial-gradient(circle at 50% 60%, rgba(255, 255, 255, 0.04), transparent 55%),
    #0c1529;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  position: relative;
  isolation: isolate;
}

.arena::before {
  content: "";
  position: absolute;
  inset: -20%;
  background: radial-gradient(circle at 25% 30%, rgba(56, 189, 248, 0.14), transparent 38%),
    radial-gradient(circle at 70% 70%, rgba(244, 114, 182, 0.12), transparent 36%);
  opacity: 0.5;
  filter: blur(60px);
  animation: floaty 10s ease-in-out infinite alternate;
  pointer-events: none;
}

.arena::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, rgba(255, 255, 255, 0.04), transparent 40%, rgba(255, 255, 255, 0.03));
  mix-blend-mode: screen;
  opacity: 0.5;
  pointer-events: none;
}

.circle {
  position: absolute;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #e0f2fe, var(--accent));
  box-shadow: 0 12px 30px rgba(56, 189, 248, 0.45);
  display: none;
  opacity: 0;
  transform: scale(0.95);
  cursor: pointer;
  will-change: transform;
  isolation: isolate;
}

.circle.visible {
  display: block;
  opacity: 1;
  animation: pop 0.18s ease, halo 1.6s ease-in-out infinite 0.12s;
  transform: scale(1);
}

@keyframes pop {
  0% {
    transform: scale(0.7);
  }
  100% {
    transform: scale(1);
  }
}

.circle.burst::after {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.6);
  animation: ripple 0.5s ease-out forwards;
  pointer-events: none;
  z-index: -1;
}

.hit-pulse {
  position: absolute;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.65), transparent 70%);
  pointer-events: none;
  opacity: 0.9;
  transform: translate(-50%, -50%) scale(0.4);
  animation: pulseOut 0.6s ease-out forwards;
  filter: blur(0.2px);
}

@keyframes halo {
  0% {
    box-shadow: 0 12px 30px rgba(56, 189, 248, 0.45), 0 0 0 0 rgba(56, 189, 248, 0.35);
  }
  70% {
    box-shadow: 0 14px 36px rgba(56, 189, 248, 0.55), 0 0 0 12px rgba(56, 189, 248, 0);
  }
  100% {
    box-shadow: 0 12px 30px rgba(56, 189, 248, 0.45), 0 0 0 0 rgba(56, 189, 248, 0);
  }
}

@keyframes ripple {
  from {
    transform: scale(0.8);
    opacity: 0.8;
  }
  to {
    transform: scale(1.4);
    opacity: 0;
  }
}

@keyframes pulseOut {
  0% {
    opacity: 0.9;
    transform: translate(-50%, -50%) scale(0.4);
  }
  80% {
    opacity: 0.15;
    transform: translate(-50%, -50%) scale(1.8);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(2);
  }
}

@keyframes riseIn {
  0% {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes aurora {
  0% {
    transform: translate3d(-8%, -6%, 0) rotate(2deg);
  }
  50% {
    transform: translate3d(6%, 4%, 0) rotate(-1deg);
  }
  100% {
    transform: translate3d(10%, -4%, 0) rotate(3deg);
  }
}

@keyframes floaty {
  0% {
    transform: translateY(-6px) scale(1);
  }
  100% {
    transform: translateY(8px) scale(1.02);
  }
}

@keyframes pulseGlow {
  0% {
    box-shadow: 0 8px 20px rgba(56, 189, 248, 0.3), 0 0 0 0 rgba(244, 114, 182, 0.22);
  }
  60% {
    box-shadow: 0 12px 30px rgba(56, 189, 248, 0.45), 0 0 0 12px rgba(244, 114, 182, 0);
  }
  100% {
    box-shadow: 0 8px 20px rgba(56, 189, 248, 0.3), 0 0 0 0 rgba(244, 114, 182, 0);
  }
}

.screamer {
  position: fixed;
  inset: 0;
  background: url("../img/scrimer.png") center center / cover no-repeat, #000;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  display: none;
  transition: opacity 0.12s ease;
}

.screamer.visible {
  display: block;
  opacity: 1;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  background: rgba(15, 23, 42, 0.9);
  border-radius: 14px;
  padding: 22px 24px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  box-shadow: 0 12px 32px var(--shadow);
  text-align: center;
  min-width: 220px;
}

.overlay-title {
  margin: 0 0 8px;
  font-size: 1.3rem;
  color: var(--danger);
}

.overlay-sub {
  margin: 4px 0 12px;
  color: var(--muted);
}

.overlay-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* Ultra-stylized extras */
button,
.button-link,
.play-button {
  position: relative;
  overflow: hidden;
}

button::before,
.button-link::before,
.play-button::before {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: inherit;
  background: conic-gradient(from 120deg, rgba(56, 189, 248, 0.35), rgba(244, 114, 182, 0.4), rgba(56, 189, 248, 0.2), rgba(244, 114, 182, 0.25));
  opacity: 0.35;
  filter: blur(1px);
  z-index: 0;
  animation: btnBorder 4s linear infinite;
  pointer-events: none;
}

button::after,
.button-link::after,
.play-button::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--rx, 50%) var(--ry, 50%), rgba(255, 255, 255, 0.5), transparent 45%);
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.2s ease;
  z-index: 1;
  pointer-events: none;
}

button.rippling::after,
.button-link.rippling::after,
.play-button.rippling::after {
  animation: btnRipple 0.55s ease-out;
}

button span,
.button-link span,
.play-button span {
  position: relative;
  z-index: 2;
}

body:not(.page-ready) .shell {
  opacity: 0;
  transform: translateY(14px) scale(0.98);
}

body.page-ready .shell {
  animation: shellIn 0.55s cubic-bezier(0.22, 0.9, 0.2, 1.05);
}

.page-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 30% 30%, rgba(56, 189, 248, 0.28), rgba(11, 18, 36, 0.9) 48%),
    radial-gradient(circle at 70% 70%, rgba(244, 114, 182, 0.25), rgba(11, 18, 36, 0.92) 50%);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transform: scale(1.04);
  transition: opacity 0.35s ease, transform 0.35s ease;
  z-index: 60;
}

.page-overlay.show {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.leaderboard {
  position: relative;
}

.leaderboard::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent, rgba(56, 189, 248, 0.08), transparent 70%);
  opacity: 0.8;
  mix-blend-mode: screen;
  animation: scanline 4s linear infinite;
  pointer-events: none;
}

.lb-sweep::before {
  animation-duration: 2.4s;
}

.lb-row {
  position: relative;
}

.lb-row::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 4px;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(56, 189, 248, 0.6), rgba(244, 114, 182, 0.6), transparent);
  opacity: 0;
  transform: scaleX(0.5);
  transform-origin: left;
  transition: opacity 0.2s ease, transform 0.25s ease;
  pointer-events: none;
}

.lb-row:hover {
  transform: translateX(4px) skewX(-1deg);
}

.lb-row:hover::after {
  opacity: 1;
  transform: scaleX(1);
}

.arena.shake {
  animation: arenaShake 0.4s ease;
}

.arena.hurt {
  box-shadow: inset 0 0 0 2px rgba(244, 63, 94, 0.45), 0 0 30px rgba(244, 63, 94, 0.25);
}

.arena.boost {
  box-shadow: inset 0 0 0 2px rgba(56, 189, 248, 0.45), 0 0 36px rgba(56, 189, 248, 0.35);
}

.circle {
  background: radial-gradient(circle at 30% 30%, var(--c1, #e0f2fe), var(--c2, var(--accent)));
}

.circle.visible {
  animation: slitIn 0.22s cubic-bezier(0.2, 0.9, 0.2, 1), halo 1.6s ease-in-out infinite 0.12s;
}

.circle.slit {
  clip-path: inset(0 0 0 0);
}

.spark {
  position: absolute;
  width: var(--spark-size, 10px);
  height: var(--spark-size, 10px);
  border-radius: 999px;
  pointer-events: none;
  opacity: 0.9;
  transform-origin: center;
  animation: sparkFly 0.45s ease-out forwards;
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.25));
}

.spark-hit {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.7), rgba(244, 114, 182, 0.7));
}

.spark-miss {
  background: radial-gradient(circle, rgba(244, 63, 94, 0.8), transparent 70%);
}

.spark-trail {
  background: radial-gradient(circle, rgba(56, 189, 248, 0.7), transparent 70%);
}

.score-pop {
  animation: scorePop 0.4s ease;
}

#comboBadge {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 24px var(--shadow), 0 0 0 1px rgba(56, 189, 248, 0.25);
  backdrop-filter: blur(4px);
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

#comboBadge.hidden {
  opacity: 0;
  transform: translateY(-6px) scale(0.95);
}

.combo-pop {
  animation: comboPop 0.4s ease;
}

.confetti-piece {
  position: fixed;
  top: -10px;
  width: 10px;
  height: 18px;
  border-radius: 3px;
  opacity: 0.9;
  z-index: 80;
  animation: confettiFall var(--fall, 1200ms) ease-out forwards;
  transform: translateY(0) rotate(0deg) translateX(0);
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.2));
}

@keyframes shellIn {
  0% {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes btnBorder {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes btnRipple {
  0% {
    opacity: 0.55;
    transform: scale(0.2);
  }
  90% {
    opacity: 0.05;
    transform: scale(2.1);
  }
  100% {
    opacity: 0;
    transform: scale(2.4);
  }
}

@keyframes scanline {
  0% {
    transform: translateY(-100%);
  }
  100% {
    transform: translateY(100%);
  }
}

@keyframes slitIn {
  0% {
    transform: scale(0.6) rotateX(28deg);
    opacity: 0;
    clip-path: inset(45% 50% 45% 50%);
  }
  100% {
    transform: scale(1) rotateX(0deg);
    opacity: 1;
    clip-path: inset(0 0 0 0);
  }
}

@keyframes sparkFly {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(0.6) rotate(var(--spark-rotate, 0deg));
  }
  100% {
    opacity: 0;
    transform: translate(0, -18px) scale(1.6) rotate(calc(var(--spark-rotate, 0deg) * -1));
  }
}

@keyframes scorePop {
  0% {
    transform: translateY(0) scale(1);
  }
  40% {
    transform: translateY(-4px) scale(1.1);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

@keyframes comboPop {
  0% {
    transform: translateY(-4px) scale(0.9);
    opacity: 0.4;
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes arenaShake {
  0% {
    transform: translateX(0) rotate(0deg);
  }
  25% {
    transform: translateX(-6px) rotate(-0.5deg);
  }
  50% {
    transform: translateX(5px) rotate(0.4deg);
  }
  75% {
    transform: translateX(-4px) rotate(-0.2deg);
  }
  100% {
    transform: translateX(0) rotate(0deg);
  }
}

@keyframes confettiFall {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
  100% {
    transform: translate3d(calc(var(--drift, 1) * 40px), 100vh, 0) rotate(620deg);
    opacity: 0.1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

@media (max-width: 900px) {
  body {
    padding: 14px;
  }

  .shell {
    padding: 20px;
    width: 100%;
  }

  .top h1 {
    font-size: 1.5rem;
  }

  .top p {
    font-size: 0.95rem;
  }

  .hud {
    gap: 10px;
  }

  .message {
    margin: 10px 0 14px;
  }

  .arena {
    height: clamp(260px, 56vh, 420px);
  }

  .lb-row {
    grid-template-columns: 60px 1fr 70px;
  }

  .team-row {
    grid-template-columns: 50px 1fr 110px 80px;
  }
}

@media (max-height: 520px) {
  body {
    padding: 10px;
  }

  .shell {
    padding: 16px;
  }

  .top h1 {
    font-size: 1.35rem;
  }

  .top p,
  .message,
  .stat {
    font-size: 0.95rem;
  }

  button {
    padding: 8px 12px;
  }

  .arena {
    height: clamp(200px, 62vh, 320px);
    min-height: 200px;
  }

  .overlay-card {
    padding: 18px;
  }
}
