* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: radial-gradient(circle at 50% 20%, #1e1b4b 0%, #0f172a 60%, #020617 100%);
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #f8fafc;
  display: flex;
  justify-content: center;
  align-items: center;
}

.game-wrapper {
  width: 100%;
  height: 100%;
  max-width: 920px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  gap: 6px;
  box-sizing: border-box;
  overflow: hidden;
}

/* Header & Brand */
.game-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  gap: 12px;
  padding: 0 2px;
}

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

.brand-glow-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #38bdf8;
  box-shadow: 0 0 12px #38bdf8, 0 0 20px #0284c7;
  animation: pulse-dot 2s infinite ease-in-out;
}

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.7; }
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: 1.5px;
  color: #ffffff;
  text-shadow: 0 2px 10px rgba(255, 255, 255, 0.2);
}

.brand-title span {
  color: #38bdf8;
  text-shadow: 0 0 15px rgba(56, 189, 248, 0.6);
}

/* Mode Selector Switch */
.mode-selector {
  display: flex;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 3px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: #94a3b8;
  padding: 5px 14px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.mode-btn:hover {
  color: #ffffff;
}

.mode-btn.active {
  background: linear-gradient(135deg, #0284c7 0%, #2563eb 100%);
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(2, 132, 199, 0.4);
}

.mode-icon {
  font-size: 0.9rem;
}

/* Sound Button */
.sound-toggle {
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #f8fafc;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
  outline: none;
}

.sound-toggle:hover {
  transform: scale(1.08);
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(255, 255, 255, 0.25);
}

.sound-toggle svg {
  width: 17px;
  height: 17px;
  fill: currentColor;
}

/* Match Scoreboard */
.match-scoreboard {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 6px 18px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  flex-shrink: 0;
}

.player-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.player-card.right-player {
  justify-content: flex-end;
}

.player-avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 0.95rem;
}

.p1-avatar {
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  color: #ffffff;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

.p2-avatar {
  background: linear-gradient(135deg, #ec4899, #f43f5e);
  color: #ffffff;
  box-shadow: 0 0 12px rgba(244, 63, 94, 0.4);
}

.player-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.player-info.text-right {
  text-align: right;
}

.player-name {
  font-weight: 800;
  font-size: 0.85rem;
  color: #f8fafc;
}

.player-controls-badge {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.8px;
  color: #94a3b8;
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 6px;
  border-radius: 4px;
  display: inline-block;
  align-self: flex-start;
}

.player-info.text-right .player-controls-badge {
  align-self: flex-end;
}

.player-score {
  font-family: 'Press Start 2P', monospace, sans-serif;
  font-size: 1.5rem;
  font-weight: 900;
  color: #ffffff;
  min-width: 35px;
  text-align: center;
}

.left-player .player-score {
  color: #38bdf8;
  text-shadow: 0 0 12px rgba(56, 189, 248, 0.6);
}

.right-player .player-score {
  color: #f43f5e;
  text-shadow: 0 0 12px rgba(244, 63, 94, 0.6);
}

.match-divider {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.first-to {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 1.2px;
  color: #38bdf8;
  text-transform: uppercase;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.25);
  padding: 2px 7px;
  border-radius: 5px;
  transition: all 0.3s ease;
}

.first-to.lvl-mid {
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.12);
  border-color: rgba(251, 191, 36, 0.35);
  box-shadow: 0 0 8px rgba(251, 191, 36, 0.2);
}

.first-to.lvl-high {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.35);
  animation: pulse-dot 1.5s infinite ease-in-out;
}

.vs-badge {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.68rem;
  color: #ffd166;
  background: rgba(255, 209, 102, 0.1);
  border: 1px solid rgba(255, 209, 102, 0.3);
  padding: 2px 8px;
  border-radius: 6px;
}

/* Canvas Container & Arena - Auto Flex Scaling */
.canvas-container {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 18px;
  background: #020617;
  border: 2px solid rgba(56, 189, 248, 0.25);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55), 0 0 25px rgba(2, 132, 199, 0.12);
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #030712;
  cursor: grab;
}

canvas:active {
  cursor: grabbing;
}

/* Arena Overlay Card (Start / Pause Screens) */
.arena-overlay {
  position: absolute;
  inset: 0;
  background: rgba(3, 7, 18, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 20;
  transition: opacity 0.3s ease, visibility 0.3s;
}

.arena-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay-content {
  text-align: center;
  padding: 16px;
}

.overlay-icon {
  font-size: 2.4rem;
  margin-bottom: 4px;
  animation: bounce 2s infinite ease-in-out;
}

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

.overlay-title {
  font-size: 1.6rem;
  font-weight: 900;
  color: #ffffff;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.overlay-sub {
  color: #94a3b8;
  font-size: 0.85rem;
  margin-bottom: 18px;
}

.overlay-btn {
  background: linear-gradient(135deg, #0284c7 0%, #2563eb 100%);
  border: none;
  color: #ffffff;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 11px 30px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(2, 132, 199, 0.45);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.overlay-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 25px rgba(2, 132, 199, 0.6);
}

/* Control Bar Actions */
.controls-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  flex-shrink: 0;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  padding: 7px 18px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
}

.btn-icon {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

.btn-primary {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.35);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(16, 185, 129, 0.5);
}

.btn-secondary {
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

.btn-secondary:hover {
  transform: translateY(-2px);
  background: rgba(51, 65, 85, 0.95);
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: #ffffff;
  box-shadow: 0 6px 16px rgba(239, 68, 68, 0.35);
}

.btn-danger:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(239, 68, 68, 0.5);
}

.action-btn:active {
  transform: translateY(1px);
}

/* Key Hints Legend */
.key-hints {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  color: #64748b;
  font-size: 0.72rem;
  font-weight: 600;
  flex-shrink: 0;
}

.hint-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 3px 10px;
  border-radius: 999px;
}

.hint-key {
  background: rgba(255, 255, 255, 0.15);
  color: #f8fafc;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 800;
}

/* Winner Celebration Modal */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.modal.show {
  display: flex;
  opacity: 1;
}

.modal-dialog {
  max-width: 380px;
  width: 90%;
  margin: auto;
}

.modal-content {
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 24px;
  padding: 30px 24px;
  text-align: center;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  transform: scale(0.9);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal.show .modal-content {
  transform: scale(1);
}

.modal-trophy {
  font-size: 3rem;
  margin-bottom: 4px;
  animation: bounce 2s infinite ease-in-out;
}

.modal-tag {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: #ffd166;
  margin-bottom: 4px;
}

.modal-title {
  font-size: 1.6rem;
  font-weight: 900;
  color: #ffffff;
  margin-bottom: 4px;
}

.modal-sub {
  color: #94a3b8;
  font-size: 0.85rem;
  margin-bottom: 20px;
}

.modal-match-summary {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  background: rgba(30, 41, 59, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 10px 20px;
  margin-bottom: 20px;
}

.summary-score {
  font-family: 'Press Start 2P', monospace;
  font-size: 1.6rem;
  font-weight: 900;
}

.summary-score.p1-glow {
  color: #38bdf8;
  text-shadow: 0 0 12px rgba(56, 189, 248, 0.6);
}

.summary-score.p2-glow {
  color: #f43f5e;
  text-shadow: 0 0 12px rgba(244, 63, 94, 0.6);
}

.summary-vs {
  color: #64748b;
  font-size: 1.1rem;
  font-weight: 900;
}

.modal-btn-action {
  width: 100%;
  background: linear-gradient(135deg, #0284c7 0%, #2563eb 100%);
  border: none;
  color: #ffffff;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 14px;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(2, 132, 199, 0.45);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-btn-action:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 25px rgba(2, 132, 199, 0.6);
}

@media (max-width: 640px) {
  .game-wrapper {
    padding: 6px 8px;
    gap: 4px;
  }
  .brand-title {
    font-size: 1rem;
  }
  .mode-btn {
    padding: 4px 10px;
    font-size: 0.72rem;
  }
  .match-scoreboard {
    padding: 4px 10px;
    gap: 8px;
  }
  .player-name {
    font-size: 0.75rem;
  }
  .player-score {
    font-size: 1.2rem;
    min-width: 25px;
  }
  .action-btn {
    padding: 6px 14px;
    font-size: 0.75rem;
  }
}
