/* ---------- rich text editor ---------- */
:root {
  --hl-yellow: #fff1a8; --hl-green: #c9f0d2; --hl-blue: #cfe4ff; --hl-pink: #ffd3e6; --hl-orange: #ffddb8; --hl-gray: #e2e6ec;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --hl-yellow: #5a4a00; --hl-green: #1d4a2b; --hl-blue: #1d3a63; --hl-pink: #5c2442; --hl-orange: #5c3510; --hl-gray: #3a4250;
  }
}
:root[data-theme="dark"] {
  --hl-yellow: #5a4a00; --hl-green: #1d4a2b; --hl-blue: #1d3a63; --hl-pink: #5c2442; --hl-orange: #5c3510; --hl-gray: #3a4250;
}

.rich-editor { display: grid; gap: 8px; min-width: 0; }

.rt-toolbar {
  display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; padding: 6px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius);
}
.rt-group { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.rt-btn { min-width: 44px; min-height: 44px; padding: 0 8px; }
.rt-btn[aria-pressed="true"] { background: var(--brand-soft); border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.rt-select { min-height: 44px; width: auto; max-width: 10.5rem; padding-block: 6px; }
.rt-glyph { font-weight: 700; line-height: 1; }
.rt-b { font-weight: 800; }
.rt-i { font-style: italic; font-family: Georgia, serif; }
.rt-u { text-decoration: underline; }
.rt-s { text-decoration: line-through; }
.rt-glyph-color { border-bottom: 4px solid var(--c-red); padding-bottom: 1px; }
.rt-glyph-mark { background: var(--hl-yellow); padding: 1px 4px; border-radius: 3px; }
.rt-skip { position: absolute; left: -9999px; }
.rt-skip:focus { position: static; }

.rt-pop-wrap { position: relative; display: inline-block; }
.rt-pop {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; display: grid; gap: 8px; width: max-content; max-width: 86vw;
  padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.rt-swatches { display: grid; grid-template-columns: repeat(4, 44px); gap: 6px; }
.rt-swatch { width: 44px; height: 44px; padding: 0; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; }
.rt-swatch:hover { border-color: var(--ink); }
.rt-swatch-clear { min-height: 44px; }

.rich-body {
  --note-size: calc(1.0625rem * var(--note-scale));
  font-size: var(--note-size); line-height: 1.65; min-height: 50dvh; padding: 12px 14px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius);
  overflow-wrap: anywhere; word-break: normal;
}
:root[data-easy-read="true"] .rich-body { --note-size: calc(1.1875rem * var(--note-scale)); }
.rich-body:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.rich-body[data-empty="true"]::before { content: attr(data-placeholder); float: left; height: 0; color: var(--muted); pointer-events: none; }
.rich-body p { margin: 0 0 0.55em; min-height: 1.2em; }
.rich-body h1 { font-size: calc(var(--note-size) * 2); margin: 0.5em 0 0.3em; }
.rich-body h2 { font-size: calc(var(--note-size) * 1.5); margin: 0.5em 0 0.3em; }
.rich-body h3 { font-size: calc(var(--note-size) * 1.2); margin: 0.5em 0 0.3em; }
.rich-body ul, .rich-body ol { margin: 0 0 0.55em; padding-left: 1.7em; }
.rich-body li { margin: 0.1em 0; }
.rich-body blockquote { margin: 0 0 0.55em; padding: 0.1em 0 0.1em 1em; border-left: 4px solid var(--brand); color: var(--muted); }
.rich-body a { color: var(--brand); text-decoration: underline; }
.rich-body code, .rich-body pre { font-family: "Source Code Pro", Consolas, monospace; background: var(--surface-2); border-radius: 4px; padding: 0.05em 0.3em; }
.rich-body pre { padding: 0.6em 0.8em; white-space: pre-wrap; }
.rich-body hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.rich-body table { width: 100%; border-collapse: collapse; table-layout: fixed; margin: 0.4em 0 0.8em; }
.rich-body th, .rich-body td { border: 1px solid var(--line); padding: 0.4em 0.6em; vertical-align: top; text-align: left; overflow-wrap: anywhere; }
.rich-body th { background: var(--surface-2); font-weight: 700; }
.rich-body td p, .rich-body td ul, .rich-body td ol { margin: 0 0 0.3em; }
@media (max-width: 519px) { .rich-body table { font-size: 0.9em; } .rich-body th, .rich-body td { padding: 0.3em 0.4em; } }

@media (max-width: 519px) {
  .rt-toolbar { gap: 4px 8px; }
  .rt-select { max-width: 8.5rem; }
}

/* Docs-style compact bar: dividers between groups, a size stepper, simple menus */
.rt-sep { width: 1px; align-self: stretch; margin: 6px 0; background: var(--line); }
.rt-toolbar { gap: 4px 6px; }
.rt-select { border-color: transparent; background: transparent; }
.rt-select:hover { background: var(--surface); border-color: var(--line); }
.rt-size { display: flex; align-items: center; gap: 2px; }
.rt-size-input { width: 3.1em; min-height: 36px; padding: 2px 4px; text-align: center; }
.rt-row { display: flex; gap: 4px; }
.rt-column { display: grid; gap: 2px; }
.rt-item { justify-content: flex-start; }

/* checklists */
.rich-body ul.checklist { list-style: none; padding-left: 0; }
.rich-body ul.checklist > li { position: relative; padding-left: 1.9em; }
.rich-body ul.checklist > li::before {
  content: ""; position: absolute; left: 0.2em; top: 0.3em; width: 1.05em; height: 1.05em; box-sizing: border-box;
  border: 2px solid var(--muted); border-radius: 4px; background: var(--surface); cursor: pointer;
}
.rich-body ul.checklist > li[data-checked="true"]::before {
  background: var(--brand) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12l5 5 9-10'/%3E%3C/svg%3E") center / 80% no-repeat;
  border-color: var(--brand);
}
.rich-body ul.checklist > li[data-checked="true"] { color: var(--muted); text-decoration: line-through; }

/* ---------- paper pages ---------- */
.rich-desk, .rich-sheet { min-width: 0; }
.rich-sheet { position: relative; container-type: inline-size; }
.rich-breaks { display: none; }
:root[data-pages="true"] .rich-desk {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: clamp(6px, 2vw, 22px) clamp(6px, 2vw, 22px) clamp(14px, 3vw, 32px);
}
:root[data-pages="true"] .rich-sheet {
  max-width: 900px; margin-inline: auto; background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px rgba(0, 0, 0, 0.12);
}
:root[data-pages="true"] .rich-sheet > * { --page-h: calc(100cqw * 1.2941); }
:root[data-pages="true"] .rich-body {
  min-height: calc(var(--pages, 1) * var(--page-h)); box-sizing: border-box;
  padding: clamp(20px, 9cqw, 86px) clamp(18px, 10cqw, 92px);
  border: 0; border-radius: 0; background: transparent;
}
:root[data-pages="true"] .rich-body:focus-visible { outline-offset: -3px; }
:root[data-pages="true"] .rich-breaks { display: block; position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.rich-break { position: absolute; left: 0; right: 0; top: calc(var(--page-h) * var(--i)); height: 0; border-top: 2px dashed var(--line); }
.rich-break span { position: absolute; right: 8px; top: 4px; font-size: 0.75rem; font-weight: 700; color: var(--muted); background: var(--surface); padding: 0 6px; border-radius: 6px; }

@media print {
  .rich-desk { background: none !important; border: 0 !important; padding: 0 !important; }
  .rich-sheet { max-width: none !important; box-shadow: none !important; }
  .rich-breaks { display: none !important; }
  :root[data-pages="true"] .rich-body { min-height: 0 !important; padding: 0 !important; }
  .app-header, .banner, .folders-pane, .list-pane, .rt-toolbar, .editor-bar, .editor-meta, .editor-status, .toasts, .skip-link { display: none !important; }
  .notes { display: block !important; }
  .editor-pane { display: block !important; padding: 0 !important; }
  .editor-title { border: 0; padding: 0; }
  .rich-body { border: 0; min-height: 0; padding: 0; color: #000; background: #fff; }
}
