:root {
  --bg: #f3f6fb;
  --bg-strong: #e9eef7;
  --surface: #ffffff;
  --surface-alt: #f7f9fd;
  --line: #c0ccdc;
  --line-strong: #91a1b8;
  --text: #132033;
  --muted: #3c4c62;
  --accent: #0f5aa5;
  --accent-strong: #083a72;
  --accent-soft: #d9e9ff;
  --danger: #8f1d2d;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 9px;
  --shadow: 0 16px 36px rgba(11, 30, 57, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Avenir Next", "Sora", "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.55;
  background: radial-gradient(circle at 10% 5%, rgba(15, 90, 165, 0.09), transparent 32%),
    radial-gradient(circle at 85% 2%, rgba(8, 58, 114, 0.07), transparent 28%),
    linear-gradient(165deg, var(--bg), var(--bg-strong));
  color: var(--text);
}

a {
  color: var(--accent-strong);
  text-underline-offset: 2px;
}

a:hover {
  color: var(--accent);
}

.touch-target {
  min-height: 48px;
  min-width: 48px;
}

.app-shell {
  max-width: 1600px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 12px;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  grid-template-areas:
    "topbar topbar"
    "sidebar main";
  gap: 12px;
}

.topbar {
  grid-area: topbar;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, var(--surface-alt) 6%);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 12px 16px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
}

.menu-toggle,
.secondary-btn,
.list button,
.mobile-bottom-nav button {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.menu-toggle:hover,
.secondary-btn:hover,
.list button:hover,
.mobile-bottom-nav button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.menu-toggle {
  padding: 0 16px;
  font-weight: 600;
}

.brand-lockup {
  min-width: 0;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.brand-lockup h1 {
  margin: 4px 0 0;
  font-family: "DM Serif Display", "Iowan Old Style", serif;
  font-size: clamp(1.4rem, 2.4vw, 2rem);
  line-height: 1.08;
}

.brand-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.switchers {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.switchers label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.79rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.switchers select {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
  min-width: 170px;
}

.sidebar-overlay {
  display: none;
}

.sidebar {
  grid-area: sidebar;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--surface) 96%, var(--surface-alt) 4%);
  box-shadow: var(--shadow);
  min-height: 0;
  overflow: auto;
  padding: 12px;
  display: grid;
  gap: 12px;
  align-content: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: 10px;
}

.panel h2,
.panel label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  font-weight: 700;
}

.search-panel {
  position: sticky;
  top: 0;
  z-index: 4;
  background: linear-gradient(165deg, color-mix(in srgb, var(--surface) 88%, var(--accent-soft) 12%), var(--surface));
}

.search-panel input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  padding: 0 12px;
}

.search-panel input:focus,
.switchers select:focus {
  outline: 2px solid color-mix(in srgb, var(--accent-soft) 65%, transparent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.secondary-btn {
  margin-top: 8px;
  width: 100%;
  font-weight: 600;
}

.list {
  display: grid;
  gap: 7px;
}

.list button {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  display: grid;
  gap: 4px;
}

.list button.active {
  border-color: var(--accent);
  background: linear-gradient(130deg, color-mix(in srgb, var(--accent-soft) 76%, white 24%), color-mix(in srgb, var(--surface) 87%, var(--accent-soft) 13%));
}

.item-title {
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
}

.item-meta {
  color: var(--muted);
  font-size: 0.83rem;
}

.main {
  grid-area: main;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--surface) 96%, var(--surface-alt) 4%);
  box-shadow: var(--shadow);
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.breadcrumbs {
  border-bottom: 1px solid var(--line);
  padding: 10px 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.crumb-link,
.crumb-current {
  font-size: 0.89rem;
}

.crumb-link {
  color: var(--accent-strong);
  text-decoration: none;
}

.crumb-sep {
  color: var(--muted);
  font-size: 0.9rem;
}

.crumb-current {
  color: var(--text);
  font-weight: 600;
}

.badge {
  border: 1px solid var(--line);
  background: var(--surface-alt);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 700;
}

.repo-badge {
  color: var(--accent-strong);
}

.domain-badge {
  color: var(--muted);
}

.doc-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.badge-row {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}

.doc-path {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.doc-header h2 {
  margin: 6px 0 0;
  font-family: "DM Serif Display", "Iowan Old Style", serif;
  font-size: clamp(1.5rem, 2.6vw, 2.2rem);
  line-height: 1.08;
}

.doc-summary {
  margin: 8px 0 0;
  color: var(--muted);
  max-width: 80ch;
}

.doc-meta {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
}

.doc-meta p {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.doc-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
}

.doc-body {
  min-height: 0;
  overflow: auto;
  padding: 16px;
  line-height: 1.7;
}

.doc-body > :first-child {
  margin-top: 0;
}

.doc-body > :last-child {
  margin-bottom: 0;
}

.doc-body h1,
.doc-body h2,
.doc-body h3,
.doc-body h4,
.doc-body h5,
.doc-body h6 {
  margin: 1.35rem 0 0.5rem;
  font-family: "DM Serif Display", "Iowan Old Style", serif;
  line-height: 1.15;
  scroll-margin-top: 18px;
}

.doc-body h1 {
  font-size: 2rem;
}

.doc-body h2 {
  font-size: 1.6rem;
}

.doc-body h3 {
  font-size: 1.28rem;
}

.doc-body p,
.doc-body ul,
.doc-body ol,
.doc-body pre,
.doc-body blockquote,
.doc-body table {
  max-width: 80ch;
}

.doc-body code {
  font-family: "IBM Plex Mono", "SFMono-Regular", Menlo, monospace;
  background: var(--surface-alt);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 5px;
  font-size: 0.9em;
}

.doc-body pre {
  background: #102033;
  color: #f5f8ff;
  border-radius: 10px;
  padding: 12px;
  overflow: auto;
}

.doc-body pre code {
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
}

.doc-body blockquote {
  margin-left: 0;
  border-left: 4px solid var(--accent);
  background: var(--surface-alt);
  border-radius: 0 10px 10px 0;
  padding: 4px 12px;
}

.doc-body table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--line);
}

.doc-body th,
.doc-body td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
}

.toc {
  border-left: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-alt) 88%, var(--surface) 12%);
  min-height: 0;
  overflow: auto;
  padding: 14px 12px;
}

.toc h3 {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.73rem;
  color: var(--muted);
}

.toc ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 4px;
}

.toc a {
  text-decoration: none;
  display: block;
  border-radius: 6px;
  padding: 4px 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

.toc a:hover,
.toc a.active {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.toc-level-2 {
  margin-left: 8px;
}

.toc-level-3,
.toc-level-4,
.toc-level-5,
.toc-level-6 {
  margin-left: 14px;
}

.error {
  color: var(--danger);
}

.mobile-bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, var(--surface-alt) 8%);
  display: none;
  gap: 8px;
  z-index: 60;
}

.mobile-bottom-nav button {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 600;
}

@media (max-width: 1220px) {
  .doc-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .toc {
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: 230px;
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main";
    padding: 10px;
    padding-bottom: 88px;
  }

  .topbar {
    grid-template-columns: auto 1fr;
    row-gap: 8px;
    align-items: start;
  }

  .switchers {
    grid-column: 1 / -1;
    flex-wrap: wrap;
  }

  .switchers label {
    flex: 1 1 180px;
  }

  .switchers select {
    min-width: 100%;
  }

  .sidebar {
    position: fixed;
    top: 10px;
    bottom: 78px;
    left: 10px;
    width: min(90vw, 380px);
    transform: translateX(-115%);
    transition: transform 180ms ease;
    z-index: 55;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    border: 0;
    margin: 0;
    padding: 0;
    background: rgba(8, 18, 32, 0.35);
    z-index: 50;
  }

  body.sidebar-open .sidebar-overlay {
    display: block;
  }

  .mobile-bottom-nav {
    display: flex;
  }

  .doc-header,
  .doc-body,
  .toc,
  .breadcrumbs {
    padding-left: 12px;
    padding-right: 12px;
  }
}

@media (max-width: 620px) {
  .brand-lockup h1 {
    font-size: 1.5rem;
  }

  .doc-header h2 {
    font-size: 1.7rem;
  }

  .doc-body h1 {
    font-size: 1.65rem;
  }

  .doc-body h2 {
    font-size: 1.38rem;
  }
}
