:root {
  --bg: #f5ede1; --ink: #2b1a0e; --muted: #7a6150; --card: #fffaf2; --line: #e2d3bf;
  --wood: #b07a45; --wood-dark: #7a4c25; --groove: #4a2c15;
  --accent: #c2410c; --accent-ink: #fff; --gold: #f5b83d;
  --goat: #f7efe0; --goat-edge: #a88a63; --tiger: #e48a2a; --tiger-edge: #7a3d0c; --stripe: #2a1609;
  --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: #8a5a33; --wood-dark: #4f2f14; --groove: #24140a;
    --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); }
.also { color: var(--muted); font-size: 14px; margin-top: 18px; text-align: center; }
.also a { color: inherit; }
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: 2.9em; margin: 4px 0 6px; font-size: 17px; display: flex; align-items: center; justify-content: center; }
.status .you { color: var(--you); } .status .them { color: var(--them); }
.status .mill { color: var(--accent); }

.boardWrap { width: min(100%, calc((100svh - 300px) * var(--ar, 1)), 640px); min-width: 260px; margin: 0 auto; aspect-ratio: var(--ar, 1); }
.board { width: 100%; height: 100%; display: block; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.board .slab { fill: url(#woodGrad); }
.board .groove { fill: none; stroke: var(--groove); stroke-width: 7; stroke-linecap: round; }
.board .groove.diag { stroke-width: 5; }
.board .flash-line { fill: none; stroke: #ef4444; stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; opacity: 0; transition: opacity .2s; }
.board .flash-line.on { opacity: .9; }
.board .dot { fill: var(--groove); }
.board .hit { fill: transparent; cursor: default; }
.board .hit.target { cursor: pointer; }
.board .ring { fill: none; stroke: var(--gold); stroke-width: 4; opacity: 0; pointer-events: none; }
.board .ring.on { opacity: .95; }
.board .ring.last { opacity: .55; stroke-dasharray: 6 6; }
.piece { transition: transform .28s cubic-bezier(.2,.8,.2,1), opacity .3s; pointer-events: none; }
.piece circle.base { stroke-width: 3; }
.piece.goat circle.base { fill: url(#goatGrad); stroke: var(--goat-edge); }
.piece.tiger circle.base { fill: url(#tigerGrad); stroke: var(--tiger-edge); }
.piece .stripe { fill: none; stroke: var(--stripe); stroke-width: 3.4; stroke-linecap: round; }
.piece .horn { fill: none; stroke: #5c4326; stroke-width: 4.5; stroke-linecap: round; }
.piece.sel circle.base { stroke: var(--gold); stroke-width: 6; }
.piece.doomed circle.base { stroke: #ef4444; stroke-width: 6; }
.piece.gone { opacity: 0; }

.hand { display: flex; justify-content: center; align-items: center; gap: 4px; min-height: 26px; flex-wrap: wrap; }
.hand .who { font-size: 13px; font-weight: 700; margin-right: 6px; }
.hand .who.goat { color: var(--you); } .hand .who.tiger { color: var(--them); }
.hand .tally { font-size: 13px; color: var(--muted); margin-left: 6px; }
.hand .tally b { color: var(--ink); }
.hand i { width: 16px; height: 16px; border-radius: 50%; display: inline-block; box-shadow: 0 1px 2px rgba(0,0,0,.45); }
.hand i.goat { background: radial-gradient(circle at 35% 30%, #fff, var(--goat) 60%, var(--goat-edge)); }
.hand i.taken { opacity: .35; }
.hand .left { font-size: 13px; color: var(--muted); margin-left: 6px; }

.controls { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
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, dialog ul { padding-left: 20px; margin: 4px 0; }
dialog li { margin: 4px 0; }
dialog .reg { color: var(--accent); font-weight: 600; font-size: 14px; margin: 0; }
dialog .src { font-size: 13px; color: var(--muted); }
.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) { .status { font-size: 15.5px; } .boardWrap { width: min(100%, calc((100svh - 270px) * var(--ar, 1))); } }
@media (prefers-reduced-motion: reduce) { .piece { transition: none; } }
