:root {
  font: 100%/1.5 system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --ink: #1d1d1f; --muted: #6e6e73; --line: #d2d2d7; --bg: #f5f5f7; --card: #fff;
  --accent: #0071e3; --gold: #ffd60a; --good: #30d158; --bad: #ff453a;
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button, .button {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: .5em .9em; cursor: pointer;
  text-decoration: none; color: inherit; white-space: nowrap; transition: transform 100ms ease-out, background 100ms;
}
button:active:not(:disabled), .button:active { transform: scale(.97); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { color: var(--bad); }
input, select, textarea { border: 1px solid var(--line); border-radius: 10px; padding: .55em .8em; background: var(--card); min-width: 0; width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.muted { color: var(--muted); font-size: .875rem; }
.error { color: var(--bad); min-height: 1.5em; margin: 0; font-size: .9rem; }
.grow { flex: 1; min-width: 0; }

/* ---------- 玩家手機 ---------- */
body.player { background: #0b0b12; color: #fff; --card: #1c1c26; --line: #33334a; --muted: #a1a1b5; }
body.player main { min-height: 100dvh; display: flex; flex-direction: column; padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); gap: 16px; max-width: 520px; margin: 0 auto; }
.player .card { margin: auto 0; display: grid; gap: 14px; }
.player .card h1 { font-size: 1.75rem; letter-spacing: -.02em; line-height: 1.15; margin: 0 0 8px; }
.player input, .player select { font-size: 1.125rem; padding: .8em 1em; border-radius: 14px; }
.player button.primary { font-size: 1.125rem; padding: .85em 1em; border-radius: 14px; }
.player header { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.player header strong { font-size: 1.125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .score { color: var(--gold); font-weight: 600; white-space: nowrap; }
.player .stage { flex: 1; display: grid; place-content: center; text-align: center; gap: 4px; }
.player .stage p { margin: 0; }
.player .label { color: var(--muted); }
.player .big { font-size: clamp(1.75rem, 9vw, 2.75rem); font-weight: 700; letter-spacing: -.02em; line-height: 1.15; overflow-wrap: anywhere; }
.player .stage.solved .big, .player .stage.revealed .big { color: var(--gold); }
.player .hints { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 8px; justify-items: center; }
.player .hints li { background: #fff; color: #14102b; font-weight: 600; padding: .35em .9em; border-radius: 12px; overflow-wrap: anywhere; }
.player .answer { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.player .answer .error { grid-column: 1 / -1; }
.player .answer button { position: relative; overflow: hidden; min-width: 5.5em; }
.player .answer .fill { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); transform-origin: left; transform: scaleX(0); }
.player .answer .text { position: relative; font-variant-numeric: tabular-nums; }

/* ---------- 投影 ---------- */
body.screen {
  height: 100vh; overflow: hidden; color: #fff; display: grid; grid-template-rows: auto 1fr;
  background: radial-gradient(120% 90% at 30% 110%, #3a1c71 0%, #14102b 45%, #07060f 100%);
  font-size: clamp(14px, 1.25vw, 28px);
}
.screen #board { position: relative; z-index: 3; display: flex; gap: .8em; padding: 1em 1.5em; overflow: hidden; min-height: 5.2em; align-items: center; }
.screen #board.empty { visibility: hidden; }
.screen .chip { flex: 1 0 auto; display: flex; align-items: baseline; justify-content: center; gap: .5em; padding: .45em 1em; border-radius: 1em; background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .14); white-space: nowrap; }
.screen .chip .table { font-size: 1.3em; font-weight: 600; }
.screen .chip .points { font-size: 2em; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--gold); line-height: 1; }
.screen .chip.rank1 { background: linear-gradient(135deg, rgba(255, 214, 10, .32), rgba(255, 159, 10, .18)); border-color: rgba(255, 214, 10, .6); }
.screen main { display: grid; grid-template-columns: 1fr 30%; gap: 1.5em; padding: 0 1.5em 1.5em; min-height: 0; }
.screen.wall-hidden main { grid-template-columns: 1fr; }
.screen.wall-hidden #wall { display: none; }
.screen #stage { border-radius: 2em; background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .1); display: grid; grid-template-rows: auto auto 1fr auto; padding: 1.5em; gap: 1em; min-height: 0; }
.screen #top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 1em; }
.screen #number { margin: 0; font-size: 3.6em; font-weight: 800; letter-spacing: -.02em; line-height: 1.05; min-height: 1.05em; white-space: nowrap; }
.screen #status { margin: 0; font-size: 2em; color: rgba(255, 255, 255, .7); min-height: 1.5em; text-align: center; }
/* QR Code 固定在上方，不會被現場桌子擋住 */
.screen #join { justify-self: start; display: flex; align-items: center; gap: 1em; background: rgba(0, 0, 0, .35); padding: .7em 1.2em .7em .7em; border-radius: 1.2em; }
.screen #qr { width: 9em; height: 9em; border-radius: .6em; background: #fff; display: block; }
.screen #join div { display: grid; }
.screen #join strong { font-size: 1.4em; }
.screen #join span { color: rgba(255, 255, 255, .7); font-size: 1.1em; }
.screen #worth { justify-self: end; display: grid; grid-template-columns: auto auto; align-items: baseline; justify-content: end; column-gap: .2em; }
.screen #worth b { font-size: 5.4em; font-weight: 800; line-height: 1; color: var(--gold); font-variant-numeric: tabular-nums; }
.screen #worth span { font-size: 2em; font-weight: 700; color: var(--gold); }
.screen #worth i { grid-column: 1 / -1; height: .5em; width: 9em; border-radius: 99px; background: rgba(255, 255, 255, .15); overflow: hidden; margin-top: .5em; }
.screen #worth u { display: block; height: 100%; background: var(--gold); transform-origin: left; transform: scaleX(0); }
.screen #hints { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .7em; justify-content: center; align-content: start; min-height: 0; }
.screen #hints li { font-size: 2.3em; font-weight: 700; line-height: 1.2; padding: .35em .9em; border-radius: .7em; background: #fff; color: #14102b; overflow-wrap: anywhere; }
.screen #hints li.new { animation: hint 600ms cubic-bezier(.2, 1.3, .3, 1); }
@keyframes hint { from { opacity: 0; transform: scale(.6); } }
.screen #bars { display: flex; align-items: center; gap: .55em; width: 78%; justify-self: center; min-height: 0; height: 100%; max-height: 22em; align-self: center; }
.screen #bars i { flex: 1; height: 12%; border-radius: 99px; background: linear-gradient(180deg, #ff375f, #bf5af2 55%, #0a84ff); transform-origin: center; }
.screen[data-phase="playing"] #bars i { animation: bar var(--d, 900ms) ease-in-out infinite alternate; animation-delay: calc(var(--i) * -137ms); }
@keyframes bar { from { height: 10%; } to { height: 100%; } }
.screen[data-phase="lobby"] #top { grid-template-columns: 1fr; }
.screen[data-phase="lobby"] #number, .screen[data-phase="lobby"] #hints, .screen[data-phase="lobby"] #bars { display: none; }
.screen[data-phase="lobby"] #stage { grid-template-rows: 1fr auto; place-items: center; }
.screen[data-phase="lobby"] #join { justify-self: center; flex-direction: column; padding: 1.5em; text-align: center; }
.screen[data-phase="lobby"] #qr { width: min(22em, 52vh); height: min(22em, 52vh); }
.screen #wall { border-radius: 2em; background: rgba(0, 0, 0, .3); border: 1px solid rgba(255, 255, 255, .1); padding: 1.2em; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; min-height: 0; }
.screen #messages { list-style: none; margin: 0; padding: 0; display: grid; gap: .6em; }
.screen #messages li { background: rgba(255, 255, 255, .1); border-radius: 1em; padding: .5em .9em; display: grid; animation: pop 220ms cubic-bezier(.2, .9, .3, 1); }
.screen #messages b { font-size: .95em; color: #9fd0ff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.screen #messages span { font-size: 1.35em; font-weight: 600; overflow-wrap: anywhere; line-height: 1.25; }
@keyframes pop { from { opacity: 0; transform: translateY(40%) scale(.96); } }
.screen #overlay { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: .5em; text-align: center; background: rgba(7, 6, 15, .82); backdrop-filter: blur(14px); animation: fade 250ms ease-out; padding: 4vh 6vw; }
@keyframes fade { from { opacity: 0; } }
.screen #overlay p { margin: 0; }
.screen .cheer { font-size: 3em; font-weight: 800; color: var(--gold); letter-spacing: -.02em; }
.screen .winner { background: #fff; color: #14102b; border-radius: 1.6em; padding: 1em 2.2em; box-shadow: 0 1.5em 4em rgba(0, 0, 0, .5); margin: .4em 0; max-width: 80vw; }
.screen .winner .who { font-size: 4.6em; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; overflow-wrap: anywhere; }
.screen .winner .said { font-size: 2em; color: #55506f; overflow-wrap: anywhere; }
.screen #overlay .answer { font-size: 5em; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; overflow-wrap: anywhere; }
.screen .plus { font-size: 3em; font-weight: 700; color: var(--good); }
.screen[data-phase="ended"] #board { visibility: hidden; }
.screen #overlay.ended h1 { font-size: min(3.2em, 9vh); margin: 0 0 .3em; letter-spacing: -.02em; line-height: 1.1; }
.screen #overlay.ended ol { list-style: none; margin: 0; padding: 0; display: grid; grid-auto-flow: column; grid-template-rows: repeat(5, auto); gap: .5em 2em; font-size: min(2em, 5.4vh); }
.screen #overlay.ended li { display: grid; grid-template-columns: 1.6em 6.5em 4em; align-items: baseline; gap: .6em; font-weight: 700; padding: .35em 1em; border-radius: .8em; background: rgba(255, 255, 255, .08); text-align: left; white-space: nowrap; }
.screen #overlay.ended li.rank1 { background: linear-gradient(135deg, rgba(255, 214, 10, .4), rgba(255, 159, 10, .2)); }
.screen #overlay.ended .rank { color: rgba(255, 255, 255, .6); }
.screen #overlay.ended .points { color: var(--gold); text-align: right; font-variant-numeric: tabular-nums; }
.screen #confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.screen #unlock { position: fixed; inset: 0; margin: auto; width: 9em; height: 3.2em; font-size: 2.6em; font-weight: 700; border-radius: 99px; background: var(--gold); color: #14102b; border: 0; box-shadow: 0 0 0 100vmax rgba(7, 6, 15, .75); }

/* ---------- 後台 ---------- */
body.host main { max-width: 1280px; margin: 0 auto; padding: 20px; display: grid; gap: 16px; }
.host .top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.host h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.01em; }
.host h2 { font-size: 1rem; margin: 0 0 10px; }
.host .columns { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.host .panel { background: var(--card); border-radius: 16px; padding: 18px; display: grid; gap: 12px; }
.host .row { display: flex; gap: 8px; align-items: center; }
.host .row input[type=number] { max-width: 8em; }
.host ul, .host ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.host li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: var(--bg); }
.host .rooms li { cursor: pointer; flex-direction: column; align-items: flex-start; gap: 0; }
.host .rooms li:hover { background: #e8e8ed; }
.host .no { width: 1.8em; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.host .questions div.grow { display: grid; }
.host .questions li.current { outline: 2px solid var(--accent); }
.host .questions audio { height: 32px; width: 220px; }
.host .warn { color: var(--bad); font-size: .875rem; }
.host .now { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; min-height: 2.6em; }
.host .now .answer { font-size: 1.75rem; letter-spacing: -.01em; }
.host .phase { padding: .15em .7em; border-radius: 99px; background: var(--bg); font-weight: 600; }
.host .phase.playing { background: var(--good); color: #fff; }
.host .phase.solved { background: var(--gold); }
.host .won { color: #248a3d; font-weight: 600; }
.host .worth { font-weight: 700; color: #b25000; }
.host .qform { display: grid; gap: 8px; }
.host .sec { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.host .sec input { width: 5em; }
.host .questions li.editing { align-items: stretch; }
.host .controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.host button.big { font-size: 1.125rem; padding: .8em 1.3em; }
.host .messages { max-height: 46vh; overflow: auto; align-content: start; }
.host .messages li.correct { background: #e3f9e8; }
.host .messages li.hidden { opacity: .4; text-decoration: line-through; }
.host .messages b { white-space: nowrap; }
.host .qr { width: 100%; border-radius: 12px; background: #fff; }
.host .url { overflow-wrap: anywhere; margin: 0; }
.host .toast { margin: 0; padding: 10px 14px; border-radius: 10px; background: #1d1d1f; color: #fff; position: sticky; top: 8px; z-index: 2; }
.host textarea { resize: vertical; }
@media (max-width: 900px) { .host .columns { grid-template-columns: 1fr; } .host .questions li { flex-wrap: wrap; } }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
