/* ==========================================================
 * NOTES Web — styles.css
 * 取代 Tailwind CDN（離線可用）。斷點：
 *   手機   ≤ 640px   側邊欄 → 底部分頁列
 *   平板   ≤ 1024px  側邊欄 → 精簡圖示欄；縮圖欄 → 抽屜
 * ========================================================== */
:root {
  --ink: #111827;
  --ink-2: #374151;
  --mute: #6b7280;
  --line: #d1d5db;
  --line-2: #9ca3af;
  --bg: #f9fafb;
  --bg-2: #f3f4f6;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --tabbar-h: 58px;
  --surface: #ffffff;
  --on-ink: #ffffff;
  --ink-hover: #000000;
  --stage: #e5e7eb;
  --card-min: 190px;
  color-scheme: light;
}
/* ---------- 深色主題 ---------- */
:root[data-theme="dark"] {
  --ink: #f3f4f6; --ink-2: #cbd5e1; --mute: #9aa3b2;
  --line: #373d48; --line-2: #5b6472;
  --bg: #0f1216; --bg-2: #171b21; --surface: #1c2128;
  --on-ink: #111827; --ink-hover: #ffffff; --stage: #0a0c0f;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --ink: #f3f4f6; --ink-2: #cbd5e1; --mute: #9aa3b2;
    --line: #373d48; --line-2: #5b6472;
    --bg: #0f1216; --bg-2: #171b21; --surface: #1c2128;
    --on-ink: #111827; --ink-hover: #ffffff; --stage: #0a0c0f;
    color-scheme: dark;
  }
}

* { border-radius: 0 !important; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'IBM Plex Sans', system-ui, -apple-system, 'Noto Sans TC', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  background: var(--bg); color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-touch-callout: none;
}
button { font-family: inherit; }
.hidden { display: none !important; }
.mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; }

button:focus-visible, input:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--ink); outline-offset: 0;
}
::selection { background: var(--ink); color: var(--on-ink); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-2); }
::-webkit-scrollbar-thumb { background: var(--line); border: 2px solid var(--bg-2); }
::-webkit-scrollbar-thumb:hover { background: var(--line-2); }

/* ---------- 整體框架 ---------- */
.app { display: flex; height: 100%; width: 100%; height: 100dvh; padding-left: var(--sal); padding-right: var(--sar); }
.main { flex: 1; position: relative; min-width: 0; background: var(--bg); display: flex; flex-direction: column; }

.view {
  position: absolute; inset: 0;
  opacity: 0; transform: translateY(10px);
  pointer-events: none;
  transition: opacity .28s ease, transform .28s ease;
  overflow: hidden;
}
.view.active { opacity: 1; transform: none; pointer-events: auto; }
#viewDashboard.active { overflow-y: auto; -webkit-overflow-scrolling: touch; }
#viewEditor { display: flex; flex-direction: column; }

/* 開啟筆記本（編輯器）時，任何裝置都不顯示側邊欄 */
body.in-editor .sidebar { display: none; }

/* ---------- 左側邊欄 ---------- */
.sidebar {
  width: 240px; flex: none; background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding-top: var(--sat);
}
.sb-brand { padding: 20px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.logo { width: 32px; height: 32px; flex: none; display: block; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: .03em; line-height: 1; }
.brand-sub { font-family: 'IBM Plex Mono', monospace; font-size: 10.5px; color: var(--mute); margin-top: 4px; letter-spacing: .15em; }
.sb-nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 4px; }
.sb-label { padding: 4px 12px 8px; font-family: 'IBM Plex Mono', monospace; font-size: 10.5px; letter-spacing: .2em; color: var(--line-2); }
.sb-foot { padding: 12px 16px; border-top: 1px solid var(--line); font-family: 'IBM Plex Mono', monospace; font-size: 10.5px; color: var(--line-2); line-height: 1.6; }
.sb-foot .save-state { margin-top: 4px; word-break: break-all; }
.install-btn { margin: 0 8px 8px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 14px; min-height: 40px;
  font-size: 13.5px; font-weight: 500;
  color: var(--ink-2); text-align: left;
  border: 1px solid transparent; cursor: pointer; background: transparent;
  transition: background .12s ease, color .12s ease;
}
.nav-item:hover { background: var(--surface); color: var(--ink); }
.nav-item.active { background: var(--surface); color: var(--ink); border-color: var(--ink); }
.nav-item .count { margin-left: auto; font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--mute); }

/* ---------- 儀表板 ---------- */
.dash-header {
  position: sticky; top: 0; z-index: 10; background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: calc(20px + var(--sat)) 32px 20px;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
}
.dash-title { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
.dash-sub { margin: 6px 0 0; font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--mute); }
.dash-actions { display: flex; gap: 10px; }
.dash-body { padding: 28px 32px; }
#dashGrid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fill, minmax(var(--card-min), 1fr)); }
.empty-state { border: 1px dashed var(--line-2); padding: 80px 16px; text-align: center; }
.empty-icon { width: 48px; height: 48px; border: 2px solid var(--line-2); margin: 0 auto 16px; display: flex; align-items: center; justify-content: center; }
.empty-state p { margin: 0; font-size: 14px; color: var(--mute); }

.nb-card {
  background: var(--surface); border: 1px solid var(--line);
  cursor: pointer; position: relative;
  transition: border-color .12s ease, transform .12s ease;
}
.nb-card:hover { border-color: var(--ink); transform: translateY(-2px); }
.nb-cover { aspect-ratio: 3 / 4; display: flex; align-items: flex-end; padding: 14px; border-bottom: 1px solid var(--line); position: relative; overflow: hidden; }
.nb-cover .cover-mark { position: absolute; top: 10px; right: 10px; width: 18px; height: 18px; border: 2px solid currentColor; opacity: .55; }
.nb-cover-inner { position: relative; width: 100%; }
.nb-name { font-size: 15px; font-weight: 700; line-height: 1.35; word-break: break-word; }
.nb-meta { font-family: 'IBM Plex Mono', monospace; font-size: 10px; margin-top: 6px; opacity: .7; }
.nb-foot { padding: 10px 12px; display: flex; align-items: center; gap: 6px; }
.nb-foot .kind { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--mute); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 按鈕 / 表單 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; min-height: 38px; font-size: 13.5px; font-weight: 600;
  border: 1px solid var(--ink); cursor: pointer;
  transition: background .12s ease, color .12s ease, opacity .12s ease;
  user-select: none; -webkit-user-select: none; white-space: nowrap;
}
.btn-primary { background: var(--ink); color: var(--on-ink); }
.btn-primary:hover { background: var(--ink-hover); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }
.btn-ghost { background: var(--surface); color: var(--ink); }
.btn-ghost:hover { background: var(--bg-2); }
.btn-ghost:disabled { opacity: .4; cursor: not-allowed; }
.btn-dark-ghost { background: transparent; color: var(--ink-2); border-color: transparent; }
.btn-dark-ghost:hover { background: var(--bg-2); color: var(--ink); border-color: var(--line); }
.btn-danger { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.btn-sm { padding: 5px 10px; min-height: 30px; font-size: 12px; }
.btn-icon { padding: 8px; min-width: 38px; }

.field-input { width: 100%; padding: 10px 12px; border: 1px solid var(--line-2); background: var(--surface); font-size: 16px; color: var(--ink); font-family: inherit; }
.field-input:focus { border-color: var(--ink); outline: none; }
.field-label { display: block; font-family: 'IBM Plex Mono', monospace; font-size: 11px; letter-spacing: .12em; color: var(--mute); margin-bottom: 8px; }

.swatch { width: 34px; height: 34px; border: 1px solid rgba(0,0,0,.25); cursor: pointer; position: relative; transition: transform .1s ease; }
.swatch:hover { transform: scale(1.08); }
.swatch.selected::after { content: ''; position: absolute; inset: -4px; border: 2px solid var(--ink); }

.paper-btn {
  padding: 10px 8px; border: 1px solid var(--line-2); background: var(--surface);
  font-size: 12.5px; font-weight: 500; color: var(--ink-2);
  cursor: pointer; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  transition: border-color .12s ease, background .12s ease, color .12s ease;
}
.paper-btn:hover { border-color: var(--ink); }
.paper-btn.selected { border-color: var(--ink); background: var(--ink); color: var(--on-ink); }
#paperOptions { display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: 8px; }

.mini-swatch { width: 20px; height: 20px; border: 1px solid rgba(0,0,0,.25); cursor: pointer; position: relative; flex: none; }
.mini-swatch.selected::after { content: ''; position: absolute; inset: -3px; border: 2px solid var(--ink); }
.width-btn, .mode-btn { padding: 4px 9px; min-height: 28px; font-size: 11.5px; font-weight: 600; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.width-btn:hover, .mode-btn:hover { border-color: var(--ink); }
.width-btn.selected, .mode-btn.selected { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }

.icon { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: square; stroke-linejoin: miter; flex: none; }
.icon-sm { width: 15px; height: 15px; }
.badge { display: inline-block; padding: 2px 7px; font-family: 'IBM Plex Mono', monospace; font-size: 10.5px; letter-spacing: .05em; border: 1px solid var(--line-2); color: var(--mute); white-space: nowrap; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(17,24,39,.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; opacity: 0; pointer-events: none;
  transition: opacity .2s ease;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal-box { background: var(--surface); border: 1px solid var(--ink); width: 100%; max-width: 520px; max-height: 90vh; max-height: 90dvh; overflow: auto; transform: translateY(12px); transition: transform .22s ease; }
.modal-box.narrow { max-width: 420px; }
.modal-overlay.open .modal-box { transform: none; }
.modal-head { padding: 16px 24px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.modal-body { padding: 20px 24px; display: flex; flex-direction: column; gap: 20px; }
.modal-foot { padding: 16px 24px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; background: var(--bg); }
.wrap-row { display: flex; flex-wrap: wrap; gap: 10px; }
.pdf-box { border: 1px solid var(--line); background: var(--bg); padding: 16px; }
.pdf-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pdf-name { font-size: 13px; font-weight: 600; color: var(--ink-2); display: flex; align-items: center; gap: 8px; min-width: 0; }
.pdf-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pdf-status { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--mute); margin-top: 6px; }
.pdf-note { font-size: 11px; color: var(--mute); margin: 12px 0 0; padding-top: 12px; border-top: 1px solid var(--line); line-height: 1.6; }
.radio-row { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--line); cursor: pointer; font-size: 13.5px; }
.radio-row:hover { border-color: var(--ink); }
.radio-row.selected { border-color: var(--ink); background: var(--bg-2); }
.radio-row input { accent-color: var(--ink); }
.stack { display: flex; flex-direction: column; gap: 8px; }
.res-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.hint { font-size: 11px; color: var(--mute); margin: 8px 0 0; }

/* ---------- 編輯器 ---------- */
.ed-header {
  flex: none; background: var(--surface); border-bottom: 1px solid var(--line);
  padding: calc(10px + var(--sat)) 20px 10px;
  display: flex; align-items: center; gap: 12px;
}
.ed-sep { width: 1px; height: 24px; background: var(--line); flex: none; }
.ed-title-wrap { min-width: 0; flex: 1; }
.ed-title { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-meta { font-family: 'IBM Plex Mono', monospace; font-size: 10.5px; color: var(--mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.page-indicator { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--ink-2); padding: 0 8px; white-space: nowrap; }
#btnThumbs { display: none; }

.toolbar-wrap { flex: none; display: flex; justify-content: center; padding: 12px 16px 8px; }
#toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; max-width: 100%; }
/* 每組工具是一個不可拆的方塊；畫面過窄時整組換到下一行 */
.tb-box { display: flex; flex-wrap: nowrap; align-items: center; gap: 2px; background: var(--surface); border: 1px solid var(--line); padding: 4px; max-width: 100%; }
.tb-group { display: flex; align-items: center; gap: 6px; padding: 0 6px; }
.tb-group + .tb-group { border-left: 1px solid var(--line); margin-left: 4px; padding-left: 10px; }
.tool-btn {
  width: 38px; height: 34px; display: flex; align-items: center; justify-content: center;
  border: 1px solid transparent; color: var(--ink-2); cursor: pointer; background: transparent;
  transition: background .12s ease, border-color .12s ease; flex: none;
}
.tool-btn:hover { background: var(--bg-2); }
.tool-btn:disabled { opacity: .35; cursor: not-allowed; }
.tool-btn:disabled:hover { background: transparent; }
.tool-btn.active { border-color: var(--ink); background: var(--ink); color: var(--on-ink); }
.tool-btn.wide { width: auto; padding: 0 9px; font-size: 11px; font-weight: 600; white-space: nowrap; }
#eraserModes { display: none; align-items: center; gap: 4px; padding: 0 4px; }

.ed-body { flex: 1; display: flex; min-height: 0; position: relative; }
#thumbSidebar { width: 124px; flex: none; background: var(--bg-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.thumb-head { padding: 8px 10px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.thumb-head span { font-family: 'IBM Plex Mono', monospace; font-size: 10.5px; letter-spacing: .15em; color: var(--mute); }
#thumbList { flex: 1; overflow: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; -webkit-overflow-scrolling: touch; }
.thumb-foot { padding: 8px; border-top: 1px solid var(--line); display: flex; gap: 6px; }
.thumb-foot .btn { flex: 1; padding: 4px 6px; font-size: 11px; min-height: 30px; }
.thumb-scrim { display: none; }

.thumb-item { border: 1px solid var(--line); background: var(--surface); padding: 3px; cursor: pointer; transition: border-color .12s ease; flex: none; }
.thumb-item:hover { border-color: var(--mute); }
.thumb-item.current { border-color: var(--ink); border-width: 2px; padding: 2px; }
.thumb-item.dragover { border-color: var(--ink); border-style: dashed; }
.thumb-item canvas { display: block; width: 100%; height: auto; background: #fff; }
.thumb-label { font-size: 10px; font-family: 'IBM Plex Mono', monospace; color: var(--mute); text-align: center; margin-top: 3px; }

#pageContainer { flex: 1; position: relative; min-width: 0; background: var(--stage); overflow: hidden; touch-action: none; }
#stageCanvas { display: block; position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; -webkit-user-select: none; user-select: none; }
#textEditor {
  position: absolute; z-index: 20; background: var(--surface);
  border: 1.5px solid var(--ink); padding: 2px 4px; margin: 0;
  resize: none; outline: none; font-family: 'IBM Plex Sans', sans-serif;
  color: var(--ink); line-height: 1.3; overflow: hidden;
  -webkit-user-select: text; user-select: text;
}
#selToolbar { position: absolute; z-index: 20; display: none; background: var(--surface); border: 1px solid var(--ink); padding: 3px; gap: 3px; }
#selToolbar button { padding: 6px 12px; min-height: 30px; font-size: 11.5px; font-weight: 600; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2); cursor: pointer; }
#selToolbar button:hover { border-color: var(--ink); background: var(--bg-2); }
#selToolbar button.danger { border-color: #b91c1c; color: #b91c1c; }
#selToolbar button.danger:hover { background: #b91c1c; color: #fff; }

.statusbar { flex: none; background: var(--surface); border-top: 1px solid var(--line); padding: 8px 20px calc(8px + var(--sab)); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-family: 'IBM Plex Mono', monospace; font-size: 10.5px; color: var(--mute); }
.statusbar .tips { display: inline; }

/* 手勢提示（縮放時短暫顯示） */
.zoom-toast { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); z-index: 15; background: var(--ink); color: var(--on-ink); font-family: 'IBM Plex Mono', monospace; font-size: 12px; padding: 5px 10px; opacity: 0; pointer-events: none; transition: opacity .2s ease; }
.zoom-toast.show { opacity: 1; }

/* ---------- 觸控裝置：放大點擊目標 ---------- */
@media (pointer: coarse) {
  .tool-btn { width: 44px; height: 42px; }
  .tool-btn.wide { height: 42px; }
  .btn { min-height: 42px; }
  .btn-sm { min-height: 36px; }
  .mini-swatch { width: 26px; height: 26px; }
  .width-btn, .mode-btn { min-height: 36px; padding: 4px 12px; font-size: 12.5px; }
  .nav-item { min-height: 46px; }
  .thumb-foot .btn { min-height: 38px; }
  #selToolbar button { min-height: 38px; padding: 6px 14px; }
  .tb-group { gap: 8px; }
}

/* ================================================================
 * 平板（≤ 1024px）：側邊欄收成圖示欄；縮圖欄改為抽屜
 * ================================================================ */
@media (max-width: 1024px) {
  .sidebar { width: 72px; }
  .sb-brand { padding: 16px 0; justify-content: center; }
  .brand-text, .sb-label, .sb-foot .txt { display: none; }
  .sb-nav { padding: 12px 6px; align-items: stretch; }
  .nav-item { flex-direction: column; gap: 4px; padding: 10px 2px; font-size: 10.5px; text-align: center; justify-content: center; }
  .nav-item .count { margin: 0; font-size: 10px; }
  .sb-foot { padding: 10px 4px; text-align: center; font-size: 9px; }
  .install-btn { margin: 0 6px 8px; padding: 8px 2px; font-size: 10.5px; }
  .install-btn .lbl { display: none; }

  .dash-header { padding-left: 24px; padding-right: 24px; }
  .dash-body { padding: 22px 24px; }

  #btnThumbs { display: inline-flex; }
  #thumbSidebar { position: absolute; z-index: 30; left: 0; top: 0; bottom: 0; width: 148px; transform: translateX(-102%); transition: transform .22s ease, box-shadow .22s ease; }
  #thumbSidebar.open { transform: none; box-shadow: 4px 0 18px rgba(0,0,0,.12); }
  .thumb-scrim { position: absolute; inset: 0; z-index: 29; background: rgba(17,24,39,.25); display: block; opacity: 0; pointer-events: none; transition: opacity .2s ease; }
  .thumb-scrim.open { opacity: 1; pointer-events: auto; }
  .statusbar .tips { display: none; }
}

/* ================================================================
 * 手機（≤ 640px）：底部分頁列、精簡頂欄、單列工具列
 * ================================================================ */
@media (max-width: 640px) {
  .app { flex-direction: column-reverse; }
  .sidebar {
    width: 100%; height: calc(var(--tabbar-h) + var(--sab)); flex: none;
    flex-direction: row; border-right: none; border-top: 1px solid var(--line);
    padding: 0 0 var(--sab);
  }
  .sb-brand, .sb-foot, .sb-label { display: none; }
  .sb-nav { flex-direction: row; padding: 0; gap: 0; align-items: stretch; flex: 1; }
  .nav-item { flex: 1; border: none; border-top: 2px solid transparent; padding: 6px 2px; min-height: 0; }
  .nav-item.active { border-color: transparent; border-top-color: var(--ink); background: var(--surface); }
  .install-btn { margin: 6px 6px; align-self: center; width: auto; flex: none; padding: 6px 10px; }

  .dash-header { padding: calc(14px + var(--sat)) 16px 14px; flex-wrap: wrap; align-items: center; }
  .dash-title { font-size: 20px; }
  .dash-body { padding: 16px; }
  #dashGrid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  #btnResetData .lbl-full { display: none; }

  .ed-header { padding: calc(8px + var(--sat)) 10px 8px; gap: 6px; }
  .ed-header .lbl { display: none; }
  .ed-header .btn { padding: 8px; min-width: 40px; }
  .ed-sep { display: none; }
  .ed-meta { display: none; }
  .page-indicator { padding: 0 2px; font-size: 11px; }

  .toolbar-wrap { padding: 8px 8px 6px; }
  .tb-box { padding: 3px; }
  .tb-group { padding: 0 4px; gap: 6px; }

  .statusbar { padding: 6px 12px calc(6px + var(--sab)); }
  #statusLeft { display: none; }
  .statusbar { justify-content: flex-end; }

  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-box { max-width: 100%; max-height: 92dvh; border-left: none; border-right: none; border-bottom: none; }
  .modal-head, .modal-body, .modal-foot { padding-left: 16px; padding-right: 16px; }
  .modal-foot { padding-bottom: calc(16px + var(--sab)); }
}

/* 手機橫向：高度很小，壓縮頂部 */
@media (max-height: 480px) and (orientation: landscape) {
  .toolbar-wrap { padding: 4px 8px; }
  #toolbar { flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; width: 100%; scrollbar-width: none; }
  #toolbar::-webkit-scrollbar { display: none; }
  .tb-box { flex: none; }
  .ed-header { padding-top: calc(4px + var(--sat)); padding-bottom: 4px; }
  .statusbar { display: none; }
}

/* 已安裝為 App（standalone）時 */
@media (display-mode: standalone) {
  body { user-select: none; -webkit-user-select: none; }
}

/* ---------- 偏好：動畫 / 狀態列 / 縮圖欄 ---------- */
body.no-anim *, body.no-anim *::before, body.no-anim *::after { transition: none !important; animation: none !important; }
body.hide-statusbar .statusbar { display: none; }
@media (min-width: 1025px) { body.hide-thumbs #thumbSidebar { display: none; } }

/* ---------- 設定頁 ---------- */
#viewSettings.active { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.set-header {
  position: sticky; top: 0; z-index: 10; background: var(--bg); border-bottom: 1px solid var(--line);
  padding: calc(16px + var(--sat)) 32px 0;
}
.set-header h1 { margin: 0 0 12px; font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
.set-tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin: 0 -4px; padding: 0 4px; }
.set-tabs::-webkit-scrollbar { display: none; }
.set-tab { flex: none; padding: 10px 14px; min-height: 40px; font-size: 13px; font-weight: 600; color: var(--mute); background: transparent; border: 0; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.set-tab:hover { color: var(--ink); }
.set-tab.active { color: var(--ink); border-bottom-color: var(--ink); }
.set-body { padding: 24px 32px 48px; max-width: 860px; }
.set-section { margin-bottom: 28px; scroll-margin-top: 120px; }
.set-section > h2 { margin: 0 0 10px; font-family: 'IBM Plex Mono', monospace; font-size: 11px; letter-spacing: .2em; color: var(--mute); font-weight: 500; }
.set-card { background: var(--surface); border: 1px solid var(--line); }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: 0; }
.set-text { min-width: 0; flex: 1; }
.set-label { font-size: 14px; font-weight: 600; }
.set-desc { font-size: 12px; color: var(--mute); margin-top: 3px; line-height: 1.55; }
.set-ctl { flex: none; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; max-width: 55%; }
.set-select { padding: 8px 10px; min-height: 38px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); font-size: 14px; font-family: inherit; max-width: 100%; }
.set-select:focus { border-color: var(--ink); outline: none; }
.set-range { width: 160px; accent-color: var(--ink); }
.set-val { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--mute); min-width: 44px; text-align: right; }
.set-color { width: 38px; height: 34px; padding: 0; border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; }
.set-seg { display: inline-flex; border: 1px solid var(--line-2); }
.set-seg button { padding: 7px 12px; min-height: 36px; font-size: 12.5px; font-weight: 600; background: var(--surface); color: var(--ink-2); border: 0; border-right: 1px solid var(--line-2); cursor: pointer; white-space: nowrap; }
.set-seg button:last-child { border-right: 0; }
.set-seg button.selected { background: var(--ink); color: var(--on-ink); }
.switch { position: relative; width: 46px; height: 26px; flex: none; border: 1px solid var(--line-2); background: var(--bg-2); cursor: pointer; padding: 0; transition: background .15s ease; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: var(--line-2); transition: transform .15s ease, background .15s ease; }
.switch[aria-checked="true"] { background: var(--ink); border-color: var(--ink); }
.switch[aria-checked="true"]::after { transform: translateX(20px); background: var(--on-ink); }
.set-note { font-size: 12px; color: var(--mute); padding: 12px 16px; border-top: 1px solid var(--line); line-height: 1.6; font-family: 'IBM Plex Mono', monospace; }
.set-bar { height: 6px; background: var(--bg-2); border: 1px solid var(--line); width: 160px; }
.set-bar > i { display: block; height: 100%; background: var(--ink); width: 0; }

@media (max-width: 1024px) { .set-header { padding-left: 24px; padding-right: 24px; } .set-body { padding: 20px 24px 40px; } }
@media (max-width: 640px) {
  .set-header { padding: calc(12px + var(--sat)) 16px 0; }
  .set-header h1 { font-size: 20px; }
  .set-body { padding: 16px 16px 24px; }
  .set-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .set-ctl { max-width: none; justify-content: flex-start; }
  .set-row.inline { flex-direction: row; align-items: center; }
  .set-range { flex: 1; width: auto; min-width: 120px; }
}

/* ===== 多選 / 批次操作 ===== */
.nb-check {
  position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; padding: 0;
  border: 2px solid currentColor; background: rgba(255,255,255,.12); color: inherit;
  cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 2;
  opacity: .75; transition: opacity .1s ease, background .1s ease;
}
.nb-check:hover { opacity: 1; background: rgba(255,255,255,.25); }
.nb-check[aria-checked="true"] { opacity: 1; background: var(--ink); color: var(--on-ink); border-color: var(--on-ink); }
.nb-check[aria-checked="true"]::after { content: ''; width: 11px; height: 6px; border-left: 2.5px solid currentColor; border-bottom: 2.5px solid currentColor; transform: rotate(-45deg) translate(1px,-1px); }
.nb-card.selected { border-color: var(--ink); outline: 2px solid var(--ink); outline-offset: -1px; }
.dash-header { flex-wrap: wrap; }
.bulk-bar { flex: 0 0 100%; border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.bulk-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.bulk-row strong { font-size: 13px; margin-right: 6px; }
.bulk-status { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--mute); }
.info-rows { border: 1px solid var(--line); }
.info-row { display: flex; justify-content: space-between; gap: 16px; padding: 8px 12px; font-size: 12.5px; border-bottom: 1px solid var(--line); }
.info-row:last-child { border-bottom: 0; }
.info-row span:first-child { color: var(--mute); white-space: nowrap; }
.info-row span:last-child { text-align: right; word-break: break-all; }

.size-inputs { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 13px; color: var(--mute); }
.size-inputs .field-input { width: 96px; padding: 7px 10px; }
