:root {
  --bg: #140a2e;
  --bg2: #1f1147;
  --bg-card: #271a52;
  --line: #3d2f6b;
  --ink: #f2eefe;
  --ink-dim: #b3a8d6;
  --accent: #ffd23f;     /* show gold */
  --accent2: #ff4d9d;    /* hot pink */
  --ok: #36b37e;
  --danger: #e8503a;
  --a0: #e8503a; --a1: #2b7fff; --a2: #f0a921; --a3: #36b37e;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; color: var(--ink); -webkit-font-smoothing: antialiased; overscroll-behavior: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; font-size: 17px; line-height: 1.45;
  background: radial-gradient(1200px 800px at 50% -10%, var(--bg2), var(--bg)) fixed; }
#app { min-height: 100%; }
h1,h2,h3 { font-family: "Futura", "Trebuchet MS", system-ui, sans-serif; letter-spacing: .01em; }
h2 { font-size: 1.5rem; margin: 0 0 .6rem; }
.muted { color: var(--ink-dim); }
.center { text-align: center; }
[hidden] { display: none !important; }
.screen { min-height: 100vh; min-height: 100dvh; }

.text-input { width: 100%; padding: 14px 16px; font-size: 17px; color: var(--ink); background: rgba(0,0,0,.25); border: 1px solid var(--line); border-radius: var(--radius); outline: none; margin-bottom: 14px; }
.text-input:focus { border-color: var(--accent); }
.code-input { text-transform: uppercase; letter-spacing: .5em; text-align: center; font-size: 1.6rem; font-weight: 800; }
.field-label { display: block; font-size: .85rem; color: var(--ink-dim); margin: 0 0 6px 2px; }
.btn { width: 100%; padding: 16px; font-size: 17px; font-weight: 800; border: none; border-radius: var(--radius); cursor: pointer; color: #2a1500; transition: transform .06s ease, filter .2s; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; }
.btn-primary { background: linear-gradient(180deg, #ffe06b, var(--accent)); box-shadow: 0 6px 0 #b9962a, 0 10px 20px rgba(255,210,63,.25); }
.btn-primary:active { transform: translateY(3px); box-shadow: 0 3px 0 #b9962a; }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); box-shadow: none; }
.btn + .btn { margin-top: 10px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--ink-dim); font-size: .8rem; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.error-text { color: #ffb3a8; text-align: center; margin-top: 14px; }

.home-wrap, .lobby-wrap, .finished-wrap { max-width: 480px; margin: 0 auto; padding: calc(var(--safe-top) + 30px) 20px 40px; }
.lobby-wrap { text-align: center; }
.brand { text-align: center; margin-bottom: 26px; }
.brand-badge { font-size: 2.6rem; }
.brand h1 { font-size: 3.4rem; font-weight: 900; letter-spacing: .12em; margin: 4px 0 10px; background: linear-gradient(180deg, #fff, var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 4px 18px rgba(255,210,63,.4)); }
.tagline { color: var(--ink-dim); margin: 0 auto; max-width: 330px; }
.card { background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.room-code { font-family: ui-monospace, Menlo, monospace; font-size: 3rem; font-weight: 900; letter-spacing: .3em; color: #2a1500; background: linear-gradient(180deg,#ffe06b,var(--accent)); border: none; border-radius: var(--radius); padding: 14px 10px 14px 24px; margin: 10px 0; width: 100%; cursor: pointer; box-shadow: 0 6px 0 #b9962a; }
.copied-hint { color: var(--ok); font-size: .9rem; margin: -4px 0 10px; }
.section-title { text-align: left; margin: 22px 0 10px; color: var(--ink-dim); text-transform: uppercase; font-size: .78rem; letter-spacing: .12em; }
.player-list { list-style: none; padding: 0; margin: 0; text-align: left; }
.player-list li { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--bg-card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; }
.player-list .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-dim); flex: 0 0 auto; }
.player-list .dot.on { background: var(--ok); }
.player-list .rank { font-weight: 900; color: var(--accent); min-width: 26px; text-align: center; }
.player-list .pname { flex: 1; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-list .pscore { font-weight: 800; font-variant-numeric: tabular-nums; }
.player-list .pdelta { font-size: .8rem; color: var(--ok); font-weight: 700; margin-left: 6px; }
.player-list .pdelta.zero { color: var(--ink-dim); }
.player-list .badge { font-size: .7rem; padding: 2px 8px; border-radius: 999px; background: rgba(255,210,63,.16); color: var(--accent); }
.player-list li.you { border-color: var(--accent); }

.seg { display: flex; gap: 6px; background: rgba(0,0,0,.25); border: 1px solid var(--line); border-radius: 12px; padding: 5px; }
.seg-btn { flex: 1; padding: 11px 6px; border: none; background: none; color: var(--ink-dim); border-radius: 9px; font-size: .95rem; font-weight: 700; cursor: pointer; }
.seg-btn.active { background: var(--accent); color: #2a1500; }

.center-screen { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 8px; }
.spinner { width: 46px; height: 46px; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .9s linear infinite; margin-bottom: 16px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================ SHOW ============================ */
.show-screen { display: flex; flex-direction: column; min-height: 100dvh; }
.hud-top { display: flex; align-items: center; gap: 8px; padding: calc(var(--safe-top) + 12px) 14px 10px; }
.hud-left { flex: 1; min-width: 0; }
.hud-round { font-weight: 900; font-size: 1rem; }
.hud-theme { font-size: .72rem; color: var(--ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { flex: 0 0 auto; background: var(--bg-card); border: 1px solid var(--line); color: var(--ink); border-radius: 999px; padding: 8px 12px; font-size: .85rem; font-weight: 800; cursor: pointer; }
#gh-code { font-family: ui-monospace, Menlo, monospace; color: var(--accent); }

.phase { flex: 1; display: flex; flex-direction: column; padding: 8px 16px calc(20px + var(--safe-bottom)); animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* intro */
#phase-intro { align-items: center; justify-content: center; text-align: center; }
.intro-card { background: var(--bg-card); border: 1px solid var(--line); border-radius: 20px; padding: 30px 24px; max-width: 460px; box-shadow: 0 16px 50px rgba(0,0,0,.4); }
.intro-card .mc { font-size: 3rem; margin-bottom: 10px; }
.intro-card p { font-size: 1.3rem; font-weight: 700; margin: 0 0 12px; }

/* question */
.q-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.q-meta { font-weight: 800; color: var(--accent); letter-spacing: .05em; }
.answered-count { font-size: .85rem; color: var(--ink-dim); }
.timerbar { height: 10px; background: rgba(0,0,0,.3); border-radius: 999px; overflow: hidden; margin-bottom: 18px; }
#timerfill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--ok), var(--accent), var(--danger)); border-radius: 999px; }
.q-text { font-size: 1.5rem; line-height: 1.3; text-align: center; margin: 6px 0 20px; flex: 0 0 auto; }
.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ans { border: none; border-radius: 16px; padding: 20px 14px; font-size: 1.05rem; font-weight: 800; color: #fff; cursor: pointer; min-height: 84px; display: flex; align-items: center; gap: 10px; text-align: left; box-shadow: 0 6px 0 rgba(0,0,0,.35); transition: transform .08s; }
.ans:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0,0,0,.35); }
.ans .shape { font-size: 1.2rem; flex: 0 0 auto; }
.ans.a0 { background: var(--a0); } .ans.a1 { background: var(--a1); } .ans.a2 { background: var(--a2); } .ans.a3 { background: var(--a3); }
.ans.dim { opacity: .35; }
.ans.chosen { outline: 4px solid #fff; outline-offset: 2px; }
.ans.correct { box-shadow: 0 0 0 4px #fff, 0 0 24px var(--ok); }
.ans.wrong { filter: grayscale(.5); }
.answers.reveal .ans { cursor: default; }
.answer-status { text-align: center; margin-top: 16px; font-weight: 700; color: var(--accent); min-height: 24px; }

/* reveal */
.rv-you { text-align: center; font-size: 1.6rem; font-weight: 900; margin: 14px 0 4px; }
.rv-you.good { color: var(--ok); } .rv-you.bad { color: var(--ink-dim); }
.rv-quip { text-align: center; color: var(--ink-dim); font-style: italic; margin: 0 0 16px; }
.mini-board { display: flex; flex-direction: column; gap: 6px; }
.mini-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; background: var(--bg-card); border: 1px solid var(--line); border-radius: 10px; }
.mini-row .rank { font-weight: 900; color: var(--accent); min-width: 22px; }
.mini-row .pname { flex: 1; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-row .pscore { font-weight: 800; font-variant-numeric: tabular-nums; }
.mini-row.you { border-color: var(--accent); }

/* finished / podium */
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 10px; margin: 20px 0 24px; }
.pod { flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; }
.pod .pavatar { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; font-weight: 900; font-size: 1.3rem; color: #2a1500; margin-bottom: 8px; }
.pod .pn { font-weight: 800; font-size: .9rem; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.pod .ps { font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.pod .bar { width: 100%; border-radius: 12px 12px 0 0; margin-top: 8px; background: linear-gradient(180deg, var(--bg-card), var(--bg2)); border: 1px solid var(--line); border-bottom: none; display: grid; place-items: start center; padding-top: 8px; font-weight: 900; font-size: 1.4rem; }
.pod.p1 .pavatar { background: linear-gradient(180deg,#ffe06b,var(--accent)); } .pod.p1 .bar { height: 130px; }
.pod.p2 .pavatar { background: #cfd6e6; } .pod.p2 .bar { height: 96px; }
.pod.p3 .pavatar { background: #e0a064; } .pod.p3 .bar { height: 70px; }

/* overlay */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.66); display: flex; align-items: flex-end; justify-content: center; z-index: 100; animation: fade .2s; }
.overlay-card { background: var(--bg2); border: 1px solid var(--line); border-top-left-radius: 22px; border-top-right-radius: 22px; width: 100%; max-width: 520px; padding: 18px 18px calc(20px + var(--safe-bottom)); max-height: 84dvh; overflow-y: auto; }
.overlay-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.overlay-head h3 { margin: 0; }
.icon-btn { background: none; border: none; color: var(--ink-dim); font-size: 1.3rem; cursor: pointer; }

.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%); background: #000; color: #fff; padding: 12px 18px; border-radius: 999px; font-size: .92rem; z-index: 150; border: 1px solid var(--line); max-width: 90vw; text-align: center; }
.confetti { position: fixed; top: -10px; width: 10px; height: 16px; z-index: 180; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); opacity: .9; } }
