/* ===== 碰碰車大亂鬥 — 遊樂園夜晚霓虹招牌風 =====
 * 色票：夜空紫底、霓虹粉／青／黃；面板像燈箱招牌（燈泡點點邊框）；按鈕像遊樂設施大按鈕（有厚度、按下會沉）。 */
:root {
  --bg: #1d1640;
  --bg2: #2a1f5c;
  --panel: #2b2266;
  --panel2: #362b7d;
  --ink: #1a1236;
  --text: #fff8ee;
  --muted: #c9bff2;
  --pink: #ff4fa3;
  --pink-d: #b8236f;
  --cyan: #2fd6f5;
  --cyan-d: #1689a8;
  --yellow: #ffd23f;
  --yellow-d: #c4960c;
  --violet: #9c7bff;
  --violet-d: #5f43c4;
  --green: #4ee07a;
  --red: #ff4d5e;
  --bulb: #ffe9a3;
  --radius: 18px;
  --font: "Baloo 2", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --tb-size: 1;
  --tb-alpha: 0.75;
  --side-w: 240px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); -webkit-tap-highlight-color: transparent; }
body {
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 79, 163, .18), transparent 40%),
    radial-gradient(circle at 85% 90%, rgba(47, 214, 245, .16), transparent 45%),
    var(--bg);
  overscroll-behavior: none;
  touch-action: manipulation;
}
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; border-radius: 10px; }
svg { stroke: currentColor; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 全域工具列 ---------- */
.topbar-global {
  position: fixed; z-index: 60; top: calc(10px + var(--safe-t)); right: calc(10px + var(--safe-r));
  display: flex; gap: 8px; align-items: center;
}
.icon-btn {
  width: 48px; height: 48px; border-radius: 14px; border: 0; cursor: pointer;
  display: grid; place-items: center; background: var(--panel2); color: var(--text);
  box-shadow: 0 4px 0 #1a1440, inset 0 0 0 2px rgba(255,255,255,.12);
  transition: transform .08s, box-shadow .08s;
}
.icon-btn svg { width: 26px; height: 26px; }
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #1a1440, inset 0 0 0 2px rgba(255,255,255,.12); }

/* ---------- 下拉選單 ---------- */
.dd { position: relative; display: inline-block; }
.dd-btn {
  min-height: 48px; min-width: 120px; display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 14px;
  border: 0; border-radius: 14px; background: var(--panel2); cursor: pointer; text-align: left;
  box-shadow: 0 4px 0 #1a1440, inset 0 0 0 2px rgba(255,255,255,.14); font-weight: 800;
}
.dd-btn:disabled { opacity: .55; cursor: default; }
.dd-label { flex: 1; display: flex; align-items: center; gap: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dd-caret svg, .dd-icon svg { width: 20px; height: 20px; display: block; }
.dd.is-open .dd-caret { transform: rotate(180deg); }
.dd-swatch { width: 16px; height: 16px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 2px rgba(255,255,255,.4); }
.dd-list {
  position: absolute; z-index: 80; top: calc(100% + 6px); left: 0; margin: 0; padding: 6px 4px 6px 6px;
  background: #241b58; border-radius: 14px; box-shadow: 0 12px 30px rgba(0,0,0,.45), inset 0 0 0 2px rgba(255,255,255,.14);
  display: none; outline: none;
}
.dd-list.up { top: auto; bottom: calc(100% + 6px); }
.dd-list.open { display: flex; }   /* 外框是自訂捲動區（.sa），選項太多時右側有自繪捲軸 */
.dd-list.sa:not(.open) { display: none; }   /* .sa 的 display:flex 不能讓關著的選單露出來 */
.dd-list.sa-over .dd-ul { padding-right: 12px; }
.dd-ul { margin: 0; padding: 0; list-style: none; outline: none; }
.dd-opt { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 12px; border-radius: 10px; cursor: pointer; font-weight: 700; white-space: nowrap; }
.dd-opt.active { background: rgba(255,255,255,.12); }
.dd-opt[aria-selected="true"] { color: var(--yellow); }
.dd-opt[aria-selected="true"]::after { content: ""; margin-left: auto; width: 8px; height: 8px; border-radius: 50%; background: var(--yellow); }
.dd-badge { margin-left: auto; font-size: .8em; color: var(--muted); }
.dd-lang .dd-btn { min-width: 0; }
.dd-lang .dd-list { left: auto; right: 0; }

/* ---------- 按鈕 ---------- */
.btn {
  min-height: 48px; padding: 8px 18px; border: 0; border-radius: 14px; cursor: pointer; font-weight: 800; letter-spacing: .02em;
  background: var(--panel2); color: var(--text); box-shadow: 0 5px 0 #18113d, inset 0 0 0 2px rgba(255,255,255,.14);
  transition: transform .08s, box-shadow .08s, filter .15s; white-space: normal; line-height: 1.15;
}
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 #18113d, inset 0 0 0 2px rgba(255,255,255,.14); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { min-height: 44px; padding: 6px 12px; font-size: .92em; border-radius: 12px; }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 2px rgba(255,255,255,.3); }
.btn.ghost:active:not(:disabled) { transform: translateY(2px); box-shadow: inset 0 0 0 2px rgba(255,255,255,.3); }
.b-pink { background: var(--pink) !important; color: #fff; box-shadow: 0 5px 0 var(--pink-d), inset 0 0 0 2px rgba(255,255,255,.25) !important; }
.b-cyan { background: var(--cyan) !important; color: var(--ink); box-shadow: 0 5px 0 var(--cyan-d), inset 0 0 0 2px rgba(255,255,255,.3) !important; }
.b-yellow { background: var(--yellow) !important; color: var(--ink); box-shadow: 0 5px 0 var(--yellow-d), inset 0 0 0 2px rgba(255,255,255,.35) !important; }
.b-violet { background: var(--violet) !important; color: #fff; box-shadow: 0 5px 0 var(--violet-d), inset 0 0 0 2px rgba(255,255,255,.25) !important; }
.big-btn {
  display: flex; align-items: center; gap: 14px; min-height: 64px; padding: 10px 20px; border: 0; border-radius: 20px; cursor: pointer; text-align: left;
  font-size: 1.15rem; transition: transform .08s, box-shadow .08s; background: var(--panel2);
}
.big-btn b { display: block; font-size: 1.25em; line-height: 1.1; }
.big-btn small { display: block; font-weight: 600; opacity: .85; font-size: .78em; margin-top: 2px; }
.big-btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,.4) !important; }
.big-btn:disabled { opacity: .6; cursor: not-allowed; filter: grayscale(1) brightness(.8); box-shadow: 0 3px 0 rgba(0,0,0,.35), inset 0 0 0 2px rgba(255,255,255,.25) !important; }   /* 不能按的大按鈕：灰階，一眼看出還不能開始 */
.bb-ico { width: 52px; height: 52px; flex: none; border-radius: 16px; background: rgba(255,255,255,.22); display: grid; place-items: center; }
.bb-ico svg { width: 32px; height: 32px; }
.go-btn { justify-content: center; text-align: center; min-width: 200px; }

/* ---------- 開關 ---------- */
.sw {
  position: relative; width: 64px; height: 38px; flex: none; border: 0; border-radius: 20px; cursor: pointer; padding: 0;
  background: #4a3f86; box-shadow: inset 0 3px 0 rgba(0,0,0,.3); transition: background .15s;
}
.sw[aria-checked="true"] { background: var(--green); }
.sw-knob { position: absolute; top: 4px; left: 4px; width: 30px; height: 30px; border-radius: 50%; background: #fff; box-shadow: 0 3px 0 rgba(0,0,0,.25); transition: transform .15s; }
.sw[aria-checked="true"] .sw-knob { transform: translateX(26px); }
.sw::after { content: ""; position: absolute; inset: -5px 0; }

/* ---------- 滑桿 ---------- */
.slider { width: min(220px, 46vw); height: 44px; display: flex; align-items: center; cursor: pointer; touch-action: none; border-radius: 12px; }
.sl-track { position: relative; flex: 1; height: 12px; border-radius: 6px; background: #4a3f86; box-shadow: inset 0 2px 0 rgba(0,0,0,.3); }
.sl-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 6px; background: var(--cyan); }
.sl-thumb { position: absolute; top: 50%; width: 28px; height: 28px; border-radius: 50%; background: #fff; transform: translate(-50%, -50%); box-shadow: 0 3px 0 rgba(0,0,0,.3), 0 0 0 4px rgba(47,214,245,.35); }

/* ---------- 加減鈕 ---------- */
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.st-btn { width: 44px; height: 44px; border: 0; border-radius: 12px; background: var(--panel2); cursor: pointer; display: grid; place-items: center; box-shadow: 0 4px 0 #18113d; }
.st-btn svg { width: 22px; height: 22px; }
.st-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #18113d; }
.st-btn:disabled { opacity: .4; cursor: default; }
.st-val { min-width: 2.2em; text-align: center; font-size: 1.3rem; font-weight: 800; }

/* ---------- 文字輸入 ---------- */
.txt {
  appearance: none; -webkit-appearance: none; min-height: 48px; width: min(260px, 100%); padding: 8px 14px; border: 0; border-radius: 14px;
  background: #160f38; color: var(--text); font-weight: 700; box-shadow: inset 0 3px 0 rgba(0,0,0,.35), inset 0 0 0 2px rgba(255,255,255,.12);
}
.txt::placeholder { color: #8f86c2; }
.txt:focus { outline: 3px solid var(--cyan); outline-offset: 2px; }

/* ---------- 鍵帽 ---------- */
.kc { display: inline-grid; place-items: center; min-width: 28px; height: 28px; padding: 0 6px; margin: 0 2px; border-radius: 7px; background: #fff; color: var(--ink); font: 800 .82rem var(--font); box-shadow: 0 3px 0 #9d94c9; vertical-align: middle; }
.kc.wide { min-width: 48px; }

/* ---------- 捲動區（自訂捲軸） ---------- */
/* 捲動區用 flex 決定高度：父層是 flex 項目時 height:100% 算不出來，內容會被裁掉卻不能捲 */
.sa { position: relative; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.sa-view { flex: 1 1 auto; min-height: 0; max-height: inherit; overflow: auto; scrollbar-width: none; -ms-overflow-style: none; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.sa-view::-webkit-scrollbar { display: none; }
.sa-track { position: absolute; top: 6px; bottom: 6px; right: 3px; width: 8px; border-radius: 4px; background: rgba(255,255,255,.08); opacity: 0; transition: opacity .2s; z-index: 5; }
.sa-over > .sa-track:not(.sa-h) { opacity: 1; transition: none; }  /* 內容一超出就立刻顯示捲軸，收起時才淡出 */
.sa-thumb { width: 100%; border-radius: 4px; background: linear-gradient(var(--pink), var(--violet)); cursor: grab; touch-action: none; }
.sa-track.sa-h { top: auto; bottom: 3px; left: 6px; right: 6px; width: auto; height: 8px; }
.sa-h .sa-thumb { height: 100%; }
.sa-over-x > .sa-h { opacity: 1; }
.sa-drag .sa-thumb { cursor: grabbing; }
.sa-track::before { content: ""; position: absolute; inset: 0 -8px; }

/* ---------- 畫面骨架 ---------- */
#app { position: fixed; inset: 0; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; }
.scr-head {
  flex: none; display: flex; align-items: center; gap: 12px; min-height: 68px;
  padding: calc(10px + var(--safe-t)) calc(var(--gw, 196px) + 8px) 8px calc(12px + var(--safe-l));   /* --gw＝右上角語言＋設定鈕實際佔的寬度（app 依語系量測） */
}
.scr-head h2 { margin: 0; font-size: clamp(1.25rem, 3.6vw, 1.8rem); line-height: 1.1; text-shadow: 0 3px 0 rgba(0,0,0,.35); min-width: 0; overflow-wrap: anywhere; }
.back-btn { width: 48px; height: 48px; flex: none; border: 0; border-radius: 14px; background: var(--panel2); cursor: pointer; display: grid; place-items: center; box-shadow: 0 4px 0 #18113d; }
.back-btn svg { width: 28px; height: 28px; }
.back-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #18113d; }
.scr-body { flex: 1; min-height: 0; }
.scr-body > .sa-view > * { padding: 4px calc(14px + var(--safe-r)) 20px calc(14px + var(--safe-l)); }
.scr-foot { flex: none; display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; padding: 10px calc(14px + var(--safe-r)) calc(12px + var(--safe-b)) calc(14px + var(--safe-l)); background: linear-gradient(transparent, rgba(0,0,0,.25)); }
.panel {
  position: relative; margin: 0 auto 16px; max-width: 760px; padding: 16px 18px; border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  box-shadow: 0 6px 0 #160f3a, inset 0 0 0 3px rgba(255,233,163,.18);
}
.panel::before { /* 燈箱招牌的燈泡邊 */
  content: ""; position: absolute; inset: 5px; border-radius: calc(var(--radius) - 5px); pointer-events: none;
  border: 3px dotted rgba(255,233,163,.5);
}
.panel h3 { margin: 0 0 10px; font-size: 1.2rem; color: var(--yellow); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; min-height: 56px; padding: 4px 0; }
.row-label { font-weight: 800; display: flex; flex-direction: column; min-width: 0; flex: 1 1 140px; }
.row-label small, .set-row small { font-weight: 600; color: var(--muted); font-size: .8rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.hint { color: var(--muted); font-size: .9rem; margin: 8px 0 0; }
.err { color: #ff9aa5; font-weight: 700; min-height: 1.2em; margin: 6px 0 0; }
.toast {
  position: fixed; z-index: 90; left: calc(10px + var(--safe-l)); right: calc(10px + var(--safe-r)); margin: 0 auto; width: fit-content; bottom: calc(24px + var(--safe-b)); transform: translateY(30px);   /* 置中用左右＋auto，避免 left:50% 讓可用寬度只剩一半、長訊息被擠成窄條 */ opacity: 0; pointer-events: none;
  max-width: min(92vw, 460px); padding: 12px 18px; border-radius: 14px; background: #fff; color: var(--ink); font-weight: 800; text-align: center;
  box-shadow: 0 6px 0 rgba(0,0,0,.3); transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.bad { background: #ffd4d9; }

/* ---------- 首頁 ---------- */
#s-home { overflow: hidden; }
.hero-cv { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .5; filter: saturate(.85); }
#s-home::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 50%, rgba(29,22,64,.55), rgba(29,22,64,.15) 70%); }
.home-scroll { z-index: 1; }
.home-scroll { position: relative; flex: 1; min-height: 0; }
.home-inner { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: calc(72px + var(--safe-t)) calc(16px + var(--safe-r)) calc(20px + var(--safe-b)) calc(16px + var(--safe-l)); }
.lobby-link {
  position: absolute; z-index: 20; top: calc(10px + var(--safe-t)); left: calc(10px + var(--safe-l)); display: flex; align-items: center; gap: 4px;
  min-height: 48px; padding: 6px 14px 6px 8px; border-radius: 14px; color: var(--text); text-decoration: none; font-weight: 800;
  background: rgba(43,34,102,.88); box-shadow: 0 4px 0 #18113d;
}
.lobby-link svg { width: 24px; height: 24px; }
.logo { text-align: center; }
.logo-title {
  margin: 0; font-size: clamp(2.4rem, 9vw, 4.6rem); line-height: 1; color: #fff; letter-spacing: .02em;
  text-shadow: 0 0 12px var(--pink), 0 0 30px rgba(255,79,163,.6), 0 5px 0 var(--pink-d);
  -webkit-text-stroke: 2px #fff2fa;
}
.logo-sub { margin: 10px 0 0; font-size: clamp(1rem, 3vw, 1.3rem); font-weight: 800; color: var(--yellow); text-shadow: 0 2px 0 rgba(0,0,0,.4); }
.home-menu { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; width: min(760px, 100%); }
.home-menu .big-btn { min-height: 92px; }
.home-stats { margin: 0; padding: 8px 16px; border-radius: 999px; background: rgba(20,14,50,.6); font-weight: 700; color: var(--muted); text-align: center; }
.home-stats:empty { display: none; }

/* ---------- 單機設定 ---------- */
/* 寬螢幕（桌機、平板橫拿）：選車放左欄、電腦對手與這局設定放右欄，少捲動也不浪費兩側空間 */
@media (min-width: 1080px) and (orientation: landscape) {
  .setup { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 18px; max-width: 1240px; margin: 0 auto; align-items: start; }
  .setup { grid-template-areas: "cars cpus" "rules cpus"; }
  .setup > .panel { max-width: none; margin: 0 0 16px; }
  .setup > .panel:nth-child(1) { grid-area: cars; }
  .setup > .panel:nth-child(2) { grid-area: cpus; }
  .setup > .panel:nth-child(3) { grid-area: rules; }
  .setup .car-card canvas { max-width: 92px; }
  .setup .theme-preview { max-width: 260px; }
}
.car-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.car-card {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px 8px; border: 0; border-radius: 16px; cursor: pointer;
  background: rgba(255,255,255,.08); box-shadow: inset 0 0 0 2px rgba(255,255,255,.12); min-height: 48px;
}
.car-card canvas { width: 100%; aspect-ratio: 1; max-width: 120px; }
.car-card span { font-weight: 800; font-size: .92rem; }
.car-card[aria-checked="true"] { background: rgba(255,210,63,.22); box-shadow: inset 0 0 0 3px var(--yellow), 0 0 18px rgba(255,210,63,.35); }
.mini-cars { display: flex; flex-wrap: wrap; gap: 6px; }
.mini-cars .car-card { width: 58px; padding: 2px; }
.mini-cars .car-card span { display: none; }
.cpu-list { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 8px; }
.cpu-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 6px 8px; border-radius: 14px; background: rgba(0,0,0,.18); }
.cpu-row canvas { width: 48px; height: 48px; flex: none; }
.cpu-row .cpu-name { flex: 1 1 100px; font-weight: 800; min-width: 0; }
.theme-preview { display: block; width: 100%; max-width: 360px; aspect-ratio: 16 / 9; margin: 10px auto 0; border-radius: 14px; }

/* ---------- 大廳 ---------- */
.conn { margin-left: auto; padding: 4px 10px; border-radius: 999px; font-size: .85rem; font-weight: 800; background: rgba(0,0,0,.25); white-space: nowrap; }
.conn.ok { color: var(--green); }
.conn.wait { color: var(--yellow); }
.conn.bad { color: #ff9aa5; }
.room-list { display: grid; gap: 10px; }
.room-item { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 12px; border-radius: 14px; background: rgba(0,0,0,.2); }
.room-item .ri-main { flex: 1 1 180px; min-width: 0; }
.room-item .ri-name { font-weight: 800; font-size: 1.05rem; overflow-wrap: anywhere; }
.room-item .ri-meta { color: var(--muted); font-size: .85rem; display: flex; gap: 8px; flex-wrap: wrap; }
.tag { padding: 1px 8px; border-radius: 999px; background: rgba(255,255,255,.12); font-weight: 800; font-size: .78rem; }
.tag.play { background: rgba(255,79,163,.3); }
.tag.wait { background: rgba(78,224,122,.25); }
.empty { color: var(--muted); text-align: center; padding: 18px 8px; }

/* ---------- 房間 ---------- */
.room-code { font-size: .6em; color: var(--muted); }
.role-tag { max-width: 760px; margin: 0 auto 10px; font-weight: 800; color: var(--cyan); }
.seats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.seat { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 8px; border-radius: 16px; background: rgba(0,0,0,.2); min-height: 150px; text-align: center; }
.seat canvas { width: 72px; height: 72px; }
.seat .s-name { font-weight: 800; overflow-wrap: anywhere; }
.seat .s-sub { color: var(--muted); font-size: .82rem; }
.seat.me { box-shadow: inset 0 0 0 3px var(--yellow); }
.seat.ready .s-sub { color: var(--green); font-weight: 800; }
.seat.empty-seat { justify-content: center; border: 2px dashed rgba(255,255,255,.2); background: transparent; }
.seat .seat-acts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.seat .host-crown { position: absolute; top: 6px; left: 8px; color: var(--yellow); font-weight: 900; font-size: .8rem; }
.invite-box { padding: 10px 12px; border-radius: 12px; background: #160f38; font-family: ui-monospace, monospace; font-size: .85rem; overflow-wrap: anywhere; user-select: all; }
.room-foot .go-btn { min-width: 180px; }
.room-foot.rc-dock { padding-left: calc(84px + var(--safe-l)); }   /* 讓出左邊給聊天氣泡 */
.room-foot.rc-dock .go-btn { min-width: 0; flex: 1 1 140px; }
/* ---------- 房間聊天（左下） ---------- */
.room-chat { position: absolute; z-index: 20; left: calc(14px + var(--safe-l)); bottom: var(--rc-bottom, calc(92px + var(--safe-b))); pointer-events: none; }
.room-chat > * { pointer-events: auto; }
.room-chat-fab { position: relative; width: 56px; height: 56px; border: 0; border-radius: 50%; cursor: pointer; display: grid; place-items: center; color: #fff; background: var(--violet); box-shadow: 0 5px 0 var(--violet-d), 0 0 0 3px rgba(255,255,255,.18); }
.room-chat-fab svg { width: 28px; height: 28px; }
.room-chat-fab:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--violet-d); }
.room-chat-fab.bump { animation: fabBump .5s ease-out; }
@keyframes fabBump { 30% { transform: translateY(-6px) scale(1.08); } }
.room-chat-panel { display: none; position: absolute; left: 0; bottom: 68px; width: min(320px, calc(100vw - 28px)); height: min(52vh, 440px); min-height: 260px; padding: 12px; border-radius: 18px; flex-direction: column; background: linear-gradient(180deg, var(--panel2), var(--panel)); box-shadow: 0 6px 0 #160f3a, inset 0 0 0 3px rgba(255,233,163,.2); }
.room-chat.open .room-chat-panel { display: flex; }
.room-chat-slot { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.room-chat-slot .chat { min-height: 0; }
.room-chat-close { position: absolute; top: 6px; right: 6px; width: 44px; height: 44px; z-index: 2; }
.room-chat-close svg { width: 22px; height: 22px; }
.room-chat-slot .chat h3 { padding-right: 48px; min-height: 32px; display: flex; align-items: center; }
/* 寬螢幕：聊天固定在左欄，房間內容往右讓 */
@media (min-width: 1080px) and (orientation: landscape) and (min-height: 600px) {
  .room-chat { top: calc(76px + var(--safe-t)); width: 300px; }
  .room-chat-fab, .room-chat-close { display: none; }
  .room-chat-panel { display: flex; position: absolute; inset: 0; width: auto; height: auto; }
  #s-room .scr-body { margin-left: calc(314px + var(--safe-l)); }
}
/* 手機（窄或矮）：點開是全螢幕面板，蓋過房間所有按鈕 */
@media (max-width: 640px), (max-height: 520px) {
  .room-chat.open { position: fixed; inset: 0; z-index: 65; padding: calc(10px + var(--safe-t)) calc(10px + var(--safe-r)) calc(10px + var(--safe-b)) calc(10px + var(--safe-l)); background: rgba(10,6,30,.7); }
  .room-chat.open .room-chat-fab { display: none; }
  body.room-chat-full #network-latency { visibility: hidden; }
  .room-chat.open .room-chat-panel { position: relative; left: auto; bottom: auto; width: 100%; height: 100%; min-height: 0; }
}

/* ---------- 對局 ---------- */
#s-game { background: #000; }
.game-wrap { position: absolute; inset: 0; display: flex; }
.side {
  position: relative; z-index: 15; flex: none; width: var(--side-w); display: flex; flex-direction: column; gap: 8px;
  padding: calc(10px + var(--safe-t)) 10px calc(10px + var(--safe-b)) calc(10px + var(--safe-l));
  background: rgba(24,17,60,.94); box-shadow: 4px 0 0 rgba(0,0,0,.25); transition: width .2s;
}
.side-toggle { position: relative; width: 48px; height: 48px; flex: none; border: 0; border-radius: 14px; background: var(--panel2); cursor: pointer; display: grid; place-items: center; box-shadow: 0 4px 0 #18113d; }
.side-toggle svg { width: 26px; height: 26px; }
.unread { position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--red); color: #fff; font-size: .75rem; font-weight: 900; display: grid; place-items: center; }
.side-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.side.collapsed { width: calc(68px + var(--safe-l)); }
.side.collapsed .side-body { display: none; }
.summary h3, .chat h3 { margin: 0 0 6px; font-size: 1rem; color: var(--yellow); }
.sum-status { margin: 0 0 8px; font-weight: 700; font-size: .9rem; color: var(--muted); }
.rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.rank li { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 10px; background: rgba(255,255,255,.06); font-weight: 700; font-size: .9rem; }
.rank li.out { opacity: .5; }
.rank li.rank-team { background: none; padding: 6px 2px 0; font-size: .8rem; font-weight: 900; }
.rank li.me { box-shadow: inset 0 0 0 2px var(--yellow); }
.rank .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.rank .rn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .rk { color: var(--yellow); }
.chat { flex: 1; min-height: 160px; display: flex; flex-direction: column; }
.chat-log { flex: 1; min-height: 60px; border-radius: 12px; background: rgba(0,0,0,.25); }
.chat-log .sa-view > div { padding: 6px 14px 6px 8px; }
.cmsg { margin: 0 0 4px; font-size: .88rem; overflow-wrap: anywhere; }
.cmsg b { color: var(--cyan); }
.cmsg.sys { color: var(--muted); font-style: italic; }
.cmsg.mine b { color: var(--yellow); }
.cmsg.pending { opacity: .6; }
.quick-phr { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.quick-phr button { min-height: 44px; padding: 2px 12px; border: 0; border-radius: 999px; background: rgba(255,255,255,.12); cursor: pointer; font-size: .82rem; font-weight: 700; }
.chat-form { display: flex; gap: 6px; }
.chat-form .txt { min-height: 40px; flex: 1; width: auto; min-width: 0; font-size: .9rem; }

.stage { position: relative; flex: 1; min-width: 0; overflow: hidden; touch-action: none; }
#game-cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hud-top { position: absolute; z-index: 10; top: calc(10px + var(--safe-t)); left: 10px; right: calc(10px + var(--safe-r)); display: flex; align-items: center; gap: 10px; pointer-events: none; padding-right: var(--gw, 210px); }
.hud-top > * { pointer-events: auto; }
.hud-bar { display: flex; align-items: center; gap: 12px; padding: 4px 14px; min-height: 44px; border-radius: 999px; background: rgba(20,14,50,.75); font-weight: 800; }
.hud-time { font-size: 1.4rem; min-width: 2.2em; text-align: center; font-variant-numeric: tabular-nums; }
.hud-time.warn { color: var(--red); animation: pulse .5s infinite alternate; }
.hud-alive { color: var(--muted); }
.role-pill { padding: 4px 12px; border-radius: 999px; background: rgba(47,214,245,.25); font-weight: 800; }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.15); } }
.ghost-tip { position: absolute; z-index: 9; left: calc(66px + var(--safe-l)); right: calc(10px + var(--safe-r)); margin: 0 auto; width: fit-content; top: calc(64px + var(--safe-t)); max-width: min(92%, 520px); padding: 5px 14px; border-radius: 12px; background: rgba(120,92,230,.72); font-size: .86rem; line-height: 1.35; font-weight: 800; text-align: center; pointer-events: none; animation: tipLife 5s ease forwards; }   /* 小一點、半透明，5 秒後淡出 */
@keyframes tipLife { 0% { opacity: 0; transform: translateY(-6px); } 6% { opacity: 1; transform: none; } 88% { opacity: 1; } 100% { opacity: 0; } }
.countdown {
  position: absolute; z-index: 25; inset: 0; display: grid; place-items: center; pointer-events: none;
  font: 900 clamp(96px, 26vmin, 220px)/1 var(--font); color: #fff; -webkit-text-stroke: 10px var(--ink); paint-order: stroke fill;
  text-shadow: 0 8px 0 var(--pink), 0 0 40px rgba(255,79,163,.7);
}
.countdown span { animation: pop .9s ease-out both; }
.countdown.go span { color: var(--yellow); font-size: .6em; }
@keyframes pop { 0% { transform: scale(2.2); opacity: 0; } 25% { transform: scale(1); opacity: 1; } 80% { opacity: 1; } 100% { transform: scale(.85); opacity: 0; } }

/* 觸控 */
.touch { position: absolute; inset: 0; z-index: 8; pointer-events: none; display: none; }
body.touch-on .touch { display: block; }
.joy-zone { position: absolute; left: 0; bottom: 0; width: 50%; height: 65%; pointer-events: auto; touch-action: none; }
.joy { position: absolute; left: calc(30px + var(--safe-l) + 70px * var(--tb-size)); bottom: calc(30px + var(--safe-b) + 70px * var(--tb-size)); width: 0; height: 0; opacity: var(--tb-alpha); }
.joy-base { position: absolute; width: calc(140px * var(--tb-size)); height: calc(140px * var(--tb-size)); left: 0; top: 0; transform: translate(-50%, -50%); border-radius: 50%; background: rgba(255,255,255,.14); box-shadow: inset 0 0 0 4px rgba(255,255,255,.35); }
.joy-knob { position: absolute; width: calc(64px * var(--tb-size)); height: calc(64px * var(--tb-size)); left: 0; top: 0; transform: translate(-50%, -50%); border-radius: 50%; background: rgba(255,255,255,.85); box-shadow: 0 4px 0 rgba(0,0,0,.3); }
.joy.active { opacity: 1; }
.tbtns { position: absolute; right: calc(18px + var(--safe-r)); bottom: calc(18px + var(--safe-b)); display: flex; align-items: flex-end; gap: 14px; pointer-events: auto; opacity: var(--tb-alpha); }
.tbtn { position: relative; border: 0; border-radius: 50%; cursor: pointer; display: grid; place-items: center; touch-action: none; color: #fff; font-weight: 900; }
.tbtn-dash { width: calc(118px * var(--tb-size)); height: calc(118px * var(--tb-size)); background: var(--pink); box-shadow: 0 7px 0 var(--pink-d); font-size: calc(1.15rem * var(--tb-size)); }
.tbtn-item { width: calc(78px * var(--tb-size)); height: calc(78px * var(--tb-size)); background: var(--violet); box-shadow: 0 6px 0 var(--violet-d); margin-bottom: calc(26px * var(--tb-size)); }
.tbtn-item canvas { width: 72%; height: 72%; }
.tbtn-item.empty { filter: grayscale(1); opacity: .55; }
.tbtn.pressed { transform: translateY(5px); box-shadow: 0 2px 0 rgba(0,0,0,.35); }
.tbtn.cooling { filter: saturate(.4) brightness(.85); }
.tbtn-key { position: absolute; bottom: -4px; right: -2px; min-width: 26px; height: 22px; padding: 0 5px; border-radius: 6px; background: #fff; color: var(--ink); font-size: .7rem; display: grid; place-items: center; box-shadow: 0 2px 0 #9d94c9; }
body.touch-on .tbtn-key { display: none; }
.cd-ring { position: absolute; inset: -6px; width: calc(100% + 12px); height: calc(100% + 12px); transform: rotate(-90deg); pointer-events: none; }
.cd-ring circle { fill: none; stroke: rgba(255,255,255,.25); stroke-width: 6; }
.cd-ring .cd-arc { stroke: #fff; stroke-dasharray: 283; stroke-dashoffset: 0; }
/* 鍵盤玩家也看得到衝刺／道具狀態：非觸控時縮小顯示在右下 */
body:not(.touch-on) .touch { display: block; }
body:not(.touch-on) .joy-zone { display: none; }
body:not(.touch-on) .tbtns { --tb-size: .62; opacity: .9; }

.practice-bar { position: absolute; z-index: 12; left: calc(66px + var(--safe-l)); right: calc(10px + var(--safe-r)); margin: 0 auto; width: fit-content; top: calc(64px + var(--safe-t)); display: flex; flex-direction: column; gap: 6px; align-items: center; max-width: calc(100% - 20px);   /* 不用 left:50%＋translate（那樣可用寬度只剩一半，道具會被擠成兩排） */ padding: 8px 10px; border-radius: 16px; background: rgba(20,14,50,.72); }
.pr-items { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.pr-items button { width: 48px; height: 48px; border: 0; border-radius: 12px; background: rgba(255,255,255,.14); cursor: pointer; display: grid; place-items: center; box-shadow: 0 3px 0 rgba(0,0,0,.3); }
.pr-items canvas { width: 36px; height: 36px; }
.pr-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
.pr-row .row-label { flex: none; }
/* 收合鈕：收起後只留「練習工具」＋「離開」，不擋擂台 */
.pr-toggle { flex: none; min-width: 44px; height: 44px; padding: 0 10px; border: 0; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: rgba(255,255,255,.14); color: #fff; font: inherit; font-weight: 800; cursor: pointer; }
.pr-toggle svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s; }
.pr-toggle-label { display: none; }
.practice-bar.collapsed { padding: 4px 6px; background: rgba(20,14,50,.55); }
.practice-bar.collapsed .pr-items, .practice-bar.collapsed .pr-row > .row-label, .practice-bar.collapsed #pr-count, .practice-bar.collapsed #pr-reset { display: none; }
.practice-bar.collapsed .pr-toggle-label { display: inline; }
.practice-bar.collapsed .pr-toggle svg { transform: rotate(180deg); }
@media (max-width: 480px) {   /* 窄手機：工具列讓開左上角☰，道具鈕 44px、間距縮小，盡量一排放完 */
  .practice-bar { padding: 6px 8px; }
  .pr-items { gap: 4px; }
  .pr-items button { width: 44px; height: 44px; }
  .pr-items canvas { width: 32px; height: 32px; }
  .pr-row { gap: 5px; }
  .pr-row .btn.small { padding-left: 10px; padding-right: 10px; }
}
/* 橫向（寬比高多）：練習工具列改成右側直欄，擂台往左讓、不會因為工具列縮小；收合時只剩「離開」和展開鈕 */
@media (min-aspect-ratio: 11/10) {
  .practice-bar { left: auto; right: calc(10px + var(--safe-r)); margin: 0; width: auto; max-width: none; top: calc(64px + var(--safe-t)); padding: 8px; }
  .pr-items { display: grid; grid-template-columns: repeat(3, auto); }
  .pr-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; width: 100%; justify-items: center; }
  .pr-row > .row-label, .pr-row > #pr-count, .pr-row > #pr-reset { grid-column: span 2; }
  .pr-row > #pr-reset { width: 100%; }
  .pr-row > #pr-exit, .pr-row > .pr-toggle { width: 100%; }
  .practice-bar.collapsed .pr-row { grid-template-columns: auto auto; }
  .practice-bar.collapsed .pr-toggle svg { transform: rotate(-90deg); }   /* 收在右邊：箭頭朝左表示往左展開 */
  .practice-bar:not(.collapsed) .pr-toggle svg { transform: rotate(90deg); }
}
@media (min-aspect-ratio: 11/10) and (max-height: 500px) {   /* 矮的橫向手機：道具｜控制左右並排，整塊放得進衝刺鍵上方 */
  .practice-bar { top: calc(58px + var(--safe-t)); padding: 6px; gap: 6px; flex-direction: row; align-items: flex-start; }
  .pr-row { width: auto; grid-template-columns: auto auto; }
  .pr-row > .row-label { font-size: .75rem; line-height: 1; }
  #s-game:has(.practice-bar:not([hidden]):not(.collapsed)) .th-right { visibility: hidden; }   /* 右側提示會被展開的工具列蓋住、透出來很亂：展開時先不顯示 */
  .pr-items { gap: 4px; }
  .pr-items button { width: 44px; height: 44px; }
  .pr-items canvas { width: 32px; height: 32px; }
  .pr-row { gap: 4px; }
}
.rotate-tip .btn { flex: none; white-space: nowrap; }
.rotate-tip { position: absolute; z-index: 11; left: calc(66px + var(--safe-l));   /* 讓開左上角☰ */ right: calc(10px + var(--safe-r)); margin: 0 auto; width: fit-content; top: calc(64px + var(--safe-t)); display: flex; gap: 10px; align-items: center; padding: 6px 8px 6px 14px; border-radius: 14px; background: rgba(20,14,50,.85); font-weight: 800; max-width: calc(100% - 20px); }

/* 結算（疊在擂台上） */
.result { position: absolute; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; padding: calc(64px + var(--safe-t)) 12px calc(12px + var(--safe-b)); background: rgba(16,10,40,.55); backdrop-filter: blur(2px); }
.result-card {
  width: min(560px, 100%); max-height: 100%; display: flex; flex-direction: column; gap: 8px; padding: 18px; border-radius: 24px;
  background: linear-gradient(180deg, var(--panel2), var(--panel)); box-shadow: 0 8px 0 #160f3a, inset 0 0 0 3px rgba(255,233,163,.25); animation: rise .35s ease-out;
}
@keyframes rise { from { transform: translateY(30px) scale(.96); opacity: 0; } }
.result-card h2 { margin: 0; text-align: center; font-size: clamp(1.6rem, 5vw, 2.4rem); color: var(--yellow); text-shadow: 0 3px 0 rgba(0,0,0,.4); }
.result-sub { margin: 0; text-align: center; color: var(--muted); font-weight: 700; }
.result-scroll { position: relative; flex: 1 1 auto; min-height: 96px; }
/* 內容超出時：底部漸層＋常駐自訂捲軸，看得出來可以往下捲 */
.result-scroll.sa-over:not(.sa-end)::after { content: ""; position: absolute; left: 0; right: 14px; bottom: 0; height: 36px; pointer-events: none; background: linear-gradient(rgba(43,34,102,0), var(--panel)); border-radius: 0 0 12px 12px; }
.result-card > :not(.result-scroll) { flex: none; }
.podium { list-style: none; margin: 0; padding: 0 12px 0 0; display: grid; gap: 6px; }
.podium li { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 14px; background: rgba(0,0,0,.2); font-weight: 800; }
.podium li.me { box-shadow: inset 0 0 0 3px var(--yellow); }
.podium .pl { width: 34px; height: 34px; flex: none; border-radius: 50%; display: grid; place-items: center; background: #4a3f86; font-size: 1.05rem; }
.podium li:nth-child(1) .pl { background: #ffd23f; color: var(--ink); }
.podium .pl.medal-2 { background: #d6dbe6; color: var(--ink); }
.podium .pl.medal-3 { background: #e39b5b; color: var(--ink); }
.podium canvas { width: 40px; height: 40px; flex: none; }
.podium .pn { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.podium .pk { color: var(--yellow); white-space: nowrap; }
.my-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); grid-auto-flow: dense; gap: 6px; margin: 8px 14px 4px 0; }   /* dense：寬格子換行留下的空位由後面的小格補上 */
.my-stats div { padding: 4px 8px; border-radius: 10px; background: rgba(255,255,255,.07); }
.my-stats dt { font-size: .78rem; color: var(--muted); font-weight: 700; }
.my-stats dd { margin: 0; font-weight: 800; font-size: .98rem; word-break: keep-all; overflow-wrap: break-word; line-height: 1.35; }   /* 中文只在「、」等標點換行，不會出現「護／盾」 */
.my-stats .txt dd { font-size: .88rem; }
.my-stats .wide { grid-column: span 2; }
/* 再來一局（主要）一整列；分享、回到設定／房間、回到首頁同一列 */
.result-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 10px; }
.result-actions #res-again { grid-column: 1 / -1; order: -1; justify-content: center; text-align: center; min-height: 58px; }
.result-actions .btn { padding: 8px 10px; }

/* ---------- 怎麼玩 ---------- */
.howto { max-width: 820px; margin: 0 auto; display: grid; gap: 14px; }
.how-card { display: grid; grid-template-columns: 180px 1fr; gap: 16px; align-items: center; }
.how-card canvas { width: 180px; height: 135px; border-radius: 14px; background: rgba(0,0,0,.25); }
.how-card h3 { margin: 0 0 6px; }
.how-card p { margin: 0; line-height: 1.55; }
.item-table { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.item-cell { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 12px; background: rgba(0,0,0,.18); }
.item-cell canvas { width: 48px; height: 48px; flex: none; }
.item-cell b { display: block; }
.item-cell span { font-size: .88rem; color: var(--muted); }

/* ---------- 彈窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; padding: calc(70px + var(--safe-t)) calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l)); background: rgba(10,6,30,.66); }
.modal-card { width: min(560px, 100%); max-height: 100%; display: flex; flex-direction: column; border-radius: 24px; background: linear-gradient(180deg, var(--panel2), var(--panel)); box-shadow: 0 8px 0 #160f3a, inset 0 0 0 3px rgba(255,233,163,.25); animation: rise .25s ease-out; }
.modal-card.small { width: min(400px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 14px 6px 20px; }
.modal-head h2 { margin: 0; font-size: 1.5rem; color: var(--yellow); }
.modal-body { flex: 1 1 auto; min-height: 0; }
.modal-head, .modal-foot { flex: none; }
.modal-body > .sa-view > *, .modal-body > p { margin-left: 20px; margin-right: 20px; }
.modal-body .sa-view { padding: 0 0 8px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 10px 20px 18px; flex-wrap: wrap; }
.modal-foot.col { flex-direction: column; align-items: stretch; }
.modal-foot.col .big-btn { justify-content: center; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 58px; padding: 4px 20px; border-bottom: 1px solid rgba(255,255,255,.07); }
.set-row .row-label { flex: 1 1 auto; }
.keys-hint { padding: 6px 20px 0; line-height: 2.2; }
.share-img { display: block; width: 100%; max-width: 480px; margin: 0 auto; border-radius: 14px; background: rgba(0,0,0,.2); }
.share-text { white-space: pre-wrap; padding: 10px 14px; border-radius: 12px; background: #160f38; font-size: .9rem; user-select: text; margin-left: 20px; margin-right: 20px; }

/* ---------- RWD ---------- */
@media (max-width: 900px), (max-height: 520px) {
  :root { --side-w: 220px; }
}
/* 窄版或直向：資訊欄改成左側浮動抽屜，擂台用滿畫面 */
@media (max-width: 760px), (orientation: portrait) and (max-width: 1100px), (max-height: 480px) {
  .side { position: absolute; left: 0; top: 0; bottom: 0; width: min(300px, 86vw); background: rgba(24,17,60,.96); transform: translateX(0); transition: transform .2s; }
  .side.collapsed { width: min(300px, 86vw); transform: translateX(calc(-100% + 0px)); box-shadow: none; background: transparent; }
  .side.collapsed .side-toggle { position: absolute; left: calc(100% + 10px + var(--safe-l)); top: calc(66px + var(--safe-t)); }
  .side:not(.collapsed) .side-toggle { align-self: flex-end; }
  .hud-top { left: 10px; }
}
@media (max-width: 640px) {
  .home-menu { grid-template-columns: 1fr; gap: 12px; }
  .home-menu .big-btn { min-height: 74px; }
  .car-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .car-card span { font-size: .78rem; }
  .how-card { grid-template-columns: 1fr; }
  .how-card canvas { width: 100%; max-width: 320px; height: auto; aspect-ratio: 4 / 3; margin: 0 auto; }
  .go-btn { min-width: 0; flex: 1 1 160px; }
}
@media (max-width: 420px) {
  .dd-lang .dd-label { display: none; }
  .dd-lang .dd-btn { min-width: 48px; padding: 6px 8px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .home-inner { padding-top: calc(64px + var(--safe-t)); gap: 10px; justify-content: flex-start; }
  .logo-title { font-size: clamp(2rem, 8vh, 3rem); }
  .home-menu .big-btn { min-height: 64px; }
  .home-menu { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .scr-head { min-height: 58px; }
  /* 矮橫向：結算卡往上貼頂，但要讓開右上角的語言／設定鈕（約 200px 寬），不能被蓋住 */
  .result { padding-top: calc(10px + var(--safe-t)); padding-right: calc(var(--gw, 214px) + 12px); }
  .result-card { padding: 12px; }
  .result-actions { grid-template-columns: repeat(4, 1fr); }
  .result-actions #res-again { grid-column: auto; }
  .result-actions .big-btn { min-height: 48px; font-size: 1rem; padding: 6px 10px; }
}
/* 矮又窄的橫向（如 667×375）：右邊讓不出 200px，改成讓出頂端那一列 */
@media (max-height: 520px) and (orientation: landscape) and (max-width: 779px) {
  .result { padding-top: calc(66px + var(--safe-t)); padding-right: calc(12px + var(--safe-r)); }
  .result-card h2 { font-size: 1.4rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
body.reduce * { animation-duration: .01ms !important; transition-duration: .01ms !important; }

/* 大廳聊天室：不顯示大廳在線人數（不做全站在線人數） */
.lc-online { display: none !important; }

/* ---------- 紀錄與成就 ---------- */
.records-btn { display: inline-flex; align-items: center; gap: 8px; }
.rb-ico svg { width: 24px; height: 24px; display: block; }
.records { max-width: 820px; margin: 0 auto; }
/* 寬螢幕（桌機、平板橫拿）：怎麼玩改兩欄、紀錄放寬，少捲動也不浪費兩側空間 */
@media (min-width: 1080px) and (orientation: landscape) {
  .howto { max-width: 1240px; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; }
  .howto > :last-child:nth-child(odd) { grid-column: 1 / -1; }
  .howto .how-card { margin: 0; max-width: none; }
  .records { max-width: 1240px; }
  .records > .panel { max-width: none; }
}
.rec-stats { margin: 6px 0 0; }
.ach-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.ach { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border-radius: 14px; background: rgba(0,0,0,.2); opacity: .75; }
.ach.got { opacity: 1; background: rgba(255,210,63,.14); box-shadow: inset 0 0 0 2px rgba(255,210,63,.45); }
.ach-ico { width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center; background: #4a3f86; color: #c9bff2; }
.ach-ico svg { width: 24px; height: 24px; fill: currentColor; stroke: none; }
.ach.got .ach-ico { background: var(--yellow); color: var(--ink); }
.ach div { min-width: 0; flex: 1; }
.ach b { display: block; }
.ach span { display: block; font-size: .85rem; color: var(--muted); }
.ach .ach-prog { margin-top: 4px; font-weight: 700; color: var(--text); }
.ach-bar { display: block; height: 8px; margin-top: 4px; border-radius: 4px; background: rgba(255,255,255,.12); overflow: hidden; }
.ach-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--pink), var(--yellow)); }
.recent { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.recent li { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 10px; border-radius: 12px; background: rgba(0,0,0,.2); font-weight: 700; }
.recent .pl { min-width: 40px; text-align: center; padding: 2px 6px; border-radius: 999px; background: #4a3f86; }
.recent .pl.gold { background: var(--yellow); color: var(--ink); }
.recent .rc-main { flex: 1 1 200px; min-width: 0; }
.recent .rc-date { color: var(--muted); font-size: .82rem; }
.result-new { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; padding-right: 12px; }
.result-new:not(:empty) { margin-bottom: 8px; }   /* 新紀錄／成就徽章放在捲動區最上面，跟名次一起捲，不會把按鈕擠出畫面 */
.chip { padding: 4px 12px; border-radius: 999px; font-weight: 800; font-size: .88rem; background: rgba(255,255,255,.12); }
.chip.best { background: rgba(78,224,122,.25); color: #c9ffd8; }
.chip.ach { background: rgba(255,210,63,.25); color: #fff2b8; }
.chip.warn { background: rgba(255,77,94,.25); color: #ffd4d9; }
.btn.danger { background: #a3243a; box-shadow: 0 5px 0 #5e1220, inset 0 0 0 2px rgba(255,255,255,.18); color: #fff; }
.online-n { margin-left: auto; padding: 4px 10px; border-radius: 999px; background: rgba(78,224,122,.2); color: #c9ffd8; font-weight: 800; font-size: .85rem; white-space: nowrap; }
.online-n::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: var(--green); vertical-align: 1px; }
.online-n + .conn { margin-left: 6px; }
.share-stage { display: grid; place-items: center; gap: 10px; min-height: 160px; padding: 0 20px; }
.share-img { aspect-ratio: auto; max-height: 60vh; object-fit: contain; }
.share-status { margin: 0; color: var(--muted); font-weight: 700; text-align: center; }
@media (max-width: 640px) {
  .scr-head .conn, .scr-head .online-n { font-size: .75rem; padding: 3px 8px; }
}
.team-tag { color: #fff; margin-left: 4px; }

/* 窄版：標題列的連線／在線人數膠囊換到第二行，標題不被擠成直排 */
@media (max-width: 640px) {
  .scr-head { flex-wrap: wrap; row-gap: 4px; }
  .scr-head h2 { flex: 1 1 6em; }   /* 標題優先跟返回鍵同一行，空間不夠時換行的是連線狀態 */
  .scr-head .online-n { margin-left: 60px; }
  .scr-head .online-n[hidden] + .conn { margin-left: 60px; }
}
/* 設定列：空間不夠時滑桿／開關換到標籤下一行，不把標籤擠到斷字 */
.set-row { flex-wrap: wrap; row-gap: 2px; }
.set-row .row-label { flex: 1 1 150px; min-width: 0; }
.set-row .slider { margin-left: auto; }
/* 簡中字形後備 */
:lang(zh-Hans) { --font: "Baloo 2", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif; }
:lang(zh-Hans) body, html:lang(zh-Hans) { font-family: var(--font); }

/* ---------- 觸控優化 ---------- */
#s-game, #s-game * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#s-game input, #s-game .chat-log { -webkit-user-select: text; user-select: text; }
/* 搖桿感應區：整個左半邊（避開上方 HUD），手指放哪裡搖桿就出現在哪裡 */
.joy-zone { top: calc(70px + var(--safe-t)); height: auto; bottom: 0; }
/* 按鈕命中區比外觀大一圈，手指偏一點也按得到 */
.tbtn::before { content: ""; position: absolute; inset: -12px; border-radius: 50%; }
.touch-hint { position: absolute; z-index: 9; inset: auto 0 calc(170px * var(--tb-size) + var(--safe-b)) 0; display: flex; justify-content: space-between; padding: 0 calc(24px + var(--safe-r)) 0 calc(24px + var(--safe-l)); pointer-events: none; animation: hintIn .4s ease-out; }
.touch-hint span { max-width: 46%; padding: 8px 14px; border-radius: 14px; background: rgba(20,14,50,.82); font-weight: 800; box-shadow: 0 4px 0 rgba(0,0,0,.3); word-break: keep-all; text-wrap: balance; line-height: 1.35; }   /* 中文只在標點處換行（不會出現「開／車」斷字） */
@keyframes hintIn { from { opacity: 0; transform: translateY(10px); } }
body:not(.touch-on) .touch-hint { display: none; }
/* 鍵盤提示（桌機）：擂台下方中間，自繪鍵帽 */
.key-hint { position: absolute; z-index: 9; left: 150px; right: 150px; margin: 0 auto; width: fit-content; bottom: calc(18px + var(--safe-b)); display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; padding: 10px 16px; border-radius: 16px; background: rgba(20,14,50,.86); box-shadow: 0 4px 0 rgba(0,0,0,.3); pointer-events: none; animation: hintIn .4s ease-out; }
.kh-grp { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; font-weight: 800; }
.kh-grp b { margin-left: 4px; }
.kh-grp i { font-style: normal; color: var(--muted); margin: 0 2px; }
.kc { min-width: 28px; height: 28px; padding: 0 6px; border-radius: 7px; display: inline-grid; place-items: center; background: #fff; color: var(--ink); font-weight: 900; font-size: .85rem; box-shadow: 0 3px 0 #9d94c9; }
.kc-wide { min-width: 52px; }
body.touch-on .key-hint { display: none; }

/* ---------- 大廳聊天室：套用遊戲的霓虹紫配色（共用元件只透過變數調整，不改元件本身） ---------- */
body .lc-root {
  --lc-accent: var(--pink);
  --lc-accent-ink: #ffffff;
  --lc-panel-bg: #2b2266;
  --lc-panel-solid: #241c58;
  --lc-ink: var(--text);
  --lc-muted: var(--muted);
  --lc-line: rgba(255, 233, 163, 0.22);
  --lc-field-bg: rgba(0, 0, 0, 0.28);
  --lc-sys-bg: rgba(156, 123, 255, 0.22);
  --lc-name: var(--cyan);
  --lc-shadow: 0 6px 0 #160f3a, 0 0 0 3px rgba(255, 233, 163, 0.25);
  --lc-radius: 18px;
  --lc-font: var(--font);
  --lc-z: 65;            /* 高於大廳內容與右上角按鈕（60），低於設定彈窗（70）與提示 */
}
