/*
 * editor.css — the typed view: a sheet of plain paper with the margin rule,
 * the formatting tray, the margin flags and the selection popover.
 * Built by js/editor.js. Colors come from tokens.css only.
 */

/* ------------------------------ sheet ----------------------------- */
/* The host is the scroll container; #nb-stage positions it. */
.nb-ed-host {
  position: absolute; inset: 0;
  overflow-x: hidden; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: var(--desk);
}

.nb-ed-well {
  min-height: 100%;
  display: flex; flex-direction: column;
  padding: 28px 32px 48px;
}

/*
 * --nb-ed-margin is a share of the sheet's width. It is only used on the
 * sheet's own children, where a percentage means "of the sheet", so the
 * rule, the gutter and the text always agree.
 */
.nb-ed-sheet {
  --nb-ed-margin: clamp(44px, 14%, 128px);
  position: relative;
  flex: 1 0 auto;
  width: 100%; max-width: 920px; margin-inline: auto;
  display: flex; flex-direction: column;
  background: var(--paper);
  border-radius: 3px;
  box-shadow: var(--shadow-paper);
}
.nb-ed-sheet::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: var(--nb-ed-margin);
  width: 1.5px; background: var(--margin-rule);
  pointer-events: none; z-index: 1;
}

.nb-ed-head {
  min-height: 112px;
  padding: 24px 24px 14px calc(var(--nb-ed-margin) + 18px);
  display: flex; flex-direction: column; justify-content: flex-end;
  border-bottom: 1px solid var(--feint);
}

/* ------------------------------ gutter ---------------------------- */
.nb-ed-gutter {
  position: absolute; left: 0; top: 0; bottom: 0; width: var(--nb-ed-margin);
  pointer-events: none; z-index: 2;
}
/* the flags of one line sit beside each other, the earliest at the right */
.nb-ed-flags {
  position: absolute; left: 0; right: 8px;
  display: flex; flex-direction: row-reverse; align-items: flex-end; gap: 4px;
  pointer-events: none;
}
.nb-ed-flags > .nb-flag { pointer-events: auto; }

/* ------------------------------- text ----------------------------- */
/*
 * The text is as wide as the sheet, so a press anywhere on the paper puts
 * the caret into the nearest line. The padding on the right keeps the
 * measure at 68 characters.
 */
.nb-ed-body {
  position: relative;
  flex: 1 0 auto;
  min-height: 320px;
  padding: 20px max(24px, calc(100% - var(--nb-ed-margin) - 18px - 68ch)) 64px calc(var(--nb-ed-margin) + 18px);
  font: 400 var(--fs-read)/27px var(--font-body);
  color: var(--text);
  caret-color: var(--accent);
  overflow-wrap: anywhere;
  -webkit-user-select: text; user-select: text;
  outline: none;               /* the caret shows where the focus is */
  cursor: text;
}
.nb-ed-body:focus-visible { outline: none; }

/* No offsets: the placeholder sits where the first line starts. */
.nb-ed-body.is-empty::before {
  content: attr(data-placeholder);
  position: absolute;
  color: var(--text-3);
  pointer-events: none;
}

.nb-ed-body > p,
.nb-ed-body > div { margin: 0 0 10px; min-height: 27px; }
.nb-ed-body h1 {
  margin: 28px 0 10px;
  font: 600 var(--fs-head)/32px var(--font-display);
  letter-spacing: -0.01em;
}
.nb-ed-body h2 { margin: 26px 0 8px; font: 600 20px/27px var(--font-body); }
.nb-ed-body h3 { margin: 20px 0 6px; font: 600 var(--fs-read)/27px var(--font-body); }
.nb-ed-body > :first-child { margin-top: 0; }

.nb-ed-body blockquote {
  margin: 0 0 10px; padding: 0 0 0 16px; min-height: 27px;
  border-left: 1px solid var(--hairline-strong);
  color: var(--text-2);
}
/* quotes that follow each other share one rule */
.nb-ed-body blockquote + blockquote { margin-top: -10px; padding-top: 10px; }

.nb-ed-body b, .nb-ed-body strong { font-weight: 700; }
.nb-ed-body a { color: var(--accent); text-underline-offset: 3px; }
.nb-ed-body mark {
  background: var(--marker); color: inherit;
  border-radius: 2px;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
/*
 * Browsers keep the look of text they merge from another block with inline
 * styles. The note's own styles decide how text looks.
 */
.nb-ed-body span[style], .nb-ed-body font {
  font-family: inherit !important; font-size: inherit !important;
  line-height: inherit !important; color: inherit !important;
}

/* ------------------------------ lists ----------------------------- */
.nb-ed-body ul, .nb-ed-body ol { list-style: none; margin: 0 0 10px; padding: 0; }
.nb-ed-body li { position: relative; margin: 0 0 6px; padding: 0 0 0 30px; min-height: 27px; }
.nb-ed-body li:last-child { margin-bottom: 0; }
.nb-ed-body li[data-level="1"] { margin-left: 28px; }
.nb-ed-body li[data-level="2"] { margin-left: 56px; }
.nb-ed-body li[data-level="3"] { margin-left: 84px; }
.nb-ed-body li[data-level="4"] { margin-left: 112px; }
.nb-ed-body li::before { position: absolute; left: 0; top: 0; color: var(--text-2); }

/* bullets: filled, ring, dash, by depth */
.nb-ed-body ul:not(.nb-todo) > li::before {
  content: ""; left: 9px; top: 11px; width: 6px; height: 6px;
  border-radius: 50%; background: var(--text-2);
}
.nb-ed-body ul:not(.nb-todo) > li[data-level="1"]::before,
.nb-ed-body ul:not(.nb-todo) > li[data-level="3"]::before {
  background: transparent; box-shadow: inset 0 0 0 1.5px var(--text-2);
}
.nb-ed-body ul:not(.nb-todo) > li[data-level="2"]::before,
.nb-ed-body ul:not(.nb-todo) > li[data-level="4"]::before {
  top: 13px; width: 8px; height: 2px; border-radius: 1px;
}

/*
 * Numbers. The list is flat and depth is an attribute, so every depth has
 * its own counter; an item starts the counters of the depths below it again.
 */
.nb-ed-body ol { counter-reset: nb-ed-0 nb-ed-1 nb-ed-2 nb-ed-3 nb-ed-4; }
.nb-ed-body ol > li { counter-increment: nb-ed-0; counter-reset: nb-ed-1 nb-ed-2 nb-ed-3 nb-ed-4; }
.nb-ed-body ol > li[data-level="1"] { counter-increment: nb-ed-1; counter-reset: nb-ed-2 nb-ed-3 nb-ed-4; }
.nb-ed-body ol > li[data-level="2"] { counter-increment: nb-ed-2; counter-reset: nb-ed-3 nb-ed-4; }
.nb-ed-body ol > li[data-level="3"] { counter-increment: nb-ed-3; counter-reset: nb-ed-4; }
.nb-ed-body ol > li[data-level="4"] { counter-increment: nb-ed-4; counter-reset: none; }
.nb-ed-body ol > li::before { content: counter(nb-ed-0) "."; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nb-ed-body ol > li[data-level="1"]::before { content: counter(nb-ed-1, lower-alpha) "."; }
.nb-ed-body ol > li[data-level="2"]::before { content: counter(nb-ed-2, lower-roman) "."; }
.nb-ed-body ol > li[data-level="3"]::before { content: counter(nb-ed-3) "."; }
.nb-ed-body ol > li[data-level="4"]::before { content: counter(nb-ed-4, lower-alpha) "."; }

/* to-do items: a drawn box, ticked when done */
.nb-ed-body ul.nb-todo > li { padding-left: 34px; }
.nb-ed-body ul.nb-todo > li::before {
  content: ""; left: 0; top: 2.5px; width: 22px; height: 22px;
  border: 1.5px solid var(--text-3); border-radius: 6px;
  background: transparent;
  cursor: pointer;
  transition: background-color 120ms var(--ease), border-color 120ms var(--ease);
}
.nb-ed-body ul.nb-todo > li::after {
  content: ""; position: absolute; left: 8px; top: 6px; width: 6px; height: 11px;
  border: solid var(--on-ink); border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  opacity: 0; pointer-events: none;
}
.nb-ed-body ul.nb-todo > li[data-checked="true"] { color: var(--text-3); text-decoration: line-through; }
.nb-ed-body ul.nb-todo > li[data-checked="true"]::before { background: var(--ink); border-color: var(--ink); }
.nb-ed-body ul.nb-todo > li[data-checked="true"]::after { opacity: 1; }

/* ----------------------------- pictures --------------------------- */
.nb-ed-body p.nb-img {
  margin: 8px 0 14px; min-height: 0;
  -webkit-user-select: none; user-select: none;
  cursor: pointer;
}
.nb-ed-body p.nb-img img {
  display: block; max-width: 100%; height: auto;
  border-radius: 2px;
  box-shadow: 0 0 0 1px var(--hairline-strong);
}
/* a picture whose file is gone still takes its place */
.nb-ed-body p.nb-img img:not([src]) { width: 240px; height: 120px; background: var(--track); }
.nb-ed-body p.nb-img.is-selected img { outline: 2px solid var(--accent); outline-offset: 3px; }
.nb-ed-body p.nb-img[data-caption]::after {
  content: attr(data-caption);
  display: block; margin-top: 8px;
  font: 400 12px/1.4 var(--font-util); color: var(--text-3);
}

/* ------------------------------- tray ----------------------------- */
/* Same tray as the written view. The app's toolbar row draws the hairline under it. */
.nb-ed-tray {
  display: flex; align-items: center;
  min-height: 54px; min-width: 0;
  padding: 5px 12px;
  background: var(--chrome);
}
.nb-ed-tray__scroll {
  flex: 1 1 auto; min-width: 0;
  display: flex; align-items: center;
  overflow-x: auto; overflow-y: hidden;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.nb-ed-tray__scroll::-webkit-scrollbar { display: none; }
.nb-ed-tray__grp, .nb-ed-tray__end { display: flex; align-items: center; flex: none; }
.nb-ed-tray__end { margin-left: auto; padding-left: 8px; }
/* undo and redo stay in reach; a rule says that tools lie under them */
.nb-ed-tray.is-clipped .nb-ed-tray__end { box-shadow: -1px 0 0 var(--hairline-strong); margin-left: 4px; }
/* more tools lie to the right: the row fades out until it is scrolled to its end (the mask is alpha only, not a color) */
.nb-ed-tray.is-clipped:not(.is-at-end) .nb-ed-tray__scroll {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
}
/* the ring stays inside the button, where the scrolling row cannot cut it off */
.nb-ed-tray .nb-iconbtn:focus-visible, .nb-ed-style:focus-visible { outline-offset: -2px; }

.nb-ed-style {
  min-height: var(--tap); min-width: 124px;
  padding: 0 8px 0 12px;
  display: inline-flex; align-items: center; justify-content: space-between; gap: 4px;
  border: 0; border-radius: var(--r-m);
  background: transparent; color: var(--text);
  font: 500 var(--fs-body)/1 var(--font-body); white-space: nowrap;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
.nb-ed-style:hover { background: var(--hover); }
.nb-ed-style:active, .nb-ed-style[aria-expanded="true"] { background: var(--track); }
.nb-ed-style:disabled { opacity: 0.35; pointer-events: none; }
.nb-ed-style .nb-icon { color: var(--text-2); }

/* ------------------------ selection popover ----------------------- */
.nb-popover.nb-ed-selpop { border-radius: 14px; }
.nb-ed-selpop__row { display: flex; align-items: center; gap: 2px; padding: 4px; }
.nb-ed-selpop__main, .nb-ed-selpop__opt {
  min-height: var(--tap);
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; border-radius: var(--r-m);
  white-space: nowrap;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
.nb-ed-selpop__main {
  padding: 0 16px 0 12px;
  background: var(--ink); color: var(--on-ink);
  font: 600 var(--fs-body)/1 var(--font-body);
}
.nb-ed-selpop__main:hover, .nb-ed-selpop__main:active { opacity: 0.9; }
/* the popover cuts off what stands out of it */
.nb-ed-selpop__main:focus-visible, .nb-ed-selpop__opt:focus-visible { outline-offset: -2px; }
.nb-ed-selpop__main:focus-visible { outline-color: var(--on-ink); }
.nb-ed-selpop__opt {
  padding: 0 12px 0 10px;
  background: transparent; color: var(--text);
  font: 500 14px/1 var(--font-body);
}
.nb-ed-selpop__opt .nb-icon { color: var(--text-2); }
.nb-ed-selpop__opt:hover { background: var(--hover); }
.nb-ed-selpop__opt:active { background: var(--track); }

/* ------------------------------ narrow ---------------------------- */
/* js/editor.js sets data-narrow from the width of the host, not the window. */
.nb-ed-host[data-narrow="true"] .nb-ed-well { padding: 10px 8px 28px; }
.nb-ed-host[data-narrow="true"] .nb-ed-head { min-height: 98px; padding: 20px 14px 12px calc(var(--nb-ed-margin) + 12px); }
.nb-ed-host[data-narrow="true"] .nb-ed-body {
  padding: 16px max(14px, calc(100% - var(--nb-ed-margin) - 12px - 68ch)) 56px calc(var(--nb-ed-margin) + 12px);
}
.nb-ed-host[data-narrow="true"] .nb-ed-flags { left: 0; right: 0; justify-content: center; }
.nb-ed-tray[data-narrow="true"] { padding-inline: 8px; }
/* a phone: the title is scaled down like the written sheet scales it, so it is read whole */
@media (max-width: 480px) {
  .nb-ed-head .nb-sheethead { --zoom: 0.8; }
}
