/*
 * /guidelines: a long document people have to be able to use, not just scroll past.
 *
 * Plain words first: the short version, the one emergency line, and how moderation
 * works (the disclosure everyone agrees to). Then the full text in a 62ch column, its
 * twenty sections in four parts with neutral number badges, and contents that stay in
 * reach: a sticky sidebar from 60rem, a collapsed list above the text below that.
 * Tokens and components come from styles.css; this file is layout.
 *
 * - The header (.appbar) is sticky, and it stays pinned only because nothing gives
 *   html or body a height or an overflow. A body one viewport tall is the header's
 *   containing block, and the header scrolled away after the first screen.
 * - Red is for one thing on this page: the emergency line. Section numbers are
 *   neutral: blue would make twenty labels look pressable, and red would make every
 *   section an alarm.
 * - In a tab of its own the way back reads "Close": the page's inline script sets
 *   data-alone on <html> before the first paint.
 */

/* Every jump (contents, the skip link, #moderation) lands below the pinned header. */
:root {
  scroll-padding-top: calc(
    var(--appbar-h) + env(safe-area-inset-top, 0px) + var(--sp-4)
  );
}

/* =================================================================== header */

.leave-back,
.leave-close {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
}
:root[data-alone] .leave-back,
:root:not([data-alone]) .leave-close {
  display: none;
}

/* Narrow phones: "Back" alone, with the rest of the label kept for screen readers. */
@media (max-width: 29.99rem) {
  .appbar .long {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }
}

/* =================================================================== layout */

/* One 62ch column, centred; from 60rem the contents join it on the left. (68ch measured
   76-83 characters a line: past the 45-75 that long reading, and a wandering eye,
   can take.) No bottom
   padding here: the grid row is the sidebar's sticky range, and padding below it
   pushed the sidebar up under the header at the end of the page. */
.doc {
  display: grid;
  grid-template-columns: minmax(0, 62ch);
  justify-content: center;
  width: min(100%, 72rem);
  margin: 0 auto;
  padding: var(--sp-6) max(var(--sp-4), env(safe-area-inset-right, 0px)) 0
    max(var(--sp-4), env(safe-area-inset-left, 0px));
}
@media (min-width: 37.5rem) {
  .doc {
    padding: var(--sp-8) max(var(--sp-6), env(safe-area-inset-right, 0px)) 0
      max(var(--sp-6), env(safe-area-inset-left, 0px));
  }
}
@media (min-width: 60rem) {
  .doc {
    grid-template-columns: minmax(15rem, 19rem) minmax(0, 62ch);
    column-gap: var(--sp-12);
    padding-top: var(--sp-10);
  }
  /* A page with no contents beside it (the Cookie Policy): one centred column. */
  .doc.single {
    grid-template-columns: minmax(0, 62ch);
  }
}

.doc-main {
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
  min-width: 0;
  padding-bottom: calc(var(--sp-16) + env(safe-area-inset-bottom, 0px));
}

.updated {
  margin-top: var(--sp-2);
  color: var(--text-faint);
  font-size: var(--t-small);
}

/* ============================================ the short version, moderation */

.points {
  display: grid;
  gap: var(--sp-4);
  margin: 0;
  padding: 0;
  list-style: none;
}
.points li {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
}
/* Puts the first line's centre on the icon's centre (6px at the default text size),
   at any text size: the circle is 10px + 0.5rem to its centre, the line 0.75rem. */
.points p {
  padding-top: calc(10px - 0.25rem);
  color: var(--text-dim);
}
.points strong {
  color: var(--text);
}
/* 36px at the default text size, and growing with it so "18+" stays inside. */
.point-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: calc(20px + 1rem);
  height: calc(20px + 1rem);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-dim);
}
.point-icon.age {
  font: 700 var(--t-micro) / 1 var(--font-ui);
}

/* The only red on the page. Words stay --text; the icon carries the tone. */
.emergency {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border: 1px solid var(--danger-line);
  border-radius: var(--r-md);
  background: var(--danger-bg);
  color: var(--text);
}
/* Centred on the first line (2px at the default text size). */
.emergency > .i {
  margin-top: calc(0.75rem - 10px);
  color: var(--danger);
}
.emergency strong {
  font-weight: 700;
}

/* ================================================================ full text */

/* The Cookie Policy's tables: what is kept in the browser, one row each. On a phone
   the table scrolls inside its own box, never the page. */
.table-wrap {
  overflow-x: auto;
  margin: var(--sp-3) 0;
}
.store {
  width: 100%;
  min-width: 30rem;
  border-collapse: collapse;
  font-size: var(--t-small);
  line-height: 1.45;
}
.store caption {
  padding-bottom: var(--sp-2);
  color: var(--text-dim);
  font-weight: 600;
  text-align: left;
}
.store th,
.store td {
  padding: var(--sp-2) var(--sp-3) var(--sp-2) 0;
  border-bottom: 1px solid var(--line-soft);
  color: var(--text-dim);
  text-align: left;
  vertical-align: top;
}
.store thead th {
  color: var(--text-faint);
  font-weight: 600;
}
.store tbody th {
  color: var(--text);
  font-weight: 400;
  letter-spacing: normal;
  /* The names exactly as the browser stores them (styles.css capitalises th). */
  text-transform: none;
  white-space: nowrap;
}
/* A three-column table on a phone: one card per row, each answer under its
   column's name (the cells carry it in data-label; the header row is still read
   by screen readers where the table stays a table). */
@media (max-width: 37.4375rem) {
  .store.stack {
    min-width: 0;
  }
  .store.stack thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .store.stack tr,
  .store.stack td {
    display: block;
  }
  .store.stack tr {
    padding: var(--sp-2) 0;
    border-bottom: 1px solid var(--line-soft);
  }
  .store.stack td {
    padding: var(--sp-1) 0;
    border-bottom: 0;
  }
  /* The row's name: a first cell, or a row header (the comparison table). */
  .store.stack tbody th {
    display: block;
    padding: var(--sp-1) 0;
    border-bottom: 0;
  }
  .store.stack td:first-child {
    color: var(--text);
    font-weight: 600;
  }
  .store.stack td[data-label]:not(:first-child)::before,
  .store.stack th + td[data-label]::before {
    content: attr(data-label) ": ";
    color: var(--text-faint);
    font-weight: 600;
  }
}
.store code {
  font: 400 var(--t-small) / 1.45 var(--font-mono);
}

/* Permission to stop reading, just before the long part. */
.legal-signpost {
  margin-top: var(--sp-8);
  color: var(--text-dim);
  font-size: var(--t-small);
  line-height: 1.5;
}

.legal {
  margin-top: var(--sp-6);
  padding-top: var(--sp-10);
  border-top: 1px solid var(--line);
  color: var(--text-dim);
  line-height: 1.7;
}
.legal > h2 {
  color: var(--text);
}
.legal p,
.legal ul {
  margin: var(--sp-4) 0 0;
}
.legal ul {
  display: grid;
  gap: var(--sp-2);
  padding-left: 1.375em;
}
.legal strong {
  color: var(--text);
}

/* A part of the text: a quiet label on a rule, so it reads as a divider, not as one
   more heading to read. */
.part {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-top: var(--sp-12);
  color: var(--text-dim);
  font: 600 var(--t-small) / 1.45 var(--font-ui);
  letter-spacing: 0.02em;
}
.part::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--line);
}

.legal section {
  /* Laid out and painted only near the viewport: twenty sections of text are most
     of this page's work on a phone. `auto` keeps a section's real height once it
     has been seen, so scrolling back up does not jump. */
  content-visibility: auto;
  contain-intrinsic-size: auto 36rem;
  /* That also clips painting to the section's box: 4px of room keeps a focus ring on
     a link at the edge of the text whole. */
  margin: var(--sp-8) -4px 0;
  padding: 0 4px;
}
.legal .part + section {
  margin-top: var(--sp-5);
}
@media (max-width: 37.49rem) {
  .legal section {
    contain-intrinsic-size: auto 56rem;
  }
}

.legal h4 {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  margin: 0;
  color: var(--text);
  font: 700 var(--t-lede) / 1.35 var(--font-display);
  letter-spacing: -0.01em;
  text-wrap: balance;
}
/* The number: neutral, a hairline box, digits that line up. Text-centred rather than
   a grid, so the number and its separator stay one run of text (below). Sized in rem,
   not px, so the box grows with the digits at a larger text size: 26 × 28px at the
   default, on the heading's first line. */
.num {
  flex: none;
  min-width: 1.75rem;
  margin-top: -1px;
  padding: 0 0.375rem;
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  background: var(--surface-2);
  color: var(--text-dim);
  font: 600 var(--t-small) / 1.5rem var(--font-ui);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  text-align: center;
}
/*
 * ". " after a number, heard but not seen, so a screen reader says "1. Core Safety
 * Principles" instead of running the two together. Zero size rather than .sr-only:
 * an absolutely positioned separator is its own box, and Chromium then names the
 * heading "1 . Core…", which some readers speak as "1 dot Core".
 */
.num > .sep,
.toc-num > .sep {
  font-size: 0;
  line-height: 0;
}
/* Where a contents link landed, when the page could not scroll it to the top. */
.legal section:target .num {
  border-color: var(--line-strong);
  background: var(--surface-3);
  color: var(--text);
}

/* ================================================================= contents */

.toc-groups,
.toc-groups ol {
  margin: 0;
  padding: 0;
  list-style: none;
}
.toc-groups > li + li {
  margin-top: var(--sp-4);
}
.toc-part {
  display: block;
  padding: 0 10px var(--sp-1);
  color: var(--text);
  font: 600 var(--t-small) / 1.45 var(--font-ui);
}
.toc-groups a {
  display: flex;
  gap: var(--sp-2);
  padding: 6px 10px;
  border-radius: var(--r-sm);
  color: var(--text-dim);
  font-size: var(--t-small);
  line-height: 1.4;
  text-decoration: none;
}
.toc-num {
  flex: none;
  min-width: 1.5em;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}
@media (hover: hover) {
  .toc-groups a:hover {
    background: var(--surface-2);
    color: var(--text);
  }
}
/* Touch: 44px rows. The padding makes a one-line row 44px and keeps the number on
   the first line of a long title. */
@media (pointer: coarse) {
  .toc-groups a {
    min-height: var(--tap);
    padding-block: 12px;
  }
}

/* Wide screens: a sidebar that stays beside the text, 24px from the header and from
   the bottom of the window, scrolling on its own when it is taller than that. */
.toc {
  display: none;
}
.toc-title {
  margin-bottom: var(--sp-3);
  padding: 0 10px;
  color: var(--text);
  font: 700 var(--t-body) / 1.5 var(--font-display);
}
@media (min-width: 60rem) {
  .toc {
    display: block;
    position: sticky;
    top: calc(var(--appbar-h) + env(safe-area-inset-top, 0px) + var(--sp-6));
    align-self: start;
    max-height: calc(
      100vh - var(--appbar-h) - env(safe-area-inset-top, 0px) - var(--sp-12)
    );
    max-height: calc(
      100dvh - var(--appbar-h) - env(safe-area-inset-top, 0px) - var(--sp-12)
    );
    /* Room inside the scroll box for the focus ring. */
    margin: -4px;
    padding: 4px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .toc-mobile {
    display: none;
  }
}

/* Narrower screens: one closed row above the text, so nothing long comes first. */
.toc-mobile {
  margin-top: var(--sp-5);
}
.toc-mobile > details {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
}
.toc-mobile summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: 48px;
  padding: 0 var(--sp-4);
  border-radius: inherit;
  color: var(--text);
  font-weight: 600;
  line-height: 1.3;
  list-style: none;
  cursor: pointer;
}
.toc-mobile summary::-webkit-details-marker {
  display: none;
}
/* An icon rather than a background image, so it takes the text colour, High
   Contrast included. */
.toc-mobile summary > .i {
  color: var(--text-dim);
  transition: transform var(--dur-3) var(--ease-drift);
}
.toc-mobile details[open] > summary > .i {
  transform: rotate(180deg);
}
.toc-mobile .toc-groups {
  padding: var(--sp-1) var(--sp-2) var(--sp-4);
}
.toc-mobile .toc-groups a {
  min-height: var(--tap);
  padding-block: 12px;
}

/* ================================================================== the end */

.doc-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-top: var(--sp-6);
  padding-top: var(--sp-6);
  border-top: 1px solid var(--line-soft);
  color: var(--text-faint);
  font-size: var(--t-small);
}

/* =================================================================== print */

/* Ink on paper whatever the theme, and all of the text: printing the dark theme put
   near-white words on a white page. */
@media print {
  :root,
  :root[data-theme] {
    color-scheme: light;
    --bg: Canvas;
    --surface: Canvas;
    --surface-2: Canvas;
    --surface-3: Canvas;
    --text: CanvasText;
    --text-dim: CanvasText;
    --text-faint: CanvasText;
    --line: GrayText;
    --line-soft: GrayText;
    --line-strong: GrayText;
    --danger: CanvasText;
    --danger-bg: Canvas;
    --danger-line: CanvasText;
    /* Links and status too: the dark theme's light blue prints at about 1.7:1. */
    --accent-text: LinkText;
    --ok: CanvasText;
    --warn: CanvasText;
  }
  .skip-link,
  .appbar,
  .toc,
  .toc-mobile,
  .doc-foot .btn {
    display: none;
  }
  .doc {
    display: block;
    width: auto;
    padding: 0;
  }
  .doc-main {
    padding-bottom: 0;
  }
  .legal section {
    content-visibility: visible;
  }
  .card,
  .emergency {
    box-shadow: none;
    break-inside: avoid;
  }
  .part,
  .legal h4 {
    break-after: avoid;
  }
}
