:root {
  --bg: #160c31;
  --panel: rgba(255, 255, 255, 0.055);
  --panel-strong: rgba(255, 255, 255, 0.09);
  --line: rgba(255, 255, 255, 0.11);
  --ink: #fff7e8;
  --muted: #b8acdf;
  --accent: #ffc53d;
  --accent-deep: #b9730a;
  --pink: #ff3d8b;
  --good: #3ddc97;
  --bad: #ff6262;
  --paper: #fff6e3;
  --paper-line: #ecdcb8;
  --paper-ink: #22154a;
  --font: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font: 16px/1.4 var(--font);
  color: var(--ink);
  background:
    radial-gradient(1100px 620px at 8% -12%, #3f2082 0%, transparent 62%),
    radial-gradient(900px 520px at 108% 112%, #5b1d63 0%, transparent 60%),
    var(--bg);
  background-attachment: fixed;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
input { color: var(--ink); }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
h1, h2, h3 { margin: 0; line-height: 1.15; }
h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 800; }
h3 { font-size: 0.95rem; font-weight: 700; color: var(--muted); }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--bad); min-height: 1.4em; font-weight: 600; }

/* --- logo ------------------------------------------------------------- */
.logo { display: inline-flex; gap: 3px; flex: none; }
.logo i {
  font-style: normal; font-weight: 900; font-size: 0.95rem;
  width: 1.7em; height: 1.7em; border-radius: 50%;
  display: grid; place-items: center; color: #fff;
  background: radial-gradient(circle at 35% 30%, hsl(var(--h) 95% 72%), hsl(var(--h) 80% 42%));
  box-shadow: inset -2px -3px 5px rgba(0, 0, 0, 0.3);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
}

/* --- buttons and form bits -------------------------------------------- */
.primary, .ghost, .seg button, .bot-btn {
  border-radius: 999px; border: 0; padding: 0.6em 1.3em; font-weight: 700;
  transition: transform 0.08s, background 0.15s, opacity 0.15s;
}
.primary { background: linear-gradient(180deg, #ffd96e, #ffae1a); color: #2a1600; box-shadow: 0 4px 0 var(--accent-deep), 0 8px 20px rgba(0, 0, 0, 0.3); }
.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--accent-deep); }
.primary:disabled { opacity: 0.45; cursor: default; }
.primary.big { font-size: 1.25rem; padding: 0.7em 1.6em; }
.ghost { background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); }
.ghost:hover { background: rgba(255, 255, 255, 0.14); }
.ghost.small { font-size: 0.85rem; padding: 0.4em 1em; }
.controls { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }

input[type="text"], input:not([type]) {
  width: 100%; padding: 0.7em 0.9em; border-radius: 14px;
  border: 2px solid var(--line); background: rgba(0, 0, 0, 0.25); font-size: 1.2rem;
}
input:focus-visible { outline: none; border-color: var(--accent); }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
#code { text-transform: uppercase; letter-spacing: 0.4em; font-weight: 800; font-size: 1.8rem; text-align: center; }

.seg { display: inline-flex; flex-wrap: wrap; gap: 0.35rem; }
.seg button { background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line); padding: 0.45em 0.95em; }
.seg button.on { background: var(--accent); color: #2a1600; border-color: var(--accent); }

.toggle { display: flex; align-items: center; gap: 0.6rem; cursor: pointer; user-select: none; }
.toggle input { appearance: none; width: 2.6em; height: 1.5em; border-radius: 999px; background: rgba(255, 255, 255, 0.15); position: relative; flex: none; margin: 0; transition: background 0.15s; cursor: pointer; }
.toggle input::after { content: ""; position: absolute; top: 0.18em; left: 0.18em; width: 1.14em; height: 1.14em; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.toggle input:checked { background: var(--good); }
.toggle input:checked::after { transform: translateX(1.1em); }

.panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.035));
  border: 1px solid var(--line); border-radius: 22px; padding: 1.2rem;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 18px 40px rgba(0, 0, 0, 0.25);
}

/* --- top bar ---------------------------------------------------------- */
.bar { display: flex; align-items: center; gap: 0.8rem; padding: 0.6rem 1rem; padding-top: max(0.6rem, env(safe-area-inset-top)); }
.bar .spacer { flex: 1; }
.bar .lang-toggle { padding: 0.3em 0.8em; font-size: 0.8rem; flex: none; }
.whoami { flex: 1; display: flex; align-items: center; justify-content: flex-end; gap: 0.45rem; min-width: 0; font-weight: 700; }
.whoami .code { font-weight: 800; letter-spacing: 0.15em; padding: 0.1em 0.55em; border-radius: 8px; background: rgba(255, 255, 255, 0.1); font-size: 0.8rem; }
.whoami .me { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- chips ------------------------------------------------------------ */
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: center; }
.chip { display: inline-flex; align-items: center; gap: 0.35em; padding: 0.25em 0.75em 0.25em 0.35em; border-radius: 999px; background: rgba(255, 255, 255, 0.09); font-weight: 600; }
.chip-avatar { font-size: 1.2em; }
.chip.offline { opacity: 0.45; }
.chip.me { background: rgba(255, 197, 61, 0.22); }

/* --- balls ------------------------------------------------------------ */
.ball {
  --size: 64px;
  position: relative;
  width: var(--size); height: var(--size); border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: radial-gradient(circle at 30% 26%, hsl(var(--h) 95% 80%), hsl(var(--h) 85% 54%) 40%, hsl(var(--h) 85% 26%) 100%);
  box-shadow: inset calc(var(--size) * -0.04) calc(var(--size) * -0.07) calc(var(--size) * 0.12) rgba(0, 0, 0, 0.35), 0 calc(var(--size) * 0.06) calc(var(--size) * 0.16) rgba(0, 0, 0, 0.45);
}
/* Glossy highlight. */
.ball::after {
  content: ""; position: absolute; top: 7%; left: 17%; width: 36%; height: 22%; border-radius: 50%;
  background: radial-gradient(ellipse, rgba(255, 255, 255, 0.75), transparent 70%); transform: rotate(-28deg);
}
.ball-face {
  width: 62%; height: 62%; border-radius: 50%; background: #fffdf6; color: #1d1240;
  display: grid; place-content: center; text-align: center; line-height: 0.95;
  box-shadow: inset 0 calc(var(--size) * -0.03) calc(var(--size) * 0.06) rgba(0, 0, 0, 0.18);
}
.ball-face b { font-size: calc(var(--size) * 0.29); font-weight: 850; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.ball-face .letter { font-size: calc(var(--size) * 0.13); font-weight: 900; color: hsl(var(--h) 75% 40%); }
.ball-q .ball-face { width: 80%; height: 80%; }
.ball-q b.q { font-size: calc(var(--size) * 0.19); white-space: nowrap; }
.ball-q .a { font-size: calc(var(--size) * 0.13); font-weight: 800; color: hsl(var(--h) 70% 38%); margin-top: 0.2em; }
.ball-pic .ball-face { width: 72%; height: 72%; }
.ball-pic b.pic { font-size: calc(var(--size) * 0.36); }
.ball.drop { animation: drop 0.6s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes drop {
  from { transform: translateY(-60%) scale(0.4) rotate(-200deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.recent { display: flex; gap: 0.35rem; align-items: center; }
.recent .ball { --size: 38px; }
.recent .ball::after, .call-grid .ball::after { display: none; }

/* --- cards ------------------------------------------------------------ */
/* A card keeps its proportions (--ratio, set by render.js); inside a .fit box
   it takes the largest size that fits. Text scales with the card's width. */
.card {
  --ratio: 1;
  container-type: inline-size;
  aspect-ratio: var(--ratio);
  display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 5px;
  padding: 8px; border-radius: 18px; color: var(--paper-ink);
  background: radial-gradient(130% 100% at 25% 0%, #fffcf3 0%, #fff4dc 55%, #f9e6bf 100%);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.7) inset, 0 3px 0 #dcc28c, 0 16px 34px rgba(0, 0, 0, 0.45);
}
.fit { flex: 1; min-height: 0; min-width: 0; container-type: size; display: grid; place-items: center; }
.fit > .card { width: min(100cqw, 100cqh * var(--ratio)); }
.card-head {
  display: grid; place-items: center; font-weight: 900; font-size: calc(100cqw / var(--cols) * 0.36);
  color: hsl(var(--h) 80% 46%); line-height: 1;
}
.cell {
  position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; padding: 0;
  border: 0; border-radius: 22%; background: #fffefa;
  box-shadow: inset 0 0 0 1.5px var(--paper-line), inset 0 -3px 0 rgba(120, 90, 30, 0.06);
  font-weight: 800; font-size: calc(100cqw / var(--cols) * 0.4); line-height: 1; color: var(--paper-ink);
  font-variant-numeric: tabular-nums; letter-spacing: -0.02em; user-select: none; -webkit-user-select: none;
}
.cell span { position: relative; z-index: 1; }
button.cell { transition: transform 0.08s; }
button.cell:active { transform: scale(0.93); }
.card-b90 { gap: 3px; padding: 6px; border-radius: 12px; }
.card-b90 .cell { border-radius: 16%; font-size: calc(100cqw / var(--cols) * 0.48); box-shadow: inset 0 0 0 1px var(--paper-line); }
.card-b30 .cell, .card-math .cell { font-size: calc(100cqw / var(--cols) * 0.36); }
.card-pics .cell { font-size: calc(100cqw / var(--cols) * 0.55); }
.cell.blank { background: repeating-linear-gradient(45deg, rgba(214, 186, 128, 0.28) 0 4px, transparent 4px 8px); box-shadow: none; }
.cell.free { color: #f0a500; font-size: calc(100cqw / var(--cols) * 0.5); background: radial-gradient(circle, #fff3c4, #ffe592); box-shadow: inset 0 0 0 1.5px #f3cf6b; }
/* The dauber: a slightly irregular ink blot, rotated differently on every cell. */
.cell.marked::after {
  content: ""; position: absolute; inset: 7%;
  border-radius: 47% 53% 49% 51% / 53% 46% 54% 47%;
  background: radial-gradient(circle at 40% 36%, rgba(255, 140, 190, 0.5), rgba(240, 40, 125, 0.74) 55%, rgba(200, 12, 98, 0.86));
  mix-blend-mode: multiply;
  transform: translate(var(--dx, 0), var(--dy, 0)) rotate(var(--rot, 0deg));
  animation: daub 0.22s ease-out;
}
.cell.free.marked::after { display: none; }
.card-b90 .cell.marked::after { inset: 8% 5%; }
@keyframes daub { from { transform: translate(var(--dx, 0), var(--dy, 0)) rotate(var(--rot, 0deg)) scale(1.7); opacity: 0; } }
.cell.win { background: #ffe58a; box-shadow: inset 0 0 0 2px #efb400; }
.cell.last:not(.marked) { box-shadow: inset 0 0 0 2.5px var(--pink); }
.cell.shake { animation: shake 0.35s; }
@keyframes shake { 25% { transform: translateX(-5px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }

/* mini pattern preview */
.mini { display: inline-grid; grid-template-columns: repeat(var(--cols), 1fr); gap: 2px; width: 3.2em; flex: none; }
.mini i { aspect-ratio: 1; border-radius: 2px; background: rgba(255, 255, 255, 0.18); }
.mini i.on { background: var(--pink); box-shadow: 0 0 4px rgba(255, 61, 139, 0.6); }

/* --- phone page: one screen, nothing scrolls -------------------------- */
body.player { height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
.player .bar { flex: none; padding: max(8px, env(safe-area-inset-top)) 12px 6px; gap: 10px; }
.player .bar .logo i { font-size: 0.7rem; }
.player main { flex: 1; min-height: 0; width: 100%; max-width: 560px; margin: 0 auto; padding: 0 12px; display: flex; flex-direction: column; }
.player .view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

#v-join { overflow-y: auto; justify-content: center; padding-bottom: 8vh; }
.join-panel { display: grid; gap: 0.9rem; }
.join-panel label { display: grid; gap: 0.3rem; font-weight: 700; color: var(--muted); }
.join-panel .muted { text-align: center; font-size: 0.9rem; }
.host-link { display: block; text-align: center; margin-top: 1.4rem; color: var(--muted); }

#v-lobby, #v-wait { justify-content: center; padding-bottom: 12px; }
.lobby-panel { display: flex; flex-direction: column; gap: 0.8rem; text-align: center; align-items: center; max-height: 100%; overflow-y: auto; }
.avatar-big { font-size: 4.5rem; line-height: 1; animation: bob 2.4s ease-in-out infinite; filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.4)); }
@keyframes bob { 50% { transform: translateY(-8px) rotate(4deg); } }
.variant-note { display: flex; gap: 0.5rem; align-items: center; justify-content: center; flex-wrap: wrap; font-weight: 700; }
.variant-note .pat { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.25rem 0.7rem 0.25rem 0.35rem; border-radius: 999px; background: rgba(255, 255, 255, 0.08); }
.variant-note .mini { width: 1.6em; }

.game .callbar { flex: none; display: flex; align-items: center; gap: 10px; padding: 2px 0 8px; }
.callbar .current { flex: none; }
.callbar .current .ball { --size: 70px; }
.callbar .placeholder { width: 70px; height: 70px; border-radius: 50%; border: 3px dashed var(--line); display: grid; place-items: center; font-size: 1.8rem; color: var(--muted); }
.callinfo { flex: 1; min-width: 0; display: grid; gap: 4px; }
.stage { display: flex; align-items: center; gap: 0.5rem; font-weight: 800; min-width: 0; }
.stage .mini { width: 1.9em; }
.stage .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage .label { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.stage .of { color: var(--muted); font-size: 0.8rem; font-weight: 700; }
.callbar .recent { overflow: hidden; }
.callbar .recent .ball { --size: 28px; opacity: 0.9; }
.hint { font-size: 0.85rem; color: var(--muted); min-height: 1.25em; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hint.hot { color: var(--accent); }
.hint.bad { color: var(--bad); }
.vip-controls { display: flex; flex-direction: column; gap: 6px; }
.vip-controls:empty { display: none; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.08); display: grid; place-items: center; padding: 0; }
.icon-btn svg { width: 15px; height: 15px; fill: currentColor; }
.icon-btn:active { transform: scale(0.92); }

.pager {
  flex: 1; min-height: 0; margin: 0 -12px;
  display: flex; overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain;
}
.pager::-webkit-scrollbar { display: none; }
.page { flex: 0 0 100%; min-width: 0; height: 100%; padding: 2px 12px; scroll-snap-align: start; scroll-snap-stop: always; }
.cards-page { display: flex; flex-direction: column; gap: 8px; }
.details { overflow-y: auto; overscroll-behavior: contain; }
.details-inner { display: flex; flex-direction: column; gap: 10px; padding: 4px 0 12px; }
.details h2 { margin-top: 4px; }
.call-grid { display: flex; flex-wrap: wrap; gap: 5px; }
.call-grid .ball { --size: 34px; }
.mini-standings { display: grid; gap: 4px; }
.mini-standings .row { display: grid; grid-template-columns: 1.8em minmax(0, 1fr) auto auto; gap: 0.5rem; align-items: center; padding: 0.35rem 0.7rem; border-radius: 12px; background: rgba(255, 255, 255, 0.06); font-weight: 700; }
.mini-standings .row.me { background: rgba(255, 197, 61, 0.18); }
.mini-standings .row.offline { opacity: 0.5; }
.mini-standings .av { font-size: 1.25rem; }
.mini-standings .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-standings .needs { font-size: 0.8rem; color: var(--pink); }
.mini-standings .pts { color: var(--accent); font-size: 0.85rem; }
.reactions { display: flex; gap: 8px; flex-wrap: wrap; }
.reactions button, .tray button { width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, 0.08); font-size: 1.45rem; padding: 0; }
.reactions button.sent, .tray button.sent { animation: sent 0.4s ease-out; }
@keyframes sent { 40% { transform: scale(1.35) translateY(-6px); } }
.details .leave { align-self: center; margin-top: 6px; }

.tabs { flex: none; display: flex; justify-content: center; align-items: center; gap: 8px; height: 30px; }
.tab-dot { width: 9px; height: 9px; border-radius: 5px; border: 0; padding: 0; background: rgba(255, 255, 255, 0.28); transition: width 0.2s, background 0.2s; }
.tab-dot.on { background: var(--accent); width: 24px; }
.tab-label { border: 0; border-radius: 999px; padding: 3px 12px; font-size: 0.78rem; font-weight: 800; background: rgba(255, 255, 255, 0.08); color: var(--muted); transition: background 0.2s, color 0.2s; }
.tab-label.on { background: var(--accent); color: #2a1600; }

.actionbar { flex: none; position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 4px 0 max(10px, env(safe-area-inset-bottom)); }
.bingo-btn {
  position: relative; overflow: hidden;
  border: 0; border-radius: 20px; padding: 0.32em; font-size: clamp(1.6rem, 8vw, 2.1rem); font-weight: 900; letter-spacing: 0.1em; color: #fff;
  background: linear-gradient(180deg, #ff6aae, #e8186f); box-shadow: 0 6px 0 #9c0a48, 0 12px 26px rgba(0, 0, 0, 0.4);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}
.bingo-btn:active { transform: translateY(3px); box-shadow: 0 3px 0 #9c0a48; }
.bingo-btn:disabled { filter: grayscale(0.85); opacity: 0.55; }
.bingo-btn.ready { animation: glow 0.9s ease-in-out infinite alternate; }
.bingo-btn.ready::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, 0.45) 50%, transparent 70%);
  animation: shine 1.4s ease-in-out infinite;
}
@keyframes glow { to { box-shadow: 0 6px 0 #9c0a48, 0 0 0 5px rgba(255, 197, 61, 0.85), 0 0 40px rgba(255, 61, 139, 0.9); } }
@keyframes shine { to { transform: translateX(100%); } }
.react-btn { width: 58px; border-radius: 18px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.08); font-size: 1.6rem; padding: 0; }
.tray {
  position: absolute; bottom: calc(100% + 6px); right: 0; z-index: 12; display: flex; gap: 6px; padding: 8px;
  border-radius: 999px; background: #2b1a5e; border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: tray-in 0.18s ease-out;
}
@keyframes tray-in { from { transform: translateY(8px) scale(0.95); opacity: 0; } }

/* --- overlays, toasts ------------------------------------------------- */
.overlay {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 1rem;
  background: radial-gradient(circle at 50% 30%, rgba(60, 25, 120, 0.85), rgba(10, 5, 28, 0.92));
  backdrop-filter: blur(4px); animation: fade 0.25s;
}
@keyframes fade { from { opacity: 0; } }
.overlay-box { width: min(100%, 640px); max-height: 100%; overflow: auto; text-align: center; display: grid; gap: 0.8rem; justify-items: center; }
.overlay h1 { font-size: clamp(1.6rem, 7vw, 3.2rem); font-weight: 900; }
.overlay .burst {
  font-size: clamp(3rem, 15vw, 6.5rem); font-weight: 900; letter-spacing: 0.06em; line-height: 1;
  background: linear-gradient(180deg, #fff3b0, var(--accent) 55%, #ff9a1a); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 0 var(--accent-deep)) drop-shadow(0 0 24px rgba(255, 197, 61, 0.55));
  animation: burst 0.6s cubic-bezier(0.2, 1.6, 0.4, 1);
}
@keyframes burst { from { transform: scale(0.2) rotate(-12deg); opacity: 0; } }
.overlay .winner-fit { width: min(86vw, 420px); height: min(36dvh, 330px); flex: none; }
.overlay .winners-cards { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center; }
.overlay .winner-card { display: grid; gap: 0.4rem; justify-items: center; font-weight: 700; }
.standings { width: min(100%, 420px); display: grid; gap: 0.35rem; }
.standings .row { display: grid; grid-template-columns: 2.2em 2em 1fr auto; align-items: center; gap: 0.5rem; padding: 0.45rem 0.8rem; border-radius: 12px; background: rgba(255, 255, 255, 0.06); font-weight: 700; text-align: left; }
.standings .row.first { background: linear-gradient(90deg, rgba(255, 197, 61, 0.32), rgba(255, 197, 61, 0.1)); }
.standings .pos { color: var(--muted); }
.standings .pts { color: var(--accent); }

.toast {
  position: fixed; left: 50%; top: 0.8rem; transform: translateX(-50%); z-index: 40;
  padding: 0.6rem 1.1rem; border-radius: 999px; background: #2d1b63; border: 1px solid var(--line);
  font-weight: 700; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45); max-width: calc(100vw - 2rem); text-align: center;
  animation: toast-in 0.25s;
}
@keyframes toast-in { from { transform: translate(-50%, -150%); } }
.offline { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; text-align: center; padding: 0.5rem; background: var(--bad); color: #fff; font-weight: 700; }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 35; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 9px; height: 15px; border-radius: 2px; background: hsl(var(--h) 92% 62%); animation: fall var(--d) cubic-bezier(0.3, 0.1, 0.6, 1) forwards; }
@keyframes fall { to { transform: translate(var(--dx), 110vh) rotate(var(--r)); } }

/* --- host screen ------------------------------------------------------ */
.host { font-size: clamp(14px, 1.05vw, 26px); overflow: hidden; }
/* Slowly drifting coloured light behind everything. */
.host::before {
  content: ""; position: fixed; inset: -15%; z-index: -1; pointer-events: none;
  background:
    radial-gradient(32% 30% at 22% 28%, rgba(124, 58, 237, 0.32), transparent 70%),
    radial-gradient(30% 28% at 78% 72%, rgba(236, 72, 153, 0.24), transparent 70%),
    radial-gradient(26% 26% at 62% 18%, rgba(59, 130, 246, 0.18), transparent 70%);
  animation: drift 36s ease-in-out infinite alternate;
}
@keyframes drift { to { transform: translate(4%, -3%) rotate(10deg) scale(1.1); } }
.host .bar { padding: 0.8rem 1.4rem; }
.host .bar .logo i { font-size: 1.15rem; }
.joininfo { font-weight: 700; font-size: 1.15rem; display: flex; gap: 0.6rem; align-items: center; }
.joininfo button { margin-left: 0.8rem; font-size: 0.8rem; }
.joininfo b { color: var(--accent); letter-spacing: 0.12em; font-size: 1.4em; }
.bar-actions { display: flex; align-items: center; gap: 0.8rem; }
.bar-actions .note { font-size: 0.8rem; color: var(--muted); }
.host main { padding: 0 1.4rem 1.4rem; height: calc(100vh - 4.5rem); height: calc(100dvh - 4.5rem); }

.host-lobby { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); grid-template-rows: auto 1fr; gap: 1.2rem; height: 100%; }
.join-card { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0.3rem 1.5rem; }
.join-text { font-size: 1.6rem; font-weight: 600; grid-column: 1; }
.join-text b { color: var(--accent); }
.code-label { grid-column: 1; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700; font-size: 0.9rem; margin-top: 0.4rem; }
/* Room code as four letter tiles, readable from the sofa. */
.room-code { grid-column: 1; display: flex; gap: 0.12em; font-size: clamp(3.4rem, 7.5vw, 11rem); font-weight: 900; line-height: 1; }
.room-code span {
  display: grid; place-items: center; width: 1.08em; height: 1.22em; border-radius: 0.16em;
  background: linear-gradient(180deg, #ffffff, #efe4ff); color: #1d1240;
  box-shadow: 0 0.07em 0 #a58fe0, 0 0.16em 0.35em rgba(0, 0, 0, 0.45), 0 0 0.5em rgba(255, 61, 139, 0.25);
  animation: tile-in 0.5s cubic-bezier(0.2, 1.5, 0.4, 1) backwards;
}
@keyframes tile-in { from { transform: translateY(-0.4em) rotate(-8deg) scale(0.6); opacity: 0; } }
.qr-wrap { grid-column: 2; grid-row: 1 / span 3; display: grid; justify-items: center; gap: 0.4rem; color: var(--muted); font-weight: 600; }
.qr-wrap img { width: clamp(150px, 13vw, 360px); height: auto; border-radius: 14px; background: #fff; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); }
.players-card { overflow: auto; display: flex; flex-direction: column; gap: 0.9rem; min-height: 0; }
.players-card h2 .count { color: var(--accent); }
.player-grid { display: flex; flex-wrap: wrap; gap: 0.7rem; align-content: flex-start; }
.player-tile { position: relative; display: grid; justify-items: center; gap: 0.2rem; width: 7.5rem; padding: 0.8rem 0.4rem 0.6rem; border-radius: 18px; background: var(--panel-strong); border: 1px solid var(--line); animation: pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes pop { from { transform: scale(0.3); opacity: 0; } }
.player-tile .av { font-size: 2.6rem; line-height: 1.1; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.35)); }
.player-tile .nm { font-weight: 700; text-align: center; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-tile .sub { font-size: 0.75rem; color: var(--muted); }
.player-tile.offline { opacity: 0.45; }
.player-tile .kick { position: absolute; top: 0.2rem; right: 0.3rem; border: 0; background: none; color: var(--muted); font-size: 1.1rem; opacity: 0; padding: 0.1rem 0.3rem; }
.player-tile:hover .kick, .player-tile .kick:focus-visible { opacity: 1; }
.player-tile .crown { position: absolute; top: -0.6rem; left: 50%; transform: translateX(-50%); font-size: 1.1rem; }
.nobody { color: var(--muted); font-size: 1.2rem; }

.settings { grid-row: 1 / span 2; grid-column: 2; overflow: auto; display: grid; gap: 0.9rem; align-content: start; }
.variant-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr)); gap: 0.5rem; }
.variant-btn { text-align: left; border-radius: 16px; border: 2px solid var(--line); background: rgba(255, 255, 255, 0.05); padding: 0.6rem 0.8rem; display: grid; gap: 0.15rem; transition: border-color 0.15s, background 0.15s; }
.variant-btn b { font-size: 1.05rem; }
.variant-btn span { font-size: 0.78rem; color: var(--muted); line-height: 1.3; }
.variant-btn.on { border-color: var(--accent); background: rgba(255, 197, 61, 0.12); }
.pattern-grid { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.pattern-btn { display: flex; align-items: center; gap: 0.55rem; border-radius: 14px; border: 2px solid var(--line); background: rgba(255, 255, 255, 0.05); padding: 0.4rem 0.75rem 0.4rem 0.45rem; font-weight: 700; }
.pattern-btn .mini { width: 2.4em; }
.pattern-btn small { color: var(--muted); font-weight: 600; }
.pattern-btn.on { border-color: var(--pink); background: rgba(255, 61, 139, 0.14); }
.settings .row { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }
.settings .row h3 { min-width: 9rem; }
.bot-btn { background: rgba(255, 255, 255, 0.07); border: 1px dashed rgba(255, 255, 255, 0.3); padding: 0.45em 0.95em; }
.settings .start-row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 0.3rem; }
.settings .small-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.host-game { display: grid; grid-template-columns: minmax(14rem, 22vw) minmax(0, 1fr) minmax(13rem, 18vw); gap: 1.2rem; height: 100%; }
.col-call {
  --ball: min(74cqw, 38vh);
  container-type: inline-size; display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  gap: 0.6rem; text-align: center; min-height: 0;
}
.col-call .stage { flex-direction: column; gap: 0.35rem; }
.col-call .stage .name { font-size: 1.6rem; font-weight: 800; }
.col-call .stage .row { display: flex; align-items: center; gap: 0.6rem; }
.col-call .stage .mini { width: 2.6em; }
.col-call .stage .hint { font-size: 0.85rem; white-space: normal; }
/* The current ball sits in a countdown ring with a glow in its own colour. */
.current-wrap { position: relative; display: grid; place-items: center; width: calc(var(--ball) * 1.18); aspect-ratio: 1; flex: none; }
.current-wrap::before {
  content: ""; position: absolute; inset: -14%; border-radius: 50%;
  background: radial-gradient(circle, hsl(var(--h, 275) 90% 60% / 0.5), transparent 66%);
  transition: background 0.6s;
}
.ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.ring circle { fill: none; stroke-width: 2.4; }
.ring-track { stroke: rgba(255, 255, 255, 0.09); }
.ring-fill { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: 100; filter: drop-shadow(0 0 2px rgba(255, 197, 61, 0.8)); }
.current-big { position: relative; display: grid; place-items: center; }
.current-big .ball { --size: var(--ball); }
.current-big .placeholder { width: var(--ball); height: var(--ball); border-radius: 50%; border: 4px dashed var(--line); display: grid; place-items: center; color: var(--muted); padding: 1.5rem; font-weight: 600; }
.current-big .paused { position: absolute; inset: 0; display: grid; place-items: center; font-size: 2.4rem; font-weight: 900; color: var(--accent); background: rgba(23, 13, 51, 0.72); border-radius: 50%; letter-spacing: 0.1em; }
.call-name { font-size: 2rem; font-weight: 800; min-height: 0; }
.call-name:empty { display: none; }
.count-line { font-weight: 700; color: var(--muted); }
/* The board fills its box: as wide as the box allows, unless that would make it too tall. */
.col-board { display: flex; flex-direction: column; gap: 1rem; min-height: 0; overflow: hidden; }
.board-fit { flex: 1; min-height: 0; container-type: size; display: grid; place-items: center; }
.rail { flex: none; container-type: inline-size; display: grid; gap: 0.6rem; justify-items: center; padding-top: 1rem; border-top: 1px solid var(--line); }
.rail .recent { justify-content: center; gap: 1.6cqw; min-height: calc(100cqw / 8 - 1.6cqw); }
.rail .recent .ball { --size: min(5.5rem, calc(100cqw / 8 - 1.6cqw)); }
.rail .recent .ball:first-child { animation: slide-in 0.5s ease-out; }
@keyframes slide-in { from { transform: translateX(-40%); opacity: 0; } }
.board {
  --w: min(100cqw, 100cqh * var(--cols) / var(--rows));
  width: var(--w); display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: calc(var(--w) / var(--cols) * 0.08);
}
.board-cell { aspect-ratio: 1; display: grid; place-items: center; border-radius: 50%; font-weight: 800; font-size: calc(var(--w) / var(--cols) * 0.4); color: rgba(255, 255, 255, 0.24); background: rgba(255, 255, 255, 0.045); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04); font-variant-numeric: tabular-nums; }
.board-cell.on {
  color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  background: radial-gradient(circle at 34% 28%, hsl(var(--h) 95% 74%), hsl(var(--h) 82% 46%) 60%, hsl(var(--h) 85% 32%));
  box-shadow: 0 0.15em 0.35em rgba(0, 0, 0, 0.35);
}
.board-cell.last { box-shadow: 0 0 0 0.22rem var(--accent), 0 0 1.2rem rgba(255, 197, 61, 0.7); animation: beat 1s ease-in-out infinite; }
@keyframes beat { 50% { transform: scale(1.12); } }
.board-letter { display: grid; place-items: center; font-weight: 900; font-size: calc(var(--w) / var(--cols) * 0.6); color: hsl(var(--h) 90% 66%); }
.board-pics .board-cell { font-size: calc(var(--w) / var(--cols) * 0.55); border-radius: 22%; filter: grayscale(1) opacity(0.35); }
.board-pics .board-cell.on { filter: none; background: rgba(255, 255, 255, 0.14); }

.col-players { display: flex; flex-direction: column; gap: 0.7rem; min-height: 0; }
.player-list { display: grid; gap: 0.35rem; overflow: auto; align-content: start; }
.player-row { display: grid; grid-template-columns: 2rem minmax(0, 1fr) auto; grid-template-areas: "av nm pts" "av needs pts"; align-items: center; column-gap: 0.55rem; padding: 0.35rem 0.7rem; border-radius: 12px; background: rgba(255, 255, 255, 0.05); font-weight: 700; transition: background 0.3s; }
.player-row .av { grid-area: av; font-size: 1.6rem; }
.player-row .nm { grid-area: nm; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-row .needs { grid-area: needs; font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.player-row .pts { grid-area: pts; color: var(--accent); font-size: 0.9rem; white-space: nowrap; }
.player-row.hot { background: linear-gradient(90deg, rgba(255, 61, 139, 0.28), rgba(255, 61, 139, 0.08)); }
.player-row.hot .needs { color: #ff8fc0; }
.player-row.claim { background: var(--accent); color: #2a1600; }
.player-row.claim .needs, .player-row.claim .pts { color: #2a1600; }
.player-row.offline { opacity: 0.45; }

.reactions-layer { position: fixed; inset: 0; pointer-events: none; z-index: 25; overflow: hidden; }
.float-react { position: absolute; bottom: -5rem; display: grid; justify-items: center; animation: rise 3.2s ease-out forwards; }
.float-react .e { font-size: 4rem; line-height: 1; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.4)); }
.float-react .n { font-size: 0.85rem; font-weight: 700; background: rgba(0, 0, 0, 0.4); padding: 0.1em 0.5em; border-radius: 999px; }
@keyframes rise { 15% { opacity: 1; } to { transform: translateY(-75vh) rotate(var(--r)); opacity: 0; } }

.host .overlay-box { width: min(100%, 1400px); }
.host .overlay .winner-card .card { width: clamp(16rem, 21vw, 30rem); gap: 6px; padding: 12px; }
.host .overlay .winner-card .card-b90 { width: clamp(24rem, 36vw, 46rem); }
.host .overlay .standings { width: min(100%, 34rem); font-size: 1.2rem; }

@media (max-width: 900px) {
  .host { overflow: auto; }
  .host main { height: auto; }
  .host-lobby, .host-game { grid-template-columns: 1fr; }
  .settings { grid-row: auto; grid-column: auto; }
  .join-card { grid-template-columns: 1fr; }
  .qr-wrap { grid-column: 1; grid-row: auto; }
  .board-fit { height: 50vh; flex: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
