/* ============================================================
   Legal pages — editorial typography for /legal/terms-of-use and
   /legal/privacy-policy.
   ============================================================
   Aesthetic: editorial / magazine-grade clinical refinement.
   Fraunces (display, opsz variable serif) + Newsreader (body
   serif). Patient-facing legal text styled with the care of a
   published act of parliament rather than a corporate EULA.

   Everything is scoped under `.legal-page` so the design choices
   here don't bleed into the intake / admin UIs. The page declares
   its own palette overrides via custom properties on `.legal-page`
   (paper-toned light theme, deep warm dark theme); semantic tokens
   from tokens.css are still used everywhere so dark-mode flips
   automatically. No hardcoded hex outside the local-theme block.

   Fonts are SELF-HOSTED (assets/fonts/*.woff2), not Google Fonts.
   Fraunces + Newsreader are both variable woff2 (one file per
   weight-range / style), latin subset. The page <head> preloads the
   Newsreader body face. See @font-face declarations immediately below.
   ============================================================ */

/* Fraunces — variable (wght 300–700), latin. Display serif. */
@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("../assets/fonts/fraunces-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Newsreader — variable (wght 400–700), latin. Body serif, upright + italic. */
@font-face {
  font-family: "Newsreader";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../assets/fonts/newsreader-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Newsreader";
  font-style: italic;
  font-weight: 400 500;
  font-display: swap;
  src: url("../assets/fonts/newsreader-latin-italic.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ============================================================
   Design rules (continued): no hardcoded hex outside the
   local-theme block below — ``check_dark_mode.py --strict``
   enforces this.

   CSP note: the marketing site's _headers CSP is `font-src 'self'`
   / `style-src 'self' 'unsafe-inline'` — the legal pages need NO
   Google Fonts origins now that the faces above are self-hosted.
   The only remaining inline-script allowance is for the small
   inline script in _base_legal.html (TOC ``<details open>`` toggle
   + IntersectionObserver scroll-spy); for a strict no-`'unsafe-inline'`
   policy, move that script to a separate file under /static/js/.
   ============================================================ */

/* ── Local theme: per-page custom properties on top of tokens.css ──

   The legal pages want a slightly different palette than the rest
   of the app (paper-warmed light theme, deep warm dark theme) to
   reinforce the editorial / archival aesthetic. Following the same
   pattern tokens.css uses — light values on the root, dark values
   under [data-theme="dark"] — scoped to ``.legal-page`` so nothing
   leaks. These are the legal-only design tokens; treat each line
   as the canonical source for that token. Hex values flagged here
   match the check_dark_mode.py exemption convention: /* dark-mode-ok */ */
.legal-page {
  /* Paper-toned page surround — warmer than the cool slate the
     rest of the app uses. Reads as archival / printed-document. */
  --legal-paper: #faf7f0; /* dark-mode-ok */
  --legal-paper-edge: #ede7d6; /* dark-mode-ok */
  /* Rule colour used under section headings and around the TOC. */
  --legal-rule: #d6cdb8; /* dark-mode-ok */
  /* Drop-cap clause number colour — a muted aged-ink tone. */
  --legal-clause-num: #8a6d3b; /* dark-mode-ok */
  /* TOC inactive marker — a quiet bullet line on the side. */
  --legal-toc-rail: #d6cdb8; /* dark-mode-ok */
  /* Subtle backdrop tint behind the prose card. */
  --legal-prose-bg: #ffffff; /* dark-mode-ok */
}

[data-theme="dark"] .legal-page {
  /* Deep warm blue-grey — feels intentional next to the cool
     navy of the rest of the app. Like reading a leather-bound
     book in a low-lit room. */
  --legal-paper: #0c1219; /* dark-mode-ok */
  --legal-paper-edge: #1a2230; /* dark-mode-ok */
  --legal-rule: #34405a; /* dark-mode-ok */
  --legal-clause-num: #c8a16a; /* dark-mode-ok */
  --legal-toc-rail: #34405a; /* dark-mode-ok */
  --legal-prose-bg: #11161f; /* dark-mode-ok */
}

/* ── Base page ── */
.legal-page {
  min-height: 100vh;
  background: var(--legal-paper);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  /* Subtle paper-grain backdrop: a single fine-noise radial that
     adds atmosphere without competing with the prose. Falls back
     to a flat colour if `background-image` doesn't render. */
  background-image:
    radial-gradient(
      ellipse 1200px 600px at top center,
      var(--legal-paper-edge) 0%,
      transparent 60%
    );
  background-repeat: no-repeat;
  /* System fallback before Fraunces / Newsreader loads. The serif
     fallback list is chosen to keep glyph metrics close to
     Newsreader so the FOUT shift is small. */
  font-family: "Newsreader", Charter, "Iowan Old Style", "Source Serif Pro",
    "Apple Garamond", Georgia, "Times New Roman", serif;
  /* ``kern`` and ``liga`` are usually on by default but we declare
     them explicitly for older WebKit. ``calt`` enables contextual
     alternates (Newsreader uses these to disambiguate similar
     letterforms). We deliberately do NOT enable ``ss01`` etc.
     here because Fraunces' stylistic sets affect specific glyphs
     in a way that hasn't been reviewed against the legal copy;
     opt in per-element if needed. */
  font-feature-settings: "kern", "liga", "calt";
  /* Newsreader and Fraunces both expose an opsz axis; let the
     browser interpolate the optical size based on font-size. */
  font-optical-sizing: auto;
}

/* ── Header (editorial masthead) ── */
.legal-header {
  position: relative;
  padding: 2.5rem 1.25rem 2rem;
  text-align: center;
  /* Hairline rule along the bottom — sits flush with the start
     of the layout grid and continues across the full width. */
  border-bottom: 1px solid var(--legal-rule);
}

/* Top nav — back-link left, switch-doc link right. Small kerned
   sans-serif tracking gives it an editorial header feel. */
.legal-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1100px;
  margin: 0 auto 2.5rem;
  gap: 1rem;
  font-family: "Fraunces", Georgia, serif;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.legal-back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--color-primary);
  text-decoration: none;
  min-height: 44px; /* mobile tap target */
  transition: color 180ms ease, transform 180ms ease;
}

.legal-back-link:hover,
.legal-back-link:focus-visible {
  color: var(--color-primary-dark);
  transform: translateX(-2px);
}

.legal-back-link:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 4px;
  border-radius: 2px;
}

.legal-back-link--placeholder {
  /* Reserve a slot when no return_to is set so the right-side
     "switch doc" link stays anchored to the right; matches the
     visual width of the back-link icon + label. */
  min-width: 1px;
  min-height: 44px;
  display: inline-block;
}

.legal-switch-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-secondary);
  text-decoration: none;
  min-height: 44px;
  transition: color 180ms ease, transform 180ms ease;
}

.legal-switch-link:hover,
.legal-switch-link:focus-visible {
  color: var(--color-primary);
  transform: translateX(2px);
}

.legal-switch-link:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 4px;
  border-radius: 2px;
}

/* ── Hero ──
   A kicker (tracked small caps), big serif title with display-
   optical-size Fraunces, and a refined byline. Composed like the
   masthead of a feature article. */
.legal-hero {
  max-width: 720px;
  margin: 0 auto;
}

.legal-kicker {
  font-family: "Fraunces", Georgia, serif;
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-weight: 500;
  color: var(--color-primary);
  margin-bottom: 1rem;
  /* A tiny ornamental dot before and after the kicker — sets the
     editorial tone without being noisy. */
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
}

.legal-kicker::before,
.legal-kicker::after {
  content: "";
  width: 18px;
  height: 1px;
  background: var(--color-primary);
  opacity: 0.6;
}

.legal-title {
  /* Display-weight Fraunces with opsz set high so the variant
     glyphs render. Tight leading. */
  font-family: "Fraunces", Georgia, serif;
  font-variation-settings: "opsz" 144, "wght" 500;
  font-size: clamp(2.25rem, 6vw, 3.75rem);
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: -0.015em;
  color: var(--text-primary);
  margin: 0;
  /* A subtle italic-style swash flourish via font-feature-settings
     where the font supports it. Fraunces has ss01 (stylistic set 1)
     enabled at the page level. */
}

.legal-byline {
  margin-top: 1.25rem;
  font-family: "Newsreader", Georgia, serif;
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-style: italic;
  font-variation-settings: "opsz" 14;
}

.legal-byline-org {
  font-weight: 500;
  color: var(--text-primary);
}

.legal-byline-sep {
  margin: 0 0.5rem;
  color: var(--text-tertiary);
}

/* ── Layout grid (prose + TOC sidebar) ──
   Single-column by default; two-column at ≥ 1024 px with the prose
   on the left (visual) and the sidebar on the right. DOM order is
   <aside> then <article> so screen readers / keyboard users get
   the in-document nav first; the visual swap happens via explicit
   grid-column placement. */
.legal-layout {
  display: grid;
  grid-template-columns: 1fr;
  max-width: 1100px;
  margin: 0 auto;
  align-items: start;
}

@media (min-width: 1024px) {
  .legal-layout {
    grid-template-columns: minmax(0, 720px) 260px;
    gap: 3rem;
    padding: 0 1.25rem;
    justify-content: center;
  }
  .legal-layout > .legal-prose {
    grid-column: 1;
    grid-row: 1;
  }
  .legal-layout > .legal-toc {
    grid-column: 2;
    grid-row: 1;
  }
}

/* ── Prose container ── */
.legal-prose {
  position: relative;
  max-width: min(720px, 92vw);
  margin: 0 auto;
  padding: 3rem 1.25rem 4rem;
  line-height: 1.7;
  color: var(--text-primary);
  /* Body serif. Newsreader's opsz axis at ~16 gives a generous
     x-height for screen reading. */
  font-family: "Newsreader", Charter, "Iowan Old Style", "Source Serif Pro",
    Georgia, "Times New Roman", serif;
  font-variation-settings: "opsz" 18;
  font-size: 1.0625rem;
  /* Prevent overly long lines on widescreens by capping the
     measure (handled via max-width above); also prevent the
     ``min-width: 0`` issue inside CSS grid. */
  min-width: 0;
}

@media (min-width: 1024px) {
  .legal-prose {
    /* The grid handles centring at desktop sizes; ``margin: 0 auto``
       fights the grid placement, so reset to anchor left in column. */
    margin: 0;
    padding: 4rem 0 5rem;
  }
}

/* "Last updated" line — styled like an editorial dateline. */
.legal-prose > p:first-child {
  font-family: "Fraunces", Georgia, serif;
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 500;
  color: var(--text-tertiary);
  margin-bottom: 2.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--legal-rule);
}

.legal-prose > p:first-child strong {
  /* The "Last Updated:" label inherits the tracked uppercase
     treatment; suppress the bold weight that would compete. */
  font-weight: 600;
  color: var(--text-secondary);
}

/* ── Section headings (H2) ──
   Set with a small section marker ("§") in primary colour,
   followed by the heading in a display-weight Fraunces. */
.legal-prose h2 {
  position: relative;
  font-family: "Fraunces", Georgia, serif;
  font-variation-settings: "opsz" 72, "wght" 500;
  font-size: clamp(1.5rem, 3.5vw, 1.9rem);
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.15;
  margin: 3.5rem 0 1.5rem;
  padding-bottom: 0.875rem;
  color: var(--text-primary);
  /* A thin accent rule under each section heading. */
  border-bottom: 1px solid var(--legal-rule);
  /* Offset for in-page anchor jumps so the heading lands a bit
     below the top of the viewport. */
  scroll-margin-top: 1.5rem;
}

.legal-prose h2:first-of-type {
  margin-top: 0;
}

/* A subtle paragraph indicator (§) in the H2's left margin on
   wide viewports — purely decorative, fades in via CSS. */
@media (min-width: 1024px) {
  .legal-prose h2::before {
    content: "§";
    position: absolute;
    left: -2.25rem;
    top: 0.1em;
    font-family: "Fraunces", Georgia, serif;
    font-variation-settings: "opsz" 144, "wght" 400;
    font-size: 1.4em;
    color: var(--color-primary);
    opacity: 0.7;
  }
}

.legal-prose h3 {
  font-family: "Fraunces", Georgia, serif;
  font-variation-settings: "opsz" 36, "wght" 600;
  font-size: 1.125rem;
  font-weight: 600;
  margin: 2rem 0 0.75rem;
  color: var(--text-primary);
}

/* ── Paragraphs and inline ── */
.legal-prose p {
  margin: 0 0 1.25rem;
}

/* Defined-term emphasis. Markdown's `**Term**` → `<strong>`.
   Render in a slightly heavier weight and a teal tint so legal
   defined terms catch the eye without screaming. */
.legal-prose strong {
  color: var(--text-primary);
  font-weight: 600;
  font-variation-settings: "opsz" 18;
}

/* The clause label at the start of each <li> — same Markdown
   produces `<li><p><strong>The Agreement:</strong> ...</p></li>`.
   We can't target the label specifically without nth-child trickery,
   but the visual emphasis is already there. */

.legal-prose em {
  /* Statutes / acts of parliament: e.g. *Privacy Act 1988* (Cth).
     Newsreader has a true italic — set it explicitly. */
  font-style: italic;
  font-variation-settings: "opsz" 18, "wght" 400;
}

.legal-prose a {
  color: var(--color-primary);
  /* Underline with a soft offset for editorial feel. */
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  text-decoration-color: color-mix(in srgb, var(--color-primary) 50%, transparent);
  transition: text-decoration-color 160ms ease, color 160ms ease;
}

.legal-prose a:hover,
.legal-prose a:focus-visible {
  color: var(--color-primary-dark);
  text-decoration-color: var(--color-primary);
}

.legal-prose a:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ── Numbered clauses ──
   Markdown gives us `<ol start="N"><li><p>...</p></li>...</ol>`.
   We replace the default `1.` marker with a custom display-serif
   clause number positioned in the left margin. The effect mimics
   the way published acts of parliament number their clauses. */
/* @property registration: the typed declaration lets the integer
   value flow through ``counter-reset`` cleanly across all modern
   browsers (Chrome/Edge 85+, Firefox 128+, Safari 16.4+).
   The initial-value of 0 means a normal <ol> (no start attribute)
   starts at "1" after the first counter-increment. */
@property --clause-start {
  syntax: "<integer>";
  inherits: false;
  initial-value: 0;
}

/* Numbered-clause counter.
   ``list-style: none`` means the browser doesn't render its own
   ``::marker``, but ``counter-reset`` still honours an integer in
   the cascade. The renderer side-channels the value of
   ``<ol start="N">`` into ``--clause-start`` (= N-1) so the counter
   reset picks up the right starting value. See
   ``_propagate_ol_start_to_css_var`` in scripts/render_legal_docs.py. */
.legal-prose ol {
  list-style: none;
  margin: 1.75rem 0 2rem;
  padding: 0;
  counter-reset: clause var(--clause-start);
}

.legal-prose ol > li {
  position: relative;
  counter-increment: clause;
  padding-left: 3.25rem;
  margin: 0 0 1.5rem;
  min-height: 2rem;
}

.legal-prose ol > li::before {
  content: counter(clause);
  position: absolute;
  left: 0;
  top: -0.05em;
  width: 2.5rem;
  text-align: right;
  padding-right: 0.625rem;
  font-family: "Fraunces", Georgia, serif;
  font-variation-settings: "opsz" 72, "wght" 400;
  font-size: 1.4rem;
  font-weight: 400;
  color: var(--legal-clause-num);
  /* A hairline divider between the number and the body. */
  border-right: 1px solid var(--legal-rule);
  line-height: 1.4;
}

@media (max-width: 600px) {
  /* On phones, drop the clause number into the line so it doesn't
     consume the slim horizontal real estate. */
  .legal-prose ol > li {
    padding-left: 0;
  }
  .legal-prose ol > li::before {
    position: static;
    display: inline-block;
    width: auto;
    text-align: left;
    padding: 0 0.5rem 0 0;
    border-right: 0;
    border-bottom: 0;
    font-size: 1.15rem;
    margin-right: 0.25rem;
    color: var(--legal-clause-num);
  }
}

/* Nested ol — the (a), (b), (c) sublists inside Platform Limitations
   come through Markdown as nested ordered lists. Drop the big-number
   treatment, use lowercase letters in parens. */
.legal-prose ol ol {
  margin: 0.75rem 0 0;
  counter-reset: subclause;
}

.legal-prose ol ol > li {
  counter-increment: subclause;
  padding-left: 2.25rem;
  margin-bottom: 0.75rem;
  min-height: 0;
}

.legal-prose ol ol > li::before {
  content: "(" counter(subclause, lower-alpha) ")";
  width: 1.75rem;
  font-family: "Newsreader", Georgia, serif;
  font-variation-settings: "opsz" 14;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-secondary);
  border-right: 0;
  padding-right: 0;
  text-align: left;
  top: 0;
}

@media (max-width: 600px) {
  .legal-prose ol ol > li {
    padding-left: 0;
  }
  .legal-prose ol ol > li::before {
    display: inline-block;
    padding-right: 0.375rem;
  }
}

/* ── Unordered lists ── */
.legal-prose ul {
  list-style: none;
  margin: 1rem 0 1.5rem 0;
  padding: 0;
}

.legal-prose ul > li {
  position: relative;
  padding-left: 1.5rem;
  margin-bottom: 0.75rem;
}

.legal-prose ul > li::before {
  /* A small "fleuron"-style bullet, sitting at the baseline. */
  content: "";
  position: absolute;
  left: 0.25rem;
  top: 0.7em;
  width: 6px;
  height: 1px;
  background: var(--color-primary);
}

.legal-prose ul ul {
  margin-top: 0.5rem;
}

.legal-prose hr {
  border: 0;
  border-top: 1px solid var(--legal-rule);
  margin: 2.5rem auto;
  width: 40%;
}

/* Code (rare in legal text but the extensions support it). */
.legal-prose code {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  padding: 0.125rem 0.375rem;
  border-radius: 3px;
  font-size: 0.92em;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono",
    Menlo, Consolas, monospace;
}

.legal-prose pre {
  background: var(--bg-tertiary);
  padding: 1rem;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: 0 0 1rem;
}

.legal-prose pre code {
  background: transparent;
  padding: 0;
}

/* ── Table of contents ──
   On wide viewports it's a sticky sidebar with section numbers
   and a thin colour rail. On narrow viewports it's a collapsible
   <details>. */
.legal-toc {
  padding: 1.5rem 1.25rem 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

@media (min-width: 1024px) {
  .legal-toc {
    position: sticky;
    top: 2rem;
    padding: 4rem 0 0;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
    /* Hide scrollbar chrome unless used — keep the editorial
       silhouette clean. */
    scrollbar-width: thin;
    scrollbar-color: var(--legal-toc-rail) transparent;
  }
  .legal-toc::-webkit-scrollbar {
    width: 6px;
  }
  .legal-toc::-webkit-scrollbar-thumb {
    background: var(--legal-toc-rail);
    border-radius: 3px;
  }
}

.legal-toc-details {
  background: var(--bg-elevated);
  border: 1px solid var(--legal-rule);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
}

@media (min-width: 1024px) {
  .legal-toc-details {
    background: transparent;
    border: 0;
    padding: 0;
  }
  .legal-toc-details[open] > .legal-toc-summary {
    /* Desktop sidebar: the summary acts as a small heading; no
       disclosure triangle. */
    list-style: none;
    cursor: default;
    pointer-events: none;
  }
  .legal-toc-details[open] > .legal-toc-summary::-webkit-details-marker {
    display: none;
  }
}

.legal-toc-summary {
  font-family: "Fraunces", Georgia, serif;
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.25rem 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.legal-toc-summary-marker {
  color: var(--color-primary);
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.1rem;
  font-variation-settings: "opsz" 72;
  line-height: 1;
  letter-spacing: 0;
  text-transform: none;
}

.legal-toc-summary:hover,
.legal-toc-summary:focus-visible {
  color: var(--color-primary);
}

.legal-toc-content {
  margin-top: 1.25rem;
  /* Counter to number TOC entries — the visual section-number
     in the sidebar. */
  counter-reset: toc-section;
}

.legal-toc-content ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.legal-toc-content li {
  counter-increment: toc-section;
  margin: 0;
  /* The thin colour rail on the left of each entry — quiet by
     default, brightens on hover and goes solid teal on active. */
  border-left: 1px solid var(--legal-toc-rail);
  transition: border-color 200ms ease;
}

.legal-toc-content li:hover {
  border-left-color: color-mix(in srgb, var(--color-primary) 50%, transparent);
}

.legal-toc-content a {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
  padding: 0.55rem 0 0.55rem 0.875rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-family: "Newsreader", Georgia, serif;
  font-variation-settings: "opsz" 14;
  font-size: 0.92rem;
  line-height: 1.35;
  font-weight: 400;
  min-height: 32px;
  transition: color 200ms ease, transform 200ms ease;
}

.legal-toc-content a::before {
  /* The TOC section number in a small tracked serif. */
  content: counter(toc-section, decimal-leading-zero);
  font-family: "Fraunces", Georgia, serif;
  font-weight: 500;
  font-variation-settings: "opsz" 14;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  flex: 0 0 auto;
  transition: color 200ms ease;
}

.legal-toc-content a:hover,
.legal-toc-content a:focus-visible {
  color: var(--text-primary);
  transform: translateX(2px);
}

.legal-toc-content a:hover::before,
.legal-toc-content a:focus-visible::before {
  color: var(--color-primary);
}

.legal-toc-content a:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Active (scroll-spy current section) state. JS toggles
   `.is-active` on the matching link as the reader scrolls. */
.legal-toc-content li:has(a.is-active) {
  border-left-color: var(--color-primary);
}

.legal-toc-content a.is-active {
  color: var(--text-primary);
  font-weight: 500;
}

.legal-toc-content a.is-active::before {
  color: var(--color-primary);
}

/* ── Footer ── */
.legal-footer {
  margin-top: auto;
  padding: 3rem 1.25rem 2.5rem;
  border-top: 1px solid var(--legal-rule);
  background: linear-gradient(
    to bottom,
    transparent 0%,
    color-mix(in srgb, var(--legal-paper-edge) 30%, transparent) 100%
  );
  text-align: center;
  color: var(--text-secondary);
}

.legal-footer-inner {
  max-width: 720px;
  margin: 0 auto;
}

.legal-footer-mark {
  margin-bottom: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.legal-footer-logo {
  font-family: "Fraunces", Georgia, serif;
  font-variation-settings: "opsz" 144, "wght" 500;
  font-size: 1.5rem;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.legal-footer-tag {
  font-family: "Newsreader", Georgia, serif;
  font-variation-settings: "opsz" 14;
  font-size: 0.85rem;
  font-style: italic;
  color: var(--text-tertiary);
}

.legal-footer-links {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.5rem;
  font-family: "Fraunces", Georgia, serif;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 500;
}

.legal-footer-links a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 180ms ease;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.legal-footer-links a:hover,
.legal-footer-links a:focus-visible {
  color: var(--color-primary);
}

.legal-footer-links a:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 4px;
  border-radius: 2px;
}

.legal-footer-return {
  margin-top: 1.5rem;
  font-family: "Newsreader", Georgia, serif;
  font-style: italic;
  font-size: 0.9rem;
}

.legal-footer-back {
  color: var(--color-primary);
  text-decoration: none;
  padding: 0.5rem 0;
  display: inline-block;
  min-height: 44px;
  transition: transform 180ms ease;
}

.legal-footer-back:hover,
.legal-footer-back:focus-visible {
  text-decoration: underline;
  transform: translateX(-2px);
}

/* ── Page-load entrance ──
   A calm, single fade-in for the hero + first paragraphs. No
   bouncing or scaling — this is a legal document, not a marketing
   landing. `prefers-reduced-motion` disables the animation. */
@media (prefers-reduced-motion: no-preference) {
  .legal-hero {
    animation: legal-fade-up 800ms cubic-bezier(0.16, 1, 0.3, 1) both;
  }
  .legal-prose > p:first-child {
    animation: legal-fade-up 800ms cubic-bezier(0.16, 1, 0.3, 1) 100ms both;
  }
  .legal-prose > h2:first-of-type,
  .legal-prose > h2:first-of-type + ol {
    animation: legal-fade-up 800ms cubic-bezier(0.16, 1, 0.3, 1) 200ms both;
  }
  .legal-toc {
    animation: legal-fade-in 800ms ease 300ms both;
  }
}

@keyframes legal-fade-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes legal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Smooth in-page scrolling for anchor jumps. */
@media (prefers-reduced-motion: no-preference) {
  html:has(.legal-page) {
    scroll-behavior: smooth;
  }
}

/* ── Narrow viewports (≤ 480 px) ── */
@media (max-width: 480px) {
  .legal-header {
    padding: 1.75rem 1rem 1.5rem;
  }
  .legal-hero {
    padding: 0 0.25rem;
  }
  .legal-title {
    font-size: clamp(1.875rem, 8vw, 2.5rem);
  }
  .legal-kicker {
    font-size: 0.68rem;
  }
  .legal-prose {
    padding: 2rem 1rem 3rem;
    font-size: 1rem;
  }
  .legal-prose ol,
  .legal-prose ul {
    margin-left: 0;
  }
  .legal-nav {
    margin-bottom: 1.5rem;
  }
}

/* ── Print ──
   Patients sometimes want a paper copy. Hide the TOC, nav,
   animations, and footer chrome. Use sober black-on-white. */
@media print {
  .legal-page {
    background: white;
    color: black;
    background-image: none;
  }
  .legal-header,
  .legal-footer {
    border: 0;
    background: transparent;
  }
  .legal-nav,
  .legal-toc,
  .legal-footer-back,
  .legal-footer-tag {
    display: none;
  }
  .legal-layout {
    grid-template-columns: 1fr;
  }
  .legal-prose {
    max-width: 100%;
    margin: 0 auto;
  }
  .legal-hero,
  .legal-prose > p:first-child,
  .legal-prose > h2:first-of-type,
  .legal-prose > h2:first-of-type + ol,
  .legal-toc {
    animation: none;
  }
  .legal-prose h2::before {
    display: none;
  }
}
