* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; height: 100dvh; overflow: hidden; background: #05070d; }
body {
  touch-action: none; overscroll-behavior: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC", system-ui, sans-serif;
  color: #fff; user-select: none; -webkit-user-select: none;
}
canvas#gl { position: fixed; inset: 0; display: block; width: 100%; height: 100%; }
.hidden { display: none !important; }

/* ── 顯示切換：lobby ↔ playing ── */
body:not(.playing) #hud,
body:not(.playing) #board,
body:not(.playing) #emotes,
body:not(.playing) #marker,
body:not(.playing) #nametags { display: none !important; }
body.playing #lobby { display: none !important; }

/* ── 大廳 ── */
#lobby {
  --pick: #ff4d6d;
  position: fixed; inset: 0; z-index: 40; overflow-y: auto; touch-action: pan-y; overscroll-behavior: contain;
  display: flex; align-items: flex-start; justify-content: center;
  padding: calc(4vh + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(4vh + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  background-color: #6ec6ff;
  background-image: url(assets/img/lobby-bg.png), linear-gradient(180deg, #5ab8ff 0%, #9fd8ff 45%, #ffd08a 80%, #ff9f5a 100%);
  background-size: cover, cover; background-position: center, center; background-repeat: no-repeat, no-repeat;
}
.lobby-inner { width: 100%; max-width: 980px; display: flex; flex-direction: column; align-items: center; gap: 22px; text-align: center; }
.lobby-title {
  padding: 18px 28px 6px; border-radius: 28px;
  background-image: url(assets/img/title.png); background-size: contain; background-position: center; background-repeat: no-repeat;
}
.lobby-title h1 {
  font-size: clamp(36px, 7vw, 76px); font-weight: 900; letter-spacing: .08em; line-height: 1.1;
  color: #fff; -webkit-text-stroke: 2px #ff7a3d; paint-order: stroke fill;
  text-shadow: 0 4px 0 #ff9f43, 0 10px 30px rgba(255, 120, 40, .45);
}
.lobby-title .sub { margin-top: 10px; font-size: clamp(16px, 2.4vw, 22px); font-weight: 700; color: #fff; text-shadow: 0 2px 8px rgba(0, 60, 120, .45); }
.lobby-row { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.row-label { font-size: 20px; font-weight: 800; color: #fff; text-shadow: 0 2px 6px rgba(0, 60, 120, .5); }

#nameInput {
  width: min(420px, 100%); height: 60px; padding: 0 24px; border-radius: 30px; border: 4px solid #fff;
  font-family: inherit; font-size: 22px; font-weight: 700; text-align: center; color: #2b2f55;
  background: rgba(255, 255, 255, .92); outline: none; box-shadow: 0 6px 18px rgba(0, 60, 120, .25);
  user-select: text; -webkit-user-select: text; transition: border-color .2s, box-shadow .2s;
}
#nameInput:focus { border-color: var(--pick); box-shadow: 0 0 0 6px color-mix(in srgb, var(--pick) 35%, transparent), 0 6px 18px rgba(0, 60, 120, .25); }
#nameInput::placeholder { color: #9aa3c7; }
.name-count { margin-top: -6px; font-size: 14px; font-weight: 700; color: #fff; opacity: .85; text-shadow: 0 1px 4px rgba(0, 60, 120, .5); }

/* 飛機卡片 */
#planeCards { width: 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.plane-card {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px 14px 18px;
  border-radius: 26px; border: 4px solid rgba(255, 255, 255, .85); cursor: pointer; color: #2b2f55;
  font-family: inherit; text-align: center;
  background: linear-gradient(160deg, #ffffff 0%, #e6f4ff 55%, #ffe9d2 100%);
  box-shadow: 0 8px 20px rgba(0, 60, 120, .22);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.plane-card:hover { transform: scale(1.06); box-shadow: 0 14px 30px rgba(0, 60, 120, .3); }
.plane-card:active { transform: scale(.98); }
.plane-card.selected {
  border-color: var(--pick); transform: scale(1.06);
  box-shadow: 0 0 0 4px #fff, 0 0 26px 8px var(--pick), 0 14px 30px rgba(0, 60, 120, .3);
}
.plane-card[data-plane="paper"] .plane-art { background: linear-gradient(135deg, #fff7c2, #ffd3e0); }
.plane-card[data-plane="jet"] .plane-art { background: linear-gradient(135deg, #b8e4ff, #7aa8ff); }
.plane-card[data-plane="biplane"] .plane-art { background: linear-gradient(135deg, #c9f5c4, #ffe38a); }
.plane-card[data-plane="rocket"] .plane-art { background: linear-gradient(135deg, #ffc3a0, #ff7aa2); }
.plane-art {
  position: relative; width: 100%; aspect-ratio: 4 / 3; border-radius: 18px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.plane-art .emoji { font-size: 56px; line-height: 1; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .2)); }
.plane-art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.plane-art .plane-badge {   /* U3 / V3b：角色卡片「✨ 專屬特效」小標（疊在卡片圖左上角） */
  position: absolute; top: 8px; left: 8px; z-index: 1; padding: 3px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 900; color: #fff; white-space: nowrap; pointer-events: none;
  background: linear-gradient(135deg, #ff7ab8, #ff4d94); box-shadow: 0 2px 6px rgba(200, 40, 110, .35);
}
.plane-name { font-size: 22px; font-weight: 900; }
.plane-desc { font-size: 15px; font-weight: 700; color: #5a6190; min-height: 1.4em; }
.stat-bars { width: 100%; display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.stat-bar { display: grid; grid-template-columns: 3em 1fr; align-items: center; gap: 8px; font-size: 13px; font-weight: 800; color: #5a6190; text-align: left; }
.stat-bar .track { height: 12px; border-radius: 6px; background: rgba(43, 47, 85, .12); overflow: hidden; }
.stat-bar .fill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, #ffd93d, #ff9f43); }
.stat-bar[data-stat="speed"] .fill { background: linear-gradient(90deg, #4dd0e1, #4d79ff); }
.stat-bar[data-stat="turn"] .fill { background: linear-gradient(90deg, #6bcb77, #b0e57c); }
.stat-bar[data-stat="boost"] .fill { background: linear-gradient(90deg, #ff9f43, #ff4d6d); }

/* 出發按鈕 */
#startBtn {
  margin-top: 6px; min-height: 84px; padding: 0 72px; border-radius: 48px; border: 5px solid #fff; cursor: pointer;
  font-family: inherit; font-size: 40px; font-weight: 900; letter-spacing: .15em; text-indent: .15em; color: #fff;
  background: linear-gradient(180deg, #ffb347 0%, #ff6a3d 100%);
  text-shadow: 0 3px 0 rgba(160, 50, 0, .45);
  box-shadow: 0 8px 0 #c94a1f, 0 16px 30px rgba(200, 80, 20, .4);
  transition: transform .12s ease, box-shadow .12s ease;
  animation: breathe 2.2s ease-in-out infinite;
}
#startBtn:hover { transform: translateY(-3px) scale(1.04); }
#startBtn:active { transform: translateY(6px); box-shadow: 0 2px 0 #c94a1f, 0 6px 14px rgba(200, 80, 20, .4); animation: none; }
@keyframes breathe { 50% { transform: scale(1.05); } }
/* 畫質選項：三顆等寬並排（360px 不換行） */
.quality-group { width: min(420px, 100%); display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.quality-btn {
  min-width: 0; height: 48px; padding: 0 8px; border-radius: 24px; border: 4px solid rgba(255, 255, 255, .85); cursor: pointer;
  font-family: inherit; font-size: 20px; font-weight: 800; color: #2b2f55; white-space: nowrap;
  background: rgba(255, 255, 255, .92); box-shadow: 0 6px 18px rgba(0, 60, 120, .25);
  transition: transform .12s ease, border-color .18s ease, box-shadow .18s ease;
}
.quality-btn:hover { transform: scale(1.04); }
.quality-btn:active { transform: scale(.97); }
.quality-btn.active {
  border-color: var(--pick); color: #fff; background: linear-gradient(180deg, #ffb347 0%, #ff6a3d 100%);
  box-shadow: 0 0 0 3px #fff, 0 6px 18px rgba(0, 60, 120, .3);
}
.lobby-hint { font-size: 14px; font-weight: 700; color: #fff; opacity: .9; text-shadow: 0 1px 4px rgba(0, 60, 120, .5); }
.lobby-hint kbd { color: #fff; }

/* ── 載入 ── */
#loading {
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; gap: 18px;
  align-items: center; justify-content: center; background: radial-gradient(circle at 50% 60%, #2a5fa8, #0b1530 75%);
  letter-spacing: .2em; font-size: 20px; font-weight: 700; color: #fff; transition: opacity 1s ease;
}
#loading.gone { opacity: 0; pointer-events: none; }
.spinner {
  width: 64px; height: 64px; border-radius: 50%;
  border: 6px solid rgba(255, 255, 255, .2); border-top-color: #ffd93d;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── HUD ── */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.panel {
  position: absolute; background: rgba(12, 18, 34, .32); border: 1px solid rgba(255, 255, 255, .14);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-radius: 18px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .18);
}
.stats { left: 26px; bottom: 44px; display: flex; gap: 26px; padding: 14px 22px; }
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 70px; }
.stat .label { font-size: 13px; letter-spacing: .25em; opacity: .75; font-weight: 700; }
.stat .val b { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .val small { font-size: 12px; opacity: .7; margin-left: 4px; }
.topleft { left: 26px; top: 24px; padding: 9px 16px; display: flex; gap: 14px; align-items: center; font-size: 14px; font-weight: 700; letter-spacing: .1em; }
#netStatus { font-size: 12px; opacity: .75; }
.help { right: 26px; bottom: 120px; padding: 12px 16px; font-size: 13px; line-height: 2; opacity: .85; }
kbd {
  display: inline-block; min-width: 22px; padding: 0 6px; margin-right: 3px; text-align: center;
  font-family: inherit; font-size: 12px; line-height: 20px; border-radius: 6px;
  background: rgba(255, 255, 255, .15); border: 1px solid rgba(255, 255, 255, .3);
}
#fps { position: absolute; left: 28px; bottom: 14px; font-size: 11px; opacity: .45; letter-spacing: .1em; }

/* COMBO */
#combo {
  position: absolute; left: 50%; top: 20vh; transform: translateX(-50%);
  font-size: clamp(40px, 7vw, 72px); font-weight: 900; letter-spacing: .06em; white-space: nowrap;
  color: #fff; -webkit-text-stroke: 3px #ffc300; paint-order: stroke fill;
  text-shadow: 0 0 18px rgba(255, 200, 0, .8), 0 4px 0 #ff8c00;
}
#combo.pop { animation: comboPop .5s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes comboPop {
  0% { transform: translateX(-50%) scale(.4); }
  60% { transform: translateX(-50%) scale(1.3); }
  100% { transform: translateX(-50%) scale(1); }
}
.score-pop { display: inline-block; animation: scorePop .45s cubic-bezier(.3, 1.6, .5, 1); color: #ffd93d; }
@keyframes scorePop { 0% { transform: scale(1); } 45% { transform: scale(1.6); } 100% { transform: scale(1); } }

/* ── 排行榜 ── */
#board {
  position: fixed; right: 20px; top: 20px; z-index: 11; width: max-content; min-width: 200px; max-width: 340px; padding: 12px 16px;
  pointer-events: none; background: rgba(12, 18, 34, .42);
}
.board-title { font-size: 16px; font-weight: 900; margin-bottom: 6px; letter-spacing: .1em; }
#boardList { list-style: none; counter-reset: rank; display: flex; flex-direction: column; gap: 4px; }
#boardList li {
  counter-increment: rank; display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 700; padding: 3px 8px; border-radius: 10px; border-left: 5px solid transparent;
  background: rgba(255, 255, 255, .06); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#boardList li::before { content: counter(rank); min-width: 1.2em; opacity: .7; }
#boardList li.me { background: rgba(255, 217, 61, .25); }
#boardList li .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#boardList li .pts { flex: none; min-width: 2.5em; text-align: right; }
#boardList li .plane, #boardList li .dot { flex: none; }

/* ── 表情列 ── */
#emotes {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 12;
  display: flex; gap: 16px;
}
.emote-btn {
  width: 68px; height: 68px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .8); cursor: pointer;
  font-size: 34px; line-height: 1; background: rgba(12, 18, 34, .4);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, .25); transition: transform .12s ease, background .12s ease;
}
.emote-btn:hover { transform: scale(1.12); background: rgba(255, 255, 255, .25); }
.emote-btn:active { transform: scale(.92); }

/* U17 語音鈕：與表情鈕同列；on = 開麥、denied = 權限被拒（灰） */
.voice-btn { width: auto; padding: 0 16px; border-radius: 34px; font-size: 20px; font-weight: 900; color: #fff; font-family: inherit; white-space: nowrap; }
.voice-btn.on { background: #2ecc71; border-color: #fff; }
.voice-btn.denied, .voice-btn:disabled { opacity: .45; filter: grayscale(1); cursor: not-allowed; }
.voice-btn:disabled:hover { transform: none; background: rgba(12, 18, 34, .4); }
/* U21：語音鈕旁小字「P2P / 中繼」（未開麥時為空、不佔位） */
.voice-mode { align-self: center; margin-left: -10px; font-size: 12px; font-weight: 900; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, .6); white-space: nowrap; pointer-events: none; }
.voice-mode:empty { display: none; }
/* U22：長按語音鈕開診斷面板——按鈕本身不選字 / 不跳 iOS 長按選單 */
.voice-btn { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; touch-action: manipulation; }
/* U22 語音診斷面板：文字可選取（長按複製） */
.voice-diag { position: fixed; left: calc(10px + env(safe-area-inset-left)); top: calc(56px + env(safe-area-inset-top)); z-index: 20; max-width: min(560px, calc(100vw - 20px)); max-height: 60vh; overflow: auto; padding: 8px 10px; border-radius: 12px; background: rgba(8, 12, 24, .88); color: #e8f0ff; border: 1px solid rgba(255, 255, 255, .35); box-shadow: 0 6px 18px rgba(0, 0, 0, .4); pointer-events: auto; -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
.voice-diag.hidden { display: none; }
.voice-diag-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 14px; }
.voice-diag-head b { flex: 1; }
.voice-diag-head button { font: inherit; font-size: 12px; padding: 2px 10px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, .5); background: rgba(255, 255, 255, .12); color: #fff; cursor: pointer; }
.voice-diag pre { margin: 0; font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-all; -webkit-user-select: text; user-select: text; }
body.touch .voice-diag pre { font-size: 11px; }
body.touch .voice-mode { margin-left: -4px; font-size: 11px; }

/* ── 名牌 / 表情氣泡 ── */
#nametags { position: fixed; inset: 0; z-index: 8; pointer-events: none; overflow: hidden; }
.nametag {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -100%);
  padding: 3px 12px 3px 9px; border-radius: 999px; border-left: 8px solid #fff;
  background: rgba(12, 18, 34, .55); color: #fff; font-size: calc(14px * var(--tag-k, 1)); font-weight: 800; white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .9), 0 0 6px rgba(0, 0, 0, .6);
}
.nametag.speaking::after { content: ' 🔊'; }
.emote-bubble {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -100%);
  font-size: 52px; line-height: 1; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .35)) drop-shadow(0 0 10px rgba(255, 255, 255, .55));
  animation: pop 1.5s cubic-bezier(.2, .9, .3, 1) forwards; will-change: transform, opacity;
}
/* 表情氣泡彈出：放大回彈 + 左右搖擺 + 上飄淡出（位置由 left/top 決定，transform 全交給動畫） */
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, -60%) scale(.1) rotate(-25deg); }
  12% { opacity: 1; transform: translate(-50%, -110%) scale(1.55) rotate(12deg); }
  22% { transform: translate(-50%, -100%) scale(.88) rotate(-8deg); }
  32% { transform: translate(-50%, -100%) scale(1.08) rotate(4deg); }
  42% { transform: translate(-50%, -100%) scale(1) rotate(0deg); }
  78% { opacity: 1; transform: translate(-50%, -115%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -150%) scale(.8); }
}

/* ── 光環指標 ── */
#marker { position: fixed; left: 0; top: 0; z-index: 9; pointer-events: none; display: none; }
#marker .diamond {
  position: absolute; left: -11px; top: -11px; width: 22px; height: 22px; transform: rotate(45deg);
  border: 3px solid rgba(255, 210, 120, .95); box-shadow: 0 0 12px rgba(255, 190, 90, .8);
}
#marker .arrow { display: none; position: absolute; left: -12px; top: -16px; width: 24px; text-align: center; color: #ffd27a; font-size: 22px; text-shadow: 0 0 10px rgba(255, 180, 80, .9); }
#marker.edge .diamond { display: none; }
#marker.edge .arrow { display: block; }
#marker .dist { position: absolute; left: -40px; top: 16px; width: 80px; text-align: center; font-size: 13px; font-weight: 700; color: #ffe6bb; text-shadow: 0 1px 6px rgba(0, 0, 0, .7); }

/* ── 提示 ── */
#toast {
  position: fixed; top: 14vh; left: 50%; transform: translate(-50%, -8px); z-index: 30; padding: 12px 30px;
  border-radius: 30px; background: rgba(12, 18, 34, .5); border: 1px solid rgba(255, 255, 255, .2);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  font-size: 18px; font-weight: 700; letter-spacing: .15em; opacity: 0; transition: opacity .4s, transform .4s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#warn {
  position: fixed; top: 28vh; left: 50%; transform: translateX(-50%); z-index: 12; color: #ffcf9a;
  font-size: 18px; font-weight: 700; letter-spacing: .2em; opacity: 0; transition: opacity .6s; text-shadow: 0 1px 10px rgba(0, 0, 0, .6); pointer-events: none;
}
#warn.show { opacity: 1; }

/* ── 手機 ── */
@media (max-width: 800px) { .help { display: none; } }
@media (max-width: 700px) {
  /* 卡片改橫向滑動列 */
  #planeCards {
    display: flex; gap: 12px; overflow-x: auto; overflow-y: hidden; touch-action: pan-x pan-y;
    scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
    padding: 10px 12% 14px; scrollbar-width: none;
  }
  #planeCards::-webkit-scrollbar { display: none; }
  .plane-card { flex: 0 0 72%; min-height: 56px; scroll-snap-align: center; }
  .plane-card:hover { transform: none; }
  .plane-card.selected { transform: scale(1.03); }
  #nameInput { height: 56px; }
  .plane-art .emoji { font-size: 44px; }
  #startBtn { min-height: 72px; padding: 0 48px; font-size: 32px; }
  #board { min-width: 150px; max-width: 180px; padding: 8px 10px; }
  #boardList li { font-size: 13px; }
  .stats { gap: 14px; padding: 10px 14px; bottom: 104px; }
  .stat .val b { font-size: 22px; }
}

/* ── 觸控裝置（body.touch 由 touch.js 加上）── */
.touch-only { display: none !important; }
body.touch .touch-only { display: inline-block !important; }
body.touch .help, body.touch .lobby-hint { display: none !important; }
#caption .touch-hint { display: none; }
body.touch #caption .kb-hint { display: none; }
body.touch #caption .touch-hint { display: inline; }

/* 搖桿區（左半螢幕）/ 加速鈕：只在 playing 顯示 */
#touchPad, #boostBtn { display: none; }
body.touch.playing #touchPad { display: block; position: fixed; left: 0; top: 0; width: 50%; height: 100%; z-index: 7; touch-action: none; }
.stick-base {
  position: absolute; left: calc(110px + env(safe-area-inset-left)); top: 70%;
  width: 128px; height: 128px; margin: -64px 0 0 -64px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .35); background: rgba(12, 18, 34, .22); opacity: .55; transition: opacity .15s;
}
.stick-base.active { opacity: 1; }
.stick-knob {
  position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; border-radius: 50%; transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, .7); box-shadow: 0 4px 12px rgba(0, 0, 0, .3);
}
.stick-base:not(.active) .stick-knob { transition: transform .12s ease-out; }
body.touch.playing #boostBtn {
  display: flex; align-items: center; justify-content: center; position: fixed; z-index: 13; touch-action: none;
  right: calc(28px + env(safe-area-inset-right)); bottom: calc(28px + env(safe-area-inset-bottom));
  width: 108px; height: 108px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .85);
  font-size: 44px; line-height: 1; color: #fff; background: rgba(255, 106, 61, .55);
  box-shadow: 0 8px 20px rgba(0, 0, 0, .3);
}
#boostBtn.on { background: rgba(255, 106, 61, .9); transform: scale(.94); }

/* 表情列 + 巡航鈕：右上小鈕 */
body.touch #emotes {
  left: auto; transform: none; bottom: auto; gap: 8px;
  top: calc(10px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right));
}
body.touch .emote-btn { width: 44px; height: 44px; font-size: 22px; border-width: 2px; }
body.touch .emote-btn:hover { transform: none; }
body.touch .cruise-btn { width: auto; padding: 0 12px; border-radius: 22px; font-size: 15px; font-weight: 900; color: #fff; font-family: inherit; }
body.touch.cruise .cruise-btn { background: #ff4d6d; border-color: #fff; }
body.touch .voice-btn { padding: 0 12px; border-radius: 22px; font-size: 15px; }
body.touch .voice-btn.on { background: #2ecc71; }

/* HUD 縮小並避開 safe-area */
body.touch .topleft { left: calc(12px + env(safe-area-inset-left)); top: calc(10px + env(safe-area-inset-top)); padding: 6px 12px; font-size: 12px; gap: 10px; }
body.touch .stats {
  left: 50%; transform: translateX(-50%); bottom: auto; top: calc(10px + env(safe-area-inset-top));
  gap: 14px; padding: 6px 14px; border-radius: 14px;
}
body.touch .stat { min-width: 48px; }
body.touch .stat .label { font-size: 10px; letter-spacing: .15em; }
body.touch .stat .val b { font-size: 18px; }
body.touch #fps { left: 50%; transform: translateX(-50%); bottom: calc(4px + env(safe-area-inset-bottom)); }
body.touch #board {
  top: calc(62px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right));
  width: max-content; min-width: 0; max-width: min(60vw, 320px); padding: 6px 10px; border-radius: 14px;
}
body.touch .board-title { font-size: 13px; margin-bottom: 3px; }
body.touch #boardList li { font-size: 12px; padding: 2px 6px; }
body.touch #combo { font-size: clamp(30px, 6vw, 52px); top: 26vh; }
body.touch #toast { font-size: 15px; padding: 8px 20px; top: calc(64px + env(safe-area-inset-top)); }
body.touch #warn { font-size: 15px; }

/* 直向遮罩：遊戲中直拿手機時 */
#rotateMask {
  display: none; position: fixed; inset: 0; z-index: 60; flex-direction: column; gap: 14px; align-items: center; justify-content: center;
  background: rgba(5, 7, 13, .92); color: #fff; font-size: 24px; font-weight: 900; letter-spacing: .2em;
}
#rotateMask .phone { font-size: 64px; animation: rotHint 1.6s ease-in-out infinite; }
@keyframes rotHint { 50% { transform: rotate(-90deg); } }
@media (orientation: portrait) { body.touch.playing #rotateMask { display: flex; } }

/* iOS 一次性提示 */
#iosHint {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 55;
  padding: 10px 20px; border-radius: 24px; background: rgba(12, 18, 34, .8); border: 1px solid rgba(255, 255, 255, .25);
  font-size: 15px; font-weight: 700; letter-spacing: .08em; white-space: nowrap; pointer-events: none;
}

/* ── 上滑全螢幕（U13）：requestFullscreen 不可用時 touch.js 加 html.swipe-scroll ──
   頁面比視窗高 → 玩家上滑時瀏覽器收起網址列 / 工具列；canvas / HUD 皆 position: fixed; inset: 0 不受捲動影響 */
html.swipe-scroll { height: auto; overflow-x: hidden; overflow-y: auto; }
html.swipe-scroll body { height: calc(100vh + 240px); overflow: visible; }
body.swipe-mask { touch-action: pan-y; }
/* U15：遮罩常駐 DOM、以 opacity 淡入淡出；body.swipe-mask = 上滑路徑，body.fs-mask = requestFullscreen 被退出（大按鈕） */
#swipeUp {
  display: none; position: fixed; inset: 0; z-index: 58; touch-action: pan-y;
  flex-direction: column; gap: 16px; align-items: center; justify-content: center;
  background: rgba(5, 7, 13, .72); color: #fff; font-size: 22px; font-weight: 900; letter-spacing: .15em;
  opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .35s ease, visibility 0s linear .35s;
}
#swipeUp .swipe-anim { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; animation: swipeMove 1.4s ease-in-out infinite; }
#swipeUp .swipe-arrow { font-size: 34px; color: #ffd93d; text-shadow: 0 0 12px rgba(255, 210, 80, .8); }
#swipeUp .swipe-finger { font-size: 56px; line-height: 1; }
@keyframes swipeMove {
  0% { transform: translateY(40px); opacity: 0; }
  25% { opacity: 1; }
  75% { opacity: 1; }
  100% { transform: translateY(-40px); opacity: 0; }
}
#fsBackBtn {
  display: none; padding: 22px 44px; border-radius: 40px; border: 3px solid #fff; background: #ff4d6d; color: #fff;
  font: inherit; font-size: 26px; letter-spacing: .12em; box-shadow: 0 8px 30px rgba(255, 77, 109, .5); touch-action: manipulation;
}
body.fs-mask:not(.swipe-mask) #swipeUp .swipe-anim, body.fs-mask:not(.swipe-mask) #swipeText { display: none; }
body.fs-mask:not(.swipe-mask) #fsBackBtn { display: block; }
@media (orientation: landscape) {
  body.touch.playing #swipeUp { display: flex; }
  body.touch.playing.swipe-mask #swipeUp, body.touch.playing.fs-mask #swipeUp {
    opacity: 1; visibility: visible; pointer-events: auto; transition: opacity .35s ease, visibility 0s;
  }
}
#iosHint { z-index: 59; }
/* U20：手機（≤ 900px 寬）排行榜寬度 / 字級 / 最多 5 列；放檔尾並帶 body.touch 以蓋過上方觸控規則 */
@media (max-width: 900px) {
  #board, body.touch #board { width: max-content; min-width: 0; max-width: min(60vw, 320px); }
  body.touch #boardList li .name { min-width: 6.5em; }
  #boardList li, body.touch #boardList li { font-size: 13px; }
}
/* 排行榜：server 最多 10 名；電腦直接全顯示；手機同時顯示 5 列、可捲動、自動捲到自己（列高 ≈ 13px 字級 + 4px padding + 4px gap ≈ 25px）*/
body.touch #boardList { max-height: calc(5 * 25px); overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; pointer-events: auto; scrollbar-width: none; }
body.touch #boardList::-webkit-scrollbar { display: none; }
#boardList li:nth-child(n+11) { display: none; }
/* 手機：4 個表情收進一顆 😀 切換鈕（避免擋到上方中間的速度 / 高度 / 分數），點開才在下方展開一列 */
body.touch #emotes { position: fixed; }
body.touch #emotes .emote-btn[data-k] { display: none; }
body.touch #emotes.open .emote-btn[data-k] { display: flex; position: absolute; top: 52px; }
body.touch #emotes.open .emote-btn[data-k="1"] { right: 0; }
body.touch #emotes.open .emote-btn[data-k="2"] { right: 52px; }
body.touch #emotes.open .emote-btn[data-k="3"] { right: 104px; }
body.touch #emotes.open .emote-btn[data-k="4"] { right: 156px; }
body.touch #emotes.open #emoteToggle { background: rgba(255, 217, 61, .35); }
body:not(.touch) #emoteToggle { display: none; }
/* 排行榜：說話中的玩家顯示 🎤（由 voice.js setSpeaking 切換 li.speaking） */
#boardList li .mic { display: none; flex: none; font-size: .85em; width: 1.2em; text-align: center; }
#boardList li.speaking .mic { display: inline-block; animation: micPulse 1s ease-in-out infinite; }
#boardList li .name { min-width: 6.5em; }   /* 桌面也保證放得下 6 個中文字（加 🎤 後不截名） */
@keyframes micPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.25); } }
/* 指定跟飛：排行榜每列（自己除外）可點；被跟的那列 ✈️ + 底色；HUD「跟飛中：<名字> ✕」 */
#boardList li:not(.me) { pointer-events: auto; cursor: pointer; }
#boardList li.following { background: rgba(77, 208, 225, .38); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .55); }
#boardList li.following .name::before { content: '✈️ '; }
#followChip {
  position: fixed; left: 26px; top: 76px; z-index: 12; padding: 7px 14px; cursor: pointer; pointer-events: auto;
  font: inherit; font-size: 14px; font-weight: 700; letter-spacing: .06em; color: #fff; white-space: nowrap;
  background: rgba(77, 208, 225, .45); border-color: rgba(255, 255, 255, .5);
}
#followChip .follow-name { display: inline-block; max-width: 9em; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
#followChip .follow-x { margin-left: 10px; padding: 0 6px; border-radius: 8px; background: rgba(255, 255, 255, .22); }
body:not(.playing) #followChip { display: none; }
body.touch #followChip { left: calc(12px + env(safe-area-inset-left)); top: calc(50px + env(safe-area-inset-top)); padding: 6px 12px; font-size: 13px; }

/* ── U4 惡作劇道具：桌面 HUD 指示 / 手機道具鈕（加速鈕左側）/ 墨漬疊層 ── */
#itemHud {
  left: 26px; bottom: 136px; padding: 6px 12px; display: flex; gap: 8px; align-items: center;
  font-size: 13px; font-weight: 700; letter-spacing: .06em;
  background: conic-gradient(rgba(255, 207, 90, .38) calc(var(--item-k, 0) * 360deg), rgba(12, 18, 34, .32) 0);
}
@media (max-width: 700px) { #itemHud { bottom: 188px; } }   /* 窄視窗 .stats 上移到 bottom 104，道具指示再往上避開 */
#itemHud .item-icon { font-size: 22px; line-height: 1; filter: grayscale(.8); opacity: .7; }
#itemHud.ready { border-color: rgba(255, 207, 90, .9); animation: itemReady 1.2s ease-in-out infinite; }
#itemHud.ready .item-icon, #itemBtn.ready .item-icon { filter: none; opacity: 1; }
@keyframes itemReady { 50% { box-shadow: 0 0 18px rgba(255, 207, 90, .65); } }
body.touch #itemHud { display: none; }
#itemBtn { display: none; }
body.touch.playing #itemBtn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; position: fixed; z-index: 13; touch-action: none;
  right: calc(152px + env(safe-area-inset-right)); bottom: calc(40px + env(safe-area-inset-bottom));
  width: 78px; height: 78px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .8); padding: 0;
  color: #fff; font-family: inherit; box-shadow: 0 6px 16px rgba(0, 0, 0, .3);
  background: conic-gradient(rgba(255, 207, 90, .75) calc(var(--item-k, 0) * 360deg), rgba(12, 18, 34, .45) 0);
}
#itemBtn .item-icon { font-size: 30px; line-height: 1; filter: grayscale(.8); opacity: .7; }
#itemBtn .item-prog { font-size: 11px; font-weight: 900; line-height: 1; }
#itemBtn.ready { border-color: #ffcf5a; animation: itemReady 1.2s ease-in-out infinite; }
#itemBtn:active { transform: scale(.94); }
/* 墨漬：只蓋畫面、不動鏡頭；出現快、最後 0.8 秒淡出；不擋操作 */
#inkOverlay { position: fixed; inset: 0; z-index: 25; pointer-events: none; opacity: 0; transition: opacity .8s ease-out; }
#inkOverlay.show { opacity: 1; transition: opacity .12s ease-in; }
#inkOverlay .ink-blot {
  position: absolute; border-radius: 47% 53% 42% 58% / 55% 41% 59% 45%;
  background: radial-gradient(circle at 40% 38%, rgba(40, 20, 70, .96) 0 55%, rgba(20, 10, 40, .85) 70%, rgba(20, 10, 40, 0) 74%);
  box-shadow: 1.5vmin 2vmin 0 -0.6vmin rgba(30, 15, 55, .9), -2vmin -1.5vmin 0 -1vmin rgba(30, 15, 55, .85);
}

/* V2 🦑 角色貼紙：白邊圓角、隨機角度（--rot）、依序「啪」貼上（--d 延遲），最後 0.8 秒淡出 */
#stickerOverlay { position: fixed; inset: 0; z-index: 25; pointer-events: none; opacity: 1; }
#stickerOverlay.fade { opacity: 0; transition: opacity .8s ease-out; }
#stickerOverlay .sticker {
  position: absolute; aspect-ratio: 1 / 1; background: #fff center / cover no-repeat;
  border: 1.4vmin solid #fff; border-radius: 22%; box-sizing: border-box;
  box-shadow: 0 1.2vmin 2.6vmin rgba(0, 0, 0, .35), 0 0 0 .25vmin rgba(0, 0, 0, .08);
  opacity: 0; transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) scale(1.7);
  animation: stickerSlap .28s cubic-bezier(.3, 1.5, .5, 1) var(--d, 0s) forwards;
}
@keyframes stickerSlap {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) scale(1.7); }
  55% { opacity: 1; }
  100% { opacity: 1; transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) scale(1); }
}
@media (prefers-reduced-motion: reduce) { #stickerOverlay .sticker { animation-duration: .01s; } }

/* 🫧 泡泡：滿畫面大小不一的 CSS 泡泡（外層 .bubble 冒出 / 啵破，內層 i 緩慢飄晃）；只動 transform / opacity，不擋操作 */
#bubbleOverlay { position: fixed; inset: 0; z-index: 25; pointer-events: none; overflow: hidden; }
#bubbleOverlay .bubble {
  position: absolute; margin: 0; opacity: 0; transform: translate(-50%, -50%) scale(.2);
  animation: bubbleIn .45s cubic-bezier(.3, 1.6, .5, 1) var(--d, 0s) forwards;
}
#bubbleOverlay .bubble i {
  position: absolute; inset: 0; border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, .95) 0 7%, rgba(255, 255, 255, 0) 15%),
    radial-gradient(circle at 70% 76%, rgba(255, 255, 255, .5) 0 4%, rgba(255, 255, 255, 0) 9%),
    radial-gradient(circle at 50% 50%, rgba(190, 240, 255, .32) 0 52%, rgba(160, 200, 255, .5) 64%, rgba(255, 190, 245, .7) 69%, rgba(255, 255, 255, .9) 71%, rgba(255, 255, 255, 0) 72%);
  animation: bubbleFloat var(--ft, 2s) ease-in-out var(--fd, 0s) infinite alternate;
}
#bubbleOverlay.pop .bubble { animation: bubblePop .25s ease-out var(--p, 0s) forwards; opacity: 1; transform: translate(-50%, -50%) scale(1); }
@keyframes bubbleIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.2); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes bubbleFloat {
  0% { transform: translate(0, 0) scale(1, 1); }
  50% { transform: translate(calc(var(--fx, 0vmin) * .5), calc(var(--fy, 0vmin) * .5)) scale(1.04, .97); }
  100% { transform: translate(var(--fx, 0vmin), var(--fy, 0vmin)) scale(.97, 1.03); }
}
@keyframes bubblePop {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.35); }
}
@media (prefers-reduced-motion: reduce) { #bubbleOverlay .bubble { animation-duration: .01s; } #bubbleOverlay .bubble i { animation: none; } }

/* ── U5 回合制：倒數 / 頒獎橫幅 / 慶祝提示 / 👑 ── */
.round-left { margin-left: 6px; font-size: .8em; font-weight: 700; letter-spacing: .05em; opacity: .85; font-variant-numeric: tabular-nums; }
.round-note { margin-bottom: 6px; padding: 4px 8px; border-radius: 10px; background: rgba(255, 195, 90, .18); font-size: 13px; font-weight: 700; line-height: 1.5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.round-note .round-celeb { opacity: .9; }
#boardList li .crown { flex: none; font-size: .85em; }
#podium {
  position: fixed; top: 6vh; left: 50%; transform: translateX(-50%); z-index: 29; pointer-events: none;
  min-width: 240px; max-width: min(80vw, 420px); padding: 12px 22px; border-radius: 22px; text-align: center;
  background: rgba(12, 18, 34, .55); border: 1px solid rgba(255, 207, 90, .6);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: 0 8px 30px rgba(0, 0, 0, .25);
}
#podium.show { animation: podiumIn .6s cubic-bezier(.3, 1.4, .5, 1); }
@keyframes podiumIn { 0% { opacity: 0; transform: translateX(-50%) scale(.7); } 100% { opacity: 1; transform: translateX(-50%) scale(1); } }
#podium .podium-title { font-size: 20px; font-weight: 900; letter-spacing: .12em; margin-bottom: 6px; color: #ffd93d; }
#podium .podium-row { font-size: 17px; font-weight: 700; padding: 3px 10px; margin: 3px 0; border-radius: 10px; border-left: 5px solid transparent; background: rgba(255, 255, 255, .08); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#podium .podium-row.champ { background: rgba(255, 217, 61, .25); }
#podium .podium-foot { margin-top: 6px; font-size: 13px; opacity: .85; letter-spacing: .1em; }
body.touch #podium { top: calc(8px + env(safe-area-inset-top)); padding: 8px 14px; min-width: 0; }
body.touch #podium .podium-title { font-size: 15px; margin-bottom: 3px; }
body.touch #podium .podium-row { font-size: 13px; padding: 2px 8px; }
body.touch .round-note { font-size: 11px; padding: 2px 6px; margin-bottom: 3px; }
body:not(.playing) #podium { display: none !important; }
