/* 编辑器 3.0：一张温润的纸放在安静的书案上，工具条如文房器物般精准退居幕后。
   目录：外壳 · 顶栏与标签 · 工具栏 · 选项区 · 侧栏 · 纸面 · 浮层 · 就地文字 · 小伙伴 · 书写与专注 · 窄屏 */

/* ── 外壳 ─────────────────────────────────────────── */
.editor {
  --side-w: 192px;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  background: var(--surface-1);
}
.editor > * { flex: none; }

.ed-body {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

/* ── 顶栏与标签 ───────────────────────────────────── */
.ed-top {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  height: 46px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line-subtle);
  background: var(--surface-1);
}

.ed-back {
  gap: 3px;
  min-height: 32px;
  padding: 0 11px 0 7px;
  border-radius: var(--radius-s);
  color: var(--ink-2);
  font-size: var(--text-s);
  font-weight: 500;
}
.ed-back .icon { width: 17px; height: 17px; }
@media (hover: hover) {
  .ed-back:hover { color: var(--ink-1); }
}

.ed-tabs {
  display: flex;
  align-items: center;
  gap: 3px;
  flex: 1;
  min-width: 0;
  margin-left: var(--space-2);
  overflow-x: auto;
  scrollbar-width: none;
}
.ed-tabs::-webkit-scrollbar { display: none; }

.ed-tab {
  position: relative;
  display: flex;
  align-items: center;
  flex: 0 1 auto;
  min-width: 78px;
  max-width: 210px;
  height: 32px;
  padding: 0 4px 0 0;
  border: 1px solid transparent;
  border-radius: var(--radius-s);
  color: var(--ink-2);
  transition: background var(--fast), color var(--fast), border-color var(--fast), box-shadow var(--fast);
}
@media (hover: hover) {
  .ed-tab:hover:not(.is-current) { background: var(--surface-3); color: var(--ink-1); }
}
.ed-tab.is-current {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--ink-1);
  box-shadow: var(--shadow-1), var(--highlight);
}
/* 当前标签底部一道陶土细线，与文库侧栏的当前标记呼应 */
.ed-tab.is-current::after {
  content: '';
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--accent);
  opacity: .88;
}
.ed-tab-open {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 4px 0 12px;
  border-radius: var(--radius-s);
  font-size: var(--text-s);
  font-weight: 500;
}
.ed-tab .save-dot { margin: 0 8px 0 2px; }
.ed-tab-close {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: none;
  border-radius: 6px;
  color: var(--ink-3);
  opacity: 0;
  transition: opacity var(--fast), background var(--fast), color var(--fast);
}
.ed-tab-close .icon { width: 13px; height: 13px; }
@media (hover: hover) {
  .ed-tab-close:hover { background: var(--surface-4); color: var(--ink-1); }
  .ed-tab:hover .ed-tab-close { opacity: 1; }
}
.ed-tab-close:focus-visible { opacity: 1; }
.ed-tab.is-current .ed-tab-close { position: absolute; right: 4px; }
.ed-tab.is-current:hover .save-dot, .ed-tab.is-current:focus-within .save-dot { opacity: 0; }
.ed-tab.is-current .ed-tab-open { padding-right: 2px; }

.ed-top-actions { display: flex; align-items: center; gap: 3px; margin-left: var(--space-2); }
.page-bookmark[aria-pressed='true'] { color: var(--accent); background: var(--accent-soft); }
.page-bookmark[aria-pressed='true'] .icon { fill: currentColor; }
.ed-magic {
  min-height: 32px;
  padding: 0 11px;
  border-radius: var(--radius-pill);
  color: var(--ink-2);
  font-size: var(--text-s);
}
.ed-magic .icon { width: 17px; height: 17px; color: var(--accent); }
.ed-magic[aria-pressed='true'] {
  background: var(--accent-soft);
  color: var(--accent-ink);
  box-shadow: inset 0 0 0 1px var(--accent-line);
}

/* ── 工具栏（文房工作台） ─────────────────────────── */
.ed-toolbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 4px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-1);
  box-shadow: 0 6px 14px -12px rgb(48 38 24 / .34);
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
  padding: 3px;
  border: 1px solid var(--line-subtle);
  border-radius: 12px;
  background: var(--surface-3);
  box-shadow: inset 0 1px 2px rgb(42 36 26 / .04);
}
:root[data-theme='dark'] .tool-group {
  border-color: var(--line);
  background: color-mix(in oklab, var(--surface-0) 78%, var(--surface-1));
  box-shadow: inset 0 1px 3px rgb(0 0 0 / .34);
}
.tool-picker-toggle { display: none; }
.tool-picker-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tool-picker-grid button {
  display: grid; justify-items: center; align-content: center; gap: 6px;
  min-height: 68px; padding: 6px; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: var(--surface-1); color: var(--ink-1);
  font: inherit; text-align: center; overflow-wrap: anywhere;
  transition: background var(--fast), border-color var(--fast), color var(--fast);
}
@media (hover: hover) {
  .tool-picker-grid button:hover:not([aria-disabled='true']) { background: var(--surface-3); border-color: var(--line-strong); }
}
.tool-picker-grid button[aria-pressed='true'] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.tool-picker-grid button[data-pick-tool='space'][aria-pressed='true'] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.tool-picker-grid .icon { width: 21px; height: 21px; }

.shape-library { width: min(580px, calc(100vw - 24px)); }
.shape-library-toggle { white-space: nowrap; flex: none; }
.shape-library-toggle .icon:last-child { width: 13px; height: 13px; }
.shape-family + .shape-family { margin-top: 16px; }
.shape-family h3 { margin: 0 0 7px; color: var(--ink-2); font-size: .88rem; font-weight: 600; }
.shape-family .shape-grid { grid-template-columns: repeat(auto-fit, minmax(min(80px, 100%), 1fr)); gap: 6px; }
.shape-grid button { min-height: 64px; font-size: .83rem; line-height: 1.2; }
.shape-grid .icon { width: 28px; height: 28px; stroke-width: 1.6; }
@media (max-width: 600px) {
  .tool-options[data-for='shape'] .opt-segment { display: none; }
  .shape-family .shape-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .shape-grid button { min-height: 56px; }
}

.tool-group .icon-btn {
  position: relative;
  min-inline-size: 34px;
  min-block-size: 34px;
  width: 34px;
  height: 34px;
  border-radius: 9px;
}
.tool-group .tool-btn.group-break {
  margin-inline-start: 9px;
}
.tool-group .tool-btn.group-break::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 8px;
  bottom: 8px;
  width: 1px;
  border-radius: 1px;
  background: var(--line-strong);
  opacity: .58;
  pointer-events: none;
}
/* 选中层级：书写(ink) 纸感抬起+陶土底标 / 套索(select) 柔和陶土选区底 / 插空(reflow) 实色陶土动作态 / 浏览(view) 安静中性态 */
.tool-group .icon-btn[aria-pressed='true'] {
  background: var(--surface-2);
  color: var(--accent-ink);
  box-shadow: 0 1px 3px rgb(46 38 24 / .11), 0 0 0 1px color-mix(in oklab, var(--accent-line) 68%, var(--line-strong)), var(--highlight);
}
.tool-group .motion-pill {
  border-radius: 9px;
  background: var(--surface-2);
  box-shadow: 0 1px 3px rgb(46 38 24 / .11), 0 0 0 1px color-mix(in oklab, var(--accent-line) 68%, var(--line-strong)), var(--highlight);
  transition: background var(--fast), box-shadow var(--fast);
}
.tool-group .motion-pill::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 3px;
  width: 14px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
  opacity: .86;
  transform: translateX(-50%);
  transition: opacity var(--fast), width var(--fast);
}
:root[data-theme='dark'] .tool-group[data-active-tier='ink'] .icon-btn[aria-pressed='true'],
:root[data-theme='dark'] .tool-group[data-active-tier='ink'] .motion-pill,
:root[data-theme='dark'] .tool-group:not([data-active-tier]) .motion-pill {
  background: #2f2d28;
  box-shadow: 0 2px 6px rgb(0 0 0 / .42), 0 0 0 1px color-mix(in oklab, var(--accent-line) 58%, var(--line-strong)), inset 0 1px 0 rgb(255 250 240 / .08);
}
.tool-group[data-active-tier='select'] .motion-pill,
.tool-group [data-tool='lasso'][aria-pressed='true'] {
  background: color-mix(in oklab, var(--accent-soft) 78%, var(--surface-2));
  box-shadow: 0 1px 3px color-mix(in oklab, var(--accent) 16%, transparent), inset 0 0 0 1.25px var(--accent-line);
}
:root[data-theme='dark'] .tool-group[data-active-tier='select'] .motion-pill,
:root[data-theme='dark'] .tool-group [data-tool='lasso'][aria-pressed='true'] {
  background: color-mix(in oklab, var(--accent-soft) 84%, var(--surface-2));
  box-shadow: 0 2px 6px rgb(0 0 0 / .36), inset 0 0 0 1.25px var(--accent-line);
}
.tool-group[data-active-tier='select'] .motion-pill::after,
.tool-group[data-active-tier='reflow'] .motion-pill::after,
.tool-group[data-active-tier='view'] .motion-pill::after {
  opacity: 0;
  width: 0;
}
.tool-group[data-active-tier='reflow'] .motion-pill,
.tool-group [data-tool='space'][aria-pressed='true'],
:root[data-theme='dark'] .tool-group[data-active-tier='reflow'] .motion-pill,
:root[data-theme='dark'] .tool-group [data-tool='space'][aria-pressed='true'] {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 2px 8px color-mix(in oklab, var(--accent) 36%, transparent), inset 0 1px 0 rgb(255 255 255 / .22);
}
.tool-group[data-active-tier='view'] .motion-pill,
.tool-group [data-tool='laser'][aria-pressed='true'],
.tool-group [data-tool='hand'][aria-pressed='true'],
:root[data-theme='dark'] .tool-group[data-active-tier='view'] .motion-pill,
:root[data-theme='dark'] .tool-group [data-tool='laser'][aria-pressed='true'],
:root[data-theme='dark'] .tool-group [data-tool='hand'][aria-pressed='true'] {
  color: var(--ink-1);
  background: var(--surface-2);
  box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line-strong);
}
:root[data-theme='dark'] .tool-group[data-active-tier='view'] .motion-pill,
:root[data-theme='dark'] .tool-group [data-tool='laser'][aria-pressed='true'],
:root[data-theme='dark'] .tool-group [data-tool='hand'][aria-pressed='true'] {
  background: #2f2d28;
}
.tool-group.rail-ready .icon-btn[aria-pressed='true'],
:root[data-theme='dark'] .tool-group.rail-ready .icon-btn[aria-pressed='true'] { background: transparent; box-shadow: none; }
.tool-group.rail-ready [data-tool='space'][aria-pressed='true'],
:root[data-theme='dark'] .tool-group.rail-ready [data-tool='space'][aria-pressed='true'] { color: var(--on-accent); }
.tool-group [data-tool='space'][aria-disabled='true'] { opacity: .36; }
@media (hover: hover) {
  .tool-group .icon-btn:hover:not([aria-pressed='true']):not([aria-disabled='true']) { background: color-mix(in oklab, var(--surface-2) 68%, transparent); color: var(--ink-1); }
  :root[data-theme='dark'] .tool-group .icon-btn:hover:not([aria-pressed='true']):not([aria-disabled='true']) { background: color-mix(in oklab, var(--surface-3) 76%, transparent); }
}

.ed-divider {
  width: 1px;
  height: 22px;
  flex: none;
  margin: 0 2px;
  background: linear-gradient(transparent, var(--line-strong) 24%, var(--line-strong) 76%, transparent);
  opacity: .78;
}

.tool-end { display: flex; align-items: center; gap: 3px; flex: none; margin-left: auto; }
.tool-end .pen-only-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: auto; min-width: 44px; min-height: 38px; gap: 4px; padding-inline: 7px;
  font-size: var(--text-s); white-space: nowrap;
  box-shadow: inset 0 0 0 1px var(--line);
}
.tool-end .pen-only-toggle[aria-pressed='true'] {
  color: var(--accent-ink); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent-line);
}
@media (pointer: coarse), (any-pointer: coarse) {
  .tool-end .pen-only-toggle { min-width: 44px; min-height: 44px; height: auto; }
}
@media (max-width: 600px), (min-width: 1061px) and (max-width: 1280px) {
  .tool-end .pen-only-toggle { width: 44px; padding-inline: 0; }
  .tool-end .pen-only-toggle span { display: none; }
}
@media (max-width: 600px) {
  .tool-end .pen-only-toggle { min-height: 44px; }
}
@media (min-width: 1061px) and (max-width: 1280px) {
  .ed-toolbar { gap: 6px; padding-inline: 8px; }
  .tool-options { gap: 4px; }
  .tool-options .opt-select { padding-inline: 8px; gap: 4px; }
  .opt-group + .opt-group { padding-left: 5px; }
}
.tool-end .ed-divider { margin: 0 4px; }

/* ── 选项区 ───────────────────────────────────────── */
.tool-options {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 2px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tool-options::-webkit-scrollbar { display: none; }
.tool-options > * { flex: none; }

.opt-group { display: flex; align-items: center; gap: 3px; }
.favorite-tray { display: flex; align-items: center; gap: 2px; }
.favorite-sample {
  display: grid; place-items: center; min-width: 40px; height: 36px; padding: 0 3px;
  border-radius: var(--radius-s); background: transparent;
  transition: background var(--fast), box-shadow var(--fast);
}
.favorite-sample canvas { width: 33px; height: 20px; border-radius: 4px; background: #f8f5ed; box-shadow: inset 0 0 0 1px #61583a2e; }
@media (hover: hover) {
  .favorite-sample:hover { background: var(--surface-3); }
}
.favorite-sample[aria-pressed='true'] { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px var(--accent); }
.favorite-row { display: flex; align-items: center; gap: 6px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.favorite-row > span { flex: 1; min-width: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.favorite-row > button { flex: none; }
@media (pointer: coarse) {
  .favorite-sample, .favorite-row .icon-btn, .favorite-tools .icon-btn { min-width: 44px; min-height: 44px; }
}
.opt-group + .opt-group { padding-left: 10px; border-left: 1px solid var(--line); }

.preset {
  position: relative;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-s);
  color: var(--ink-1);
  transition: background var(--fast), box-shadow var(--fast);
}
@media (hover: hover) {
  .preset:hover { background: var(--surface-3); }
}
.preset-width[aria-pressed='true'] {
  background: var(--surface-2);
  box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line-strong);
}
.preset-color .swatch {
  width: 22px;
  height: 22px;
  box-shadow: inset 0 0 0 1px var(--swatch-ring), 0 0 0 1px var(--swatch-ring);
  transition: box-shadow var(--fast), transform var(--fast) var(--ease);
}
.preset-color:hover { background: transparent; }
@media (hover: hover) {
  .preset-color:hover .swatch { transform: scale(1.12); }
}
.preset-color[aria-pressed='true'] .swatch {
  transform: scale(1.06);
  box-shadow: inset 0 0 0 1px var(--swatch-ring), 0 0 0 2px var(--surface-1), 0 0 0 4px var(--accent);
}
.preset[aria-expanded='true'] { background: var(--surface-4); }

.glyph-line {
  display: block;
  width: 18px;
  height: var(--h);
  border-radius: var(--radius-pill);
  background: var(--ink, var(--ink-1));
}
.glyph-line.is-marker {
  width: 20px;
  opacity: max(0.78, var(--marker-opacity, .88));
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(60, 50, 30, 0.14);
}
.glyph-tape {
  display: block;
  width: 22px;
  height: var(--h);
  border-radius: 2px;
  background-color: var(--ink, #dfd3bc);
  background-image: repeating-linear-gradient(
    -45deg,
    transparent 0 3px,
    rgba(255, 255, 255, 0.42) 3px 5px
  );
  box-shadow: inset 0 0 0 1px rgba(48, 40, 28, 0.18);
}
.glyph-laser {
  display: block;
  width: var(--d);
  height: var(--d);
  border-radius: 50%;
  background: radial-gradient(circle at 46% 44%, #ffffff 0 34%, var(--laser, #ff3b30) 64%, var(--laser, #ff3b30) 100%);
  box-shadow: 0 0 8px color-mix(in srgb, var(--laser, #ff3b30) 68%, transparent);
}
.laser-orb {
  width: 30px;
  height: 30px;
}
.laser-orb:hover { background: transparent; }
.laser-orb i {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 42% 38%, #ffffff 0 24%, var(--laser) 58%, color-mix(in srgb, var(--laser) 82%, #181410) 100%);
  box-shadow: 0 0 0 1px rgba(40, 32, 24, 0.12), 0 0 8px color-mix(in srgb, var(--laser) 45%, transparent);
  transition: transform var(--fast) var(--ease), box-shadow var(--fast);
}
@media (hover: hover) {
  .laser-orb:hover i { transform: scale(1.14); box-shadow: 0 0 0 1px rgba(40, 32, 24, 0.14), 0 0 12px color-mix(in srgb, var(--laser) 70%, transparent); }
}
.laser-orb[aria-pressed='true'] i {
  transform: scale(1.08);
  box-shadow: 0 0 0 2px var(--surface-1), 0 0 0 3.8px var(--laser), 0 0 14px color-mix(in srgb, var(--laser) 62%, transparent);
}
.sticky-swatch {
  width: 30px;
  height: 30px;
}
.sticky-swatch:hover { background: transparent; }
.sticky-swatch i {
  position: relative;
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background: linear-gradient(135deg, var(--sticky) 0 76%, color-mix(in srgb, var(--sticky) 76%, #ffffff) 76% 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), inset 0 0 0 1px rgba(56, 46, 30, 0.18), 0 1px 3px rgba(40, 32, 20, 0.10);
  transition: transform var(--fast) var(--ease), box-shadow var(--fast);
}
@media (hover: hover) {
  .sticky-swatch:hover i { transform: translateY(-1px) scale(1.08); }
}
.sticky-swatch[aria-pressed='true'] i {
  transform: scale(1.06);
  box-shadow: inset 0 0 0 1px rgba(56, 46, 30, 0.2), 0 0 0 2px var(--surface-1), 0 0 0 3.8px var(--accent);
}
.laser-spot-chip { gap: 5px; }
.laser-spot-chip[aria-pressed='true'] {
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-color: var(--accent-line);
  box-shadow: 0 0 0 1px color-mix(in oklab, var(--accent) 28%, transparent);
}
.glyph-dot {
  display: block;
  width: var(--d);
  height: var(--d);
  border: 1.5px solid var(--ink-2);
  border-radius: 50%;
}
.glyph-a { font: 500 var(--fs)/1 var(--font-ui); font-style: normal; color: var(--ink, var(--ink-1)); }

.opt-segment > button { min-height: 28px; padding: 0 10px; gap: 5px; }
.opt-segment > button .icon { width: 16px; height: 16px; }
.opt-segment:has(.icon):not(:has(span)) > button { padding: 0 7px; }
.opt-chip .icon { width: 16px; height: 16px; }
.opt-chip:disabled { opacity: .45; cursor: default; }
.opt-chip:disabled:hover { background: var(--surface-2); }
.opt-select {
  gap: 5px;
  padding: 0 9px 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--ink-1);
  box-shadow: 0 1px 1.5px rgb(40 34 22 / .04);
}
.opt-select .icon { width: 14px; height: 14px; color: var(--ink-3); }
@media (hover: hover) {
  .opt-select:hover { border-color: var(--line-strong); background: var(--surface-3); }
}
.opt-clear { color: var(--ink-2); }
.opt-clear .icon { width: 16px; height: 16px; }
.opt-hint { color: var(--ink-3); font-size: var(--text-s); white-space: nowrap; }
.opt-mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 11px 0 9px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: var(--text-s);
  font-weight: 600;
  white-space: nowrap;
}
.opt-mode-pill .icon { width: 15px; height: 15px; color: var(--accent); }
.opt-space-layers {
  gap: 5px;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: var(--text-xs);
}
.opt-space-layers .icon { width: 14px; height: 14px; color: var(--ink-3); }
.opt-space-layers.is-blocked {
  border-color: color-mix(in oklab, var(--danger) 42%, var(--line));
  background: var(--danger-soft);
  color: var(--danger);
}
.opt-space-layers.is-blocked .icon { color: var(--danger); }
.opt-space-exit {
  margin-inline-start: auto;
  gap: 5px;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: var(--text-xs);
}
.opt-space-exit .icon { width: 14px; height: 14px; color: var(--accent); }
.font-serif { font-family: var(--font-serif); }

/* 预设气泡 */
.preset-popover { width: 256px; }
.preset-popover.palette-popover { width: min(280px, calc(100vw - 20px)); }
.preset-pop { display: grid; gap: var(--space-2); }
.preset-pop-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.preset-pop-head strong { font-size: var(--text-s); font-weight: 600; }
.preset-pop-head output { color: var(--accent-ink); font-size: var(--text-s); font-weight: 600; }
.preset-pop p { margin: 0; }
.palette-popover .palette-sample {
  gap: 5px;
  min-width: 44px;
  min-height: 34px;
  padding: 0 10px 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--accent-ink);
  font-size: var(--text-xs);
  font-weight: 500;
  white-space: nowrap;
}
.palette-popover .palette-sample .icon { width: 14px; height: 14px; color: var(--accent); flex: none; }
@media (hover: hover) {
  .palette-popover .palette-sample:hover {
    border-color: var(--accent-line);
    background: var(--accent-soft);
  }
}
@media (max-width: 759px), (pointer: coarse) {
  .palette-popover .palette-sample { min-width: 44px; min-height: 44px; padding: 0 12px 0 10px; }
}

/* ── 侧栏 ─────────────────────────────────────────── */
.ed-side {
  display: none;
  flex-direction: column;
  width: var(--side-w);
  flex: none;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--surface-1);
}
.editor.side-open .ed-side { display: flex; }

.ed-side-head { padding: 10px 12px 8px; }
.ed-side-head .segment > button { min-height: 28px; }

.ed-side-list {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-height: 0;
  padding: 8px 12px 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.side-tile {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 7px;
  width: 100%;
  padding: 9px 6px 7px;
  border-radius: var(--radius-m);
  touch-action: pan-y;
  user-select: none;
  transition: background var(--fast), opacity var(--fast);
}
@media (hover: hover) {
  .side-tile:hover { background: var(--surface-3); }
}
.side-tile .thumb {
  width: 128px;
  max-height: 260px;
  border-radius: 5px;
  transition: box-shadow var(--fast), transform var(--fast) var(--ease);
}
@media (hover: hover) {
  .side-tile:hover .thumb { transform: translateY(-1px); }
}
.side-tile .thumb canvas { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.side-tile[aria-current='page'] .thumb {
  box-shadow: 0 0 0 2.2px var(--accent), 0 6px 16px color-mix(in oklab, var(--accent) 20%, transparent);
}
.side-num {
  padding: 1px 8px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  color: var(--ink-3);
}
.side-tile[aria-current='page'] .side-num {
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 600;
}
.side-mark {
  position: absolute;
  top: 8px;
  right: 22px;
  color: var(--accent);
}
.side-mark .icon { width: 16px; height: 16px; fill: var(--accent-soft); }
.side-practice {
  position: absolute;
  top: 12px;
  left: 24px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface-1);
  border: 1px solid var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow-1);
}
:root[data-theme='dark'][data-night-paper='off'] .side-practice { border-color: var(--accent-line); }
.side-practice .icon { width: 12px; height: 12px; }
.side-tile.is-dragging { opacity: .35; }
.ed-side-list.is-sorting .side-tile:hover { background: transparent; }
.side-drop-line {
  position: absolute;
  left: var(--space-4);
  right: var(--space-4);
  height: 2.5px;
  border-radius: 2px;
  background: var(--accent);
  pointer-events: none;
}
.side-empty { padding: var(--space-6) var(--space-2); }
.side-empty strong { font-size: var(--text-l); }
.side-empty .btn { white-space: normal; }

.ed-side-foot { padding: 10px 12px max(12px, env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); }
.ed-side-foot .btn { color: var(--ink-2); font-size: var(--text-s); }
.ed-side-foot .icon { width: 16px; height: 16px; }

.ed-scrim { display: none; }

/* ── 纸面 ─────────────────────────────────────────── */
.ed-stage {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  background: var(--desk);
  isolation: isolate;
}
#ink {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}
.ed-stage .page-turn-image {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  max-width: none;
  pointer-events: none;
}
.ed-stage.is-dropping::after {
  content: var(--drop-label);
  position: absolute;
  inset: 14px;
  z-index: 8;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: var(--radius-l);
  background: color-mix(in oklab, var(--accent-soft) 55%, transparent);
  backdrop-filter: blur(4px);
  color: var(--accent-ink);
  font: 500 var(--text-l) var(--font-serif);
  pointer-events: none;
}

/* ── 浮层 ─────────────────────────────────────────── */
.ed-stage .floating-bar { transition: opacity var(--normal) var(--ease), transform var(--fast) var(--ease), box-shadow var(--fast); }

.sel-bar {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 6;
  will-change: transform;
  max-width: calc(100% - 12px);
  gap: 2px;
  padding: 4px 5px;
}
.sel-kind, .sel-action span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sel-kind { min-width: 0; margin: 0 9px; color: var(--ink-2); font-size: var(--text-s); font-weight: 500; }
.sel-divider { flex: 0 0 1px; height: 16px; margin-right: 3px; background: var(--line-strong); }
.sel-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 44px;
  min-height: 36px;
  padding: 0 9px;
  border: 0;
  border-radius: var(--radius-pill);
  color: var(--ink-1);
  background: transparent;
  font-size: var(--text-s);
  font-weight: 500;
  transition: background var(--fast);
}
@media (hover: hover) {
  .sel-action:hover, .sel-action[aria-expanded='true'] { background: var(--surface-3); }
}
.sel-action:active { background: var(--surface-4); }
.sel-action .icon { flex: none; width: 17px; height: 17px; }
.sel-color {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--selected-color, conic-gradient(from 210deg, #e1745d, #e7c636, #51a05c, #4e9dda, #b382d5, #e1745d));
  box-shadow: inset 0 0 0 1px var(--swatch-ring), 0 0 0 1px var(--glass-line);
}
.editor.narrow .sel-action { min-height: 44px; padding: 0 6px; }
@media (pointer: coarse) { .sel-action { min-height: 44px; } }
@media (max-width: 380px) {
  .sel-kind { margin: 0 5px; }
  .sel-action[data-sel='copy'] .icon, .sel-action[data-sel='more'] .icon { display: none; }
}
.bar-sep { width: 1px; height: 18px; margin: 0 3px; background: var(--line); }

.stage-status {
  position: absolute;
  top: var(--space-3);
  left: 50%;
  z-index: 5;
  margin: 0;
  padding: 6px 15px;
  color: var(--ink-2);
  font-size: var(--text-s);
  transform: translateX(-50%);
  pointer-events: none;
}
.stage-status.is-error { z-index: 8; width: max-content; color: var(--danger); pointer-events: auto; max-width: min(520px, calc(100% - 32px)); }

.stage-status.is-error .btn { flex: none; color: var(--accent-ink); min-height: 44px; }
.stage-reading-tools {
  position: absolute;
  inset: var(--space-3) var(--space-3) auto;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--space-2);
  pointer-events: none;
}
.stage-reading-tools > * { flex: 0 0 auto; pointer-events: auto; }
.reference-card {
  margin-inline-start: auto;
  max-width: min(340px, 46%);
  overflow: hidden;
  color: var(--ink-1);
  background: var(--surface-1);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-2);
}
.reference-card header, .reference-card button, .reference-prompt { display: flex; align-items: center; }
.reference-card header { justify-content: space-between; }
.reference-card button {
  min-height: 44px; min-width: 44px; justify-content: center; gap: 6px;
  padding: 0 9px; border: 0; color: inherit; background: transparent; font-size: var(--text-s);
}
.reference-card [data-reference-jump] { min-width: 0; justify-content: flex-start; flex: 1; text-align: start; }
.reference-card [data-reference-jump] span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reference-card [data-reference-jump]:enabled { color: var(--accent-ink); }
.reference-card [data-reference-jump] .icon { width: 15px; height: 15px; flex: none; }
.reference-card [data-fold-reference], .reference-card [data-close-reference] { flex: none; width: 44px; }
.reference-card [data-fold-reference] .icon { width: 15px; height: 15px; flex: none; }
.reference-card [aria-expanded='false'] .icon:last-child { transform: rotate(-90deg); }
.reference-card canvas { display: block; max-width: 100%; max-height: min(28vh, 240px); width: auto; height: auto; margin: auto; }
.reference-card canvas[hidden] { display: none; }
.reference-crop { position: absolute; inset: 0; z-index: 20; touch-action: none; cursor: crosshair; }
.reference-prompt {
  position: absolute; top: var(--space-3); left: 50%; transform: translateX(-50%);
  z-index: 1; gap: 8px; width: max-content; max-width: 95%; padding: 0 6px 0 14px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-pill); background: var(--surface-1);
  color: var(--ink-1); font-size: var(--text-s); box-shadow: var(--shadow-1);
}
.reference-prompt .btn { min-height: 44px; }
.reference-frame {
  position: absolute; pointer-events: none; outline: 2px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  box-shadow: 0 0 0 200vmax rgb(0 0 0 / 12%);
}
.color-sampler {
  position: absolute;
  inset: 0;
  z-index: 20;
  touch-action: none;
  cursor: crosshair;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.color-sampler-prompt {
  position: absolute;
  top: var(--space-3);
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: min(94%, 420px);
  padding: 0 6px 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--surface-1);
  color: var(--ink-1);
  font-size: var(--text-s);
  box-shadow: var(--shadow-2);
}
.color-sampler-prompt .icon { width: 16px; height: 16px; color: var(--accent); flex: none; }
.color-sampler-prompt span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.color-sampler-prompt .btn { min-width: 44px; min-height: 44px; padding: 0 12px; border-radius: var(--radius-pill); flex: none; }
.color-sampler-loupe {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  will-change: transform;
}
.color-sampler-loupe[hidden], .color-sampler-pin[hidden] { display: none; }
.color-sampler-ring {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  overflow: hidden;
  border: 6px solid var(--sampled-color, var(--line-strong));
  background: var(--surface-1);
  box-shadow:
    inset 0 0 0 1px rgb(32 26 18 / .22),
    0 0 0 2px var(--surface-1),
    0 10px 26px rgb(28 22 14 / .24);
}
:root[data-theme='dark'] .color-sampler-ring {
  box-shadow:
    inset 0 0 0 1px rgb(255 250 240 / .24),
    0 0 0 2px var(--surface-1),
    0 12px 28px rgb(0 0 0 / .48);
}
.color-sampler-loupe.is-outside .color-sampler-ring {
  border-style: dashed;
  border-color: var(--line-strong);
  background: var(--surface-2);
}
.color-sampler-zoom {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}
.color-sampler-readout {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 7px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--surface-1);
  color: var(--ink-1);
  box-shadow: var(--shadow-2);
  white-space: nowrap;
}
.color-sampler-swatch {
  display: block;
  width: 14px;
  height: 14px;
  flex: none;
  border-radius: 50%;
  background: var(--sampled-color, transparent);
  box-shadow: inset 0 0 0 1px var(--swatch-ring), 0 0 0 1px var(--swatch-ring);
}
.color-sampler-loupe.is-outside .color-sampler-swatch {
  background: transparent;
  border: 1.5px dashed var(--ink-3);
  box-shadow: none;
}
.color-sampler-hex {
  font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  text-transform: uppercase;
  color: var(--ink-1);
}
.color-sampler-loupe.is-outside .color-sampler-hex {
  font-family: var(--font-ui);
  font-weight: 500;
  text-transform: none;
  color: var(--ink-2);
}
.color-sampler-pin {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1.5px rgb(24 20 16 / .72), inset 0 0 0 1px rgb(24 20 16 / .45);
  pointer-events: none;
  will-change: transform;
}
@media (max-width: 600px) {
  .reference-card { max-width: min(75%, 260px); }
  .sel-action[data-sel='pin'] span { display: none; }
  .color-sampler-prompt {
    top: var(--space-2);
    max-width: calc(100% - 16px);
    gap: 6px;
    padding: 0 4px 0 11px;
    font-size: var(--text-xs);
  }
  .color-sampler-ring { width: 82px; height: 82px; border-width: 5px; }
}

.paper-grip {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  z-index: 5;
  gap: 6px;
  padding: 6px 14px 6px 10px;
  color: var(--accent-ink);
  font-size: var(--text-s);
  font-weight: 600;
  pointer-events: none;
}
.paper-grip .icon { width: 16px; height: 16px; }

.stage-dock {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: max(14px, env(safe-area-inset-bottom, 0px));
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: end;
  gap: var(--space-3);
  pointer-events: none;
}
.stage-dock > * { pointer-events: auto; }
.dock-left {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-self: start;
  min-width: 0;
  max-width: 100%;
}
.dock-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; justify-self: end; }
.dock-right > * { pointer-events: auto; }

/* 深色主题关闭护眼纸面（即深色界面配浅色纸）时，底部浮层提高实底对比，彻底消除暗影发脏问题 */
:root[data-theme='dark'][data-night-paper='off'] .stage-dock .floating-bar {
  background: rgb(34 33 29 / .93);
  border-color: rgb(255 250 240 / .16);
  box-shadow: 0 4px 16px rgb(0 0 0 / .24);
}

.pill-btn {
  gap: 7px;
  max-width: 100%;
  height: 36px;
  padding: 0 14px 0 11px;
  color: var(--ink-1);
  font-size: var(--text-s);
  font-weight: 500;
  white-space: nowrap;
}
.pill-btn span { overflow: hidden; text-overflow: ellipsis; }
.pill-btn .icon { width: 16px; height: 16px; color: var(--accent); flex: none; }
.practice-pill {
  min-width: 44px;
  border-color: var(--accent);
  color: var(--accent-ink);
  font-variant-numeric: tabular-nums;
}
:root[data-theme='dark'][data-night-paper='off'] .stage-dock .practice-pill { border-color: var(--accent); }
.practice-pill .icon:last-child { width: 14px; height: 14px; color: var(--ink-3); display: none; }
.practice-pill.has-menu { padding-right: 10px; }
.practice-pill.has-menu .icon:last-child { display: block; }
@media (max-width: 1140px) {
  .editor.side-open .dock-left:has([data-practice-pill]:not([hidden])) [data-paper-pill] { display: none; }
}
@media (max-width: 1020px) {
  .dock-left:has([data-practice-pill]:not([hidden])) [data-paper-pill] { display: none; }
}
@media (pointer: coarse), (any-pointer: coarse) {
  .practice-pill { min-width: 44px; min-height: 44px; height: auto; }
}
@media (hover: hover) {
  .pill-btn:hover { background: var(--glass-strong); transform: translateY(-1px); }
}

.page-pill, .zoom-pill { gap: 1px; padding: 3px; }
.page-pill .icon-btn, .zoom-pill .icon-btn { min-inline-size: 30px; min-block-size: 30px; width: 30px; height: 30px; }
.page-pill .icon-btn .icon, .zoom-pill .icon-btn .icon { width: 15px; height: 15px; }
.pill-label {
  min-width: 64px;
  height: 30px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  color: var(--ink-1);
  font-size: var(--text-s);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transition: background var(--fast);
}
@media (hover: hover) {
  .pill-label:hover { background: var(--surface-3); }
}
.zoom-pill .pill-label { min-width: 56px; }

/* ── 就地文字 ─────────────────────────────────────── */
.ink-text-editor {
  position: absolute;
  z-index: 5;
  min-width: 40px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: transparent;
  outline: 1.5px dashed var(--accent-line);
  outline-offset: 6px;
  overflow: hidden;
  resize: none;
  white-space: pre-wrap;
  word-break: break-all;
  caret-color: var(--accent);
  letter-spacing: 0;
}
.ink-text-editor::placeholder { color: var(--ink-3); opacity: .75; }
.ink-text-editor.is-sticky {
  outline: none;
  border: 1px solid rgb(73 67 49 / .16);
  border-radius: 10px;
  box-shadow: 0 8px 22px rgb(38 30 18 / .18);
}
.ink-text-editor.is-sticky::placeholder { color: rgb(63 57 40 / .5); }

/* ── 小伙伴 ───────────────────────────────────────── */
.ed-stage .pet {
  width: 64px;
  height: 64px;
  margin-right: 4px;
  padding: 4px;
  border: 1px solid transparent;
  border-radius: 50%;
  opacity: .96;
  filter: drop-shadow(0 4px 10px rgb(38 30 18 / .14));
  transition: opacity 180ms var(--ease), background var(--fast), border-color var(--fast), transform var(--normal) var(--ease);
}
@media (hover: hover) {
  .ed-stage .pet:hover {
    background: var(--glass);
    border-color: var(--glass-border);
    transform: translateY(-2px);
  }
}
.ed-stage .pet[data-mood='focus'] { opacity: .20; pointer-events: none; }
.ed-stage .pet[data-mood='rest'] { opacity: .74; }
.ed-stage .pet[data-mood='sprout'] { background: radial-gradient(circle at 55% 58%, color-mix(in oklab, var(--accent-soft) 80%, transparent), transparent 68%); }
.ed-stage .pet[data-mood='sprout'] .pet-awake { animation: pet-peek 440ms cubic-bezier(.2, 1.1, .4, 1); }
@keyframes pet-peek { 0%, 100% { transform: translateY(0); } 45% { transform: translateY(-5px); } }

/* ── 书写与专注 ───────────────────────────────────── */
body.writing .ed-stage .floating-bar:not(.study-bar):not(.study-grade):not(.audio-bar),
body.writing .ed-stage .pet { opacity: .28; }
body.writing .ed-stage .sel-bar { opacity: 0; }

.editor.focus .ed-top,
.editor.focus .ed-side,
.editor.focus .ed-scrim { display: none !important; }
.editor.focus .ed-toolbar { box-shadow: var(--shadow-1); }

.editor.text-editing .sel-bar { display: none; }

.ed-read {
  min-width: 44px;
  min-height: 32px;
  padding: 0 11px;
  gap: 5px;
  border-radius: var(--radius-pill);
  font-size: var(--text-s);
  white-space: nowrap;
}
.ed-read[data-on='true'] {
  background: var(--accent-soft);
  color: var(--accent-ink);
  box-shadow: inset 0 0 0 1px var(--accent-line);
}
.editor.reading .ed-toolbar, .editor.reading [data-add-page], .editor.reading [data-bookmark],
.editor.reading [data-export], .editor.reading .ed-side-foot, .editor.reading [data-mark-current],
.editor.reading [data-paper-pill], .editor.reading .pet { display: none; }
.editor.reading #ink { cursor: grab; }
.editor.reading #ink:active { cursor: grabbing; }
@media (max-width: 540px) {
  .editor [data-layers],
  .editor [data-audio]:not([aria-pressed='true']):not(.is-recording),
  .editor [data-zoom-window]:not([aria-pressed='true']),
  .editor [data-ruler]:not([aria-pressed='true']) { display: none; }
}
@media (max-width: 480px) {
  .editor [data-export] { display: none; }
}

/* ── 窄屏 ─────────────────────────────────────────── */
.editor.narrow { --side-w: min(260px, 82vw); }
.editor.narrow .ed-top { padding: 0 6px; gap: 2px; }
.editor.narrow .ed-back span,
.editor.narrow .ed-magic span,
.editor.narrow .ed-read span { display: none; }
.editor.narrow .ed-back { padding: 0 8px; }
.editor.narrow .ed-magic { width: 34px; padding: 0; }
.editor.narrow .ed-read { width: 34px; min-width: 34px; padding: 0; }
.editor.narrow .ed-top-actions { margin-left: 2px; gap: 1px; }
.editor.narrow .ed-top-actions .icon-btn { min-inline-size: 32px; width: 32px; }
.editor.narrow .ed-tabs { margin-left: 2px; }
.editor.narrow .ed-tab:not(.is-current) { display: none; }
.editor.narrow .ed-tab-close { display: none; }
.editor.narrow .ed-tab { max-width: none; flex: 1 1 72px; min-width: 72px; padding-right: 4px; }
.editor.narrow .ed-tab.is-current .save-dot { opacity: 1; margin: 0 6px 0 2px; flex: none; }
.editor.narrow .ed-tab.is-current::after { left: 10px; right: 10px; }
@media (max-width: 440px) {
  .editor.audio-open .ed-magic,
  .editor.zoom-open .ed-magic { display: none; }
}

@media (max-width: 1060px) {
  .ed-toolbar {
    display: grid; grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas: 'tools picker end' 'opts opts opts';
    padding: 4px var(--space-2) 0; row-gap: 4px;
  }
  .tool-group { grid-area: tools; justify-self: start; width: fit-content; max-width: 100%; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .tool-group::-webkit-scrollbar { display: none; }
  .tool-group .tool-btn { flex: 0 0 auto; }
  .tool-picker-toggle { display: inline-flex; grid-area: picker; width: auto; min-width: 44px; min-height: 44px; gap: 4px; padding: 0 8px; font-size: var(--text-s); white-space: nowrap; }
  .tool-end { grid-area: end; }
  .tool-options { grid-area: opts; height: 46px; padding: 0 2px; border-top: 1px solid var(--line-subtle); }
  .ed-toolbar > .ed-divider { display: none; }
}
.editor.narrow .tool-group .tool-btn { min-inline-size: 40px; min-block-size: 40px; width: 40px; height: 40px; }
.editor.narrow .tool-picker-toggle { width: auto; min-width: 44px; height: 44px; }

.editor.narrow .ed-side {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: flex;
  box-shadow: var(--shadow-3);
  transform: translateX(-102%);
  visibility: hidden;
  transition: transform var(--normal) var(--ease), visibility 0s linear var(--normal);
}
.editor.narrow.side-open .ed-side { transform: none; visibility: visible; transition: transform var(--normal) var(--ease); }
.editor.narrow.side-open .ed-scrim { display: block; position: absolute; inset: 0; z-index: 19; background: var(--scrim); backdrop-filter: blur(3px); }

.editor.narrow .stage-dock {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  left: var(--space-2);
  right: var(--space-2);
  bottom: max(var(--space-2), env(safe-area-inset-bottom, 0px));
  gap: 6px;
}
.editor.narrow .dock-left { flex: 0 1 auto; min-width: 0; }
.editor.narrow .page-pill,
.editor.narrow .dock-right { flex: 0 0 auto; }
.editor.narrow .pill-btn span { display: none; }
.editor.narrow .pill-btn { width: 36px; height: 34px; padding: 0; justify-content: center; }
.editor.narrow .practice-pill {
  width: auto;
  min-width: 44px;
  min-height: 44px;
  height: auto;
  max-width: 100%;
  gap: 4px;
  padding: 0 9px 0 8px;
}
.editor.narrow .practice-pill span {
  display: inline;
  min-width: 0;
  font-size: var(--text-xs);
}
.editor.narrow .practice-pill.has-menu { padding-right: 6px; }
.editor.narrow .practice-pill .icon:last-child { width: 12px; height: 12px; }
.editor.narrow .ed-stage .pet { width: 52px; height: 52px; }
.editor.narrow .page-pill .icon-btn,
.editor.narrow .zoom-pill .icon-btn { min-inline-size: 28px; min-block-size: 28px; width: 28px; height: 28px; }
.editor.narrow .page-pill .pill-label,
.editor.narrow .zoom-pill .pill-label { min-width: 40px; padding: 0 4px; font-size: var(--text-xs); }

body:has(.editor) #toast { bottom: calc(max(14px, env(safe-area-inset-bottom, 0px)) + 56px); }
body:has(.editor.narrow) #toast { bottom: calc(max(var(--space-2), env(safe-area-inset-bottom, 0px)) + 56px); }
body:not(:has(.scratch-panel:not([hidden]))):has(.editor.narrow:not(.zoom-open):not(.reading) .pet:not([hidden])) #toast { bottom: calc(max(var(--space-2), env(safe-area-inset-bottom, 0px)) + 104px); }

:root[data-theme='dark'] .glyph-line:not(.is-marker) { background: var(--ink-1); }
:root[data-theme='dark'] .glyph-a { color: var(--ink-1); }

.lasso-settings fieldset { min-width: 0; padding: 0 0 8px; margin: 0 0 8px; border: 0; border-bottom: 1px solid var(--line); }
.lasso-settings legend { padding: 0; color: var(--ink-2); font-size: var(--text-s); font-weight: 600; }
.icon-btn.lasso-filtered { color: var(--accent-ink); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent-line); }
.lasso-settings .setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; cursor: pointer; }
.lasso-settings .setting-row strong { font-weight: 500; }

/* ── 顶栏工具开关（图层 / 录音同步 / 标尺 / 放大书写窗 / 演示激光笔） ────── */
.ed-top-actions [data-layers] { position: relative; }
.top-count {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 15px;
  height: 15px;
  padding: 0 4px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--on-accent);
  font: 700 10px/15px var(--font-ui);
  font-style: normal;
  text-align: center;
  box-shadow: 0 1px 3px rgb(0 0 0 / .22);
}
.ed-top-actions [data-audio][aria-pressed='true'],
.ed-top-actions [data-ruler][aria-pressed='true'],
.ed-top-actions [data-zoom-window][aria-pressed='true'],
.ed-top-actions [data-read-laser][aria-pressed='true'] {
  color: var(--accent-ink);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent-line);
}
.ed-top-actions [data-audio].is-recording {
  color: #fff;
  background: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 24%, transparent);
}
.editor.reading [data-layers],
.editor.reading [data-ruler],
.editor.reading [data-zoom-window] { display: none; }
@media (hover: hover) {
  .editor[data-current-tool='laser'] #ink,
  .editor.reading-laser #ink { cursor: none; }
  .editor[data-current-tool='space'] #ink { cursor: ns-resize; }
}

/* ── 数字标尺（GoodNotes 风格半透明绘图尺） ─────────── */
.stage-ruler {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 4;
  border-radius: 9px;
  border-top: 1.5px solid rgba(58, 48, 34, 0.28);
  border-bottom: 1.5px solid rgba(58, 48, 34, 0.28);
  border-left: 1px solid rgba(58, 48, 34, 0.16);
  border-right: 1px solid rgba(58, 48, 34, 0.16);
  background: rgba(255, 252, 246, 0.78);
  backdrop-filter: blur(12px) saturate(1.25);
  -webkit-backdrop-filter: blur(12px) saturate(1.25);
  box-shadow: 0 8px 24px rgba(38, 30, 18, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.65);
  cursor: grab;
  user-select: none;
  touch-action: none;
  will-change: transform;
  transition: box-shadow var(--fast);
}
.stage-ruler.is-dragging {
  cursor: grabbing;
  box-shadow: 0 14px 32px rgba(38, 30, 18, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.7);
}
.stage-ruler.is-snapped {
  border-top-color: color-mix(in oklab, var(--accent) 55%, rgba(58, 48, 34, 0.28));
  border-bottom-color: color-mix(in oklab, var(--accent) 55%, rgba(58, 48, 34, 0.28));
}
:root[data-theme='dark'] .stage-ruler {
  background: rgba(34, 33, 29, 0.80);
  border-top-color: rgba(244, 240, 232, 0.24);
  border-bottom-color: rgba(244, 240, 232, 0.24);
  border-left-color: rgba(244, 240, 232, 0.14);
  border-right-color: rgba(244, 240, 232, 0.14);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.44), inset 0 1px 0 rgba(255, 250, 240, 0.08);
}
:root[data-theme='dark'] .stage-ruler.is-snapped {
  border-top-color: color-mix(in oklab, var(--accent) 65%, rgba(244, 240, 232, 0.24));
  border-bottom-color: color-mix(in oklab, var(--accent) 65%, rgba(244, 240, 232, 0.24));
}
.ruler-ticks {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  pointer-events: none;
}
.ruler-hub {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 4px 2px 6px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line-strong);
  background: var(--surface-1);
  box-shadow: var(--shadow-1);
}
.ruler-angle {
  min-width: 38px;
  height: 24px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  color: var(--ink-1);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition: background var(--fast), color var(--fast);
}
.stage-ruler.is-snapped .ruler-angle { color: var(--accent-ink); }
@media (hover: hover) {
  .ruler-angle:hover { background: var(--surface-3); }
}
.ruler-close {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: var(--ink-3);
  transition: background var(--fast), color var(--fast);
}
.ruler-close .icon { width: 13px; height: 13px; }
@media (hover: hover) {
  .ruler-close:hover { background: var(--surface-3); color: var(--ink-1); }
}
.ruler-handle {
  position: absolute;
  top: 50%;
  width: 28px;
  height: 40px;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  border-radius: 8px;
  cursor: alias;
  background: transparent;
}
.ruler-handle-l { left: 2px; }
.ruler-handle-r { right: 2px; }
.ruler-handle i {
  display: block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.8px solid var(--accent);
  background: var(--surface-1);
  box-shadow: 0 1px 3px rgba(32, 24, 16, 0.22);
  transition: transform var(--fast) var(--ease), background var(--fast);
}
@media (hover: hover) {
  .ruler-handle:hover i { transform: scale(1.22); background: var(--accent-soft); }
}

/* ── 放大书写窗（Zoom Window + 自动推进） ────────────── */
.zoom-focus-frame {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 4;
  border: 1.8px solid var(--accent);
  border-radius: 6px;
  background: color-mix(in oklab, var(--accent) 6%, transparent);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.45), 0 4px 16px rgba(184, 93, 67, 0.16);
  cursor: grab;
  touch-action: none;
  will-change: transform, width, height;
}
.zoom-focus-frame.is-dragging {
  cursor: grabbing;
  background: color-mix(in oklab, var(--accent) 11%, transparent);
}
.zoom-focus-bar {
  position: absolute;
  top: -11px;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  width: 44px;
  height: 18px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  box-shadow: 0 2px 6px rgba(32, 22, 14, 0.24);
}
.zoom-focus-bar span {
  display: block;
  width: 18px;
  height: 2.5px;
  border-radius: 2px;
  background: rgba(255, 253, 248, 0.9);
}
.zoom-focus-advance {
  display: none;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 26%;
  border-left: 1.25px dashed color-mix(in oklab, var(--accent) 65%, transparent);
  background: color-mix(in oklab, var(--accent) 10%, transparent);
  border-radius: 0 4px 4px 0;
  pointer-events: none;
}
.zoom-focus-frame.has-advance .zoom-focus-advance { display: block; }

.zoom-window {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  height: clamp(180px, 27vh, 236px);
  border-top: 1px solid var(--line-strong);
  background: var(--surface-1);
  box-shadow: 0 -10px 30px rgba(32, 26, 18, 0.14);
}
:root[data-theme='dark'] .zoom-window {
  box-shadow: 0 -10px 32px rgba(0, 0, 0, 0.42);
}
.zoom-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  height: 40px;
  padding: 0 10px 0 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  overflow-x: auto;
  scrollbar-width: none;
}
.zoom-head::-webkit-scrollbar { display: none; }
.zoom-head > :not(.spacer) { flex: none; }
.zoom-head > .spacer { flex: 1 1 12px; min-width: 12px; }
.zoom-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-2);
  font-size: var(--text-s);
  font-weight: 600;
}
.zoom-title .icon { width: 16px; height: 16px; color: var(--accent); }
.zoom-nav { display: inline-flex; align-items: center; gap: 3px; }
.zoom-return { gap: 4px; height: 28px; padding: 0 9px; font-size: 12px; }
.zoom-return .icon { width: 14px; height: 14px; }
.zoom-mags > button { min-height: 26px; padding: 0 8px; font-size: 12px; font-variant-numeric: tabular-nums; }
.zoom-adv-chip { min-height: 28px; padding: 0 10px; font-size: 12px; }

.zoom-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--desk);
}
.zoom-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}
.zoom-advance-zone {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  border-left: 1.5px dashed color-mix(in oklab, var(--accent) 52%, transparent);
  background: linear-gradient(90deg, color-mix(in oklab, var(--accent) 9%, transparent), color-mix(in oklab, var(--accent) 4%, transparent));
  pointer-events: none;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 6px 10px;
}
.zoom-advance-zone[hidden] { display: none; }
.zoom-advance-zone span {
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  background: var(--surface-1);
  border: 1px solid var(--accent-line);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 500;
  opacity: 0.85;
}

.editor.zoom-open .stage-dock {
  bottom: calc(clamp(180px, 27vh, 236px) + 12px);
}
.editor.zoom-open .ed-stage .pet { display: none; }
body:has(.editor.zoom-open) #toast {
  bottom: calc(clamp(180px, 27vh, 236px) + 64px);
}
@media (max-width: 640px) {
  .zoom-head { gap: 4px; padding: 0 6px; }
  .zoom-head > .spacer { flex: 1 1 2px; min-width: 2px; }
  .zoom-title { display: none; }
  .zoom-return { padding: 0 6px; min-width: 28px; }
  .zoom-return span { display: none; }
  .zoom-mags > button { padding: 0 6px; font-size: 11.5px; }
  .zoom-adv-chip { padding: 0 8px; font-size: 11.5px; }
}
