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

body {
  font-family: Arial, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  padding: 20px;
  overflow-x: hidden;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
}

/* Mobile: stack layout, shrink board */
@media (max-width: 700px) {
  body { padding: 8px; }

  h1 { font-size: 1.5em; margin-bottom: 14px; }

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

  .game-sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .sidebar-section {
    flex: 1;
    min-width: 140px;
  }

  #game-container {
    padding: 10px;
  }

  .options-container, .room-form, .lobby-container {
    padding: 16px;
  }

  .score-board {
    font-size: 0.9em;
    gap: 6px;
  }

  .player-score {
    padding: 6px 10px;
  }

  .color-btn {
    width: 42px;
    height: 42px;
  }

  .game-over-modal {
    padding: 20px;
  }

  .game-info h2 {
    font-size: 1.1em;
  }

  .color-picker {
    min-height: 50px;
    gap: 6px;
    margin: 10px 0;
  }

  .score-board {
    margin: 10px 0;
  }
}

h1 {
  text-align: center;
  color: white;
  margin-bottom: 30px;
  font-size: 2.5em;
}

.game-menu {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.game-card {
  background: white;
  border-radius: 10px;
  padding: 20px;
  cursor: pointer;
  transition: transform 0.2s;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.game-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 6px 12px rgba(0,0,0,0.2);
}

.game-card h2 { color: #667eea; margin-bottom: 10px; }
.game-card p { color: #666; line-height: 1.5; }

.options-container, .room-form, .lobby-container {
  background: white;
  border-radius: 10px;
  padding: 30px;
  max-width: 500px;
  margin: 0 auto;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.options-container h2, .room-form h2, .lobby-container h2 {
  color: #667eea;
  margin-bottom: 20px;
  text-align: center;
}

.option-buttons {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.option-btn {
  background: #667eea;
  color: white;
  border: none;
  padding: 15px 30px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1em;
  transition: background 0.2s;
}

.option-btn:hover { background: #5568d3; }

.room-form label {
  display: block;
  color: #555;
  font-size: 0.9em;
  margin-bottom: 4px;
  margin-top: 10px;
}

.room-form input,
.room-form select {
  width: 100%;
  padding: 12px;
  margin-bottom: 10px;
  border: 2px solid #ddd;
  border-radius: 5px;
  font-size: 1em;
  background: white;
}

.room-form input:focus,
.room-form select:focus {
  outline: none;
  border-color: #667eea;
}

.submit-btn {
  width: 100%;
  background: #667eea;
  color: white;
  border: none;
  padding: 12px 30px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 1.1em;
  transition: background 0.2s;
  margin-top: 10px;
}

.submit-btn:hover { background: #5568d3; }

.copy-btn {
  background: #4CAF50;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 1em;
  margin: 10px auto;
  display: block;
}

.copy-btn:hover { background: #45a049; }

.players-list { margin: 20px 0; }
.players-list h3 { color: #667eea; margin-bottom: 10px; }

.player-item {
  background: #f5f5f5;
  padding: 10px;
  margin: 5px 0;
  border-radius: 5px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.player-badge {
  background: #667eea;
  color: white;
  padding: 3px 10px;
  border-radius: 3px;
  font-size: 0.9em;
}

.player-name { flex: 1; font-weight: bold; }

.you-badge {
  background: #4CAF50;
  color: white;
  padding: 3px 8px;
  border-radius: 3px;
  font-size: 0.8em;
}

#waiting-message {
  text-align: center;
  color: #666;
  margin: 20px 0;
  font-style: italic;
}

#game-container {
  background: white;
  border-radius: 10px;
  padding: 30px;
  display: none;
}

.game-board {
  display: grid;
  gap: 2px;
  margin: 20px auto;
  width: fit-content;
  background: #333;
  padding: 2px;
  border-radius: 5px;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  color: white;
  text-shadow: 0 0 4px rgba(0,0,0,0.8), 0 0 2px rgba(0,0,0,0.8);
  transition: opacity 0.2s;
  user-select: none;
}

.game-info {
  text-align: center;
  margin-bottom: 20px;
}

#turn-indicator {
  font-size: 1.2em;
  font-weight: bold;
  margin-top: 10px;
}

.color-picker {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 20px 0;
  min-height: 80px;
}

.your-turn, .waiting-turn {
  font-size: 1.1em;
  font-weight: bold;
  width: 100%;
  text-align: center;
}

.your-turn { color: #4CAF50; }
.waiting-turn { color: #666; }

.color-btn {
  width: 55px;
  height: 55px;
  border: 3px solid #333;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.2s;
}

.color-btn:hover:not(.disabled) { transform: scale(1.1); }
.color-btn.disabled { opacity: 0.3; cursor: not-allowed; }

/* Score board - flex wrap for 3-4 players */
.score-board {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 20px 0;
  font-size: 1.1em;
}

.player-score {
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: bold;
  text-align: center;
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-symbol { font-size: 1.3em; }

.player-1-score { background: #FFE5E5; border: 2px solid #FF6B6B; }
.player-2-score { background: #E5F5FF; border: 2px solid #4ECDC4; }
.player-3-score { background: #FFF5E5; border: 2px solid #FFA07A; }
.player-4-score { background: #F0FFE5; border: 2px solid #98D8C8; }

.back-btn {
  background: #667eea;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 1em;
  margin-bottom: 20px;
}

.back-btn:hover { background: #5568d3; }

.game-over {
  text-align: center;
  padding: 20px;
  background: #f0f0f0;
  border-radius: 10px;
  margin-top: 20px;
}

.game-over h2 { color: #667eea; margin-bottom: 10px; }

.restart-btn {
  background: #667eea;
  color: white;
  border: none;
  padding: 12px 30px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 1.1em;
  margin-top: 15px;
}

.restart-btn:hover { background: #5568d3; }

.reconnect-message {
  background: #fff3cd;
  border: 2px solid #ffc107;
  border-radius: 8px;
  padding: 20px;
  margin: 20px 0;
  text-align: center;
}

.reconnect-message p {
  margin: 10px 0;
  color: #856404;
  font-weight: bold;
}

/* Game layout: board + sidebar */
.game-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.game-main {
  flex: 1;
  min-width: 0;
}

.board-wrapper {
  position: relative;
  display: inline-block;
}

/* Win overlay */
.game-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  z-index: 10;
}

.game-over-modal {
  background: white;
  border-radius: 12px;
  padding: 30px 40px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  max-width: 360px;
  width: 90%;
}

.game-over-modal h2 {
  color: #667eea;
  font-size: 1.6em;
  margin-bottom: 16px;
}

.game-over-scores {
  margin: 12px 0 20px;
  font-size: 1em;
  color: #444;
  line-height: 1.8;
}

.waiting-restart {
  color: #888;
  font-style: italic;
  margin: 10px 0;
}

.back-btn-small {
  background: none;
  border: 1px solid #ccc;
  color: #888;
  padding: 8px 16px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.9em;
  margin-top: 8px;
}

.back-btn-small:hover { background: #f5f5f5; }

/* Sidebar */
.game-sidebar {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-section {
  background: #f9f9f9;
  border-radius: 8px;
  padding: 14px;
  border: 1px solid #e0e0e0;
}

.sidebar-section h3 {
  color: #667eea;
  font-size: 0.95em;
  margin-bottom: 10px;
}

.win-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 0.9em;
  border-bottom: 1px solid #eee;
}

.win-row:last-child { border-bottom: none; }

.win-count {
  font-weight: bold;
  color: #667eea;
}

/* Game log */
#game-log-entries {
  max-height: 300px;
  overflow-y: auto;
  font-size: 0.82em;
}

.log-entry {
  padding: 4px 0;
  border-bottom: 1px solid #eee;
  line-height: 1.4;
  color: #444;
}

.log-entry:last-child { border-bottom: none; }

.log-time {
  color: #aaa;
  font-size: 0.85em;
  margin-right: 4px;
}

.log-win { color: #2e7d32; font-weight: bold; }
.log-warn { color: #b45309; }
.log-info { color: #444; }
