/* =========================================================================
   PostgreSQL Logical Replication & CDC — site styles
   Light, elegant, professional. Wide on desktop, refined on mobile.
   ========================================================================= */

:root {
  /* Palette — calm teal/blue primary with warm + green accents */
  --c-bg: #f6f9fb;
  --c-surface: #ffffff;
  --c-surface-alt: #eef4f7;
  --c-ink: #16323d;
  --c-ink-soft: #46606c;
  --c-muted: #6d8693;
  --c-border: #d9e4ea;
  --c-border-strong: #bcd0da;

  --c-primary: #0b6e8f;
  --c-primary-dark: #085470;
  --c-primary-soft: #e3f1f6;
  --c-accent: #b7791f;
  --c-accent-soft: #fbf2dd;
  --c-green: #2f855a;
  --c-green-soft: #e4f3ea;

  --c-code-bg: #f4f8fa;
  --c-code-border: #dde8ee;
  --c-inline-bg: #eaf2f6;
  --c-inline-ink: #0a5a76;

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

  /* Metrics */
  --header-h: 64px;
  --maxw: 1280px;
  --maxw-prose: 78ch;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(16, 50, 61, 0.06), 0 1px 3px rgba(16, 50, 61, 0.05);
  --shadow-md: 0 6px 20px rgba(16, 50, 61, 0.08);
  --shadow-lg: 0 18px 48px rgba(16, 50, 61, 0.14);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- Reset / base -------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--c-bg);
  color: var(--c-ink);
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

a {
  color: var(--c-primary);
  text-decoration: none;
  transition: color 0.18s var(--ease);
}

h1, h2, h3, h4, h5, h6 {
  line-height: 1.25;
  color: var(--c-ink);
  font-weight: 700;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--c-primary);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus {
  left: 0;
}

:target {
  scroll-margin-top: calc(var(--header-h) + 16px);
}

/* ---- Header -------------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--c-border);
}
.site-header__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 clamp(1rem, 3vw, 2rem);
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 1rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--c-ink);
  font-weight: 700;
  margin-right: auto;
}
.brand .emblem {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.25s var(--ease);
}
.brand:hover .emblem {
  transform: rotate(-4deg) scale(1.05);
}
.brand__text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.brand__name {
  font-size: 1.02rem;
  letter-spacing: -0.01em;
}
.brand__tag {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--c-muted);
}

.primary-nav {
  display: flex;
  gap: 0.4rem;
}
.primary-nav__link {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  color: var(--c-ink-soft);
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 0.18s var(--ease), color 0.18s var(--ease);
}
.primary-nav__link .nav-icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
}
.primary-nav__link:hover {
  background: var(--c-primary-soft);
  color: var(--c-primary-dark);
}
.primary-nav__link.is-active {
  background: var(--c-primary);
  color: #fff;
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 42px;
  height: 42px;
  padding: 0 9px;
  border: 1px solid var(--c-border);
  border-radius: 10px;
  background: var(--c-surface);
  cursor: pointer;
}
.nav-toggle__bar {
  height: 2px;
  background: var(--c-ink);
  border-radius: 2px;
  transition: transform 0.22s var(--ease), opacity 0.22s var(--ease);
}
.nav-toggle[aria-expanded="true"] .nav-toggle__bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.nav-toggle[aria-expanded="true"] .nav-toggle__bar:nth-child(2) {
  opacity: 0;
}
.nav-toggle[aria-expanded="true"] .nav-toggle__bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ---- Main / footer scaffolding ------------------------------------------ */
.site-main {
  flex: 1 0 auto;
  width: 100%;
}

.site-footer {
  flex-shrink: 0;
  margin-top: 4rem;
  background: linear-gradient(180deg, #0c5e7b, #0a4a62);
  color: #d7eaf1;
}
.site-footer a {
  color: #cfe7f0;
}
.site-footer a:hover {
  color: #fff;
}
.site-footer__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 3rem clamp(1rem, 3vw, 2rem);
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 2.5rem;
}
.footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  color: #fff;
}
.footer-brand .emblem {
  width: 34px;
  height: 34px;
  border-radius: 9px;
}
.site-footer__desc {
  margin: 0.9rem 0 0;
  max-width: 52ch;
  color: #bcd9e3;
  font-size: 0.95rem;
}
.site-footer__heading {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8fc3d4;
  margin: 0 0 0.8rem;
}
.site-footer__nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}
.site-footer__bar {
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  text-align: center;
  font-size: 0.85rem;
  color: #9fc6d3;
  padding: 1rem;
}
.site-footer__bar p {
  margin: 0;
}

/* ---- Breadcrumbs --------------------------------------------------------- */
.breadcrumbs ol {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin: 0 0 1.4rem;
  padding: 0;
  font-size: 0.86rem;
  color: var(--c-muted);
}
.breadcrumbs li + li::before {
  content: "›";
  margin-right: 0.35rem;
  color: var(--c-border-strong);
}
.breadcrumbs a {
  color: var(--c-ink-soft);
  font-weight: 600;
}
.breadcrumbs a:hover {
  color: var(--c-primary);
}
.breadcrumbs [aria-current="page"] {
  color: var(--c-primary-dark);
  font-weight: 600;
}

/* ---- Article layout ------------------------------------------------------ */
.article {
  width: 100%;
}
.article__shell {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 2.4rem clamp(1rem, 3vw, 2.5rem) 1rem;
}
.article__header {
  margin-bottom: 1.6rem;
  padding-bottom: 1.4rem;
  border-bottom: 1px solid var(--c-border);
}
.article__title {
  font-size: clamp(1.9rem, 1.2rem + 2.6vw, 3rem);
  letter-spacing: -0.02em;
  margin: 0;
  background: linear-gradient(120deg, var(--c-primary-dark), var(--c-primary) 45%, var(--c-green));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.article__lede {
  margin: 0.9rem 0 0;
  font-size: 1.15rem;
  color: var(--c-ink-soft);
  max-width: 70ch;
}

/* Wide reading column: text uses the full width of its container (not a thin
   strip), with a sticky table-of-contents filling the horizontal space on
   large screens. Stays comfortable & elegant on mobile. */
.article__layout {
  display: block;
}
/* Text fills the full width of its container (never a thin centred column). */
.prose,
.prose > * {
  max-width: 100%;
}

/* Two-column reading layout only when there's a table of contents to show. */
@media (min-width: 1080px) {
  .article__layout--with-toc {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 16rem;
    gap: clamp(2rem, 4vw, 4rem);
    align-items: start;
  }
}

/* ---- On-page table of contents ------------------------------------------ */
.toc {
  display: none;
}
@media (min-width: 1080px) {
  .toc {
    display: block;
    position: sticky;
    top: calc(var(--header-h) + 1.5rem);
    max-height: calc(100vh - var(--header-h) - 3rem);
    overflow-y: auto;
    padding: 1.1rem 1.2rem;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    font-size: 0.9rem;
  }
}
.toc__title {
  margin: 0 0 0.7rem;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-muted);
}
.toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.15rem;
}
.toc__item a {
  display: block;
  padding: 0.3rem 0.5rem;
  border-radius: 7px;
  color: var(--c-ink-soft);
  font-weight: 600;
  border-left: 2px solid transparent;
  transition: background 0.15s var(--ease), color 0.15s var(--ease),
    border-color 0.15s var(--ease);
}
.toc__item a:hover {
  background: var(--c-primary-soft);
  color: var(--c-primary-dark);
  border-left-color: var(--c-primary);
}
.toc__item--l3 a {
  padding-left: 1.2rem;
  font-weight: 500;
  font-size: 0.86rem;
}

/* ---- Prose typography ---------------------------------------------------- */
.prose h2 {
  font-size: clamp(1.4rem, 1.1rem + 1vw, 1.85rem);
  margin: 2.4rem 0 0.9rem;
  padding-top: 0.4rem;
  letter-spacing: -0.01em;
  color: var(--c-primary-dark);
}
.prose h2::after {
  content: "";
  display: block;
  width: 3rem;
  height: 3px;
  margin-top: 0.5rem;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--c-primary), var(--c-green));
}
.prose h3 {
  font-size: 1.28rem;
  margin: 1.9rem 0 0.6rem;
  color: var(--c-ink);
}
.prose h4 {
  font-size: 1.08rem;
  margin: 1.5rem 0 0.5rem;
  color: var(--c-ink-soft);
}
.prose p {
  margin: 0 0 1.1rem;
}
.prose ul,
.prose ol {
  margin: 0 0 1.3rem;
  padding-left: 0;
  list-style: none;
}
/* Unordered lists — gradient diamond marker */
.prose ul:not(.contains-task-list) > li,
.prose ol > li {
  position: relative;
  margin: 0.55rem 0;
  padding-left: 1.9rem;
  line-height: 1.6;
}
.prose ul:not(.contains-task-list) > li::before {
  content: "";
  position: absolute;
  left: 0.3rem;
  top: 0.66em;
  width: 0.52rem;
  height: 0.52rem;
  border-radius: 2px;
  background: linear-gradient(135deg, var(--c-primary), var(--c-green));
  transform: translateY(-50%) rotate(45deg);
  box-shadow: 0 1px 2px rgba(16, 50, 61, 0.15);
}
/* Ordered lists — numbered accent badges */
.prose ol {
  counter-reset: lr-counter;
}
.prose ol > li {
  padding-left: 2.5rem;
}
.prose ol > li::before {
  counter-increment: lr-counter;
  content: counter(lr-counter);
  position: absolute;
  left: 0;
  top: 0.05em;
  display: grid;
  place-items: center;
  width: 1.65rem;
  height: 1.65rem;
  font-size: 0.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
  background: linear-gradient(135deg, var(--c-primary), var(--c-primary-dark));
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
}
/* Nested lists */
.prose li > ul,
.prose li > ol {
  margin: 0.45rem 0 0.6rem;
}
.prose li > ul > li::before {
  background: var(--c-accent);
}
.prose strong {
  color: var(--c-ink);
  font-weight: 700;
}
.prose blockquote {
  margin: 1.4rem 0;
  padding: 0.6rem 1.2rem;
  border-left: 4px solid var(--c-primary);
  background: var(--c-primary-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--c-ink-soft);
}
.prose hr {
  border: none;
  border-top: 1px solid var(--c-border);
  margin: 2.5rem 0;
}

/* Headings: anchor permalink + offset for sticky header */
.prose h2,
.prose h3,
.prose h4 {
  scroll-margin-top: calc(var(--header-h) + 18px);
  position: relative;
}
.heading-anchor {
  opacity: 0;
  margin-left: 0.4rem;
  color: var(--c-border-strong);
  font-weight: 400;
  text-decoration: none;
  transition: opacity 0.15s var(--ease), color 0.15s var(--ease);
}
.prose h2:hover .heading-anchor,
.prose h3:hover .heading-anchor,
.prose h4:hover .heading-anchor {
  opacity: 1;
}
.heading-anchor:hover {
  color: var(--c-primary);
}

/* Prose links */
.prose a {
  color: var(--c-primary);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--c-primary) 35%, transparent);
  text-underline-offset: 0.18em;
  transition: color 0.18s var(--ease), text-decoration-color 0.18s var(--ease);
}
.prose a:hover {
  color: var(--c-primary-dark);
  text-decoration-color: var(--c-primary);
}

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

/* ---- Code blocks --------------------------------------------------------- */
.code-block {
  margin: 1.5rem 0;
  border: 1px solid var(--c-code-border);
  border-radius: var(--radius);
  background: var(--c-code-bg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.code-block__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.55rem 0.4rem 0.95rem;
  background: linear-gradient(180deg, #eef5f8, #e6eff4);
  border-bottom: 1px solid var(--c-code-border);
}
.code-block__lang {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--c-muted);
}
.code-block__copy {
  font: inherit;
  font-size: 0.74rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--c-border-strong);
  border-radius: 999px;
  background: var(--c-surface);
  color: var(--c-ink-soft);
  cursor: pointer;
  transition: all 0.16s var(--ease);
}
.code-block__copy:hover {
  border-color: var(--c-primary);
  color: var(--c-primary);
  box-shadow: var(--shadow-sm);
}
.code-block__copy.is-copied {
  border-color: var(--c-green);
  color: var(--c-green);
  background: var(--c-green-soft);
}
.code-block__pre {
  margin: 0;
  padding: 1.1rem 1.2rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.65;
  color: #243b44;
  -webkit-overflow-scrolling: touch;
}
.code-block__pre code {
  font-family: inherit;
  background: none;
  padding: 0;
  white-space: pre;
}

/* Prism token theme — light, palette-matched */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
  color: #7b8f99;
  font-style: italic;
}
.token.punctuation {
  color: #51707c;
}
.token.keyword,
.token.boolean,
.token.atrule,
.token.important {
  color: #0b6e8f;
  font-weight: 600;
}
.token.string,
.token.char,
.token.attr-value,
.token.regex {
  color: #2f855a;
}
.token.number,
.token.constant,
.token.symbol {
  color: #b7791f;
}
.token.function,
.token.class-name {
  color: #2b6cb0;
}
.token.operator,
.token.entity,
.token.url {
  color: #905b1f;
}
.token.property,
.token.tag,
.token.selector {
  color: #b83280;
}
.token.variable,
.token.attr-name {
  color: #2c5282;
}
.token.deleted {
  color: #c53030;
}
.token.inserted {
  color: #2f855a;
}

/* ---- Tables -------------------------------------------------------------- */
.table-wrap {
  margin: 1.5rem 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.table-wrap table {
  border-collapse: collapse;
  width: 100%;
  min-width: 480px;
  font-size: 0.95rem;
  background: var(--c-surface);
}
.table-wrap th,
.table-wrap td {
  padding: 0.7rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--c-border);
  vertical-align: top;
}
.table-wrap thead th {
  background: var(--c-surface-alt);
  color: var(--c-primary-dark);
  font-weight: 700;
  white-space: nowrap;
  border-bottom: 2px solid var(--c-border-strong);
}
.table-wrap tbody tr:nth-child(even) {
  background: #fafcfd;
}
.table-wrap tbody tr:hover {
  background: var(--c-primary-soft);
}
.table-wrap td code {
  white-space: nowrap;
}

/* ---- Task list checkboxes ------------------------------------------------ */
.prose ul.contains-task-list,
.prose .contains-task-list {
  list-style: none;
  padding-left: 0.2rem;
}
.prose li.task-list-item {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.45rem 0.7rem;
  margin: 0.35rem 0;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  transition: background 0.16s var(--ease), border-color 0.16s var(--ease);
}
.prose li.task-list-item::marker {
  content: "";
}
.prose li.task-list-item:hover {
  border-color: var(--c-border-strong);
  background: #fbfdfe;
}
.task-list-item-checkbox {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  width: 1.2rem;
  height: 1.2rem;
  margin-top: 0.18rem;
  border: 2px solid var(--c-border-strong);
  border-radius: 6px;
  background: var(--c-surface);
  cursor: pointer;
  position: relative;
  transition: all 0.16s var(--ease);
}
.task-list-item-checkbox:hover {
  border-color: var(--c-primary);
}
.task-list-item-checkbox:checked {
  background: var(--c-green);
  border-color: var(--c-green);
}
.task-list-item-checkbox:checked::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.task-list-item.is-checked,
.task-list-item:has(.task-list-item-checkbox:checked) {
  color: var(--c-muted);
  text-decoration: line-through;
}
.task-list-item.is-checked code,
.task-list-item:has(.task-list-item-checkbox:checked) code {
  color: var(--c-muted);
  text-decoration: line-through;
}

/* ---- FAQ accordions ------------------------------------------------------ */
.faq {
  margin: 1.5rem 0;
  display: grid;
  gap: 0.7rem;
}
.faq__item {
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.faq__q {
  cursor: pointer;
  padding: 0.95rem 1.1rem;
  font-weight: 700;
  color: var(--c-primary-dark);
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.faq__q::-webkit-details-marker {
  display: none;
}
.faq__q::after {
  content: "+";
  font-size: 1.4rem;
  color: var(--c-primary);
  transition: transform 0.2s var(--ease);
}
.faq__item[open] .faq__q::after {
  transform: rotate(45deg);
}
.faq__a {
  padding: 0 1.1rem 1.1rem;
  color: var(--c-ink-soft);
}

/* ---- Math ---------------------------------------------------------------- */
.math-block {
  margin: 1.5rem 0;
  padding: 1rem 1.2rem;
  overflow-x: auto;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  text-align: center;
}

/* ---- Mermaid diagrams ---------------------------------------------------- */
.diagram {
  position: relative;
  margin: 1.8rem 0;
  padding: 1.4rem 1.4rem 1.2rem;
  background:
    radial-gradient(120% 100% at 0% 0%, rgba(11, 110, 143, 0.05), transparent 60%),
    var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s var(--ease), border-color 0.2s var(--ease);
}
.diagram.is-ready:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--c-border-strong);
}
.diagram pre.mermaid {
  margin: 0;
  padding: 0;
  background: none;
  border: 0;
  text-align: center;
  overflow-x: auto;
  line-height: normal;
}
.diagram.is-ready pre.mermaid {
  cursor: zoom-in;
}
.diagram pre.mermaid svg {
  max-width: 100%;
  height: auto;
}
/* Avoid a flash of raw diagram source before Mermaid renders */
.diagram pre.mermaid:not(:has(svg)) {
  min-height: 3rem;
  color: var(--c-muted);
  font-family: var(--font-mono);
  font-size: 0.8rem;
}
.diagram__caption {
  margin-top: 0.9rem;
  padding-top: 0.8rem;
  border-top: 1px dashed var(--c-border);
  font-size: 0.86rem;
  color: var(--c-muted);
  text-align: center;
}
.diagram__expand {
  position: absolute;
  top: 0.7rem;
  right: 0.7rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.32rem 0.7rem;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--c-primary-dark);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--c-border);
  border-radius: 999px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.16s var(--ease), background 0.16s var(--ease),
    color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}
.diagram:hover .diagram__expand,
.diagram__expand:focus-visible {
  opacity: 1;
}
.diagram__expand svg {
  width: 14px;
  height: 14px;
  fill: none;
}
.diagram__expand:hover {
  background: var(--c-primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
@media (hover: none) {
  .diagram__expand {
    opacity: 1;
  }
}

/* ---- Full-screen diagram lightbox --------------------------------------- */
.no-scroll {
  overflow: hidden;
}
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: clamp(0.6rem, 2vw, 1.5rem);
}
.lightbox[hidden] {
  display: none;
}
.lightbox__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 40, 52, 0.74);
  backdrop-filter: blur(4px);
  animation: lb-fade 0.18s var(--ease);
}
.lightbox__panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(96vw, 1400px);
  max-height: 92vh;
  background: var(--c-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: lb-pop 0.2s var(--ease);
}
.lightbox__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0.7rem 0.7rem 1.2rem;
  border-bottom: 1px solid var(--c-border);
  background: var(--c-surface-alt);
}
.lightbox__title {
  font-weight: 700;
  color: var(--c-primary-dark);
  font-size: 0.98rem;
}
.lightbox__close {
  flex: 0 0 auto;
  width: 2.2rem;
  height: 2.2rem;
  font-size: 1.7rem;
  line-height: 1;
  color: var(--c-ink-soft);
  background: none;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.lightbox__close:hover {
  background: var(--c-surface);
  border-color: var(--c-border);
  color: var(--c-ink);
}
.lightbox__stage {
  flex: 1 1 auto;
  min-height: 0;
  padding: clamp(1rem, 3vw, 2.5rem);
  overflow: auto;
  display: grid;
  place-items: center;
  background:
    linear-gradient(var(--c-border) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(90deg, var(--c-border) 1px, transparent 1px) 0 0 / 24px 24px,
    #ffffff;
  background-blend-mode: soft-light;
}
.lightbox__stage svg {
  width: 100%;
  height: auto;
  max-height: 100%;
}
@keyframes lb-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes lb-pop {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

/* ---- Related content ----------------------------------------------------- */
.related {
  margin-top: 3rem;
  padding-top: 1.8rem;
  border-top: 1px solid var(--c-border);
}
.related__title {
  font-size: 1.35rem;
  color: var(--c-primary-dark);
  margin: 0 0 1.2rem;
}
.related__group {
  margin-bottom: 1.6rem;
}
.related__group h3 {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--c-muted);
  margin: 0 0 0.7rem;
}
.related__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.8rem;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
}
.related__list a {
  display: block;
  height: 100%;
  padding: 1rem 1.1rem;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease),
    border-color 0.18s var(--ease);
}
.related__list a:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--c-primary);
}
.related__name {
  display: block;
  font-weight: 700;
  color: var(--c-primary-dark);
  margin-bottom: 0.25rem;
}
.related__desc {
  display: block;
  font-size: 0.88rem;
  color: var(--c-muted);
  line-height: 1.5;
}
.related__up a {
  font-weight: 600;
}

/* =========================================================================
   Home page
   ========================================================================= */
.hero {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(1200px 500px at 75% -10%, rgba(72, 187, 120, 0.12), transparent 60%),
    radial-gradient(900px 480px at 8% 0%, rgba(11, 110, 143, 0.14), transparent 55%),
    linear-gradient(180deg, #ffffff, var(--c-bg));
  border-bottom: 1px solid var(--c-border);
}
.hero__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(2.5rem, 6vw, 5rem) clamp(1rem, 3vw, 2.5rem) clamp(2.5rem, 5vw, 4rem);
  text-align: center;
}
.hero__logo {
  display: block;
  margin: 0 auto 1.8rem;
}
.hero__logo .emblem {
  width: clamp(96px, 18vw, 148px);
  height: clamp(96px, 18vw, 148px);
  border-radius: 28px;
  box-shadow: var(--shadow-lg);
}
.hero__title {
  font-size: clamp(2rem, 1.2rem + 3.4vw, 3.5rem);
  letter-spacing: -0.025em;
  margin: 0 auto 1rem;
  max-width: 18ch;
  background: linear-gradient(120deg, var(--c-primary-dark), var(--c-primary) 50%, var(--c-green));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero__lede {
  max-width: 64ch;
  margin: 0 auto;
  font-size: clamp(1.05rem, 1rem + 0.4vw, 1.25rem);
  color: var(--c-ink-soft);
}
.hero__lede + .hero__lede {
  margin-top: 1rem;
}

.cta-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem;
  margin-top: 2.2rem;
}
.cta {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.85rem 1.4rem;
  border-radius: 999px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
  font-weight: 700;
  color: var(--c-ink);
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease),
    border-color 0.18s var(--ease);
}
.cta:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--cta-accent, var(--c-primary));
  color: var(--c-ink);
}
.cta__icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: #fff;
  background: var(--cta-accent, var(--c-primary));
  box-shadow: inset 0 -2px 6px rgba(0, 0, 0, 0.15);
}
.cta__icon svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

/* Section grid */
.home-section {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(2.5rem, 5vw, 4rem) clamp(1rem, 3vw, 2.5rem);
}
.home-section__head {
  text-align: center;
  margin-bottom: 2.2rem;
}
.home-section__head h2 {
  font-size: clamp(1.6rem, 1.2rem + 1.4vw, 2.2rem);
  margin: 0 0 0.6rem;
  color: var(--c-primary-dark);
}
.home-section__head p {
  margin: 0 auto;
  max-width: 60ch;
  color: var(--c-ink-soft);
}
.card-grid {
  display: grid;
  gap: 1.4rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
}
.section-card {
  display: flex;
  flex-direction: column;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease),
    border-color 0.2s var(--ease);
}
.section-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-lg);
  border-color: var(--card-accent, var(--c-primary));
}
.section-card__top {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 1.3rem 1.4rem 0.8rem;
}
.section-card__icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  color: #fff;
  background: var(--card-accent, var(--c-primary));
  box-shadow: var(--shadow-sm);
}
.section-card__icon svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
}
.section-card__title {
  font-size: 1.15rem;
  margin: 0;
  color: var(--c-ink);
}
.section-card__body {
  padding: 0 1.4rem 1.2rem;
  color: var(--c-ink-soft);
  flex: 1 0 auto;
}
.section-card__body p {
  margin: 0 0 0.9rem;
  font-size: 0.96rem;
}
.section-card__links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}
.section-card__links a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
  font-size: 0.92rem;
}
.section-card__links a::before {
  content: "›";
  color: var(--card-accent, var(--c-primary));
  font-weight: 700;
}
.section-card__cta {
  margin: auto 1.4rem 1.4rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.92rem;
  color: #fff;
  background: var(--card-accent, var(--c-primary));
  align-self: flex-start;
  transition: filter 0.18s var(--ease), transform 0.18s var(--ease);
}
.section-card__cta:hover {
  filter: brightness(1.08);
  transform: translateX(3px);
  color: #fff;
}

/* ---- Content index page -------------------------------------------------- */
.page-head {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 2.6rem clamp(1rem, 3vw, 2.5rem) 0;
}
.page-head h1 {
  font-size: clamp(1.9rem, 1.3rem + 2vw, 2.8rem);
  margin: 0 0 0.6rem;
  background: linear-gradient(120deg, var(--c-primary-dark), var(--c-green));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.page-head p {
  max-width: 70ch;
  color: var(--c-ink-soft);
  font-size: 1.1rem;
  margin: 0;
}
.page-head--index {
  padding-bottom: 0.5rem;
}
.page-head__eyebrow {
  margin: 0 0 0.4rem !important;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--c-primary);
}

.index-wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 2rem clamp(1rem, 3vw, 2.5rem) 1rem;
  display: grid;
  gap: 1.8rem;
}

/* ---- Section card -------------------------------------------------------- */
.index-section {
  position: relative;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: clamp(1.3rem, 2.5vw, 2rem);
  overflow: hidden;
  transition: box-shadow 0.2s var(--ease);
}
.index-section::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 45%, #fff));
}
.index-section:hover {
  box-shadow: var(--shadow-md);
}

.index-section__head {
  display: flex;
  align-items: flex-start;
  gap: 1.1rem;
  margin-bottom: 1.5rem;
}
.index-section__icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 15px;
  color: #fff;
  background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #000 12%));
  box-shadow: var(--shadow-sm);
}
.index-section__icon svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
}
.index-section__heading {
  min-width: 0;
}
.index-section__title {
  display: inline-block;
  font-size: clamp(1.25rem, 1.05rem + 0.7vw, 1.55rem);
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--c-ink);
  transition: color 0.16s var(--ease);
}
.index-section__title:hover {
  color: var(--accent);
}
.index-section__summary {
  color: var(--c-ink-soft);
  margin: 0.4rem 0 0.7rem;
  max-width: 88ch;
}
.index-section__open {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--accent);
}
.index-section__open svg {
  width: 17px;
  height: 17px;
  transition: transform 0.16s var(--ease);
}
.index-section__open:hover {
  color: var(--accent);
}
.index-section__open:hover svg {
  transform: translateX(4px);
}

/* ---- Subsection cards ---------------------------------------------------- */
.index-sub {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
}
.subcard {
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #fbfdfe, var(--c-surface));
  border: 1px solid var(--c-border);
  border-left: 3px solid color-mix(in srgb, var(--accent) 55%, var(--c-border));
  border-radius: var(--radius-sm);
  padding: 1rem 1.1rem;
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease),
    border-color 0.18s var(--ease);
}
.subcard:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
  border-left-color: var(--accent);
}
.subcard__title {
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--c-ink);
  transition: color 0.16s var(--ease);
}
.subcard:hover .subcard__title {
  color: var(--accent);
}
.subcard__desc {
  margin: 0.4rem 0 0;
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--c-muted);
}
.subcard__children {
  list-style: none;
  margin: 0.8rem 0 0;
  padding: 0.8rem 0 0;
  border-top: 1px dashed var(--c-border);
  display: grid;
  gap: 0.45rem;
}
.subcard__children a {
  display: inline-flex;
  align-items: baseline;
  gap: 0.45rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--c-ink-soft);
  transition: color 0.16s var(--ease);
}
.subcard__children a::before {
  content: "›";
  color: var(--accent);
  font-weight: 800;
}
.subcard__children a:hover {
  color: var(--accent);
}

/* ---- Emblem stream animation -------------------------------------------- */
.emblem__dot {
  animation: lr-flow 2.6s var(--ease) infinite;
}
.emblem__dot--2 {
  animation-delay: 0.35s;
}
.emblem__dot--3 {
  animation-delay: 0.7s;
}
@keyframes lr-flow {
  0%, 100% {
    opacity: 0.55;
    transform: translateY(0);
  }
  50% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

/* =========================================================================
   Responsive
   ========================================================================= */
@media (max-width: 760px) {
  .nav-toggle {
    display: flex;
  }
  .primary-nav {
    position: absolute;
    top: var(--header-h);
    left: 0;
    right: 0;
    flex-direction: column;
    gap: 0.3rem;
    padding: 0.8rem clamp(1rem, 3vw, 2rem) 1.1rem;
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    box-shadow: var(--shadow-md);
    transform: translateY(-12px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.2s var(--ease), opacity 0.2s var(--ease);
  }
  .primary-nav.is-open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }
  .primary-nav__link {
    width: 100%;
  }
  .site-footer__inner {
    grid-template-columns: 1fr;
    gap: 1.8rem;
  }
  .brand__tag {
    display: none;
  }
}

@media (min-width: 1500px) {
  :root {
    --maxw: 1400px;
  }
}

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