/*
 * The Robot Institute — D1 · Policy Institute, application layer.
 *
 * Source of truth: design/mockups/build.py (DIRS_D["d1"]) and web/app/globals.css
 * as shipped in PR #16. The same seeds are the engine theme
 * backend/themes/theme-d1 (priv/static/themes/d1.css), which the style-guide
 * pages load; the paper pages load only this file.
 *
 * Six fixes carried from web/: links are underlined; H1 > H2 > H3 by size and
 * weight; a 62–72ch reading measure (66ch); one section rule (h2 only); the
 * claret accent is reserved for the one primary action and current state; and
 * trailing slashes redirect (InstituteWeb.Plugs.PaperRoutes).
 *
 * Scales, kept deliberately small (design-lint):
 *   spacing 4 · 8 · 12 · 16 · 24 · 32 · 48
 *   type    40/500 · 24/500 · 18/400 · 18/600 · 14/400 · 14/600 · 12/600
 *   radius  2 · 4 · pill
 *
 * Light is the default. Dark follows prefers-color-scheme unless the reader
 * pinned a mode: <html data-theme="light|dark">, written from the color-mode
 * cookie by the server and by /js/institute.js on toggle.
 */

:root {
  --f-read: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --f-ui: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "Source Code Pro", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --measure: 66ch;

  --page: #eef0f3;
  --head: #ffffff;
  --head-text: #14284b;
  --rail: #f7f8fa;
  --rail-text: #1f2a3a;
  --rail-muted: #556175;
  --rail-link: #14284b;
  --rail-chip-bg: #e7eaf0;
  --chrome-rule: #d7dce4;
  --paper: #fbfaf6;
  --ink: #1b2230;
  --ink-muted: #525c6b;
  --link: #14284b;
  --rule: #e2ded4;
  --rule-strong: #878d98;
  --accent: #7a1f2b;
  --on-accent: #fbfaf6;
  --marker: #7a1f2b;
  --chip-bg: #eeede6;
  --chip-fg: #1b2230;
  --add-bg: #dcedf0;
  --add-fg: #0e5361;
  --rem-bg: #f4e4cf;
  --rem-fg: #7d4414;
  --sheet-shadow: 0 1px 2px rgba(24, 32, 48, 0.08), 0 8px 24px rgba(24, 32, 48, 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #0f1726;
    --head: #131c2d;
    --head-text: #dfe3ea;
    --rail: #131c2d;
    --rail-text: #d5dae3;
    --rail-muted: #9aa5b8;
    --rail-link: #a9c0e8;
    --rail-chip-bg: #1f2a42;
    --chrome-rule: #29344b;
    --paper: #1a2233;
    --ink: #dcd9d0;
    --ink-muted: #a7adb8;
    --link: #a9c0e8;
    --rule: #2e384c;
    --rule-strong: #5e697d;
    --accent: #9a3342;
    --on-accent: #fbf3f3;
    --marker: #d4a5aa;
    --chip-bg: #26314a;
    --chip-fg: #dcd9d0;
    --add-bg: #173d46;
    --add-fg: #8fd3de;
    --rem-bg: #45301c;
    --rem-fg: #efb584;
    --sheet-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --page: #0f1726;
  --head: #131c2d;
  --head-text: #dfe3ea;
  --rail: #131c2d;
  --rail-text: #d5dae3;
  --rail-muted: #9aa5b8;
  --rail-link: #a9c0e8;
  --rail-chip-bg: #1f2a42;
  --chrome-rule: #29344b;
  --paper: #1a2233;
  --ink: #dcd9d0;
  --ink-muted: #a7adb8;
  --link: #a9c0e8;
  --rule: #2e384c;
  --rule-strong: #5e697d;
  --accent: #9a3342;
  --on-accent: #fbf3f3;
  --marker: #d4a5aa;
  --chip-bg: #26314a;
  --chip-fg: #dcd9d0;
  --add-bg: #173d46;
  --add-fg: #8fd3de;
  --rem-bg: #45301c;
  --rem-fg: #efb584;
  --sheet-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

/* Scaffold sheets on the D1 face (.content, sg-* — home, account): the theme
   sheet scopes its dark tokens to `html.dark`, a class the layout only writes
   for a PINNED dark mode. With colour-mode `system` + a dark OS theme, this
   sheet went dark (media query) while the scaffold sheets stayed light — a
   light sheet with washed-out text on / and /account (F3, 2026-12 walkthrough).
   Map the scaffold's bare tokens onto the D1 tokens for that mode; pinned
   light and pinned dark are untouched. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --text: var(--ink);
    --text-secondary: var(--ink-muted);
    --text-muted: var(--rail-muted);
    --text-inverse: var(--page);
    --surface: var(--paper);
    --surface-alt: var(--page);
    --surface-inverse: var(--head-text);
    --border: var(--rule);
    --border-strong: var(--rule-strong);
    --error: var(--accent);
  }
}

/* ── base ─────────────────────────────────────────────────────────────── */

html.d1 {
  -webkit-text-size-adjust: 100%;
}

/* The root stays at the browser default (16px) so rem-based sizes are what
   they say; the UI text size is set on body. */
html.d1,
html.d1 body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--f-ui);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

html.d1 body {
  font-size: 0.875rem;
}

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

.d1 :is(p, ol, ul, dl, dd, dt, h1, h2, h3, h4, h5, h6, blockquote, figure, pre) {
  margin: 0;
}

.d1 :is(ol, ul) {
  padding: 0;
}

.d1 strong {
  font-weight: 600;
}

.d1 a {
  color: inherit;
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

.d1 a:hover {
  text-decoration-thickness: 2px;
}

.d1 :focus-visible {
  outline: 2px solid var(--marker);
  outline-offset: 2px;
}

.d1 code,
.d1 pre {
  font-family: var(--f-mono);
}

.d1 ::selection {
  background: var(--link);
  color: var(--paper);
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.d1 .skip-link {
  position: absolute;
  left: 16px;
  top: -48px;
  z-index: 80;
  background: var(--accent);
  color: var(--on-accent);
  padding: 8px 16px;
  font-weight: 600;
  text-decoration: none;
}

.d1 .skip-link:focus {
  top: 12px;
}

/* ── header ───────────────────────────────────────────────────────────── */

.d1-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 24px;
  padding: 12px 24px;
  background: var(--head);
  color: var(--head-text);
  border-bottom: 1px solid var(--chrome-rule);
}

.d1 .d1-mark {
  font-family: var(--f-read);
  font-size: 1.125rem;
  font-weight: 600;
  font-variant-caps: all-small-caps;
  letter-spacing: 0.08em;
  text-decoration: none;
  padding-right: 16px;
  border-right: 1px solid var(--chrome-rule);
  min-height: 32px;
  display: inline-flex;
  align-items: center;
}

.d1-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.d1 .d1-nav a,
.d1 .d1-signin,
.d1 .d1-account {
  text-decoration: none;
  min-height: 32px;
  min-width: 32px;
  justify-content: center;
  display: inline-flex;
  align-items: center;
}

.d1 .d1-nav a:hover,
.d1 .d1-signin:hover,
.d1 .d1-account:hover,
.d1 .d1-nav a[aria-current="page"] {
  text-decoration: underline;
}

.d1-head-end {
  margin-left: auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.d1-mode {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid var(--chrome-rule);
  border-radius: 4px;
  padding: 4px 12px;
  min-height: 32px;
  cursor: pointer;
}

.d1 .d1-signin {
  font-weight: 600;
}

.d1-linkbtn {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  padding: 0;
  min-height: 32px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.when-dark {
  display: none;
}

:root[data-theme="dark"] .when-dark {
  display: inline;
}

:root[data-theme="dark"] .when-light {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .when-dark {
    display: inline;
  }

  :root:not([data-theme="light"]) .when-light {
    display: none;
  }
}

/* ── footer ───────────────────────────────────────────────────────────── */

.d1-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  color: var(--rail-muted);
  border-top: 1px solid var(--chrome-rule);
  background: var(--head);
}

.d1 .d1-foot a {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
}

.d1-foot select {
  font: inherit;
  color: inherit;
  background: var(--paper);
  border: 1px solid var(--chrome-rule);
  border-radius: 4px;
  min-height: 32px;
  padding: 4px 8px;
}

.d1-foot label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* ── generic page frame ───────────────────────────────────────────────── */

/* main is a grid so frames centre with justify-self rather than auto
   margins (which compute to one-off spacing values). */
.d1-main {
  min-height: 60vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

/* Style-guide pages centre .content with auto margins; with inline-size
   containment a grid item would shrink to nothing, so give it the width. */
.d1-main > .content {
  width: 100%;
}

.d1-frame {
  justify-self: center;
  width: 100%;
  max-width: 1120px;
  padding: 32px 24px 48px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.d1-frame-narrow {
  max-width: 880px;
}

.d1-title {
  font-family: var(--f-read);
  font-size: 2.5rem;
  line-height: 1.15;
  font-weight: 500;
  letter-spacing: -0.01em;
  text-wrap: balance;
  color: var(--ink);
}

.d1-lede {
  color: var(--ink-muted);
  max-width: 72ch;
}

.d1-h2 {
  font-family: var(--f-read);
  font-size: 1.5rem;
  line-height: 1.25;
  font-weight: 500;
  text-wrap: balance;
}

.d1-label {
  font-family: var(--f-ui);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--rail-muted);
}

.d1-muted {
  color: var(--ink-muted);
}

.d1-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.d1-stack-tight {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.d1-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* ── chips, pills, ballot bars ────────────────────────────────────────── */

.d1-chip {
  display: inline-block;
  font-family: var(--f-mono);
  font-size: 0.875rem;
  font-weight: 400;
  padding: 0 4px;
  border-radius: 2px;
  background: var(--rail-chip-bg);
  color: inherit;
  white-space: nowrap;
  font-variant-ligatures: none;
}

.d1-sheet .d1-chip {
  background: var(--chip-bg);
  color: var(--chip-fg);
}

.d1-pill {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 0 8px;
  color: var(--rail-muted);
  white-space: nowrap;
}

.d1-pill-current {
  color: var(--marker);
}

.d1-pill-strong {
  color: var(--rail-text);
}

.d1-ballot {
  display: flex;
  gap: 4px;
}

.d1-ballot i {
  display: block;
  width: 32px;
  height: 4px;
  border-radius: 2px;
  background: var(--chrome-rule);
}

.d1-ballot i.on {
  background: var(--rail-text);
}

.d1-person {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
}

.d1-name {
  font-weight: 600;
}

/* ── buttons ──────────────────────────────────────────────────────────── */

.d1-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  font-family: var(--f-ui);
  font-size: 0.875rem;
}

.d1 .d1-btn {
  font: inherit;
  font-family: var(--f-ui);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.5;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 4px;
  text-decoration: none;
  cursor: pointer;
}

.d1 .d1-btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  border: 1px solid var(--accent);
}

.d1 .d1-btn-secondary {
  background: transparent;
  color: inherit;
  border: 1px solid var(--rule-strong);
}

.d1 .d1-btn:disabled,
.d1 .d1-btn[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.6;
}

.d1 .d1-btn[aria-busy="true"] {
  cursor: progress;
}

.d1 .d1-btn:hover:not(:disabled) {
  text-decoration: underline;
}

/* ── notices: the state vocabulary ────────────────────────────────────── */

.d1-notice {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
  border-left: 4px solid var(--rule-strong);
  background: var(--rail);
  color: var(--rail-text);
}

.d1-notice-pending,
.d1-notice-stale {
  border-left-color: var(--marker);
}

.d1-notice-error {
  border-left-color: var(--rem-fg);
}

.d1-notice-empty {
  border-left-color: var(--chrome-rule);
}

.d1-notice > strong {
  font-weight: 600;
}

.d1-status {
  min-height: 24px;
  color: var(--ink-muted);
}

/* ── the paper page: rails + sheet ────────────────────────────────────── */

.d1-doc {
  container: d1doc / inline-size;
}

.d1-tabs {
  display: none;
}

/* The revision rail (revisions, proposals, ballots) sits above the contents:
   a long paper's contents list would otherwise push it out of view. */
.d1-body {
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr) 320px;
  grid-template-areas:
    "revs paper disc"
    "toc paper disc";
  grid-template-rows: auto 1fr;
}

.d1-revs {
  grid-area: revs;
  border-right: 1px solid var(--chrome-rule);
  border-bottom: 1px solid var(--chrome-rule);
}

.d1-toc {
  grid-area: toc;
  border-right: 1px solid var(--chrome-rule);
}

.d1-sheet-wrap {
  grid-area: paper;
  min-width: 0;
}

.d1-disc {
  grid-area: disc;
  border-left: 1px solid var(--chrome-rule);
}

.d1-panel {
  background: var(--rail);
  color: var(--rail-text);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.d1-panel a {
  color: var(--rail-link);
}

.d1-toc ol {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.d1-toc ol ol {
  padding-left: 12px;
  margin-top: 8px;
}

.d1 .d1-toc a {
  min-height: 24px;
  display: inline-block;
}

.d1-toc-part {
  color: var(--rail-muted);
}

.d1-revlist {
  list-style: none;
  display: flex;
  flex-direction: column;
}

.d1-rev {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 0;
  border-top: 1px solid var(--chrome-rule);
}

.d1-rev[aria-current] {
  box-shadow: inset 4px 0 0 var(--marker);
  padding-left: 12px;
}

.d1-rev-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.d1 .d1-rev-line a {
  font-weight: 600;
  min-height: 24px;
  min-width: 24px;
  display: inline-flex;
  align-items: center;
}

.d1-rev-meta {
  color: var(--rail-muted);
}

.d1-sheet {
  background: var(--paper);
  color: var(--ink);
  margin: 24px;
  padding: 48px;
  display: flex;
  justify-content: center;
  border-radius: 2px;
  box-shadow: var(--sheet-shadow);
}

.d1-sheet-inner {
  width: 100%;
  max-width: var(--measure);
  display: flex;
  flex-direction: column;
  gap: 16px;
  font-family: var(--f-read);
  font-size: 1.125rem;
  line-height: 1.6;
  min-width: 0;
}

.d1-sheet-inner > .d1-label,
.d1-sheet-inner > .d1-meta,
.d1-sheet-inner > .d1-actions,
.d1-sheet-inner > .d1-notice {
  font-family: var(--f-ui);
}

.d1-sheet .d1-label {
  color: var(--ink-muted);
}

.d1-sheet a {
  color: var(--link);
}

.d1-sheet h1 {
  font-family: var(--f-read);
  font-size: clamp(2rem, 4.5cqi, 2.5rem);
  line-height: 1.15;
  font-weight: 500;
  text-wrap: balance;
  letter-spacing: -0.01em;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--rule-strong);
}

.d1-sub {
  font-style: italic;
  color: var(--ink-muted);
}

.d1-meta {
  font-size: 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 0;
  border-block: 1px solid var(--rule);
}

.d1-meta > div {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 12px;
  align-items: baseline;
}

.d1-meta dt {
  color: var(--ink-muted);
}

.d1-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.d1-cite {
  font-family: var(--f-mono);
}

.d1-compare {
  margin-left: auto;
  min-height: 24px;
  display: inline-flex;
  align-items: center;
}

/* ── rendered markdown ────────────────────────────────────────────────── */

.d1-prose {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.d1-prose :is(h2, h3, h4, h5, h6) {
  font-family: var(--f-read);
  text-wrap: balance;
  scroll-margin-top: 24px;
}

/* The single section rule: only h2 carries a rule. */
.d1-prose h2 {
  font-size: 1.5rem;
  line-height: 1.25;
  font-weight: 500;
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
}

.d1-prose :is(h3, h4, h5, h6) {
  font-size: 1.125rem;
  line-height: 1.4;
  font-weight: 600;
  margin-top: 16px;
}

.d1-prose hr {
  border: 0;
  height: 0;
  margin: 0;
}

.d1-prose :is(ul, ol) {
  padding-left: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.d1-prose blockquote {
  border-left: 2px solid var(--rule);
  padding-left: 16px;
  font-style: italic;
  color: var(--ink-muted);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.d1-prose code {
  font-size: 1em;
  background: var(--chip-bg);
  padding: 0 4px;
  border-radius: 2px;
}

.d1-prose pre {
  overflow-x: auto;
  padding: 12px 16px;
  background: var(--chip-bg);
  border-radius: 2px;
  font-size: 0.875rem;
  line-height: 1.5;
}

.d1-prose pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
}

.d1-prose .d1-table-wrap {
  overflow-x: auto;
}

.d1-prose table {
  border-collapse: collapse;
  font-family: var(--f-ui);
  font-size: 0.875rem;
  width: 100%;
}

.d1-prose :is(td, th) {
  border-bottom: 1px solid var(--rule);
  padding: 8px 12px 8px 0;
  text-align: left;
  vertical-align: top;
}

.d1-prose th {
  font-weight: 600;
}

.d1-prose .d1-math {
  font-family: var(--f-mono);
  font-size: 0.875rem;
  overflow-x: auto;
}

.d1-prose [id^="b-"]:target,
.d1-prose [id^="b-"].d1-hl {
  background: var(--add-bg);
  box-shadow: 0 0 0 4px var(--add-bg);
}

.d1-blk-note {
  font-family: var(--f-ui);
  font-size: 0.875rem;
  color: var(--ink-muted);
}

/* ── diff ──────────────────────────────────────────────────────────────── */

.d1-diff {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-left: 16px;
  border-left: 2px solid var(--rule-strong);
}

.d1 ins,
.d1 del {
  padding: 0 4px;
  border-radius: 2px;
  text-decoration-thickness: 2px;
}

.d1 ins {
  background: var(--add-bg);
  color: var(--add-fg);
  text-decoration-line: underline;
  text-underline-offset: 0.2em;
}

.d1 del {
  background: var(--rem-bg);
  color: var(--rem-fg);
  text-decoration-line: line-through;
}

/* The marker is inline and joined to the first word by a no-break space, so
   a line never breaks between "+" and what was added. */
.d1 ins::before,
.d1 del::before {
  font-family: var(--f-mono);
  font-weight: 400;
}

.d1 ins::before {
  content: "+\00a0";
}

.d1 del::before {
  content: "\2212\00a0";
}

.d1-dblock {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0 12px 16px;
  border-left: 4px solid var(--rule);
}

.d1-dblock-ins {
  border-left-color: var(--add-fg);
}

.d1-dblock-del {
  border-left-color: var(--rem-fg);
}

.d1-dblock-mod {
  border-left-color: var(--rule-strong);
}

.d1-dblock p {
  white-space: pre-wrap;
}

.d1-dblock-same {
  color: var(--ink-muted);
}

.d1-dblock .d1-label {
  color: var(--ink-muted);
}

.d1-diffstat {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--ink-muted);
}

/* ── discussion ───────────────────────────────────────────────────────── */

.d1-thread {
  list-style: none;
  display: flex;
  flex-direction: column;
}

.d1-thread .d1-thread {
  margin-top: 12px;
  padding-left: 16px;
  border-left: 1px solid var(--chrome-rule);
}

.d1-comment {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 0;
  border-top: 1px solid var(--chrome-rule);
}

.d1-thread .d1-thread .d1-comment:first-child {
  border-top: 0;
  padding-top: 0;
}

.d1-comment:target {
  box-shadow: inset 4px 0 0 var(--marker);
  padding-left: 12px;
}

.d1-comment .d1-cbody {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.d1-when {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--rail-muted);
}

/* ── forms ────────────────────────────────────────────────────────────── */

.d1-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.d1-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.d1-field > label,
.d1-field > .d1-flabel {
  font-weight: 600;
}

.d1-hint {
  color: var(--ink-muted);
}

.d1 .d1-input,
.d1 .d1-textarea,
.d1 .d1-select {
  font: inherit;
  font-family: var(--f-ui);
  font-size: 0.875rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  padding: 8px 12px;
  min-height: 40px;
  width: 100%;
  max-width: 100%;
}

.d1 .d1-textarea {
  font-family: var(--f-mono);
  line-height: 1.6;
  resize: vertical;
}

.d1 .d1-textarea-doc {
  min-height: 60vh;
}

.d1 .d1-input[readonly] {
  background: var(--rail);
}

/* ── lists: index, queue, proposal rows ───────────────────────────────── */

.d1-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border-radius: 2px;
  box-shadow: var(--sheet-shadow);
}

.d1-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--rule);
}

.d1-item:first-child {
  border-top: 0;
}

.d1-item-title {
  font-family: var(--f-read);
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.4;
}

.d1 .d1-item-title a {
  color: var(--link);
}

.d1-item-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  color: var(--ink-muted);
}

.d1-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── two-column pages: proposal detail, editor ────────────────────────── */

.d1-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: start;
}

.d1-card {
  background: var(--paper);
  color: var(--ink);
  border-radius: 2px;
  box-shadow: var(--sheet-shadow);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.d1-card-rail {
  background: var(--rail);
  color: var(--rail-text);
  box-shadow: none;
  border: 1px solid var(--chrome-rule);
}

.d1-card .d1-read {
  font-family: var(--f-read);
  font-size: 1.125rem;
  line-height: 1.6;
}

.d1-editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.d1-seg {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--chrome-rule);
}

.d1-seg button {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  min-height: 40px;
  padding: 0 12px;
  cursor: pointer;
}

.d1-seg button[aria-selected="true"] {
  border-bottom-color: var(--marker);
  font-weight: 600;
}

.d1-votes {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.d1-dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 12px;
}

.d1-dl dt {
  color: var(--rail-muted);
}

/* ── narrow containers: tabs replace rails ────────────────────────────── */

@container d1doc (max-width: 1079px) {
  .d1-tabs {
    display: flex;
    gap: 4px;
    padding: 0 16px;
    background: var(--head);
    color: var(--head-text);
    border-bottom: 1px solid var(--chrome-rule);
    overflow-x: auto;
  }

  .d1-tabs button {
    font: inherit;
    color: inherit;
    background: transparent;
    border: 0;
    border-bottom: 2px solid transparent;
    min-height: 44px;
    padding: 0 12px;
    cursor: pointer;
    white-space: nowrap;
  }

  .d1-tabs button[aria-selected="true"] {
    border-bottom-color: var(--marker);
    font-weight: 600;
  }

  .d1-body {
    display: block;
  }

  .d1-panel {
    border: 0 !important;
  }

  .d1-sheet {
    margin: 12px;
    padding: 24px 16px;
  }

  .d1-doc[data-tab="paper"] :is(.d1-toc, .d1-revs, .d1-disc),
  .d1-doc[data-tab="contents"] :is(.d1-sheet-wrap, .d1-disc),
  .d1-doc[data-tab="discussion"] :is(.d1-sheet-wrap, .d1-toc, .d1-revs) {
    display: none;
  }

  .d1-compare {
    margin-left: 0;
  }

  .d1-meta > div {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

@media (max-width: 960px) {
  .d1-split,
  .d1-editor {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 820px) {
  .d1 .d1-input,
  .d1 .d1-textarea,
  .d1 .d1-select {
    font-size: 1.125rem;
  }

  /* Two rows: wordmark + controls, then the site nav. */
  .d1-head {
    padding: 8px 16px;
    gap: 8px 12px;
  }

  .d1 .d1-mark {
    border-right: 0;
    padding-right: 0;
  }

  .d1-nav {
    order: 3;
    width: 100%;
  }

  .d1-head-end {
    margin-left: auto;
    gap: 8px;
  }

  .d1-foot {
    padding: 12px 16px;
    gap: 8px 16px;
  }

  .d1-frame {
    padding: 24px 16px 48px;
  }

  .d1-title {
    font-size: 2rem;
  }

  .d1-item {
    padding: 16px;
  }
}

@media (max-width: 480px) {
  /* The sign-in page links to joining, and /account has Sign out: keep the
     header to one row of controls. */
  /* Sign out is also on /account. */
  .d1 .d1-head-end a[data-auth-open="join"],
  .d1 .d1-head-end .d1-signout {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .d1 * {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}

.d1-pre {
  white-space: pre-wrap;
}

/* Cookie choice (the app sets only necessary cookies): in the page flow after
   the footer, never fixed over the text being read. */
.d1 .cookie-banner {
  background: var(--head);
  color: var(--head-text);
  border-top: 1px solid var(--chrome-rule);
  padding: 16px 24px;
}

.d1 .cookie-banner__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
}

.d1 .cookie-banner__actions {
  display: flex;
  gap: 8px;
}

/* ── /admin/genesis: owner-signed first revisions of reserved papers ───── */

.d1-genesis-hash {
  font-family: var(--f-mono);
  font-size: 0.8125rem;
  overflow-wrap: anywhere;
  word-break: break-all;
}

.d1-genesis-preview {
  font-family: var(--f-mono);
  font-size: 0.8125rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 24rem;
  overflow: auto;
  margin: 0;
  padding: 12px 16px;
  background: var(--rail);
  color: var(--rail-text);
  border: 1px solid var(--rule);
}

.d1-genesis-preview:focus-visible {
  outline: 2px solid var(--marker);
  outline-offset: 2px;
}

/* ── /join: account creation ─────────────────────────────────────────────
   Two layers. The interactive block is the [data-identity-root] element, which
   /js/auth-modal.js lifts into the sign-in panel and whose class list it
   replaces, so the rules scoped to .join-page are page-only. The explainers
   beside and below it are reading matter. Scales as at the top of this file.
   The engine theme's form controls carry light-mode tokens only, so the form
   restates them with the D1 tokens; the claret marks the one primary action
   and the section a reader jumped to. */

.d1 .join-head {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: var(--measure);
}

.d1 .join-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: start;
}

.d1 .join-panel {
  max-width: 40rem;
}

.d1 .join-rail {
  position: sticky;
  top: 24px;
}

/* The interactive block */

.d1 .join-page [data-identity-root] {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.d1 .join-intro,
.d1 .join-hint {
  color: var(--ink-muted);
}

.d1 .join-page .sg-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 28rem;
}

.d1 .join-page .sg-field {
  gap: 4px;
  margin-bottom: 0;
}

/* Labels in the D1 form voice: sentence case, UI font, 14/600. The engine
   theme puts small-caps mono on every bare <label>. */
.d1 .join-page .sg-field > label {
  display: block;
  font-family: var(--f-ui);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: normal;
  text-transform: none;
  color: var(--ink);
}

.d1 .join-page .sg-field input:not([type="checkbox"]) {
  background: var(--rail);
  color: var(--ink);
  caret-color: var(--ink);
  border-color: var(--rule-strong);
}

.d1 .join-page .sg-field input::placeholder {
  color: var(--ink-muted);
}

.d1 .join-page .sg-field input:focus {
  outline: 2px solid var(--marker);
  outline-offset: 2px;
  border-color: var(--rule-strong);
  box-shadow: none;
}

.d1 .join-page [data-identity-slot="pseudonym-status"] {
  font-weight: 600;
}

.d1 .join-page [data-identity-slot="pseudonym-status"]:empty {
  display: none;
}

.d1 .join-page .btn {
  min-height: 40px;
  white-space: normal;
  text-align: center;
}

.d1 .join-page .btn:focus-visible {
  outline: 2px solid var(--marker);
  outline-offset: 2px;
}

/* The engine theme's .btn variants carry light-mode tokens only, so both are
   restated with the D1 tokens here (which is what makes dark mode work).
   One claret action at a time: "Create my key" until the backup step opens,
   then "Activate account". */
.d1 .join-page .btn.btn-black,
.d1 .join-page .btn.btn-black:hover:not(:disabled) {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}

.d1 .join-page .btn.btn-black:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.d1 .join-page .btn.btn-outline,
.d1 .join-page .btn.btn-outline:hover:not(:disabled) {
  background: transparent;
  color: var(--ink);
}

.d1 .join-page .btn.btn-outline {
  border-color: var(--rule-strong);
}

.d1 .join-page .btn.btn-outline:hover:not(:disabled) {
  border-color: var(--ink);
}

/* Once the backup step is open, "Create my key" yields the claret to
   "Activate account". */
.d1 .join-page:has(.join-step:not([hidden])) [data-identity-form="join"] .btn.btn-black {
  background: transparent;
  color: var(--ink);
  border-color: var(--rule-strong);
}

.d1 .join-page .join-step {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
}

.d1 .join-page .join-step[hidden] {
  display: none;
}

@keyframes join-step-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.d1 .join-page .join-step:not([hidden]) {
  animation: join-step-in 160ms ease-out;
}

.d1 .join-step-title {
  font-family: var(--f-read);
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.4;
}

.d1 .join-fingerprint {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.d1 .join-fingerprint dt,
.d1 .join-details code,
.d1 .join-fingerprint code {
  font-size: 0.875rem;
}

.d1 .join-fingerprint dt {
  color: var(--ink-muted);
}

.d1 .join-details code,
.d1 .join-fingerprint code {
  background: var(--chip-bg);
  padding: 0 4px;
  border-radius: 2px;
  overflow-wrap: anywhere;
}

.d1 .join-fingerprint code:empty {
  display: none;
}

.d1 .join-kit {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.d1 .join-page .join-step > .btn {
  width: 100%;
  max-width: 28rem;
}

.d1 .join-page .join-check > label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-weight: 400;
  cursor: pointer;
}

.d1 .join-page .join-check input {
  flex: none;
  width: 16px;
  height: 16px;
  margin: 4px 0 0;
  padding: 0;
  accent-color: var(--ink);
}

.d1 .join-switch {
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  color: var(--ink-muted);
}

/* The rail */

.d1 .join-facts {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.d1 .join-facts > li {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.875rem;
  line-height: 1.5;
}

.d1 .join-toc ol {
  list-style: none;
  display: flex;
  flex-direction: column;
}

.d1 .join-toc a {
  display: block;
  padding: 8px 0 8px 12px;
  border-left: 2px solid var(--chrome-rule);
  color: var(--rail-link);
  transition: border-color 120ms ease;
}

.d1 .join-toc a:hover,
.d1 .join-toc a:focus-visible {
  border-left-color: var(--marker);
}

/* The explainers: one paper card, three sections. Each section sets its
   heading and summary in a 320px margin column, as the form sets its rail. */

.d1 .join-explain {
  gap: 0;
}

.d1 .join-section {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  padding: 32px 0;
  border-top: 1px solid var(--rule);
  scroll-margin-top: 24px;
}

.d1 .join-section:first-child {
  padding-top: 0;
  border-top: 0;
}

.d1 .join-section:last-child {
  padding-bottom: 0;
}

.d1 .join-section-intro {
  flex: 0 0 320px;
  position: sticky;
  top: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.d1 .join-section:target .join-section-intro .d1-label {
  color: var(--marker);
}

.d1 .join-section-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Steps */

.d1 .join-steps {
  list-style: none;
  counter-reset: join-step;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: var(--measure);
}

.d1 .join-steps > li {
  counter-increment: join-step;
  position: relative;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  column-gap: 16px;
  row-gap: 8px;
  padding: 16px 12px;
  border-radius: 2px;
  transition: background-color 120ms ease;
}

.d1 .join-steps > li:hover {
  background: var(--rail);
}

.d1 .join-steps > li::before {
  content: counter(join-step, decimal-leading-zero);
  position: relative;
  z-index: 1;
  grid-column: 1;
  grid-row: 1;
  font-family: var(--f-mono);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 24px;
  text-align: center;
  color: var(--rail-muted);
  background: var(--rail-chip-bg);
  border-radius: 2px;
}

/* The thread that joins one numeral to the next: 16px of padding above and
   below the neighbours' text, plus the 8px gap. */
.d1 .join-steps > li + li::after {
  content: "";
  position: absolute;
  top: -24px;
  left: 24px;
  width: 1px;
  height: 40px;
  background: var(--rule-strong);
}

.d1 .join-steps > li > p {
  grid-column: 2;
}

.d1 .join-steps h3 {
  grid-row: 1;
  grid-column: 2;
  font-family: var(--f-read);
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.4;
}

.d1 .join-steps p {
  font-size: 0.875rem;
  line-height: 1.6;
}

.d1 .join-wire {
  color: var(--ink-muted);
  padding-left: 12px;
  border-left: 2px solid var(--rule-strong);
}

.d1 .join-wire .d1-label {
  margin-right: 8px;
  color: var(--ink);
}

/* Definition rows: a ledger of term and explanation */

.d1 .join-dl {
  display: flex;
  flex-direction: column;
}

.d1 .join-dl > div {
  display: grid;
  grid-template-columns: 12rem minmax(0, 1fr);
  gap: 16px;
  padding: 12px 0;
  border-top: 1px solid var(--rule);
}

.d1 .join-dl > div:first-child {
  padding-top: 0;
  border-top: 0;
}

.d1 .join-dl > div:last-child {
  padding-bottom: 0;
}

.d1 .join-dl dt {
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.5;
}

.d1 .join-dl dd {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.875rem;
  line-height: 1.6;
}

.d1 .join-facts-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 24px;
}

.d1 .join-facts-strip > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.d1 .join-facts-strip dd {
  font-size: 0.875rem;
  line-height: 1.5;
}

/* Who holds what: three columns of short facts */

.d1 .join-cards {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.d1 .join-cards > li {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0 0;
  border-top: 1px solid var(--rule-strong);
}

.d1 .join-cards ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.d1 .join-cards li li {
  font-size: 0.875rem;
  line-height: 1.5;
}

/* The request sequence for programs: closed until asked for */

.d1 .join-details {
  border-top: 1px solid var(--rule);
  padding-top: 8px;
}

.d1 .join-details summary {
  color: var(--link);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  cursor: pointer;
}

.d1 .join-details ol {
  list-style: decimal;
  padding-left: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.d1 .join-sub {
  margin-top: 16px;
  font-family: var(--f-read);
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.4;
}

.d1 .join-limits {
  list-style: disc;
  padding-left: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.875rem;
  line-height: 1.6;
}

@media (max-width: 960px) {
  .d1 .join-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .d1 .join-section {
    flex-direction: column;
    gap: 16px;
  }

  .d1 .join-rail,
  .d1 .join-section-intro {
    position: static;
  }

  .d1 .join-section-intro {
    flex: none;
  }
}

@media (max-width: 720px) {
  .d1 .join-dl > div,
  .d1 .join-facts-strip,
  .d1 .join-cards {
    grid-template-columns: minmax(0, 1fr);
  }
}
