:root {
  --bg: #0f1226; --panel: #1a1f3d; --text: #f4f6ff; --muted: #8b93c4;
  --c0: #3b82f6; --c1: #ef4444; --c2: #f5f5f5; --c3: #22c55e; --c4: #f59e0b;
  --t0: #fff; --t1: #fff; --t2: #111; --t3: #111; --t4: #111;
}
.c0 { --col: var(--c0); --tc: var(--t0); } .c1 { --col: var(--c1); --tc: var(--t1); }
.c2 { --col: var(--c2); --tc: var(--t2); } .c3 { --col: var(--c3); --tc: var(--t3); }
.c4 { --col: var(--c4); --tc: var(--t4); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; touch-action: manipulation; }
body.offline::after { content: "offline - reconnecting…"; position: fixed; top: 8px; right: 12px;
  background: #b91c1c; color: #fff; padding: 4px 10px; border-radius: 999px; font-size: 14px; z-index: 99; }

/* ---------- shared: board, ball ---------- */
.board { display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: 4px; }
.cell { display: flex; align-items: center; justify-content: center; border-radius: 8px;
  font-weight: 700; aspect-ratio: 1; border: 0; font-size: inherit; font-family: inherit; padding: 0; }
.cell.head { background: var(--col); color: var(--tc); font-size: 1.4em; }
.cell.num { background: var(--panel); color: var(--muted); }
.cell.num.called { background: var(--col); color: var(--tc); }
.cell.num.latest { outline: 3px solid #fff; transform: scale(1.12); z-index: 1; }

.ball { border-radius: 50%; aspect-ratio: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; font-weight: 800; line-height: 1; background: var(--col, #fff); color: var(--tc, #111);
  box-shadow: inset -.08em -.1em .25em rgba(0,0,0,.25), 0 8px 30px rgba(0,0,0,.5); }
.ball .l { font-size: .55em; } .ball .n { font-size: 1em; }
.ball.pop { animation: pop .6s cubic-bezier(.2,1.6,.4,1) .25s backwards; }
@keyframes pop { from { transform: scale(.2) rotate(-200deg); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- admin (phone-first) ---------- */
.admin { max-width: 640px; margin: 0 auto; padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.bar { position: sticky; top: 0; z-index: 5; display: flex; gap: 12px; align-items: center;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: var(--bg); border-bottom: 1px solid #2a3060; }
.bar .ball { width: 74px; height: 74px; font-size: 38px; flex: none; box-shadow: none; }
.bar .meta { flex: 1; min-width: 0; }
.bar .count { color: var(--muted); } .bar .count strong { color: var(--text); font-size: 22px; }
.chips { display: flex; gap: 6px; margin-top: 6px; overflow: hidden; }
.chip { flex: none; height: 28px; padding: 0 10px; border-radius: 999px; display: flex; align-items: center;
  font-size: 14px; font-weight: 700; background: var(--col); color: var(--tc); }
.iconbtn { display: flex; align-items: center; justify-content: center; flex: none; width: 46px; height: 46px; border-radius: 12px; border: 0; background: var(--panel);
  color: var(--text); font-size: 22px; }

.tabs { display: flex; gap: 6px; padding: 10px 12px 0; }
.tabs button { flex: 1; padding: 10px; border-radius: 10px; border: 0; background: var(--panel); color: var(--muted);
  font-size: 15px; font-weight: 700; font-family: inherit; }
.tabs button.on { background: #4f46e5; color: #fff; }

.panel { position: fixed; inset: 0; z-index: 30; overflow: auto; background: var(--bg);
  padding: calc(16px + env(safe-area-inset-top)) 14px 28px; }
.panel .inner { max-width: 640px; margin: 0 auto; }
.panel .top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.panel .top h1 { margin: 0; font-size: 22px; }
.panel .top button { flex: none; padding: 10px 20px; background: #4f46e5; }
.panel h2 { font-size: 15px; margin: 0 0 8px; color: var(--muted); font-weight: 600; }
.colors { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.swatch { display: flex; flex-direction: column; align-items: center; gap: 4px; font-weight: 700; }
.swatch input { width: 100%; height: 48px; border: 0; padding: 0; border-radius: 10px; background: none; }
.panel .row { display: flex; gap: 8px; margin-top: 12px; }
.panel button { flex: 1; padding: 12px; border-radius: 10px; border: 0; background: #2a3060; color: var(--text); font-size: 15px; }
.panel button.danger { background: #7f1d1d; }
.panel .gc { color: var(--muted); font-size: 13px; margin-top: 10px; }

/* number pad */
.padview { padding: 10px 12px; }
.admin.padmode { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow-y: auto; padding-bottom: 0; }
.admin.padmode .bar, .admin.padmode .tabs { flex: none; }
.admin.padmode .padview { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.admin.padmode .actions { position: static; transform: none; max-width: none; flex: none; width: auto; }
.entry { flex: none; display: flex; align-items: center; justify-content: center; position: relative; height: 64px; padding: 0 16px;
  background: var(--panel); border-radius: 14px; }
.typed { display: flex; align-items: center; justify-content: center; height: 100%; line-height: 1;
  font-size: 44px; font-weight: 800; letter-spacing: .05em; }
.typed:empty::before { content: "Type a number"; font-size: 18px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.flash { position: absolute; right: 12px; opacity: 0; transition: opacity .2s; padding: 6px 14px; border-radius: 999px; font-weight: 800; font-size: 18px;
  background: var(--col, #2a3060); color: var(--tc, #fff); }
.flash.show { opacity: 1; }
.cands { flex: none; display: flex; flex-wrap: wrap; justify-content: center; align-content: flex-start; gap: 6px; height: 86px; margin: 10px 0; }
.cands .chip { width: calc((100% - 30px) / 6); height: 40px; min-width: 0; padding: 0; justify-content: center; font-size: 16px; border: 0; font-family: inherit; }
.pad { flex: 1; min-height: 240px; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(4, 1fr); gap: 8px; }
.pad button { height: 100%; border: 0; border-radius: 16px; background: var(--panel);
  color: var(--text); font-size: clamp(30px, 5.5vh, 46px); font-weight: 700; font-family: inherit; }
.pad button:active { background: #2a3060; }
.pad button:disabled { opacity: .2; }
.pad .back { background: #2a3060; font-size: clamp(24px, 4vh, 34px); }
.pad .enter { background: #4f46e5; font-size: clamp(20px, 3.4vh, 30px); }

.board.vertical { padding: 10px 12px; gap: 6px; }
.board.vertical .cell { aspect-ratio: auto; height: 54px; font-size: 24px; border-radius: 12px; }
.board.vertical .cell.head { height: 46px; font-size: 26px; }
.board.vertical .cell.num { color: var(--text); border-bottom: 4px solid var(--col); }
.board.vertical .cell.num.called { color: var(--tc); }
.board.vertical .cell.num.latest { transform: none; outline: 3px solid #fff; outline-offset: -3px; }

.actions { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 640px;
  display: flex; gap: 10px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%); }
.actions button { flex: 1; padding: 16px 8px; border-radius: 14px; border: 0; font-size: 17px; font-weight: 700;
  background: #2a3060; color: var(--text); box-shadow: 0 4px 14px rgba(0,0,0,.4); font-family: inherit; }
.actions button.primary { background: #4f46e5; }

/* ---------- TV display: fills the whole screen ---------- */
.tv { height: 100vh; display: grid; grid-template-columns: 36vw 1fr; grid-template-rows: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 1.5vh 1.5vw; padding: 1.5vh 1.5vw; overflow: hidden; }
.tv .stage { display: flex; align-items: center; justify-content: center; min-height: 0; }
.tv .stage .ball { height: min(56vh, 34vw); font-size: min(28vh, 17vw); }
.tv .empty { font-size: 4vh; color: var(--muted); text-align: center; }

.tv .prev { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.tv .phead { display: flex; justify-content: space-between; align-items: center; height: 4vh; flex: none;
  color: var(--muted); font-size: 2.2vh; }
.tv .rlabel { font-weight: 800; letter-spacing: .14em; color: var(--text); font-size: 2.6vh; }
.tv .phead .meta { display: flex; gap: 1.5vw; align-items: center; }
.tv .phead button { background: none; border: 0; color: var(--muted); font-size: 2.6vh; opacity: .4; cursor: pointer; }
.tv .phead button:hover { opacity: 1; }
.tv .recent { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(2, 1fr);
  gap: 1.5vh 1.5vw; align-items: center; justify-items: center; min-height: 0; }
.tv .recent .ball { height: min(24vh, 13.2vw); font-size: min(12vh, 6.6vw);
  box-shadow: 0 0 0 .5vh rgba(255,255,255,.9), 0 1vh 2vh rgba(0,0,0,.5); }
.tv .rlabel small { font-size: 2.2vh; letter-spacing: .04em; color: var(--muted); font-weight: 600; margin-left: 1vw; }
.tv .norecent { grid-column: 1 / -1; color: var(--muted); font-size: 3vh; }

.tv .board { grid-column: 1 / -1; grid-template-rows: repeat(5, 1fr); gap: .8vh .5vw; min-height: 0; }
.tv .cell { aspect-ratio: auto; border-radius: 1vh; }
.tv .cell.num { font-size: min(5vh, 3vw); }
.tv .cell.head { font-size: min(6.2vh, 3.6vw); }
.tv .cell.num.called { box-shadow: inset 0 0 0 .2vh rgba(0,0,0,.25); }
.tv .cell.num.latest { transform: scale(1.06); }

@media (max-aspect-ratio: 1/1) {
  .tv { height: auto; min-height: 100vh; grid-template-columns: 1fr; grid-template-rows: auto; padding: 3vw; gap: 3vw; }
  .tv .stage .ball { height: 62vw; font-size: 31vw; }
  .tv .recent { grid-template-rows: auto; gap: 2vw; }
  .tv .recent .ball { height: 20vw; font-size: 10vw; }
  .tv .phead { height: auto; font-size: 3vw; } .tv .rlabel { font-size: 4vw; }
  .tv .board { grid-template-rows: none; } .tv .cell { padding: 1.2vw 0; }
  .tv .cell.num { font-size: 3vw; } .tv .cell.head { font-size: 3.6vw; }
}

/* ---------- landing ---------- */
.landing { max-width: 420px; margin: 12vh auto; padding: 0 20px; text-align: center; }
.landing a { display: block; margin: 14px 0; padding: 18px; border-radius: 12px; background: var(--panel);
  color: var(--text); text-decoration: none; font-size: 1.2em; font-weight: 600; }
.landing input { width: 100%; padding: 12px; border-radius: 10px; border: 0; font-size: 1em; text-align: center; margin-top: 8px; }
