:root {
  --bg: #f5ede1;
  --ink: #2b1a0e;
  --muted: #7a6150;
  --card: #fffaf2;
  --line: #e2d3bf;
  --wood: #8a5a33;
  --wood-dark: #5e3a1d;
  --pit: #4a2c15;
  --pit-hi: #6b4120;
  --seed: #f3e3c3;
  --seed-edge: #c9a978;
  --accent: #c2410c;
  --accent-ink: #fff;
  --you: #0f766e;
  --them: #9a3412;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b130d;
    --ink: #f2e6d6;
    --muted: #b49c86;
    --card: #261a11;
    --line: #3d2b1d;
    --wood: #6e4526;
    --wood-dark: #47290f;
    --pit: #2a170a;
    --pit-hi: #4a2c15;
    --accent: #f97316;
    --accent-ink: #1b130d;
    --you: #2dd4bf;
    --them: #fb923c;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Helvetica, Arial, sans-serif;
  min-height: 100vh; display: flex; flex-direction: column;
}
.bar {
  display: flex; align-items: center; gap: 8px; padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
}
.bar h1 { flex: 1; margin: 0; font-size: 20px; letter-spacing: .01em; }
main { flex: 1; width: 100%; max-width: 900px; margin: 0 auto; padding: 0 16px 16px; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; }
.lead { margin: 4px 0 0; color: var(--muted); }
button { font: inherit; color: inherit; cursor: pointer; border-radius: 10px; }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.ghost { background: transparent; border: 1px solid var(--line); padding: 7px 12px; }
.ghost:hover { border-color: var(--accent); }
.primary { background: var(--accent); color: var(--accent-ink); border: 0; padding: 9px 18px; font-weight: 700; }
.primary.big { width: 100%; padding: 14px; font-size: 18px; margin-top: 22px; }

.variants { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.variant {
  text-align: left; background: var(--card); border: 2px solid var(--line); padding: 12px 14px;
  display: grid; gap: 2px;
}
.variant[aria-checked="true"] { border-color: var(--accent); }
.variant b { font-size: 17px; }
.variant .reg { font-size: 13px; color: var(--accent); font-weight: 600; }
.variant .bl { font-size: 13.5px; color: var(--muted); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.seg button { background: var(--card); border: 2px solid var(--line); padding: 8px 12px; flex: 1 1 auto; }
.seg button[aria-checked="true"] { border-color: var(--accent); font-weight: 700; }

.status { text-align: center; font-weight: 700; min-height: 1.5em; margin: 8px 0 12px; font-size: 17px; }
.status .you { color: var(--you); } .status .them { color: var(--them); }

.board {
  --n: 6;
  display: grid; grid-template-columns: repeat(calc(var(--n) + 2), minmax(0, 1fr));
  grid-template-rows: auto auto;
  gap: 8px; padding: 12px; border-radius: 28px; margin: 0 auto;
  max-width: calc(min(900px, (100svh - 240px) * (var(--n) + 2) / 2.1));
  background: linear-gradient(160deg, var(--wood), var(--wood-dark));
  box-shadow: 0 10px 30px rgba(43, 26, 14, .35), inset 0 2px 0 rgba(255,255,255,.12);
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
/* Portrait phones: rotate the board so pits are big enough to tap.
   Your row runs down the left, the opponent's up the right; sowing stays counter-clockwise. */
.board.vertical {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: 0.7fr repeat(var(--n), 1fr) 0.7fr;
  width: calc(2 * ((100svh - 310px) / (var(--n) + 1.4)) + 28px);
  max-width: 100%; min-width: 112px;
  padding: 10px; gap: 7px 10px;
}
.board.vertical .store { min-height: 0; aspect-ratio: auto; flex-direction: row; padding: 0 14px; justify-content: space-between; }
.board.vertical .store .seeds { inset: 12% 20% 12% 40%; }
.board.vertical .store .seed { width: 14%; }
.game .status { margin: 4px 0 8px; }
.board.vertical .store .count { margin: 0; }
.board.vertical .pit .count { top: auto; bottom: -1px; right: 2px; }
.pit, .store {
  position: relative; border-radius: 999px; background: radial-gradient(circle at 50% 35%, var(--pit-hi), var(--pit));
  box-shadow: inset 0 4px 10px rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; border: 0; padding: 0;
}
.pit { aspect-ratio: 1; min-width: 0; }
.store { border-radius: 999px; flex-direction: column; min-height: 100%; padding: 6px 0; }
.pit .count, .store .count {
  position: absolute; font-size: 12px; font-weight: 700; color: #fbe9cf; text-shadow: 0 1px 2px #000;
}
.pit .count { bottom: -2px; right: 4px; }
.pit.top .count { top: -2px; bottom: auto; }
.store .count { bottom: 6px; font-size: 15px; position: static; margin-top: auto; }
.store .lbl { font-size: 11px; font-weight: 700; color: #fbe9cf; opacity: .85; text-align: center; padding: 0 2px; }
.seeds { position: absolute; inset: 14%; pointer-events: none; }
.store .seeds { inset: 22px 14% 26px; }
.seed {
  position: absolute; width: 26%; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff8e8, var(--seed) 55%, var(--seed-edge));
  box-shadow: 0 1px 1.5px rgba(0,0,0,.6);
}
.store .seed { width: 20%; }
.pit.playable { cursor: pointer; box-shadow: inset 0 4px 10px rgba(0,0,0,.55), 0 0 0 3px rgba(251, 191, 36, .75); }
.pit.playable:hover { filter: brightness(1.15); }
.pit.flash { animation: flash .35s ease-out; }
.pit.cap { animation: cap .5s ease-out; }
.pit.from { box-shadow: inset 0 4px 10px rgba(0,0,0,.55), 0 0 0 3px #fff; }
@keyframes flash { from { filter: brightness(1.8); } to { filter: none; } }
@keyframes cap { 0% { box-shadow: 0 0 0 0 #fbbf24; } 60% { box-shadow: 0 0 0 8px rgba(251,191,36,.0); } }

.controls { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.variantNote { text-align: center; color: var(--muted); font-size: 13.5px; margin: 12px 0 0; }

dialog {
  border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--ink);
  max-width: min(560px, calc(100vw - 32px)); padding: 18px 20px;
}
dialog::backdrop { background: rgba(20, 12, 6, .55); }
dialog h2 { margin-top: 0; color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 20px; }
dialog h3 { margin: 14px 0 4px; font-size: 16px; }
dialog ol { padding-left: 20px; margin: 4px 0; }
dialog li { margin: 4px 0; }
dialog .reg { color: var(--accent); font-weight: 600; font-size: 14px; margin: 0; }
.row-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
dialog form { display: flex; justify-content: flex-end; margin-top: 12px; }

.foot { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; color: var(--muted); font-size: 13px; padding: 12px 16px max(12px, env(safe-area-inset-bottom)); }
.foot a { color: inherit; }

@media (max-width: 520px) {
  .board:not(.vertical) { gap: 5px; padding: 8px; border-radius: 20px; }
  .pit .count { font-size: 11px; }
  .store .lbl { font-size: 9.5px; }
}
@media (max-width: 640px) and (orientation: portrait) and (max-height: 900px) {
  .variantNote { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .pit.flash, .pit.cap { animation: none; }
}
