/* Shared stylesheet for standalone legal documents served from /legal/*.html
   (and the in-app reader iframe). Self-contained on purpose: these files are
   read outside the app shell (no auth, no build step), so they must not depend
   on the Next.js app CSS. Mirrors the Noir theme in app/globals.css: yellow on
   ink, Inter text, Space Grotesk headings; light and dark styled separately.

   Theme: app/api/legal/[doc]/route.ts injects a tiny script that copies the
   site's next-themes choice (localStorage "theme", dark by default) onto
   <html data-theme>. Without it (no JS, srcDoc reader) the OS preference wins.

   Fonts: latin subsets self-hosted from public/legal/fonts (SIL OFL) — no
   third-party font request on the privacy pages. */

@font-face {
  font-family: "OW Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/legal/fonts/inter-latin.woff2") format("woff2");
}

@font-face {
  font-family: "OW Space Grotesk";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("/legal/fonts/space-grotesk-latin.woff2") format("woff2");
}

:root {
  color-scheme: light;
  --lg-bg: #f6f6f2;
  --lg-fg: #0a0a0b;
  --lg-text: #2b2b30;
  --lg-muted: #5b5b62;
  --lg-border: rgb(10 10 11 / 0.09);
  --lg-surface: #ffffff;
  --lg-surface-edge: rgb(10 10 11 / 0.08);
  --lg-shadow: 0 1px 2px rgb(10 10 11 / 0.05), 0 8px 24px -12px rgb(10 10 11 / 0.18);
  --lg-accent: #ffec00;
  --lg-accent-line: rgb(10 10 11 / 0.2);
  --lg-dot: #ffec00;
  --lg-selection: #ffec00;
  --lg-warn-bg: #fff9c4;
  --lg-warn-border: #ffec00;
  --lg-warn-fg: #0a0a0b;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --lg-bg: #09090b;
  --lg-fg: #f4f4f0;
  --lg-text: #d6d6d0;
  --lg-muted: #a1a1a8;
  --lg-border: rgb(255 255 255 / 0.08);
  --lg-surface: rgb(255 255 255 / 0.04);
  --lg-surface-edge: rgb(255 255 255 / 0.08);
  --lg-shadow: inset 0 1px 0 rgb(255 255 255 / 0.05);
  --lg-accent: #ffec00;
  --lg-accent-line: rgb(255 236 0 / 0.35);
  --lg-dot: #ffec00;
  --lg-selection: #ffec00;
  --lg-warn-bg: #2b2408;
  --lg-warn-border: #6b5300;
  --lg-warn-fg: #f0c74e;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --lg-bg: #09090b;
    --lg-fg: #f4f4f0;
    --lg-text: #d6d6d0;
    --lg-muted: #a1a1a8;
    --lg-border: rgb(255 255 255 / 0.08);
    --lg-surface: rgb(255 255 255 / 0.04);
    --lg-surface-edge: rgb(255 255 255 / 0.08);
    --lg-shadow: inset 0 1px 0 rgb(255 255 255 / 0.05);
    --lg-accent: #ffec00;
    --lg-accent-line: rgb(255 236 0 / 0.35);
    --lg-dot: #ffec00;
    --lg-selection: #ffec00;
    --lg-warn-bg: #2b2408;
    --lg-warn-border: #6b5300;
    --lg-warn-fg: #f0c74e;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: 1.5rem;
}

body {
  margin: 0;
  background: var(--lg-bg);
  color: var(--lg-text);
  font-family: "OW Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

::selection {
  background: var(--lg-selection);
  color: #0a0a0b;
}

a:focus-visible {
  outline: 2px solid var(--lg-accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.legal-doc {
  --lg-col: 760px;
  max-width: 100%;
  min-width: 0;
}

/* ---------- Header ---------- */

.legal-header {
  position: relative;
  border-bottom: 1px solid var(--lg-border);
  padding: 0.65rem clamp(1rem, 4vw, 2.5rem) 0.85rem;
  background: none;
}

/* Kill any leftover horizon glow from older cached stylesheets. */
.legal-header::before,
.legal-header::after {
  content: none !important;
  display: none !important;
}

.legal-header > * {
  max-width: var(--lg-col);
  margin-left: auto;
  margin-right: auto;
}

.legal-header__brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.55rem;
}

.legal-header__brand a {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-family: "OW Space Grotesk", "OW Inter", ui-sans-serif, system-ui, sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--lg-fg);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.legal-header__brand a:not(.back)::before {
  content: "";
  width: 1.35rem;
  height: 1.35rem;
  background: url("/brand/maskot.svg") center / contain no-repeat;
}

/* "← All legal documents" as the site's outline chip. */
.legal-header__brand .back {
  font-family: "OW Inter", ui-sans-serif, system-ui, sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--lg-fg);
  padding: 0.3rem 0.65rem;
  border-radius: 0.45rem;
  background: var(--lg-surface);
  border: 1px solid var(--lg-surface-edge);
  box-shadow: var(--lg-shadow);
  transition: background-color 0.2s, border-color 0.2s;
}

.legal-header__brand .back:hover {
  border-color: var(--lg-accent-line);
}

.legal-header h1 {
  margin-block: 0 0.25rem;
  font-family: "OW Space Grotesk", "OW Inter", ui-sans-serif, system-ui, sans-serif;
  font-size: clamp(1.35rem, 1.15rem + 1vw, 1.75rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--lg-fg);
  text-wrap: balance;
}

.legal-meta {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--lg-muted);
  font-size: 0.8rem;
  margin-block: 0;
}

.legal-meta::before {
  content: "";
  flex: none;
  width: 0.35rem;
  height: 0.35rem;
  border-radius: 999px;
  background: var(--lg-dot);
}

/* Compact header: keep dates if nested here; hide related-doc chips. */
.legal-crosslinks {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0;
}

.legal-crosslinks > .label,
.legal-crosslinks > a {
  display: none;
}

.legal-crosslinks span.label {
  color: var(--lg-muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-right: 0.25rem;
}

.legal-crosslinks a {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--lg-fg);
  text-decoration: none;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: var(--lg-surface);
  border: 1px solid var(--lg-surface-edge);
  box-shadow: var(--lg-shadow);
  transition: border-color 0.2s, color 0.2s;
}

.legal-crosslinks a:hover {
  border-color: var(--lg-accent-line);
  color: var(--lg-accent);
}

/* ---------- Body ---------- */

.legal-body {
  max-width: calc(var(--lg-col) + 2 * clamp(1rem, 4vw, 2.5rem));
  min-width: 0;
  margin: 0 auto;
  padding: clamp(1.25rem, 3vw, 2rem) clamp(1rem, 4vw, 2.5rem) 4rem;
}

.legal-body h1,
.legal-body h2,
.legal-body h3,
.legal-body h4 {
  font-family: "OW Space Grotesk", "OW Inter", ui-sans-serif, system-ui, sans-serif;
  color: var(--lg-fg);
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.3;
  word-break: break-word;
}

/* The body repeats the document title in caps — keep it quiet. */
.legal-body h1 {
  font-size: clamp(1.15rem, 1rem + 0.6vw, 1.4rem);
  margin: 0 0 0.5rem;
}

.legal-body h2 {
  font-size: clamp(1.1rem, 1rem + 0.4vw, 1.3rem);
  margin: 2.75rem 0 0.75rem;
  padding-top: 1.75rem;
  border-top: 1px solid var(--lg-border);
}

.legal-body h3 {
  font-size: 1.05rem;
  margin: 1.75rem 0 0.5rem;
}

.legal-body h4 {
  font-size: 0.95rem;
  margin: 1.5rem 0 0.5rem;
}

.legal-body p,
.legal-body li {
  font-size: 0.975rem;
  word-break: break-word;
}

.legal-body p {
  margin: 0 0 1rem;
}

.legal-body ul,
.legal-body ol {
  padding-left: 1.4rem;
  margin: 0 0 1rem;
}

.legal-body li + li {
  margin-top: 0.4rem;
}

.legal-body li::marker {
  color: var(--lg-muted);
  font-weight: 600;
}

.legal-body li > p {
  margin-bottom: 0.4rem;
}

.legal-body a,
.legal-footer a {
  color: var(--lg-accent);
  text-decoration: underline;
  text-decoration-color: var(--lg-accent-line);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: text-decoration-color 0.2s;
}

.legal-body a:hover,
.legal-footer a:hover {
  text-decoration-color: currentColor;
}

.legal-body strong {
  color: var(--lg-fg);
  font-weight: 650;
}

.legal-body blockquote {
  margin: 0 0 1.25rem;
  padding: 0.85rem 1.1rem;
  border-radius: 0.75rem;
  border: 1px solid var(--lg-surface-edge);
  border-left: 3px solid var(--lg-dot);
  background: var(--lg-surface);
  box-shadow: var(--lg-shadow);
  color: var(--lg-text);
}

.legal-body blockquote > :last-child {
  margin-bottom: 0;
}

.legal-table-wrap {
  overflow-x: auto;
  margin: 1.25rem 0 1.75rem;
  border-radius: 0.875rem;
  border: 1px solid var(--lg-surface-edge);
  background: var(--lg-surface);
  box-shadow: var(--lg-shadow);
}

.legal-body table {
  border-collapse: collapse;
  width: 100%;
  min-width: 480px;
  font-size: 0.85rem;
}

.legal-body th,
.legal-body td {
  border-bottom: 1px solid var(--lg-border);
  padding: 0.65rem 0.85rem;
  text-align: left;
  vertical-align: top;
}

.legal-body tr:last-child td {
  border-bottom: 0;
}

.legal-body thead th,
.legal-body tr:first-child td[colspan] {
  color: var(--lg-fg);
  font-weight: 650;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: color-mix(in srgb, var(--lg-fg) 4%, transparent);
}

.legal-body td p,
.legal-body th p {
  font-size: inherit;
  margin: 0;
}

.legal-body mark {
  background: var(--lg-warn-bg);
  color: var(--lg-warn-fg);
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
}

.legal-todo {
  display: inline-block;
  background: var(--lg-warn-bg);
  border: 1px solid var(--lg-warn-border);
  color: var(--lg-warn-fg);
  font-weight: 700;
  font-size: 0.82em;
  padding: 0.05rem 0.4rem;
  border-radius: 6px;
  white-space: normal;
}

/* ---------- Footer ---------- */

.legal-footer {
  border-top: 1px solid var(--lg-border);
  padding: 1.5rem clamp(1rem, 4vw, 2.5rem) 3rem;
  color: var(--lg-muted);
  font-size: 0.8rem;
  max-width: calc(var(--lg-col) + 2 * clamp(1rem, 4vw, 2.5rem));
  margin: 0 auto;
}

@media print {
  :root,
  :root[data-theme] {
    color-scheme: light;
    --lg-bg: #ffffff;
    --lg-fg: #000000;
    --lg-text: #111111;
    --lg-accent: #000000;
  }

  .legal-header__brand .back,
  .legal-crosslinks > .label,
  .legal-crosslinks > a {
    display: none;
  }
}
