/* Style Reset and Fonts */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
  --font-family: 'Outfit', sans-serif;
  --bg-color: #0b0f19;
  --panel-bg: rgba(22, 28, 45, 0.6);
  --border-color: rgba(255, 255, 255, 0.08);
  --cell-bg: #1e293b;
  --cell-hover: rgba(99, 102, 241, 0.15);
  --board-bg: #0f172a;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  
  /* Dimensions - Responsive Grid */
  --cell-size: 52px;
  --gap-size: 12px;
  
  /* Shadows and Glass */
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  --glass-blur: blur(12px);
  
  /* Wall styling */
  --wall-color: #e2e8f0;
  --wall-glow: rgba(226, 232, 240, 0.2);
}

@media (max-width: 650px) {
  :root {
    --cell-size: 34px;
    --gap-size: 8px;
  }
}

@media (max-width: 400px) {
  :root {
    --cell-size: 28px;
    --gap-size: 6px;
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem 1rem;
  overflow-x: hidden;
  background-image: 
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(244, 63, 94, 0.12) 0px, transparent 50%);
}

/* App Header */
header {
  text-align: center;
  margin-bottom: 1.5rem;
}

h1 {
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -0.05em;
  background: linear-gradient(135deg, #a5b4fc, #fda4af);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.25rem;
}

.subtitle {
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-weight: 300;
}

/* Main Container Layout */
.app-container {
  width: 100%;
  max-width: 950px;
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 850px) {
  .app-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 550px;
    align-items: center;
  }
  .play-area {
    order: 1;
    width: 100%;
  }
  aside {
    order: 2;
    width: 100%;
  }
}

/* ─── Phone layout (≤ 520px) ─── */
@media (max-width: 520px) {
  body {
    padding: 0.75rem 0.5rem 1.5rem;
    justify-content: flex-start;
  }

  header {
    margin-bottom: 0.75rem;
  }

  h1 {
    font-size: 1.6rem;
  }

  .subtitle {
    font-size: 0.8rem;
  }

  /* Make board scrollable horizontally on very small screens */
  .board-outer {
    padding: 0.75rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100vw;
  }

  /* Sidebar: horizontal scroll for player cards */
  .status-cards-row {
    display: flex;
    flex-direction: row;
    gap: 0.75rem;
  }

  .status-card {
    flex: 1;
    min-width: 0;
  }

  .wall-visuals {
    flex-wrap: wrap;
    height: auto;
    min-height: 20px;
  }

  /* Bigger touch targets for buttons */
  button {
    padding: 0.9rem 1rem;
    font-size: 1rem;
    min-height: 48px;
  }

  select {
    padding: 0.75rem 2.5rem 0.75rem 0.8rem;
    font-size: 1rem;
    min-height: 48px;
  }

  .panel {
    border-radius: 12px;
    padding: 1rem;
  }

  /* Compact controls: side-by-side undo + restart */
  .action-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .action-row button {
    font-size: 0.85rem;
    padding: 0.75rem 0.5rem;
  }
}

/* Sidebar & Controls Panel */
aside {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Player cards default: stacked on desktop, side-by-side on mobile */
.status-cards-row {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Undo + Restart always side-by-side */
.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.panel {
  background: var(--panel-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 1.25rem;
  box-shadow: var(--shadow-lg);
}

.panel-title {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Control Elements */
.control-group {
  margin-bottom: 1rem;
}

.control-group:last-child {
  margin-bottom: 0;
}

label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
  font-weight: 500;
}

select {
  width: 100%;
  background: #121824; /* Solid premium dark background */
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  padding: 0.6rem 0.8rem;
  font-family: var(--font-family);
  font-size: 0.9rem;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  
  /* Custom styled arrow */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.8rem center;
  background-size: 1rem;
  padding-right: 2.5rem;
}

select option {
  background-color: #121824;
  color: var(--text-primary);
  padding: 0.75rem;
}

select:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.25);
}

/* Button Styles */
button {
  width: 100%;
  background: #1e293b;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.75rem 1rem;
  font-family: var(--font-family);
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

button:hover:not(:disabled) {
  background: #334155;
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button.primary {
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  border: none;
}

button.primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #4338ca, #4f46e5);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.3);
}

/* Status Cards & Wall counters */
.status-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border-left: 4px solid var(--accent-color, #6366f1);
}

.status-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.wall-count {
  font-size: 0.85rem;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.05);
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  color: var(--text-secondary);
}

.wall-visuals {
  display: flex;
  gap: 3px;
  height: 24px;
  align-items: center;
}

.wall-stick {
  width: 6px;
  height: 20px;
  border-radius: 2px;
  opacity: 0.85;
  transition: transform 0.2s, opacity 0.2s;
}

/* Turn Indicator Styling */
.turn-indicator-panel {
  text-align: center;
  padding: 0.8rem 1rem;
}

#turn-indicator {
  font-weight: 700;
  font-size: 1.1rem;
  transition: color 0.3s ease;
}

/* Center Play Area */
.play-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

/* Board Container & Grid */
.board-outer {
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 1.25rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  justify-content: center;
  align-items: center;
}

#game-board {
  display: grid;
  grid-template-columns: repeat(8, var(--cell-size) var(--gap-size)) var(--cell-size);
  grid-template-rows: repeat(8, var(--cell-size) var(--gap-size)) var(--cell-size);
  background-color: var(--board-bg);
  border-radius: 12px;
  padding: var(--gap-size);
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* Cells */
.cell {
  background-color: var(--cell-bg);
  border-radius: 6px;
  cursor: default;
  position: relative;
  transition: background-color 0.2s, box-shadow 0.2s;
  z-index: 1;
}

.cell:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.cell.valid-move {
  cursor: pointer;
  background-color: var(--cell-hover);
  box-shadow: inset 0 0 0 2px var(--highlight-color);
  animation: pulse-glow 1.5s infinite alternate;
}

.cell.valid-move:hover {
  background-color: rgba(99, 102, 241, 0.25);
  box-shadow: inset 0 0 0 2px var(--highlight-color), 0 0 8px var(--highlight-color);
}

@keyframes pulse-glow {
  0% { opacity: 0.85; }
  100% { opacity: 1; }
}

/* Last-move marker: a soft amber ring on the destination cell */
.cell.last-move::after {
  content: '';
  position: absolute;
  inset: 4px;
  border-radius: 4px;
  box-shadow: inset 0 0 0 2px rgba(251, 191, 36, 0.65);
  pointer-events: none;
}

/* Move History Panel */
.move-log {
  list-style: none;
  max-height: 168px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-right: 4px;
}

.move-log-empty {
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 300;
  padding: 0.25rem 0;
}

.move-log-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  padding: 0.2rem 0.35rem;
  border-radius: 6px;
}

.move-log-item:nth-child(odd) {
  background: rgba(255, 255, 255, 0.03);
}

.move-num {
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  min-width: 1.4rem;
  font-size: 0.72rem;
}

.move-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.move-text {
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* Sound Toggle Button */
.sound-toggle {
  margin-top: 0.6rem;
  width: 100%;
  font-size: 0.85rem;
  opacity: 0.9;
}

.sound-toggle.muted {
  opacity: 0.55;
}

/* Pawns */
.pawn {
  position: absolute;
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: calc(var(--cell-size) * 0.55);
  z-index: 5;
  pointer-events: none;
  transition: left 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), 
              top 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.3));
}

.pawn.player-1 {
  background: radial-gradient(circle at 35% 35%, #818cf8 0%, #4f46e5 70%, #312e81 100%);
  border-radius: 50%;
  border: 2px solid #a5b4fc;
}

.pawn.player-2 {
  background: radial-gradient(circle at 35% 35%, #fda4af 0%, #f43f5e 70%, #9f1239 100%);
  border-radius: 50%;
  border: 2px solid #fecdd3;
}

.pawn.active-turn {
  animation: bounce-turn 1.8s infinite ease-in-out;
  box-shadow: 0 0 15px rgba(255, 255, 255, 0.3);
}

@keyframes bounce-turn {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1) translateY(-2px); }
}

/* Intersection Points (Hover trigger zones) */
.intersection-point {
  position: relative;
  width: 100%;
  height: 100%;
  cursor: pointer;
  z-index: 10;
}

/* Expanded hover zone */
.intersection-point::after {
  content: '';
  position: absolute;
  top: -12px;
  left: -12px;
  right: -12px;
  bottom: -12px;
}

/* Permanent Walls */
.wall {
  background-color: var(--wall-color);
  box-shadow: 0 0 8px var(--wall-glow), inset 0 1px 1px rgba(255, 255, 255, 0.2);
  z-index: 3;
  border-radius: 3px;
  pointer-events: none; /* Let clicks bypass permanent walls */
}

/* Only the wall just placed this turn animates in (others are re-rendered silently) */
.wall.just-placed {
  animation: wall-spawn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.wall-h {
  height: var(--gap-size);
  margin-top: 0;
}

.wall-v {
  width: var(--gap-size);
  margin-left: 0;
}

/* Wall Placement Previews */
.wall-preview {
  background-color: var(--preview-color);
  opacity: 0.55;
  z-index: 8;
  border-radius: 3px;
  pointer-events: none; /* Let hover persist */
}

.wall-preview.invalid {
  background: repeating-linear-gradient(
    45deg,
    #ef4444,
    #ef4444 6px,
    #dc2626 6px,
    #dc2626 12px
  );
  opacity: 0.6;
}

.wall-preview-h {
  height: var(--gap-size);
}

.wall-preview-v {
  width: var(--gap-size);
}

/* Shake Animation for Invalid Clicks */
.shake {
  animation: shake-anim 0.35s ease-in-out;
}

@keyframes shake-anim {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(4, 6, 14, 0.85);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-content {
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  max-width: 420px;
  width: 100%;
  padding: 2.25rem;
  text-align: center;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  animation: modal-slide-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.modal-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  animation: float 2s infinite ease-in-out;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.modal-title {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

#win-message {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  font-size: 1.05rem;
}

/* Rules / Instructions Sheet */
.rules-card {
  margin-top: 1rem;
}

.rules-list {
  padding-left: 1rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.rules-list li {
  margin-bottom: 0.4rem;
}

.rules-list li strong {
  color: var(--text-primary);
}

/* Helper Utilities */
.hidden {
  display: none !important;
}

.flex {
  display: flex !important;
}

/* Hotkey Indicator Badge */
.badge {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-family: monospace;
  color: #a5b4fc;
}
