:root {
  --bg1: #1a1240;
  --bg2: #3a2280;
  --bg3: #0b0820;
  --accent: #ffd23f;
  --accent-2: #ff9f1c;
  --ink: #fbf7ff;
  --muted: rgba(251, 247, 255, .7);
  --card: rgba(255, 255, 255, .07);
  --card-line: rgba(255, 210, 63, .28);
  --ok: #2fd08f;
  --ng: #ff6b7d;
  --danger: #ff9b8a;
  /* Answer tiles: colour + shape (▲ ◆ ● ■) */
  --o0: #e8455c; --o0-ink: #fff;
  --o1: #2f86e8; --o1-ink: #fff;
  --o2: #f2b01e; --o2-ink: #2a1a00;
  --o3: #19a874; --o3-ink: #fff;
  --radius: 18px;
  --font: "PingFang TC", "Hiragino Sans", "Noto Sans TC", "Noto Sans JP", "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  --num: "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", "Segoe UI", var(--font);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background-color: var(--bg1);
  background-image: radial-gradient(120% 70% at 50% 0%, var(--bg2) 0%, var(--bg1) 55%, var(--bg3) 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.45rem; letter-spacing: .02em; }
h2 { font-size: 1.1rem; letter-spacing: .03em; }
a { color: var(--accent); }
.muted { color: var(--muted); margin: 0; }
.small { font-size: .88rem; }
.center { text-align: center; }
.num { font-family: var(--num); font-weight: 800; letter-spacing: .03em; font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.error { color: var(--danger); font-weight: 700; margin: 8px 0 0; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  max-width: 560px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .04em; color: var(--ink); text-decoration: none; }
.chip {
  font: inherit; font-size: .85rem; color: var(--ink);
  background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 999px; padding: 6px 14px; cursor: pointer; white-space: nowrap;
}
.lang-sel { appearance: none; -webkit-appearance: none; padding-right: 14px; }
.lang-sel option { color: #000; }

/* Controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  font: inherit; font-weight: 800; font-size: 1rem; text-decoration: none; cursor: pointer;
  color: var(--ink); background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 14px; padding: 14px 18px;
}
.btn.primary { color: #241500; background: linear-gradient(180deg, var(--accent), var(--accent-2)); border: 0; box-shadow: 0 6px 18px rgba(255, 159, 28, .3); }
.btn.big { font-size: 1.2rem; padding: 17px 20px; border-radius: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, .chip:focus-visible, input:focus-visible, .opt:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
input.code-input, input.nick-input {
  width: 100%; font: inherit; font-size: 1.15rem; color: var(--ink);
  background: rgba(0, 0, 0, .25); border: 1px solid rgba(255, 255, 255, .22); border-radius: 14px; padding: 14px 16px;
}
input.code-input { text-align: center; letter-spacing: .25em; font-size: 1.5rem; text-transform: uppercase; }
input::placeholder { color: rgba(251, 247, 255, .45); letter-spacing: normal; font-size: 1rem; font-family: var(--font); font-weight: 400; }

main { max-width: 560px; margin: 0 auto; padding: 0 16px 24px; }
.view { display: grid; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--card-line); border-radius: var(--radius); padding: 18px; }
.hero { text-align: center; display: grid; gap: 14px; justify-items: center; padding: 26px 18px; }
.hero h1 { font-size: 1.3rem; }
.code-form { display: grid; gap: 10px; width: 100%; }
.last-link { display: block; text-decoration: none; font-weight: 700; text-align: center; }
.demo-link { color: var(--muted); }
.banner { border-radius: 14px; padding: 12px 14px; font-weight: 700; text-align: center; white-space: pre-line; }
.banner.warn { background: rgba(255, 155, 138, .16); border: 1px solid rgba(255, 155, 138, .45); color: #ffd3ca; }
.event-name { font-weight: 800; font-size: 1.15rem; color: var(--accent); }
.field-k { display: block; font-weight: 700; margin: 14px 0 8px; }
.join-card form { display: grid; gap: 6px; }
.join-card .btn { margin-top: 10px; }
.agree { font-size: .8rem; color: var(--muted); text-align: center; margin: 0; }
.site-footer { text-align: center; font-size: .8rem; color: var(--muted); padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); }
.site-footer a { color: var(--muted); }
.legal h2 { font-size: 1rem; margin: 18px 0 6px; color: var(--accent); }
.legal p, .legal li { line-height: 1.7; color: var(--muted); }

/* ---------- Phone: play ---------- */
.play-head { display: grid; gap: 8px; }
.me-row { display: flex; gap: 8px; flex-wrap: wrap; }
.me-chip { cursor: default; font-weight: 700; }
.score-chip { cursor: default; }
.score-chip b { color: var(--accent); margin-left: 4px; }
.pane { display: grid; gap: 14px; }
.big-emoji { font-size: 3rem; }
.paused-card { text-align: center; display: grid; gap: 6px; justify-items: center; border-color: rgba(255, 155, 138, .45); }
.paused-icon { font-size: 2.4rem; }
.q-meta { display: flex; align-items: center; gap: 8px; }
.pts-chip { background: rgba(255, 210, 63, .2); border-color: var(--card-line); color: var(--accent); font-weight: 800; cursor: default; }
.timer { margin-left: auto; font-size: 1.8rem; min-width: 2.2em; text-align: right; color: var(--accent); }
.q-text-phone { font-size: 1.3rem; font-weight: 800; line-height: 1.45; overflow-wrap: anywhere; }
.opts-phone { display: grid; gap: 12px; }
.opts-phone[data-n="4"], .opts-phone[data-n="2"] { grid-template-columns: 1fr 1fr; }
.opt {
  position: relative; display: flex; align-items: center; gap: 12px; min-height: 104px;
  font: inherit; font-weight: 800; font-size: 1.05rem; text-align: left; line-height: 1.3;
  border: 0; border-radius: 16px; padding: 14px 16px; cursor: pointer; overflow: hidden;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .22);
}
.opt:active:not(:disabled) { transform: translateY(2px); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .22); }
.opt:disabled { cursor: default; opacity: .55; }
.opt-shape { font-size: 1.5rem; line-height: 1; flex: none; }
.opt-text { overflow-wrap: anywhere; position: relative; }
.opt-0 { background: var(--o0); color: var(--o0-ink); }
.opt-1 { background: var(--o1); color: var(--o1-ink); }
.opt-2 { background: var(--o2); color: var(--o2-ink); }
.opt-3 { background: var(--o3); color: var(--o3-ink); }
.sent-card { display: grid; gap: 8px; justify-items: center; font-weight: 700; }
.sent-choice { border-radius: 12px; padding: 10px 16px; font-weight: 800; font-size: 1.1rem; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .15); border-top-color: var(--accent); animation: spin 1s linear infinite; margin: 0 auto 10px; }
.spinner.big { width: 9vh; height: 9vh; border-width: 1vh; }
@keyframes spin { to { transform: rotate(360deg); } }

.result { text-align: center; justify-items: center; padding: 26px 18px; border-radius: var(--radius); }
.result[data-state="ok"] { background: radial-gradient(circle at 50% 0, rgba(47, 208, 143, .35), rgba(47, 208, 143, .08)); border: 1px solid rgba(47, 208, 143, .6); }
.result[data-state="ng"] { background: radial-gradient(circle at 50% 0, rgba(255, 107, 125, .3), rgba(255, 107, 125, .07)); border: 1px solid rgba(255, 107, 125, .55); }
.result[data-state="none"] { background: var(--card); border: 1px solid var(--card-line); }
.res-icon { font-size: 3.4rem; line-height: 1; }
.result h1 { font-size: 2rem; }
.res-pts { font-size: 1.8rem; color: var(--accent); min-height: 1.2em; }
.res-ans { border-radius: 12px; padding: 8px 14px; font-weight: 800; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }
.stat { background: rgba(0, 0, 0, .2); border-radius: 14px; padding: 10px; text-align: center; }
.stat-k { font-size: .8rem; color: var(--muted); }
.stat-v { font-size: 1.5rem; }

.my-rank { font-weight: 800; color: var(--accent); white-space: pre-line; margin: 8px 0 12px; }
.board-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.board-list li { display: grid; grid-template-columns: 2.4em 1fr auto auto; align-items: center; gap: 10px; background: rgba(0, 0, 0, .2); border-radius: 12px; padding: 10px 14px; }
.board-list li.me { outline: 2px solid var(--accent); }
.b-rank { color: var(--accent); }
.b-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(10, 8, 30, .92); color: var(--ink); border: 1px solid var(--card-line);
  padding: 12px 18px; border-radius: 14px; font-weight: 700; z-index: 50; max-width: calc(100% - 32px); text-align: center;
}
.qr-box { flex: none; background: #fff; border-radius: 14px; padding: 12px; line-height: 0; }
.qr-box svg { display: block; width: 100%; height: auto; }

/* ---------- Big screen ---------- */
.screen-tools, .start-overlay { display: none; }
body.screen-mode { overflow: hidden; }
.screen-mode .topbar, .screen-mode .site-footer { display: none; }
.screen-mode main { max-width: none; padding: 0; }
.screen-mode #screenView { display: block; min-height: 100vh; }
.screen-mode .start-overlay {
  display: flex; position: fixed; inset: 0; z-index: 40; flex-direction: column; align-items: center; justify-content: center; gap: 2vh;
  font: inherit; font-size: clamp(1.2rem, 3vh, 2.4rem); font-weight: 800; color: var(--ink);
  background: rgba(10, 8, 30, .78); border: 0; cursor: pointer;
}
.start-icon { font-size: clamp(3rem, 10vh, 7rem); }
.screen-mode .screen-tools { display: flex; position: fixed; right: 1.5vw; bottom: 1.5vh; gap: 10px; z-index: 30; opacity: 0; transition: opacity .3s; }
.screen-mode.show-tools .screen-tools { opacity: 1; }
.screen-mode.pin-tools .screen-tools { opacity: 1; } /* paused / host lost: keep Reconnect visible */
.screen-mode:not(.show-tools) { cursor: none; }
.screen-tools .chip:empty { display: none; }

.pair-pane { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2vh; text-align: center; padding: 4vh 4vw; }
.pair-pane h1 { font-size: clamp(1.8rem, 5vh, 3.6rem); }
.pair-pane p { font-size: clamp(1rem, 2.4vh, 1.6rem); max-width: 40em; }
.pair-row { display: flex; align-items: center; gap: 4vw; margin-top: 2vh; text-align: left; }
.pair-row .qr-box { width: clamp(160px, 32vh, 360px); }
.pair-code { font-size: clamp(3rem, 12vh, 9rem); color: var(--accent); letter-spacing: .12em; }

.quiz-pane { height: 100vh; display: flex; flex-direction: column; padding: 3vh 3vw; gap: 2vh; position: relative; }
.s-head { display: flex; align-items: center; gap: 2vw; min-width: 0; }
.s-event { font-size: clamp(1.4rem, 4vh, 3rem); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--accent); }
.pill { border-radius: 999px; padding: .35em 1em; font-weight: 800; background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .2); font-size: clamp(1rem, 2.6vh, 2rem); white-space: nowrap; }
.pill.pts { background: rgba(255, 210, 63, .2); border-color: var(--card-line); color: var(--accent); }
.s-code-small { margin-left: auto; font-size: clamp(1rem, 3vh, 2.2rem); background: #fff; color: #1a1240; border-radius: 12px; padding: .2em .6em; letter-spacing: .15em; }
.s-lost { font-size: clamp(1rem, 2.6vh, 1.8rem); }
.s-stage { flex: 1; min-height: 0; }

.s-wait { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3vh; }
.s-wait h2 { font-size: clamp(1.6rem, 5vh, 3.6rem); }

/* Lobby */
.s-lobby { display: grid; grid-template-columns: auto 1fr; gap: 4vw; align-items: center; }
.lobby-join { display: grid; gap: 2vh; justify-items: center; text-align: center; background: rgba(255, 255, 255, .06); border: 1px solid var(--card-line); border-radius: 3vh; padding: 3vh 3vw; }
.lobby-join .qr-box { width: clamp(200px, 46vh, 560px); border-radius: 2vh; padding: 2vh; }
.lobby-k { font-size: clamp(1.2rem, 3.4vh, 2.6rem); font-weight: 800; }
.join-code { font-size: clamp(2.6rem, 10vh, 8rem); color: var(--accent); letter-spacing: .14em; line-height: 1; }
.lobby-join-text .muted { font-size: clamp(.9rem, 2.2vh, 1.6rem); margin-top: 1vh; }
.lobby-players { align-self: stretch; display: flex; flex-direction: column; gap: 2vh; min-width: 0; overflow: hidden; }
.lobby-count { font-size: clamp(1.6rem, 5vh, 4rem); font-weight: 800; }
.name-cloud { display: flex; flex-wrap: wrap; gap: 1.2vh; align-content: flex-start; overflow: hidden; }
.name-chip { font-size: clamp(1rem, 3vh, 2.2rem); font-weight: 800; background: rgba(255, 255, 255, .12); border-radius: 999px; padding: .35em .9em; }
.name-chip.pop { animation: pop .5s ease-out; }
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 70% { transform: scale(1.12); } 100% { transform: scale(1); opacity: 1; } }

/* Question */
.s-question { display: grid; grid-template-rows: auto auto 1fr; gap: 2.4vh; min-height: 0; }
.sq-top { display: grid; gap: 1.4vh; justify-items: center; text-align: center; }
.sq-text { font-size: clamp(1.8rem, 6.4vh, 5.2rem); font-weight: 800; line-height: 1.3; max-width: 90%; overflow-wrap: anywhere; }
.sq-mid { display: flex; align-items: center; justify-content: space-between; padding: 0 4vw; }
.timer-ring { position: relative; width: clamp(110px, 22vh, 260px); aspect-ratio: 1; display: grid; place-items: center; }
.timer-ring svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.ring-bg { fill: rgba(0, 0, 0, .25); stroke: rgba(255, 255, 255, .12); stroke-width: 8; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round; stroke-dasharray: 276.46; transition: stroke-dashoffset .1s linear; }
.timer-ring span { position: relative; font-size: clamp(2.6rem, 9vh, 7rem); }
.timer-ring.hurry .ring-fg { stroke: var(--ng); }
.timer-ring.hurry span { color: var(--ng); animation: beat 1s ease-in-out infinite; }
@keyframes beat { 50% { transform: scale(1.12); } }
.time-up { font-size: clamp(2rem, 8vh, 6rem); font-weight: 900; color: var(--ng); animation: pop .5s ease-out; }
.answered-box { text-align: center; margin-left: auto; }
.answered-n { font-size: clamp(2.2rem, 8vh, 6rem); line-height: 1; }
.answered-box .muted { font-size: clamp(1rem, 2.6vh, 2rem); }
.opts-screen { display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: minmax(13vh, 1fr); gap: 2vh 1.6vw; min-height: 0; }
.opts-screen[data-n="2"], .opts-screen[data-n="3"] { grid-template-columns: 1fr; }
.opts-screen .opt { min-height: 13vh; font-size: clamp(1.3rem, 4.4vh, 3.4rem); border-radius: 2.2vh; padding: 2vh 2vw; gap: 1.6vw; cursor: default; box-shadow: inset 0 -.8vh 0 rgba(0, 0, 0, .22); transition: opacity .4s, transform .4s; }
.opts-screen .opt-shape { font-size: 1.2em; }
.opt-bar { position: absolute; inset: 0; background: rgba(255, 255, 255, .22); transform-origin: left; transform: scaleX(0); transition: transform .9s cubic-bezier(.2, .8, .2, 1); }
.opt-count { margin-left: auto; position: relative; font-size: 1.1em; }
.revealed .opt.dim { opacity: .35; }
.revealed .opt.correct { transform: scale(1.03); box-shadow: 0 0 0 .6vh #fff, 0 0 4vh rgba(255, 255, 255, .45); }
.revealed .opt.correct .opt-text::after { content: " ✓"; }


/* Lobby aquarium: one fish per player */
.tank {
  position: relative; flex: 1; min-height: 0; overflow: hidden; border-radius: 3vh;
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(140, 220, 255, .35), transparent 60%),
    linear-gradient(180deg, rgba(40, 140, 220, .55) 0%, rgba(10, 60, 130, .65) 55%, rgba(5, 25, 70, .8) 100%);
  border: 1px solid rgba(140, 220, 255, .35);
  box-shadow: inset 0 0 6vh rgba(0, 20, 60, .5);
}
.tank::before { /* light rays */
  content: ""; position: absolute; inset: -20% -10% 0; pointer-events: none;
  background: repeating-linear-gradient(100deg, rgba(255, 255, 255, .07) 0 3vw, transparent 3vw 9vw);
  animation: rays 12s ease-in-out infinite alternate;
}
@keyframes rays { to { transform: translateX(4vw); } }
.tank::after { /* rising bubbles */
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .7;
  background:
    radial-gradient(circle, rgba(255, 255, 255, .55) 0 .35vh, transparent .4vh) 12% 100% / 100% 30vh repeat-y,
    radial-gradient(circle, rgba(255, 255, 255, .45) 0 .25vh, transparent .3vh) 47% 100% / 100% 22vh repeat-y,
    radial-gradient(circle, rgba(255, 255, 255, .5) 0 .3vh, transparent .35vh) 83% 100% / 100% 26vh repeat-y;
  animation: bubbles 7s linear infinite;
}
@keyframes bubbles { to { background-position: 12% -30vh, 47% -22vh, 83% -26vh; } }
.tank-deco { position: absolute; left: 0; right: 0; bottom: .4vh; text-align: center; font-size: 5vh; letter-spacing: 6vw; opacity: .9; pointer-events: none; z-index: 1; }
.fish { position: absolute; display: flex; flex-direction: column; align-items: center; transform: translate(-50%, -50%); z-index: 2; will-change: left, top; }
.fish-body { font-size: clamp(2rem, 7vh, 5.5rem); line-height: 1; filter: drop-shadow(0 .4vh .6vh rgba(0, 0, 0, .35)); transition: transform .4s; }
.fish-name { margin-top: .2vh; font-size: clamp(.8rem, 2.2vh, 1.6rem); font-weight: 800; color: #fff; background: rgba(0, 30, 70, .55); border-radius: 999px; padding: .1em .7em; white-space: nowrap; max-width: 22vw; overflow: hidden; text-overflow: ellipsis; }
.tank.no-names .fish-name { display: none; }
.fish.enter { animation: fishIn .8s cubic-bezier(.3, 1.5, .5, 1); }
@keyframes fishIn { from { transform: translate(-50%, -50%) scale(0); } to { transform: translate(-50%, -50%) scale(1); } }
.fish.hello .fish-body { animation: hello 1.8s ease-in-out; }
@keyframes hello {
  0% { translate: 0 0; rotate: 0deg; } 15% { translate: 0 -4vh; rotate: -18deg; } 30% { translate: 0 -4vh; rotate: 18deg; }
  45% { translate: 0 -4vh; rotate: -18deg; } 60% { translate: 0 -4vh; rotate: 14deg; } 80% { translate: 0 0; rotate: 0deg; } 100% { translate: 0 0; }
}
.fish-bubble {
  position: absolute; bottom: calc(100% + .6vh); left: 50%; transform: translateX(-50%);
  background: #fff; color: #10203a; font-weight: 800; font-size: clamp(.9rem, 2.8vh, 2rem); line-height: 1.3;
  padding: .5em .9em; border-radius: 1.6vh; max-width: 26vw; width: max-content; text-align: center; overflow-wrap: anywhere;
  box-shadow: 0 .6vh 1.6vh rgba(0, 0, 0, .3);
}
.fish-bubble::after { content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%); border: 1vh solid transparent; border-top-color: #fff; }
.fish-bubble.pop { animation: pop .45s ease-out; }

/* Lobby scene: full-screen tank, QR on a wooden sign in the sand */
.screen-mode .s-lobby { display: flex; align-items: stretch; }
.s-lobby .tank { flex: 1; }
.tank-sand { position: absolute; left: 0; right: 0; bottom: 0; height: 12%; z-index: 0; pointer-events: none;
  background: radial-gradient(120% 140% at 50% 100%, #e9cf98 0%, #d3b06e 55%, rgba(211, 176, 110, 0) 100%); }
.tank-top { position: absolute; top: 2.4vh; left: 2vw; right: 2vw; display: flex; align-items: flex-start; justify-content: space-between; gap: 2vw; z-index: 3; pointer-events: none; }
.tank-top .lobby-count { text-shadow: 0 .3vh 1vh rgba(0, 20, 60, .6); }
.tank-top .s-message { max-width: 55%; background: rgba(0, 30, 70, .45); }
.tank-sign { position: absolute; right: 2.5vw; bottom: 3vh; z-index: 3; display: flex; flex-direction: column; align-items: center; }
.sign-board {
  display: grid; justify-items: center; gap: 1vh; text-align: center;
  padding: 2vh 2vw 1.6vh; border-radius: 2vh;
  background: linear-gradient(180deg, #a8743f, #7a4f26);
  border: .8vh solid #5b3816;
  box-shadow: 0 1.4vh 3vh rgba(0, 0, 0, .45), inset 0 .3vh 0 rgba(255, 255, 255, .25);
  background-image: repeating-linear-gradient(0deg, rgba(0, 0, 0, .08) 0 .25vh, transparent .25vh 3.2vh), linear-gradient(180deg, #a8743f, #7a4f26);
}
.sign-board .lobby-k { color: #fff7e6; text-shadow: 0 .25vh 0 rgba(0, 0, 0, .35); }
.sign-board .qr-box { width: clamp(120px, 22vh, 280px); border-radius: 1.2vh; padding: 1.1vh; }
.sign-board .join-code { color: #ffe27a; text-shadow: 0 .3vh 0 rgba(0, 0, 0, .4); font-size: clamp(1.4rem, 4.6vh, 3.6rem); }
.sign-url { color: rgba(255, 247, 230, .85); font-size: clamp(.65rem, 1.5vh, 1.1rem); max-width: 26vh; text-align: center; }
.sign-post { width: 2.2vh; height: 5vh; background: linear-gradient(90deg, #6a4420, #8b5a2b, #6a4420); border-radius: 0 0 .6vh .6vh; margin-top: -.4vh; }
.tank-deco { display: flex; justify-content: space-around; letter-spacing: 0; padding-left: 30vw; }
.tank-deco span:nth-child(odd) { animation: sway 4s ease-in-out infinite alternate; transform-origin: bottom center; display: inline-block; }
@keyframes sway { from { transform: rotate(-6deg); } to { transform: rotate(6deg); } }

/* ===== Full-screen scene behind every stage (the theme, maxed). Content floats on top. ===== */
.tank.scene { position: fixed; inset: 0; border-radius: 0; border: 0; z-index: 0; box-shadow: inset 0 0 14vh rgba(0, 20, 60, .45); }
.quiz-pane > .s-head, .quiz-pane > .s-lost, .quiz-pane > .s-stage { position: relative; z-index: 2; }
.scene:not(.in-lobby) .lobby-only { display: none !important; }
.scene:not(.in-lobby) .fish { opacity: .55; }
.scene:not(.in-lobby) .fish-bubble { display: none; }
.scene .tank-top { top: 11vh; left: 3vw; right: 3vw; }
.s-head .s-event { text-shadow: 0 .3vh 1.2vh rgba(0, 0, 0, .55); }
/* Readable on top of the scene */
.sq-text { background: rgba(0, 12, 35, .5); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); border-radius: 2.2vh; padding: 1.4vh 2.6vw; }
.answered-box { background: rgba(0, 12, 35, .45); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); border-radius: 2vh; padding: 1.2vh 1.8vw; }
.time-up { text-shadow: 0 .4vh 1.4vh rgba(0, 0, 0, .6); }
.board-title, .thanks, .s-wait h2, .ready-k, .ready-next { text-shadow: 0 .3vh 1.4vh rgba(0, 0, 0, .6); }
.board-list.big li { background: rgba(0, 12, 35, .55); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.board-list.big li:nth-child(1) { background: rgba(160, 120, 10, .6); }
.board-list.big li:nth-child(2) { background: rgba(120, 125, 145, .55); }
.board-list.big li:nth-child(3) { background: rgba(140, 80, 35, .55); }
.board-list.rest li { background: rgba(0, 12, 35, .5); }
.ready-main { background: rgba(0, 12, 35, .42); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); border-radius: 3vh; padding: 3vh 3vw; }
.ready-side { background: rgba(0, 12, 35, .45); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
/* Theme water + floor (the old full-screen emoji strips are replaced by the scene's own decorations) */
body[data-theme="kids"] .scene { background: radial-gradient(120% 60% at 50% -10%, rgba(255, 255, 255, .45), transparent 60%), linear-gradient(180deg, #7fe0ff 0%, #2ea0ff 55%, #1563c9 100%); }
body[data-theme="cyber"] .scene { background: linear-gradient(180deg, #06261a 0%, #031510 55%, #010805 100%); }
body[data-theme="science"] .scene { background: radial-gradient(90% 60% at 80% 10%, rgba(94, 231, 255, .18), transparent 60%), linear-gradient(180deg, #123a75 0%, #071733 60%, #030a1a 100%); }
body[data-theme="party"] .scene { background: radial-gradient(90% 60% at 20% 0%, rgba(255, 210, 87, .28), transparent 60%), linear-gradient(180deg, #8a1420 0%, #4a070d 60%, #2a0306 100%); }
body[data-theme="cyber"] .tank-sand { background: linear-gradient(180deg, transparent, rgba(57, 255, 136, .12)); }
body[data-theme="science"] .tank-sand { background: linear-gradient(180deg, transparent, rgba(94, 231, 255, .12)); }
body[data-theme="party"] .tank-sand { background: linear-gradient(180deg, transparent, rgba(255, 210, 87, .18)); }
/* Theme patterns live inside the scene (in place of the light rays) */
body[data-theme] .scene::before { animation: none; inset: 0; }
body[data-theme="kids"] .scene::before {
  background:
    radial-gradient(circle at 8% 22%, rgba(255, 255, 255, .3) 0 3.2vh, transparent 3.3vh),
    radial-gradient(circle at 92% 16%, rgba(255, 225, 77, .55) 0 2.4vh, transparent 2.5vh),
    radial-gradient(circle at 80% 70%, rgba(255, 79, 139, .4) 0 3.6vh, transparent 3.7vh),
    radial-gradient(circle at 20% 64%, rgba(124, 77, 255, .35) 0 2.8vh, transparent 2.9vh);
}
body[data-theme="cyber"] .scene::before {
  background:
    repeating-linear-gradient(0deg, rgba(57, 255, 136, .05) 0 1px, transparent 1px 4px),
    linear-gradient(rgba(57, 255, 136, .08) 1px, transparent 1px) 0 0 / 6vh 6vh,
    linear-gradient(90deg, rgba(57, 255, 136, .08) 1px, transparent 1px) 0 0 / 6vh 6vh;
}
body[data-theme="science"] .scene::before {
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='104' viewBox='0 0 120 104'%3E%3Cpath d='M30 2h60l30 50-30 50H30L0 52z' fill='none' stroke='%235ee7ff' stroke-opacity='.1' stroke-width='2'/%3E%3C/svg%3E") 0 0 / 12vh auto;
}
body[data-theme="party"] .scene::before { background: repeating-linear-gradient(135deg, rgba(255, 210, 87, .06) 0 2vh, transparent 2vh 6vh); }
.screen-mode[data-theme="kids"] #screenView::after, .screen-mode[data-theme="science"] #screenView::after, .screen-mode[data-theme="party"] #screenView::after { display: none; }
.screen-mode[data-theme="cyber"] #screenView::after { z-index: 1; }

/* Auto mode countdown (reveal / leaderboard) */
.s-auto {
  position: fixed; z-index: 5; right: 2.5vw; bottom: 3vh; display: flex; align-items: center; gap: 1vw;
  padding: 1vh 1.6vw; border-radius: 99px; font-weight: 800; font-size: clamp(1rem, 3vh, 2.2rem);
  background: rgba(0, 12, 35, .6); border: 1px solid var(--card-line); color: var(--muted);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.s-auto b { display: grid; place-items: center; min-width: 1.9em; height: 1.9em; border-radius: 50%; background: var(--accent); color: #111; }

/* Start-time countdown (lobby) */
.s-clock {
  position: absolute; z-index: 3; top: 10vh; left: 50%; transform: translateX(-50%);
  display: grid; justify-items: center; gap: .6vh; text-align: center; padding: 1.6vh 3vw 1.8vh;
  background: rgba(0, 12, 35, .55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--card-line); border-radius: 3vh; box-shadow: 0 1vh 3vh rgba(0, 0, 0, .35);
}
.clock-k { font-size: clamp(1.1rem, 3.2vh, 2.4rem); font-weight: 800; color: var(--muted); }
.clock-k .num { color: var(--ink); }
.clock-left { font-size: clamp(2.6rem, 10vh, 8rem); line-height: 1; color: var(--accent); text-shadow: 0 .4vh 1.6vh rgba(0, 0, 0, .5); }
.clock-note { font-size: clamp(.9rem, 2.4vh, 1.8rem); color: var(--muted); }
.s-clock.soon .clock-left { animation: beat 1s ease-in-out infinite; }
.s-clock.due .clock-left { font-size: clamp(1.8rem, 6vh, 5rem); color: var(--ok); animation: none; }
/* In the lobby the clock sits at the top centre: keep the count left and the welcome right */
/* Lobby: the countdown sits in the corner with the QR sign (moved there by screen.js) */
.tank-sign .s-clock { position: static; transform: none; margin-bottom: 1.2vh; padding: 1.1vh 1.6vw 1.3vh; gap: .3vh; width: 100%; box-sizing: border-box; }
.tank-sign .clock-k { font-size: clamp(.9rem, 2.4vh, 1.8rem); }
.tank-sign .clock-left { font-size: clamp(1.6rem, 5.4vh, 4.2rem); }
.tank-sign .clock-note { display: none; }
.tank-sign .s-clock.due .clock-left { font-size: clamp(1.1rem, 3.4vh, 2.6rem); }
.clock-phone { font-weight: 800; color: var(--accent); background: rgba(0, 0, 0, .25); border-radius: 12px; padding: 10px 14px; margin: 0; }

/* Phone: my fish + hello + message */
.fish-box { display: grid; gap: 10px; margin-top: 8px; text-align: center; }
.fish-me { font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px; }
.fish-me-emoji { font-size: 3rem; line-height: 1; }
.shout-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.shout-row .btn { width: auto; }

/* Host messages on the big screen (before / after the event) */
.s-message { font-size: clamp(1.1rem, 3.4vh, 2.6rem); line-height: 1.45; white-space: pre-line; background: rgba(255, 255, 255, .08); border: 1px solid var(--card-line); border-radius: 2vh; padding: 1.6vh 2vw; overflow-wrap: anywhere; max-width: 70vw; }
.s-wait .s-message { text-align: center; }

/* Get Ready */
.s-ready { display: grid; grid-template-columns: 1fr auto; gap: 4vw; align-items: center; }
.ready-main { display: grid; gap: 2.4vh; align-content: center; min-width: 0; }
.ready-k { font-size: clamp(2.6rem, 10vh, 8rem); font-weight: 900; color: var(--accent); line-height: 1.05; animation: pop .6s ease-out; }
.ready-next { font-size: clamp(1.4rem, 4.6vh, 3.6rem); font-weight: 800; }
.ready-info { font-size: clamp(1.1rem, 3.6vh, 2.8rem); line-height: 1.45; white-space: pre-line; background: rgba(255, 255, 255, .08); border: 1px solid var(--card-line); border-radius: 2vh; padding: 2vh 2.4vw; overflow-wrap: anywhere; }
.ready-how { margin: 0; padding-left: 1.4em; display: grid; gap: 1vh; font-size: clamp(1rem, 3vh, 2.2rem); color: var(--muted); }
.ready-side { display: grid; gap: 1.6vh; justify-items: center; text-align: center; background: rgba(255, 255, 255, .06); border: 1px solid var(--card-line); border-radius: 3vh; padding: 3vh 2vw; }
.ready-side .qr-box { width: clamp(150px, 30vh, 380px); border-radius: 2vh; padding: 1.6vh; }
.ready-side .join-code { font-size: clamp(1.8rem, 6vh, 5rem); }
.ready-players { font-size: clamp(1rem, 3vh, 2.2rem); font-weight: 800; }
.ready-next-phone { font-size: 1.2rem; font-weight: 800; color: var(--accent); margin: 0; }
.ready-info-phone { white-space: pre-line; text-align: left; background: rgba(0, 0, 0, .2); border-radius: 12px; padding: 12px 14px; line-height: 1.6; overflow-wrap: anywhere; }
@media (max-aspect-ratio: 4/3) { .s-ready { grid-template-columns: 1fr; } }

/* Leaderboard */
.s-board { display: grid; grid-template-rows: auto 1fr; gap: 3vh; justify-items: center; }
.board-title { font-size: clamp(1.8rem, 5vh, 4rem); color: var(--accent); text-align: center; }
.s-board .board-list.big { width: min(1100px, 80vw); gap: 1vh; align-content: start; }
.board-list.big li { font-size: clamp(1rem, 3.4vh, 2.6rem); padding: .9vh 2vw; border-radius: 1.4vh; }
.board-list.big li:nth-child(1) { background: rgba(255, 210, 63, .28); }
.board-list.big li:nth-child(2) { background: rgba(220, 225, 240, .2); }
.board-list.big li:nth-child(3) { background: rgba(214, 140, 80, .22); }

/* Ended: podium */
.s-ended { display: grid; grid-template-rows: auto 1fr auto auto; gap: 2vh; justify-items: center; }
.podium { display: flex; align-items: flex-end; gap: 2vw; height: 100%; min-height: 0; }
.podium-col { display: flex; flex-direction: column; align-items: center; gap: 1vh; width: clamp(140px, 22vw, 360px); animation: rise .9s ease-out both; }
.podium-col.p2 { animation-delay: .3s; } .podium-col.p3 { animation-delay: .6s; }
@keyframes rise { from { transform: translateY(30vh); opacity: 0; } to { transform: none; opacity: 1; } }
.p-name { font-size: clamp(1.3rem, 4.4vh, 3.4rem); font-weight: 900; text-align: center; overflow-wrap: anywhere; }
.p-score { font-size: clamp(1rem, 3vh, 2.2rem); color: var(--muted); }
.p-correct { font-size: clamp(.85rem, 2.4vh, 1.8rem); font-weight: 700; color: var(--ok); }
.b-correct { font-size: .8em; font-weight: 700; color: var(--ok); white-space: nowrap; }
.b-correct:empty { display: none; }
.p-block { width: 100%; display: grid; place-items: center; font-size: clamp(2.4rem, 9vh, 7rem); color: #1a1240; border-radius: 2vh 2vh 0 0; }
.p1 .p-block { height: 30vh; background: linear-gradient(180deg, #ffe680, #ffc21a); }
.p2 .p-block { height: 22vh; background: linear-gradient(180deg, #f2f4fa, #b9c0d4); }
.p3 .p-block { height: 16vh; background: linear-gradient(180deg, #f3c39b, #c97f45); }
.board-list.rest { width: min(900px, 70vw); grid-template-columns: 1fr 1fr; }
.board-list.rest li { font-size: clamp(.9rem, 2.4vh, 1.8rem); }
.thanks { font-size: clamp(1.2rem, 3.4vh, 2.6rem); font-weight: 800; margin: 0; }

/* Paused overlay */
.s-paused {
  position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2vh;
  background: rgba(10, 8, 30, .82); backdrop-filter: blur(6px); text-align: center;
}
.s-paused .paused-icon { font-size: clamp(3rem, 14vh, 10rem); }
.s-paused h2 { font-size: clamp(2rem, 7vh, 5rem); }
.s-paused p { font-size: clamp(1.1rem, 3.4vh, 2.4rem); color: var(--muted); margin: 0; }


/* ===================== Themes (Settings → Screen → Theme) =====================
   Set on <body data-theme="…"> by screen.js / app.js from events/{id}.screen.theme.
   Each theme swaps the colour tokens and adds a decorative background layer on the big screen. */
body[data-theme="kids"] {
  --bg1: #1f6fd1; --bg2: #39a0ff; --bg3: #0f3f8f;
  --accent: #ffe14d; --accent-2: #ff8a3d; --card: rgba(255, 255, 255, .14); --card-line: rgba(255, 225, 77, .55);
  --o0: #ff4f8b; --o1: #7c4dff; --o2: #ffc400; --o2-ink: #3a2400; --o3: #00c48c;
  --font: "Arial Rounded MT Bold", "SF Pro Rounded", "Hiragino Maru Gothic ProN", "Yuanti TC", "PingFang TC", system-ui, sans-serif;
  --radius: 26px;
}
body[data-theme="cyber"] {
  --bg1: #03100a; --bg2: #062a17; --bg3: #000;
  --accent: #39ff88; --accent-2: #00d9ff; --ink: #d9ffe9; --muted: rgba(217, 255, 233, .65);
  --card: rgba(57, 255, 136, .06); --card-line: rgba(57, 255, 136, .45);
  --o0: #ff3d5a; --o1: #1e90ff; --o2: #ffd23f; --o3: #00c070;
  --font: "SF Mono", "Menlo", "Consolas", "Noto Sans Mono CJK TC", "PingFang TC", monospace;
  --num: "SF Mono", "Menlo", "Consolas", monospace;
  --radius: 6px;
}
body[data-theme="science"] {
  --bg1: #071a3a; --bg2: #0d3b73; --bg3: #020a1c;
  --accent: #5ee7ff; --accent-2: #3d8bff; --card: rgba(94, 231, 255, .07); --card-line: rgba(94, 231, 255, .4);
  --o0: #ff5c7a; --o1: #4f7dff; --o2: #ffcf3d; --o3: #2fd6a0;
}
body[data-theme="party"] {
  --bg1: #5b0b12; --bg2: #a3141f; --bg3: #2a0307;
  --accent: #ffd257; --accent-2: #ffae2b; --card: rgba(255, 210, 87, .08); --card-line: rgba(255, 210, 87, .5);
  --o0: #ff5a4e; --o1: #2f7de8; --o2: #ffcc33; --o3: #1fae6e;
}
/* Decorative layers (big screen only; behind the content, ignore clicks) */
.screen-mode[data-theme] .quiz-pane { padding-bottom: 6.5vh; }
.screen-mode[data-theme] #screenView::before { content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 1; }
.screen-mode #pairPane, .screen-mode #quizPane { position: relative; z-index: 1; }
.screen-mode[data-theme="kids"] #screenView::before {
  background:
    radial-gradient(circle at 8% 18%, rgba(255, 255, 255, .25) 0 3.2vh, transparent 3.3vh),
    radial-gradient(circle at 92% 12%, rgba(255, 225, 77, .5) 0 2.4vh, transparent 2.5vh),
    radial-gradient(circle at 85% 88%, rgba(255, 79, 139, .45) 0 3.6vh, transparent 3.7vh),
    radial-gradient(circle at 12% 85%, rgba(0, 196, 140, .45) 0 2.8vh, transparent 2.9vh),
    radial-gradient(circle at 50% 96%, rgba(124, 77, 255, .4) 0 2vh, transparent 2.1vh);
}
.screen-mode[data-theme="kids"] #screenView::after {
  content: "⭐ 🎈 🍭 🎉 🌈"; position: fixed; right: 2vw; bottom: 1vh; font-size: 4vh; letter-spacing: 1vw; opacity: .85; pointer-events: none; z-index: 0;
}
.screen-mode[data-theme="kids"] .opt, .screen-mode[data-theme="kids"] .name-chip { border-radius: 999px; }
.screen-mode[data-theme="kids"] .name-chip.pop { animation: bounce .7s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes bounce { 0% { transform: scale(.2) rotate(-20deg); } 100% { transform: none; } }
.screen-mode[data-theme="cyber"] #screenView::before {
  background:
    repeating-linear-gradient(0deg, rgba(57, 255, 136, .05) 0 1px, transparent 1px 4px),
    linear-gradient(rgba(57, 255, 136, .07) 1px, transparent 1px) 0 0 / 6vh 6vh,
    linear-gradient(90deg, rgba(57, 255, 136, .07) 1px, transparent 1px) 0 0 / 6vh 6vh;
}
.screen-mode[data-theme="cyber"] #screenView::after {
  content: "🔒 FIREWALL: ACTIVE  ·  ACCESS GRANTED  ·  ENCRYPTED"; position: fixed; left: 3vw; bottom: 1.2vh;
  font: 700 1.6vh var(--num); letter-spacing: .3em; color: rgba(57, 255, 136, .55); pointer-events: none; z-index: 0;
}
.screen-mode[data-theme="cyber"] .s-event, .screen-mode[data-theme="cyber"] .ready-k, .screen-mode[data-theme="cyber"] .board-title { text-shadow: 0 0 1.2vh rgba(57, 255, 136, .7); }
.screen-mode[data-theme="cyber"] .s-event::before { content: "> "; }
.screen-mode[data-theme="cyber"] .opt { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .25), 0 0 2vh rgba(57, 255, 136, .15); }
.screen-mode[data-theme="cyber"] .ring-fg { filter: drop-shadow(0 0 .8vh var(--accent)); }
.screen-mode[data-theme="science"] #screenView::before {
  background:
    radial-gradient(circle at 85% 20%, rgba(94, 231, 255, .14), transparent 30vh),
    radial-gradient(circle at 10% 90%, rgba(61, 139, 255, .16), transparent 34vh),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='104' viewBox='0 0 120 104'%3E%3Cpath d='M30 2h60l30 50-30 50H30L0 52z' fill='none' stroke='%235ee7ff' stroke-opacity='.08' stroke-width='2'/%3E%3C/svg%3E") 0 0 / 12vh auto;
}
.screen-mode[data-theme="science"] #screenView::after {
  content: "⚛︎  🧪  🔭  🧬"; position: fixed; right: 2.4vw; bottom: 1vh; font-size: 3.4vh; letter-spacing: 1.2vw; opacity: .55; pointer-events: none; z-index: 0;
}
.screen-mode[data-theme="party"] #screenView::before {
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 210, 87, .25), transparent 22vh),
    radial-gradient(circle at 85% 15%, rgba(255, 210, 87, .18), transparent 26vh),
    repeating-linear-gradient(135deg, rgba(255, 210, 87, .05) 0 2vh, transparent 2vh 6vh);
}
.screen-mode[data-theme="party"] #screenView::after {
  content: "🎊 🧧 🎉 🥂 🎊"; position: fixed; left: 50%; transform: translateX(-50%); bottom: .6vh; font-size: 3.6vh; letter-spacing: 1.4vw; opacity: .8; pointer-events: none; z-index: 0;
}
.screen-mode[data-theme="party"] .s-event, .screen-mode[data-theme="party"] .board-title, .screen-mode[data-theme="party"] .ready-k { text-shadow: 0 .3vh 0 rgba(0, 0, 0, .35), 0 0 2vh rgba(255, 210, 87, .45); }

@media (max-aspect-ratio: 4/3) {
  .s-lobby { grid-template-columns: 1fr; }
  .opts-screen { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
