/* ---------- Tokens ---------- */
:root {
  --bg:            #f7f9fb;
  --surface:       #ffffff;
  --surface-soft:  #eef2f7;
  --ink:           #0f1f33;
  --ink-muted:     #5a6b80;
  --ink-faint:     #8b97a8;
  --border:        #e2e8ef;
  --primary:       #2563eb;   /* route blue   */
  --primary-50:    #eef4ff;
  --secondary:     #0d9488;   /* node teal    */
  --secondary-50:  #e6f6f4;
  --accent:        #f59e0b;   /* signal amber */
  --accent-50:     #fff5e0;
  --danger:        #dc2626;
  --code-surface:  #f1f5f9;
  --code-ink:      #0b3b3a;
  --inline-code:   #0f766e;
  --shadow-sm:     0 1px 2px rgba(15, 31, 51, 0.05);
  --shadow-md:     0 6px 18px rgba(15, 31, 51, 0.08);
  --shadow-lg:     0 16px 40px rgba(15, 31, 51, 0.10);
  --radius-sm:     6px;
  --radius:        10px;
  --radius-lg:     16px;
  --header-h:      64px;
  --container:     min(1400px, 92vw);
  --reading:       100%;
  --font-sans:     ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono:     ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: clamp(15px, 0.9vw + 13px, 17px);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

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

a {
  color: var(--primary);
  text-decoration-color: rgba(37, 99, 235, 0.3);
  text-underline-offset: 3px;
  transition: color .15s ease, text-decoration-color .15s ease, text-decoration-thickness .15s ease;
}
a:hover {
  color: var(--secondary);
  text-decoration-color: var(--secondary);
  text-decoration-thickness: 2px;
}
a:focus-visible,
button:focus-visible,
summary:focus-visible,
input:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

:where(h1, h2, h3, h4, h5, h6) {
  scroll-margin-top: calc(var(--header-h) + 24px);
  line-height: 1.25;
  color: var(--ink);
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* ---------- Layout shell ---------- */
.container {
  width: var(--container);
  margin-inline: auto;
}

main {
  padding-block: clamp(24px, 4vw, 56px);
}

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(160%) blur(10px);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.site-header__inner {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 24px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 700;
}
.brand:hover { color: var(--primary); text-decoration: none; }
.brand__logo { width: 32px; height: 32px; }
.brand__name { font-size: 1.05rem; letter-spacing: -0.01em; }
.brand__name span { color: var(--primary); }

.primary-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
}
.primary-nav a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--ink-muted);
  font-weight: 500;
  font-size: 0.95rem;
  transition: background .15s, color .15s, transform .15s;
}
.primary-nav a:hover { background: var(--surface-soft); color: var(--ink); }
.primary-nav a[aria-current="page"] {
  color: var(--primary);
  background: var(--primary-50);
}
.primary-nav .nav-icon { width: 18px; height: 18px; }
.primary-nav .nav-icon.primary  { color: var(--primary); }
.primary-nav .nav-icon.secondary { color: var(--secondary); }
.primary-nav .nav-icon.accent    { color: var(--accent); }

.nav-toggle { display: none; }

@media (max-width: 880px) {
  .primary-nav {
    position: absolute;
    top: var(--header-h);
    left: 0; right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 8px 0;
    transform: translateY(-110%);
    transition: transform .2s ease;
  }
  .primary-nav a { padding: 14px 24px; border-radius: 0; }
  .primary-nav.is-open { transform: translateY(0); }
  .nav-toggle {
    display: inline-flex;
    margin-left: auto;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    cursor: pointer;
    color: var(--ink);
  }
}

/* ---------- Footer ---------- */
.site-footer {
  margin-top: 64px;
  background: linear-gradient(180deg, var(--surface-soft), var(--surface));
  border-top: 1px solid var(--border);
  padding: 40px 0 32px;
}
.site-footer__grid {
  display: grid;
  grid-template-columns: 1.4fr repeat(3, 1fr);
  gap: 32px;
}
.site-footer__brand p { color: var(--ink-muted); margin-top: 8px; font-size: 0.95rem; }
.site-footer h4 { margin: 0 0 12px; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-muted); }
.site-footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.site-footer a { text-decoration: none; color: var(--ink); font-size: 0.95rem; }
.site-footer a:hover { color: var(--primary); }
.site-footer__bottom { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--border); color: var(--ink-faint); font-size: 0.85rem; display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

@media (max-width: 880px) {
  .site-footer__grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .site-footer__grid { grid-template-columns: 1fr; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  text-decoration: none;
  font-weight: 600;
  font-size: 1rem;
  box-shadow: var(--shadow-sm);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease, color .15s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); border-color: var(--primary); color: var(--primary); text-decoration: none; }
.btn--primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn--primary:hover { color: #fff; background: #1d4ed8; border-color: #1d4ed8; }

.btn .btn-icon { width: 22px; height: 22px; }

/* ---------- Homepage ---------- */
.hero {
  padding: clamp(40px, 6vw, 80px) 0 clamp(24px, 3vw, 48px);
}
.hero__eyebrow {
  display: inline-block;
  padding: 4px 10px;
  background: var(--secondary-50);
  color: var(--secondary);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.hero__title {
  margin: 16px 0 0;
  font-size: clamp(2rem, 3vw + 1rem, 3.6rem);
  line-height: 1.1;
  background: linear-gradient(120deg, var(--primary), var(--secondary) 70%, var(--accent));
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
  letter-spacing: -0.02em;
}
.hero__lede {
  margin-top: 18px;
  font-size: clamp(1.05rem, 0.4vw + 1rem, 1.2rem);
  color: var(--ink-muted);
}
.hero__lede p { margin: 0; }
.hero__lede p + p { margin-top: 12px; }

.cta-grid {
  margin-top: clamp(28px, 3vw, 40px);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}
.cta-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow-sm);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.cta-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: transparent;
  text-decoration: none;
}
.cta-card__icon {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 12px;
}
.cta-card__icon svg { width: 26px; height: 26px; }
.cta-card.primary  .cta-card__icon { background: var(--primary-50);   color: var(--primary); }
.cta-card.secondary .cta-card__icon { background: var(--secondary-50); color: var(--secondary); }
.cta-card.accent   .cta-card__icon { background: var(--accent-50);    color: var(--accent); }
.cta-card__title { font-weight: 700; font-size: 1.05rem; color: var(--ink); margin-bottom: 2px; }
.cta-card__desc  { color: var(--ink-muted); font-size: 0.95rem; }
.cta-card__arrow { margin-left: auto; color: var(--ink-faint); transition: transform .18s ease, color .18s ease; }
.cta-card:hover .cta-card__arrow { transform: translateX(4px); color: var(--primary); }

.section-grid {
  margin-top: 56px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}
.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .18s ease, transform .18s ease;
}
.section-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.section-card h3 { margin: 0 0 8px; font-size: 1.15rem; }
.section-card h3 a { text-decoration: none; color: var(--ink); }
.section-card h3 a:hover { color: var(--primary); }
.section-card p { color: var(--ink-muted); font-size: 0.95rem; margin: 0 0 12px; }
.section-card ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.section-card ul a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 0;
  text-decoration: none; color: var(--ink); font-size: 0.92rem;
}
.section-card ul a::before { content: "→"; color: var(--ink-faint); transition: transform .15s ease, color .15s ease; }
.section-card ul a:hover { color: var(--primary); }
.section-card ul a:hover::before { color: var(--primary); transform: translateX(2px); }

/* Hero stripe at the bottom of the homepage */
.closing-strip {
  margin-top: 64px;
  padding: 28px;
  background: linear-gradient(120deg, var(--primary-50), var(--secondary-50));
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}
.closing-strip h3 { margin: 0 0 8px; }
.closing-strip p  { margin: 0; color: var(--ink-muted); }

/* ---------- Content layout ---------- */
.content-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 40px;
  align-items: start;
}
@media (max-width: 1080px) {
  .content-layout { grid-template-columns: 1fr; }
  .content-toc { display: none; }
}

.breadcrumb {
  font-size: 0.9rem;
  color: var(--ink-muted);
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
}
.breadcrumb a { text-decoration: none; color: var(--ink-muted); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb__sep { color: var(--ink-faint); }
.breadcrumb__current { color: var(--ink); font-weight: 600; }

.article {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(20px, 3vw, 40px);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.article > * { max-width: var(--reading); }
.article > pre,
.article > .table-scroll,
.article > .mermaid,
.article > .faq-list,
.article > figure { max-width: 100%; }

.article h1 {
  margin: 0 0 8px;
  font-size: clamp(1.7rem, 2vw + 1rem, 2.6rem);
  background: linear-gradient(120deg, var(--primary), var(--secondary));
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
  letter-spacing: -0.02em;
}
.article h2 {
  margin: 36px 0 12px;
  padding-left: 14px;
  border-left: 4px solid var(--primary);
  font-size: clamp(1.3rem, 1vw + 1rem, 1.7rem);
}
.article h3 {
  margin: 28px 0 8px;
  font-size: 1.15rem;
  color: var(--secondary);
}
.article h2 a.header-anchor,
.article h3 a.header-anchor { color: inherit; text-decoration: none; }
.article h2 a.header-anchor:hover,
.article h3 a.header-anchor:hover { color: var(--primary); }

.article p { color: var(--ink); margin: 0 0 16px; }
.article ul, .article ol { margin: 0 0 16px; padding-left: 1.4em; }
.article li + li { margin-top: 4px; }
.article strong { color: var(--ink); }
.article blockquote {
  margin: 16px 0;
  padding: 14px 18px;
  border-left: 4px solid var(--accent);
  background: var(--accent-50);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--ink);
}
.article hr { border: none; border-top: 1px solid var(--border); margin: 32px 0; }

/* Tables */
.table-scroll {
  overflow-x: auto;
  margin: 0 0 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.article table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.article th, .article td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.article th {
  background: var(--surface-soft);
  font-weight: 700;
  color: var(--ink);
}
.article tr:last-child td { border-bottom: none; }
.article tbody tr:nth-child(even) td { background: rgba(241,245,249,0.45); }

/* Inline & block code */
.article code:not([class*="language-"]) {
  background: var(--code-surface);
  color: var(--inline-code);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.9em;
  border: none;
}
.article pre {
  position: relative;
  background: var(--code-surface);
  color: var(--code-ink);
  padding: 18px 18px 18px 18px;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 0.92rem;
  line-height: 1.55;
  margin: 16px 0;
  border: 1px solid var(--border);
}
.article pre code { background: transparent; color: inherit; padding: 0; border-radius: 0; font-family: var(--font-mono); }
.copy-btn {
  position: absolute;
  top: 8px; right: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface);
  color: var(--ink-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s ease, color .15s, border-color .15s, background .15s;
}
.article pre:hover .copy-btn,
.copy-btn:focus-visible { opacity: 1; }
.copy-btn:hover { color: var(--primary); border-color: var(--primary); }
.copy-btn.is-copied { color: var(--secondary); border-color: var(--secondary); background: var(--secondary-50); }

/* Task lists */
.article ul.contains-task-list,
.article ul.task-list { list-style: none; padding-left: 0; }
.article ul.contains-task-list li.task-list-item,
.article li.task-list-item {
  list-style: none;
  padding-left: 0;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 6px 0;
}
.article li.task-list-item input.task-list-item-checkbox {
  margin-top: 4px;
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}
.article li.task-list-item.is-checked { color: var(--ink-muted); text-decoration: line-through; }

/* Mermaid */
.mermaid {
  background: var(--surface);
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  text-align: center;
  margin: 16px 0;
  overflow-x: auto;
}

/* FAQ accordion */
.faq-list { display: grid; gap: 8px; margin: 12px 0 24px; }
.faq-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 16px;
  transition: box-shadow .15s ease;
}
.faq-item[open] { box-shadow: var(--shadow-sm); }
.faq-item summary {
  list-style: none;
  cursor: pointer;
  font-weight: 600;
  padding: 14px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: "+";
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--primary);
  transition: transform .2s ease;
}
.faq-item[open] summary::after { content: "−"; }
.faq-body { padding: 0 0 14px; color: var(--ink); }

/* TOC sidebar */
.content-toc {
  position: sticky;
  top: calc(var(--header-h) + 16px);
  align-self: start;
  font-size: 0.92rem;
  max-height: calc(100vh - var(--header-h) - 32px);
  overflow-y: auto;
}
.content-toc h4 {
  margin: 0 0 10px;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.content-toc ol { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.content-toc ol ol { padding-left: 12px; margin-top: 4px; }
.content-toc a {
  display: block;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--ink-muted);
  border-left: 2px solid transparent;
}
.content-toc a:hover { color: var(--primary); background: var(--primary-50); border-left-color: var(--primary); }

/* Related */
.related-pages {
  margin-top: 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}
.related-pages h3 { margin: 0 0 12px; font-size: 1rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-muted); }
.related-pages__grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.related-pages a {
  display: block;
  padding: 10px 14px;
  background: var(--surface-soft);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--ink);
  font-weight: 500;
  border: 1px solid transparent;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.related-pages a:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-50); }
.related-pages a small { display: block; color: var(--ink-muted); font-weight: 400; margin-top: 2px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }

/* ---------- Helpers ---------- */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}
