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

:root {
  --bg: #14100c;
  --bg-card: #241c14;
  --text: #f6ecdf;
  --text-muted: #c0ac96;
  --accent: #e0b079;
  --accent-hover: #f0c894;

  --radius: 22px;
  --radius-pit: 50%;
}

html {
  font-size: 16px;
}

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 90% 60% at 50% -10%, rgba(224, 176, 121, 0.10), transparent 70%),
    radial-gradient(ellipse 70% 50% at 50% 120%, rgba(90, 55, 30, 0.25), transparent 70%);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.app {
  width: 100%;
  max-width: 760px;
}

/* ---------- Header ---------- */
.header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.header h1 {
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.15rem;
}

.wins {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

.wins span {
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.difficulty-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

select {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  border: 1px solid rgba(224, 176, 121, 0.25);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
}

.btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.5rem 1.1rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #3a2412;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:hover {
  background: var(--accent-hover);
}

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

.btn-large {
  font-size: 1rem;
  padding: 0.65rem 1.5rem;
  margin-top: 0.5rem;
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--accent);
  border: 1px solid rgba(224, 176, 121, 0.3);
}

.btn-secondary:hover {
  background: #30251a;
}

.btn-icon {
  background: var(--bg-card);
  color: var(--accent);
  border: 1px solid rgba(224, 176, 121, 0.3);
  font-size: 1.05rem;
  line-height: 1;
  padding: 0.4rem 0.65rem;
  position: relative;
}

.btn-icon:hover {
  background: #30251a;
}

.btn-icon.muted {
  color: var(--text-muted);
}

/* Diagonal slash to show music is off */
.btn-icon.muted::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 70%;
  height: 2px;
  background: var(--text-muted);
  transform: translate(-50%, -50%) rotate(-45deg);
  border-radius: 2px;
}

/* ---------- Scoreboard ---------- */
.scoreboard {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  min-width: 64px;
  padding: 0.4rem 0.7rem;
  border-radius: 12px;
  background: var(--bg-card);
  border: 1px solid rgba(224, 176, 121, 0.15);
  transition: border-color 0.25s, box-shadow 0.25s, transform 0.25s;
}

.score-name {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
}

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

.score.active {
  border-color: rgba(224, 176, 121, 0.6);
  box-shadow: 0 0 0 2px rgba(224, 176, 121, 0.25), 0 4px 16px rgba(0, 0, 0, 0.3);
  transform: translateY(-1px);
}

.score.bump {
  animation: score-bump 0.45s ease-out;
}

@keyframes score-bump {
  0% { transform: scale(1); }
  35% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.status {
  text-align: center;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--accent);
  min-height: 1.4em;
}

/* ---------- Board ---------- */
.board-wrapper {
  padding: 0.25rem;
  perspective: 1200px;
}

.board {
  display: grid;
  grid-template-columns: 92px 1fr 92px;
  grid-template-rows: auto auto;
  gap: 0.85rem;
  padding: 1.1rem;
  border-radius: var(--radius);

  /* Walnut surface with a carved, beveled wooden frame */
  background-image:
    linear-gradient(rgba(60, 36, 18, 0.12), rgba(40, 22, 10, 0.28)),
    url('assets/wood-board.jpg');
  background-color: #9a6638;
  background-size: cover;
  background-position: center;

  border: 1px solid rgba(40, 24, 12, 0.6);
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.55),
    0 2px 0 rgba(255, 226, 188, 0.18),                 /* top bevel highlight */
    inset 0 2px 3px rgba(255, 230, 195, 0.35),         /* inner rim light */
    inset 0 -4px 8px rgba(20, 10, 4, 0.55),            /* inner rim shadow */
    inset 0 0 0 6px rgba(60, 38, 20, 0.45),            /* carved channel */
    inset 0 0 0 7px rgba(255, 220, 180, 0.10);
  transition: box-shadow 0.3s;
}

/* ---------- Pits & stores (carved hollows) ---------- */
.store {
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 230px;
  position: relative;
  border-radius: 46px;

  background-image:
    radial-gradient(ellipse 75% 80% at 50% 42%, rgba(10, 5, 2, 0.15), rgba(10, 5, 2, 0.62) 92%),
    url('assets/wood-dark.jpg');
  background-color: #3c2415;
  background-size: cover;
  background-position: center;

  box-shadow:
    inset 0 6px 12px rgba(0, 0, 0, 0.7),
    inset 0 -3px 6px rgba(0, 0, 0, 0.55),
    inset 0 2px 1px rgba(0, 0, 0, 0.5),
    0 1px 0 rgba(255, 226, 188, 0.16);
}

.store-player { grid-column: 3; } /* your store sits on your right */
.store-ai { grid-column: 1; }

.store .stones {
  position: relative;
  flex: 1;
  width: 100%;
  align-self: stretch;
  min-height: 120px;
}

.store-label {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(246, 236, 223, 0.65);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
  z-index: 3;
}

.store-count {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  z-index: 3;
}

.pits-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.6rem;
  min-width: 0; /* allow the 1fr board column to shrink instead of overflowing */
}

.pits-row .pit {
  min-width: 0;
}

.pits-ai { grid-column: 2; grid-row: 1; }
.pits-player { grid-column: 2; grid-row: 2; }

.pit {
  aspect-ratio: 1;
  border: none;
  border-radius: var(--radius-pit);
  cursor: default;
  position: relative;
  padding: 0;
  overflow: visible;

  background-image:
    radial-gradient(circle at 50% 38%, rgba(10, 5, 2, 0.05), rgba(10, 5, 2, 0.6) 95%),
    url('assets/wood-dark.jpg');
  background-color: #3c2415;
  background-size: cover;
  background-position: center;

  box-shadow:
    inset 0 7px 14px rgba(0, 0, 0, 0.72),
    inset 0 -3px 7px rgba(0, 0, 0, 0.5),
    inset 0 3px 2px rgba(0, 0, 0, 0.45),
    0 1px 0 rgba(255, 226, 188, 0.18);
  transition: transform 0.15s, box-shadow 0.2s;
}

.pit-ai {
  cursor: default;
  pointer-events: none;
}

.pit-player.playable {
  cursor: pointer;
  box-shadow:
    inset 0 7px 14px rgba(0, 0, 0, 0.6),
    inset 0 -3px 7px rgba(0, 0, 0, 0.4),
    0 0 0 2px rgba(224, 176, 121, 0.55),
    0 0 16px rgba(224, 176, 121, 0.35);
}

.pit-player.playable:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow:
    inset 0 7px 14px rgba(0, 0, 0, 0.55),
    0 0 0 3px rgba(224, 176, 121, 0.75),
    0 6px 20px rgba(224, 176, 121, 0.4);
}

.pit.last-move {
  box-shadow:
    inset 0 7px 14px rgba(0, 0, 0, 0.6),
    0 0 0 2px rgba(224, 176, 121, 0.5);
}

.pit.sowing {
  animation: sow-pulse 0.22s ease-out;
}

@keyframes sow-pulse {
  0% { transform: scale(1); }
  45% { transform: scale(1.07); }
  100% { transform: scale(1); }
}

.pit.captured,
.store.capture-flash {
  animation: capture-flash 0.6s ease-out;
}

@keyframes capture-flash {
  0%, 100% { box-shadow:
    inset 0 7px 14px rgba(0, 0, 0, 0.72),
    inset 0 -3px 7px rgba(0, 0, 0, 0.5),
    0 1px 0 rgba(255, 226, 188, 0.18); }
  30% { box-shadow:
    inset 0 0 18px rgba(255, 222, 150, 0.9),
    0 0 22px rgba(255, 210, 130, 0.8),
    0 0 0 3px rgba(255, 220, 150, 0.9); }
}

.pit-count {
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.72rem;
  font-weight: 700;
  color: rgba(246, 236, 223, 0.85);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  line-height: 1;
  z-index: 4;
  pointer-events: none;
}

/* ---------- Marbles (warm stone / agate) ---------- */
.stones {
  position: absolute;
  inset: 8%;
  pointer-events: none;
}

.marble {
  position: absolute;
  border-radius: 50%;
  aspect-ratio: 1; /* keep marbles perfectly round even in tall/narrow stores */
  transform: translate(-50%, -50%) rotate(var(--rot, 0deg));
  background:
    radial-gradient(circle at 32% 26%, rgba(255, 255, 255, 0.92) 0%, rgba(255, 255, 255, 0.35) 9%, rgba(255, 255, 255, 0) 22%),
    radial-gradient(circle at 70% 78%, rgba(0, 0, 0, 0.28) 0%, rgba(0, 0, 0, 0) 45%),
    var(--agate);
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.55),
    inset 0 -2px 4px rgba(0, 0, 0, 0.35),
    inset 0 2px 3px rgba(255, 255, 255, 0.25);
}

.marble.drop {
  animation: marble-drop 0.22s ease-out;
}

@keyframes marble-drop {
  0% { transform: translate(-50%, -130%) rotate(var(--rot, 0deg)) scale(0.6); opacity: 0; }
  60% { opacity: 1; }
  100% { transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) scale(1); opacity: 1; }
}

/* ---------- Legend ---------- */
.legend {
  margin-top: 1.25rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
  padding: 0 0.5rem;
}

/* ---------- Overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 7, 4, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 100;
  backdrop-filter: blur(5px);
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  background:
    linear-gradient(rgba(36, 24, 14, 0.86), rgba(28, 18, 10, 0.92)),
    url('assets/wood-dark.jpg');
  background-size: cover;
  background-position: center;
  border: 1px solid rgba(224, 176, 121, 0.3);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 20px 56px rgba(0, 0, 0, 0.6);
}

.overlay-card h2 {
  font-size: 1.6rem;
  margin-bottom: 0.5rem;
  color: var(--accent);
}

.overlay-card p {
  color: var(--text);
  margin-bottom: 0.25rem;
}

/* ---------- Rules modal ---------- */
.rules-card {
  max-width: 520px;
  text-align: left;
}

.rules-card h2 {
  text-align: center;
}

.rules-body {
  max-height: 60vh;
  overflow-y: auto;
  margin: 0.75rem 0 1rem;
}

.rules-body p {
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.55;
  margin-bottom: 0.75rem;
}

.rules-body ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-bottom: 0.75rem;
}

.rules-body li {
  position: relative;
  padding-left: 1.4rem;
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.5;
}

.rules-body li::before {
  content: '●';
  position: absolute;
  left: 0;
  top: 0.05rem;
  color: var(--accent);
  font-size: 0.7rem;
}

.rules-body li strong {
  color: var(--accent);
}

.rules-tip {
  margin-bottom: 0 !important;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(224, 176, 121, 0.15);
  font-style: italic;
}

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  body { padding: 0.75rem; }

  .header { margin-bottom: 0.75rem; }
  .header h1 { font-size: 1.5rem; }
  .subtitle { display: none; }

  .board {
    grid-template-columns: 58px 1fr 58px;
    padding: 0.6rem;
    gap: 0.45rem;
    border-radius: 16px;
  }

  .store {
    min-height: 175px;
    border-radius: 30px;
  }

  .store .stones { min-height: 90px; }
  .store-count { font-size: 1.1rem; }

  .pits-row { gap: 0.4rem; }

  .pit-count { font-size: 0.62rem; }

  .score { min-width: 52px; padding: 0.3rem 0.5rem; }
  .score-value { font-size: 1.2rem; }
  .status { font-size: 0.82rem; }

  .legend { font-size: 0.75rem; margin-top: 1rem; }
}

@media (max-width: 380px) {
  .board { grid-template-columns: 48px 1fr 48px; gap: 0.35rem; }
  .pits-row { gap: 0.3rem; }
  .store { min-height: 155px; }
}

@media (prefers-reduced-motion: reduce) {
  .marble.drop,
  .pit.sowing,
  .pit.captured,
  .store.capture-flash,
  .score.bump {
    animation: none;
  }
}

/* GameKit toolbar (sign-in · leaderboard · Play Online) sits on its own row under the header. */
.gk-mount {
  flex-basis: 100%;
  display: flex;
  justify-content: flex-end;
  margin-top: 0.35rem;
}
.overlay-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  flex-wrap: wrap;
}
@media (max-width: 640px) {
  .gk-mount { justify-content: center; }
}
