/* Classic family games (Drop Four, Draughts, Ludo, Snap): the shared play screen. Base-plan rows BP17, BP18, BP21.
 * Built on the tokens (family-design.css), the game shell (.fos-game-top, .fos-game-home, .fos-game-tap in family-bridge.css) and the kit
 * (family-kit.css). Load after family-kit.css. Two screens per game: a setup screen (.cg-setup) and the play screen (.cg-play) with one row
 * of status at the top, the board in the middle (as big as the screen allows) and controls at the bottom edge. Nothing floats over the board.
 * Persona floors come from --target (44, 56 Amaya, 64 grandparent). Big-piece mode (.cg-big on <body>, the grandparent's default) thickens
 * every edge, raises contrast and makes every control at least 64px. Motion uses the kit tokens and stops under reduced motion.
 * Game colours are original, written as light/dark pairs; never pure black or white; no images, no outside requests.
 */
:where(html[data-persona]) {
  --cg-red: light-dark(oklch(0.56 0.2 27), oklch(0.66 0.19 27));
  --cg-red-edge: light-dark(oklch(0.38 0.15 27), oklch(0.42 0.14 27));
  --cg-yellow: light-dark(oklch(0.84 0.16 88), oklch(0.86 0.15 88));
  --cg-yellow-edge: light-dark(oklch(0.56 0.12 75), oklch(0.6 0.12 75));
  --cg-green: light-dark(oklch(0.58 0.15 150), oklch(0.68 0.15 150));
  --cg-green-edge: light-dark(oklch(0.38 0.1 150), oklch(0.42 0.1 150));
  --cg-blue: light-dark(oklch(0.52 0.15 255), oklch(0.66 0.14 255));
  --cg-blue-edge: light-dark(oklch(0.34 0.11 255), oklch(0.4 0.1 255));
  --cg-cream: light-dark(oklch(0.96 0.025 85), oklch(0.93 0.03 85));
  --cg-cream-edge: light-dark(oklch(0.62 0.04 75), oklch(0.6 0.04 75));
  --cg-board: light-dark(oklch(0.46 0.14 258), oklch(0.36 0.1 258));
  /* Drop Four's own counters: coral and teal (each also carries its own shape) */
  --cg-p1: light-dark(oklch(0.64 0.17 38), oklch(0.7 0.16 38));
  --cg-p1-edge: light-dark(oklch(0.45 0.13 38), oklch(0.5 0.12 38));
  --cg-p2: light-dark(oklch(0.62 0.1 195), oklch(0.72 0.1 195));
  --cg-p2-edge: light-dark(oklch(0.42 0.08 195), oklch(0.48 0.08 195));
  --cg-hole: var(--bg);
  --cg-wood-light: light-dark(oklch(0.9 0.04 80), oklch(0.62 0.05 70));
  --cg-wood-dark: light-dark(oklch(0.5 0.08 55), oklch(0.34 0.05 55));
  --cg-mark: var(--ink);
  --cg-edge-w: 2px;
  --cg-ctrl: max(var(--target, 44px), 48px);
}
/* older browsers without light-dark(): the light values */
@supports not (color: light-dark(white, black)) {
  :where(html[data-persona]) {
    --cg-red: oklch(0.56 0.2 27); --cg-red-edge: oklch(0.38 0.15 27); --cg-yellow: oklch(0.84 0.16 88); --cg-yellow-edge: oklch(0.56 0.12 75);
    --cg-green: oklch(0.58 0.15 150); --cg-green-edge: oklch(0.38 0.1 150); --cg-blue: oklch(0.52 0.15 255); --cg-blue-edge: oklch(0.34 0.11 255);
    --cg-cream: oklch(0.96 0.025 85); --cg-cream-edge: oklch(0.62 0.04 75); --cg-board: oklch(0.46 0.14 258);
    --cg-p1: oklch(0.64 0.17 38); --cg-p1-edge: oklch(0.45 0.13 38); --cg-p2: oklch(0.62 0.1 195); --cg-p2-edge: oklch(0.42 0.08 195);
    --cg-wood-light: oklch(0.9 0.04 80); --cg-wood-dark: oklch(0.5 0.08 55);
  }
}
body.cg-big { --cg-edge-w: 4px; --cg-ctrl: max(var(--target, 44px), 64px); }

body.cg { margin: 0; min-block-size: 100dvh; overflow-x: hidden; }
.cg-main { max-inline-size: 1100px; margin: 0 auto; padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left)); box-sizing: border-box; }
.cg-main .fos-game-top { padding-block: max(8px, env(safe-area-inset-top)) 4px; gap: 10px; flex-wrap: nowrap; }
.cg-main .fos-game-top h1 { font-size: clamp(1.35rem, 5vw, 2rem); flex: 1 1 auto; min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cg-menu-btn { flex: 0 0 auto; min-inline-size: var(--cg-ctrl); min-block-size: var(--cg-ctrl); }
.cg-menu-btn[hidden], .cg-think[hidden], .cg-field[hidden] { display: none !important; }

/* ---------- setup screen ---------- */
.cg-setup { display: grid; gap: var(--s-4, 16px); padding-block: var(--s-3, 12px) max(24px, env(safe-area-inset-bottom)); max-inline-size: 640px; margin-inline: auto; }
.cg-setup[hidden], .cg-play[hidden] { display: none !important; }
.cg-hero { display: grid; place-items: center; padding-block: var(--s-2, 8px); }
.cg-hero svg { inline-size: min(220px, 56vw); block-size: auto; }
.cg-setup h2 { font-size: var(--t-title2, 22px); margin: 0; display: flex; align-items: center; gap: 4px; }
.cg-field { display: grid; gap: 6px; }
.cg-field > .cg-label { font-size: var(--t-sm, 15px); font-weight: 650; color: var(--ink-2); margin: 0; }
.cg-setup .fk-seg > button { font-size: max(15px, var(--t-sm, 15px)); }
.cg-setup .fk-btn--primary { min-block-size: max(var(--cg-ctrl), 56px); font-size: var(--t-title3, 20px); }
.cg-setup .langbar { margin-top: var(--s-4, 16px); }
.cg-setup .langbar summary { min-block-size: var(--target, 44px); display: flex; align-items: center; color: var(--ink-2); font-weight: 600; cursor: pointer; }

/* ---------- play screen: status row, board, controls ---------- */
body.cg-playing { overflow: hidden; }
.cg-play { display: flex; flex-direction: column; block-size: calc(100dvh - var(--cg-top, 72px)); min-block-size: 360px; }
.cg-status { display: flex; align-items: center; gap: 8px; min-block-size: 44px; padding-block: 2px 6px; }
.cg-status h2 { margin: 0; font-size: var(--t-title3, 20px); line-height: 1.2; display: flex; align-items: center; gap: 6px; flex: 1 1 auto; min-inline-size: 0; }
.cg-turn { display: inline-flex; align-items: center; gap: 8px; min-inline-size: 0; }
.cg-turn-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cg-dot { inline-size: 1.1em; block-size: 1.1em; border-radius: 50%; flex: 0 0 auto; border: var(--cg-edge-w) solid var(--cg-mark); box-sizing: border-box; }
.cg-stage { flex: 1 1 auto; min-block-size: 0; display: grid; place-items: center; container-type: size; }
.cg-controls { display: flex; gap: var(--s-2, 8px); justify-content: center; padding-block: 8px max(10px, env(safe-area-inset-bottom)); flex-wrap: wrap; }
.cg-controls .fk-btn { min-block-size: var(--cg-ctrl); flex: 1 1 0; max-inline-size: 220px; }
body.cg-big .cg-controls .fk-btn, body.cg-big .cg-setup .fk-btn, body.cg-big .cg-menu-btn { font-size: max(20px, var(--t-body)); border-width: 2px; }

/* the thinking indicator: three dots, calm */
.cg-think { display: inline-flex; gap: 4px; margin-inline-start: 4px; }
.cg-think i { inline-size: 6px; block-size: 6px; border-radius: 50%; background: currentColor; opacity: .35; animation: cg-think 900ms var(--ease-std, ease) infinite; }
.cg-think i:nth-child(2) { animation-delay: 150ms; } .cg-think i:nth-child(3) { animation-delay: 300ms; }
@keyframes cg-think { 50% { opacity: 1; } }

/* ---------- the win moment: winning pieces pop once, a soft ring of stars, the end sheet rises (kit) ---------- */
.cg-burst { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.cg-burst i {
  position: absolute; inset-inline-start: var(--x); inset-block-start: var(--y); inline-size: 14px; block-size: 14px; margin: -7px;
  background: var(--c, var(--accent)); clip-path: polygon(50% 0, 61% 38%, 100% 50%, 61% 62%, 50% 100%, 39% 62%, 0 50%, 39% 38%);
  animation: cg-star 900ms var(--ease-in, ease-out) forwards;
}
@keyframes cg-star {
  0% { transform: translate(0, 0) scale(.3) rotate(0); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1.1) rotate(160deg); opacity: 0; }
}
.cg-pop { animation: cg-pop var(--d-slow, 320ms) var(--ease-spring, ease-out) 2; }
@keyframes cg-pop { 50% { transform: scale(1.12); } }
.cg-win-glow { filter: drop-shadow(0 0 6px var(--accent)); }

/* ---------- shared bits for SVG boards ---------- */
.cg-svg { display: block; inline-size: 100%; block-size: 100%; touch-action: manipulation; -webkit-tap-highlight-color: transparent; user-select: none; }
.cg-svg text { font-family: var(--font-body, system-ui); }
.cg-hint-ring { fill: none; stroke: var(--accent-ink); stroke-width: 3; stroke-dasharray: 5 4; }
body.cg-big .cg-hint-ring { stroke-width: 5; stroke-dasharray: none; }
.cg-sr { position: absolute !important; inline-size: 1px; block-size: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  .cg-burst { display: none; }
  .cg-pop, .cg-think i { animation: none; }
  .cg-think i { opacity: .8; }
}
html[data-motion="reduced"] .cg-burst { display: none; }
html[data-motion="reduced"] .cg-pop { animation: none; }

/* tablets and TVs: the board grows with the screen; controls sit beside it when the screen is wide and short */
@media (min-width: 900px) and (max-aspect-ratio: 16/9) { .cg-controls .fk-btn { max-inline-size: 260px; } }
@media (orientation: landscape) and (max-height: 520px) {
  .cg-play { display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto 1fr; }
  .cg-status { grid-column: 1 / -1; }
  .cg-controls { flex-direction: column; justify-content: center; padding-inline-start: 8px; }
  .cg-controls .fk-btn { flex: 0 0 auto; }
}

/* ---------- the coach line, the review bar, the 3D stage ---------- */
.cg-coach { margin: 0 0 4px; min-block-size: 1.5em; font-size: max(15px, var(--t-sm, 15px)); color: var(--ink-2); line-height: 1.35; }
.cg-coach[hidden] { display: block !important; visibility: hidden; }
.cg-coach-in { animation: cg-coach-in var(--d-base, 220ms) var(--ease-in, ease-out); }
@keyframes cg-coach-in { from { opacity: 0; transform: translateY(4px); } }
body.cg-big .cg-coach { font-size: max(18px, var(--t-body)); color: var(--ink); }
.cg-stage { position: relative; }
.cg-stage--3d { display: block; container-type: normal; }
.cg-gl { position: absolute; inset: 0; display: block; touch-action: manipulation; }
.cg-review { display: flex; gap: var(--s-2, 8px); justify-content: center; padding-block: 8px max(10px, env(safe-area-inset-bottom)); }
.cg-review[hidden], .cg-controls[hidden], .cg-controls .fk-btn[hidden] { display: none !important; }
.cg-review .fk-btn { min-block-size: var(--cg-ctrl); flex: 1 1 0; max-inline-size: 320px; }
.cg-controls .fk-btn[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.cg-menu-switches { display: grid; gap: 2px; }
.cg-sr-focus { position: absolute; inset-inline: 0; inset-block-end: 0; display: flex; opacity: 0; pointer-events: none; }
.cg-sr-focus > * { flex: 1 1 0; min-block-size: 1px; }
@media (prefers-reduced-motion: reduce) { .cg-coach-in { animation: none; } }

/* the 3D stage: a soft vignette so the eye goes to the board (pointer events pass through) */
.cg-stage--3d::after { content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  background: radial-gradient(120% 90% at 50% 45%, transparent 55%, color-mix(in oklch, var(--ink) 16%, transparent) 100%); }
.cg-stage--3d { border-radius: var(--r-lg, 16px); overflow: hidden; }
/* part 3, the family table: pieces are picked up and carried on the 3D stage, so a drag there never scrolls or zooms the page; the 3D
   view fades in over the 2D board it replaces (not under reduced motion, where the 2D board is the game) */
.cg-stage--3d .cg-gl { touch-action: none; cursor: grab; }
.cg-stage--3d .cg-gl:active { cursor: grabbing; }
.cg-gl:not(.cg-gl--on) { opacity: 0; }
.cg-gl--on { transition: opacity 360ms var(--ease-out, ease-out); }

/* ---------- the frame around the board: a clean icon home button (like the app shell), solid controls with icons ---------- */
.cg-main .fos-game-home {
  inline-size: max(48px, var(--target, 44px)); block-size: max(48px, var(--target, 44px)); border-radius: var(--r-full, 999px);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); box-shadow: var(--e1); font-size: 0;
}
.cg-main .fos-game-home svg { inline-size: 24px; block-size: 24px; }
html[data-persona="grandparent"] .cg-main .fos-game-home svg, html[data-persona="amaya"] .cg-main .fos-game-home svg { inline-size: 30px; block-size: 30px; }
.cg-main .cg-menu-btn { gap: 8px; }
.cg-controls .fk-btn { gap: 10px; }
.cg-controls .fk-btn svg { flex: 0 0 auto; }
/* while the computer moves, the controls rest: solid and quieter, never the dashed "unfinished" look */
.cg-controls .fk-btn:disabled { border-style: solid; border-color: transparent; background: var(--surface-2); color: var(--ink-2); opacity: .6; }
.cg-controls .ld-roll { min-block-size: max(var(--cg-ctrl), 68px); border-radius: var(--r-full, 999px); font-size: var(--t-title2, 22px); font-weight: 800; letter-spacing: .01em; box-shadow: 0 0 0 4px var(--ld-seat, var(--accent)), var(--e1); }
.cg-controls .ld-roll:disabled { box-shadow: 0 0 0 4px color-mix(in oklch, var(--ld-seat, var(--accent)) 45%, transparent); }
@media (prefers-reduced-motion: no-preference) {
  .cg-controls .ld-roll:not(:disabled) .ld-dieface { animation: ld-wiggle 2.4s var(--ease-std, ease) infinite; }
}
@keyframes ld-wiggle { 0%, 80%, 100% { transform: none; } 85% { transform: rotate(-12deg); } 90% { transform: rotate(10deg); } 95% { transform: rotate(-5deg); } }

/* ---------- The Fable pass (12 Nov 2026): one family with Draughts, Snap and Quiz night ----------
 * The setup screen is the lid of the box: the game's picture sits under a soft light on the table, and Play waits in the thumb zone
 * (it stays at the bottom edge while the choices scroll). The controls are raised game buttons that dip when pressed, the turn dot is
 * a little domed counter, and a 2D board sits on a lit table rather than on the bare page. All motion stops under reduced motion. */
.cg-hero { position: relative; isolation: isolate; padding-block: var(--s-3, 12px) var(--s-2, 8px); }
.cg-hero::before { content: ""; position: absolute; inset: -6% 6% 0; z-index: -1; border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in oklch, var(--accent) 18%, transparent) 0%, color-mix(in oklch, var(--accent) 7%, transparent) 60%, transparent 100%); }
.cg-hero svg { inline-size: min(260px, 64vw); filter: drop-shadow(0 8px 10px rgb(0 0 0 / .14)); overflow: visible; }
@media (prefers-reduced-motion: no-preference) {
  .cg-hero svg { animation: cg-lid 520ms var(--ease-out, ease-out) both; }
  .cg-hero-drop { animation: cg-hover 2.8s ease-in-out 600ms infinite; }
}
@keyframes cg-lid { from { opacity: 0; transform: translateY(10px) scale(.97); } }
@keyframes cg-hover { 0%, 100% { transform: none; } 50% { transform: translateY(-5px); } }
html[data-motion="reduced"] .cg-hero svg, html[data-motion="reduced"] .cg-hero-drop { animation: none; }

/* Play stays in reach: sticky at the bottom of the setup screen, a raised button with a ledge */
.cg-setup > #playBtn { position: sticky; inset-block-end: max(12px, env(safe-area-inset-bottom)); z-index: 5; }
html:not([data-pack="grimy"]) .cg-setup > #playBtn { box-shadow: 0 5px 0 color-mix(in oklch, var(--accent) 62%, black), 0 12px 24px rgb(0 0 0 / .18), 0 0 0 12px var(--bg); }
html:not([data-pack="grimy"]) .cg-setup > #playBtn:active { transform: translateY(3px); box-shadow: 0 2px 0 color-mix(in oklch, var(--accent) 62%, black), 0 6px 12px rgb(0 0 0 / .16), 0 0 0 12px var(--bg); }
html[data-pack="grimy"] .cg-setup > #playBtn { box-shadow: var(--fk-hard), 0 0 0 12px var(--bg); }

/* the controls under the board: raised game buttons that dip when pressed (as the Snap pads do) */
html:not([data-pack="grimy"]) .cg-controls .fk-btn:not(:disabled), html:not([data-pack="grimy"]) .cg-review .fk-btn { box-shadow: 0 4px 0 color-mix(in oklch, var(--fk-fill) 66%, var(--ink)); }
html:not([data-pack="grimy"]) .cg-controls .fk-btn:not(:disabled):active, html:not([data-pack="grimy"]) .cg-review .fk-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 color-mix(in oklch, var(--fk-fill) 66%, var(--ink)); }
html:not([data-pack="grimy"]) .cg-controls .ld-roll:not(:disabled) { box-shadow: 0 0 0 4px var(--ld-seat, var(--accent)), 0 6px 0 3px color-mix(in oklch, var(--ld-seat, var(--accent)) 60%, black); }
html:not([data-pack="grimy"]) .cg-controls .ld-roll:not(:disabled):active { transform: translateY(4px); box-shadow: 0 0 0 4px var(--ld-seat, var(--accent)), 0 2px 0 3px color-mix(in oklch, var(--ld-seat, var(--accent)) 60%, black); }
.cg-controls .fk-btn[aria-pressed="true"] { box-shadow: inset 0 3px 0 rgb(0 0 0 / .18); }

/* whose turn: the dot is a small domed counter in that player's colour, and it says hello when the turn changes */
.cg-dot { position: relative; box-shadow: 0 2px 0 rgb(0 0 0 / .18); }
.cg-dot::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: radial-gradient(circle at 34% 30%, rgb(255 255 255 / .6) 0 14%, rgb(255 255 255 / 0) 52%, rgb(0 0 0 / .14) 100%); }
@media (prefers-reduced-motion: no-preference) { .cg-dot.cg-dot--new { animation: cg-dot-new 360ms var(--ease-out, ease-out); } }
@keyframes cg-dot-new { 0% { transform: scale(.6); } 60% { transform: scale(1.18); } 100% { transform: none; } }

/* a 2D board sits on the table: a soft lit surface under it, in the member's own colours */
.cg-stage:has(> .cg-svg) { border-radius: var(--r-lg, 16px); padding: 10px; box-sizing: border-box;
  background: radial-gradient(110% 80% at 50% 38%, color-mix(in oklch, var(--surface) 70%, var(--accent) 6%) 0%, color-mix(in oklch, var(--bg) 88%, var(--ink)) 100%);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .25), inset 0 -10px 24px rgb(0 0 0 / .06); }

/* the end sheet's picture: a rosette for a winner, two counters side by side for a good game */
.cg-end { display: grid; justify-items: center; gap: var(--s-2, 8px); text-align: center; }
.cg-end svg { inline-size: 96px; block-size: 96px; filter: drop-shadow(0 6px 8px rgb(0 0 0 / .18)); }
.cg-end p { margin: 0; }
@media (prefers-reduced-motion: no-preference) { .cg-end svg { animation: cg-end-in 560ms var(--ease-out, ease-out) both; } }
@keyframes cg-end-in { from { opacity: 0; transform: translateY(12px) rotate(-8deg) scale(.8); } }
html[data-motion="reduced"] .cg-end svg { animation: none; }

/* part 3: in Amaya's persona every control on the play screen is at least 64px (her hands are small and quick) */
html[data-persona="amaya"] body.cg { --cg-ctrl: max(var(--target, 44px), 64px); }
html[data-persona="amaya"] .cg-main .fos-game-home { inline-size: 64px; block-size: 64px; }
html[data-persona="amaya"] .sn-pause { min-block-size: 64px; min-inline-size: 64px; }
/* the Picture choice in the games menu (Auto, Smooth, Pretty; docs/perf-gaps.md): full-size targets in the sheet too */
.cg-look .fk-seg > button { min-block-size: max(44px, var(--target, 44px)); font-size: max(15px, var(--t-sm, 15px)); }
