/* NoteDown app styles. Colors come only from the semantic tokens below,
 * which map the Catppuccin flavor (catppuccin.css) onto roles.
 * Tiers (PROJECT.md → "Device tiers"): phone < 600px, tablet 600–1023px,
 * desktop >= 1024px. */

:root {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --radius: 14px;
  --topbar-h: 56px;
  --toc-w: 280px;
  --fab-size: 56px;
  --tap: 44px;
  /* Safe areas: the Android shell draws edge-to-edge and also injects the
   * insets as --safe-area-inset-* (Capacitor SystemBars), the browser has env(). */
  --safe-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --safe-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  /* QR codes stay dark on light and the camera view stays dark in every flavor. */
  --qr-bg: #eff1f5;
  --qr-fg: #4c4f69;
  --scan-bg: #11111b;
}

[data-flavor] {
  --bg: var(--ctp-mantle);
  --surface: var(--ctp-base);
  --surface-raised: var(--ctp-base);
  --surface-hover: var(--ctp-surface0);
  --border: var(--ctp-surface0);
  --text: var(--ctp-text);
  --text-muted: var(--ctp-subtext0);
  --text-faint: var(--ctp-overlay1);
  --accent: var(--ctp-mauve);
  --on-accent: var(--ctp-base);
  --accent-soft: color-mix(in srgb, var(--ctp-mauve) 16%, transparent);
  --danger: var(--ctp-red);
  --danger-soft: color-mix(in srgb, var(--ctp-red) 14%, transparent);
  --done: var(--ctp-green);
  --link: var(--ctp-blue);
  --code-bg: var(--ctp-surface0);
  /* One color per contact (avatars); text on them. */
  --person-1: var(--ctp-peach);
  --person-2: var(--ctp-teal);
  --person-3: var(--ctp-blue);
  --person-4: var(--ctp-green);
  --person-5: var(--ctp-pink);
  --person-6: var(--ctp-yellow);
  --on-person: var(--ctp-crust);
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 2px 8px rgb(0 0 0 / 0.05);
  --shadow-high: 0 4px 12px rgb(0 0 0 / 0.18), 0 12px 32px rgb(0 0 0 / 0.16);
}
[data-flavor="latte"] {
  --on-accent: #ffffff;
  /* Latte's saturated colors need a darker shade to carry white initials. */
  --person-1: color-mix(in srgb, var(--ctp-peach) 74%, #000);
  --person-2: color-mix(in srgb, var(--ctp-teal) 82%, #000);
  --person-3: color-mix(in srgb, var(--ctp-blue) 88%, #000);
  --person-4: color-mix(in srgb, var(--ctp-green) 80%, #000);
  --person-5: color-mix(in srgb, var(--ctp-pink) 72%, #000);
  --person-6: color-mix(in srgb, var(--ctp-yellow) 70%, #000);
  --on-person: #ffffff;
}

/* The archive keeps the same layout on a tinted background. */
.app[data-view="closed"] {
  --bg: color-mix(in srgb, var(--ctp-mantle) 84%, var(--ctp-teal));
  --surface: color-mix(in srgb, var(--ctp-base) 93%, var(--ctp-teal));
  --border: color-mix(in srgb, var(--ctp-surface0) 80%, var(--ctp-teal));
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 var(--font);
  color: var(--text);
  background: var(--ctp-mantle);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.app { min-height: 100dvh; background: var(--bg); transition: background-color 0.2s; }

/* ---------- icons and buttons ---------- */
.icon { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: var(--tap); height: var(--tap); padding: 0 10px;
  border: 0; border-radius: 999px; background: transparent; cursor: pointer;
  color: var(--text-muted);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn:focus-visible, .fab:focus-visible, .status:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn.small { min-width: 32px; height: 32px; padding: 0 6px; }
.icon-btn.small .icon { width: 18px; height: 18px; }
.icon-btn[aria-pressed="true"] { color: var(--accent); }
.btn-icon { display: contents; }
.btn-label { font-size: 0.9rem; font-weight: 500; }
.count {
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px;
  font-size: 0.78rem; font-weight: 700; line-height: 22px; text-align: center;
  background: var(--surface-hover); color: var(--text-muted);
}
.count.has { background: var(--done); color: var(--on-accent); }

/* ---------- top bar ---------- */
.main { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 4px;
  height: calc(var(--topbar-h) + var(--safe-top)); padding: var(--safe-top) 8px 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--border); }
.title { flex: 1; min-width: 0; margin: 0 6px; font-size: 1.25rem; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#backBtn { display: none; }
.app[data-view="closed"] #backBtn { display: inline-flex; }
.app[data-view="closed"] #archiveBtn, .app[data-view="closed"] .fab { display: none; }

.search {
  display: flex; align-items: center; gap: 6px;
  width: 260px; height: 40px; padding: 0 6px 0 12px;
  border-radius: 999px; background: var(--surface-hover); color: var(--text-muted);
}
.search:focus-within { outline: 2px solid var(--accent); }
.search input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  font: inherit; color: var(--text);
}
.search input::-webkit-search-cancel-button { display: none; }
.search-icon { display: contents; }
.search-icon .icon { width: 18px; height: 18px; }
#searchClose { visibility: hidden; }
.app.has-search #searchClose { visibility: visible; }
#searchBtn { display: none; }

/* ---------- list ---------- */
.list {
  display: flex; flex-direction: column; gap: 12px;
  max-width: 780px; margin: 0 auto;
  padding: 8px 16px calc(var(--fab-size) + 40px + var(--safe-bottom));
}
.note {
  position: relative;
  display: grid; grid-template-columns: 32px 1fr; column-gap: 10px;
  padding: 14px 16px 12px 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  scroll-margin-top: calc(var(--topbar-h) + var(--safe-top) + 12px);
}
.note.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--accent); } to { box-shadow: var(--shadow); } }

.status {
  width: 32px; height: 32px; margin-top: -3px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 999px; background: transparent; cursor: pointer; color: var(--text-faint);
}
.note.lead-heading .status { margin-top: 1px; }
.status .ring { width: 22px; height: 22px; border: 2px solid currentColor; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; }
.status .icon { width: 14px; height: 14px; stroke-width: 3; opacity: 0; }
.status:hover { color: var(--done); }
.status:hover .icon { opacity: 0.6; }
.note.closed .status { color: var(--done); }
.note.closed .status .ring { background: var(--done); border-color: var(--done); }
.note.closed .status .icon { opacity: 1; color: var(--on-accent); }

.note-body { min-width: 0; cursor: text; overflow-wrap: anywhere; }
.note.closed .note-body { cursor: default; }
.note-meta {
  grid-column: 2; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
  margin-top: 8px; font-size: 0.8rem; color: var(--text-faint);
}
.note-meta:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 9px;
  border-radius: 999px; background: var(--surface-hover); color: var(--text-muted); font-weight: 600;
}
.chip .icon { width: 14px; height: 14px; }
.chip.today { background: var(--accent-soft); color: var(--accent); }
.chip.overdue { background: var(--danger-soft); color: var(--danger); }

.note.editing { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }

/* ---------- live-preview editor (CodeMirror, ui/live-preview.js) ---------- */
.editor-host { cursor: text; }
.editor-host .cm-editor { font: inherit; color: inherit; }
.editor-host .cm-scroller { font-family: var(--font); line-height: 1.5; overflow: visible; }
.editor-host .cm-line { padding: 0; }
.cm-lp-h1, .cm-lp-h2, .cm-lp-h3, .cm-lp-h4, .cm-lp-h5, .cm-lp-h6 { font-weight: 700; line-height: 1.3; padding-top: 0.55em !important; padding-bottom: 0.2em !important; }
.cm-line:first-child.cm-lp-h1, .cm-line:first-child.cm-lp-h2, .cm-line:first-child.cm-lp-h3 { padding-top: 0 !important; }
.cm-lp-h1 { font-size: 1.45rem; }
.cm-lp-h2 { font-size: 1.25rem; }
.cm-lp-h3 { font-size: 1.06rem; }
.cm-lp-h4, .cm-lp-h5, .cm-lp-h6 { color: var(--text-muted); }
.cm-lp-quote { border-left: 3px solid var(--border); padding-left: 12px !important; color: var(--text-muted); }
.cm-lp-codeblock { font-family: var(--mono); font-size: 0.88em; background: var(--code-bg); padding: 0 12px !important; }
.cm-lp-bullet { display: inline-block; box-sizing: border-box; padding-right: 0.55em; text-align: right; text-indent: 0; color: var(--text-muted); }
.cm-lp-task { display: inline-block; position: relative; height: 1.2em; vertical-align: top; text-indent: 0; }
.cm-lp-task input.task { left: auto; right: 10px; top: 0.2em; }
.cm-lp-done { color: var(--text-faint); text-decoration: line-through; }
.cm-lp-hr { display: inline-block; width: 100%; height: 0; border-top: 1px solid var(--border); vertical-align: middle; }
.cm-interim { color: var(--text-faint); font-style: italic; }
.editor-host .cm-selectionBackground, .editor-host .cm-focused .cm-selectionBackground { background: var(--accent-soft) !important; }

/* ---------- editing toolbar ---------- */
.toolbar {
  position: fixed; z-index: 25; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; gap: 4px;
  padding: 6px 8px calc(6px + var(--safe-bottom));
  background: var(--ctp-base); border-top: 1px solid var(--ctp-surface0);
  box-shadow: 0 -2px 12px rgb(0 0 0 / 0.08);
}
.toolbar-scroll {
  flex: 1; min-width: 0; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
}
.toolbar-scroll::-webkit-scrollbar { display: none; }
.tool {
  position: relative; flex: none; width: var(--tap); height: var(--tap); border: 0; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: var(--text-muted); cursor: pointer; isolation: isolate;
}
.tool:hover { background: var(--ctp-surface0); color: var(--text); }
.tool.active { color: var(--on-accent); background: var(--danger); }
.tool.active::before {
  content: ""; position: absolute; inset: 0; border-radius: 12px; z-index: -1;
  background: var(--danger); opacity: 0.35; transform: scale(calc(1 + var(--level, 0) * 0.6));
}
.toolbar-done {
  flex: none; height: 38px; padding: 0 16px; border: 0; border-radius: 999px; cursor: pointer;
  background: var(--accent); color: var(--on-accent); font-weight: 650;
}
.app.is-editing .fab { display: none; }
.app.is-editing .list { padding-bottom: 50vh; }
.visually-hidden { position: fixed; bottom: 0; left: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* ---------- dictation (ui/recorder.js) ---------- */
.fab { --level: 0; }
.fab::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%; z-index: -1;
  background: var(--danger); opacity: 0; transition: opacity 0.15s;
}
.app.recording .fab { background: var(--danger); border-radius: 50%; transform: scale(1.12); }
.app.recording .fab::before { opacity: 0.3; transform: scale(calc(1.15 + var(--level) * 0.9)); }
.app.rec-locked .fab { transform: none; }
.fab { touch-action: none; -webkit-touch-callout: none; }
.recorder { position: fixed; z-index: 14; inset: auto 0 0 0; pointer-events: none; }
.recorder > * { pointer-events: auto; }
.rec-preview {
  position: absolute; left: 16px; right: calc(var(--fab-size) + 36px); bottom: calc(88px + var(--safe-bottom));
  max-height: 40dvh; overflow-y: auto; padding: 12px 14px; border-radius: var(--radius);
  background: var(--ctp-base); border: 1px solid var(--ctp-surface0); box-shadow: var(--shadow-high);
  font-size: 1rem; line-height: 1.45; color: var(--text);
}
.rec-preview.placeholder { color: var(--text-faint); font-style: italic; }
.rec-bar {
  display: flex; align-items: center; gap: 10px;
  height: calc(76px + var(--safe-bottom)); padding: 0 calc(var(--fab-size) + 36px) var(--safe-bottom) 16px;
  background: var(--ctp-base); border-top: 1px solid var(--ctp-surface0);
}
.rec-trash { display: none; color: var(--danger); }
.app.rec-locked .rec-trash { display: inline-flex; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s steps(2, start) infinite; flex: none; }
@keyframes blink { to { visibility: hidden; } }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 3.2em; }
.rec-level { flex: 1; min-width: 0; height: 32px; display: flex; align-items: center; gap: 2px; overflow: hidden; }
.rec-level span { flex: 1; min-width: 2px; max-width: 4px; height: 100%; border-radius: 2px; background: var(--accent); transform: scaleY(0.08); transition: transform 0.07s linear; }
.rec-hint { flex: none; position: relative; padding-left: 8px; background: var(--ctp-base); color: var(--text-muted); font-size: 0.9rem; white-space: nowrap; }
.app.rec-locked .rec-hint { display: none; }
.rec-lock {
  --pull: 0;
  position: absolute; right: 20px; bottom: calc(96px + var(--safe-bottom) + var(--pull) * 24px);
  width: var(--fab-size); padding: 10px 0 8px; border-radius: 999px;
  display: flex; justify-content: center;
  background: var(--ctp-base); border: 1px solid var(--ctp-surface0); box-shadow: var(--shadow-high); color: var(--text-muted);
}
.rec-lock span { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.rec-lock .chevron { width: 16px; height: 16px; animation: nudge 1.2s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateY(-3px); } }
.app.rec-locked .rec-lock { display: none; }

/* ---------- multi-select (ui/selection.js) ---------- */
.app.selecting .fab { display: none; }
.app.selecting .note, .app.selecting .note-body { cursor: pointer; -webkit-user-select: none; user-select: none; }
/* A held note shows no text selection or callout on touch screens. */
@media (hover: none) {
  .note:not(.editing) .note-body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
}
.sel-count { flex: 1; min-width: 0; margin: 0 6px; font-size: 1.15rem; font-weight: 650; white-space: nowrap; }
.sel-actions { display: flex; align-items: center; gap: 2px; }
.sel-action {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: var(--tap); height: var(--tap); padding: 0 10px; border: 0; border-radius: 999px;
  background: transparent; color: var(--text); cursor: pointer;
}
.sel-action:hover { background: var(--surface-hover); }
.sel-action:disabled { opacity: 0.35; cursor: default; background: transparent; }
.sel-action[data-action="trash"] { color: var(--danger); }
.sel-label { font-size: 0.9rem; font-weight: 500; }

/* A contextual top bar replaces the normal one (Android pattern): the
 * thumb area at the bottom stays free. */
.app.selecting .topbar { display: none; }
.selectbar {
  display: flex; align-items: center; gap: 4px;
  position: sticky; top: 0; z-index: 10; height: calc(var(--topbar-h) + var(--safe-top)); padding: var(--safe-top) 8px 0;
  background: color-mix(in srgb, var(--accent) 14%, var(--bg)); border-bottom: 1px solid var(--border);
}
.sel-label { display: none; }

/* A selected note only gets the accent border; the whole card toggles it,
 * so the round button keeps its look but shows no close hint. */
.note.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.app.selecting .status:hover { color: var(--text-faint); }
.app.selecting .status:hover .icon { opacity: 0; }
.app.selecting .note.closed .status:hover { color: var(--done); }
.app.selecting .note.closed .status:hover .icon { opacity: 1; }

/* Order dialog for Copy and Merge. */
.dialog-scrim {
  position: fixed; z-index: 45; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom)); background: rgb(0 0 0 / 0.4);
}
.dialog {
  display: flex; flex-direction: column; width: min(460px, 100%); max-height: 100%;
  padding: 20px 16px 12px; border-radius: 18px; background: var(--ctp-base); color: var(--text); box-shadow: var(--shadow-high);
}
.dialog-title { margin: 0 8px; font-size: 1.15rem; }
.dialog-hint { margin: 4px 8px 12px; font-size: 0.88rem; color: var(--text-muted); }
.order-list { flex: 1; min-height: 0; overflow-y: auto; margin: 0; padding: 0; list-style: none; counter-reset: order; }
.order-item {
  counter-increment: order; position: relative;
  display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 0 0 12px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--bg); margin-bottom: 6px;
}
.order-item::before { content: counter(order); flex: none; width: 20px; color: var(--text-faint); font-weight: 700; font-size: 0.85rem; }
.order-item.dragging { z-index: 1; box-shadow: var(--shadow-high); border-color: var(--accent); }
.order-text { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.order-text.plain { font-weight: 500; font-style: italic; color: var(--text-muted); }
.order-grip {
  flex: none; width: var(--tap); height: 50px; border: 0; background: transparent; color: var(--text-faint);
  cursor: grab; touch-action: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px;
}
.order-grip:focus-visible { outline: 2px solid var(--accent); }
.order-item.dragging .order-grip { cursor: grabbing; color: var(--accent); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.btn { height: 40px; padding: 0 18px; border: 0; border-radius: 999px; background: transparent; color: var(--accent); font-weight: 650; cursor: pointer; }
.btn:hover { background: var(--surface-hover); }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Sync & sharing panel ---------- */
/* Centered dialog on tablet and desktop, full-screen sheet on the phone. */
.sheet { width: min(480px, 100%); height: min(680px, 100%); padding: 0; overflow: hidden; }
.sheet-head { flex: none; display: flex; align-items: center; gap: 4px; height: var(--topbar-h); padding: 0 8px; }
.sheet-title { margin: 0; font-size: 1.15rem; outline: none; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 20px calc(20px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 14px; }
.sheet-body > * { flex: none; }
.sheet .btn { height: var(--tap); }
.sheet-foot { flex: none; padding: 10px 20px calc(10px + var(--safe-bottom)); border-top: 1px solid var(--border); }
.foot-actions { display: flex; justify-content: flex-end; gap: 8px; }
.foot-actions .btn { min-width: 112px; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.sheet-text { margin: 0; color: var(--text-muted); font-size: 0.95rem; }
.sheet-text.muted { color: var(--text-faint); }
.sheet-text.center, .qr-name { text-align: center; }
.sheet-section { margin: 8px 4px -6px; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-faint); }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.sheet-actions .btn { width: 100%; }
.sheet-divider { height: 1px; background: var(--border); margin: 4px 0; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.button-row .btn { flex: 1 1 140px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.button-row.center { justify-content: center; }
.button-row.center .btn { flex: 0 1 auto; }
.btn .icon { width: 20px; height: 20px; }
.btn.outline { border: 1px solid var(--border); }
.btn.outline:hover { background: var(--surface-hover); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:disabled:hover { background: transparent; }
.btn.primary:disabled:hover { background: var(--accent); }
.hero {
  align-self: center; display: flex; align-items: center; justify-content: center; width: 72px; height: 72px; margin: 12px 0 4px;
  border-radius: 50%; background: var(--accent-soft); color: var(--accent);
}
.hero .icon { width: 34px; height: 34px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 0.85rem; font-weight: 650; color: var(--text-muted); }
.field-hint { font-size: 0.85rem; color: var(--text-faint); }
.field-error { margin: -6px 0 0; font-size: 0.88rem; color: var(--danger); }
.input {
  width: 100%; height: var(--tap); padding: 0 14px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg); color: var(--text); font: inherit;
}
.input.mono { font-family: var(--mono); font-size: 0.92rem; }
.input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

.key-box {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 6px; padding: 16px 12px; border: 1px solid var(--border);
  border-radius: 12px; background: var(--bg); font-family: var(--mono); font-size: 1.05rem; font-weight: 700; letter-spacing: 0.06em;
  text-align: center; -webkit-user-select: all; user-select: all;
}
.check-row { display: flex; align-items: center; gap: 12px; min-height: var(--tap); cursor: pointer; }
.check-row input { flex: none; width: 22px; height: 22px; margin: 0; accent-color: var(--accent); }

.sync-status { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--bg); font-size: 0.92rem; }
.sync-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--done); }
.sync-status[data-status="syncing"] .sync-dot { background: var(--accent); animation: pulse 0.9s ease-in-out infinite; }
.sync-status[data-status="offline"] .sync-dot { background: var(--text-faint); }
@keyframes pulse { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .sync-status[data-status="syncing"] .sync-dot { animation: none; } }

.sheet-card { margin: 0; padding: 0; list-style: none; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); }
.sheet-row { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 6px 4px 6px 14px; }
.sheet-row + .sheet-row { border-top: 1px solid var(--border); }
.row-icon { flex: none; display: inline-flex; width: 36px; justify-content: center; color: var(--text-muted); }
.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 0.82rem; color: var(--text-faint); }
.avatar {
  flex: none; display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 0.85rem; font-weight: 700;
}

.segmented { display: flex; padding: 3px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); }
.segment {
  flex: 1; height: 38px; border: 0; border-radius: 999px; background: transparent; color: var(--text-muted); font-weight: 650; cursor: pointer;
}
.segment[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.segment:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.qr-wrap { display: flex; justify-content: center; }
.qr { margin: 0; width: min(260px, 100%); text-align: center; }
.qr svg { display: block; width: 100%; height: auto; border-radius: 12px; box-shadow: var(--shadow); }
.qr-bg { fill: var(--qr-bg); }
.qr-fg { fill: var(--qr-fg); }
.qr figcaption { margin-top: 8px; font-size: 0.8rem; color: var(--text-faint); }
.qr-name { margin: -4px 0 0; font-size: 1.15rem; font-weight: 700; }

.scanner-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.scanner {
  position: relative; display: flex; align-items: center; justify-content: center; width: min(280px, 100%); aspect-ratio: 1;
  border-radius: 18px; background: var(--scan-bg); color: var(--ctp-overlay1);
}
.scanner-icon { width: 56px; height: 56px; opacity: 0.35; }
.corner { position: absolute; width: 38px; height: 38px; border: 0 solid var(--accent); }
.corner.tl { top: 18px; left: 18px; border-top-width: 4px; border-left-width: 4px; border-top-left-radius: 10px; }
.corner.tr { top: 18px; right: 18px; border-top-width: 4px; border-right-width: 4px; border-top-right-radius: 10px; }
.corner.bl { bottom: 18px; left: 18px; border-bottom-width: 4px; border-left-width: 4px; border-bottom-left-radius: 10px; }
.corner.br { bottom: 18px; right: 18px; border-bottom-width: 4px; border-right-width: 4px; border-bottom-right-radius: 10px; }
.scanner-hint { margin: 0; text-align: center; color: var(--text-muted); font-size: 0.95rem; }

@media (max-width: 599px) {
  #syncPanel { padding: 0; }
  .sheet { width: 100%; height: 100dvh; max-height: none; border-radius: 0; }
  .sheet-head { height: calc(var(--topbar-h) + var(--safe-top)); padding-top: var(--safe-top); }
}

/* ---------- share dialog, shared marker, sync status ---------- */
.share-list { overflow: hidden; }
.share-row {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 6px 14px;
  border: 0; background: transparent; text-align: left; cursor: pointer;
}
.share-list .share-row + .share-row { border-top: 1px solid var(--border); }
.share-row:hover { background: var(--surface-hover); }
.share-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.share-row.add { border: 1px solid var(--border); border-radius: 12px; color: var(--accent); font-weight: 650; }
.share-row.add .row-icon { color: var(--accent); }
.share-row .row-title { flex: 1; }
.check-box {
  flex: none; display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px;
  border: 2px solid var(--text-faint); border-radius: 7px; color: var(--on-accent);
}
.check-box[data-state="all"], .check-box[data-state="some"] { background: var(--accent); border-color: var(--accent); }
.check-box .icon { width: 16px; height: 16px; stroke-width: 3.2; }

.avatar.person { background: var(--c); color: var(--on-person); }
.avatar.small { width: 22px; height: 22px; font-size: 0.64rem; }
.avatar-stack { display: inline-flex; }
.avatar-stack .avatar { box-shadow: 0 0 0 2px var(--surface); }
.avatar-stack .avatar + .avatar { margin-left: -7px; }
.avatar.more { background: var(--surface-hover); color: var(--text-muted); }
.note.editing .avatar-stack .avatar, .note.selected .avatar-stack .avatar { box-shadow: 0 0 0 2px var(--surface); }
.shared-mark {
  position: relative; display: inline-flex; align-items: center; gap: 6px; padding: 0; border: 0; background: transparent;
  font: inherit; font-weight: 600; color: var(--text-muted);
}
button.shared-mark { cursor: pointer; }
button.shared-mark::after { content: ""; position: absolute; inset: -11px -6px; }
button.shared-mark:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 999px; }

/* Sync status: an icon in the top bar. */
#syncBtn[data-status="syncing"] { color: var(--accent); }
#syncBtn[data-status="offline"] { color: var(--danger); }
#syncBtn .spin { transform-box: fill-box; transform-origin: center; animation: spin 1.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { #syncBtn .spin { animation: none; } }

@media (max-width: 599px) {
  .foot-actions .btn { flex: 1; }
  .app.searching #syncBtn { display: none; }
}

/* ---------- rendered Markdown ---------- */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 1em 0 0.35em; line-height: 1.3; scroll-margin-top: calc(var(--topbar-h) + var(--safe-top) + 16px); }
.md h1 { font-size: 1.45rem; }
.md h2 { font-size: 1.25rem; }
.md h3 { font-size: 1.06rem; }
.md h4, .md h5, .md h6 { font-size: 1rem; color: var(--text-muted); }
.md p { margin: 0.4em 0; }
.md ul, .md ol { margin: 0.35em 0; padding-left: 1.4em; }
.md li { margin: 0.15em 0; }
.md li:has(> input.task, > p:first-child > input.task) { list-style: none; position: relative; margin-left: -1.4em; padding-left: 28px; }
.md input.task {
  appearance: none; -webkit-appearance: none;
  position: absolute; left: 0; top: 0.2em;
  width: 18px; height: 18px; margin: 0;
  border: 2px solid var(--text-faint); border-radius: 5px; cursor: pointer; background: transparent;
  display: inline-grid; place-content: center;
}
.md input.task::before { content: ""; position: absolute; inset: -10px; } /* larger touch target */
.md input.task:checked { background: var(--accent); border-color: var(--accent); }
.md input.task:checked::after { content: ""; width: 9px; height: 5px; border: solid var(--on-accent); border-width: 0 0 2px 2px; transform: translateY(-1px) rotate(-45deg); }
.md li:has(> input.task:checked, > p:first-child > input.task:checked) { color: var(--text-faint); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--text-faint) 60%, transparent); }
.note.closed .md input.task { cursor: default; }
.md a { color: var(--link); }
.md code { font: 0.88em var(--mono); background: var(--code-bg); padding: 0.1em 0.35em; border-radius: 5px; }
.md pre { background: var(--code-bg); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0.5em 0; padding-left: 12px; border-left: 3px solid var(--border); color: var(--text-muted); }

.empty { max-width: 780px; margin: 48px auto; padding: 0 24px; text-align: center; color: var(--text-muted); }

/* ---------- table of contents ---------- */
.toc-panel {
  position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; width: var(--toc-w);
  display: flex; flex-direction: column; padding-top: var(--safe-top);
  background: var(--bg); border-right: 1px solid var(--border);
}
.toc-handle { display: none; }
.toc-head {
  display: flex; align-items: center; justify-content: space-between;
  height: var(--topbar-h); padding: 0 8px 0 18px; flex: none;
}
.toc-title { font-weight: 650; }
.stepper { display: flex; align-items: center; gap: 2px; padding: 2px; border-radius: 999px; background: var(--surface-hover); }
.stepper-value { min-width: 18px; text-align: center; font-size: 0.85rem; font-weight: 700; color: var(--text-muted); }
.stepper .icon-btn:disabled { opacity: 0.35; cursor: default; background: transparent; }
.toc-list { flex: 1; overflow-y: auto; padding: 4px 8px 24px; overscroll-behavior: contain; }
.toc-entry {
  display: block; width: 100%; padding: 6px 10px; border: 0; border-radius: 8px; text-align: left;
  background: transparent; cursor: pointer; color: var(--text); font-size: 0.92rem; line-height: 1.35;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toc-entry:hover { background: var(--surface-hover); }
.toc-entry.level-1 { font-weight: 600; margin-top: 4px; }
.toc-entry.level-2 { padding-left: 24px; color: var(--text-muted); }
.toc-entry.level-3 { padding-left: 38px; color: var(--text-muted); font-size: 0.88rem; }
.toc-entry.level-4, .toc-entry.level-5, .toc-entry.level-6 { padding-left: 52px; color: var(--text-faint); font-size: 0.86rem; }
.toc-entry.plain { font-style: italic; font-weight: 500; color: var(--text-muted); }
.toc-empty { padding: 12px 10px; color: var(--text-faint); font-size: 0.9rem; }
.scrim { display: none; }

/* ---------- FAB, snackbar, menu ---------- */
.fab {
  position: fixed; z-index: 15; right: 20px; bottom: calc(20px + var(--safe-bottom));
  width: var(--fab-size); height: var(--fab-size); border: 0; border-radius: 18px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-high);
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
}
.fab .icon { width: 28px; height: 28px; stroke-width: 2.4; }
.fab:active { transform: scale(0.96); }

.snackbar {
  position: fixed; z-index: 50; left: 16px; bottom: calc(24px + var(--safe-bottom));
  display: flex; align-items: center; gap: 16px; max-width: calc(100% - 32px - var(--fab-size) - 20px);
  padding: 10px 10px 10px 16px; border-radius: 10px;
  background: var(--ctp-text); color: var(--ctp-base); box-shadow: var(--shadow-high); font-size: 0.92rem;
}
.snackbar button { border: 0; background: transparent; color: var(--ctp-mauve); font-weight: 700; cursor: pointer; padding: 6px 8px; border-radius: 6px; }
[data-flavor="latte"] .snackbar button { color: var(--ctp-lavender); }
[data-flavor="latte"] .snackbar { background: #4c4f69; color: #eff1f5; }

.menu {
  position: fixed; z-index: 40; min-width: 220px; max-width: calc(100vw - 16px); padding: 6px;
  max-height: calc(100dvh - 16px); overflow-y: auto;
  background: var(--ctp-base); color: var(--text); border: 1px solid var(--ctp-surface0);
  border-radius: 12px; box-shadow: var(--shadow-high);
}
.menu-section { padding: 8px 10px 4px; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-faint); }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 0 10px;
  border: 0; border-radius: 8px; background: transparent; cursor: pointer; text-align: left; font-size: 0.95rem;
}
.menu-item:hover { background: var(--ctp-surface0); }
.menu-item .check { width: 18px; height: 18px; color: var(--accent); visibility: hidden; }
.menu-item[aria-checked="true"] .check { visibility: visible; }
.menu-sep { height: 1px; margin: 6px 4px; background: var(--ctp-surface0); }

/* ---------- tiers ---------- */
@media (min-width: 600px) {
  .main { margin-left: var(--toc-w); }
  #tocBtn { display: none; }
  .toc-panel { background: var(--bg); }
}
@media (min-width: 600px) and (max-width: 1023px) {
  :root { --toc-w: 248px; }
  .search { width: 190px; }
  .btn-label { display: none; }
}
@media (min-width: 1024px) {
  .topbar { padding-inline: 16px; }
  .list { padding-top: 12px; }
  .selectbar { padding-inline: 16px; }
  .sel-label { display: inline; }
  /* On the desktop the toolbar floats over the list column. */
  .toolbar {
    left: calc(var(--toc-w) + (100% - var(--toc-w)) / 2); right: auto; bottom: 20px; transform: translateX(-50%);
    width: min(720px, calc(100% - var(--toc-w) - 48px)); border: 1px solid var(--ctp-surface0); border-radius: 16px; box-shadow: var(--shadow-high);
    padding-bottom: 6px;
  }
}
@media (min-width: 600px) {
  .rec-preview { left: calc(var(--toc-w) + 16px); max-width: 640px; }
  .rec-bar { padding-left: calc(var(--toc-w) + 16px); }
}
@media (max-width: 599px) {
  .btn-label { display: none; }
  .topbar { padding-inline: 4px; gap: 0; }
  .search { display: none; }
  #searchBtn { display: inline-flex; }
  .app.searching .search { display: flex; flex: 1; width: auto; }
  .app.searching .title, .app.searching #searchBtn, .app.searching #sortBtn, .app.searching #archiveBtn,
  .app.searching #moreBtn, .app.searching #tocBtn, .app.searching #backBtn { display: none; }
  .app.searching #searchClose { visibility: visible; }
  .list { padding-left: 12px; padding-right: 12px; gap: 10px; }
  .note { padding: 12px 14px 10px 8px; column-gap: 8px; }
  .count { margin-left: -14px; margin-top: -18px; min-width: 18px; height: 18px; line-height: 18px; font-size: 0.7rem; padding: 0 5px; }
  #archiveBtn { padding: 0 6px; }

  .scrim { display: block; position: fixed; inset: 0; z-index: 19; background: rgb(0 0 0 / 0.35); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
  .app.toc-open .scrim { opacity: 1; pointer-events: auto; }
  /* The contents open as a bottom sheet, within thumb reach. */
  .toc-panel {
    transition: transform 0.25s ease; box-shadow: var(--shadow-high); background: var(--ctp-base);
    top: auto; right: 0; width: auto; height: min(72dvh, 600px);
    border-right: 0; border-radius: 18px 18px 0 0; padding-top: 0; padding-bottom: var(--safe-bottom);
    transform: translateY(105%);
  }
  .app.toc-open .toc-panel { transform: none; }
  .toc-handle { display: block; width: 40px; height: 5px; margin: 8px auto 0; border-radius: 999px; background: var(--ctp-surface2); flex: none; }
  .toc-head { height: 48px; }
}
@media (hover: none) {
  .icon-btn:hover, .toc-entry:hover, .menu-item:hover { background: transparent; }
  .status:hover { color: var(--text-faint); }
  .status:hover .icon { opacity: 0; }
  .note.closed .status:hover { color: var(--done); }
  .note.closed .status:hover .icon { opacity: 1; }
}
