/* ==========================================================================
   protocols.charlessieg.com
   --------------------------------------------------------------------------
   One family with charlessieg.com: the same graphite ground, one brass
   accent, teal reserved for evidence, a serif display over a neutral sans
   body, and mono for every label that reads like an instrument.
   Every color is a token below, and every token is defined for light, for
   dark by preference, and for an explicit dark choice. Contrast targets
   WCAG 2.1 AA: body text 4.5:1 or better on every surface it sits on.
   ========================================================================== */

/* 1. Tokens ---------------------------------------------------------------- */
:root {
  --ground: #eef1f3;
  --surface: #fbfcfd;
  --surface-2: #f5f7f9;
  --band: #e4e8eb;
  --ink: #11161b;
  --ink-2: #4b5661;
  --ink-3: #5d6873;
  --rule: #d2d8dc;
  --rule-2: #b3bcc3;
  --brass: #88601f;
  --brass-hover: #6f4e19;
  --brass-wash: #f2e9d8;
  --on-brass: #ffffff;
  --signal: #2c6b5b;
  --signal-wash: #deebe6;
  --moderate: #7a5a14;
  --moderate-wash: #f4ead2;
  --early: #4b5661;
  --early-wash: #e4e8eb;
  --mixed: #9a3b2e;
  --mixed-wash: #f6e4e0;
  --alert: #8a2f22;
  --alert-wash: #f8e6e2;
  --shadow: 0 1px 2px rgba(17, 22, 27, .05);
  --shadow-lift: 0 2px 10px rgba(17, 22, 27, .07);

  --f-display: "Newsreader", "Hoefler Text", "Iowan Old Style", Palatino, Georgia, serif;
  --f-body: "Google Sans Flex", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --f-data: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --t-xs: .75rem;
  --t-sm: .8125rem;
  --t-md: .9375rem;
  --t-base: 1.0625rem;
  --t-lg: 1.25rem;
  --t-xl: 1.625rem;
  --t-2xl: 2.25rem;
  --t-3xl: 3.25rem;

  --wrap: 1120px;
  --measure: 70ch;
  --gutter: 1.25rem;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #0e1216;
    --surface: #161b21;
    --surface-2: #12171c;
    --band: #1d242b;
    --ink: #e3e8ec;
    --ink-2: #a3afb9;
    --ink-3: #8f9ba5;
    --rule: #28313a;
    --rule-2: #3c4751;
    --brass: #d6a354;
    --brass-hover: #e5b872;
    --brass-wash: #2a2114;
    --on-brass: #14191e;
    --signal: #5cb39a;
    --signal-wash: #14261f;
    --moderate: #d9b25e;
    --moderate-wash: #2a2312;
    --early: #a3afb9;
    --early-wash: #1d242b;
    --mixed: #e08a7a;
    --mixed-wash: #2b1714;
    --alert: #eb9a8b;
    --alert-wash: #2e1814;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lift: 0 2px 12px rgba(0, 0, 0, .5);
  }
}

:root[data-theme="dark"] {
  --ground: #0e1216;
  --surface: #161b21;
  --surface-2: #12171c;
  --band: #1d242b;
  --ink: #e3e8ec;
  --ink-2: #a3afb9;
  --ink-3: #8f9ba5;
  --rule: #28313a;
  --rule-2: #3c4751;
  --brass: #d6a354;
  --brass-hover: #e5b872;
  --brass-wash: #2a2114;
  --on-brass: #14191e;
  --signal: #5cb39a;
  --signal-wash: #14261f;
  --moderate: #d9b25e;
  --moderate-wash: #2a2312;
  --early: #a3afb9;
  --early-wash: #1d242b;
  --mixed: #e08a7a;
  --mixed-wash: #2b1714;
  --alert: #eb9a8b;
  --alert-wash: #2e1814;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lift: 0 2px 12px rgba(0, 0, 0, .5);
}

/* 2. Base ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-padding-top: 5rem; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: var(--t-base);
  line-height: 1.65;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

img, svg { max-width: 100%; height: auto; }

a { color: var(--brass); text-decoration-thickness: 1px; text-underline-offset: .18em; }
a:hover { color: var(--brass-hover); }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 3px; border-radius: 3px; }

h1, h2, h3, h4 { font-family: var(--f-display); font-weight: 400; line-height: 1.15; color: var(--ink); margin: 0; text-wrap: balance; }

p, ul, ol, table, blockquote { margin: 0 0 1.1rem; }

code, kbd, samp { font-family: var(--f-data); font-size: .9em; }

.skip {
  position: absolute; left: -999px; top: .5rem; z-index: 100;
  background: var(--surface); color: var(--ink); padding: .5rem .9rem; border-radius: 6px; box-shadow: var(--shadow-lift);
}
.skip:focus { left: .75rem; }

.wrap { width: 100%; max-width: var(--wrap); margin: 0 auto; padding: 0 var(--gutter); }

.eyebrow {
  font-family: var(--f-data); font-size: var(--t-xs); letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-3); margin: 0 0 .6rem;
}

/* 3. Header ---------------------------------------------------------------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--ground) 92%, transparent);
  backdrop-filter: saturate(1.2) blur(8px);
  border-bottom: 1px solid var(--rule);
}
.site-header__inner { display: flex; align-items: center; gap: 1rem; min-height: 3.75rem; }
.brand {
  display: inline-flex; align-items: baseline; gap: .45rem; text-decoration: none; color: var(--ink);
  font-family: var(--f-display); font-size: 1.3rem; white-space: nowrap;
}
.brand:hover { color: var(--ink); }
.brand__mark { color: var(--brass); font-family: var(--f-data); font-size: .9rem; }
.brand__sub { font-family: var(--f-data); font-size: var(--t-xs); color: var(--ink-3); letter-spacing: .04em; }

.nav { margin-left: auto; }
.nav__list { list-style: none; margin: 0; padding: 0; display: flex; gap: .15rem; flex-wrap: wrap; }
.nav__list a {
  display: block; padding: .45rem .6rem; border-radius: 6px; text-decoration: none;
  color: var(--ink-2); font-size: var(--t-sm); font-weight: 500;
}
.nav__list a:hover { color: var(--ink); background: var(--band); }
.nav__list a[aria-current="page"] { color: var(--ink); background: var(--band); }

.nav-toggle, .theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2.75rem; min-height: 2.75rem; padding: 0 .6rem;
  border: 1px solid var(--rule); border-radius: 8px; background: var(--surface); color: var(--ink);
  font: inherit; font-size: var(--t-sm); cursor: pointer;
}
.nav-toggle:hover, .theme-toggle:hover { border-color: var(--rule-2); }
.nav-toggle { display: none; margin-left: auto; }
.theme-toggle svg { width: 1.1rem; height: 1.1rem; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

@media (max-width: 960px) {
  .nav-toggle { display: inline-flex; }
  .nav { position: absolute; left: 0; right: 0; top: 100%; margin: 0; display: none;
         background: var(--surface); border-bottom: 1px solid var(--rule); box-shadow: var(--shadow-lift); }
  .nav.is-open { display: block; }
  .nav__list { flex-direction: column; padding: .5rem var(--gutter) 1rem; }
  .nav__list a { padding: .75rem .6rem; font-size: var(--t-md); }
  .site-header__inner { position: relative; }
}
@media (max-width: 420px) { .brand__sub { display: none; } }

/* 4. Hero (home) ----------------------------------------------------------- */
.hero { padding: 4rem 0 2.5rem; }
.hero h1 { font-size: clamp(2.4rem, 7vw, var(--t-3xl)); letter-spacing: -.01em; max-width: 18ch; }
.hero__lede { font-size: var(--t-lg); color: var(--ink-2); max-width: 60ch; margin-top: 1.1rem; line-height: 1.55; }
.hero__meta { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; margin-top: 1.4rem;
              font-family: var(--f-data); font-size: var(--t-xs); color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }

/* 5. Cards ------------------------------------------------------------------ */
.section { padding: 1.5rem 0 2.5rem; }
.section__head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 1rem;
                 border-bottom: 1px solid var(--rule); padding-bottom: .6rem; }
.section__head h2 { font-size: var(--t-xl); }
.section__head p { margin: 0; color: var(--ink-3); font-size: var(--t-sm); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 1rem; }
.card {
  position: relative; display: flex; flex-direction: column; gap: .5rem;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 1.2rem 1.25rem 1.1rem; box-shadow: var(--shadow);
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.card:hover { border-color: var(--rule-2); box-shadow: var(--shadow-lift); }
.card h3 { font-size: 1.35rem; }
.card h3 a { color: var(--ink); text-decoration: none; }
.card h3 a::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.card p { margin: 0; color: var(--ink-2); font-size: var(--t-md); line-height: 1.55; }
.card__foot { margin-top: auto; padding-top: .5rem; display: flex; align-items: center; justify-content: space-between; gap: .75rem;
              font-family: var(--f-data); font-size: var(--t-xs); color: var(--ink-3); }
@media (prefers-reduced-motion: no-preference) { .card:hover { transform: translateY(-1px); } }

/* 6. Evidence grades -------------------------------------------------------- */
.grade {
  display: inline-flex; align-items: center; gap: .35rem;
  font-family: var(--f-data); font-size: var(--t-xs); font-weight: 500; letter-spacing: .05em; text-transform: uppercase;
  padding: .12rem .5rem; border-radius: 999px; white-space: nowrap; vertical-align: .1em;
  border: 1px solid currentColor;
}
.grade::before { content: ""; width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; }
.grade--strong { color: var(--signal); background: var(--signal-wash); }
.grade--moderate { color: var(--moderate); background: var(--moderate-wash); }
.grade--early { color: var(--early); background: var(--early-wash); }
.grade--mixed { color: var(--mixed); background: var(--mixed-wash); }

.meter { display: inline-flex; gap: 3px; vertical-align: middle; }
.meter span { width: 1.1rem; height: .4rem; border-radius: 2px; background: var(--rule); }
.meter[data-level="1"] span:nth-child(-n+1),
.meter[data-level="2"] span:nth-child(-n+2),
.meter[data-level="3"] span:nth-child(-n+3),
.meter[data-level="4"] span:nth-child(-n+4) { background: currentColor; }

.legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: .75rem; padding: 0; list-style: none; }
.legend li { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: .9rem 1rem; font-size: var(--t-md); color: var(--ink-2); }
.legend li .grade { margin-bottom: .45rem; }

/* 7. Protocol pages --------------------------------------------------------- */
.page-head { padding: 3rem 0 1.75rem; border-bottom: 1px solid var(--rule); background: var(--surface-2); }
.page-head h1 { font-size: clamp(2.1rem, 6vw, var(--t-3xl)); letter-spacing: -.01em; }
.page-head__dek { font-size: var(--t-lg); color: var(--ink-2); max-width: 62ch; margin: .9rem 0 0; line-height: 1.5; }
.page-head__facts { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1.4rem; margin-top: 1.25rem;
                    font-family: var(--f-data); font-size: var(--t-xs); color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }
.page-head__note { margin: .9rem 0 0; max-width: 70ch; font-size: var(--t-md); color: var(--ink-2); }

/* Block padding only: .layout shares its element with .wrap, whose side padding must survive. */
.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2.5rem; padding-top: 2.25rem; padding-bottom: 3rem; }
@media (min-width: 1000px) { .layout { grid-template-columns: minmax(0, 1fr) 240px; } }

.rail { display: none; }
@media (min-width: 1000px) {
  .rail { display: block; position: sticky; top: 5rem; align-self: start; font-size: var(--t-sm); }
  .rail h2 { font-family: var(--f-data); font-size: var(--t-xs); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); margin-bottom: .6rem; }
  .rail ol { list-style: none; margin: 0; padding: 0 0 0 .8rem; border-left: 1px solid var(--rule); }
  .rail li { margin: 0 0 .45rem; }
  .rail a { color: var(--ink-2); text-decoration: none; }
  .rail a:hover { color: var(--brass); }
}

.prose { max-width: var(--measure); }
.prose h2 { font-size: var(--t-2xl); margin: 2.6rem 0 1rem; padding-top: .4rem; }
.prose h2:first-child { margin-top: 0; }
.prose h3 { font-size: var(--t-xl); margin: 2rem 0 .75rem; }
.prose h4 { font-family: var(--f-body); font-weight: 600; font-size: var(--t-base); margin: 1.5rem 0 .5rem; }
.prose ul, .prose ol { padding-left: 1.3rem; }
.prose li { margin: 0 0 .45rem; }
.prose li::marker { color: var(--ink-3); }
.prose strong { font-weight: 600; }
.prose blockquote { margin: 1.5rem 0; padding: .2rem 0 .2rem 1.1rem; border-left: 3px solid var(--brass); color: var(--ink-2); }
.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }

.prose table { width: 100%; border-collapse: collapse; font-size: var(--t-md); display: block; overflow-x: auto;
               background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); }
.prose th, .prose td { text-align: left; vertical-align: top; padding: .65rem .85rem; border-bottom: 1px solid var(--rule); }
.prose th { font-family: var(--f-data); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 500; background: var(--surface-2); }
.prose tr:last-child td { border-bottom: 0; }

sup.cite { font-family: var(--f-data); font-size: .68em; line-height: 0; margin-left: .1em; white-space: nowrap; }
sup.cite a { text-decoration: none; padding: 0 .08em; }
sup.cite a:hover { text-decoration: underline; }

.callout { margin: 1.5rem 0; padding: 1rem 1.15rem; border-radius: var(--radius); border: 1px solid var(--rule); background: var(--surface); }
.callout--caution { border-color: color-mix(in srgb, var(--alert) 45%, var(--rule)); background: var(--alert-wash); }
.callout--caution strong:first-child { color: var(--alert); }
.callout p:last-child { margin-bottom: 0; }

/* 8. References ------------------------------------------------------------- */
/* The running news list (scripts/build_pages.py, news_page). */
.news-item { padding: 1rem 0 1.1rem; border-bottom: 1px solid var(--rule); }
.prose .news-item h3 { font-size: var(--t-lg); margin: .25rem 0 .4rem; }
.news-item__meta { margin: 0; font-family: var(--f-data); font-size: var(--t-xs); letter-spacing: .04em; color: var(--ink-3); text-transform: uppercase; }
.news-item p { margin: 0 0 .4rem; }
.news-item__related { font-size: var(--t-sm); color: var(--ink-3); }
/* Links to the other pages in a page's section (scripts/build_pages.py, related_block). */
.related { margin: 2.75rem 0 0; padding: 1.1rem 1.25rem 1rem; border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--band); }
.prose .related h2 { font-size: var(--t-md); margin: 0 0 .5rem; padding: 0; }
.related ul { margin: 0; padding-left: 1.1rem; }
.related li { margin: .2rem 0; }
.related p { margin: .7rem 0 0; font-size: var(--t-sm); }
.section__head h2 a { color: inherit; text-decoration: none; }
.section__head h2 a:hover { text-decoration: underline; text-underline-offset: .2em; }
.refs { margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--rule); }
.refs h2 { font-size: var(--t-xl); margin: 0 0 1rem; }
.refs__list { padding-left: 1.6rem; font-size: var(--t-md); }
.refs__list > li { margin: 0 0 1.1rem; padding: .15rem .4rem; border-radius: 6px; scroll-margin-top: 5.5rem; }
.refs__list > li::marker { font-family: var(--f-data); color: var(--ink-3); font-size: var(--t-sm); }
.refs__list > li:target { background: var(--brass-wash); }
.refs__cite { color: var(--ink); }
.refs__cite cite { font-style: normal; font-weight: 600; }
.refs__kind { font-family: var(--f-data); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); margin-left: .3rem; }
.refs__links { display: block; margin-top: .15rem; font-family: var(--f-data); font-size: var(--t-xs); }
.refs__note { margin: .3rem 0 0; color: var(--ink-2); font-size: var(--t-sm); line-height: 1.5; }
.refs__note b { color: var(--ink); font-weight: 600; }

.sources-group { margin-bottom: 2.5rem; }
.sources-group h2 { font-size: var(--t-xl); margin: 0 0 .8rem; }

/* 9. Footer and disclaimer -------------------------------------------------- */
.site-footer { border-top: 1px solid var(--rule); background: var(--surface-2); margin-top: 2rem; padding: 2.25rem 0 2.5rem; font-size: var(--t-sm); color: var(--ink-2); }
.disclaimer {
  border: 1px solid color-mix(in srgb, var(--alert) 40%, var(--rule)); background: var(--alert-wash);
  border-radius: var(--radius); padding: 1rem 1.15rem; margin-bottom: 1.75rem; color: var(--ink);
}
.disclaimer h2 { font-family: var(--f-body); font-size: var(--t-md); font-weight: 700; margin: 0 0 .35rem; color: var(--alert); letter-spacing: .01em; }
.disclaimer p { margin: 0 0 .5rem; font-size: var(--t-sm); line-height: 1.55; }
.disclaimer p:last-child { margin-bottom: 0; }
.footer-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 1.5rem; }
.footer-grid h2 { font-family: var(--f-data); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 500; margin: 0 0 .6rem; }
.footer-grid ul { list-style: none; margin: 0; padding: 0; }
.footer-grid li { margin: 0 0 .4rem; }
.footer-grid a { color: var(--ink-2); }
.footer-grid a:hover { color: var(--brass); }
.footer-fine { margin-top: 1.75rem; padding-top: 1rem; border-top: 1px solid var(--rule); font-size: var(--t-xs); color: var(--ink-3); }
.footer-fine p { margin: 0 0 .4rem; }

/* 10. Small screens --------------------------------------------------------- */
@media (max-width: 640px) {
  :root { --gutter: 1rem; }
  body { font-size: 1rem; }
  .hero { padding: 2.5rem 0 1.75rem; }
  .page-head { padding: 2rem 0 1.25rem; }
  .prose h2 { font-size: var(--t-xl); }
  .prose h3 { font-size: var(--t-lg); }
  .refs__list { padding-left: 1.2rem; }
}

@media print {
  .site-header, .rail, .theme-toggle, .nav-toggle { display: none !important; }
  body { background: #fff; color: #000; }
  a { color: #000; }
}
