/* Mancala (Kalah) — single-screen, board-first. Brand-aligned, two-player hot-seat. */

:root {
  --gof-primary-dark: #157623;
  --gof-primary: #9bca3e;
  --gof-bg-light: #dde5ed;
  --gof-bg-mint: #defff0;
  --gof-accent: #ffb920;
  --gof-warm: #de6739;
  --text-primary: #2f2c28;
  --text-secondary: #5e5c5e;
  --card-bg: #ffffff;
  --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);

  /* Player colours */
  --p1: #1f8a32;
  --p2: #de6739;

  /* Board surface */
  --board-wood: linear-gradient(165deg, #cf9152 0%, #ab6b34 48%, #8a5226 100%);
  --board-edge: #5e3415;
  --pit-hole: radial-gradient(circle at 50% 33%, #7a4c28, #3c2310 88%);
  --stone: radial-gradient(circle at 36% 30%, #fffef8, #ece0c4 54%, #c2ac81);
  --capture-glow: #ffd24a;

  /* Sizing — min() keeps the whole board on screen down to ~320px wide */
  --pit-w: min(10.6vw, 70px);
  --pit-h: var(--pit-w);
  --store-w: min(13vw, 86px);
  --gap: min(1.1vw, 8px);
  --stone-size: min(3.2vw, 13px);
}

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

body {
  font-family: 'Arimo', sans-serif;
  color: var(--text-primary);
  background: linear-gradient(180deg, var(--gof-bg-light) 0%, var(--gof-bg-mint) 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#app {
  flex: 1;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.875rem;
}

/* ===== Shared header bar (per HEADER_SPECS) ===== */
.header-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  width: 100%;
  margin-bottom: 0.25rem;
  padding: 4px 0;
  gap: 12px;
  position: relative;
  z-index: 1100;
}

.header-left { flex: 1; min-width: 0; max-width: 85%; }
.header-right { flex-shrink: 0; min-width: 52px; }

.game-title-wrap { position: relative; display: inline-block; }

.game-title-dropdown-trigger {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
}

.game-title-heading {
  margin: 0;
  font-family: 'League Spartan', sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

.game-title-chevron {
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.game-title-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  min-width: 160px;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 100;
}

.game-title-dropdown[aria-hidden="false"] { display: block; }

.game-nav-link {
  display: block;
  padding: 10px 14px;
  font-size: 0.9rem;
  color: var(--text-primary);
  text-decoration: none;
  border-bottom: 1px solid #e2e8f0;
}

.game-nav-link:last-child { border-bottom: none; }
.game-nav-link:hover { background: var(--gof-bg-mint); }

.mode-row,
.difficulty-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

/* `display: flex` above would otherwise override the [hidden] attribute. */
.difficulty-row[hidden] { display: none; }

.difficulty-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.mode-btn,
.diff-btn {
  display: inline-flex;
  align-items: center;
  padding: 3px 11px;
  min-height: 28px;
  font-family: 'Arimo', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  background: white;
  color: var(--text-secondary);
  border: 1.5px solid #d1d5db;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.mode-btn:hover,
.diff-btn:hover {
  border-color: var(--gof-primary);
  background: var(--gof-bg-mint);
}

.mode-btn[aria-pressed="true"],
.diff-btn[aria-pressed="true"] {
  background: var(--gof-bg-mint);
  color: var(--gof-primary-dark);
  border-color: var(--gof-primary-dark);
  border-width: 2px;
  padding: 2px 10px;
}

/* ===== Scoreboard (live store counts) ===== */
.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  width: 100%;
  max-width: 420px;
}

.score-card {
  background: var(--card-bg);
  border-radius: 10px;
  padding: 0.5rem 0.625rem;
  box-shadow: var(--card-shadow);
  border: 2px solid transparent;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  transition: border-color 0.2s, transform 0.2s, background 0.2s;
}

.score-card.is-current {
  border-color: var(--gof-primary-dark);
  background: var(--gof-bg-mint);
  transform: translateY(-2px);
}

.score-card.is-winner {
  border-color: var(--gof-accent);
  background: #fff6e0;
}

.score-card-name-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.score-card-color {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
}

.score-card-color.is-p1 { background: var(--p1); }
.score-card-color.is-p2 { background: var(--p2); }

.score-card-name {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.score-card-count {
  font-family: 'League Spartan', sans-serif;
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--gof-primary-dark);
  line-height: 1;
}

.score-card-label {
  font-size: 0.65rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ===== Turn indicator ===== */
.turn-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2rem;
  flex-wrap: wrap;
}

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

.turn-dot.is-p1 { background: var(--p1); }
.turn-dot.is-p2 { background: var(--p2); }

.turn-text {
  font-size: 1.05rem;
  color: var(--text-secondary);
}

.turn-text strong {
  font-family: 'League Spartan', sans-serif;
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--gof-primary-dark);
}

.turn-text.turn-final {
  font-family: 'League Spartan', sans-serif;
  font-weight: 800;
  font-size: 1.4rem;
  color: var(--gof-primary-dark);
}

/* ===== Board ===== */
.board-wrap {
  display: flex;
  justify-content: center;
  width: 100%;
}

.board {
  display: grid;
  grid-template-columns: var(--store-w) repeat(6, var(--pit-w)) var(--store-w);
  grid-template-rows: repeat(2, var(--pit-h));
  gap: var(--gap);
  padding: calc(var(--gap) * 1.6);
  background: var(--board-wood);
  border: 3px solid var(--board-edge);
  border-radius: 28px;
  box-shadow: var(--card-shadow), inset 0 2px 6px rgba(255, 255, 255, 0.22);
  user-select: none;
}

/* ===== Pits ===== */
.pit {
  width: var(--pit-w);
  height: var(--pit-h);
  border-radius: 50%;
  position: relative;
  background: var(--pit-hole);
  box-shadow:
    inset 0 5px 11px rgba(0, 0, 0, 0.6),
    inset 0 -2px 4px rgba(255, 255, 255, 0.12),
    0 0 0 2px rgba(0, 0, 0, 0.18);
  transition: transform 0.12s ease, box-shadow 0.15s ease;
}

/* Faint owner-coloured rim so each side reads as a team. */
.pit.owner-p1 {
  box-shadow:
    inset 0 5px 11px rgba(0, 0, 0, 0.6),
    inset 0 -2px 4px rgba(255, 255, 255, 0.12),
    0 0 0 2px rgba(31, 138, 50, 0.55);
}

.pit.owner-p2 {
  box-shadow:
    inset 0 5px 11px rgba(0, 0, 0, 0.6),
    inset 0 -2px 4px rgba(255, 255, 255, 0.12),
    0 0 0 2px rgba(222, 103, 57, 0.6);
}

/* Legal-move highlight for the current player's non-empty pits. */
.pit.is-playable { cursor: pointer; }

.pit.owner-p1.is-playable {
  box-shadow:
    inset 0 5px 11px rgba(0, 0, 0, 0.55),
    0 0 0 3px var(--p1),
    0 0 14px 2px rgba(31, 138, 50, 0.7);
  animation: playable-pulse 1.5s ease-in-out infinite;
}

.pit.owner-p2.is-playable {
  box-shadow:
    inset 0 5px 11px rgba(0, 0, 0, 0.55),
    0 0 0 3px var(--p2),
    0 0 14px 2px rgba(222, 103, 57, 0.7);
  animation: playable-pulse 1.5s ease-in-out infinite;
}

@keyframes playable-pulse {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.pit.is-playable:hover { transform: translateY(-4px) scale(1.04); }

/* A stone just arrived in this pit. */
.pit.receiving { animation: pit-receive 0.26s ease-out; }

@keyframes pit-receive {
  0% { transform: scale(1); }
  45% { transform: scale(1.16); }
  100% { transform: scale(1); }
}

/* The pit a sow started from — briefly dimmed as its stones lift out. */
.pit.is-sowing-from { opacity: 0.55; }

/* Capture / sweep flash on a pit being emptied into a store. */
.pit.captured { animation: capture-flash 0.6s ease-in-out; }

@keyframes capture-flash {
  0%, 100% { background: var(--pit-hole); }
  35%, 70% {
    background: radial-gradient(circle at 50% 35%, #ffe488, #e0991c 88%);
    box-shadow: inset 0 3px 8px rgba(0,0,0,0.4), 0 0 16px 3px var(--capture-glow);
  }
}

/* ===== Stones ===== */
.stones {
  position: absolute;
  inset: 12% 12% 30% 12%;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 2px;
  pointer-events: none;
}

.stone {
  width: var(--stone-size);
  height: var(--stone-size);
  border-radius: 50%;
  background: var(--stone);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  flex-shrink: 0;
}

/* Count chip — the unambiguous source of truth for each pit. */
.pit-count {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'League Spartan', sans-serif;
  font-weight: 800;
  font-size: 0.8rem;
  line-height: 1;
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
  z-index: 2;
}

.pit.owner-p1 .pit-count { background: var(--p1); }
.pit.owner-p2 .pit-count { background: var(--p2); }
.pit.is-empty .pit-count { opacity: 0.45; }

/* ===== Stores ===== */
.store {
  width: var(--store-w);
  border-radius: 999px;
  position: relative;
  box-shadow:
    inset 0 6px 14px rgba(0, 0, 0, 0.55),
    inset 0 -3px 6px rgba(255, 255, 255, 0.18);
  transition: box-shadow 0.2s ease;
}

.store.owner-p1 { background: linear-gradient(165deg, #2faa45, #14601f); }
.store.owner-p2 { background: linear-gradient(165deg, #ec8052, #b1481f); }

.store.store-gain {
  box-shadow:
    inset 0 6px 14px rgba(0, 0, 0, 0.45),
    0 0 0 4px rgba(255, 185, 32, 0.85),
    0 0 20px 4px var(--capture-glow);
}

.store.receiving { animation: pit-receive 0.26s ease-out; }

.store-label {
  position: absolute;
  top: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-family: 'League Spartan', sans-serif;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.92);
}

.store .stones {
  inset: 26% 16% 24% 16%;
}

.store-count {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-family: 'League Spartan', sans-serif;
  font-weight: 800;
  font-size: 1.5rem;
  line-height: 1;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* ===== Status line ===== */
.status-line {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gof-primary-dark);
  text-align: center;
  min-height: 1.4em;
  padding: 0 0.5rem;
}

.status-line.is-result {
  font-family: 'League Spartan', sans-serif;
  font-size: 1.25rem;
  font-weight: 800;
}

/* ===== Play actions ===== */
.play-actions {
  display: flex;
  justify-content: center;
  width: 100%;
  max-width: 360px;
}

.secondary-btn {
  font-family: 'Arimo', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  padding: 0.75rem 1.5rem;
  min-height: 44px;
  background: white;
  color: var(--gof-primary-dark);
  border: 2px solid var(--gof-primary-dark);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.secondary-btn:hover { background: var(--gof-bg-mint); }
.secondary-btn:active { transform: scale(0.97); }

/* ===== Footer ===== */
.footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.footer-links a {
  color: var(--gof-primary-dark);
  text-decoration: none;
  font-weight: 600;
}

.footer-links a:hover { text-decoration: underline; }

/* ===== Mobile tweaks ===== */
@media (max-width: 480px) {
  #app { padding: 0.875rem 0.5rem 1.25rem; }
  :root {
    --pit-w: min(11.4vw, 70px);
    --store-w: min(14vw, 86px);
    --gap: min(1vw, 8px);
    --stone-size: min(3.4vw, 13px);
  }
  .turn-text strong { font-size: 1.15rem; }
  .score-card-count { font-size: 1.55rem; }
  .store-count { font-size: 1.25rem; }
  .pit-count { font-size: 0.72rem; padding: 2px 6px; }
}

@media (max-width: 340px) {
  :root { --pit-w: 32px; --store-w: 40px; --gap: 3px; --stone-size: 7px; }
}
