/* DreamGate · /legal/ document layer (W-007, D-036)
   Typeset to docs/design/document-layer.md (G-002); its mock's CSS is the reference. Controls follow
   the button system (G-005). Paper and ink by day, pure red on black at night: no art, gradients,
   shadows or motion. Colours come only from docs/design/tokens.json (light and red palettes). */

:root {
  --paper: #F5F3EF;                 /* light.background */
  --ink: #111111;                   /* light.text        17.0:1 on paper */
  --ink-muted: #4B4B50;             /* light.textMuted    7.8:1 on paper */
  --bronze: #6E5220;                /* light.accent       non-text only (6.6:1) */
  --on-bronze: #FFFFFF;             /* light.onAccent     7.3:1 on bronze */
  --hair: rgba(0, 0, 0, 0.08);      /* light.border */
  --surface: rgba(0, 0, 0, 0.03);   /* light.surface */
  --rule: rgba(17, 17, 17, 0.4);    /* alpha step of light.text: table header rule, outlined controls */
  --red: #FF0000; --red-line: #330000; --red-surface: rgba(255, 0, 0, 0.04);
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --gutter: clamp(16px, 4vw, 32px);
}
[data-theme="document"] {
  color-scheme: light;
  --bg: var(--paper); --fg: var(--ink); --muted: var(--ink-muted);
  --accent: var(--bronze); --accent-ink: var(--on-bronze);
  --line: var(--hair); --line-strong: var(--rule); --card: var(--surface);
}
/* Night mode: the same document, red on true black. Hierarchy from size and weight, never a dimmer red. */
html[data-night="on"] [data-theme="document"] {
  color-scheme: dark;
  --bg: #000000; --fg: var(--red); --muted: var(--red);
  --accent: var(--red); --accent-ink: #000000;
  --line: var(--red-line); --line-strong: var(--red); --card: var(--red-surface);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 72px; background: var(--paper); }
html[data-night="on"] { background: #000000; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
body { margin: 0; font-family: var(--font-sans); -webkit-font-smoothing: antialiased; }
[data-theme] { background: var(--bg); color: var(--fg); }
a { color: inherit; text-decoration-color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
::selection { background: var(--accent); color: var(--accent-ink); }
.skip { position: absolute; left: 12px; top: -64px; z-index: 10; padding: 8px 12px; background: var(--accent); color: var(--accent-ink); }
.skip:focus { top: 12px; }

/* ---------- Draft banner (always first, never sticky) ---------- */
.draft { background: var(--accent); color: var(--accent-ink); font-size: 14px; line-height: 20px; padding: 10px var(--gutter); text-align: center; }
.draft strong { letter-spacing: .06em; text-transform: uppercase; }
.draft a { text-decoration-color: currentColor; }

/* ---------- Document bar ---------- */
.doc-bar { border-bottom: 1px solid var(--line); }
.doc-bar .in { max-width: 1120px; margin: 0 auto; padding: 0 var(--gutter); height: 56px; display: flex; align-items: center; gap: 16px; }
.brand { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; text-decoration: none; color: var(--fg); }
.brand svg { display: block; flex: none; fill: currentColor; }
.brand .mark { width: 24px; height: 24px; }
.brand .word { width: 105.3px; height: 15px; }    /* 15 px tall at the wordmark's 455 × 64.81 ratio */
.crumb { font-size: 14px; color: var(--muted); white-space: nowrap; }
.crumb a { display: inline-flex; align-items: center; min-height: 44px; color: var(--fg); }   /* 44 px tap target (G-002 §6) */
.doc-bar .spacer { flex: 1; }

/* Night toggle (G-005): outlined, radius 14, icon-only on phones. */
.night-toggle {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px 0 12px; border-radius: 14px;
  border: 1px solid var(--line-strong); background: transparent; color: var(--fg); font: 400 14px/1.2 var(--font-sans); cursor: pointer;
  -webkit-tap-highlight-color: transparent; transition: background-color .12s ease, border-color .12s ease;
}
.night-toggle svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
@media (hover: hover) { .night-toggle:hover { border-color: var(--accent); background: var(--card); } }
.night-toggle[aria-pressed="true"] { border-color: var(--accent); background: var(--card); }
.night-toggle[aria-pressed="true"] svg { fill: currentColor; }
@media (max-width: 480px) {
  .night-toggle { width: 44px; padding: 0; justify-content: center; }
  .night-toggle-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* ---------- Shell: contents + document ---------- */
.shell { max-width: 1120px; margin: 0 auto; padding: 0 var(--gutter) 64px; display: grid; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1024px) {
  .shell { grid-template-columns: 232px minmax(0, 68ch); gap: 72px; justify-content: center; }
  .shell-hub { grid-template-columns: minmax(0, 960px); }
}

/* ---------- Contents: a bar on phones, sticky and always open on desktop ---------- */
.toc { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); margin: 0 calc(-1 * var(--gutter)); padding: 0 var(--gutter); }
.toc summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; min-height: 48px; font-size: 15px; font-weight: 600; }
.toc summary::-webkit-details-marker { display: none; }
.toc summary::after { content: ""; flex: none; width: 8px; height: 8px; border-right: 1.5px solid var(--fg); border-bottom: 1.5px solid var(--fg); transform: rotate(45deg); margin-left: auto; margin-top: -4px; }
.toc details[open] summary::after { transform: rotate(-135deg); margin-top: 4px; }
.toc .current { font-weight: 400; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toc ol { list-style: none; margin: 0; padding: 0 0 14px; font-size: 15px; line-height: 22px; }
.toc ol ol { padding: 2px 0 4px 1.9em; font-size: 14px; }
.toc li a { display: flex; gap: 8px; padding: 5px 0 5px 10px; text-decoration: none; border-left: 2px solid transparent; color: var(--fg); }
.toc li a .n { min-width: 1.6em; font-variant-numeric: tabular-nums; color: var(--muted); }
.toc li a:hover { text-decoration: underline; text-decoration-color: var(--accent); }
.toc li a[aria-current="true"] { border-left-color: var(--accent); font-weight: 600; }
@media (min-width: 1024px) {
  .toc { position: sticky; top: 24px; align-self: start; margin: 40px 0 0; padding: 0; border: 0; max-height: calc(100vh - 48px); overflow: auto; }
  .toc summary { pointer-events: none; min-height: 0; padding-bottom: 10px; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; }
  .toc summary::after, .toc .current { display: none; }
}

/* ---------- Document ---------- */
.doc { font-size: 17px; line-height: 28px; padding-top: 40px; min-width: 0; }
.doc p { margin: 0 0 16px; }
.doc code { font-family: var(--font-mono); font-size: .88em; background: var(--card); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; overflow-wrap: anywhere; }
.doc-head { padding-bottom: 8px; }
.eyebrow { font-size: 13px; line-height: 18px; letter-spacing: .08em; text-transform: uppercase; font-weight: 600; color: var(--muted); margin: 0 0 10px; }
.doc h1 { font-size: 34px; line-height: 40px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 16px; text-wrap: balance; }
.lede { font-size: 18px; line-height: 29px; max-width: 68ch; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 22px; margin: 0 0 18px; font-size: 14px; line-height: 20px; color: var(--muted); font-variant-numeric: tabular-nums; }
.meta div { display: flex; gap: 6px; }
.meta dt { font-weight: 600; color: var(--fg); }
.meta dd { margin: 0; }
.status { display: inline-block; font-size: 12px; line-height: 18px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; border: 1px solid var(--accent); border-radius: 6px; padding: 0 8px; color: var(--fg); white-space: nowrap; }
.actions { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; font-size: 14px; }
/* Secondary small button (G-005): outlined, radius 14, keyline-free hover. */
.btn {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border-radius: 14px;
  border: 1px solid var(--line-strong); background: transparent; color: var(--fg); font: 600 14px/1.2 var(--font-sans); cursor: pointer;
  -webkit-tap-highlight-color: transparent; transition: background-color .12s ease, border-color .12s ease;
}
@media (hover: hover) { .btn:hover { border-color: var(--accent); background: var(--card); } }
.btn:active { border-color: var(--accent); background: var(--card); box-shadow: inset 0 0 0 1px var(--accent); }
@media (prefers-reduced-motion: reduce) { .btn, .night-toggle { transition: none; } }
.summary-box { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 16px 20px; margin: 24px 0 8px; }
.summary-box h2 { margin: 0 0 6px; font-size: 13px; line-height: 18px; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; }
.summary-box ul { margin: 0; padding-left: 1.2em; }
.summary-box li { margin: 0 0 4px; }
.summary-box p { margin: 0; }
/* Research notes (W-026): the plain status line every note opens with, before anything else. */
.note-status { margin: 0 0 20px; padding: 10px 14px; max-width: 68ch; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 6px; background: var(--card); font-size: 15px; line-height: 22px; }

/* Emblems (G-002 §10, G-018): the only art in this layer, a 72 px engraving left of the eyebrow and title
   on Security & Data (key) and Methodology & Sources (tree). Decorative; night swaps the file, never a filter. */
.doc-head .title-row { display: grid; grid-template-columns: 72px minmax(0, 1fr); column-gap: 20px; align-items: center; margin: 0 0 16px; }
.doc-head .title-row .eyebrow { margin: 0 0 10px; }
.doc-head .title-row h1 { margin: 0; }
.emblem { display: block; width: 72px; height: 72px; }
.emblem.night { display: none; }
html[data-night="on"] [data-theme="document"] .emblem.day { display: none; }
html[data-night="on"] [data-theme="document"] .emblem.night { display: block; }
@media (max-width: 480px) { .doc-head .title-row { column-gap: 14px; } }

/* Numbered headings: the numbers are written into the HTML at build time, so they survive copy, print and reader modes. */
.doc section > h2 { font-size: 22px; line-height: 30px; font-weight: 600; letter-spacing: -0.01em; margin: 48px 0 12px; padding-top: 24px; border-top: 1px solid var(--line); }
.doc h3 { font-size: 18px; line-height: 27px; font-weight: 600; margin: 32px 0 8px; }
.doc h4 { font-size: 17px; line-height: 28px; font-weight: 600; margin: 24px 0 4px; }
.doc .num { font-variant-numeric: tabular-nums; margin-right: .55em; }
.anchor { margin-left: .4em; font-weight: 400; color: var(--muted); text-decoration: none; opacity: 0; }
:is(h2, h3, h4):hover .anchor, .anchor:focus { opacity: 1; }
@media (min-width: 1024px) {
  .doc :is(h2, h3, h4) { position: relative; }
  .doc :is(section > h2, h3, h4) .num { position: absolute; right: 100%; margin-right: 18px; text-align: right; white-space: nowrap; }
}

/* Lists */
.doc ol, .doc ul { margin: 0 0 16px; padding-left: 2.1em; }
.doc li { margin: 0 0 8px; padding-left: .2em; }
.doc li::marker { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Definitions */
.defs { margin: 8px 0 20px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px 24px; }
.defs dt { font-weight: 600; }
.defs dd { margin: 0 0 12px; }
@media (min-width: 640px) { .defs { grid-template-columns: 11em minmax(0, 1fr); } .defs dd { margin: 0 0 8px; } }

/* Tables: phones scroll a table sideways rather than crushing its columns. */
.table-wrap { overflow-x: auto; margin: 16px 0 24px; }
.doc table { width: 100%; min-width: 34em; border-collapse: collapse; font-size: 15px; line-height: 23px; }
.doc caption { caption-side: top; text-align: left; font-size: 14px; line-height: 20px; color: var(--muted); padding-bottom: 8px; }
.doc th { text-align: left; vertical-align: bottom; font-weight: 600; border-bottom: 1px solid var(--line-strong); padding: 8px 16px 8px 0; }
.doc td { vertical-align: top; border-bottom: 1px solid var(--line); padding: 10px 16px 10px 0; }
.doc td:last-child, .doc th:last-child { padding-right: 0; }

/* Hub: the documents as rows; on phones each row stacks. */
.hub tbody th { vertical-align: top; border-bottom: 1px solid var(--line); padding: 12px 16px 12px 0; font-size: 16px; }
.hub td { padding-top: 12px; padding-bottom: 12px; }
.hub td[data-label] { white-space: nowrap; font-variant-numeric: tabular-nums; }
/* The whole row is the link's tap target (G-002 §6): the title link's box stretches over the row. */
.hub tbody tr { position: relative; }
.hub tbody th a::after { content: ""; position: absolute; inset: 0; }
@media (hover: hover) { .hub tbody tr:hover { background: var(--card); } }
.held { display: block; margin-top: 4px; font-size: 14px; color: var(--muted); }
@media (max-width: 760px) {
  .hub-wrap { overflow: visible; }
  .doc table.hub { min-width: 0; }
  .hub thead { display: none; }
  .hub, .hub tbody, .hub tr, .hub th, .hub td { display: block; }
  .hub caption { display: block; }
  .hub tr { padding: 14px 0; border-bottom: 1px solid var(--line); }
  .hub tbody th, .hub td { border: 0; padding: 0 0 4px; }
  .hub td[data-label] { display: inline-block; margin-right: 18px; font-size: 14px; color: var(--muted); }
  .hub td[data-label]::before { content: attr(data-label) " "; font-weight: 600; color: var(--fg); }
}

/* Callouts: Important (accent rule), Note (strong rule), Placeholder (dashed) */
.callout { background: var(--card); border-left: 3px solid var(--accent); border-radius: 0 6px 6px 0; padding: 14px 18px; margin: 20px 0 24px; font-size: 16px; line-height: 26px; }
.callout p:last-child { margin-bottom: 0; }
.callout .label { display: block; font-size: 12px; line-height: 18px; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; margin-bottom: 4px; }
.callout.note { border-left-color: var(--line-strong); border-left-width: 2px; }
.ph { background: var(--card); border-bottom: 1px dashed var(--accent); padding: 0 3px; font-style: normal; }

/* Footer with the provider block */
.doc-foot { border-top: 1px solid var(--line); font-size: 14px; line-height: 22px; color: var(--muted); }
.doc-foot .in { max-width: 1120px; margin: 0 auto; padding: 28px var(--gutter) 40px; display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 760px) { .doc-foot .in { grid-template-columns: 1.4fr 1fr; } }
.doc-foot address { font-style: normal; }
.doc-foot ul { list-style: none; margin: 0; padding: 0; columns: 2; column-gap: 20px; }
.doc-foot li { display: flex; align-items: center; min-height: 44px; break-inside: avoid; }
.doc-foot a { color: var(--fg); }
.doc-foot nav a { display: inline-flex; align-items: center; min-height: 44px; }   /* links in the address text stay inline */
.doc-foot .soon { font-size: 13px; }

/* ---------- Print: always ink on white, whatever the screen mode (G-002 §7) ----------
   Each page's running footer ("DreamGate · <title> · v<version>") is in assets/css/legal-print/<slug>.css. */
@media print {
  @page { size: A4; margin: 18mm 16mm 20mm; }
  html, html[data-night="on"] { background: #FFFFFF; }
  html[data-night] [data-theme="document"], [data-theme="document"] {
    --bg: #FFFFFF; --fg: #111111; --muted: #4B4B50; --accent: #6E5220; --accent-ink: #111111;
    --line: rgba(0, 0, 0, 0.2); --line-strong: #111111; --card: transparent;
  }
  body { font-size: 10.5pt; }
  .skip, .doc-bar .spacer, .night-toggle, .crumb, .toc, .actions, .anchor, .emblem { display: none !important; }
  .doc-head .title-row { display: block; }
  .doc-bar { border: 0; }
  .doc-bar .in { height: auto; padding: 0 0 8pt; }
  .draft { background: none; color: #111111; border: 1pt solid #111111; text-align: left; padding: 6pt 8pt; margin-bottom: 10pt; font-size: 9pt; }
  .shell { display: block; padding: 0; max-width: none; }
  .doc { font-size: 10.5pt; line-height: 1.5; padding-top: 0; }
  .doc h1 { font-size: 20pt; line-height: 1.2; }
  .doc section > h2 { font-size: 13pt; line-height: 1.3; margin-top: 18pt; padding-top: 8pt; break-after: avoid; }
  .doc h3, .doc h4 { font-size: 11pt; break-after: avoid; }
  .doc .num { position: static !important; }
  .doc p, .doc li { orphans: 3; widows: 3; }
  .doc table, .callout, .defs, .summary-box { break-inside: avoid; }
  .doc table { font-size: 9.5pt; line-height: 1.4; }
  .table-wrap { overflow: visible; }
  .doc table { min-width: 0; }
  .callout { border-left-width: 2pt; }
  .doc a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 8.5pt; color: #4B4B50; word-break: break-all; }
  .doc-foot { border-top: .5pt solid #111111; }
  .doc-foot .in { padding: 10pt 0 0; display: block; }
  .doc-foot nav { display: none; }
}
