:root {
  --bg: #0f1115; --bg2: #171a21; --card: #1e222b; --line: #2b303b;
  --text: #f2f4f8; --muted: #9aa3b2; --accent: #ffd23f; --accent2: #ff4f8b;
  --ok: #22c55e; --bad: #ef4444; --team: #ffd23f;
  --r: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100dvh; padding-bottom: calc(76px + env(safe-area-inset-bottom)); overscroll-behavior-y: contain; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
input { font: inherit; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.15; }
p { line-height: 1.45; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.hidden { display: none !important; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 20; background: rgba(15,17,21,.92); backdrop-filter: blur(10px);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--line);
}
.top .team-pill { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--card); border: 2px solid var(--team); font-weight: 700; }
.top .score { font-size: 1.3rem; font-weight: 800; color: var(--team); margin-left: auto; text-align: right; line-height: 1; }
.top .score small { display: block; font-size: .7rem; color: var(--muted); font-weight: 500; }
.top .clock { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .85rem; }

main { padding: 14px 14px 24px; max-width: 640px; margin: 0 auto; }

/* Bottom nav */
nav.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; background: var(--bg2);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs button { flex: 1; padding: 9px 2px 10px; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .72rem; color: var(--muted); position: relative; }
nav.tabs button .i { font-size: 1.45rem; }
nav.tabs button.on { color: var(--accent); }
nav.tabs .dot { position: absolute; top: 6px; right: calc(50% - 18px); width: 9px; height: 9px; border-radius: 50%; background: var(--accent2); }

/* Cards */
.card { background: var(--card); border-radius: var(--r); padding: 14px; margin-bottom: 10px; border: 1px solid var(--line); }
.hint { background: #1b2433; border: 1px dashed #3a4a66; color: #b8c7e0; border-radius: 12px; padding: 10px 12px; font-size: .85rem; margin-bottom: 12px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; margin: 0 -14px 4px; padding-left: 14px; padding-right: 14px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { white-space: nowrap; padding: 8px 14px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-size: .9rem; }
.chip.on { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 700; }

.ch { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; margin-bottom: 10px; }
.ch .e { font-size: 1.9rem; width: 44px; text-align: center; flex-shrink: 0; }
.ch .t { flex: 1; min-width: 0; }
.ch .t b { display: block; font-size: 1.02rem; }
.ch .t span { font-size: .8rem; color: var(--muted); }
.ch .p { font-weight: 800; color: var(--accent); white-space: nowrap; }
.ch.done { opacity: .55; }
.ch.done .p { color: var(--ok); }
.ch.blitz { border: 2px solid var(--accent2); background: linear-gradient(135deg, #3a1530, #1e222b); }
.badge { display: inline-block; font-size: .7rem; padding: 2px 7px; border-radius: 999px; background: #2a3040; color: #c9d1df; margin-right: 4px; margin-top: 3px; }

.blitzbar { display: block; width: 100%; text-align: left; background: linear-gradient(90deg, var(--accent2), #ff8a3d); color: #fff; border-radius: var(--r); padding: 12px 14px; margin-bottom: 12px; font-weight: 700; animation: pulse 1.4s infinite; }
.blitzbar small { display: block; font-weight: 500; opacity: .9; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,79,139,.6); } 50% { box-shadow: 0 0 0 8px rgba(255,79,139,0); } }

/* Buttons */
.btn { display: block; width: 100%; padding: 15px; border-radius: 14px; background: var(--accent); color: #111; font-weight: 800; font-size: 1.05rem; margin-top: 10px; }
.btn.sec { background: #2a3040; color: var(--text); font-weight: 600; }
.btn.danger { background: #3b1d22; color: #ffb4b4; font-weight: 600; }
.btn.big { padding: 20px; font-size: 1.25rem; }
.btn:disabled { opacity: .45; }

/* Forms */
.field { width: 100%; padding: 15px; border-radius: 14px; border: 2px solid var(--line); background: var(--bg2); color: var(--text); font-size: 1.1rem; }
.field:focus { outline: none; border-color: var(--accent); }
.teamsel { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 10px; margin-top: 10px; }
.teamsel button { padding: 16px 10px; border-radius: 14px; background: var(--card); border: 3px solid var(--line); text-align: center; }
.teamsel button .em { font-size: 2.2rem; display: block; }
.teamsel button.on { border-color: var(--tc); background: color-mix(in srgb, var(--tc) 18%, var(--card)); }
.teamsel .mem { font-size: .75rem; color: var(--muted); display: block; margin-top: 4px; min-height: 1em; }

/* Level select */
.levels { display: grid; gap: 8px; margin: 10px 0; }
.levels button { display: flex; justify-content: space-between; align-items: center; padding: 14px; border-radius: 12px; background: var(--bg2); border: 2px solid var(--line); text-align: left; }
.levels button.on { border-color: var(--accent); background: #2b2a1a; }
.levels button b { color: var(--accent); }

/* Sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { background: var(--bg2); width: 100%; max-width: 640px; max-height: 92dvh; overflow-y: auto; border-radius: 22px 22px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); animation: up .2s ease-out; }
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: -6px auto 12px; }
.sheet .bigemoji { font-size: 3rem; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* Stopwatch */
.sw { text-align: center; background: var(--card); border-radius: var(--r); padding: 14px; margin: 10px 0; }
.sw .disp { font-size: 3rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
.sw .row { display: flex; gap: 8px; }
.sw .row .btn { margin-top: 6px; }

/* Photo */
.photo-pick { display: flex; align-items: center; justify-content: center; gap: 8px; border: 2px dashed var(--line); border-radius: 14px; padding: 16px; color: var(--muted); margin: 10px 0; min-height: 70px; }
.photo-pick img { max-width: 100%; max-height: 220px; border-radius: 10px; }
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.gallery button { padding: 0; aspect-ratio: 1; overflow: hidden; border-radius: 6px; background: var(--card); position: relative; }
.gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery .tb { position: absolute; left: 4px; bottom: 4px; font-size: .9rem; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.95); z-index: 60; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 80dvh; border-radius: 10px; }
.lightbox p { text-align: center; }

/* Scoreboard */
.sb-team { margin-bottom: 14px; }
.sb-row { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.sb-row .n { flex: 1; }
.sb-row .v { font-size: 1.5rem; }
.bar { height: 12px; border-radius: 6px; background: var(--bg2); overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; border-radius: 6px; transition: width .6s; }
.breakdown { font-size: .78rem; color: var(--muted); margin-top: 5px; }
.lead { font-size: 1.4rem; }

/* Quiz */
.q .opts { display: grid; gap: 8px; margin-top: 8px; }
.q .opts button { padding: 13px; border-radius: 12px; background: var(--bg2); border: 2px solid var(--line); text-align: left; }
.q .opts button.right { border-color: var(--ok); background: #143222; }
.q .opts button.wrong { border-color: var(--bad); background: #3a1717; }

/* Mission */
.mission { text-align: center; padding: 26px 18px; background: linear-gradient(160deg, #241a3a, #1e222b); border: 1px solid #3c2d63; }
.mission .secret { font-size: 1.25rem; font-weight: 700; margin: 14px 0; line-height: 1.4; }
.mission .cover { font-size: 4rem; }

/* Lobby / hero */
.hero { text-align: center; padding: 30px 10px 10px; }
.hero .logo { font-size: 4rem; }
.hero h1 { font-size: 2.1rem; background: linear-gradient(90deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.rules li { margin-bottom: 6px; line-height: 1.4; }

/* Toast */
.toasts { position: fixed; bottom: calc(84px + env(safe-area-inset-bottom));  left: 0; right: 0; z-index: 70; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { background: #fff; color: #111; padding: 10px 16px; border-radius: 999px; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.4); animation: up .2s; max-width: 92%; text-align: center; }
.toast.err { background: var(--bad); color: #fff; }
.offline { position: fixed; bottom: calc(70px + env(safe-area-inset-bottom)); left: 10px; right: 10px; z-index: 25; background: #3b2f10; color: #ffe08a; border-radius: 12px; padding: 8px 12px; font-size: .85rem; text-align: center; }

/* Finale */
.finale-hero { text-align: center; padding: 20px 6px; }
.finale-hero .trophy { font-size: 5rem; animation: bounce 1.2s infinite; }
@keyframes bounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
.msg { white-space: pre-line; font-size: 1.08rem; line-height: 1.55; }
.video { width: 100%; aspect-ratio: 16/9; border: 0; border-radius: 12px; }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 80; }

/* Countdown */
.countdown { text-align: center; background: linear-gradient(135deg, #2b2410, #2a1424); border: 1px solid #4a3a1a; border-radius: var(--r); padding: 14px 10px; margin-bottom: 12px; }
.cd-label { color: var(--muted); font-size: .85rem; margin-bottom: 8px; }
.countdown .cd-label:only-child { color: var(--accent); font-size: 1.15rem; font-weight: 800; margin: 0; }
.cd-row { display: flex; justify-content: center; gap: 8px; }
.cd-box { background: var(--bg); border-radius: 12px; padding: 8px 6px; min-width: 62px; }
.cd-box b { display: block; font-size: 1.8rem; font-variant-numeric: tabular-nums; color: var(--accent); line-height: 1.1; }
.cd-box span { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

/* Videos & spectator feed */
.gallery video { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.play { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 1.6rem; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,.7); pointer-events: none; }
.lightbox video { max-width: 100%; max-height: 75dvh; border-radius: 10px; background: #000; }
.feed-item { display: flex; gap: 10px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px; margin-bottom: 8px; font-size: .92rem; line-height: 1.35; }
.feed-txt { flex: 1; min-width: 0; }
.feed-emoji { width: 52px; height: 52px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 1.8rem; background: var(--bg2); border-radius: 10px; }
.feed-thumb { width: 52px; height: 52px; flex-shrink: 0; padding: 0; border-radius: 10px; overflow: hidden; position: relative; background: var(--bg2); }
.feed-thumb img, .feed-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.upbar { position: fixed; left: 10px; right: 10px; top: calc(66px + env(safe-area-inset-top)); z-index: 75; background: #1b2433; border: 1px solid #3a4a66; border-radius: 14px; padding: 10px 12px; font-size: .9rem; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
