/* Frisbee 介面：深色、手機優先（手機介面原則） */
:root {
  --bg: #111318;
  --bg-2: #1a1d24;
  --bg-3: #242833;
  --line: #2f3442;
  --fg: #eceef3;
  --fg-2: #9aa1b2;
  --accent: #4f8cff;
  --accent-fg: #fff;
  --danger: #e5484d;
  --ok: #3cb44b;
  --radius: 14px;
  --tap: 44px;
  --tabbar-h: 60px;
  --topbar-h: 52px;
  --boardbar-h: 56px; /* 桌機舞台下方的畫圖工具列 */
  --side-w: 360px; /* 桌機右側面板（聊天／成員／待播）寬度 */
  --draw: #ffb020; /* 畫圖模式的邊框提示色 */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

/* ---- 開啟／關閉動畫（public/js/ui/anim.js）：以動畫開啟的介面一律以反向動畫關閉 ----
   關閉中（.is-closing）不可點；inert 由 anim.js 設定（不可聚焦）。
   位移用獨立的 translate 屬性，不蓋掉元素原本的 transform（例如置中用的 translateX(-50%)） */
.is-closing { pointer-events: none !important; }
@keyframes ui-in-up { from { opacity: 0; translate: 0 8px; } }
@keyframes ui-out-down { to { opacity: 0; translate: 0 8px; } }
@keyframes ui-in-down { from { opacity: 0; translate: 0 -8px; } }
@keyframes ui-out-up { to { opacity: 0; translate: 0 -8px; } }
@keyframes ui-pop-in { from { opacity: 0; scale: .96; } }
@keyframes ui-pop-out { to { opacity: 0; scale: .96; } }
@keyframes ui-fade-in { from { opacity: 0; } }
@keyframes ui-fade-out { to { opacity: 0; } }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  overscroll-behavior: none; /* 關掉下拉重新整理 */
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
#app { min-height: 100%; }

/* ---- 文字選取：整個 App 預設不可選（按鈕、標籤、分頁、通知、成員名稱等），
   只有聊天訊息內容（可複製）與可編輯欄位例外；手機長按不跳出系統選單 ---- */
html { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input, textarea, select, [contenteditable]:not([contenteditable="false"]),
.chat-text, .legal {
  -webkit-user-select: text; user-select: text; -webkit-touch-callout: default;
}
/* 非文字輸入（按鈕型、核取、滑桿等）維持不可選 */
input:is([type="button"], [type="submit"], [type="reset"], [type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"]) {
  -webkit-user-select: none; user-select: none;
}
h1, h2, p { margin: 0; }
button, input { font: inherit; color: inherit; }

/* ---- 按鈕與表單 ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); min-width: var(--tap); padding: 0 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg-3); color: var(--fg); text-decoration: none;
  cursor: pointer; user-select: none; touch-action: manipulation;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-block { display: flex; width: 100%; }
.btn-small { padding: 0 12px; font-size: 14px; }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: var(--tap); min-height: var(--tap); padding: 0 10px;
  border: 0; border-radius: 12px; background: transparent; color: var(--fg); cursor: pointer;
  touch-action: manipulation;
}
.btn-icon:active, .btn:active { filter: brightness(1.2); }
.btn-text { display: none; }
/* 中英並列標籤（ui/bilingual.js）：兩行置中，第一行中文、第二行英文 */
.bi { display: inline-flex; flex-direction: column; align-items: center; text-align: center; line-height: 1.25; min-width: 0; }
.bi-zh, .bi-en { max-width: 100%; }
.bi-en { font-size: .86em; opacity: .85; }
/* 按鈕內有兩行標籤：留一點上下內距（最小高度仍 ≥ 44px） */
.btn:has(> .bi), .seg:has(> .bi) { padding-top: 4px; padding-bottom: 4px; }
/* 分段按鈕較窄：英文行不換行（縮小字級、減少左右內距），維持剛好兩行 */
.seg:has(> .bi) { padding-left: 4px; padding-right: 4px; }
.seg .bi-en { font-size: .8em; white-space: nowrap; }
.icon { display: inline-flex; width: 24px; height: 24px; flex: none; }
.icon svg { width: 100%; height: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 14px; color: var(--fg-2); }
.input {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  font-size: 16px; /* iOS 小於 16px 會自動放大 */
}
.input:focus { border-color: var(--accent); outline: none; }
.code-input { letter-spacing: .3em; text-transform: uppercase; }
:root:lang(en) .code-input::placeholder { letter-spacing: normal; text-transform: none; }
.form-error { color: #ff8a8d; min-height: 1.5em; font-size: 14px; }
.form-error:empty { display: none; }
.hint { color: var(--fg-2); margin-bottom: 12px; }

.card {
  display: flex; flex-direction: column; gap: 14px;
  padding: 18px; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
}
.card h2 { font-size: 18px; }

/* ---- 首頁 ---- */
.home {
  max-width: 480px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px;
  padding: calc(24px + var(--safe-t)) calc(16px + var(--safe-r)) calc(32px + var(--safe-b)) calc(16px + var(--safe-l));
}
.home-hero { text-align: center; padding: 12px 0 4px; }
.home-hero h1 { font-size: 34px; letter-spacing: .02em; }
.home-hero p { color: var(--fg-2); }
/* 回到剛才的房間（home.js）：主要按鈕 + 右側小 × */
.home-notice { padding: 12px 16px; border-radius: 12px; background: var(--bg-2); border: 1px solid var(--danger); text-align: center; font-weight: 600; }
.rejoin { display: flex; align-items: stretch; gap: 4px; }
.rejoin-go { flex: 1; min-width: 0; justify-content: flex-start; padding: 10px 16px; text-align: left; font-weight: 600; }
.rejoin-label { min-width: 0; overflow-wrap: anywhere; }
.rejoin-close { flex: none; color: var(--fg-2); }
.rejoin-close .icon { width: 20px; height: 20px; }

.center-page {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
}
.center-page > .card { width: 100%; max-width: 420px; }
.loading { color: var(--fg-2); }
.fatal-text { font-size: 18px; text-align: center; }

/* ---- 房間外殼 ---- */
.room { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

.netbar {
  position: fixed; z-index: 60; top: 0; left: 0; right: 0;
  padding: calc(2px + var(--safe-t)) 12px 2px; text-align: center; font-size: 13px;
  background: #b7791f; color: #fff;
}

.topbar {
  display: flex; align-items: center; gap: 4px; flex: none; height: calc(var(--topbar-h) + var(--safe-t));
  padding: calc(4px + var(--safe-t)) calc(6px + var(--safe-r)) 4px calc(6px + var(--safe-l));
  background: var(--bg-2); border-bottom: 1px solid var(--line);
}
.room-title { flex: 1; min-width: 0; }
.room-name { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-meta { font-size: 12px; color: var(--fg-2); display: flex; gap: 6px; }
.room-code { letter-spacing: .12em; }

.room-main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
/* 工作區：影片（舞台容器）與戰術板並列（tactics.css）；右側面板：聊天／成員／待播。
   直式：工作區只有上方的影片，面板在下方（分頁內容＋底部導覽） */
.workspace { flex: none; position: relative; min-width: 0; }
.side { flex: 1; min-height: 0; min-width: 0; display: flex; flex-direction: column; }

/* 16:9 舞台：容器內 letterbox */
.stage-wrap {
  flex: none; position: relative; width: 100%; aspect-ratio: 16 / 9;
  background: #000;
  display: flex; align-items: center; justify-content: center;
}
.stage {
  position: relative; overflow: hidden; background: #0b0c10;
  width: 100%; aspect-ratio: 16 / 9;
}
/* 不用 container query：WebKit(WPE) 在 container-type:size 下調整視窗會當掉 */
.stage-placeholder {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--fg-2); font-size: 15px; pointer-events: none; text-align: center; padding: 12px;
}

.tabbar {
  order: 3; flex: none; display: flex;
  padding: 0 var(--safe-r) var(--safe-b) var(--safe-l);
  background: var(--bg-2); border-top: 1px solid var(--line);
}
.tab {
  flex: 1; min-width: var(--tap); min-height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: transparent; color: var(--fg-2); font-size: 12px; cursor: pointer;
  touch-action: manipulation;
}
.tab[aria-selected="true"] { color: var(--accent); }
.tab-icon { position: relative; display: inline-flex; }
.dot {
  position: absolute; top: -2px; right: -4px; width: 9px; height: 9px;
  border-radius: 50%; background: var(--danger); border: 2px solid var(--bg-2);
}

.panels { order: 2; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.panel { padding: 8px calc(12px + var(--safe-r)) 12px calc(12px + var(--safe-l)); }
.soon, .empty { color: var(--fg-2); text-align: center; padding: 32px 0; }

.fab {
  display: none; position: fixed; z-index: 30;
  right: calc(16px + var(--safe-r)); bottom: calc(16px + var(--safe-b));
  width: 52px; height: 52px; border-radius: 50%; border: 0;
  background: rgba(36, 40, 51, .85); color: var(--fg);
  align-items: center; justify-content: center; cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .4);
}

/* 成員清單 */
.member-list { list-style: none; margin: 0; padding: 0; }
.member-row {
  display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 4px 6px;
  border-bottom: 1px solid var(--line); border-radius: 8px;
}
.member-row[data-online="false"] { opacity: .5; }
.member-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.member-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.you { color: var(--fg-2); font-size: 13px; }
:root:lang(en) .you { margin-left: .3em; }
.crown { color: #f5c542; display: inline-flex; }
.crown .icon { width: 18px; height: 18px; }
.member-status { font-size: 12px; color: var(--fg-2); }
.member-transfer { flex: none; }

/* 設定 */
.settings { display: flex; flex-direction: column; gap: 18px; }
.setting { display: flex; flex-direction: column; gap: 8px; }
.segmented { display: flex; gap: 6px; background: var(--bg); padding: 4px; border-radius: 12px; }
.seg {
  flex: 1; min-height: var(--tap); border: 0; border-radius: 9px; background: transparent;
  color: var(--fg-2); cursor: pointer; touch-action: manipulation;
}
.seg[aria-pressed="true"] { background: var(--accent); color: #fff; }
.setting-hint { margin: -4px 0 0; color: var(--fg-2); font-size: .85em; }
/* 同步顯示控制權：兩個子項（戰術板／整個畫面），標籤在左、選項在右；窄畫面換行 */
.setting-sub { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.setting-sub-label { flex: 1 1 8em; color: var(--fg-2); }
.setting-sub .segmented { flex: 1 1 14em; }

/* ---- 播放器圖層（舞台內，由下而上）---- */
.player-host { position: absolute; inset: 0; z-index: 1; background: #000; }
.player-host iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
/* 裁切 YouTube iframe 上下緣：iframe 上下各多出 --yt-crop 再由 .stage 的 overflow:hidden 裁掉。
   YouTube 會把影片垂直置中（仍對齊舞台），標題／分享／更多影片貼著 iframe 上下緣 → 落在看不到的區域。
   .yt-crop-off：疑似廣告（點擊穿透中）時還原，不裁掉「略過廣告」 */
.stage:not(.yt-crop-off) .player-host iframe {
  --yt-crop: 180px;
  inset: auto 0; top: calc(-1 * var(--yt-crop)); height: calc(100% + 2 * var(--yt-crop));
}
.fake-player {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--fg-2); font: 13px/1.4 ui-monospace, monospace; background: #050608;
}
.stage-empty {
  position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; padding: 12px 16px; text-align: center;
}
.stage-empty-title { color: var(--fg-2); font-size: 15px; }
.stage-empty .load-form { width: min(100%, 520px); }
.stage-empty.readonly .load-form { display: none; }
.stage-wait { color: var(--fg-2); font-size: 14px; }
.stage-msg {
  position: absolute; inset: 0; z-index: 6; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; padding: 16px; text-align: center;
  background: rgba(11, 12, 16, .92);
}
.stage-msg-text { font-size: 16px; }
.stage-resume {
  position: absolute; inset: 0; z-index: 7; width: 100%; height: 100%; border: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 18px; touch-action: manipulation;
}
.stage-resume-label { padding: 12px 22px; border-radius: 999px; background: var(--accent); }

/* 貼網址表單 */
.load-form { display: flex; gap: 8px; width: 100%; }
.load-form .input { flex: 1; min-width: 0; }
.load-buttons { display: flex; gap: 8px; flex: none; }
.load-panel { flex-wrap: wrap; padding: 4px 0 10px; }
.load-panel .input { flex-basis: 100%; }
.load-panel .load-buttons { flex: 1; }
.load-panel .load-buttons .btn { flex: 1; }

/* 播放清單（類似 YouTube：目前項目原地標示、縮圖下緣為觀看進度） */
.queue-head { display: flex; align-items: center; gap: 8px; padding: 4px 4px 6px; }
.queue-head-title { font-weight: 600; font-size: 14px; }
.queue-count { font-size: 12px; color: var(--fg-2); font-variant-numeric: tabular-nums; }
.queue-prune { margin-left: auto; }
.queue-list { list-style: none; margin: 0; padding: 0; position: relative; }
.queue-item {
  position: relative; display: flex; align-items: center; gap: 10px; min-height: 64px; padding: 5px 4px;
  border-bottom: 1px solid var(--line); border-radius: 8px; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; cursor: pointer; background: var(--bg);
  transition: transform .18s ease, background-color .15s;
}
.queue-item:hover { background: var(--bg-2); }
.queue-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.queue-item.current { background: color-mix(in srgb, var(--accent) 16%, var(--bg)); }
.queue-item.done:not(.current) .queue-thumb { opacity: .7; }
.queue-item.can-drag { cursor: grab; }
.queue-item.pressing { background: var(--bg-2); }
.queue-list.reordering .queue-item { cursor: grabbing; }
/* 拖曳中的列跟著指標（不套動畫），其他列滑開露出空位 */
.queue-item.dragging {
  z-index: 2; transition: none; background: var(--bg-3); border-color: transparent;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}
.queue-list.no-anim .queue-item { transition: none; }
.queue-idx { width: 18px; flex: none; text-align: center; font-size: 12px; color: var(--fg-2); font-variant-numeric: tabular-nums; }
.queue-idx .icon { width: 14px; height: 14px; color: var(--accent); vertical-align: middle; }
.queue-thumb-wrap { position: relative; width: 96px; height: 54px; flex: none; border-radius: 6px; overflow: hidden; background: var(--bg-3); }
.queue-thumb { display: block; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.queue-badge {
  position: absolute; right: 3px; bottom: 6px; padding: 0 4px; border-radius: 4px; font-size: 11px; line-height: 16px;
  background: rgba(0, 0, 0, .78); color: #fff; font-variant-numeric: tabular-nums;
}
.queue-prog { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255, 255, 255, .35); }
.queue-prog-fill { display: block; height: 100%; background: #f03; }
.queue-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.queue-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.queue-item.current .queue-title { font-weight: 600; }
.queue-by { font-size: 12px; color: var(--fg-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 觸控：水平移動由頁面處理（滑動移除），垂直交給瀏覽器捲動 */
.queue-item { touch-action: pan-y; }
/* 滑動移除：列滑開後露出紅色「移除」底（偽元素貼在列的左／右側，清單水平裁切） */
.queue-list.swiping { overflow-x: clip; }
.queue-item.swiping { transition: none; }
.queue-item.swipe-out { opacity: 0; transition: transform .18s ease-in, opacity .18s ease-in; }
.queue-item[data-swipe]::before {
  content: '移除'; position: absolute; top: 0; bottom: 0; width: 100%; display: flex; align-items: center;
  padding: 0 20px; box-sizing: border-box; background: var(--danger, #d93025); color: #fff; font-size: 14px; font-weight: 600;
  border-radius: 8px; opacity: .75; transition: opacity .12s;
}
.queue-item[data-swipe="right"]::before { right: 100%; justify-content: flex-end; }
.queue-item[data-swipe="left"]::before { left: 100%; justify-content: flex-start; }
:root:lang(en) .queue-item[data-swipe]::before { content: 'Remove'; }
.queue-item.swipe-armed::before { opacity: 1; }
/* 滑鼠：× 移除鈕在懸停／鍵盤焦點時出現 */
@media (hover: hover) {
  .queue-remove { opacity: 0; transition: opacity .12s; }
  .queue-item:hover .queue-remove, .queue-item:focus-within .queue-remove { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .queue-item { transition: none; } }

/* ---- 共筆畫布（舞台內最上層；畫圖模式關閉時不攔截指標）---- */
.board { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.board.drawing { z-index: 8; }
.board canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.board-committed { pointer-events: none; transform-origin: 0 0; }
/* 舞台縮放（board/zoom.js，本地檢視）：只變換內容圖層的外層（播放器容器、共享網頁框），不動 iframe 本身；
   畫布以同一檢視重畫；控制列、按鈕、通知等不在變換範圍內。舞台上不讓瀏覽器做整頁雙指縮放（捲動照常） */
.stage { touch-action: pan-x pan-y; }
.stage.zoomed > .player-host, .stage.zoomed .web-frame-box { transform: var(--zoom-tf, none); transform-origin: 0 0; }
.stage.zoom-panning, .stage.zoom-panning .board-live { cursor: grabbing; }
.zoom-reset { width: auto; min-width: 48px; padding: 0 10px; background: var(--bg-3); font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.zoom-reset[hidden], .zoom-chip[hidden] { display: none; }
.stage-btn.zoom-chip {
  /* 手機未開畫圖模式時的倍率標籤：排在舞台右上按鈕列的最前面（board-ui.js 放進 .stage-controls）——
     不佔影片中段左右兩側的雙擊快轉區，也不擋播放器控制；與其他舞台按鈕（.stage-btn）一起自動淡出 */
  width: auto; gap: 4px; padding: 0 10px 0 14px; border-radius: 999px; background: rgba(17, 19, 24, .78);
  font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.stage-btn.zoom-chip .icon { width: 18px; height: 18px; }
.stage-wrap.drawing .zoom-chip { display: none; }
/* 畫圖模式讓出工具列的位置（board/stage-fit.js）：舞台的 width 與 left/top 以行內樣式設定，轉場期間加上 .fit-anim。
   不能有 flex-shrink：寬度由行內樣式決定 */
.stage.fit { flex: none; }
.stage.fit-anim { transition: width .28s cubic-bezier(.3, .7, .2, 1), left .28s cubic-bezier(.3, .7, .2, 1), top .28s cubic-bezier(.3, .7, .2, 1); }
@media (prefers-reduced-motion: reduce) { .stage.fit-anim { transition: none; } }
.board.drawing .board-live { cursor: crosshair; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.board-cursor {
  position: absolute; left: 0; top: 0; pointer-events: none; border-radius: 50%;
  border: 1.5px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .6);
}
.board-hint {
  position: absolute; inset: 0; z-index: 9; pointer-events: none;
  box-shadow: inset 0 0 0 3px var(--draw);
}
.board-hint-label {
  position: absolute; top: 8px; left: 8px; padding: 2px 10px; border-radius: 999px;
  background: var(--draw); color: #111; font-size: 12px; font-weight: 600;
}

/* 工具列：手機為底部浮出的一排大圖示（可橫向捲動），桌機為舞台下方的一列 */
.board-toolbar {
  position: fixed; z-index: 35; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; gap: 4px;
  min-height: calc(var(--tabbar-h) + var(--safe-b));
  padding: 4px calc(8px + var(--safe-r)) calc(4px + var(--safe-b)) calc(8px + var(--safe-l));
  background: var(--bg-2); border-top: 2px solid var(--draw);
  overflow-x: auto; overscroll-behavior: contain; touch-action: pan-x; scrollbar-width: none;
}
.board-toolbar:not(.open) { display: none; }
/* 自動淡出（ui/idle.js）：播放中無操作後隱藏（點畫面再出現）。
   直式非全螢幕時畫圖鈕不在舞台上 → 不隱藏；桌機工具列在舞台下方 → 不隱藏（見下方桌機區塊） */
.board-toolbar.idle, .fab-draw.idle { visibility: hidden; opacity: 0; transition: opacity .25s, visibility .25s; }
.room[data-layout="portrait"] .stage-wrap:not(.fs) .fab-draw.idle { visibility: visible; opacity: 1; }
.board-toolbar::-webkit-scrollbar { display: none; }
.tool {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; border: 0; border-radius: 12px; background: transparent; color: var(--fg);
  cursor: pointer; touch-action: manipulation;
}
.tool .icon { width: 26px; height: 26px; }
.tool[aria-pressed="true"] { background: var(--accent); color: #fff; }
.tool:disabled { opacity: .35; cursor: default; }
.tool:active:not(:disabled) { filter: brightness(1.25); }
.tool-sep { flex: none; width: 1px; height: 28px; background: var(--line); margin: 0 2px; }
.swatch-dot { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .5); }
.board-toggle { display: none; flex: none; }
.board-toggle[aria-pressed="true"] { background: var(--draw); border-color: var(--draw); color: #111; }

.fab-draw {
  position: fixed; z-index: 36; right: calc(16px + var(--safe-r));
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  background: var(--accent); color: #fff; box-shadow: 0 4px 16px rgba(0, 0, 0, .45);
  touch-action: manipulation;
}
.fab-draw.on { background: var(--draw); color: #111; }
/* 繪圖控制權為僅主持人：畫圖鍵顯示停用（仍可點，點了跳出說明） */
.fab-draw.denied, .board-toggle.denied { opacity: .45; }
.fab-draw .icon { width: 28px; height: 28px; }
/* 直式：讓面板最後一列可捲到浮動按鈕上方 */
.panels { padding-bottom: 84px; }

.board-style { display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer;
  touch-action: manipulation;
}
.swatch[aria-pressed="true"] { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.width-range { width: 100%; min-height: var(--tap); accent-color: var(--accent); }
.width-value { color: var(--fg); font-variant-numeric: tabular-nums; }
.board-text { display: flex; flex-direction: column; gap: 12px; }
.board-text-input { resize: none; }

/* ---- 底部抽屜 ---- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 80; background: rgba(0, 0, 0, .5);
  opacity: 0; transition: opacity .2s;
}
.sheet-backdrop.open { opacity: 1; }
.sheet {
  position: fixed; z-index: 81; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 560px;
  max-height: 85dvh; display: flex; flex-direction: column;
  background: var(--bg-2); border-radius: 18px 18px 0 0; border: 1px solid var(--line); border-bottom: 0;
  padding: 0 calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
  transform: translateY(100%); transition: transform .22s ease-out; touch-action: pan-y;
}
.sheet.open { transform: translateY(0); }
/* 關閉中：邏輯上已關閉（hidden），但仍顯示到反向轉場結束（ui/sheet.js） */
.sheet.is-closing[hidden] { display: flex !important; }
.sheet-backdrop.is-closing[hidden] { display: block !important; }
.sheet-grip { display: flex; justify-content: center; padding: 10px 0 8px; cursor: grab; touch-action: none; }
.sheet-grip span { width: 40px; height: 5px; border-radius: 3px; background: var(--line); }
.sheet-title { font-size: 17px; padding-bottom: 12px; touch-action: none; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; min-height: 0; }
.sheet-tall { max-height: 92dvh; height: 92dvh; }
.sheet-tall .sheet-body { flex: 1; display: flex; }
.sheet-panels { flex: 1; display: flex; flex-direction: column; min-height: 0; width: 100%; }
.sheet-panels .tabbar { order: 0; border: 0; border-bottom: 1px solid var(--line); padding: 0; background: transparent; }
.sheet-panels .tab { min-height: var(--tap); flex-direction: row; gap: 6px; font-size: 14px; }
.sheet-panels .panels { order: 1; }
.confirm p { margin-bottom: 16px; font-size: 17px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.member-actions .btn { margin-top: 4px; }

/* ---- toast ---- */
.toasts {
  position: fixed; z-index: 90; left: 0; right: 0;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px);
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.toast {
  max-width: min(90vw, 420px); padding: 10px 16px; border-radius: 999px;
  background: rgba(236, 238, 243, .95); color: #111; font-size: 14px;
  opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* 只在桌機版面顯示的按鈕（側欄收合） */
.desktop-only { display: none; }

/* ---- 桌機（≥900px）：舞台在左、右側欄分頁 ---- */
@media (min-width: 900px) and (min-height: 541px) {
  .btn-text { display: inline; }
  .btn-icon.desktop-only { display: inline-flex; }
  /* 工作區在左、面板在右：面板佔自己的寬度（不蓋住工作區），收合／展開時從右緣滑出／滑入 */
  .room-main { flex-direction: row; overflow: hidden; }
  .workspace { flex: 1; display: flex; }
  .side {
    flex: none; width: var(--side-w); border-left: 1px solid var(--line); background: var(--bg);
    transition: margin-right .22s ease;
  }
  .room.side-collapsed .side {
    margin-right: calc(0px - var(--side-w)); visibility: hidden;
    transition: margin-right .22s ease, visibility 0s .22s;
  }
  .stage-wrap { flex: 1 1 0; min-width: 0; width: auto; height: 100%; aspect-ratio: auto; flex-direction: column; }
  .stage { width: min(100%, (100dvh - var(--topbar-h) - var(--safe-t) - var(--boardbar-h)) * 16 / 9); }
  .board-toolbar, .board-toolbar:not(.open) {
    position: static; display: flex; flex: none; justify-content: flex-start; width: 100%;
    min-height: var(--boardbar-h); height: var(--boardbar-h); padding: 4px 8px;
    border-top: 1px solid var(--line); overflow-x: auto;
  }
  /* 置中，但窄到放不下時（並排戰術板）從左邊開始、可橫向捲動 */
  .board-toolbar > :first-child { margin-left: auto; }
  .board-toolbar > :last-child { margin-right: auto; }
  .board-toolbar.open { border-top-color: var(--draw); }
  .board-toolbar.idle { visibility: visible; opacity: 1; }
  .board-toggle { display: inline-flex; margin-right: 6px; }
  .tool { width: 44px; height: 44px; }
  .fab-draw { display: none; }
  .stage-btn.zoom-chip { display: none; } /* 桌機工具列常駐，倍率顯示在工具列 */
  .panels { padding-bottom: 0; }
  .tabbar { order: 0; padding: 0; border-top: 0; border-bottom: 1px solid var(--line); }
  .tab { flex-direction: row; gap: 6px; min-height: 48px; font-size: 14px; }
  .panels { order: 1; }
  .mobile-only { display: none; }
  .toasts { bottom: 24px; }
  .sheet { bottom: auto; top: 50%; border-radius: 18px; border-bottom: 1px solid var(--line);
    transform: translateY(-40%); opacity: 0; transition: transform .2s, opacity .2s; max-height: 80dvh; }
  .sheet.open { transform: translateY(-50%); opacity: 1; }
}

/* ---- 手機橫式：沉浸舞台，面板由浮動按鈕開啟 ---- */
@media (orientation: landscape) and (max-height: 540px) {
  .topbar, .side { display: none; }
  /* 工作區佔滿畫面；舞台容器在工作區內（並排戰術板時只佔左半），浮動按鈕與工具列跟著舞台容器 */
  .room-main { flex-direction: row; }
  .workspace { flex: 1; display: flex; }
  .stage-wrap { flex: 1 1 0; min-width: 0; width: auto; height: 100%; aspect-ratio: auto; isolation: isolate; }
  .stage { width: min(100%, 100dvh * 16 / 9); }
  .fab { display: flex; right: calc(16px + var(--safe-r) + var(--ws-pane-w, 0px)); }
  .fab-draw { position: absolute; bottom: calc(16px + 52px + 12px + var(--safe-b)); }
  .board-toolbar { position: absolute; right: calc(84px + var(--safe-r)); min-height: 60px; border-radius: 0 16px 0 0; }
  /* 畫圖中：畫圖鍵（52px）移到底部工具列那一排、面板鍵的左側，面板鍵也對齊這一排 →
     蓋在舞台上的只剩底部一排，舞台（stage-fit.js）只需讓出這一排的高度，不必再避開疊在畫面中段的畫圖鍵
     （並排戰術板時影片窗格只有半個畫面寬，原本會因畫圖鍵縮掉約三成） */
  .stage-wrap.drawing .fab-draw {
    width: 52px; height: 52px; bottom: calc(4px + var(--safe-b)); right: calc(16px + 52px + 8px + var(--safe-r));
  }
  .stage-wrap.drawing .board-toolbar { right: calc(16px + 52px + 8px + 52px + 8px + var(--safe-r)); }
  .room.board-drawing .fab { bottom: calc(4px + var(--safe-b)); }
  /* 全螢幕沒有面板鍵：畫圖鍵在右下角 */
  .stage-wrap.fs.drawing .fab-draw { right: calc(16px + var(--safe-r)); }
  .stage-wrap.fs.drawing .board-toolbar { right: calc(16px + 52px + 8px + var(--safe-r)); }
  .toasts { bottom: calc(16px + var(--safe-b)); }
  .sheet { max-width: 520px; }
}

/* 減少動態：右側面板不滑動 */
@media (prefers-reduced-motion: reduce) {
  .side, .room.side-collapsed .side { transition: none; }
  .sheet, .sheet-backdrop { transition: none; }
}

/* 主持人離開房間：轉移主持人／關閉房間 */
.host-leave { display: flex; flex-direction: column; gap: 10px; }
.host-leave .hint { margin: 0; }
.host-leave-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.host-leave-btn .icon { width: 18px; height: 18px; }
.host-leave-picks { display: flex; flex-direction: column; gap: 8px; max-height: 40vh; overflow-y: auto; }
.host-leave-pick { display: flex; align-items: center; justify-content: flex-start; gap: 10px; text-align: left; }
.host-leave-pick .pick-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.host-leave-danger-text { color: var(--danger); margin: 0; }
