:root {
  --bg: #f3f4f9; --card: #fff; --ink: #151827; --muted: #626883; --line: #e1e4ee;
  --brand: #e3350d; --brand-2: #b82a0a;
  --c0: #e21b3c; --c1: #1368ce; --c2: #c47f00; --c3: #26890c;
  --ok: #1f9d55; --bad: #d64545; --r: 18px;
  --shadow: 0 1px 2px rgba(20,24,40,.06), 0 6px 20px rgba(20,24,40,.07);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  min-height: 100vh; min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: .2em 0 .45em; line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }
.grow { flex: 1; }
.mono { font-variant-numeric: tabular-nums; letter-spacing: .08em; }

/* 上方列 */
.topbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 8px 16px; background: var(--ink); color: #fff; min-height: 48px; }
.topbar:empty { display: none; }
.tb-title { font-size: 1.05rem; }
.tb-code b { font-size: 1.15rem; }
.tb-score { font-weight: 700; }

main { max-width: 720px; margin: 0 auto; padding: 16px; padding-bottom: 40px; }
.host main { max-width: 1180px; }
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 20px; margin-bottom: 14px; }
.join { max-width: 420px; margin: 6vh auto 0; text-align: center; }
.logo { font-size: 48px; }
.field { display: block; text-align: left; margin: 14px 0; }
.field span { display: block; font-weight: 700; margin-bottom: 6px; }
input[type=text], input:not([type]), textarea, select {
  width: 100%; padding: 12px 14px; border: 2px solid var(--line); border-radius: 12px; background: #fff; font-size: 1.05rem;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--c1); }
#jcode { font-size: 1.9rem; text-align: center; letter-spacing: .3em; font-variant-numeric: tabular-nums; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 12px; border: 2px solid var(--line); background: #fff; font-weight: 700; cursor: pointer; min-height: 44px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:active:not(:disabled) { background: var(--brand-2); }
.btn.block { display: flex; width: 100%; }
.btn.big { font-size: 1.25rem; padding: 14px 24px; min-height: 58px; }
.btn.sm { min-height: 34px; padding: 4px 10px; font-size: .9rem; }
.btn.ghost { background: transparent; color: inherit; border-color: rgba(255,255,255,.35); }
.err { color: var(--bad); min-height: 1.5em; margin: .6em 0 0; font-weight: 600; }

.net { position: sticky; top: 0; z-index: 5; background: #fff4d6; color: #7a5200; text-align: center; padding: 6px; font-weight: 700; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 20; max-width: calc(100vw - 32px); box-shadow: var(--shadow); font-weight: 600; }
.pill { display: inline-block; padding: 4px 12px; border-radius: 999px; background: #e7e9f3; font-weight: 800; font-size: .92rem; }
.big-emoji { font-size: 56px; line-height: 1.1; }
.statline { font-size: 1.12rem; }

/* 題目與選項 */
.qhead { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.qtext { font-size: 1.35rem; font-weight: 800; background: #fff; border-radius: var(--r); padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 12px; word-break: break-word; }
.timer { height: 12px; background: #e1e4ee; border-radius: 99px; overflow: hidden; margin-bottom: 12px; }
.timer > div { height: 100%; width: 100%; background: var(--c1); transition: width .1s linear; }
.timer.hurry > div { background: var(--bad); }
.left { font-size: 1.7rem; font-weight: 900; font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }
.opts { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 640px) { .opts { grid-template-columns: 1fr 1fr; } }
.opt {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 70px; padding: 12px 16px;
  border: 0; border-radius: 14px; color: #fff; font-size: 1.18rem; font-weight: 800; text-align: left;
  box-shadow: inset 0 -5px 0 rgba(0,0,0,.18); text-shadow: 0 1px 2px rgba(0,0,0,.3);
  outline: 4px solid transparent; outline-offset: 3px; transition: transform .08s, opacity .15s, outline-color .15s;
}
button.opt { cursor: pointer; }
button.opt:active { transform: scale(.98); }
.c0 { background: var(--c0); } .c1 { background: var(--c1); } .c2 { background: var(--c2); } .c3 { background: var(--c3); }
.shape { font-size: 1.4rem; width: 1.6em; text-align: center; flex: none; }
.otext { word-break: break-word; }
.has-sel .opt:not(.sel) { opacity: .42; }
.opt.sel { outline-color: var(--ink); transform: scale(1.01); }
.opt.sel::after { content: '✓'; margin-left: auto; font-size: 1.5rem; }
.hint { text-align: center; color: var(--muted); margin-top: 14px; font-weight: 600; }
button.opt:disabled { cursor: default; color: #fff; }
.opts.locked .opt:not(.sel) { opacity: .3; }
.send-area { margin-top: 16px; }
.send-state { text-align: center; color: var(--muted); font-weight: 700; margin: 10px 0 0; }
.send-state.ok { color: var(--ok); font-size: 1.1rem; }
.warn { text-align: center; margin: 10px 0 0; padding: 10px; border-radius: 12px; background: #fde8e8; color: var(--bad); font-weight: 900; font-size: 1.15rem; animation: blink 1s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .45; } }
.chip.me { background: var(--brand); color: #fff; }

/* 主持首頁：場次清單、金鑰、題庫 */
.setup { display: grid; gap: 14px; max-width: 760px; margin: 0 auto; }
.setup .card { margin-bottom: 0; }
.room-list { list-style: none; margin: 0; padding: 0; }
.room-list li { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.room-list li:last-child { border-bottom: 0; }
.room-open { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; background: none; border: 0; padding: 12px 4px; cursor: pointer; }
.room-open b { font-size: 1.05rem; }
.room-open:hover b { color: var(--c1); }
.chip { display: inline-flex; align-items: center; gap: 6px; }
.chip-x { border: 0; background: rgba(0,0,0,.08); color: inherit; border-radius: 50%; width: 22px; height: 22px; line-height: 22px; padding: 0; cursor: pointer; font-size: 14px; }
.chip-x:hover { background: var(--bad); color: #fff; }
.keyrow { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.keyrow code { background: #f1f2f7; padding: 6px 10px; border-radius: 8px; }
.keyrow input { flex: 1; min-width: 200px; padding: 8px 10px; font-size: .95rem; }
.bank-panel { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.ready { text-align: center; padding: 28px 0; }
.ready-num { font-size: 110px; font-weight: 900; line-height: 1; color: var(--brand); }
.result { text-align: center; border-radius: var(--r); padding: 28px 20px; color: #fff; margin-bottom: 14px; }
.result.ok { background: var(--ok); } .result.bad { background: var(--bad); } .result.none { background: #6b7089; }
.points { font-size: 2.8rem; font-weight: 900; }

/* 頒獎台 */
.podium { display: grid; grid-template-columns: 1fr 1fr 1fr; align-items: end; gap: 10px; margin: 18px 0; }
.pod { text-align: center; min-width: 0; }
.pod .medal { font-size: 40px; }
.pod .pname { font-weight: 900; font-size: 1.1rem; word-break: break-all; }
.pod .pname.me { color: var(--brand); }
.pod .pscore { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .95rem; }
.pod .step { margin-top: 8px; border-radius: 12px 12px 0 0; color: #fff; font-weight: 900; font-size: 2rem; display: flex; align-items: center; justify-content: center; }
.p1 .step { height: 140px; background: #d4a017; } .p2 .step { height: 100px; background: #9aa3b5; } .p3 .step { height: 72px; background: #b87333; }
.podium.big .pname { font-size: clamp(1.1rem, 2.6vw, 2rem); }
.podium.big .medal { font-size: clamp(40px, 6vw, 72px); }
.podium.big .p1 .step { height: clamp(140px, 22vh, 240px); } .podium.big .p2 .step { height: clamp(100px, 15vh, 170px); } .podium.big .p3 .step { height: clamp(72px, 10vh, 120px); }
.rank-list { list-style: none; padding: 0; margin: 0; }
.rank-list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.rank-list li:last-child { border-bottom: 0; }

/* 主持端 */
.lobby { display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 820px) { .lobby { grid-template-columns: 1fr; } }
.join-panel { text-align: center; }
.qr svg { width: min(320px, 72vw); height: auto; display: block; margin: 8px auto; }
.code-big { font-size: clamp(2.6rem, 7vw, 4.6rem); font-weight: 900; letter-spacing: .14em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.url { font-weight: 700; word-break: break-all; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; min-height: 44px; margin-bottom: 16px; }
.chip { background: #eef0f7; border-radius: 999px; padding: 6px 14px; font-weight: 700; animation: pop .25s ease; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
.qsum { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 12px 0; border-top: 1px solid var(--line); margin-bottom: 12px; }
.host .qtext { font-size: clamp(1.4rem, 3.2vw, 2.5rem); text-align: center; padding: 22px; }
.hq-mid { display: flex; align-items: center; justify-content: center; gap: 32px; margin: 6px 0 18px; }
.clock { width: 116px; height: 116px; border-radius: 50%; background: var(--c1); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 3.2rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.clock.ready { background: var(--brand); } .clock.hurry { background: var(--bad); } .clock.done { background: #6b7089; }
.answered { text-align: center; font-weight: 700; color: var(--muted); }
.answered b { display: block; font-size: 2.8rem; line-height: 1; color: var(--ink); }
.host .opt { min-height: 84px; font-size: clamp(1.1rem, 2.2vw, 1.7rem); }
.opt .cnt { margin-left: auto; background: rgba(0,0,0,.24); border-radius: 999px; padding: 2px 12px; font-size: 1rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.opts.result .opt:not(.correct) { opacity: .35; }
.opts.result .opt.correct { outline-color: var(--ink); }
.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.actions.left { justify-content: flex-start; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 16px; }
@media (max-width: 720px) { .cols { grid-template-columns: 1fr; } }

/* 題目編輯 */
.import-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.paste { margin-top: 12px; }
.paste textarea { font-family: ui-monospace, Consolas, monospace; font-size: .95rem; }
.qcard { background: #fff; border-radius: var(--r); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.qc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.qc-head select { width: auto; padding: 6px 10px; font-size: .95rem; }
.icon { border: 1px solid var(--line); background: #fff; border-radius: 10px; min-width: 42px; min-height: 42px; cursor: pointer; font-size: 1rem; }
.icon:disabled { opacity: .35; cursor: default; }
.qcard textarea { resize: vertical; margin-bottom: 10px; }
.qopts { display: grid; gap: 8px; }
@media (min-width: 720px) { .qopts { grid-template-columns: 1fr 1fr; } }
.qopt { display: flex; align-items: center; gap: 8px; border-radius: 12px; padding: 6px 8px; background: #f6f7fb; border-left: 8px solid; }
.qopt.is-correct { background: #e3f5ea; box-shadow: 0 0 0 2px var(--ok) inset; }
.qopt .cor { display: flex; align-items: center; gap: 4px; cursor: pointer; flex: none; }
.qopt .cor input { width: 22px; height: 22px; accent-color: var(--ok); margin: 0; }
.qopt input[type=text] { padding: 8px 10px; font-size: 1rem; }
.ed-foot { position: sticky; bottom: 0; display: flex; align-items: center; gap: 10px; padding: 14px 0 12px; background: linear-gradient(rgba(243,244,249,0), var(--bg) 35%); z-index: 3; }
