:root {
  /* NotesWeaving: graphite surfaces and mint threads in dark; warm off-white paper tones in light. */
  --bg: #f5f2eb;
  --desk: #e9e5dc;
  --surface: #faf8f3;
  --surface-2: #f0ece4;
  --surface-3: #e6e1d7;
  --fg: #1d1b18;
  --muted: #6b665d;
  --line: #e0dacf;
  --accent: #0e8f79;
  --accent-soft: rgba(14, 143, 121, 0.12);
  --accent-fg: #ffffff;
  --thread: #d4a017;
  --hl: #f2b630;
  --danger: #c93636;
  --ok: #2f9e6a;
  --tag: #7c4dd8;
  --shadow: 0 1px 2px rgba(40, 33, 20, 0.06), 0 8px 24px rgba(40, 33, 20, 0.08);
  --page-shadow: 0 1px 2px rgba(40, 33, 20, 0.10), 0 12px 32px rgba(40, 33, 20, 0.10);
  --graph-bg: #f7f4ee;
  --graph-node: #857e72;
  --graph-link: #cfc8bb; --graph-connect: #d98a0b;
  --graph-tag: #7c4dd8;

  --font-ui: "Atkinson Hyperlegible", "Noto Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Bricolage Grotesque", "Atkinson Hyperlegible", system-ui, sans-serif;
  --page-font: "Atkinson Hyperlegible", "Noto Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --text-scale: 1;
  --tap: 44px;
  --radius: 14px;
  --radius-sm: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1015; --desk: #090b0f; --surface: #151820; --surface-2: #1d212b; --surface-3: #262b37; --fg: #e9ecf2; --muted: #8c94a6;
    --line: #272c38; --accent: #34d3b4; --accent-soft: rgba(52, 211, 180, 0.14); --accent-fg: #04201a; --thread: #f6c453; --hl: #f6c453;
    --danger: #ff7272; --ok: #5fd3a0; --tag: #b794f6; --shadow: 0 1px 2px rgba(0, 0, 0, 0.45), 0 10px 28px rgba(0, 0, 0, 0.4);
    --page-shadow: 0 0 0 1px rgba(255, 255, 255, 0.05), 0 14px 36px rgba(0, 0, 0, 0.5);
    --graph-bg: #10131a; --graph-node: #7f889b; --graph-link: #323848; --graph-tag: #b794f6; --graph-connect: #f5a524;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1015; --desk: #090b0f; --surface: #151820; --surface-2: #1d212b; --surface-3: #262b37; --fg: #e9ecf2; --muted: #8c94a6;
  --line: #272c38; --accent: #34d3b4; --accent-soft: rgba(52, 211, 180, 0.14); --accent-fg: #04201a; --thread: #f6c453; --hl: #f6c453;
  --danger: #ff7272; --ok: #5fd3a0; --tag: #b794f6; --shadow: 0 1px 2px rgba(0, 0, 0, 0.45), 0 10px 28px rgba(0, 0, 0, 0.4);
  --page-shadow: 0 0 0 1px rgba(255, 255, 255, 0.05), 0 14px 36px rgba(0, 0, 0, 0.5);
  --graph-bg: #10131a; --graph-node: #7f889b; --graph-link: #323848; --graph-tag: #b794f6; --graph-connect: #f5a524;
  color-scheme: dark;
}
:root[data-mode="pro"] { --tap: 44px; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: calc(15px * var(--text-scale));
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
#app { height: 100%; display: flex; flex-direction: column; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: 0.45; cursor: default; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.icon { display: inline-flex; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 0.86em; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: 999px; border: 1px solid transparent;
  font-weight: 700; background: var(--surface-2); color: var(--fg);
}
.btn.primary { background: var(--accent); color: var(--accent-fg); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.plain { background: transparent; border-color: var(--line); }
.btn.big { min-height: 56px; padding: 0 28px; font-size: 1.08em; }
.btn.block { width: 100%; justify-content: flex-start; }
.btn:hover { filter: brightness(1.05); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: var(--tap); min-height: var(--tap); padding: 0 8px; border-radius: 12px;
  border: none; background: transparent; color: var(--fg);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn[aria-pressed="true"] { color: var(--accent); }
.icon-btn.fav[aria-pressed="true"] { color: #e0a800; }
.icon-btn.fav[aria-pressed="true"] svg { fill: currentColor; }
.icon-btn.labeled { flex-direction: column; gap: 2px; padding: 4px 8px; font-size: 0.78em; font-weight: 700; }
.btn-label { line-height: 1.1; }

.text-input, .select {
  width: 100%; min-height: var(--tap); padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg); font: inherit;
}
.text-input:focus, .select:focus { outline: 2.5px solid var(--accent-soft); border-color: var(--accent); }

/* ---------- onboarding ---------- */
.onboarding {
  flex: 1; overflow: auto; display: grid; place-items: center;
  padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background:
    repeating-linear-gradient(to bottom, transparent 0 31px, rgba(80, 120, 200, 0.12) 31px 32px),
    var(--bg);
}
.onb-card {
  width: min(640px, 100%); background: var(--surface); border-radius: 22px; padding: clamp(22px, 5vw, 40px);
  box-shadow: var(--page-shadow); display: flex; flex-direction: column; gap: 18px;
}
.onb-mark { width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; background: var(--accent); color: var(--accent-fg); }
.onb-title { font-family: var(--font-display); font-size: clamp(30px, 6vw, 44px); line-height: 1.05; margin: 0; letter-spacing: -0.01em; text-wrap: balance; }
.onb-lead { font-size: 1.12em; margin: 0; color: var(--muted); }
.onb-note { margin: 0; color: var(--muted); }
.onb-actions { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.lang-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.lang-btn {
  min-height: 56px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface);
  font-size: 1.1em; font-weight: 700;
}
.lang-btn[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.mode-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.mode-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px; text-align: start;
  padding: 20px; border-radius: 18px; border: 2px solid var(--line); background: var(--surface);
}
.mode-card strong { font-family: var(--font-display); font-size: 1.35em; }
.mode-card span:last-child { color: var(--muted); }
.mode-card[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.mode-icon { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; background: var(--hl); color: #1c2230; }

/* ---------- library ---------- */
.library { flex: 1; display: grid; grid-template-columns: 268px 1fr; min-height: 0; }
.sidebar {
  background: var(--surface); border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0;
  padding-top: env(safe-area-inset-top);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 10px; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1.3em; letter-spacing: -0.01em; }
.side-scroll { flex: 1; overflow: auto; padding: 4px 10px 12px; display: flex; flex-direction: column; gap: 14px; }
.side-group { display: flex; flex-direction: column; gap: 2px; }
.side-heading { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 4px; color: var(--muted); font-weight: 700; font-size: 0.86em; }
.divider-toggle { border: none; background: none; padding: 0; color: inherit; font-weight: 700; display: inline-flex; gap: 6px; align-items: center; }
.side-item { display: flex; align-items: center; }
.side-row {
  flex: 1; display: flex; align-items: center; gap: 12px; min-height: var(--tap); padding: 0 10px; min-width: 0;
  border: none; border-radius: 10px; background: transparent; text-align: start; font-weight: 700;
}
.side-row:hover { background: var(--surface-2); }
.side-row[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.side-row.add { color: var(--muted); font-weight: 400; }
.side-row.drop { outline: 2px dashed var(--accent); }
.side-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-count { color: var(--muted); font-weight: 400; font-size: 0.86em; font-variant-numeric: tabular-nums; }
.side-more { border: none; background: none; color: var(--muted); width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; opacity: 0.7; }
.side-more:hover { background: var(--surface-2); opacity: 1; }
.side-empty { margin: 0 10px; color: var(--muted); font-size: 0.86em; }
.side-footer { border-top: 1px solid var(--line); padding: 8px 10px max(10px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 2px; }
.subject-dot { width: 12px; height: 12px; border-radius: 4px; flex: none; }

.lib-body { position: relative; min-width: 0; min-height: 0; display: flex; }
.lib-main { flex: 1; overflow: auto; min-width: 0; padding: 0 max(16px, env(safe-area-inset-right)) 40px max(16px, env(safe-area-inset-left)); }
.lib-header {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: max(14px, env(safe-area-inset-top)) 4px 14px;
}
.drawer-btn { display: none; }
.lib-title { font-family: var(--font-display); font-size: clamp(24px, 3.4vw, 34px); margin: 0; letter-spacing: -0.01em; flex: 1 1 200px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-wrap { position: relative; flex: 1 1 240px; max-width: 420px; display: flex; align-items: center; }
.search-wrap .icon { position: absolute; inset-inline-start: 12px; color: var(--muted); pointer-events: none; }
.search-input {
  width: 100%; min-height: var(--tap); border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  padding-inline: 38px 14px; font: inherit; color: var(--fg);
}
.header-actions { display: flex; align-items: center; gap: 6px; }
.new-note { white-space: nowrap; }

.note-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 26px 22px; padding: 6px 4px 20px; }
:root[data-mode="simple"] .note-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.note-card { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.card-open { border: none; background: none; padding: 0; text-align: start; display: flex; flex-direction: column; gap: 8px; }
.thumb {
  position: relative; width: 100%; border-radius: 10px; overflow: hidden; background: #fff;
  box-shadow: var(--page-shadow); transition: transform 0.12s ease;
}
.card-open:hover .thumb { transform: translateY(-2px); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-text {
  position: absolute; inset: 0; padding: 18px 16px; font-size: 10px; line-height: 15px; overflow: hidden; white-space: pre-wrap;
  background-image: repeating-linear-gradient(to bottom, transparent 0 14px, rgba(80, 120, 200, 0.22) 14px 15px);
  background-position: 0 32px;
}
.thumb-band { position: absolute; inset-block: 10px; inset-inline-start: 0; width: 5px; border-radius: 0 3px 3px 0; }
.thumb-star { position: absolute; top: 6px; inset-inline-end: 6px; color: #e0a800; }
.thumb-star svg { fill: currentColor; }
.thumb-badges {
  position: absolute; bottom: 6px; inset-inline-end: 6px; display: flex; gap: 4px; align-items: center;
  background: rgba(255, 255, 255, 0.9); color: #3a4256; border-radius: 999px; padding: 2px 7px; font-size: 11px; font-weight: 700;
}
.note-card.new-card { border: none; background: none; padding: 0; text-align: start; font: inherit; color: inherit; }
.new-card .new-thumb {
  aspect-ratio: 768 / 992; display: grid; place-items: center; color: var(--accent);
  background: var(--accent-soft); box-shadow: none; border: 2px dashed color-mix(in srgb, var(--accent) 55%, transparent);
}
.card-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.new-card .card-title { color: var(--accent); }
.card-meta { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.84em; min-width: 0; }
.card-subject { display: inline-flex; align-items: center; gap: 5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-subject .subject-dot { width: 8px; height: 8px; }
.card-date { white-space: nowrap; }
.card-more { margin-inline-start: auto; border: none; background: none; color: var(--muted); width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; }
.card-more:hover { background: var(--surface-2); }
.empty-state { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 40px 10px; display: grid; place-items: center; gap: 8px; }

.drawer-scrim { display: none; }
@media (max-width: 860px) {
  .library { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 40; inset-block: 0; inset-inline-start: 0; width: min(300px, 86vw);
    transform: translateX(-104%); transition: transform 0.2s ease; box-shadow: var(--shadow);
  }
  [dir="rtl"] .sidebar { transform: translateX(104%); }
  .library.drawer-open .sidebar { transform: none; }
  .library.drawer-open .drawer-scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(10, 14, 22, 0.35); }
  .drawer-btn { display: inline-flex; }
  .lib-title { flex-basis: 50%; }
  .search-wrap { order: 3; flex-basis: 100%; max-width: none; }
  .new-note > span:not(.icon) { display: none; }
  .new-note { padding: 0 14px; }
  .note-grid, :root[data-mode="simple"] .note-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 20px 14px; }
}

/* ---------- editor ---------- */
.editor { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--desk); }
.editor-header {
  display: flex; align-items: center; gap: 6px; background: var(--surface); border-bottom: 1px solid var(--line);
  padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left));
}
[dir="rtl"] .back .icon, [dir="rtl"] .icon-btn.back .icon { transform: scaleX(-1); }
.title-input {
  flex: 1; min-width: 0; border: none; background: transparent; color: var(--fg); font: inherit;
  font-family: var(--font-display); font-weight: 700; font-size: 1.25em; padding: 6px 8px; border-radius: 8px;
}
.title-input:hover { background: var(--surface-2); }
.toolbar {
  display: flex; align-items: center; gap: 10px; overflow-x: auto; scrollbar-width: none;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 6px max(10px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left));
}
.toolbar::-webkit-scrollbar { display: none; }
.toolbar-spacer { flex: 1; }
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: 999px; flex: none; }
.seg {
  display: inline-flex; align-items: center; gap: 6px; min-height: calc(var(--tap) - 6px); padding: 0 14px;
  border: none; border-radius: 999px; background: transparent; font-weight: 700; white-space: nowrap;
}
.seg[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }
.tool-group { display: inline-flex; gap: 2px; flex: none; }
.tool {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: var(--tap); min-height: var(--tap); border: none; border-radius: 12px; background: transparent; padding: 2px 8px;
}
.tool[aria-pressed="true"] { background: var(--hl); color: #1c2230; }
.tool-label { font-size: 0.74em; font-weight: 700; }
.swatches { display: inline-flex; gap: 6px; flex: none; align-items: center; }
.swatch-btn {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--surface); background: var(--sw);
  box-shadow: 0 0 0 1px var(--line); flex: none; padding: 0;
}
:root[data-mode="simple"] .swatch-btn { width: 38px; height: 38px; }
.swatch-btn[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--accent); }
.swatch-btn.small { width: 24px; height: 24px; }
.widths { display: inline-flex; gap: 2px; flex: none; }
.width-btn { width: var(--tap); height: var(--tap); border: none; border-radius: 12px; background: transparent; display: grid; place-items: center; }
.width-btn .dot { background: var(--fg); border-radius: 50%; display: block; }
.width-btn[aria-pressed="true"] { background: var(--surface-2); outline: 2px solid var(--accent); outline-offset: -2px; }
.rec-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: calc(var(--tap) - 4px); padding: 0 12px;
  border-radius: 999px; border: none; background: var(--danger); color: #fff; font-weight: 700; font-variant-numeric: tabular-nums; flex: none;
}

.audio-bar {
  display: flex; align-items: center; gap: 10px; overflow-x: auto; background: var(--surface-2);
  padding: 6px max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left)); border-bottom: 1px solid var(--line);
}
.audio-label { font-weight: 700; white-space: nowrap; }
.audio-time { font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 0.9em; }
.scrub { flex: 1; min-width: 120px; accent-color: var(--accent); }

.scroller { flex: 1; overflow: auto; min-height: 0; padding: 18px 0 60px; overscroll-behavior: contain; }
.stack { position: relative; margin: 0 auto; }
.pages-layer, .images-layer, .ink-layer { position: absolute; inset: 0 0 auto 0; }
.pages-layer { z-index: 1; }
.images-layer { z-index: 2; pointer-events: none; }
.page { position: absolute; left: 0; background: #fff; box-shadow: var(--page-shadow); overflow: hidden; }
.page + .page { border-top: 1px dashed rgba(120, 130, 150, 0.35); }
.page-canvas { position: absolute; left: 0; top: 0; display: block; }
.page-num { position: absolute; bottom: 8px; right: 12px; font-size: 11px; color: rgba(30, 40, 60, 0.35); z-index: 1; font-variant-numeric: tabular-nums; }
.page.dark .page-num { color: rgba(255, 255, 255, 0.35); }
.text-backdrop, .page-text {
  position: absolute; top: 0; left: 0; width: 100%; margin: 0; border: none;
  font-family: var(--page-font); white-space: pre-wrap; overflow-wrap: break-word; word-break: normal;
  letter-spacing: 0; tab-size: 4; text-align: start; box-sizing: border-box;
}
.text-backdrop { z-index: 3; pointer-events: none; color: #1c2230; }
.page-text {
  z-index: 4; background: transparent; color: transparent; resize: none; outline: none; overflow: hidden;
  caret-color: #1c2230;
}
.page-text::placeholder { color: color-mix(in srgb, var(--paper-ink, #1c2230) 45%, transparent); opacity: 1; }
.page-text::selection { background: rgba(47, 91, 211, 0.25); color: transparent; }
.tx-link { color: #2f5bd3; text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 3px; background: rgba(47, 91, 211, 0.08); border-radius: 3px; }
.tx-tag { color: #8a4fd8; background: rgba(138, 79, 216, 0.08); border-radius: 3px; }
.stack[data-mode="draw"] .page-text, .stack[data-mode="select"] .page-text { pointer-events: none; }
.stack[data-mode="select"] .tx-link, .stack[data-mode="select"] .tx-tag { pointer-events: auto; cursor: pointer; }
.stack[data-mode="draw"] { cursor: crosshair; }
.ink-layer { z-index: 5; pointer-events: none; }
.live-layer { position: absolute; left: 0; z-index: 6; pointer-events: none; }
.live-layer[hidden] { display: none; }
.live-canvas { position: absolute; left: 0; top: 0; pointer-events: none; }
.image-item { position: absolute; pointer-events: none; }
.image-item img { width: 100%; height: 100%; display: block; object-fit: fill; user-select: none; -webkit-user-drag: none; border-radius: calc(10px * var(--s, 1)); }
.editor.square-media .image-item img { border-radius: 0; }
/* Continuous view: no page breaks or numbers. */
.editor.continuous .page + .page { border-top: none; }
.editor.continuous .page { box-shadow: none; }
.editor.continuous .pages-layer { box-shadow: var(--page-shadow); }
.editor.continuous .page-num { display: none; }
.stack[data-mode="select"] .images-layer { z-index: 6; pointer-events: none; }
.image-item.editable { pointer-events: auto; cursor: move; outline: 1.5px dashed rgba(47, 91, 211, 0.6); touch-action: none; }
.image-item.selected { outline: 2px solid var(--accent); }
.resize-handle { display: none; position: absolute; right: -9px; bottom: -9px; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; cursor: nwse-resize; }
.image-item.editable .resize-handle { display: block; }
.selection-box { position: absolute; z-index: 7; border: 1.5px dashed var(--accent); border-radius: 6px; background: rgba(47, 91, 211, 0.04); cursor: move; touch-action: none; }
.selection-actions {
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); display: flex; gap: 4px; align-items: center;
  background: var(--surface); border-radius: 999px; padding: 4px 8px; box-shadow: var(--shadow); cursor: default; white-space: nowrap;
}

.suggest-bar, .links-panel { background: var(--surface); border-top: 1px solid var(--line); }
.suggest-bar { display: flex; gap: 8px; align-items: center; overflow-x: auto; padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left)); }
/* Links bar: one slim line under the page. */
.links-panel {
  display: flex; flex-direction: column; gap: 4px; font-size: 0.86em;
  padding: 5px max(10px, env(safe-area-inset-right)) max(5px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}
.links-row { display: flex; align-items: center; gap: 10px; min-height: 34px; min-width: 0; }
.links-summary, .links-add {
  display: inline-flex; align-items: center; gap: 6px; flex: none; white-space: nowrap; font-weight: 700; color: var(--muted);
}
.links-add {
  border: 1px dashed color-mix(in srgb, var(--accent) 50%, transparent); background: transparent; color: var(--accent);
  min-height: 30px; padding: 0 12px; border-radius: 999px;
}
.links-add:hover { background: var(--accent-soft); }
.links-hint { color: var(--muted); opacity: 0.8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 0 1 auto; }
.links-spacer { flex: 1; }
.links-more { border: none; background: var(--surface-2); color: var(--fg); border-radius: 999px; min-height: 30px; padding: 0 10px; font-weight: 700; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; flex: none; }
.counts { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; flex: none; }
.links-row .chip-row { flex: 0 1 auto; min-width: 0; }
.links-panel .chip { min-height: 30px; padding: 0 10px; font-size: 0.95em; }
@media (max-width: 600px) { .links-hint { display: none; } .counts { font-size: 0.92em; } }
.chip-row { display: flex; gap: 8px; overflow-x: auto; align-items: center; padding-bottom: 2px; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.row-label { color: var(--muted); font-size: 0.82em; font-weight: 700; white-space: nowrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; flex: none;
  min-height: 34px; padding: 0 12px; border-radius: 999px; border: none; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 0.9em;
}
.chip.in { background: rgba(224, 102, 43, 0.14); color: #c4561f; }
.chip.ghost { background: var(--surface-2); color: var(--muted); }
.chip.tag { background: rgba(138, 79, 216, 0.12); color: #8a4fd8; }
.chip.new { background: var(--hl); color: #1c2230; }
.chip.mention { background: var(--surface-2); color: var(--fg); gap: 4px; padding-inline-end: 4px; }
.plain-link { border: none; background: none; font-weight: 700; padding: 0; }
.icon-mini { border: none; background: var(--surface); width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: var(--accent); }

/* ---------- graph ---------- */
.graph-view { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--graph-bg); }
.graph-header { display: flex; align-items: center; gap: 6px; background: var(--surface); border-bottom: 1px solid var(--line);
  padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left)); }
.graph-title { flex: 1; margin: 0; font-family: var(--font-display); font-size: 1.25em; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.graph-stage { position: relative; flex: 1; min-height: 0; }
.graph-canvas { position: absolute; inset: 0; touch-action: none; cursor: grab; }
.graph-empty { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; color: var(--muted); text-align: center; padding: 20px; }
.graph-card {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: max(16px, env(safe-area-inset-bottom));
  width: min(520px, calc(100% - 32px)); display: flex; align-items: center; gap: 12px;
  background: var(--surface); border-radius: 18px; padding: 12px 14px; box-shadow: var(--shadow);
}
.card-dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.card-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.card-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-text small { color: var(--muted); }

/* ---------- overlays ---------- */
.overlay-layer { position: fixed; inset: 0; pointer-events: none; z-index: 100; }
.overlay-layer > * { pointer-events: auto; }
.backdrop, .sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 14, 22, 0.4); display: grid; place-items: center; padding: 16px; animation: fade 0.15s ease; }
@keyframes fade { from { opacity: 0; } }
.dialog { width: min(440px, 100%); background: var(--surface); border-radius: 20px; padding: 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.dialog-title { margin: 0; font-family: var(--font-display); font-size: 1.3em; }
.dialog-message { margin: 0; color: var(--muted); white-space: pre-wrap; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.sheet-backdrop { place-items: end center; padding: 0; }
.sheet {
  width: min(720px, 100%); max-height: 88vh; background: var(--surface); border-radius: 22px 22px 0 0;
  display: flex; flex-direction: column; box-shadow: var(--shadow); animation: up 0.2s ease;
  padding-bottom: env(safe-area-inset-bottom);
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@media (min-width: 900px) {
  .sheet-backdrop:has(.sheet.side) { place-items: stretch end; }
  .sheet.side { width: 440px; max-height: none; height: 100vh; height: 100dvh; border-radius: 0; animation: side 0.2s ease; }
  [dir="rtl"] .sheet-backdrop:has(.sheet.side) { place-items: stretch start; }
}
@keyframes side { from { transform: translateX(30px); opacity: 0; } }
.sheet-backdrop.closing { opacity: 0; transition: opacity 0.16s; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 6px 20px; }
.sheet-title { margin: 0; font-family: var(--font-display); font-size: 1.3em; }
.sheet-body { overflow: auto; padding: 6px 20px 24px; flex: 1; min-height: 0; overscroll-behavior: contain; }
.menu-shield { position: fixed; inset: 0; }
.menu {
  position: fixed; min-width: 220px; max-width: min(320px, calc(100vw - 16px)); max-height: 70vh; overflow: auto;
  background: var(--surface); border-radius: 14px; padding: 6px; box-shadow: var(--shadow); border: 1px solid var(--line);
}
.menu-item {
  width: 100%; display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 10px;
  border: none; border-radius: 9px; background: none; text-align: start;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline: none; }
.menu-item.danger { color: var(--danger); }
.menu-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.menu-heading { padding: 8px 10px 2px; font-size: 0.8em; color: var(--muted); font-weight: 700; }
.icon-spacer { width: 18px; flex: none; }
.swatch { width: 16px; height: 16px; border-radius: 50%; flex: none; box-shadow: 0 0 0 1px var(--line); }
.color-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; padding: 6px 10px 8px; }
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(20px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(520px, calc(100% - 32px)); }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 12px; background: #1c2230; color: #fff;
  padding: 12px 16px; border-radius: 14px; box-shadow: var(--shadow); transition: opacity 0.3s, transform 0.3s;
}
:root[data-theme="dark"] .toast { background: #e8ecf4; color: #1c2230; }
.toast.out { opacity: 0; transform: translateY(8px); }
.toast-action { border: none; background: none; color: var(--hl); font-weight: 700; }

/* settings */
.settings { display: flex; flex-direction: column; gap: 22px; }
.set-section { display: flex; flex-direction: column; gap: 8px; }
.set-section h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 4px; font-size: 1em; }
.radio-row, .switch-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); cursor: pointer; }
.switch-row { justify-content: space-between; }
.radio-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.radio-text small { color: var(--muted); }
.radio-row input, .switch-row input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.slider-row { display: flex; align-items: center; gap: 12px; justify-content: space-between; padding: 6px 2px; }
.slider-row input { flex: 1; max-width: 220px; accent-color: var(--accent); }
.seg-row { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: 999px; align-self: flex-start; }
.settings-list { display: flex; flex-direction: column; gap: 8px; }
.settings-list h3 { margin: 12px 0 2px; font-size: 0.95em; color: var(--muted); }
.cloud-box { display: flex; flex-direction: column; gap: 12px; }
.cloud-status { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px; border-radius: 14px; background: var(--accent-soft); }
.cloud-status > div { flex: 1; min-width: 160px; display: flex; flex-direction: column; }
.cloud-status small { color: var(--muted); }
.provider-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.provider-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 12px 14px; text-align: start;
  border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); min-height: 64px;
}
.provider-btn small { color: var(--muted); font-size: 0.8em; }
.provider-name { font-weight: 700; }
.provider-btn[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.dev-setup { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.dev-setup summary { cursor: pointer; font-weight: 700; }
.dev-setup[open] { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.9em; }
.button-col { display: flex; flex-direction: column; gap: 6px; }
.button-col p { margin: 0 0 8px; }

.page-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.page-row { display: flex; align-items: center; gap: 8px; }
.page-open { flex: 1; display: flex; align-items: center; gap: 14px; border: none; background: none; text-align: start; padding: 6px; border-radius: 12px; }
.page-open:hover { background: var(--surface-2); }
.page-thumb { width: 96px; height: auto; border-radius: 4px; box-shadow: var(--page-shadow); background: #fff; }
.page-row-label { display: flex; flex-direction: column; font-weight: 700; }
.page-row-label small { color: var(--muted); font-weight: 400; }
.page-row-actions { display: flex; }
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 10px; }
.sticker { font-size: 36px; height: 64px; border: none; border-radius: 14px; background: var(--surface-2); }
.qs { display: flex; flex-direction: column; gap: 10px; }
.qs-list { display: flex; flex-direction: column; gap: 2px; }
.qs-item { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 10px; border: none; border-radius: 10px; background: none; text-align: start; }
.qs-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qs-item small { color: var(--muted); }
.qs-item[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.fatal { padding: 40px 20px; }

/* Simple mode: bigger, friendlier */
:root[data-mode="simple"] body { font-size: calc(16px * var(--text-scale)); }
:root[data-mode="simple"] .seg { padding: 0 18px; }
:root[data-mode="simple"] .tool { min-width: 60px; }

@media (max-width: 600px) {
  .seg > span:not(.icon) { display: none; }
  .seg { padding: 0 12px; }
  .toolbar { gap: 6px; }
  .header-actions .icon-btn.labeled .btn-label { display: none; }
}
.stack:not([data-mode="text"]) .page-text::placeholder { color: transparent; }
.stack[data-mode="select"] .image-item.editable { opacity: 0.88; }
/* Note card meta wraps instead of squeezing the subject name. */
.card-meta { flex-wrap: wrap; row-gap: 0; }
.card-subject { max-width: 100%; }
/* Simple mode: every tool visible, wrapping onto a second row when needed. */
.toolbar.simple { flex-wrap: wrap; overflow-x: visible; row-gap: 6px; }


/* ---------- opening animation ---------- */
.intro {
  position: fixed; inset: 0; z-index: 500; background: var(--bg); display: grid; place-items: center;
  opacity: 0; transition: opacity 0.25s ease;
}
.intro.show { opacity: 1; }
.intro.out { opacity: 0; transition: opacity 0.32s ease; pointer-events: none; }
.intro-canvas { position: absolute; inset: 0; }
.intro-word {
  position: absolute; left: 0; right: 0; bottom: max(14vh, 90px); display: flex; flex-direction: column; align-items: center; gap: 6px;
  opacity: 0; transform: translateY(8px); animation: introWord 0.6s 0.7s ease forwards; text-align: center; padding: 0 16px;
}
.intro-title { font-family: var(--font-display); font-weight: 700; font-size: clamp(30px, 6vw, 46px); letter-spacing: -0.02em; }
.intro-tag { color: var(--muted); font-size: 1.05em; letter-spacing: 0.04em; }
@keyframes introWord { to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .intro-word { opacity: 1; transform: none; } }

/* ---------- notes map (library) ---------- */
.home-map {
  margin: 2px 4px 22px; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow);
  border: 1px solid var(--line); overflow: hidden; transition: opacity 0.2s;
}
.home-map.dim { opacity: 0.35; }
.map-head { display: flex; align-items: center; gap: 12px; padding: 10px 10px 0 16px; flex-wrap: wrap; }
.map-title { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 700; font-size: 1.05em; }
.map-title .icon { color: var(--accent); }
.map-stats { color: var(--muted); font-size: 0.86em; font-variant-numeric: tabular-nums; flex: 1; }
.map-open {
  display: inline-flex; align-items: center; gap: 4px; border: none; background: var(--accent-soft); color: var(--accent);
  font-weight: 700; border-radius: 999px; min-height: 34px; padding: 0 10px 0 14px; white-space: nowrap;
}
.map-open .icon { transform: scaleX(-1); }
[dir="rtl"] .map-open .icon { transform: none; }
.map-stage {
  position: relative; height: clamp(170px, 26vh, 260px);
  background:
    radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--muted) 22%, transparent) 1px, transparent 0) 0 0 / 22px 22px,
    var(--graph-bg);
}
:root[data-mode="simple"] .map-stage { height: clamp(150px, 22vh, 220px); }
.map-canvas { position: absolute; inset: 0; touch-action: pan-y; }
.brand-mark.big { width: 56px; height: 56px; border-radius: 16px; }

/* ---------- settings (two panes) ---------- */
@media (min-width: 900px) { .sheet.side.wide { width: min(860px, 92vw); } }
.sheet.wide .sheet-body { padding: 0; display: flex; }
.settings2 { flex: 1; display: grid; grid-template-columns: 240px 1fr; min-height: 0; }
.set-nav { border-inline-end: 1px solid var(--line); padding: 8px 10px 20px; overflow: auto; display: flex; flex-direction: column; gap: 2px; }
.set-nav-item {
  display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 0 10px; border: none; border-radius: 12px;
  background: none; text-align: start; font-weight: 700;
}
.set-nav-item:hover { background: var(--surface-2); }
.set-nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.set-nav-icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-2); color: var(--fg); flex: none; }
.set-nav-item[aria-current="page"] .set-nav-icon { background: var(--accent); color: var(--accent-fg); }
.set-chev { display: none; color: var(--muted); transform: scaleX(-1); }
[dir="rtl"] .set-chev { transform: none; }
.set-detail { overflow: auto; min-height: 0; display: flex; flex-direction: column; }
.set-detail-head { display: flex; align-items: center; gap: 4px; padding: 10px 20px 2px; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.set-back { display: none; }
.set-page-title { margin: 0; font-family: var(--font-display); font-size: 1.2em; }
.set-page-body { padding: 8px 20px 28px; display: flex; flex-direction: column; gap: 18px; }
.set-page-body > p { margin: 0; }
.set-section h3 { color: var(--muted); font-size: 0.82em; text-transform: uppercase; letter-spacing: 0.05em; margin: 0 0 6px 4px; }
.set-card { display: flex; flex-direction: column; background: var(--surface-2); border-radius: 14px; overflow: hidden; }
.set-card > * + * { border-top: 1px solid var(--line); }
.set-card .switch-row, .set-card .radio-row { border-radius: 0; background: transparent; min-height: 58px; }
.choice-row, .select-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; flex-wrap: wrap; min-height: 58px; }
.choice-row .seg-row { background: var(--surface); }
.select-row .select { width: auto; min-width: 150px; max-width: 220px; }
.swatch-row { display: flex; gap: 8px; flex-wrap: wrap; }
.switch-row input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; width: 46px; height: 28px; border-radius: 999px; background: var(--line);
  position: relative; cursor: pointer; transition: background 0.15s; flex: none;
}
.switch-row input[type="checkbox"]::after {
  content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.15s;
}
.switch-row input[type="checkbox"]:checked { background: var(--accent); }
.switch-row input[type="checkbox"]:checked::after { transform: translateX(18px); }
[dir="rtl"] .switch-row input[type="checkbox"]:checked::after { transform: translateX(-18px); }
.set-card .slider-row { padding: 10px 12px; }
.key-list { list-style: none; margin: 0; padding: 0; }
.key-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px; }
kbd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.86em; background: var(--surface); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 2px 7px; }
.deleted-row { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 12px; }
.deleted-row .btn { min-height: 36px; padding: 0 14px; }
.empty-mini { display: grid; place-items: center; gap: 4px; color: var(--muted); padding: 30px 0; }
.empty-mini p { margin: 0; }
.danger-text { color: var(--danger); align-self: flex-start; }
.help-list { display: flex; flex-direction: column; gap: 8px; }
.help-item { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; }
.help-item summary { font-weight: 700; cursor: pointer; }
.help-item p { margin: 8px 0 0; color: var(--muted); }
.about-card { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 0 4px; }
.about-card strong { font-family: var(--font-display); font-size: 1.4em; }
.info-row { display: flex; justify-content: space-between; padding: 12px; }
@media (max-width: 899px) {
  .sheet.wide { height: 92vh; height: 92dvh; max-height: none; }
  .settings2 { grid-template-columns: 1fr; }
  .settings2[data-view="nav"] .set-detail { display: none; }
  .settings2[data-view="detail"] .set-nav { display: none; }
  .set-nav { border: none; padding-top: 0; }
  .set-chev { display: inline-flex; margin-inline-start: auto; }
  .set-nav-item[aria-current="page"] { background: none; color: inherit; }
  .set-nav-item[aria-current="page"] .set-nav-icon { background: var(--surface-2); color: var(--fg); }
  .set-back { display: inline-flex; }
  .set-detail-head { padding: 4px 10px 2px; }
  .set-page-body { padding: 8px 16px 28px; }
}
.grid-sentinel { grid-column: 1 / -1; height: 1px; }
.choice-row .seg-row { display: flex; flex-wrap: wrap; max-width: 100%; border-radius: 18px; }
.choice-row .seg { white-space: normal; text-align: center; }
@media (max-width: 600px) { .links-row.has-chips .links-summary > span:not(.icon) { display: none; } }

/* =====================================================================
   NotesWeaving 1.2 look: tree sidebar, folder tiles, card notes, slim
   editor chrome. These rules come last and override the older ones.
   ===================================================================== */
body { letter-spacing: 0.005em; }
.scroller { position: relative; }
.btn.small-btn { min-height: 34px; padding: 0 14px; font-size: 0.9em; }

/* logo */
.logo-lockup { display: block; }
.logo-dots { fill: var(--accent); stroke: var(--accent); }
.logo-dots circle:last-of-type { fill: var(--thread); stroke: none; }
.logo-dots circle { stroke: none; }
.logo-thread { stroke: var(--thread); }
.logo-thread-end { fill: var(--thread); }
.logo-text { font-family: var(--font-display); font-weight: 700; fill: var(--fg); letter-spacing: -0.01em; }
.logo-mark .logo-tile { fill: #10131a; }
.logo-lockup.animate .logo-thread { stroke-dasharray: var(--len, 200); stroke-dashoffset: var(--len, 200); animation: thread 0.9s 0.55s ease-out forwards; }
.logo-lockup.animate .logo-thread-end { opacity: 0; animation: fadein 0.2s 1.4s forwards; }
@keyframes thread { to { stroke-dashoffset: 0; } }
@keyframes fadein { to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .logo-lockup.animate .logo-thread { stroke-dashoffset: 0; } .logo-lockup.animate .logo-thread-end { opacity: 1; } }
.intro-title { display: flex; justify-content: center; }

/* sidebar */
.sidebar { background: var(--surface); }
.brand { padding: 18px 16px 12px; }
.side-row { min-height: 40px; border-radius: 10px; font-weight: 600; gap: 10px; }
.side-row[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.side-row[aria-current="page"] .side-count { color: var(--accent); }
.side-heading { text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.74em; padding: 10px 8px 4px; }
.side-add { border: none; background: none; color: var(--muted); width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; }
.side-add:hover { background: var(--surface-2); color: var(--accent); }
.tree { display: flex; flex-direction: column; gap: 1px; }
.tree-item { display: flex; align-items: center; padding-inline-start: calc(var(--depth, 0) * 16px); position: relative; }
.tree-item::before {
  content: ""; position: absolute; inset-block: 0; inset-inline-start: calc(var(--depth, 0) * 16px - 4px);
  border-inline-start: 1px solid var(--line); display: var(--guide, block);
}
.tree-item[style*="--depth: 0"]::before { display: none; }
.tree-chev { width: 22px; height: 28px; border: none; background: none; color: var(--muted); display: grid; place-items: center; flex: none; padding: 0; border-radius: 6px; }
.tree-chev .icon { transform: rotate(180deg); transition: transform 0.15s; }
.tree-item[aria-expanded="true"] > .tree-chev .icon { transform: rotate(270deg); }
[dir="rtl"] .tree-chev .icon { transform: none; }
[dir="rtl"] .tree-item[aria-expanded="true"] > .tree-chev .icon { transform: rotate(-90deg); }
.tree-chev.empty { pointer-events: none; }
.tree-row { padding-inline-start: 4px; }
.folder-ic { display: inline-flex; }
.side-row.drop, .folder-tile.drop { outline: 2px dashed var(--accent); outline-offset: -2px; }

/* library main */
.lib-header { background: var(--bg); align-items: flex-end; }
.lib-heading { flex: 1 1 220px; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.lib-heading .lib-title { flex: none; }
.crumbs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; color: var(--muted); font-size: 0.88em; }
.crumb { border: none; background: none; color: var(--muted); padding: 2px 4px; border-radius: 6px; display: inline-flex; align-items: center; gap: 4px; font-weight: 600; }
.crumb:hover { color: var(--accent); background: var(--accent-soft); }
.crumb.current { color: var(--fg); }
.crumb-sep { opacity: 0.6; }
.section-title { margin: 6px 4px 12px; font-size: 0.78em; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); font-weight: 700; }
.folder-section { margin-bottom: 18px; }
.folder-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; padding: 0 4px; }
.folder-tile {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 64px; text-align: start;
  border-radius: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--fg);
  transition: border-color 0.15s, transform 0.12s;
}
.folder-tile:hover { border-color: color-mix(in srgb, var(--fc, var(--accent)) 60%, var(--line)); transform: translateY(-1px); }
.folder-tile .tile-ic { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; flex: none;
  color: var(--fc, var(--accent)); background: color-mix(in srgb, var(--fc, var(--accent)) 16%, transparent); }
.folder-tile .tile-text { display: flex; flex-direction: column; min-width: 0; }
.folder-tile strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-tile small { color: var(--muted); }
.folder-tile.add { border-style: dashed; color: var(--accent); }
.folder-tile.add .tile-ic { color: var(--accent); background: var(--accent-soft); }

.bin-reminder {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 4px 16px; padding: 10px 10px 10px 14px;
  border-radius: 14px; background: color-mix(in srgb, var(--thread) 13%, var(--surface)); border: 1px solid color-mix(in srgb, var(--thread) 35%, transparent);
}
.bin-reminder .bin-ic { color: var(--thread); display: inline-flex; }
.bin-reminder .bin-text { flex: 1 1 180px; font-weight: 600; }
.bin-later { min-width: 36px; min-height: 36px; }

/* note cards: a card with the top of the page, then title and details */
.note-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)) !important; gap: 16px !important; }
.note-card {
  position: relative; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s;
}
.note-card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); box-shadow: var(--shadow); transform: translateY(-2px); }
.card-open { gap: 0; width: 100%; }
.note-card .thumb { aspect-ratio: 4 / 3 !important; border-radius: 0; box-shadow: none; border-bottom: 1px solid var(--line); }
.card-open:hover .thumb { transform: none; }
.thumb img { object-position: top center; }
.card-body { display: flex; flex-direction: column; gap: 4px; padding: 10px 40px 12px 12px; min-width: 0; }
[dir="rtl"] .card-body { padding: 10px 12px 12px 40px; }
.card-title { font-weight: 700; }
.card-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.8em; flex-wrap: wrap; }
.card-folder { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-folder::before { content: ""; width: 8px; height: 8px; border-radius: 3px; background: var(--fc); flex: none; }
.card-links { display: inline-flex; align-items: center; gap: 3px; color: var(--accent); font-weight: 700; }
.card-more { position: absolute; bottom: 8px; inset-inline-end: 6px; }
.thumb-star { color: var(--thread); }
.thumb-badges { background: rgba(10, 12, 16, 0.72); color: #fff; }
.note-card.new-card { border-style: dashed; background: transparent; display: flex; flex-direction: column; }
.new-card .new-thumb { aspect-ratio: 4 / 3 !important; border: none !important; background: var(--accent-soft); border-radius: 0; }
.new-card .card-title { color: var(--accent); }
.home-map { border-radius: 18px; }
.map-stage { height: clamp(190px, 28vh, 280px); }

/* editor chrome */
.editor-header { gap: 4px; }
.rel-bar {
  display: inline-flex; align-items: stretch; margin-inline-end: 6px; border-radius: 999px; overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--accent-soft);
}
.rel-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 12px;
  background: transparent; border: 0; color: var(--accent); font-weight: 700; white-space: nowrap;
}
.rel-btn + .rel-btn { border-inline-start: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line)); }
.rel-btn:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.rel-btn.connect-btn { color: var(--graph-connect); }
.link-count, .rel-count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-fg); font-size: 0.78em; display: inline-grid; place-items: center; }
.connect-btn .rel-count { background: var(--graph-connect); color: #1b1203; }
@media (max-width: 1100px) { .rel-label { display: none; } .rel-btn { padding: 0 9px; gap: 4px; } }
@media (max-width: 420px) { .rel-btn { padding: 0 7px; } .rel-count { min-width: 17px; height: 17px; padding: 0 4px; } }
.rel-panel { display: flex; flex-direction: column; gap: 12px; }
.rel-tabs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); }
.rel-tab { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 700; }
.rel-tab[aria-selected="true"] { background: var(--surface); color: var(--fg); box-shadow: 0 1px 3px rgba(0,0,0,0.18); }
.rel-tab[data-tab="connects"][aria-selected="true"] { color: var(--graph-connect); }
.connect-intro { margin: 0; font-size: 0.9em; }
.connect-target { display: grid; grid-template-columns: 1fr 1fr; }
.connect-target .seg { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 0; }
.connect-target .seg span { display: inline !important; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.connect-target .seg[disabled] { opacity: 0.45; }
.chip.connect { display: inline-flex; align-items: center; gap: 2px; padding: 0 4px 0 10px; border-color: color-mix(in srgb, var(--graph-connect) 55%, var(--line)); }
.chip.connect .plain-link { display: inline-flex; align-items: center; gap: 6px; }
.connect-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dot); flex: none; }
.space-row .link-state:not(.add) { color: var(--graph-connect); }
.toolbar { gap: 8px; }
.segmented { background: var(--surface-2); }
.seg[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }
.tool { border-radius: 12px; }
.tool[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 55%, transparent); }
.editor { background: var(--desk); }
.page { box-shadow: var(--page-shadow); }
.page-num { font-size: 10px; }
.page.dark .page-num { color: rgba(255, 255, 255, 0.28); }

/* linking notes panel */
.linking { display: flex; flex-direction: column; gap: 10px; }
.link-search { min-height: 48px; font-size: 1.05em; }
.link-results { display: flex; flex-direction: column; gap: 2px; max-height: 42vh; overflow: auto; }
.link-row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 6px 10px; border: none; border-radius: 12px; background: none; text-align: start; }
.link-row:hover, .link-row:focus-visible { background: var(--surface-2); }
.link-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.link-dot.new { width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; background: var(--hl); color: #1c2230; }
.link-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.link-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-text small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-state { display: inline-flex; align-items: center; gap: 4px; font-size: 0.85em; font-weight: 700; color: var(--muted); white-space: nowrap; }
.link-state.add { color: var(--accent); }
.link-divider { height: 1px; background: var(--line); margin: 4px 0; }
.link-sections { display: flex; flex-direction: column; gap: 14px; }
.link-sec h3 { margin: 0 0 8px; font-size: 0.78em; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.chip-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.link-empty { margin: 4px 2px; }
.link-footer { color: var(--muted); font-size: 0.85em; font-variant-numeric: tabular-nums; border-top: 1px solid var(--line); padding-top: 10px; }
.chip.tag { background: color-mix(in srgb, var(--tag) 16%, transparent); color: var(--tag); }
.tx-tag { color: #8a4fd8; }

/* graph */
.card-dot.square { border-radius: 4px; }

/* bin */
.empty-bin { align-self: flex-start; }
.tx-link { color: var(--paper-link, #0b7a68); background: color-mix(in srgb, var(--paper-link, #0b7a68) 12%, transparent); text-decoration-color: color-mix(in srgb, var(--paper-link, #0b7a68) 60%, transparent); }
.tx-tag { color: var(--paper-tag, #7c4dd8); background: color-mix(in srgb, var(--paper-tag, #7c4dd8) 12%, transparent); }
.note-card.new-card { border: 1.5px dashed color-mix(in srgb, var(--accent) 50%, transparent); }
@media (max-width: 600px) { .editor-header .wide-only { display: none; } .editor-header .fav { min-width: 40px; } }
.link-label { margin: 2px 2px -2px; font-size: 0.78em; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.link-filter { min-height: 42px; }
.progress-toast {
  position: fixed; z-index: 120; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-radius: 14px;
  background: var(--surface); color: var(--fg); border: 1px solid var(--line); box-shadow: var(--shadow); font-weight: 600;
}
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--accent-soft); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* logo: thin yellow thread with a needle */
.logo-needle { fill: var(--needle); }
:root { --needle: #8b8f98; }
:root[data-theme="dark"] { --needle: #cfd5df; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --needle: #cfd5df; } }
.logo-lockup.animate .logo-needle { opacity: 0; transform: translateX(-6px); transform-box: fill-box; animation: needleIn 0.45s 1.25s ease-out forwards; }
@keyframes needleIn { to { opacity: 1; transform: none; } }

/* ---------- v1.4 home: Space on top, Spaces below, + for every note ---------- */
.lib-main { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 0; position: relative; }
.lib-header { position: static; flex: none; }
.lib-split { flex: 1; min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; padding: 0 4px 14px; }
.split-top { min-height: 0; display: flex; }
.split-top .home-map { flex: 1; margin: 0; display: flex; flex-direction: column; min-height: 0; }
.split-top .map-stage, :root[data-mode="simple"] .split-top .map-stage { flex: 1; height: auto; min-height: 140px; }
.split-top .map-head { padding-bottom: 8px; }
.map-off { flex: 1; display: grid; place-content: center; justify-items: center; gap: 6px; color: var(--muted); border: 1px dashed var(--line); border-radius: 18px; }
.split-bottom { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 2px 2px 96px; border-radius: 18px; }
.split-bottom .folder-section { margin-top: 0; }
.split-bottom .section-title:first-child, .split-bottom .folder-section:first-child .section-title { margin-top: 4px; }
.folder-tile.unfiled-tile { --fc: var(--muted); }
.fab {
  position: absolute; inset-inline-end: max(22px, env(safe-area-inset-right)); bottom: max(22px, env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 20px; border: none; display: grid; place-items: center; z-index: 8;
  background: var(--accent); color: var(--on-accent, #0b1512);
  box-shadow: 0 10px 26px color-mix(in srgb, var(--accent) 40%, transparent), 0 2px 6px rgba(0,0,0,0.25);
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}
.fab:hover { transform: translateY(-2px); }
.fab:active { transform: scale(0.95); }
.fab .icon { width: 28px; height: 28px; stroke-width: 2.4; }
.notes-sheet.sheet.side { width: min(760px, 100vw); }
.notes-sheet .sheet-body { display: flex; flex-direction: column; min-height: 0; overflow: hidden; padding-bottom: 0; }
.all-notes { display: flex; flex-direction: column; min-height: 0; flex: 1; gap: 12px; }
.all-notes-bar { display: flex; align-items: center; gap: 12px; }
.all-notes-bar input { flex: 1; }
.all-notes-count { white-space: nowrap; font-variant-numeric: tabular-nums; }
.all-notes-grid-wrap { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; margin: 0 -4px; padding-bottom: 24px; }
.all-notes-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 20px 18px; }
@media (max-width: 720px) {
  .lib-split { grid-template-rows: minmax(190px, 42%) minmax(0, 1fr); gap: 10px; }
  .fab { width: 56px; height: 56px; border-radius: 18px; }
}
@media (max-height: 560px) and (min-width: 721px) { .lib-split { grid-template-rows: minmax(150px, 0.8fr) minmax(0, 1fr); } }
.library, .lib-main { background: var(--bg); }

/* ---------- v1.4 PDF editing ---------- */
.pdf-box { position: absolute; transform-origin: 50% 50%; z-index: 1; pointer-events: none; }
.pdf-marks, .pdf-words, .pdf-objs { position: absolute; inset: 0; }
.pdf-mark { position: absolute; pointer-events: none; }
.pdf-mark.hl { background: var(--mc); mix-blend-mode: multiply; opacity: 0.5; border-radius: 2px; }
.pdf-mark.ul { border-bottom: max(1px, calc(var(--bh) * 0.0012)) solid var(--mc); }
.pdf-mark.st { background: linear-gradient(to bottom, transparent calc(56% - 0.6px), var(--mc) calc(56% - 0.6px), var(--mc) calc(56% + 0.8px), transparent calc(56% + 0.8px)); }
.page.dark .pdf-mark.hl { mix-blend-mode: screen; }
.pdf-w {
  position: absolute; white-space: pre; color: transparent; line-height: 1; transform-origin: 0 0;
  font-family: Helvetica, Arial, "Noto Sans", system-ui, sans-serif; cursor: text; user-select: text; -webkit-user-select: text;
}
.pdf-w::selection { background: transparent; color: transparent; }
.pdf-selhl { position: absolute; inset: 0; pointer-events: none; }
.pdf-sel { position: absolute; background: rgba(47, 111, 224, 0.3); border-radius: 2px; margin: -0.15% -0.2%; padding: 0.15% 0.2%; box-sizing: content-box; }
.stack[data-mode="pdf"] .pdf-box { pointer-events: auto; }
.stack[data-mode="pdf"] .page-text, .stack[data-mode="pdf"] .images-layer { pointer-events: none; }
.stack[data-mode="pdf"] { cursor: text; }
.pdf-obj {
  position: absolute; box-sizing: border-box; line-height: 1.22; font-family: Helvetica, Arial, "Noto Sans", system-ui, sans-serif;
  padding: 0 0.12em; border-radius: 2px; pointer-events: none; white-space: pre-wrap; overflow-wrap: anywhere;
}
.pdf-obj-text { outline: none; min-height: 1.22em; user-select: text; -webkit-user-select: text; }
.stack[data-mode="pdf"] .pdf-obj { pointer-events: auto; outline: 1px dashed color-mix(in srgb, var(--accent) 55%, transparent); cursor: text; }
.stack[data-mode="pdf"] .pdf-obj.editing { outline: 2px solid var(--accent); }
.pdf-obj-tools {
  position: absolute; bottom: calc(100% + 6px); inset-inline-start: -2px; display: none; align-items: center; gap: 2px; padding: 3px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); font-size: 13px; color: var(--fg);
  white-space: nowrap; z-index: 3;
}
.stack[data-mode="pdf"] .pdf-obj.editing .pdf-obj-tools, .stack[data-mode="pdf"] .pdf-obj:hover .pdf-obj-tools { display: inline-flex; }
.pdf-obj-btn, .pdf-obj-grip { border: none; background: none; color: inherit; min-width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-weight: 700; font-family: var(--font-ui, inherit); }
.pdf-obj-grip { cursor: grab; touch-action: none; }
.pdf-obj-btn:hover, .pdf-obj-grip:hover { background: var(--surface-2); }
.pdf-obj-size { position: absolute; top: 0; bottom: 0; inset-inline-end: -5px; width: 10px; cursor: ew-resize; touch-action: none; display: none; }
.stack[data-mode="pdf"] .pdf-obj.editing .pdf-obj-size, .stack[data-mode="pdf"] .pdf-obj:hover .pdf-obj-size { display: block; }
.pdf-obj-size::after { content: ''; position: absolute; top: 50%; left: 3px; width: 4px; height: 18px; margin-top: -9px; border-radius: 3px; background: var(--accent); }
.pdf-bar {
  position: fixed; z-index: 60; display: flex; align-items: center; gap: 4px; padding: 5px; border-radius: 14px;
  background: var(--surface); color: var(--fg); border: 1px solid var(--line); box-shadow: 0 12px 34px rgba(0,0,0,0.28);
  animation: pop 0.12s ease;
}
.pdf-bar-btn { display: inline-flex; align-items: center; gap: 6px; border: none; background: none; color: inherit; min-height: 38px; padding: 0 10px; border-radius: 10px; font: inherit; font-size: 0.92em; font-weight: 600; white-space: nowrap; }
.pdf-bar-btn:hover { background: var(--surface-2); }
.pdf-bar-sep { width: 1px; align-self: stretch; margin: 6px 2px; background: var(--line); }
.pdf-bar-sw { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line); background: var(--sw); padding: 0; flex: none; }
.pdf-bar-sw.small { width: 18px; height: 18px; margin: 0 2px; }
.pdf-tools .tool { gap: 6px; padding-inline: 10px; width: auto; }
.pdf-tools .tool-label { display: inline; font-size: 0.86em; font-weight: 600; }
.pdf-hint { color: var(--muted); font-size: 0.85em; }
@media (max-width: 720px) { .pdf-hint { display: none; } .pdf-bar-btn span { display: none; } .pdf-tools .tool-label { display: none; } }
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(0.98); } }
.pdf-obj.tools-below .pdf-obj-tools { bottom: auto; top: calc(100% + 6px); }
.pdf-objs, .pdf-marks { pointer-events: none; }
@media (max-width: 860px) {
  .sidebar { visibility: hidden; transition: transform 0.2s ease, visibility 0s linear 0.2s; }
  .library.drawer-open .sidebar { visibility: visible; transition: transform 0.2s ease; }
}
@media (max-width: 520px) { .note-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 16px 12px !important; } }



/* ---------- v1.7 writing never selects the page ---------- */
.stack, .stack * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.stack[data-mode="text"] .page-text { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
.stack[data-mode="pdf"] .pdf-words, .stack[data-mode="pdf"] .pdf-w, .pdf-obj-text { -webkit-user-select: text; user-select: text; }
.pdf-words::selection { background: transparent; }
.editor { -webkit-tap-highlight-color: transparent; }
.image-item { contain: layout paint; backface-visibility: hidden; -webkit-backface-visibility: hidden; transform: translateZ(0); }
.image-item.selected { will-change: transform; }
.toolbar .type-here { gap: 6px; padding-inline: 10px; width: auto; }
.toolbar .type-here .tool-label { display: inline; font-size: 0.86em; font-weight: 600; }
.toolbar .type-here[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg, #0b1512); }
@media (max-width: 720px) { .toolbar .type-here .tool-label { display: none; } }

/* ---------- v1.8 writing tools ribbon ---------- */
.rib-tools { background: var(--surface-2); border-radius: 14px; padding: 3px; gap: 1px; }
.rib-tools .tool { position: relative; min-width: 40px; min-height: 40px; border-radius: 11px; }
.rib-tools .tool[aria-pressed="true"] { background: var(--surface); color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,0.25), inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 60%, transparent); }
.rib-dot { position: absolute; bottom: 3px; left: 50%; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--accent); }
.rib-favs { padding: 0 2px; }
.rib-favs .swatch-btn { width: 26px; height: 26px; }
.rib-widths .width-btn { width: 36px; height: 36px; }
.width-btn .dot.ring { background: transparent; border: 2px solid var(--fg); }
.rib-chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line);
  background: transparent; color: var(--fg); font: inherit; font-size: 0.86em; font-weight: 600; white-space: nowrap; flex: none;
}
.rib-chip[aria-pressed="true"] { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.rib-seg { gap: 2px; }
.rib-seg .rib-chip { border: none; }
.rib-type .icon { color: var(--fg); }
.rib-hint { color: var(--muted); font-size: 0.82em; white-space: nowrap; }
.tool-pop-wrap { position: fixed; z-index: 70; animation: pop 0.12s ease; }
.tool-pop {
  width: min(340px, calc(100vw - 16px)); padding: 12px; border-radius: 16px; background: var(--surface); color: var(--fg);
  border: 1px solid var(--line); box-shadow: 0 16px 40px rgba(0,0,0,0.32); display: grid; gap: 12px;
}
.pop-title { font-weight: 700; font-family: var(--font-display); }
.pop-row { display: grid; gap: 6px; }
.pop-label { font-size: 0.8em; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.pop-ctl { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pop-seg { flex-wrap: wrap; }
.pop-seg .rib-chip { border: none; }
.pop-colors { display: grid; grid-template-columns: repeat(8, 30px); gap: 7px; }
.pop-colors .swatch-btn { width: 30px; height: 30px; }
.pop-custom { width: 30px; height: 30px; border-radius: 50%; border: 1.5px dashed var(--muted); display: grid; place-items: center; position: relative; overflow: hidden; color: var(--muted); font-weight: 700; }
.pop-custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.pop-slider { width: 100%; accent-color: var(--accent); }
.pop-toggle { display: flex; align-items: center; gap: 10px; font-size: 0.92em; }
.pop-toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.pop-note { margin: 0; color: var(--muted); font-size: 0.85em; }
@media (max-width: 720px) { .rib-hint { display: none; } }

/* ---------- v1.8 find in note ---------- */
.find-bar {
  display: flex; align-items: center; gap: 8px; padding: 6px max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left));
  background: var(--surface); border-bottom: 1px solid var(--line); color: var(--muted);
}
.find-input { flex: 1; min-width: 0; min-height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--fg); padding: 0 12px; font: inherit; }
.find-count { font-variant-numeric: tabular-nums; font-size: 0.86em; white-space: nowrap; min-width: 3em; text-align: center; }
.icon-btn.small { min-width: 36px; min-height: 36px; }
.find-layer { position: absolute; inset: 0 0 auto 0; height: 0; z-index: 8; pointer-events: none; }
.find-hit { position: absolute; background: rgba(255, 214, 10, 0.42); border-radius: 3px; mix-blend-mode: multiply; }
.page.dark ~ .find-hit, :root[data-theme="dark"] .find-hit { mix-blend-mode: normal; background: rgba(255, 214, 10, 0.35); }
.find-hit.current { background: rgba(255, 140, 0, 0.6); box-shadow: 0 0 0 2px rgba(255, 140, 0, 0.9); }
.toolbar .type-here .tool-label { white-space: nowrap; }
/* v1.9: the browser never zooms the page on its own (two-finger scrolls stay scrolls) */
.editor, .scroller, .editor .toolbar, .editor-header { touch-action: pan-x pan-y; }
.connect-section { margin: 4px 0 18px; }
.connect-section .chip-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.connect-section .chip.connect { padding: 0 12px; gap: 6px; }

/* ---------- v1.12 page setup ---------- */
.page-setup { display: flex; flex-direction: column; gap: 18px; }
.ps-label { margin: 0 2px 8px; font-size: 0.78em; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.ps-templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.ps-template { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 4px; border-radius: 12px; border: 2px solid transparent; background: var(--surface-2); color: var(--fg); font-size: 0.82em; font-weight: 600; }
.ps-template[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.ps-thumb { border-radius: 4px; box-shadow: 0 1px 4px rgba(0,0,0,0.25); max-height: 140px; object-fit: contain; }
.ps-colors { display: flex; flex-wrap: wrap; gap: 8px; }
.ps-sizes { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-bottom: 10px; }
.ps-size { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; min-height: 76px; padding: 8px 4px; border-radius: 12px; border: 2px solid transparent; background: var(--surface-2); color: var(--fg); font-size: 0.8em; font-weight: 600; }
.ps-size[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.ps-size[disabled] { opacity: 0.45; }
.ps-size-box { display: block; border: 1.5px solid currentColor; border-radius: 2px; background: color-mix(in srgb, var(--fg) 8%, transparent); }
.ps-orient { display: grid; grid-template-columns: 1fr 1fr; }
.ps-orient .seg { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.ps-orient .seg span { display: inline !important; }
.ps-land { display: inline-flex; transform: rotate(90deg); }
.ps-note { margin: 8px 2px 0; font-size: 0.86em; }
.page-setup-row { width: 100%; text-align: start; border: 0; background: transparent; color: inherit; cursor: pointer; }

/* ---------- v1.12 Canvas ---------- */
.canvas-view { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--graph-bg, var(--bg)); }
.canvas-pick { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--surface); color: var(--accent); }
.canvas-search { width: 180px; flex: none; min-height: 36px; }
.canvas-words { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.canvas-words::-webkit-scrollbar { display: none; }
.chip.canvas-word { flex: none; display: inline-flex; align-items: center; gap: 6px; }
.chip.canvas-word small { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--surface-2); color: var(--muted); display: inline-grid; place-items: center; font-size: 0.78em; }
.chip.canvas-word[aria-selected="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.chip.canvas-word[aria-selected="true"] small { background: rgba(0,0,0,0.2); color: inherit; }
.canvas-wrap { position: relative; flex: 1; min-height: 0; }
.canvas-stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab; outline: none;
  background-image: radial-gradient(color-mix(in srgb, var(--fg) 14%, transparent) 1px, transparent 1px); background-size: 26px 26px; }
.canvas-stage:active { cursor: grabbing; }
.canvas-board { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.canvas-lines { position: absolute; overflow: visible; pointer-events: none; z-index: 2; }
.canvas-line { fill: none; stroke: #f5c518; stroke-width: 1.5; stroke-linecap: round; stroke-dasharray: 0.1 5; opacity: 0.95; }
.canvas-line-end { fill: #f5c518; }
.canvas-card { position: absolute; left: 0; top: 0; border-radius: 14px; overflow: hidden; background: var(--surface); box-shadow: 0 8px 28px rgba(0,0,0,0.35); border: 1px solid var(--line); }
.canvas-card.center { border: 2px solid var(--accent); box-shadow: 0 10px 40px color-mix(in srgb, var(--accent) 30%, rgba(0,0,0,0.4)); }
.canvas-card-head { display: flex; align-items: center; gap: 8px; height: 48px; padding: 0 10px 0 12px; cursor: move; border-bottom: 1px solid var(--line); }
.canvas-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.canvas-card-title { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.15; }
.canvas-card-title strong, .canvas-card-title small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.canvas-card-title small { color: var(--muted); font-size: 0.78em; }
.canvas-pager { display: inline-flex; align-items: center; gap: 2px; color: var(--muted); }
.canvas-pager .flip { transform: scaleX(-1); }
.canvas-open { min-height: 30px; padding: 0 10px; font-size: 0.85em; }
.canvas-page-wrap { position: relative; cursor: pointer; }
.canvas-page { display: block; width: 100%; height: 100%; }
.canvas-hl { position: absolute; border-radius: 3px; background: rgba(245, 197, 24, 0.16); box-shadow: 0 0 0 1px rgba(245, 197, 24, 0.95); pointer-events: none; }
.canvas-pageno { color: var(--muted); font-size: 0.78em; white-space: nowrap; }
.canvas-card.lite { border-style: dashed; }
.canvas-lite { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px; font-weight: 700; color: var(--accent); }
.canvas-lite[aria-pressed="true"] { background: var(--accent-soft); }
.canvas-info { color: var(--muted); font-size: 0.86em; white-space: nowrap; }
@media (max-width: 600px) { .canvas-info { display: none; } .canvas-lite span { display: none; } }
.canvas-ghost { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px; text-align: center; color: var(--muted); border: 2px dashed var(--line); }
.canvas-empty { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px; color: var(--muted); text-align: center; padding: 24px; }
.canvas-section { margin: 2px 0 18px; }
.canvas-section .section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.canvas-open-all { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); font-weight: 700; }
.canvas-hint { margin: 2px 0 10px; font-size: 0.9em; }
.canvas-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.link-label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.canvas-from-note { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 10px; color: var(--accent); font-weight: 700; font-size: 0.86em; }
@media (max-width: 600px) { .canvas-search { width: 120px; } .canvas-pick { padding: 8px 10px; } }

/* ---------- v1.13 sidebar ---------- */
.side-sep { height: 1px; margin: 8px 10px; background: var(--line); }
.text-style { display: inline-flex; align-items: center; gap: 8px; flex-wrap: nowrap; }
.tool.text-font { display: inline-flex; align-items: center; gap: 6px; padding: 0 10px; }
.text-font-a { font-size: 17px; font-weight: 700; }
.text-size-step { display: inline-flex; align-items: center; border-radius: 12px; background: var(--surface-2); padding: 2px; }
.text-size-step .tool { min-width: 32px; min-height: 34px; padding: 0 6px; font-size: 18px; font-weight: 700; }
.tool.text-size-num { min-width: 40px; font-size: 15px !important; font-variant-numeric: tabular-nums; }
.text-inks { display: inline-flex; align-items: center; gap: 4px; }
.text-ink { width: 24px; height: 24px; }
.text-ink[data-color="auto"] { background: conic-gradient(from 45deg, var(--paper-ink, #1c2230) 0 50%, transparent 0) !important; border: 1.5px solid var(--muted); }
@media (max-width: 820px) { .text-font .tool-label { display: none; } .text-inks .text-ink:nth-child(n+5) { display: none; } }
.side-toggle { width: 100%; border: 0; background: transparent; cursor: pointer; justify-content: flex-start !important; gap: 6px; }
.side-toggle .side-count { margin-inline-start: auto; }
.side-toggle .tree-chev { display: inline-grid; place-items: center; transform: rotate(180deg); transition: transform 0.15s; }
.side-toggle[aria-expanded="true"] .tree-chev { transform: rotate(270deg); }
.recent-section { display: flex; flex-direction: column; gap: 14px; margin: 2px 0 18px; }
.recent-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.recent-canvas, .recent-note { display: flex; align-items: center; gap: 10px; min-height: 58px; padding: 8px 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--fg); text-align: start; cursor: pointer; min-width: 0; }
.recent-canvas:hover, .recent-note:hover { border-color: var(--accent); }
.recent-ic { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: color-mix(in srgb, #f5c518 18%, transparent); color: #d9a600; flex: none; }
.recent-canvas[data-mode="tags"] .recent-ic { background: color-mix(in srgb, var(--graph-tag, #b794f6) 20%, transparent); color: var(--graph-tag, #b794f6); }
.recent-thumb { width: 38px; height: 48px; border-radius: 6px; object-fit: cover; flex: none; background: var(--surface-2); }
.recent-thumb.blank { display: grid; place-items: center; color: var(--muted); }
.recent-canvas .tile-text, .recent-note .tile-text { display: flex; flex-direction: column; min-width: 0; }
.recent-canvas strong, .recent-note strong, .recent-note small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-note small, .recent-canvas small { color: var(--muted); font-size: 0.8em; }

/* ---------- v1.14 canvas ---------- */
.canvas-header .header-actions { gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.canvas-mode .seg, .canvas-lite-seg .seg { display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; min-height: 34px; }
.canvas-mode .seg span, .canvas-lite-seg .seg span { display: inline !important; }
.canvas-word-hub { position: absolute; left: 0; top: 0; height: 56px; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0 18px;
  border-radius: 999px; background: color-mix(in srgb, #f5c518 16%, var(--surface)); border: 1.5px dashed #f5c518; color: var(--fg); font-size: 18px; box-shadow: 0 6px 22px rgba(0,0,0,0.3); box-sizing: border-box; cursor: grab; }
.canvas-word-hub .icon { color: #d9a600; }
.canvas-word-hub.tag { background: color-mix(in srgb, var(--graph-tag, #b794f6) 16%, var(--surface)); border-color: var(--graph-tag, #b794f6); }
.canvas-word-hub.tag .icon { color: var(--graph-tag, #b794f6); }
.canvas-hl.tag { background: rgba(183, 148, 246, 0.16); box-shadow: 0 0 0 1px rgba(183, 148, 246, 0.95); }
.canvas-note { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); margin: 0; padding: 8px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-size: 0.86em; box-shadow: 0 4px 16px rgba(0,0,0,0.25); max-width: calc(100% - 32px); text-align: center; }
.canvas-pick-ic { display: inline-grid; place-items: center; color: var(--accent); }
@media (max-width: 760px) { .canvas-mode .seg span, .canvas-lite-seg .seg span { display: none !important; } .canvas-mode .seg, .canvas-lite-seg .seg { padding: 0 9px; } }

/* ---- 1.15: typed text with its own size, font and colour per stretch ---- */
.page-text { white-space: pre-wrap; overflow-wrap: break-word; cursor: text; }
.page-text:focus { outline: none; }
.page-text .tl, .text-backdrop .bl { min-height: 0; }
/* Every line is exactly one line of the page, whatever the sizes on it: text sits on the line's baseline. */
.page-text .tl > span, .text-backdrop .bl > span { line-height: 0; }
.page-text ::selection, .page-text::selection { background: rgba(47, 91, 211, 0.28); color: transparent; }
.text-backdrop .ph { color: color-mix(in srgb, var(--paper-ink, #1c2230) 45%, transparent); }
.stack:not([data-mode="text"]) .text-backdrop .ph { visibility: hidden; }
.text-font-menu-item { font-size: 15px; }
/* Spool of thread with a needle through it (cartoon style: bold outline). */
.logo-lockup { --spool-line: #3b4357; }
.logo-spool-flange { fill: #eef1f7; stroke: var(--spool-line); }
.logo-spool-body { fill: var(--thread); stroke: var(--spool-line); }
.logo-spool-wind { stroke: color-mix(in srgb, var(--spool-line) 55%, var(--thread)); }
.logo-spool .logo-needle { fill: #eef1f7; stroke: var(--spool-line); }
.logo-loose { fill: none; }
/* The logo is a picture, not text: it can't be selected. */
.logo-lockup, .logo-lockup *, .brand { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.logo-text { pointer-events: none; }

/* Fields: a solid square in the field's colour instead of an icon. */
.field-swatch { display: inline-block; width: 16px; height: 16px; border-radius: 5px; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12); }
.folder-ic .field-swatch { width: 17px; height: 17px; }
.folder-tile .tile-ic .field-swatch { width: 22px; height: 22px; border-radius: 6px; }

/* Tags dropdown: a down chevron when closed, up when open. */
.side-toggle .tree-chev { transform: none; }
.side-toggle .tree-chev .icon { transform: rotate(270deg); transition: transform 0.15s; }
.side-toggle[aria-expanded="true"] .tree-chev .icon { transform: rotate(90deg); }
[dir="rtl"] .side-toggle .tree-chev .icon { transform: rotate(270deg); }
[dir="rtl"] .side-toggle[aria-expanded="true"] .tree-chev .icon { transform: rotate(90deg); }

/* Space map: double tap to open. */
.map-hint { margin-inline-start: auto; font-size: 12px; color: var(--muted); }
.starred-empty { padding: 24px 16px; text-align: center; }

/* Canvas: a note that many pages link to gets the same dotted yellow box around its name as a word. */
.canvas-card.center .canvas-card-title strong { border: 1.5px dashed #f5c518; border-radius: 999px; padding: 2px 12px; background: color-mix(in srgb, #f5c518 14%, transparent); align-self: flex-start; max-width: 100%; box-sizing: border-box; }
.logo-lockup.animate .logo-spool { opacity: 0; transform: translateY(4px); transform-box: fill-box; animation: needleIn 0.45s 1.25s ease-out forwards; }
.logo-lockup.animate .logo-spool .logo-needle { opacity: 1; transform: none; animation: none; }
@media (prefers-reduced-motion: reduce) { .logo-lockup.animate .logo-spool { opacity: 1; transform: none; animation: none; } }
