/* ===== CSS Variables ===== */
:root {
  --bg-primary: #050508;
  --bg-secondary: #0a0a12;
  --bg-tertiary: #12121f;

  --human-primary: #00f5ff;
  --human-secondary: #0099ff;
  --human-glow: rgba(0, 245, 255, 0.4);

  --ai-primary: #ff00ff;
  --ai-secondary: #bf00ff;
  --ai-glow: rgba(255, 0, 255, 0.4);

  --text-primary: #ffffff;
  --text-secondary: #8892b0;
  --text-muted: #4a5568;

  --accent-gold: #ffd700;
  --accent-red: #ff4757;
  --accent-green: #00ff88;

  --border-color: #1e1e2e;
  --card-bg: rgba(15, 15, 25, 0.8);
}

/* ===== Top Navigation ===== */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  flex-shrink: 0;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 6px;
  text-decoration: none;
  font-family: "Rajdhani", sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.nav-link:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
  border-color: var(--border-color);
}

.nav-link .nav-icon {
  font-size: 0.9rem;
}

.nav-link .nav-text {
  display: inline;
}

/* ===== Auth Bar ===== */
.auth-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-shrink: 0;
}

.auth-status {
  display: flex;
  align-items: center;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.auth-loading {
  color: var(--text-muted);
}

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

.auth-btn {
  font-family: "Rajdhani", sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  letter-spacing: 1px;
  border: 1px solid transparent;
}

.sign-in-btn {
  background: transparent;
  color: var(--human-primary);
  border-color: var(--human-primary);
}

.sign-in-btn:hover {
  background: var(--human-primary);
  color: var(--bg-primary);
  box-shadow: 0 0 20px var(--human-glow);
}

.sign-up-btn {
  background: linear-gradient(
    135deg,
    var(--human-primary),
    var(--human-secondary)
  );
  color: var(--bg-primary);
}

.sign-up-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 25px var(--human-glow);
}

.auth-user {
  display: flex;
  align-items: center;
}

#user-button {
  display: flex;
  align-items: center;
}

.auth-required {
  font-size: 0.85rem;
  color: var(--text-secondary);
  letter-spacing: 1px;
}

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.hidden {
  display: none;
}

html,
body {
  height: 100%;
  overflow: auto;
}

body {
  font-family: "Rajdhani", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 100vh;
  background-image: radial-gradient(
      ellipse at 20% 20%,
      rgba(0, 245, 255, 0.05) 0%,
      transparent 50%
    ),
    radial-gradient(
      ellipse at 80% 80%,
      rgba(255, 0, 255, 0.05) 0%,
      transparent 50%
    ),
    linear-gradient(to bottom, var(--bg-primary), var(--bg-secondary));
  background-attachment: fixed;
}

/* ===== Game Container ===== */
.game-container {
  width: 100%;
  max-width: 1600px;
  min-height: 100vh;
  height: auto;
  max-height: none;
  padding: 10px 30px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: visible;
}

/* ===== Header ===== */
.game-header {
  text-align: center;
  padding: 5px 0;
  flex-shrink: 0;
}

.title {
  font-family: "Orbitron", monospace;
  font-size: clamp(1.5rem, 3vw, 2.5rem);
  font-weight: 900;
  letter-spacing: 6px;
  margin-bottom: 2px;
}

.title-tetris {
  background: linear-gradient(
    135deg,
    var(--human-primary),
    var(--human-secondary)
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 0 0 40px var(--human-glow);
}

.title-battle {
  background: linear-gradient(135deg, var(--ai-primary), var(--ai-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-left: 15px;
}

.title-subtitle {
  font-family: "Orbitron", monospace;
  font-size: 1rem;
  color: var(--text-secondary);
  letter-spacing: 12px;
  font-weight: 500;
}

/* ===== Live Scoreboard ===== */
.live-scoreboard {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  padding: 10px 25px;
  background: var(--card-bg);
  border-radius: 16px;
  border: 1px solid var(--border-color);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
}

.scoreboard-player {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 200px;
}

.human-scoreboard {
  justify-content: flex-end;
}

.ai-scoreboard {
  justify-content: flex-start;
}

.scoreboard-icon {
  font-size: 1.5rem;
}

.scoreboard-name {
  font-family: "Orbitron", monospace;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--text-secondary);
}

.scoreboard-score {
  font-family: "Orbitron", monospace;
  font-size: 2rem;
  font-weight: 900;
  min-width: 80px;
  text-align: center;
}

.human-scoreboard .scoreboard-score {
  color: var(--human-primary);
  text-shadow: 0 0 20px var(--human-glow);
}

.ai-scoreboard .scoreboard-score {
  color: var(--ai-primary);
  text-shadow: 0 0 20px var(--ai-glow);
}

.scoreboard-leader {
  font-size: 1.2rem;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.scoreboard-leader.visible {
  opacity: 1;
  animation: crownBounce 1s ease infinite;
}

@keyframes crownBounce {
  0%,
  100% {
    transform: translateY(0) rotate(-5deg);
  }
  50% {
    transform: translateY(-3px) rotate(5deg);
  }
}

.scoreboard-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 200px;
}

.score-bar-container {
  width: 100%;
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  display: flex;
  overflow: hidden;
  position: relative;
}

.score-bar {
  height: 100%;
  transition: width 0.5s ease;
  position: absolute;
  top: 0;
}

.human-bar {
  left: 0;
  background: linear-gradient(
    90deg,
    var(--human-secondary),
    var(--human-primary)
  );
  border-radius: 4px 0 0 4px;
  box-shadow: 0 0 10px var(--human-glow);
}

.ai-bar {
  right: 0;
  background: linear-gradient(90deg, var(--ai-primary), var(--ai-secondary));
  border-radius: 0 4px 4px 0;
  box-shadow: 0 0 10px var(--ai-glow);
}

.game-timer {
  display: flex;
  align-items: center;
  gap: 8px;
}

.timer-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 2px;
}

.timer-value {
  font-family: "Orbitron", monospace;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent-gold);
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

/* Score change animation */
.scoreboard-score.score-up {
  animation: scoreUp 0.3s ease;
}

@keyframes scoreUp {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}

/* ===== Battle Arena ===== */
.battle-arena {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
}

/* ===== Player Section ===== */
.player-section {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 10px;
  padding: 0;
  background: transparent;
  border-radius: 0;
  border: none;
  backdrop-filter: none;
  position: relative;
  min-height: 0;
  max-height: 100%;
  flex: 0 1 auto;
  overflow: visible;
}

.human-section {
  border-color: rgba(0, 245, 255, 0.2);
}

.ai-section {
  border-color: rgba(255, 0, 255, 0.2);
}

/* Top accent lines on board wrappers */
.game-board-wrapper::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  border-radius: 12px 12px 0 0;
}

.human-section .game-board-wrapper::before {
  background: linear-gradient(
    90deg,
    transparent,
    var(--human-primary),
    transparent
  );
}

.ai-section .game-board-wrapper::before {
  background: linear-gradient(
    90deg,
    transparent,
    var(--ai-primary),
    transparent
  );
}

/* ===== Player Header ===== */
/* ===== Player Sidebar ===== */
.player-sidebar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px 10px;
  background: var(--card-bg);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  backdrop-filter: blur(10px);
  width: 120px;
  flex-shrink: 0;
}

.human-section .player-sidebar {
  border-color: rgba(0, 245, 255, 0.2);
}

.ai-section .player-sidebar {
  border-color: rgba(255, 0, 255, 0.2);
}

.sidebar-identity {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}

.sidebar-stats {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.sidebar-stats .stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 8px;
  background: var(--bg-tertiary);
  border-radius: 8px;
}

.sidebar-stats .stat-label {
  font-size: 0.5rem;
  letter-spacing: 1px;
}

.sidebar-stats .stat-value {
  font-size: 1rem;
}

.player-icon {
  font-size: 1.5rem;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: var(--bg-tertiary);
}

.human-icon {
  box-shadow: 0 0 20px var(--human-glow);
}

.ai-icon {
  box-shadow: 0 0 20px var(--ai-glow);
}

.player-name {
  font-family: "Orbitron", monospace;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-align: center;
  line-height: 1.2;
  word-break: break-word;
}

.human-section .player-name {
  color: var(--human-primary);
}

/* When player 1 section is AI controlled */
.human-section.ai-controlled .player-name {
  color: var(--ai-primary);
}

.human-section.ai-controlled .player-icon {
  background: linear-gradient(135deg, var(--ai-primary), var(--ai-secondary));
  box-shadow: 0 0 20px var(--ai-glow);
}

.human-section.ai-controlled .human-glow {
  background: radial-gradient(
    ellipse at center,
    var(--ai-glow) 0%,
    transparent 70%
  );
}

.ai-section .player-name {
  color: var(--ai-primary);
}

/* ===== Model Selector ===== */
.player-sidebar .model-select {
  width: 100%;
}

.model-select {
  font-family: "Orbitron", monospace;
  font-size: 0.55rem;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--bg-tertiary);
  color: var(--ai-primary);
  letter-spacing: 0.5px;
  font-weight: 600;
  border: 1px solid var(--ai-primary);
  cursor: pointer;
  transition: all 0.2s ease;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23ff00ff' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 22px;
}

.model-select:hover {
  border-color: var(--ai-secondary);
  box-shadow: 0 0 15px var(--ai-glow);
}

.model-select:focus {
  outline: none;
  box-shadow: 0 0 20px var(--ai-glow);
}

.model-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 8px;
}

.model-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Player 1 Model Selector (cyan theme) */
.player1-model-select {
  color: var(--human-primary);
  border-color: var(--human-primary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2300f5ff' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}

.player1-model-select:hover {
  border-color: var(--human-secondary);
  box-shadow: 0 0 15px var(--human-glow);
}

.player1-model-select:focus {
  box-shadow: 0 0 20px var(--human-glow);
}

/* Algorithm Notice */
.algorithm-notice {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  background: rgba(0, 255, 136, 0.1);
  border: 1px solid var(--accent-green);
  border-radius: 6px;
  font-size: 0.45rem;
  color: var(--accent-green);
  letter-spacing: 0.5px;
  text-align: center;
  width: 100%;
}

.algorithm-notice.visible {
  display: flex;
}

.notice-icon {
  font-size: 0.7rem;
}

.notice-text {
  font-family: "Rajdhani", sans-serif;
  font-weight: 600;
  line-height: 1.2;
}

.status-indicator {
  font-family: "Orbitron", monospace;
  font-size: 0.55rem;
  padding: 4px 8px;
  border-radius: 12px;
  background: var(--bg-tertiary);
  color: var(--accent-green);
  letter-spacing: 1px;
  font-weight: 600;
  border: 1px solid var(--accent-green);
  animation: pulse 2s infinite;
}

.status-indicator.playing {
  color: var(--accent-gold);
  border-color: var(--accent-gold);
}

.status-indicator.defeated {
  color: var(--accent-red);
  border-color: var(--accent-red);
  animation: none;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

/* ===== Game Board ===== */
.game-board-wrapper {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  max-height: none;
  overflow: visible;
  padding: 8px;
  background: var(--card-bg);
  border-radius: 12px;
  border: 1px solid var(--border-color);
}

.human-section .game-board-wrapper {
  border-color: rgba(0, 245, 255, 0.25);
}

.ai-section .game-board-wrapper {
  border-color: rgba(255, 0, 255, 0.25);
}

.game-board {
  border-radius: 8px;
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.5), 0 0 10px rgba(0, 0, 0, 0.5);
  max-height: none;
  width: auto;
  height: auto;
  object-fit: contain;
}

.human-section .game-board {
  border: 2px solid rgba(0, 245, 255, 0.3);
}

.ai-section .game-board {
  border: 2px solid rgba(255, 0, 255, 0.3);
}

.board-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 120%;
  height: 120%;
  pointer-events: none;
  opacity: 0.3;
  filter: blur(60px);
  z-index: -1;
}

.human-glow {
  background: radial-gradient(ellipse, var(--human-primary), transparent 70%);
}

.ai-glow {
  background: radial-gradient(ellipse, var(--ai-primary), transparent 70%);
}

/* ===== Stats Panel ===== */
.stats-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.stat-row {
  display: flex;
  gap: 12px;
}

.stat-item {
  flex: 1;
  background: var(--bg-tertiary);
  padding: 8px 10px;
  border-radius: 10px;
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 2px;
  margin-bottom: 4px;
}

.stat-value {
  display: block;
  font-family: "Orbitron", monospace;
  font-size: 1.3rem;
  font-weight: 700;
}

.human-section .stat-value {
  color: var(--human-primary);
}

.ai-section .stat-value {
  color: var(--ai-primary);
}

.next-piece-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: var(--bg-tertiary);
  padding: 8px;
  border-radius: 10px;
  flex-shrink: 0;
  width: 100%;
}

.next-label {
  font-size: 0.55rem;
  color: var(--text-muted);
  letter-spacing: 1.5px;
}

.next-piece-canvas {
  border-radius: 6px;
}

/* ===== VS Divider ===== */
.vs-divider {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
}

.vs-line {
  width: 2px;
  flex: 1;
  background: linear-gradient(
    to bottom,
    transparent,
    var(--border-color),
    transparent
  );
}

.vs-badge {
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border-radius: 50%;
  border: 2px solid var(--border-color);
  margin: 20px 0;
}

.vs-text {
  font-family: "Orbitron", monospace;
  font-size: 1.2rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--human-primary), var(--ai-primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ===== Controls Area ===== */
.controls-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  flex-shrink: 0;
}

/* Mobile AI Model Selector - hidden on desktop */
.mobile-model-selector {
  display: none;
}

@media (max-width: 768px) {
  .controls-area {
    gap: 6px;
    position: relative;
    z-index: 5;
  }

  .mobile-model-selector {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    height: 30px;
    background: rgba(10, 10, 18, 0.9);
    border-radius: 16px;
    border: 1px solid rgba(255, 0, 255, 0.25);
    box-shadow: 0 0 10px rgba(255, 0, 255, 0.12);
    margin-bottom: 2px;
    max-width: 92vw;
  }

  .mobile-model-label {
    font-family: "Orbitron", monospace;
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    white-space: nowrap;
  }

  .mobile-ai-select {
    color: var(--ai-primary);
    border: none;
    background: transparent;
    font-size: 0.6rem;
    padding: 2px 22px 2px 6px;
    border-radius: 12px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23ff00ff' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
    line-height: 1;
    max-width: 70vw;
    text-overflow: ellipsis;
    overflow: hidden;
  }

  .mobile-ai-select:hover {
    box-shadow: none;
  }
}

.game-btn {
  font-family: "Orbitron", monospace;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 3px;
  padding: 15px 40px;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all 0.3s ease;
  text-decoration: none;
}

.game-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
}

.leaderboard-btn {
  background: linear-gradient(135deg, var(--accent-gold), #ffb700);
  color: var(--bg-primary);
  box-shadow: 0 0 30px rgba(255, 215, 0, 0.35);
}

.leaderboard-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 45px rgba(255, 215, 0, 0.6);
}

.bench-btn {
  background: linear-gradient(135deg, var(--ai-primary), var(--ai-secondary));
  color: #fff;
  box-shadow: 0 0 30px rgba(255, 0, 255, 0.35);
}

.bench-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 45px rgba(255, 0, 255, 0.6);
}

.start-btn {
  background: linear-gradient(135deg, var(--accent-green), #00cc6a);
  color: var(--bg-primary);
  box-shadow: 0 0 30px rgba(0, 255, 136, 0.4);
}

.start-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 50px rgba(0, 255, 136, 0.6);
}

.restart-btn {
  background: linear-gradient(135deg, var(--accent-gold), #ffaa00);
  color: var(--bg-primary);
  box-shadow: 0 0 30px rgba(255, 215, 0, 0.4);
}

.restart-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 50px rgba(255, 215, 0, 0.6);
}

.pause-btn {
  background: linear-gradient(135deg, var(--accent-gold), #cc9900);
  color: var(--bg-primary);
  box-shadow: 0 0 30px rgba(255, 215, 0, 0.4);
}

.pause-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 50px rgba(255, 215, 0, 0.6);
}

.pause-btn.paused {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  box-shadow: 0 0 30px rgba(34, 197, 94, 0.4);
}

.pause-btn.paused:hover {
  box-shadow: 0 0 50px rgba(34, 197, 94, 0.6);
}

.abandon-btn {
  background: linear-gradient(135deg, var(--accent-red), #cc0033);
  color: var(--text-primary);
  box-shadow: 0 0 30px rgba(255, 71, 87, 0.4);
}

.abandon-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 50px rgba(255, 71, 87, 0.6);
}

.button-group {
  display: flex;
  gap: 15px;
  align-items: center;
}

.btn-icon {
  font-size: 1.2rem;
}

.controls-help {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  justify-content: center;
}

.control-key {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  letter-spacing: 1px;
}

/* ===== Winner Overlay ===== */
.winner-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(5, 5, 8, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.5s ease;
}

.winner-overlay.hidden {
  display: none;
}

/* ===== Leaderboard ===== */
.leaderboard-content {
  width: min(760px, 94vw);
}

.leaderboard-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  justify-content: center;
}

.leaderboard-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  letter-spacing: 1px;
}

.leaderboard-table-container {
  overflow-x: auto;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-family: "Rajdhani", sans-serif;
}

.leaderboard-table th {
  font-family: "Orbitron", monospace;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 2px;
  text-align: left;
  padding: 12px 15px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-tertiary);
}

.leaderboard-table td {
  padding: 12px 15px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.95rem;
}

.leaderboard-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* ===== Loading Overlay ===== */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(5, 5, 8, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100;
  animation: fadeIn 0.3s ease;
}

.loading-overlay.hidden {
  display: none;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.loading-spinner {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 4px solid rgba(0, 245, 255, 0.2);
  border-top-color: var(--human-primary);
  animation: spin 0.9s linear infinite;
}

.loading-title {
  font-family: "Orbitron", monospace;
  letter-spacing: 3px;
  font-size: 1rem;
  color: var(--human-primary);
}

.loading-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  letter-spacing: 1px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.winner-content {
  text-align: center;
  animation: popIn 0.5s ease;
}

@keyframes popIn {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.winner-crown {
  font-size: 5rem;
  animation: bounce 1s infinite;
}

@keyframes bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

.winner-title {
  font-family: "Orbitron", monospace;
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: 8px;
  margin: 20px 0 10px;
  background: linear-gradient(135deg, var(--accent-gold), #ffaa00);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.winner-title.human-wins {
  background: linear-gradient(
    135deg,
    var(--human-primary),
    var(--human-secondary)
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.winner-title.ai-wins {
  background: linear-gradient(135deg, var(--ai-primary), var(--ai-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.winner-subtitle {
  font-size: 1.2rem;
  color: var(--text-secondary);
  letter-spacing: 3px;
}

.winner-stats {
  margin-top: 30px;
  display: flex;
  gap: 40px;
  justify-content: center;
}

.winner-stats .stat-box {
  background: var(--bg-tertiary);
  padding: 20px 30px;
  border-radius: 15px;
  min-width: 150px;
}

.winner-stats .stat-box h4 {
  font-size: 0.8rem;
  color: var(--text-muted);
  letter-spacing: 2px;
  margin-bottom: 10px;
}

.winner-stats .stat-box .value {
  font-family: "Orbitron", monospace;
  font-size: 1.8rem;
  font-weight: 700;
}

.play-again-btn {
  display: block;
  margin: 30px auto 0;
  background: linear-gradient(135deg, var(--accent-gold), #ffaa00);
  color: var(--bg-primary);
  border: none;
  padding: 15px 50px;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

.play-again-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 30px rgba(255, 215, 0, 0.5);
}

/* ===== Animations ===== */
@keyframes glow {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.2);
  }
}

.playing .game-board {
  animation: glow 2s infinite;
}

/* ===== Responsive ===== */

/* Large screens - reduce padding */
@media (max-width: 1500px) {
  .game-container {
    padding: 12px 20px;
    gap: 8px;
  }

  .title {
    font-size: 2rem;
  }

  .battle-arena {
    gap: 15px;
  }

  .player-section {
    gap: 8px;
  }

  .player-sidebar {
    width: 100px;
    padding: 10px 8px;
    gap: 8px;
  }

  .player-icon {
    width: 30px;
    height: 30px;
    font-size: 1.2rem;
  }

  .player-name {
    font-size: 0.6rem;
  }

  .stat-item {
    padding: 8px 10px;
  }

  .stat-value {
    font-size: 1.1rem;
  }
}

/* Medium screens - stack vertically */
@media (max-width: 1100px) {
  .game-container {
    padding: 10px 15px;
  }

  .title {
    font-size: 1.8rem;
  }

  .battle-arena {
    flex-direction: column;
    align-items: center;
    gap: 10px;
  }

  .player-section {
    width: 100%;
    max-width: 500px;
    padding: 12px;
  }

  .vs-divider {
    flex-direction: row;
    padding: 5px 0;
    width: 100%;
    max-width: 450px;
  }

  .vs-line {
    height: 2px;
    width: auto;
    flex: 1;
    background: linear-gradient(
      to right,
      transparent,
      var(--border-color),
      transparent
    );
  }

  .vs-badge {
    margin: 0 15px;
    width: 40px;
    height: 40px;
  }

  .vs-text {
    font-size: 0.9rem;
  }

  .player-header {
    width: 100%;
    flex-wrap: wrap;
    gap: 10px;
  }

  .game-board-wrapper {
    flex: 0 0 auto;
  }

  .stats-panel {
    width: 100%;
  }

  .stat-row {
    justify-content: center;
  }

  .live-scoreboard {
    padding: 10px 15px;
    gap: 10px;
  }

  .scoreboard-player {
    min-width: auto;
    gap: 8px;
  }

  .scoreboard-score {
    font-size: 1.4rem;
    min-width: 60px;
  }

  .scoreboard-center {
    min-width: 120px;
  }

  .scoreboard-name {
    display: none;
  }
}

@media (max-width: 768px) {
  .game-container {
    padding: 8px 6px;
    gap: 10px;
  }

  .game-header {
    padding: 5px 0;
  }

  .title {
    font-size: 1.5rem;
    letter-spacing: 4px;
  }

  .title-battle {
    margin-left: 8px;
  }

  .title-subtitle {
    font-size: 0.7rem;
    letter-spacing: 6px;
  }

  .live-scoreboard {
    padding: 8px 10px;
    border-radius: 10px;
  }

  .scoreboard-icon {
    font-size: 1.2rem;
  }

  .scoreboard-score {
    font-size: 1.2rem;
    min-width: 50px;
  }

  .scoreboard-center {
    min-width: 80px;
  }

  .timer-value {
    font-size: 0.9rem;
  }

  .player-section {
    width: 100%;
    max-width: none;
    flex-direction: row;
    gap: 6px;
    gap: 8px;
  }

  .player-header {
    gap: 8px;
    padding-bottom: 8px;
  }

  .player-icon {
    font-size: 1.5rem;
    width: 36px;
    height: 36px;
    border-radius: 8px;
  }

  .player-name {
    font-size: 1rem;
    letter-spacing: 2px;
  }

  .model-selector {
    margin-left: 0;
    margin-right: 0;
  }

  .model-select {
    font-size: 0.55rem;
    padding: 4px 24px 4px 8px;
  }

  .status-indicator {
    font-size: 0.55rem;
    padding: 4px 8px;
  }

  .stat-item {
    padding: 6px 8px;
  }

  .stat-label {
    font-size: 0.55rem;
  }

  .stat-value {
    font-size: 1rem;
  }

  .next-piece-container {
    padding: 6px 10px;
    gap: 10px;
  }

  .next-label {
    font-size: 0.6rem;
  }

  .controls-area {
    padding: 10px 0;
    gap: 10px;
  }

  .game-btn {
    font-size: 0.8rem;
    padding: 12px 30px;
  }

  .controls-help {
    gap: 10px;
  }

  .control-key {
    font-size: 0.65rem;
    padding: 4px 8px;
  }

  .vs-badge {
    width: 35px;
    height: 35px;
    margin: 0 10px;
  }

  .vs-text {
    font-size: 0.8rem;
  }

  /* Winner overlay mobile */
  .winner-crown {
    font-size: 3rem;
  }

  .winner-title {
    font-size: 1.8rem;
    letter-spacing: 4px;
  }

  .winner-subtitle {
    font-size: 0.9rem;
    letter-spacing: 2px;
  }

  .winner-stats {
    flex-direction: column;
    gap: 15px;
  }

  .winner-stats .stat-box {
    padding: 15px 20px;
    min-width: auto;
  }

  .winner-stats .stat-box .value {
    font-size: 1.4rem;
  }

  .play-again-btn {
    margin-top: 20px;
    padding: 12px 40px;
    font-size: 1rem;
  }
}

@media (max-width: 480px) {
  .game-container {
    padding: 5px 4px;
    gap: 6px;
  }

  .top-nav {
    padding: 4px 0;
  }

  .nav-links {
    gap: 2px;
  }

  .nav-link {
    padding: 4px 8px;
    font-size: 0.75rem;
  }

  .nav-link .nav-text {
    display: none;
  }

  .nav-link .nav-icon {
    font-size: 1rem;
  }

  .title {
    font-size: 1.2rem;
    letter-spacing: 2px;
  }

  .title-subtitle {
    font-size: 0.6rem;
    letter-spacing: 4px;
  }

  .live-scoreboard {
    flex-wrap: wrap;
    justify-content: space-around;
    padding: 6px 8px;
  }

  .scoreboard-center {
    order: -1;
    width: 100%;
    margin-bottom: 5px;
  }

  .scoreboard-player {
    flex: 1;
    justify-content: center;
  }

  .player-section {
    width: 100%;
    max-width: none;
    padding: 8px;
    border-radius: 10px;
  }

  .player-header {
    justify-content: center;
    text-align: center;
    flex-wrap: nowrap;
    gap: 6px;
  }

  .player-name {
    flex: none;
    font-size: 0.9rem;
  }

  .player-icon {
    width: 32px;
    height: 32px;
    font-size: 1.2rem;
  }

  .model-selector {
    width: auto;
    margin-left: auto;
    margin-top: 0;
  }

  .status-indicator {
    margin-top: 0;
  }

  .stat-row {
    gap: 6px;
  }

  .stat-item {
    padding: 5px 6px;
  }

  .stat-label {
    font-size: 0.5rem;
  }

  .stat-value {
    font-size: 0.9rem;
  }

  .next-piece-container {
    padding: 5px 8px;
  }

  .game-btn {
    font-size: 0.7rem;
    padding: 10px 20px;
    letter-spacing: 2px;
  }

  .btn-icon {
    font-size: 1rem;
  }

  .control-key {
    font-size: 0.6rem;
    padding: 3px 6px;
  }

  /* Make battle arena full width */
  .battle-arena {
    gap: 6px;
  }

  .vs-divider {
    padding: 3px 0;
  }

  .vs-badge {
    width: 30px;
    height: 30px;
  }

  .vs-text {
    font-size: 0.7rem;
  }
}

/* ===== Mobile Touch Controls ===== */
.mobile-controls {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 100;
  padding: 10px 15px 20px;
  background: linear-gradient(
    to top,
    rgba(5, 5, 8, 0.98) 0%,
    rgba(5, 5, 8, 0.95) 70%,
    transparent 100%
  );
  backdrop-filter: blur(10px);
}

.mobile-controls.hidden {
  display: none;
}

.mobile-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid var(--human-primary);
  background: rgba(0, 245, 255, 0.15);
  color: var(--human-primary);
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.mobile-btn:active {
  transform: scale(0.92);
  background: rgba(0, 245, 255, 0.4);
  box-shadow: 0 0 15px var(--human-glow);
}

.mobile-btn-icon {
  pointer-events: none;
}

.rotate-btn {
  border-color: var(--accent-gold);
  background: rgba(255, 215, 0, 0.15);
  color: var(--accent-gold);
}

.rotate-btn:active {
  background: rgba(255, 215, 0, 0.4);
  box-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
}

.drop-btn {
  width: 58px;
  height: 58px;
  border-color: var(--accent-green);
  background: rgba(0, 255, 136, 0.15);
  color: var(--accent-green);
  font-size: 1.5rem;
}

.drop-btn:active {
  background: rgba(0, 255, 136, 0.4);
  box-shadow: 0 0 20px rgba(0, 255, 136, 0.5);
}

.soft-drop-btn {
  border-color: var(--ai-primary);
  background: rgba(255, 0, 255, 0.15);
  color: var(--ai-primary);
}

.soft-drop-btn:active {
  background: rgba(255, 0, 255, 0.4);
  box-shadow: 0 0 15px var(--ai-glow);
}

/* Hide keyboard controls help on mobile when touch controls are visible */
@media (max-width: 768px) {
  .controls-help {
    display: none;
  }

  /* Adjust game container to make room for mobile controls */
  .game-container {
    padding-bottom: 90px;
  }

  /* Make game board fill available width */
  .game-board-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
  }

  .game-board {
    max-width: 100%;
  }

  /* Adjust stats panel for mobile */
  .stats-panel {
    gap: 6px;
  }

  .next-piece-container {
    justify-content: center;
  }

  /* Mobile controls layout - horizontal bar at bottom */
  .mobile-controls {
    gap: 10px;
    padding: 8px 15px 18px;
  }
}

/* Smaller touch controls on small screens */
@media (max-width: 480px) {
  .mobile-controls {
    padding: 6px 10px 14px;
    gap: 8px;
  }

  .mobile-btn {
    width: 46px;
    height: 46px;
    font-size: 1.1rem;
  }

  .drop-btn {
    width: 52px;
    height: 52px;
    font-size: 1.3rem;
  }
}

/* ===== Mobile Battle Layout - Side by Side with Mini AI ===== */
@media (max-width: 768px) {
  /* Reorder layout: auth, header, scoreboard, controls, then battle */
  .game-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    height: auto;
    padding-bottom: 10px;
  }

  .auth-bar {
    order: 1;
  }

  .game-header {
    order: 2;
  }

  .live-scoreboard {
    order: 3;
  }

  /* Move controls above the battle arena */
  .controls-area {
    order: 4;
    padding: 8px 0;
  }

  .battle-arena {
    order: 5;
    flex-direction: row;
    align-items: flex-end;
    gap: 10px;
    flex: 1;
    min-height: 0;
    overflow: visible;
  }

  /* Human player - takes most of the space */
  .human-section {
    flex: 1;
    min-width: 0;
    max-width: none;
  }

  /* Sidebar adjustments for mobile */
  .player-sidebar {
    width: 85px;
    padding: 8px 6px;
    gap: 6px;
  }

  .sidebar-stats .stat-item {
    padding: 4px 6px;
  }

  .sidebar-stats .stat-label {
    font-size: 0.4rem;
  }

  .sidebar-stats .stat-value {
    font-size: 0.85rem;
  }

  .player-name {
    font-size: 0.55rem;
  }

  .player-icon {
    width: 28px;
    height: 28px;
    font-size: 1rem;
  }

  /* Remove outer frames on mobile for a cleaner look */
  .player-section,
  .human-section,
  .ai-section {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 4px 0 0;
    overflow: visible;
  }

  .player-section::before {
    display: none;
  }

  /* Position next piece to the left of the human board on mobile */
  .human-section {
    position: relative;
    margin-left: 80px;
  }

  .human-section .next-piece-container {
    position: absolute;
    left: -88px;
    top: 83%;
    transform: translateY(-50%);
    flex-direction: column;
    padding: 6px;
    gap: 4px;
    background: var(--bg-tertiary);
    border: 1px solid rgba(0, 245, 255, 0.3);
    border-radius: 8px;
    z-index: 10;
    transform-origin: center;
    scale: 0.7;
  }

  .human-section .next-label {
    font-size: 0.5rem;
    text-align: center;
  }

  /* AI player - sleek mini preview pane */
  .ai-section {
    flex: 0 0 90px;
    min-width: 90px;
    max-width: 90px;
    padding: 0;
    gap: 6px;
  }

  .ai-section .player-header {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding-bottom: 4px;
  }

  .ai-section .player-icon {
    width: 22px;
    height: 22px;
    font-size: 0.75rem;
    border-radius: 6px;
    background: rgba(255, 0, 255, 0.2);
    box-shadow: 0 0 8px rgba(255, 0, 255, 0.3);
  }

  .ai-section .player-name {
    font-size: 0.65rem;
    letter-spacing: 1px;
  }

  .ai-section .model-selector {
    display: none;
  }

  .ai-section .status-indicator {
    display: none;
  }

  .ai-section .game-board-wrapper {
    flex: 1;
    min-height: 0;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .ai-section .game-board {
    max-width: 100%;
    max-height: 100%;
    border-width: 1px;
    border-radius: 4px;
    box-shadow: 0 0 10px rgba(255, 0, 255, 0.15);
  }

  .ai-section .board-glow {
    display: none;
  }

  /* Simplified AI stats - only show score */
  .ai-section .stats-panel {
    gap: 0;
  }

  .ai-section .stat-row {
    flex-direction: row;
    justify-content: center;
    gap: 8px;
  }

  .ai-section .stat-item {
    padding: 4px 6px;
    border-radius: 6px;
    background: rgba(255, 0, 255, 0.08);
    flex: none;
  }

  /* Hide lines and level on AI mini pane */
  .ai-section .stat-item:nth-child(2),
  .ai-section .stat-item:nth-child(3) {
    display: none;
  }

  .ai-section .stat-label {
    font-size: 0.4rem;
    margin-bottom: 2px;
    color: rgba(255, 0, 255, 0.6);
  }

  .ai-section .stat-value {
    font-size: 0.75rem;
  }

  /* Hide next piece preview on AI - too cramped */
  .ai-section .next-piece-container {
    display: none;
  }

  /* Hide VS divider on mobile battle layout */
  .vs-divider {
    display: none;
  }

  /* Compact button group */
  .button-group {
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
  }

  .game-btn {
    padding: 12px 20px;
    font-size: 0.7rem;
    letter-spacing: 1px;
    border-radius: 30px;
  }

  .btn-icon {
    font-size: 1rem;
  }

  /* Make game container room for mobile controls bar */
  .game-container {
    padding-bottom: calc(110px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 480px) {
  /* Even smaller AI preview on very small screens */
  .ai-section {
    flex: 0 0 70px;
    min-width: 70px;
    max-width: 70px;
    padding: 0;
    gap: 4px;
  }

  .ai-section .player-header {
    gap: 4px;
    padding-bottom: 4px;
  }

  .ai-section .player-icon {
    width: 18px;
    height: 18px;
    font-size: 0.65rem;
  }

  .ai-section .player-name {
    font-size: 0.55rem;
    letter-spacing: 0.5px;
  }

  .ai-section .stat-item {
    padding: 3px 5px;
  }

  .ai-section .stat-label {
    font-size: 0.35rem;
  }

  .ai-section .stat-value {
    font-size: 0.65rem;
  }

  /* Smaller buttons */
  .game-btn {
    padding: 10px 14px;
    font-size: 0.6rem;
    gap: 6px;
  }

  .btn-icon {
    font-size: 0.85rem;
  }

  /* Adjust human section to fit better */
  .human-section {
    padding: 0;
    gap: 6px;
    margin-left: 70px;
  }

  .human-section .player-header {
    gap: 6px;
    padding-bottom: 6px;
  }

  .human-section .player-icon {
    width: 28px;
    height: 28px;
    font-size: 1rem;
  }

  .human-section .player-name {
    font-size: 0.85rem;
  }

  .human-section .stat-item {
    padding: 5px 6px;
  }

  .human-section .stat-label {
    font-size: 0.5rem;
  }

  .human-section .stat-value {
    font-size: 0.9rem;
  }

  /* Smaller next piece box on tiny screens */
  .human-section .next-piece-container {
    left: -70px;
    padding: 4px;
    scale: 0.65;
  }

  .human-section .next-label {
    font-size: 0.45rem;
  }

  /* Smaller live scoreboard */
  .live-scoreboard {
    padding: 6px 8px;
    gap: 8px;
    border-radius: 10px;
  }

  .scoreboard-icon {
    font-size: 1.1rem;
  }

  .scoreboard-score {
    font-size: 1.1rem;
    min-width: 45px;
  }

  .scoreboard-center {
    min-width: 70px;
  }

  .timer-label {
    font-size: 0.5rem;
  }

  .timer-value {
    font-size: 0.8rem;
  }

  /* Compact header */
  .game-header {
    padding: 3px 0;
  }

  .title {
    font-size: 1.1rem;
    letter-spacing: 3px;
    margin-bottom: 0;
  }

  .title-subtitle {
    font-size: 0.55rem;
    letter-spacing: 4px;
  }
}
