/* Variables & Design Tokens */
:root {
  --bg-gradient: linear-gradient(135deg, #0b0f19 0%, #111827 50%, #1e1b4b 100%);
  --panel-bg: rgba(17, 24, 39, 0.7);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  
  /* Player 1 Theme (Neon Cyan) */
  --p1-color: #06b6d4;
  --p1-glow: 0 0 15px rgba(6, 182, 212, 0.6);
  --p1-glow-soft: 0 0 25px rgba(6, 182, 212, 0.2);
  --p1-bg: linear-gradient(135deg, #06b6d4, #0891b2);

  /* Player 2 Theme (Neon Pink/Magenta) */
  --p2-color: #ec4899;
  --p2-glow: 0 0 15px rgba(236, 72, 153, 0.6);
  --p2-glow-soft: 0 0 25px rgba(236, 72, 153, 0.2);
  --p2-bg: linear-gradient(135deg, #ec4899, #db2777);

  /* Board Variables */
  --cell-size: 50px;
  --gap-size: 12px;
  --board-bg: #1f2937;
  --cell-bg: #111827;
  --cell-border: rgba(255, 255, 255, 0.03);
  --cell-hover: rgba(255, 255, 255, 0.08);
  
  /* Wall colors */
  --wall-color: #f59e0b;
  --wall-glow: 0 0 12px rgba(245, 158, 11, 0.7);
  --wall-preview-p1: rgba(6, 182, 212, 0.4);
  --wall-preview-p2: rgba(236, 72, 153, 0.4);
  
  /* Fonts */
  --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 Panel */
.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.37);
}

/* Layout */
.app-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1100px;
  height: 90vh;
  min-height: 700px;
  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(--p1-color), var(--p2-color));
  border-radius: 10px;
  color: #fff;
  box-shadow: 0 0 15px rgba(6, 182, 212, 0.3);
}

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

.logo h1 span {
  background: linear-gradient(to right, var(--p1-color), var(--p2-color));
  -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.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  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.15);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

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

/* Game Layout Grid */
.game-layout {
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 30px;
  flex: 1;
  min-height: 0; /* allows grid items to shrink */
}

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

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

/* Game Mode Button Selector */
.game-mode-selector {
  display: flex;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.mode-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.85rem;
  transition: all 0.2s ease;
}

.mode-btn.active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

/* Player Cards */
.players-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.player-card {
  border-radius: 12px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

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

.player-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-muted);
  display: inline-block;
  transition: all 0.3s ease;
}

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

.player-walls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
}

.wall-label {
  color: var(--text-secondary);
}

.wall-dots {
  display: flex;
  gap: 4px;
}

.wall-dot {
  width: 6px;
  height: 16px;
  border-radius: 2px;
  background: var(--text-muted);
  transition: all 0.3s ease;
  display: inline-block;
}

/* Player Active Turn Styling */
.player-1-theme.active-turn {
  background: rgba(6, 182, 212, 0.05);
  border-color: rgba(6, 182, 212, 0.4);
  box-shadow: 0 0 15px rgba(6, 182, 212, 0.05);
}
.player-1-theme.active-turn .player-indicator {
  background: var(--p1-color);
  box-shadow: var(--p1-glow);
}
.player-1-theme .wall-dot.active {
  background: var(--p1-color);
  box-shadow: 0 0 5px var(--p1-color);
}

.player-2-theme.active-turn {
  background: rgba(236, 72, 153, 0.05);
  border-color: rgba(236, 72, 153, 0.4);
  box-shadow: 0 0 15px rgba(236, 72, 153, 0.05);
}
.player-2-theme.active-turn .player-indicator {
  background: var(--p2-color);
  box-shadow: var(--p2-glow);
}
.player-2-theme .wall-dot.active {
  background: var(--p2-color);
  box-shadow: 0 0 5px var(--p2-color);
}

/* Turn Banner */
.turn-banner {
  text-align: center;
  padding: 12px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.5px;
  transition: all 0.3s ease;
}

.player-1-turn {
  background: rgba(6, 182, 212, 0.15);
  color: var(--p1-color);
  border: 1px solid rgba(6, 182, 212, 0.2);
}

.player-2-turn {
  background: rgba(236, 72, 153, 0.15);
  color: var(--p2-color);
  border: 1px solid rgba(236, 72, 153, 0.2);
}

/* Action Buttons */
.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: auto;
}

.action-btn {
  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.secondary {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.action-btn.secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

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

.action-btn.danger {
  grid-column: span 2;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #f87171;
}

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

/* Board Area */
.board-area {
  display: flex;
  justify-content: center;
  align-items: center;
}

.board-wrapper {
  background: rgba(0, 0, 0, 0.4);
  padding: 16px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: inset 0 4px 20px rgba(0,0,0,0.5);
}

/* Board Grid Definition */
.board {
  display: grid;
  /* 9 cells (50px) + 8 gaps (12px) */
  grid-template-columns: 
    var(--cell-size) var(--gap-size)
    var(--cell-size) var(--gap-size)
    var(--cell-size) var(--gap-size)
    var(--cell-size) var(--gap-size)
    var(--cell-size) var(--gap-size)
    var(--cell-size) var(--gap-size)
    var(--cell-size) var(--gap-size)
    var(--cell-size) var(--gap-size)
    var(--cell-size);
  grid-template-rows: 
    var(--cell-size) var(--gap-size)
    var(--cell-size) var(--gap-size)
    var(--cell-size) var(--gap-size)
    var(--cell-size) var(--gap-size)
    var(--cell-size) var(--gap-size)
    var(--cell-size) var(--gap-size)
    var(--cell-size) var(--gap-size)
    var(--cell-size) var(--gap-size)
    var(--cell-size);
  background: var(--board-bg);
  border-radius: 12px;
  padding: 10px;
  position: relative;
}

/* Cells styling */
.cell {
  background: var(--cell-bg);
  border: 1px solid var(--cell-border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cell:hover {
  background: var(--cell-hover);
}

/* Highlight reachable cells */
.cell.valid-move {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.5);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.2);
}

.cell.valid-move:hover {
  background: rgba(16, 185, 129, 0.3);
  transform: scale(1.05);
}

/* Pawns styling */
.pawn {
  width: 70%;
  height: 70%;
  border-radius: 50%;
  position: absolute;
  z-index: 10;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.pawn-1 {
  background: var(--p1-bg);
  box-shadow: var(--p1-glow), var(--p1-glow-soft);
  animation: pulse-glow-1 2s infinite alternate;
}

.pawn-2 {
  background: var(--p2-bg);
  box-shadow: var(--p2-glow), var(--p2-glow-soft);
  animation: pulse-glow-2 2s infinite alternate;
}

/* Wall Slots (Invisible until hovered) */
.wall-slot-h, .wall-slot-v {
  z-index: 5;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
  border-radius: 4px;
}

/* Standard states: invisible gaps */
.wall-slot-h {
  margin: 1px 0;
  height: 10px;
}

.wall-slot-v {
  margin: 0 1px;
  width: 10px;
}

/* Hover previews for slots */
.wall-slot-h:hover:not(.disabled) {
  background: var(--wall-preview-p1);
}
.player-2-turn-active .wall-slot-h:hover:not(.disabled) {
  background: var(--wall-preview-p2);
}

.wall-slot-v:hover:not(.disabled) {
  background: var(--wall-preview-p1);
}
.player-2-turn-active .wall-slot-v:hover:not(.disabled) {
  background: var(--wall-preview-p2);
}

/* Placed Walls styling */
.wall-placed {
  background: var(--wall-color);
  box-shadow: var(--wall-glow);
  z-index: 8;
  border-radius: 4px;
  animation: wall-deploy 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Disable slots when occupied or invalid */
.wall-slot-h.disabled, .wall-slot-v.disabled {
  pointer-events: none;
}

/* Modals styling */
.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;
  animation: modal-enter 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.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(--p1-color), var(--p2-color));
  -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, #4f46e5, #06b6d4);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(79, 70, 229, 0.4);
  transition: all 0.2s ease;
}

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

/* Animations */
@keyframes pulse-glow-1 {
  0% {
    box-shadow: 0 0 10px rgba(6, 182, 212, 0.5), 0 0 20px rgba(6, 182, 212, 0.1);
  }
  100% {
    box-shadow: 0 0 20px rgba(6, 182, 212, 0.8), 0 0 35px rgba(6, 182, 212, 0.3);
  }
}

@keyframes pulse-glow-2 {
  0% {
    box-shadow: 0 0 10px rgba(236, 72, 153, 0.5), 0 0 20px rgba(236, 72, 153, 0.1);
  }
  100% {
    box-shadow: 0 0 20px rgba(236, 72, 153, 0.8), 0 0 35px rgba(236, 72, 153, 0.3);
  }
}

@keyframes wall-deploy {
  0% {
    transform: scale(0.6);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes modal-enter {
  0% {
    transform: scale(0.9) translateY(20px);
    opacity: 0;
  }
  100% {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

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

@keyframes flash-red {
  0%, 100% {
    box-shadow: none;
  }
  50% {
    box-shadow: 0 0 25px rgba(239, 68, 68, 0.7);
  }
}

/* Confetti Effect (Simple aesthetic border glow/pulse) */
.modal-content.confetti {
  border: 2px solid transparent;
  background-image: linear-gradient(var(--panel-bg), var(--panel-bg)), 
                    linear-gradient(135deg, var(--p1-color), var(--p2-color));
  background-origin: border-box;
  background-clip: padding-box, border-box;
  box-shadow: 0 0 30px rgba(79, 70, 229, 0.3);
}

/* Responsive adjustments */
@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;
    margin-bottom: 20px;
  }
}
