/* =================================================================
   Water Utility SCADA & EPA Compliance — design system
   Light, professional, water-inspired palette.
   ================================================================= */

:root {
  /* Palette */
  --teal-900: #134e4a;
  --teal-700: #0e7490;
  --teal-600: #0891b2;
  --cyan-400: #22d3ee;
  --cyan-100: #cffafe;
  --green-600: #059669;
  --amber-600: #d97706;

  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #5b6b7f;
  --line: #e2e8f0;
  --line-soft: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --bg: #f6fafb;

  --brand: var(--teal-700);
  --brand-2: var(--teal-600);
  --accent: var(--teal-700);

  /* Code */
  --code-bg: #f8fafc;
  --code-border: #e2e8f0;
  --code-inline-bg: rgba(8, 145, 178, 0.1);
  --code-inline-fg: #0b6680;

  /* Type */
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", "Cascadia Code", Menlo, Consolas, monospace;

  /* Metrics */
  --container: 1280px;
  --container-wide: 1560px;
  --header-h: 4.25rem;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 6px 20px -8px rgba(15, 23, 42, 0.18);
  --shadow-lg: 0 22px 50px -22px rgba(13, 89, 110, 0.45);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.65;
  font-size: clamp(1rem, 0.96rem + 0.2vw, 1.075rem);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; max-width: 100%; }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--teal-900); }
h1, h2, h3, h4 { line-height: 1.2; font-weight: 700; color: var(--ink); }
:focus-visible { outline: 3px solid var(--cyan-400); outline-offset: 2px; border-radius: 4px; }

.icon { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor; flex: none; }

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: clamp(1rem, 4vw, 2.75rem);
}

.skip-link {
  position: absolute; left: 0.5rem; top: -3rem;
  background: var(--brand); color: #fff; padding: 0.6rem 1rem;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm); z-index: 200;
  transition: top 0.2s var(--ease);
}
.skip-link:focus { top: 0; color: #fff; }

.site-main { flex: 1 0 auto; }

/* =================================================================
   Header
   ================================================================= */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; min-height: var(--header-h);
}
.brand { display: inline-flex; align-items: center; gap: 0.7rem; color: var(--ink); }
.brand-logo { width: 40px; height: 40px; transition: transform 0.3s var(--ease); }
.brand:hover .brand-logo { transform: rotate(-6deg) scale(1.06); }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-weight: 800; font-size: 1.12rem; letter-spacing: -0.01em; }
.brand-dot { color: var(--brand-2); }
.brand-tag { font-size: 0.7rem; color: var(--muted); font-weight: 500; letter-spacing: 0.01em; }

.primary-nav .nav-list {
  list-style: none; padding: 0; display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap;
}
.nav-link {
  display: inline-flex; align-items: center; gap: 0.45rem;
  padding: 0.5rem 0.8rem; border-radius: 999px; color: var(--ink-soft);
  font-weight: 600; font-size: 0.92rem; position: relative;
  transition: background 0.2s var(--ease), color 0.2s var(--ease), transform 0.2s var(--ease);
}
.nav-link .icon { width: 1.1rem; height: 1.1rem; color: var(--brand-2); }
.nav-link:hover { background: var(--surface-3); color: var(--teal-900); transform: translateY(-1px); }
.nav-link.is-active { background: var(--cyan-100); color: var(--teal-900); }
.nav-link.is-active .icon { color: var(--teal-700); }

.nav-toggle {
  display: none; align-items: center; justify-content: center;
  width: 2.6rem; height: 2.6rem; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); cursor: pointer;
}
.nav-toggle .icon { width: 1.4rem; height: 1.4rem; }
.nav-toggle .icon-shut { display: none; }
.nav-toggle[aria-expanded="true"] .icon-open { display: none; }
.nav-toggle[aria-expanded="true"] .icon-shut { display: block; }

@media (max-width: 860px) {
  .nav-toggle { display: inline-flex; }
  .primary-nav {
    position: absolute; left: 0; right: 0; top: 100%;
    background: var(--surface); border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow-md);
    max-height: 0; overflow: hidden; transition: max-height 0.3s var(--ease);
  }
  .primary-nav.open { max-height: 70vh; overflow: auto; }
  .primary-nav .nav-list { flex-direction: column; align-items: stretch; padding: 0.75rem clamp(1rem, 4vw, 2.75rem); gap: 0.2rem; }
  .nav-link { width: 100%; }
}

/* =================================================================
   Hero
   ================================================================= */
.hero {
  background:
    radial-gradient(1200px 500px at 15% -10%, rgba(34, 211, 238, 0.18), transparent 60%),
    radial-gradient(1000px 460px at 95% 0%, rgba(5, 150, 105, 0.12), transparent 55%),
    linear-gradient(180deg, #ffffff, var(--surface-2));
  border-bottom: 1px solid var(--line);
}
.hero-inner { padding-block: clamp(2.5rem, 5vw, 4.5rem); text-align: center; }
.hero-logo img { width: clamp(96px, 12vw, 132px); height: auto; margin-inline: auto; filter: drop-shadow(var(--shadow-lg)); }
.hero-title {
  margin-top: 1.4rem; font-size: clamp(1.9rem, 1.2rem + 3vw, 3.4rem);
  font-weight: 800; letter-spacing: -0.02em; max-width: 20ch; margin-inline: auto;
}
.grad { background: linear-gradient(90deg, var(--teal-600), var(--cyan-400)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.grad-2 { background: linear-gradient(90deg, var(--green-600), var(--teal-600)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero-copy { max-width: 70ch; margin: 1.5rem auto 0; color: var(--ink-soft); display: grid; gap: 0.85rem; }

.hero-cta {
  margin-top: 2.25rem; display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); max-width: 880px; margin-inline: auto;
}
.cta {
  display: flex; align-items: center; gap: 0.9rem; text-align: left;
  padding: 1rem 1.15rem; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); color: var(--ink);
  transition: transform 0.22s var(--ease), box-shadow 0.22s var(--ease), border-color 0.22s var(--ease);
}
.cta:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); color: var(--ink); }
.cta-icon {
  display: grid; place-items: center; width: 3rem; height: 3rem; flex: none; border-radius: 12px;
  color: #fff; background: linear-gradient(140deg, color-mix(in srgb, var(--accent) 80%, #22d3ee), var(--accent));
  box-shadow: 0 8px 18px -8px var(--accent);
}
.cta-icon .icon { width: 1.55rem; height: 1.55rem; }
.cta-text { display: flex; flex-direction: column; }
.cta-label { font-weight: 700; }
.cta-go { display: inline-flex; align-items: center; gap: 0.3rem; color: var(--accent); font-size: 0.85rem; font-weight: 600; }
.cta:hover .cta-go .icon { transform: translateX(3px); }
.cta-go .icon { width: 1rem; height: 1rem; transition: transform 0.2s var(--ease); }

/* =================================================================
   Sections / pillar cards (home)
   ================================================================= */
.section { padding-block: clamp(2.5rem, 5vw, 4rem); }
.section-title { font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.1rem); letter-spacing: -0.01em; }
.section-lead { color: var(--muted); max-width: 72ch; margin-top: 0.6rem; }

.pillar-grid {
  margin-top: 2rem; display: grid; gap: 1.4rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
}
.pillar-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.5rem; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
  display: flex; flex-direction: column;
  transition: transform 0.22s var(--ease), box-shadow 0.22s var(--ease);
}
.pillar-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: linear-gradient(90deg, var(--accent), var(--cyan-400)); }
.pillar-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-lg); }
.pillar-head { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 0.7rem; }
.pillar-icon { display: grid; place-items: center; width: 2.8rem; height: 2.8rem; flex: none; border-radius: 11px; color: #fff; background: linear-gradient(140deg, color-mix(in srgb, var(--accent) 78%, #22d3ee), var(--accent)); }
.pillar-icon .icon { width: 1.45rem; height: 1.45rem; }
.pillar-title { font-size: 1.2rem; }
.pillar-title a { color: var(--ink); }
.pillar-title a:hover { color: var(--accent); }
.pillar-desc { color: var(--ink-soft); font-size: 0.96rem; }
.pillar-links { list-style: none; padding: 0; margin: 1rem 0; display: grid; gap: 0.1rem; }
.pillar-links a { display: flex; align-items: center; gap: 0.4rem; padding: 0.4rem 0.5rem; border-radius: 8px; color: var(--ink-soft); font-weight: 500; font-size: 0.93rem; transition: background 0.18s var(--ease), color 0.18s var(--ease); }
.pillar-links a:hover { background: var(--surface-3); color: var(--accent); }
.pillar-links .icon { width: 1rem; height: 1rem; color: var(--accent); }
.pillar-more { margin-top: auto; display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 700; color: var(--accent); }
.pillar-more .icon { transition: transform 0.2s var(--ease); }
.pillar-more:hover .icon { transform: translateX(4px); }

/* =================================================================
   Breadcrumbs
   ================================================================= */
.breadcrumbs { background: var(--surface-2); border-bottom: 1px solid var(--line); }
.breadcrumbs ol { list-style: none; display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; padding-block: 0.8rem; font-size: 0.86rem; }
.crumb { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--muted); }
.crumb a { color: var(--muted); font-weight: 500; }
.crumb a:hover { color: var(--brand); }
.crumb [aria-current="page"] { color: var(--ink); font-weight: 600; }
.crumb-sep { width: 0.85rem; height: 0.85rem; color: var(--line); stroke-width: 2.5; }

/* =================================================================
   Content page layout (sidebar + article)
   ================================================================= */
.page-grid { max-width: var(--container-wide); padding-block: clamp(1.6rem, 3vw, 2.75rem); display: grid; gap: clamp(1.5rem, 3vw, 3rem); }

.section-nav { display: none; }
@media (min-width: 1024px) {
  .page-grid { grid-template-columns: 290px minmax(0, 1fr); align-items: start; }
  .section-nav {
    display: block; position: sticky; top: calc(var(--header-h) + 1rem);
    max-height: calc(100vh - var(--header-h) - 2rem); overflow: auto;
    padding: 1.25rem; background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow-sm);
  }
}
.section-nav-title { font-weight: 800; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 0.6rem; }
.section-nav-title a { color: var(--teal-900); }
.section-list { list-style: none; padding-left: 0; margin: 0; display: grid; gap: 0.1rem; }
.section-list .section-list { padding-left: 0.85rem; margin-top: 0.1rem; border-left: 2px solid var(--line-soft); }
.section-list a { display: block; padding: 0.4rem 0.55rem; border-radius: 8px; color: var(--ink-soft); font-size: 0.9rem; font-weight: 500; transition: background 0.18s var(--ease), color 0.18s var(--ease); }
.section-list a:hover { background: var(--surface-3); color: var(--brand); }
.section-list li.is-current > a { background: var(--cyan-100); color: var(--teal-900); font-weight: 700; }

/* =================================================================
   Prose (rendered markdown)
   ================================================================= */
.prose { min-width: 0; }
.prose > h1:first-child,
.prose > h1 {
  font-size: clamp(1.7rem, 1.2rem + 2vw, 2.6rem); letter-spacing: -0.02em;
  background: linear-gradient(100deg, var(--teal-700), var(--teal-600) 45%, var(--cyan-400));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  padding-bottom: 0.2rem; margin-bottom: 1.2rem;
}
.prose h2 { font-size: clamp(1.35rem, 1.05rem + 1vw, 1.75rem); margin-top: 2.4rem; margin-bottom: 0.85rem; color: var(--teal-900); position: relative; padding-left: 0.9rem; }
.prose h2::before { content: ""; position: absolute; left: 0; top: 0.18em; bottom: 0.18em; width: 5px; border-radius: 4px; background: linear-gradient(var(--teal-600), var(--cyan-400)); }
.prose h3 { font-size: 1.25rem; margin-top: 1.9rem; margin-bottom: 0.6rem; color: var(--teal-700); }
.prose h4 { font-size: 1.08rem; margin-top: 1.5rem; margin-bottom: 0.5rem; color: var(--ink); }
.prose h2, .prose h3, .prose h4 { scroll-margin-top: calc(var(--header-h) + 1rem); }

.prose p { margin-block: 0.9rem; color: var(--ink-soft); }
.prose strong { color: var(--ink); font-weight: 700; }
.prose ul, .prose ol { margin-block: 0.9rem; padding-left: 1.4rem; color: var(--ink-soft); }
.prose li { margin-block: 0.35rem; }
.prose li::marker { color: var(--brand-2); }

/* Heading anchor links (markdown-it-anchor headerLink) */
.prose :is(h2, h3, h4) > a { color: inherit; text-decoration: none; }
.prose :is(h2, h3, h4) > a:hover { text-decoration: none; }
.prose :is(h2, h3, h4) > a::after {
  content: "#"; margin-left: 0.4rem; color: var(--cyan-400); font-weight: 600;
  opacity: 0; transition: opacity 0.18s var(--ease);
}
.prose :is(h2, h3, h4):hover > a::after { opacity: 1; }

/* Body links */
.prose a:not(:where(h1,h2,h3,h4) a) {
  color: var(--brand); font-weight: 600;
  background: linear-gradient(var(--cyan-400), var(--cyan-400)) no-repeat left bottom / 0% 2px;
  transition: background-size 0.25s var(--ease), color 0.2s var(--ease);
  padding-bottom: 1px;
}
.prose a:not(:where(h1,h2,h3,h4) a):hover { color: var(--teal-900); background-size: 100% 2px; }

.prose blockquote {
  margin: 1.3rem 0; padding: 0.7rem 1.2rem; border-left: 4px solid var(--teal-600);
  background: var(--surface-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--ink-soft);
}
.prose hr { border: none; border-top: 1px solid var(--line); margin-block: 2rem; }

/* ---------- Inline code ---------- */
.prose :not(pre) > code {
  font-family: var(--font-mono); font-size: 0.86em;
  background: var(--code-inline-bg); color: var(--code-inline-fg);
  padding: 0.12em 0.4em; border-radius: 6px; border: none; white-space: break-spaces;
}

/* ---------- Code blocks ---------- */
.prose pre {
  position: relative; margin: 1.4rem 0; padding: 1.05rem 1.15rem;
  background: var(--code-bg); border: 1px solid var(--code-border); border-radius: var(--radius);
  overflow: auto; box-shadow: var(--shadow-sm); -webkit-overflow-scrolling: touch;
  font-size: 0.875rem; line-height: 1.6; tab-size: 4;
}
.prose pre code { font-family: var(--font-mono); background: none; color: var(--ink); padding: 0; border: 0; font-size: inherit; }
.prose pre::-webkit-scrollbar { height: 10px; }
.prose pre::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 999px; }

/* Copy button (injected by JS) */
.code-wrap { position: relative; }
.copy-btn {
  position: absolute; top: 0.55rem; right: 0.55rem; z-index: 2;
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.32rem 0.6rem; font-size: 0.75rem; font-weight: 600;
  color: var(--ink-soft); background: rgba(255, 255, 255, 0.9); border: 1px solid var(--line);
  border-radius: 8px; cursor: pointer; opacity: 0; transition: opacity 0.18s var(--ease), color 0.18s var(--ease), border-color 0.18s var(--ease); backdrop-filter: blur(4px);
}
.code-wrap:hover .copy-btn, .copy-btn:focus-visible { opacity: 1; }
.copy-btn:hover { color: var(--teal-700); border-color: var(--teal-600); }
.copy-btn .icon { width: 0.95rem; height: 0.95rem; }
.copy-btn.copied { color: var(--green-600); border-color: var(--green-600); opacity: 1; }

/* Prism light tokens (matched to palette) */
.token.comment, .token.prolog, .token.doctype, .token.cdata { color: #64748b; font-style: italic; }
.token.punctuation { color: #475569; }
.token.namespace { opacity: 0.7; }
.token.property, .token.tag, .token.constant, .token.symbol, .token.deleted { color: #b91c1c; }
.token.boolean, .token.number { color: #b45309; }
.token.selector, .token.attr-name, .token.string, .token.char, .token.builtin, .token.inserted { color: #047857; }
.token.operator, .token.entity, .token.url, .language-css .token.string, .style .token.string { color: #0e7490; }
.token.atrule, .token.attr-value, .token.keyword { color: #0e7490; font-weight: 600; }
.token.function, .token.class-name { color: #2563eb; }
.token.regex, .token.important, .token.variable { color: #c026d3; }
.token.important, .token.bold { font-weight: 700; }
.token.italic { font-style: italic; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 1.4rem 0; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); -webkit-overflow-scrolling: touch; }
.prose table { border-collapse: collapse; width: 100%; min-width: 480px; font-size: 0.92rem; }
.prose thead th { background: var(--surface-3); color: var(--teal-900); text-align: left; font-weight: 700; }
.prose th, .prose td { padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--line); }
.prose tbody tr:nth-child(even) { background: var(--surface-2); }
.prose tbody tr:hover { background: var(--cyan-100); }

/* ---------- Task lists (checkboxes) ---------- */
.prose ul.contains-task-list { list-style: none; padding-left: 0.2rem; }
.prose li.task-list-item { list-style: none; display: flex; align-items: flex-start; gap: 0.6rem; padding: 0.15rem 0; }
.prose li.task-list-item::marker { content: ""; }
.prose li.task-list-item input.task-list-item-checkbox,
.prose li.task-list-item input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; margin: 0.28em 0 0; width: 1.15rem; height: 1.15rem; flex: none;
  border: 2px solid var(--teal-600); border-radius: 6px; background: var(--surface); cursor: pointer;
  display: grid; place-content: center; transition: background 0.18s var(--ease), border-color 0.18s var(--ease);
}
.prose li.task-list-item input[type="checkbox"]::before {
  content: ""; width: 0.62rem; height: 0.62rem; transform: scale(0); transform-origin: center;
  clip-path: polygon(14% 44%, 0 65%, 40% 100%, 100% 16%, 84% 0, 38% 70%); background: #fff; transition: transform 0.15s var(--ease);
}
.prose li.task-list-item input[type="checkbox"]:checked { background: var(--green-600); border-color: var(--green-600); }
.prose li.task-list-item input[type="checkbox"]:checked::before { transform: scale(1); }
.prose li.task-list-item input[type="checkbox"]:checked ~ * ,
.prose li.task-list-item.is-checked > label,
.prose li.task-list-item.is-checked { text-decoration: line-through; text-decoration-color: var(--muted); color: var(--muted); }
.prose li.task-list-item label { cursor: pointer; }

/* ---------- FAQ / accordions ---------- */
.prose details {
  border: 1px solid var(--line); border-radius: var(--radius); margin: 0.9rem 0;
  background: var(--surface); box-shadow: var(--shadow-sm); overflow: hidden;
}
.prose details + details { margin-top: 0.6rem; }
.prose summary {
  cursor: pointer; padding: 0.95rem 1.15rem; font-weight: 700; color: var(--teal-900);
  list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.prose summary::-webkit-details-marker { display: none; }
.prose summary::after { content: ""; width: 0.7rem; height: 0.7rem; border-right: 2.5px solid var(--teal-600); border-bottom: 2.5px solid var(--teal-600); transform: rotate(45deg); transition: transform 0.2s var(--ease); flex: none; }
.prose details[open] summary::after { transform: rotate(-135deg); }
.prose details[open] summary { border-bottom: 1px solid var(--line); }
.prose details > :not(summary) { padding-inline: 1.15rem; }
.prose details > :not(summary):last-child { padding-bottom: 1rem; }

/* ---------- Mermaid diagrams ---------- */
.mermaid { text-align: center; }
.mermaid:not([data-processed]) { color: var(--muted); font-family: var(--font-mono); font-size: 0.85rem; white-space: pre; overflow-x: auto; }
.mermaid svg { max-width: 100%; height: auto; }

/* Diagram figure (wraps a rendered mermaid diagram) */
figure.diagram {
  position: relative; margin: 1.6rem 0; padding: 1.25rem 1.25rem 0.75rem;
  background:
    radial-gradient(120% 120% at 0% 0%, rgba(34, 211, 238, 0.06), transparent 55%),
    var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  overflow: hidden; transition: box-shadow 0.22s var(--ease), border-color 0.22s var(--ease);
}
figure.diagram.is-ready { cursor: zoom-in; }
figure.diagram.is-ready:hover { box-shadow: var(--shadow-md); border-color: color-mix(in srgb, var(--teal-600) 40%, var(--line)); }
figure.diagram .mermaid { margin: 0; }
.diagram-caption {
  display: block; margin-top: 0.85rem; padding-top: 0.6rem; border-top: 1px dashed var(--line);
  font-size: 0.85rem; color: var(--muted); text-align: center; font-style: italic;
}
.diagram-expand {
  position: absolute; top: 0.6rem; right: 0.6rem; z-index: 2;
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.32rem 0.6rem; font-size: 0.74rem; font-weight: 600; font-style: normal;
  color: var(--ink-soft); background: rgba(255, 255, 255, 0.9); border: 1px solid var(--line);
  border-radius: 8px; cursor: pointer; opacity: 0; backdrop-filter: blur(4px);
  transition: opacity 0.18s var(--ease), color 0.18s var(--ease), border-color 0.18s var(--ease);
}
figure.diagram:hover .diagram-expand,
.diagram-expand:focus-visible { opacity: 1; }
.diagram-expand:hover { color: var(--teal-700); border-color: var(--teal-600); }
.diagram-expand .icon { width: 0.95rem; height: 0.95rem; }

/* Full-screen diagram modal */
.diagram-modal {
  position: fixed; inset: 0; z-index: 1000; display: none;
  align-items: center; justify-content: center; padding: clamp(0.75rem, 3vw, 2.5rem);
  background: rgba(8, 47, 58, 0.72); backdrop-filter: blur(6px);
  opacity: 0; transition: opacity 0.2s var(--ease);
}
.diagram-modal.open { display: flex; opacity: 1; }
.diagram-modal-inner {
  position: relative; width: min(96vw, 1500px); max-height: 92vh; overflow: auto;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: clamp(1.25rem, 3vw, 2.5rem); -webkit-overflow-scrolling: touch;
}
.diagram-modal-inner svg { width: 100%; height: auto; max-width: none; display: block; }
.diagram-modal-caption { margin-top: 1rem; text-align: center; color: var(--muted); font-size: 0.92rem; }
.diagram-modal-close {
  position: sticky; top: 0; float: right; margin: -0.5rem -0.5rem 0 0; z-index: 3;
  display: inline-flex; align-items: center; justify-content: center; width: 2.5rem; height: 2.5rem;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink);
  cursor: pointer; box-shadow: var(--shadow-sm); transition: background 0.18s var(--ease), color 0.18s var(--ease), transform 0.18s var(--ease);
}
.diagram-modal-close:hover { background: var(--teal-700); color: #fff; transform: rotate(90deg); }
.diagram-modal-close .icon { width: 1.3rem; height: 1.3rem; }

/* ---------- KaTeX ---------- */
.katex-display { overflow-x: auto; overflow-y: hidden; padding-block: 0.4rem; }

/* ---------- Related pages ---------- */
.related { margin-top: 3rem; padding-top: 1.6rem; border-top: 1px solid var(--line); }
.related h2 { font-size: 1.2rem; color: var(--teal-900); margin-bottom: 0.9rem; padding-left: 0; }
.related h2::before { display: none; }
.related-list { list-style: none; padding: 0; display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.related-list a {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.9rem 1rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  color: var(--ink); transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), border-color 0.2s var(--ease);
}
.related-list a:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--teal-600); color: var(--ink); }
.related-title { font-weight: 700; display: block; }
.related-desc { display: block; font-size: 0.82rem; color: var(--muted); font-weight: 400; line-height: 1.4; }
.related-list .icon { margin-left: auto; color: var(--teal-600); flex: none; }

/* =================================================================
   Footer
   ================================================================= */
.site-footer { flex-shrink: 0; margin-top: auto; background: var(--teal-900); color: #cbe7ee; }
.footer-inner { display: grid; gap: 2rem; padding-block: clamp(2.25rem, 4vw, 3.25rem); grid-template-columns: 1fr; }
@media (min-width: 760px) { .footer-inner { grid-template-columns: 1.2fr 2fr; } }
.footer-brand .brand { color: #fff; }
.footer-brand .brand-name { color: #fff; }
.footer-brand .brand-dot { color: var(--cyan-400); }
.footer-blurb { margin-top: 0.8rem; font-size: 0.9rem; color: #a9d4de; max-width: 42ch; }
.footer-nav { display: grid; gap: 1.5rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.footer-heading { font-size: 0.92rem; margin-bottom: 0.6rem; }
.footer-heading a { color: #fff; }
.footer-heading a:hover { color: var(--cyan-400); }
.footer-nav ul { list-style: none; padding: 0; display: grid; gap: 0.35rem; }
.footer-nav li a { color: #a9d4de; font-size: 0.86rem; transition: color 0.18s var(--ease), padding-left 0.18s var(--ease); }
.footer-nav li a:hover { color: #fff; padding-left: 3px; }
.footer-bar { border-top: 1px solid rgba(255, 255, 255, 0.12); }
.footer-bar .container { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; justify-content: space-between; padding-block: 1rem; font-size: 0.82rem; color: #8fc1cd; }
.footer-bar a { color: #cbe7ee; }
.footer-bar a:hover { color: #fff; }

/* =================================================================
   Misc
   ================================================================= */
.error-page { text-align: center; padding-block: clamp(3rem, 8vw, 6rem); }
.error-page h1 { font-size: clamp(3rem, 10vw, 6rem); background: linear-gradient(100deg, var(--teal-700), var(--cyan-400)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.btn {
  display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.7rem 1.3rem; border-radius: 999px;
  background: linear-gradient(135deg, var(--teal-600), var(--teal-700)); color: #fff; font-weight: 700;
  box-shadow: var(--shadow-md); transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.btn:hover { color: #fff; transform: translateY(-2px); box-shadow: var(--shadow-lg); }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
