/* papertooth: writing on the sheet
   Text inside .pt-sheet sits on the grid. The script nudges each block onto a dot row. */
/* the text on a sheet is styled through :where(), as weakly as one class: it wins over a bare reset (h2 { … }), and a
   component's or an app's own class wins over it when it loads later, as an app's styles do. Within papertooth the
   per-part stylesheets can come in any order. */
.pt-sheet :where(h1, h2, h3, h4, p, ul, ol, li, figure, blockquote) { margin: 0; }
.pt-sheet :where(p, li) { font-size: var(--pt-s-body); line-height: var(--pt-grid); max-width: 52ch; }
.pt-mode-hand .pt-sheet :where(p, li), .pt-sheet.pt-mode-hand :where(p, li) { max-width: 34em; }
.pt-sheet :where(h1, h2) { font-family: var(--pt-f-head); font-weight: 400; line-height: calc(var(--pt-grid) * 2); text-wrap: balance; }
.pt-sheet :where(h1) { font-size: var(--pt-s-h1); max-width: 18em; }
.pt-sheet :where(h2) { font-size: var(--pt-s-h2); }
.pt-sheet :where(h3) { font-family: var(--pt-font-type); font-weight: 400; font-size: var(--pt-s-small); line-height: var(--pt-grid); opacity: .7; }
.pt-mode-hand .pt-sheet :where(h1, h2), .pt-sheet.pt-mode-hand :where(h1, h2) { font-weight: 700; }
/* a <section>, and a whole .pt-sheet--page, keep the sheet's rhythm between their blocks of text, a line of the grid
   above each after the first. They stay ordinary blocks and space only text, as weakly as one class, so an app's
   sections and parts keep their own layout */
.pt-sheet :where(section > :is(h1, h2, h3, h4, h5, h6, p, ul, ol, dl, figure, blockquote, pre, table, hr, details):not(:first-child)),
.pt-sheet--page > :where(:is(h1, h2, h3, h4, h5, h6, p, ul, ol, dl, figure, blockquote, pre, table, hr, details):not(:first-child)) { margin-top: var(--pt-grid); }
.pt-row { display: flex; flex-wrap: wrap; gap: 0 var(--pt-grid); align-items: center; }

/* ink texture: body text varies in density only; headings also get a fine rough edge */
.pt-sheet :where(p, li) { filter: var(--pt-text-filter, ); }
.pt-sheet :where(h1, h2) { filter: var(--pt-head-filter, ); }

/* per-letter wobble: the script wraps each letter of .pt-wobble in a span */
.pt-c {
  display: inline-block;
  opacity: calc(1 - (1 - var(--o, 1)) * var(--pt-wobble));
  transform: translateY(calc(var(--y, 0) * var(--pt-wobble) * 1px)) rotate(calc(var(--r, 0) * var(--pt-wobble) * 1deg));
}
.pt-mode-hand .pt-c { display: inline; transform: none; }
/* the whole text for screen readers, next to letters hidden from them; not selectable, so a copy is not doubled */
.pt-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; user-select: none; }

/* text in a particular tool */
.pt-type { font-family: var(--pt-font-type); color: var(--pt-ribbon); }
.pt-pen-text { font-family: var(--pt-font-hand); color: var(--pt-pen); }
.pt-pencil-text { font-family: var(--pt-font-hand); color: var(--pt-pencil-hb); }
.pt-note { font-family: var(--pt-font-hand); color: var(--pt-pencil); }
.pt-sheet :is(.pt-pencil-text, .pt-note), :is(.pt-pencil-text, .pt-note) { filter: var(--pt-graphite, ); }
.pt-sheet p.pt-note, .pt-sheet p.pt-pencil-text { font-size: calc(var(--pt-s-body) * 1.05 + 4px); }
.pt-sheet p.pt-pen-text { font-size: calc(var(--pt-s-body) * 1.05 + 6px); }
.pt-jp { font-family: var(--pt-font-jp); font-weight: 800; }
.pt-jp-round { font-family: var(--pt-font-jp-round); font-weight: 700; }

/* typewriter texture for any font: add .pt-typewriter, tune it with setTypewriter() */
.pt-typewriter { filter: url(#pt-typewriter); text-shadow: var(--pt-double-strike); }
.pt-texture-off .pt-typewriter { filter: none; }

/* lets the browser skip drawing sections far off screen */
.pt-lazy { content-visibility: auto; contain-intrinsic-size: auto 600px; }

/* selecting text: a clean highlighter colour, and the ink filter steps aside while it is selected */
.pt-sheet ::selection, .pt-sheet::selection { background: color-mix(in srgb, var(--pt-hl-yellow, #fff04a) 70%, transparent); color: inherit; text-shadow: none; }
[data-pt-selecting], [data-pt-selecting] .pt-c { filter: none !important; }
