/*
  Legal pages (/impressum /datenschutz /nutzungsbedingungen, /legal-notice /privacy /terms): page-specific
  styles only. Loaded after styles.css and motion.css on these pages only (scripts/build.mjs › SUBPAGES).
  Markup: scripts/pages/legal.mjs (the legal wording comes unchanged from content/).
  Layout (subpage spec §5): document header on the shell edge (H1, meta line), then
    privacy / terms : .side-layout = sticky TOC (240px) | reading column (≤ 720px, text ≤ 68ch);
                      numbers hang left of the section titles so titles and text share one edge;
                      ≤ 960px the TOC is a collapsed <details> card at the top of the document.
    imprint         : a sheet of cards (provider spans two rows), one column ≤ 640px.
  Motion: none besides the header (legal.js only marks the active TOC entry; the indicator scales,
  transform only). Rules: the two literal breakpoints; no hidden start states.
*/

.legal { padding-block: var(--page-top) var(--space-8); }

/* Document header: H1 at the H2 size (a document, not a marketing hero), meta line from the source. */
.legal-head { padding-bottom: var(--space-7); }
/* 8.2vw keeps one-word German titles ("Nutzungsbedingungen") on one line down to 320px. */
.legal-head h1 { font-size: min(var(--fs-h2), 8.2vw); line-height: var(--lh-heading); overflow-wrap: break-word; hyphens: auto; }
.legal .legal-meta { max-width: none; margin-top: var(--space-4); font-size: var(--fs-meta); line-height: 1.5; color: var(--muted); }

/* Running text (also inside the note and the imprint cards). */
.legal p, .legal li { max-width: var(--measure); font-size: var(--fs-body); line-height: var(--lh-long); color: var(--ink-2); }
.legal p + p, .legal p + ul, .legal ul + p { margin-top: var(--space-3); }
.legal ul { margin: var(--space-3) 0 0; padding-left: 20px; }
.legal li + li { margin-top: var(--space-1); }
.legal li::marker { color: var(--muted); }
.legal strong { color: var(--ink); font-weight: 500; }
.legal :is(.legal-section, .legal-card, .legal-note) :is(p, li) a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--line-strong); text-decoration-thickness: 1px; text-underline-offset: 3px; overflow-wrap: anywhere; transition: text-decoration-color var(--dur-micro) var(--ease-out); }
.legal :is(.legal-section, .legal-card, .legal-note) :is(p, li) a:hover { text-decoration-color: currentColor; }
.legal code { padding: 1px 3px; border-radius: 4px; background: var(--surface-hover); font: 400 .875em/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--ink); }

/* Draft / translation note: the shared .callout; same paragraphs as the source. */
.legal-note { max-width: none; }
.legal .legal-note p { font-size: var(--fs-ui); line-height: 1.6; }
.legal .legal-note p + p { margin-top: var(--space-3); }

/* Section headings: number column + title + "#" anchor. */
.legal-heading { display: flex; align-items: flex-start; gap: var(--space-1); max-width: calc(var(--measure) + 48px); margin: 56px 0 var(--space-3); }
/* Number column: 3ch + 12px gap, so three-character numbers ("14a") keep the same gap as "8a". */
.legal-heading h2 { display: grid; grid-template-columns: 48px minmax(0, 1fr); align-items: baseline; min-width: 0; font-size: var(--fs-title); line-height: var(--lh-title); font-weight: 600; letter-spacing: var(--tracking-title); text-wrap: pretty; overflow-wrap: break-word; hyphens: auto; }
.legal-heading h2.legal-h--plain { display: block; }
.legal-heading h2 .legal-title { color: var(--ink); }
.legal-num { font: 500 var(--fs-title)/var(--lh-title) var(--font); letter-spacing: 0; color: var(--muted); font-variant-numeric: tabular-nums; }
/* Hit area 44px; centred on the first title line (22px × 1.3 ≈ 29px). Visible on hover/focus, always on touch. */
.heading-anchor { display: inline-grid; place-items: center; flex: none; width: var(--touch); height: var(--touch); margin-top: -8px; border-radius: var(--radius-sm); font: 500 18px/1 var(--font); color: var(--muted); opacity: 0; transition: opacity var(--dur-ui) var(--ease-standard), color var(--dur-micro) var(--ease-out); }
.legal-heading:hover .heading-anchor, .heading-anchor:focus-visible { opacity: 1; }
.heading-anchor:hover { color: var(--ink); }
.heading-anchor:focus-visible { outline: 2px solid var(--ink); outline-offset: -4px; }
@media (hover: none) { .heading-anchor { opacity: 1; } }

/* Long documents: sticky TOC beside the reading column (shared .side-layout / .side-nav). */
.legal-doc { align-items: start; }
.legal-body { min-width: 0; }
/* ≤ 960px the collapsed TOC card comes first, then the note. */
@media (max-width: 960px) { .legal-body > .legal-toc-mobile + .legal-note { margin-top: var(--space-5); } }
/* Wide screens: the number hangs into the column gap, so titles and paragraphs share one edge. */
@media not all and (max-width: 960px) {
  .legal--doc .legal-heading h2:not(.legal-h--plain) { margin-left: -48px; }
  /* Hanging numbers sit flush right with a fixed 12px gap, whatever their length ("8a", "14a"). */
  .legal--doc .legal-heading h2:not(.legal-h--plain) .legal-num { justify-self: end; padding-right: var(--space-3); }
}
.legal-toc ol { padding-block: 2px; }
/* A TOC taller than the viewport scrolls in its own box; legal.js marks the clipped edge(s) and a
   48px fade shows that more entries follow (static: no animation). */
.legal-toc[data-more=below] { -webkit-mask-image: linear-gradient(#000 calc(100% - 48px), #0000); mask-image: linear-gradient(#000 calc(100% - 48px), #0000); }
.legal-toc[data-more=above] { -webkit-mask-image: linear-gradient(#0000, #000 48px); mask-image: linear-gradient(#0000, #000 48px); }
.legal-toc[data-more=both] { -webkit-mask-image: linear-gradient(#0000, #000 48px, #000 calc(100% - 48px), #0000); mask-image: linear-gradient(#0000, #000 48px, #000 calc(100% - 48px), #0000); }
.legal-toc a { display: grid; grid-template-columns: 36px minmax(0, 1fr); align-content: center; align-items: baseline; gap: 0; padding-block: 4px; padding-right: var(--space-2); min-height: var(--touch); font-size: var(--fs-meta); line-height: 1.5; text-wrap: pretty; }
.legal-toc a .toc-num { color: var(--muted); font-variant-numeric: tabular-nums; }
.legal-toc a:is([aria-current], [data-active]) .toc-num { color: var(--ink-2); }

/* Tablets and phones: the TOC as one collapsed card at the top of the document (native <details>). */
.legal-toc-mobile { border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); }
.legal-toc-mobile > summary { min-height: 48px; padding: 12px var(--space-5); font-size: var(--fs-ui); font-weight: 500; }
.legal-toc-mobile > summary:focus-visible { outline-offset: 2px; border-radius: var(--radius-md); }
.legal-toc-mobile nav { padding: 0 var(--space-5) var(--space-3); border-top: 1px solid var(--line); }
.legal-toc-mobile ol { list-style: none; margin: 0; padding: var(--space-2) 0 0; }
.legal-toc-mobile a { display: grid; grid-template-columns: 32px minmax(0, 1fr); align-content: center; align-items: baseline; min-height: var(--touch); padding-block: 6px; font-size: var(--fs-ui); line-height: 1.5; color: var(--ink-2); }
.legal-toc-mobile a:hover, .legal-toc-mobile a[aria-current] { color: var(--ink); }
.legal-toc-mobile a:focus-visible { outline-offset: 0; }
.legal-toc-mobile .toc-num { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Short documents (imprint / legal notice): a sheet of cards. */
.legal--sheet .legal-note { margin-bottom: var(--space-5); }
.legal-sheet { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-5); align-items: stretch; }
.legal-sheet > .legal-card:first-child { grid-row: span 2; }
.legal-card .legal-heading { margin: -8px 0 var(--space-3); }
.legal-card > p { font-size: var(--fs-body); }

/* Back to top (long documents): hairline, then one text link to the start of <main>. */
.legal .legal-top { max-width: none; margin-top: var(--space-8); padding-top: var(--space-4); border-top: 1px solid var(--line); }
.legal-top .text-link { gap: var(--space-2); color: var(--ink-2); }
.legal-top .text-link:hover { color: var(--ink); }
.legal-top .text-link svg { transition: transform var(--dur-micro) var(--ease-out); }
.legal-top .text-link:hover svg { transform: translateY(-3px); }

@media (max-width: 960px) {
  .legal-head { padding-bottom: var(--space-6); }
}
@media (max-width: 640px) {
  .legal-sheet { grid-template-columns: minmax(0, 1fr); }
  .legal-sheet > .legal-card:first-child { grid-row: auto; }
  .legal-heading { margin-top: var(--space-7); }
  .legal-heading h2 { grid-template-columns: 36px minmax(0, 1fr); }
  .legal-toc-mobile > summary { padding-inline: var(--space-4); }
  .legal-toc-mobile nav { padding-inline: var(--space-4); }
}

/* Print: the document only, full width; no navigation, anchors or back link. */
@media print {
  .legal-toc, .legal-toc-mobile, .heading-anchor, .legal-top { display: none !important; }
  .legal-doc, .legal-sheet { display: block; }
  .legal-card { padding: 0; border: 0; background: none; }
  .legal-card + .legal-card { margin-top: var(--space-6); }
  .legal--doc .legal-heading h2:not(.legal-h--plain) { margin-left: 0; }
  .legal p, .legal li, .legal-note { max-width: none; }
}
