:root {
  --ink: #10243a;
  --ink-soft: #2a445c;
  --accent: #1a6b7c;
  --accent-deep: #0f4f5c;
  --accent-soft: #e4f2f4;
  --paper: #ffffff;
  --bg: #e9eef3;
  --bg-panel: #f4f7fa;
  --line: #d3dde6;
  --muted: #5a6b7c;
  --success: #1f6b4a;
  --warning: #8a5a12;
  --shadow: 0 10px 30px rgba(16, 36, 58, 0.08);
  --radius: 14px;
  --sidebar-width: 210px;
  --font-display: "Fraunces", "Times New Roman", serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(ellipse at top left, rgba(26, 107, 124, 0.08), transparent 42%),
    radial-gradient(ellipse at bottom right, rgba(16, 36, 58, 0.06), transparent 45%),
    var(--bg);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.65;
  min-height: 100vh;
}

a {
  color: var(--accent-deep);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover {
  color: var(--accent);
}

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #f7f9fb;
  color: var(--ink);
  padding: 18px 14px 16px;
  border-right: 1px solid var(--line);
}

.brand {
  display: block;
  flex: 0 0 auto;
  padding: 0 2px 12px;
  margin-bottom: 2px;
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid var(--line);
}

.brand-kicker {
  display: block;
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}

.brand-title {
  display: block;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.15;
  color: var(--ink);
}

.brand-sub {
  display: none;
}

.nav-group {
  margin: 10px 0 0;
  padding: 0;
  flex: 0 0 auto;
}

.nav-group + .nav-group {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.nav-group-title {
  margin: 0 2px 2px;
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 550;
  line-height: 1.2;
}

.nav-link {
  display: block;
  padding: 2px 0 2px 8px;
  border-radius: 0;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 12px;
  line-height: 1.3;
  border-left: 2px solid transparent;
  margin-left: -2px;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.nav-link:hover {
  color: var(--accent-deep);
}

.nav-link.active {
  color: var(--accent-deep);
  border-left-color: var(--accent);
  font-weight: 650;
  background: transparent;
  box-shadow: none;
}

@media (max-height: 780px) {
  .sidebar {
    overflow: auto;
  }

  .nav-link {
    font-size: 11.5px;
    padding-block: 1px;
  }

  .nav-group + .nav-group {
    margin-top: 8px;
    padding-top: 6px;
  }
}

.content-wrap {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover {
  border-color: var(--accent);
  color: var(--accent-deep);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-deep);
  color: #fff;
}

.menu-toggle {
  display: none;
}

main.page {
  max-width: 920px;
  margin: 0 auto;
  padding: 36px 28px 80px;
}

.hero {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 34px 36px 28px;
  margin-bottom: 28px;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 6px;
  background: linear-gradient(180deg, var(--accent), var(--ink));
}

.hero h1 {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 2.4vw, 2.4rem);
  line-height: 1.15;
  color: var(--ink);
}

.hero .lede {
  margin: 0;
  color: var(--muted);
  max-width: 62ch;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 22px;
}

.meta-item {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}

.meta-item span {
  display: block;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.meta-item strong {
  font-size: 14.5px;
  color: var(--ink-soft);
  font-weight: 600;
}

.article {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 36px 40px;
}

.article > *:first-child {
  margin-top: 0;
}

.article h1 {
  display: none;
}

.article h2 {
  font-family: var(--font-display);
  font-size: 1.55rem;
  margin: 2.2rem 0 0.8rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--line);
  color: var(--ink);
  scroll-margin-top: 84px;
}

.article h2:first-of-type {
  border-top: 0;
  margin-top: 0.4rem;
}

.article h3 {
  font-family: var(--font-display);
  font-size: 1.18rem;
  margin: 1.6rem 0 0.55rem;
  color: var(--ink-soft);
  scroll-margin-top: 84px;
}

.article h4 {
  margin: 1.2rem 0 0.4rem;
  font-size: 1rem;
  color: var(--accent-deep);
}

.article p {
  margin: 0.75rem 0;
}

.article ul,
.article ol {
  margin: 0.6rem 0 1rem;
  padding-left: 1.35rem;
}

.article li {
  margin: 0.28rem 0;
}

.article li::marker {
  color: var(--accent);
}

.article hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 1.8rem 0;
}

.article blockquote {
  margin: 1.2rem 0;
  padding: 12px 16px;
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  color: var(--ink-soft);
  border-radius: 0 10px 10px 0;
}

.article code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.1em 0.4em;
}

.article pre {
  background: #10243a;
  color: #e8eef4;
  border-radius: 12px;
  padding: 16px 18px;
  overflow: auto;
  border: 1px solid #1c3a55;
}

.article pre code {
  background: transparent;
  border: 0;
  padding: 0;
  color: inherit;
  font-size: 0.86rem;
}

.article table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0 1.4rem;
  font-size: 0.95rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  display: block;
  max-width: 100%;
  overflow-x: auto;
}

.article thead {
  background: var(--bg-panel);
}

.article th,
.article td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.article th {
  font-weight: 650;
  color: var(--ink);
  white-space: nowrap;
}

.article tbody tr:nth-child(even) {
  background: #fafcfd;
}

.article tbody tr:hover {
  background: var(--accent-soft);
}

.article strong {
  color: var(--ink);
}

.mermaid-wrap {
  margin: 1.4rem 0 1.8rem;
  padding: 18px;
  background: linear-gradient(180deg, #f8fbfd, #ffffff);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow-x: auto;
}

.mermaid {
  display: flex;
  justify-content: center;
  margin: 0;
}

.toc-panel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  margin: 0 0 1.6rem;
}

.toc-panel h2 {
  margin: 0 0 10px !important;
  padding: 0 !important;
  border: 0 !important;
  font-size: 1rem !important;
  font-family: var(--font-body) !important;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted) !important;
}

.toc-panel ul {
  margin: 0;
  padding-left: 1.1rem;
}

.toc-panel li {
  margin: 0.2rem 0;
}

.page-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 28px;
}

.page-nav a {
  flex: 1;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  text-decoration: none;
  color: var(--ink-soft);
  box-shadow: var(--shadow);
}

.page-nav a span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.page-nav a strong {
  font-family: var(--font-display);
  font-size: 1.05rem;
}

.page-nav a.next {
  text-align: right;
}

/* Index page */
.index-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  margin-top: 8px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 18px 16px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, border-color 0.15s ease;
  min-height: 132px;
}

.card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.card-domain {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 650;
}

.card h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
  color: var(--ink);
}

.card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  flex: 1;
}

.footer-note {
  margin-top: 28px;
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, var(--sidebar-width));
    z-index: 40;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  body.nav-open::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(16, 36, 58, 0.45);
    z-index: 30;
  }

  .menu-toggle {
    display: inline-flex;
  }

  main.page {
    padding: 24px 16px 64px;
  }

  .hero,
  .article {
    padding-left: 18px;
    padding-right: 18px;
  }

  .topbar {
    padding-inline: 16px;
  }
}

@media print {
  .sidebar,
  .topbar,
  .menu-toggle,
  .page-nav {
    display: none !important;
  }

  .shell {
    display: block;
  }

  body {
    background: #fff;
  }

  .hero,
  .article {
    box-shadow: none;
    border: 0;
    padding: 0;
  }
}
