:root {
  --bg: #f4ede1;
  --ink: #2b2118;
  --muted: #7a6a58;
  --wood: #8a5a2b;
  --wood-dark: #5e3b1a;
  --pit: #4a2e14;
  --pit-hover: #6b4422;
  --seed: #f2d7a6;
  --accent: #d9822b;
  --ok: #3f8a4a;
  --bad: #b3452f;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1814;
    --ink: #eee3d2;
    --muted: #a8977f;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.top {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 14px 20px;
}
.top h1 { margin: 0; font-size: 1.6rem; letter-spacing: .02em; }
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.controls label { font-size: .85rem; color: var(--muted); display: flex; gap: 6px; align-items: center; }
select, button {
  font: inherit; font-size: .9rem; padding: 6px 10px; border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--ink) 25%, transparent);
  background: color-mix(in srgb, var(--bg) 80%, white); color: var(--ink);
}
button { cursor: pointer; background: var(--accent); color: white; border-color: transparent; }
button.ghost { background: transparent; color: var(--ink); border-color: color-mix(in srgb, var(--ink) 25%, transparent); }
button.link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 0 4px; }

main { max-width: 980px; margin: 0 auto; padding: 8px 16px 40px; }

.side-label { font-weight: 600; margin: 8px 6px; display: flex; gap: 8px; align-items: center; }
.bottom-label { justify-content: flex-end; }
.score { background: var(--wood); color: var(--seed); border-radius: 999px; padding: 0 10px; min-width: 2.2em; text-align: center; }

.board {
  display: grid;
  grid-template-columns: 1.1fr repeat(6, 1fr) 1.1fr;
  grid-template-rows: 1fr 1fr;
  gap: 12px;
  padding: 18px;
  background: linear-gradient(180deg, var(--wood), var(--wood-dark));
  border-radius: 80px;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.15), 0 10px 30px rgba(0,0,0,.25);
  aspect-ratio: 8 / 2.6;
}
.row { display: contents; }

/* Vertical board: computer's store on top, yours at the bottom, your pits down the left. */
body.vertical .board {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto repeat(6, auto) auto;
  /* Sized from the window height so the whole column fits without scrolling. */
  width: clamp(160px, calc((100dvh - 270px) / 2.9), 340px);
  margin: 0 auto;
  aspect-ratio: auto;
  border-radius: 60px;
  padding: 14px;
  gap: 8px;
}
body.vertical .pit { aspect-ratio: 1.3 / 1; }
body.vertical .store { aspect-ratio: 3 / 1; }
body.vertical .side-label { margin: 4px 6px; }
body.vertical .status { margin-top: 10px; }
body.vertical .store .seeds { inset: 16% 12% 22%; }
body.vertical .side-label { justify-content: center; }

.pit, .store {
  position: relative;
  background: var(--pit);
  border-radius: 999px;
  box-shadow: inset 0 6px 14px rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .15s, box-shadow .15s;
  min-height: 0;
}
.pit { aspect-ratio: 1; align-self: center; }
.pit.playable { cursor: pointer; }
.pit.playable:hover { background: var(--pit-hover); transform: translateY(-2px); }
.pit.flash, .store.flash { box-shadow: inset 0 6px 14px rgba(0,0,0,.55), 0 0 0 3px var(--accent); }
.pit.captured { box-shadow: inset 0 6px 14px rgba(0,0,0,.55), 0 0 0 3px var(--bad); }
.pit.last { box-shadow: inset 0 6px 14px rgba(0,0,0,.55), 0 0 0 2px var(--seed); }

.seeds { position: absolute; inset: 14%; pointer-events: none; }
.seed {
  position: absolute; width: 22%; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6e2, var(--seed) 45%, #b9935a);
  box-shadow: 0 1px 2px rgba(0,0,0,.5);
}
.store .seeds { inset: 10% 18%; }
.store .seed { width: 26%; }
.count {
  position: absolute; bottom: -2px; right: -2px;
  font-size: .78rem; font-weight: 700; color: var(--seed);
  background: rgba(0,0,0,.45); border-radius: 999px; padding: 0 7px;
}
.store .count { bottom: 8px; right: 50%; transform: translateX(50%); font-size: 1rem; }

/* Store names */
.store-name {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  font-size: .68rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: color-mix(in srgb, var(--seed) 70%, transparent); white-space: nowrap; pointer-events: none;
}
body.vertical .store-name { top: 6px; }

/* ── Whose turn ──
   The side that is NOT moving fades back; the mover's store glows; the mover's
   label lights up. Your playable pits get a soft ring so you can see them without hovering. */
.pit, .store { transition: background .15s, transform .15s, box-shadow .25s, opacity .25s, filter .25s; }
body[data-turn="1"] .pit[data-slot="0"], body[data-turn="1"] .pit[data-slot="1"],
body[data-turn="1"] .pit[data-slot="2"], body[data-turn="1"] .pit[data-slot="3"],
body[data-turn="1"] .pit[data-slot="4"], body[data-turn="1"] .pit[data-slot="5"],
body[data-turn="0"] .pit[data-slot="7"], body[data-turn="0"] .pit[data-slot="8"],
body[data-turn="0"] .pit[data-slot="9"], body[data-turn="0"] .pit[data-slot="10"],
body[data-turn="0"] .pit[data-slot="11"], body[data-turn="0"] .pit[data-slot="12"] {
  opacity: .45; filter: saturate(.5);
}
body[data-turn="0"] .store[data-slot="6"],
body[data-turn="1"] .store[data-slot="13"] {
  box-shadow: inset 0 6px 14px rgba(0,0,0,.55), 0 0 0 3px var(--accent), 0 0 18px var(--accent);
}
body[data-turn="0"] .pit.playable {
  box-shadow: inset 0 6px 14px rgba(0,0,0,.55), 0 0 0 2px color-mix(in srgb, var(--accent) 75%, transparent);
  animation: breathe 1.8s ease-in-out infinite;
}
@keyframes breathe {
  50% { box-shadow: inset 0 6px 14px rgba(0,0,0,.55), 0 0 0 3px var(--accent), 0 0 12px var(--accent); }
}
@media (prefers-reduced-motion: reduce) { body[data-turn="0"] .pit.playable { animation: none; } }

.side-label { transition: opacity .25s; }
.side-label:not(.active) { opacity: .55; }
body[data-turn="over"] .side-label { opacity: 1; }
.side-label.active .score { background: var(--accent); color: white; }
.turn-tag {
  display: none; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--accent);
}
.side-label.active .turn-tag { display: inline; }
#aiLabel.active .turn-tag { animation: blink 1.2s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .35; } }

.status { text-align: center; font-size: 1.15rem; min-height: 1.6em; margin: 18px 0 6px; }
.status.win { color: var(--ok); font-weight: 700; }
.status.lose { color: var(--bad); font-weight: 700; }
.record { text-align: center; color: var(--muted); font-size: .9rem; }

dialog { border: 0; border-radius: 14px; max-width: 520px; background: var(--bg); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.4); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog li { margin-bottom: 6px; }

@media (max-width: 640px) {
  .board { gap: 6px; padding: 10px; border-radius: 40px; aspect-ratio: auto; }
  .count { font-size: .65rem; padding: 0 4px; }
}
