:root {
  --bg: #120a26;
  --bg-2: #1e1140;
  --panel: rgba(22, 12, 48, 0.88);
  --line: rgba(255, 255, 255, 0.14);
  --text: #fff6e8;
  --muted: #b9acd6;
  --pink: #ff3d7f;
  --lantern: #ffc93c;
  --cyan: #3de8ff;
  --green: #7ee081;
  --perfect: #ffd95a;
  --great: #4fd8ff;
  --good: #8ef08a;
  --miss: #9b93ad;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "Noto Sans TC", system-ui, -apple-system, "PingFang TC", sans-serif;
  --display: "Bungee", "Noto Sans TC", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: var(--font);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
b { font-weight: 900; }

/* ---------- 背景影片 ---------- */
#video-wrap {
  position: fixed; inset: 0; overflow: hidden; pointer-events: none;
  background: radial-gradient(ellipse at 50% 120%, #3a1460 0%, var(--bg) 60%);
}
#video-wrap iframe, #yt {
  position: absolute; top: 50%; left: 50%;
  /* 以 16:9 鋪滿整個畫面（等同 object-fit: cover） */
  width: max(100vw, 177.78dvh); height: max(56.25vw, 100dvh);
  transform: translate(-50%, -50%);
  border: 0;
}
/* 開演前：播放器縮到說明列上方、完整露出可點擊（不疊任何東西在播放器前面） */
:root { --prelude-bar: calc(56px + var(--safe-b)); }
body.prelude #video-wrap { pointer-events: auto; z-index: 30; background: #000; }
body.prelude #video-wrap iframe {
  top: calc((100dvh - var(--prelude-bar)) / 2);
  width: min(100vw, calc((100dvh - var(--prelude-bar)) * 16 / 9));
  height: min(calc(100dvh - var(--prelude-bar)), 56.25vw);
}
body.prelude #video-dim, body.prelude #stage, body.prelude #hud { visibility: hidden; }
#prelude-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  height: var(--prelude-bar); padding: 0 calc(16px + var(--safe-r)) var(--safe-b) calc(16px + var(--safe-l));
  display: flex; align-items: center; justify-content: center; gap: 12px;
  background: var(--bg); border-top: 1px solid var(--line);
  font-size: 14px; line-height: 1.35; text-align: center;
}
/* 影片暫停時 YouTube 會疊上推薦影片，非遊戲畫面就把影片藏起來 */
#video-wrap iframe { transition: opacity 0.6s, width 0.4s, height 0.4s, top 0.4s; }
body.video-off #video-wrap iframe { opacity: 0; }
#video-dim {
  position: fixed; inset: 0; pointer-events: none;
  background: #000; opacity: 0.5;
}
#stage { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; }

/* ---------- 共用畫面 ---------- */
.screen {
  position: fixed; inset: 0; z-index: 10;
  padding: 12px calc(16px + var(--safe-r)) calc(12px + var(--safe-b)) calc(16px + var(--safe-l));
  display: flex; flex-direction: column;
}
.screen.modal {
  z-index: 40; align-items: center; justify-content: center;
  background: rgba(8, 4, 20, 0.6); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: var(--bg); text-align: center; padding: 24px;
}
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
  padding: 18px 22px; width: min(440px, 92vw); max-height: 92dvh; overflow: auto;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 61, 127, 0.15) inset;
}
.panel.center { align-items: center; text-align: center; }
.panel h2 { margin: 0; font-size: 22px; }
.eyebrow { margin: 0; color: var(--lantern); font-size: 13px; font-weight: 700; letter-spacing: 0.12em; }
.hint { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.muted { color: var(--muted); }

.btn {
  font: 700 16px var(--font); color: var(--text);
  background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line);
  border-radius: 999px; padding: 10px 22px; min-height: 44px; cursor: pointer;
  transition: transform 0.08s, background 0.15s;
}
.btn:active { transform: scale(0.96); }
.btn.primary {
  background: linear-gradient(135deg, var(--pink), #ff7a3d);
  border-color: transparent; color: #fff;
  box-shadow: 0 6px 24px rgba(255, 61, 127, 0.45);
}
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 14px; min-height: 36px; font-size: 14px; }
.btn.big { font-size: 20px; padding: 12px 34px; min-height: 52px; }
.btn:disabled { opacity: 0.5; }

/* ---------- 直向／電腦提示 ---------- */
#rotate { display: none; }
@media (orientation: portrait) {
  #rotate { display: flex; }
}
.rotate-phone {
  width: 56px; height: 96px; border: 4px solid var(--text); border-radius: 12px;
  animation: rot 1.8s ease-in-out infinite;
}
@keyframes rot { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
#rotate p { font-size: 20px; margin: 16px 0 0; }
#rotate small, .qr-hint { color: var(--muted); }
.qr-hint b { color: var(--cyan); word-break: break-all; }

/* ---------- 標題 ---------- */
#title {
  align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 50% 110%, rgba(255, 61, 127, 0.35), transparent 60%),
    linear-gradient(180deg, rgba(18, 10, 38, 0.55), rgba(18, 10, 38, 0.92));
}
.title-box { position: relative; text-align: center; display: flex; flex-direction: column; align-items: center; }
#title h1 {
  margin: 2px 0 0; font-size: clamp(44px, 13dvh, 84px); font-weight: 900; line-height: 1;
  letter-spacing: 0.06em;
  background: linear-gradient(180deg, #fff3c4, var(--lantern) 55%, #ff8a3d);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 18px rgba(255, 201, 60, 0.55)) drop-shadow(0 4px 0 #8a1f4d);
}
#title h1 span {
  display: block; font: 400 clamp(13px, 3.6dvh, 20px) var(--display);
  letter-spacing: 0.08em; margin-top: 6px;
  background: linear-gradient(90deg, var(--cyan), var(--pink));
  -webkit-background-clip: text; background-clip: text;
}
#title .sub { margin: 8px 0 14px; color: var(--muted); font-size: 13px; letter-spacing: 0.2em; }
#name-form { display: flex; gap: 8px; }
#nickname {
  font: 500 16px var(--font); color: var(--text);
  background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line); border-radius: 999px;
  padding: 10px 18px; width: min(260px, 50vw); outline: none;
  -webkit-user-select: text; user-select: text;
}
#nickname:focus { border-color: var(--pink); }
.disclaimer {
  position: absolute; bottom: calc(8px + var(--safe-b)); left: 0; right: 0;
  margin: 0 auto; max-width: 720px; padding: 0 16px;
  text-align: center; font-size: 11px; color: var(--muted); opacity: 0.8;
}
.title-members { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.title-members img {
  position: absolute; width: clamp(64px, 20dvh, 120px);
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.5));
  animation: bob 3s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(-8px) rotate(var(--r, 0deg)); } }

/* ---------- 選難度 ---------- */
#select { gap: 10px; background: linear-gradient(180deg, rgba(18, 10, 38, 0.75), rgba(18, 10, 38, 0.9)); }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.who { color: var(--muted); font-size: 14px; }
.who b { color: var(--text); }
.select-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 1.15fr 1fr; gap: 12px; }
.diffs { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.diff {
  flex: 1; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  text-align: left; padding: 8px 16px; border-radius: 16px; cursor: pointer;
  background: rgba(255, 255, 255, 0.06); border: 2px solid transparent; color: var(--text);
  font-family: var(--font);
}
.diff .lv {
  font: 400 22px var(--display); width: 54px; height: 54px; border-radius: 50%;
  display: grid; place-items: center; background: var(--c); color: #1a0b33;
}
.diff h4 { margin: 0; font: 400 18px var(--display); letter-spacing: 0.05em; }
.diff p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.diff .best { font: 400 14px var(--display); color: var(--lantern); text-align: right; }
.diff .best small { display: block; font: 700 11px var(--font); color: var(--muted); }
.diff.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 18%, transparent); }
.board {
  background: rgba(0, 0, 0, 0.3); border: 1px solid var(--line); border-radius: 16px;
  padding: 10px 14px; display: flex; flex-direction: column; min-height: 0;
}
.board-head { display: flex; justify-content: space-between; align-items: baseline; }
.board-head h3 { margin: 0; font-size: 16px; }
.board-head span { font: 400 13px var(--display); color: var(--lantern); }
.board-list { list-style: none; margin: 6px 0 0; padding: 0; overflow: auto; flex: 1; font-size: 14px; }
.board-list li { display: grid; grid-template-columns: 28px 1fr auto; gap: 6px; padding: 4px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.board-list li.me { color: var(--lantern); }
.board-list li.muted { display: block; border: 0; padding-top: 12px; }
.board-list .rk { font: 400 13px var(--display); color: var(--muted); }
.board-list li:nth-child(1) .rk { color: #ffd95a; }
.board-list li:nth-child(2) .rk { color: #dfe6f0; }
.board-list li:nth-child(3) .rk { color: #e7a36b; }
.board-list .sc { font: 400 13px var(--display); }
.board-list .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-me { margin: 6px 0 0; font-size: 13px; color: var(--lantern); min-height: 1em; }
#play { align-self: center; }

/* ---------- 設定 ---------- */
.row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 15px; align-items: center; }
.row input[type=range] { grid-column: 1 / -1; width: 100%; accent-color: var(--pink); }
.row output { font: 400 14px var(--display); color: var(--lantern); }
.seg { grid-column: 1 / -1; display: flex; gap: 6px; }
.seg button {
  flex: 1; min-height: 36px; border-radius: 10px; cursor: pointer;
  font: 700 14px var(--font); color: var(--text);
  background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line);
}
.seg button.on { background: var(--pink); border-color: transparent; }

/* ---------- 點影片 ---------- */

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#pause-btn {
  position: absolute; top: 10px; left: calc(12px + var(--safe-l));
  width: 44px; height: 44px; border-radius: 50%; pointer-events: auto;
  background: rgba(0, 0, 0, 0.4); color: var(--text); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; gap: 5px;
}
#pause-btn i { width: 4px; height: 14px; border-radius: 2px; background: var(--text); }
.hud-score { position: absolute; top: 8px; right: calc(16px + var(--safe-r)); text-align: right; }
.hud-score b { display: block; font: 400 26px var(--display); text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7); }
.hud-score small { font: 400 11px var(--display); color: var(--lantern); letter-spacing: 0.1em; }
.hud-progress {
  position: absolute; top: 0; left: 0; right: 0; height: 3px; background: rgba(255, 255, 255, 0.12);
}
.hud-progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--cyan), var(--pink)); }
/* 開場資訊卡 */
#intro {
  position: absolute; top: 50%; left: 50%; text-align: center;
  padding: 14px 34px 16px; border-radius: 22px;
  background: linear-gradient(160deg, rgba(42, 15, 69, 0.82), rgba(18, 10, 38, 0.82));
  border: 1px solid rgba(255, 201, 60, 0.35);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.5), 0 0 30px rgba(255, 61, 127, 0.25);
  opacity: 0; transform: translate(-50%, -40%) scale(0.92);
  transition: opacity 0.45s, transform 0.45s cubic-bezier(.2, 1.3, .4, 1);
}
#intro.show { opacity: 1; transform: translate(-50%, -55%) scale(1); }
#intro h2 {
  margin: 4px 0 0; font-size: clamp(30px, 11dvh, 52px); font-weight: 900; line-height: 1;
  letter-spacing: 0.06em;
  background: linear-gradient(180deg, #fff3c4, var(--lantern) 55%, #ff8a3d);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
#intro h2 span { display: block; margin-top: 4px; font: 400 clamp(11px, 3dvh, 15px) var(--display); color: var(--cyan); -webkit-text-fill-color: var(--cyan); }
.intro-heads { display: flex; justify-content: center; margin-bottom: 4px; }
.intro-heads img { width: clamp(30px, 9dvh, 44px); margin: 0 -3px; animation: bob 1.92s ease-in-out infinite; }
.intro-heads img:nth-child(2n) { animation-delay: -0.96s; }
.intro-diff { margin: 8px 0 0; font: 400 15px var(--display); letter-spacing: 0.1em; }

/* ---------- 謝幕暗場 ---------- */
#curtain {
  position: fixed; inset: 0; z-index: 35; pointer-events: none;
  background: radial-gradient(ellipse at 50% 60%, #2a0f45, #07030f 75%);
  opacity: 0; transition: opacity 0.6s ease;
}
#curtain.show { opacity: 1; }

/* ---------- 結算 ---------- */
#result {
  justify-content: center;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(255, 61, 127, 0.3), transparent 55%),
    linear-gradient(180deg, rgba(18, 10, 38, 0.82), rgba(18, 10, 38, 0.95));
}
.result-body { display: grid; grid-template-columns: 0.8fr 1.2fr; gap: 16px; align-items: center; max-width: 860px; width: 100%; margin: 0 auto; }
.result-left { position: relative; display: flex; flex-direction: column; align-items: center; }
.rank {
  font: 400 clamp(72px, 26dvh, 140px) var(--display); line-height: 1;
  background: linear-gradient(180deg, #fff3c4, var(--lantern) 50%, var(--pink));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 22px rgba(255, 201, 60, 0.5));
  transform: rotate(-8deg);
}
/* 結算動畫：分數滾動（JS）→ 各判定依序浮現 → 評價蓋章 → 畫面一震 */
.play .rank { animation: stamp 0.42s cubic-bezier(.3, 1.5, .5, 1) 1.15s both; }
.play .badge, .play #r-member { animation: fadeUp 0.4s ease-out 1.55s both; }
.play .r-counts li { animation: fadeUp 0.35s ease-out calc(0.15s + var(--i) * 0.12s) both; }
.play.result-body { animation: shake 0.3s ease-out 1.5s; }
@keyframes stamp {
  0% { transform: scale(3.2) rotate(-20deg); opacity: 0; }
  55% { opacity: 1; }
  100% { transform: scale(1) rotate(-8deg); opacity: 1; }
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } }
@keyframes shake {
  20% { transform: translate(-4px, 3px); }
  40% { transform: translate(4px, -2px); }
  60% { transform: translate(-3px, 1px); }
  80% { transform: translate(2px, 0); }
}
.badge { font: 400 14px var(--display); color: var(--cyan); min-height: 1.2em; letter-spacing: 0.08em; }
#r-member { width: clamp(80px, 26dvh, 150px); margin-top: 4px; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.5)); }
.r-score { font: 400 clamp(32px, 11dvh, 56px) var(--display); line-height: 1.1; }
.r-best { margin: 0; color: var(--lantern); font-size: 13px; min-height: 1em; }
.r-counts { list-style: none; margin: 8px 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 18px; font: 400 13px var(--display); }
.r-counts li { display: flex; justify-content: space-between; }
.r-counts .perfect { color: var(--perfect); }
.r-counts .great { color: var(--great); }
.r-counts .good { color: var(--good); }
.r-counts .miss { color: var(--miss); }
.r-timing, .r-upload { margin: 2px 0; font-size: 13px; color: var(--muted); }
.r-timing button { margin-left: 6px; }
.r-actions { display: flex; gap: 10px; margin-top: 8px; }

/* ---------- 加到主畫面 ---------- */
.a2hs {
  display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 10px;
  margin-top: 8px; padding: 8px 10px; border-radius: 14px;
  background: rgba(255, 201, 60, 0.12); border: 1px solid rgba(255, 201, 60, 0.4);
  animation: fadeUp 0.4s ease-out 1.8s both;
}
.a2hs img { width: 36px; height: 36px; border-radius: 9px; }
.a2hs span { font-size: 12px; color: var(--muted); line-height: 1.35; }
.a2hs span b { display: block; font-size: 14px; color: var(--text); }
.a2hs-x { background: none; border: 0; color: var(--muted); font-size: 16px; padding: 6px; cursor: pointer; }
#a2hs-steps ol { margin: 0; padding-left: 22px; line-height: 1.9; font-size: 15px; }
#a2hs-steps .ios-share {
  display: inline-grid; place-items: center; width: 24px; height: 24px; vertical-align: -6px;
  border-radius: 6px; background: rgba(255, 255, 255, 0.12);
}
#a2hs-steps .warn { color: var(--lantern); font-size: 14px; margin: 0 0 6px; }

/* 矮螢幕（橫向手機）壓縮 */
@media (max-height: 420px) {
  .diff { padding: 4px 12px; }
  .diff .lv { width: 42px; height: 42px; font-size: 18px; }
  .diff h4 { font-size: 15px; }
  .btn.big { font-size: 17px; min-height: 44px; padding: 8px 28px; }
  .panel { padding: 12px 18px; gap: 6px; }
}
