/* ════════════════════════════════════════════════════════════════════════
   style.css — Checkers
   ════════════════════════════════════════════════════════════════════════ */

/* ── Theme variables ──────────────────────────────────────────────────── */

:root {
  /* Board squares — identical in both themes */
  --sq-light: #f0e6cc;
  --sq-dark:  #4a7c59;

  /* Piece colours */
  --piece-red:       #b52020;
  --piece-red-hi:    #d84040;
  --piece-red-rim:   #7a1010;
  --piece-white:     #f2efea;
  --piece-white-hi:  #ffffff;
  --piece-white-rim: #b0aba2;

  /* Move highlights */
  --hi-last:      rgba(255, 210,   0, 0.42);
  --hi-potential: rgba( 40, 120, 220, 0.38);
  --hi-selected:  rgba( 50, 190, 110, 0.42);

  /* Light theme UI */
  --bg:                #f5f0e8;
  --surface:           #fdfaf4;
  --surface-alt:       #f0ebe0;
  --text:              #2c2318;
  --text-muted:        #7a6a56;
  --border:            #ddd0b8;
  --accent:            #4a7c59;
  --accent-hover:      #3d6b4c;
  --card-active-bg:    #eaf3ed;
  --card-active-ring:  rgba( 74, 124,  89, 0.30);
  --card-winner-bg:    #fffbea;
  --card-winner-ring:  rgba(180, 140,   0, 0.28);
  --btn-bg:            #e8e0d0;
  --btn-fg:            #2c2318;
  --btn-hover:         #ddd4c0;
  --board-border:      #2a1e0e;
}

[data-theme="dark"] {
  --bg:                #15120d;
  --surface:           #1e1a13;
  --surface-alt:       #272218;
  --text:              #e8e0d0;
  --text-muted:        #8a7a65;
  --border:            #3a3224;
  --accent:            #5e9e74;
  --accent-hover:      #508860;
  --card-active-bg:    #192219;
  --card-active-ring:  rgba( 94, 158, 116, 0.30);
  --card-winner-bg:    #1e1c10;
  --card-winner-ring:  rgba(200, 160,   0, 0.25);
  --btn-bg:            #2c2820;
  --btn-fg:            #e8e0d0;
  --btn-hover:         #36302a;
  --board-border:      #0e0c08;
}

/* ── Reset ────────────────────────────────────────────────────────────── */

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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.25s, color 0.25s;
}

/* ── Utility ──────────────────────────────────────────────────────────── */

.hidden { display: none !important; }

/* ── Theme toggle ─────────────────────────────────────────────────────── */

#theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 300;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
#theme-toggle:hover {
  background: var(--surface-alt);
  transform: scale(1.08);
}

/* ── Mode-selection screen ────────────────────────────────────────────── */

#mode-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding: 72px 32px 56px;
  width: 100%;
  max-width: 420px;
}

#mode-screen h1 {
  font-size: 3rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}

/* Mode buttons */
.mode-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.mode-btn {
  width: 100%;
  padding: 16px 20px;
  font-size: 1.05rem;
  font-weight: 500;
  text-align: left;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.mode-btn:hover {
  background: var(--surface-alt);
  border-color: var(--accent);
}
.mode-btn.active {
  border-color: var(--accent);
  background: var(--card-active-bg);
  color: var(--accent);
  font-weight: 600;
}

/* Difficulty selector */
#difficulty-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.section-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.diff-options {
  display: flex;
  gap: 8px;
  width: 100%;
}

.diff-btn {
  flex: 1;
  padding: 12px 8px;
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.diff-btn:hover {
  background: var(--surface-alt);
  border-color: var(--accent);
}
.diff-btn.active {
  border-color: var(--accent);
  background: var(--card-active-bg);
  color: var(--accent);
  font-weight: 600;
}

/* Start button */
#start-btn {
  width: 100%;
  padding: 16px;
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
#start-btn:hover  { background: var(--accent-hover); }
#start-btn:active { transform: scale(0.98); }

/* ── Game screen layout ───────────────────────────────────────────────── */

.game-layout {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 28px;
  padding: 44px 24px;
  width: 100%;
}

.board-area {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Board ────────────────────────────────────────────────────────────── */

#board {
  display: grid;
  grid-template-columns: repeat(8, 64px);
  grid-template-rows: repeat(8, 64px);
  border: 7px solid var(--board-border);
  border-radius: 4px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.35);
  overflow: hidden;
  user-select: none;
  cursor: default;
  transition: transform 0.0s ease;
}

.square {
  position: relative;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.square.light { background-color: var(--sq-light); }
.square.dark  { background-color: var(--sq-dark); }

/* Highlight overlay — sits above the square colour, below pieces */
.square::before {
  content: '';
  position: absolute;
  inset: 0;
  background: transparent;
  pointer-events: none;
  z-index: 1;
  transition: background 0.12s;
}
.square.last-move::before  { background: var(--hi-last); }
.square.selected::before   { background: var(--hi-selected); }
.square.potential::before  { background: var(--hi-potential); }

/* ── Pieces ───────────────────────────────────────────────────────────── */

.piece {
  position: relative;
  z-index: 2;
  width: 80%;
  height: 80%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s;
}

.square.dark .piece { cursor: pointer; }

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

/* HvH board flip — rotates board 180°; counter-rotates pieces to stay upright */
#board.flipped                { transform: rotate(180deg); }
#board.flipped .piece         { transform: rotate(180deg); }
#board.flipped .piece:hover   { transform: rotate(180deg) scale(1.07); }
#board.flipped .piece.lifted  { transform: rotate(180deg) scale(1.12); }

.piece.red {
  background: radial-gradient(circle at 36% 32%, var(--piece-red-hi), var(--piece-red) 68%);
  border: 3px solid var(--piece-red-rim);
  box-shadow:
    0 4px 10px rgba(0,0,0,0.50),
    inset 0 -3px 6px rgba(0,0,0,0.28),
    inset 0 2px 4px rgba(255,255,255,0.12);
}

.piece.white {
  background: radial-gradient(circle at 36% 32%, var(--piece-white-hi), var(--piece-white) 68%);
  border: 3px solid var(--piece-white-rim);
  box-shadow:
    0 4px 10px rgba(0,0,0,0.35),
    inset 0 -3px 6px rgba(0,0,0,0.12),
    inset 0 2px 4px rgba(255,255,255,0.60);
}

.piece:hover  { transform: scale(1.07); }
.piece.lifted { transform: scale(1.12); }

/* King crown */
.piece.king::after {
  content: '♛';
  position: absolute;
  font-size: 1.05rem;
  line-height: 1;
  pointer-events: none;
}
.piece.red.king::after   { color: rgba(255, 235, 170, 0.90); }
.piece.white.king::after { color: rgba(  70,  50,  30, 0.78); }

/* ── Status bar ───────────────────────────────────────────────────────── */

#status-bar {
  margin-top: 16px;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  min-height: 1.5em;
  text-align: center;
  letter-spacing: 0.01em;
  transition: font-size 0.15s, color 0.15s;
}

#status-bar.game-over {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
}

/* ── Game controls ────────────────────────────────────────────────────── */

.game-controls {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.game-controls button {
  padding: 10px 20px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--btn-bg);
  color: var(--btn-fg);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.game-controls button:hover  {
  background: var(--btn-hover);
  border-color: var(--accent);
}
.game-controls button:active { transform: scale(0.97); }

/* ── Score cards ──────────────────────────────────────────────────────── */

.score-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 16px;
  width: 148px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 14px;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.score-card.active {
  border-color: var(--accent);
  background: var(--card-active-bg);
  box-shadow: 0 0 0 3px var(--card-active-ring);
}

.score-card.winner {
  border-color: #b8960a;
  background: var(--card-winner-bg);
  box-shadow: 0 0 0 3px var(--card-winner-ring);
}

/* Colour swatch mirrors piece appearance */
.color-swatch {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 3px solid transparent;
  flex-shrink: 0;
}
.color-swatch.red {
  background: radial-gradient(circle at 36% 32%, var(--piece-red-hi), var(--piece-red) 68%);
  border-color: var(--piece-red-rim);
  box-shadow: 0 3px 8px rgba(0,0,0,0.40);
}
.color-swatch.white {
  background: radial-gradient(circle at 36% 32%, var(--piece-white-hi), var(--piece-white) 68%);
  border-color: var(--piece-white-rim);
  box-shadow: 0 3px 8px rgba(0,0,0,0.25);
}

/* Player name input */
.player-name {
  width: 100%;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  color: var(--text);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 4px 4px 0 0;
  padding: 3px 4px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.player-name:hover         { border-bottom-color: var(--accent); }
.player-name:focus         { border-bottom-color: var(--accent); background: var(--surface-alt); }
.player-name[readonly]     {
  cursor: default;
  border-bottom-color: transparent;
  color: var(--text-muted);
  font-weight: 500;
}

.score-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.score-value {
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ── Responsive ───────────────────────────────────────────────────────── */

@media (max-width: 820px) {
  .game-layout {
    flex-direction: column;
    align-items: center;
    padding: 20px 12px;
    gap: 14px;
  }

  /* Horizontal score cards stacked above/below board on narrow screens */
  .score-card {
    flex-direction: row;
    width: 100%;
    max-width: 530px;
    padding: 12px 18px;
    gap: 14px;
    justify-content: space-between;
    align-items: center;
  }

  .score-label { display: none; }

  .score-value { font-size: 1.6rem; }

  /* Scale board squares down proportionally */
  #board {
    grid-template-columns: repeat(8, min(calc((100vw - 24px) / 8), 64px));
    grid-template-rows:    repeat(8, min(calc((100vw - 24px) / 8), 64px));
  }

  .square {
    width:  min(calc((100vw - 24px) / 8), 64px);
    height: min(calc((100vw - 24px) / 8), 64px);
  }
}
