/*
 * doc-widget.v1.css — the `doc@v1` stylesheet. See specs/spec-doc-layout-contract.md.
 *
 * Loads in the EDITOR and in published output, because both surfaces have to agree on
 * what a document looks like. It carries BOTH modes: `pageless` (continuous, the
 * default) and `paged` (paper boxes, margins, header/footer, print breaks) — the DOM is
 * identical in each, so switching is a class flip and a repaint, never a content
 * rewrite.
 */

/* ── the document ─────────────────────────────────────────────────────────── */
[data-pd-doc] {
  --pd-doc-measure: 8.5in;        /* the paper's width; content sits inside the margin */
  --pd-doc-page-height: 11in;     /* …and its height. Letter portrait, the default */
  --pd-doc-margin: 1in;
  --pd-doc-gap: 24px;             /* between pages, in paged mode */
  --pd-doc-ink: #202124;
  --pd-doc-paper: #fff;
  --pd-doc-mat: #f1f3f4;          /* the grey behind the paper — Docs' own tone */
  --pd-doc-rule: #dadce0;
  color: var(--pd-doc-ink);
  /* THE DEFAULT IS GOOGLE'S, TUNED FOR READING (owner 2026-08-20: "modern, like the
     Google default size, optimised for readability").
     • 11pt Arial is exactly what a new Google Doc opens with, so a document made
       here and a document made there are the same document — including when one is
       pasted into the other.
     • 1.15 leading is Docs' default too (owner 2026-08-20: "make it very native like
       a Google Doc"). A looser 1.5 reads better in the abstract, but a document that
       spaces its lines differently from the one it will be pasted into or compared
       against is not the same document — and 1.15 is the rhythm people recognise as
       "a doc" before they read a word of it. Line spacing is a per-document choice to
       expose later, not a default to be clever about. */
  /* THE TAIL IS FOR THE SCRIPTS ARIAL CANNOT DRAW. Latin is untouched — Arial still
     wins every glyph it has — but a Japanese or Arabic document was falling through
     four Latin faces to the generic `sans-serif`, which means the reader's OS picked,
     and the same file looked like a different document on the next machine. Naming the
     usual system faces per platform (macOS, Windows, then Noto) makes the choice ours.
     Checked in a real browser: ja/ar/vi all render, and Latin is byte-identical. */
  font: 11pt/1.15 Arial, 'Helvetica Neue', Helvetica, 'Segoe UI',
        'Hiragino Sans', 'Yu Gothic UI', 'Noto Sans JP',
        'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC',
        'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR',
        'Geeza Pro', 'Segoe UI Historic', 'Noto Sans Arabic',
        'Nirmala UI', 'Noto Sans Devanagari',
        sans-serif;
  /* The leading again, as its own property, so the document's line spacing can be
     changed without restating the whole font stack. Identical to the shorthand's 1.15
     until `data-pd-line-spacing` says otherwise — this line changes nothing on its
     own, it only makes the value reachable. MUST stay after the `font` shorthand,
     which sets line-height too and would otherwise win by order. */
  line-height: var(--pd-doc-leading, 1.15);
  background: var(--pd-doc-mat);
}

/* A tab is one document surface — the paper AND the caret's region. There is no
   page container: paper in `paged` mode is decoration the paginator paints over this
   one continuous flow (spec §7.1b), which is what keeps the file free of layout.
   Only the staged tab shows while editing; the published runtime shows the selected
   one. Hiding rather than unmounting keeps anchors resolvable across tabs (§7.7). */
[data-pd-doc-tab] { display: block; }
[data-pd-doc-tab][hidden], [data-pd-doc-tab][data-pd-off] { display: none; }

/* ── the READER's tab strip ──────────────────────────────────────────────────
   `doc-widget.v1.js` builds `[data-pd-doc-nav]` for any document with two tabs or more,
   and until 2026-09-22 this sheet never styled it: every multi-tab document opened in
   preview, or published, with a row of bare browser buttons stuck to the top-left of
   the mat. New Document with AI writes multi-tab documents as a matter of course, so it
   was the first thing anyone saw after the build. It sits over the paper at the paper's
   width, and stays in reach while the reader scrolls a long tab. The editor has its own
   rail and never shows this. */
[data-pd-doc-nav] {
  position: sticky;
  top: 8px;
  z-index: 2;
  box-sizing: border-box;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  width: min(var(--pd-doc-measure), 100%);   /* exactly the paper's width, at every size */
  margin: 0 auto 16px;
  padding: 4px;
  background: var(--pd-doc-paper);
  border: 1px solid var(--pd-doc-rule);
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(60, 64, 67, .12);
  font: 500 13px/1.2 Arial, 'Helvetica Neue', Helvetica, 'Segoe UI', sans-serif;
}
[data-pd-doc-nav]::-webkit-scrollbar { display: none; }
[data-pd-doc-nav-tab] {
  appearance: none;
  flex: 0 0 auto;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #5f6368;
  font: inherit;
  padding: 8px 14px;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .12s, color .12s;
}
[data-pd-doc-nav-tab]:hover { background: var(--pd-doc-mat); color: var(--pd-doc-ink); }
[data-pd-doc-nav-tab][aria-current='true'] { background: #e8f0fe; color: #1967d2; }
[data-pd-doc-nav-tab]:focus-visible { outline: 2px solid #1a73e8; outline-offset: 1px; }

/* ── pageless (default) ───────────────────────────────────────────────────── */
/* A gap above the paper, so the sheet reads as a sheet lying on the mat rather than
   as a white page that happens to start at the top of the window. */
[data-pd-doc]:not([data-pd-doc-mode='paged']) { padding: 24px 0; }
[data-pd-doc]:not([data-pd-doc-mode='paged']) [data-pd-doc-tab] {
  max-width: var(--pd-doc-measure);
  margin: 0 auto;
  padding: var(--pd-doc-margin);
  background: var(--pd-doc-paper);
  /* PORTRAIT, ALWAYS (owner 2026-08-20: "the doc mode of page should look like a
     portrait page, not like a slide"). A `60vh` floor made an empty document 816
     wide by ~590 tall — landscape proportions, which reads as a slide even though
     everything about it is a document. One page of paper is the floor instead, so
     the very first thing anyone sees has the shape of the thing they are writing. */
  min-height: var(--pd-doc-page-height);
  /* THE PAPER IS 8.5×11 INCLUDING ITS MARGINS — that is what "letter" means, and
     `content-box` (the default) made it 8.5in + 2×1in = 10.5in wide by 13in tall:
     measured 1008×1248 where letter is 816×1056, so the sheet was the wrong SHAPE
     as well as too big (owner 2026-08-20: "proper sizing like letter or A4 ratio"). */
  box-sizing: border-box;
  box-shadow: 0 1px 3px rgba(60, 64, 67, .18), 0 1px 2px rgba(60, 64, 67, .1);
}
/* No page furniture without pages — the content stays in the file (spec §7.5). */
[data-pd-doc]:not([data-pd-doc-mode='paged']) [data-pd-doc-header],
[data-pd-doc]:not([data-pd-doc-mode='paged']) [data-pd-doc-footer] { display: none; }
/* An explicit page break is inert here, but must not collapse into a stray line. */
[data-pd-doc]:not([data-pd-doc-mode='paged']) hr[data-pd-break] { display: none; }

/* ── paged ────────────────────────────────────────────────────────────────── */
[data-pd-doc][data-pd-doc-mode='paged'] {
  padding: var(--pd-doc-gap) 0;
}
[data-pd-doc][data-pd-doc-mode='paged'] [data-pd-doc-tab] {
  width: var(--pd-doc-measure);
  min-height: var(--pd-doc-page-height);
  margin: 0 auto var(--pd-doc-gap);
  padding: var(--pd-doc-margin);
  background: var(--pd-doc-paper);
  box-shadow: 0 1px 3px rgba(60, 64, 67, .3), 0 4px 8px rgba(60, 64, 67, .15);
  position: relative;
  box-sizing: border-box;
}
[data-pd-doc][data-pd-doc-mode='paged'] [data-pd-doc-header],
[data-pd-doc][data-pd-doc-mode='paged'] [data-pd-doc-footer] {
  display: block;
  color: #5f6368;
  font-size: .85em;
}

/* Page setup is AUTHORED (§7.3), so it drives the paper in both modes — a document
   set to A4 should look like A4 while you write it, not only when you print. */
[data-pd-doc][data-pd-page-size='a4'] { --pd-doc-measure: 210mm; --pd-doc-page-height: 297mm; }
[data-pd-doc][data-pd-page-size='legal'] { --pd-doc-measure: 8.5in; --pd-doc-page-height: 14in; }

/* ORIENTATION (§7.3). The one page-setup choice a document has that nothing in the
   contract could say: every size above is portrait, and turning a page sideways is
   what a wide table or a landscape chart needs. It is a SWAP, not a fourth size — the
   paper is the same paper — so one rule per size exchanges the two custom properties
   and both modes, the paginator, the header/footer inset and the print rules all
   follow, because every one of them is already written against these two variables. */
[data-pd-doc][data-pd-page-orientation='landscape'] { --pd-doc-measure: 11in; --pd-doc-page-height: 8.5in; }
[data-pd-doc][data-pd-page-orientation='landscape'][data-pd-page-size='a4'] { --pd-doc-measure: 297mm; --pd-doc-page-height: 210mm; }
[data-pd-doc][data-pd-page-orientation='landscape'][data-pd-page-size='legal'] { --pd-doc-measure: 14in; --pd-doc-page-height: 8.5in; }

/* MARGINS — `data-pd-page-margin` has been in the contract (§7.3) since the doc shell
   was specced, carrying a real CSS LENGTH ("e.g. 1in"), and nothing ever read it. All
   it needs is to reach `--pd-doc-margin`, which BOTH modes already use for the tab's
   padding and which the paginator already reads for the position of headers, footers
   and page rules — so one rule per value moves the paper's text inset, the furniture
   and the page breaks together, with no measuring code anywhere.

   The three values are the ones the Tools menu writes (Narrow · Normal · Wide). 1in is
   Docs' default and stays the ABSENT case, so a document nobody has touched carries no
   attribute and a document set back to Normal returns to those exact bytes. An
   authored length outside this set is legal per the contract but has no rule to match;
   it falls back to 1in rather than breaking, and the day arbitrary lengths are wanted
   this becomes `attr(data-pd-page-margin type(<length>))` without a markup change. */
[data-pd-doc][data-pd-page-margin='0.5in'] { --pd-doc-margin: 0.5in; }
[data-pd-doc][data-pd-page-margin='1in']   { --pd-doc-margin: 1in; }
[data-pd-doc][data-pd-page-margin='1.5in'] { --pd-doc-margin: 1.5in; }

/* LINE SPACING, as the DOCUMENT'S DEFAULT — distinct from the per-paragraph command in
   the right-click menu, which sets the leading of the paragraphs you have selected.
   This is the value everything falls back to, so a whole document opens double-spaced
   without touching (and without leaving a `line-height` on) a single paragraph.

   It rides the same inheritance the body font already establishes: `--pd-doc-leading`
   feeds a `line-height` on the root, and every paragraph, list item, cell and quote
   picks it up because none of them declare one. HEADINGS DELIBERATELY DO NOT — they
   each set `line-height: 1.15` a few rules below, they are landmarks with their own
   rhythm, and 20pt type at double leading tears the page apart while saying nothing a
   reader needs. Docs' four values, and 1.15 is the untouched default (absent). */
[data-pd-doc][data-pd-line-spacing='1']   { --pd-doc-leading: 1; }
[data-pd-doc][data-pd-line-spacing='1.5'] { --pd-doc-leading: 1.5; }
[data-pd-doc][data-pd-line-spacing='2']   { --pd-doc-leading: 2; }
[data-pd-doc][data-pd-line-spacing='1.15'] { --pd-doc-leading: 1.15; }

/* ── flow content ─────────────────────────────────────────────────────────── */
[data-pd-doc-tab] > :first-child { margin-top: 0; }
/* DOCS' OWN PARAGRAPH STYLES, values and all — sizes in `pt`, spacing in `pt`, so
   they track the 11pt body and land identically on A4 and letter.
     Normal    11pt, 1.15, 0 before / 0 after
     Heading 1 20pt, 20pt before / 6pt after
     Heading 2 16pt, 18pt before / 6pt after
     Heading 3 14pt, 16pt before / 4pt after, #434343
   Headings are normal weight in Docs, not bold: they are LANDMARKS, and the size
   already does that work. */
[data-pd-doc-tab] h1 { font-size: 20pt; font-weight: 400; line-height: 1.15; color: #000; margin: 20pt 0 6pt; }
[data-pd-doc-tab] h2 { font-size: 16pt; font-weight: 400; line-height: 1.15; color: #000; margin: 18pt 0 6pt; }
[data-pd-doc-tab] h3 { font-size: 14pt; font-weight: 400; line-height: 1.15; color: #434343; margin: 16pt 0 4pt; }
/* …and the three below them, which a long document needs and which had NO styling at
   all — they fell to the browser's defaults, so H4 came out BOLDER and smaller than the
   H3 above it and the ladder read backwards. Docs' own values again:
     Heading 4 12pt  #666, 14pt before / 4pt after
     Heading 5 11pt  #666, 12pt before / 4pt after
     Heading 6 11pt  #666 italic, 12pt before / 4pt after  */
[data-pd-doc-tab] h4 { font-size: 12pt; font-weight: 400; line-height: 1.15; color: #666; margin: 14pt 0 4pt; }
[data-pd-doc-tab] h5 { font-size: 11pt; font-weight: 400; line-height: 1.15; color: #666; margin: 12pt 0 4pt; }
[data-pd-doc-tab] h6 { font-size: 11pt; font-weight: 400; line-height: 1.15; color: #666; margin: 12pt 0 4pt; font-style: italic; }
/* No paragraph spacing at all — the leading IS the rhythm, exactly as in Docs.
   Anything else and a pasted document changes shape. */
[data-pd-doc-tab] p { margin: 0; }
/* AN EMPTY LINE IS STILL A LINE. A block with no text in it is zero pixels tall, so
   the line a writer is about to type on has no height until they type — and a blank
   line they left between two paragraphs closes up on its own.

   This used to be papered over by the placeholder hint: the grey "Start writing…" gave
   the block SOMETHING to be as tall as, which is why the hint had to be kept on blocks
   that already sat under real text (measured: type a title and the body line collapsed
   from a full line to 0px, vanishing from under the cursor). That made a piece of
   editor chrome load-bearing for layout, and then the chrome could not be taken away.

   Height is a layout property, so give it to CSS: one line of leading, on any block
   that is empty. The hint is then free to be purely a hint. Both selectors are needed
   because a contenteditable block a user typed in and then emptied keeps a stray <br>,
   which `:empty` does not match. */
[data-pd-doc-tab] :is(p, h1, h2, h3, h4, h5, h6, li, blockquote):empty,
[data-pd-doc-tab] :is(p, h1, h2, h3, h4, h5, h6, li, blockquote):has(> br:only-child) {
  /* One line of leading — the DOCUMENT'S leading, so an empty line in a double-spaced
     document is as tall as the typed lines around it. A fixed 1.15em here would make
     the blank line a writer leaves between paragraphs visibly shorter than the rest. */
  min-height: calc(var(--pd-doc-leading, 1.15) * 1em);
}
/* Docs indents a list by half an inch and puts no space between items. */
[data-pd-doc-tab] ul, [data-pd-doc-tab] ol { margin: 0; padding-left: .5in; }
[data-pd-doc-tab] li { margin: 0; }
[data-pd-doc-tab] blockquote {
  margin: .8em 0; padding-left: 1em; border-left: 3px solid var(--pd-doc-rule); color: #5f6368;
}
[data-pd-doc-tab] pre { background: #f8f9fa; padding: .8em 1em; overflow-x: auto; }
[data-pd-doc-tab] hr { border: 0; border-top: 1px solid var(--pd-doc-rule); margin: 1.2em 0; }

/* ORDERED-LIST FORMATS (§6b). `data-pd-list-format` has been in the contract since
   the doc shell was specced and nothing read it, so every numbered list rendered
   "1. 2. 3." whatever the file said — an (a)(b)(c) sub-list or a i/ii/iii appendix was
   not expressible at all. The mapping is 1:1 onto `list-style-type`, which is also
   what the .docx walk needs: OOXML numbering formats are these same five, so the
   attribute exports rather than being a screen-only flourish.

   `start` needs no rule — it is the native HTML attribute, so "continue after that
   interrupting paragraph" and "restart at 1" are the browser's job in every format. */
[data-pd-doc-tab] ol[data-pd-list-format='decimal']     { list-style-type: decimal; }
[data-pd-doc-tab] ol[data-pd-list-format='lower-alpha'] { list-style-type: lower-alpha; }
[data-pd-doc-tab] ol[data-pd-list-format='upper-alpha'] { list-style-type: upper-alpha; }
[data-pd-doc-tab] ol[data-pd-list-format='lower-roman'] { list-style-type: lower-roman; }
[data-pd-doc-tab] ol[data-pd-list-format='upper-roman'] { list-style-type: upper-roman; }

/* Checklists — a real list, marked, never a div of divs (spec §2.2). */
[data-pd-doc-tab] ul[data-pd-list='check'] { list-style: none; padding-left: 1.2em; }
[data-pd-doc-tab] ul[data-pd-list='check'] > li::before {
  content: '☐'; margin-right: .5em;
}
[data-pd-doc-tab] ul[data-pd-list='check'] > li[data-pd-checked]::before { content: '☑'; }
/* Done reads as done: Docs greys a ticked item AND strikes it through, which is what
   makes a half-finished list scannable at a glance. The rule is on the TEXT, not the
   box, so the tick itself stays legible. */
[data-pd-doc-tab] ul[data-pd-list='check'] > li[data-pd-checked] { color: #5f6368; text-decoration: line-through; }
[data-pd-doc-tab] ul[data-pd-list='check'] > li[data-pd-checked]::before { text-decoration: none; }
/* The box is a control, so it says so on hover — the only hint that it is clickable. */
[data-pd-doc-tab] ul[data-pd-list='check'] > li::before { cursor: pointer; }

/* Tables print and export as tables, so they are styled as tables. */
[data-pd-doc-tab] table { border-collapse: collapse; width: 100%; margin: .8em 0; }
[data-pd-doc-tab] th, [data-pd-doc-tab] td {
  border: 1px solid var(--pd-doc-rule); padding: .5em .65em; text-align: left; vertical-align: top;
  /* A CELL IS SOMEWHERE YOU PUT A SENTENCE, so it has to look like one before
     anything is typed (owner 2026-08-20, with a screenshot: a new 3x3 table came
     out as a stack of hairlines — the empty cells collapsed to their padding and
     the whole thing read as a decorative rule rather than a grid).

     A minimum of one full line of text is what Docs and Word both start with, and
     it costs nothing once a cell has content: `min-height` on the cell's box only
     applies while the cell is emptier than a line. Set in `em` so it tracks the
     document's type rather than pinning a pixel height that would be wrong the
     moment anyone changes the size. */
  min-height: 1.15em;
  height: 1.15em;
}
[data-pd-doc-tab] thead th { background: #f8f9fa; font-weight: 700; }
/* A cell whose formula failed says so, rather than reading as an empty cell. */
[data-pd-doc-tab] td[data-pd-grid-error] { color: #c5221f; }

/* A CALCULATING TABLE (§6.1). Only `[data-pd-grid]` gets any of this — an ordinary
   document table is untouched, which is what the marker is for. Computed cells are
   right-aligned because that is how a column of figures is read, in Sheets and in every
   printed table; the labels beside them stay left. */
[data-pd-doc-tab] table[data-pd-grid] :is(td, th)[data-pd-grid-formula] {
  text-align: right; font-variant-numeric: tabular-nums;
}
[data-pd-doc-tab] table[data-pd-grid] :is(td, th)[data-pd-grid-error] {
  color: #c5221f; text-align: right;
}

/* ── objects: the one framed thing, placed relative to TEXT (spec §2.3) ────── */
[data-pd-object] { margin: .8em 0; }
[data-pd-object][data-pd-flow='inline'] { display: inline-block; vertical-align: baseline; margin: 0 .3em; }
[data-pd-object][data-pd-flow='wrap-left'] { float: left; margin: .2em 1em .6em 0; max-width: 50%; }
[data-pd-object][data-pd-flow='wrap-right'] { float: right; margin: .2em 0 .6em 1em; max-width: 50%; }
[data-pd-object][data-pd-flow='break'] { display: block; clear: both; }
[data-pd-object][data-pd-flow='break-all'] { display: block; clear: both; column-span: all; }
[data-pd-object] > img, [data-pd-object] > video, [data-pd-object] > svg { max-width: 100%; display: block; }
[data-pd-object] > figcaption { font-size: .85em; color: #5f6368; margin-top: .3em; }

/* ── columns: a section of the document, not a mode (spec §6a) ─────────────── */
[data-pd-doc-columns='2'] { column-count: 2; }
[data-pd-doc-columns='3'] { column-count: 3; }
[data-pd-doc-columns] { column-gap: var(--pd-doc-column-gap, .5in); }
/* THE GUTTER, and the same shape as `data-pd-page-margin` above: a real CSS length in
   the file, one rule per value the editor writes. CSS cannot read an attribute's value
   as a length, so an open-ended `data-pd-column-gap="37px"` would have had to be
   plumbed through JS — which is how it sat in the contract unimplemented, with the
   default gutter silently standing in for whatever the file asked for. Three values is
   what a column gutter is actually chosen from; `.5in` is Word's default and stays the
   ABSENT case, so an untouched document carries no attribute. */
[data-pd-doc-columns][data-pd-column-gap='0.25in'] { --pd-doc-column-gap: 0.25in; }
[data-pd-doc-columns][data-pd-column-gap='0.5in']  { --pd-doc-column-gap: 0.5in; }
[data-pd-doc-columns][data-pd-column-gap='0.75in'] { --pd-doc-column-gap: 0.75in; }
/* Responsive rather than blanket-disabled: two columns on a phone is unreadable,
   but silently dropping the author's layout on a wide screen would be worse. */
@media (max-width: 720px) { [data-pd-doc-columns] { column-count: 1; } }

/* ── auto numbering: counters, never typed text (spec §6b) ─────────────────── */
[data-pd-doc][data-pd-heading-numbering='decimal'] [data-pd-doc-tab] { counter-reset: pd-h2; }
[data-pd-doc][data-pd-heading-numbering='decimal'] h2 { counter-increment: pd-h2; counter-reset: pd-h3 pd-h4; }
[data-pd-doc][data-pd-heading-numbering='decimal'] h2::before { content: counter(pd-h2) '  '; }
[data-pd-doc][data-pd-heading-numbering='decimal'] h3 { counter-increment: pd-h3; counter-reset: pd-h4; }
[data-pd-doc][data-pd-heading-numbering='decimal'] h3::before {
  content: counter(pd-h2) '.' counter(pd-h3) '  ';
}
/* The counter has to reach as deep as the headings do, or a numbered document simply
   stops numbering half way down — which reads as a bug in the numbering, not as a
   depth limit. */
[data-pd-doc][data-pd-heading-numbering='decimal'] h4 { counter-increment: pd-h4; }
[data-pd-doc][data-pd-heading-numbering='decimal'] h4::before {
  content: counter(pd-h2) '.' counter(pd-h3) '.' counter(pd-h4) '  ';
}
figcaption[data-pd-caption='figure'] { counter-increment: pd-figure; }
figcaption[data-pd-caption='figure']::before { content: 'Figure ' counter(pd-figure) '. '; }
figcaption[data-pd-caption='table'] { counter-increment: pd-table; }
figcaption[data-pd-caption='table']::before { content: 'Table ' counter(pd-table) '. '; }

/* ── footnotes: two pieces of content and no number (§7.8) ─────────────────── */
/* The MARK and the NOTE are content and travel in the file. The NUMBER is not: it is
   a counter, exactly as heading numbering is (§6b), because a typed number is wrong
   the moment a note is added above it. Marks count in document order; the notes are an
   <ol> and number themselves. So the two agree with no renumbering code at all —
   including after a delete, which is the case hand-written numbering always loses. */
[data-pd-doc-tab] { counter-reset: pd-figure pd-table pd-fn; }
[data-pd-doc-tab] sup[data-pd-fn] { counter-increment: pd-fn; }
[data-pd-doc-tab] sup[data-pd-fn]::before {
  content: counter(pd-fn);
  font-size: .75em;
  line-height: 0;
  color: #1a73e8;
  cursor: default;
}
/* The region reads as an aside: a rule, smaller type, at the foot of the document. */
[data-pd-doc-tab] [data-pd-footnotes] {
  margin-top: 24pt;
  border-top: 1px solid var(--pd-doc-rule);
  padding-top: 8pt;
  font-size: 9pt;
  color: #3c4043;
}
[data-pd-doc-tab] [data-pd-footnotes] ol { margin: 0; padding-left: 1.6em; }
[data-pd-doc-tab] [data-pd-footnotes] li { margin: 0 0 4pt; line-height: 1.3; }
/* A region with no notes in it is not an empty region — it is nothing, and it must not
   leave a rule across the foot of the page. */
[data-pd-doc-tab] [data-pd-footnotes]:not(:has(li)) { display: none; }

/* ── the table of contents ────────────────────────────────────────────────── */
[data-pd-toc] { margin: 1em 0 1.5em; }
[data-pd-toc] a { display: block; text-decoration: none; color: inherit; padding: .15em 0; }
[data-pd-toc] a:hover { text-decoration: underline; }
[data-pd-toc] a[data-pd-toc-level='2'] { padding-left: 1.5em; }
[data-pd-toc] a[data-pd-toc-level='3'] { padding-left: 3em; }
/* …and the deeper levels indent too, or every heading below the third sits at the
   same margin and the contents stops showing the shape of the document. */
[data-pd-toc] a[data-pd-toc-level='4'] { padding-left: 4.5em; }
[data-pd-toc] a[data-pd-toc-level='5'] { padding-left: 6em; }
[data-pd-toc] a[data-pd-toc-level='6'] { padding-left: 7.5em; }
/* No page numbers to show a reader who is not looking at pages (spec §7.6). */
[data-pd-doc]:not([data-pd-doc-mode='paged']) [data-pd-toc] [data-pd-field] { display: none; }

/* ── print: the exact one. CSS fragments mid-paragraph natively, so the PDF
      breaks where a word processor would, and no exporter is needed (§7.6). ─── */
/* ── equations — §7.8 ────────────────────────────────────────────────────────────
   MathML is rendered by the browser; what this adds is the two things a PAPER needs and
   MathML has no opinion about: a display equation is centred on its own line, and it
   NUMBERS ITSELF against the right margin from a counter — so inserting one above
   renumbers the rest, exactly as a figure caption does. A number typed by hand is wrong
   the moment anybody adds an equation, and nobody renumbers a paper twice. */
[data-pd-doc] { counter-reset: pd-eq 0; }
[data-pd-equation='block'] {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  margin: 1.1em 0;
  text-align: center;
}
[data-pd-equation='block'] math { justify-self: center; font-size: 1.08em; }
[data-pd-equation='block'][data-pd-equation-number] { counter-increment: pd-eq; }
[data-pd-equation='block'][data-pd-equation-number]::after {
  content: '(' counter(pd-eq) ')';
  justify-self: end;
  color: #5f6368;
  font-size: .95em;
  font-variant-numeric: tabular-nums;
}
/* An inline equation sits IN the sentence: it must not change the line's height, which is
   what an over-eager `font-size` on `math` does to a paragraph. */
[data-pd-equation='inline'] { display: inline; }
[data-pd-equation='inline'] math { font-size: 1em; }
/* The editor's affordance: an equation is one object to click, never a place the caret
   wanders into character by character. */
[data-pd-doc-tab] [data-pd-equation] { cursor: pointer; }

@media print {
  [data-pd-doc] { background: #fff; }
  /* THE MARGIN COMES FROM `@page`, AND ONLY FROM THERE.
     This reset is `[data-pd-doc] [data-pd-doc-tab]` (0,2,0) and the paged-mode rule above
     it is `[data-pd-doc][data-pd-doc-mode='paged'] [data-pd-doc-tab]` (0,3,0) — so the
     paged rule won, the tab kept its `padding: var(--pd-doc-margin)` on top of the page
     box's own margin, and every printed document was inset TWICE. Measured out of the
     PDF's text layer (2026-09-21): a 0.5in document put its first character 1.01in from
     the paper's edge, a 1in one at 1.82in. Matching the specificity is the whole fix. */
  [data-pd-doc][data-pd-doc-mode='paged'] [data-pd-doc-tab],
  [data-pd-doc] [data-pd-doc-tab] {
    width: auto; min-height: 0; margin: 0; padding: 0; box-shadow: none; background: #fff;
  }
  /* …and the mat's gutter between sheets is a screen affordance: on paper the page box
     already separates them, and the padding lands as a band at the top of page one. */
  [data-pd-doc][data-pd-doc-mode='paged'] { padding: 0; }
  [data-pd-doc-tab][data-pd-off] { display: none; }
  /* The reader's tab strip is a screen control; on paper it is a row of words. */
  [data-pd-doc-nav] { display: none; }
  hr[data-pd-break='page'] { display: block; border: 0; break-after: page; page-break-after: always; }
  /* Header and footer are PAGE FURNITURE: hidden on the web (§8a), present on paper.
     Pageless hides them, and print is where they belong, so print puts them back —
     including on a published document, which renders pageless by definition. */
  [data-pd-doc] [data-pd-doc-header], [data-pd-doc] [data-pd-doc-footer] {
    display: block; color: #5f6368; font-size: .85em;
  }
  hr[data-pd-break='column'] { display: block; border: 0; break-after: column; }
  [data-pd-doc-tab] h1, [data-pd-doc-tab] h2, [data-pd-doc-tab] h3 { break-after: avoid; }
  [data-pd-object], [data-pd-doc-tab] table { break-inside: avoid; }
}

/* PAGE SETUP REACHES THE PAPER (§7.3). This used to be a flat
   `@page { size: letter; margin: 1in }`, which meant the Tools menu's paper size and
   margins changed the sheet you WROTE on and were then silently discarded at the one
   moment they are load-bearing — printing, and the PDF export that is nothing but a
   print. A document set to A4 came out Letter. That is worse than not offering the
   control, because the screen says it worked.

   CSS cannot read an attribute, and the page context inherits from the ROOT element
   rather than from the document root our attributes live on — so this is built from
   the two things that CAN bridge that gap, verified in a real browser against the
   generated PDF (MediaBox + page count, 2026-09-21):
     • MARGIN travels as a custom property hoisted to `:root` with `:has()`, and one
       generic `@page` reads it. One axis, three rules.
     • SIZE + ORIENTATION are NAMED pages, selected by `page:` on the root. They
       compose with the generic rule rather than replacing it, so the margin above
       still applies — which is what keeps this six rules instead of eighteen.
   An unmatched combination simply falls through to Letter portrait, i.e. exactly
   what this printed before, so nothing can print worse than it used to. */
@page { margin: var(--pd-print-margin, 1in); }
:root:has([data-pd-doc][data-pd-page-margin='0.5in']) { --pd-print-margin: 0.5in; }
:root:has([data-pd-doc][data-pd-page-margin='1.5in']) { --pd-print-margin: 1.5in; }

@page pd-letter-landscape { size: letter landscape; }
@page pd-a4              { size: A4; }
@page pd-a4-landscape    { size: A4 landscape; }
@page pd-legal           { size: legal; }
@page pd-legal-landscape { size: legal landscape; }

:root:has([data-pd-doc]:not([data-pd-page-size='a4']):not([data-pd-page-size='legal'])[data-pd-page-orientation='landscape']) { page: pd-letter-landscape; }
:root:has([data-pd-doc][data-pd-page-size='a4']:not([data-pd-page-orientation='landscape'])) { page: pd-a4; }
:root:has([data-pd-doc][data-pd-page-size='a4'][data-pd-page-orientation='landscape']) { page: pd-a4-landscape; }
:root:has([data-pd-doc][data-pd-page-size='legal']:not([data-pd-page-orientation='landscape'])) { page: pd-legal; }
:root:has([data-pd-doc][data-pd-page-size='legal'][data-pd-page-orientation='landscape']) { page: pd-legal-landscape; }

/* ── FREEZE and FILTER on a document's calculating table (§6.1) ───────────────
   The same two behaviours the sheet has, because it is the same table: a document
   with a long grid in it wants its header row held just as much, and a filtered table
   must print filtered. Stated here as well as in the sheet's stylesheet because a
   document loads this one and not that one — the alternative is a shared third file
   for four rules, which costs a request to save a repetition. */
[data-pd-doc-tab] table[data-pd-grid] [data-pdp-frozen] {
  position: sticky; background: #f8f9fa; z-index: 3;
}
[data-pd-doc-tab] table[data-pd-grid] [data-pdp-frozen='row'] { top: 0; z-index: 4; }
[data-pd-doc-tab] table[data-pd-grid] [data-pdp-frozen='both'] { z-index: 5; }
[data-pd-doc-tab] table[data-pd-grid] tr[hidden] { display: none; }
/* A formatted number lines up on the right, like every other number in the column. */
[data-pd-doc-tab] table[data-pd-grid] :is(td, th)[data-pd-grid-format]:not([data-pd-grid-format='text']) {
  text-align: right; font-variant-numeric: tabular-nums;
}
