/* ============================================================
   Ram Pump Knowledge Base — design system
   Plain CSS, no dependencies, works offline.
   ============================================================ */

/* ---------- Tokens ---------- */
:root {
  --bg: #f4f7f9;
  --surface: #ffffff;
  --surface-2: #eef3f6;
  --surface-3: #e4ecf1;
  --ink: #182430;
  --ink-soft: #33475a;
  --muted: #5c6f80;
  --border: #d9e2e9;
  --border-strong: #c3d0da;

  --accent: #0e7490;
  --accent-strong: #0b5d73;
  --accent-soft: #e0f2f7;
  --accent-ink: #083c4a;

  --ok: #1a7f4e;
  --ok-soft: #e2f4ea;
  --warn: #9a6700;
  --warn-soft: #fdf3d8;
  --danger: #b42334;
  --danger-soft: #fbe9eb;

  --shadow: 0 1px 2px rgba(15, 32, 44, .06), 0 8px 24px rgba(15, 32, 44, .07);
  --shadow-lg: 0 2px 6px rgba(15, 32, 44, .08), 0 16px 40px rgba(15, 32, 44, .12);

  --radius: 12px;
  --radius-sm: 8px;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, "SF Mono", Menlo, monospace;

  --sidebar-w: 272px;
  /* Reading measure for long-form prose (~77 characters) and the width of
     the on-page table-of-contents rail on wide screens. */
  --measure: 34rem;
  --rail-w: 11.5rem;

  /* SVG palette */
  --svg-ground: #d9dfcd;
  --svg-ground-2: #c9d2bd;
  --svg-steel: #aebcc9;
  --svg-steel-2: #8ea3b5;
  --svg-steel-dark: #6f8496;
  --svg-water: #4db3d4;
  --svg-water-deep: #2b8cb0;
  --svg-water-soft: #bfe4f0;
  --svg-pulse: #f0704a;
  --svg-suction: #7f9ff0;
  --svg-label: #54697a;
  --svg-line: #93a7b6;
  --svg-tank: #c9b391;
  --svg-wood: #b99e76;
}

[data-theme="dark"] {
  --bg: #0d141b;
  --surface: #141e28;
  --surface-2: #1a2632;
  --surface-3: #223140;
  --ink: #e8eff5;
  --ink-soft: #c3d2de;
  --muted: #8fa3b3;
  --border: #263544;
  --border-strong: #33475a;

  --accent: #4cc3e4;
  --accent-strong: #7ad4ee;
  --accent-soft: #12333f;
  --accent-ink: #c9edf8;

  --ok: #55c78a;
  --ok-soft: #12301f;
  --warn: #e3b341;
  --warn-soft: #33280e;
  --danger: #f08494;
  --danger-soft: #3a171d;

  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, .5), 0 16px 40px rgba(0, 0, 0, .45);

  --svg-ground: #2a3630;
  --svg-ground-2: #22302a;
  --svg-steel: #4e6377;
  --svg-steel-2: #5d7689;
  --svg-steel-dark: #3c4f61;
  --svg-water: #43aed2;
  --svg-water-deep: #2f8db1;
  --svg-water-soft: #1d4a5c;
  --svg-pulse: #e8815f;
  --svg-suction: #8aa5e8;
  --svg-label: #93a7b6;
  --svg-line: #42566a;
  --svg-tank: #8a744f;
  --svg-wood: #7d6647;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html:focus-within { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
img, svg { max-width: 100%; height: auto; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent); color: #fff; }

/* Anchored headings/sections stop clear of the sticky topbar */
:where([id]) { scroll-margin-top: 5.4rem; }

.skip {
  position: absolute; left: -999px; top: 0; z-index: 200;
  background: var(--accent); color: #fff; padding: .5rem 1rem; border-radius: 0 0 8px 0;
}
.skip:focus { left: 0; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem clamp(1rem, 3vw, 2rem);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; flex: 0 0 auto;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  font-size: 1.05rem; cursor: pointer; transition: background .15s, border-color .15s;
}
.icon-btn:hover { background: var(--surface-2); }
#menuBtn { display: none; }
.brand {
  display: inline-flex; align-items: center; gap: .5rem;
  font-weight: 700; font-size: 1.06rem; letter-spacing: -.01em;
  color: var(--ink); white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand svg { width: 26px; height: 26px; flex: 0 0 auto; }
.brand .kb { color: var(--accent); }

.search { position: relative; flex: 1 1 auto; min-width: 0; max-width: 460px; margin-left: auto; }
.search input {
  width: 100%; padding: .55rem .9rem .55rem 2.2rem;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--ink); font: inherit; font-size: .92rem;
}
.search input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.search::before {
  content: "🔍"; position: absolute; left: .8rem; top: 50%; translate: 0 -50%;
  font-size: .8rem; opacity: .6; pointer-events: none;
}
.search-results {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0; z-index: 150;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); overflow: hidden; max-height: 380px; overflow-y: auto;
}
.search-results a {
  display: block; padding: .6rem .9rem; border-bottom: 1px solid var(--border);
  color: var(--ink);
}
.search-results a:last-child { border-bottom: 0; }
.search-results a:hover, .search-results a.sel { background: var(--accent-soft); text-decoration: none; }
.search-results .sr-t { display: block; font-weight: 600; font-size: .92rem; }
.search-results .sr-d { display: block; font-size: .8rem; color: var(--muted); }
.search-results mark { background: none; color: var(--accent); font-weight: 700; }
.search-results .sr-none { padding: .8rem .9rem; color: var(--muted); font-size: .9rem; }
.search-kbd {
  position: absolute; right: .7rem; top: 50%; translate: 0 -50%;
  font-size: .68rem; color: var(--muted); border: 1px solid var(--border);
  border-radius: 5px; padding: .05rem .35rem; pointer-events: none; background: var(--surface-2);
}

/* ---------- Sidenav ---------- */
.sidenav {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 120;
  width: var(--sidebar-w); padding: 1.1rem .9rem 1.5rem;
  background: var(--surface); border-right: 1px solid var(--border);
  overflow-y: auto; overscroll-behavior: contain;
}
.sidenav .brand { margin: 0 .4rem 1.1rem; font-size: 1.12rem; }
.nav-group { margin-bottom: 1.2rem; }
.nav-group h3 {
  position: relative;
  margin: 0 0 .35rem; padding: 0 .55rem;
  font-size: .7rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted);
}
/* the group that owns the current page gets a quiet accent nod */
.nav-group.current h3 { color: var(--accent-strong); }
.nav-group.current h3::before {
  content: ""; position: absolute; left: 0; top: 50%; translate: 0 -50%;
  width: 4px; height: 4px; border-radius: 50%; background: var(--accent);
}
.nav-group a {
  display: block; padding: .42rem .55rem; border-radius: 8px;
  color: var(--ink-soft); font-size: .92rem; line-height: 1.35;
  border-left: 3px solid transparent;
}
.nav-group a:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.nav-group a.active {
  background: var(--accent-soft); color: var(--accent-strong);
  font-weight: 600; border-left-color: var(--accent);
}
.sidefoot {
  margin-top: 1.6rem; padding: .7rem .55rem; font-size: .74rem; color: var(--muted);
  border-top: 1px dashed var(--border); letter-spacing: .02em;
}
.scrim {
  position: fixed; inset: 0; z-index: 110; background: rgba(9, 18, 26, .5);
  backdrop-filter: blur(2px);
}

/* ---------- Layout ---------- */
.main { margin-left: var(--sidebar-w); min-height: 100dvh; display: flex; flex-direction: column; }
.page {
  position: relative;
  width: min(880px, 100%); margin: 0 auto;
  padding: 2rem clamp(1rem, 4vw, 2.4rem) 3rem; flex: 1;
  container-type: inline-size;
}

/* Long-form prose is held to a comfortable measure while tables, grids,
   figures and the interactive widgets keep the full column width. */
.page > :is(p, ul, ol, dl, blockquote, h2, h3, h4, h5, hr),
.page > :is(.callout, details.faq, .formula, .steps, .timeline, .toc-box, .glossary),
.page-head > .lede { max-width: var(--measure); }

/* ---------- On-page table of contents rail ---------- */
/* The rail lives in the right gutter of the page, so the space the prose
   gives up is put to work instead of leaving a hole. */
.rail-slot { display: none; }
.page.has-rail { width: min(980px, 100%); padding-right: calc(var(--rail-w) + 2rem); }
.page.has-rail > .rail-slot {
  display: block; position: absolute; inset: 0 0 0 auto; width: var(--rail-w);
}
.page.has-rail > .rail-slot > .toc-box {
  position: sticky; top: 5.4rem; margin: 0;
  background: none; border: 0; border-left: 2px solid var(--border);
  border-radius: 0; padding: .1rem 0 .1rem .95rem; font-size: .86rem;
}
.page.has-rail > .rail-slot > .toc-box > h3 { font-size: .72rem; }
.page.has-rail > .rail-slot > .toc-box > ol {
  grid-column: 1 / -1; columns: 1; list-style: none;
  margin: .1rem 0 0; padding-left: 0;
}
.page.has-rail > .rail-slot > .toc-box li { margin-bottom: .34rem; }
.page.has-rail > .rail-slot > .toc-box li > a { display: block; padding: .08rem 0; }

.page-head { margin: 1.2rem 0 2rem; }
.kicker {
  display: inline-flex; align-items: center; gap: .5rem;
  margin: 0 0 .6rem; font-size: .74rem; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase; color: var(--accent);
}
.kicker::before { content: ""; width: 26px; height: 2px; background: var(--accent); border-radius: 2px; }
h1 {
  margin: 0 0 .6rem; font-size: clamp(1.9rem, 4.2vw, 2.7rem);
  line-height: 1.12; letter-spacing: -.025em; font-weight: 800;
}
.lede { margin: 0; font-size: 1.12rem; color: var(--muted); max-width: var(--measure); }

h2 {
  margin: 2.6rem 0 .9rem; font-size: 1.5rem; letter-spacing: -.015em; line-height: 1.25;
  padding-top: .35rem;
}
h2 .anchor, h3 .anchor { opacity: 0; margin-left: .4rem; font-weight: 400; font-size: .85em; transition: opacity .15s; }
h2:hover .anchor, h3:hover .anchor { opacity: .65; }
h3 { margin: 1.9rem 0 .6rem; font-size: 1.14rem; letter-spacing: -.01em; }
h2[id], h3[id] { scroll-margin-top: 4.6rem; }
h4 { margin: 1.4rem 0 .4rem; font-size: .98rem; }

p { margin: 0 0 1rem; }
ul, ol { margin: 0 0 1rem; padding-left: 1.4rem; }
li { margin-bottom: .35rem; }
li > ul, li > ol { margin-top: .35rem; }
strong { color: var(--ink); }
hr { border: 0; border-top: 1px solid var(--border); margin: 2.2rem 0; }

/* ---------- Cards & grids ---------- */
.grid { display: grid; gap: 1rem; margin-bottom: 1.4rem; }
.grid > * { min-width: 0; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
/* Widths resolve against the page column, not the viewport, so cards never
   end up squeezed when the prose measure narrows the column. */
@container (max-width: 780px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@container (max-width: 640px) { .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@container (max-width: 519px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow);
}
.card h3, .card h4 { margin-top: 0; }
.card p:last-child { margin-bottom: 0; }
.card .big {
  font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.1;
  display: block; margin-bottom: .2rem; color: var(--accent-strong);
}
.card .sub { font-size: .84rem; color: var(--muted); }

a.card { display: block; color: inherit; transition: transform .15s, box-shadow .15s, border-color .15s; }
a.card:hover { text-decoration: none; transform: translateY(-2px); border-color: var(--accent); box-shadow: var(--shadow-lg); }
a.card .go { color: var(--accent); font-weight: 600; font-size: .86rem; }

/* ---------- Callouts ---------- */
.callout {
  display: grid; grid-template-columns: auto 1fr; gap: .1rem .8rem;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm); padding: .9rem 1.1rem; margin: 1.2rem 0;
}
.callout .co-icon { font-size: 1.15rem; line-height: 1.5; }
.callout .co-title { font-weight: 700; font-size: .95rem; }
.callout p { margin: 0; font-size: .95rem; color: var(--ink-soft); }
.callout.info { border-left-color: var(--accent); }
.callout.warn { border-left-color: var(--warn); }
.callout.warn .co-icon { color: var(--warn); }
.callout.danger { border-left-color: var(--danger); }
.callout.danger .co-icon { color: var(--danger); }
.callout.ok { border-left-color: var(--ok); }
.callout.ok .co-icon { color: var(--ok); }

/* ---------- Tables ---------- */
.tablewrap { overflow-x: auto; margin: 1.2rem 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .92rem; min-width: 540px; }
caption { caption-side: top; text-align: left; padding: .8rem 1rem .2rem; font-size: .85rem; color: var(--muted); font-style: italic; }
th, td { padding: .6rem .9rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
thead th { background: var(--surface-2); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Figures ---------- */
figure { margin: 1.6rem 0; }
figcaption { font-size: .85rem; color: var(--muted); margin-top: .5rem; text-align: center; }
.figure-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow);
}

/* ---------- YouTube videos (click-to-load facade) ---------- */
figure.video { margin: 1.6rem 0; }
.video-box {
  position: relative; aspect-ratio: 16 / 9; width: 100%;
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; background: var(--surface-2); box-shadow: var(--shadow);
}
.video-box iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-facade { position: relative; display: block; width: 100%; height: 100%; text-decoration: none; }
.video-facade img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block;
  background: var(--surface-2);
}
.video-play {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  display: grid; place-items: center; width: 4.4rem; height: 3.1rem; border-radius: .8rem;
  background: var(--accent); color: #fff; font-size: 1.35rem;
  box-shadow: 0 4px 18px rgb(0 0 0 / .35);
  transition: transform .12s, background .15s;
}
.video-facade:hover .video-play { background: var(--accent-strong); transform: translate(-50%, -50%) scale(1.07); }
.video-facade:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.video-note {
  position: absolute; left: .9rem; right: .9rem; bottom: .75rem;
  color: #fff; font-size: .8rem; font-weight: 600; text-shadow: 0 1px 4px rgb(0 0 0 / .8);
}

/* SVG scene palette */
.scene { display: block; width: 100%; height: auto; }
.s-ground { fill: var(--svg-ground); }
.s-ground2 { fill: var(--svg-ground-2); }
.s-steel { fill: var(--svg-steel); }
.s-steel2 { fill: var(--svg-steel-2); }
.s-steelD { fill: var(--svg-steel-dark); }
.s-water { fill: var(--svg-water); }
.s-waterDeep { fill: var(--svg-water-deep); }
.s-waterSoft { fill: var(--svg-water-soft); }
.s-tank { fill: var(--svg-tank); }
.s-wood { fill: var(--svg-wood); }
.s-line { stroke: var(--svg-line); fill: none; }
.s-lbl { fill: var(--svg-label); font-family: var(--sans); }
.s-lbl-bold { font-weight: 700; fill: var(--ink-soft); font-family: var(--sans); }

/* Inline formulas inside prose — same voice as the .formula blocks below */
.formula-inline { font-family: var(--serif); font-style: italic; white-space: nowrap; }

/* ---------- Formula blocks ---------- */
.formula {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.3rem; margin: 1.2rem 0; box-shadow: var(--shadow);
  overflow-x: auto;
}
.formula .fx {
  font-family: var(--serif); font-style: italic; font-size: 1.25rem;
  display: block; text-align: center; margin: .2rem 0 .5rem; color: var(--ink);
}
.formula .fx sub, .formula .fx sup { font-size: .68em; }
.formula .fnote { font-size: .84rem; color: var(--muted); text-align: center; margin: 0; }
.formula .fnote b { color: var(--ink-soft); }

/* ---------- Badges & buttons ---------- */
.badge {
  display: inline-block; padding: .18rem .6rem; border-radius: 999px;
  font-size: .74rem; font-weight: 700; letter-spacing: .03em; vertical-align: middle;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--accent-soft); color: var(--accent-strong); }

.btn {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .6rem 1.15rem; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer; text-decoration: none;
  transition: transform .12s, background .15s, border-color .15s;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); color: #fff; }
.btn-ghost { background: var(--surface); border-color: var(--border-strong); color: var(--ink); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent-strong); }
.btn-row { display: flex; flex-wrap: wrap; gap: .7rem; margin: 1.4rem 0; }

kbd {
  font-family: var(--mono); font-size: .78em; padding: .12em .45em;
  border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 6px;
  background: var(--surface-2); color: var(--ink-soft);
}

/* ---------- Timeline (history) ---------- */
.timeline { list-style: none; padding: 0; margin: 1.4rem 0; position: relative; }
.timeline::before {
  content: ""; position: absolute; left: 76px; top: 6px; bottom: 6px;
  width: 2px; background: linear-gradient(var(--accent), var(--border));
}
.timeline li { display: grid; grid-template-columns: 64px 24px 1fr; gap: 0 .6rem; margin-bottom: 1.1rem; }
.timeline .tl-year {
  text-align: right; font-weight: 800; color: var(--accent-strong);
  font-variant-numeric: tabular-nums; font-size: .95rem; padding-top: .1rem;
}
.timeline .tl-dot { position: relative; }
.timeline .tl-dot::before {
  content: ""; position: absolute; left: 8px; top: .45rem;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface); box-shadow: 0 0 0 2px var(--accent);
}
.timeline .tl-body { font-size: .95rem; }
.timeline .tl-body b { display: block; }
.timeline .tl-body span { color: var(--muted); }
@media (max-width: 620px) {
  .timeline::before { left: 12px; }
  .timeline li { grid-template-columns: 1fr; padding-left: 30px; position: relative; }
  .timeline .tl-year { text-align: left; }
  .timeline .tl-dot { display: none; }
  .timeline li::before {
    content: ""; position: absolute; left: 7px; top: .4rem;
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--accent); box-shadow: 0 0 0 2px var(--bg);
  }
}

/* ---------- Steps (build) ---------- */
.steps { counter-reset: step; list-style: none; padding: 0; margin: 1.4rem 0; }
.steps > li {
  counter-increment: step; position: relative;
  padding: 0 0 1.4rem 3.4rem; margin: 0;
}
.steps > li::before {
  content: counter(step);
  position: absolute; left: 0; top: -.1rem;
  width: 2.2rem; height: 2.2rem; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 800;
  display: flex; align-items: center; justify-content: center; font-size: 1rem;
}
.steps > li::after {
  content: ""; position: absolute; left: 1.08rem; top: 2.3rem; bottom: .2rem;
  width: 2px; background: var(--border);
}
.steps > li:last-child::after { display: none; }
.steps > li h4 { margin: 0 0 .3rem; font-size: 1rem; }
.steps > li p { margin-bottom: .4rem; color: var(--ink-soft); font-size: .95rem; }
.steps > li p:last-child { margin-bottom: 0; }

/* ---------- FAQ / details ---------- */
details.faq {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: .8rem; box-shadow: var(--shadow); overflow: hidden;
}
details.faq summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: .8rem;
  padding: .95rem 1.15rem; font-weight: 600; font-size: .99rem;
}
details.faq summary::-webkit-details-marker { display: none; }
details.faq summary::before {
  content: "+"; flex: 0 0 auto;
  width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-strong);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; transition: rotate .2s;
}
details.faq[open] summary::before { rotate: 45deg; }
details.faq .faq-body { padding: 0 1.15rem 1.05rem 3.1rem; color: var(--ink-soft); font-size: .95rem; }
details.faq .faq-body p:last-child { margin-bottom: 0; }

/* ---------- Glossary ---------- */
.glossary dt { font-weight: 700; color: var(--accent-strong); margin-top: 1.1rem; }
.glossary dd { margin: .15rem 0 0 0; color: var(--ink-soft); font-size: .96rem; }
.glossary .g-alt { font-size: .8rem; color: var(--muted); font-weight: 400; font-style: italic; }

/* ---------- Cycle animation UI ---------- */
.cycle-wrap { margin: 1.6rem 0; }
.cycle-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.cycle-stage { display: block; width: 100%; height: auto; }
.cycle-controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
  padding: .7rem .9rem; border-top: 1px solid var(--border); background: var(--surface-2);
}
.cycle-controls .spacer { flex: 1; }
.cbtn {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink);
  border-radius: 8px; padding: .35rem .7rem; font: inherit; font-size: .84rem; font-weight: 600;
  cursor: pointer;
}
.cbtn:hover { border-color: var(--accent); color: var(--accent-strong); }
.cbtn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.beat-count { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.phase-tabs { display: flex; gap: .4rem; flex-wrap: wrap; padding: .7rem .9rem 0; }
.phase-tabs button {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  padding: .3rem .75rem; border-radius: 999px; font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer;
}
.phase-tabs button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.cycle-desc {
  padding: .8rem .95rem 1rem; border-top: 1px solid var(--border);
  min-height: 4.6rem;
}
.cycle-desc h4 { margin: 0 0 .25rem; font-size: .95rem; color: var(--accent-strong); }
.cycle-desc p { margin: 0; font-size: .9rem; color: var(--ink-soft); }

/* SVG animation styles (how-it-works) */
.flow-dash { stroke-dasharray: 7 11; animation: dashmove .55s linear infinite; animation-play-state: paused; opacity: 0; transition: opacity .25s; }
.ph-1 .flow-dash.in-flow, .ph-4 .flow-dash.in-flow { animation-play-state: running; opacity: 1; }
.ph-3 .flow-dash.out-flow { animation-play-state: running; opacity: 1; }
@keyframes dashmove { to { stroke-dashoffset: -18; } }

.flap { transition: transform .12s ease-in; transform-box: fill-box; transform-origin: 0 50%; }
.ph-2 .flap, .ph-3 .flap { transform: rotate(0deg); }
.ph-1 .flap, .ph-4 .flap { transform: rotate(78deg); transition: transform .5s cubic-bezier(.34, 1.4, .5, 1); }

.dvalve { transition: transform .22s ease-out, opacity .2s; }
.ph-3 .dvalve { transform: translateY(-9px); }

.jet { opacity: 0; transition: opacity .2s; }
.ph-1 .jet, .ph-4 .jet { opacity: 1; }
.droplet { animation: drip 0.9s linear infinite; animation-play-state: paused; }
.ph-1 .droplet, .ph-4 .droplet { animation-play-state: running; }
@keyframes drip {
  0% { transform: translate(0, 0); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translate(34px, 44px); opacity: 0; }
}

.vessel-water { transform-box: fill-box; transform-origin: 50% 100%; transition: transform .5s ease; }
.ph-3 .vessel-water { transform: scaleY(1.22); }
.bubble { transform-box: fill-box; transform-origin: 50% 100%; transition: transform .5s ease; }
.ph-3 .bubble { transform: scale(.5); }

.pulse { opacity: 0; }
.pulse-hi { transition: transform .4s ease-out, opacity .18s ease-in; }
.ph-2 .pulse-hi { opacity: .95; transform: translateX(-333px); }
.pulse-lo { transition: transform .55s ease-in-out, opacity .22s; }
.ph-4 .pulse-lo { opacity: .9; transform: translateX(343px); }
.ph-4 .pulse-lo.suck { opacity: .9; }

.slam-ring { opacity: 0; transform-box: fill-box; transform-origin: center; }
.ph-2 .slam-ring { animation: slamring .5s ease-out 1; }
@keyframes slamring {
  0% { opacity: .95; transform: scale(.4); }
  100% { opacity: 0; transform: scale(2.1); }
}

.tk-water { transition: y 1s ease, height 1s ease; }

/* ---------- Anatomy explorer ---------- */
.anatomy-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 1.2rem; align-items: start; margin: 1.6rem 0; }
@media (max-width: 860px) { .anatomy-grid { grid-template-columns: 1fr; } }
.hotspot { cursor: pointer; }
.hotspot circle.hc { fill: var(--accent); stroke: var(--surface); stroke-width: 2; transition: fill .15s; }
.hotspot text { fill: #fff; font-weight: 800; font-size: 11px; font-family: var(--sans); pointer-events: none; }
.hotspot:hover circle.hc, .hotspot.on circle.hc { fill: var(--accent-strong); }
.hotspot.on circle.hc { stroke: var(--accent); stroke-width: 3; }
.part-panel { position: sticky; top: 5rem; }
.part-panel h4 { margin: 0 0 .3rem; font-size: 1.02rem; color: var(--accent-strong); }
.part-panel .part-tag { font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.part-list { list-style: none; padding: 0; margin: 1rem 0 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.part-list button {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-soft);
  border-radius: 999px; padding: .25rem .65rem; font: inherit; font-size: .78rem; font-weight: 600; cursor: pointer;
}
.part-list button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Calculator ---------- */
.calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; align-items: start; margin: 1.6rem 0; }
@media (max-width: 860px) { .calc-grid { grid-template-columns: 1fr; } }
.field { margin-bottom: .9rem; }
.field label { display: block; font-size: .84rem; font-weight: 600; color: var(--ink-soft); margin-bottom: .25rem; }
.field .hint { font-size: .76rem; color: var(--muted); font-weight: 400; }
.field-row { display: flex; gap: .5rem; }
.field input[type="number"], .field select {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--ink); font: inherit; font-size: .95rem;
}
.field input[type="number"]:focus, .field select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.range-val { font-size: .85rem; color: var(--accent-strong); font-weight: 700; }
.calc-out { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.out-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .7rem .85rem;
}
.out-card .ov { font-size: 1.35rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.out-card .ov small { font-size: .72rem; font-weight: 600; color: var(--muted); margin-left: .2rem; }
.out-card .ol { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; font-weight: 700; }
.out-card.wide { grid-column: 1 / -1; }
.warn-list { list-style: none; padding: 0; margin: .9rem 0 0; }
.warn-list li {
  padding: .55rem .8rem; border-radius: 8px; font-size: .86rem; margin-bottom: .45rem;
  display: flex; gap: .55rem; align-items: flex-start;
}
.warn-list li::before { content: "▸"; font-weight: 800; }
.warn-list li.ok { background: var(--ok-soft); color: var(--ok); }
.warn-list li.warn { background: var(--warn-soft); color: var(--warn); }
.warn-list li.bad { background: var(--danger-soft); color: var(--danger); }
.warn-list li.info { background: var(--accent-soft); color: var(--accent-strong); }

/* Site-survey checklist (design-tools) — tappable on screen, tickable in print */
.survey { list-style: none; padding-left: 0; margin: 0; }
.survey li { display: flex; gap: .55rem; align-items: flex-start; margin-bottom: .45rem; }
.survey input { flex: 0 0 auto; margin-top: .32rem; accent-color: var(--accent); }
.survey label { cursor: pointer; }
.example-row { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .8rem; }

/* ---------- Interactive trace ---------- */
.trace { cursor: crosshair; touch-action: pan-y; }
.trace:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 6px; }
.trace-readout {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: .55rem .8rem; font-size: .86rem; color: var(--ink-soft);
  font-variant-numeric: tabular-nums; min-height: 2.4em;
}
.trace-readout b { color: var(--accent-strong); }

/* ---------- Cheat sheet ---------- */
.sheet-toolbar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin: 1.1rem 0; }
.sheet-toolbar .hint { font-size: .85rem; color: var(--muted); }
.sheet {
  --sh-ink: #1b2a36; --sh-mut: #5a6d7c; --sh-line: #cfdbe3;
  --sh-acc: #0e7490; --sh-accsoft: #e7f4f8; --sh-warn: #8a5a00; --sh-warnsoft: #fdf3d8;
  color-scheme: light;
  background: #fff; color: var(--sh-ink);
  width: 100%; max-width: 210mm; margin: 0 auto;
  padding: 8mm 9mm 6mm;
  border: 1px solid #d5e0e7; border-radius: 6px; box-shadow: var(--shadow);
  font-size: 10px; line-height: 1.45;
}
.sh-head { display: flex; justify-content: space-between; align-items: center; gap: 4mm; border-bottom: 2.5px solid var(--sh-acc); padding-bottom: 2.5mm; margin-bottom: 3mm; }
.sh-brand { font-size: 15px; font-weight: 800; letter-spacing: .05em; color: var(--sh-acc); }
.sh-sub { font-size: 8.5px; color: var(--sh-mut); margin-top: .5mm; }
.sh-master { text-align: right; background: var(--sh-accsoft); border: 1px solid var(--sh-line); border-radius: 4px; padding: 1.5mm 3mm; flex: 0 0 auto; }
.sh-eq { display: block; font-family: var(--serif); font-style: italic; font-size: 13.5px; font-weight: 700; }
.sh-master .sh-note { font-size: 7.8px; color: var(--sh-mut); }
.sh-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 4mm; }
.sh-sec { min-width: 0; }
.sh-sec + .sh-sec { border-left: 1px solid var(--sh-line); padding-left: 4mm; }
.sh-ttl { font-size: 8.4px; font-weight: 800; text-transform: uppercase; letter-spacing: .09em; color: var(--sh-acc); border-bottom: 1.5px solid var(--sh-accsoft); padding-bottom: 1mm; margin: 2.4mm 0 1.4mm; }
.sh-sec .sh-ttl:first-child { margin-top: 0; }
.sh-fx { display: flex; justify-content: space-between; align-items: baseline; gap: 2mm; flex-wrap: wrap; padding: .6mm 0; border-bottom: 1px dotted var(--sh-line); }
.sh-fx b { font-weight: 600; font-size: 8.8px; }
.sh-fx i { font-family: var(--serif); font-size: 10.4px; white-space: nowrap; }
.sh-note { font-size: 7.8px; color: var(--sh-mut); margin: .8mm 0 0; }
.sh-list { list-style: none; margin: 0; padding: 0; }
.sh-list li { position: relative; padding: .5mm 0 .5mm 3mm; border-bottom: 1px dotted var(--sh-line); font-size: 8.9px; }
.sh-list li::before { content: "▸"; position: absolute; left: 0; color: var(--sh-acc); font-weight: 700; }
.sh-list li b { font-weight: 700; }
.sh-tbl { width: 100%; min-width: 0; border-collapse: collapse; font-size: 8.6px; margin-top: .6mm; }
.sh-tbl td, .sh-tbl th { border: 1px solid var(--sh-line); padding: .6mm 1.6mm; text-align: left; }
.sh-tbl th { background: var(--sh-accsoft); font-weight: 700; }
.sh-tbl .sym { font-family: var(--serif); font-style: italic; font-weight: 700; color: var(--sh-acc); width: 6mm; text-align: center; }
.sh-tbl.sh-num td, .sh-tbl.sh-num th { text-align: center; }
.sh-never { margin-top: 2mm; background: var(--sh-warnsoft); border: 1px solid #e5cf97; border-radius: 3px; padding: 1.6mm 2mm; font-size: 8.7px; color: var(--sh-warn); }
.sh-never b { font-weight: 800; }
.sh-foot { display: flex; justify-content: space-between; gap: 3mm; margin-top: 3mm; border-top: 1.5px solid var(--sh-line); padding-top: 1.5mm; font-size: 7.8px; color: var(--sh-mut); }
@media screen and (max-width: 700px) {
  .sh-grid { grid-template-columns: 1fr; }
  .sh-sec + .sh-sec { border-left: 0; padding-left: 0; border-top: 1px solid var(--sh-line); margin-top: 3mm; padding-top: 2mm; }
  .sh-head { flex-direction: column; align-items: flex-start; }
  .sh-master { text-align: left; }
}

/* ---------- Pager & footer ---------- */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 3rem 0 1rem; }
.pager a {
  display: block; padding: .9rem 1.1rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}
.pager a:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-2px); }
.pager a.next { text-align: right; }
.pager .pg-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 700; }
.pager .pg-title { font-weight: 700; color: var(--accent-strong); }
@media (max-width: 620px) { .pager { grid-template-columns: 1fr; } .pager a.prev { display: none; } }

.site-footer {
  border-top: 1px solid var(--border); margin-top: 2rem;
  padding: 1.6rem clamp(1rem, 4vw, 2.4rem) 2.2rem;
  font-size: .84rem; color: var(--muted);
}
.site-footer .foot-inner { width: min(880px, 100%); margin: 0 auto; }
.site-footer p { margin-bottom: .4rem; }
.fineprint { font-size: .76rem; }

/* Footer sitemap — static HTML generated from NAV by sync-pages.js. The column
   count follows the number of nav groups, so adding a group needs no CSS edit. */
.foot-nav {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: 1rem 1.2rem;
  margin: 0 0 1.5rem; padding-bottom: 1.2rem; border-bottom: 1px solid var(--border);
}
.foot-col h4 {
  margin: 0 0 .45rem; font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .12em; color: var(--muted);
}
.foot-col a { display: block; padding: .16rem 0; font-size: .86rem; color: var(--ink-soft); line-height: 1.4; }
.foot-col a:hover { color: var(--accent-strong); }
.foot-col a.active { color: var(--accent-strong); font-weight: 600; }
.foot-tag { grid-column: 1 / -1; margin: 0; font-size: .74rem; letter-spacing: .02em; }
@media (max-width: 760px) { .foot-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 350px) { .foot-nav { grid-template-columns: 1fr; } }

/* ---------- Hero (home) ---------- */
.hero {
  display: grid; grid-template-columns: 1.25fr .9fr; gap: 2rem; align-items: center;
  background: linear-gradient(135deg, var(--accent-soft), var(--surface) 55%);
  border: 1px solid var(--border); border-radius: 18px; padding: clamp(1.4rem, 4vw, 2.6rem);
  margin: 1.2rem 0 2.2rem; box-shadow: var(--shadow);
}
@media (max-width: 820px) { .hero { grid-template-columns: 1fr; } }
.hero h1 { margin-bottom: .7rem; }
.hero .lede { margin-bottom: 1.2rem; }
.hero-art { filter: drop-shadow(0 10px 24px rgba(14, 116, 144, .18)); }

/* ---------- TOC box ---------- */
.toc-box {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.3rem; margin: 1.4rem 0; font-size: .92rem;
  display: grid; grid-template-columns: 1fr auto; align-items: center;
}
.toc-box > h3 {
  grid-column: 1; grid-row: 1; margin: 0;
  font-size: .8rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted);
}
.toc-toggle {
  grid-column: 2; grid-row: 1; display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; padding: 0; margin-left: .6rem;
  border: 1px solid var(--border-strong); border-radius: 7px;
  background: var(--surface); color: var(--ink-soft); font: inherit; cursor: pointer;
}
.toc-toggle:hover { border-color: var(--accent); color: var(--accent-strong); }
.toc-toggle .chev { display: block; line-height: 1; transition: rotate .18s ease; }
.toc-box.collapsed .toc-toggle .chev { rotate: -90deg; }
.toc-box > ol { grid-column: 1 / -1; grid-row: 2; columns: 2; column-gap: 2rem; margin: .7rem 0 0; }
.toc-box.collapsed > ol { display: none; }
@container (max-width: 519px) { .toc-box > ol { columns: 1; } }
.toc-box li { break-inside: avoid; }
.toc-box a.active { color: var(--accent-strong); font-weight: 700; }

/* ---------- Back to top ---------- */
.to-top {
  position: fixed; right: 1.2rem; bottom: 1.2rem; z-index: 90;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--accent); color: #fff; border: 0; cursor: pointer;
  font-size: 1.05rem; box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  transform: translateY(6px);
}
.to-top.show { opacity: 1; pointer-events: auto; transform: none; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  /* visibility, not only a transform: a closed drawer must not stay reachable
     by keyboard or screen reader. The delayed visibility transition keeps the
     slide-out animation while removing it from the tab order. */
  .sidenav {
    transform: translateX(-100%); visibility: hidden;
    transition: transform .22s ease, visibility .22s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidenav.open { transform: none; visibility: visible; }
  .main { margin-left: 0; }
  #menuBtn { display: inline-flex; }
  .search { max-width: none; }
  .search-kbd { display: none; }
}

/* ---------- Reading progress ---------- */
.read-progress {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 130;
  transform: scaleX(0); transform-origin: 0 50%; pointer-events: none;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  transition: transform .08s linear;
}

/* ---------- Sidenav close (mobile) ---------- */
.sidenav-close {
  display: none; position: absolute; top: .7rem; right: .7rem;
  width: 34px; height: 34px; padding: 0; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface-2); color: var(--ink-soft);
  font: inherit; font-size: .92rem; line-height: 1; cursor: pointer;
}
.sidenav-close:hover { background: var(--surface-3); color: var(--ink); }
@media (max-width: 960px) { .sidenav-close { display: inline-flex; } }

/* ---------- Small-screen topbar fit ---------- */
@media (max-width: 620px) {
  .topbar { gap: .5rem; padding: .5rem .7rem; }
  .topbar .brand { font-size: .98rem; }
  .topbar .brand svg { width: 22px; height: 22px; }
  .icon-btn { width: 36px; height: 36px; }
  .search input { padding: .5rem .8rem .5rem 1.85rem; font-size: .88rem; }
  :where([id]) { scroll-margin-top: 4.4rem; }
}
/* On very narrow screens the wordmark yields its space to search; the
   sidenav still carries the brand. */
@media (max-width: 480px) { .topbar .brand { display: none; } }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .flow-dash, .droplet { animation: none !important; }
}

@page { size: A4; margin: 9mm; }

/* ---------- Print ---------- */
@media print {
  .topbar, .sidenav, .to-top, .pager, .cycle-controls, .phase-tabs, .search, .scrim, .site-footer, .read-progress, .rail-slot, .print-hide { display: none !important; }
  .main { margin: 0; }
  .page.has-rail { width: auto !important; padding-right: 0 !important; }
  body { background: #fff; color: #000; }
  .card, .callout, .figure-box, .formula, details.faq { box-shadow: none; }
  figure.video { display: none !important; }
  details.faq { break-inside: avoid; }
  details.faq:not([open]) .faq-body { display: block; }
  .cheat-main { padding: 0; width: auto; }
  .cheat-main .page-head { display: none; }
  .sheet { border: 0 !important; box-shadow: none !important; border-radius: 0 !important; width: auto !important; max-width: none !important; padding: 0 !important; margin: 0 !important; }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}
