/* Doppio: crisp white. White page, near-black ink, light grey cards and empty squares, one typeface (Inter 400/500/600/700).
   Players: blue = rows (first player), red = columns (second player); used for score cards, line scores and the thin
   border outside a scoring die. Dice: white, or soft tone-on-tone (Spectrum, Cool) chosen on the setup screen.
   Spacing scale: 4 / 8 / 12 / 16 / 24 / 32 / 40. */

@font-face {
  font-family: "Inter";
  src: url("../assets/fonts/inter-var.woff2") format("woff2-variations"), url("../assets/fonts/inter-var.woff2") format("woff2");
  font-weight: 100 900; font-style: normal; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #ffffff;
  --card: #f3f4f6;        /* score cards, setup panels */
  --track: #e8eaee;       /* segmented-control track */
  --ink: #111418;
  --ink-2: #4f5560;
  --ink-3: #6b717c;
  --ink-4: #a9aeb6;
  --sq: #eceef1;          /* empty square */
  --sq-hi: #dde1e6;       /* empty square under the pointer / drag target */
  --die: #ffffff;
  --pip-ink: #1c1f24;
  --edge: #cfd3d9;        /* edge of a white die (Light) */
  --edge-2: #a3a9b2;      /* edge of a white die (Dark) */
  --rows: #2f5fd0;
  --cols: #d9483b;
  --btn: #2f5fd0;
  --btn-ink: #ffffff;
  --scrim: rgba(17, 20, 24, .36);
  --r-card: 16px;
  --pad: 16px;
  --ease: cubic-bezier(.2, .8, .3, 1);
  --t: 1;                 /* motion multiplier (0 with reduced motion) */
  color-scheme: light;
}
@media (prefers-reduced-motion: reduce) { :root { --t: 0; } }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif; font-weight: 400;
  font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--rows); outline-offset: 2px; }
[hidden] { display: none !important; }
b { font-weight: 600; }
h1, h2, h3 { font-weight: 600; }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.app {
  min-height: 100vh; min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) max(var(--pad), env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(var(--pad), env(safe-area-inset-left));
  max-width: 1280px; margin: 0 auto;
}
.t-rows { color: var(--rows); font-weight: 600; }
.t-cols { color: var(--cols); font-weight: 600; }

/* ---------- buttons ---------- */
.ghost-btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 14px; border-radius: 10px;
  font-size: 14px; font-weight: 500; color: var(--ink-2); white-space: nowrap; transition: background-color calc(var(--t) * 150ms);
}
.ghost-btn:hover { background: var(--card); color: var(--ink); }
.ghost-btn:active { background: var(--track); }
.ghost-btn.big { min-height: 52px; background: var(--card); color: var(--ink); border-radius: 14px; font-size: 15px; }
.ghost-btn.big:hover { background: var(--track); }
.go {
  width: 100%; min-height: 56px; border-radius: 14px; background: var(--btn); color: var(--btn-ink);
  display: flex; align-items: center; justify-content: center; padding: 0 20px;
  font-size: 17px; font-weight: 600; transition: opacity calc(var(--t) * 150ms);
}
.go:hover { opacity: .92; }
.go:active { opacity: .85; }
.go.small { min-height: 52px; font-size: 15px; }

/* ---------- setup: a game's front door, one column ---------- */
.setup { max-width: 480px; margin: 0 auto; padding-top: 8px; }
.hero { padding: 16px 0 8px; }
.wordmark { margin: 0; font-size: 48px; font-weight: 700; letter-spacing: -1.6px; line-height: 1; }

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-top: 32px; border-radius: 16px; background: var(--card); }
.modes button {
  min-height: 52px; border-radius: 12px; font-size: 15px; font-weight: 500; color: var(--ink-2);
  transition: background-color calc(var(--t) * 150ms), color calc(var(--t) * 150ms);
}
.modes button:hover:not(.on) { color: var(--ink); }
/* before js/ui.js runs, the saved choice is only on <html> (index.html's head script; refresh() keeps it current) */
.modes button.on, :root[data-play="cpu"] #s-mode [data-v="cpu"], :root[data-play="human"] #s-mode [data-v="human"] { background: var(--bg); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(17, 20, 24, .08); }

:root[data-play="cpu"] #sect-human, :root[data-play="human"] #sect-cpu { display: none; } /* the panel for who you play */
.panel { margin-top: 12px; padding: 20px; background: var(--card); border-radius: 20px; display: grid; gap: 20px; }
.field { min-width: 0; }
.field-l { margin-bottom: 8px; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.seg { display: flex; gap: 2px; padding: 3px; border-radius: 12px; background: var(--track); }
.seg button {
  flex: 1 1 0; min-width: 0; min-height: 40px; padding: 4px 6px; border-radius: 9px;
  font-size: 14px; font-weight: 500; color: var(--ink-2); white-space: nowrap; line-height: 1.2;
  transition: background-color calc(var(--t) * 150ms), color calc(var(--t) * 150ms);
}
.seg button:hover:not(:disabled):not(.on) { color: var(--ink); }
/* Difficulty and You go: the saved choice is on <html> before js/ui.js runs, like the tab */
.seg button.on,
:root[data-opp="naive"] #s-opp [data-v='"naive"'],
:root[data-opp="selfish"] #s-opp [data-v='"selfish"'],
:root[data-opp="balanced"] #s-opp [data-v='"balanced"'],
:root[data-opp="look"] #s-opp [data-v='"look"'],
:root[data-opp="strong"] #s-opp [data-v='"strong"'],
:root[data-me="first"] #s-me [data-v='"first"'],
:root[data-me="second"] #s-me [data-v='"second"'],
:root[data-me="random"] #s-me [data-v='"random"'] { background: var(--bg); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(17, 20, 24, .08); }
.seg button:disabled { color: var(--ink-4); cursor: not-allowed; }
.seg.wrap { flex-wrap: wrap; }
.seg.wrap button { flex: 1 1 auto; padding: 4px 12px; }
.note { margin: 8px 0 0; font-size: 13px; color: var(--ink-3); line-height: 1.45; }
.note:empty { display: none; }

.names { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.name { display: block; min-width: 0; cursor: text; }
.name span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.name-rows span { color: var(--rows); }
.name-cols span { color: var(--cols); }
.name input {
  width: 100%; min-width: 0; border: 0; background: var(--bg); color: var(--ink); font: inherit; font-size: 16px; font-weight: 500;
  padding: 10px 12px; border-radius: 10px; outline: none; box-shadow: inset 0 0 0 1px var(--track);
}
.name input:focus { box-shadow: inset 0 0 0 1.5px var(--ink-4); }
.name input::placeholder { color: var(--ink-4); }

.house { margin-top: 12px; background: var(--card); border-radius: 20px; }
.house summary {
  list-style: none; display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 0 20px; cursor: pointer;
  border-radius: 20px; -webkit-tap-highlight-color: transparent;
}
.house summary::-webkit-details-marker { display: none; }
.house-l { font-size: 15px; font-weight: 500; }
.house-v { flex: 1; min-width: 0; text-align: right; font-size: 14px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { width: 16px; height: 16px; flex: none; fill: none; stroke: var(--ink-3); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; transition: transform calc(var(--t) * 200ms) var(--ease); }
.house[open] > summary .chev { transform: rotate(180deg); }
.house .fields { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; padding: 4px 20px 20px; }
/* Extra settings: a quieter nested row inside Rules */
.extra summary { list-style: none; display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--ink-3); padding: 2px 0; }
.extra summary::-webkit-details-marker { display: none; }
.extra summary .chev { width: 14px; height: 14px; }
.extra[open] .chev { transform: rotate(180deg); }
.house .extra .fields { padding: 16px 0 0; }
.reset { justify-self: start; margin-left: -12px; }

.runs-l { margin-top: 16px; }
.rsw { display: inline-flex; gap: 2px; align-items: center; height: 11px; }
.rsw i { width: 8px; height: 8px; border-radius: 2px; display: block; background: #fff; box-shadow: inset 0 0 0 1px var(--edge); }
.rsw-capsule { background: color-mix(in srgb, var(--rows) 24%, transparent); border-radius: 4px; padding: 0 2px; height: 12px; }
.rsw-ring { box-shadow: 0 0 0 1.5px var(--rows); border-radius: 3px; padding: 0 1px; }
.rsw-die i { box-shadow: 0 0 0 1.5px var(--rows); } .rsw-die { gap: 4px; }
.esw { display: inline-flex; gap: 3px; }
.esw i { width: 11px; height: 11px; border-radius: 3px; display: block; background: var(--fill, var(--die)); }
[data-dice="white"] .esw-none i { box-shadow: inset 0 0 0 1px var(--track); } /* the faintest line, so white swatches show on the white popover */
.esw-light i { box-shadow: inset 0 0 0 1.5px var(--rim-l); }
.esw-dark i { box-shadow: inset 0 0 0 1.5px var(--rim-d); }
#s-runs button, #s-edge button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; min-height: 52px; padding: 6px 4px; font-size: 13px; }
/* Difficulty info popover */
.lvf { position: relative; }
.lvf .field-l { display: flex; align-items: center; gap: 4px; }
.info { width: 24px; height: 24px; margin: -4px 0; display: grid; place-items: center; border-radius: 50%; color: var(--ink-3); }
.info:hover { color: var(--ink); }
.info svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; }
.info svg .dot { fill: currentColor; stroke: none; }
.pop { position: absolute; z-index: 30; left: -6px; right: -6px; top: 26px; padding: 14px 16px; background: var(--bg); border-radius: 14px;
  box-shadow: 0 0 0 1px rgba(17, 20, 24, .06), 0 8px 28px rgba(17, 20, 24, .14); display: grid; gap: 10px; }
.pop[hidden] { display: none; }
.pop .lv { display: grid; gap: 1px; font-size: 13.5px; line-height: 1.35; }
.pop .lv b { font-weight: 600; color: var(--ink); }
.pop .lv span { color: var(--ink-2); }
#s-dice button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 52px; padding: 6px 4px; }
.sw { display: inline-flex; gap: 2px; }
.sw i { width: 8px; height: 11px; border-radius: 2px; display: block; }
.sw-white i { background: #fff; box-shadow: inset 0 0 0 1px var(--edge), inset 0 -4px 0 var(--pip-ink); }

.go-bar {
  position: sticky; bottom: 0; z-index: 5; margin: 24px calc(-1 * var(--pad)) 0;
  padding: 8px var(--pad) max(12px, env(safe-area-inset-bottom)); background: var(--bg);
}
.setup-foot { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-top: 4px; padding-bottom: 24px; }
.setup-foot .record { margin: 4px 0 0; text-align: center; }
.record { margin: 0; font-size: 13px; color: var(--ink-3); }
.record:empty { display: none; }

/* ---------- dice faces ---------- */
.pips {
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  width: 58%; height: 58%; gap: 9%; pointer-events: none;
}
.pips i, .pips b { display: block; border-radius: 50%; }
.pips i { background: var(--pip, var(--pip-ink)); }
.num { font-weight: 700; color: var(--pip, var(--pip-ink)); line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; pointer-events: none; }

/* ---------- rules explainer (dialog) ---------- */
.ex-sec + .ex-sec { margin-top: 20px; }
.ex-sec h3 { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
.ex-sec p { margin: 0; font-size: 14px; line-height: 1.55; color: var(--ink-2); }
.ex-sec ol { margin: 0 0 6px; padding-left: 22px; font-size: 14px; line-height: 1.55; color: var(--ink-2); }
.ex-sec p.ex-bag { margin-bottom: 6px; }
.ex-line { display: flex; align-items: center; gap: 6px; margin: 12px 0 4px; flex-wrap: wrap; }
.ex-line .mt { width: 36px; height: 36px; border-radius: 8px; background: var(--die); box-shadow: inset 0 0 0 1.5px var(--edge); display: grid; place-items: center; position: relative; }
.ex-line .mt .pips { width: 60%; height: 60%; gap: 12%; }
.ex-line .mt .num { font-size: 15px; }
.ex-line .mt.sc::after { content: ""; position: absolute; inset: -2px; border-radius: 10px; border: 2px solid var(--rows); }
.ex-line .eq { margin: 0 4px 0 8px; color: var(--ink-3); font-size: 16px; }
.ex-line .eqv { font-size: 18px; font-weight: 600; color: var(--rows); font-variant-numeric: tabular-nums; }
.ex-cap { font-size: 12.5px; color: var(--ink-3); }

/* ---------- game ---------- */
.game {
  --cell: 56px; --gap: 9px; --gut: 28px; --gut-top: 12px; --ds: 70px; --rad: calc(var(--cell) * .2);
  display: flex; flex-direction: column;
  min-height: calc(100dvh - max(16px, env(safe-area-inset-top)) - max(16px, env(safe-area-inset-bottom)));
}
.game > * { flex: none; }
.game > .endbar { order: 4; }
.game.measuring .dock { flex: none; }
.gbar { position: relative; display: flex; align-items: center; gap: 4px; min-height: 40px; }
.wm-s { font-size: 22px; font-weight: 700; letter-spacing: -.5px; line-height: 1; padding: 8px 8px 8px 0; min-height: 40px; }
.gbar .wm-s { margin-right: auto; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.icon-btn svg circle { fill: var(--bg); }
.icon-btn[aria-expanded="true"] { background: var(--card); color: var(--ink); }
.look-pop { left: auto; right: -6px; top: 46px; width: min(360px, calc(100vw - 20px)); display: block; }
.look-pop .seg { margin-bottom: 4px; }
.gbar .ghost-btn { padding: 0 10px; }
.gbar .ghost-btn:last-child { margin-right: -10px; }

.hud { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; margin-top: 12px; }
.side {
  position: relative; min-width: 0; padding: 10px 14px; background: var(--card); border-radius: var(--r-card);
  transition: box-shadow calc(var(--t) * 220ms) ease;
}
.side-top { display: flex; align-items: center; gap: 8px; min-height: 18px; font-size: 13px; color: var(--ink-2); font-weight: 500; }
.side-who { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.side-word { white-space: nowrap; flex: none; margin-left: auto; font-size: 12px; font-weight: 600; }
.side-rows .side-word { color: var(--rows); }
.side-cols .side-word { color: var(--cols); }
.side-total { display: flex; align-items: baseline; gap: 8px; margin-top: 2px; min-height: 42px; }
.side-total > span:first-child { font-size: 34px; font-weight: 700; letter-spacing: -1px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.side-bonus { min-width: 0; font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side.turn.side-rows, .side.win.side-rows { box-shadow: inset 0 0 0 2px var(--rows); }
.side.turn.side-cols, .side.win.side-cols { box-shadow: inset 0 0 0 2px var(--cols); }
.side.lose .side-total > span:first-child { color: var(--ink-4); }
/* bot thinking (Aaron 11-20): a streak orbits the bot's card edge at a constant speed (js/orbit.js) and the solid turn
   ring dims to a faint 22% track under it; rgba, not color-mix, so iOS Safari shows it the same */
.orbit { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; opacity: 0; }
.orbit path { fill: none; stroke: var(--rows); stroke-linecap: round; }
.side-cols .orbit path { stroke: var(--cols); }
.side.track.side-rows { box-shadow: inset 0 0 0 2px rgba(47, 95, 208, .22); }
.side.track.side-cols { box-shadow: inset 0 0 0 2px rgba(217, 72, 59, .22); }
/* score lead (Appearance > Score lead, default off; Aaron 11-19): +n at the right of the leader's total row */
.side-lead { margin-left: auto; flex: none; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; visibility: hidden; }
.side-rows .side-lead { color: var(--rows); } .side-cols .side-lead { color: var(--cols); }
.side-lead.on { visibility: visible; }
.app:not([data-lead="on"]) .side-lead { display: none; }

/* board: only the tile grid defines the centre. Row scores live in the right gutter, column scores in the bottom
   gutter; equal empty gutters on the left (and on top on desktop) keep the tiles centred. */
.board-wrap { min-height: 0; display: flex; align-items: flex-start; justify-content: center; margin-top: 4px; }
.board { position: relative; padding: var(--gut-top) var(--gut) var(--gut); }
.tiles { position: relative; display: grid; grid-template-columns: repeat(var(--n), var(--cell)); grid-auto-rows: var(--cell); gap: var(--gap); }
.rscores { position: absolute; right: 0; top: var(--gut-top); width: var(--gut); display: grid; grid-auto-rows: var(--cell); gap: var(--gap); }
.cscores { position: absolute; left: var(--gut); bottom: 0; height: var(--gut); display: grid; grid-template-columns: repeat(var(--n), var(--cell)); gap: var(--gap); }
.cell {
  position: relative; width: var(--cell); height: var(--cell); border-radius: var(--rad); background: var(--sq);
  display: grid; place-items: center; transition: background-color calc(var(--t) * 150ms);
}
.cell .n { display: contents; }
.cell .num { font-size: calc(var(--cell) * .44); }
.cell .pips { width: 56%; height: 56%; } /* same face proportions as the field die, so nothing jumps when it lands */
.cell.f { background: var(--fill, var(--die)); cursor: default; transition: none; } /* a landing die must show its colour at once: no fade from the empty-square grey */
/* die edges (cfg.edge): a 1.5px inset edge in a tint of the die's own colour, mixed from its fill and pip colours;
   on White the Light edge is the grey it always had. The edge swatches in the Appearance popover use the same tints. */
.cell.f, .die, .esw i {
  --rim-l: color-mix(in oklch, var(--fill, var(--die)) 65%, var(--pip, var(--pip-ink)) 35%);
  --rim-d: color-mix(in oklch, var(--fill, var(--die)) 35%, var(--pip, var(--pip-ink)) 65%);
}
[data-dice="white"] .cell.f, [data-dice="white"] .die, [data-dice="white"] .esw i { --rim-l: var(--edge); --rim-d: var(--edge-2); }
[data-edge="light"] .cell.f { box-shadow: inset 0 0 0 1.5px var(--rim-l); }
[data-edge="dark"] .cell.f { box-shadow: inset 0 0 0 1.5px var(--rim-d); }
[data-runs="die"][data-edge] .cell.f.sr, [data-runs="die"][data-edge] .cell.f.sc { box-shadow: none; } /* the scoring border is its edge */
.cell.can { cursor: pointer; }
@media (hover: hover) { .cell.can:hover { background: var(--sq-hi); } }
/* drop here: the square darkens and grows very slightly */
.cell.target { z-index: 2; transform: scale(1.04); background: color-mix(in srgb, var(--sq-hi) 72%, var(--ink) 14%); }
/* scoring border: 2px OUTSIDE the tile edge, so a scoring die is the same size as every other die.
   Rows blue, columns red, split diagonally when the die scores both ways. Fades in when a die lands. */
.cell.sr { --b1: var(--rows); --b2: var(--rows); }
.cell.sc { --b1: var(--cols); --b2: var(--cols); }
.cell.sr.sc { --b1: var(--rows); --b2: var(--cols); }
.cell::after {
  content: ""; position: absolute; inset: -2px; border-radius: calc(var(--rad) + 2px); padding: 2px; pointer-events: none;
  background: linear-gradient(135deg, var(--b1, transparent) 50%, var(--b2, transparent) 50%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude;
  opacity: 0; transition: opacity calc(var(--t) * 250ms) ease calc(var(--t) * 60ms);
}
[data-runs="die"] .cell.sr::after, [data-runs="die"] .cell.sc::after { opacity: 1; }
/* run marks (cfg.runs): capsules under the dice, ring around the run; drawn by renderRuns() */
.runs-u, .runs-o, .rl { position: absolute; inset: 0; pointer-events: none; }
/* capsules are solid colour; their layer (one per direction, columns over rows) gives the 24% tint, so a capsule fading
   in over the one it replaces doesn't darken where they overlap (issue #14) */
.rl { opacity: .24; }
.runs-o { z-index: 1; }
.tiles { --cp: min(3.5px, calc(var(--gap) * .4)); --rp: max(2px, min(3px, calc(var(--gap) * .45))); }
.rm { position: absolute; opacity: 0; transition: opacity calc(var(--t) * 250ms) ease calc(var(--t) * 60ms); }
.rm.in { opacity: 1; }
.rm-r { --p: var(--rows); } .rm-c { --p: var(--cols); }
.rm.capsule { background: var(--p); border-radius: calc(var(--rad) + var(--cp)); }
.rm.ring { border: 2px solid var(--p); border-radius: calc(var(--rad) + var(--rp)); }
/* No bounce when a die lands (Aaron 11-19: it read as a pulse): the die just settles into its square. */
/* end of game: each scoring run is gently tinted once */
.cell::before { content: ""; position: absolute; inset: 0; border-radius: inherit; opacity: 0; pointer-events: none; }
.cell.flash-r::before { background: var(--rows); animation: pulse calc(var(--t) * 700ms) ease-in-out; }
.cell.flash-c::before { background: var(--cols); animation: pulse calc(var(--t) * 700ms) ease-in-out; }
@keyframes pulse { 0%, 100% { opacity: 0; } 45% { opacity: .14; } }

.ls, .cs {
  display: grid; place-items: center; font-size: clamp(12px, calc(var(--cell) * .22), 16px); line-height: 1;
  font-variant-numeric: tabular-nums; color: var(--rows); font-weight: 600; transition: opacity calc(var(--t) * 200ms);
}
.cs { color: var(--cols); }
.ls.z, .cs.z { opacity: 0; }
.ls.flash, .cs.flash { animation: fade calc(var(--t) * 700ms) ease-in-out; }
@keyframes fade { 0%, 100% { opacity: 1; } 45% { opacity: .45; } }

/* dice in play: under the board, with the same edge as the board dice (cfg.edge); selected = 10% bigger */
/* phone: the dice sit a short way under the board; the rest of the height stays free above the end buttons */
.dock { order: 2; flex: 1 0 auto; min-height: var(--ds); display: flex; flex-direction: column; justify-content: flex-start; align-items: center; padding: clamp(16px, 7vh, 64px) 0 8px; }
#field { display: flex; justify-content: center; gap: 24px; height: var(--ds); }
.die {
  width: var(--ds); height: var(--ds); border-radius: calc(var(--ds) * .2); background: var(--fill, var(--die));
  display: grid; place-items: center; position: relative; touch-action: none;
  transition: scale calc(var(--t) * 180ms) var(--ease); /* `scale` composes with the roll, drag and flight transforms */
}
[data-edge="light"] .die { box-shadow: inset 0 0 0 1.5px var(--rim-l); }
[data-edge="dark"] .die { box-shadow: inset 0 0 0 1.5px var(--rim-d); }
.die .pips { width: 56%; height: 56%; }
.die .num { font-size: calc(var(--ds) * .44); }
.die.gone { visibility: hidden; }
.die:disabled { cursor: default; color: inherit; }
/* selected or dragged (Aaron 11-19): 10% bigger, nothing else (no ring); it grows in, and shrinks back while it travels to its square */
.die.sel { scale: 1.1; }
.die.drag { z-index: 20; cursor: grabbing; }
.die.fly { z-index: 20; }

/* Bag: what's left in the bag, one small die per number with its count; quiet, under the dice in play */
.bag { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 4px 12px; margin-top: 20px; font-size: 13px; color: var(--ink-3); }
.bag-l { font-weight: 500; margin-right: -2px; }
.bt { display: inline-flex; align-items: center; gap: 4px; transition: opacity calc(var(--t) * 200ms); }
.bd { width: 18px; height: 18px; border-radius: 4px; background: var(--fill, var(--die)); box-shadow: inset 0 0 0 1px var(--rim-l); display: grid; place-items: center;
  --rim-l: color-mix(in oklch, var(--fill, var(--die)) 65%, var(--pip, var(--pip-ink)) 35%); }
[data-dice="white"] .bd { --rim-l: var(--edge); }
.bd .pips { width: 64%; height: 64%; gap: 10%; }
.bd .num { font-size: 11px; }
.bn { min-width: 1ch; font-weight: 600; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.bt.out { opacity: .35; }
.result { display: flex; justify-content: center; align-items: center; gap: 12px; min-height: var(--ds); }
.result .res-t { font-size: 24px; font-weight: 700; letter-spacing: -.4px; white-space: nowrap; }
.result.w0 .res-t { color: var(--rows); } .result.w1 .res-t { color: var(--cols); }
.result .res-s { font-size: 16px; color: var(--ink-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.end-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.endbar .record { margin: 12px 0 0; text-align: center; }

/* ---------- rules dialog ---------- */
.rules {
  border: 0; padding: 0; margin: auto; width: min(560px, calc(100vw - 32px)); max-height: min(86dvh, 820px);
  background: var(--bg); color: var(--ink); border-radius: 20px;
}
.rules::backdrop { background: var(--scrim); }
.rules[open] { animation: rin calc(var(--t) * 200ms) var(--ease); }
@keyframes rin { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
.rules-in { padding: 20px 24px 24px; }
.rules-h { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.rules-h h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.3px; }
.rules-h .ghost-btn { margin-right: -14px; }
@media (max-width: 600px) {
  .rules { width: 100vw; max-width: 100vw; max-height: 90dvh; margin: auto 0 0; border-radius: 20px 20px 0 0; }
  .rules-in { padding: 16px 20px max(24px, env(safe-area-inset-bottom)); }
}

/* ---------- small phones ---------- */
@media (max-width: 400px) { .seg button { font-size: 13px; padding: 4px 2px; } }
@media (max-width: 370px) {
  :root { --pad: 12px; }
  .panel, .house .fields { padding-left: 16px; padding-right: 16px; }
  .side-total > span:first-child { font-size: 30px; }
}

/* ---------- desktop ---------- */
@media (min-width: 960px) {
  :root { --pad: 40px; }
  .app { padding-top: 32px; padding-bottom: 32px; }
  .setup { padding-top: 48px; }
  .wordmark { font-size: 56px; letter-spacing: -1.8px; }
  .go-bar { position: static; margin: 24px 0 0; padding: 0; }

  .game {
    display: grid; height: calc(100dvh - 64px); min-height: 600px;
    grid-template-columns: minmax(0, 1fr) 360px; grid-template-rows: auto auto auto auto 1fr; column-gap: 40px;
  }
  .game > .endbar { order: 0; }
  .gbar { grid-column: 1 / -1; }
  .board-wrap { grid-column: 1; grid-row: 2 / 6; margin-top: 8px; align-items: center; }
  .hud, .dock, .endbar { grid-column: 2; }
  .hud { margin-top: calc(8px + var(--gut)); }
  .side { padding: 14px 16px; }
  .side-total > span:first-child { font-size: 40px; }
  .dock { margin-top: 32px; padding: 0; flex: none; }
}
