/*
 * CoSavr site — the shared shell.
 *
 * Direction and the reason behind every choice here: DESIGN.md.
 * Colours: assets/tokens.css, mirrored from the app.
 */

/* --- Type ---------------------------------------------------------------
 * Self-hosted deliberately. Loading these from Google would hand every
 * visitor's IP to Google before they reach the privacy policy, on the site
 * that hosts that policy. See DESIGN.md.
 */

@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/ibm-plex-sans-latin-600-normal.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2");
}

:root {
  --font-sans: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system,
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", "Cascadia Mono",
    Menlo, Consolas, monospace;

  /* Spacing scale. Rhythm comes from choosing different steps for different
   * relationships, not from one padding value used everywhere. */
  --space-2xs: 0.25rem;
  --space-xs: 0.5rem;
  --space-sm: 0.75rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4.5rem;
  --space-4xl: 7rem;

  /* Three radii, used for three different things: controls, surfaces, and the
   * device screen. Not one pill value on everything. */
  --radius-control: 0.5rem;
  --radius-surface: 0.875rem;
  --radius-screen: 1.75rem;

  --measure: 34rem;      /* readable line length for body copy */
  --page-max: 68rem;
  --gutter: clamp(1rem, 4vw, 2.5rem);
}

/* --- Reset -------------------------------------------------------------- */

*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;   /* stop iOS inflating text in landscape */
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  overflow-wrap: break-word;   /* an email or domain breaks at 200% text on a phone */
}

/* Deliberately no `overflow-x: hidden` on body. Nothing overflows (probed from
 * 280px up), so it would only hide a future regression, and on body it creates
 * a scroll container that can break the sticky header. */

img, svg, video { max-width: 100%; height: auto; }

h1, h2, h3 {
  line-height: 1.15;
  letter-spacing: -0.015em;
  font-weight: 600;
  text-wrap: balance;
  margin: 0 0 var(--space-md);
}

h1 { font-size: clamp(2rem, 1.3rem + 3.4vw, 3.5rem); }
h2 { font-size: clamp(1.5rem, 1.15rem + 1.7vw, 2.25rem); }
h3 { font-size: clamp(1.125rem, 1rem + 0.6vw, 1.375rem); }

p { margin: 0 0 var(--space-md); max-width: var(--measure); }

a { color: var(--accent-text); text-underline-offset: 0.2em; }
a:hover { text-decoration-thickness: 2px; }

/* One focus treatment, everywhere, in the accent. Never removed without a
 * replacement (antislop R-32). */
:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 3px;
  border-radius: var(--radius-control);
}

/* --- Layout ------------------------------------------------------------- */

.wrap {
  width: 100%;
  max-width: var(--page-max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* Read by a screen reader, not drawn: a caption, or the words behind a mark. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: var(--space-md);
  top: var(--space-md);
  z-index: 100;
  padding: var(--space-xs) var(--space-md);
  background: var(--accent-primary);
  color: var(--on-accent);
  border-radius: var(--radius-control);
  transform: translateY(-200%);
}

.skip-link:focus { transform: translateY(0); color: var(--on-accent); }

/* --- Header -------------------------------------------------------------
 * Glass instance 1 of 2 (DESIGN.md caps it at two). It is glass because it
 * sits over scrolling content and must stay legible without becoming an
 * opaque bar that hides the page. The @supports fallback matters: Android
 * WebView versions still in use ignore backdrop-filter, and a header that
 * degrades to transparent is unreadable.
 */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg-primary) 88%, transparent);
  border-bottom: 1px solid var(--border);
}

@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .site-header {
    background: color-mix(in srgb, var(--bg-primary) 62%, transparent);
    -webkit-backdrop-filter: blur(16px) saturate(1.5);
    backdrop-filter: blur(16px) saturate(1.5);
  }
}

.site-header > .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  min-height: 3.75rem;
  flex-wrap: wrap;
  /* When the nav wraps under the wordmark, its links' own padding spaces the
   * rows, and this keeps the icon off the header's top edge. */
  row-gap: 0;
  padding-block: var(--space-xs);
}

.wordmark {
  font-weight: 600;
  font-size: 1.125rem;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
}

/* --accent-text, not --accent-primary: the wordmark is 18px semibold, which
 * is below WCAG's large-text threshold (14pt bold = 18.66px), so it needs the
 * full 4.5:1. */
.wordmark .wordmark__accent { color: var(--accent-text); }

/* rem, so the icon grows with the reader's text size like the word beside it.
 * 22.37% is the usual CSS stand-in for iOS's rounded app-icon corner. */
.wordmark img { display: block; width: 1.5rem; height: 1.5rem; border-radius: 22.37%; }

.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: clamp(0.75rem, 2.5vw, 1.5rem);
  font-size: 0.9375rem;
}

.site-nav a {
  color: var(--text-secondary);
  text-decoration: none;
  padding: var(--space-xs) 0;
}

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

.site-nav a[aria-current="page"] {
  box-shadow: inset 0 -2px 0 var(--accent-primary);
}

/* --- Buttons ------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;          /* 44px tap target */
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-control);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease,
    transform 120ms ease;
}

/* Dark label on a mango fill, not white: white on Mango is 3.43:1 and fails
 * at button text size. Hover brightens to Papaya rather than darkening, which
 * keeps the same label legible (7.81:1) and suits an amber control. */
.btn--primary { background: var(--accent-primary); color: var(--on-accent); }
.btn--primary:hover { background: var(--accent-secondary); color: var(--on-accent); }
.btn--primary:active { transform: translateY(1px); }

.btn--quiet {
  background: transparent;
  border-color: var(--border);
  color: var(--text-primary);
}

.btn--quiet:hover { border-color: var(--accent-primary); color: var(--text-primary); }

/* --- The readout -------------------------------------------------------
 * The identity motif. Any number the site states appears in one of these.
 * The scanlines are the retro-tech texture, deliberately confined to this
 * component rather than laid over the page as a background grid
 * (antislop R-07): they belong to the thing pretending to be a display.
 */

.readout {
  position: relative;
  overflow: hidden;
  padding: var(--space-lg) var(--space-xl);
  border-radius: var(--radius-surface);
  background: var(--accent-primary-tint);
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 color-mix(in srgb, #FFFFFF 55%, transparent);
}

.readout::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    color-mix(in srgb, var(--text-primary) 5%, transparent) 0 1px,
    transparent 1px 4px
  );
  opacity: 0.5;
}

.readout__label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin: 0 0 var(--space-2xs);
}

.readout__figure {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: clamp(2rem, 1.4rem + 2.8vw, 3rem);
  line-height: 1.05;
  color: var(--accent-text);
  font-variant-numeric: tabular-nums;
  margin: 0;
  overflow-wrap: anywhere;
}

.readout__note {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin: var(--space-xs) 0 0;
  max-width: none;
}

/* Phosphor. The one glow on the site, dark mode only, on one element: an
 * amber display in a dark room is the whole retro-tech reference, and it is
 * invisible on cream anyway. */
@media (prefers-color-scheme: dark) {
  .readout__figure {
    text-shadow: 0 0 18px color-mix(in srgb, var(--accent-primary) 40%, transparent);
  }
  .readout { box-shadow: inset 0 1px 0 color-mix(in srgb, #FFFFFF 10%, transparent); }
}

.lede { font-size: clamp(1.0625rem, 1rem + 0.35vw, 1.25rem); color: var(--text-secondary); }

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

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  padding-block: var(--space-2xl);
  margin-top: var(--space-3xl);
  font-size: 0.9375rem;
}

.site-footer__inner {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-lg) var(--space-2xl);
  justify-content: space-between;
}

.site-footer h2 {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
}

.site-footer ul { list-style: none; margin: 0; padding: 0; }
.site-footer li + li { margin-top: var(--space-2xs); }
.site-footer a { color: var(--text-primary); text-decoration: none; overflow-wrap: anywhere; }
.site-footer a:hover { text-decoration: underline; color: var(--accent-text); }

.site-footer__note { color: var(--text-secondary); max-width: 22rem; font-size: 0.875rem; }

/* --- Reveal on scroll ---------------------------------------------------
 * MOTION 2. Applied by JS (assets/reveal.js), so with script disabled every
 * section is simply visible: the class is only added once the observer is
 * running. Reduced motion opts out entirely.
 */

@media (prefers-reduced-motion: no-preference) {
  .js-reveal .reveal {
    opacity: 0;
    transform: translateY(14px);
    transition: opacity 500ms ease, transform 500ms ease;
  }
  .js-reveal .reveal.is-visible { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Document pages -----------------------------------------------------
 * /support, /security and, later, the legal pages (iOS-168). One reading
 * column at the body measure: these pages are read top to bottom, so they get
 * none of the landing page's split layouts.
 */

.doc { padding-block: var(--space-2xl) 0; }
.doc > .wrap > * { max-width: var(--measure); }
.doc h1 { font-size: clamp(1.75rem, 1.3rem + 2.2vw, 2.75rem); }
.doc h2 {
  font-size: clamp(1.25rem, 1.1rem + 0.8vw, 1.625rem);
  margin-top: var(--space-2xl);
  /* Clear the sticky header on a #fragment jump. 8rem, not its 3.75rem:
   * below about 384px the nav wraps and the header grows to two rows. */
  scroll-margin-top: 8rem;
}

/* Under 20rem wide the nav wraps to three rows or more, and under 15rem tall
 * even one row is a third of the screen, so the header stops following and a
 * jump has nothing to clear. A media query's rem is the browser's default text
 * size (zoom narrows the viewport instead), so either way this is large text
 * on a phone; at the default size, a screen under 320px wide or 240px tall. */
@media (width < 20rem), (max-height: 15rem) {
  .site-header { position: static; }
  .doc h2 { scroll-margin-top: var(--space-md); }
}

.doc h3 { font-size: 1.0625rem; margin-top: var(--space-lg); margin-bottom: var(--space-xs); }
.doc ul, .doc ol { padding-left: 1.25rem; margin: 0 0 var(--space-md); }
.doc li + li { margin-top: var(--space-2xs); }
.doc .steps > li + li { margin-top: var(--space-md); }   /* numbered steps are read one at a time */
.doc .doc__updated { font-family: var(--font-mono); font-size: 0.8125rem; color: var(--text-secondary); }

/* The in-app path to a setting, e.g. Settings ▸ Back up to CSV. Mono so it reads
 * as something to follow on screen rather than prose. */
.path { font-family: var(--font-mono); font-size: 0.9em; }

/* The one contact address on each page, in the readout motif (DESIGN.md). */
.doc .contact {
  display: inline-block;
  margin: 0 0 var(--space-md);
  padding: var(--space-sm) var(--space-lg);
  background: var(--accent-primary-tint);
  border-radius: var(--radius-surface);
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--bg-secondary) 70%, transparent);
  font-family: var(--font-mono);
  overflow-wrap: anywhere;
}

/* --- Legal pages (iOS-169) ------------------------------------------------
 * A draft policy says so at the top, and every undecided point says so where it
 * sits, so nobody reads a placeholder as a promise. Neutral surfaces, not mango:
 * the accent is reserved (DESIGN.md), and a pending note is not an action.
 */

.doc .doc__status,
.doc .pending {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-surface);
  padding: var(--space-sm) var(--space-md);
  margin: 0 0 var(--space-md);
}
.doc .doc__status { margin-top: var(--space-lg); }
.doc .doc__status p { margin: 0; }
.doc .pending { font-size: 0.9375rem; color: var(--text-secondary); }

.doc .pending-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 0 var(--space-xs);
  margin-right: var(--space-2xs);
  white-space: nowrap;
}

/* The contents list: a page skimmed by heading gets its headings up front. */
.doc .doc__toc h2 { margin-top: var(--space-xl); }
.doc .doc__toc ol { columns: 2 16rem; column-gap: var(--space-2xl); }
.doc .doc__toc li { break-inside: avoid; }

/* Vendors: who, what for, then where on its own line, so a 320px column never
 * has to fit three table cells side by side. */
.doc .vendors .where {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-secondary);
}
.doc .vendors .where.pending-tag { display: inline-block; color: var(--text-primary); }

/* Sub-processor register (iOS-171): a real table, because each row is the same
 * four facts about one company and a screen reader should say which column it
 * is in. Below its natural width it scrolls inside its own box rather than
 * pushing the page sideways; the box is focusable so a keyboard can scroll it. */
.doc > .wrap > .register { max-width: 60rem; }
.doc .register {
  overflow-x: auto;
  margin: var(--space-md) 0 var(--space-lg);
  border: 1px solid var(--border);
  border-radius: var(--radius-surface);
}
.doc .register table {
  width: 100%;
  min-width: 40rem;
  border-collapse: collapse;
  font-size: 0.9375rem;
}
.doc .register th,
.doc .register td {
  text-align: left;
  vertical-align: top;
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border);
}
.doc .register tbody tr:last-child > * { border-bottom: 0; }
.doc .register thead th {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-secondary);
}
.doc .register tbody th { font-weight: 600; white-space: nowrap; }
.doc .register td:last-child { white-space: nowrap; }
