/* ═══════════════════════════════════════════════════════════════════════════
   EDITOR UI
   Consolidated chrome/layout/notes styles.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ═══════════════════════════════════════════════════════════════════════════
   COMPOSE — Editor
   The writing surface. Premium, quiet, focused.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Scroll container ────────────────────────────────────────────────── */
#editor-scroll {
  flex: 1 1 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Canvas is always the brightest surface — content is the light */
  background: var(--bg-canvas);
}

/* ── Paper — full-surface, no card, clean ────────────────────────────── */
#editor-paper {
  position: relative;
  width: 100%;
  max-width: calc(var(--ed-line-width) + 80px);
  padding: 56px 40px 80px;
  flex: 1;
  min-height: calc(100vh - var(--app-header-h));
  min-height: calc(100svh - var(--app-header-h));
  background: var(--bg-canvas);
}

#editor-column {
  width: 100%;
  max-width: var(--ed-line-width);
  margin: 0 auto;
}

/* ── Desktop and tablet share the same writing-surface spacing ────────── */
@media (min-width: 768px) {
  #editor-scroll { padding: 0 var(--s-generous); }
  #editor-paper  { min-height: auto; }
}

/* ── Mobile: compact padding, no artificial min-height ───────────────── */
@media (max-width: 767px) {
  #editor-scroll {
    padding: 0;
    /* Allow scroll area to fill canvas (canvas has bottom padding for toolbar) */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #editor-paper {
    padding: 24px 20px 48px;
    max-width: 100%;
    /* Remove desktop min-height — flex layout fills the space correctly */
    min-height: unset;
  }
}

/* ── ProseMirror root ────────────────────────────────────────────────── */
.ProseMirror {
  font-family: var(--ed-body-font);
  font-size: var(--ed-font-size);
  line-height: var(--ed-line-height);
  color: var(--ed-text);
  width: 100%;
  max-width: none;
  margin: 0;
  outline: none;
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
  text-rendering: optimizeLegibility;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures contextual;
  hanging-punctuation: first allow-end last;
}

/* Hyphenation off — toggled via appearance panel */
[data-hyphenation="off"] .ProseMirror {
  hyphens: none;
}




/* ── Notes section ───────────────────────────────────────────────────── */
#notes-section {
  width: 100%;
  margin: 3em 0 0;
  padding-top: 0;
  box-sizing: border-box;
}

/* The top rule only appears when there IS content */
#notes-section:not(:empty) {
  border-top: 1px solid var(--border);
  padding-top: 1.5em;
}

#notes-section:empty { display: none; }

.notes-block { margin-bottom: 1.2em; }

.notes-block-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: .8em;
  font-family: var(--font-ui);
}

/* Separator between Footnotes and Endnotes blocks */
.notes-separator {
  height: 1px;
  background: var(--border);
  margin: 1.2em 0;
}

.note-item {
  font-family: var(--ed-body-font);
  font-size: 0.82em;
  color: var(--text-sec);
  line-height: 1.65;
  margin-bottom: 0.7em;
  display: flex;
  gap: 0.5em;
}

.note-item .note-number {
  color: var(--accent);
  font-size: 0.9em;
  flex-shrink: 0;
  min-width: 1.75em;
}

.note-edit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.85em;
  padding: 0 .45em;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 0.9em;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.note-edit-btn:hover,
.note-edit-btn:focus-visible {
  background: color-mix(in srgb, rgba(var(--accent-rgb), .14) 82%, transparent);
  text-decoration: underline;
  outline: none;
}

@media (pointer: coarse) {
  .note-edit-btn {
    min-height: 2.2em;
    min-width: 2.2em;
    padding-inline: 0.55em;
  }
}

/* ── Selection ───────────────────────────────────────────────────────── */
.ProseMirror ::selection {
  background: rgba(var(--accent-rgb), 0.2);
}

/* ── Cursor ──────────────────────────────────────────────────────────── */
.ProseMirror-focused { caret-color: var(--accent); }

/* ── Drag and drop ───────────────────────────────────────────────────── */
.ProseMirror .ProseMirror-gapcursor {
  display: none;
  pointer-events: none;
  position: absolute;
}

.ProseMirror .ProseMirror-gapcursor::after {
  content: '';
  display: block;
  position: absolute;
  top: -2px;
  width: 20px;
  border-top: 2px solid var(--text);
}

.ProseMirror-focused .ProseMirror-gapcursor { display: block; }

/* ── Search highlight — CSS Custom Highlight API ─────────────────────── */
/* These ::highlight() pseudo-elements are painted by the browser as a
   separate layer. Zero DOM mutations inside ProseMirror. */
::highlight(search-results) {
  background-color: rgba(var(--accent-rgb), 0.22);
  color: inherit;
}

::highlight(search-current) {
  background-color: rgba(var(--accent-rgb), 0.55);
  color: inherit;
}

/* ══════════════════════════════════════════════════════════════════════
   PAGE LAYOUT MODE
   The scroll container becomes the "desk" (darker surround).
   The paper card sits centered in it and grows with content.
   ══════════════════════════════════════════════════════════════════════ */

/* Desk — scrolls naturally; items stack from the top */
[data-layout="page"] {
  --page-shell-gutter-inline: 20px;
  --page-shell-gutter-top: 28px;
  --page-shell-gutter-bottom: 84px;
  --page-paper-pad-inline: 75px;
  --page-paper-pad-top: 100px;
  --page-paper-pad-bottom: 120px;
  --page-paper-min-height-offset: 68px;
  --page-content-measure: var(--ed-line-width);
}

[data-layout="page"] #editor-scroll {
  background-color: var(--sidebar-bg);
  padding: var(--page-shell-gutter-top) var(--page-shell-gutter-inline) var(--page-shell-gutter-bottom);
  align-items: center;
  justify-content: flex-start;
}

/* Paper card — one shared tablet/desktop model */
[data-layout="page"] #editor-paper {
  background: var(--page-paper, var(--bg-canvas));
  border-radius: 6px;
  border: 0;
  box-shadow: var(--paper-shadow-light);
  flex: 0 0 auto;
  min-height: calc(100vh - var(--app-header-h) - var(--page-paper-min-height-offset));
  min-height: calc(100svh - var(--app-header-h) - var(--page-paper-min-height-offset));
  width: 100%;
  max-width: calc(var(--page-content-measure) + (var(--page-paper-pad-inline) * 2));
  padding: var(--page-paper-pad-top) var(--page-paper-pad-inline) var(--page-paper-pad-bottom);
}

[data-layout="page"] #editor-column {
  max-width: var(--page-content-measure);
}

/* Mobile */
@media (max-width: 767px) {
  [data-layout="page"] {
    --page-shell-gutter-inline: 12px;
    --page-shell-gutter-top: 18px;
    --page-shell-gutter-bottom: 72px;
    --page-paper-pad-inline: 28px;
    --page-paper-pad-top: 52px;
    --page-paper-pad-bottom: 76px;
    --page-paper-min-height-offset: 52px;
  }
  [data-layout="page"] #editor-paper {
    border-radius: 6px;
  }
}

/* Dark page mode — warm dark surround + slightly raised card */
[data-theme="dark"][data-layout="page"] #editor-scroll {
  background-color: var(--sidebar-bg);
}
[data-theme="dark"][data-layout="page"] #editor-paper {
  background: var(--page-paper-dark, var(--bg-canvas));
  border-color: transparent;
  box-shadow: var(--paper-shadow-dark);
}

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE / TOUCH INTEGRATION
   Editor-specific mobile rules formerly lived in 11-mobile-polish.css.
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  :root {
    --header-row-h: 52px;
    --header-action-size: 40px;
  }

  #editor-scroll {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    scroll-behavior: auto;
  }

  #editor-paper {
    padding-bottom: 80px;
  }

  .ProseMirror {
    font-size: max(var(--ed-font-size), 17px);
    line-height: max(var(--ed-line-height), 1.75);
  }
}

@media (pointer: coarse) {
  #editor-scroll {
    overscroll-behavior-y: contain;
  }
}

:root:is([dir="rtl"]) #main {
  margin-right: 0;
}

:root:is([dir="rtl"]) .ProseMirror {
  direction: rtl;
  text-align: right;
}
