/* 基础样式与通用组件。类名是全应用的公共词汇，视图样式共享同一套设计语法。
   目录：重置 · 滚动条与滚动渐隐 · 排版 · 按钮 · 表单与滑杆 · 分段与色板 · 布局小件 · 浮层 · 状态 */

/* ── 滚动渐隐自定义属性 ───────────────────────────── */
@property --fade-start {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}

@property --fade-end {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}

/* ── 重置 ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

/* A long press on the empty canvas can select the nearest toolbar or sidebar
   label in WebKit. Keep the entire writing surface out of native selection. */
:root, .ink-surface {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.ink-surface {
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
:is(input, textarea, [contenteditable]:not([contenteditable="false"])) {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

body {
  margin: 0;
  background: var(--surface-0);
  color: var(--ink-1);
  font: var(--text-m)/1.55 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-kerning: normal;
  text-autospace: normal;
  text-spacing-trim: trim-start;
  overflow: hidden;
}

h1, h2, h3, h4, p, figure { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
img, canvas, svg { display: block; max-width: 100%; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
a { color: var(--accent-ink); text-underline-offset: 3px; }

button {
  appearance: none;
  border: 0;
  margin: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:disabled, button[aria-disabled='true'] { cursor: default; opacity: .38; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }
::selection { background: var(--accent-soft); color: var(--ink-1); }

/* ── 滚动条（标准优先，WebKit 仅作不支持时回退） ──── */
:root, * {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}
@supports not (scrollbar-color: auto) {
  :root, * { scrollbar-width: auto; }
  ::-webkit-scrollbar { width: 9px; height: 9px; }
  ::-webkit-scrollbar-track { background: var(--scrollbar-track); }
  ::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border: 2.5px solid transparent;
    background-clip: content-box;
    border-radius: var(--radius-pill);
  }
}

/* 横向滚动画布外缘的柔和渐隐提示（纯 CSS 滚动驱动） */
@supports (animation-timeline: scroll(self inline)) {
  .scroll-fade-x {
    --fade-size: 24px;
    --fade-dir: right;
    --fade-start-pos: 0;
    --fade-end-pos: 100%;
    mask:
      linear-gradient(black, black) no-clip subtract,
      linear-gradient(to var(--fade-dir), black, transparent) var(--fade-start-pos) 0 / var(--fade-start) 100% no-repeat no-clip,
      linear-gradient(to var(--fade-dir), transparent, black) var(--fade-end-pos) 0 / var(--fade-end) 100% no-repeat no-clip;
    animation: qing-fade-start linear both, qing-fade-end linear both;
    animation-timeline: scroll(self inline);
    animation-range: 0 var(--fade-size), calc(100% - var(--fade-size)) 100%;
    scroll-padding-inline: var(--fade-size);
  }
  @keyframes qing-fade-start { to { --fade-start: var(--fade-size); } }
  @keyframes qing-fade-end { from { --fade-end: var(--fade-size); } }
}

/* 纵向滚动画布的柔和边缘渐隐提示（纯 CSS 滚动驱动，无伪元素遮挡条） */
@supports (animation-timeline: scroll(self block)) {
  .scroll-fade-y {
    --fade-size: 24px;
    mask:
      linear-gradient(black, black) no-clip subtract,
      linear-gradient(to bottom, black, transparent) 0 0 / 100% var(--fade-start) no-repeat no-clip,
      linear-gradient(to bottom, transparent, black) 0 100% / 100% var(--fade-end) no-repeat no-clip;
    animation: qing-fade-start linear both, qing-fade-end linear both;
    animation-timeline: scroll(self block);
    animation-range: 0 var(--fade-size), calc(100% - var(--fade-size)) 100%;
    scroll-padding-block: var(--fade-size);
  }
}

/* ── 排版 ─────────────────────────────────────────── */
h1, h2, .serif { font-family: var(--font-serif); font-weight: 500; letter-spacing: -.012em; }
h1, h2, .empty-state strong, .first-content h3, .designer-caption strong { text-wrap: balance; }
h1 { font-size: var(--text-3xl); line-height: 1.22; }
h2 { font-size: var(--text-xl); line-height: 1.32; }
h3 { font-size: var(--text-m); font-weight: 600; }
.dialog-body > p, .empty-state p, .note, .setting-row p, .settings-text, .guide-pane p, .privacy-copy p { text-wrap: pretty; }
small, .small { font-size: var(--text-s); }
.muted { color: var(--ink-3); }
.num { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

.eyebrow {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.icon {
  width: 19px;
  height: 19px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── 按钮 ─────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: var(--control);
  padding: 0 15px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  background: var(--surface-2);
  color: var(--ink-1);
  font-size: var(--text-m);
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 1px 1.5px rgb(42 34 22 / .04);
  transition: background var(--fast), border-color var(--fast), color var(--fast), box-shadow var(--fast);
}
@media (hover: hover) {
  .btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--line-strong); }
}
.btn:active:not(:disabled) { background: var(--surface-4); }

.btn.primary {
  min-height: var(--control-l);
  padding: 0 18px;
  border-color: transparent;
  background: var(--ink-1);
  color: var(--surface-2);
  box-shadow: 0 2px 6px rgb(30 24 16 / .16), inset 0 1px 0 rgb(255 255 255 / .14);
}
@media (hover: hover) {
  .btn.primary:hover:not(:disabled) {
    background: color-mix(in oklab, var(--ink-1) 88%, var(--accent));
    box-shadow: 0 4px 12px rgb(30 24 16 / .22), inset 0 1px 0 rgb(255 255 255 / .16);
  }
}
.btn.primary:active:not(:disabled) { background: var(--ink-1); }

.btn.accent {
  border-color: transparent;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 2px 8px color-mix(in oklab, var(--accent) 34%, transparent), inset 0 1px 0 rgb(255 255 255 / .22);
}
@media (hover: hover) {
  .btn.accent:hover:not(:disabled) { background: var(--accent-ink); }
}

.btn.quiet { border-color: transparent; background: transparent; box-shadow: none; }
@media (hover: hover) {
  .btn.quiet:hover:not(:disabled) { background: var(--surface-3); }
}

.btn.danger { color: var(--danger); }
.btn.danger.primary { background: var(--danger); color: var(--on-accent); }
@media (hover: hover) {
  .btn.danger:hover:not(:disabled) { background: var(--danger-soft); }
  .btn.danger.primary:hover:not(:disabled) { background: color-mix(in oklab, var(--danger) 88%, black); }
}

.btn.small { min-height: 31px; padding: 0 11px; font-size: var(--text-s); }
.btn.block { display: flex; width: 100%; }
.btn .icon { width: 17px; height: 17px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  min-inline-size: var(--control);
  min-block-size: var(--control);
  width: var(--control);
  height: var(--control);
  flex: none;
  border-radius: var(--radius-s);
  color: var(--ink-2);
  transition: background var(--fast), color var(--fast), box-shadow var(--fast);
}
@media (hover: hover) {
  .icon-btn:hover:not(:disabled) { background: var(--surface-3); color: var(--ink-1); }
}
.icon-btn:active:not(:disabled) { background: var(--surface-4); }
.icon-btn[aria-pressed='true'], .icon-btn.active {
  background: var(--accent-soft);
  color: var(--accent-ink);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--accent-line) 65%, transparent);
}
.icon-btn.small { min-inline-size: 28px; min-block-size: 28px; width: 28px; height: 28px; }
.icon-btn.small .icon { width: 16px; height: 16px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 31px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: var(--text-s);
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--fast), border-color var(--fast), color var(--fast), box-shadow var(--fast);
}
@media (hover: hover) {
  .chip:hover { background: var(--surface-3); color: var(--ink-1); border-color: var(--line-strong); }
}
.chip[aria-pressed='true'], .chip.selected {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent-ink);
  box-shadow: 0 1px 2px color-mix(in oklab, var(--accent) 12%, transparent);
}

/* ── 表单与现代化进度滑杆 ─────────────────────────── */
.field { display: block; margin: var(--space-4) 0; }
.field > span {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: var(--text-s);
  font-weight: 500;
  color: var(--ink-2);
}
.field output { color: var(--ink-3); font-weight: 500; font-variant-numeric: tabular-nums; }

.input, .field input:not([type='range'], [type='color'], [type='checkbox']), .field textarea {
  width: 100%;
  min-height: var(--control-l);
  padding: 8px 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  background: var(--surface-2);
  color: var(--ink-1);
  transition: border-color var(--fast), box-shadow var(--fast), background var(--fast);
}
.input::placeholder, .field input::placeholder, .field textarea::placeholder { color: var(--ink-3); opacity: .78; }
.input:focus, .field input:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring-soft);
}
.field textarea { min-height: 120px; resize: vertical; line-height: 1.65; }
.field select { width: 100%; }

/* 下拉选择框：统一轻笔记暖纸外观；桌面现代浏览器渐进增强为顶层定制菜单，触屏保留系统原生体验 */
select, select.input, .select {
  appearance: none;
  -webkit-appearance: none;
  min-height: var(--control-l);
  padding: 0 36px 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a897e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 10px center / 16px;
  color: var(--ink-1);
  cursor: pointer;
  box-shadow: var(--shadow-1), var(--highlight);
  transition: border-color var(--fast), box-shadow var(--fast), background-color var(--fast);
}
@media (hover: hover) {
  select:hover, select.input:hover, .select:hover { border-color: color-mix(in srgb, var(--line-strong) 70%, var(--ink-3)); }
}
select:focus, select.input:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring-soft);
}
select option, .select option { background: var(--surface-2); color: var(--ink-1); }

@media (hover: hover) and (pointer: fine) {
  @supports (appearance: base-select) {
    select, select.input, .select,
    select::picker(select), .select::picker(select) {
      appearance: base-select;
    }
    select, select.input, .select {
      display: inline-flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      padding: 0 12px;
      background-image: none;
    }
    select::picker-icon, .select::picker-icon {
      content: '';
      width: 15px;
      height: 15px;
      flex: none;
      background: var(--ink-3);
      -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3C/svg%3E") center / contain no-repeat;
      mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3C/svg%3E") center / contain no-repeat;
      transition: transform var(--fast) var(--ease), background-color var(--fast);
    }
    select:open::picker-icon, .select:open::picker-icon {
      transform: rotate(180deg);
      background: var(--accent-ink);
    }
    select::picker(select), .select::picker(select) {
      padding: 5px;
      margin-block: 4px;
      border: 1px solid var(--line-strong);
      border-radius: var(--radius-m);
      background: var(--surface-2);
      color: var(--ink-1);
      box-shadow: var(--shadow-3), var(--highlight);
    }
    select option, .select option {
      display: flex;
      align-items: center;
      gap: 8px;
      min-height: 34px;
      padding: 6px 10px;
      border-radius: 7px;
      color: var(--ink-1);
      cursor: pointer;
      transition: background var(--fast), color var(--fast);
    }
    select option:hover, .select option:hover {
      background: var(--surface-3);
    }
    select option:checked, .select option:checked {
      background: var(--accent-soft);
      color: var(--accent-ink);
      font-weight: 500;
    }
    select option::checkmark, .select option::checkmark {
      color: var(--accent-ink);
    }
  }
}

.search-field { position: relative; display: flex; align-items: center; }
.search-field .icon { position: absolute; left: 12px; width: 16px; height: 16px; color: var(--ink-3); pointer-events: none; transition: color var(--fast); }
.search-field:focus-within .icon { color: var(--accent-ink); }
.search-field .input {
  padding-left: 36px;
  padding-right: 54px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  border-color: var(--line);
}
@media (hover: hover) {
  .search-field .input:hover { border-color: var(--line-strong); }
}
.search-field .input:focus { background: var(--surface-2); border-color: var(--accent); }
.search-field kbd { position: absolute; right: 9px; pointer-events: none; }

/* 现代化进度条滑杆：实时填充已走轨道，WebKit 与 Firefox 独立声明 */
input[type='range'] {
  --slider-track-size: 5px;
  --slider-thumb-size: 18px;
  --slider-track-color: var(--line-strong);
  --slider-fill-color: var(--accent);
  --slider-thumb-color: var(--surface-2);
  --slider-direction: to right;
  --attr-min: attr(min type(<number>), 0);
  --attr-max: attr(max type(<number>), 100);
  --control-value: attr(value type(<number>), 50);
  --slider-progress: calc(progress(var(--control-value), var(--attr-min), var(--attr-max)) * 100%);

  appearance: none;
  inline-size: 100%;
  block-size: 32px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
@supports not (opacity: progress(1, 0, 100)) {
  input[type='range'] {
    --slider-progress: calc((var(--control-value) - var(--attr-min)) / max(0.0001, var(--attr-max) - var(--attr-min)) * 100%);
  }
}
input[type='range']:dir(rtl) { --slider-direction: to left; }

input[type='range']::-webkit-slider-runnable-track {
  block-size: var(--slider-track-size);
  border: 0;
  border-radius: var(--radius-pill);
  background: linear-gradient(
    var(--slider-direction),
    var(--slider-fill-color) var(--slider-progress),
    var(--slider-track-color) var(--slider-progress)
  );
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  inline-size: var(--slider-thumb-size);
  block-size: var(--slider-thumb-size);
  margin-block-start: calc((var(--slider-track-size) - var(--slider-thumb-size)) / 2);
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: var(--slider-thumb-color);
  box-shadow: 0 1px 4px rgb(35 28 18 / .24);
  transition: transform var(--fast) var(--ease), box-shadow var(--fast);
}
@media (hover: hover) {
  input[type='range']:hover::-webkit-slider-thumb {
    box-shadow: 0 0 0 4px color-mix(in oklab, var(--accent) 16%, transparent), 0 2px 5px rgb(35 28 18 / .24);
  }
}
input[type='range']:active::-webkit-slider-thumb {
  transform: scale(1.14);
  box-shadow: 0 0 0 6px color-mix(in oklab, var(--accent) 22%, transparent), 0 2px 6px rgb(35 28 18 / .28);
}

input[type='range']::-moz-range-track {
  block-size: var(--slider-track-size);
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--slider-track-color);
}
input[type='range']::-moz-range-progress {
  block-size: var(--slider-track-size);
  border-radius: var(--radius-pill);
  background: var(--slider-fill-color);
}
input[type='range']::-moz-range-thumb {
  inline-size: var(--slider-thumb-size);
  block-size: var(--slider-thumb-size);
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: var(--slider-thumb-color);
  box-shadow: 0 1px 4px rgb(35 28 18 / .24);
}
input[type='range']:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

input[type='color'] {
  width: 44px;
  height: var(--control);
  padding: 2px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  background: var(--surface-2);
  cursor: pointer;
}

.check { display: flex; align-items: center; gap: 10px; margin: var(--space-3) 0; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }

.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch i {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-pill);
  background: var(--line-strong);
  pointer-events: none;
  box-shadow: inset 0 1px 2px rgb(0 0 0 / .10);
  transition: background var(--normal) var(--ease);
}
.switch i::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface-2);
  box-shadow: 0 1px 3px rgb(0 0 0 / .22);
  transition: transform var(--slow) var(--ease-spring), width var(--normal) var(--ease);
}
.switch:active i::after { width: 22px; }
.switch input:checked:active + i::after { transform: translateX(14px); }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(18px); }
.switch input:focus-visible + i { outline: none; box-shadow: var(--ring); }

kbd {
  padding: 1.5px 6px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--ink-3);
  font: 500 11px/1.5 var(--font-ui);
  font-variant-numeric: tabular-nums;
  box-shadow: 0 1px 0 var(--line);
}

/* ── 分段与色板 ───────────────────────────────────── */
.segment {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line-subtle);
  border-radius: var(--radius-s);
  background: var(--surface-3);
}
.segment.block { display: flex; }
.segment > button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex: 1;
  min-height: 30px;
  padding: 0 12px;
  border-radius: 7px;
  color: var(--ink-2);
  font-size: var(--text-s);
  font-weight: 500;
  white-space: nowrap;
  transition: color var(--fast), background var(--fast);
}
@media (hover: hover) {
  .segment > button:hover:not(.selected):not([aria-pressed='true']):not([aria-selected='true']) { color: var(--ink-1); }
}
.segment > button.selected, .segment > button[aria-pressed='true'], .segment > button[aria-selected='true'] {
  background: var(--surface-2);
  color: var(--ink-1);
  box-shadow: var(--shadow-1);
}

.motion-rail { position: relative; isolation: isolate; }
.motion-rail > button { position: relative; z-index: 1; }
.motion-pill {
  position: absolute;
  z-index: 0;
  border-radius: 7px;
  background: var(--surface-2);
  box-shadow: var(--shadow-1);
  pointer-events: none;
  transform-origin: top left;
}
.segment.rail-ready > button.selected,
.segment.rail-ready > button[aria-pressed='true'],
.segment.rail-ready > button[aria-selected='true'] { background: transparent; box-shadow: none; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  position: relative;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 50%;
  background: var(--swatch, currentColor);
  /* 双重环确保深色工具栏下的纯黑墨色与浅色背景下的白色均有清晰轮廓 */
  box-shadow: inset 0 0 0 1px var(--swatch-ring), 0 0 0 1px var(--swatch-ring);
  forced-color-adjust: none;
  transition: transform var(--fast) var(--ease), box-shadow var(--fast);
}
@media (hover: hover) {
  .swatch:hover { transform: scale(1.1); }
}
.swatch[aria-pressed='true'], .swatch.selected {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.swatch.small { width: 22px; height: 22px; }

/* ── 布局小件 ─────────────────────────────────────── */
.row { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.stack { display: grid; gap: var(--space-3); }
.spacer { flex: 1; }
.divider { height: 1px; margin: var(--space-3) 0; border: 0; background: var(--line); }
.v-divider { width: 1px; height: 20px; flex: none; background: var(--line); }

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 7px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--ink-3);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}

.note {
  padding: var(--space-3) 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--surface-1);
  color: var(--ink-2);
  font-size: var(--text-s);
  line-height: 1.65;
}

.setting-row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: 54px;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--line);
}
.setting-row:last-child { border-bottom: 0; }
.setting-row > :first-child { flex: 1; min-width: 0; }
.setting-row strong { display: block; font-weight: 500; color: var(--ink-1); }
.setting-row p { color: var(--ink-3); font-size: var(--text-s); }

.empty-state {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  padding: var(--space-7) var(--space-5);
  color: var(--ink-3);
  text-align: center;
}
.empty-state strong { font: 500 var(--text-xl)/1.4 var(--font-serif); color: var(--ink-1); }
.empty-state p { max-width: 32em; font-size: var(--text-s); color: var(--ink-2); line-height: 1.65; }
.empty-state .btn { margin-top: var(--space-3); }

.thumb {
  position: relative;
  overflow: hidden;
  border-radius: 5px;
  background: var(--paper);
  box-shadow: var(--shadow-1), 0 0 0 1px var(--line);
}
.thumb canvas { width: 100%; height: auto; }

.loading {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--space-2);
  height: 100dvh;
  font: 500 var(--text-2xl) var(--font-serif);
  letter-spacing: .06em;
  background: var(--grain), var(--surface-0);
  animation: loading-in 480ms var(--ease-out) both;
}
.loading::before {
  content: '';
  width: 56px;
  height: 56px;
  margin-bottom: var(--space-2);
  background: url('../icon.svg') no-repeat center / contain;
  filter: drop-shadow(0 6px 14px rgb(48 38 24 / .18));
}
.loading span {
  color: var(--ink-3);
  font: var(--text-s) var(--font-ui);
  letter-spacing: .02em;
  animation: loading-breathe 1.6s ease-in-out 400ms infinite;
}
@keyframes loading-in { from { opacity: 0; transform: translateY(6px); } }
@keyframes loading-breathe { 50% { opacity: .45; } }

/* ── 浮层（高质感实底对话框、工具锚定面板、轻菜单、玻璃胶囊） ── */
dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: min(86dvh, 820px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-l);
  background: var(--surface-2);
  color: var(--ink-1);
  box-shadow: var(--shadow-3), var(--glass-specular);
  overflow: hidden;
}
dialog[open] { display: flex; flex-direction: column; }
dialog:modal { overscroll-behavior: contain; }
dialog::backdrop {
  background: var(--scrim);
  overflow: hidden;
  overscroll-behavior: contain;
  backdrop-filter: blur(8px) saturate(1.15);
  -webkit-backdrop-filter: blur(8px) saturate(1.15);
}
dialog.dialog-wide { width: min(780px, calc(100vw - 32px)); }
dialog.dialog-xl { width: min(980px, calc(100vw - 32px)); }
dialog.dialog-narrow { width: min(410px, calc(100vw - 32px)); }

.dialog-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 18px 16px 10px 24px;
  flex: none;
}
.dialog-head h2 { flex: 1; min-width: 0; }
.dialog-body {
  flex: 1;
  min-height: 0;
  padding: var(--space-2) 24px 24px;
  overflow: auto;
  overscroll-behavior: contain;
}
.dialog-body > p { margin-bottom: var(--space-3); color: var(--ink-2); }
.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-5);
}
.dialog-foot.sticky {
  position: sticky;
  z-index: 3;
  bottom: -24px;
  margin: var(--space-4) -24px -24px;
  padding: var(--space-3) 24px var(--space-4);
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  box-shadow: 0 -8px 16px -12px rgb(30 24 16 / .24);
}

/* 锚定式悬浮工具面板（如笔盒、荧光笔）：贴于工具栏下方且不遮挡纸面；纯实底确保底层笔迹绝不透视干扰 */
dialog.surface-panel[open] {
  position: fixed;
  inset: auto;
  margin: 0;
  width: min(560px, calc(100vw - 24px));
  max-height: min(82dvh, 720px);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-l);
  background: var(--surface-2);
  box-shadow: var(--shadow-3), var(--glass-specular);
}
dialog.surface-panel.dialog-narrow[open] { width: min(390px, calc(100vw - 24px)); }
dialog.surface-panel::backdrop {
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
dialog.surface-panel .dialog-head {
  padding: 14px 14px 8px 20px;
  border-bottom: 1px solid var(--line);
}
dialog.surface-panel .dialog-head h2 { font-size: var(--text-l); }
dialog.surface-panel .dialog-body { padding: 14px 20px 18px; }
dialog.surface-panel .dialog-foot.sticky {
  bottom: -18px;
  margin: var(--space-3) -20px -18px;
  padding: var(--space-3) 20px;
  background: var(--surface-2);
}

/* 菜单：精准贴着触发按钮弹出的轻盈浮层 */
dialog.surface-menu[open] {
  position: fixed;
  inset: auto;
  margin: 0;
  width: min(268px, calc(100vw - 24px));
  max-height: min(560px, 76dvh);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-m);
  background: var(--glass-strong);
  box-shadow: var(--shadow-3), var(--glass-specular);
  backdrop-filter: blur(22px) saturate(1.4);
  -webkit-backdrop-filter: blur(22px) saturate(1.4);
}
dialog.surface-menu::backdrop { background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; }
.surface-menu .dialog-head { display: none; }
.surface-menu .dialog-body { padding: 6px; }
dialog.surface-menu.surface-sheet[open] {
  width: min(520px, calc(100vw - 16px));
  bottom: max(16px, calc(env(safe-area-inset-bottom, 0px) + 8px));
  border-radius: var(--radius-l);
  background: var(--surface-2);
}
dialog.surface-menu.surface-sheet::backdrop { background: var(--scrim); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.surface-menu.surface-sheet .dialog-head { display: flex; padding: 14px 10px 4px 18px; }
.surface-menu.surface-sheet .dialog-head h2 { font-size: var(--text-l); }

.menu-list { display: grid; gap: 2px; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--ink-1);
  font-size: var(--text-m);
  text-align: left;
  transition: background var(--fast), color var(--fast);
}
@media (hover: hover) {
  .menu-item:hover { background: var(--surface-3); }
}
.menu-item:focus-visible { background: var(--surface-3); outline: none; box-shadow: inset 0 0 0 1.5px var(--focus); }
.menu-item .icon { width: 17px; height: 17px; color: var(--ink-3); transition: color var(--fast); }
@media (hover: hover) {
  .menu-item:hover .icon { color: var(--ink-1); }
}
.menu-item > span { flex: 1; min-width: 0; }
.menu-item small { color: var(--ink-3); font-size: var(--text-xs); white-space: nowrap; font-variant-numeric: tabular-nums; }
.menu-item.checked { font-weight: 500; }
.menu-item.checked::after {
  content: '';
  width: 16px;
  height: 16px;
  flex: none;
  background: var(--accent-ink);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7'/%3E%3C/svg%3E") center / contain no-repeat;
}
.menu-item.danger, .menu-item.danger .icon { color: var(--danger); }
@media (hover: hover) {
  .menu-item.danger:hover { background: var(--danger-soft); }
}
.menu-title { padding: 8px 10px 4px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.menu-sep { height: 1px; margin: 5px 6px; background: var(--line); }

/* 非模态气泡（预设粗细、快速调色、选区粘贴） */
.popover {
  position: fixed;
  z-index: 60;
  min-width: 184px;
  max-width: min(340px, calc(100vw - 24px));
  padding: 14px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-m);
  background: var(--glass-strong);
  box-shadow: var(--shadow-3), var(--glass-specular);
  backdrop-filter: blur(22px) saturate(1.4);
  -webkit-backdrop-filter: blur(22px) saturate(1.4);
}

/* 纸面悬浮玻璃胶囊 */
.floating-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  background: var(--glass);
  box-shadow: var(--shadow-glass), var(--glass-specular);
  backdrop-filter: blur(20px) saturate(1.45);
  -webkit-backdrop-filter: blur(20px) saturate(1.45);
}
.floating-bar .icon-btn { border-radius: 50%; }
.floating-bar .label { padding: 0 10px; font-size: var(--text-s); color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* 底部轻提示 */
#toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 10000;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: max-content;
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 18px;
  border: 1px solid rgb(255 255 255 / .12);
  border-radius: var(--radius-pill);
  background: var(--ink-1);
  color: var(--surface-2);
  font-size: var(--text-s);
  font-weight: 500;
  box-shadow: var(--shadow-3);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px) scale(.97);
  transition: opacity var(--normal) var(--ease), transform var(--normal) var(--ease);
}
#toast.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0) scale(1); }
body:has(dialog.surface-menu[open], dialog[open] [role='menu']) #toast.show {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition-duration: 0ms;
}
#toast:has(button) { padding: 6px 8px 6px 16px; }
#toast button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  min-width: 44px;
  min-height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  background: rgb(255 255 255 / .14);
  color: var(--accent-line);
  font-weight: 600;
  white-space: nowrap;
}
:root[data-theme='dark'] #toast button {
  background: var(--surface-2);
  color: var(--accent-ink);
}
@media (max-width: 600px) {
  #toast {
    max-width: calc(100vw - 24px);
    gap: 10px;
    border-radius: 22px;
    font-size: var(--text-xs);
    line-height: 1.4;
  }
  #toast:has(button) { padding: 6px 6px 6px 14px; }
  #toast button { min-width: 44px; min-height: 44px; padding: 0 12px; font-size: var(--text-s); }
}

/* ── 状态 ─────────────────────────────────────────── */
.save-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 2px color-mix(in oklab, var(--green) 20%, transparent); }
.save-dot[data-phase='saving'] { background: var(--accent); }
@media (prefers-reduced-motion: no-preference) {
  .save-dot[data-phase='saving'] { animation: save-pulse 1s ease-in-out infinite; }
}
.save-dot[data-phase='error'] { background: var(--danger); }
@keyframes save-pulse { 50% { opacity: .35; } }

progress { width: 100%; height: 5px; border: 0; border-radius: var(--radius-pill); background: var(--line); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--line); }
progress::-webkit-progress-value { background: var(--accent); border-radius: var(--radius-pill); }

.busy { opacity: .6; pointer-events: none; }

/* 无毛玻璃 / 减少透明度 / 减少动效 / 高对比度 / 触屏 / 强制色彩 */
.glass-off .floating-bar,
.glass-off dialog.surface-menu,
.glass-off dialog.surface-panel,
.glass-off .popover,
.glass-off .stage-ruler {
  background: var(--surface-2);
  border-color: var(--line-strong);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.glass-off dialog::backdrop, .glass-off #toast { backdrop-filter: none; -webkit-backdrop-filter: none; }

@media (prefers-reduced-transparency: reduce) {
  .floating-bar, dialog.surface-menu, dialog.surface-panel, .popover, .stage-ruler {
    background: var(--surface-2);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  dialog::backdrop, #toast { backdrop-filter: none; -webkit-backdrop-filter: none; }
}

@media (prefers-reduced-motion: reduce) {
  /* 仅关闭空间位移动效与循环动画，保留色彩/透明度柔和过渡 */
  .btn, .icon-btn, .chip, .swatch, .side-item, .book-cover .cover, .resume-paper, #toast, .lib-search {
    transition-property: background-color, border-color, color, opacity;
    transition-duration: 100ms;
  }
  .cover-print img, .cover-movement, .pet-awake, .trace-ink, .lib-bar,
  .loading, .loading span, .lib-empty, .lib-drop-card .icon, .settings-pane > * { animation: none !important; }
}
.glass-off .cover-print img, .glass-off .cover-movement, .glass-off .pet-awake, .glass-off .trace-ink,
.glass-off .loading, .glass-off .loading span, .glass-off .lib-empty, .glass-off .lib-drop-card .icon, .glass-off .settings-pane > * { animation: none !important; }

@media (prefers-contrast: more) {
  :root { --line: var(--ink-3); --line-strong: var(--ink-2); --glass-border: var(--ink-2); --ink-3: var(--ink-2); --ink-4: var(--ink-3); }
}

@media (pointer: coarse), (any-pointer: coarse) {
  .btn { min-height: 44px; }
  .btn.small { min-height: 36px; }
  .menu-item { min-height: 44px; }
  .surface-menu.surface-sheet [data-dismiss] { min-inline-size: 44px; min-block-size: 44px; width: 44px; height: 44px; }
  #toast button { min-width: 44px; min-height: 44px; padding: 0 14px; }
}

@media (forced-colors: active) {
  .icon-btn[aria-pressed='true'], .chip[aria-pressed='true'], .segment > button.selected, .side-item[aria-current='page'] {
    outline: 2px solid Highlight;
    outline-offset: -2px;
  }
  .floating-bar, dialog, .popover { border: 1px solid CanvasText; }
}

/* 按钮与导航控件的双层焦点环（任何深浅底色下均有清晰边缘） */
.btn:focus-visible,
.icon-btn:focus-visible,
.chip:focus-visible,
.segment > button:focus-visible,
.side-item:focus-visible,
.settings-nav button:focus-visible,
.ed-tab-open:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}
.btn.quiet:hover:not(:disabled), .btn.quiet.danger:hover:not(:disabled) { border-color: transparent; }

dialog:focus { outline: none; }
