:root {
  --bg: #f3f6f5;
  --surface: #ffffff;
  --text: #22323a;
  --muted: #5b6d72;
  --border: #d9e3e0;
  --accent: #196558;
  --accent-soft: #e3efeb;
  --pos: #d1453b;
  --neg: #2f6fd0;
  --field: #2d3d44;
  --equi: #8a5a00;
  --grid: rgba(34, 50, 58, 0.07);
  --probe: #0d7f57; /* 11/11 由 #0f8a5f 調深：當文字色時對比要 ≥ 4.5（WCAG AA） */
  --canvas-bg: #fbfcfc;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1517;
    --surface: #172024;
    --text: #e3ecec;
    --muted: #98a9ab;
    --border: #2a383c;
    --accent: #5cc2a8;
    --accent-soft: #1d3330;
    --pos: #ff6f61;
    --neg: #6aa2ff;
    --field: #c9d6d8;
    --equi: #e7b75a;
    --grid: rgba(227, 236, 236, 0.07);
    --probe: #3fd69a;
    --canvas-bg: #121a1d;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1517;
  --surface: #172024;
  --text: #e3ecec;
  --muted: #98a9ab;
  --border: #2a383c;
  --accent: #5cc2a8;
  --accent-soft: #1d3330;
  --pos: #ff6f61;
  --neg: #6aa2ff;
  --field: #c9d6d8;
  --equi: #e7b75a;
  --grid: rgba(227, 236, 236, 0.07);
  --probe: #3fd69a;
  --canvas-bg: #121a1d;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft JhengHei", "PingFang TC", sans-serif;
  line-height: 1.65;
  font-size: calc(16px * var(--fs, 1));
}
a { color: var(--accent); text-underline-offset: 3px; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 20px 16px 48px; }

.top { margin-bottom: 18px; }
.top .back { font-size: calc(14px * var(--fs, 1)); }
.top h1 { font-size: calc(clamp(24px, 4vw, 34px) * var(--fs, 1)); margin: 6px 0 4px; line-height: 1.25; }
.top p { margin: 0; color: var(--muted); }
.eyebrow { color: var(--accent); font-weight: 650; letter-spacing: .08em; font-size: calc(14px * var(--fs, 1)); margin: 0; }

/* ---------- 實驗台 ---------- */
.lab { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
@media (max-width: 880px) { .lab { grid-template-columns: minmax(0, 1fr); } }

.stage {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
}
.stage canvas {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  border-radius: 8px;
  touch-action: none;
  cursor: crosshair;
  background: var(--canvas-bg);
}
.stage .hint { font-size: calc(13px * var(--fs, 1)); color: var(--muted); margin: 8px 4px 0; }

.panel { display: grid; gap: 12px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
}
.card h2 { font-size: calc(15px * var(--fs, 1)); margin: 0 0 8px; }

.slider { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; margin: 8px 0 10px; font-size: calc(14px * var(--fs, 1)); }
.slider output { font-variant-numeric: tabular-nums; font-weight: 600; }
.slider input { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); }
/* 按鈕列或勾選框正下方的滑桿：多留空間，數字欄的觸控範圍（往上 17 px）才不會被按鈕擋住 */
:is(.seg, .seg2, .seg3, .presets, .btns, .chips, .quick, .toggle, .checks, .movebox, button) + .slider,
:is(.seg, .seg2, .seg3, .presets, .btns, .chips, .quick, .toggle, .checks, .movebox, button) + div > .slider:first-child { margin-top: 18px; }

.checks { display: flex; flex-wrap: wrap; gap: 0 14px; font-size: calc(14px * var(--fs, 1)); }
.checks label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.checks input { accent-color: var(--accent); }

.btns { display: flex; flex-wrap: wrap; gap: 8px; }
button {
  font: inherit;
  font-size: calc(14px * var(--fs, 1));
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
/* 觸控目標至少 44 px（站長規定）：按鈕、勾選框與選項的整列都算 */
button { min-height: 44px; }
label:has(> input[type="checkbox"]), label:has(> input[type="radio"]) { min-height: 44px; }
/* 按鈕與勾選框疊在數字欄（.lab-num）放大的隱形觸控範圍上面：按在按鈕邊緣不會誤開數字輸入 */
button, label:has(> input[type="checkbox"]), label:has(> input[type="radio"]) { position: relative; z-index: 1; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--surface); font-weight: 600; }

dl.readout { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; font-size: calc(14px * var(--fs, 1)); }
dl.readout dt { color: var(--muted); }
dl.readout dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.status { font-size: calc(13px * var(--fs, 1)); color: var(--muted); margin: 8px 0 0; min-height: 1.4em; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: calc(13px * var(--fs, 1)); color: var(--muted); margin: 8px 4px 0; }
.legend i { display: inline-block; width: 18px; height: 3px; vertical-align: middle; margin-right: 6px; border-radius: 2px; }

/* ---------- 說明 ---------- */
.notes {
  margin-top: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px clamp(16px, 3vw, 28px);
}
.notes h2 { font-size: calc(18px * var(--fs, 1)); margin: 0 0 8px; }
.notes h3 { font-size: calc(16px * var(--fs, 1)); margin: 18px 0 4px; }
.formula {
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 6px 14px;
  overflow-x: auto;
}
.notes ul { padding-left: 1.3em; }

/* ---------- 首頁：物理分支分類 ---------- */
:root {
  --b-mech: #c2410c; --b-thermo: #b91c1c; --b-wave: #0e7490;
  --b-optics: #7c3aed; --b-em: #1d4ed8; --b-modern: #0f766e;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --b-mech: #fb923c; --b-thermo: #f87171; --b-wave: #22d3ee;
    --b-optics: #a78bfa; --b-em: #60a5fa; --b-modern: #2dd4bf;
  }
}
:root[data-theme="dark"] {
  --b-mech: #fb923c; --b-thermo: #f87171; --b-wave: #22d3ee;
  --b-optics: #a78bfa; --b-em: #60a5fa; --b-modern: #2dd4bf;
}
html { scroll-behavior: smooth; }

.branch-nav {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(calc(104px * var(--fs, 1)), 1fr));
  gap: 10px;
  margin: 22px 0 8px;
}
html[lang="en"] .branch-nav { grid-template-columns: repeat(auto-fill, minmax(calc(130px * var(--fs, 1)), 1fr)); }
html[lang="en"] .branch-nav a { font-size: calc(16px * var(--fs, 1)); }
.branch-nav a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 58px;
  padding: 8px 6px;
  text-align: center;
  text-decoration: none;
  color: var(--c);
  font-size: calc(18px * var(--fs, 1));
  font-weight: 700;
  line-height: 1.3;
  background: var(--surface);
  border: 2px solid var(--c);
  border-radius: 12px;
  -webkit-tap-highlight-color: transparent;
  overflow-wrap: anywhere;
}
.branch-nav a:hover,
.branch-nav a:focus-visible { background: var(--c); color: var(--surface); outline: none; }
.branch-nav a:active { transform: scale(.97); }
@media (min-width: 880px) { html:not([lang="en"]) .branch-nav, html[lang="en"] .branch-nav { grid-template-columns: repeat(6, 1fr); } }

/* ---------- 首頁：兩大科目（物理／地球科學，11/12 站長要求） ---------- */
:root {
  --d-phys: #3730a3; --d-earth: #15803d;
  --b-astro: #4338ca; --b-geo: #92400e; --b-atmo: #0369a1; --b-ocean: #1e3a8a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --d-phys: #a5b4fc; --d-earth: #4ade80;
    --b-astro: #a5b4fc; --b-geo: #fbbf24; --b-atmo: #7dd3fc; --b-ocean: #93c5fd;
  }
}
:root[data-theme="dark"] {
  --d-phys: #a5b4fc; --d-earth: #4ade80;
  --b-astro: #a5b4fc; --b-geo: #fbbf24; --b-atmo: #7dd3fc; --b-ocean: #93c5fd;
}
.domain-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 22px 0 4px; }
@media (max-width: 560px) { .domain-nav { grid-template-columns: 1fr; } }
.domain-tab {
  position: relative; overflow: hidden;
  display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 14px; row-gap: 2px;
  min-height: 88px; padding: 14px 16px;
  color: inherit; text-decoration: none;
  background: var(--surface); border: 2px solid var(--c); border-radius: 16px;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow .2s ease, transform .2s ease;
}
.domain-tab::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(130% 160% at 0% 0%, var(--c), transparent 62%); opacity: .10;
}
.domain-tab svg { grid-row: span 2; width: 52px; height: 52px; color: var(--c); }
.domain-name { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; font-size: calc(23px * var(--fs, 1)); font-weight: 800; color: var(--c); line-height: 1.2; }
.domain-count { font-size: calc(13px * var(--fs, 1)); font-weight: 700; color: var(--muted); }
.domain-sub { font-size: calc(13.5px * var(--fs, 1)); color: var(--muted); line-height: 1.45; }
.domain-tab:hover { box-shadow: 0 6px 18px rgba(0, 0, 0, .10); transform: translateY(-1px); }
.domain-tab:focus-visible { outline: 3px solid var(--c); outline-offset: 2px; }
.domain-tab:active { transform: scale(.985); }
@media (prefers-reduced-motion: reduce) { .domain-tab { transition: none; } .domain-tab:hover, .domain-tab:active { transform: none; } }
.domain { margin-top: 34px; scroll-margin-top: 12px; }
.domain-head { display: flex; align-items: center; gap: 12px; padding: 0 0 10px; border-bottom: 2px solid var(--c); }
.domain-head svg { flex: none; width: 40px; height: 40px; color: var(--c); }
.domain-head h2 { margin: 0; font-size: calc(28px * var(--fs, 1)); color: var(--c); letter-spacing: .03em; }
.domain-head p { margin: 2px 0 0; color: var(--muted); font-size: calc(14px * var(--fs, 1)); }
@media (min-width: 880px) { html:not([lang="en"]) .branch-nav.four, html[lang="en"] .branch-nav.four { grid-template-columns: repeat(4, 1fr); } }
/* 首頁 QR code（classroom.js：點一下放大） */
.site-qr {
  display: flex; align-items: center; gap: 12px; min-height: 88px; padding: 8px 14px 8px 8px;
  color: inherit; text-decoration: none; background: var(--surface);
  border: 2px dashed var(--border); border-radius: 16px; -webkit-tap-highlight-color: transparent;
}
.site-qr img { flex: none; width: 76px; height: 76px; border-radius: 6px; background: #fff; image-rendering: pixelated; }
.site-qr-text { display: grid; gap: 2px; font-size: calc(13px * var(--fs, 1)); color: var(--muted); line-height: 1.35; }
.site-qr-text strong { font-size: calc(16px * var(--fs, 1)); color: var(--text); }
.site-qr:hover, .site-qr:focus-visible { border-color: var(--accent); outline: none; }
@media (min-width: 561px) and (max-width: 899px) { .site-qr { grid-column: 1 / -1; } }
@media (min-width: 900px) { .domain-nav { grid-template-columns: 1fr 1fr auto; } }

/* 還沒有實驗的分支：一行說明（加入第一個實驗時 integrate 會移除） */
.branch-soon { margin: 12px 0 0; padding: 14px 16px; color: var(--muted); border: 1px dashed var(--border); border-radius: 12px; font-size: calc(14px * var(--fs, 1)); }

.branch { margin-top: 30px; scroll-margin-top: 16px; }
.branch-head { border-left: 5px solid var(--c); padding-left: 12px; }
.branch-head h2 { font-size: calc(22px * var(--fs, 1)); margin: 0; color: var(--c); }
.branch-head p { margin: 2px 0 0; color: var(--muted); font-size: calc(14px * var(--fs, 1)); }

.modules { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; margin-top: 12px; }
.module {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  color: inherit;
  text-decoration: none;
}
.module.live { border-top: 3px solid var(--c); overflow: hidden; }
/* 卡片縮圖（js/thumbs.js 依語言與深淺色挑圖；圖由 tools/make-thumbs.cjs 產生） */
.module-thumb {
  display: block; width: calc(100% + 32px); max-width: none; height: auto; aspect-ratio: 16 / 9;
  margin: -14px -16px 12px; object-fit: cover;
  background: var(--canvas-bg, var(--bg)); border-bottom: 1px solid var(--border);
  transition: transform .25s ease-out;
}
.module-thumb[hidden] { display: none; }
a.module:hover .module-thumb { transform: scale(1.03); }
@media (prefers-reduced-motion: reduce) { .module-thumb { transition: none; } a.module:hover .module-thumb { transform: none; } }
a.module:hover { border-color: var(--c); box-shadow: 0 2px 10px rgba(0, 0, 0, .06); }
.module h3, .module h4 { font-size: calc(17px * var(--fs, 1)); margin: 6px 0 4px; }

/* ---------- 首頁小分類：選修物理各章（只寫章名） ---------- */
.chapter-nav { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 2px; }
.chapter-nav a, .chapter-nav .soon {
  display: inline-flex; align-items: center; gap: 7px; min-height: 44px; padding: 4px 14px;
  border-radius: 99px; font-size: calc(14px * var(--fs, 1)); font-weight: 600; line-height: 1.25;
  text-decoration: none; transition: background-color .15s ease-out, color .15s ease-out;
}
.chapter-nav a {
  color: var(--c);
  background: color-mix(in srgb, var(--c) 9%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--c) 38%, var(--border));
}
.chapter-nav a:hover, .chapter-nav a:focus-visible { background: var(--c); color: var(--surface); outline: none; }
.chapter-nav .n {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 99px;
  font-size: calc(12px * var(--fs, 1)); font-variant-numeric: tabular-nums; background: var(--c); color: var(--surface);
}
.chapter-nav a:hover .n, .chapter-nav a:focus-visible .n { background: var(--surface); color: var(--c); }
.chapter-nav .soon { color: var(--muted); border: 1px dashed var(--border); font-weight: 500; cursor: default; }
/* 章並排：每章的寬度依實驗數 --n 分配（卡片寬度一致），實驗少的章自動排在同一列；手機一章一列 */
.chapters { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 0 16px; }
.chapter {
  --n: 1;
  flex: var(--n) 1 calc(var(--n) * 250px + (var(--n) - 1) * 12px);
  max-width: calc(var(--n) * 340px + (var(--n) - 1) * 12px);
  min-width: 0;
  margin-top: 20px; scroll-margin-top: 14px;
}
.chapter.solo { margin-top: 12px; max-width: none; }
@media (max-width: 640px) { .chapter { flex-basis: 100%; max-width: none; } }
.chapter-head { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; font-size: calc(17px * var(--fs, 1)); color: var(--text); }
.chapter-head::before { content: ""; flex: none; width: 9px; height: 9px; border-radius: 2px; background: var(--c); transform: rotate(45deg); }
.chapter-head::after { content: ""; flex: 1; min-width: 12px; height: 1px; background: linear-gradient(90deg, color-mix(in srgb, var(--c) 50%, transparent), transparent); }
.chapter .modules { margin-top: 0; }
@media (prefers-reduced-motion: reduce) { .chapter-nav a { transition: none; } }
.module p { margin: 0; color: var(--muted); font-size: calc(14px * var(--fs, 1)); }
.module.soon { opacity: .72; }
.module-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.topic { font-size: calc(12px * var(--fs, 1)); font-weight: 600; color: var(--c); }
.tag { display: inline-block; font-size: calc(12px * var(--fs, 1)); font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--c); color: var(--surface); white-space: nowrap; }
.tag.soon { background: transparent; border: 1px solid var(--border); color: var(--muted); }
footer.site { margin-top: 32px; font-size: calc(13px * var(--fs, 1)); color: var(--muted); border-top: 1px solid var(--border); padding-top: 16px; }

/* ---------- 公式（KaTeX） ---------- */
.formula .katex-display { margin: 6px 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.formula .katex { font-size: 1.12em; }
dl.readout sup { font-size: .72em; line-height: 0; }
.crumbs { font-size: calc(14px * var(--fs, 1)); color: var(--muted); }
/* 導覽連結字小：用內距放大到 44 px 觸控範圍，負邊距抵銷，版面不變 */
.crumbs a { display: inline-block; position: relative; padding: 13px 8px; margin: -13px -8px; } /* relative：放大的範圍才會蓋在分隔符號上 */
.nb { white-space: nowrap; }

/* ---------- 統計（stats.js） ---------- */
.stats-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 22px;
  margin: 0 0 14px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: calc(14px * var(--fs, 1));
}
.stats-bar .stat { display: inline-flex; align-items: baseline; gap: 8px; }
.stats-bar .stat-label { color: var(--muted); }
.stats-bar .stat-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.stats-bar .stats-title { font-weight: 700; color: var(--accent); }
.stats-bar .stat[hidden] { display: none; }
.stats-bar .online-dot {
  display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; vertical-align: .05em;
  background: var(--probe); box-shadow: 0 0 0 0 color-mix(in srgb, var(--probe) 55%, transparent);
  animation: online-pulse 2.4s ease-out infinite;
}
@keyframes online-pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--probe) 55%, transparent); } 70%, 100% { box-shadow: 0 0 0 7px transparent; } }
@media (prefers-reduced-motion: reduce) { .stats-bar .online-dot { animation: none; } }
.stats-total { margin-top: 18px; }
.module-stats { margin: 8px 0 0 !important; font-size: calc(12px * var(--fs, 1)) !important; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- 首頁搜尋（search.js） ---------- */
.search { margin: 18px 0 4px; }
.search-label { display: block; font-weight: 700; font-size: calc(15px * var(--fs, 1)); margin: 0 0 6px; }
.search-box { position: relative; }
.search-icon { position: absolute; left: 14px; top: 50%; width: 22px; height: 22px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input {
  width: 100%;
  font: inherit;
  font-size: calc(17px * var(--fs, 1));
  padding: 14px 16px 14px 46px;
  min-height: 54px;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  -webkit-appearance: none;
  appearance: none;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: none; border-color: var(--accent); }
.search-status { margin: 8px 2px 0; font-size: calc(14px * var(--fs, 1)); color: var(--muted); }
.search-suggest {
  margin: 4px 0 0 6px;
  padding: 4px 12px;
  font-size: calc(14px * var(--fs, 1));
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent);
}
.search-results { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.search-item {
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  min-height: 56px;
  color: inherit;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 5px solid var(--c, var(--accent));
  border-radius: 10px;
}
a.search-item:hover, a.search-item:focus-visible { border-color: var(--c, var(--accent)); outline: none; box-shadow: 0 2px 10px rgba(0, 0, 0, .08); }
.search-item.soon { opacity: .7; }
.search-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.search-meta { font-size: calc(12px * var(--fs, 1)); font-weight: 600; color: var(--c, var(--accent)); }
.search-title { font-size: calc(17px * var(--fs, 1)); font-weight: 700; }
.search-title mark { background: var(--accent-soft); background: color-mix(in srgb, var(--c, var(--accent)) 24%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.search-why { font-size: calc(13px * var(--fs, 1)); color: var(--muted); }
a.search-item .search-title::after { content: " →"; color: var(--c, var(--accent)); }

/* ---------- 齒輪設定（settings.js） ---------- */
html.lab-converting body { visibility: hidden; }
.wrap { position: relative; }
.top > :first-child { padding-right: 58px; }
.has-account .top > :first-child { padding-right: var(--head-reserve, 150px); }
/* 窄螢幕：頁首第一行至少和右上角按鈕一樣高，下一行的標題才會排在按鈕下方 */
@media (max-width: 900px) { .top > :first-child { min-height: 40px; } }
.lab-gear {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 46px;
  height: 46px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  z-index: 20;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .08);
}
.lab-gear svg { width: 24px; height: 24px; transition: transform .3s; }
.lab-gear:hover svg, .lab-gear[aria-expanded="true"] svg { transform: rotate(60deg); }
.lab-gear[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }
.lab-settings {
  position: absolute;
  top: 68px;
  right: 16px;
  z-index: 21;
  width: min(360px, calc(100% - 32px));
  padding: 14px 16px 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .18);
}
.lab-set-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; font-size: calc(17px * var(--fs, 1)); }
.lab-set-close { border: none; background: transparent; font-size: 18px; padding: 4px 8px; color: var(--muted); }
.lab-set-group { border: none; margin: 10px 0 0; padding: 0; }
.lab-set-group legend { font-size: calc(14px * var(--fs, 1)); font-weight: 700; color: var(--muted); padding: 0; margin-bottom: 6px; }
.lab-seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.lab-seg button {
  min-height: 44px;
  padding: 6px 4px;
  font-size: calc(15px * var(--fs, 1));
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.lab-seg button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--surface); font-weight: 700; }
.lab-set-preview { margin: 8px 0 0; padding: 6px 10px; border-radius: 8px; background: var(--accent-soft); font-size: calc(16px * var(--fs, 1)); }
.lab-set-reset { margin-top: 14px; width: 100%; min-height: 44px; color: var(--muted); }
.lab-en-note {
  margin: 0 0 14px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  font-size: calc(14px * var(--fs, 1));
}

/* ---------- 登入與留言（comments.js） ---------- */
.lab-account {
  position: absolute;
  top: 14px;
  right: 70px;
  z-index: 20;
  height: 46px;
  max-width: 180px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px 0 10px;
  border-radius: 23px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .08);
}
.lab-account svg { width: 18px; height: 18px; flex: none; }
.lab-account-avatar {
  flex: none;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent); color: var(--surface);
  font-size: calc(14px * var(--fs, 1));
}
.lab-account-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 7em; }
@media (max-width: 480px) { .lab-account-name { display: none; } .lab-account:has(.lab-account-avatar) { padding: 0 8px; } }
.lab-account-menu {
  position: absolute; top: 68px; right: 70px; z-index: 21;
  min-width: 200px; padding: 10px;
  display: grid; gap: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .18);
}
.lab-account-menu p { margin: 2px 4px 4px; font-size: calc(14px * var(--fs, 1)); color: var(--muted); }
.lab-account-menu .lab-account-admin { color: var(--accent); font-weight: 700; }
.lab-account-menu button { text-align: left; min-height: 44px; }

.comments {
  margin-top: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px clamp(16px, 3vw, 28px);
}
.comments h2 { font-size: calc(18px * var(--fs, 1)); margin: 0 0 4px; }
.c-count { color: var(--muted); font-weight: 600; }
.c-note { margin: 0 0 12px; font-size: calc(13px * var(--fs, 1)); color: var(--muted); }
.c-hint { margin: 0 0 10px; }
.c-google { display: inline-flex; align-items: center; gap: 10px; min-height: 46px; padding: 8px 16px; font-weight: 600; }
.c-google svg { width: 18px; height: 18px; }
.c-nick label { display: block; margin-bottom: 8px; font-size: calc(14px * var(--fs, 1)); }
.c-nick input, .c-form textarea {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.c-nick input { flex: 1; min-width: 0; min-height: 44px; }
.c-form textarea { resize: vertical; min-height: 90px; line-height: 1.6; }
.c-nick input:focus, .c-form textarea:focus { outline: none; border-color: var(--accent); }
.c-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.c-row-end { justify-content: flex-end; }
.c-row button { min-height: 44px; }
.c-who { margin: 0 0 8px; font-size: calc(14px * var(--fs, 1)); }
.c-counter { font-size: calc(13px * var(--fs, 1)); color: var(--muted); font-variant-numeric: tabular-nums; margin-right: auto; }
.c-link { border: none; background: none; padding: 2px 4px; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; font-size: calc(13px * var(--fs, 1)); }
.c-msg { margin: 8px 0 0; color: var(--pos); font-size: calc(14px * var(--fs, 1)); min-height: 0; }
.c-msg:empty { display: none; }
.c-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 10px; }
.c-item { padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); }
.c-item.mine { border-color: var(--accent); }
.c-item.flagged { border-style: dashed; }
.c-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.c-name { font-size: calc(15px * var(--fs, 1)); }
.c-time { font-size: calc(12px * var(--fs, 1)); color: var(--muted); }
.c-flag { font-size: calc(12px * var(--fs, 1)); color: var(--pos); font-weight: 700; }
.c-text { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.c-hidden { margin: 6px 0 0; color: var(--muted); font-style: italic; font-size: calc(14px * var(--fs, 1)); }
.c-acts { display: flex; gap: 10px; align-items: center; margin-top: 6px; }
.c-done { font-size: calc(12px * var(--fs, 1)); color: var(--muted); }
.c-empty { color: var(--muted); }
.lab-account[hidden], .lab-account-menu[hidden], .lab-settings[hidden] { display: none; }

/* ---------- 點擊數字直接輸入（numinput.js） ---------- */
.lab-num {
  position: relative;
  cursor: text;
  border-bottom: 1px dashed var(--muted);
  border-radius: 2px;
  padding: 0 2px;
  -webkit-tap-highlight-color: transparent;
}
/* 看不見的放大觸控範圍（約 44 px 高）：往上多、往下少，不搶下方滑桿的拖曳 */
.lab-num::after { content: ""; position: absolute; left: 50%; width: max(calc(100% + 20px), 44px); transform: translateX(-50%); top: -17px; bottom: -8px; }
.lab-num:hover, .lab-num:focus-visible { border-bottom-color: var(--accent); color: var(--accent); outline: none; background: var(--accent-soft); }
.lab-num-edit { display: inline-flex; align-items: center; gap: 4px; justify-self: end; }
.lab-num-edit input {
  width: 6.5em;
  min-height: 44px;
  padding: 2px 8px;
  font: inherit;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--accent);
  border-radius: 8px;
}
.lab-num-edit input:focus { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.lab-num-pm { min-width: 44px; min-height: 44px; padding: 0 6px; font-weight: 700; }
.lab-num-hint {
  position: absolute;
  z-index: 50;
  max-width: 220px;
  padding: 6px 10px;
  font-size: calc(13px * var(--fs, 1));
  color: var(--surface);
  background: var(--text);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .2);
  pointer-events: none;
}
.lab-num-hint[hidden] { display: none; }

/* ---------- 任務模式與倪的星星（missions.js、leaderboard.js） ---------- */
:root { --star: #e0a100; --star-soft: #fff4d1; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --star: #ffc93c; --star-soft: #3a3018; } }
:root[data-theme="dark"] { --star: #ffc93c; --star-soft: #3a3018; }

.ms-wrap { margin: 0 0 14px; }
.ms-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.ms-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 46px; padding: 6px 16px 6px 12px;
  font-weight: 700; font-size: calc(16px * var(--fs, 1));
  border: 2px solid var(--star); border-radius: 23px;
  background: var(--surface); color: var(--text);
}
.ms-toggle svg { width: 22px; height: 22px; fill: var(--star); filter: drop-shadow(0 1px 1px rgba(0,0,0,.25)); }
.ms-toggle.on { background: var(--star); color: #2b2100; }
.ms-toggle.on svg { fill: #fff8e1; }
.ms-summary { font-size: calc(14px * var(--fs, 1)); color: var(--muted); font-variant-numeric: tabular-nums; }
.ms-board-link { margin-left: auto; font-size: calc(14px * var(--fs, 1)); font-weight: 600; }
.ms-panel {
  margin-top: 10px; padding: 14px 16px;
  background: linear-gradient(180deg, var(--star-soft), var(--surface) 70%);
  border: 1px solid var(--border); border-left: 4px solid var(--star); border-radius: 14px;
}
.ms-note { margin: 0 0 10px; font-size: calc(14px * var(--fs, 1)); color: var(--muted); }
.ms-msg { margin: 0 0 10px; color: var(--pos); font-size: calc(14px * var(--fs, 1)); }
.ms-signin { min-height: 44px; }
.ms-nick { display: grid; gap: 8px; margin-bottom: 10px; }
.ms-nick label { font-size: calc(14px * var(--fs, 1)); }
.ms-nick input { font: inherit; min-height: 44px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); }
.ms-nick button { justify-self: start; min-height: 44px; }
.ms-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ms-item { padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.ms-item.done { border-color: var(--star); box-shadow: inset 0 0 0 1px var(--star); }
.ms-item.hidden-m { background: repeating-linear-gradient(135deg, var(--surface) 0 10px, var(--bg) 10px 20px); }
.ms-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.ms-title { font-size: calc(15px * var(--fs, 1)); }
.ms-desc { margin: 4px 0 0; font-size: calc(14px * var(--fs, 1)); color: var(--muted); }
.hidden-m .ms-desc { font-style: italic; color: var(--text); }
.ms-check { margin-left: auto; font-size: calc(13px * var(--fs, 1)); font-weight: 700; color: var(--star); }
.ms-stars, .lb-stars {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 1px 8px 1px 5px; border-radius: 99px;
  font-weight: 800; font-size: calc(13px * var(--fs, 1)); font-variant-numeric: tabular-nums;
  background: var(--star-soft); color: var(--text); border: 1px solid var(--star);
}
.ms-stars svg, .lb-stars svg { width: 15px; height: 15px; fill: var(--star); }

.ms-celebrate { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: transparent; animation: ms-fade .25s ease-out; pointer-events: none; } /* 不擋住操作：有時間限制的任務要能立刻繼續 */
.ms-celebrate.out { opacity: 0; transition: opacity .3s; }
.ms-celebrate-box {
  position: relative; min-width: min(320px, 86vw); padding: 26px 24px 22px; text-align: center;
  background: radial-gradient(circle at 50% 0%, var(--star-soft), var(--surface) 70%);
  border: 2px solid var(--star); border-radius: 20px; box-shadow: 0 18px 50px rgba(0,0,0,.35);
  animation: ms-pop .45s cubic-bezier(.2, 1.4, .4, 1);
}
.ms-celebrate-title { font-size: calc(24px * var(--fs, 1)); font-weight: 800; }
.ms-celebrate-name { margin-top: 4px; color: var(--muted); }
.ms-celebrate-gain { display: inline-flex; align-items: center; gap: 6px; margin-top: 12px; padding: 6px 16px; border-radius: 99px; background: var(--star); color: #2b2100; font-weight: 800; font-size: calc(18px * var(--fs, 1)); }
.ms-celebrate-gain svg { width: 22px; height: 22px; fill: #fff8e1; }
.ms-burst { position: absolute; left: 50%; top: 50%; width: 0; height: 0; pointer-events: none; }
.ms-spark { position: absolute; width: 22px; height: 22px; margin: -11px; animation: ms-spark .9s ease-out forwards; transform: rotate(var(--a)) translateY(0); }
.ms-spark svg { width: 100%; height: 100%; fill: var(--star); }
@keyframes ms-fade { from { opacity: 0; } }
@keyframes ms-pop { from { transform: scale(.6); opacity: 0; } }
@keyframes ms-spark { to { transform: rotate(var(--a)) translateY(-150px) scale(.4); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .ms-celebrate, .ms-celebrate-box, .ms-spark { animation: none; } .ms-spark { display: none; } }

/* 排行榜頁 */
.lb-title { display: flex; align-items: center; gap: 10px; }
.lb-star { width: 1.1em; height: 1.1em; flex: none; background: var(--star); clip-path: polygon(50% 2%, 62% 36%, 98% 38%, 69% 59%, 80% 95%, 50% 74%, 20% 95%, 31% 59%, 2% 38%, 38% 36%); filter: drop-shadow(0 2px 2px rgba(0,0,0,.25)); }
.lb-me, .lb-board, .lb-progress, .lb-admin { margin-top: 16px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.lb-me { border-left: 4px solid var(--star); }
.lb-board h2, .lb-progress h2, .lb-admin h2 { font-size: calc(18px * var(--fs, 1)); margin: 0 0 10px; }
.lb-note { margin: 0 0 10px; color: var(--muted); font-size: calc(14px * var(--fs, 1)); }
.lb-card { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.lb-big .lb-stars { font-size: calc(26px * var(--fs, 1)); padding: 4px 16px 4px 10px; }
.lb-big .lb-stars svg { width: 30px; height: 30px; }
.lb-myname { font-weight: 800; font-size: calc(18px * var(--fs, 1)); }
.lb-myrank { color: var(--muted); }
.lb-pub { margin: 14px 0 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; display: grid; gap: 6px; }
.lb-pub legend { font-weight: 700; font-size: calc(14px * var(--fs, 1)); padding: 0 4px; }
.lb-pub label { display: flex; gap: 8px; align-items: center; min-height: 44px; cursor: pointer; }
.lb-pub input { accent-color: var(--accent); width: 18px; height: 18px; }
.lb-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.lb-row { display: grid; grid-template-columns: 3em 1fr auto; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 10px; background: var(--bg); border: 1px solid transparent; }
.lb-row.me { border-color: var(--accent); background: var(--accent-soft); }
.lb-rank { font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; }
.lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row.podium .lb-rank { display: grid; place-items: center; width: 2em; height: 2em; border-radius: 50%; color: #2b2100; justify-self: center; }
.lb-row.p1 .lb-rank { background: radial-gradient(circle at 35% 30%, #fff3b0, #e0a100); }
.lb-row.p2 .lb-rank { background: radial-gradient(circle at 35% 30%, #ffffff, #a9b4bd); }
.lb-row.p3 .lb-rank { background: radial-gradient(circle at 35% 30%, #ffe0c2, #c7783c); }
.lb-empty { color: var(--muted); }
.lb-prog { display: grid; grid-template-columns: minmax(6em, 10em) 1fr; gap: 4px 12px; align-items: center; padding: 8px 0; color: inherit; text-decoration: none; border-top: 1px solid var(--border); }
.lb-prog:first-child { border-top: none; }
.lb-prog-name { font-weight: 700; }
.lb-prog-bar { height: 10px; border-radius: 99px; background: var(--bg); border: 1px solid var(--border); overflow: hidden; }
.lb-prog-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--star), #ffd75e); }
.lb-prog-num { grid-column: 2; font-size: calc(13px * var(--fs, 1)); color: var(--muted); font-variant-numeric: tabular-nums; }
.lb-prog-total {
  grid-template-columns: 1fr; gap: 8px; margin: 0 -8px 6px; padding: 12px 12px 12px; border: 1px solid var(--star); border-radius: 12px;
  background: radial-gradient(circle at 0% 0%, var(--star-soft), var(--surface) 75%);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--star) 18%, transparent);
}
.lb-prog-total + .lb-prog { border-top: none; }
.lb-prog-total-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.lb-prog-total .lb-prog-name { font-size: calc(16px * var(--fs, 1)); }
.lb-prog-total-stars { display: inline-flex; align-items: baseline; gap: 4px; font-variant-numeric: tabular-nums; }
.lb-prog-total-stars .lb-stars { font-size: calc(18px * var(--fs, 1)); }
.lb-prog-total-stars .lb-stars svg { width: 20px; height: 20px; }
.lb-prog-total-of { color: var(--muted); font-weight: 700; }
.lb-prog-total .lb-prog-bar { height: 16px; box-shadow: inset 0 1px 3px rgba(0, 0, 0, .12); }
.lb-prog-total .lb-prog-fill { background: linear-gradient(90deg, #f0b400, var(--star) 45%, #ffe27a); box-shadow: 0 0 10px color-mix(in srgb, var(--star) 60%, transparent); }
.lb-prog-total .lb-prog-num { grid-column: 1; }
.lb-admin { border-style: dashed; }
.lb-admin-msg { margin: 8px 0 0; color: var(--muted); font-size: calc(14px * var(--fs, 1)); }
.lb-banner {
  display: flex; align-items: center; gap: 12px; margin: 14px 0 0; padding: 12px 16px; min-height: 56px;
  color: var(--text); text-decoration: none; font-weight: 700;
  background: linear-gradient(90deg, var(--star-soft), var(--surface)); border: 2px solid var(--star); border-radius: 14px;
}
.lb-banner .lb-star { width: 28px; height: 28px; }
.lb-banner small { display: block; font-weight: 400; color: var(--muted); }
.ms-details > summary { cursor: pointer; font-weight: 700; min-height: 44px; display: flex; align-items: center; gap: 6px; list-style: none; }
.ms-details > summary::-webkit-details-marker { display: none; }
.ms-details > summary::before { content: "▸"; color: var(--star); transition: transform .2s; }
.ms-details[open] > summary::before { transform: rotate(90deg); }
.ms-details[open] > summary { margin-bottom: 8px; }

/* ---------- 規則說明與成就（missions.js、achievements.js） ---------- */
.ms-rules { margin: 0 0 10px; padding: 8px 12px; border: 1px dashed var(--star); border-radius: 10px; background: var(--surface); font-size: calc(14px * var(--fs, 1)); }
.ms-rules > summary { cursor: pointer; font-weight: 700; min-height: 44px; display: flex; align-items: center; }
.ms-rules ul { margin: 6px 0; padding-left: 1.3em; }
.ms-rules li { margin: 3px 0; }
.lb-rules, .lb-ach { margin-top: 16px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; scroll-margin-top: 16px; }
.lb-rules h2, .lb-ach h2 { font-size: calc(18px * var(--fs, 1)); margin: 0 0 8px; }
.lb-rules h3 { font-size: calc(15px * var(--fs, 1)); margin: 14px 0 4px; color: var(--accent); }
.lb-rules ul { margin: 0; padding-left: 1.3em; }
.lb-rules li { margin: 4px 0; }
.ac-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 8px; }
.ac-card { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg); opacity: .6; filter: grayscale(1); }
.ac-card.on { opacity: 1; filter: none; background: var(--surface); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.ac-card.secret:not(.on) { background: repeating-linear-gradient(135deg, var(--bg) 0 10px, var(--surface) 10px 20px); }
.ac-ico { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; }
.ac-ico svg { width: 24px; height: 24px; fill: #fff; filter: drop-shadow(0 1px 1px rgba(0,0,0,.3)); }
.tier1 .ac-ico { background: radial-gradient(circle at 35% 30%, #ffe0c2, #b8692e); }
.tier2 .ac-ico { background: radial-gradient(circle at 35% 30%, #ffffff, #8e9aa4); }
.tier3 .ac-ico { background: radial-gradient(circle at 35% 30%, #fff3b0, #d29a00); }
.tier4 .ac-ico { background: radial-gradient(circle at 35% 30%, #e9d9ff, #7b4ad1); }
.ac-tx { display: grid; gap: 2px; min-width: 0; }
.ac-tx strong { font-size: calc(15px * var(--fs, 1)); }
.ac-tx span { font-size: calc(13px * var(--fs, 1)); color: var(--muted); }
.ac-card.secret .ac-tx span { font-style: italic; }
.ac-stats { margin-top: 10px; }
.ac-toasts { position: fixed; right: 16px; bottom: 16px; z-index: 110; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; }
.ac-toast {
  display: flex; align-items: center; gap: 12px;
  max-width: min(360px, calc(100vw - 32px)); padding: 12px 16px; border-radius: 14px;
  background: var(--surface); color: var(--text); border: 2px solid var(--star); box-shadow: 0 10px 30px rgba(0,0,0,.25);
  animation: ac-in .4s cubic-bezier(.2, 1.3, .4, 1);
}
.ac-toast.out { opacity: 0; transform: translateY(10px); transition: all .4s; }
.ac-toast .ac-tx span { color: var(--text); font-weight: 600; }
@keyframes ac-in { from { opacity: 0; transform: translateY(20px) scale(.9); } }
@media (prefers-reduced-motion: reduce) { .ac-toast { animation: none; } }
.tier5 .ac-ico { background: radial-gradient(circle at 35% 30%, #f2ffff, #4fc3d9 55%, #1b7f9a); box-shadow: 0 0 8px rgba(79, 195, 217, .55); }
.tier6 .ac-ico { background: conic-gradient(from 0deg, #ff6b6b, #ffd93d, #6bcb77, #4d96ff, #9b5de5, #ff6b6b); box-shadow: 0 0 10px rgba(155, 93, 229, .55); }
.ac-cat { margin-top: 14px; }
.ac-cat h3 { font-size: calc(15px * var(--fs, 1)); margin: 0 0 8px; color: var(--accent); font-variant-numeric: tabular-nums; }
.ac-bar { display: block; height: 6px; margin-top: 4px; border-radius: 99px; background: var(--border); overflow: hidden; }
.ac-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--star)); }
.ac-tx .ac-prog { font-size: calc(12px * var(--fs, 1)); font-variant-numeric: tabular-nums; }
.ac-tx .ac-tier { font-size: calc(11px * var(--fs, 1)); font-weight: 700; letter-spacing: .05em; }
.ac-card { filter: grayscale(.9); }
.ac-card.on { filter: none; }
.lab-account-link { display: flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 8px; font-weight: 700; text-decoration: none; color: var(--text); background: var(--star-soft); border: 1px solid var(--star); }

.ac-series { align-items: flex-start; }
.ac-lv { font-size: calc(13px * var(--fs, 1)); font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.ac-tx .ac-title { color: var(--text); font-weight: 700; }
.ac-tx .ac-next { font-size: calc(12px * var(--fs, 1)); }
.ac-titles { margin-top: 4px; font-size: calc(12px * var(--fs, 1)); }
.ac-titles > summary { cursor: pointer; color: var(--accent); }
.ac-titles ul { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 2px; }
.ac-titles li { color: var(--muted); font-variant-numeric: tabular-nums; }
.ac-titles li.got { color: var(--text); font-weight: 700; }
.ac-titles li.got::before { content: "✓ "; color: var(--star); }

/* ---------- 首次進站的登入提示（可跳過） ---------- */
.lab-welcome {
  position: fixed; inset: 0; z-index: 120; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  animation: ms-fade .25s ease-out;
}
.lab-welcome.out { opacity: 0; transition: opacity .25s; }
.lab-welcome-box {
  position: relative; width: min(440px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  padding: 30px 24px 20px; text-align: center; color: var(--text);
  background: radial-gradient(circle at 50% -10%, var(--star-soft), var(--surface) 62%);
  border: 1px solid var(--border); border-top: 3px solid var(--star); border-radius: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .28), 0 2px 6px rgba(0, 0, 0, .08);
  animation: ms-pop .45s cubic-bezier(.2, 1.3, .4, 1);
}
.lab-welcome-star {
  width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #fff6cf, var(--star) 70%);
  box-shadow: 0 0 0 6px var(--star-soft), 0 8px 22px color-mix(in srgb, var(--star) 45%, transparent);
}
.lab-welcome-star svg { width: 36px; height: 36px; fill: #fffaf0; filter: drop-shadow(0 1px 1px rgba(120, 80, 0, .45)); }
.lab-welcome-box h2 { margin: 4px 0 8px; font-size: calc(22px * var(--fs, 1)); line-height: 1.3; }
.lab-welcome-lead { margin: 0 0 12px; color: var(--text); font-size: calc(15px * var(--fs, 1)); line-height: 1.6; }
.lab-welcome-list { list-style: none; margin: 0 auto 16px; padding: 0; display: grid; gap: 6px; text-align: left; width: fit-content; max-width: 100%; }
.lab-welcome-list li { display: flex; align-items: flex-start; gap: 8px; font-size: calc(14px * var(--fs, 1)); line-height: 1.5; color: var(--muted); }
.lab-welcome-list svg { flex: none; width: 16px; height: 16px; margin-top: .2em; fill: var(--star); }
.lab-welcome-actions { display: grid; gap: 10px; }
.lab-welcome-actions button { min-height: 48px; font-size: calc(16px * var(--fs, 1)); border-radius: 12px; }
.lab-welcome-go { display: inline-flex; align-items: center; justify-content: center; gap: 10px; }
.lab-welcome-go svg { width: 20px; height: 20px; padding: 3px; box-sizing: content-box; background: #fff; border-radius: 6px; }
.lab-welcome-skip { background: transparent; color: var(--text); border: 1px solid var(--border); }
.lab-welcome-msg { min-height: 0; margin: 8px 0 0; color: var(--pos); font-size: calc(14px * var(--fs, 1)); }
.lab-welcome-msg:empty { display: none; }
.lab-welcome-fine { margin: 14px 0 0; color: var(--muted); font-size: calc(12.5px * var(--fs, 1)); line-height: 1.6; }
@media (prefers-reduced-motion: reduce) { .lab-welcome, .lab-welcome-box { animation: none; } }

/* ---------- 上課工具（classroom.js）：投影模式、分享與 QR code、試試看 ---------- */
.lab-tools { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin: 6px 0 8px; }
.lab-tool {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; min-width: 44px; padding: 0 14px;
  font: inherit; font-size: calc(15px * var(--fs, 1)); font-weight: 600;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 22px; cursor: pointer;
}
.lab-tool svg { width: 20px; height: 20px; flex: none; }
.lab-tool:hover, .lab-tool:focus-visible { border-color: var(--accent); color: var(--accent); outline: none; }
.lab-tool[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--surface); }

.lab-share, .lab-bigqr {
  position: fixed; inset: 0; z-index: 120; display: grid; place-items: center; padding: 16px;
  background: rgba(10, 14, 20, .55); animation: ms-fade .2s ease-out;
}
.lab-share-card {
  width: min(440px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  display: grid; gap: 12px; padding: 16px 18px 18px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .3);
}
.lab-share-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: calc(18px * var(--fs, 1)); }
.lab-share-x { width: 44px; height: 44px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; }
.lab-share-x svg { width: 20px; height: 20px; }
.lab-share-x:hover, .lab-share-x:focus-visible { background: var(--accent-soft); color: var(--text); outline: none; }
.lab-share-opt { display: flex; align-items: center; gap: 8px; min-height: 44px; font-size: calc(15px * var(--fs, 1)); cursor: pointer; }
.lab-share-opt input { width: 20px; height: 20px; accent-color: var(--accent); }
.lab-share-row { display: flex; gap: 8px; }
.lab-share-url {
  flex: 1; min-width: 0; min-height: 44px; padding: 0 12px; font: inherit; font-size: calc(14px * var(--fs, 1));
  color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
}
.lab-share-qr {
  justify-self: center; width: min(240px, 70vw); aspect-ratio: 1; padding: 0; border: 1px solid var(--border);
  border-radius: 12px; background: #fff; cursor: zoom-in; overflow: hidden;
}
.lab-share-qr svg, .lab-bigqr-code svg { display: block; width: 100%; height: 100%; }
.lab-share-tip { margin: 0; color: var(--muted); font-size: calc(13.5px * var(--fs, 1)); }
.lab-bigqr { background: rgba(10, 14, 20, .78); }
.lab-bigqr-card { display: grid; justify-items: center; gap: 10px; padding: 22px; background: #fff; color: #111; border-radius: 18px; max-width: 100%; }
.lab-bigqr-code { width: min(76vh, 86vw, 640px); aspect-ratio: 1; }
.lab-bigqr-cap { margin: 0; font-size: calc(20px * var(--fs, 1)); font-weight: 700; text-align: center; }
.lab-bigqr-url { margin: 0; font-size: calc(14px * var(--fs, 1)); color: #444; word-break: break-all; text-align: center; }
.lab-bigqr .lab-tool { color: #111; background: #fff; border-color: #bbb; }

.lab-restored {
  margin: 0 0 8px; padding: 10px 14px; border-radius: 10px; font-size: calc(14.5px * var(--fs, 1));
  background: var(--accent-soft); color: var(--text); transition: opacity .6s ease;
}
.lab-restored.out { opacity: 0; }

/* 試試看：第一次打開時的一行提示 */
.try-hint { display: none; }
.try-hint.show {
  display: flex; align-items: center; gap: 10px; margin: 0 0 10px; padding: 6px 6px 6px 14px;
  font-size: calc(15px * var(--fs, 1)); line-height: 1.5; color: var(--text);
  background: var(--accent-soft); border-left: 4px solid var(--accent); border-radius: 10px;
  animation: ms-fade .35s ease-out; transition: opacity .4s ease, transform .4s ease;
}
.try-hint.show::before { content: "\2192"; font-weight: 800; color: var(--accent); }
.try-hint-text { min-width: 0; flex: 1 1 auto; }
.try-hint.out { opacity: 0; transform: translateY(-4px); }
.try-hint-x { margin-left: auto; flex: none; width: 44px; height: 44px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; }
.try-hint-x svg { width: 18px; height: 18px; }
.try-hint-x:hover, .try-hint-x:focus-visible { background: var(--surface); color: var(--text); outline: none; }
@media (prefers-reduced-motion: reduce) { .try-hint.show, .lab-share, .lab-bigqr { animation: none; } .try-hint, .lab-restored { transition: none; } }

/* 投影模式：全螢幕、放大字、用滿寬度、收起留言與頁尾 */
html.lab-projector .wrap { max-width: none; padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px)); }
html.lab-projector .comments, html.lab-projector #comments, html.lab-projector footer.site,
html.lab-projector .lab-account, html.lab-projector .lab-account-menu { display: none !important; }

/* 分享視窗：傳給學生、嵌入網頁 */
.lab-share-to { display: flex; flex-wrap: wrap; gap: 8px; }
a.lab-tool { text-decoration: none; }
.lab-share-embed { display: grid; gap: 8px; }
.lab-share-embed[hidden] { display: none; }
.lab-share-code {
  width: 100%; box-sizing: border-box; resize: vertical; padding: 8px 10px; border-radius: 10px;
  font: calc(12.5px * var(--fs, 1))/1.45 ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: var(--text); background: var(--bg); border: 1px solid var(--border);
}
.lab-share-embed .lab-tool { justify-self: start; }

/* 數據表下方：下載 CSV、複製表格 */
.lab-export[hidden] { display: none; }
.lab-export { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0 4px; }
.lab-export .lab-tool { font-size: calc(14px * var(--fs, 1)); padding: 0 12px; }
.lab-tool:disabled { opacity: .45; cursor: default; border-color: var(--border); color: var(--muted); }
.lab-export-msg { color: var(--muted); font-size: calc(13.5px * var(--fs, 1)); }

/* 嵌入模式（?embed=1）：放進老師的網頁時只留實驗本身 */
html.lab-embed .wrap { padding-top: 8px; padding-bottom: 12px; }
html.lab-embed .top .crumbs, html.lab-embed .top > p, html.lab-embed .notes, html.lab-embed .comments, html.lab-embed #comments,
html.lab-embed footer.site, html.lab-embed .lab-account, html.lab-embed .lab-account-menu, html.lab-embed .ms-bar,
html.lab-embed .try-hint, html.lab-embed .stats-bar { display: none !important; }
html.lab-embed .top { margin-bottom: 4px; }
html.lab-embed .top h1 { font-size: calc(20px * var(--fs, 1)); margin: 6px 0 0; }
html.lab-embed .top > :first-child { min-height: 0; }
html.lab-embed .top h1 { padding-right: 60px; } /* 右上角齒輪 */

/* 相關實驗（每個實驗頁底部，classroom.js 產生） */
.related { margin: 28px 0 8px; }
.related h2 { font-size: calc(20px * var(--fs, 1)); margin: 0 0 4px; }
.related .module { display: flex; flex-direction: column; text-decoration: none; color: inherit; }
.related .module h3 { margin: 4px 0 4px; }
.related .module p { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.related-tag { margin-top: 8px; font-size: calc(12.5px * var(--fs, 1)); font-weight: 650; letter-spacing: .02em; color: var(--c); }
html.lab-projector .related, html.lab-embed .related { display: none; }

/* 列印：白底、收起按鈕與留言；classroom.js 會在列印前把深色模式換成淺色 */
.print-only { display: none; }
@media print {
  body { background: #fff !important; color: #000 !important; }
  .wrap { max-width: none; padding: 0; }
  .print-only { display: block; }
  .print-name { margin: 6px 0 10px; font-size: 13pt; letter-spacing: .02em; }
  .lab-gear, .lab-settings, .lab-account, .lab-account-menu, .lab-tools, .lab-export, .try-hint, .lab-restored,
  .comments, #comments, .related, footer.site, .ms-bar, .stats-bar, .lab-welcome, .lab-share, .lab-bigqr,
  .site-qr, .search, .domain-nav, .branch-nav, .crumbs, .try-hint-x, #soundBtn { display: none !important; }
  .top p { color: #333 !important; }
  .lab, .card, table, figure, canvas { break-inside: avoid; }
  canvas { max-width: 100% !important; height: auto !important; }
  a { color: inherit; text-decoration: none; }
  .notes { break-before: auto; }
}

/* 鍵盤操作畫布（keys.js） */
.lab-kb-canvas:focus { outline: none; }
.lab-kb-canvas:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
/* 只給螢幕閱讀器的文字 */
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
