/* ===== 炸彈小隊 — 可愛、明亮、圓潤；手機／平板／桌機、直橫向皆可用 ===== */
:root {
  --ink: #3b2a5a; --ink2: #6b5a8a; --ink3: #9a8cb8;
  --paper: #fff9ef; --card: #ffffff; --line: #eadff7;
  --pink: #ff7eb6; --pink-d: #d3438a;
  --sky: #5cc4ff; --sky-d: #2a8ed6;
  --mint: #4fd6a8; --mint-d: #23a67b;
  --sun: #ffd24d; --sun-d: #e0a014;
  --grape: #9b7bff; --grape-d: #6a49d4;
  --red: #ff6b6b; --red-d: #d93d4a;
  --r: 22px;
  --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);
  --font: "Baloo 2", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); color: var(--ink); font-size: 16px; line-height: 1.45;
  background: radial-gradient(circle at 12% 18%, #ffe0ef 0, transparent 38%), radial-gradient(circle at 88% 12%, #d7efff 0, transparent 40%), radial-gradient(circle at 70% 92%, #fff0c4 0, transparent 40%), #fff4fa;
  overflow: hidden; overscroll-behavior: none; touch-action: manipulation; -webkit-user-select: none; user-select: none;
}
input, textarea { -webkit-user-select: text; user-select: text; }
.app { position: fixed; inset: 0; overflow: hidden; }
h1, h2, h3, p { margin: 0; }
.ico { display: block; flex: none; }
:focus-visible { outline: 4px solid var(--grape-d); outline-offset: 2px; border-radius: 12px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- 按鈕 ---------- */
.btn {
  --c: var(--sky); --cd: var(--sky-d);
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  min-height: 48px; padding: .55em 1.4em; border: 0; border-radius: 999px;
  font: inherit; font-weight: 800; font-size: 1.05rem; color: #fff; cursor: pointer;
  background: linear-gradient(180deg, color-mix(in srgb, var(--c) 82%, #fff) 0, var(--c) 100%);
  box-shadow: 0 5px 0 var(--cd), 0 9px 16px rgba(80, 40, 120, .18), inset 0 2px 0 rgba(255, 255, 255, .45);
  text-shadow: 0 1px 0 rgba(0, 0, 0, .18); transition: transform .08s, box-shadow .08s, filter .15s;
  position: relative; top: 0;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--cd), 0 3px 6px rgba(80, 40, 120, .18), inset 0 2px 0 rgba(255, 255, 255, .35); }
.btn:disabled { filter: grayscale(.7) opacity(.55); cursor: not-allowed; transform: none; box-shadow: 0 5px 0 #b9b0c9; }
.btn-sky { --c: var(--sky); --cd: var(--sky-d); }
.btn-pink { --c: var(--pink); --cd: var(--pink-d); }
.btn-mint { --c: var(--mint); --cd: var(--mint-d); }
.btn-sun { --c: var(--sun); --cd: var(--sun-d); color: #5a3a00; text-shadow: 0 1px 0 rgba(255, 255, 255, .5); }
.btn-grape { --c: var(--grape); --cd: var(--grape-d); }
.btn-ghost { --c: #fff; --cd: #cdbfe6; color: var(--ink); text-shadow: none; }
.btn-lg { min-height: 64px; font-size: 1.3rem; padding: .6em 1.8em; }
.btn-sm { min-height: 40px; font-size: .95rem; padding: .35em 1em; box-shadow: 0 4px 0 var(--cd), 0 6px 10px rgba(80, 40, 120, .14), inset 0 2px 0 rgba(255, 255, 255, .45); }
.btn-block { display: flex; width: 100%; }
.btn-ico { display: inline-flex; }
.icon-btn {
  width: 48px; height: 48px; display: inline-grid; place-items: center; border: 0; border-radius: 50%;
  background: #fff; color: var(--ink); cursor: pointer; box-shadow: 0 4px 0 #cdbfe6, 0 8px 14px rgba(80, 40, 120, .16);
  transition: transform .08s, box-shadow .08s;
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #cdbfe6; }
.icon-btn.sm { width: 40px; height: 40px; }
.gear {
  position: fixed; z-index: 60; top: calc(10px + var(--safe-t)); right: calc(12px + var(--safe-r));
}
/* 首頁左上角的「← 回遊戲大廳」，外觀跟右上角的設定鈕一致；display 寫死會蓋掉 [hidden]，所以要留下面那條 */
.lobby-home-link {
  position: fixed; z-index: 60; top: calc(10px + var(--safe-t)); left: calc(12px + var(--safe-l));
  display: inline-flex; align-items: center; min-height: 48px; padding: 0 14px;
  background: #ffe03d; color: #17122b; border: 3px solid #17122b; border-radius: 14px; box-shadow: 0 4px 0 #17122b;
  font-weight: 900; font-size: .92rem; text-decoration: none; white-space: nowrap; transition: transform .08s, box-shadow .08s;
}
.lobby-home-link[hidden] { display: none; }
.lobby-home-link:active { transform: translateY(3px); box-shadow: 0 1px 0 #17122b; }
.lobby-home-link:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

/* ---------- 版面共通 ---------- */
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden; padding: calc(14px + var(--safe-t)) calc(16px + var(--safe-r)) calc(18px + var(--safe-b)) calc(16px + var(--safe-l)); -webkit-overflow-scrolling: touch; }
.screen.center { align-items: center; }
.wrap { width: 100%; max-width: 1040px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.topbar { display: flex; align-items: center; gap: 10px; min-height: 52px; padding-right: 58px; }
.topbar h2 { font-size: clamp(1.3rem, 3.2vw, 1.8rem); font-weight: 900; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card { background: var(--card); border-radius: var(--r); padding: 16px; box-shadow: 0 6px 0 var(--line), 0 14px 26px rgba(90, 50, 140, .12); border: 3px solid #fff; }
.card h3 { font-size: 1.1rem; font-weight: 900; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.muted { color: var(--ink2); }
.small { font-size: .88rem; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row.gap-lg { gap: 18px; }
.grow { flex: 1 1 auto; min-width: 0; }
.field { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 8px 0; border-bottom: 2px dashed var(--line); }
.field:last-child { border-bottom: 0; }
.field > .label { font-weight: 800; min-width: 7.5em; display: flex; align-items: center; gap: 6px; }
.field > .ctl { flex: 1 1 220px; min-width: 0; display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.text-input {
  width: 100%; min-height: 48px; border: 3px solid var(--line); border-radius: 16px; padding: 8px 14px; font: inherit; font-weight: 700; color: var(--ink);
  background: #fff9ff; outline: none; box-shadow: inset 0 3px 0 rgba(120, 80, 180, .06);
}
.text-input:focus { border-color: var(--grape); box-shadow: 0 0 0 4px rgba(155, 123, 255, .22); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 12px; border-radius: 999px; background: #f4ecff; color: var(--grape-d); font-weight: 800; font-size: .85rem; }
.pill.mint { background: #dcf8ee; color: var(--mint-d); }
.pill.sun { background: #fff0c4; color: #a86f00; }
.pill.pink { background: #ffe1ef; color: var(--pink-d); }
.pill.gray { background: #eee9f5; color: var(--ink2); }
.hint { background: #fff6d8; border-radius: 14px; padding: 8px 12px; color: #7a5a00; font-weight: 700; font-size: .92rem; }

/* ---------- 分段選項／步進器／開關／音量 ---------- */
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: #f3ebff; border-radius: 999px; }
.seg-btn {
  border: 0; background: transparent; color: var(--ink2); font: inherit; font-weight: 800; min-height: 40px; padding: 4px 14px; border-radius: 999px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; transition: background .12s, color .12s;
}
.seg-btn[aria-checked="true"] { background: var(--grape); color: #fff; box-shadow: 0 3px 0 var(--grape-d); }
.seg-btn:disabled { opacity: .45; cursor: not-allowed; }
.seg.small .seg-btn { min-height: 34px; padding: 2px 10px; font-size: .9rem; }
.seg.lvl .seg-btn[aria-checked="true"] { background: var(--mint); box-shadow: 0 3px 0 var(--mint-d); }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.step-btn { width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--sun); color: #5a3a00; display: grid; place-items: center; cursor: pointer; box-shadow: 0 4px 0 var(--sun-d); }
.step-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--sun-d); }
.step-btn:disabled { opacity: .4; cursor: not-allowed; }
.stepper-val { min-width: 3.4em; text-align: center; font-weight: 900; font-size: 1.2rem; }
.sw { width: 66px; height: 38px; border: 0; border-radius: 999px; background: #d8cfe8; position: relative; cursor: pointer; box-shadow: inset 0 3px 0 rgba(0, 0, 0, .12); transition: background .15s; flex: none; }
.sw[aria-checked="true"] { background: var(--mint); }
.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, .18); transition: transform .15s; }
.sw[aria-checked="true"] .sw-knob { transform: translateX(28px); }
.sw:disabled { opacity: .5; cursor: not-allowed; }
.vol { position: relative; width: min(220px, 100%); height: 38px; cursor: pointer; touch-action: none; }
.vol::before { content: ""; position: absolute; left: 0; right: 0; top: 13px; height: 12px; border-radius: 999px; background: #e6dcf5; box-shadow: inset 0 2px 0 rgba(0, 0, 0, .08); }
.vol-fill { position: absolute; left: 0; top: 13px; height: 12px; border-radius: 999px; background: linear-gradient(90deg, var(--pink), var(--sun)); }
.vol-thumb { position: absolute; top: 3px; width: 32px; height: 32px; margin-left: -16px; border-radius: 50%; background: #fff; box-shadow: 0 3px 0 #cdbfe6, 0 6px 10px rgba(80, 40, 120, .2); }
.vol.is-off { opacity: .45; }
.key {
  display: inline-grid; place-items: center; min-width: 2.1em; height: 2.1em; padding: 0 .5em; border-radius: 9px; font: inherit; font-weight: 900; font-size: .95rem; color: var(--ink);
  background: linear-gradient(180deg, #fff, #f3ecff); border: 2px solid #d9cdef; box-shadow: 0 3px 0 #b9a8d9; margin: 0 2px;
}
.key.wide { min-width: 5.5em; }
.avatar { display: inline-grid; place-items: center; border-radius: 50%; background: radial-gradient(circle at 35% 25%, #fff, #f1e8ff); flex: none; overflow: hidden; box-shadow: inset 0 0 0 3px #fff, 0 3px 0 #e1d5f3; }
.avatar-img { width: 92%; height: 92%; object-fit: contain; pointer-events: none; }

/* ---------- 首頁 ---------- */
.home { justify-content: center; align-items: center; text-align: center; gap: 18px; }
.hero { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.hero-title { font-size: clamp(2.6rem, 9vw, 5rem); font-weight: 900; letter-spacing: .04em; color: #fff; -webkit-text-stroke: 0; text-shadow: 0 5px 0 var(--pink-d), 0 9px 0 rgba(90, 40, 120, .25), 0 0 20px rgba(255, 126, 182, .5); line-height: 1.05; }
.hero-title span { display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.hero-title span:nth-child(2) { animation-delay: .15s; } .hero-title span:nth-child(3) { animation-delay: .3s; } .hero-title span:nth-child(4) { animation-delay: .45s; }
.hero-sub { font-weight: 800; color: var(--ink2); font-size: clamp(1rem, 2.4vw, 1.3rem); }
.hero-cast { display: flex; justify-content: center; align-items: flex-end; gap: 0; margin-top: 8px; flex-wrap: nowrap; max-width: 100%; }
.hero-cast .avatar { box-shadow: none; background: transparent; width: clamp(44px, 9vw, 78px) !important; height: clamp(44px, 9vw, 78px) !important; margin: 0 -4px; animation: hop 1.8s ease-in-out infinite; }
.hero-cast .avatar:nth-child(2n) { animation-delay: .25s; } .hero-cast .avatar:nth-child(3n) { animation-delay: .5s; }
.hero-bomb { width: clamp(70px, 14vw, 120px); height: clamp(70px, 14vw, 120px); animation: pulse 1.1s ease-in-out infinite; }
.home-menu { display: flex; flex-direction: column; gap: 14px; width: min(420px, 100%); }
.home-foot { color: var(--ink2); font-weight: 700; font-size: .92rem; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes hop { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.1); } }
body.calm *, body.calm *::before, body.calm *::after { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) { .hero-title span, .hero-cast .avatar, .hero-bomb { animation: none; } }

/* ---------- 教學 ---------- */
.help-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.help-fig { width: 100%; max-width: 360px; margin: 6px auto 0; display: block; }
.item-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 8px 14px; }
.item-row { display: flex; align-items: center; gap: 10px; padding: 6px 4px; }
.item-row img { width: 46px; height: 46px; flex: none; }
.item-row b { display: block; }
.steps { padding-left: 1.2em; margin: 6px 0 0; display: grid; gap: 6px; font-weight: 700; }

/* ---------- 單機設定／選角色 ---------- */
.animal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 10px; }
.animal-opt { border: 3px solid transparent; background: #faf5ff; border-radius: 20px; padding: 6px 4px 8px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; font: inherit; font-weight: 800; color: var(--ink2); }
.animal-opt[aria-checked="true"] { border-color: var(--grape); background: #efe6ff; color: var(--grape-d); box-shadow: 0 4px 0 var(--grape); }
.animal-opt[aria-disabled="true"] { opacity: .35; cursor: not-allowed; }
.ai-rows { display: grid; gap: 8px; }
.ai-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 6px 10px; background: #faf5ff; border-radius: 18px; }
.ai-row .name { font-weight: 800; min-width: 5em; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- 大廳 ---------- */
.room-list { display: grid; gap: 10px; }
.room-item { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 14px; background: #fbf7ff; border-radius: 20px; border: 3px solid #fff; box-shadow: 0 4px 0 var(--line); }
.room-item .info { flex: 1 1 200px; min-width: 0; }
.room-item .name { font-weight: 900; font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-box { text-align: center; padding: 26px 12px; color: var(--ink2); font-weight: 800; }
.status { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: .9rem; padding: 4px 12px; border-radius: 999px; background: #fff; box-shadow: 0 2px 0 var(--line); }
.status i { width: 10px; height: 10px; border-radius: 50%; background: var(--mint); display: inline-block; }
.status.warn i { background: var(--sun); animation: pulse 1s infinite; }
.status.bad i { background: var(--red); }
.invite-card { background: linear-gradient(135deg, #fff1fa, #eaf6ff); border: 3px solid #fff; box-shadow: 0 6px 0 var(--line), 0 14px 26px rgba(90, 50, 140, .14); border-radius: var(--r); padding: 16px; }

/* ---------- 房間 ---------- */
.room-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.seats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.seat { position: relative; background: #fbf7ff; border: 3px solid #fff; box-shadow: 0 4px 0 var(--line); border-radius: 20px; padding: 10px; display: flex; flex-direction: column; gap: 8px; min-height: 124px; }
.seat.me { background: #eef8ff; box-shadow: 0 4px 0 #bfe3fa; }
.seat.empty { align-items: center; justify-content: center; color: var(--ink3); font-weight: 800; border-style: dashed; border-color: var(--line); background: transparent; box-shadow: none; }
.seat-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.seat-name { font-weight: 900; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.seat-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.seat-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }
.chat-box { display: flex; flex-direction: column; min-height: 0; }
.chat-log { flex: 1; min-height: 120px; max-height: 280px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding: 8px; background: #faf6ff; border-radius: 16px; font-size: .93rem; -webkit-user-select: text; user-select: text; }
.chat-log .msg b { color: var(--grape-d); margin-right: 6px; }
.chat-log .msg.spec b { color: var(--ink3); }
.chat-log .msg.sys { color: var(--ink3); font-weight: 700; text-align: center; font-size: .85rem; }
.chat-log .msg { word-break: break-word; }
.chat-form { display: flex; gap: 8px; margin-top: 8px; }
.chat-form .text-input { min-height: 44px; }
.quick-chat { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.quick-chat button { border: 0; background: #f0e8ff; color: var(--grape-d); border-radius: 999px; padding: 4px 12px; font: inherit; font-weight: 800; font-size: .88rem; cursor: pointer; min-height: 34px; }

/* ---------- 對戰畫面 ---------- */
.game { position: absolute; inset: 0; display: flex; background: var(--stage, #ffd9ec); transition: background .3s; overflow: hidden; }
.game-side {
  flex: none; width: clamp(230px, 24vw, 300px); display: flex; flex-direction: column; gap: 10px; padding: calc(10px + var(--safe-t)) 10px calc(10px + var(--safe-b)) calc(10px + var(--safe-l));
  background: rgba(255, 255, 255, .86); backdrop-filter: blur(6px); border-right: 3px solid #fff; box-shadow: 4px 0 18px rgba(90, 50, 140, .14); z-index: 20; min-height: 0;
}
.game.side-closed .game-side { display: none; }
.side-head { display: flex; align-items: center; gap: 8px; }
.side-head h3 { flex: 1; font-size: 1.05rem; font-weight: 900; }
.summary { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; min-height: 60px; flex: 0 1 auto; max-height: 46%; }
.sum-row { display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 4px; border-radius: 16px; background: #faf6ff; border: 3px solid transparent; }
.sum-row.me { border-color: var(--grape); background: #f0e9ff; }
.sum-row.dead { opacity: .5; }
.sum-row .nm { flex: 1; min-width: 0; font-weight: 800; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sum-row .nm small { display: block; color: var(--ink3); font-weight: 700; font-size: .74rem; }
.sum-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.kills { font-weight: 900; color: var(--pink-d); display: inline-flex; align-items: center; gap: 2px; }
.mystats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.stat { background: #fff8e4; border-radius: 14px; padding: 4px; text-align: center; font-weight: 900; line-height: 1.1; }
.stat img { width: 28px; height: 28px; display: block; margin: 0 auto 2px; }
.stat small { display: block; color: var(--ink2); font-size: .7rem; font-weight: 700; }
.stat.off { opacity: .35; }
.curse-bar { background: #efe4ff; color: var(--grape-d); border-radius: 12px; padding: 4px 10px; font-weight: 800; font-size: .88rem; text-align: center; }
.side-keys { font-size: .84rem; font-weight: 700; color: var(--ink2); display: flex; flex-direction: column; gap: 6px; }
.side-keys .k-row { display: flex; align-items: center; flex-wrap: wrap; gap: 2px 4px; }
.side-chat { display: flex; flex-direction: column; min-height: 0; flex: 1 1 0; margin-top: auto; }
.side-chat .chat-log { max-height: none; flex: 1; min-height: 70px; }
.game-main { position: relative; flex: 1 1 auto; min-width: 0; display: flex; align-items: center; justify-content: center; padding: calc(60px + var(--safe-t)) calc(8px + var(--safe-r)) calc(8px + var(--safe-b)) calc(8px + var(--safe-l)); }
.game-main.has-touch.portrait { padding-bottom: calc(210px + var(--safe-b)); }
.board { position: relative; border-radius: 14px; overflow: hidden; box-shadow: 0 0 0 5px #fff, 0 12px 30px rgba(60, 30, 100, .3); line-height: 0; }
.board canvas { display: block; touch-action: none; }
.hud { position: absolute; z-index: 15; top: calc(8px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; max-width: calc(100% - 140px); flex-wrap: wrap; justify-content: center; pointer-events: none; }
.hud-timer { background: #fff; border-radius: 999px; padding: 4px 16px; font-weight: 900; font-size: 1.35rem; box-shadow: 0 4px 0 var(--line), 0 8px 14px rgba(60, 30, 100, .16); min-width: 5em; text-align: center; font-variant-numeric: tabular-nums; }
.hud-timer.low { background: #ffe1e1; color: var(--red-d); animation: pulse .8s infinite; }
.hud-chips { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.hud-chip { background: #fff; border-radius: 999px; padding: 2px 8px 2px 2px; display: inline-flex; align-items: center; gap: 4px; font-weight: 900; font-size: .85rem; box-shadow: 0 3px 0 var(--line); border: 3px solid transparent; }
.hud-chip.dead { opacity: .4; filter: grayscale(.8); }
.hud-chip.me { border-color: var(--grape); }
.side-toggle { position: absolute; z-index: 30; top: calc(10px + var(--safe-t)); left: calc(10px + var(--safe-l)); }
.side-toggle .badge { position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px; background: var(--red); color: #fff; font-size: .74rem; font-weight: 900; display: grid; place-items: center; box-shadow: 0 2px 0 var(--red-d); }
.game.side-closed .side-toggle, .game .side-toggle { display: grid; }
.game:not(.side-closed) .side-toggle.on-wide { display: none; }
.spec-tag { position: absolute; z-index: 15; bottom: calc(10px + var(--safe-b)); left: 50%; transform: translateX(-50%); background: #fff; padding: 4px 16px; border-radius: 999px; font-weight: 900; box-shadow: 0 4px 0 var(--line); color: var(--grape-d); pointer-events: none; }
.ghost-msg { position: absolute; z-index: 15; bottom: calc(10px + var(--safe-b)); left: 50%; transform: translateX(-50%); background: rgba(255, 255, 255, .92); padding: 4px 16px; border-radius: 999px; font-weight: 800; box-shadow: 0 4px 0 var(--line); pointer-events: none; }

/* 觸控按鍵 */
.touch { position: absolute; z-index: 18; bottom: calc(16px + var(--safe-b)); left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-end; padding: 0 calc(20px + var(--safe-r)) 0 calc(20px + var(--safe-l)); pointer-events: none; }
.touch.flip { flex-direction: row-reverse; }
.stick { position: relative; width: 156px; height: 156px; border-radius: 50%; pointer-events: auto; touch-action: none; background: radial-gradient(circle, rgba(255, 255, 255, .55) 0, rgba(255, 255, 255, .3) 70%); box-shadow: inset 0 0 0 4px rgba(255, 255, 255, .8), 0 8px 18px rgba(60, 30, 100, .22); opacity: .85; }
.stick .arrow { position: absolute; width: 0; height: 0; border: 10px solid transparent; opacity: .75; }
.stick .arrow.u { top: 6px; left: 50%; margin-left: -10px; border-bottom-color: var(--grape-d); border-top-width: 0; }
.stick .arrow.d { bottom: 6px; left: 50%; margin-left: -10px; border-top-color: var(--grape-d); border-bottom-width: 0; }
.stick .arrow.l { left: 6px; top: 50%; margin-top: -10px; border-right-color: var(--grape-d); border-left-width: 0; }
.stick .arrow.r { right: 6px; top: 50%; margin-top: -10px; border-left-color: var(--grape-d); border-right-width: 0; }
.stick .knob { position: absolute; left: 50%; top: 50%; width: 66px; height: 66px; margin: -33px 0 0 -33px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, var(--grape) 80%); box-shadow: 0 5px 0 var(--grape-d), 0 10px 16px rgba(60, 30, 100, .3); }
.bomb-btn { pointer-events: auto; touch-action: none; width: 104px; height: 104px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer; background: radial-gradient(circle at 35% 28%, #ffd0e4, var(--pink) 60%); box-shadow: 0 7px 0 var(--pink-d), 0 14px 22px rgba(60, 30, 100, .3), inset 0 3px 0 rgba(255, 255, 255, .5); opacity: .92; }
.bomb-btn:active, .bomb-btn.down { transform: translateY(5px); box-shadow: 0 2px 0 var(--pink-d), 0 6px 10px rgba(60, 30, 100, .3); }
.bomb-btn img { width: 62px; height: 62px; pointer-events: none; }

/* ---------- 彈窗 ---------- */
.mask { position: fixed; inset: 0; z-index: 100; background: rgba(60, 30, 100, .45); display: flex; align-items: center; justify-content: center; padding: calc(12px + var(--safe-t)) calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l)); backdrop-filter: blur(3px); animation: fade .15s; }
.mask.out { opacity: 0; transition: opacity .15s; }
.dialog { background: #fffdf8; border-radius: 28px; width: min(560px, 100%); max-height: 100%; display: flex; flex-direction: column; box-shadow: 0 10px 0 var(--line), 0 24px 50px rgba(40, 10, 80, .4); border: 4px solid #fff; animation: pop .2s; outline: none; }
.dialog.dialog-sm { width: min(420px, 100%); }
.dialog.dialog-lg { width: min(720px, 100%); }
.dialog-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 4px 20px; }
.dialog-title { flex: 1; font-size: 1.35rem; font-weight: 900; }
.dialog-body { padding: 8px 20px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; padding: 10px 20px 18px; }
.dialog-text { font-weight: 700; padding: 6px 0; }
.big-result { text-align: center; padding: 6px 0 10px; }
.big-result .head { font-size: clamp(1.8rem, 6vw, 2.6rem); font-weight: 900; color: var(--pink-d); text-shadow: 0 3px 0 #fff, 0 6px 0 rgba(0, 0, 0, .08); }
.rank { display: grid; gap: 6px; margin-top: 10px; text-align: left; }
.rank-row { display: flex; align-items: center; gap: 10px; padding: 4px 12px 4px 6px; background: #faf5ff; border-radius: 18px; font-weight: 800; }
.rank-row.win { background: linear-gradient(90deg, #fff1b8, #ffe48a); }
.rank-row .no { width: 1.6em; text-align: center; font-weight: 900; color: var(--ink3); }
.rank-row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-box { display: flex; gap: 8px; align-items: center; background: #f4ecff; border-radius: 16px; padding: 8px 10px; }
.link-box code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; user-select: all; -webkit-user-select: all; }

/* ---------- 其他 ---------- */
.toasts { position: fixed; z-index: 200; top: calc(12px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(92vw, 520px); }
.toast { background: #3b2a5a; color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 800; box-shadow: 0 6px 16px rgba(0, 0, 0, .3); animation: pop .2s; text-align: center; }
.toast.out { opacity: 0; transition: opacity .3s; }
.banner { position: fixed; z-index: 150; left: 50%; transform: translateX(-50%); top: calc(8px + var(--safe-t)); background: #fff1c2; color: #7a5a00; border-radius: 999px; padding: 6px 18px; font-weight: 800; box-shadow: 0 4px 0 #e8cf7a; display: flex; align-items: center; gap: 8px; }
.wake-art { display: flex; align-items: center; gap: 10px; }
.spin { animation: spin 1.1s linear infinite; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
.rotate-tip { position: absolute; z-index: 25; left: 50%; bottom: calc(10px + var(--safe-b)); transform: translateX(-50%); }

/* ---------- 響應式 ---------- */
@media (max-width: 860px), (max-aspect-ratio: 1/1) {
  .game-side { position: absolute; top: 0; bottom: 0; left: 0; width: min(86vw, 330px); transform: translateX(0); transition: transform .2s; }
  .game.side-closed .game-side { display: flex; transform: translateX(-105%); box-shadow: none; visibility: hidden; transition: transform .2s, visibility 0s .2s; }
  .game-main { padding-top: calc(58px + var(--safe-t)); }
  .side-toggle.on-wide { display: grid !important; }
  .game:not(.side-closed) .side-toggle.on-wide { display: none !important; }
  .room-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .btn { font-size: 1rem; }
  .btn-lg { min-height: 58px; font-size: 1.15rem; }
  .field > .label { min-width: 100%; }
  .field > .ctl { justify-content: flex-start; }
  .hud-timer { font-size: 1.1rem; padding: 2px 12px; }
}
@media (max-height: 460px) and (orientation: landscape) {
  .home { gap: 8px; flex-direction: row; justify-content: center; flex-wrap: wrap; }
  .hero-cast { display: none; }
  .hero-title { font-size: 2.4rem; }
  .btn-lg { min-height: 50px; }
  .stick { width: 128px; height: 128px; } .stick .knob { width: 54px; height: 54px; margin: -27px 0 0 -27px; }
  .bomb-btn { width: 88px; height: 88px; }
}

/* ===== 風格：夜間街機貼紙風（深色背景＋粗黑框＋硬陰影，和其他小遊戲的木紋／粉彩風區分） ===== */
:root {
  --ink: #17122b; --ink2: #4a4470; --ink3: #8a84ad;
  --paper: #fff6dc; --card: #fffdf3; --line: #17122b;
  --pink: #ff4fa3; --pink-d: #17122b;
  --sky: #2fd4ff; --sky-d: #17122b;
  --mint: #3dffb0; --mint-d: #17122b;
  --sun: #ffe03d; --sun-d: #17122b;
  --grape: #8b5cff; --grape-d: #17122b;
  --red: #ff4d4d; --red-d: #17122b;
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC", system-ui, sans-serif;
}
body {
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 15%, rgba(255, 79, 163, .35) 0, transparent 34%),
    radial-gradient(circle at 85% 80%, rgba(47, 212, 255, .30) 0, transparent 38%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .05) 0 2px, transparent 2px 28px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .05) 0 2px, transparent 2px 28px),
    #1d1640;
}
.screen, .topbar h2 { color: #fff; }
.card, .screen .card, .invite-card { color: var(--ink); background: var(--card); border: 3px solid #17122b; border-radius: 16px; box-shadow: 6px 6px 0 #17122b; }
.topbar h2 { text-shadow: 3px 3px 0 #17122b; letter-spacing: .03em; }
.btn {
  background: var(--c); color: #17122b; text-shadow: none; border: 3px solid #17122b; border-radius: 14px;
  box-shadow: 0 5px 0 #17122b; font-weight: 900; letter-spacing: .04em;
}
.btn:hover { filter: none; background: color-mix(in srgb, var(--c) 85%, #fff); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #17122b; }
.btn:disabled { filter: grayscale(1) opacity(.5); box-shadow: 0 5px 0 #17122b; }
.btn-ghost { --c: #fffdf3; }
.btn-sm { box-shadow: 0 4px 0 #17122b; }
.icon-btn { background: #ffe03d; color: #17122b; border: 3px solid #17122b; border-radius: 14px; box-shadow: 0 4px 0 #17122b; }
.icon-btn:active { box-shadow: 0 1px 0 #17122b; }
.seg { background: #fffdf3; border: 3px solid #17122b; border-radius: 14px; padding: 3px; }
.seg-btn { border-radius: 10px; color: #17122b; }
.seg-btn[aria-checked="true"], .seg.lvl .seg-btn[aria-checked="true"] { background: #17122b; color: #ffe03d; box-shadow: none; }
.step-btn { border: 3px solid #17122b; border-radius: 12px; box-shadow: 0 3px 0 #17122b; }
.sw { border: 3px solid #17122b; border-radius: 12px; background: #d9d4ee; box-shadow: none; }
.sw[aria-checked="true"] { background: var(--mint); }
.sw-knob { border: 3px solid #17122b; border-radius: 8px; box-shadow: none; top: 2px; left: 2px; width: 28px; height: 28px; }
.sw[aria-checked="true"] .sw-knob { transform: translateX(28px); }
.vol::before { border: 3px solid #17122b; background: #fffdf3; height: 16px; top: 11px; box-shadow: none; }
.vol-fill { top: 11px; height: 16px; border-radius: 999px; background: var(--pink); border: 3px solid #17122b; }
.vol-thumb { border: 3px solid #17122b; border-radius: 8px; box-shadow: 0 3px 0 #17122b; background: var(--sun); }
.text-input { border: 3px solid #17122b; border-radius: 12px; background: #fff; box-shadow: 3px 3px 0 #17122b; }
.text-input:focus { border-color: #17122b; box-shadow: 3px 3px 0 var(--pink); }
.pill { background: #ffe03d; color: #17122b; border: 2px solid #17122b; }
.pill.mint { background: var(--mint); color: #17122b; } .pill.pink { background: var(--pink); color: #17122b; } .pill.gray { background: #e8e4f7; color: #17122b; } .pill.sun { background: var(--sun); color: #17122b; }
.hint { background: #ffe03d; color: #17122b; border: 2px solid #17122b; border-radius: 10px; }
.key { background: #fff; border: 3px solid #17122b; border-radius: 8px; box-shadow: 0 3px 0 #17122b; color: #17122b; }
.avatar { background: #fff; border: 3px solid #17122b; box-shadow: none; }
.hero-cast .avatar { border: 0; background: transparent; }
.hero-title { color: #ffe03d; text-shadow: 4px 4px 0 #17122b, 7px 7px 0 var(--pink); -webkit-text-stroke: 3px #17122b; paint-order: stroke fill; }
.hero-sub, .home-foot { color: #fff; text-shadow: 2px 2px 0 #17122b; }
.animal-opt { background: #fff; border: 3px solid #17122b; border-radius: 14px; color: #17122b; }
.animal-opt[aria-checked="true"] { background: #ffe03d; box-shadow: 0 4px 0 #17122b; border-color: #17122b; color: #17122b; }
.ai-row, .seat, .room-item, .sum-row { background: #fff; border: 3px solid #17122b; border-radius: 14px; box-shadow: 3px 3px 0 #17122b; }
.seat.me, .sum-row.me { background: #cdf6ff; border-color: #17122b; }
.seat.empty { background: transparent; border-style: dashed; box-shadow: none; color: var(--ink2); }
.chat-log { background: #fff; border: 3px solid #17122b; border-radius: 12px; }
.chat-log .msg b { color: var(--pink-d); color: #c01c78; }
.quick-chat button { background: #ffe03d; border: 2px solid #17122b; color: #17122b; }
.status { background: #fffdf3; border: 2px solid #17122b; box-shadow: 2px 2px 0 #17122b; color: #17122b; }
.mask { background: rgba(10, 6, 30, .72); }
.dialog { background: #fffdf3; border: 4px solid #17122b; border-radius: 18px; box-shadow: 8px 8px 0 #17122b; }
.dialog-title { text-shadow: none; }
.big-result .head { color: #ff4fa3; text-shadow: 3px 3px 0 #17122b; -webkit-text-stroke: 2px #17122b; paint-order: stroke fill; }
.rank-row { background: #fff; border: 2px solid #17122b; } .rank-row.win { background: #ffe03d; }
.link-box { background: #fff; border: 3px solid #17122b; border-radius: 12px; }
.toast { background: #ffe03d; color: #17122b; border: 3px solid #17122b; box-shadow: 4px 4px 0 #17122b; border-radius: 12px; }
.banner { background: #ffe03d; color: #17122b; border: 3px solid #17122b; box-shadow: 3px 3px 0 #17122b; border-radius: 12px; }
.game-side { background: #fffdf3; border-right: 4px solid #17122b; box-shadow: none; backdrop-filter: none; }
.hud-timer, .hud-chip, .ghost-msg, .spec-tag { background: #fffdf3; border: 3px solid #17122b; box-shadow: 3px 3px 0 #17122b; color: #17122b; }
.hud-timer.low { background: #ff4d4d; color: #fff; }
.hud-chip.me { border-color: #8b5cff; }
.board { border-radius: 8px; box-shadow: 0 0 0 4px #17122b, 8px 8px 0 4px rgba(0, 0, 0, .55); }
.stat { background: #fff; border: 2px solid #17122b; border-radius: 10px; }
.curse-bar { background: #8b5cff; color: #fff; border: 2px solid #17122b; }
.stick { background: rgba(255, 253, 243, .45); box-shadow: inset 0 0 0 4px #17122b; }
.stick .knob { background: #ffe03d; border: 4px solid #17122b; box-shadow: 0 4px 0 #17122b; }
.bomb-btn { background: var(--pink); border: 4px solid #17122b; box-shadow: 0 7px 0 #17122b; }
.bomb-btn:active, .bomb-btn.down { box-shadow: 0 2px 0 #17122b; }
:focus-visible { outline: 4px solid #ffe03d; box-shadow: 0 0 0 7px #17122b; }

/* ===== 單行排版：盡量不換行（放不下時縮小，或在自己的區塊內橫向捲動） ===== */
.field { flex-wrap: nowrap; gap: 10px; align-items: center; }
.field > .label { min-width: 0; flex: 0 0 auto; white-space: nowrap; font-size: .95rem; }
.field > .ctl { flex: 1 1 0; min-width: 0; flex-wrap: nowrap; justify-content: flex-end; align-items: center; gap: 8px; }
.field > .ctl > .text-input { width: 100%; }
.seg { flex-wrap: nowrap; max-width: 100%; min-width: 0; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity; }
.seg::-webkit-scrollbar { display: none; }
.seg-btn { white-space: nowrap; flex: 0 0 auto; scroll-snap-align: center; }
.pill { white-space: nowrap; flex: 0 0 auto; }
.chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; max-width: 100%; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.btn, .btn-label { white-space: nowrap; }
.dialog-actions { flex-wrap: nowrap; }
.dialog-actions .btn { flex: 1 1 0; min-width: 0; padding-left: 10px; padding-right: 10px; }
.dialog-actions:has(> .btn:only-child) { justify-content: flex-end; }
.dialog-actions .btn:only-child { flex: 0 1 auto; min-width: 8em; }
.k-row { flex-wrap: nowrap !important; white-space: nowrap; }
.key { flex: 0 0 auto; }
.room-item .name { max-width: 100%; }
.room-item { flex-wrap: nowrap; }
.room-item .info { flex: 1 1 0; min-width: 0; }
.seats { grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); }
.seat-tags { flex-wrap: nowrap; overflow: hidden; }
.seat-actions { flex-wrap: nowrap; align-items: center; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.seat-actions .btn { flex: 0 0 auto; }
.topbar > .pill, .topbar > span { white-space: nowrap; flex: 0 0 auto; }
.ai-row { flex-wrap: nowrap; min-width: 0; }
.ai-row .name { white-space: nowrap; }
.ai-row .seg { margin-left: auto; }
.hud { flex-wrap: nowrap; }
.hud-chips { flex-wrap: nowrap; }
.hud-chip { flex: 0 1 auto; min-width: 0; }
.sum-row .kills { white-space: nowrap; }
.stat small { white-space: nowrap; }
.invite-card .row, .card .row { flex-wrap: nowrap; }
.card > h3 { display: flex; align-items: center; gap: 8px; white-space: nowrap; }

/* 版面美化 */
.card > h3::before { content: ""; width: 8px; height: 1.05em; border-radius: 3px; background: linear-gradient(#ffe03d, #ff4f8b); border: 2px solid #17122b; flex: 0 0 auto; }
.btn { transition: transform .08s ease, filter .15s ease; }
.btn:hover:not(:disabled) { filter: brightness(1.06); }
.btn:active:not(:disabled) { transform: translate(2px, 2px); }
.room-item { transition: transform .12s ease; }
.room-item:hover { transform: translate(-1px, -1px); }
.seat.empty { min-height: 110px; }
.screen { scroll-behavior: smooth; }
.home-menu .btn { justify-content: center; }

@media (max-width: 560px) {
  .field { gap: 8px; }
  .field > .label { min-width: 0; font-size: .88rem; }
  .field > .ctl { justify-content: flex-end; }
  .seg-btn { padding: 2px 9px; font-size: .88rem; min-height: 38px; }
  .seg.small .seg-btn { padding: 2px 7px; font-size: .8rem; min-height: 32px; }
  .stepper-val { min-width: 2.2em; }
  .key { min-width: 1.7em; font-size: .78rem; padding: 0 4px; }
  .dialog-body { padding: 6px 14px; }
  .dialog-actions { padding: 10px 14px 16px; gap: 8px; }
  .dialog-actions .btn { font-size: .95rem; }
  .btn-lg { font-size: 1.1rem; }
  .card { padding: 14px 12px; }
  .room-item { padding: 10px; gap: 8px; }
  .room-item .row .btn { padding-left: 12px; padding-right: 12px; }
  .hud { flex-direction: column; gap: 4px; max-width: calc(100% - 128px); width: calc(100% - 128px); }
  .hud-chips { gap: 3px; max-width: 100vw; justify-content: center; }
  .hud-chip { padding: 1px 6px 1px 1px; font-size: .74rem; gap: 2px; border-width: 2px; }
  .hud-chip .avatar { width: 20px !important; height: 20px !important; }
  .game-main { padding-top: calc(86px + var(--safe-t)); }
  .game-main.has-touch.portrait { padding-bottom: calc(190px + var(--safe-b)); }
}
@media (max-width: 560px) and (orientation: landscape) { .game-main { padding-top: calc(60px + var(--safe-t)); } .hud { flex-direction: row; width: auto; } }
@media (max-width: 400px) { .topbar h2 { font-size: 1.15rem; } .hero-sub { font-size: .92rem; } }
/* 房間標題：寬螢幕和代號同一行；窄螢幕代號換到下一行，房名才不會被擠成一個字 */
.room-head { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.room-meta { display: flex; gap: 6px; flex: 0 0 auto; white-space: nowrap; }
@media (max-width: 600px) {
  .room-head { flex-direction: column; align-items: flex-start; gap: 4px; }
  .room-head h2 { width: 100%; }
  .room-meta .pill { font-size: .8rem; padding: 2px 10px; }
}

/* ===== 精簡設定面板 ===== */
.more-btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; margin-top: 8px; padding: 8px 12px; min-height: 40px; font: inherit; font-weight: 800; font-size: .92rem; color: #17122b; background: transparent; border: 3px dashed #17122b; border-radius: 12px; cursor: pointer; white-space: nowrap; }
.more-btn i { width: 8px; height: 8px; border-right: 3px solid #17122b; border-bottom: 3px solid #17122b; transform: rotate(45deg) translateY(-2px); transition: transform .15s; }
.more-btn[aria-expanded="true"] i { transform: rotate(-135deg) translateY(-2px); }
.more-btn:focus-visible { outline: 3px solid var(--sun, #ffe03d); outline-offset: 2px; }
.more-box { padding-top: 4px; }
.ai-faces { display: flex; gap: 6px; padding: 4px 0 8px; overflow-x: auto; scrollbar-width: none; }
.ai-faces .face { flex: 0 0 auto; border-radius: 50%; background: #fff; border: 3px solid #17122b; box-shadow: 2px 2px 0 #17122b; padding: 1px; display: inline-flex; }
.ai-faces .face.me { background: #cdf6ff; }
.sticky-cta { position: sticky; bottom: calc(-6px - var(--safe-b)); padding: 10px 0 4px; margin-top: auto; background: linear-gradient(to top, rgba(29,22,64,.92) 55%, rgba(29,22,64,0)); z-index: 5; }
.rules-sum { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }

/* ===== 自訂卷軸（scroll.js）：隱藏原生卷軸，改畫自己的滑軌與滑塊 ===== */
.sc-hide { scrollbar-width: none; -ms-overflow-style: none; }
.sc-hide::-webkit-scrollbar { display: none; width: 0; height: 0; }
.sc-track { position: absolute; z-index: 40; opacity: 0; transition: opacity .25s; pointer-events: none; }
.sc-track.show, .sc-track:hover { opacity: 1; }
.sc-track.v { width: 10px; }
.sc-track.h { height: 8px; }
.sc-track[hidden] { display: none; }
.sc-track::before { content: ""; position: absolute; inset: 0; border-radius: 999px; background: rgba(23, 18, 43, .35); border: 2px solid #17122b; }
.sc-track.v::before { border-radius: 6px; }
.sc-thumb { position: relative; pointer-events: auto; cursor: grab; border-radius: 999px; background: linear-gradient(#ffe86a, #ffc61a); border: 2px solid #17122b; box-sizing: border-box; touch-action: none; }
.sc-track.v .sc-thumb { width: 100%; min-height: 36px; }
.sc-track.h .sc-thumb { height: 100%; min-width: 28px; }
.sc-thumb.drag { cursor: grabbing; background: linear-gradient(#fff2a0, #ffd23a); }
.sc-track.h { pointer-events: none; }
.sc-track.v { pointer-events: auto; }
/* 內容被切到時兩端淡出，提示「還可以捲」 */
.sc-hide.can-r:not(.can-l) { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 22px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 22px), transparent); }
.sc-hide.can-l:not(.can-r) { -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 22px), transparent); mask-image: linear-gradient(to left, #000 calc(100% - 22px), transparent); }
.sc-hide.can-l.can-r { -webkit-mask-image: linear-gradient(to right, transparent, #000 22px, #000 calc(100% - 22px), transparent); mask-image: linear-gradient(to right, transparent, #000 22px, #000 calc(100% - 22px), transparent); }

/* 對局中的離開／暫停鈕 */
.exit-btn { position: absolute; z-index: 30; top: calc(66px + var(--safe-t)); left: calc(10px + var(--safe-l)); }
.game:not(.side-closed) .exit-btn { display: none; }
.exit-in { margin-left: auto; margin-right: 6px; }
/* 線上延遲：設定鈕正下方，跟左邊的暫停鈕對稱；不擋點擊 */
.ping { position: absolute; z-index: 30; top: calc(64px + var(--safe-t)); right: calc(12px + var(--safe-r)); text-align: right; font-size: .78rem; font-weight: 900; font-variant-numeric: tabular-nums; white-space: nowrap; color: #fff; text-shadow: 0 1px 2px #17122b, 0 0 3px #17122b; pointer-events: none; }
.ping::before { content: ''; display: inline-block; width: 8px; height: 8px; margin-right: 4px; border-radius: 50%; background: #9a93b5; box-shadow: 0 0 0 1.5px #17122b; vertical-align: 1px; }
.ping.good::before { background: #4cd08a; } .ping.mid::before { background: #ff9a3c; } .ping.bad::before { background: #ff4d4d; }
@media (min-width: 861px) and (min-aspect-ratio: 1/1) { .game.side-closed .exit-btn { top: calc(66px + var(--safe-t)); } }
@media (max-width: 560px) and (orientation: landscape) { .exit-btn { top: calc(62px + var(--safe-t)); } }

/* 網格欄位不可被內容撐寬（否則手機上右側會被切掉） */
.room-grid { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
.room-grid > *, .card, .wrap, .field, .ctl { min-width: 0; }
@media (max-width: 860px), (max-aspect-ratio: 1/1) { .room-grid { grid-template-columns: minmax(0, 1fr); } }

/* ===== 自訂下拉選單 ===== */
.dd { display: inline-flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; min-width: 7.5em; max-width: 100%; padding: 4px 12px; font: inherit; font-weight: 800; color: #17122b; background: #fffdf3; border: 3px solid #17122b; border-radius: 12px; box-shadow: 2px 2px 0 #17122b; cursor: pointer; white-space: nowrap; }
.dd:hover:not(:disabled) { background: #fff6bd; }
.dd:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: none; }
.dd:focus-visible, .dd-opt:focus-visible { outline: 3px solid #8b5cff; outline-offset: 2px; }
.dd.sm { min-height: 34px; min-width: 6.4em; font-size: .88rem; padding: 2px 10px; }
.dd.lvl { background: #d8fbe9; }
.dd-caret { width: 8px; height: 8px; border-right: 3px solid #17122b; border-bottom: 3px solid #17122b; transform: rotate(45deg) translateY(-2px); flex: 0 0 auto; transition: transform .15s; }
.dd[aria-expanded="true"] .dd-caret { transform: rotate(-135deg) translateY(-2px); }
.pop-layer { position: fixed; inset: 0; z-index: 300; pointer-events: none; }
.dd-list { position: fixed; pointer-events: auto; display: flex; flex-direction: column; gap: 4px; padding: 6px; overflow-y: auto; background: #fffdf3; border: 3px solid #17122b; border-radius: 14px; box-shadow: 5px 5px 0 #17122b; animation: fade .12s; scrollbar-width: none; }
.dd-list::-webkit-scrollbar { display: none; }
.dd-opt { display: flex; flex-direction: column; align-items: flex-start; gap: 0; width: 100%; padding: 8px 12px 8px 30px; position: relative; text-align: left; font: inherit; color: #17122b; background: transparent; border: 2px solid transparent; border-radius: 10px; cursor: pointer; }
.dd-opt .dd-name { font-weight: 900; white-space: nowrap; flex: 0 0 auto; }
.dd-opt small { color: #5b5378; font-weight: 700; font-size: .76rem; white-space: nowrap; }
.dd-opt:hover, .dd-opt:focus { background: #ffe86a; border-color: #17122b; }
.dd-opt[aria-selected="true"]::before { content: ""; position: absolute; left: 10px; top: 50%; width: 6px; height: 11px; border-right: 3px solid #17122b; border-bottom: 3px solid #17122b; transform: translateY(-65%) rotate(45deg); }
.ai-row { display: flex; align-items: center; gap: 10px; }
.ai-row .name { flex: 1; min-width: 0; }
.ai-row .dd { margin-left: auto; }
.dd-sw { display: inline-block; width: 18px; height: 18px; border-radius: 6px; border: 2px solid #17122b; flex: 0 0 auto; vertical-align: middle; margin-right: 8px; }
.dd-cur { display: inline-flex; align-items: center; min-width: 0; }
.dd-opt { flex-direction: row; flex-wrap: wrap; align-items: center; }
.dd-opt .dd-sw { position: static; margin-right: 8px; }
.dd-opt small { flex-basis: 100%; }

/* 席位卡：一列式 */
.seats { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.seat { min-height: 0; padding: 8px 10px; gap: 6px; justify-content: center; }
.seat-line { display: flex; align-items: center; gap: 8px; min-width: 0; width: 100%; }
.seat-line .seat-name { flex: 1 1 0; min-width: 0; }
.seat-line .dd, .seat-line .icon-btn, .seat-line .btn, .seat-line .pill { flex: 0 0 auto; }
.seat.empty { min-height: 58px; padding: 8px 10px; }
.seat.empty .seat-name { font-weight: 800; color: var(--ink2); }

/* 房間列表：不超出卡片；空間不足時按鈕移到下方，標籤可換行 */
.room-list { min-width: 0; max-width: 100%; }
.room-item { flex-wrap: wrap; min-width: 0; max-width: 100%; box-sizing: border-box; }
.room-item .info { flex: 1 1 240px; min-width: 0; }
.room-item .info .chips { flex-wrap: wrap; overflow: visible; }
.room-item > .row, .room-item > div:last-child:not(.info) { flex: 0 0 auto; }

/* 掃描修正：快速聊天改換行、邀請連結不撐破彈窗、首頁角色列窄螢幕換行置中 */
.quick-chat { flex-wrap: wrap; overflow: visible; }
.quick-chat button { white-space: nowrap; flex: 0 1 auto; }
.dialog-body, .dialog-body > *, .link-box { min-width: 0; max-width: 100%; box-sizing: border-box; }
.hero-cast { flex-wrap: wrap; justify-content: center; max-width: 100%; }
.hero-cast .avatar { margin: 0 -2px; }
