/* ============================================================
   CHECKERS — STYLES
   ============================================================ */

/* ==========================================================
   1. RESET & BASE
   ========================================================== */

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

body {
  font-family: var(--font-ui);
  background: var(--color-secondary);
  color: var(--color-neutral-light);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: var(--line-height-normal);
}

#app-header     { order: 1; }
#settings-bar   { order: 2; }
#game-container { order: 3; }
#controls       { order: 4; }
#game-over-modal { order: 5; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================
   2. HEADER
   ========================================================== */

#app-header {
  text-align: center;
  padding: var(--space-6) var(--space-6) var(--space-2);
}

#app-header h1 {
  font-family: var(--font-display);
  font-size: 2.4rem;
  font-weight: var(--font-weight-bold);
  color: var(--color-primary);
  line-height: 1;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ==========================================================
   3. SETTINGS BAR
   ========================================================== */

#settings-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: var(--space-4);
  background: var(--color-secondary-light);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  padding: var(--space-1) var(--space-3);
}

.setting-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: var(--space-1) var(--space-2);
}

.setting-group label {
  font-size: var(--font-size-xs);
  color: var(--color-neutral);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: var(--font-weight-semibold);
}

.setting-divider {
  width: 1px;
  height: 18px;
  background: var(--color-neutral-dark);
  opacity: 0.4;
  flex-shrink: 0;
}

#mode-select,
#difficulty-select {
  background: transparent;
  color: var(--color-neutral-light);
  border: none;
  font-family: var(--font-ui);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  transition: var(--transition-color);
}

#mode-select:hover,
#difficulty-select:hover {
  background: rgba(255, 255, 255, 0.06);
}

#mode-select option,
#difficulty-select option {
  background: var(--color-secondary);
  color: var(--color-neutral-light);
}

#difficulty-label {
  font-size: var(--font-size-xs);
  color: var(--color-neutral);
  font-style: italic;
}

#mute-btn {
  background: none;
  border: none;
  color: var(--color-neutral);
  font-family: var(--font-ui);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  transition: var(--transition-color);
}

#mute-btn:hover {
  color: var(--color-neutral-light);
  background: rgba(255, 255, 255, 0.06);
}

/* ==========================================================
   4. GAME CONTAINER — 3-column layout
   ========================================================== */

#game-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-6);
  padding: 0 var(--space-4);
  width: 100%;
  max-width: 900px;
}

#panel-left,
#panel-right {
  width: 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}

.panel-label {
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-neutral);
  font-weight: var(--font-weight-semibold);
}

#board-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}

/* ==========================================================
   5. BOARD GRID
   ========================================================== */

#game-board {
  --square-size: clamp(44px, min(11vw, 11vh), 70px);
  width: calc(var(--square-size) * 8);
  height: calc(var(--square-size) * 8);
  display: grid;
  grid-template-columns: repeat(8, var(--square-size));
  grid-template-rows: repeat(8, var(--square-size));
  border: 4px solid var(--color-primary-dark);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.3),
    var(--shadow-strong),
    0 0 40px rgba(0, 0, 0, 0.4);
}

.board-row {
  display: contents;
}

.square {
  width: var(--square-size);
  height: var(--square-size);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.square.light {
  background: var(--board-light);
}

.square.dark {
  background: var(--board-dark);
}

/* ==========================================================
   6. PIECES
   ========================================================== */

.piece {
  width: 80%;
  height: 80%;
  border-radius: var(--radius-full);
  position: absolute;
  top: 10%;
  left: 10%;
  cursor: pointer;
  transition: var(--transition-piece);
  z-index: 2;
}

/* --- Player (red) pieces --- */
.piece.player {
  background: radial-gradient(circle at 38% 35%,
    var(--piece-player-light) 0%,
    var(--piece-player-dark) 100%);
  box-shadow:
    inset 0 -4px 6px rgba(0, 0, 0, 0.45),
    inset 0 3px 5px rgba(255, 255, 255, 0.15),
    0 3px 6px rgba(0, 0, 0, 0.5);
}

/* --- AI (black) pieces --- */
.piece.ai {
  background: radial-gradient(circle at 38% 35%,
    var(--piece-ai-light) 0%,
    var(--piece-ai-dark) 100%);
  box-shadow:
    inset 0 -4px 6px rgba(0, 0, 0, 0.6),
    inset 0 3px 5px rgba(255, 255, 255, 0.08),
    0 3px 6px rgba(0, 0, 0, 0.5);
  cursor: default;
}

/* --- King treatment: stacked double-disc with gold crown band --- */
.piece.king {
  /* Raise the piece slightly to look "taller" */
  box-shadow:
    inset 0 -4px 6px rgba(0, 0, 0, 0.45),
    inset 0 3px 5px rgba(255, 255, 255, 0.15),
    0 2px 0 1px rgba(0, 0, 0, 0.3),
    0 4px 0 1px rgba(0, 0, 0, 0.15),
    0 6px 10px rgba(0, 0, 0, 0.5);
}

.piece.king.player {
  box-shadow:
    inset 0 -4px 6px rgba(0, 0, 0, 0.45),
    inset 0 3px 5px rgba(255, 255, 255, 0.15),
    0 2px 0 1px var(--piece-player-dark),
    0 4px 0 1px rgba(0, 0, 0, 0.2),
    0 6px 10px rgba(0, 0, 0, 0.5);
}

.piece.king.ai {
  box-shadow:
    inset 0 -4px 6px rgba(0, 0, 0, 0.6),
    inset 0 3px 5px rgba(255, 255, 255, 0.08),
    0 2px 0 1px var(--piece-ai-dark),
    0 4px 0 1px rgba(0, 0, 0, 0.3),
    0 6px 10px rgba(0, 0, 0, 0.5);
}

/* Gold crown band — inner ring */
.piece.king::before {
  content: '';
  position: absolute;
  top: 18%;
  left: 18%;
  width: 64%;
  height: 64%;
  border-radius: var(--radius-full);
  border: 2.5px solid var(--color-primary);
  box-shadow:
    0 0 6px rgba(226, 180, 90, 0.5),
    inset 0 0 4px rgba(226, 180, 90, 0.3);
  pointer-events: none;
  z-index: 3;
}

/* Crown symbol — properly sized */
.piece.king::after {
  content: '\2655';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--color-primary);
  font-size: clamp(12px, calc(var(--square-size) * 0.28), 22px);
  text-shadow:
    0 1px 3px rgba(0, 0, 0, 0.8),
    0 0 6px rgba(226, 180, 90, 0.4);
  pointer-events: none;
  line-height: 1;
  z-index: 4;
}

/* --- Hover states --- */
#game-board.player-turn .piece.player:hover {
  transform: scale(1.08);
  box-shadow:
    inset 0 -4px 6px rgba(0, 0, 0, 0.45),
    inset 0 3px 5px rgba(255, 255, 255, 0.15),
    0 6px 16px rgba(0, 0, 0, 0.6);
}

#game-board:not(.player-turn):not(.ai-turn) .piece {
  cursor: default;
}

/* 2-Player mode */
#game-board.ai-turn .piece.ai {
  cursor: pointer;
}

#game-board.ai-turn .piece.ai:hover {
  transform: scale(1.08);
  box-shadow:
    inset 0 -4px 6px rgba(0, 0, 0, 0.6),
    inset 0 3px 5px rgba(255, 255, 255, 0.08),
    0 6px 16px rgba(0, 0, 0, 0.6);
}

#game-board.ai-turn .piece.player {
  cursor: default;
}

#game-board.ai-turn .piece.player:hover {
  transform: none;
}

#game-board.player-turn .piece.ai {
  cursor: default;
}

/* ==========================================================
   7. HIGHLIGHTS
   ========================================================== */

.square.selected {
  box-shadow: var(--shadow-glow-selected);
  z-index: 1;
}

.square.valid-move::after {
  content: '';
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: var(--radius-full);
  background: var(--highlight-valid);
  z-index: 3;
  pointer-events: none;
  animation: fadeIn 150ms ease forwards;
}

.square.forced-jump::after {
  content: '';
  position: absolute;
  width: 65%;
  height: 65%;
  border-radius: var(--radius-full);
  border: 3px solid var(--highlight-jump);
  background: transparent;
  z-index: 3;
  pointer-events: none;
  animation: pulse-ring 1s ease-in-out infinite;
}

.square.invalid-flash {
  background: rgba(239, 68, 68, 0.3) !important;
  transition: background 200ms;
}

@keyframes pulse-ring {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.5; }
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.5); }
  to { opacity: 1; transform: scale(1); }
}

/* --- Hint highlight --- */
.square.hint-from {
  box-shadow: 0 0 12px 4px var(--highlight-hint);
  z-index: 1;
}

.square.hint-to::after {
  content: '';
  position: absolute;
  width: 36%;
  height: 36%;
  border-radius: var(--radius-full);
  background: var(--highlight-hint);
  z-index: 3;
  pointer-events: none;
  animation: pulse-hint 1.2s ease-in-out infinite;
}

@keyframes pulse-hint {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.3); }
}

/* --- Last-move trace --- */
.square.last-move::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--highlight-last-move);
  pointer-events: none;
  z-index: 0;
}

/* ==========================================================
   8. TURN INDICATOR & STATUS BAR
   ========================================================== */

#turn-indicator {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  min-height: 1.5em;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-neutral);
  transition: var(--transition-color);
}

#turn-indicator.ai-thinking .dot {
  display: inline-block;
  animation: dotPulse 1.4s ease-in-out infinite;
}
#turn-indicator.ai-thinking .dot:nth-child(2) { animation-delay: 0.2s; }
#turn-indicator.ai-thinking .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

#status-bar {
  min-height: 1.2em;
  font-size: var(--font-size-xs);
  color: var(--color-neutral);
  transition: var(--transition-fade);
  text-align: center;
  opacity: 0.7;
}

#status-bar.fade-out {
  opacity: 0;
}

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

#status-bar.shake {
  animation: shake 300ms ease;
}

/* ==========================================================
   9. CAPTURED TRAYS
   ========================================================== */

.captured-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;
  min-height: 24px;
  padding: var(--space-1);
}

.captured-piece {
  width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  opacity: 0.6;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.captured-piece.player-cap {
  background: radial-gradient(circle at 35% 35%,
    var(--piece-player-light),
    var(--piece-player-dark));
}

.captured-piece.ai-cap {
  background: radial-gradient(circle at 35% 35%,
    var(--piece-ai-light),
    var(--piece-ai-dark));
}

/* ==========================================================
   10. GAME ACTION CONTROLS
   ========================================================== */

#controls {
  margin-top: var(--space-3);
  padding: var(--space-2) var(--space-4);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
}

#new-game-btn,
#undo-btn,
#hint-btn {
  background: transparent;
  color: var(--color-neutral);
  border: 1px solid var(--color-neutral-dark);
  padding: var(--space-2) var(--space-6);
  border-radius: 999px;
  cursor: pointer;
  font-size: var(--font-size-sm);
  font-family: var(--font-ui);
  font-weight: var(--font-weight-semibold);
  letter-spacing: 0.03em;
  transition: all 200ms ease;
}

#new-game-btn:hover,
#undo-btn:hover:not(:disabled),
#hint-btn:hover:not(:disabled) {
  background: var(--color-primary);
  color: var(--color-secondary-dark);
  border-color: var(--color-primary);
}

#new-game-btn.confirming {
  background: var(--color-error);
  border-color: var(--color-error);
  color: var(--color-neutral-light);
}

#undo-btn:disabled,
#hint-btn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

/* ==========================================================
   11. GAME OVER MODAL
   ========================================================== */

#game-over-modal {
  background: var(--color-secondary-light);
  color: var(--color-neutral-light);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  text-align: center;
  max-width: 380px;
  width: 90%;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
}

#game-over-modal[open] {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  animation: modal-open 350ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes modal-open {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}

#game-over-modal::backdrop {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

#modal-title {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: var(--font-weight-bold);
  margin-bottom: 0;
  line-height: 1;
  letter-spacing: 0.02em;
}

#modal-title.win   { color: var(--color-success); }
#modal-title.loss  { color: var(--color-error); }
#modal-title.draw  { color: var(--color-primary); }

#modal-stats {
  margin: 0;
  font-size: var(--font-size-sm);
  color: var(--color-neutral);
  line-height: var(--line-height-relaxed);
}

#modal-stats ul {
  list-style: none;
  padding: 0;
}

#modal-stats li {
  padding: 2px 0;
}

.stat-divider {
  border: none;
  border-top: 1px solid var(--color-neutral-dark);
  opacity: 0.3;
  margin: var(--space-2) 0;
}

.stat-label {
  color: var(--color-neutral);
}

.stat-value {
  color: var(--color-neutral-light);
  font-weight: var(--font-weight-semibold);
}

#play-again-btn {
  background: var(--color-primary);
  color: var(--color-secondary-dark);
  font-weight: var(--font-weight-bold);
  border: none;
  border-radius: 999px;
  padding: var(--space-3) var(--space-8);
  cursor: pointer;
  font-size: var(--font-size-base);
  font-family: var(--font-ui);
  letter-spacing: 0.02em;
  transition: all 200ms ease;
}

#play-again-btn:hover {
  background: var(--color-primary-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(226, 180, 90, 0.3);
}

/* ==========================================================
   12. UNDO BOARD TRANSITION
   ========================================================== */

#game-board.undo-flash {
  animation: undoPulse 350ms ease-out;
}

@keyframes undoPulse {
  0%   { opacity: 1; }
  30%  { opacity: 0.4; }
  100% { opacity: 1; }
}

/* ==========================================================
   13. PIECE ANIMATION STATES
   ========================================================== */

.piece.captured {
  opacity: 0 !important;
  transform: scale(0.3) !important;
  transition: opacity 250ms ease-in, transform 250ms ease-in !important;
  pointer-events: none;
}

.piece.promoting {
  transform: scale(1.3) !important;
  transition: transform 250ms cubic-bezier(0.34, 1.56, 0.64, 1) !important;
}

/* ==========================================================
   14. KEYBOARD FOCUS
   ========================================================== */

.square:focus {
  outline: none;
}

.square:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: -3px;
  z-index: 3;
}

button:focus-visible,
select:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ==========================================================
   15. RESPONSIVE
   ========================================================== */

@media (max-width: 1023px) {
  #game-container {
    flex-direction: column;
    gap: var(--space-4);
  }

  #panel-left,
  #panel-right {
    flex-direction: row;
    width: auto;
    min-height: auto;
    gap: var(--space-2);
  }

  .panel-label {
    writing-mode: initial;
  }
}

@media (max-width: 767px) {
  #app-header {
    padding: var(--space-4) var(--space-2) var(--space-1);
  }

  #app-header h1 {
    font-size: var(--font-size-lg);
  }

  #settings-bar {
    border-radius: var(--radius-md);
    padding: var(--space-1);
    gap: 0;
    margin-bottom: var(--space-2);
  }

  .setting-group {
    padding: var(--space-1);
    gap: 4px;
  }

  .setting-group label {
    display: none;
  }

  #game-board {
    --square-size: clamp(44px, min(11.5vw, 11.5vh), 70px);
  }

  #game-over-modal {
    max-width: 90vw;
    padding: var(--space-6);
  }

  #controls {
    margin-top: var(--space-2);
  }
}

@media (max-width: 767px) and (orientation: landscape) {
  #game-board {
    --square-size: clamp(44px, min(9vw, 11vh), 60px);
  }
}

@media (hover: none) {
  .piece:hover {
    transform: none !important;
  }
}

/* ==========================================================
   16. REDUCED MOTION
   ========================================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
