/* trackchat.fit — the Terms stylesheet.
   Styles the documents web/terms_build.py writes to web/live/terms.html and
   web/live/<lang>/terms.html. The landing page and
   the 404 page use style.css; the two sheets share the palette and the Onest face but no
   rules, so a landing-page change cannot reflow the legal text. Hand-written; no build step. */

/* ---------------------------------------------------------------- typeface
   Onest, self-hosted. Split by unicode-range so Cyrillic only loads
   for the languages that need it. The wordmark is set in the same face. */

@font-face {
  font-family: "Onest";
  src: url("fonts/onest-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  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;
}

@font-face {
  font-family: "Onest";
  src: url("fonts/onest-cyrillic.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

/* Latin Extended. The latin face above stops at U+00FF (Latin-1), so Czech ě š č ř ž ů,
   Slovak ĺ ľ ŕ, Polish ł ą ę ś ź ż ć ń, Hungarian ő ű, Romanian ș ț and Turkish ğ ş İ all
   fell through to a system font MID-WORD — one word rendered in two typefaces. Nobody
   caught it before because no page had ever rendered those glyphs.

   ~10-15 kB, and `unicode-range` means only the six languages that need it ever download
   it, so the <100 kB first view is untouched for everyone else. Turkish dotless
   ı (U+0131) stays in the latin face, where it already was — do not move it here, or it
   would pull this subset down for a page that needs nothing else from it. */
@font-face {
  font-family: "Onest";
  src: url("fonts/onest-latin-ext.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-0130, U+0132-024F, U+0259, U+2020, U+2113, U+20A0-20AB,
    U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
}

/* ------------------------------------------------------------------ tokens */

:root {
  --paper: #F2EFEC;
  --surface: #FFFFFF;
  --ink: #161311;
  --muted: #6E675E;
  --edge: #DCDAD4;
  --brand: #00BC05;
  --brand-deep: #117A14;

  /* Onest carries Latin, Latin-ext and Cyrillic. Devanagari (hi), Japanese and Hangul (ko)
     get the platform's own script font instead of a per-script webfont: each would be
     100 kB+ on its own and blow the first-view budget, and every platform already ships a
     good one. The stack names them explicitly rather than trusting `sans-serif`, which on
     some Linux builds picks a font with no coverage and renders tofu. */
  --face: "Onest", system-ui, -apple-system, "Segoe UI",
    "Noto Sans Devanagari", "Noto Sans JP", "Noto Sans KR",
    "Hiragino Sans", "Yu Gothic", "Meiryo", "Apple SD Gothic Neo", "Malgun Gothic",
    sans-serif;

  color-scheme: light;
}

/* -------------------------------------------------------------------- base */

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--face);
  font-size: 1.125rem;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { font-weight: 800; letter-spacing: -0.03em; line-height: 1.08; margin: 0; }

h2 { font-size: clamp(2rem, 5vw, 3.5rem); margin-bottom: 1rem; }
h3 { font-size: 1.3rem; letter-spacing: -0.02em; }

p { margin: 0 0 1rem; }

a { color: var(--brand-deep); }

:focus-visible {
  outline: 3px solid var(--brand-deep);
  outline-offset: 3px;
  border-radius: 6px;
}

.sprite { position: absolute; }

/* ------------------------------------------------------------------- logos */

/* The wordmark is outlined Onest 800 (web/live/wordmark.svg), so the logo never
   waits on the webfont and never flashes a fallback. Its two colours cannot be
   reached by a class selector through the <use> shadow tree — custom properties
   inherit, so --wm-track / --wm-chat are what recolour it. */
.wordmark {
  --wm-track: var(--brand);
  --wm-chat: var(--ink);
  height: 0.78em;          /* cap height of the outline, so it sits like text */
  width: auto;
  aspect-ratio: 4279 / 715;  /* the viewBox — without it the box fills its parent
                                and preserveAspectRatio centres the ink in a gap */
  display: block;
  flex: none;
}

.wordmark-fit { aspect-ratio: 4731 / 715; }

.mark { width: 30px; height: 30px; flex: none; }

.lockup {
  display: inline-flex; align-items: center; gap: 0.6rem;
  color: var(--ink); text-decoration: none;
  font-size: 1.35rem;
}

/* language picker — a subordinate control, not a nav item.
   A pill at the top right: quiet until you reach for it, then it lifts, the brand
   edge comes up and the caret turns over. Everything here is a state on the
   <details>, so the whole control still works with the script switched off. */

.lang { position: relative; }
.lang summary {
  list-style: none; cursor: pointer;
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.82rem; font-weight: 700; letter-spacing: 0.06em;
  color: var(--muted);
  border: 1px solid var(--edge); border-radius: 999px;
  padding: 0.34rem 0.6rem 0.34rem 0.65rem;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(22, 19, 17, 0.05);
  transition: color 0.18s ease, border-color 0.18s ease,
              box-shadow 0.18s ease, background-color 0.18s ease;
}
.lang summary::-webkit-details-marker { display: none; }
.lang summary:hover {
  color: var(--ink);
  border-color: color-mix(in srgb, var(--brand) 45%, var(--edge));
  box-shadow: 0 5px 16px rgba(22, 19, 17, 0.10);
}
.lang summary:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
.lang .caret {
  width: 0.75rem; height: 0.75rem; opacity: 0.55;
  transition: transform 0.18s ease, opacity 0.18s ease;
}
.lang[open] summary {
  color: var(--ink); border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 7%, var(--surface));
  box-shadow: 0 5px 16px rgba(22, 19, 17, 0.10);
}
.lang[open] .caret { transform: rotate(180deg); opacity: 1; }

.lang-menu {
  position: absolute; right: 0; top: calc(100% + 0.55rem); z-index: 40;
  border: 1px solid var(--edge); border-radius: 16px;
  padding: 0.35rem; min-width: 12.5rem;
  /* A shade at the cut edge says the list scrolls: the covers scroll with the rows (local) and
     hide each shade once the list reaches that end. */
  background:
    linear-gradient(var(--surface) 30%, #FFFFFF00) top / 100% 2.25rem no-repeat local,
    linear-gradient(#FFFFFF00, var(--surface) 70%) bottom / 100% 2.25rem no-repeat local,
    radial-gradient(farthest-side at 50% 0, rgba(22, 19, 17, 0.15), rgba(22, 19, 17, 0)) top / 100% 0.75rem no-repeat scroll,
    radial-gradient(farthest-side at 50% 100%, rgba(22, 19, 17, 0.15), rgba(22, 19, 17, 0)) bottom / 100% 0.75rem no-repeat scroll,
    var(--surface);
  box-shadow: 0 20px 44px rgba(22, 19, 17, 0.16), 0 2px 6px rgba(22, 19, 17, 0.06);
  display: grid;
  /* Eighteen rows is taller than a phone viewport, so the menu scrolls rather than running
     off the bottom of the screen. Harmless at seven — the cap is never reached. */
  max-height: min(70vh, 30rem); overflow-y: auto; overscroll-behavior: contain;
  transform-origin: top right;
  animation: lang-pop 0.16s ease-out;
}
/* Past nine languages one column is a wall — build.py adds this class and the list runs in
   two. Filled column by column, --rows (build.py) to a column, because the list is
   alphabetical: the eye reads A–M down the left and N–Z down the right, where a row-major grid
   would put consecutive languages side by side and the alphabet nowhere. A grid, never
   multicol: under the height cap a multicol box spills the last rows into another column off
   to the side instead of scrolling. Below 24rem of room a second column would be narrower than
   the endonyms, so it drops back to one and relies on the scroll cap above. */
.lang-menu-wide {
  grid-template-columns: repeat(2, minmax(max-content, 1fr)); grid-template-rows: repeat(var(--rows), auto);
  grid-auto-flow: column; column-gap: 0.25rem; min-width: 24rem;
}
@media (max-width: 30rem) {
  .lang-menu-wide {
    grid-template-columns: minmax(0, 1fr); grid-template-rows: none; grid-auto-flow: row;
    min-width: 12.5rem;
  }
}

/* The pill's name for a screen reader goes on past the code it shows (build.py): kept off
   screen rather than display: none, which would drop it from the name. */
.lang .visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

@keyframes lang-pop {
  from { opacity: 0; transform: translateY(-4px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
.lang-menu a {
  position: relative;
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.45rem 1.9rem 0.45rem 0.7rem; border-radius: 10px;
  color: var(--ink); text-decoration: none; font-size: 0.95rem; white-space: nowrap;
  transition: background-color 0.12s ease, color 0.12s ease;
}
/* The language you are already reading is not a choice, so it does not light up
   under the pointer — hover means "clicking this changes something". A keyboard
   focus ring is different: that is position, not affordance, so it stays. */
.lang-menu a:not([aria-current]):hover,
.lang-menu a:not([aria-current]):focus-visible {
  background: color-mix(in srgb, var(--brand) 12%, var(--surface));
  color: var(--brand-deep);
}
.lang-menu a:not([aria-current]):focus-visible { outline: none; }
.lang-menu a[aria-current] { cursor: default; }
.lang-menu a[aria-current] { color: var(--brand-deep); font-weight: 700; }
/* The tick marks the language you are already reading — decorative, since
   aria-current already says it to a screen reader. */
.lang-menu a[aria-current]::after {
  content: "✓"; position: absolute; right: 0.7rem;
  color: var(--brand); font-weight: 700;
}
/* The picker's flags are sprite `<use>`s, not emoji — Segoe UI Emoji carries no flag
   glyphs, so Chrome and Edge on Windows drew the old emoji as "GB"/"DE" letter boxes.
   Sized off the row's own type so the artwork tracks the text it labels. */
.flag { width: 1.35em; height: auto; flex: none; border-radius: 2px; }
.lang summary .flag { width: 1.55em; }

@media (prefers-reduced-motion: reduce) {
  .lang summary, .lang .caret, .lang-menu a { transition: none; }
  .lang-menu { animation: none; }
}

/* ------------------------------------------------- terms / legal document
   The page is generated by web/terms_build.py from web/src/terms/<lang>.md —
   the words are legal-review-gated, the styling below is the brand's, and it
   has to hold for every language the document is ever translated into. */

/* The lockup, and — once the document exists in more than one language — the switcher,
   the landing page's picker pill: plain links with real hrefs, so the page works with no
   JavaScript at all, and an inline script that only remembers the pick in a cookie. */
.doc-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  width: min(720px, 90vw); margin: 0 auto; padding: 2rem 0 0;
}

.doc {
  width: min(720px, 90vw); margin: 0 auto;
  padding: 3rem 0 7rem;
  font-size: 1.0625rem;
}
.doc h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin-bottom: 0.5rem; }
.doc h2 { font-size: 1.35rem; margin: 3rem 0 0.6rem; }
.doc h3 { font-size: 1.08rem; margin: 2rem 0 0.4rem; }
.doc p, .doc li { margin: 0.6rem 0; }
.doc ul, .doc ol { padding-left: 1.3rem; }
.doc ol { padding-left: 1.5rem; }
.doc li::marker { color: var(--brand); }
/* The effective date stands apart from the prose that follows it — the same distance the
   opening paragraphs keep from the contents box below them, so the document opens on one
   rhythm rather than on a rule. */
.doc .meta { color: var(--muted); font-size: 0.98rem; margin-bottom: 2.5rem; }
/* The name, set like the logo where the document introduces it: green "track", ink "chat".
   The palette tokens directly, not the wordmark's --wm-* pair: those are declared on
   `.wordmark` for the sprite's shadow tree and do not reach text elsewhere on the page.
   Only terms_build.py's first mention carries the class. */
.doc .brand { color: var(--ink); }
.doc .brand span { color: var(--brand); }
.doc .meta strong { color: var(--ink); }
.doc address { font-style: normal; margin: 0.5rem 0 0; }
.doc hr { border: none; border-top: 1px solid var(--edge); margin: 2.8rem 0; }
.doc footer { color: var(--muted); font-size: 0.92rem; }
/* The Twemoji credit. CC-BY's one condition, so it is fine print but not optional —
   see web/src/flags/README.md before touching it. */
.doc .credits { font-size: 0.82rem; margin-top: 1.2rem; }

/* The generated contents list. A long legal document needs a way in, and the
   entries are numbered by the <ol> itself so the markup carries no numbers a
   translation could leave stale. */
/* The header's bare `nav` / `nav a` selectors would otherwise claim this one and lay it
   out as a row of uppercase bar links, so the block undoes both here. */
.doc-toc {
  display: block; margin: 2.5rem 0 0; padding: 1.25rem 1.5rem;
  border: 1px solid var(--edge); border-radius: 14px;
}
.doc-toc-title {
  margin: 0 0 0.6rem; font-weight: 600; font-size: 0.95rem;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
}
.doc-toc ul { margin: 0; padding-left: 0; list-style: none; }
.doc-toc li { margin: 0.25rem 0; }
.doc-toc a {
  color: var(--ink); text-decoration: none;
  font-size: inherit; font-weight: inherit; letter-spacing: normal; text-transform: none;
}
.doc-toc a:hover { color: var(--brand); text-decoration: underline; }
/* An in-page jump must not land the heading under the top edge of the viewport. */
.doc h2 { scroll-margin-top: 1.5rem; }

/* -------------------------------------------------------------- motion */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

/* ---------------------------------------------------------- responsive */

@media (max-width: 620px) {
  body { font-size: 1.0625rem; }
}
