/**
 * Reading layout for the founding documents. Rendered by netlify/doc-view.ts.
 *
 * The Observatory is the design language: quiet monospace labels over loud values, one accent used
 * almost entirely as tint, hairlines instead of elevation, a rail of facts beside a field of view.
 * This file extends it to long-form prose and applies the craft fixes in design-direction.md §2.9 —
 * a raised type floor, a real prose scale, focus states on everything, and no backdrop blur.
 *
 * Tokens are copied from public/visual/visual.css rather than shared, because that file is frozen
 * for this slice. test/founding-doc.test.js asserts the values here are identical to the ones there,
 * so the duplication cannot drift; consolidating both into one token file is the follow-up.
 */

:root {
  --obs-bg: #0c131f;
  --obs-bg-mid: #0a1018;
  --obs-panel: rgba(12, 18, 28, 0.82);
  --obs-panel-border: rgba(100, 130, 170, 0.16);
  --obs-text: #d8dee8;
  --obs-muted: #7a8899;
  --obs-accent: #4a9fd4;
  --obs-accent-dim: rgba(74, 159, 212, 0.28);
  --obs-badge: rgba(74, 159, 212, 0.1);
  --obs-badge-text: #8ec4e8;
  --obs-mono: ui-monospace, 'Cascadia Code', 'SF Mono', monospace;

  /* Extensions. Prose ink sits brighter than UI ink so long reading is comfortable (§2.9 item 2). */
  --doc-prose: #e6ebf2;
  --doc-rule: rgba(100, 130, 170, 0.1);
  --doc-error: #c87878;

  /* Six steps, named once (§8.1). No ad-hoc sizes below. */
  --step-0: 0.75rem;
  --step-1: 0.85rem;
  --step-2: 0.95rem;
  --step-3: 1.15rem;
  --step-4: 1.4rem;
  --step-5: 1.9rem;

  --measure: 68ch;
}

* {
  box-sizing: border-box;
}

.doc-body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  background: radial-gradient(ellipse 100% 70% at 50% -10%, #0e1624 0%, var(--obs-bg) 60%);
  background-attachment: fixed;
  color: var(--obs-text);
  min-height: 100vh;
  font-size: var(--step-2);
}

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

a:hover {
  text-decoration: underline;
}

/* The single largest craft gap in the current system: neither stylesheet has a focus rule. */
a:focus-visible,
button:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--obs-accent);
  outline-offset: 2px;
  border-radius: 3px;
}

code {
  font-family: var(--obs-mono);
  font-size: 0.92em;
}

/* --- Header ------------------------------------------------------------------------------- */

.doc-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--obs-panel-border);
}

.doc-header-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.doc-brand {
  font-weight: 600;
  font-size: var(--step-3);
  letter-spacing: 0.01em;
  color: var(--obs-text);
}

.doc-badge {
  font-family: var(--obs-mono);
  font-size: var(--step-0);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 3px;
  background: var(--obs-badge);
  color: var(--obs-badge-text);
  border: 1px solid var(--obs-accent-dim);
}

.doc-badge-error {
  background: rgba(200, 120, 120, 0.1);
  border-color: rgba(200, 120, 120, 0.28);
  color: var(--doc-error);
}

.doc-nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-left: auto;
}

.doc-nav a {
  font-size: var(--step-1);
  font-weight: 500;
  color: var(--obs-muted);
  padding: 8px;
  border-radius: 3px;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.doc-nav a:hover {
  color: var(--obs-text);
  background: rgba(74, 159, 212, 0.06);
  border-color: rgba(74, 159, 212, 0.15);
  text-decoration: none;
}

/* Current item marked by contrast, not by a coloured pill (§6.3). */
.doc-nav a[aria-current='page'] {
  color: var(--obs-text);
  border-color: var(--obs-accent-dim);
}

.doc-subtitle {
  margin: 8px 0 0;
  font-size: var(--step-1);
  color: var(--obs-muted);
  max-width: 58rem;
  line-height: 1.55;
}

/* --- Rail and field ----------------------------------------------------------------------- */

.doc-main {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.doc-main-single {
  grid-template-columns: minmax(0, 1fr);
}

.doc-rail {
  padding: 24px;
  border-right: 1px solid var(--obs-panel-border);
  align-self: start;
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
}

/* Quiet label, loud value: the section marker is the smallest text in the panel (§2.1). */
.doc-rail h2 {
  font-family: var(--obs-mono);
  font-size: var(--step-0);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--obs-muted);
  margin: 24px 0 8px;
  font-weight: 600;
}

.doc-rail h2:first-child {
  margin-top: 0;
}

.doc-disclosure {
  margin-top: 24px;
}

.doc-disclosure > summary {
  cursor: pointer;
  list-style-position: outside;
  margin-bottom: 8px;
}

.doc-disclosure > summary::marker {
  color: var(--obs-accent-dim);
}

.doc-disclosure > summary > h2 {
  display: inline;
}

.doc-disclosure > summary:focus-visible {
  outline: 2px solid var(--obs-accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* The register row: label left, value right, values aligned in a column (§2.2). */
.doc-stats {
  margin: 0;
  font-size: var(--step-1);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 2px 8px;
}

.doc-stats dt {
  color: var(--obs-muted);
}

.doc-stats dd {
  margin: 0;
  font-family: var(--obs-mono);
  font-size: var(--step-0);
  text-align: right;
  color: var(--obs-text);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* The source path is the longest string in the rail; it gets the full width instead of a column. */
.doc-source {
  margin: 0;
  font-family: var(--obs-mono);
  font-size: var(--step-0);
  line-height: 1.5;
  color: var(--obs-text);
  overflow-wrap: anywhere;
}

.doc-source-link {
  margin: 8px 0 0;
  font-size: var(--step-1);
}

.doc-contents,
.doc-siblings {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: var(--step-1);
}

.doc-contents li,
.doc-siblings li {
  line-height: 1.45;
}

.doc-contents a,
.doc-siblings a {
  display: block;
  padding: 8px;
  border-radius: 3px;
  border: 1px solid transparent;
  color: var(--obs-text);
  transition: background 0.12s, border-color 0.12s;
}

.doc-contents a:hover,
.doc-siblings a:hover {
  background: rgba(74, 159, 212, 0.06);
  border-color: rgba(74, 159, 212, 0.15);
  text-decoration: none;
}

.doc-contents-l3 a {
  padding-left: 24px;
  color: var(--obs-muted);
}

.doc-rail-empty,
.doc-rail-note {
  font-size: var(--step-0);
  line-height: 1.6;
  color: var(--obs-muted);
  margin: 8px 0 0;
}

.doc-rail-note {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--doc-rule);
}

/* --- The prose ---------------------------------------------------------------------------- */

.doc-field {
  padding: 32px 24px 64px;
  max-width: calc(var(--measure) + 48px);
  color: var(--doc-prose);
  font-size: 1rem;
  line-height: 1.7;
}

.doc-field > :first-child {
  margin-top: 0;
}

.doc-field h1,
.doc-field h2,
.doc-field h3,
.doc-field h4,
.doc-field h5,
.doc-field h6 {
  line-height: 1.3;
  font-weight: 600;
  color: var(--obs-text);
  scroll-margin-top: 16px;
}

.doc-field h1 {
  font-size: var(--step-5);
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

.doc-field h2 {
  font-size: var(--step-4);
  margin: 48px 0 16px;
}

.doc-field h3 {
  font-size: var(--step-3);
  margin: 32px 0 8px;
}

.doc-field h4,
.doc-field h5,
.doc-field h6 {
  font-size: var(--step-2);
  margin: 24px 0 8px;
  color: var(--obs-muted);
}

/* Citable clauses need a permalink. Always visible, at low contrast: hover-only would make it
 * mouse-only, which §5.5 forbids. */
.doc-anchor {
  font-family: var(--obs-mono);
  font-size: var(--step-0);
  font-weight: 400;
  margin-left: 8px;
  color: var(--obs-accent-dim);
  vertical-align: middle;
}

.doc-anchor:hover,
.doc-anchor:focus-visible {
  color: var(--obs-accent);
  text-decoration: none;
}

.doc-field p {
  margin: 16px 0;
}

/* Links in long prose are underlined, not colour-only (§8.2). */
.doc-field p a,
.doc-field li a,
.doc-field td a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.doc-field strong {
  font-weight: 600;
  color: #f0f4f9;
}

.doc-field ul,
.doc-field ol {
  margin: 16px 0;
  padding-left: 24px;
}

.doc-field li {
  margin: 8px 0;
}

.doc-field li > ul,
.doc-field li > ol {
  margin: 8px 0;
}

.doc-field hr {
  border: 0;
  border-top: 1px solid var(--obs-panel-border);
  margin: 48px 0;
}

.doc-field pre {
  margin: 16px 0;
  padding: 16px;
  overflow-x: auto;
  background: var(--obs-panel);
  border: 1px solid var(--obs-panel-border);
  border-radius: 4px;
  font-size: var(--step-1);
  line-height: 1.5;
}

/* One row height, a hairline rule, no zebra striping (§6.4). */
.doc-table-wrap {
  margin: 24px 0;
  overflow-x: auto;
}

.doc-field table {
  border-collapse: collapse;
  width: 100%;
  font-size: var(--step-1);
  line-height: 1.5;
}

.doc-field th {
  font-family: var(--obs-mono);
  font-size: var(--step-0);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--obs-muted);
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid var(--obs-panel-border);
}

.doc-field td {
  padding: 8px;
  border-bottom: 1px solid var(--doc-rule);
  vertical-align: top;
  font-variant-numeric: tabular-nums;
}

/* --- Small screens ------------------------------------------------------------------------ */

@media (max-width: 768px) {
  .doc-main {
    grid-template-columns: minmax(0, 1fr);
  }

  /* The rail becomes a strip above the field, not a long column of labels pushing it off screen
   * (§6.6). The contents list collapses; the register rows stay. */
  .doc-rail {
    position: static;
    max-height: none;
    padding: 16px;
    border-right: none;
    border-bottom: 1px solid var(--obs-panel-border);
  }

  .doc-contents {
    max-height: 40vh;
    overflow-y: auto;
  }

  .doc-field {
    padding: 24px 16px 48px;
  }

  .doc-field h1 {
    font-size: var(--step-4);
  }

  .doc-field h2 {
    font-size: var(--step-3);
  }

  /* 44px minimum touch target. */
  .doc-nav a,
  .doc-siblings a {
    padding: 12px 8px;
  }
}
