/* Variables & Design Tokens */
:root {
  --bg-gradient: linear-gradient(135deg, #090d16 0%, #111827 60%, #172554 100%);
  --panel-bg: rgba(17, 24, 39, 0.75);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  /* Colors */
  --color-red: #ef4444;
  --color-blue: #3b82f6;
  --color-green: #10b981;
  --color-yellow: #f59e0b;

  --glow-red: 0 0 15px rgba(239, 68, 68, 0.6);
  --glow-blue: 0 0 15px rgba(59, 130, 246, 0.6);
  --glow-green: 0 0 15px rgba(16, 185, 129, 0.6);
  --glow-yellow: 0 0 15px rgba(245, 158, 11, 0.6);

  --tile-size: 55px;
  --tile-gap: 6px;
  --font-primary: 'Outfit', 'Noto Sans JP', sans-serif;
}

/* Reset & Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

body {
  font-family: var(--font-primary);
  background: var(--bg-gradient);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
}

/* Glassmorphism */
.glass {
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
}

/* Layout */
.app-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1200px;
  height: 92vh;
  min-height: 720px;
  padding: 20px;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

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

.logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--color-red), var(--color-blue));
  border-radius: 10px;
  color: #fff;
  box-shadow: 0 0 15px rgba(59, 130, 246, 0.3);
}

.logo h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 2px;
}

.logo h1 span {
  background: linear-gradient(to right, var(--color-red), var(--color-yellow));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-left: 4px;
}

.header-controls {
  display: flex;
  gap: 10px;
}

/* Buttons */
.icon-btn, .icon-btn-text {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.icon-btn:hover, .icon-btn-text:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.18);
  transform: translateY(-2px);
}

.icon-btn-text {
  padding: 0 16px;
  height: 40px;
  border-radius: 20px;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 600;
}

/* Layout Grid */
.game-layout {
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 24px;
  flex: 1;
  min-height: 0;
}

/* Side Control Panel */
.control-panel {
  display: flex;
  flex-direction: column;
  padding: 20px;
  gap: 20px;
  overflow-y: auto;
}

.panel-section h3 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Settings Row */
.setting-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.setting-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.player-count-selector {
  display: flex;
  background: rgba(0, 0, 0, 0.3);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.pcount-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 8px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.85rem;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.pcount-btn.active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.ai-toggle-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.02);
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.02);
}

.ai-toggle-name {
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-toggle-name span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.ai-btn-group {
  display: flex;
  background: rgba(0, 0, 0, 0.2);
  padding: 2px;
  border-radius: 6px;
}

.ai-opt {
  background: transparent;
  border: none;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 8px;
  cursor: pointer;
  border-radius: 4px;
}

.ai-opt.active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

/* Player Cards container */
.players-cards-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.player-card {
  border-radius: 12px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.01);
  border: 1px solid rgba(255, 255, 255, 0.03);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.player-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
}

.player-card.active-turn {
  background: rgba(255, 255, 255, 0.04);
}

/* Individual colors and glow for cards */
.pcard-red.active-turn { border-color: rgba(239, 68, 68, 0.4); box-shadow: 0 0 10px rgba(239, 68, 68, 0.05); }
.pcard-red .player-dot { background: var(--color-red); box-shadow: var(--glow-red); }

.pcard-blue.active-turn { border-color: rgba(59, 130, 246, 0.4); box-shadow: 0 0 10px rgba(59, 130, 246, 0.05); }
.pcard-blue .player-dot { background: var(--color-blue); box-shadow: var(--glow-blue); }

.pcard-green.active-turn { border-color: rgba(16, 185, 129, 0.4); box-shadow: 0 0 10px rgba(16, 185, 129, 0.05); }
.pcard-green .player-dot { background: var(--color-green); box-shadow: var(--glow-green); }

.pcard-yellow.active-turn { border-color: rgba(245, 158, 11, 0.4); box-shadow: 0 0 10px rgba(245, 158, 11, 0.05); }
.pcard-yellow .player-dot { background: var(--color-yellow); box-shadow: var(--glow-yellow); }

.tiles-remain {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 600;
  background: rgba(0, 0, 0, 0.2);
  padding: 4px 8px;
  border-radius: 6px;
}

/* Turn Banner */
.turn-banner {
  text-align: center;
  padding: 12px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.95rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.02);
}

.action-buttons {
  margin-top: auto;
}

.action-btn {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
  font-size: 0.9rem;
}

.action-btn.danger {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: #f87171;
}

.action-btn.danger:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.3);
  transform: translateY(-2px);
}

/* Board Viewport & Scrolling */
.board-area {
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  position: relative;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.board-viewport {
  width: 100%;
  height: 100%;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
}

/* Board grid */
.board {
  display: grid;
  gap: var(--tile-gap);
  padding: 20px;
  background: rgba(15, 23, 42, 0.6);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.03);
  box-shadow: inset 0 4px 30px rgba(0,0,0,0.6);
}

/* Board Cell */
.cell {
  width: var(--tile-size);
  height: var(--tile-size);
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

/* Valid placement cell */
.cell.valid-place {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
}

.cell.valid-place:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.05);
}

/* Tiles */
.tile {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Tile styling by color */
.tile-red { background: linear-gradient(135deg, #f87171, #ef4444); box-shadow: var(--glow-red); }
.tile-blue { background: linear-gradient(135deg, #60a5fa, #3b82f6); box-shadow: var(--glow-blue); }
.tile-green { background: linear-gradient(135deg, #34d399, #10b981); box-shadow: var(--glow-green); }
.tile-yellow { background: linear-gradient(135deg, #fbbf24, #f59e0b); box-shadow: var(--glow-yellow); }

/* Moving phase selection styles */
.tile.selected {
  transform: scale(1.1) translateY(-3px);
  animation: tile-select-pulse 1s infinite alternate;
  z-index: 10;
  border: 2px solid #fff !important;
}

@keyframes tile-select-pulse {
  0% { box-shadow: 0 0 10px #fff; }
  100% { box-shadow: 0 0 25px #fff; }
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: opacity 0.3s ease;
}

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

.modal-content {
  width: 90%;
  max-width: 550px;
  padding: 30px;
  position: relative;
  max-height: 85vh;
  overflow-y: auto;
  border-radius: 20px;
}

.close-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.2s ease;
}

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

.modal-content h2 {
  font-size: 1.8rem;
  margin-bottom: 20px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--color-red), var(--color-blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.rules-body h3 {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin: 16px 0 8px 0;
}

.rules-body p {
  line-height: 1.6;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.rules-body ul {
  padding-left: 20px;
  margin-bottom: 16px;
}

.rules-body li {
  margin-bottom: 8px;
  line-height: 1.5;
}

.rules-body strong {
  color: #fff;
}

.modal-confirm-btn {
  display: block;
  width: 100%;
  padding: 14px;
  margin-top: 24px;
  background: linear-gradient(135deg, #3b82f6, #10b981);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
  transition: all 0.2s ease;
}

.modal-confirm-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.6);
}

.modal-content.confetti {
  border: 2px solid transparent;
  background-image: linear-gradient(var(--panel-bg), var(--panel-bg)), 
                    linear-gradient(135deg, var(--color-red), var(--color-green));
  background-origin: border-box;
  background-clip: padding-box, border-box;
  box-shadow: 0 0 30px rgba(59, 130, 246, 0.3);
}

/* Error flash on board */
.board.error-flash {
  animation: flash-red 0.4s ease;
}

@keyframes flash-red {
  0%, 100% { box-shadow: inset 0 4px 30px rgba(0,0,0,0.6); }
  50% { box-shadow: inset 0 4px 30px rgba(0,0,0,0.6), 0 0 25px rgba(239, 68, 68, 0.5); }
}

/* Responsive */
@media (max-width: 900px) {
  body {
    padding: 10px;
    align-items: flex-start;
  }
  .app-container {
    height: auto;
    min-height: auto;
  }
  .game-layout {
    grid-template-columns: 1fr;
  }
  .control-panel {
    order: 2;
  }
  .board-area {
    order: 1;
    height: 400px;
    margin-bottom: 20px;
  }
}
