/* The izbi license
   Font faces live in fonts/fonts.css, generated by tools/build_fonts.py.
   Both families are self-hosted; the page makes no third-party requests. */

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

:root {
  color-scheme: light;

  --bg: #fbfbf9;
  --surface: #ffffff;
  --surface-sunken: #f4f4f0;
  --ink: #16161a;
  --muted: #5f5f68;
  --line: #e3e3dd;
  --line-strong: #d2d2ca;
  --shadow: 0 18px 40px -24px rgba(22, 22, 26, 0.34);

  --sans: "Google Sans Flex", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Google Sans Code", ui-monospace, "SF Mono", "Liberation Mono", monospace;

  --measure: 68ch;
  --gutter: clamp(20px, 4vw, 40px);
  --col-gap: clamp(32px, 5vw, 68px);
  --shell: 1180px;
  --radius: 6px;
  --radius-control: 4px;

  --w-display: 280;
  --w-display-light: 240;
  --w-body: 400;
  --w-medium: 550;
  --w-strong: 620;
  --w-mark: 700;

  --control-pad: 8px 14px;

  --step-eyebrow: 12px;
  --step-small: 13px;
  --step-ui: 14.5px;
  --step-body: clamp(16.5px, 0.55vw + 15px, 18px);
  --step-lead: clamp(19px, 1vw + 16px, 23px);
  --step-h2: clamp(23px, 1.1vw + 19px, 28px);
  --step-h1: clamp(58px, 10vw, 132px);
}

/* System preference wins unless the reader has explicitly chosen light. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg: #101012;
    --surface: #17171a;
    --surface-sunken: #1c1c20;
    --ink: #ececea;
    --muted: #a3a3ac;
    --line: #2a2a2e;
    --line-strong: #3a3a40;
    --shadow: 0 18px 40px -24px rgba(0, 0, 0, 0.7);
  }
}

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

  --bg: #101012;
  --surface: #17171a;
  --surface-sunken: #1c1c20;
  --ink: #ececea;
  --muted: #a3a3ac;
  --line: #2a2a2e;
  --line-strong: #3a3a40;
  --shadow: 0 18px 40px -24px rgba(0, 0, 0, 0.7);
}

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

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 24px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--step-body);
  line-height: 1.55;
  font-variation-settings: "ROND" 20;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-underline-offset: 4px; }

:where(a, button, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
  border-radius: var(--radius-control);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 50%;
  top: 8px;
  z-index: 20;
  padding: 10px 18px;
  border-radius: var(--radius-control);
  background: var(--ink);
  color: var(--bg);
  font-size: var(--step-ui);
  text-decoration: none;
  transform: translate(-50%, -180%);
  transition: transform 160ms ease;
}

.skip-link:focus-visible { transform: translate(-50%, 0); }

.icon-arrow,
.icon-chevron,
.icon-back {
  width: 0.72em;
  height: 0.72em;
  flex: none;
  vertical-align: baseline;
}

.icon-arrow { margin-left: 0.4em; }

/* ---------------------------------------------------------------- header */

.site-header,
main,
footer {
  max-width: var(--shell);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  height: 76px;
}

.wordmark {
  color: var(--ink);
  font-size: 27px;
  font-weight: var(--w-mark);
  letter-spacing: -0.07em;
  text-decoration: none;
  font-variation-settings: "ROND" 100;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: clamp(12px, 2vw, 24px);
  font-size: var(--step-ui);
}

.nav-link {
  display: inline-flex;
  align-items: center;
  padding: 4px 0;
  color: var(--muted);
  text-decoration: none;
  transition: color 140ms ease;
}

.nav-link:hover { color: var(--ink); }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: var(--control-pad);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: var(--step-ui);
  cursor: pointer;
  transition: border-color 140ms ease, color 140ms ease;
}

.theme-toggle:hover { border-color: var(--ink); color: var(--ink); }

.icon-theme { width: 15px; height: 15px; flex: none; }
.icon-theme-orb { transition: r 160ms ease; }

/* System state keeps the rays; the explicit states swap in a fuller mark. */
[data-theme-state="dark"] .icon-theme-rays { opacity: 0.28; }
[data-theme-state="light"] .icon-theme-orb { fill: currentColor; }

/* ------------------------------------------------------------------ hero */

.hero {
  max-width: 780px;
  padding: clamp(56px, 9vw, 104px) 0 clamp(40px, 6vw, 72px);
}

.eyebrow {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: var(--step-eyebrow);
  font-weight: var(--w-strong);
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

/* Width locked to the crossbar of the "T" in the wordmark below it.
   The crossbar measures 0.4775em of the h1 size (glyph bbox at wght 280 /
   ROND 34), and "IZBIWARE" advances total 4.58em, so font-size 0.0909 x h1
   with 0.0961em tracking lands exactly on it. Both are expressed against
   --step-h1 so the relationship survives the clamp() at every viewport.
   max() keeps the type legible once h1 drops below ~110px, at which point the
   match necessarily loosens rather than shrinking the label to nothing. */
.hero .eyebrow {
  width: max-content;
  margin: 0 0 clamp(14px, 1.4vw, 20px);
  /* line the left edge up with the crossbar, not the text origin: the T
     carries a 0.0248em left side bearing */
  margin-left: calc(var(--step-h1) * 0.0248);
  font-size: max(10px, calc(var(--step-h1) * 0.0909));
  letter-spacing: 0.0961em;
  /* letter-spacing also trails the final glyph; pull it back so the measured
     box equals the visible ink */
  margin-right: -0.0961em;
}

h1 {
  margin: 0;
  font-size: var(--step-h1);
  font-weight: var(--w-display);
  line-height: 0.86;
  letter-spacing: -0.055em;
  font-variation-settings: "ROND" 34;
}

h1 em {
  color: var(--muted);
  font-weight: var(--w-display-light);
  font-style: normal;
}

.intro {
  max-width: 30rem;
  margin: clamp(28px, 4vw, 44px) 0 0;
  font-size: var(--step-lead);
  line-height: 1.32;
  letter-spacing: -0.018em;
  color: var(--muted);
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 22px;
  margin-top: clamp(28px, 4vw, 40px);
}

.hero-note {
  max-width: 28rem;
  margin: 0;
  color: var(--muted);
  font-size: var(--step-small);
  line-height: 1.45;
}

/* -------------------------------------------------------- version picker */

.version-picker {
  position: relative;
  flex: none;
}

.version-picker summary {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: var(--control-pad);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--ink);
  font-size: var(--step-ui);
  line-height: 1.2;
  cursor: pointer;
  list-style: none;
  transition: border-color 140ms ease, background-color 140ms ease;
}

.version-picker summary::-webkit-details-marker { display: none; }
.version-picker summary:hover { border-color: var(--ink); }

.version-picker-label {
  color: var(--muted);
  font-size: var(--step-small);
}

.version-picker-value { font-weight: var(--w-medium); }

.icon-chevron { transition: transform 160ms ease; color: var(--muted); }
.version-picker[open] .icon-chevron { transform: rotate(180deg); }

.version-menu {
  position: absolute;
  z-index: 10;
  top: calc(100% + 8px);
  left: 0;
  min-width: 100%;
  width: max-content;
  max-width: min(20rem, calc(100vw - 2 * var(--gutter)));
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.version-menu a {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 12px;
  border-radius: var(--radius-control);
  color: var(--ink);
  font-size: var(--step-ui);
  text-decoration: none;
}

.version-menu a:hover { background: var(--surface-sunken); }

.version-menu a[aria-current="true"] {
  background: var(--surface-sunken);
  color: var(--ink);
  font-weight: var(--w-medium);
}

.version-tag {
  flex: none;
  color: var(--muted);
  font-size: var(--step-small);
}

.version-menu a[aria-current="true"] .version-tag { color: inherit; }
.version-picker.is-loading summary { opacity: 0.55; pointer-events: none; }

/* ---------------------------------------------------------------- layout */

.layout {
  display: grid;
  grid-template-columns: 215px minmax(0, 1fr);
  gap: var(--col-gap);
  padding-bottom: clamp(64px, 9vw, 120px);
}

.contents {
  position: sticky;
  top: 24px;
  align-self: start;
  padding-top: 4px;
}

.contents .eyebrow { margin-bottom: 14px; }

.contents-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: var(--step-ui);
  counter-reset: toc;
}

/* Direct children only: the FAQ sub-questions are not sections and stay
   unnumbered. */
.contents-nav > a {
  counter-increment: toc;
}

.contents-nav > a::before {
  content: counter(toc, decimal-leading-zero);
  margin-right: 10px;
  font-family: var(--mono);
  font-size: var(--step-small);
  color: var(--line-strong);
  font-variant-numeric: tabular-nums;
}

.contents-nav > a.is-active::before { color: var(--muted); }

.contents-nav a {
  min-width: 24px;
  padding: 4px 0;
  color: var(--muted);
  text-decoration: none;
  transition: color 140ms ease;
}

/* One sub-entry per FAQ question, subordinate to the FAQ link above it. */
/* FAQ questions, nested under the FAQ entry. Visible by default so the
   no-JS page keeps every link; site.js adds .js-collapsible to opt in to the
   reveal-on-scroll behaviour below. */
.contents-sub {
  display: block;
  margin: 4px 0 0 3px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
}

.contents-sub-inner {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* 0fr to 1fr animates without a hard-coded height. The trick needs exactly
   one grid child, which is what .contents-sub-inner is for. */
.js-collapsible .contents-sub {
  display: grid;
  grid-template-rows: 0fr;
  margin-top: 0;
  opacity: 0;
  visibility: hidden;
  transition: grid-template-rows 220ms ease, opacity 180ms ease,
              margin-top 220ms ease, visibility 0s linear 220ms;
}

.js-collapsible .contents-sub-inner {
  min-height: 0;
  overflow: hidden;
}

.js-collapsible .contents-sub.is-open {
  grid-template-rows: 1fr;
  margin-top: 4px;
  opacity: 1;
  visibility: visible;
  transition-delay: 0s;
}

/* Controls that do nothing until site.js has run. Hidden rather than left
   inert, because a button that silently ignores a click is worse than no
   button: the theme still follows prefers-color-scheme, and the licence text
   is still selectable by hand. Written as a :not() so the ordinary display
   rules for these controls keep applying whenever scripting is on. */
html:not([data-js="on"]) .js-only { display: none; }

.contents-sub a {
  min-width: 24px;
  padding: 5px 0;
  font-size: var(--step-small);
  line-height: 1.35;
}

.contents-nav a:hover { color: var(--ink); }

.contents-nav a.is-active {
  color: var(--ink);
  font-weight: var(--w-medium);
}

article {
  min-width: 0;
  counter-reset: section;
}

article > section {
  position: relative;
  counter-increment: section;
}

/* Sections are told apart by a numeric index and whitespace instead of rules.
   Set in the mono face so it reads as apparatus, echoing the licence panel. */
article > section::before {
  content: counter(section, decimal-leading-zero);
  position: absolute;
  top: 0.35em;
  right: calc(100% + 18px);
  font-family: var(--mono);
  font-size: var(--step-small);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

article > section + section {
  margin-top: clamp(56px, 7vw, 88px);
}

h2 {
  margin: 0 0 20px;
  font-size: var(--step-h2);
  font-weight: var(--w-strong);
  letter-spacing: -0.032em;
}

.prose {
  max-width: var(--measure);
  line-height: 1.6;
}

.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose h2 { margin: 0 0 20px; }
.prose p { margin: 0 0 1em; }
.prose ol, .prose ul { padding-left: 22px; }

.small {
  max-width: var(--measure);
  margin: 22px 0 0;
  color: var(--muted);
  font-size: var(--step-small);
}

/* --------------------------------------------------------- licence panel */

.section-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 20px;
}

.section-heading h2 { margin: 0; }

.section-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.action {
  display: inline-flex;
  align-items: center;
  padding: var(--control-pad);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: var(--step-ui);
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 140ms ease, background-color 140ms ease;
}

.action:hover { border-color: var(--ink); background: var(--surface-sunken); }
.action[data-copied] { border-color: var(--ink); color: var(--ink); }

.license-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: clamp(18px, 3vw, 30px);
  overflow-x: auto;
}

.license-panel pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  tab-size: 2;
}

.license-panel code {
  font-family: var(--mono);
  font-size: clamp(13.5px, 0.35vw + 12.6px, 15px);
  line-height: 1.72;
}

.license-panel.is-swapping {
  opacity: 0.3;
  transform: translateY(6px);
}

.license-panel { transition: opacity 180ms ease, transform 180ms ease; }

/* --------------------------------------------------------------------- FAQ */

.faq-section details + details { margin-top: 4px; }

.faq-section summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  font-weight: var(--w-medium);
  cursor: pointer;
  list-style: none;
}

.faq-section summary::-webkit-details-marker { display: none; }

.faq-section summary::before {
  content: "";
  width: 9px;
  height: 9px;
  flex: none;
  border-right: 1.6px solid var(--muted);
  border-bottom: 1.6px solid var(--muted);
  transform: rotate(-45deg) translate(-1px, -1px);
  transition: transform 160ms ease;
}

.faq-section details[open] summary::before {
  transform: rotate(45deg) translate(-1px, -1px);
}

.faq-section summary:hover::before { border-color: var(--ink); }

.faq-section details p {
  max-width: calc(var(--measure) - 3ch);
  margin: 0 0 16px 21px;
  color: var(--muted);
}

/* ---------------------------------------------------------------- footer */

.footer-sources {
  display: inline-flex;
  align-items: center;
  gap: 14px;
}

footer {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  justify-content: space-between;
  padding-block: 40px 34px;
  color: var(--muted);
  font-size: var(--step-small);
}

/* ------------------------------------------------------- error / 404 page */

.error,
.not-found {
  max-width: 720px;
  padding-block: 16vh 12vh;
}

.not-found { min-height: calc(100vh - 190px); }

.error h1,
.not-found h1 {
  font-size: clamp(52px, 9vw, 128px);
  line-height: 0.9;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 26px;
  color: var(--ink);
  font-size: var(--step-ui);
}

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

@media (max-width: 940px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .contents {
    position: static;
    margin-bottom: 36px;
    padding: 0;
  }

  /* No gutter to sit in once the layout is a single column. */
  article > section::before {
    position: static;
    display: block;
    margin-bottom: 8px;
  }

  .contents-nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 2px 20px;
  }

  .contents-sub {
    width: 100%;
    margin: 6px 0 0;
    padding: 0;
    border-left: 0;
  }

  .contents-sub-inner {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 2px 16px;
  }
}

@media (max-width: 620px) {
  .site-header { height: 66px; }
  .theme-toggle [data-theme-label] { display: none; }
  .theme-toggle { padding: 7px 9px; }
  .hero-meta { gap: 12px; }
  .section-heading { align-items: flex-start; }
}

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