:root {
  color-scheme: light dark;
  --bg: #fff;
  --surface: #f6f8fa;
  --ink-strong: #1f2328;
  --ink: #2d333b;
  --muted: #59636e;
  --subtle: #656d76;
  --border: #e1e4e8;
  --kbd-border: #d0d7de;
  --accent: #0066cc;
  --accent-hover: #0052a3;
  --accent-soft: #8cbae8;
  --on-accent: #fff;
  --target: #e5f0fb;
  /* Red marks only the failure signal, since readers take red as failure. */
  --failure: #cf222e;
  /* The flash takes the browser's own selection colour, and multiplies on light backgrounds and screens on dark ones so it reads stronger than the selection under it. */
  --flash: Highlight;
  --flash-blend: multiply;
  --gutter: clamp(16px, 4vw, 48px);
  --copy-shake-ms: 400ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1e1e1e;
    --surface: #2a2a2a;
    --ink-strong: #f5f5f5;
    --ink: #e0e0e0;
    --muted: #a8a8a8;
    --subtle: #939393;
    --border: #363636;
    --kbd-border: #4a4a4a;
    --accent: #2997ff;
    --accent-hover: #5fb1ff;
    --accent-soft: #245a8f;
    --on-accent: #1e1e1e;
    --target: #1b2a3a;
    --failure: #ff7b72;
    --flash-blend: screen;
  }
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

[hidden] { display: none !important; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.page {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

/* Header and navigation */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  flex-wrap: wrap;
  padding: 20px var(--gutter);
  border-bottom: 1px solid var(--border);
}

.site-name {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.015em;
  color: var(--ink-strong);
}
.site-name:hover { color: var(--ink-strong); text-decoration: none; }

.site-nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 8px clamp(14px, 2.5vw, 28px);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 15px;
  font-weight: 500;
}
.site-nav a { color: var(--muted); }
/* A shake moves the element with translate, which inline boxes ignore. */
.site-nav a, .site-footer a { display: inline-block; }
.site-nav a:hover { color: var(--ink-strong); }
.site-nav a[aria-current="page"] {
  color: var(--ink-strong);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: var(--accent-soft);
  text-decoration-thickness: 2px;
  text-underline-offset: 6px;
}

/* Footer */

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 8px 16px;
  flex-wrap: wrap;
  padding: 28px var(--gutter);
  font-size: 14px;
  color: var(--subtle);
  border-top: 1px solid var(--border);
}
.site-footer ul {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Shared type */

.eyebrow {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

/* Home */

.hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 28px;
  padding: clamp(48px, 10vh, 120px) var(--gutter);
}

.hero-sentence {
  margin: 0;
  max-width: 14ch;
  font-size: clamp(36px, 6.5vw, 72px);
  /* Room between lines, so one line's selection highlight never covers the next line's glyphs. */
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ink-strong);
  text-wrap: balance;
}

.hero-instruction {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0;
  font-size: clamp(18px, 2vw, 22px);
  color: var(--muted);
}
.hero-instruction.for-touch { display: none; }
@media (pointer: coarse) {
  .hero-instruction.for-keyboard { display: none; }
  .hero-instruction.for-touch { display: flex; }
}

.copy-alternative {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: -12px;
  font-size: 15px;
  color: var(--subtle);
}
.copy-alternative .button { margin-top: 0; }

kbd {
  min-width: 22px;
  padding: 6px 12px;
  font-family: inherit;
  font-weight: 600;
  font-size: 18px;
  color: var(--ink-strong);
  background: var(--surface);
  border: 1px solid var(--kbd-border);
  border-bottom-width: 3px;
  border-radius: 10px;
}

.answer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-height: 150px;
  margin-top: clamp(24px, 5vh, 56px);
}
.answer-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.answer h2 {
  margin: 0;
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink-strong);
}
.answer p {
  margin: 0;
  max-width: 36ch;
  font-size: clamp(17px, 1.8vw, 20px);
  line-height: 1.5;
  color: var(--muted);
  text-wrap: pretty;
}

.button {
  margin-top: 8px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  font-size: 16px;
  color: var(--ink-strong);
  background: var(--surface);
  border: 1px solid var(--kbd-border);
  border-radius: 999px;
  cursor: pointer;
}
.button:hover { border-color: var(--accent-soft); }
.button[aria-pressed="true"] { border-color: var(--accent); }

/* Once pressed, the call to action has done its job and falls back to the plain button. */
.button-primary:not([aria-pressed="true"]) {
  padding: 14px 28px;
  font-size: 18px;
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 6px 20px -8px var(--accent);
}
.button-primary:not([aria-pressed="true"]):hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* Demo */

.demo {
  flex: 1;
  width: 100%;
  max-width: 1040px;
  box-sizing: border-box;
  margin: 0 auto;
  padding: clamp(40px, 8vh, 96px) var(--gutter);
}
.demo h1 {
  margin: 12px 0 16px;
  font-size: clamp(36px, 6vw, 64px);
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ink-strong);
}
.demo-section {
  margin-top: clamp(48px, 8vh, 80px);
  padding-top: clamp(32px, 5vh, 48px);
  border-top: 1px solid var(--border);
}
.demo-section h2 {
  margin: 0 0 12px;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink-strong);
}
.demo-intro {
  margin: 0;
  max-width: 60ch;
  font-size: 18px;
  line-height: 1.5;
  color: var(--muted);
}

.demo-controls {
  display: flex;
  align-items: center;
  gap: 8px 16px;
  flex-wrap: wrap;
  margin: 28px 0 0;
  font-size: 16px;
  color: var(--muted);
}
.demo-controls .button { margin-top: 0; }
.demo-controls kbd { padding: 3px 8px; font-size: 15px; border-radius: 8px; }
.motion-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--ink-strong);
  cursor: pointer;
}
.motion-toggle input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }

.panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  gap: 20px;
  margin-top: 28px;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: clamp(20px, 3vw, 32px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
}
.panel:focus-visible { outline-offset: 4px; }
.panel h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--subtle);
}
.panel-text {
  margin: 0;
  font-size: clamp(22px, 2.6vw, 28px);
  line-height: 1.3;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink-strong);
  text-wrap: pretty;
}
.panel-link {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: auto;
}
.panel-link code {
  min-width: 0;
  padding: 8px 12px;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-wrap: anywhere;
}
.panel-link .button { margin-top: 0; }

/* Article pages: What and History */

.article {
  flex: 1;
  width: 100%;
  max-width: 880px;
  box-sizing: border-box;
  margin: 0 auto;
  padding: clamp(40px, 8vh, 96px) var(--gutter);
  font-size: 18px;
  line-height: 1.55;
}
.article h1 {
  margin: 12px 0 16px;
  font-size: clamp(36px, 6vw, 64px);
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ink-strong);
}
.article-section, .footnotes {
  margin-top: clamp(40px, 6vh, 64px);
  padding-top: clamp(24px, 4vh, 40px);
  border-top: 1px solid var(--border);
}
.article h2 {
  margin: 0 0 16px;
  font-size: clamp(24px, 3.5vw, 36px);
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink-strong);
}
.article code { font-size: 0.9em; overflow-wrap: anywhere; }
.spec-meta { margin: 0 0 24px; font-size: 15px; color: var(--muted); }
.spec-clause { margin-top: 32px; }
.spec-clause h3 {
  margin: 0 0 8px;
  font-size: 22px;
  line-height: 1.25;
  font-weight: 600;
  color: var(--ink-strong);
}

/* Page guide: folded under the intro on a narrow screen, a sticky rail beside the article on a wide one. */
.toc {
  margin-top: 32px;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  line-height: 1.4;
}
.toc summary { cursor: pointer; }
.toc ol { list-style: none; margin: 12px 0 0; padding: 0; }
.toc li + li { margin-top: 2px; }
.toc a {
  display: block;
  padding: 4px 0 4px 12px;
  border-left: 2px solid transparent;
  color: var(--muted);
}
.toc a:hover { color: var(--ink-strong); text-decoration: none; }
.toc a[aria-current] { border-left-color: var(--accent); color: var(--ink-strong); font-weight: 600; }

@media (min-width: 1200px) {
  .article.has-toc {
    max-width: 1180px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 220px;
    column-gap: 56px;
  }
  .article.has-toc > * { grid-column: 1; }
  .article.has-toc > .toc {
    grid-column: 2;
    grid-row: 1 / span 40;
    align-self: start;
    position: sticky;
    top: 32px;
    max-height: calc(100vh - 64px);
    overflow-y: auto;
    margin-top: 0;
    padding: 0;
    border: 0;
  }
  .toc summary { pointer-events: none; list-style: none; }
  .toc summary::-webkit-details-marker { display: none; }
}

/* Only the table scrolls on a narrow screen, never the page. */
.table-wrap { overflow-x: auto; }
.article table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-size: 16px;
  line-height: 1.45;
}
.article caption {
  caption-side: top;
  padding-bottom: 8px;
  text-align: left;
  font-size: 14px;
  color: var(--muted);
}
.article th, .article td {
  padding: 10px 12px 10px 0;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.article thead th {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--subtle);
}
.article tbody th { font-weight: 600; color: var(--ink-strong); }

.article blockquote {
  margin: 0 0 24px;
  padding-left: 20px;
  border-left: 3px solid var(--accent);
}
.article blockquote p { margin: 0; font-size: 20px; color: var(--ink-strong); }
.article blockquote footer { margin-top: 8px; font-size: 15px; color: var(--muted); }

.timeline { margin: 0; padding-left: 0; list-style: none; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.timeline time { font-weight: 600; color: var(--ink-strong); }

.fn-ref { font-size: 0.7em; line-height: 0; margin-left: 1px; }
.fn-ref + .fn-ref::before { content: ","; margin-right: 1px; }
.footnotes p { margin: 0 0 16px; color: var(--muted); }
.footnotes ol { margin: 0; padding-left: 28px; font-size: 14px; line-height: 1.5; color: var(--muted); }
.footnotes li { margin-bottom: 6px; overflow-wrap: anywhere; }
.footnotes li:target { color: var(--ink-strong); background: var(--target); }

/* Copy feedback, drawn by js/copy-feedback.js */

.copy-flash {
  position: absolute;
  z-index: 9999;
  border-radius: 4px;
  background: var(--flash);
  mix-blend-mode: var(--flash-blend);
  pointer-events: none;
}

.copy-shake { animation: copy-shake var(--copy-shake-ms) ease-in-out; }

@keyframes copy-shake {
  0%, 100% { translate: 0; }
  20% { translate: -8px; }
  40% { translate: 8px; }
  60% { translate: -5px; }
  80% { translate: 5px; }
}

/* The reduced-motion shake is a static outline, from the system setting unless the page forces a version; dashed so it never reads as the focus ring. */
:root[data-motion="reduce"] .copy-shake {
  animation: none;
  outline: 3px dashed var(--failure);
  outline-offset: 6px;
}
@media (prefers-reduced-motion: reduce) {
  :root:not([data-motion="full"]) .copy-shake {
    animation: none;
    outline: 3px dashed var(--failure);
    outline-offset: 6px;
  }
}
