/* Checkers Clubhouse. The app identity (header, logo, primary buttons) uses the brand's clubhouse
   blue in every kit; theme kits colour the table: surfaces, board, pieces, highlights and cards
   (CSS variables set by client/theme.ts). Phone first (390 px, no horizontal scroll), then the TV. */
:root {
  --brand: #1f4e9c; --brand-deep: #143a78; --brand-cream: #f6f0e4; --brass: #d9a441;
  --background: #f6f0e4; --surface: #fffaf1; --surface-alt: #efe6d4; --text: #2a2118; --muted: #6b5d4c; --accent: #1f4e9c; --accent-text: #fff; --border: #dccdb2;
  --hl-selected: #ffcf3f; --hl-legal: #ffe680; --hl-last-move: #7fb7ff; --hl-capture: #ff6b6b; --hl-zone: #ffd56a;
  --radius: 16px; --shadow: 0 1px 0 #0000000d, 0 8px 24px -12px #3a2a1440;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
:root[data-mode="dark"] { color-scheme: dark; --shadow: 0 1px 0 #0000004d, 0 10px 30px -12px #000000a0; }
:root[data-large] { font-size: 118%; }
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font); color: var(--text); background-color: var(--background); background-image: var(--kit-bg); background-size: 160px;
  min-height: 100vh; line-height: 1.4; -webkit-tap-highlight-color: transparent; overflow-x: hidden;
}
button, select, input { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.15; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .6em; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .center { text-align: center; }
:focus-visible { outline: 3px solid var(--hl-selected); outline-offset: 2px; }

/* ---------------------------------------------------------------- app identity */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: .45rem; flex-wrap: wrap;
  padding: .45rem .7rem; background: linear-gradient(180deg, var(--brand), var(--brand-deep)); color: var(--brand-cream);
  box-shadow: 0 2px 0 var(--brass), 0 6px 18px -8px #0008;
}
.logo { display: inline-flex; align-items: center; gap: .4rem; font-weight: 800; letter-spacing: .01em; white-space: nowrap; }
.logo-mark svg { width: 30px; height: 30px; display: block; filter: drop-shadow(0 1px 1px #0005); }
.logo-name { font-size: 1.02rem; }
.mode-badge { display: inline-flex; flex-direction: column; line-height: 1.05; padding: .2rem .55rem; border-radius: 10px; background: #ffffff1f; font-weight: 700; font-size: .85rem; }
.mode-badge small { font-weight: 500; opacity: .85; font-size: .68rem; }
.mode-badge.variant small::before { content: "★ "; }
.topbar .spacer { flex: 1; }
.icon-btn { min-width: 40px; min-height: 40px; padding: 0 .3rem; border-radius: 12px; border: 1px solid #ffffff40; background: #ffffff14; color: var(--brand-cream); font-weight: 800; cursor: pointer; }
.icon-btn:hover { background: #ffffff2a; }
.me-chip .chip { background: #ffffff1c; color: var(--brand-cream); }
.paused-pill { background: var(--brass); color: #2a2118; padding: .15rem .5rem; border-radius: 99px; font-weight: 700; font-size: .8rem; }
.conn-banner:not(:empty) { background: #c0392b; color: #fff; padding: .15rem .5rem; border-radius: 99px; font-size: .8rem; }
@media (max-width: 480px) { .logo-name { display: none; } .mode-badge { font-size: .78rem; } .topbar { flex-wrap: nowrap; gap: .3rem; padding: .4rem .45rem; } .me-chip .chip-name { display: none; } .me-chip .chip { padding: .1rem; } .mode-badge { min-width: 0; overflow: hidden; } .mode-badge, .mode-badge small { white-space: nowrap; text-overflow: ellipsis; overflow: hidden; } }

/* ---------------------------------------------------------------- building blocks */
main { padding: .7rem; max-width: 1500px; margin: 0 auto; }
.stack { display: flex; flex-direction: column; gap: .7rem; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem; box-shadow: var(--shadow); min-width: 0; }
.note { background: var(--surface-alt); border-left: 4px solid var(--accent); padding: .5rem .7rem; border-radius: 10px; font-size: .9rem; }
.note ul { margin: .2rem 0 0; padding-left: 1.1rem; }
.tag { display: inline-block; font-size: .72rem; padding: .08rem .45rem; border-radius: 99px; background: var(--surface-alt); color: var(--text); border: 1px solid var(--border); font-weight: 700; }
.tag.out { opacity: .8; } .tag.good { background: #2f9e5a; color: #fff; border-color: transparent; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; min-height: 44px; padding: .45rem .9rem; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-alt); color: var(--text); font-weight: 700; cursor: pointer; }
.btn:hover { filter: brightness(1.04); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand-deep); color: #fff; box-shadow: 0 2px 0 var(--brand-deep); }
.btn.danger { color: #b3261e; } .btn.danger.primary, .btn.danger:not(.ghost) { background: #b3261e; color: #fff; border-color: #8c1d18; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: .25rem .65rem; font-size: .85rem; }
.btn.big { min-height: 56px; font-size: 1.1rem; width: 100%; }
.row-buttons { display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: .1rem .5rem .1rem .15rem; border-radius: 99px; background: var(--surface-alt); font-weight: 700; max-width: 100%; }
.chip .dot { width: 1.5em; height: 1.5em; border-radius: 50%; display: inline-grid; place-items: center; color: #fff; font-size: .72em; text-shadow: 0 1px 1px #0008; flex: none; }
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.swatch { display: inline-grid; place-items: center; width: 1.7em; height: 1.7em; border-radius: 50%; border: 3px solid; font-size: .75em; font-weight: 900; flex: none; box-shadow: 0 2px 0 #0003; }
.loading { display: grid; place-items: center; gap: .8rem; min-height: 60vh; color: var(--muted); }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid var(--border); border-top-color: var(--brand); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-page { max-width: 760px; display: flex; flex-direction: column; gap: .8rem; }
.center-page h1 { margin-top: .5rem; }

/* ---------------------------------------------------------------- ready & rules */
.welcome h1 { margin: 0; }
.rules-head { display: flex; justify-content: space-between; gap: .6rem; align-items: flex-start; }
.family { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.tagline { color: var(--muted); }
.rules-flag { font-size: .75rem; font-weight: 800; padding: .25rem .55rem; border-radius: 99px; white-space: nowrap; }
.rules-flag.standard { background: #2f9e5a; color: #fff; } .rules-flag.variant { background: var(--brass); color: #2a2118; }
.rules-list { padding-left: 1.25rem; margin: .4rem 0; } .rules-list li { margin: .3rem 0; }
.countdown { font-size: 1.05rem; text-align: center; margin: 0; padding: .5rem; background: var(--surface); border-radius: 12px; border: 1px dashed var(--border); }
.lineup-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.lineup-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "who slot ready" "who tag btn"; gap: .15rem .5rem; align-items: center; padding: .4rem .5rem; border-radius: 12px; background: var(--surface-alt); }
.lineup-row .chip { grid-area: who; } .lineup-row .tag { grid-area: tag; } .lineup-row .slot { grid-area: slot; font-weight: 700; font-size: .85rem; } .lineup-row .ready { grid-area: ready; font-size: .8rem; } .lineup-row .btn { grid-area: btn; }
.lineup-row.picked { outline: 3px solid var(--hl-selected); }
.ready.yes { color: #2f7d4a; font-weight: 700; } :root[data-mode="dark"] .ready.yes { color: #7fe0a2; }
.host-controls { display: flex; flex-direction: column; gap: .5rem; }

/* ---------------------------------------------------------------- the board */
.game.your-turn { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent), var(--shadow); }
.game-head { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin-bottom: .4rem; }
.sides { list-style: none; margin: 0 0 .5rem; padding: 0; display: flex; flex-wrap: wrap; gap: .35rem; }
.side { display: flex; align-items: center; gap: .35rem; padding: .3rem .55rem; border-radius: 12px; background: var(--surface-alt); flex: 1 1 140px; min-width: 0; flex-wrap: wrap; border: 2px solid transparent; }
.side.on-turn { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.side.me { box-shadow: inset 4px 0 0 var(--brass); }
.side-name { min-width: 0; flex: 1; display: flex; flex-direction: column; line-height: 1.1; }
.side-name b, .side-name small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-name small { color: var(--muted); }
.sides.n2 .side { flex-basis: 45%; }
.side .mini { font-size: .75rem; font-weight: 700; color: var(--muted); }
.turn-arrow { color: var(--accent); font-weight: 900; animation: nudge 1.1s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateX(-3px); } }
.crew { display: flex; flex-wrap: wrap; gap: .25rem; width: 100%; font-size: .75rem; }
.crew span { padding: 0 .35rem; border-radius: 99px; background: var(--surface); } .crew .cur { font-weight: 800; outline: 2px solid var(--accent); } .crew .next { font-style: italic; }
.board-wrap { display: grid; place-items: center; }
.board { width: 100%; max-width: min(92vw, 620px); height: auto; display: block; touch-action: manipulation; user-select: none; filter: drop-shadow(0 10px 18px #0004); }
.board-wrap.small .board { max-width: 360px; }
.board .hit { cursor: pointer; }
.board .hit:focus-visible { outline: none; stroke: var(--hl-selected); stroke-width: 8; }
.board .piece.selected .body { filter: brightness(1.08); }
.board .piece.selected { transform-box: fill-box; transform-origin: center; animation: lift .25s ease-out both; }
@keyframes lift { to { transform: translateY(-4px) scale(1.04); } }
.board .must-ring { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.board .legal { pointer-events: none; animation: pop .2s ease-out; transform-box: fill-box; transform-origin: center; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
.board .badge, .board .cap-preview, .board .fogged, .board .sym { pointer-events: none; }
.board text { font-family: var(--font); }
.status { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-top: .5rem; padding: .55rem .75rem; border-radius: 12px; background: var(--surface-alt); font-weight: 700; flex-wrap: wrap; }
.status.yours { background: var(--brand); color: #fff; }
.status.over { background: var(--brass); color: #2a2118; }
.turn-timer { --left: 1; position: relative; display: inline-flex; align-items: center; gap: .4rem; min-width: 7.5rem; }
.turn-timer .bar { flex: 1; height: 10px; border-radius: 99px; background: #0002; overflow: hidden; position: relative; }
.turn-timer .bar::after { content: ""; position: absolute; inset: 0; width: calc(var(--left) * 100%); background: #2f9e5a; border-radius: inherit; transition: width .1s linear; }
.turn-timer .secs { font-variant-numeric: tabular-nums; min-width: 2.6em; text-align: right; }
.turn-timer.warn .bar::after { background: #d6394b; }
.turn-timer.warn .secs { color: #ffdd57; animation: pulse .5s ease-in-out infinite; }
.status:not(.yours) .turn-timer.warn .secs { color: #b3261e; }
.event-note { font-size: .85rem; margin: .4rem 0 0; }
.game-actions { margin-top: .5rem; justify-content: flex-end; }
.moves-wrap { margin-top: .4rem; }
.moves { display: flex; flex-wrap: wrap; gap: .25rem .6rem; padding: 0; margin: .3rem 0 0; list-style: none; counter-reset: mv; font-variant-numeric: tabular-nums; max-height: 9rem; overflow: auto; }
.moves .mv { display: inline-flex; align-items: center; gap: .25rem; font-size: .85rem; }
.moves .mv .swatch { width: 1.2em; height: 1.2em; border-width: 2px; font-size: .55em; }

/* ---------------------------------------------------------------- cards (Card Checkers) */
.hand-wrap { margin-top: .5rem; }
.deck-row { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.deck { width: 22px; height: 30px; border-radius: 4px; background: var(--kit-card-back) center/cover, var(--card-accent); box-shadow: 2px 2px 0 #0003, 4px 4px 0 #0002; }
.hand { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: .4rem; margin-top: .35rem; }
.play-card { display: flex; flex-direction: column; align-items: center; gap: .15rem; padding: .45rem .3rem; min-height: 112px; border-radius: 12px; border: 2px solid var(--card-accent); background: var(--card-face); color: var(--card-ink); cursor: pointer; box-shadow: 0 3px 0 #0003; transition: transform .12s; }
.play-card .card-icon { font-size: 1.6rem; line-height: 1; } .play-card .card-name { font-weight: 800; } .play-card .card-text { font-size: .68rem; text-align: center; line-height: 1.2; }
.play-card.selected { transform: translateY(-6px); outline: 4px solid var(--hl-selected); }
.play-card.dim { opacity: .55; }

/* ---------------------------------------------------------------- panels */
.team-panel { margin-top: .5rem; padding: .6rem; border-radius: 12px; background: var(--surface-alt); }
.team-panel .row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; } .team-panel .clock { margin-left: auto; font-weight: 800; font-variant-numeric: tabular-nums; }
.votes { margin: .3rem 0; padding-left: 1.1rem; } .votes .mine { font-weight: 800; }
.draft .pool { list-style: none; padding: 0; display: grid; gap: .4rem; }
.pool-pick { width: 100%; justify-content: flex-start; flex-direction: column; align-items: flex-start; text-align: left; } .pool-pick span { font-weight: 500; font-size: .85rem; }
.picks li { margin: .3rem 0; }
.score-table, .history, .leaderboard { width: 100%; border-collapse: collapse; margin: .5rem 0; font-size: .9rem; }
.score-table caption, .history caption, .leaderboard caption { text-align: left; font-weight: 700; padding-bottom: .25rem; }
.score-table th, .score-table td, .history td, .history th, .leaderboard td, .leaderboard th { padding: .3rem .4rem; border-bottom: 1px solid var(--border); text-align: left; }
.leaderboard tr.me { background: color-mix(in srgb, var(--accent) 14%, transparent); font-weight: 700; }
.host-box { border-top: 1px dashed var(--border); margin-top: .5rem; padding-top: .5rem; }
.pick-pair select { min-height: 40px; border-radius: 10px; padding: 0 .4rem; background: var(--surface); border: 1px solid var(--border); max-width: 38%; }
.replay summary { cursor: pointer; font-weight: 700; padding: .3rem 0; }
.bracket .rounds { display: flex; gap: .6rem; overflow-x: auto; padding-bottom: .3rem; }
.round { min-width: 150px; display: flex; flex-direction: column; gap: .4rem; justify-content: space-around; }
.round.current h3 { color: var(--accent); }
.match { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface-alt); }
.match.live { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.match .slot { display: grid; grid-template-columns: 1.5em 1fr auto; gap: .3rem; padding: .25rem .4rem; font-size: .85rem; }
.match .slot.won { font-weight: 800; } .match .slot.won::after { content: ""; } .match .slot.lost { opacity: .6; text-decoration: line-through; }
.seed { color: var(--muted); font-size: .75rem; }
.champion { font-weight: 800; font-size: 1.1rem; }
.standing-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .3rem; }
.standing-list li { display: grid; grid-template-columns: 2em minmax(0, 1fr) auto; gap: .1rem .5rem; align-items: center; padding: .35rem .5rem; border-radius: 10px; background: var(--surface-alt); }
.standing-list li small { grid-column: 2 / -1; }
.standing-list li.me { outline: 2px solid var(--accent); }
.place { font-weight: 900; font-size: 1.1rem; text-align: center; }
.table-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .4rem; }
.table-list li { padding: .4rem .5rem; border-radius: 10px; background: var(--surface-alt); }
.results h1 { font-size: 1.8rem; }
.results.won h1::before { content: "🏆 "; }
.mode-guide h3 { margin-top: .8rem; color: var(--accent); }
.mode-cards { list-style: none; padding: 0; display: grid; gap: .5rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.mode-card { border: 1px solid var(--border); border-radius: 12px; padding: .6rem; background: var(--surface-alt); }
.mode-card dl { display: grid; grid-template-columns: auto 1fr; gap: .1rem .5rem; font-size: .8rem; margin: .3rem 0; } .mode-card dt { font-weight: 700; }
.mode-card .changes { font-size: .82rem; padding-left: 1rem; margin: 0; }

/* ---------------------------------------------------------------- dialogs */
dialog.drawer { border: none; border-radius: 20px; padding: 1rem; width: min(560px, 96vw); max-height: 90vh; background: var(--surface); color: var(--text); box-shadow: 0 30px 80px #0007; }
dialog.drawer.wide { width: min(900px, 96vw); }
dialog::backdrop { background: #10182ab0; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: -1rem; background: var(--surface); padding: .2rem 0; z-index: 1; }
.theme-grid { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); margin: .5rem 0; }
.theme-tile { display: flex; flex-direction: column; gap: .3rem; padding: .45rem; border-radius: 14px; border: 2px solid var(--border); background: var(--surface-alt); text-align: left; cursor: pointer; margin: 0; }
.theme-tile img { width: 100%; height: auto; border-radius: 10px; display: block; }
.theme-tile.selected { border-color: var(--brand); box-shadow: 0 0 0 3px var(--hl-selected); }
.theme-tile .tname { font-weight: 800; } .theme-tile .tdesc { font-size: .8rem; color: var(--muted); }
.season { color: #2f9e5a; } .cat { color: var(--muted); font-weight: 500; }
.preview-bar { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.toggle { display: flex; gap: .6rem; align-items: flex-start; padding: .55rem 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.toggle input { width: 1.4rem; height: 1.4rem; margin-top: .1rem; accent-color: var(--brand); flex: none; }
.toggle span { display: flex; flex-direction: column; } .toggle small { color: var(--muted); }
.auto-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: .4rem; } .auto-list li { display: flex; gap: .4rem; align-items: center; justify-content: space-between; }

/* ---------------------------------------------------------------- toasts & celebration */
.toasts { position: fixed; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; gap: .35rem; z-index: 50; width: min(92vw, 420px); pointer-events: none; }
.toast { background: #1d2433; color: #fff; padding: .55rem .8rem; border-radius: 12px; box-shadow: 0 10px 24px #0005; font-weight: 600; animation: rise .25s ease-out; transition: opacity .5s; }
.toast.good { background: #1f6f43; } .toast.bad { background: #9b2226; } .toast.out { opacity: 0; }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } }
.celebrate { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.celebrate span { position: absolute; top: -40px; animation: fall linear forwards; text-shadow: 0 1px 2px #0004; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

/* ---------------------------------------------------------------- the TV */
body[data-view="tv"] { font-size: clamp(16px, 1.25vw, 28px); }
body[data-view="tv"] main { max-width: none; padding: 1.2rem; }
.tv-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 1.2rem; align-items: start; }
.tv-grid .board { max-width: none; width: 100%; height: calc(100vh - 340px); }
.tv-grid .tv-side { align-self: stretch; } .tv-grid .tv-side > * { width: 100%; }
.tv-boards { display: grid; gap: .8rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tv-boards.n2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tv-grid .tv-boards .board { height: calc(50vh - 220px); min-height: 220px; }
body[data-view="tv"] .status { font-size: 1.15em; }
body[data-view="tv"] .moves { max-height: none; }
@media (max-width: 900px) { .tv-grid { grid-template-columns: 1fr; } }
@media (min-width: 1000px) { body[data-view="phone"] main.play { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); align-items: start; } body[data-view="phone"] main.play > .game { grid-row: span 4; } }

/* ---------------------------------------------------------------- accessibility */
:root[data-hc] .card, :root[data-hc] .side, :root[data-hc] .btn { border-width: 2px; border-color: #000; }
:root[data-hc] .status.yours { background: #000; color: #fff; }
:root[data-hc] body { background-image: none; }
:root[data-reduced-motion] *, :root[data-reduced-motion] *::before, :root[data-reduced-motion] *::after { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

.board .movable { pointer-events: none; }
