:root {
  --bg: #12122b;
  --bg2: #1c1c42;
  --panel: #23234f;
  --line: #34346a;
  --ink: #f4f3ff;
  --mute: #a9a8d6;
  --paper: #fffdf7;
  --paper-ink: #1d1b34;
  --B: #2f7bff;
  --I: #ff4d6d;
  --N: #f2f1fb;
  --G: #22c07a;
  --O: #ffb21e;
  --daub: rgba(255, 46, 120, 0.78);
  --gold: #ffd34d;
  --radius: 16px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  background: radial-gradient(1200px 600px at 50% -10%, #2b2b6e 0, transparent 70%), var(--bg);
  color: var(--ink);
  font: 16px/1.4 'Fredoka', ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
a { color: #9db8ff; }

[data-l='B'] { --c: var(--B); }
[data-l='I'] { --c: var(--I); }
[data-l='N'] { --c: var(--N); }
[data-l='G'] { --c: var(--G); }
[data-l='O'] { --c: var(--O); }
[data-l='none'] { --c: #5a5a8c; }

/* ---------- shared bits ---------- */
.top {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px; border-bottom: 1px solid var(--line); background: rgba(18, 18, 43, 0.6);
  position: sticky; top: 0; z-index: 5; backdrop-filter: blur(8px);
}
.brand { font-weight: 700; font-size: 22px; letter-spacing: 0.5px; display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand .dot { width: 26px; height: 26px; border-radius: 50%; flex: none; background: radial-gradient(circle at 35% 30%, #fff9 0, transparent 45%), var(--I); box-shadow: inset -3px -4px 6px #0005; }
.brand .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spacer { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); font-size: 14px; white-space: nowrap; }
.pill.live { background: #0e3b2a; border-color: #1d7a52; }
.pill.live::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: #3bf09c; animation: blink 1.4s infinite; }
.pill.over { background: #3a2a12; border-color: #8a6420; }
.pill.off { background: #4a1c26; border-color: #93364a; }
@keyframes blink { 50% { opacity: 0.25; } }

.btn {
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 600; background: var(--panel);
  border: 1px solid var(--line); transition: transform 0.08s, filter 0.15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(180deg, #4d8bff, #2a62e8); border-color: #6f9fff; }
.btn.small { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; filter: none; }

.panel { background: rgba(35, 35, 79, 0.75); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel h2 { margin: 0 0 10px; font-size: 15px; font-weight: 600; color: var(--mute); text-transform: uppercase; letter-spacing: 1px; }
.mute { color: var(--mute); }
input[type='text'] {
  width: 100%; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--line); background: #15153a; font-size: 18px; outline: none;
}
input[type='text']:focus { border-color: #6f9fff; box-shadow: 0 0 0 3px #4d8bff44; }
select { padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line); background: #15153a; }

.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; color: var(--mute); cursor: pointer; user-select: none; }
.switch input { appearance: none; width: 40px; height: 24px; border-radius: 99px; background: #3a3a70; position: relative; margin: 0; cursor: pointer; transition: background 0.2s; flex: none; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.switch input:checked { background: #2f9e6a; }
.switch input:checked::after { transform: translateX(16px); }

/* ---------- balls ---------- */
.ball {
  --s: 64px; width: var(--s); height: var(--s); border-radius: 50%; flex: none; display: grid; place-items: center;
  background: radial-gradient(circle at 32% 26%, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0) 40%), var(--c);
  box-shadow: inset calc(var(--s) * -0.07) calc(var(--s) * -0.1) calc(var(--s) * 0.16) rgba(0, 0, 0, 0.35), 0 calc(var(--s) * 0.06) calc(var(--s) * 0.16) rgba(0, 0, 0, 0.45);
}
.ball .face {
  width: 64%; height: 64%; border-radius: 50%; background: #fff; color: #17152b; display: flex; flex-direction: column;
  align-items: center; justify-content: center; line-height: 0.95; box-shadow: inset 0 -2px 4px #0002;
}
.ball .l { font-size: calc(var(--s) * 0.13); font-weight: 700; color: color-mix(in srgb, var(--c) 75%, #000); }
.ball[data-l='N'] .l { color: #6b6890; }
.ball .n { font-size: calc(var(--s) * 0.27); font-weight: 700; font-variant-numeric: tabular-nums; }
.ball[data-l='none'] .l { display: none; }
.ball.rolling { animation: wobble 0.18s infinite alternate ease-in-out; }
.ball.landed { animation: land 0.55s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes wobble { from { transform: rotate(-9deg) translateY(-2px); } to { transform: rotate(9deg) translateY(2px); } }
@keyframes land { 0% { transform: scale(0.6) rotate(-30deg); } 100% { transform: none; } }

.stage { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 18px 16px; text-align: center; }
.stage .count { color: var(--mute); font-size: 15px; }
.recent { display: flex; gap: 8px; justify-content: center; min-height: 46px; flex-wrap: wrap; }
.recent .ball { opacity: 0.92; }

/* ---------- 75-number board ---------- */
.board { display: grid; gap: 5px; }
.brow { display: grid; grid-template-columns: repeat(16, minmax(0, 1fr)); gap: 4px; }
.bl, .bcell { aspect-ratio: 1; border-radius: 8px; display: grid; place-items: center; font-weight: 600; font-variant-numeric: tabular-nums; font-size: clamp(10px, 1.9vw, 17px); }
.bl { background: var(--c); color: #15132a; font-weight: 700; }
.bcell { background: #1a1a40; color: #5c5b8e; border: 1px solid #2a2a5c; transition: background 0.3s, color 0.3s; }
.bcell.on { background: var(--c); color: #15132a; border-color: transparent; }
.bcell.last { box-shadow: 0 0 0 3px #fff, 0 0 18px 4px var(--c); position: relative; z-index: 1; animation: pop 0.6s; }
@keyframes pop { 40% { transform: scale(1.35); } }

/* ---------- the player card ---------- */
.card {
  --cell: 78px;
  background: var(--paper); color: var(--paper-ink); border-radius: 22px; padding: 12px; width: fit-content; margin: 0 auto;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45), inset 0 0 0 4px #ffffff;
}
.card .head, .card .grid { display: grid; grid-template-columns: repeat(5, var(--cell)); gap: 6px; }
.card .head { margin-bottom: 6px; }
.card .head div { height: calc(var(--cell) * 0.62); border-radius: 12px; background: var(--c); display: grid; place-items: center; font-weight: 700; font-size: calc(var(--cell) * 0.42); color: #fff; text-shadow: 0 2px 0 #0003; }
.card .head div[data-l='N'] { background: #8f8bb8; }
.cell {
  width: var(--cell); height: var(--cell); border-radius: 12px; border: 2px solid #e6e1f2; background: #fff; color: var(--paper-ink);
  display: grid; place-items: center; font-weight: 700; font-size: calc(var(--cell) * 0.4); position: relative; padding: 0; font-variant-numeric: tabular-nums;
}
.cell.free { background: #fff2c4; border-color: #f5d76e; font-size: calc(var(--cell) * 0.18); letter-spacing: 1px; color: #8a6a00; }
.cell.free b { font-size: calc(var(--cell) * 0.34); display: block; line-height: 1; }
.cell.marked::after {
  content: ''; position: absolute; inset: 9%; border-radius: 50%; background: var(--daub);
  animation: daub 0.28s ease-out; mix-blend-mode: multiply;
}
.cell.free.marked::after { background: rgba(255, 46, 120, 0.25); }
.cell.hint { border-color: #ff2e78; border-style: dashed; animation: hint 1s infinite alternate; }
.cell.win { box-shadow: 0 0 0 3px var(--gold), 0 0 16px 2px #ffd34daa; border-color: var(--gold); }
@keyframes daub { from { transform: scale(1.6); opacity: 0; } }
@keyframes hint { to { background: #ffe6ef; } }
.card.small { --cell: 30px; padding: 6px; border-radius: 12px; }
.card.small .head, .card.small .grid { gap: 3px; }
.card.small .cell { border-radius: 6px; border-width: 1px; }
.card.small .head div { border-radius: 6px; }

.bingo-btn {
  display: block; width: 100%; max-width: 440px; margin: 0 auto; padding: 16px; border-radius: 18px; border: 0;
  font-size: 30px; font-weight: 700; letter-spacing: 3px; color: #fff; background: linear-gradient(180deg, #5b5b8f, #43436f);
  box-shadow: 0 6px 0 #2c2c52; transition: transform 0.08s;
}
.bingo-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #2c2c52; }
.bingo-btn.ready { background: linear-gradient(180deg, #ff5d8f, #e6185e); box-shadow: 0 6px 0 #9c0d3d, 0 0 30px #ff2e78aa; animation: glow 0.9s infinite alternate; }
.bingo-btn.ready:active { box-shadow: 0 2px 0 #9c0d3d; }
@keyframes glow { to { box-shadow: 0 6px 0 #9c0d3d, 0 0 50px 8px #ff2e78cc; } }
.togo { text-align: center; color: var(--mute); min-height: 24px; margin: 10px 0; font-size: 16px; }
.togo b { color: var(--gold); }

/* ---------- overlays, toasts, confetti ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(8, 8, 24, 0.78); backdrop-filter: blur(4px); animation: fade 0.25s; }
.overlay .box { background: var(--bg2); border: 1px solid var(--line); border-radius: 22px; padding: 24px; max-width: 520px; width: 100%; text-align: center; box-shadow: 0 20px 60px #000a; max-height: calc(100dvh - 32px); overflow: auto; }
.overlay .big { font-size: clamp(44px, 12vw, 84px); font-weight: 700; line-height: 1; letter-spacing: 4px; background: linear-gradient(90deg, var(--B), var(--I), var(--G), var(--O)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.overlay .who { font-size: 26px; font-weight: 600; margin: 10px 0 4px; overflow-wrap: anywhere; }
@keyframes fade { from { opacity: 0; } }
#toasts { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; width: min(92vw, 420px); pointer-events: none; }
.toast { background: #2d2d66; border: 1px solid #4a4a90; padding: 12px 16px; border-radius: 12px; box-shadow: 0 8px 24px #0008; text-align: center; transition: opacity 0.4s, transform 0.4s; }
.toast.out { opacity: 0; transform: translateY(10px); }
.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 70; }

/* ---------- landing & join ---------- */
.center { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.hero { width: min(100%, 460px); text-align: center; display: grid; gap: 18px; }
.hero h1 { margin: 0; font-size: clamp(40px, 11vw, 64px); letter-spacing: 3px; line-height: 1; }
.hero .balls { display: flex; justify-content: center; gap: 8px; }
.row { display: flex; gap: 10px; }
.row > input { flex: 1; min-width: 0; }

/* ---------- player game layout ---------- */
.pattern-line { text-align: center; padding: 10px 16px 0; color: var(--mute); }
.pattern-line b { color: var(--ink); }
.play {
  --big: 190px; --small: 44px;
  display: grid; gap: 16px; padding: 8px 16px 40px; max-width: 1100px; margin: 0 auto;
  grid-template-areas: 'stage' 'card' 'calls';
}
.play .stage { grid-area: stage; }
.play .stage .info { display: grid; gap: 12px; justify-items: center; }
.play .cardsec { grid-area: card; }
.play .calls { grid-area: calls; }
.toggles { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; margin-top: 16px; }
details.calls summary { cursor: pointer; color: var(--mute); padding: 4px 0; list-style: none; text-align: center; }
details.calls summary::-webkit-details-marker { display: none; }
details.calls summary::before { content: '+ '; }
details.calls[open] summary::before { content: '− '; }
details.calls .board { margin-top: 10px; }
@media (min-width: 900px) {
  .play { grid-template-columns: 1fr auto; grid-template-areas: 'stage card' 'calls card'; align-items: start; gap: 20px 28px; padding-top: 18px; }
  .card { --cell: 78px; }
}
@media (max-width: 899px) {
  .play { --big: min(30vw, 130px); --small: 36px; gap: 12px; }
  .play .stage { flex-direction: row; justify-content: center; padding: 10px 0 0; gap: 16px; text-align: left; }
  .play .stage .info { justify-items: start; gap: 8px; }
  .play .recent { justify-content: flex-start; gap: 6px; min-height: 36px; }
  .card { --cell: min(calc((100vw - 84px) / 5), 78px); }
  .bingo-btn { font-size: 26px; padding: 13px; }
  .togo { margin: 8px 0; }
}

/* ---------- host layout ---------- */
.host { display: grid; gap: 16px; padding: 16px; max-width: 1500px; margin: 0 auto; }
.host .stage { padding: 4px 0 0; }
.draw-btn { width: 100%; padding: 20px; font-size: 28px; border-radius: 16px; letter-spacing: 1px; }
.draw-btn small { display: block; font-size: 13px; font-weight: 500; opacity: 0.75; letter-spacing: 0; }
.ctl { display: grid; gap: 12px; }
.ctl label.f { display: grid; gap: 6px; font-size: 14px; color: var(--mute); }
.title-input { background: transparent !important; border-color: transparent !important; font-size: 22px !important; font-weight: 700; padding: 6px 8px !important; width: min(52vw, 420px) !important; }
.title-input:hover, .title-input:focus { border-color: var(--line) !important; background: #15153a !important; }
.share { display: grid; gap: 10px; }
.share .link { font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: #15153a; border: 1px solid var(--line); border-radius: 10px; padding: 10px; overflow-wrap: anywhere; user-select: all; }
.qr { background: #fff; border-radius: 12px; padding: 8px; width: 132px; cursor: zoom-in; line-height: 0; }
.qr svg { width: 100%; height: auto; }
.qr-big { background: #fff; border-radius: 18px; padding: 18px; width: min(80vw, 70vh); margin: 0 auto; line-height: 0; }
.qr-big svg { width: 100%; height: auto; }
.roster { display: grid; gap: 4px; max-height: 46vh; overflow: auto; margin: 0 -6px; padding: 0 6px; }
.roster .p { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 9px; background: #1b1b44; }
.roster .p .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster .p .on { width: 8px; height: 8px; border-radius: 50%; background: #3bf09c; flex: none; }
.roster .p .on.no { background: #55558a; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #2e2e66; color: var(--mute); white-space: nowrap; }
.badge.hot { background: #5a1f35; color: #ffb3c8; }
.badge.win { background: #5a4a10; color: var(--gold); }
.winners { display: grid; gap: 10px; }
.winner { display: flex; gap: 12px; align-items: center; background: #2a2510; border: 1px solid #6d5a1a; border-radius: 12px; padding: 10px; }
.winner .info { min-width: 0; }
.winner .info b { display: block; font-size: 18px; overflow-wrap: anywhere; }
.keys { font-size: 13px; color: var(--mute); text-align: center; }
kbd { background: #2e2e66; border: 1px solid #4a4a90; border-bottom-width: 2px; border-radius: 5px; padding: 0 6px; font: inherit; font-size: 12px; }
@media (min-width: 1100px) {
  .host { grid-template-columns: 330px 1fr 320px; align-items: start; }
}
@media (max-width: 560px) {
  .brand { font-size: 18px; }
  .title-input { width: 100% !important; }
}
.winner .card { margin: 0; flex: none; }
