/* Bingo. Colours come from the active theme (client/themes.ts sets the variables). Text on balls
   is always dark on white; called and marked squares are shown with shapes, not colour alone. */

:root {
  --bg: #fff4e0; --bg2: #ffd9e8; --surface: #ffffff; --ink: #2a1238; --muted: #5e4a6b;
  --accent: #d6246e; --accent-ink: #ffffff; --line: #f1c9da; --radius: 18px;
  --ball-0: #e8434d; --ball-1: #f2a033; --ball-2: #2fa36b; --ball-3: #2b7de9; --ball-4: #8e4fd8;
  --chip: #e8434d;
  --good: #1f8a4c; --bad: #c62f3b;
  --shadow: 0 6px 20px rgb(0 0 0 / .10), 0 1px 3px rgb(0 0 0 / .08);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
  --fs: 16px;
  color-scheme: light;
}
:root[data-mode="dark"] { color-scheme: dark; --shadow: 0 6px 24px rgb(0 0 0 / .45); --good: #4fd88a; --bad: #ff6b76; }
:root[data-text="large"] { --fs: 19px; }
:root[data-contrast="high"] { --muted: var(--ink); --line: var(--ink); }

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 600 var(--fs)/1.4 var(--font); color: var(--ink);
  background: linear-gradient(160deg, var(--bg), var(--bg2)) fixed;
  -webkit-tap-highlight-color: transparent; overflow-x: hidden;
}
h1, h2, h3 { line-height: 1.15; margin: 0 0 .5em; font-weight: 900; }
h1 { font-size: 1.8em; } h2 { font-size: 1.3em; } h3 { font-size: 1.05em; }
p { margin: .3em 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.center { text-align: center; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }

/* ---------- backdrops (theme data: backdrop) ---------- */
body::before { content: ""; position: fixed; inset: 0; z-index: -1; opacity: .5; pointer-events: none; }
[data-backdrop="stripes"] body::before { background: repeating-linear-gradient(115deg, transparent 0 34px, color-mix(in srgb, var(--accent) 12%, transparent) 34px 68px); }
[data-backdrop="snow"] body::before { background: radial-gradient(circle, color-mix(in srgb, var(--ink) 18%, transparent) 2px, transparent 3px) 0 0/46px 46px, radial-gradient(circle, color-mix(in srgb, var(--ink) 12%, transparent) 1.5px, transparent 2.5px) 23px 23px/46px 46px; }
[data-backdrop="fields"] body::before { background: repeating-linear-gradient(0deg, transparent 0 40px, color-mix(in srgb, var(--accent) 10%, transparent) 40px 80px); }
[data-backdrop="grid"] body::before { background: linear-gradient(color-mix(in srgb, var(--accent) 14%, transparent) 1px, transparent 1px) 0 0/32px 32px, linear-gradient(90deg, color-mix(in srgb, var(--accent) 14%, transparent) 1px, transparent 1px) 0 0/32px 32px; }
[data-backdrop="dots"] body::before { background: radial-gradient(circle, color-mix(in srgb, var(--accent) 22%, transparent) 3px, transparent 4px) 0 0/28px 28px; }
[data-backdrop="bubbles"] body::before { background: radial-gradient(circle at 30% 30%, transparent 10px, color-mix(in srgb, var(--accent) 18%, transparent) 11px, transparent 13px) 0 0/90px 110px, radial-gradient(circle, transparent 5px, color-mix(in srgb, var(--accent) 14%, transparent) 6px, transparent 7px) 45px 60px/90px 110px; }
[data-backdrop="stars"] body::before { background: radial-gradient(circle, color-mix(in srgb, var(--ink) 30%, transparent) 1px, transparent 2px) 0 0/37px 41px, radial-gradient(circle, color-mix(in srgb, var(--accent) 40%, transparent) 1.5px, transparent 2.5px) 17px 9px/83px 71px; }
[data-backdrop="hex"] body::before { background: radial-gradient(circle, transparent 15px, color-mix(in srgb, var(--accent) 14%, transparent) 16px, transparent 17.5px) 0 0/48px 42px, radial-gradient(circle, transparent 15px, color-mix(in srgb, var(--accent) 14%, transparent) 16px, transparent 17.5px) 24px 21px/48px 42px; }
#decor { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
#decor span { position: absolute; font-size: 44px; opacity: .16; transform: rotate(var(--r)); animation: drift 9s ease-in-out var(--d) infinite alternate; }
@keyframes drift { to { transform: rotate(var(--r)) translateY(-14px); } }

/* ---------- basics ---------- */
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; border: 1px solid var(--line); }
.btn {
  font: inherit; font-weight: 800; color: var(--ink); background: var(--surface); border: 2px solid var(--line);
  border-radius: 999px; padding: 10px 18px; min-height: 44px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none; transition: transform .1s, background .15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.big { min-height: 54px; font-size: 1.1em; padding: 12px 24px; }
.btn.small { min-height: 38px; padding: 6px 14px; font-size: .9em; }
.btn.icon { width: 44px; height: 44px; padding: 0; border-radius: 50%; font-size: 1.2em; flex: none; }
input[type="text"], input[type="number"], select {
  font: inherit; color: var(--ink); background: var(--surface); border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; min-height: 44px; width: 100%;
}
input:focus, select:focus { border-color: var(--accent); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 22px; height: 22px; flex: none; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.loading { display: grid; place-items: center; min-height: 60vh; gap: 12px; font-size: 1.1em; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- logo and balls ---------- */
.logo { display: inline-flex; gap: .12em; }
.logo-lg { font-size: 56px; } .logo-md { font-size: 34px; } .logo-sm { font-size: 22px; }
.logo-ball { width: 1em; height: 1em; border-radius: 50%; background: var(--ring); display: grid; place-items: center; box-shadow: inset 0 -.08em 0 rgb(0 0 0 / .2); animation: bob 2.4s ease-in-out calc(var(--i) * .15s) infinite; }
.logo-ball span { width: .66em; height: .66em; border-radius: 50%; background: #fff; color: #1d1a14; font-size: .5em; font-weight: 900; display: grid; place-items: center; line-height: 1; width: 1.3em; height: 1.3em; }
@keyframes bob { 50% { transform: translateY(-.08em); } }

.ball { --s: 64px; width: var(--s); height: var(--s); border-radius: 50%; flex: none; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--ring) 55%, #fff), var(--ring) 60%, color-mix(in srgb, var(--ring) 70%, #000));
  box-shadow: 0 4px 12px rgb(0 0 0 / .22); }
.ball-face { width: 68%; height: 68%; border-radius: 50%; background: #fff; color: #17140f; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: .95; box-shadow: inset 0 2px 4px rgb(0 0 0 / .12); }
.ball-col { font-size: calc(var(--s) * .14); font-weight: 900; color: #3b352a; }
.ball-num { font-size: calc(var(--s) * .3); font-weight: 900; letter-spacing: -.02em; }
.ball-xl { --s: min(34vh, 330px); } .ball-lg { --s: 120px; } .ball-md { --s: 80px; } .ball-sm { --s: 44px; }
.ball-sm .ball-col { display: none; } .ball-sm .ball-num { font-size: calc(var(--s) * .36); }
.ball.pop { animation: pop .55s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes pop { from { transform: scale(.2) rotate(-200deg); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- home (quick rooms) ---------- */
.home { max-width: 860px; margin: 0 auto; padding: 32px 16px 48px; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.home.center { min-height: 80vh; justify-content: center; text-align: center; }
.tagline { text-align: center; max-width: 34em; font-size: 1.1em; }
.home-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; width: 100%; }
.home-card { display: flex; flex-direction: column; gap: 8px; }
.home-card label { font-weight: 800; margin-top: 4px; }
.code-input { text-transform: uppercase; letter-spacing: .3em; font-size: 1.6em !important; text-align: center; font-weight: 900; }
.form-error { color: var(--bad); min-height: 1.2em; margin: 0; }

/* ---------- phone layout ---------- */
.phone { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.top-title { flex: 1; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn { font-size: .8em; color: var(--muted); }
.conn.reconnecting, .conn.failed { color: var(--bad); }
.layout { flex: 1; display: grid; gap: 12px; padding: 12px; max-width: 1280px; width: 100%; margin: 0 auto; }
.play-col, .host-col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.playing, .phase-view { display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 900px) {
  .phone.is-host .layout { grid-template-columns: minmax(340px, 440px) minmax(0, 1fr); align-items: start; }
  .phone.is-host .host-col { position: sticky; top: 72px; max-height: calc(100vh - 84px); overflow: auto; }
  .phone:not(.is-host) .layout { max-width: 560px; }
}
@media (max-width: 899px) { .phone.is-host .host-col { order: 2; } .phone.is-host .play-col { order: 1; } .phone.is-host.phase-setup .host-col { order: 0; } }

/* ---------- calls ---------- */
.calls { display: grid; gap: 8px; }
.calls-phone { grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "stage meta" "stage recent"; align-items: center; background: var(--surface); border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.calls-phone .stage { grid-area: stage; min-width: 120px; min-height: 120px; }
.calls-phone .calls-meta { grid-area: meta; }
.calls-phone .recent-wrap { grid-area: recent; }
.stage { position: relative; display: grid; place-items: center; }
.current { display: grid; place-items: center; transition: opacity .2s; }
.current.dim { opacity: 0; }
.batch { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.calls-phone .batch-2, .calls-phone .batch-3 { max-width: 180px; }
.calls-phone .batch-4, .calls-phone .batch-5 { max-width: 180px; }
.calls-phone .batch:not(.batch-1) .ball { --s: 56px; }
.no-call { font-weight: 800; color: var(--muted); text-align: center; max-width: 9em; }
.drawing { position: absolute; inset: 0; display: grid; place-items: center; z-index: 1; }
.drawing .cage { width: 100%; height: 100%; max-width: 160px; max-height: 160px; }
.drawing-label { position: absolute; bottom: -4px; font-weight: 900; background: var(--surface); padding: 2px 10px; border-radius: 999px; font-size: .85em; }
.drawing.simple .cage { display: none; }
.drawing.simple .drawing-label { position: static; font-size: 1.1em; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }
.calls-meta { display: flex; flex-direction: column; gap: 6px; }
.meta-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: space-between; }
.counter { font-weight: 800; color: var(--muted); font-size: .9em; }
.status-badge { font-size: .8em; font-weight: 900; padding: 2px 10px; border-radius: 999px; background: var(--bg2); color: var(--ink); border: 1px solid var(--line); }
.status-badge.paused::before { content: "⏸ "; }
.status-badge.win { background: var(--accent); color: var(--accent-ink); }
.bar { display: block; height: 8px; border-radius: 99px; background: var(--bg2); overflow: hidden; border: 1px solid var(--line); }
.bar-fill { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s linear; }
.recent-wrap { display: flex; align-items: center; gap: 6px; min-width: 0; }
.recent-title { font-size: .75em; color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.recent { list-style: none; margin: 0; padding: 0; display: flex; gap: 4px; overflow: hidden; }
.calls-phone .recent .ball { --s: 36px; }

/* ---------- win info, tabs, claims ---------- */
.win-info { display: flex; align-items: center; gap: 10px; font-size: .95em; }
.pattern { display: inline-grid; grid-template-columns: repeat(5, 1fr); gap: 2px; flex: none; padding: 3px; border-radius: 6px; background: var(--surface); border: 1px solid var(--line); }
.pattern-sm { width: 40px; } .pattern-md { width: 84px; } .pattern-lg { width: min(18vh, 170px); gap: 4px; padding: 6px; border-radius: 12px; }
.pcell { aspect-ratio: 1; border-radius: 2px; background: var(--bg2); border: 1px solid var(--line); }
.pcell.on { background: var(--accent); border-color: var(--accent); }
.pcell.free { background-image: radial-gradient(circle, var(--ink) 25%, transparent 30%); }
.card-tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.tab { font: inherit; font-weight: 800; border: 2px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 12px; padding: 8px 12px; min-height: 44px; white-space: nowrap; cursor: pointer; }
.tab.on { border-color: var(--accent); box-shadow: inset 0 -4px 0 var(--accent); }
.tab small { color: var(--muted); }
.claim-bar { display: flex; gap: 10px; position: sticky; bottom: 0; padding: 8px 0 max(8px, env(safe-area-inset-bottom)); z-index: 4; background: linear-gradient(transparent, var(--bg2) 30%); }
.bingo-btn { flex: 1; min-height: 64px; font-size: 1.7em; letter-spacing: .06em; background: var(--accent); color: var(--accent-ink); border-color: var(--accent); box-shadow: 0 6px 0 color-mix(in srgb, var(--accent) 60%, #000); border-radius: 20px; }
.bingo-btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 color-mix(in srgb, var(--accent) 60%, #000); }
.bingo-btn.dimmed { opacity: .5; }
.trace-btn { min-height: 64px; border-radius: 20px; }
.trace-btn[aria-pressed="true"] { border-color: var(--accent); background: var(--bg2); }
.trace-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.trace-word { flex: 1; font-weight: 900; letter-spacing: .08em; min-width: 8em; }

/* ---------- the card ---------- */
.card { width: 100%; max-width: 560px; margin: 0 auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px; border: 1px solid var(--line); }
.card-head { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 6px; }
.card-head span { text-align: center; font-weight: 900; font-size: 1.4em; color: #fff; background: var(--ring); border-radius: 10px; padding: 2px 0; text-shadow: 0 1px 2px rgb(0 0 0 / .45); }
.card-body { position: relative; }
.card-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.cell {
  position: relative; aspect-ratio: 1; min-height: 44px; border-radius: calc(var(--radius) * .55); border: 2px solid var(--line); background: var(--surface);
  font: 900 clamp(18px, 6.4vw, 30px)/1 var(--font); color: var(--ink); cursor: pointer; display: grid; place-items: center; padding: 0; overflow: hidden;
  transition: transform .08s;
}
.card.letters .cell { font-size: clamp(22px, 8vw, 36px); }
.cell:active { transform: scale(.94); }
.cell > * { grid-area: 1 / 1; }
.cell .v { position: relative; z-index: 2; }
.cell .mk { z-index: 1; width: 100%; height: 100%; display: grid; place-items: center; pointer-events: none; }
.cell .dot { display: none; }
.cell .step { position: absolute; top: 3px; left: 5px; font-size: .45em; z-index: 3; }
.cell.free { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.free-label { display: flex; flex-direction: column; align-items: center; font-size: .45em; letter-spacing: .05em; }
.free-label span { font-size: 1.6em; color: var(--accent); }
/* called (not colour only: dashed outline + corner dot) */
[data-called="show"] .cell.called:not(.marked) { border-style: dashed; border-color: var(--accent); }
[data-called="show"] .cell.called:not(.marked) .dot { display: block; position: absolute; top: 5px; right: 5px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--surface); }
.cell.nope { animation: nope .35s; }
@keyframes nope { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.cell.win { box-shadow: 0 0 0 3px var(--accent), 0 0 18px var(--accent); }

/* marker styles (data-mark on <html>); every one changes shape, not just colour */
.cell.marked .mk { animation: stampIn .18s ease-out; }
@keyframes stampIn { from { transform: scale(1.5); opacity: 0; } }
[data-mark="dab"] .cell.marked .mk { background: radial-gradient(circle at 48% 52%, color-mix(in srgb, var(--chip) 85%, transparent) 0 52%, transparent 54%), radial-gradient(circle at 70% 30%, color-mix(in srgb, var(--chip) 70%, transparent) 0 14%, transparent 16%), radial-gradient(circle at 25% 75%, color-mix(in srgb, var(--chip) 70%, transparent) 0 10%, transparent 12%); }
[data-mark="dab"] .cell.marked .v { color: #fff; text-shadow: 0 1px 2px rgb(0 0 0 / .6), 0 0 6px rgb(0 0 0 / .4); }
[data-mark="chip"] .cell.marked .mk { width: 84%; height: 84%; border-radius: 50%; background: color-mix(in srgb, var(--chip) 38%, transparent); border: 3px solid var(--chip); box-shadow: inset 0 0 0 4px color-mix(in srgb, #fff 45%, transparent), 0 3px 6px rgb(0 0 0 / .25); }
[data-mark="chad"] .cell.marked .mk { width: 78%; height: 78%; border-radius: 50%; background: radial-gradient(circle at 50% 40%, var(--bg2), color-mix(in srgb, var(--bg2) 60%, #000)); box-shadow: inset 0 4px 8px rgb(0 0 0 / .45); border: 2px dashed color-mix(in srgb, var(--ink) 50%, transparent); }
[data-mark="stone"] .cell.marked .mk { width: 80%; height: 74%; border-radius: 46% 54% 42% 58% / 55% 45% 55% 45%; background: radial-gradient(circle at 35% 30%, #d9d4cc, #8a847a 70%, #5e5950); box-shadow: 0 3px 5px rgb(0 0 0 / .35); }
[data-mark="stone"] .cell.marked .v { color: #fff; text-shadow: 0 1px 2px #000; }
[data-mark="cross"] .cell.marked .mk { background: linear-gradient(45deg, transparent 44%, var(--chip) 44% 56%, transparent 56%), linear-gradient(-45deg, transparent 44%, var(--chip) 44% 56%, transparent 56%); }
[data-mark="cross"] .cell.marked .v { opacity: .75; }
[data-mark="check"] .cell.marked { background: color-mix(in srgb, var(--chip) 16%, var(--surface)); }
[data-mark="check"] .cell.marked .mk::after { content: "✓"; position: absolute; right: 4px; bottom: 0; font-size: .9em; color: var(--chip); text-shadow: 0 0 2px var(--surface); }
[data-mark="stamp"] .cell.marked .mk { width: 82%; height: 82%; border-radius: 50%; border: 3px double var(--chip); transform: rotate(-14deg); background: repeating-conic-gradient(from 0deg, color-mix(in srgb, var(--chip) 22%, transparent) 0 10deg, transparent 10deg 20deg); }
[data-mark="stamp"] .cell.marked .mk::after { content: "★"; position: absolute; top: -2px; right: 4px; color: var(--chip); font-size: .55em; }
[data-mark="emoji"] .cell.marked .mk { font-size: 1.3em; opacity: .55; }
[data-mark="emoji"] .cell.marked .v { text-shadow: 0 0 4px var(--surface), 0 0 8px var(--surface); }
:root[data-contrast="high"] .cell.marked { outline: 3px solid var(--ink); outline-offset: -5px; }
/* Word Trail */
.card.tracing .cell { cursor: crosshair; }
.cell.in-trail { border-color: var(--accent); border-style: solid; background: color-mix(in srgb, var(--accent) 18%, var(--surface)); }
.cell.trail-uncalled { border-color: var(--bad); border-style: dotted; }
.trail { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; }
.trail polyline { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; opacity: .7; vector-effect: non-scaling-stroke; stroke-width: 8px; }

/* ---------- phases ---------- */
.hero { text-align: center; }
.roster { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.roster li { padding: 4px 12px; border-radius: 999px; background: var(--bg2); border: 2px solid var(--c); font-weight: 800; }
.roster li.away { opacity: .5; border-style: dashed; }
.invite { display: flex; gap: 16px; align-items: center; }
.qr { background: #fff; border-radius: 10px; padding: 6px; flex: none; }
.code { font-size: 2.2em; font-weight: 900; letter-spacing: .2em; margin: 0; }
.join-url { word-break: break-all; color: var(--muted); }
.next-preview { display: flex; gap: 16px; align-items: center; }
.winners { list-style: none; padding: 0; font-size: 1.15em; }
.standings, .podium { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.standings li, .podium li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 12px; background: var(--bg2); border-left: 6px solid var(--c); }
.pname { flex: 1; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pwins { font-weight: 900; }
.podium li { text-align: left; }
.podium .place { width: 2em; text-align: center; font-size: 1.3em; }
.podium .place-1 { font-size: 1.2em; }
.results.final .form-actions { justify-content: center; margin-top: 12px; }
.rules ul { padding-left: 1.2em; margin: .5em 0 0; }
.rules li { margin: .3em 0; font-weight: 600; }
.rules summary, .status-wrap summary, .ranges summary { cursor: pointer; font-weight: 900; min-height: 32px; }
.watching { text-align: center; }

/* ---------- host ---------- */
.setup { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label, legend { font-weight: 900; font-size: .9em; }
.field-row { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.seg, .checks { border: 0; padding: 0; margin: 0; min-width: 0; }
.seg legend, .checks legend { margin-bottom: 6px; padding: 0; }
.seg-opts { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-opt { position: relative; }
.seg-opt input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.seg-opt span { display: inline-flex; align-items: center; min-height: 44px; padding: 8px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); font-weight: 800; }
.seg-opt input:checked + span { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--surface)); box-shadow: inset 0 -3px 0 var(--accent); }
.seg-opt input:checked + span::before { content: "✓ "; }
.seg-opt input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.stepper { display: inline-flex; align-items: center; gap: 8px; }
.stepper output { min-width: 4.5em; text-align: center; font-weight: 900; font-size: 1.1em; }
.ranges { border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.range-row { display: grid; grid-template-columns: 2.2em 1fr auto 1fr; gap: 8px; align-items: center; margin: 6px 0; }
.range-col { display: grid; place-items: center; width: 2em; height: 2em; border-radius: 50%; background: var(--ring); color: #fff; font-weight: 900; text-shadow: 0 1px 2px rgb(0 0 0 / .5); }
.win-preview { display: flex; gap: 12px; align-items: center; }
.pattern-editor { display: grid; grid-template-columns: repeat(5, 48px); gap: 6px; }
.pe-cell { width: 48px; height: 48px; border-radius: 10px; border: 2px solid var(--line); background: var(--surface); font: 900 20px var(--font); color: var(--accent-ink); cursor: pointer; }
.pe-cell.on { background: var(--accent); border-color: var(--accent); }
.pe-cell.free { border-style: dashed; }
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; }
.theme-opt { font: inherit; font-weight: 800; display: flex; align-items: center; gap: 8px; padding: 8px 10px; min-height: 48px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-align: left; }
.theme-opt.on { border-color: var(--accent); box-shadow: inset 0 -3px 0 var(--accent); }
.theme-emoji { font-size: 1.4em; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.form-errors p { color: var(--bad); margin: 4px 0; font-weight: 800; }
.form-errors p::before { content: "⚠ "; }
.host-controls { display: flex; flex-direction: column; gap: 10px; }
.host-primary { display: flex; flex-wrap: wrap; gap: 8px; }
.host-primary .big { flex: 1 1 140px; }
.host-note { width: 100%; font-weight: 800; }
.status-list { list-style: none; padding: 0; margin: 6px 0 0; display: flex; flex-direction: column; gap: 4px; }
.status-list li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 10px; background: var(--bg2); }
.status-list li.away { opacity: .6; }
.status-list .swatch { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.pstat { font-size: .85em; color: var(--muted); }

/* ---------- settings sheet ---------- */
.sheet { border: 0; border-radius: var(--radius); padding: 0; width: min(520px, 94vw); max-height: 88vh; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.sheet::backdrop { background: rgb(0 0 0 / .45); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.sheet-head h2 { margin: 0; }
.sheet-body { padding: 8px 16px 20px; display: flex; flex-direction: column; gap: 8px; }
.sheet-body h3 { margin: 12px 0 2px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.set-row select, .set-row input[type="range"] { max-width: 55%; }
.set-label small { display: block; color: var(--muted); font-weight: 600; }
.mark-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.mark-opt { font: inherit; font-size: .75em; font-weight: 800; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px; border: 2px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); cursor: pointer; }
.mark-opt.on { border-color: var(--accent); box-shadow: inset 0 -3px 0 var(--accent); }
.mark-opt .cell { width: 48px; min-height: 48px; font-size: 18px; pointer-events: none; }
.mark-opt[data-mark] .cell.marked .mk { animation: none; }
.chip-colors { display: flex; gap: 8px; }
.chip-swatch { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 0 0 2px var(--line); cursor: pointer; }
.chip-swatch[aria-checked="true"] { box-shadow: 0 0 0 3px var(--ink); }
.emoji-input { max-width: 5em; text-align: center; font-size: 1.4em !important; }
.switch { width: 26px; height: 26px; }
/* Mark-style demos inside the picker follow the option, not the current pref. */
.mark-opt[data-mark="dab"] .mk { background: radial-gradient(circle, color-mix(in srgb, var(--chip) 85%, transparent) 0 52%, transparent 54%) !important; border: 0 !important; transform: none !important; }
.mark-opt[data-mark="chip"] .mk { width: 84% !important; height: 84% !important; border-radius: 50%; background: color-mix(in srgb, var(--chip) 38%, transparent) !important; border: 3px solid var(--chip) !important; transform: none !important; }
.mark-opt[data-mark="chad"] .mk { width: 78% !important; height: 78% !important; border-radius: 50%; background: radial-gradient(circle at 50% 40%, var(--bg2), color-mix(in srgb, var(--bg2) 60%, #000)) !important; box-shadow: inset 0 4px 8px rgb(0 0 0 / .45); border: 2px dashed var(--muted) !important; transform: none !important; }
.mark-opt[data-mark="stone"] .mk { width: 80% !important; height: 74% !important; border-radius: 46% 54% 42% 58% / 55% 45% 55% 45%; background: radial-gradient(circle at 35% 30%, #d9d4cc, #8a847a 70%, #5e5950) !important; border: 0 !important; transform: none !important; }
.mark-opt[data-mark="cross"] .mk { background: linear-gradient(45deg, transparent 44%, var(--chip) 44% 56%, transparent 56%), linear-gradient(-45deg, transparent 44%, var(--chip) 44% 56%, transparent 56%) !important; border: 0 !important; transform: none !important; }
.mark-opt[data-mark="check"] .mk { background: none !important; border: 0 !important; transform: none !important; }
.mark-opt[data-mark="check"] .mk::after { content: "✓"; position: absolute; right: 3px; bottom: 0; color: var(--chip); }
.mark-opt[data-mark="stamp"] .mk { width: 82% !important; height: 82% !important; border-radius: 50%; border: 3px double var(--chip) !important; transform: rotate(-14deg) !important; background: none !important; }
.mark-opt[data-mark="emoji"] .mk { background: none !important; border: 0 !important; transform: none !important; opacity: .6; }
.mark-opt:not([data-mark="check"]):not([data-mark="stamp"]) .mk::after { content: none; }

/* ---------- toasts and confetti ---------- */
.toasts { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 50; width: min(92vw, 440px); pointer-events: none; }
.toast { background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 14px; font-weight: 800; box-shadow: var(--shadow); text-align: center; animation: toastIn .2s ease-out; transition: opacity .3s; }
.toast.good { background: var(--good); color: #fff; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.out { opacity: 0; }
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translate(var(--dx), 110vh) rotate(var(--rot)); } }

/* ---------- TV ---------- */
body[data-view="screen"] { overflow: hidden; }
.tv { height: 100vh; display: grid; grid-template-rows: auto 1fr auto; gap: 1.2vh; padding: 1.6vh 2vw; font-size: clamp(16px, 1.6vw, 34px); }
.tv-top { display: flex; align-items: center; gap: 2vw; }
.tv-title { flex: 1; font-weight: 900; font-size: 1.3em; }
.tv-join { display: flex; align-items: center; gap: 1vw; text-align: right; }
.tv-code { font-size: 1.5em; letter-spacing: .15em; }
.tv-main { min-height: 0; }
.tv-playing { height: 100%; display: grid; grid-template-columns: 1.05fr 1fr; gap: 2vw; min-height: 0; }
.tv-left { display: flex; flex-direction: column; min-height: 0; }
.calls-tv { flex: 1; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 2vh 2vw; grid-template-rows: 1fr auto auto; }
.calls-tv .stage { min-height: 40vh; }
.calls-tv .drawing .cage { max-width: 46vh; max-height: 46vh; }
.calls-tv .drawing-label { font-size: 1.2em; bottom: 0; }
.calls-tv .counter { font-size: 1.1em; }
.calls-tv .status-badge { font-size: 1em; padding: 4px 16px; }
.calls-tv .bar { height: 1.6vh; }
.calls-tv .no-call { font-size: 1.6em; max-width: none; }
.calls-tv .batch .ball-lg { --s: min(20vh, 15vw); }
.calls-tv .recent .ball { --s: min(6.5vh, 4.6vw); }
.calls-tv .recent-title { font-size: .7em; }
.tv-right { display: flex; flex-direction: column; gap: 1.4vh; min-height: 0; }
.tv-win { display: flex; gap: 1.5vw; align-items: center; }
.tv-win h2 { margin: 0; font-size: 1em; color: var(--muted); white-space: nowrap; }
.tv-win-body { display: flex; gap: 1.5vw; align-items: center; font-size: 1.2em; font-weight: 900; }
.flashboard { flex: 1; min-height: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 1.4vh 1vw; overflow: hidden; }
.fb-numbers { display: flex; flex-direction: column; gap: .8vh; height: 100%; justify-content: space-between; }
.fb-row { display: flex; gap: .6vw; align-items: stretch; flex: 1; min-height: 0; }
.fb-head { width: 2.2em; flex: none; display: grid; place-items: center; background: var(--ring); color: #fff; border-radius: 10px; font-weight: 900; text-shadow: 0 1px 2px rgb(0 0 0 / .5); }
.fb-nums { flex: 1; display: grid; grid-template-columns: repeat(min(var(--count), 15), 1fr); gap: 3px; align-content: stretch; font-size: clamp(10px, calc(1.1vw * 15 / max(15, var(--count) / 2)), 26px); }
.fb-n { display: grid; place-items: center; border-radius: 6px; color: var(--muted); background: var(--bg2); font-weight: 800; min-height: 0; opacity: .55; }
.fb-n.lit { opacity: 1; background: var(--ring, var(--accent)); color: #fff; text-shadow: 0 1px 2px rgb(0 0 0 / .55); font-weight: 900; }
.fb-n.latest { outline: 3px solid var(--ink); outline-offset: 1px; }
.fb-letters { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1vh; height: 100%; font-size: 2em; }
.fb-list { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.fb-list .ball { --s: min(7vh, 5vw); }
.tv-notes { min-height: 2em; font-size: .9em; }
.tv-notes .note { margin: 0; color: var(--muted); }
.tv-roster { list-style: none; padding: 0 0 0 56px; margin: 0; display: flex; flex-wrap: wrap; gap: .6vw; max-height: 14vh; overflow: hidden; }
.tv-roster li { display: flex; align-items: center; gap: .5em; padding: .25em .8em .25em .3em; border-radius: 999px; background: var(--surface); border: 3px solid var(--c); font-size: .8em; box-shadow: var(--shadow); }
.tv-roster li.away { opacity: .45; border-style: dashed; }
.tv-roster li.close { animation: glow 1s ease-in-out infinite alternate; }
@keyframes glow { to { box-shadow: 0 0 0 4px var(--accent); } }
.tv-roster .swatch { width: 1.6em; height: 1.6em; border-radius: 50%; background: var(--c); color: #fff; display: grid; place-items: center; font-weight: 900; text-shadow: 0 1px 2px rgb(0 0 0 / .5); }
.tv-roster .pname { flex: none; max-width: 10em; }
.togo { font-size: .8em; background: var(--accent); color: var(--accent-ink); padding: 0 .6em; border-radius: 999px; }
.tv-banner { position: fixed; inset: 0; display: grid; place-items: center; background: rgb(0 0 0 / .45); z-index: 40; }
.tv-banner-inner { background: var(--surface); border-radius: calc(var(--radius) * 1.5); padding: 4vh 5vw; text-align: center; box-shadow: var(--shadow); border: 6px solid var(--accent); animation: pop .5s cubic-bezier(.2, 1.6, .4, 1); min-width: 40vw; }
.tv-banner-kicker { font-size: 3.2em; font-weight: 900; color: var(--accent); margin: 0; letter-spacing: .05em; }
.tv-banner ul { list-style: none; padding: 0; margin: 2vh 0; font-size: 2.2em; }
.tv-word { margin-left: .5em; font-size: .7em; letter-spacing: .15em; background: var(--bg2); padding: 0 .4em; border-radius: 8px; }
.tv-other { height: 100%; }
.tv-lobby { height: 100%; display: grid; grid-template-columns: 1.2fr 1fr; grid-template-rows: 1fr auto; gap: 2vw; align-items: center; }
.tv-invite { display: flex; align-items: center; gap: 3vw; height: 100%; }
.qr-big { width: min(42vh, 26vw); height: auto; }
.tv-url { font-size: 1.4em; font-weight: 900; word-break: break-all; }
.tv-code-big { font-size: 4em; font-weight: 900; letter-spacing: .2em; margin: 0; color: var(--accent); }
.tv-next { align-self: center; }
.tv-wait { grid-column: 1 / -1; text-align: center; font-size: 1.2em; }
.tv-lobby .hero { grid-row: 1 / 3; }
.big { font-size: 1.3em; font-weight: 900; }
.tv-results { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2vh; }
.tv-results h1 { font-size: 3em; }
.tv-podium { width: min(60vw, 1000px); font-size: 1.3em; }
.sound-on { position: fixed; right: 2vw; bottom: 2vh; z-index: 30; font-size: .8em; }
.tv-settings { position: fixed; left: 1vw; bottom: 1.5vh; z-index: 30; opacity: .35; }
.tv-settings:hover, .tv-settings:focus-visible { opacity: 1; }
.tv[data-conn="reconnecting"]::after { content: "Reconnecting…"; position: fixed; left: 50%; top: 1vh; transform: translateX(-50%); background: var(--bad); color: #fff; padding: 4px 16px; border-radius: 999px; font-size: .7em; }

/* ---------- reduced motion ---------- */
[data-motion="reduced"] *, [data-motion="reduced"] *::before, [data-motion="reduced"] *::after { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) { #decor span, .logo-ball { animation: none; } }
