:root {
  --bg: #f5f3ff;
  --ink: #1e1b4b;
  --muted: #6b6894;
  --card: #fff;
  --line: #e4e1f7;
  --brand: #4f46e5;
  --brand-2: #3730a3;
  --hot: #f43f5e;
  --gold: #fbbf24;
  --ok: #10b981;
  --B: #3b82f6; --I: #ef4444; --N: #8b5cf6; --G: #10b981; --O: #f59e0b;
  --r: 16px;
  --surface: #fff;
  --soft: #f1f0fb;
  --soft-2: #f7f6fd;
  --cell: #e9e6fa;
  --cell-line: #bdb7e6;
  --top: #1e1b4b;
  --hot-soft: #fff1f2;
  --hot-ring: #ffe4e6;
  --hot-line: #fecdd3;
  --warn-soft: #fef3c7;
  --warn-ink: #92400e;
  --free-soft: #fde68a;
  --sum-a: #312e81; --sum-b: #1e1b4b;
  color-scheme: light;
  font-family: 'Outfit', system-ui, sans-serif;
  color: var(--ink);
}
/* Dark theme (default) */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0d24;
  --card: #1a1838;
  --surface: #221f45;
  --soft: #2a2752;
  --soft-2: #24214a;
  --cell: #2a2754;
  --cell-line: #5a5596;
  --line: #3a3670;
  --ink: #ecebff;
  --muted: #a9a6d6;
  --brand: #6366f1;
  --brand-2: #4f46e5;
  --top: #0a0819;
  --hot-soft: #3a1426;
  --hot-ring: #5c1a33;
  --hot-line: #7a2a43;
  --warn-soft: #3d2e0a;
  --warn-ink: #fcd34d;
  --free-soft: #7a6420;
  --sum-a: #2b2870; --sum-b: #151236;
}
:root[data-theme="dark"] .card { box-shadow: 0 6px 20px rgba(0, 0, 0, .35); }
:root[data-theme="dark"] .backdrop { background: rgba(0, 0, 0, .65); }
* { box-sizing: border-box; }
input, textarea, select { background: var(--surface); color: var(--ink); }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }
h3 { margin: 0; font-size: 1.1rem; }
button { font: inherit; cursor: pointer; }
input { font: inherit; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* top bar */
.theme-btn { background: rgba(255,255,255,.12); border: 0; color: #fff; width: 2.4rem; height: 2.4rem; border-radius: 50%; font-size: 1.1rem; flex: none; }
.theme-btn:hover { background: rgba(255,255,255,.22); }
.top { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: .8rem; padding: .6rem 1rem; background: var(--top); color: #fff; }
.brand { display: flex; align-items: center; gap: .5rem; font-size: 1.25rem; font-weight: 600; }
.brand b { font-weight: 900; color: var(--gold); }
.logo { width: 2rem; height: 2rem; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff 0 18%, var(--hot) 19%); display: grid; place-items: center; font-weight: 900; color: #1e1b4b; font-size: .95rem; }
.game-pill { margin-left: auto; background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 999px; padding: .4rem .9rem; font-weight: 700; max-width: 40vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.last { min-width: 3.2rem; height: 3.2rem; border-radius: 50%; display: grid; place-items: center; font-weight: 900; font-size: 1.05rem; line-height: 1; text-align: center; background: #312e81; color: #a5b4fc; }
.last.has { background: radial-gradient(circle at 35% 30%, #fff 0 30%, var(--c, var(--brand)) 31%); color: #1e1b4b; box-shadow: 0 0 0 3px rgba(255,255,255,.2); }
.last small { display: block; font-size: .65rem; }
.last.pop { animation: pop .35s; }
@keyframes pop { 50% { transform: scale(1.25); } }

.tabs { position: sticky; top: 4.4rem; z-index: 25; display: flex; gap: .3rem; padding: .5rem 1rem; background: var(--bg); }
.tabs button { flex: 1; max-width: 220px; border: 2px solid var(--line); background: var(--surface); border-radius: 999px; padding: .55rem; font-weight: 800; color: var(--muted); }
.tabs button.on { background: var(--brand); border-color: var(--brand); color: #fff; }

main { width: min(1300px, 100%); margin: 0 auto; padding: 0 1rem 6rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 1rem; box-shadow: 0 6px 20px rgba(30, 27, 75, .06); margin-bottom: 1rem; }

.btn { border: 0; border-radius: 12px; padding: .65rem 1.1rem; font-weight: 800; background: var(--brand); color: #fff; }
.btn:hover { background: var(--brand-2); }
.btn.ghost { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 2px var(--line); }
.btn.ghost:hover { box-shadow: inset 0 0 0 2px var(--brand); }
.btn.danger { background: var(--surface); color: var(--hot); box-shadow: inset 0 0 0 2px var(--hot-line); }
.btn.small { padding: .4rem .75rem; font-size: .88rem; border-radius: 10px; }
.btn.on { background: var(--hot); color: #fff; box-shadow: none; }

/* games view */
.search-row { display: flex; gap: .5rem; margin-bottom: .6rem; }
.search-row input { flex: 1; padding: .8rem 1rem; border-radius: 14px; border: 2px solid var(--line); font-size: 1.05rem; background: var(--surface); }
.search-row input:focus { outline: none; border-color: var(--brand); }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .4rem; }
.chip { border: 2px solid var(--line); background: var(--surface); border-radius: 999px; padding: .3rem .8rem; font-weight: 700; color: var(--muted); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; }
.ptile { background: var(--surface); border: 2px solid var(--line); border-radius: 14px; padding: .6rem; text-align: left; display: flex; flex-direction: column; gap: .4rem; }
.ptile:hover { border-color: var(--brand); transform: translateY(-2px); }
.ptile.active { border-color: var(--hot); box-shadow: 0 0 0 3px var(--hot-ring); }
.ptile b { font-size: .92rem; line-height: 1.15; }
.ptile span { font-size: .78rem; color: var(--muted); }

.mini { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; aspect-ratio: 1; width: 100%; }
.mini i { background: var(--cell); border-radius: 3px; box-shadow: inset 0 0 0 1px var(--cell-line); }
.mini i.on { background: var(--brand); }
.mini i.free { background: var(--free-soft); }
.mini i.free.on { background: var(--gold); }
.mini.big { max-width: 260px; gap: 4px; margin: 0 auto; }
.mini.big i { border-radius: 6px; box-shadow: inset 0 0 0 2px var(--cell-line); }
.mini.edit i { cursor: pointer; transition: transform .08s; }
.mini.edit i:hover { box-shadow: inset 0 0 0 3px var(--brand); transform: scale(1.04); }
.mini i.on { box-shadow: none; }

.lineup h3 { margin-bottom: .5rem; }
.lineup .games { display: flex; gap: .4rem; flex-wrap: wrap; }
.lineup .g { display: flex; align-items: center; gap: .4rem; border: 2px solid var(--line); background: var(--surface); border-radius: 12px; padding: .3rem .4rem .3rem .3rem; font-weight: 700; font-size: .9rem; }
.lineup .g .mini { width: 26px; gap: 1px; }
.lineup .g.on { border-color: var(--hot); background: var(--hot-soft); }
.lineup .g .rm { border: 0; background: none; color: var(--muted); padding: 0 .2rem; }

/* play view */
.play { display: grid; grid-template-columns: minmax(320px, 440px) minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 900px) { .play { grid-template-columns: minmax(0, 1fr); } }
.current { display: flex; gap: .8rem; align-items: center; margin-bottom: .8rem; }
.current .mini { width: 64px; flex: none; }
.current b { font-size: 1.15rem; display: block; }
.entry { display: flex; gap: .5rem; margin-bottom: .6rem; }
.entry input { flex: 1; min-width: 0; font-size: 1.5rem; font-weight: 800; padding: .55rem .8rem; border-radius: 14px; border: 3px solid var(--line); text-transform: uppercase; }
.entry input::placeholder { text-transform: none; font-size: 1rem; font-weight: 600; }
.entry input:focus { outline: none; border-color: var(--brand); }
.entry .btn { font-size: 1.1rem; }
@media (max-width: 900px) {
  .entry { position: sticky; top: 7.6rem; z-index: 5; background: var(--card); padding: .3rem 0; }
}
.recent { display: flex; gap: .35rem; margin-top: .8rem; flex-wrap: wrap; }
.ball { width: 2.4rem; height: 2.4rem; border-radius: 50%; display: grid; place-items: center; font-weight: 900; font-size: .8rem; line-height: 1; background: radial-gradient(circle at 35% 30%, #fff 0 35%, var(--c) 36%); color: #1e1b4b; }
.mic-log { margin-top: .6rem; background: var(--soft); border-radius: 10px; padding: .5rem .7rem; font-size: .85rem; color: var(--muted); max-height: 5.5rem; overflow: auto; }

.board { display: grid; grid-template-columns: 1.7rem repeat(15, minmax(0, 1fr)); gap: 2px; margin-top: .6rem; }
.board .L { font-weight: 900; color: #fff; border-radius: 6px; display: grid; place-items: center; }
.board button { aspect-ratio: 1; border: 0; border-radius: 6px; background: var(--soft); font-weight: 700; font-size: clamp(.55rem, 1.4vw, .8rem); padding: 0; color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
.board button.on { box-shadow: none; }
.board button.on { background: var(--c); color: #fff; }
.board button.just { box-shadow: 0 0 0 2px var(--ink); }
@media (max-width: 900px) { .board button { font-size: clamp(.6rem, 2.6vw, .85rem); } }

.summary { background: linear-gradient(135deg, var(--sum-a), var(--sum-b)); color: #fff; border: 0; }
.summary .big { font-size: 1.5rem; font-weight: 900; }
.summary .need { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .5rem; }

.summary.win { background: linear-gradient(135deg, #be123c, #f43f5e); animation: glow 1s infinite alternate; }
@keyframes glow { to { box-shadow: 0 0 30px rgba(244, 63, 94, .7); } }

.cgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(230px, 100%), 1fr)); gap: .8rem; }
.bcard { background: var(--surface); border: 2px solid var(--line); border-radius: 16px; padding: .6rem; }
.bcard.win { border-color: var(--hot); box-shadow: 0 0 0 4px var(--hot-ring); }
.bcard.close1 { border-color: var(--gold); }
.bcard .head { display: flex; align-items: center; gap: .4rem; margin-bottom: .4rem; }
.bcard .head b { flex: 1; font-size: .95rem; }
.bcard .status { font-size: .8rem; font-weight: 800; border-radius: 999px; padding: .15rem .55rem; background: var(--soft); color: var(--muted); }
.bcard.win .status { background: var(--hot); color: #fff; }
.bcard.close1 .status { background: var(--warn-soft); color: var(--warn-ink); }
.bgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px; }
.bgrid .h { text-align: center; font-weight: 900; color: #fff; border-radius: 6px; padding: .15rem 0; font-size: .85rem; }
.bgrid .c { aspect-ratio: 1; display: grid; place-items: center; border-radius: 8px; background: var(--soft-2); font-weight: 800; font-size: 1rem; position: relative; box-shadow: inset 0 0 0 1px var(--line); }
.bgrid .c.m { background: var(--c); color: #fff; }
.bgrid .c.free { background: var(--gold); color: #1e1b4b; font-size: .65rem; }
.bgrid .c.target { box-shadow: inset 0 0 0 3px var(--hot); }
.bgrid .c.target.m { box-shadow: inset 0 0 0 3px rgba(255,255,255,.7); }
.bcard .needs { font-size: .8rem; color: var(--muted); margin-top: .35rem; min-height: 1.1em; }
.icon-btn { border: 0; background: none; padding: .15rem .3rem; border-radius: 8px; color: var(--muted); }
.icon-btn:hover { background: var(--soft); }

/* modal */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 1rem; }
.modal[hidden] { display: none; }
.backdrop { position: absolute; inset: 0; background: rgba(30, 27, 75, .55); }
.sheet { position: relative; background: var(--surface); border-radius: 20px; width: min(640px, 100%); max-height: 92vh; overflow: auto; padding: 1.3rem; }
.sheet .x { position: absolute; top: .7rem; right: .7rem; border: 0; background: var(--soft); width: 2rem; height: 2rem; border-radius: 50%; }
.sheet h2 { margin: 0 2rem .4rem 0; }
.cardentry { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; max-width: 360px; margin: .6rem auto; }
.cardentry .h { text-align: center; font-weight: 900; color: #fff; border-radius: 6px; padding: .2rem 0; }
.cardentry input { width: 100%; text-align: center; font-size: 1.2rem; font-weight: 800; padding: .5rem 0; border-radius: 8px; border: 2px solid var(--line); }
.cardentry input:focus { outline: none; border-color: var(--brand); }
.cardentry input.bad { border-color: var(--hot); background: var(--hot-soft); }
.cardentry .free { display: grid; place-items: center; background: var(--gold); border-radius: 8px; font-weight: 900; font-size: .8rem; }
textarea { width: 100%; font: inherit; font-size: 1.05rem; padding: .7rem; border-radius: 12px; border: 2px solid var(--line); min-height: 110px; }
.field { width: 100%; padding: .6rem .8rem; border-radius: 12px; border: 2px solid var(--line); font-size: 1rem; margin: .3rem 0 .6rem; }
.seg { display: flex; background: var(--soft); border-radius: 999px; padding: 3px; margin: .4rem 0 .6rem; }
.seg button { flex: 1; border: 0; background: none; border-radius: 999px; padding: .45rem; font-weight: 800; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 2px 6px rgba(0,0,0,.08); }
.err { color: var(--hot); font-weight: 700; min-height: 1.2em; }
.variant-nav { display: flex; align-items: center; justify-content: center; gap: .8rem; margin: .6rem 0; font-weight: 700; }

.toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); z-index: 80; background: var(--top); color: #fff; padding: .7rem 1.2rem; border-radius: 999px; font-weight: 700; box-shadow: 0 10px 30px rgba(0,0,0,.25); max-width: 92vw; }
.toast.bad { background: var(--hot); }
.bingo-flash { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; font-size: clamp(4rem, 18vw, 12rem); font-weight: 900; color: #fff; background: rgba(244, 63, 94, .85); pointer-events: none; animation: flash 1.8s forwards; letter-spacing: .05em; }
.bingo-flash[hidden], .toast[hidden] { display: none; }
@keyframes flash { 0% { opacity: 0; transform: scale(.6); } 15% { opacity: 1; transform: scale(1.05); } 80% { opacity: 1; } 100% { opacity: 0; } }
