:root {
  --bg: #0b1a33; --bg2: #16305a; --red: #e63946; --green: #2b9348; --gold: #ffd166;
  --ink: #fff8ee; --muted: #b9c6e4; --card: rgba(255,255,255,.08); --line: rgba(255,255,255,.16);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body {
  font-family: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
  color: var(--ink);
  background: radial-gradient(ellipse at 50% 0%, var(--bg2), var(--bg) 70%) fixed;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
  overflow: hidden;
}
#app { position: relative; z-index: 1; height: 100%; display: flex; flex-direction: column; }
.snow { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- 共用 ---------- */
.screen { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 16px; text-align: center; overflow: auto; }
.big-title { font-size: clamp(24px, 5vw, 44px); font-weight: 900; text-shadow: 0 3px 0 rgba(0,0,0,.25); }
.sub { font-size: clamp(16px, 3vw, 24px); color: var(--muted); }
.sub.warn { color: var(--gold); }
.row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.btn { border: 0; border-radius: 999px; padding: 14px 34px; font-size: clamp(18px, 3.4vw, 28px); font-weight: 800; box-shadow: 0 5px 0 rgba(0,0,0,.3); transition: transform .08s; }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,.3); }
.btn.big { padding: 18px 60px; font-size: clamp(24px, 5vw, 40px); }
.btn-red { background: var(--red); }
.btn-green { background: var(--green); }
.btn-gold { background: var(--gold); color: #3b2a00; }
.btn-ghost { background: rgba(255,255,255,.15); }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; margin-top: 20px; font-size: 15px; }

.avatar { display: inline-grid; place-items: center; border-radius: 50%; box-shadow: 0 0 0 4px rgba(255,255,255,.85), 0 6px 16px rgba(0,0,0,.35); flex: none; line-height: 1; }
.av-s { width: 40px; height: 40px; font-size: 24px; box-shadow: 0 0 0 2px #fff; }
.av-m { width: 72px; height: 72px; font-size: 42px; }
.av-l { width: 100px; height: 100px; font-size: 58px; }
.av-xl { width: 150px; height: 150px; font-size: 90px; }

.topbar { position: relative; z-index: 2; display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: rgba(0,0,0,.28); border-bottom: 1px solid var(--line); }
.tb-name { font-weight: 800; font-size: 20px; }
.tb-prog { margin-left: auto; font-size: 18px; letter-spacing: 2px; }
.tb-stars { margin-left: auto; font-weight: 900; font-size: 22px; color: var(--gold); }
.tb-prog + .tb-stars { margin-left: 12px; }

.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.6); display: grid; place-items: center; }
.modal-box { background: var(--bg2); border: 2px solid var(--line); border-radius: 28px; padding: 30px 40px; display: flex; flex-direction: column; align-items: center; gap: 16px; }

.confetti { position: fixed; top: -50px; z-index: 60; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

/* ---------- 選人 ---------- */
.pick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; width: min(640px, 96vw); }
.pick-btn { background: var(--card); border: 2px solid var(--line); border-radius: 22px; padding: 14px 6px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.pick-btn:active { transform: scale(.96); }
.pick-btn.taken { opacity: .45; }
.pick-name { font-size: 22px; font-weight: 900; }
.pick-grade { font-size: 14px; color: var(--muted); }

/* ---------- 任務 ---------- */
.quest.playing { justify-content: flex-start; padding-top: 10px; }
.intro-icon { font-size: clamp(70px, 16vw, 130px); }
.bounce { animation: bounce 1s infinite; }
@keyframes bounce { 50% { transform: translateY(-16px); } }
.result-stars { font-size: clamp(60px, 14vw, 110px); color: var(--gold); animation: pop .5s; }
.result-stars.small { font-size: clamp(30px, 7vw, 54px); }
@keyframes pop { from { transform: scale(.3); opacity: 0; } }
.game-hud { font-size: 22px; font-weight: 800; color: var(--gold); }

.flip { perspective: 800px; cursor: pointer; }
.flip .inner { position: relative; width: 100%; height: 100%; transition: transform .5s; transform-style: preserve-3d; }
.flip.flipped .inner { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 16px; display: grid; place-items: center; }
.face.back { transform: rotateY(180deg); }

.mem-grid { display: grid; gap: 10px; }
.mem-grid.cols2 { grid-template-columns: repeat(2, 1fr); width: min(70vw, 52vh); }
.mem-grid.cols4 { grid-template-columns: repeat(4, 1fr); width: min(94vw, 68vh); }
.mem-card { aspect-ratio: 1; }
.mem-card .front { background: linear-gradient(135deg, #c1121f, #e63946); border: 3px solid #fff3; font-size: min(7vw, 5vh); }
.mem-card .back { background: #fffaf0; font-size: min(11vw, 8vh); }
.cols2 .mem-card .back { font-size: min(22vw, 16vh); }
.mem-card.matched .back { box-shadow: 0 0 0 5px var(--gold), 0 0 24px var(--gold); }

.catch-cv { position: relative; width: min(96vw, 900px); flex: 1; min-height: 60vh; background: rgba(255,255,255,.05); border: 2px solid var(--line); border-radius: 20px; overflow: hidden; }
.catch-cv canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }

.odd-grid { display: grid; gap: 8px; width: min(94vw, 68vh); }
.odd-cell { aspect-ratio: 1; background: rgba(255,255,255,.92); border: 0; border-radius: 14px; display: grid; place-items: center; padding: 0; line-height: 1; }
.odd-cell.right { background: var(--gold); transform: scale(1.1); }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

.fate-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; width: min(94vw, 760px); }
.fate-card { aspect-ratio: 3/4; transition: opacity .4s, transform .3s; }
.fate-card .front { font-size: clamp(20px, 4vw, 32px); font-weight: 900; border: 4px solid #fff6; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.fate-card .front.chance { background: linear-gradient(160deg, #e63946, #9d0208); }
.fate-card .front.fate { background: linear-gradient(160deg, #2b9348, #145a32); }
.fate-q { font-size: clamp(36px, 8vw, 64px); }
.fate-card .back { background: #fffaf0; color: #222; padding: 8px; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.fate-icon { font-size: clamp(34px, 7vw, 56px); }
.fate-text { font-weight: 800; font-size: clamp(13px, 2.4vw, 20px); }
.fate-stars { color: #b8860b; font-weight: 900; }
.fate-card.chosen { transform: scale(1.06); z-index: 2; }
.fate-card.chosen .back { box-shadow: 0 0 0 5px var(--gold), 0 0 30px var(--gold); }
.fate-card.dim { opacity: .45; }
.fate-action { min-height: 70px; }
.countdown { font-size: 60px; font-weight: 900; color: var(--gold); }

/* ---------- 抽禮物（平板） ---------- */
.draw-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; width: min(94vw, 720px); }
.draw-card { aspect-ratio: 3/4; transition: opacity .4s, transform .3s; }
.draw-card .front { background: linear-gradient(160deg, #e63946, #2b9348); border: 4px solid #fff8; font-size: clamp(40px, 9vw, 70px); }
.draw-card .back { flex-direction: column; display: flex; justify-content: center; border: 4px solid #fff; }
.draw-emoji { font-size: clamp(40px, 9vw, 70px); }
.draw-name { font-weight: 900; font-size: clamp(18px, 3.5vw, 28px); text-shadow: 0 2px 0 rgba(0,0,0,.3); }
.draw-card.chosen { transform: scale(1.12); z-index: 2; box-shadow: 0 0 40px var(--gold); border-radius: 16px; }
.draw-card.dim { opacity: .4; }
.draw-card.suspense { animation: suspense .3s infinite; }
@keyframes suspense { 0%,100% { transform: rotate(-4deg) scale(1.05); } 50% { transform: rotate(4deg) scale(1.1); } }
.draw-grid > .draw-card:only-child { grid-column: 2 / span 2; }

.pair-line { display: flex; align-items: center; gap: 10px; font-size: clamp(18px, 3.6vw, 28px); }
.pair-line.big { font-size: clamp(22px, 4.6vw, 36px); }

/* ---------- 搗蛋精靈 ---------- */
.boss-emoji { font-size: 140px; }
.shake-hard { animation: shakeHard .25s infinite; }
@keyframes shakeHard { 25% { transform: translate(-6px, 3px) rotate(-4deg); } 75% { transform: translate(6px, -3px) rotate(4deg); } }
.hp-bar { width: min(90vw, 700px); height: 28px; border-radius: 99px; background: rgba(255,255,255,.15); border: 2px solid #fff6; overflow: hidden; }
.hp-bar.tv { height: 44px; width: 70vw; }
.hp-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #ff006e, #e63946); transition: width .3s; }
.arena { position: relative; width: min(96vw, 900px); flex: 1; min-height: 55vh; border-radius: 20px; background: rgba(80,0,40,.25); border: 2px dashed #ff6b9d88; overflow: hidden; touch-action: none; }
.boss-target { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font-size: 170px; line-height: 1; cursor: pointer; }
.boss-target.slow, .boss-target.fast { transform: none; font-size: 110px; transition: left .9s ease-in-out, top .9s ease-in-out; }
.boss-target.fast { font-size: 90px; transition-duration: .6s; }
.boss-target.hit { animation: hitFlash .15s; }
@keyframes hitFlash { 50% { filter: brightness(2) drop-shadow(0 0 20px #fff); scale: 0.9; } }
.snowball { position: absolute; font-size: 40px; pointer-events: none; transform: translate(-50%, -50%); animation: burst .5s forwards; }
@keyframes burst { to { opacity: 0; transform: translate(-50%, -50%) scale(2.2) rotate(90deg); } }
body.glitch { animation: glitch .12s steps(2) infinite; }
@keyframes glitch { 0% { filter: hue-rotate(0) invert(0); transform: translate(0); } 50% { filter: hue-rotate(120deg) invert(1); transform: translate(-10px, 4px); } }

/* ---------- 電視 ---------- */
body.tv { font-size: 1.6vw; }
.tv-screen { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2.2vh; padding: 3vh 3vw 10vh; text-align: center; }
.tv-title { font-size: 4.2vw; font-weight: 900; text-shadow: 0 4px 0 rgba(0,0,0,.3); }
.tv-title.small { font-size: 3vw; }
.tv-sub { font-size: 2vw; color: var(--muted); }
.tv-sub.gold { color: var(--gold); font-weight: 800; }
.lobby-row { display: flex; gap: 4vw; align-items: center; }
.qr-card { background: #fff; border-radius: 24px; padding: 16px; color: #333; }
.qr { width: 24vw; height: 24vw; }
.qr svg { width: 100%; height: 100%; }
.qr-url { font-size: 1vw; word-break: break-all; max-width: 24vw; }
.lobby-right { display: flex; flex-direction: column; gap: 2vh; align-items: center; }
.tv-row { display: flex; gap: 1.4vw; flex-wrap: wrap; justify-content: center; max-width: 60vw; }
.tv-tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 1vh 1vw; border-radius: 18px; background: var(--card); border: 2px solid var(--line); opacity: .4; min-width: 8vw; }
.tv-tile.on { opacity: 1; }
.tv-tile .small { font-size: 1.1vw; color: var(--muted); }
.tv-grid { display: grid; grid-template-columns: repeat(9, 1fr); gap: 1vw; width: 94vw; }
.tv-tile.big { padding: 2vh .5vw; }
.tile-name { font-weight: 900; font-size: 1.6vw; }
.tile-stars { font-weight: 900; font-size: 1.8vw; color: var(--gold); }
.tile-prog { font-size: 1.1vw; }
.crown { position: absolute; top: -2.4vw; font-size: 3vw; animation: bounce 1s infinite; }
.ticker { min-height: 20vh; display: flex; flex-direction: column; gap: 1vh; font-size: 1.9vw; }
.tick-item { background: rgba(0,0,0,.25); padding: .6vh 2vw; border-radius: 99px; }
.tick-item:first-child { animation: pop .4s; color: var(--gold); }

.reveal-row { display: flex; align-items: center; gap: 4vw; }
.giver { display: flex; flex-direction: column; align-items: center; gap: 1vh; }
.giver .av-xl { width: 14vw; height: 14vw; font-size: 8.5vw; }
.tv-name { font-size: 3vw; font-weight: 900; }
.arrow-big { font-size: 6vw; color: var(--gold); }
.slot { width: 20vw; height: 24vw; border-radius: 3vw; background: rgba(255,255,255,.1); border: .5vw solid #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: 0 0 40px rgba(255,209,102,.4); }
.slot-q { font-size: 10vw; animation: bounce 1s infinite; }
.slot-emoji { font-size: 11vw; line-height: 1; }
.slot-name { font-size: 3.4vw; font-weight: 900; text-shadow: 0 3px 0 rgba(0,0,0,.3); }
.slot.final { animation: pop .5s; box-shadow: 0 0 80px var(--gold); }
.slot.wobble { animation: suspense .25s infinite; }
.strip { display: flex; gap: .8vw; font-size: 2.6vw; }
.strip-item { opacity: .35; }
.strip-item.done { opacity: 1; }
.strip-item.cur { opacity: 1; transform: scale(1.4); filter: drop-shadow(0 0 10px var(--gold)); }

.pairs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.4vh 2vw; }
.pair { display: flex; align-items: center; gap: .8vw; font-size: 2vw; font-weight: 800; background: var(--card); padding: 1vh 1.4vw; border-radius: 99px; }
.pair .arrow { color: var(--gold); }
.pair .av-s { width: 3vw; height: 3vw; font-size: 1.8vw; }

.setup-status { font-size: 1.2vw; color: #69db7c; background: rgba(0,0,0,.3); padding: .6vh 1.4vw; border-radius: 99px; }
.setup-status.bad { color: #ffa8a8; }

.boss-bg { background: radial-gradient(circle, rgba(120,0,60,.5), transparent 70%); }
.tv-boss { font-size: 18vw; line-height: 1; }
.tv-boss.hit { animation: hitFlash .15s; }
.speech { font-size: 3vw; font-weight: 900; background: #fff; color: #5a0030; padding: 1.5vh 3vw; border-radius: 40px; min-height: 5vw; min-width: 30vw; }
.hitter { display: flex; align-items: center; gap: .5vw; font-size: 1.6vw; font-weight: 800; }

#hostbar { position: fixed; z-index: 40; left: 50%; bottom: 1.2vh; transform: translateX(-50%); display: flex; gap: 10px; opacity: .35; transition: opacity .2s; }
#hostbar:hover, #hostbar:focus-within { opacity: 1; }
.hb { white-space: nowrap; background: rgba(0,0,0,.55); border: 1px solid var(--line); border-radius: 99px; padding: 10px 20px; font-size: 16px; color: #fff; }
.hb.main { background: var(--red); font-weight: 800; font-size: 20px; }
.hb.danger { background: rgba(120,0,0,.6); }
select.hb option { color: #000; }
.sound-hint { position: fixed; top: 12px; right: 12px; z-index: 45; background: var(--gold); color: #3b2a00; font-weight: 800; padding: 8px 16px; border-radius: 99px; animation: bounce 1.2s infinite; }
.conn { position: fixed; top: 12px; left: 12px; z-index: 45; font-size: 13px; color: var(--muted); }
.conn.ok { color: #69db7c; }
.conn.bad { color: #ff6b6b; }

.screen { justify-content: safe center; }

/* ---------- 家長設定 ---------- */
body.parent { overflow: auto; }
body.parent #app { height: auto; min-height: 100%; }
.pin { font-size: 28px; padding: 12px 20px; border-radius: 16px; border: 0; text-align: center; width: 220px; }
.p-wrap { max-width: 1100px; margin: 0 auto; padding: 20px 14px 60px; display: flex; flex-direction: column; gap: 14px; align-items: center; text-align: center; }
.p-banner { width: 100%; padding: 12px 18px; border-radius: 16px; text-align: left; font-weight: 700; }
.p-banner.ok { background: rgba(43,147,72,.3); border: 1px solid #69db7c; }
.p-banner.bad { background: rgba(230,57,70,.25); border: 1px solid #ff8787; }
.p-banner ul { margin: 6px 0 0; }
.p-banner .warn { color: var(--gold); margin-top: 6px; }
.p-list { width: 100%; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.p-card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px; display: flex; flex-direction: column; gap: 10px; text-align: left; }
.p-head { display: flex; align-items: center; gap: 10px; font-size: 20px; }
.p-grade { color: var(--muted); font-size: 14px; }
.p-saved { margin-left: auto; color: #69db7c; font-size: 14px; }
.p-fam { font-weight: 900; font-size: 18px; color: var(--gold); }
.p-row { display: grid; grid-template-columns: 40px 52px auto 1fr; align-items: center; gap: 8px; font-size: 18px; position: relative; }
.p-row .p-saved { position: absolute; right: 36px; top: -14px; font-size: 12px; }
.p-list { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.p-input { font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.92); color: #222; width: 100%; user-select: text; -webkit-user-select: text; }
@media (orientation: landscape) {
  .fate-grid { grid-template-columns: repeat(6, 1fr); width: min(96vw, 1100px, calc((100vh - 280px) * 4.5)); }
  .draw-grid { width: min(94vw, 720px, calc((100vh - 230px) * 1.45)); }
  .catch-cv, .arena { min-height: 0; }
}
@media (max-width: 600px) {
  .draw-grid { grid-template-columns: repeat(3, 1fr); }
  .av-xl { width: 120px; height: 120px; font-size: 70px; }
}

/* ---------- 試玩模式 ---------- */
body:has(.practice-bar) #app { padding-bottom: 58px; }
.practice-bar { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; display: flex; gap: 6px; align-items: center; justify-content: center; flex-wrap: wrap; padding: 8px; background: rgba(60,20,90,.92); border-top: 2px solid #b197fc; font-size: 14px; }
.practice-bar span { font-weight: 800; margin-right: 6px; }
.practice-bar button { background: rgba(255,255,255,.15); border: 1px solid #fff4; border-radius: 99px; padding: 6px 12px; font-size: 14px; }

/* ---------- 主持人頁 ---------- */
body.host { overflow: auto; }
body.host #app { height: auto; min-height: 100%; }
.h-wrap { max-width: 760px; margin: 0 auto; padding: 14px 12px 50px; display: flex; flex-direction: column; gap: 14px; }
.h-card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.h-card h3 { margin: 0; font-size: 18px; color: var(--gold); }
.h-phase { display: flex; align-items: center; justify-content: space-between; font-size: 20px; font-weight: 900; }
.h-conn { font-size: 13px; font-weight: 400; color: var(--muted); }
.h-conn.ok { color: #69db7c; } .h-conn.bad { color: #ff8787; }
.h-steps { display: flex; gap: 4px; flex-wrap: wrap; }
.h-step { font-size: 13px; padding: 4px 10px; border-radius: 99px; background: rgba(255,255,255,.08); color: var(--muted); }
.h-step.on { background: var(--red); color: #fff; font-weight: 800; }
.h-step.done { color: #69db7c; }
.h-actions { display: flex; flex-direction: column; gap: 10px; }
.h-btn { border: 0; border-radius: 16px; padding: 16px; font-size: 20px; font-weight: 900; background: var(--red); box-shadow: 0 4px 0 rgba(0,0,0,.3); }
.h-btn.sec { background: rgba(255,255,255,.14); font-size: 17px; font-weight: 700; }
.h-btn:disabled { opacity: .4; }
.h-hint { font-size: 14px; color: var(--muted); }
.h-now { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 800; flex-wrap: wrap; }
.h-players { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.h-p { display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,.2); border-radius: 12px; padding: 6px 8px; font-size: 15px; }
.h-p.off { opacity: .45; }
.h-p .h-meta { margin-left: auto; font-size: 13px; color: var(--muted); text-align: right; }
.h-links { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.h-link { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; border-radius: 14px; background: rgba(255,255,255,.08); color: inherit; text-decoration: none; font-size: 14px; font-weight: 700; }
.h-row { display: flex; gap: 8px; }
.h-row > * { flex: 1; }
.h-select { font: inherit; padding: 12px; border-radius: 12px; }
