/* CSS Variables */
:root {
  --bg-dark: hsl(240, 10%, 3.9%);
  --board-dark: hsl(240, 5%, 7%);
  --text: hsl(0, 0%, 100%);
  --muted: hsl(240, 5%, 64.9%);
  --hover: hsl(240, 5%, 84.9%);
  
  --player1: hsl(217, 91%, 60%);
  --player1-light: hsl(217, 91%, 85%);
  --player2: hsl(0, 84%, 60%);
  --player2-light: hsl(0, 84%, 85%);
  
  --success: hsl(142, 71%, 45%);
  --success-light: hsl(142, 71%, 60%);
  
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-dark);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

main#app {
  max-width: 600px;
  margin: 0 auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Game Header */
.game-header {
  text-align: center;
  margin-bottom: 16px;
}

.game-header h1 {
  margin: 0 0 12px 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.score-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

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

.player-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--player1);
}

.player-score[data-player="2"] .player-indicator {
  background: var(--player2);
}

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

.score-badge {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.9rem;
}

.score-separator {
  width: 1px;
  height: 24px;
  background: var(--muted);
}

/* Turn Indicator */
.turn-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 8px 16px;
  background: var(--player1);
  border-radius: var(--radius);
  transition: background 0.2s ease;
}

.turn-indicator[data-player="2"] {
  background: var(--player2);
}

.turn-dot {
  display: none; /* Hide the dot since entire box is colored */
}

#turnText {
  font-size: 0.9rem;
  font-weight: 600;
  color: white;
}

/* Game Notification */
.game-notification {
  text-align: center;
  margin-bottom: 12px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  pointer-events: none;
}

.game-notification.show {
  opacity: 1;
  transform: translateY(0);
}

.game-notification.bonus {
  background: rgba(59, 130, 246, 0.2);
  color: var(--player1);
}

.game-notification.bonus.player2 {
  background: rgba(239, 68, 68, 0.2);
  color: var(--player2);
}

.game-notification.game-over {
  background: linear-gradient(135deg, var(--player1), var(--player2));
  color: white;
  animation: pulse 2s infinite;
}

/* Board Container */
.board-container {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

#gameBoard {
  background: var(--board-dark);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 20px;
  cursor: pointer;
  touch-action: none;
}

/* SVG Elements */
.box {
  fill: transparent;
  stroke: none;
}

/* Box fill colors are set directly in JavaScript - no CSS override */

.edge {
  stroke: transparent;
  stroke-width: 2;
  cursor: pointer;
  transition: all 0.15s ease;
}

.edge:hover {
  stroke: var(--hover);
  stroke-width: 3;
}

.edge.placed {
  stroke-width: 3;
  pointer-events: none;
  stroke: var(--muted); /* Neutral gray for all placed edges */
}

.edge.placed.last-move {
  stroke-width: 4;
  filter: drop-shadow(0 0 3px currentColor);
}

.edge.placed.last-move.player1 {
  stroke: var(--player1);
}

.edge.placed.last-move.player2 {
  stroke: var(--player2);
}

.dot {
  fill: var(--muted);
  cursor: pointer;
}

.hit-area {
  fill: transparent;
  stroke: none;
  cursor: pointer;
}

/* Game Controls */
.game-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mode-selector {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.mode-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.85rem;
  font-weight: 600;
}

.mode-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.05);
}

.mode-btn.active {
  background: rgba(34, 197, 94, 0.15);
  border-color: var(--success);
  border-width: 2px;
  color: var(--text);
}

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

.action-buttons {
  display: flex;
  gap: 8px;
}

.action-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.9rem;
  font-weight: 600;
}

.action-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}

.action-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.action-btn.destructive {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

.action-btn.destructive:hover:not(:disabled) {
  background: var(--success-light);
  border-color: var(--success-light);
}

.action-btn.btn-icon-only {
  flex: 0 0 auto;
  width: 48px;
  padding: 12px;
  justify-content: center;
}

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

.prefill-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: all 0.2s ease;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.prefill-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
}

.prefill-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--success);
}

.prefill-toggle span {
  font-size: 0.9rem;
  white-space: nowrap;
}

/* More Games */
.more-games {
  margin-top: 16px;
  padding: 2px 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.more-games-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.more-games-left {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  min-width: 0;
}

.more-games-line1 {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.more-games-title {
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--text);
  white-space: nowrap;
  line-height: 1;
  margin: 0;
  padding: 0;
}

.more-games-links {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
}

.more-games-link {
  color: var(--player1);
  text-decoration: none;
  font-size: 0.75rem;
  transition: color 0.2s ease;
  white-space: nowrap;
  line-height: 1;
  margin: 0;
  padding: 0;
}

.more-games-link:hover {
  color: var(--player1-light);
  text-decoration: underline;
}

.more-games-right {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.logo-link {
  display: inline-block;
  text-decoration: none;
  transition: opacity 0.2s ease;
}

.logo-link:hover {
  opacity: 0.8;
}

.logo-link .logo {
  height: 40px;
  width: auto;
  max-height: 40px;
  max-width: 100px;
  opacity: 0.7;
  display: block;
  object-fit: contain;
}

.more-games-line2 {
  display: inline-flex;
  margin: 0;
  padding: 0;
  line-height: 1;
}

.more-games-line2 .feedback-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: color 0.2s ease;
  line-height: 1;
  margin: 0;
  padding: 0;
}

.more-games-line2 .feedback-link:hover {
  color: var(--text);
  text-decoration: underline;
}

/* Modal Styles */
.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;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.modal.show {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: var(--board-dark);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  transform: scale(0.9);
  transition: transform 0.3s ease;
}

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

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px 0;
  margin-bottom: 16px;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
}

.modal-body {
  padding: 0 24px 24px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 20px;
}

.btn-icon.close-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.25rem;
  padding: 4px;
}

.btn-icon.close-btn:hover {
  color: var(--text);
}

.player-names {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.player-name-input {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.player-name-input label {
  font-size: 0.875rem;
  color: var(--muted);
  font-weight: 600;
}

.player-name-input input {
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  transition: all 0.2s ease;
}

.player-name-input input:focus {
  outline: none;
  border-color: var(--player1);
  background: rgba(255, 255, 255, 0.08);
}

/* Responsive Design */
@media (max-width: 480px) {
  main#app {
    padding: 8px;
  }
  
  .game-header h1 {
    font-size: 1.25rem;
  }
  
  .score-display {
    gap: 12px;
  }
  
  .player-name {
    font-size: 0.8rem;
  }
  
  .score-badge {
    padding: 3px 10px;
    font-size: 0.85rem;
  }
  
  #gameBoard {
    padding: 16px;
  }
  
  .mode-btn {
    padding: 10px 6px;
    font-size: 0.8rem;
  }
  
  .mode-icon {
    font-size: 1rem;
  }
  
  .action-btn {
    padding: 10px 12px;
    font-size: 0.85rem;
  }
  
  .action-btn.btn-icon-only {
    width: 44px;
    padding: 10px;
  }
  
  .prefill-toggle {
    padding: 10px 12px;
    font-size: 0.8rem;
  }
  
  .prefill-toggle span {
    font-size: 0.8rem;
  }
  
  .prefill-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
  }

  .more-games-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .more-games-left {
    width: 100%;
  }

  .more-games-right {
    align-self: flex-end;
  }

  .logo-link .logo {
    height: 32px;
    max-height: 32px;
    max-width: 70px;
  }
}

/* Safe area for iOS notch */
@supports (padding: max(0px)) {
  main#app {
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }
}

