/* Aufilm legal pages: sober long-form reading layout.
   Tokens come from theme.css (night / cream / signal red, Hanken Grotesk).
   Light is the default; dark follows data-theme="dark" or, with no choice
   stored, the system preference. Mobile first; print friendly. */

/* No stored choice and no script: follow the system. (legal.js normally sets
   data-theme before first paint, so this only matters without JavaScript.) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0E0D0B; --card: #17150F; --card2: #1D1A14; --edit: #221F18; --sel: #2A261D;
    --ink: #EFE7D2; --title: #EFE7D2; --muted: #A79F8E; --faint: #7A7365;
    --line: #2E2A22; --line2: #221F19;
    --red: #E2553F; --red-hover: #EE6F5B;
  }
}

html { scroll-behavior: smooth; scroll-padding-top: 76px; -webkit-text-size-adjust: 100%; }
body.legal {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 17px/1.7 var(--font-ui);
  min-height: 100vh; display: flex; flex-direction: column;
}
body.legal a { color: var(--red); text-underline-offset: 3px; text-decoration-thickness: 1px; }
body.legal a:hover { color: var(--red-hover); }
body.legal :focus-visible { outline: 2px solid var(--red); outline-offset: 2px; border-radius: 2px; }

.skip {
  position: absolute; left: 12px; top: -48px; z-index: 100; background: var(--ink); color: var(--bg) !important;
  padding: 10px 14px; border-radius: 4px; font: 700 13px/1 var(--font-ui); text-decoration: none;
}
.skip:focus { top: 12px; }

/* ---------------------------------------------------------------- top bar */
.legal-top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--night); color: var(--cream);
  padding: 0 16px; min-height: 58px; border-bottom: 1px solid #000;
}
.legal-brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--cream) !important; min-width: 0; }
.legal-brand .mark { width: 34px; height: 34px; object-fit: contain; flex: none; }
.legal-brand .wordmark { font: 800 16px/1 var(--font-ui); letter-spacing: .2em; color: var(--cream); }
.legal-brand .by { font: 700 9px/1 var(--font-ui); letter-spacing: .26em; text-transform: uppercase; color: rgba(239,231,210,.6); white-space: nowrap; }
.legal-top-r { display: flex; align-items: center; gap: 6px; }
.legal-top .top-link {
  color: var(--cream) !important; text-decoration: none; font: 600 13px/1 var(--font-ui);
  padding: 10px 8px; border-radius: 4px;
}
.legal-top .top-link:hover, .legal-top .top-link.is-current { text-decoration: underline; text-underline-offset: 4px; }
.legal-top .top-link { white-space: nowrap; }
@media (max-width: 560px) { .legal-brand .by { display: none; } }
.legal-top .theme-btn { display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 6px; cursor: pointer; font-size: 18px; line-height: 1;
  background: transparent; color: var(--cream); border: 1px solid rgba(239,231,210,.28);
}
.legal-top .theme-btn:hover { background: rgba(239,231,210,.1); }

/* ----------------------------------------------------------------- layout */
.legal-wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 22px 16px 48px; flex: 1 0 auto; display: block; }
.legal-doc { max-width: 44rem; min-width: 0; }
.legal-wrap-index .legal-doc { max-width: 46rem; margin-inline: auto; }

.toc { margin-bottom: 20px; }
.toc-box { border: 1px solid var(--line); border-radius: 6px; background: var(--card); }
.toc-box > summary {
  cursor: pointer; padding: 12px 14px; list-style: none;
  font: 700 11px/1 var(--font-ui); letter-spacing: .14em; text-transform: uppercase; color: var(--muted);
}
.toc-box > summary::-webkit-details-marker { display: none; }
.toc-box > summary::after { content: "＋"; float: right; }
.toc-box[open] > summary::after { content: "－"; }
.toc ol { margin: 0; padding: 4px 14px 14px 36px; font-size: 14px; line-height: 1.5; columns: 1; }
.toc li { margin: 0; padding: 3px 0; }
.toc a { color: var(--ink) !important; text-decoration: none; }
.toc a:hover { color: var(--red) !important; text-decoration: underline; }
.toc li::marker { color: var(--faint); font-size: 12px; }

@media (min-width: 960px) {
  .legal-wrap { display: grid; grid-template-columns: 250px minmax(0, 1fr); column-gap: 56px; padding-top: 40px; }
  .legal-wrap-index { display: block; }
  .toc { margin: 0; position: sticky; top: 82px; align-self: start; max-height: calc(100vh - 100px); overflow-y: auto; }
  .toc-box { border: 0; background: transparent; }
  .toc-box > summary { padding: 0 0 10px; cursor: default; pointer-events: none; }
  .toc-box > summary::after, .toc-box[open] > summary::after { content: none; }
  .toc ol { padding: 0 0 0 18px; font-size: 13px; }
  .legal-doc { max-width: 46rem; }
}

/* ------------------------------------------------------------- typography */
.kicker { margin: 0 0 12px; font: 700 11px/1 var(--font-ui); letter-spacing: .22em; text-transform: uppercase; color: var(--red); }
.legal-doc h1 {
  margin: 0 0 12px; font: 800 clamp(30px, 6.5vw, 44px)/1.08 var(--font-ui);
  letter-spacing: -.02em; text-transform: uppercase; color: var(--title);
}
.meta { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 0 0 8px; color: var(--muted); font: 600 13px/1.5 var(--font-ui); font-variant-numeric: tabular-nums; }
.governs { margin: 0 0 26px; padding-bottom: 22px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 14px; line-height: 1.55; }
.legal-doc h2 { margin: 0 0 12px; font: 700 clamp(20px, 3.4vw, 24px)/1.25 var(--font-ui); letter-spacing: -.01em; color: var(--title); }
.legal-doc p { margin: 0 0 14px; }
.legal-doc ul, .legal-doc ol { margin: 0 0 16px; padding-left: 1.35em; }
.legal-doc li { margin: 0 0 8px; padding-left: 4px; }
.legal-doc li::marker { color: var(--muted); }
.legal-doc strong { font-weight: 700; color: var(--title); }
.sec { padding: 30px 0 4px; border-top: 1px solid var(--line); }
.intro { margin: 0 0 8px; }
.intro p { font-size: 18px; }

.note {
  margin: 16px 0; padding: 14px 16px; background: var(--card); border: 1px solid var(--line);
  border-left: 3px solid var(--red); border-radius: 4px; font-weight: 500;
}

/* ------------------------------------------------------------ summary box */
.summary {
  margin: 0 0 30px; padding: 20px 18px 8px; background: var(--card); border: 1px solid var(--line);
  border-top: 3px solid var(--red); border-radius: 6px; box-shadow: var(--shadow);
}
.summary h2 { margin: 0 0 4px; font: 800 13px/1.2 var(--font-ui); letter-spacing: .16em; text-transform: uppercase; color: var(--title); }
.summary-lead { margin: 0 0 14px !important; color: var(--muted); font-size: 14px; font-style: italic; }
.summary-cols { display: grid; gap: 4px 28px; grid-template-columns: 1fr; }
.summary h3 { margin: 6px 0 8px; font: 700 11px/1 var(--font-ui); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.summary ul { list-style: none; padding: 0; margin: 0 0 12px; }
.summary li { position: relative; padding: 0 0 0 26px; margin: 0 0 10px; font-size: 15.5px; line-height: 1.55; }
.summary li::before { position: absolute; left: 0; top: 0; font-weight: 800; }
.summary ul.yes li::before { content: "✓"; color: var(--green); }
.summary ul.no li::before { content: "✕"; color: var(--red); }
[data-theme="dark"] .summary ul.yes li::before { color: #7FB88A; }
@media (min-width: 700px) { .summary-cols { grid-template-columns: 1fr 1fr; } .summary { padding: 22px 24px 10px; } }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; margin: 6px 0 20px; border: 1px solid var(--line); border-radius: 6px; -webkit-overflow-scrolling: touch; }
.table-wrap:focus-visible { outline-offset: 0; }
.legal-doc table { width: 100%; border-collapse: collapse; font-size: 14.5px; line-height: 1.5; min-width: 540px; }
.legal-doc th {
  text-align: left; padding: 10px 12px; background: var(--card2); color: var(--muted);
  font: 700 11px/1.2 var(--font-ui); letter-spacing: .1em; text-transform: uppercase; border-bottom: 1px solid var(--line);
}
.legal-doc td { padding: 10px 12px; border-top: 1px solid var(--line2); vertical-align: top; }
.legal-doc tbody tr:first-child td { border-top: 0; }
.legal-doc td:first-child { min-width: 150px; }

/* Narrow screens: each table row becomes a labelled card (no sideways scrolling). */
@media (max-width: 640px) {
  .table-wrap { border: 0; overflow: visible; margin-top: 0; }
  .legal-doc table, .legal-doc tbody, .legal-doc tr, .legal-doc td { display: block; min-width: 0; width: 100%; }
  .legal-doc thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .legal-doc tr { margin: 0 0 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); padding: 4px 0; }
  .legal-doc td, .legal-doc tbody tr:first-child td { border: 0; padding: 6px 12px; }
  .legal-doc td:first-child { min-width: 0; font-weight: 700; color: var(--title); }
  .legal-doc td::before {
    content: attr(data-label); display: block; margin-bottom: 1px; color: var(--muted);
    font: 700 10.5px/1.3 var(--font-ui); letter-spacing: .1em; text-transform: uppercase;
  }
  .legal-doc td:first-child::before { display: none; }
}

/* --------------------------------------------------------- index + links */
.legal-doc .doc-cards { list-style: none; margin: 26px 0 8px; padding: 0; display: grid; gap: 14px; }
.doc-card { margin: 0 !important; padding: 18px 18px 6px !important; background: var(--card); border: 1px solid var(--line); border-radius: 6px; }
.doc-card-title { font: 800 19px/1.25 var(--font-ui); letter-spacing: -.01em; text-decoration: none; color: var(--title) !important; }
.doc-card-title:hover { color: var(--red) !important; text-decoration: underline; }
.doc-card p { margin: 6px 0 10px; }
.doc-card .doc-card-meta { color: var(--muted); font: 600 13px/1.4 var(--font-ui); font-variant-numeric: tabular-nums; }
@media (min-width: 700px) { .doc-cards { grid-template-columns: 1fr 1fr; } }

.doc-links { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 36px 0 0; padding-top: 20px; border-top: 1px solid var(--line); font-size: 14px; }
.doc-links a[aria-current="page"] { color: var(--ink) !important; font-weight: 700; text-decoration: none; }

/* ----------------------------------------------------------------- print */
@media print {
  html { scroll-behavior: auto; }
  body.legal { background: #fff !important; color: #000 !important; font-size: 11pt; line-height: 1.5; display: block; }
  .legal-top, .toc, .skip, .site-legal nav, .doc-links { display: none !important; }
  .legal-wrap { display: block; padding: 0; max-width: none; }
  .legal-doc { max-width: none; }
  .legal-doc h1, .legal-doc h2, .legal-doc strong, .meta, .governs, .kicker { color: #000 !important; }
  .legal-doc h2 { break-after: avoid; }
  .sec, .summary, .note, .table-wrap, tr { break-inside: avoid; }
  .summary, .note, .table-wrap { box-shadow: none; background: #fff !important; border-color: #999; }
  body.legal a { color: #000 !important; text-decoration: underline; }
  .site-legal { border-top: 1px solid #999; color: #000; }
  .table-wrap { overflow: visible; }
  .legal-doc table { min-width: 0; }
}

@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
