/* =============================================================================
   Base — paper canvas, editorial typography, layout primitives.
   Mirrors the structural design language of the reference explainer:
   a centered max-width reading column on warm paper, serif body text, a
   monospace "technical label" voice, generous vertical rhythm, hairline rules,
   and a margin for annotations.
   ============================================================================= */

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

/* Visually-hidden but accessible (the real <h1> behind the styled wordmark) */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

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

body {
  margin: 0;
  background-color: var(--background);
  color: var(--text-color);
  font-family: var(--font-body);
  font-size: var(--text-lg);
  line-height: 1.6;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "kern", "liga";
}

/* Paper grain overlay — fixed, behind content, very low opacity. */
body::before {
  content: "";
  position: fixed; inset: 0;
  background-image: url("../assets/img/paper-texture.svg");
  background-size: 280px 280px;
  opacity: .6;
  pointer-events: none;
  z-index: 0;
}
body > * { position: relative; z-index: 1; }

/* ---- Layout container ---------------------------------------------------- */
.page {
  max-width: var(--container-2xl);
  margin-inline: auto;
  padding: clamp(1rem, 3vw, 1.5rem);
  padding-bottom: 5rem;
}

/* Chapter pages get extra left padding so rotated margin labels have room */
.chapter-page {
  padding-left: clamp(2rem, 5vw, 4rem);
  padding-right: clamp(1rem, 3vw, 1.5rem);
}

/* Editorial reading column: prose centered to a comfortable measure, with a
    right-hand margin reserved for annotations on wide screens. */
.prose { max-width: var(--measure); margin-inline: auto; }

/* Three-column article grid: rotated label | content | margin note */
.article {
  --margin-col: 14rem;
  --label-col: 2.5rem;
  display: grid;
  grid-template-columns: var(--label-col) minmax(0, var(--measure)) var(--margin-col);
  justify-content: center;
  column-gap: 2rem;
  margin-top: 3rem;
}
.article > * { grid-column: 2; }
.article .margin-label {
  grid-column: 1;
  grid-row: 1 / span 2;
  align-self: start;
  justify-self: end;
  padding-top: .25rem;
  margin-right: .5rem;
}
.article .margin-note { grid-column: 3; }
@media (max-width: 70rem) {
  .article {
    grid-template-columns: var(--label-col) minmax(0, var(--measure));
  }
  .article .margin-note { grid-column: 2; max-width: var(--measure); }
}
@media (max-width: 48rem) {
  .article {
    grid-template-columns: minmax(0, var(--measure));
  }
  .article .margin-label { display: none; }
  .article .margin-note { grid-column: 1; }
}

/* ---- Headings (serif) ---------------------------------------------------- */
h1, h2, h3, h4 { font-family: var(--font-serif); font-weight: var(--font-weight-normal); line-height: 1.1; letter-spacing: -.01em; }
h1 { font-size: var(--text-6xl); margin: 0 0 .5em; }
h2 { font-size: var(--text-4xl); margin: 2.5em 0 .5em; }
h3 { font-size: var(--text-2xl); margin: 2em 0 .4em; }
h4 { font-size: var(--text-xl); }
em, i { font-style: italic; }
strong, b { font-weight: var(--font-weight-semibold); }

p { margin: 0 0 1.2em; }
a { color: var(--link-color); text-underline-offset: 2px; text-decoration-thickness: 1px; }

/* ---- Monospace "technical voice" ---------------------------------------- */
.mono, .eyebrow, code, kbd, .label {
  font-family: var(--font-mono);
  font-weight: var(--font-weight-medium);
}
.eyebrow {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-faint);
}
code {
  font-size: .9em;
  background: var(--color-stone-200);
  padding: .1em .35em;
  border-radius: var(--radius-xs);
}

/* Inline highlighter mark (a recurring annotation device). */
mark, .mark {
  background: var(--highlight);
  padding: 0 .15em;
  border-radius: 2px;
  color: inherit;
}

/* Hairline rule used between sections. */
hr, .rule {
  border: 0;
  border-top: 1px solid var(--rule-color);
  margin: 3rem 0;
}

/* ---- Nav + footer (mono, understated) ----------------------------------- */
.site-nav, .site-footer {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.site-nav { display: flex; gap: 1.5rem; align-items: center; justify-content: space-between; }
.site-nav a, .site-footer a { color: var(--text-muted); text-decoration: none; }
.site-nav a:hover, .site-footer a:hover { color: var(--text-color); }
.site-footer { margin-top: 6rem; color: var(--text-muted); }

/* ---- Figure / diagram frame --------------------------------------------- */
.figure {
  margin: 2.5rem auto;
  padding: 1.25rem;
  background: var(--color-white);
  border: 1px solid var(--rule-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}
.figure figcaption {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-faint);
  margin-top: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ---- Drop cap (editorial intro, works everywhere) ------------------------ */
.dropcap::first-letter {
  float: left;
  font-family: var(--font-serif);
  font-size: 3.4em;
  line-height: .8;
  padding: .05em .12em 0 0;
  color: var(--text-color);
}

/* ---- Chapter navigation bar ----------------------------------------------- */
.chapter-nav {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin: 1.5rem 0 2rem;
  padding: .75rem 0;
  border-top: 1px dashed var(--rule-color);
  border-bottom: 1px dashed var(--rule-color);
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.chapter-nav a {
  color: var(--text-faint);
  text-decoration: none;
  padding: .15rem .4rem;
}
.chapter-nav a[aria-current="true"] {
  color: var(--accent);
  border-bottom: 1px solid var(--accent);
}
.chapter-nav a:hover { color: var(--accent); }

/* ---- Section break (more breathing room than plain hr) ------------------ */
.section-break {
  border: 0;
  border-top: 1px dashed color-mix(in srgb, var(--color-black) 40%, transparent);
  margin: 4rem 0 3rem;
}

/* ---- Inline figure (simple chapter diagrams) ----------------------------- */
.figure-inline {
  margin: 2.5rem 0;
  padding: 1.5rem;
  background: var(--color-white);
  border: 1px solid var(--rule-color);
  border-radius: var(--radius-md);
}
.figure-inline figcaption {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-faint);
  margin-top: .75rem;
}

/* ---- Live protocol metrics (masthead) --------------------------------- */
.live-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  text-align: right;
}
@media (max-width: 48rem) {
  .live-metrics { grid-template-columns: 1fr; text-align: left; gap: 1rem; }
}
.live-metrics .metric-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .4rem;
}
@media (max-width: 48rem) {
  .live-metrics .metric-label { justify-content: flex-start; }
}
.live-metrics .metric-value {
  font-family: var(--font-serif);
  font-size: var(--text-4xl);
  line-height: 1.1;
  color: var(--text-color);
  margin-top: .2rem;
}
.live-metrics .metric-value.pending { color: var(--text-faint); }
.live-metrics .live-dot {
  display: inline-block;
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: live-pulse 2s ease-in-out infinite;
}
@keyframes live-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .4; transform: scale(.85); }
}

/* ---- Margin note --------------------------------------------------------- */
.margin-note {
  font-size: var(--text-sm);
  line-height: 1.45;
  color: var(--text-muted);
  border-left: 2px solid var(--color-cobalt-300);
  padding-left: .9rem;
  margin: .25rem 0 1.5rem;
}
