/* ===== Checkers - Mobile responsive ===== */
:root {
  --light-sq: #d4a574;
  --dark-sq: #5c3d2e;
  --board-frame: #2b1a12;
  --accent: #e94560;
  --red-piece: #c62828;
  --red-piece-edge: #8e1b1b;
  --black-piece: #1a1a1a;
  --black-piece-edge: #0a0a0a;
  --highlight: rgba(255, 220, 80, 0.55);
  --move-dot: rgba(255, 255, 255, 0.85);
  --capture-ring: #ff6b6b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Outfit", sans-serif;
  background: linear-gradient(135deg, #1a120b 0%, #3d2914 45%, #2a1c10 100%);
  min-height: 100vh;
  color: #f5f0e8;
  -webkit-tap-highlight-color: transparent;
}

.wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px;
}

/* ===== Level screen ===== */
.level-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  text-align: center;
}

.level-screen h1 {
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  margin: 0 0 8px;
  font-weight: 700;
}

.level-screen > p {
  margin: 0 0 24px;
  opacity: 0.9;
  font-size: 1rem;
}

.level-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}

.level-btn {
  padding: 16px 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.level-btn:hover,
.level-btn:focus-visible {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.5);
}

.level-btn:active {
  transform: scale(0.98);
}

.level-name {
  font-weight: 700;
  font-size: 1.1rem;
}

.level-desc {
  font-size: 0.85rem;
  opacity: 0.85;
  margin-top: 4px;
}

.level-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 8px;
}

.level-header h1 {
  margin: 0;
}

/* ===== Help button ===== */
.help-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}

.help-btn:hover,
.help-btn:focus-visible {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.6);
}

/* ===== Help modal ===== */
.help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 20px;
}

.help-overlay.hidden {
  display: none;
}

.help-modal {
  background: linear-gradient(145deg, #2b1a12 0%, #3d2914 100%);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
}

.help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.help-header h2 {
  margin: 0;
  font-size: 1.35rem;
}

.help-close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.help-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.help-body {
  padding: 20px;
}

.help-body p {
  margin: 0 0 12px;
}

.help-body ul {
  margin: 0;
  padding-left: 20px;
}

.help-body li {
  margin-bottom: 10px;
  line-height: 1.45;
}

.help-body li:last-child {
  margin-bottom: 0;
}

/* ===== Game screen ===== */
.game-screen {
  width: 100%;
  max-width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-screen.hidden,
.level-screen.hidden {
  display: none;
}

/* ===== Header ===== */
.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  width: 100%;
  max-width: 560px;
}

.header h1 {
  font-size: clamp(1.25rem, 4vw, 1.5rem);
  margin: 0;
  font-weight: 700;
}

.level-badge {
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.2);
  font-size: 0.8rem;
  font-weight: 600;
}

.turn-label {
  font-size: 0.95rem;
  font-weight: 600;
}

.turn-label.ai-thinking {
  opacity: 0.75;
  font-style: italic;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.btn {
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.25);
  color: inherit;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn:hover,
.btn:focus-visible {
  background: rgba(255, 255, 255, 0.35);
}

.btn:active {
  transform: scale(0.97);
}

.btn-ghost {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-large {
  padding: 12px 24px;
  font-size: 1rem;
}

/* ===== Board ===== */
.game-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 200px;
  padding: 8px 0;
}

.board-wrap {
  padding: 10px;
  background: var(--board-frame);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(92vw, 520px);
  height: min(92vw, 520px);
  max-width: 100%;
  aspect-ratio: 1;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  user-select: none;
}

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

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

.square.selected {
  box-shadow: inset 0 0 0 3px var(--highlight);
}

.square.highlight::after {
  content: "";
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: var(--move-dot);
  opacity: 0.7;
  pointer-events: none;
}

.square.highlight.capture::after {
  width: 72%;
  height: 72%;
  background: transparent;
  border: 3px solid var(--capture-ring);
  opacity: 0.9;
  box-sizing: border-box;
}

.square.can-capture {
  box-shadow: inset 0 0 0 2px rgba(255, 200, 50, 0.7);
}

/* ===== Pieces ===== */
.piece {
  width: 72%;
  height: 72%;
  border-radius: 50%;
  cursor: pointer;
  position: relative;
  z-index: 1;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.4), inset 0 2px 4px rgba(255, 255, 255, 0.25);
  transition: transform 0.12s;
}

.piece:hover {
  transform: scale(1.06);
}

.piece.red {
  background: radial-gradient(circle at 35% 30%, #ef5350, var(--red-piece) 55%, var(--red-piece-edge));
  border: 2px solid var(--red-piece-edge);
}

.piece.black {
  background: radial-gradient(circle at 35% 30%, #555, var(--black-piece) 55%, var(--black-piece-edge));
  border: 2px solid #333;
  cursor: default;
}

.piece.black:hover {
  transform: none;
}

.piece.king::before {
  content: "♛";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.7rem, 3.5vw, 1.25rem);
  line-height: 1;
  color: #ffd54f;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

.piece.disabled {
  pointer-events: none;
}

/* Flying piece during move animation */
.piece.flying {
  position: absolute;
  z-index: 20;
  pointer-events: none;
  margin: 0;
  transition: left 0.22s ease-in-out, top 0.22s ease-in-out, transform 0.22s ease-in-out;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.55), inset 0 2px 4px rgba(255, 255, 255, 0.25);
  transform: scale(1.08);
}

.piece.flying.landing {
  transform: scale(1);
}

/* Captured piece fade / shrink */
.piece.capturing {
  animation: capture-pop 0.28s ease-out forwards;
  pointer-events: none;
  z-index: 15;
}

@keyframes capture-pop {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(0.2);
  }
}

.square.anim-source .piece {
  visibility: hidden;
}

.board.animating {
  pointer-events: none;
}

/* ===== Result overlay ===== */
.result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.result-overlay.hidden {
  display: none;
}

.result-box {
  background: linear-gradient(145deg, #2b1a12 0%, #3d2914 100%);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  padding: 32px;
  text-align: center;
  max-width: 360px;
  width: 100%;
}

.result-box h2 {
  margin: 0 0 8px;
  font-size: 1.75rem;
  color: var(--accent);
}

.result-box h2.lose {
  color: #90caf9;
}

.result-box h2.draw {
  color: #ffd54f;
}

.result-box p {
  margin: 0 0 24px;
  opacity: 0.9;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ===== Mobile ===== */
@media (max-width: 600px) {
  .header {
    max-width: 100%;
  }

  .header-actions {
    width: 100%;
    margin-left: 0;
    justify-content: flex-end;
  }

  .board {
    width: min(96vw, 420px);
    height: min(96vw, 420px);
  }

  .board-wrap {
    padding: 6px;
  }

  .square.highlight::after {
    width: 32%;
    height: 32%;
  }
}
