/* ==========================================================================
   reader.css — /documents/<code>/read/, the surface a citation lands on.

   Loaded only on the reader (`{% block extra_css %}`), not by base.html: site.css is
   21.9 KB of a 30 KB file cap (§II), and this is the one page a visitor arrives at from
   a citation rather than from the nav.

   Styling consequences that are not decoration:

     * `.passage:target` is the whole point of the page. A reader following a citation
       must be able to see *where the clause is* without losing the passages around it,
       so the target is marked with ground and a rule, never with a colour that hides
       the text it just arrived at.
     * the tree is a reading aid, so it stays tappable at 390 px (§IV, ≥44 px) and scrolls
       independently of the text. On a phone it collapses to the branch the reader is in —
       a disclosure, never JavaScript (§IV, D68 §7.4).
     * nothing here styles a *claim*: a search hit is marked with `<mark>` because the
       reader typed the word, not because the page is endorsing it.
   ========================================================================== */

.reader {
  /* The reader is a working column, not a full-bleed article: a tree on the left and one
     readable measure of text on the right. The measure is deliberately narrower than
     `--container-prose` (56 rem) — 38 rem is ~85 characters at 16 px, which is where dense
     legal text stops being a scan and starts being a swim. */
  --reader-measure: 38rem;
  max-width: 72rem;
  margin-inline: auto;
}

/* A tool page, not a marketing band: the page head above already carries the air. */
.section--reader {
  padding-block: 2.5rem 4rem;
}

@media (max-width: 899px) {
  .section--reader {
    padding-block: 1.5rem 3rem;
  }
}

/* --- Search --------------------------------------------------------------- */

.reader__search {
  margin-bottom: 2rem;
  padding: 1.1rem 1.25rem 1.25rem;
  border: 1px solid var(--brand-sand);
  border-radius: var(--radius-md);
  background-color: var(--brand-creamWarm);
}

.reader__search-label {
  display: block;
  margin-bottom: 0.6rem;
  color: var(--brand-forestDark);
  font-size: var(--text-micro);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.reader__search-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem;
}

.reader__input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 2.75rem; /* 44 px — DESIGN rule 5 */
  padding: 0 0.75rem;
  border: 1px solid var(--brand-sand);
  border-radius: var(--radius-xs);
  background-color: var(--brand-cream);
  color: var(--brand-charcoal);
  font-family: var(--font-sans);
  font-size: var(--text-base);
}

.reader__search-row .btn {
  flex: none;
  min-height: 2.75rem;
}

.reader__search-note {
  margin: 0.75rem 0 0;
  color: var(--brand-muted);
  font-size: var(--text-xs);
}

.reader__no-hits {
  margin-bottom: 2rem;
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--brand-ochre);
  background-color: var(--brand-ochreLight);
  color: var(--brand-charcoal);
  font-size: var(--text-sm);
}

/* --- Search hits ---------------------------------------------------------- */

.reader__hits {
  margin: 0 0 2.5rem;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.75rem;
}

.reader__hit {
  padding: 0.85rem 1rem;
  border: 1px solid var(--brand-sand);
  border-radius: var(--radius-md);
  background-color: var(--brand-cream);
}

.reader__hit-locator {
  display: inline-block;
  min-height: 1.5rem;
  color: var(--brand-ochreInk);
  font-size: var(--text-micro);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-decoration: none;
}

.reader__hit-locator:hover {
  color: var(--brand-ochreDark);
  text-decoration: underline;
}

.reader__hit-text {
  margin: 0.35rem 0 0;
  color: var(--brand-charcoal);
  font-size: var(--text-sm);
  line-height: var(--leading-body);
}

.reader__hit-text mark {
  padding: 0 0.15em;
  border-radius: 2px;
  background-color: var(--brand-ochreLight);
  color: var(--brand-charcoal);
  font-weight: 700;
}

/* --- Body: the tree + one open branch ------------------------------------ */

/* A citation is a jump, not a journey.

   `root.css` sets `html { scroll-behavior: smooth }`, which is right for a two-screen page and wrong
   here: the SAOSO branch a definition lives in is ~12 000 px tall and the jump to it is ~11 000 of
   them. Smooth takes seconds, and any wheel nudge during it cancels the scroll — so a reader
   following `#term-synthetic` stayed where they were and concluded the link was broken (reported
   2026-10-27). A link whose whole purpose is "land on this line" must land. */
html:has(.section--reader) {
  scroll-behavior: auto;
}

.reader__body {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
}

/* A `<details>` disclosure is the phone case (D68 §7.4): 22 branch rows of 44 px is ~968 px
   of scrolling before a single clause. The summary names the branch the reader is in, so a
   closed tree still tells them where they are; desktop opens it permanently in the media
   query below. No JavaScript: `build_principles.md` §IV never requires it. */
.reader__tree-summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.75rem; /* 44 px — DESIGN rule 5 */
  padding: 0 1rem;
  border: 1px solid var(--brand-sand);
  border-radius: var(--radius-md);
  background-color: var(--brand-creamWarm);
  color: var(--brand-forestDark);
  font-size: var(--text-sm);
  font-weight: 700;
  cursor: pointer;
}

.reader__tree-details[open] .reader__tree-summary {
  margin-bottom: 0.75rem;
}

@media (min-width: 900px) {
  .reader__body {
    grid-template-columns: 17rem minmax(0, 1fr);
    gap: 2.5rem;
    align-items: start;
  }

  /* Both the search box and the tree stay put while the branch scrolls: a reader checking a
     quotation against a search hit should not have to scroll back to the top to search again.
     The tree's offset clears the search's own height (measured at 1280 px, with and without
     the "N passages matching" note, 2026-10-27), because CSS cannot read a sibling's height
     and a guessed smaller value would let the search cover the tree's first rows. */
  .reader__search {
    position: sticky;
    top: var(--header-height);
    z-index: 3;
  }

  /* The disclosure is a phone affordance. On a desk the tree is always open and the summary
     is not a control the reader has to find. A closed `<details>` hides its content through
     the `::details-content` box rather than through the child's own `display`, so both the
     pseudo-element and the child rule are needed on current Chromium/Safari/Firefox. */
  .reader__tree-summary {
    display: none;
  }

  .reader__tree-details:not([open])::details-content {
    content-visibility: visible;
    display: block;
  }

  .reader__tree-details > .reader__tree {
    display: block;
  }

  /* The grid item is the whole tree **column** (the `<details>` plus the note about what the
     corpus does not hold), so **it** is the sticky box: a sticky child cannot travel beyond its
     parent's height, and the parent's height is exactly what it contains. Making the `<details>`
     sticky instead leaves the column itself in normal flow, and any sibling added beside it —
     the note, 2026-10-27 — wraps the passages to the next grid row and lets the tree sit on top
     of them. */
  .reader__tree-column {
    position: sticky;
    top: calc(var(--header-height) + 9.5rem);
  }

  .reader__tree {
    max-height: calc(100vh - var(--header-height) - 10.5rem);
    overflow-y: auto;
  }

  /* The note sits under the tree and travels with it, so the scrollable tree has to give back
     the room the note takes — measured at 1280 px: two lines of `--text-micro` plus its margin. */
  .reader__tree-column:has(.reader__tree-note) .reader__tree {
    max-height: calc(100vh - var(--header-height) - 14.5rem);
  }
}

.reader__tree {
  padding: 0.9rem 0.75rem 1rem;
  border: 1px solid var(--brand-sand);
  border-radius: var(--radius-md);
  background-color: var(--brand-creamWarm);
}

.reader__tree-title {
  margin: 0 0 0.5rem;
  padding-inline: 0.6rem;
  color: var(--brand-forestDark);
  font-size: var(--text-micro);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

@media (max-width: 899px) {
  /* The summary already says "Contents"; inside the opened disclosure the second heading is
     noise. */
  .reader__tree-title {
    display: none;
  }
}

.reader__tree-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.1rem;
}

.reader__tree-list li {
  display: flex;
}

.reader__tree-link {
  display: flex;
  flex: 1 1 auto;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.6rem;
  min-height: 2.75rem; /* 44 px: this is the phone's whole table of contents */
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-xs);
  color: var(--brand-charcoal);
  font-size: var(--text-xs);
  line-height: 1.35;
  text-decoration: none;
}

.reader__tree-link:hover {
  background-color: var(--brand-sageLight);
  color: var(--brand-ochreInk);
}

/* The open branch is marked with a rule, not a fill: a second ground inside the warm ground
   would be a third surface in one column (DESIGN §3). */
.reader__tree-link[aria-current="page"] {
  box-shadow: inset 3px 0 0 var(--brand-ochre);
  color: var(--brand-ochreInk);
  font-weight: 700;
}

/* A reserved row is visible and cannot be opened: the standard prints the number and no
   text, so there is nothing to link to. */
.reader__tree-link--reserved {
  color: var(--brand-muted);
  cursor: default;
}

.reader__tree-link--reserved:hover {
  background-color: transparent;
  color: var(--brand-muted);
}

.reader__tree-name {
  flex: 1 1 auto;
  padding-top: 0.1rem;
}

.reader__tree-note {
  margin: 0.75rem 0 0;
  color: var(--brand-muted);
  font-size: var(--text-micro);
  line-height: var(--leading-body);
}

.reader__page {
  flex: none;
  padding-top: 0.15rem;
  color: var(--brand-muted);
  font-size: var(--text-micro);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.reader__crumb {
  margin: 0 0 1.25rem;
  color: var(--brand-muted);
  font-size: var(--text-micro);
  letter-spacing: 0.02em;
}

/* --- Passages ------------------------------------------------------------- */

.reader__passages {
  display: block;
}

/* One passage, one clause: a hairline separates the printed clauses so a long branch reads as a
   sequence of rules rather than one undifferentiated column. */
.passage {
  padding-block: 1.5rem;
  border-top: 1px solid var(--brand-sand);
  scroll-margin-top: calc(var(--header-height) + 1.5rem);
}

.reader__crumb + .passage {
  padding-top: 0.25rem;
  border-top: 0;
}

@media (min-width: 900px) {
  /* A citation lands under the sticky search and tree, not behind them. */
  .passage {
    scroll-margin-top: calc(var(--header-height) + 8rem);
  }
}

/* A definition's id is on the `<p>` *inside* a passage, so `.passage`'s own `scroll-margin-top`
   never applies to it and the definition landed behind the sticky search — measured on the live
   page 2026-10-27: term top 96 px, search bottom 191 px, so `#term-synthetic` opened a page where
   `Synthetic` was covered. Same offsets as `.passage`, for the same reason. */
.passage__term[id],
.reader__tree-note[id] {
  scroll-margin-top: calc(var(--header-height) + 1.5rem);
}

@media (min-width: 900px) {
  .passage__term[id],
  .reader__tree-note[id] {
    scroll-margin-top: calc(var(--header-height) + 8rem);
  }
}

/* The ground and rule bleed to the pane's edges so the arrival reads as a location, not as a
   coloured sentence. */
.passage:target {
  margin-inline: -0.85rem;
  padding-inline: 0.85rem;
  border-radius: var(--radius-xs);
  background-color: var(--brand-ochreLight);
  box-shadow: inset 3px 0 0 var(--brand-ochre);
}

.reader__crumb + .passage:target {
  padding-top: 0.85rem;
}

.passage__locator {
  margin: 0 0 0.45rem;
  color: var(--brand-muted);
  font-family: ui-monospace, "SFMono-Regular", "Cascadia Mono", monospace;
  font-size: var(--text-micro);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.passage__text {
  margin: 0 0 0.9rem;
  max-width: var(--reader-measure);
  color: var(--brand-charcoal);
  font-size: var(--text-base);
  line-height: var(--leading-body);
}

.passage__text:last-child {
  margin-bottom: 0;
}

/* The document's own heading (`1. DEFINITIONS`, `## INTRODUCTION` from the BPP artefact). A <p>,
   not an <h*>: it is quoted text with a shape, not the page's outline. */
.passage__heading {
  margin: 1.6rem 0 0.6rem;
  max-width: var(--reader-measure);
  color: var(--brand-forestDark);
  font-size: var(--text-lg);
  font-weight: 700;
  line-height: var(--leading-tight);
}

/* A glossary term or a printed sub-heading: one step below a section heading, one above the
   definition it introduces. */
.passage__term {
  margin: 1.2rem 0 0.4rem;
  max-width: var(--reader-measure);
  color: var(--brand-forestDark);
  font-size: var(--text-base);
  font-weight: 700;
  line-height: var(--leading-tight);
}

/* A printer's marginal label: mixed case, centred on the paper, qualifying what follows rather
   than dividing the document (`South African specific`, `Regional or other exception`). It must sit
   *below* the term it qualifies, never at `.passage__heading`'s weight — the same relationship the
   table's `South African specific` qualifier has to its row. */
.passage__qualifier {
  margin: 1.3rem 0 0.4rem;
  max-width: var(--reader-measure);
  color: var(--brand-muted);
  font-size: var(--text-micro);
  font-style: italic;
  letter-spacing: 0.01em;
}

/* A reviewed table row's substance cell (`Guano`, `Wood, bark, sawdust…`): an entry in the paper's
   table, one step below a printed heading and above the condition printed beside it. It exists so a
   row whose condition cell is empty still reads as an entry rather than as body text. */
.passage__row {
  margin: 1.1rem 0 0.35rem;
  max-width: var(--reader-measure);
  color: var(--brand-forestDark);
  font-size: var(--text-base);
  font-weight: 700;
  line-height: var(--leading-tight);
}

/* A divider the paper prints inside the table: a part heading at the heading's weight, a centred
   `South African specific` qualifier at the term's. Both are quoted text with a shape, so neither is
   an `<h*>`. A hairline above a part is the paper's own break between parts of the table. */
.passage__divider {
  max-width: var(--reader-measure);
  color: var(--brand-forestDark);
  line-height: var(--leading-tight);
}

.passage__divider--part {
  margin: 1.9rem 0 0.6rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--brand-sand);
  font-size: var(--text-lg);
  font-weight: 700;
}

.passage__divider--qualifier {
  margin: 1.4rem 0 0.4rem;
  color: var(--brand-muted);
  font-size: var(--text-base);
  font-style: italic;
}

/* What the paper's condition cell says where it says nothing. A label, not a sentence: nineteen of
   them sit in this table, and the legend says the whole thing once. */
.passage__note {
  margin: 0.45rem 0 0;
  max-width: var(--reader-measure);
  color: var(--brand-muted);
  font-size: var(--text-micro);
  letter-spacing: 0.01em;
}

