/* The legal pages: privacy policy and terms.
 *
 * Loaded after `tokens.css` and `base.css`, and composing their classes rather
 * than redefining them. Every colour, size and space below is a token.
 *
 * A legal page is the page a visitor opens when they have already decided they
 * might trust you and want to check. So it is set as a document — a contents
 * column that stays with you, a fixed measure for the prose, real numbered
 * headings that survive being copied into an email, and one table that carries
 * the whole answer to "what do you have on me and for how long".
 *
 * Nothing here needs JavaScript. There is no scroll-spy, because the only
 * honest version of one is a script, and a document that cannot be read with
 * scripting off is not a document.
 */

/* ================================================================== *
 * 1. The page frame
 * ================================================================== */

.legal {
  padding-block: var(--s-2xl) var(--s-4xl);
}

.legal__head {
  max-width: var(--measure);
  margin-bottom: var(--s-2xl);
}

.legal__head .h1 {
  margin-top: var(--s-s);
}

.legal__lede {
  margin-top: var(--s-m);
  font-size: var(--step-1);
  line-height: 1.5;
  letter-spacing: -0.01em;
}

/* Who this document is, when it changed, and what it replaces. Small, quiet,
 * and directly under the title, because a legal page with no date on it is a
 * legal page nobody can rely on. --ink-quiet is 4.9:1 on paper and passes as
 * body text at this size; --ink-faint would not. */
.legal__dateline {
  margin-top: var(--s-m);
  font-size: var(--step--1);
  color: var(--ink-quiet);
}

.legal__dateline dt {
  display: inline;
  font-weight: 600;
}

.legal__dateline dd {
  display: inline;
  margin: 0;
}

.legal__dateline div + div::before {
  content: " · ";
  color: var(--ink-faint);
}

.legal__dateline div {
  display: inline;
}

/* ================================================================== *
 * 2. The draft notice
 *
 * It has to be read, so it is ink-body on a sunk panel rather than a quiet
 * grey aside — the one thing worse than an unreviewed policy is an unreviewed
 * policy whose warning was styled into invisibility. It is still not shouting:
 * no accent, no icon, no colour that means alarm.
 * ================================================================== */

.legal-notice {
  margin-top: var(--s-l);
  padding: var(--s-m) var(--s-l);
  background-color: var(--paper-sunk);
  border: 1px solid var(--paper-edge);
  border-inline-start: var(--s-3xs) solid var(--ink-faint);
  border-radius: var(--radius-s);
  color: var(--ink-body);
  font-size: var(--step--1);
  line-height: 1.55;
}

.legal-notice__title {
  display: block;
  margin-bottom: var(--s-2xs);
  color: var(--ink);
  font-size: var(--step--1);
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.legal-notice p + p {
  margin-top: var(--s-xs);
}

/* ================================================================== *
 * 3. Contents and document, side by side
 * ================================================================== */

.legal__body {
  display: grid;
  gap: var(--s-2xl);
  align-items: start;
}

/* 60rem is where a 15rem contents column plus a full measure of prose plus the
 * page gutters stop competing for the same space. Below it the contents are
 * simply the first thing in the document, which is what a printed contents
 * page is anyway. */
@media (min-width: 60rem) {
  .legal__body {
    grid-template-columns: minmax(11rem, 15rem) minmax(0, 1fr);
    gap: var(--s-3xl);
  }

  .legal-toc {
    position: sticky;
    /* Clears the sticky masthead, and never grows taller than what is left of
     * the viewport — a 15-item contents list on a laptop otherwise runs off the
     * bottom with no way to reach the end of it. */
    top: calc(var(--masthead-h) + var(--s-l));
    max-height: calc(100vh - var(--masthead-h) - var(--s-2xl));
    overflow-y: auto;
    /* The scrollbar, when it appears, should not sit on top of the text. */
    padding-inline-end: var(--s-xs);
  }
}

/* --ink-quiet rather than --ink-faint, which is 2.9:1 and is legal for a rule
 * or a marker but never for a word somebody has to read. */
.legal-toc__title {
  font-size: var(--step--1);
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-quiet);
  margin-bottom: var(--s-s);
}

.legal-toc ol {
  border-top: 1px solid var(--paper-edge);
}

.legal-toc li {
  border-bottom: 1px solid var(--paper-edge);
}

.legal-toc a {
  display: flex;
  gap: var(--s-xs);
  padding: var(--s-xs) 0;
  font-size: var(--step--1);
  line-height: 1.4;
  color: var(--ink-body);
  text-decoration: none;
  transition: color var(--t-fast) var(--ease);
}

.legal-toc a:hover {
  color: var(--ink);
}

/* Tabular figures so the numbers form a column even at two digits. One step
 * quieter than the title beside it — which is as far down the ladder as a
 * number that is part of the link's accessible name is allowed to go. */
.legal-toc__num {
  flex: none;
  min-width: 1.4em;
  color: var(--ink-quiet);
  font-variant-numeric: tabular-nums;
}

/* ================================================================== *
 * 4. The document
 * ================================================================== */

.legal__doc > section + section {
  margin-top: var(--s-3xl);
}

/* Everything that is read as a sentence keeps the measure. Tables and the
 * definition grids do not — they are the one thing on the page allowed to use
 * the full column, because a four-column table squeezed into 62ch is how the
 * most important part of a privacy policy becomes unreadable. */
.legal__doc p,
.legal__doc li,
.legal__doc blockquote {
  max-width: var(--measure);
  text-wrap: pretty;
}

.legal__doc h2 {
  margin-bottom: var(--s-m);
}

.legal__doc h3 {
  margin-top: var(--s-l);
  margin-bottom: var(--s-xs);
}

.legal__doc p + p,
.legal__doc p + ul,
.legal__doc p + ol,
.legal__doc ul + p,
.legal__doc ol + p,
.legal__doc p + dl,
.legal__doc dl + p {
  margin-top: var(--s-m);
}

.legal__doc a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--ink-faint);
  transition: text-decoration-color var(--t-fast) var(--ease);
}

.legal__doc a:hover {
  text-decoration-color: var(--ink);
}

.legal__doc strong {
  color: var(--ink);
  font-weight: 600;
}

/* ---- Lists. base.css strips the markers site-wide; a legal document is the
 * one place they carry meaning, so they come back here. ---- */

.legal__doc ul li {
  position: relative;
  padding-inline-start: var(--s-l);
}

.legal__doc ul li + li {
  margin-top: var(--s-xs);
}

.legal__doc ul li::before {
  content: "—";
  position: absolute;
  inset-inline-start: 0;
  color: var(--ink-faint);
}

.legal__doc ol {
  list-style: decimal outside;
  padding-inline-start: var(--s-l);
}

.legal__doc ol li + li {
  margin-top: var(--s-xs);
}

.legal__doc ol li::marker {
  color: var(--ink-faint);
}

/* ---- The permalink beside a heading ---- */

.legal-anchor {
  margin-inline-start: var(--s-xs);
  color: var(--ink-quiet);
  font-weight: 400;
  text-decoration: none;
  opacity: 0;
  transition: opacity var(--t-fast) var(--ease);
}

h2:hover > .legal-anchor,
h3:hover > .legal-anchor,
.legal-anchor:focus-visible {
  opacity: 1;
}

/* On a touch screen there is no hover to reveal it with, so it is simply there
 * and quiet. */
@media (hover: none) {
  .legal-anchor {
    opacity: 1;
  }
}

/* ---- Fact pairs: the controller's details, the contact block ---- */

.legal-facts {
  display: grid;
  gap: var(--s-xs) var(--s-l);
  padding: var(--s-m) var(--s-l);
  background-color: var(--paper-raised);
  border: 1px solid var(--paper-edge);
  border-radius: var(--radius-m);
}

@media (min-width: 34rem) {
  .legal-facts {
    grid-template-columns: minmax(8rem, auto) 1fr;
  }
}

.legal-facts dt {
  color: var(--ink-quiet);
  font-size: var(--step--1);
  font-weight: 600;
}

.legal-facts dd {
  margin: 0;
  color: var(--ink-body);
}

/* Below the two-column breakpoint the pairs need air between them or they read
 * as one run-on list. */
@media (max-width: 33.99rem) {
  .legal-facts dd + dt {
    margin-top: var(--s-s);
  }
}

/* ================================================================== *
 * 5. Placeholders
 *
 * Every fact the owner still has to supply is wrapped in one of these, so that
 * a reviewer can find them by eye and a script can find them by grepping for
 * `{{`. They are deliberately not invisible.
 * ================================================================== */

.ph {
  padding: 0 var(--s-2xs);
  background-color: var(--paper-sunk);
  border: 1px dashed var(--paper-edge);
  border-radius: var(--radius-s);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.88em;
  white-space: nowrap;
}

/* ================================================================== *
 * 6. Tables
 *
 * The data-and-retention table is the part of a privacy policy anyone
 * actually reads, so it must be legible on a phone. It is not put in a
 * sideways-scrolling box: below 52rem each row becomes a small card with the
 * column names printed on the values.
 *
 * `display: block` drops a table's implicit ARIA roles, so the markup carries
 * them explicitly — role="table" / "rowgroup" / "row" / "columnheader" /
 * "rowheader" / "cell". At full width they match what the browser would have
 * inferred anyway and cost nothing.
 * ================================================================== */

.legal-table__wrap {
  margin-block: var(--s-l);
  /* A safety net rather than the plan: the stacked layout below means there is
   * nothing to scroll at small sizes, and the page itself never moves. */
  overflow-x: auto;
}

.legal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--step--1);
  line-height: 1.5;
}

/* The one four-column table on the site. Left to itself the browser gives the
 * first two columns the width of their longest word and the last one whatever
 * is left, which sets "Usage counts" over three lines beside a cell of one.
 *
 * Only while it is a table. Below the breakpoint each row is a card with a
 * single column, and a percentage width there would set the row heading one
 * word per line — so these are declared inside the query rather than undone
 * inside the other one, which a specificity tie would have lost anyway. */
@media (min-width: 52.01rem) {
  .legal-table--retention th:nth-child(1) {
    width: 17%;
  }

  .legal-table--retention th:nth-child(2) {
    width: 25%;
  }

  .legal-table--retention th:nth-child(3) {
    width: 28%;
  }

  .legal-table--retention th:nth-child(4) {
    width: 30%;
  }
}

.legal-table caption {
  margin-bottom: var(--s-xs);
  color: var(--ink-quiet);
  font-size: var(--step--1);
  text-align: start;
}

.legal-table th,
.legal-table td {
  padding: var(--s-s) var(--s-m) var(--s-s) 0;
  text-align: start;
  vertical-align: top;
  border-bottom: 1px solid var(--paper-edge);
}

.legal-table th:last-child,
.legal-table td:last-child {
  padding-inline-end: 0;
}

.legal-table thead th {
  padding-top: 0;
  color: var(--ink-quiet);
  font-size: var(--step--1);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom-color: var(--ink-faint);
}

.legal-table tbody th {
  color: var(--ink);
  font-weight: 600;
}

.legal-table tbody tr:last-child th,
.legal-table tbody tr:last-child td {
  border-bottom: 0;
}

/* The one place the accent is spent on these pages. "Not retained" and "never
 * collected" are states of a piece of data, which is exactly what the accent
 * means everywhere else in this system. */
.legal-flag {
  display: inline-block;
  padding: var(--s-3xs) var(--s-xs);
  background-color: var(--accent-quiet);
  border-radius: var(--radius-s);
  color: var(--accent-ink);
  font-weight: 600;
  white-space: nowrap;
}

@media (max-width: 52rem) {
  .legal-table,
  .legal-table tbody,
  .legal-table tr,
  .legal-table th,
  .legal-table td {
    display: block;
  }

  /* The column names move onto the values, so the header row has nothing left
   * to say to the eye — but it stays in the accessibility tree. */
  .legal-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  /* A `table-caption` inside a box that is no longer a table gets an anonymous
   * table wrapper, which shrink-wraps it to the width of its longest word. */
  .legal-table caption {
    display: block;
  }

  .legal-table tbody tr {
    padding: var(--s-m);
    background-color: var(--paper-raised);
    border: 1px solid var(--paper-edge);
    border-radius: var(--radius-m);
  }

  .legal-table tbody tr + tr {
    margin-top: var(--s-s);
  }

  .legal-table tbody th,
  .legal-table tbody td {
    padding: 0;
    border-bottom: 0;
  }

  .legal-table tbody th {
    font-size: var(--step-0);
    line-height: 1.3;
  }

  .legal-table tbody td {
    margin-top: var(--s-s);
  }

  .legal-table tbody td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: var(--s-3xs);
    color: var(--ink-quiet);
    font-size: var(--step--1);
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }
}

/* ================================================================== *
 * 7. Print
 *
 * Somebody will send one of these to a lawyer, and a lawyer will print it.
 * ================================================================== */

@media print {
  .masthead,
  .site-footer,
  .legal-toc,
  .legal-anchor,
  .skip-link {
    display: none !important;
  }

  .legal {
    padding-block: 0;
  }

  .legal__doc p,
  .legal__doc li {
    max-width: none;
  }

  .legal__doc > section {
    break-inside: avoid-page;
  }

  .legal-table {
    break-inside: avoid;
  }
}
