* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

#app {
  width: 100%;
  max-width: 600px;
  position: relative;
}

.screen {
  background: white;
  border-radius: 20px;
  padding: 40px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.hidden {
  display: none !important;
}

h1 {
  text-align: center;
  color: #333;
  margin-bottom: 30px;
  font-size: 2.5em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.title-icon {
  font-size: 40px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  font-weight: bold;
  letter-spacing: 2px;
  font-family: 'Courier New', monospace;
}

.input-group {
  margin-bottom: 20px;
}

label {
  display: block;
  margin-bottom: 8px;
  color: #555;
  font-weight: 600;
}

input[type="text"] {
  width: 100%;
  padding: 12px;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
  transition: border-color 0.3s;
}

input[type="text"]:focus {
  outline: none;
  border-color: #667eea;
}

.name-hint {
  font-size: 12px;
  color: #999;
  margin-top: 4px;
}

/* Layout 4: Action Cards */
.action-cards {
  display: grid;
  gap: 16px;
  margin-top: 24px;
}

.action-card {
  padding: 24px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 12px;
  transition: transform 0.2s, box-shadow 0.2s;
}

.action-card:hover {
  transform: scale(1.02);
  box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
}

.card-title {
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 16px;
}

.card-input {
  margin-bottom: 12px;
}

.card-input input {
  background: rgba(255, 255, 255, 0.9);
  width: 100%;
  padding: 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  font-size: 16px;
  transition: background 0.3s, border-color 0.3s;
}

.card-input input:focus {
  outline: none;
  background: white;
  border-color: white;
}

.card-button {
  width: 100%;
  padding: 14px;
  background: white;
  color: #667eea;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.3s, transform 0.1s;
}

.card-button:hover {
  background: #f9fafb;
}

.card-button:active {
  transform: scale(0.98);
}

button {
  width: 100%;
  padding: 14px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.3s, transform 0.1s;
  margin-bottom: 10px;
}

button:hover {
  background: #5568d3;
}

button:active {
  transform: scale(0.98);
}

button:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.divider {
  text-align: center;
  color: #999;
  margin: 20px 0;
  position: relative;
}

.divider::before,
.divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: #ddd;
}

.divider::before {
  left: 0;
}

.divider::after {
  right: 0;
}

.error {
  color: #f44336;
  text-align: center;
  margin-top: 10px;
  font-size: 14px;
  min-height: 20px;
}

/* Game Screen */
.game-header {
  margin-bottom: 30px;
}

.game-info {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 15px;
}

.game-code-display {
  font-size: 18px;
  font-weight: 600;
  color: #333;
  display: flex;
  align-items: center;
  gap: 10px;
}

.game-code-display span {
  background: #f0f0f0;
  padding: 8px 15px;
  border-radius: 6px;
  font-family: monospace;
  font-size: 20px;
  letter-spacing: 2px;
}

#copyCodeBtn {
  width: auto;
  padding: 8px 12px;
  margin: 0;
  font-size: 14px;
}

.player-name-edit {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

#currentPlayerName {
  padding: 8px 12px;
  background: #f0f0f0;
  border-radius: 6px;
}

#editNameBtn {
  width: auto;
  padding: 8px 12px;
  margin: 0;
  font-size: 14px;
  background: #667eea;
}

#editNameBtn:hover {
  background: #5568d3;
}

.players-info {
  display: flex;
  gap: 15px;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.player-symbol {
  font-weight: bold;
  font-size: 18px;
  width: 25px;
  height: 25px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f0f0;
  border-radius: 50%;
}

.player-name {
  font-weight: 600;
  color: #333;
}

.player-stats {
  font-size: 12px;
  color: #666;
  margin-left: 8px;
}

.status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ccc;
}

.status-indicator.online {
  background: #4CAF50;
  box-shadow: 0 0 8px rgba(76, 175, 80, 0.6);
}

.status-indicator.offline {
  background: #f44336;
}

.turn-indicator {
  text-align: center;
  font-size: 20px;
  font-weight: 600;
  color: #666;
  padding: 15px;
  background: #f9f9f9;
  border-radius: 10px;
}

.game-container {
  display: flex;
  justify-content: center;
  margin: 20px 0;
}

#board {
  width: 100%;
  max-width: 400px;
  height: auto;
  cursor: pointer;
}

#marks {
  pointer-events: none;
}

#marks * {
  pointer-events: none;
}

.cell {
  cursor: pointer;
  transition: fill 0.2s;
}

.cell:hover {
  fill: rgba(102, 126, 234, 0.1);
}

#winLine {
  transition: all 0.3s ease;
  stroke-dasharray: 500;
  stroke-dashoffset: 500;
  pointer-events: none;
}

#winLine:not(.hidden) {
  animation: drawLine 0.5s ease forwards;
}

@keyframes drawLine {
  to {
    stroke-dashoffset: 0;
  }
}

.game-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.game-actions button {
  flex: 1;
  background: #999;
}

.game-actions button:hover {
  background: #777;
}

/* Fireworks Animation */
#fireworks {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1000;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
}

#fireworks::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.85);
  z-index: 1;
}

.firework {
  position: fixed;
  width: 0px;
  height: 0px;
  animation: fireworkLaunch 2s ease-out infinite;
  z-index: 3;
}

.firework:nth-child(1) {
  left: 20%;
  animation-delay: 0s;
}

.firework:nth-child(2) {
  left: 40%;
  animation-delay: 0.4s;
}

.firework:nth-child(3) {
  left: 60%;
  animation-delay: 0.8s;
}

.firework:nth-child(4) {
  left: 80%;
  animation-delay: 1.2s;
}

.firework:nth-child(5) {
  left: 50%;
  animation-delay: 1.6s;
}

.firework::before,
.firework::after {
  content: '';
  position: absolute;
  width: 2px;
  height: 2px;
  border-radius: 50%;
}

@keyframes fireworkLaunch {
  0% {
    bottom: 0;
    opacity: 1;
    box-shadow: 0 0 20px 8px rgba(255, 215, 0, 0.9);
  }
  48% {
    bottom: 65%;
    opacity: 1;
    box-shadow: 0 0 20px 8px rgba(255, 215, 0, 0.9);
  }
  50% {
    bottom: 65%;
    opacity: 1;
    box-shadow: none;
  }
  51% {
    box-shadow:
      /* Ring 1 - inner sparks - CRISP and bright */
      0 0 8px 4px #ffd700,
      15px 0 8px 4px #ff4500,
      -15px 0 8px 4px #00ffff,
      0 15px 8px 4px #ff1493,
      0 -15px 8px 4px #00ff00,
      10px 10px 8px 4px #ffff00,
      -10px 10px 8px 4px #ff6347,
      10px -10px 8px 4px #9370db,
      -10px -10px 8px 4px #00bfff,
      /* Ring 2 - middle sparks - DEFINED glow */
      25px 5px 6px 3px #ff69b4,
      -25px 5px 6px 3px #ffa500,
      5px 25px 6px 3px #7fff00,
      5px -25px 6px 3px #ff00ff,
      -5px 25px 6px 3px #00ffff,
      -5px -25px 6px 3px #ffd700,
      20px 15px 6px 3px #ff4500,
      -20px 15px 6px 3px #00ff00,
      20px -15px 6px 3px #ff1493,
      -20px -15px 6px 3px #ffff00,
      /* Ring 3 - outer sparks - SHARP glow */
      35px 0 5px 2px #ff6347,
      -35px 0 5px 2px #9370db,
      0 35px 5px 2px #00bfff,
      0 -35px 5px 2px #ffa500,
      25px 25px 5px 2px #7fff00,
      -25px 25px 5px 2px #ff00ff,
      25px -25px 5px 2px #00ffff,
      -25px -25px 5px 2px #ffd700,
      30px 15px 5px 2px #ff69b4,
      -30px 15px 5px 2px #ff4500,
      15px 30px 5px 2px #00ff00,
      15px -30px 5px 2px #ff1493;
  }
  100% {
    bottom: 65%;
    opacity: 0;
    box-shadow:
      /* Ring 1 - inner sparks spreading - CRISP fade */
      0 0 6px 3px #ffd700,
      30px 0 6px 3px #ff4500,
      -30px 0 6px 3px #00ffff,
      0 30px 6px 3px #ff1493,
      0 -30px 6px 3px #00ff00,
      22px 22px 6px 3px #ffff00,
      -22px 22px 6px 3px #ff6347,
      22px -22px 6px 3px #9370db,
      -22px -22px 6px 3px #00bfff,
      /* Ring 2 - middle sparks spreading - DEFINED fade */
      50px 10px 5px 2px #ff69b4,
      -50px 10px 5px 2px #ffa500,
      10px 50px 5px 2px #7fff00,
      10px -50px 5px 2px #ff00ff,
      -10px 50px 5px 2px #00ffff,
      -10px -50px 5px 2px #ffd700,
      40px 30px 5px 2px #ff4500,
      -40px 30px 5px 2px #00ff00,
      40px -30px 5px 2px #ff1493,
      -40px -30px 5px 2px #ffff00,
      /* Ring 3 - outer sparks spreading - SHARP fade */
      70px 0 4px 1px #ff6347,
      -70px 0 4px 1px #9370db,
      0 70px 4px 1px #00bfff,
      0 -70px 4px 1px #ffa500,
      50px 50px 4px 1px #7fff00,
      -50px 50px 4px 1px #ff00ff,
      50px -50px 4px 1px #00ffff,
      -50px -50px 4px 1px #ffd700,
      60px 30px 4px 1px #ff69b4,
      -60px 30px 4px 1px #ff4500,
      30px 60px 4px 1px #00ff00,
      30px -60px 4px 1px #ff1493;
  }
}

.winner-modal {
  position: relative;
  z-index: 4;
  background: rgba(0, 0, 0, 0.9);
  padding: 40px 60px;
  border-radius: 20px;
  text-align: center;
  box-shadow:
    0 10px 40px rgba(0, 0, 0, 0.6),
    0 0 0 3px rgba(255, 215, 0, 0.3),
    0 0 30px rgba(255, 215, 0, 0.4);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  pointer-events: auto;
}

.winner-text {
  font-size: 48px;
  font-weight: bold;
  color: #ffd700;
  text-shadow: 0 0 20px rgba(255, 215, 0, 0.8);
  animation: winnerPulse 1s ease-in-out infinite;
  margin-bottom: 30px;
}

.play-again-modal-btn {
  width: auto;
  min-width: 200px;
  padding: 16px 40px;
  background: #ffd700;
  color: #000;
  border: none;
  border-radius: 10px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 5px 20px rgba(255, 215, 0, 0.4);
  margin: 0;
}

.play-again-modal-btn:hover {
  background: #ffed4e;
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(255, 215, 0, 0.6);
}

.play-again-modal-btn:active {
  transform: translateY(0);
}

.play-again-modal-btn:disabled {
  background: #999;
  cursor: not-allowed;
  box-shadow: none;
}

@keyframes winnerPulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

/* Cat Animation - Rainbow Cat */
#catAnimation {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  pointer-events: none;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.cat {
  font-size: 120px;
  position: relative;
  animation: rainbowCat 2s ease-in-out infinite;
}

.cat::before {
  content: '🐱';
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0.3;
  animation: rainbowTrail 2s ease-in-out infinite;
}

@keyframes rainbowCat {
  0% {
    filter: hue-rotate(0deg);
    transform: translateY(0);
  }
  50% {
    filter: hue-rotate(180deg);
    transform: translateY(-30px);
  }
  100% {
    filter: hue-rotate(360deg);
    transform: translateY(0);
  }
}

@keyframes rainbowTrail {
  0%, 100% {
    transform: scale(1.2);
    opacity: 0;
  }
  50% {
    transform: scale(1);
    opacity: 0.3;
  }
}

.cat-text {
  color: white;
  font-size: 48px;
  font-weight: bold;
  margin-top: 40px;
  text-shadow:
    0 0 10px rgba(255, 255, 255, 0.8),
    0 0 20px rgba(255, 152, 0, 0.6);
  animation: catTextFloat 2s ease-in-out infinite;
}

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

.draw-modal {
  position: relative;
  z-index: 4;
  background: rgba(0, 0, 0, 0.9);
  padding: 40px 60px;
  border-radius: 20px;
  text-align: center;
  box-shadow:
    0 10px 40px rgba(0, 0, 0, 0.6),
    0 0 0 3px rgba(255, 152, 0, 0.3),
    0 0 30px rgba(255, 152, 0, 0.4);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  pointer-events: auto;
  margin-top: 40px;
}

.draw-text {
  font-size: 48px;
  font-weight: bold;
  color: #ff9800;
  text-shadow: 0 0 20px rgba(255, 152, 0, 0.8);
  animation: drawTextFloat 2s ease-in-out infinite;
  margin-bottom: 30px;
}

@keyframes drawTextFloat {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal-content {
  background: white;
  border-radius: 20px;
  padding: 40px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
  margin-bottom: 20px;
  color: #333;
  text-align: center;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.modal-actions button {
  flex: 1;
}

/* Stats Button */
.stats-btn {
  width: auto;
  padding: 12px 24px;
  margin: 15px auto 0;
  display: block;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.stats-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.stats-btn:active {
  transform: translateY(0);
}

/* Stats Modal */
.stats-modal-content {
  max-width: 600px;
  padding: 30px;
}

.stats-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}

.stats-header h2 {
  margin: 0;
  font-size: 28px;
  color: #333;
}

.close-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  margin: 0;
  background: #f0f0f0;
  border: none;
  border-radius: 50%;
  font-size: 24px;
  color: #666;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.close-btn:hover {
  background: #e0e0e0;
  color: #333;
  transform: rotate(90deg);
}

/* Stats Summary */
.stats-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  margin-bottom: 30px;
}

.stat-box {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
  border-radius: 12px;
  text-align: center;
  color: white;
}

.stat-label {
  font-size: 14px;
  opacity: 0.9;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 32px;
  font-weight: bold;
}

/* Player Stats Section */
.player-stats-section {
  margin-bottom: 30px;
}

.player-stat-card {
  background: #f9f9f9;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  transition: transform 0.3s, box-shadow 0.3s;
  border-left: 5px solid transparent;
}

.player-stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

#player1StatCard {
  border-left-color: #2196F3;
}

#player2StatCard {
  border-left-color: #F44336;
}

.player-stat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 15px;
}

.stat-player-symbol {
  width: 35px;
  height: 35px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border-radius: 50%;
  font-weight: bold;
  font-size: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.stat-player-name {
  font-size: 20px;
  font-weight: 600;
  color: #333;
}

.win-rate {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.win-rate-label {
  font-size: 14px;
  color: #666;
}

.win-rate-value {
  font-size: 24px;
  font-weight: bold;
}

#player1StatCard .win-rate-value {
  color: #2196F3;
}

#player2StatCard .win-rate-value {
  color: #F44336;
}

.progress-bar {
  width: 100%;
  height: 12px;
  background: #e0e0e0;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 15px;
}

.progress-fill {
  height: 100%;
  border-radius: 10px;
  transition: width 0.8s ease-out;
}

#player1StatCard .progress-fill {
  background: linear-gradient(90deg, #2196F3, #1976D2);
  box-shadow: 0 0 10px rgba(33, 150, 243, 0.5);
}

#player2StatCard .progress-fill {
  background: linear-gradient(90deg, #F44336, #D32F2F);
  box-shadow: 0 0 10px rgba(244, 67, 54, 0.5);
}

.stat-details {
  display: flex;
  justify-content: space-around;
  font-size: 14px;
  color: #666;
}

.stat-details strong {
  color: #333;
  font-size: 18px;
}

/* VS Divider */
.vs-divider {
  text-align: center;
  font-size: 24px;
  font-weight: bold;
  color: #999;
  margin: 20px 0;
  position: relative;
}

.vs-divider::before,
.vs-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #ddd, transparent);
}

.vs-divider::before {
  left: 0;
}

.vs-divider::after {
  right: 0;
}

/* Head-to-Head */
.head-to-head {
  background: #f9f9f9;
  padding: 20px;
  border-radius: 12px;
}

.head-to-head h3 {
  text-align: center;
  color: #333;
  margin-bottom: 20px;
  font-size: 18px;
}

.h2h-bars {
  display: flex;
  gap: 10px;
}

.h2h-bar-container {
  flex: 1;
  height: 60px;
  background: #e0e0e0;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.h2h-bar {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  transition: width 0.8s ease-out;
}

.player1-bar {
  background: linear-gradient(90deg, #2196F3, #1976D2);
  box-shadow: 0 0 15px rgba(33, 150, 243, 0.4);
}

.player2-bar {
  background: linear-gradient(90deg, #F44336, #D32F2F);
  box-shadow: 0 0 15px rgba(244, 67, 54, 0.4);
}

.h2h-label {
  position: relative;
  color: white;
  font-weight: bold;
  font-size: 24px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  z-index: 1;
}

/* Stats Animation */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.stats-modal-content:not(.hidden) {
  animation: slideIn 0.3s ease-out;
}

/* Responsive */
@media (max-width: 600px) {
  .screen {
    padding: 20px;
  }

  h1 {
    font-size: 2em;
  }

  .title-icon {
    font-size: 32px;
  }

  .game-info {
    flex-direction: column;
  }

  .winner-text,
  .cat-text {
    font-size: 32px;
  }

  .cat-head {
    width: 90px;
    height: 75px;
  }

  .cat-body {
    width: 75px;
    height: 60px;
  }
}
