/* dorwij.to — the stylesheet of the two legal pages, /regulamin and /prywatnosc (plan 019 §A).
 *
 * ─── why a separate, hand-written file ───────────────────────────────────────────────
 *
 * The legal pages are static HTML in `public/`, copied verbatim into `dist/` and served by
 * Caddy without the SPA: they must open, read and print with JavaScript off, on a phone that
 * has never loaded the app. Under the site's CSP (`style-src 'self'`) an inline <style> or a
 * style="" attribute is refused outright, so this file is the ONLY place their look can live.
 *
 * It echoes `web/src/theme.css` — the same Public Sans files, the same oklch palette in both
 * themes, the same rule that green is spent only on the `.to` of the logo — but it imports
 * nothing from the app. The SPA's bundle has a content-hashed name that changes on every
 * build; linking it from a page meant to be stable for years would break on the next deploy.
 * If the app's tokens move, move the copies below with them.
 *
 * ─── reading, not using ──────────────────────────────────────────────────────────────
 *
 * The app is set for ten-second glances. These pages are read start to finish, maybe
 * printed, maybe quoted back in a complaint — so: a ~70ch column, a looser line height than
 * the app's, list numbers that stay visible (ust. 3 of §7 is cited by number from the other
 * document), and a print stylesheet that drops the chrome.
 */

/* Self-hosted, from the same origin (CSP: fonts fall back to `default-src 'self'`). Both
   subsets: Polish lives in latin-ext, and without it ą ć ę ł ń ó ś ź ż would drop to a system
   face mid-word. unicode-range keeps each file lazy. */
@font-face {
  font-family: "Public Sans";
  font-style: normal;
  font-weight: 300 800;
  font-display: swap;
  src: url("/fonts/public-sans-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304,
    U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0,
    U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Public Sans";
  font-style: normal;
  font-weight: 300 800;
  font-display: swap;
  src: url("/fonts/public-sans-latin-wght-normal.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;
}

/* Polish legal numbering: ustępy "1.", punkty "1)". Browsers without @counter-style keep
   the decimal declared first, which still reads correctly. */
@counter-style punkt {
  system: extends decimal;
  suffix: ") ";
}

/* ─── tokens (copies of theme.css) ─────────────────────────────────────────────────── */

:root {
  color-scheme: light dark;

  --sans: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --bg: oklch(0.985 0.004 70);
  --surface: oklch(1 0 0);
  --surface-sunken: oklch(0.955 0.005 70);
  --border: oklch(0.9 0.005 70);
  --border-strong: oklch(0.82 0.006 70);
  --text: oklch(0.2 0.008 60);
  --text-muted: oklch(0.48 0.008 60);
  --live: oklch(0.52 0.155 155);
  --focus: oklch(0.55 0.16 250);
  --shade: oklch(0.2 0.008 60 / 14%);

  --measure: 70ch;
  --gutter: max(1rem, env(safe-area-inset-left), env(safe-area-inset-right));
  --r-control: 8px;
  --r-row: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: oklch(0.155 0.006 250);
    --surface: oklch(0.205 0.007 250);
    --surface-sunken: oklch(0.175 0.006 250);
    --border: oklch(0.32 0.009 250);
    --border-strong: oklch(0.42 0.01 250);
    --text: oklch(0.94 0.004 250);
    --text-muted: oklch(0.62 0.008 250);
    --live: oklch(0.72 0.135 155);
    --focus: oklch(0.72 0.13 250);
    --shade: oklch(0 0 0 / 45%);
  }
}

/* The same night when it is CHOSEN (Ustawienia › Wygląd, the landing's button: public/theme.js),
   whatever the system says. Keep this block identical to the one above:
   test/spa-rules.test.ts compares them. */
:root[data-theme="dark"] {
  --bg: oklch(0.155 0.006 250);
  --surface: oklch(0.205 0.007 250);
  --surface-sunken: oklch(0.175 0.006 250);
  --border: oklch(0.32 0.009 250);
  --border-strong: oklch(0.42 0.01 250);
  --text: oklch(0.94 0.004 250);
  --text-muted: oklch(0.62 0.008 250);
  --live: oklch(0.72 0.135 155);
  --focus: oklch(0.72 0.13 250);
  --shade: oklch(0 0 0 / 45%);
}

:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

/* ─── page ──────────────────────────────────────────────────────────────────────────── */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  /* 17px, the app's reading size, in rem so system text scaling is honoured. */
  font-size: 1.0625rem;
  /* Looser than the app's 1.5: this is continuous prose, and Polish descenders (ą, ę) need
     the room. */
  line-height: 1.6;
  text-wrap: pretty;
  /* A real e-mail address or street address in place of a placeholder can be one long
     unbroken token; at 360px it must wrap, not push the page sideways. */
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 1rem var(--gutter) max(3rem, env(safe-area-inset-bottom));
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-control);
}

a {
  color: inherit;
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 0.2em;
}

a:hover {
  text-decoration-color: currentColor;
}

/* ─── masthead ──────────────────────────────────────────────────────────────────────── */

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding-block: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
}

/* Same wordmark as the app: lowercase, with the suffix, `.to` in green — the one place green
   does not mean "available". */
.logo {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.035em;
  text-decoration: none;
  white-space: nowrap;
}

.logo > .tld {
  color: var(--live);
}

.docnav {
  display: flex;
  gap: 1.25rem;
  font-size: 0.9375rem;
}

.docnav a {
  display: inline-block;
  padding-block: 0.625rem; /* a 44px-ish touch target without looking like a button */
  color: var(--text-muted);
  text-decoration: none;
}

.docnav a:hover,
.docnav a[aria-current="page"] {
  color: var(--text);
}

.docnav a[aria-current="page"] {
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.35em;
  text-decoration-color: currentColor;
}

/* ─── document ──────────────────────────────────────────────────────────────────────── */

h1 {
  margin: 2rem 0 0.25rem;
  font-size: clamp(1.5rem, 1.2rem + 1.5vw, 2rem);
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.version {
  margin: 0 0 1.5rem;
  color: var(--text-muted);
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}

h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1875rem;
  line-height: 1.3;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

/* One hairline between sections: the reader sees where a paragraph (§) ends without the page
   turning into a form. `scroll-margin` keeps a heading reached by #s7 off the very top edge. */
.doc section {
  padding-block: 1.5rem 0.25rem;
  border-top: 1px solid var(--border);
  scroll-margin-top: 1rem;
}

.doc p {
  margin: 0 0 0.875rem;
}

.doc ol {
  margin: 0 0 0.875rem;
  padding-left: 1.75em;
  list-style-type: decimal;
}

.doc ol ol {
  margin: 0.375rem 0 0;
  padding-left: 1.75em;
  list-style-type: decimal;
  list-style-type: punkt;
}

.doc li {
  margin-bottom: 0.5rem;
  padding-left: 0.25em;
}

.doc li::marker {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.doc strong {
  font-weight: 650;
}

/* ─── table of contents ─────────────────────────────────────────────────────────────── */

/* A <details>, so it costs one line on a phone and needs no script to open. */
.toc {
  margin: 0 0 1.5rem;
}

.toc details {
  border: 1px solid var(--border);
  border-radius: var(--r-row);
  background: var(--surface);
}

.toc summary {
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9375rem;
  border-radius: var(--r-row);
}

.toc ol {
  margin: 0;
  padding: 0 1rem 0.75rem 1rem;
  list-style: none;
  font-size: 0.9375rem;
}

.toc li {
  margin: 0;
}

.toc a {
  display: block;
  padding-block: 0.3rem;
  text-decoration: none;
}

.toc a:hover {
  text-decoration: underline;
}

/* ─── the privacy table ─────────────────────────────────────────────────────────────── */

/* Three columns of prose do not fit 360px, and squeezing them does worse than scrolling: the
   legal basis column would wrap one word per line. So the table keeps a readable minimum
   width and its wrapper scrolls sideways. The wrapper is focusable (tabindex, role=region)
   so a keyboard user can scroll it too; the edge shadows — pure CSS, `local` covers over
   `scroll` shades — show that there is more to the side on phones that hide scrollbars. */
.table-scroll {
  margin: 0 0 1rem;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-row);
  background:
    linear-gradient(to right, var(--surface) 30%, transparent) left center / 2.5rem 100% no-repeat local,
    linear-gradient(to left, var(--surface) 30%, transparent) right center / 2.5rem 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, var(--shade), transparent) left center / 0.75rem 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, var(--shade), transparent) right center / 0.75rem 100% no-repeat scroll,
    var(--surface);
}

.table-scroll table {
  width: 100%;
  min-width: 36rem;
  border-collapse: collapse;
  font-size: 0.9375rem;
  line-height: 1.5;
}

.table-scroll th,
.table-scroll td {
  padding: 0.75rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

.table-scroll tbody tr:last-child > * {
  border-bottom: 0;
}

.table-scroll thead th {
  font-size: 0.84375rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom-color: var(--border-strong);
}

.table-scroll tbody th {
  font-weight: 550;
  width: 36%;
}

.table-scroll td:last-child {
  width: 26%;
}

/* ─── footer ────────────────────────────────────────────────────────────────────────── */

.docfoot {
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.9375rem;
}

.docfoot p {
  margin: 0 0 0.5rem;
}

.docfoot nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.25rem;
}

.docfoot nav a {
  display: inline-block;
  padding-block: 0.5rem;
}

/* ─── print ─────────────────────────────────────────────────────────────────────────── */

/* The regulamin promises a form "którą można pobrać, zapisać i wydrukować" (§11 ust. 3).
   On paper: black on white whatever the screen theme, no navigation, no contents box, the
   table unrolled at full width, and a cross-reference that shows where it points. */
@media print {
  :root,
  :root[data-theme] {
    color-scheme: light;
    --bg: #fff;
    --surface: #fff;
    --text: #000;
    --text-muted: #333;
    --border: #bbb;
    --border-strong: #888;
    --live: #000;
  }

  @page {
    margin: 18mm 16mm;
  }

  body {
    font-size: 10.5pt;
    line-height: 1.45;
  }

  .page {
    max-width: none;
    padding: 0;
  }

  .docnav,
  .toc,
  .docfoot nav {
    display: none;
  }

  a {
    text-decoration: none;
  }

  a.xref::after {
    content: " (dorwij.to" attr(href) ")";
    color: var(--text-muted);
  }

  h1 {
    margin-top: 1rem;
    font-size: 18pt;
  }

  h2 {
    break-after: avoid;
    font-size: 12pt;
  }

  .doc section {
    padding-top: 0.75rem;
  }

  li,
  tr {
    break-inside: avoid;
  }

  .table-scroll {
    overflow: visible;
    border: 0;
    background: none;
  }

  .table-scroll table {
    min-width: 0;
    font-size: 9.5pt;
  }

  .table-scroll th,
  .table-scroll td {
    padding: 0.4rem 0.5rem 0.4rem 0;
  }
}
