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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
  min-height: 85vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
}

#app {
  width: 100%;
  max-width: 1200px;
  padding: 20px;
}

.screen {
  display: none;
  animation: fadeIn 0.3s ease-in-out;
}

.screen.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Menu Screen */
.menu-container {
  background: white;
  border-radius: 20px;
  padding: 40px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  text-align: center;
  max-width: 500px;
  margin: 0 auto;
}

.game-title {
  font-size: 3rem;
  margin-bottom: 10px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.game-subtitle {
  color: #666;
  margin-bottom: 40px;
  font-size: 1.1rem;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 30px;
}

.menu-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 20px;
  border-radius: 15px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 15px;
  text-align: left;
}

.menu-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
}

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

.btn-text {
  font-size: 1.2rem;
  font-weight: 600;
}

.btn-desc {
  font-size: 0.9rem;
  opacity: 0.9;
  display: block;
}

.back-link {
  color: #667eea;
  text-decoration: none;
  font-size: 1rem;
  transition: color 0.3s ease;
}

.back-link:hover {
  color: #764ba2;
}

/* Online Menu */
.menu-title {
  font-size: 2rem;
  margin-bottom: 30px;
  color: #333;
}

.online-options {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 30px;
}

.online-menu-expanded {
  max-width: 700px;
}

/* Rooms List Section */
.rooms-list-section {
  margin-top: 30px;
  margin-bottom: 30px;
  padding-top: 20px;
  border-top: 2px solid #e0e0e0;
}

.rooms-title {
  font-size: 1.3rem;
  margin-bottom: 20px;
  color: #667eea;
}

.available-rooms {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 300px;
  overflow-y: auto;
}

.room-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  background: #f8f9fa;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 2px solid transparent;
}

.room-card:hover {
  background: #e8e9ea;
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.room-card.full {
  background: #ffebee;
  cursor: not-allowed;
  opacity: 0.7;
}

.room-card.full:hover {
  transform: none;
  box-shadow: none;
}

.room-info-left {
  display: flex;
  align-items: center;
  gap: 15px;
}

.room-code-badge {
  font-size: 1.2rem;
  font-weight: bold;
  color: #667eea;
  letter-spacing: 2px;
}

.room-host {
  color: #666;
  font-size: 0.95rem;
}

.room-status {
  display: flex;
  align-items: center;
  gap: 10px;
}

.players-count {
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
}

.players-count.waiting {
  background: #fff3cd;
  color: #856404;
}

.players-count.full {
  background: #d4edda;
  color: #155724;
}

.join-btn-inline {
  padding: 8px 16px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.3s ease;
}

.join-btn-inline:hover {
  background: #764ba2;
}

.no-rooms-message {
  text-align: center;
  padding: 30px;
  color: #999;
  font-style: italic;
}

.back-btn {
  background: #f0f0f0;
  color: #333;
  border: none;
  padding: 12px 24px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.3s ease;
}

.back-btn:hover {
  background: #e0e0e0;
}

/* Room Screen */
.room-container {
  background: white;
  border-radius: 20px;
  padding: 40px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  max-width: 500px;
  margin: 0 auto;
}

.room-title {
  font-size: 2rem;
  margin-bottom: 30px;
  text-align: center;
  color: #333;
}

.room-info {
  margin-bottom: 30px;
}

.room-code-container {
  margin-bottom: 30px;
  text-align: center;
}

.room-code-container label {
  display: block;
  margin-bottom: 10px;
  color: #666;
  font-size: 1rem;
}

.room-code-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #f8f9fa;
  padding: 15px;
  border-radius: 10px;
}

#roomCode {
  font-size: 2rem;
  font-weight: bold;
  letter-spacing: 5px;
  color: #667eea;
}

.copy-btn {
  background: #667eea;
  color: white;
  border: none;
  padding: 8px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 1.2rem;
  transition: all 0.3s ease;
}

.copy-btn:hover {
  background: #764ba2;
}

.players-list h3 {
  margin-bottom: 15px;
  color: #333;
}

.player-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 10px;
  margin-bottom: 10px;
}

.player-color {
  font-size: 1.5rem;
}

.player-status {
  margin-left: auto;
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 0.9rem;
}

.player-status.ready {
  background: #4caf50;
  color: white;
}

.room-actions {
  display: flex;
  gap: 10px;
}

.ready-btn {
  flex: 1;
  background: #4caf50;
  color: white;
  border: none;
  padding: 15px;
  border-radius: 10px;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

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

.ready-btn.ready {
  background: #ff9800;
}

.leave-btn {
  flex: 1;
  background: #f44336;
  color: white;
  border: none;
  padding: 15px;
  border-radius: 10px;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

.leave-btn:hover {
  background: #da190b;
}

/* Game Screen */
.game-container {
  background: white;
  border-radius: 20px;
  padding: 30px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 15px;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.player-info.current-player {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 10px 20px;
  border-radius: 10px;
  color: white;
}

.player-info.current-player .player-name,
.player-info.current-player .captured-count {
  color: white;
}

.player-stone {
  font-size: 2rem;
}

.player-name {
  font-weight: 600;
  font-size: 1.1rem;
}

.captured-count {
  font-size: 0.9rem;
  color: #666;
}

.player-timer {
  font-size: 1.3rem;
  font-weight: bold;
  color: #333;
  margin-top: 1px;
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 8px;
}

.player-info.current-player .player-timer {
  color: white;
  background: rgba(255, 255, 255, 0.2);
}

.game-status {
  text-align: center;
}

#turnIndicator {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 5px;
}

.timer {
  font-size: 1.5rem;
  color: #667eea;
  font-weight: bold;
}

.board-container {
  display: flex;
  justify-content: center;
  margin: 20px 0;
  background: #deb887;
  padding: 20px;
  border-radius: 15px;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.2);
}

#goBoard {
  cursor: pointer;
  border: 2px solid #8b7355;
  border-radius: 5px;
  display: block;
  margin: 0 auto;
  touch-action: none; /* Prevent default touch behavior */
  -webkit-touch-callout: none; /* iOS Safari */
  -webkit-user-select: none; /* Safari */
  user-select: none; /* Standard */
}

.game-controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

.control-btn {
  background: #667eea;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

.control-btn:hover {
  background: #764ba2;
  transform: translateY(-2px);
}

#resignBtn {
  background: #f44336;
}

#resignBtn:hover {
  background: #da190b;
}

/* Tutorial Screen */
.tutorial-container {
  background: white;
  border-radius: 20px;
  padding: 40px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  max-width: 800px;
  margin: 0 auto;
  max-height: 80vh;
  overflow-y: auto;
}

.tutorial-title {
  font-size: 2rem;
  margin-bottom: 30px;
  text-align: center;
  color: #333;
}

.tutorial-content {
  line-height: 1.8;
}

.tutorial-section {
  margin-bottom: 30px;
}

.tutorial-section h3 {
  color: #667eea;
  margin-bottom: 15px;
  font-size: 1.3rem;
}

.tutorial-section ul {
  margin-left: 30px;
}

.tutorial-section li {
  margin-bottom: 10px;
  color: #555;
}

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

.modal.active {
  display: flex;
}

.modal-content {
  background: white;
  padding: 30px;
  border-radius: 15px;
  max-width: 400px;
  width: 90%;
  text-align: center;
}

.modal-content h3 {
  margin-bottom: 20px;
  color: #333;
}

#roomCodeInput {
  width: 100%;
  padding: 12px;
  font-size: 1.2rem;
  text-align: center;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  margin-bottom: 20px;
  text-transform: uppercase;
  letter-spacing: 2px;
}

#roomCodeInput:focus {
  outline: none;
  border-color: #667eea;
}

.modal-buttons {
  display: flex;
  gap: 10px;
}

.confirm-btn {
  flex: 1;
  background: #4caf50;
  color: white;
  border: none;
  padding: 12px;
  border-radius: 10px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

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

.cancel-btn {
  flex: 1;
  background: #f44336;
  color: white;
  border: none;
  padding: 12px;
  border-radius: 10px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

.cancel-btn:hover {
  background: #da190b;
}

/* Loading Overlay */
.loading-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.loading-overlay.active {
  display: flex;
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 5px solid #f3f3f3;
  border-top: 5px solid #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

#loadingText {
  color: white;
  margin-top: 20px;
  font-size: 1.1rem;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 3000;
}

.toast {
  background: white;
  padding: 15px 20px;
  border-radius: 10px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  margin-bottom: 10px;
  min-width: 250px;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.toast.success {
  border-left: 4px solid #4caf50;
}

.toast.error {
  border-left: 4px solid #f44336;
}

.toast.info {
  border-left: 4px solid #2196f3;
}

/* Responsive Design */
@media (max-width: 768px) {
  .game-header {
    flex-direction: column;
    gap: 15px;
  }

  .game-controls {
    flex-wrap: wrap;
  }

  .control-btn {
    flex: 1 1 45%;
  }

  #goBoard {
    max-width: 100%;
    height: auto;
  }
}

@media (min-width: 275) {
  .player-stone {
    font-size: 1rem;
  }

  .player-timer {
    margin-top: 1px;
  }
}
