/* 教室白板：外框與共用樣式。顏色、圓角、陰影全部用 themes.css 的變數，四種主題才換得過來。 */
:root {
  --font: system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Noto Sans JP", "Noto Sans KR", sans-serif;
  --num: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}
html[lang="zh-Hans"] { --font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif; }
html[lang="ja"] { --font: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif; }
html[lang="ko"] { --font: system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body { font: 400 1rem/1.5 var(--font); color: var(--ch-ink); background: #1b1b1b; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--acc); outline-offset: 2px; }
.ic { display: inline-flex; flex: none; }
.ic svg { display: block; }
body.booting #topbar, body.booting #dock { visibility: hidden; }
.boot-error { position: fixed; inset: 0; display: grid; place-items: center; margin: 0; padding: 2rem; text-align: center; font-size: 1.125rem; color: #fff; }

/* 共用的「外框面板」外觀：上方列、工具列、選單、抽屜都用它 */
.chrome { background: var(--ch-bg); color: var(--ch-ink); border: var(--ch-border); border-radius: var(--ch-radius); box-shadow: var(--ch-shadow); backdrop-filter: var(--ch-blur); -webkit-backdrop-filter: var(--ch-blur); }

/* ---- 畫布 ---- */
/* 底色由 .bg-* 決定；這裡不要設 background-color，id 選擇器會蓋過它們 */
#viewport { position: fixed; inset: 0; overflow: auto; background-size: cover; background-position: center; }
#stage-wrap { position: relative; width: var(--stage-w, 100%); height: var(--stage-h, 100%); }
#stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.empty-hint { position: fixed; inset: 0; margin: 0; display: grid; place-items: center; pointer-events: none; font-size: 1.375rem; color: #5b5750; text-align: center; padding: 2rem; }
#viewport[data-tone="dark"] ~ .empty-hint, #viewport[data-tone="dark"] .empty-hint { color: rgba(255, 255, 255, 0.82); }

/* 背景：auto＝跟著主題；其他是固定的底色與紋路 */
.bg-auto { background: var(--board-bg); }
.bg-paper { background-color: #e4e2dd; }
.bg-snow { background-color: #f4f2ec; }
.bg-sand { background-color: #e7d9bf; }
.bg-sky { background-color: #cddfe9; }
.bg-mint { background-color: #d3e3d2; }
.bg-rose { background-color: #ecd5d0; }
.bg-horizon { background: linear-gradient(#d9e3e6 0 62%, #c9c2b2 62% 100%); }
.bg-chalk { background-color: #23483c; }
.bg-navy { background-color: #1d2e4c; }
.bg-night { background-color: #1f1e1c; }
.bg-dusk { background: linear-gradient(#2b3350 0 62%, #1b1d27 62% 100%); }
.bg-image { background-color: #1f1e1c; }
.bg-dots { background-color: #ebe9e3; background-image: radial-gradient(rgba(0, 0, 0, 0.22) 1.6px, transparent 1.8px); background-size: 2.2vw 2.2vw; }
.bg-grid { background-color: #f4f2ec; background-image: linear-gradient(rgba(40, 72, 184, 0.16) 1px, transparent 1px), linear-gradient(90deg, rgba(40, 72, 184, 0.16) 1px, transparent 1px); background-size: 2.6vw 2.6vw; }
.bg-lines { background-color: #f6f3ea; background-image: linear-gradient(transparent calc(100% - 1.5px), rgba(40, 72, 184, 0.22) calc(100% - 1.5px)); background-size: 100% 4.4vw; }
.bg-blueprint { background-color: #1c3d6e; background-image: linear-gradient(rgba(255, 255, 255, 0.14) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, 0.14) 1px, transparent 1px); background-size: 2.6vw 2.6vw; }
.bg-sunrise { background: linear-gradient(#f6c9a0 0%, #f3dcc0 38%, #e9e3d6 62%, #c9c2b2 62% 100%); }
.bg-ocean { background: linear-gradient(#cfe4ee 0 55%, #7fb0c9 55% 70%, #5b93b3 70% 100%); }
.bg-meadow { background: linear-gradient(#d6e8f0 0 60%, #a9c98f 60% 74%, #8db674 74% 100%); }
.bg-space { background: radial-gradient(circle at 70% 20%, #3a3f6b 0, #1b1d33 45%, #0e0f1c 100%); }

/* ---- 工具外框（在畫布裡，單位是邏輯像素）---- */
.w { position: absolute; left: 0; top: 0; touch-action: none; }
.w-body { position: relative; width: 100%; height: 100%; background: var(--w-bg); color: var(--w-ink); border: var(--w-border); border-radius: var(--w-radius); overflow: hidden; container-type: size; box-shadow: var(--w-shadow); font-size: 22px; line-height: 1.4; transition: box-shadow 0.15s, outline-color 0.15s; }
.w.selected .w-body { outline: var(--w-select); outline-offset: 7px; }

/* 卡片控制列：選取或滑過時，浮在卡片右上方的一顆小膠囊 */
.w-bar { position: absolute; right: 0; bottom: 100%; margin-bottom: 12px; height: 46px; display: none; align-items: center; gap: 0; padding: 0 3px; white-space: nowrap; z-index: 3; background: var(--ch-bg); color: var(--ch-ink); border: var(--ch-border); border-radius: 999px; box-shadow: var(--ch-shadow); backdrop-filter: var(--ch-blur); -webkit-backdrop-filter: var(--ch-blur); }
.w-bar::after { content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 14px; }
.w.bar-in .w-bar { bottom: auto; top: 10px; right: 10px; margin: 0; }
.w.bar-in .w-bar::after { display: none; }
.w.selected:not(.locked) .w-bar { display: flex; }
@media (hover: hover) and (pointer: fine) { .w:hover:not(.locked) .w-bar { display: flex; } }
.w-grip { display: flex; align-items: center; gap: 6px; height: 100%; padding: 0 10px 0 12px; cursor: grab; font-size: 17px; font-weight: 700; max-width: 230px; overflow: hidden; text-overflow: ellipsis; touch-action: none; user-select: none; -webkit-user-select: none; }
.w-grip .ic { opacity: 0.55; }
.w-grip-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--tool, var(--acc)); flex: none; }
.w-btn { width: 42px; height: 40px; display: grid; place-items: center; background: none; border: 0; border-radius: 999px; color: inherit; padding: 0; }
.w-btn:hover { background: var(--ch-hover); }
.w-h { position: absolute; width: 22px; height: 22px; background: var(--ch-bg); border: 3px solid var(--acc); border-radius: 50%; display: none; z-index: 3; touch-action: none; }
.w-h::after { content: ""; position: absolute; inset: -14px; }
.w-h-nw { left: -12px; top: -12px; cursor: nwse-resize; }
.w-h-ne { right: -12px; top: -12px; cursor: nesw-resize; }
.w-h-sw { left: -12px; bottom: -12px; cursor: nesw-resize; }
.w-h-se { right: -12px; bottom: -12px; cursor: nwse-resize; }
.w-rot { position: absolute; left: 50%; top: 100%; margin: 20px 0 0 -18px; width: 36px; height: 36px; border-radius: 50%; background: var(--ch-bg); border: 2px solid var(--acc); color: var(--acc); display: none; place-items: center; cursor: grab; z-index: 3; touch-action: none; }
.w.selected:not(.locked) .w-h { display: block; }
.w.selected:not(.locked) .w-rot { display: grid; }
.w-lock { position: absolute; right: 10px; top: 10px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--ch-ink); color: var(--ch-bg); display: none; place-items: center; z-index: 3; padding: 0; }
.w.locked.selected .w-lock { display: grid; }
.w-error { margin: 0; padding: 20px; color: var(--danger); font-size: 20px; }
body.present .w-bar, body.present .w-h, body.present .w-rot, body.present .w-lock { display: none !important; }
body.present .w.selected .w-body { outline: none; }
body.dragging { user-select: none; -webkit-user-select: none; cursor: grabbing; }
body.dragging iframe, body.dragging video { pointer-events: none; }

/* ---- 工具內容的共用零件（各工具都可以用）---- */
.w-fill { width: 100%; height: 100%; display: flex; flex-direction: column; }
.w-center { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.w-pad { padding: clamp(10px, 4cqmin, 28px); }
.w-gap { gap: clamp(8px, 3cqmin, 20px); }
.w-grow { flex: 1 1 0; min-height: 0; min-width: 0; }
.w-row { display: flex; align-items: center; justify-content: center; gap: clamp(8px, 2.5cqmin, 16px); flex-wrap: wrap; }
.w-num { font-family: var(--num); font-variant-numeric: tabular-nums; font-weight: var(--num-weight); letter-spacing: -0.01em; line-height: 1; }
.w-label { color: var(--w-sub); font-size: clamp(15px, 5cqmin, 24px); }
.w-title { font-family: var(--font-display); font-weight: 800; }
.w-scroll { overflow: auto; touch-action: pan-y; overscroll-behavior: contain; }
.wb { min-height: clamp(48px, 14cqmin, 76px); min-width: clamp(48px, 14cqmin, 76px); padding: 0 clamp(16px, 5.5cqmin, 30px); border-radius: var(--wb-radius); border: var(--wb-border); box-shadow: var(--wb-shadow); background: var(--w-bg-2); color: var(--w-ink); font-size: clamp(20px, 6.5cqmin, 34px); font-weight: var(--wb-weight); display: inline-flex; align-items: center; justify-content: center; gap: 8px; line-height: 1.1; transition: transform 0.08s, filter 0.12s; }
.wb:hover { filter: brightness(0.96); }
.wb:active { transform: translateY(2px); box-shadow: none; }
.wb.primary { background: var(--w-acc); color: var(--w-acc-ink); }
.wb.primary:hover { filter: brightness(1.08); }
.wb.ghost { background: none; box-shadow: none; }
.wb.round { padding: 0; border-radius: 50%; }
.wb:disabled { opacity: 0.45; cursor: default; }
.w-input { min-height: 48px; padding: 8px 12px; border: 1px solid var(--w-line); border-radius: 12px; background: var(--w-surface); color: var(--w-ink); font-size: 20px; width: 100%; }

/* ---- 上方列 ---- */
#topbar { position: fixed; left: 0; right: 0; top: 0; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left)); pointer-events: none; z-index: 5000; }
.tb-group { pointer-events: auto; display: flex; align-items: center; gap: 2px; padding: 5px; max-width: 100%; }
.brand { display: flex; align-items: center; gap: 9px; padding: 0 10px 0 8px; min-height: 46px; text-decoration: none; color: inherit; font-weight: 800; white-space: nowrap; letter-spacing: -0.01em; }
.brand-mark { width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(#c9d6dc 0 56%, #161616 56% 100%); border: 2px solid #161616; flex: none; }
.tb-scene { display: flex; align-items: center; gap: 6px; min-height: 46px; padding: 0 12px 0 14px; border: 0; border-left: 1px solid var(--ch-line); background: none; max-width: 32vw; font-weight: 600; }
.tb-scene-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-btn { position: relative; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; min-width: 46px; padding: 0 11px; border: 0; border-radius: calc(var(--ch-radius) - 5px); background: none; white-space: nowrap; font-weight: 600; }
.tb-btn:hover, .tb-scene:hover { background: var(--ch-hover); }
.tb-btn.primary { background: var(--acc); color: var(--acc-ink); padding: 0 18px; box-shadow: var(--acc-shadow); margin-inline-start: 4px; }
.tb-btn.primary:hover { background: var(--acc-hover); }
.tb-btn.on { background: var(--ch-hover); }
.tb-label-hide { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.status { display: flex; align-items: center; gap: 6px; font-size: 0.8125rem; color: var(--ch-sub); padding: 0 10px; white-space: nowrap; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.status.saving::before { background: var(--hi); }
.status.error { color: var(--danger); font-weight: 600; }
.status.error::before { background: var(--danger); }
@media (max-width: 1100px) { .status { display: none; } }
@media (max-width: 620px) { .brand-name { display: none; } .tb-btn.primary .tb-label { display: none; } }

/* ---- 下方工具列 ---- */
#dock { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; padding: 0 max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); pointer-events: none; z-index: 5000; }
.dock-scroll { pointer-events: auto; display: flex; gap: 2px; max-width: 100%; overflow-x: auto; padding: 7px; scrollbar-width: none; }
.dock-scroll::-webkit-scrollbar { display: none; }
.dock-btn { flex: none; width: 5.6rem; min-height: 4.6rem; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; padding: 6px 4px 5px; border: 0; border-radius: calc(var(--ch-radius) - 4px); background: none; font-size: 0.75rem; font-weight: 600; line-height: 1.15; text-align: center; color: inherit; }
.dock-btn > span:last-child { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; hyphens: auto; -webkit-hyphens: auto; }
.dock-btn:hover { background: var(--ch-hover); }
.dock-btn:hover .dock-ic { transform: translateY(-3px); }
.dock-btn:active .dock-ic { transform: translateY(1px); }
.dock-ic { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; background: var(--tool, var(--acc)); color: #fff; transition: transform 0.14s; }
.dock-all .dock-ic { background: var(--ch-ink); color: var(--ch-bg); }
.dock-sep { flex: none; width: 1px; margin: 10px 4px; background: var(--ch-line); }
/* 各主題的工具圖示外觀 */
body[data-theme="sketch"] .dock-ic { border: 2px solid #161616; box-shadow: 2px 2px 0 #161616; color: #161616; background: color-mix(in srgb, var(--tool, var(--acc)) 30%, #fffdf8); }
body[data-theme="sketch"] .dock-all .dock-ic { background: var(--hi); color: #161616; }
body[data-theme="blocks"] .dock-ic { border-radius: 16px; box-shadow: 0 4px 0 color-mix(in srgb, var(--tool, var(--acc)) 60%, #000); }
body[data-theme="chalk"] .dock-ic { border-radius: 6px; background: color-mix(in srgb, var(--tool, var(--acc)) 22%, #fffaee); color: color-mix(in srgb, var(--tool, var(--acc)) 80%, #000); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.18); }
body[data-theme="dark"] .dock-ic { background: color-mix(in srgb, var(--tool, var(--acc)) 24%, transparent); color: color-mix(in srgb, var(--tool, var(--acc)) 60%, #fff); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tool, var(--acc)) 45%, transparent); }
body[data-theme="dark"] .dock-all .dock-ic { background: rgba(255, 255, 255, 0.12); color: #fff; }
body.present #topbar, body.present #dock { display: none; }

/* ---- 上課模式的小控制列 ---- */
#presentbar { position: fixed; right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom)); display: none; align-items: center; gap: 4px; padding: 4px; background: rgba(20, 20, 20, 0.72); color: #fff; border-radius: 14px; z-index: 5000; opacity: 0.35; transition: opacity 0.2s; }
#presentbar:hover, #presentbar:focus-within { opacity: 1; }
@media (hover: none) { #presentbar { opacity: 0.8; } }
body.present #presentbar { display: flex; }
.pb-btn { min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 0 10px; border: 0; border-radius: 10px; background: none; color: #fff; }
.pb-btn:hover { background: rgba(255, 255, 255, 0.18); }
.pb-name { padding: 0 6px; max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- 浮層 ---- */
#layer { position: fixed; inset: 0; pointer-events: none; z-index: 6000; }
#layer > * { pointer-events: auto; }
.popover { position: fixed; min-width: 13rem; max-width: min(22rem, calc(100vw - 20px)); overflow: auto; padding: 6px; background: var(--ch-bg); color: var(--ch-ink); border: var(--ch-border); border-radius: var(--ch-radius); box-shadow: var(--ch-shadow), 0 24px 50px -24px rgba(0, 0, 0, 0.45); backdrop-filter: var(--ch-blur); -webkit-backdrop-filter: var(--ch-blur); animation: pop-in 0.14s ease-out; }
.popover.wide { width: min(24rem, calc(100vw - 20px)); max-width: none; padding: 14px; }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(0.98); } }
.menu { display: flex; flex-direction: column; }
.menu hr { width: 100%; border: 0; border-top: 1px solid var(--ch-line); margin: 6px 0; }
.menu-item { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 12px; border: 0; border-radius: calc(var(--ch-radius) - 6px); background: none; text-align: start; font-weight: 500; }
.menu-item:hover { background: var(--ch-hover); }
.menu-item .ic { opacity: 0.7; }
.menu-range { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 12px; }
.menu-range input { flex: 1; min-width: 6rem; accent-color: var(--acc); }
.menu-note { margin: 4px 8px 8px; font-size: 0.875rem; color: var(--ch-sub); }
.scene-row { display: flex; align-items: center; border-radius: 9px; }
.scene-row.on { background: color-mix(in srgb, var(--acc) 14%, transparent); }
.scene-pick { flex: 1; min-height: 44px; min-width: 0; padding: 0 12px; border: 0; border-radius: 9px; background: none; text-align: start; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scene-row.on .scene-pick { font-weight: 700; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border: 0; border-radius: 9px; background: none; padding: 0; }
.scene-pick:hover, .icon-btn:hover { background: var(--ch-hover); }
.toast { position: fixed; left: 50%; bottom: calc(7.5rem + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; align-items: center; gap: 14px; max-width: calc(100vw - 24px); padding: 10px 10px 10px 18px; min-height: 48px; background: #161616; color: #fff; border-radius: 14px; box-shadow: 0 14px 34px -16px rgba(0, 0, 0, 0.6); animation: pop-in 0.16s ease-out; }
body.present .toast { bottom: 4.5rem; }
.toast-action { min-height: 36px; padding: 0 12px; border: 0; border-radius: 9px; background: rgba(255, 255, 255, 0.18); color: #fff; font-weight: 600; }
.dlg { border: var(--ch-border); border-radius: calc(var(--ch-radius) + 4px); padding: 24px; width: min(26rem, calc(100vw - 24px)); background: var(--ch-bg); color: var(--ch-ink); box-shadow: var(--ch-shadow), 0 30px 70px -24px rgba(0, 0, 0, 0.6); }
.dlg.wide { width: min(40rem, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(15, 15, 15, 0.5); backdrop-filter: blur(3px); }
.dlg-title { margin: 0 0 14px; font-size: 1.375rem; font-weight: 800; text-wrap: balance; font-family: var(--font-display); }
.dlg-text { margin: 0 0 6px; white-space: pre-line; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.btn { min-height: 44px; padding: 0 16px; border: 1px solid var(--ch-line); border-radius: calc(var(--ch-radius) - 5px); background: var(--field-bg); color: var(--ch-ink); font-weight: 600; }
.btn:hover { background: var(--ch-hover); }
.btn.primary { background: var(--acc); border-color: var(--acc); color: var(--acc-ink); box-shadow: var(--acc-shadow); }
.btn.primary:hover { background: var(--acc-hover); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }

/* ---- 設定抽屜（右側） ---- */
.drawer { position: fixed; top: 12px; right: 12px; bottom: 12px; width: min(400px, calc(100vw - 24px)); display: flex; flex-direction: column; background: var(--ch-bg); color: var(--ch-ink); border: var(--ch-border); border-radius: calc(var(--ch-radius) + 4px); box-shadow: var(--ch-shadow), 0 30px 70px -24px rgba(0, 0, 0, 0.55); backdrop-filter: var(--ch-blur); -webkit-backdrop-filter: var(--ch-blur); animation: drawer-in 0.2s ease-out; z-index: 1; }
@keyframes drawer-in { from { opacity: 0; transform: translateX(24px); } }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 14px 10px 12px 18px; border-bottom: 1px solid var(--ch-line); }
.drawer-head h2 { margin: 0; flex: 1; font-size: 1.125rem; font-weight: 800; font-family: var(--font-display); display: flex; align-items: center; gap: 10px; }
.drawer-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--tool, var(--acc)); flex: none; }
.drawer-body { flex: 1; overflow: auto; padding: 16px 18px 24px; overscroll-behavior: contain; }
.drawer-body .settings-title { display: none; }

/* ---- 設定面板與表單 ---- */
.settings, .bg-panel { display: flex; flex-direction: column; gap: 12px; }
.settings-title { margin: 0; font-size: 1.0625rem; font-weight: 700; }
.f-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; min-height: 44px; }
.f-row.f-col { flex-direction: column; align-items: stretch; }
.f-label { font-size: 0.9375rem; color: var(--ch-sub); font-weight: 500; }
.f-hint { flex-basis: 100%; font-size: 0.8125rem; color: var(--ch-sub); }
.f-input { min-height: 44px; padding: 6px 10px; border: 1px solid var(--ch-line); border-radius: 10px; background: var(--field-bg); color: var(--ch-ink); min-width: 0; flex: 1 1 9rem; max-width: 100%; }
.f-num { flex: 0 0 6.5rem; text-align: end; font-variant-numeric: tabular-nums; }
.f-area { resize: vertical; line-height: 1.5; width: 100%; }
.f-toggle { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.f-toggle input { width: 22px; height: 22px; accent-color: var(--acc); flex: none; }
.f-seg { display: flex; flex-wrap: wrap; gap: 4px; }
.f-seg label { position: relative; display: inline-flex; }
.f-seg input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.f-seg span { min-height: 40px; min-width: 44px; padding: 0 12px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--ch-line); border-radius: 10px; background: var(--field-bg); font-weight: 500; }
.f-seg input:checked + span { background: var(--ch-ink); border-color: var(--ch-ink); color: var(--ch-bg); }
.f-seg input:focus-visible + span { outline: 3px solid var(--acc); outline-offset: 2px; }
.f-range { display: flex; align-items: center; gap: 10px; flex: 1 1 10rem; }
.f-range input { flex: 1; min-width: 5rem; accent-color: var(--acc); }
.f-out { min-width: 3rem; text-align: end; font-variant-numeric: tabular-nums; font-size: 0.9375rem; }
.f-colors { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.f-color { width: 44px; height: 44px; padding: 2px; border: 1px solid var(--ch-line); border-radius: 10px; background: var(--field-bg); }
.f-swatch { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--ch-line); padding: 0; }
.f-note { margin: 0; font-size: 0.875rem; color: var(--ch-sub); }
.f-group { display: flex; flex-direction: column; gap: 8px; padding-top: 10px; border-top: 1px solid var(--ch-line); }
.bg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(3.5rem, 1fr)); gap: 8px; }
.bg-swatch { aspect-ratio: 4 / 3; border: 1px solid var(--ch-line); border-radius: 10px; padding: 0; }
.bg-swatch:hover, .bg-swatch.on { outline: 3px solid var(--acc); outline-offset: 2px; }

/* ---- 名單 ---- */
.roster { display: flex; flex-direction: column; gap: 12px; }
.roster-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.roster-tab { min-height: 40px; padding: 0 14px; border: 1px solid var(--ch-line); border-radius: 999px; background: var(--field-bg); max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster-tab.on { background: var(--ch-ink); border-color: var(--ch-ink); color: var(--ch-bg); }
.roster-tab.add { border-style: dashed; background: none; }
.roster-area { min-height: 12rem; font-size: 1.0625rem; }
.roster-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.roster-count { color: var(--ch-sub); margin-inline-end: auto; }
.roster-fill { display: flex; gap: 6px; align-items: center; }
.help-list { margin: 0; padding-inline-start: 1.25rem; display: grid; gap: 8px; }
.help-links { margin: 12px 0 0; }
.help .f-note { margin-top: 14px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---- 全部工具面板 ---- */
.popover.tools-pop { width: min(52rem, calc(100vw - 20px)); padding: 18px; }
.tools-panel { display: flex; flex-direction: column; gap: 14px; }
.tools-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.tools-head .settings-title { font-size: 1.25rem; font-weight: 800; font-family: var(--font-display); }
.tools-search { flex: 0 1 17rem; }
.tools-body { max-height: min(62vh, 36rem); overflow: auto; display: flex; flex-direction: column; gap: 16px; padding-inline-end: 4px; }
.tools-cat h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 0.8125rem; font-weight: 700; color: var(--ch-sub); text-transform: uppercase; letter-spacing: 0.04em; }
.tools-cat h3::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--tool); }
.tools-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); gap: 8px; }
.tool-cell { position: relative; }
.tool-add { width: 100%; min-height: 5.5rem; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; padding: 10px 8px; border: 1px solid var(--ch-line); border-radius: calc(var(--ch-radius) - 4px); background: var(--field-bg); font-size: 0.875rem; font-weight: 600; line-height: 1.2; text-align: center; overflow-wrap: anywhere; hyphens: auto; }
.tool-add:hover { background: var(--ch-hover); border-color: var(--tool); }
.tool-add .dock-ic { width: 40px; height: 40px; }
.tool-pin { position: absolute; top: 3px; inset-inline-end: 3px; width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 8px; background: none; color: color-mix(in srgb, var(--ch-sub) 60%, transparent); padding: 0; }
.tool-pin:hover { background: var(--ch-hover); }
.tool-pin.on { color: #e0a000; }
.tool-pin.on svg { fill: currentColor; }

/* ---- 主題選擇 ---- */
.theme-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.theme-card { display: flex; flex-direction: column; gap: 8px; padding: 8px; border: 2px solid transparent; border-radius: calc(var(--ch-radius) - 2px); background: none; text-align: start; font-weight: 700; }
.theme-card:hover { background: var(--ch-hover); }
.theme-card.on { border-color: var(--acc); }
.theme-card small { font-weight: 500; color: var(--ch-sub); line-height: 1.35; }
.theme-prev { position: relative; aspect-ratio: 16 / 10; border-radius: 10px; overflow: hidden; }
.theme-prev i { position: absolute; }

/* ---- 第一次打開：歡迎畫面（選主題、選範本） ---- */
.welcome { position: fixed; inset: 0; z-index: 6500; display: grid; place-items: center; padding: 24px; background: rgba(12, 12, 12, 0.45); backdrop-filter: blur(6px); animation: pop-in 0.2s ease-out; }
.welcome-box { width: min(64rem, 100%); max-height: calc(100vh - 48px); overflow: auto; padding: clamp(20px, 3vw, 36px); background: var(--ch-bg); color: var(--ch-ink); border: var(--ch-border); border-radius: calc(var(--ch-radius) + 8px); box-shadow: var(--ch-shadow), 0 40px 80px -30px rgba(0, 0, 0, 0.6); }
.welcome h1 { margin: 0 0 6px; font-size: clamp(1.75rem, 1.2rem + 2vw, 2.75rem); font-weight: 900; letter-spacing: -0.02em; font-family: var(--font-display); }
.welcome h2 { margin: 26px 0 12px; font-size: 1.125rem; font-weight: 800; }
.welcome p.lead { margin: 0; color: var(--ch-sub); font-size: 1.0625rem; max-width: 40em; }
.welcome .theme-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 760px) { .welcome .theme-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.welcome-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 22px; flex-wrap: wrap; }

/* ---- 場景範本 ---- */
.tpl-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.tpl-cats { display: flex; flex-wrap: wrap; gap: 6px; }
.tpl-search { flex: 0 1 14rem; }
.tpl-more .tpl-thumb { display: grid; place-items: center; font-size: 1.5rem; font-weight: 800; color: var(--ch-sub); border: 2px dashed var(--ch-line); background: none; }
.tpl-dialog { width: min(62rem, calc(100vw - 24px)); }
.tpl-cat { min-height: 38px; padding: 0 14px; border: 1px solid var(--ch-line); border-radius: 999px; background: var(--field-bg); font-weight: 600; }
.tpl-cat.on { background: var(--ch-ink); color: var(--ch-bg); border-color: var(--ch-ink); }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(11.5rem, 1fr)); gap: 10px; }
.tpl-card { display: flex; flex-direction: column; gap: 10px; padding: 10px; border: 1px solid var(--ch-line); border-radius: calc(var(--ch-radius) - 2px); background: var(--field-bg); text-align: start; }
.tpl-card:hover { border-color: var(--acc); background: var(--ch-hover); }
.tpl-thumb { position: relative; aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; background: var(--board-bg); }
.tpl-thumb i { position: absolute; border-radius: 3px; background: color-mix(in srgb, var(--tool) 30%, #fff); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15); display: grid; place-items: center; color: color-mix(in srgb, var(--tool) 75%, #000); }
.tpl-card b { font-weight: 700; line-height: 1.25; }
.tpl-card small { color: var(--ch-sub); line-height: 1.35; }
.tpl-blank .tpl-thumb { display: grid; place-items: center; font-size: 2rem; color: var(--ch-sub); border: 2px dashed var(--ch-line); background: none; }

/* ---- 卡片顏色（每個工具都能換）---- */
.w[data-tint="yellow"] { --tool: #e9b10a; }
.w[data-tint="green"] { --tool: #1fa463; }
.w[data-tint="blue"] { --tool: #3d6df2; }
.w[data-tint="pink"] { --tool: #e8559a; }
.w[data-tint="purple"] { --tool: #8b5cf6; }
.w[data-tint="orange"] { --tool: #f07c13; }
body:not([data-theme="blocks"]):not([data-theme="chalk"]) .w[data-tint]:not([data-tint="dark"]):not([data-tint="clear"]) .w-body { --w-bg: color-mix(in srgb, var(--tool) 16%, #fffdf8); --w-bg-2: color-mix(in srgb, var(--tool) 28%, #fffdf8); }
body[data-theme="dark"] .w[data-tint]:not([data-tint="dark"]):not([data-tint="clear"]) .w-body { --w-bg: color-mix(in srgb, var(--tool) 22%, #1a2040); --w-bg-2: color-mix(in srgb, var(--tool) 32%, #1a2040); }
.w[data-tint="dark"] .w-body { --w-bg: #24231f; --w-bg-2: #37352f; --w-bg-3: #45423b; --w-ink: #f4f2ec; --w-sub: #bdb9b0; --w-line: rgba(255, 255, 255, 0.22); --w-acc: #8ea6ff; --w-acc-ink: #10131f; --w-surface: #2e2c27; }
.w[data-tint="clear"] .w-body { background: transparent; border-color: transparent; box-shadow: none; border-top-color: transparent; }
#viewport[data-tone="dark"] .w[data-tint="clear"] .w-body { --w-ink: #f4f2ec; --w-sub: #cfcbc2; --w-line: rgba(255, 255, 255, 0.3); }
.menu-tints { display: flex; flex-direction: column; gap: 6px; padding: 8px 12px; }
.menu-tints > span { font-size: 0.875rem; color: var(--ch-sub); }
.tint-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tint-dot { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--ch-line); padding: 0; }
.tint-dot.on { outline: 3px solid var(--acc); outline-offset: 2px; }
.tint-none { background: var(--w-bg); } .tint-yellow { background: #f6d860; } .tint-green { background: #7fd3a5; } .tint-blue { background: #8fb0fa; } .tint-pink { background: #f2a3c6; } .tint-purple { background: #c2a8fa; } .tint-orange { background: #f8b678; } .tint-dark { background: #24231f; }
.tint-clear { background: repeating-conic-gradient(#ddd 0 25%, #fff 0 50%) 50% / 12px 12px; }

/* ---- 遮住畫面（要全班看老師時用）---- */
body.blanked #viewport { filter: blur(26px) brightness(0.75); pointer-events: none; }
body.blanked::after { content: attr(data-blank); position: fixed; inset: 0; z-index: 5200; display: grid; place-items: center; padding: 2rem; text-align: center; color: #fff; font-size: clamp(1.5rem, 4vw, 3.5rem); font-weight: 700; text-shadow: 0 2px 18px rgba(0, 0, 0, 0.6); pointer-events: none; }

/* 截圖模式 */
body.solo #topbar, body.solo #dock, body.solo .empty-hint { display: none !important; }

/* 設定分區（form.section）：常用的展開、進階的收起 */
.f-sec { border-top: 1px solid var(--ch-line); padding: 4px 0 10px; }
.f-sec:first-child { border-top: 0; padding-top: 0; }
.f-sec-head { list-style: none; display: flex; align-items: center; justify-content: space-between; min-height: 44px; cursor: pointer; font-size: 0.8125rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ch-sub); }
.f-sec-head::-webkit-details-marker { display: none; }
.f-sec-head::after { content: ""; width: 8px; height: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg) translate(-2px, -2px); transition: transform 0.15s; }
.f-sec:not([open]) > .f-sec-head::after { transform: rotate(-45deg); }
.f-sec-head:focus-visible { outline: 3px solid var(--acc); outline-offset: 2px; border-radius: 6px; }
.f-sec-body { display: flex; flex-direction: column; gap: 10px; }
.f-sec-note { margin-bottom: 8px; }
