/* All Things Pharmaceutical: a calm reading layout matching Gab's training sheets.
   Always light (Gab prefers it to a dark theme): pale sage page, white cards, Mist table headers,
   deep-forest bars, Nunito throughout. */

@font-face { font-family: "Nunito"; font-style: normal; font-weight: 400 800; font-display: swap; src: url("fonts/nunito-latin.woff2") format("woff2"); }
@font-face { font-family: "Nunito"; font-style: italic; font-weight: 400 800; font-display: swap; src: url("fonts/nunito-latin-italic.woff2") format("woff2"); }

:root {
  --bg: #edf0ec;
  --paper: #ffffff;
  --tint: #e2e7e3;
  --mist: #bbc0b9;
  --line: #d3dad5;
  --strong-line: #5f7a6b;
  --text: #1c332d;
  --muted: #4b6357;
  --accent: #365545;
  --head: #1c332d;
  --on-head: #f3f5f2;
  --link: #2c5a45;
  --proven: #2f6b4f;
  --plausible: #8a6a1f;
  --theorised: #6b5a8a;
  --caution: #a33a2f;
  --community: #b07a1f;
  --serif: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --sans: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light only;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 72px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1.0625rem/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-underline-offset: 2px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 12px; z-index: 100; background: var(--paper); padding: 8px 12px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 70%, transparent); outline-offset: 2px; }

/* ---------- frame ---------- */

.site-head {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: calc(env(safe-area-inset-top) + 10px) 20px 10px;
  background: var(--head);
  color: var(--on-head);
}
.brand { display: flex; align-items: center; gap: 10px; flex: 1; color: inherit; text-decoration: none; font: 600 1.05rem/1.2 var(--serif); }
.mark { width: 22px; height: 22px; border-radius: 11px; background: linear-gradient(90deg, #bbc0b9 50%, #5f7a6b 50%); transform: rotate(-35deg); flex: none; }
.site-head nav { display: flex; gap: 4px; }
.site-head nav a { color: inherit; text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: 0.9rem; opacity: 0.85; }
.site-head nav a[aria-current="page"], .site-head nav a:hover { background: rgb(255 255 255 / 0.1); opacity: 1; }
.site-head nav a { white-space: nowrap; }
/* Phones: the name gets its own line and the menu sits under it, so nothing runs off the screen. */
@media (max-width: 600px) {
  .site-head { flex-wrap: wrap; gap: 4px 12px; padding-bottom: 6px; }
  .brand { flex-basis: 100%; }
  .site-head nav { width: 100%; margin-left: -10px; }
}

.layout { max-width: 1180px; margin: 0 auto; padding: 24px 20px 48px; }
.layout.has-toc { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 40px; }
main { min-width: 0; }
.site-foot { max-width: 760px; margin: 0 auto; padding: 24px 20px calc(env(safe-area-inset-bottom) + 40px); font-size: 0.85rem; color: var(--muted); border-top: 1px solid var(--line); }

/* ---------- table of contents ---------- */

.toc details { position: sticky; top: 76px; max-height: calc(100vh - 100px); overflow-y: auto; }
.toc summary { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); cursor: pointer; list-style: none; padding: 4px 0 8px; }
.toc summary::-webkit-details-marker { display: none; }
.toc ol { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.toc li a { display: block; padding: 4px 12px; color: var(--muted); text-decoration: none; font-size: 0.88rem; line-height: 1.35; border-left: 2px solid transparent; margin-left: -2px; }
.toc li.l3 a { padding-left: 24px; font-size: 0.82rem; }
.toc li a.active { color: var(--text); border-left-color: var(--accent); font-weight: 600; }
@media (max-width: 900px) {
  .layout.has-toc { display: block; }
  .toc { margin-bottom: 20px; }
  .toc details { position: static; max-height: none; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; }
  .toc summary { padding: 4px 0; }
  .toc details[open] summary { padding-bottom: 8px; }
}

/* ---------- chapter ---------- */

.chapter { max-width: 760px; }
.chapter-head { margin-bottom: 28px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 6px; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
h1, h2, h3, h4 { font-family: var(--serif); line-height: 1.2; color: var(--text); }
h1 { font-size: clamp(2rem, 6vw, 2.8rem); margin: 0 0 8px; letter-spacing: -0.01em; }
h2 { font-size: 1.6rem; margin: 2.4em 0 0.6em; padding-top: 0.4em; border-top: 1px solid var(--line); }
h3 { font-size: 1.22rem; margin: 1.8em 0 0.4em; }
h4 { font-size: 1.02rem; margin: 1.4em 0 0.3em; font-family: var(--sans); }
.aliases { margin: 0; color: var(--muted); font-size: 0.92rem; }
.lede { font: 1.2rem/1.55 var(--serif); margin: 14px 0 0; }
.draft { display: inline-block; margin-top: 12px; padding: 4px 10px; border-radius: 8px; background: color-mix(in srgb, var(--community) 18%, transparent); font-size: 0.85rem; font-weight: 600; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(150px, calc(50% - 5px)), 1fr)); gap: 10px; margin: 20px 0 0; }
.facts div { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.facts dt { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 600; font-size: 0.95rem; overflow-wrap: anywhere; }
p, ul, ol { margin: 0 0 1em; }
li + li { margin-top: 0.3em; }
strong { font-weight: 650; }
code { font-size: 0.9em; background: var(--tint); padding: 1px 5px; border-radius: 5px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }

.structure { float: right; margin: 0 0 16px 24px; padding: 12px; width: 230px; background: #fff; border: 1px solid var(--line); border-radius: 14px; text-align: center; }
.structure img { width: 100%; height: auto; display: block; }
.structure figcaption { font-size: 0.75rem; color: #4b6357; }
.structure figcaption a { color: #2c5a45; }
@media (max-width: 600px) { .structure { float: none; margin: 0 auto 16px; } }

/* Tables follow the training sheets: Mist header with a firm rule under it, hairlines, alternate rows shaded. */
.table-wrap { overflow-x: auto; margin: 0 0 1.4em; border: 1px solid var(--strong-line); border-radius: 12px; background: var(--paper); -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; line-height: 1.45; }
th, td { padding: 9px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
td + td, th + th { border-left: 1px solid var(--line); }
th { background: var(--mist); color: var(--text); font-weight: 700; white-space: nowrap; border-bottom: 2px solid var(--strong-line); }
tbody tr:nth-child(even) td { background: #f6f8f5; }
tr:last-child td { border-bottom: 0; }

/* evidence and mechanism labels */
.tag { display: inline-block; padding: 1px 7px; margin: 0 2px; border-radius: 6px; font: 650 0.72rem/1.5 var(--sans); letter-spacing: 0.02em; vertical-align: 0.1em; white-space: nowrap; border: 1px solid currentColor; }
.tag-proven, .tag-meta, .tag-rct, .tag-guideline, .tag-label, .tag-consistent { color: var(--proven); }
.tag-plausible, .tag-observational, .tag-extrapolated { color: var(--plausible); }
.tag-theorised, .tag-animal, .tag-in-vitro, .tag-case, .tag-anecdotal { color: var(--theorised); }
.tag-draft { color: var(--community); }

/* callouts */
.callout { margin: 0 0 1.4em; padding: 14px 18px 4px; border-radius: 14px; background: var(--paper); border: 1px solid var(--line); border-left: 5px solid var(--accent); }
.callout-title { margin: 0 0 6px; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.callout-caution { border-left-color: var(--caution); }
.callout-caution .callout-title { color: var(--caution); }
.callout-clinical { border-left-color: var(--proven); }
.callout-community { border-left-color: var(--community); background: color-mix(in srgb, var(--community) 7%, var(--paper)); }
.callout-community .callout-title { color: var(--community); }
/* cross-references, floating Contents/Back buttons, and the Contents page */
a.xref { font-weight: 600; text-decoration-style: dotted; text-underline-offset: 3px; }
a.xref::before { content: "§ "; font-weight: 400; opacity: 0.7; }
.floats { position: fixed; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: flex-end; gap: 8px; z-index: 60; }
.float-btn { font: 600 0.85rem/1 var(--sans); padding: 11px 15px; border-radius: 999px; border: 0; background: var(--head); color: var(--on-head); box-shadow: 0 4px 14px rgb(0 0 0 / 0.22); cursor: pointer; max-width: 80vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.float-btn[hidden] { display: none; }
@media (min-width: 901px) { .float-toc { display: none; } }
@media (max-width: 900px) {
  .toc-open .toc { position: fixed; left: 12px; right: 12px; bottom: 76px; max-height: 70vh; overflow-y: auto; z-index: 55; margin: 0; box-shadow: 0 10px 30px rgb(0 0 0 / 0.25); border-radius: 14px; }
}
html { scroll-padding-top: 76px; }
@media (max-width: 600px) { html { scroll-padding-top: 110px; } }
.contents-chapter { margin: 0 0 18px; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; }
.contents-chapter summary { font: 600 1.1rem/1.3 var(--serif); cursor: pointer; }
.contents-chapter ol { list-style: none; margin: 10px 0 0; padding: 0; }
.contents-chapter li a { display: block; padding: 5px 0; text-decoration: none; }
.contents-chapter li.l3 a { padding-left: 18px; font-size: 0.92rem; color: var(--muted); }
.callout-tldr { border: 0; border-left: 0; background: var(--head); color: var(--on-head); padding: 16px 20px 6px; }
.callout-tldr .callout-title { color: var(--on-head); opacity: 0.8; }
.callout-tldr a { color: inherit; }
.callout-tldr li + li { margin-top: 0.35em; }

/* footnotes */
.footnote-ref a, a.footnote-ref { text-decoration: none; font-size: 0.75em; padding: 0 1px; }
.footnotes-sep { margin-top: 3em; }
.footnotes { font-size: 0.85rem; color: var(--muted); }
.footnotes ol { padding-left: 1.4em; }
.footnotes li { overflow-wrap: anywhere; }
.fn-pop { position: fixed; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 12px); z-index: 50; max-width: 640px; margin: 0 auto; padding: 14px 44px 14px 16px; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 10px 30px rgb(0 0 0 / 0.2); font-size: 0.88rem; overflow-wrap: anywhere; }
.fn-pop p { margin: 0; }
.fn-pop button { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; border: 0; border-radius: 16px; background: var(--tint); color: var(--text); cursor: pointer; font-size: 1rem; }

/* ---------- home ---------- */

.hero { max-width: 760px; margin: 12px 0 32px; }
.hero p { font: 1.2rem/1.55 var(--serif); color: var(--muted); }
.search input { width: 100%; min-height: 52px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); color: var(--text); font: inherit; font-size: 16px; }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.group h2 { border: 0; margin-top: 1.2em; font-size: 1.15rem; font-family: var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.card { display: flex; flex-direction: column; gap: 4px; padding: 16px; background: var(--paper); border: 1px solid var(--line); border-radius: 16px; color: var(--text); text-decoration: none; }
.card:hover { border-color: var(--accent); }
.card-title { font: 600 1.15rem/1.25 var(--serif); }
.card-sub { font-size: 0.88rem; color: var(--muted); }
.card .tag { align-self: flex-start; margin: 6px 0 0; }

/* ---------- sign-in ---------- */

.gate { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.gate form { width: 100%; max-width: 380px; padding: 28px 24px; background: var(--paper); border: 1px solid var(--line); border-radius: 18px; }
.gate h1 { font-size: 1.6rem; }
.gate input { width: 100%; min-height: 48px; margin: 8px 0 14px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--text); font-size: 16px; }
.gate button { width: 100%; min-height: 48px; border: 0; border-radius: 999px; background: var(--accent); color: var(--bg); font: 600 1rem var(--sans); cursor: pointer; }
.gate .error { color: var(--caution); font-weight: 600; }
