/* 聖誕老人爬煙囪：玩家頁與主控台共用樣式。字級偏大，長輩也看得清楚（D-001）。 */
:root {
  --night: #0b1633; --night2: #16244d; --red: #d62839; --red2: #a61e2c; --green: #1f7a4d;
  --gold: #f6c453; --snow: #f4f8ff; --ink: #1d2433; --muted: #6b7488;
  --font: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 18px; color: var(--ink); background: radial-gradient(ellipse at top, #24366e, var(--night) 70%); }
[hidden] { display: none !important; }
button { font-family: inherit; cursor: pointer; }

.topbar { position: fixed; top: 0; left: 0; right: 0; z-index: 30; display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 6px) 12px 6px; color: #fff; background: rgba(8, 14, 36, .55); backdrop-filter: blur(4px); }
.brand { font-weight: 700; font-size: 16px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 12px; background: #e9a23b; color: #222; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.icon-btn { font-size: 22px; background: rgba(255,255,255,.15); border: 0; border-radius: 12px; width: 44px; height: 40px; color: #fff; }
.text-btn { background: transparent; border: 1px solid rgba(255,255,255,.5); color: #fff; border-radius: 8px; padding: 6px 12px; font-size: 15px; }
.pill { font-size: 14px; padding: 3px 10px; border-radius: 999px; background: rgba(255,255,255,.18); white-space: nowrap; }
.pill[data-phase="running"] { background: var(--green); }
.pill[data-phase="ended"] { background: var(--red); }

main { min-height: 100%; }
.screen { min-height: 100vh; min-height: 100dvh; padding: calc(env(safe-area-inset-top) + 64px) 16px 24px; }
.center { display: flex; align-items: center; justify-content: center; }
.card { background: var(--snow); border-radius: 22px; padding: 24px 20px; width: 100%; max-width: 440px; text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,.35); border-top: 8px solid var(--red); }
.card h1 { margin: 6px 0 10px; font-size: 28px; color: var(--red2); }
.hero { font-size: 56px; line-height: 1.2; }
.spin { animation: spin 3s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 15px; line-height: 1.5; }
.error { color: var(--red); font-weight: 700; }
label { display: block; text-align: left; font-weight: 700; margin: 14px 0 6px; }
input { width: 100%; font-size: 22px; padding: 12px 14px; border: 2px solid #c8d0e0; border-radius: 14px; font-family: inherit; }
input:focus { outline: none; border-color: var(--green); }
.big-btn { width: 100%; margin-top: 14px; font-size: 22px; font-weight: 700; color: #fff; background: var(--red); border: 0;
  border-radius: 16px; padding: 16px; box-shadow: 0 5px 0 var(--red2); }
.big-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--red2); }
.big-btn:disabled { opacity: .6; }
.big-btn.go { background: var(--green); box-shadow: 0 5px 0 #145536; }
.big-btn.stop { background: #444c63; box-shadow: 0 5px 0 #2a3042; }
.big-btn.warn { background: #b5651d; box-shadow: 0 5px 0 #7c4310; }
.big-btn.armed { background: #e9a23b; color: #222; box-shadow: 0 5px 0 #a86d16; }

/* 等候畫面 */
.name-tag { font-size: 32px !important; }
.waiting { font-weight: 700; color: var(--green); }
.dots-anim::after { content: '…'; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.tutorial { background: #fff; border: 2px dashed #d7dceb; border-radius: 16px; padding: 14px 10px; margin: 14px 0; min-height: 170px; }
.tut-emoji { font-size: 54px; line-height: 1.2; }
.tut-title { font-size: 22px; font-weight: 800; margin-top: 4px; }
.tut-how { font-size: 20px; color: var(--green); font-weight: 700; margin-top: 4px; }
.tut-dots { margin-top: 10px; display: flex; gap: 6px; justify-content: center; }
.tut-dots span { width: 8px; height: 8px; border-radius: 50%; background: #d7dceb; }
.tut-dots span.on { background: var(--red); }

/* 遊戲畫面 */
.screen.game { padding: 0; position: fixed; inset: 0; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hud { position: absolute; top: calc(env(safe-area-inset-top) + 56px); left: 10px; right: 34px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; z-index: 5; }
.hud-row { display: flex; justify-content: space-between; gap: 8px; }
.hud-pill.rank { background: rgba(246,196,83,.92); color: #3a2a10; }
.hud-pill.stars { margin-left: auto; font-size: 16px; }
/* 節奏連擊（D-016） */
.combo { position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 104px); transform: translateX(-50%); z-index: 5; pointer-events: none;
  text-align: center; color: #fff; font-weight: 900; font-size: 22px; text-shadow: 0 2px 6px #000; white-space: nowrap; }
.combo-bar { width: 170px; height: 10px; margin: 4px auto 0; background: rgba(255,255,255,.25); border-radius: 5px; overflow: hidden; }
#comboFill { height: 100%; width: 0; background: linear-gradient(90deg, #ffd54a, #ff7a3d); transition: width .12s; }
.combo.max { animation: pop .5s infinite alternate; }
.combo.max #comboFill { background: linear-gradient(90deg, #ff7a3d, #ff3d6e); }
@keyframes pop { to { transform: translateX(-50%) scale(1.08); } }
.hud-pill { background: rgba(8,14,36,.7); color: #fff; font-weight: 800; font-size: 18px; padding: 6px 12px; border-radius: 999px; }
.hud-pill.warn { background: var(--red); animation: blink 1s infinite; }
.tap-hint { position: absolute; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 160px); text-align: center; color: #fff; font-size: 24px; font-weight: 800;
  text-shadow: 0 2px 6px #000; animation: bounce 0.8s infinite; z-index: 4; }
@keyframes bounce { 50% { transform: translateY(-8px); } }
.overlay { position: absolute; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 70px 14px 20px; }
.countdown { background: rgba(8,14,36,.55); color: #fff; font-size: 110px; font-weight: 900; text-shadow: 0 4px 20px rgba(0,0,0,.6); }
.toast { position: absolute; left: 50%; top: 32%; transform: translateX(-50%); z-index: 12; background: rgba(255,255,255,.95); color: var(--ink);
  font-weight: 800; font-size: 20px; padding: 10px 18px; border-radius: 999px; box-shadow: 0 6px 20px rgba(0,0,0,.35); white-space: nowrap; pointer-events: none; }

/* 左右手按鍵區（D-017）：只是提示，pointer-events 關掉讓點擊落到 canvas */
.hands { position: absolute; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 12px); display: flex; justify-content: space-between;
  padding: 0 12px; pointer-events: none; z-index: 4; }
.hands::before { content: ''; position: absolute; left: 50%; bottom: 0; height: 84px; border-left: 2px dashed rgba(255,255,255,.22); }
.hand-pad { width: min(36vw, 170px); height: 84px; border-radius: 22px; display: flex; align-items: center; justify-content: center; gap: 6px;
  background: rgba(255,255,255,.12); border: 2px solid rgba(255,255,255,.28); color: rgba(255,255,255,.75); font-weight: 900; font-size: 20px;
  transition: background .12s, border-color .12s, transform .12s; }
.hand-pad .hand-ico { font-size: 34px; }
.hand-pad.L .hand-ico { transform: scaleX(-1); display: inline-block; }
.hand-pad.next { background: rgba(255,213,74,.38); border-color: #ffd54a; color: #fff; box-shadow: 0 0 18px rgba(255,213,74,.55); }
.hand-pad.hit { transform: scale(.93); }

/* 岔路 */
.fork { background: rgba(8,14,36,.72); color: #fff; }
.fork h2 { font-size: 26px; margin: 0 0 16px; text-shadow: 0 2px 8px #000; }
.lanes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; max-width: 520px; }
.lane-btn { display: flex; flex-direction: column; align-items: center; gap: 6px; background: var(--snow); border: 0; border-radius: 18px;
  padding: 14px 4px 12px; box-shadow: 0 6px 0 #9aa6c4; min-height: 150px; justify-content: center; }
.lane-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #9aa6c4; }
.lanes.wait .lane-btn { opacity: .55; }
.lane-chimney { font-size: 34px; }
.lane-name { font-size: 20px; font-weight: 800; color: var(--red2); }
.legend { font-size: 15px; line-height: 1.7; text-align: center; margin-top: 16px; color: #e8ecf8; }

/* 干擾物（D-015）：背景只淡淡壓暗，讓玩家看得到動物在鬧聖誕老人；點擊目標每幀跟著聖誕老人定位 */
.ob { background: linear-gradient(180deg, rgba(8,14,36,.55) 0, rgba(8,14,36,.12) 30%, rgba(8,14,36,.12) 100%); color: #fff; justify-content: flex-start; touch-action: none; }
.ob-banner { position: relative; z-index: 2; background: var(--snow); color: var(--ink); border-radius: 18px; padding: 8px 16px; text-align: center; width: 100%; max-width: 440px;
  border-top: 6px solid var(--red); pointer-events: none; }
.ob-banner span { display: block; font-size: 20px; font-weight: 800; }
.ob-banner strong { display: block; font-size: 24px; color: var(--green); margin-top: 2px; }
.ob-stage { position: absolute; inset: 0; z-index: 1; }
.ob-hit { position: absolute; width: 132px; height: 132px; transform: translate(-50%, -50%); border-radius: 50%; border: 4px dashed rgba(255,255,255,.9);
  background: rgba(255,255,255,.08); animation: ring 1s infinite; }
@keyframes ring { 50% { transform: translate(-50%, -50%) scale(1.1); border-color: rgba(255,230,120,.95); } }
.ob-count { position: absolute; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 9%); font-size: 22px; font-weight: 800; text-shadow: 0 2px 6px #000; text-align: center; pointer-events: none; }
.snow-clump { position: absolute; font-size: 70px; width: 104px; height: 96px; transform: translate(-50%, -50%); background: rgba(255,255,255,.12); border: 3px dashed rgba(255,255,255,.7);
  border-radius: 50%; transition: transform .25s, opacity .25s; line-height: 1; }
.snow-clump.gone { transform: translate(-50%, -50%) scale(1.6); opacity: 0; }
.ob-arrow { position: absolute; font-size: 46px; transform: translate(-50%, -50%); animation: nudge .7s infinite alternate; pointer-events: none; }
.ob-arrow.right { animation-direction: alternate-reverse; }
@keyframes nudge { to { transform: translate(calc(-50% - 10px), -50%); } }
.ice-bar { position: absolute; left: 5%; width: 90%; bottom: calc(env(safe-area-inset-bottom) + 16%); height: 44px; background: #d9e6ff; border-radius: 22px; overflow: hidden; border: 3px solid #fff; }
.ice-zone { position: absolute; left: 36%; width: 28%; top: 0; bottom: 0; background: #3cc47c; }
.ice-needle { position: absolute; top: -4px; bottom: -4px; width: 8px; margin-left: -4px; background: var(--red); border-radius: 4px; }
.ob-timer { position: relative; z-index: 2; width: 100%; max-width: 440px; height: 10px; margin-top: 6px; background: rgba(255,255,255,.25); border-radius: 5px; overflow: hidden; pointer-events: none; }
#obTimerBar { height: 100%; background: var(--gold); width: 100%; }

/* 到頂 */
.finish { pointer-events: none; justify-content: flex-start; padding-top: 22vh; }
.finish-title { text-align: center; color: #fff; text-shadow: 0 3px 12px #000; }
.ft-main { font-size: 34px; font-weight: 900; }
.ft-sub { font-size: 22px; margin-top: 6px; }
.finish-verse { margin-top: 30vh; background: rgba(255,248,220,.95); color: #5a3d00; border-radius: 16px; padding: 14px 18px; max-width: 420px;
  text-align: center; animation: fadein 1.2s; }
.fv-text { font-size: 21px; font-weight: 800; line-height: 1.6; }
.fv-ref { font-size: 16px; margin-top: 6px; }
@keyframes fadein { from { opacity: 0; transform: translateY(10px); } }

/* 結果與經文卡（E5：一個畫面內完整顯示） */
.result { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.res-rank { background: var(--snow); border-radius: 20px; padding: 16px; color: var(--ink); }
.res-rank.prize { background: linear-gradient(135deg, #fff6d5, #ffe08a); border: 3px solid var(--gold); }
.rr-big { font-size: 28px; font-weight: 900; color: var(--red2); }
.rr-line { font-size: 20px; margin-top: 4px; font-weight: 700; }
.rr-name { font-size: 30px; font-weight: 900; margin-top: 6px; color: var(--green); }
.verse-card { background: linear-gradient(160deg, #1f7a4d, #145536); color: #fff; border-radius: 22px; padding: 20px 20px 16px;
  border: 4px solid var(--gold); box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.vc-title { font-size: 18px; color: var(--gold); font-weight: 800; letter-spacing: 2px; }
.vc-text { font-size: 22px; line-height: 1.7; font-weight: 700; margin: 12px 0 8px; text-align: left; }
.vc-ref { text-align: right; color: var(--gold); font-weight: 700; margin: 0; }
.vc-stars { margin: 10px 0 0; font-size: 17px; font-weight: 800; color: var(--gold); }
.vc-name { margin: 10px 0 0; font-size: 15px; opacity: .85; }
.result .hint { color: #c9d3ee; margin: 0; }

/* 主控台 */
.host .screen { min-height: 100vh; }
.host-main { padding: 72px 16px 24px; max-width: 1200px; margin: 0 auto; }
.host .screen.center { padding-top: 0; }
.host-grid { display: grid; grid-template-columns: 1fr 1.4fr; gap: 16px; }
.panel { background: var(--snow); border-radius: 18px; padding: 18px; box-shadow: 0 8px 30px rgba(0,0,0,.3); min-width: 0; }
.panel h2 { margin: 6px 0 12px; font-size: 22px; color: var(--red2); }
.qr-panel { text-align: center; }
.qr { display: inline-block; background: #fff; padding: 12px; border-radius: 12px; }
.qr img, .qr canvas { display: block; max-width: 100%; height: auto; }
.join-url { word-break: break-all; font-size: 15px; color: var(--muted); }
.count-row { display: flex; align-items: baseline; gap: 8px; font-size: 22px; }
.count-row strong { font-size: 60px; color: var(--green); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; max-height: 46vh; overflow: auto; }
.chip { background: #fff; border: 2px solid #d7dceb; border-radius: 999px; padding: 4px 12px; font-size: 17px; }
.timer-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.race-timer { font-size: 54px; font-weight: 900; color: var(--ink); }
.arrival { margin: 10px 0; background: #fff6d5; border: 3px solid var(--gold); border-radius: 14px; padding: 12px; font-size: 24px; font-weight: 900;
  color: #7a4b00; animation: fadein .5s; }
.arrival.first { background: var(--red); color: #fff; border-color: var(--gold); font-size: 28px; }
.top3 { list-style: none; padding: 0; margin: 0 0 8px; }
.top3-row { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 8px; font-size: 24px; padding: 8px 4px; border-bottom: 1px solid #e3e7f1; }
.medal { font-size: 32px; }
.top3-row .nm { font-weight: 800; overflow-wrap: anywhere; }
.top3-row .tm { color: var(--muted); font-size: 18px; }
.board { list-style: none; padding: 0; margin: 0; max-height: 70vh; overflow: auto; }
.board-row { display: grid; grid-template-columns: 34px minmax(80px, 1fr) minmax(60px, 1.2fr) auto; align-items: center; gap: 8px; padding: 7px 2px;
  border-bottom: 1px solid #e3e7f1; font-size: 17px; }
.board-row.podium { background: #fff6d5; }
.board-row .rk { font-weight: 900; color: var(--red2); text-align: right; }
.board-row .nm { overflow-wrap: anywhere; }
.bar { height: 12px; background: #e3e7f1; border-radius: 6px; overflow: hidden; }
.fill { height: 100%; background: linear-gradient(90deg, var(--green), var(--gold)); }
.board-row .val { font-size: 15px; color: var(--muted); white-space: nowrap; }
.end-panel { margin-top: 16px; }

@media (max-width: 860px) {
  .host-grid { grid-template-columns: 1fr; }
  .race-timer { font-size: 42px; }
  .board { max-height: none; }
}
@media (max-width: 380px) {
  .lane-btn { min-height: 130px; }
  .vc-text { font-size: 20px; }
}

/* 主控台投影模式（D-018）：投影機 16:9，字要大、離很遠也看得清楚 */
body.projecting { overflow: hidden; }
.proj { position: fixed; inset: 0; z-index: 100; background: #0b1638; color: #fff; overflow: hidden; }
#projCv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.proj-lobby { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 5vw; padding: 4vh 5vw; }
.proj-qr-box { background: #fff; padding: 18px; border-radius: 24px; box-shadow: 0 10px 40px rgba(0,0,0,.5); flex: none; }
.proj-qr-box img, .proj-qr-box canvas { display: block; }
.proj-lobby-info { max-width: 46vw; }
.proj-lobby-info h1 { font-size: clamp(32px, 4.4vw, 64px); margin: 0 0 8px; text-shadow: 0 4px 16px rgba(0,0,0,.5); }
.proj-lead { font-size: clamp(20px, 2.2vw, 32px); margin: 0 0 18px; opacity: .9; }
.proj-count { font-size: clamp(22px, 2.4vw, 34px); font-weight: 800; margin-bottom: 14px; }
.proj-count strong { font-size: 1.9em; color: #ffd54a; margin-right: 6px; }
.proj-chips { max-height: 36vh; overflow: hidden; }
.proj-chips .chip { font-size: clamp(15px, 1.4vw, 22px); color: #1d2340; font-weight: 700; }
.proj-hud { position: absolute; top: 16px; left: 0; right: 0; display: flex; justify-content: center; gap: 28px; align-items: baseline; pointer-events: none; }
.proj-timer { font-size: clamp(34px, 4vw, 60px); font-weight: 900; text-shadow: 0 3px 12px #000; }
.proj-timer.warn { color: #ff6b6b; animation: blink 1s infinite; }
.proj-fin { font-size: clamp(18px, 1.8vw, 28px); font-weight: 800; opacity: .9; text-shadow: 0 2px 8px #000; }
.proj-count3 { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 26vh; font-weight: 900;
  background: rgba(8,14,36,.5); text-shadow: 0 6px 30px rgba(0,0,0,.6); pointer-events: none; }
.proj-banner { position: absolute; left: 50%; top: 46%; transform: translateX(-50%); background: rgba(255,255,255,.96); color: #1d2340;
  font-size: clamp(26px, 3.4vw, 54px); font-weight: 900; padding: 16px 36px; border-radius: 999px; white-space: nowrap; box-shadow: 0 10px 40px rgba(0,0,0,.5);
  animation: pop .6s infinite alternate; pointer-events: none; }
.proj-banner.first { background: #ffd54a; }
.proj-podium { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(8,14,36,.86); }
.proj-podium h1 { font-size: clamp(30px, 3.8vw, 58px); margin: 0 0 3vh; text-shadow: 0 4px 16px #000; }
.pod-row { display: flex; align-items: flex-end; gap: 3vw; }
.pod { display: flex; flex-direction: column; align-items: center; width: min(24vw, 340px); }
.pod-medal { font-size: clamp(50px, 6vw, 96px); }
.pod-name { font-size: clamp(24px, 2.8vw, 44px); font-weight: 900; text-align: center; }
.pod-val { font-size: clamp(18px, 1.8vw, 28px); opacity: .85; margin-bottom: 10px; }
.pod-block { width: 100%; display: flex; align-items: flex-start; justify-content: center; padding-top: 12px; border-radius: 14px 14px 0 0;
  font-size: clamp(40px, 5vw, 80px); font-weight: 900; color: rgba(0,0,0,.35); }
.pod-1 .pod-block { height: 24vh; background: #ffd54a; }
.pod-2 .pod-block { height: 16vh; background: #d5dde8; }
.pod-3 .pod-block { height: 11vh; background: #e09a68; }
.proj-exit { position: absolute; right: 14px; bottom: 14px; background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.35);
  border-radius: 999px; padding: 8px 16px; font-size: 15px; opacity: .55; }
.proj-exit:hover { opacity: 1; }
.text-btn.proj-btn { font-weight: 800; }
