:root {
  --bg: #0d1020; --bg2: #151a33;
  --surface: rgba(255,255,255,.05); --surface-hi: rgba(255,255,255,.09);
  --text: #f2f3fa; --muted: #9aa0bf; --accent: #8fb0ff;
  --border: rgba(255,255,255,.10); --glow: rgba(110,120,255,.45);
  --pink: #ff3fa4; --lime: #8fe83a; --cyan: #27d3f0; --orange: #ff8a1f; --yellow: #ffe03a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.55; color: var(--text);
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(47,111,228,.35), transparent 60%),
    radial-gradient(800px 500px at 100% 0%, rgba(123,63,228,.30), transparent 60%),
    var(--bg);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.view { min-height: 100vh; min-height: 100dvh; }
.page { display: flex; align-items: center; justify-content: center; padding: 64px 16px 32px; position: relative; overflow: hidden; }

.back { position: fixed; top: 12px; left: 14px; z-index: 30; color: var(--accent); text-decoration: none; font-weight: 600; font-size: .92rem; padding: 6px 12px; border-radius: 999px; background: rgba(13,16,32,.6); }
.back:focus-visible, .btn:focus-visible, .mute:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.mute { position: fixed; top: 10px; right: 12px; z-index: 30; width: 44px; height: 44px; border-radius: 999px; border: 1px solid var(--border); background: rgba(13,16,32,.6); color: var(--text); font-size: 1.1rem; cursor: pointer; }
html.party .mute { top: 64px; }

.btn {
  font: inherit; font-weight: 700; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 10px 20px; min-height: 44px; cursor: pointer;
  transition: transform .18s ease, background .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.btn:hover, .btn:focus-visible { background: var(--surface-hi); border-color: rgba(143,176,255,.45); transform: translateY(-2px); box-shadow: 0 12px 30px -14px var(--glow); }
.btn.primary { background: linear-gradient(135deg, #8fd8ff, #a98bff); color: #0d1020; border: 0; }
.btn.big { font-size: 1.1rem; padding: 14px 28px; }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 22px; padding: 22px; }
.muted { color: var(--muted); }
h2 { margin: 0 0 12px; letter-spacing: -0.01em; }

/* ---------- Home ---------- */
.home-inner { position: relative; z-index: 1; max-width: 640px; text-align: center; }
.logo { margin: 0; line-height: .9; font-weight: 900; letter-spacing: -0.04em; font-size: clamp(3.4rem, 15vw, 7.5rem); display: flex; flex-direction: column; align-items: center; }
.logo span { display: inline-block; padding: 0 .08em; }
.logo .l1 { background: linear-gradient(100deg, var(--pink), var(--orange) 55%, var(--yellow)); -webkit-background-clip: text; background-clip: text; color: transparent; transform: rotate(-3deg); filter: drop-shadow(0 6px 0 rgba(0,0,0,.35)); }
.logo .l2 { background: linear-gradient(100deg, var(--cyan), var(--lime)); -webkit-background-clip: text; background-clip: text; color: transparent; transform: rotate(2deg) translateX(.3em); filter: drop-shadow(0 6px 0 rgba(0,0,0,.35)); }
.tag { font-size: 1.1rem; color: var(--muted); margin: 18px auto 26px; max-width: 30em; }
.home-buttons { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.how { margin-top: 30px; display: grid; gap: 10px; text-align: left; }
.how-step { display: flex; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 10px 14px; }
.how-step b { flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: #0d1020; background: linear-gradient(135deg, #8fd8ff, #a98bff); }
.how-step em { color: var(--yellow); font-style: normal; font-weight: 700; }
.splats i { position: absolute; border-radius: 50%; filter: blur(1px); opacity: .55; animation: drip 9s ease-in-out infinite alternate; }
.splats i:nth-child(1) { width: 260px; height: 240px; left: -60px; top: 12%; background: var(--pink); border-radius: 46% 54% 60% 40%; }
.splats i:nth-child(2) { width: 200px; height: 220px; right: -40px; top: 8%; background: var(--cyan); border-radius: 58% 42% 40% 60%; animation-delay: -3s; }
.splats i:nth-child(3) { width: 180px; height: 170px; right: 8%; bottom: -50px; background: var(--lime); border-radius: 40% 60% 52% 48%; animation-delay: -5s; }
.splats i:nth-child(4) { width: 140px; height: 150px; left: 10%; bottom: -30px; background: var(--orange); animation-delay: -1s; }
.splats i:nth-child(5) { width: 90px; height: 90px; left: 48%; top: 4%; background: var(--yellow); opacity: .35; animation-delay: -7s; }
@keyframes drip { to { transform: translateY(18px) scale(1.06) rotate(8deg); } }

/* ---------- Join ---------- */
.join-card { width: min(420px, 100%); display: grid; gap: 14px; }
.join-card label { display: grid; gap: 6px; font-weight: 600; color: var(--muted); }
.join-card input { font: inherit; font-size: 1.3rem; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--border); background: rgba(0,0,0,.25); color: var(--text); text-transform: none; }
#codeIn { text-transform: uppercase; letter-spacing: .3em; font-weight: 800; }
.err { color: #ff8a8a; margin: 0; min-height: 1.5em; }

/* ---------- Lobby ---------- */
.lobby-grid { display: grid; grid-template-columns: minmax(260px, 360px) minmax(300px, 560px); gap: 22px; width: min(960px, 100%); }
.qr-card { text-align: center; }
.qr-card img { width: 100%; max-width: 260px; aspect-ratio: 1; border-radius: 16px; background: #fff; padding: 8px; }
.code { font-size: 3.2rem; font-weight: 900; letter-spacing: .25em; margin: 8px 0 0; padding-left: .25em; color: var(--yellow); }
.note { color: #ffb38a; font-size: .9rem; }
.plist { list-style: none; margin: 0 0 16px; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; min-height: 60px; }
.plist li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 14px; background: rgba(0,0,0,.2); border: 1px solid var(--border); font-weight: 700; min-width: 0; animation: pop .3s ease; }
.plist li.off { opacity: .45; }
.plist .chip { flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid #fff; background-size: 14px 14px; }
.plist .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist .kind { margin-left: auto; font-size: .78rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.plist .empty { grid-column: 1 / -1; justify-content: center; color: var(--muted); font-weight: 500; border-style: dashed; }
.lobby-buttons { display: flex; flex-wrap: wrap; gap: 10px; }
.lobby-buttons #startBtn { margin-left: auto; }
.hint { color: var(--muted); font-size: .9rem; margin: 12px 0 0; }
@keyframes pop { from { transform: scale(.8); opacity: 0; } }

/* ---------- Play ---------- */
#play { position: fixed; inset: 0; display: flex; flex-direction: column; background: #0b0d1a; }
.hud { flex: none; height: clamp(44px, 7vh, 84px); display: flex; align-items: center; gap: 14px; padding: 6px 66px 6px 140px; }
html.party .hud { padding-right: 150px; }
.scorebar { flex: 1; display: flex; height: 62%; border-radius: 999px; overflow: hidden; background: rgba(255,255,255,.06); border: 1px solid var(--border); }
.seg { display: flex; align-items: center; justify-content: center; min-width: 0; overflow: hidden; white-space: nowrap; font-weight: 800; font-size: clamp(.7rem, 1.4vh, 1.2rem); color: #0d1020; transition: flex-grow .5s ease; background-size: 16px 16px; }
.seg.lead { box-shadow: inset 0 0 0 3px #ffd45e; }
.timer { flex: none; min-width: 3.6em; text-align: center; font-weight: 900; font-size: clamp(1.2rem, 4vh, 2.6rem); font-variant-numeric: tabular-nums; padding: 0 .4em; border-radius: 14px; background: rgba(255,255,255,.06); }
.timer.final { color: #fff; background: #e11d48; animation: throb .5s ease-in-out infinite alternate; }
@keyframes throb { to { transform: scale(1.08); } }
.stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; }
#cv { display: block; border-radius: 10px; box-shadow: 0 0 0 2px rgba(255,255,255,.06), 0 20px 60px -20px #000; }
.stage.final #cv { box-shadow: 0 0 0 3px rgba(225,29,72,.7), 0 0 60px -10px rgba(225,29,72,.6); }
.callout { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); pointer-events: none; font-weight: 900; font-size: clamp(2rem, 8vh, 6rem); letter-spacing: -0.02em; white-space: nowrap; color: #fff; text-shadow: 0 6px 0 rgba(0,0,0,.5), 0 0 30px rgba(255,255,255,.3); opacity: 0; }
.callout.show { animation: callout 1.4s ease-out; }
@keyframes callout { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.4) rotate(-6deg); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1) rotate(-3deg); } 70% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(-3deg); } 100% { opacity: 0; transform: translate(-50%, -60%) scale(1) rotate(-3deg); } }
.bigcount { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; font-weight: 900; font-size: clamp(5rem, 30vh, 18rem); color: #fff; text-shadow: 0 10px 0 rgba(0,0,0,.45); }
.bigcount span { animation: pop .5s ease; }

.results { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 50% 40%, var(--win, #8fb0ff) 0%, transparent 70%), rgba(8,10,22,.72); animation: flood .8s ease; overflow-y: auto; }
@keyframes flood { from { background-color: transparent; opacity: 0; } }
.results-card { width: min(720px, 100%); background: rgba(13,16,32,.92); border: 1px solid var(--border); border-radius: 26px; padding: 26px; box-shadow: 0 30px 80px -30px #000; }
.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: .14em; font-size: .8rem; font-weight: 700; color: var(--muted); }
#winTitle { font-size: clamp(1.8rem, 5vw, 3rem); font-weight: 900; margin: 4px 0 16px; }
.ranking { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 8px; }
.ranking li { display: grid; grid-template-columns: 2.2em 28px 1fr auto; align-items: center; gap: 12px; padding: 8px 14px; border-radius: 14px; background: rgba(255,255,255,.05); font-weight: 700; animation: pop .4s ease backwards; }
.ranking .chip { width: 28px; height: 28px; border-radius: 50%; border: 2px solid #fff; background-size: 14px 14px; }
.ranking .pl { color: var(--muted); }
.ranking li:first-child { background: rgba(255,212,94,.14); }
.ranking .pct { font-variant-numeric: tabular-nums; }
.awards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-bottom: 18px; }
.award { padding: 10px 12px; border-radius: 14px; background: rgba(255,255,255,.05); border: 1px solid var(--border); }
.award b { display: block; font-size: .78rem; text-transform: uppercase; letter-spacing: .1em; color: var(--yellow); }
.results-buttons { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Phone ---------- */
#phone { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--crew, #333) ; color: var(--ink, #0d1020); user-select: none; -webkit-user-select: none; touch-action: none; }
#phone::before { content: ""; position: absolute; inset: 0; background-image: var(--pat, none); background-size: 44px 44px; pointer-events: none; }
.pad { position: relative; flex: 2; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 60px 18px 18px; touch-action: none; }
.ph-top { position: absolute; top: 58px; left: 0; right: 0; }
.ph-name { font-size: 1.6rem; font-weight: 900; letter-spacing: -0.02em; }
.ph-crew { font-weight: 700; opacity: .75; }
.ph-status { font-size: clamp(1.6rem, 8vw, 2.6rem); font-weight: 900; line-height: 1.1; letter-spacing: -0.02em; text-shadow: 0 2px 0 rgba(255,255,255,.15); }
.ph-sub { font-weight: 700; opacity: .8; margin-top: 6px; min-height: 1.5em; }
.ph-hint { position: absolute; bottom: 14px; left: 0; right: 0; font-weight: 600; opacity: .65; font-size: .95rem; }
.ph-start { margin-top: 18px; position: relative; z-index: 2; }
.ph-arrow { position: absolute; inset: 0; display: grid; place-items: center; font-size: 9rem; font-weight: 900; opacity: 0; pointer-events: none; }
.ph-arrow.show { animation: arrow .35s ease-out; }
@keyframes arrow { 0% { opacity: .7; transform: scale(.8); } 100% { opacity: 0; transform: scale(1.3); } }
#phone.danger .pad { animation: danger .4s ease-in-out infinite alternate; }
@keyframes danger { to { box-shadow: inset 0 0 0 14px #e11d48; } }
#phone.dead { filter: grayscale(.85) brightness(.7); }
.can { position: relative; flex: 1; margin: 0 12px 12px; border-radius: 26px; border: 3px solid rgba(0,0,0,.25); background: rgba(13,16,32,.82); color: var(--text); font: inherit; font-weight: 800; font-size: 1.05rem; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
.can:disabled { opacity: .55; }
.can-icon { font-size: 2.4rem; filter: grayscale(1); }

/* ---------- Phone width ---------- */
@media (max-width: 760px) {
  .lobby-grid { grid-template-columns: 1fr; }
  .plist { grid-template-columns: 1fr; }
  .hud { padding-left: 120px; }
}

/* ---------- TV ---------- */
html.tv body { font-size: 22px; }
html.tv .page { padding: 5vh 5vw; }
html.tv .btn { min-height: 56px; }
html.tv .btn:focus, html.tv .back:focus { outline: 4px solid #fff; outline-offset: 4px; background: var(--surface-hi); transform: scale(1.05); }
html.tv .btn.primary:focus { background: linear-gradient(135deg, #b6e6ff, #c4adff); }
html.tv .hud { padding: 1.5vh calc(5vw + 60px) 0 calc(5vw + 150px); height: 9vh; }
html.tv .stage { padding: 1vh 5vw 4vh; }
html.tv .lobby-grid { width: min(1500px, 100%); grid-template-columns: 480px 1fr; }
html.tv .qr-card img { max-width: 340px; }
html.tv .code { font-size: 5rem; }
