/* ==========================================================================
   QUIC & HTTP/3 — book.css
   "Packet Scope": dark instrument chrome + light cool-paper reading column.
   Design tokens first; nothing below hardcodes a color outside :root.
   ========================================================================== */

:root {
  /* ---- palette: ink on cool paper ---- */
  --ink:        #11161c;
  --ink-soft:   #2b3742;
  --muted:      #576470;
  --muted-2:    #838d99;
  --paper:      #eef1f4;
  --surface:    #ffffff;

  /* ---- instrument panel (dark chrome) ---- */
  --panel:      #0e141b;
  --panel-2:    #151d26;
  --panel-3:    #1d2833;
  --panel-ink:  #ccd6e0;
  --panel-muted:#7f8b98;
  --panel-line: #263340;

  /* ---- signal: phosphor teal-cyan ---- */
  --signal:      #0b6e7d;   /* accent / links on light  */
  --signal-deep: #084c57;
  --signal-bright:#22c7d6;  /* accent on dark chrome    */
  --signal-wash: #e1f0f2;

  /* ---- semantic instrument LEDs ---- */
  --amber:       #a86b06;   /* caution / "in practice"  */
  --amber-bright:#f2b04a;
  --amber-wash:  #f9f0dd;
  --alert:       #bd3c29;   /* failure modes / errors   */
  --alert-bright:#ef7a67;
  --alert-wash:  #f9e7e4;
  --ok:          #2c7a4b;
  --ok-wash:     #e3f1e9;

  /* ---- rules ---- */
  --line:       #d7dde3;
  --line-soft:  #e6eaee;

  /* ---- type ---- */
  --font-display: "Space Grotesk", "SF Pro Display", "Segoe UI", system-ui, sans-serif;
  --font-body:    "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono:    "IBM Plex Mono", ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;

  /* ---- metrics ---- */
  --measure:    70ch;
  --sidebar-w:  20rem;
  --radius:     6px;
  --radius-lg:  10px;
  --tick:       8px;            /* graticule tick pitch */

  /* ---- spacing scale ---- */
  --s1: .25rem; --s2: .5rem; --s3: .75rem; --s4: 1rem;
  --s5: 1.5rem; --s6: 2rem;  --s7: 3rem;   --s8: 4.5rem;

  --shadow-panel: 0 1px 0 rgba(255,255,255,.02) inset, 0 10px 30px -12px rgba(4,10,16,.55);
  --shadow-card:  0 1px 2px rgba(17,22,28,.04), 0 8px 24px -16px rgba(17,22,28,.22);
}

/* ==========================================================================
   reset / base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.68;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1, "liga" 1;
}
a { color: var(--signal); text-decoration-color: color-mix(in srgb, var(--signal) 40%, transparent);
    text-underline-offset: .18em; }
a:hover { color: var(--signal-deep); text-decoration-color: currentColor; }
:focus-visible { outline: 2.5px solid var(--signal-bright); outline-offset: 2px; border-radius: 3px; }
::selection { background: color-mix(in srgb, var(--signal-bright) 32%, transparent); }
img, svg { max-width: 100%; }
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; line-height: 1.18;
    letter-spacing: -0.012em; color: var(--ink); }

/* small precision motif reused throughout: a horizontal graticule tick ruler */
.graticule {
  height: 6px;
  background-image:
    linear-gradient(90deg, var(--line) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--signal) 55%, transparent) 1px, transparent 1px);
  background-size: var(--tick) 100%, calc(var(--tick) * 4) 100%;
  background-position: 0 bottom, 0 bottom;
  background-repeat: repeat-x;
  opacity: .8;
}

/* ==========================================================================
   app shell — sidebar + reading column
   ========================================================================== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* ---------- sidebar: the instrument panel ---------- */
.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  background: var(--panel);
  color: var(--panel-ink);
  border-right: 1px solid var(--panel-line);
  box-shadow: var(--shadow-panel);
  scrollbar-width: thin;
  scrollbar-color: var(--panel-3) transparent;
}
.sidebar::-webkit-scrollbar { width: 9px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 9px; }

.brand {
  display: block;
  padding: var(--s5) var(--s5) var(--s4);
  border-bottom: 1px solid var(--panel-line);
  color: var(--panel-ink);
  text-decoration: none;
}
.brand__mark {
  font-family: var(--font-mono);
  font-size: .72rem;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--signal-bright);
  display: flex; align-items: center; gap: .5rem;
}
.brand__mark::before {
  content: "";
  width: 26px; height: 10px;
  /* a tiny scope-trace glyph */
  background:
    linear-gradient(90deg, var(--signal-bright) 0 40%, transparent 40% 60%, var(--signal-bright) 60% 100%) bottom/100% 2px no-repeat,
    radial-gradient(circle at 50% 2px, var(--signal-bright) 2px, transparent 2.5px);
  flex: none;
}
.brand__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.16rem;
  letter-spacing: -0.01em;
  margin-top: .5rem;
  color: #eaf1f6;
}
.brand__sub {
  font-family: var(--font-mono);
  font-size: .68rem;
  color: var(--panel-muted);
  margin-top: .15rem;
  letter-spacing: .02em;
}

/* table of contents */
.toc { padding: var(--s4) var(--s3) var(--s7); }
.toc__chapter { margin-bottom: .35rem; }
.toc__chapter-btn {
  width: 100%;
  display: flex; align-items: baseline; gap: .55rem;
  background: none; border: 0; cursor: pointer;
  padding: .5rem .6rem;
  color: var(--panel-ink);
  font-family: var(--font-body);
  font-size: .92rem;
  font-weight: 600;
  text-align: left;
  border-radius: var(--radius);
  line-height: 1.3;
}
.toc__chapter-btn:hover { background: var(--panel-2); }
.toc__num {
  font-family: var(--font-mono);
  font-size: .74rem;
  font-weight: 500;
  color: var(--signal-bright);
  flex: none;
  min-width: 1.4em;
}
.toc__caret { margin-left: auto; color: var(--panel-muted); transition: transform .18s ease; flex: none; }
.toc__chapter[open] .toc__caret { transform: rotate(90deg); }
.toc__sections { list-style: none; margin: .1rem 0 .5rem; padding: 0 0 0 .5rem; }
.toc__link {
  display: flex; gap: .5rem; align-items: baseline;
  padding: .32rem .6rem;
  margin-left: .35rem;
  border-left: 1.5px solid var(--panel-line);
  color: var(--panel-muted);
  text-decoration: none;
  font-size: .855rem;
  line-height: 1.4;
}
.toc__link:hover { color: var(--panel-ink); border-left-color: var(--panel-3); }
.toc__link .toc__num { color: var(--panel-muted); }
.toc__link.is-current {
  color: #eef4f8;
  border-left-color: var(--signal-bright);
  background: linear-gradient(90deg, color-mix(in srgb, var(--signal-bright) 12%, transparent), transparent 80%);
}
.toc__link.is-current .toc__num { color: var(--signal-bright); }

/* details/summary reset for the chapter disclosure */
.toc__chapter summary { list-style: none; }
.toc__chapter summary::-webkit-details-marker { display: none; }

/* ==========================================================================
   main / reading column
   ========================================================================== */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: none; /* shown on mobile */
  position: sticky; top: 0; z-index: 30;
  align-items: center; gap: .75rem;
  padding: .6rem .9rem;
  background: var(--panel);
  color: var(--panel-ink);
  border-bottom: 1px solid var(--panel-line);
}
.topbar__toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: var(--radius);
  background: var(--panel-2); border: 1px solid var(--panel-line);
  color: var(--panel-ink); cursor: pointer;
}
.topbar__title { font-family: var(--font-mono); font-size: .8rem; letter-spacing: .08em; color: var(--signal-bright); text-transform: uppercase; }

.reading {
  width: 100%;
  max-width: calc(var(--measure) + 8rem);
  margin: 0 auto;
  padding: var(--s7) var(--s6) var(--s8);
  flex: 1 0 auto;
}
.prose { max-width: var(--measure); }

/* ---------- section header: instrument readout ---------- */
.section-head { margin-bottom: var(--s6); }
.eyebrow {
  font-family: var(--font-mono);
  font-size: .72rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex; align-items: center; gap: .5rem;
  margin-bottom: var(--s3);
}
.eyebrow__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--signal); flex: none;
  box-shadow: 0 0 0 3px var(--signal-wash); }
.section-title {
  font-size: clamp(1.9rem, 1.3rem + 2.4vw, 2.7rem);
  margin: 0 0 var(--s3);
  max-width: 24ch;
}
.section-num {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--signal);
  font-size: .9em;
  margin-right: .35em;
}
.rfc-row { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: var(--s4); }
.chip {
  font-family: var(--font-mono);
  font-size: .74rem;
  font-weight: 500;
  padding: .18rem .5rem;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  white-space: nowrap;
}
.chip--rfc { border-color: color-mix(in srgb, var(--signal) 35%, var(--line)); color: var(--signal-deep);
  background: var(--signal-wash); }
.chip--lab { border-color: color-mix(in srgb, var(--amber) 40%, var(--line)); color: var(--amber);
  background: var(--amber-wash); }
.section-head .graticule { margin-top: var(--s5); }

/* ---------- prose typography ---------- */
.prose h2 {
  font-size: 1.6rem;
  margin: var(--s8) 0 var(--s4);
  padding-top: var(--s3);
  scroll-margin-top: 1rem;
}
.prose h3 { font-size: 1.22rem; margin: var(--s6) 0 var(--s3); scroll-margin-top: 1rem; }
.prose h4 { font-size: 1.02rem; margin: var(--s5) 0 var(--s2); font-family: var(--font-body); font-weight: 600; }
.prose h2 .header-anchor, .prose h3 .header-anchor {
  opacity: 0; margin-left: .4rem; font-family: var(--font-mono); font-weight: 400;
  color: var(--muted-2); text-decoration: none; font-size: .8em;
}
.prose h2:hover .header-anchor, .prose h3:hover .header-anchor { opacity: 1; }
.prose p { margin: 0 0 var(--s4); }
.prose ul, .prose ol { margin: 0 0 var(--s4); padding-left: 1.3rem; }
.prose li { margin: .3rem 0; }
.prose li::marker { color: var(--muted-2); }
.prose strong { font-weight: 600; color: var(--ink); }
.prose blockquote {
  margin: var(--s5) 0;
  padding: .2rem 0 .2rem var(--s4);
  border-left: 3px solid var(--line);
  color: var(--muted);
  font-style: italic;
}
.prose hr { border: 0; height: 1px; background: var(--line); margin: var(--s7) 0; }

/* term on first mention / glossary link */
.term { border-bottom: 1px dotted var(--muted-2); cursor: help; text-decoration: none; color: inherit; }

/* ---------- tables ---------- */
.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--s5) 0;
  font-size: .92rem;
}
.prose th, .prose td { text-align: left; padding: .5rem .7rem; border-bottom: 1px solid var(--line-soft);
  vertical-align: top; }
.prose thead th {
  font-family: var(--font-mono); font-size: .74rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); border-bottom: 1.5px solid var(--line);
}
.prose tbody tr:hover { background: color-mix(in srgb, var(--signal-wash) 45%, transparent); }
.prose td code, .prose th code { font-size: .86em; }

/* ---------- code ---------- */
code, kbd, samp { font-family: var(--font-mono); }
.prose :not(pre) > code {
  font-size: .86em;
  padding: .1em .38em;
  border-radius: 4px;
  background: color-mix(in srgb, var(--signal-wash) 60%, var(--surface));
  border: 1px solid var(--line-soft);
  color: var(--signal-deep);
  white-space: nowrap;
}
.codeblock {
  margin: var(--s5) 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--panel-line);
  background: var(--panel);
  box-shadow: var(--shadow-card);
}
.codeblock__bar {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .85rem;
  background: var(--panel-2);
  border-bottom: 1px solid var(--panel-line);
  font-family: var(--font-mono);
  font-size: .74rem;
  color: var(--panel-muted);
}
.codeblock__dots { display: inline-flex; gap: 5px; }
.codeblock__dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--panel-3); display: block; }
.codeblock__name { color: var(--panel-ink); }
.codeblock__lang { margin-left: auto; color: var(--signal-bright); letter-spacing: .08em; text-transform: uppercase; }
.codeblock pre {
  margin: 0; padding: var(--s4) var(--s5);
  overflow-x: auto;
  font-size: .84rem;
  line-height: 1.6;
  color: var(--panel-ink);
  scrollbar-width: thin;
}
.codeblock pre code { font-size: inherit; background: none; border: 0; padding: 0; white-space: pre; }

/* ==========================================================================
   prev / next navigation
   ========================================================================== */
.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s4);
  margin-top: var(--s8);
  padding-top: var(--s5);
  border-top: 1px solid var(--line);
}
.pager__link {
  display: flex; flex-direction: column; gap: .2rem;
  padding: var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-decoration: none;
  color: var(--ink);
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.pager__link:hover { border-color: var(--signal); box-shadow: var(--shadow-card); }
.pager__link--next { text-align: right; align-items: flex-end; }
.pager__dir { font-family: var(--font-mono); font-size: .72rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--signal); }
.pager__label { font-weight: 600; font-size: .96rem; line-height: 1.3; }
.pager__link--empty { visibility: hidden; }

/* ==========================================================================
   landing page
   ========================================================================== */
.hero {
  padding: var(--s8) 0 var(--s7);
  border-bottom: 1px solid var(--line);
  margin-bottom: var(--s7);
}
.hero__eyebrow { font-family: var(--font-mono); font-size: .76rem; letter-spacing: .2em; text-transform: uppercase;
  color: var(--signal); margin-bottom: var(--s4); }
.hero__title { font-size: clamp(2.4rem, 1.4rem + 4vw, 4rem); line-height: 1.04; margin: 0 0 var(--s4); }
.hero__lede { font-size: 1.14rem; color: var(--ink-soft); max-width: 60ch; margin: 0 0 var(--s5); }
.hero__meta { display: flex; flex-wrap: wrap; gap: .5rem; }

.contents-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr));
  gap: var(--s4); }
.ch-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: var(--s5);
  text-decoration: none;
  color: var(--ink);
  display: flex; flex-direction: column;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.ch-card:hover { border-color: var(--signal); box-shadow: var(--shadow-card); transform: translateY(-2px); }
.ch-card__num { font-family: var(--font-mono); font-size: .8rem; color: var(--signal); letter-spacing: .05em; }
.ch-card__title { font-family: var(--font-display); font-weight: 700; font-size: 1.14rem; margin: .35rem 0 .6rem;
  line-height: 1.2; }
.ch-card__list { list-style: none; margin: 0; padding: 0; font-size: .84rem; color: var(--muted); }
.ch-card__list li { padding: .1rem 0; display: flex; gap: .45rem; }
.ch-card__list .toc__num { color: var(--muted-2); }

/* ==========================================================================
   responsive: collapse the instrument panel on narrow screens
   ========================================================================== */
@media (max-width: 940px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 50; top: 0; left: 0; bottom: 0; width: min(86vw, var(--sidebar-w));
    transform: translateX(-102%); transition: transform .22s ease;
  }
  .app.nav-open .sidebar { transform: translateX(0); }
  .topbar { display: flex; }
  .scrim {
    position: fixed; inset: 0; z-index: 40; background: rgba(6,11,16,.5);
    opacity: 0; pointer-events: none; transition: opacity .2s ease;
  }
  .app.nav-open .scrim { opacity: 1; pointer-events: auto; }
  .reading { padding: var(--s6) var(--s4) var(--s7); }
}
@media (min-width: 941px) { .scrim { display: none; } }

@media (max-width: 560px) {
  body { font-size: 16px; }
  .pager { grid-template-columns: 1fr; }
}

/* ==========================================================================
   print: clean paper output, drop chrome
   ========================================================================== */
@media print {
  .sidebar, .topbar, .pager, .scrim, .header-anchor { display: none !important; }
  .app { display: block; }
  .reading { max-width: none; padding: 0; }
  body { background: #fff; font-size: 11pt; }
  .codeblock, .ch-card, .callout, .wire { break-inside: avoid; box-shadow: none; }
  a { color: var(--ink); text-decoration: none; }
  .prose h2, .prose h3 { break-after: avoid; }
}
