/* ---------- Themes ---------- */
:root { --ca:#ff5a6e; --cb:#5b6cff; --cc:#f59e0b; --cd:#12b886; --good:#3ddc97; --bad:#ff5d6c; }
body[data-theme="aurora"] { --bg1:#07131f; --bg2:#1b1147; --bg3:#063b3f; --card:rgba(255,255,255,.09); --text:#fff; --muted:#b4c6e0; --accent:#8b5cf6; --accent2:#2dd4bf; --glow:rgba(45,212,191,.45); --btn-text:#fff; --title:linear-gradient(90deg,#fff,#7ef0e0 60%,#c4a8ff); }
body[data-theme="sunset"] { --bg1:#2a0a24; --bg2:#7a1f4d; --bg3:#c2410c; --card:rgba(255,255,255,.13); --text:#fff; --muted:#ffd9c7; --accent:#fb7185; --accent2:#fbbf24; --glow:rgba(251,113,133,.5); --btn-text:#2a0a24; --title:linear-gradient(90deg,#fff,#ffd29a 60%,#ff9bb0); }
body[data-theme="gold"]   { --bg1:#0b0b10; --bg2:#1a1722; --bg3:#12100c; --card:rgba(255,255,255,.07); --text:#f8f5ec; --muted:#bdb49b; --accent:#d4a73a; --accent2:#f3d98b; --glow:rgba(212,167,58,.4); --btn-text:#1a1305; --title:linear-gradient(90deg,#f3d98b,#fff 55%,#d4a73a); }
body[data-theme="ocean"]  { --bg1:#031a2e; --bg2:#073b63; --bg3:#0b6e8a; --card:rgba(255,255,255,.10); --text:#fff; --muted:#b9dcf0; --accent:#38bdf8; --accent2:#a7f3d0; --glow:rgba(56,189,248,.45); --btn-text:#032033; --title:linear-gradient(90deg,#fff,#a7f3d0 55%,#7dd3fc); }

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text);
  background: linear-gradient(135deg, var(--bg1), var(--bg2), var(--bg3), var(--bg1)); background-size: 300% 300%;
  animation: bgshift 18s ease-in-out infinite; overflow-x: hidden;
}
body[data-theme="gold"] { animation: none; background: linear-gradient(160deg, var(--bg1), var(--bg3)); }
body::before, body::after { content: ""; position: fixed; z-index: 0; width: 60vmax; height: 60vmax; border-radius: 50%; filter: blur(80px); opacity: .35; pointer-events: none; }
body::before { background: var(--accent); top: -25vmax; left: -20vmax; animation: float1 20s ease-in-out infinite; }
body::after  { background: var(--accent2); bottom: -30vmax; right: -20vmax; animation: float2 24s ease-in-out infinite; }
body[data-theme="gold"]::before, body[data-theme="gold"]::after { opacity: .12; animation: none; }
@keyframes bgshift { 0%,100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
@keyframes float1 { 50% { transform: translate(18vmax, 12vmax) scale(1.15); } }
@keyframes float2 { 50% { transform: translate(-16vmax, -10vmax) scale(1.1); } }

/* effects level */
body[data-fx="light"]::before, body[data-fx="light"]::after, body[data-fx="off"]::before, body[data-fx="off"]::after { animation: none; }
body[data-fx="light"], body[data-fx="off"] { animation: none; }
body[data-fx="off"] *, body[data-fx="off"] *::before, body[data-fx="off"] *::after { animation: none !important; transition: none !important; }

#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }
.hidden { display: none !important; }
.view { position: relative; z-index: 1; }
.card { background: var(--card); border: 1px solid rgba(255,255,255,.14); border-radius: 22px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); padding: 22px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.muted { color: var(--muted); }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
.btn { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: var(--btn-text, #fff); font-weight: 800; padding: 14px 26px; border-radius: 16px; font-size: 1.1rem; box-shadow: 0 8px 24px var(--glow); transition: transform .15s, filter .15s; }
.btn:hover { transform: translateY(-2px); filter: brightness(1.1); } .btn:active { transform: scale(.97); }
.btn.ghost { background: rgba(255,255,255,.14); box-shadow: none; color: var(--text); }
.btn.small { padding: 9px 16px; font-size: .95rem; border-radius: 12px; }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
input, select, textarea { font: inherit; color: #111; background: #fff; border: 2px solid transparent; border-radius: 12px; padding: 12px 14px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent2); }
.pop { animation: pop .45s cubic-bezier(.2,1.6,.4,1) both; }
@keyframes pop { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes shake { 10%,90% { transform: translateX(-3px); } 20%,80% { transform: translateX(6px); } 30%,50%,70% { transform: translateX(-10px); } 40%,60% { transform: translateX(10px); } }
@keyframes pulse { 50% { transform: scale(1.06); } }
@keyframes bounce { 0%,80%,100% { transform: translateY(0); } 40% { transform: translateY(-10px); } }
.dots span { display: inline-block; width: 10px; height: 10px; margin: 0 4px; border-radius: 50%; background: var(--accent2); animation: bounce 1.2s infinite; }
.dots span:nth-child(2) { animation-delay: .15s; } .dots span:nth-child(3) { animation-delay: .3s; }

.opt-a { --c: var(--ca); } .opt-b { --c: var(--cb); } .opt-c { --c: var(--cc); } .opt-d { --c: var(--cd); }

/* ---------- Player ---------- */
.player { max-width: 520px; margin: 0 auto; min-height: 100%; padding: calc(14px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; position: relative; z-index: 1; }
.player header { display: flex; justify-content: space-between; align-items: center; padding: 6px 4px 14px; }
.brand { font-weight: 900; letter-spacing: .5px; font-size: 1.2rem; }
.conn { font-size: .8rem; color: var(--muted); } .conn.bad { color: var(--bad); }
.player .view { flex: 1; display: flex; flex-direction: column; gap: 16px; justify-content: center; text-align: center; }
.player h1 { font-size: 2rem; line-height: 1.15; } .player h2 { font-size: 1.4rem; }
.big-num { font-size: 7rem; font-weight: 900; line-height: 1; text-shadow: 0 0 40px var(--glow); }
.timerbar { height: 12px; border-radius: 99px; background: rgba(255,255,255,.18); overflow: hidden; }
.timerbar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--accent2), var(--accent)); border-radius: 99px; }
.timerbar.low i { background: var(--bad); }
.qtext { font-size: 1.35rem; font-weight: 800; line-height: 1.3; }
.opts { display: grid; gap: 12px; }
.opt { display: flex; align-items: center; gap: 14px; text-align: left; background: var(--c); color: #fff; padding: 18px 16px; border-radius: 18px; font-size: 1.15rem; font-weight: 700; min-height: 74px; box-shadow: 0 6px 0 rgba(0,0,0,.28); transition: transform .12s, opacity .2s, box-shadow .12s; }
.opt:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,.28); }
.opt b { display: grid; place-items: center; min-width: 40px; height: 40px; border-radius: 12px; background: rgba(0,0,0,.25); font-size: 1.2rem; }
.opt.dim { opacity: .35; } .opt.picked { outline: 4px solid #fff; transform: scale(1.02); }
.opt:disabled { cursor: default; }
.result .icon { font-size: 4rem; } .result .delta { font-size: 4.5rem; font-weight: 900; line-height: 1; }
.result.good .delta, .good-t { color: var(--good); } .result.bad .delta, .bad-t { color: var(--bad); }
.result.good .card { box-shadow: 0 0 60px rgba(61,220,151,.45); } .result.bad .card { box-shadow: 0 0 60px rgba(255,93,108,.4); }
.result.shake .card { animation: shake .6s; }
.mini { display: grid; gap: 6px; text-align: left; }
.mini div { display: flex; gap: 10px; padding: 9px 12px; border-radius: 12px; background: rgba(255,255,255,.1); font-weight: 700; }
.mini div.me { background: rgba(255,255,255,.3); outline: 2px solid var(--accent2); }
.mini .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rankchip { display: inline-block; padding: 4px 12px; border-radius: 99px; background: rgba(255,255,255,.18); font-weight: 800; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #000c; padding: 10px 18px; border-radius: 99px; z-index: 60; }
.err { color: var(--bad); min-height: 1.3em; font-weight: 700; }
.joinform { display: grid; gap: 12px; }

/* ---------- Host ---------- */
.host { position: relative; z-index: 1; min-height: 100vh; padding: 3vh 4vw 11vh; display: flex; flex-direction: column; }
.host .view { flex: 1; display: flex; flex-direction: column; }
.host h1 { font-size: clamp(2.2rem, 6vw, 5rem); font-weight: 900; text-shadow: 0 0 40px var(--glow); }
.lobby-grid { flex: 1; display: grid; grid-template-columns: minmax(280px, 34%) 1fr; gap: 3vw; align-items: center; }
.qrcard { background: #fff; border-radius: 28px; padding: 18px; text-align: center; color: #111; box-shadow: 0 0 80px var(--glow); }
.qrcard canvas { width: 100%; height: auto; image-rendering: pixelated; display: block; }
.qrcard .url { font-weight: 900; font-size: clamp(1rem, 2vw, 1.8rem); margin-top: 8px; word-break: break-all; }
.cloud { display: flex; flex-wrap: wrap; gap: 10px; align-content: flex-start; max-height: 62vh; overflow: hidden; }
.bubble { padding: 8px 18px; border-radius: 99px; font-weight: 800; font-size: clamp(1rem, 2vw, 1.7rem); background: hsl(var(--h) 80% 50%); box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.topline { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 2vh; }
.chip { background: var(--card); padding: 8px 18px; border-radius: 99px; font-weight: 800; font-size: clamp(1rem, 1.6vw, 1.5rem); }
.hq { font-size: clamp(1.8rem, 4.2vw, 4rem); font-weight: 900; line-height: 1.15; text-align: center; flex: 1; display: grid; place-items: center; padding: 1vh 2vw; text-shadow: 0 4px 20px rgba(0,0,0,.3); }
.hopts { display: grid; grid-template-columns: 1fr 1fr; gap: 1.6vw; }
.hopt { position: relative; display: flex; align-items: center; gap: 1.4vw; background: var(--c); border-radius: 20px; padding: 2.4vh 1.8vw; font-size: clamp(1.1rem, 2.5vw, 2.4rem); font-weight: 800; min-height: 11vh; box-shadow: 0 8px 0 rgba(0,0,0,.28); overflow: hidden; transition: opacity .4s, transform .4s; }
.hopt b { display: grid; place-items: center; width: 2.2em; height: 2.2em; border-radius: 14px; background: rgba(0,0,0,.25); flex: none; }
.hopt .bar { position: absolute; left: 0; bottom: 0; height: 8px; background: rgba(255,255,255,.85); width: 0; transition: width 1s ease-out; }
.hopt .cnt { margin-left: auto; font-size: .8em; background: rgba(0,0,0,.3); padding: 2px 14px; border-radius: 99px; }
.hopt.dim { opacity: .28; transform: scale(.97); } .hopt.right { outline: 6px solid #fff; transform: scale(1.03); box-shadow: 0 0 60px rgba(255,255,255,.6); }
.ring { position: relative; width: clamp(80px, 11vw, 150px); aspect-ratio: 1; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; } .ring .bg { stroke: rgba(255,255,255,.18); } .ring .fg { stroke: var(--accent2); stroke-linecap: round; }
.ring.low .fg { stroke: var(--bad); } .ring.low { animation: pulse .5s infinite; }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(1.8rem, 4vw, 3.6rem); font-weight: 900; }
.overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(0,0,0,.55); backdrop-filter: blur(6px); }
.overlay .n { font-size: 28vmin; font-weight: 900; text-shadow: 0 0 80px var(--glow); }
.overlay .sm { font-size: 4vmin; font-weight: 800; text-align: center; }
.reveal-grid { flex: 1; display: grid; grid-template-columns: 1fr minmax(340px, 42%); gap: 3vw; align-items: start; }
.lb-title { font-size: clamp(1.4rem, 2.6vw, 2.4rem); font-weight: 900; margin-bottom: 1.2vh; }
.lb { position: relative; --rh: 56px; }
.lb .row { position: absolute; left: 0; right: 0; height: calc(var(--rh) - 8px); display: flex; align-items: center; gap: 14px; padding: 0 16px; border-radius: 14px; background: var(--card); border: 1px solid rgba(255,255,255,.14); font-weight: 800; font-size: clamp(1rem, 1.9vw, 1.8rem); transition: transform 1s cubic-bezier(.2,.9,.2,1), opacity .5s; }
.lb .row.r1 { background: linear-gradient(90deg, #ffd34d55, var(--card)); } .lb .row.r2 { background: linear-gradient(90deg, #cfd8e655, var(--card)); } .lb .row.r3 { background: linear-gradient(90deg, #e0955b55, var(--card)); }
.lb .rk { width: 2.2em; text-align: center; } .lb .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb .dl { font-size: .75em; padding: 2px 10px; border-radius: 99px; background: rgba(0,0,0,.3); } .lb .dl.p { color: var(--good); } .lb .dl.n { color: var(--bad); }
.lb .sc { min-width: 3.4em; text-align: right; font-variant-numeric: tabular-nums; }
.podium { flex: 1; display: flex; justify-content: center; align-items: flex-end; gap: 2vw; padding: 2vh 0; min-height: 46vh; }
.pcol { width: min(24vw, 280px); display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
.pcol .who { font-size: clamp(1.2rem, 2.6vw, 2.6rem); font-weight: 900; margin-bottom: 1vh; text-align: center; opacity: 0; } .pcol .pts { opacity: 0; font-weight: 800; font-size: clamp(1rem, 1.8vw, 1.8rem); margin-bottom: 1vh; }
.pcol .blk { width: 100%; height: 0; border-radius: 18px 18px 0 0; display: grid; place-items: start center; padding-top: 1.5vh; font-size: clamp(2rem, 5vw, 5rem); font-weight: 900; transition: height 1.4s cubic-bezier(.2,.9,.2,1); }
.pcol.p1 .blk { background: linear-gradient(#ffe27a, #e8a800); color: #5b3b00; } .pcol.p2 .blk { background: linear-gradient(#f1f5fa, #aab6c8); color: #33415a; } .pcol.p3 .blk { background: linear-gradient(#f0b27d, #b36b30); color: #4a2408; }
.pcol.show .who, .pcol.show .pts { opacity: 1; transition: opacity .6s .9s; }
.rest { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 16px; margin-top: 1vh; font-weight: 700; }
#bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; gap: 10px; justify-content: center; align-items: center; padding: 14px; background: linear-gradient(transparent, rgba(0,0,0,.55)); opacity: .55; transition: opacity .2s; flex-wrap: wrap; }
#bar:hover { opacity: 1; }
#bar.off { display: none; }
.gate { position: relative; z-index: 1; max-width: 420px; margin: 18vh auto 0; text-align: center; display: grid; gap: 14px; padding: 0 16px; }
dialog { margin: auto; border: 0; border-radius: 22px; padding: 24px; width: min(920px, 94vw); max-height: 92vh; overflow: auto; background: #151a33; color: #fff; z-index: 100; }
body[data-theme="gold"] dialog { background: #1a1722; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin-bottom: 14px; } .field { display: grid; gap: 6px; margin-bottom: 14px; } .field > label { font-weight: 700; color: var(--muted); }
.seg { display: flex; gap: 8px; flex-wrap: wrap; } .seg button { padding: 10px 16px; border-radius: 12px; background: rgba(255,255,255,.12); font-weight: 700; } .seg button.on { background: var(--accent); color: #fff; outline: 2px solid #fff; }
.qed { background: rgba(255,255,255,.07); border-radius: 16px; padding: 14px; margin-bottom: 12px; display: grid; gap: 8px; }
.qed .head { display: flex; gap: 8px; align-items: center; } .qed .head strong { flex: none; }
.qed .ans { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; } .qed .ans label { display: flex; gap: 8px; align-items: center; } .qed .ans input[type=radio] { width: 22px; height: 22px; flex: none; accent-color: #3ddc97; }
.qed .ans input[type=text] { padding: 9px 11px; } .qed .tm { width: 90px; flex: none; padding: 9px; }
.qed .mini-btn { background: rgba(255,255,255,.14); border-radius: 10px; padding: 7px 11px; font-weight: 700; } .qed .mini-btn.del { background: #ff5d6c55; }
.row-btns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
@media (max-width: 820px) { .lobby-grid, .reveal-grid { grid-template-columns: 1fr; } .hopts { grid-template-columns: 1fr; } .qed .ans { grid-template-columns: 1fr; } }
.hq.sm { flex: none; font-size: clamp(1.3rem, 2.6vw, 2.4rem); padding: 0 0 1vh; text-align: left; place-items: start; }
.lb { overflow: hidden; }
.lb .mv { font-size: .7em; font-weight: 800; min-width: 2.6em; } .lb .mv.u { color: var(--good); } .lb .mv.d { color: var(--bad); }
.cloud:empty::before { content: "Waiting for players…"; color: var(--muted); font-size: 1.6rem; font-weight: 700; }

/* ---------- Quiz Game style layer ---------- */
.host h1 { background: var(--title); -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: none; filter: drop-shadow(0 4px 28px var(--glow)); letter-spacing: -.5px; }
.brand { background: var(--title); -webkit-background-clip: text; background-clip: text; color: transparent; font-size: 1.3rem; }
.card { border-radius: 28px; border-color: rgba(255,255,255,.2); box-shadow: 0 14px 50px rgba(0,0,0,.3), inset 0 1px 0 rgba(255,255,255,.18); }
.opt, .hopt { background: linear-gradient(180deg, rgba(255,255,255,.24), rgba(255,255,255,0) 55%), var(--c); border: 1px solid rgba(255,255,255,.25); }
.opt b, .hopt b { background: rgba(255,255,255,.22); box-shadow: inset 0 -3px 0 rgba(0,0,0,.18); }
.bubble { background: linear-gradient(135deg, hsl(var(--h) 85% 58%), hsl(calc(var(--h) + 45) 85% 44%)); border: 1px solid rgba(255,255,255,.4); font-size: clamp(1.1rem, 2.4vw, 2.1rem); padding: 10px 22px; }
.chip { border: 1px solid rgba(255,255,255,.18); backdrop-filter: blur(8px); }
.lobby-grid { grid-template-columns: minmax(190px, 21%) 1fr; gap: 4vw; align-items: start; padding-top: 2vh; }
.qrcard { padding: 12px; border-radius: 24px; box-shadow: 0 0 0 6px rgba(255,255,255,.12), 0 0 70px var(--glow); }
.qrcard .url { font-size: clamp(.8rem, 1.3vw, 1.2rem); }
.tagline { font-size: clamp(1.1rem, 2vw, 1.8rem); font-weight: 700; color: var(--muted); margin-bottom: 2.5vh; }
.cloud { max-height: 66vh; }
.lb .row { backdrop-filter: blur(8px); border-radius: 18px; }
.lb .row.r1 { background: linear-gradient(90deg, rgba(255,211,77,.4), var(--card)); }
.btn { border-radius: 99px; }
.ring .fg { filter: drop-shadow(0 0 8px var(--glow)); }
