/* Relay documentation site — self-contained, theme-aware (light default, dark via toggle / OS). */
:root {
  --bg: #ffffff;
  --bg-subtle: #f6f7f9;
  --surface: #ffffff;
  --text: #1a1d21;
  --text-secondary: #444b54;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --accent: #2563eb;
  --accent-subtle: #eff4ff;
  --code-bg: #f6f7f9;
  --topbar-h: 56px;
  --sidebar-w: 264px;
  --toc-w: 220px;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --bg-subtle: #15181e; --surface: #15181e; --text: #e6e8eb;
    --text-secondary: #b7bdc7; --text-muted: #8a92a0; --border: #262a31; --border-strong: #363b44;
    --accent: #5b8cff; --accent-subtle: #16203a; --code-bg: #1a1e25; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --bg-subtle: #15181e; --surface: #15181e; --text: #e6e8eb;
  --text-secondary: #b7bdc7; --text-muted: #8a92a0; --border: #262a31; --border-strong: #363b44;
  --accent: #5b8cff; --accent-subtle: #16203a; --code-bg: #1a1e25; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.6; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Topbar ── */
.topbar {
  position: sticky; top: 0; z-index: 50; height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px; padding: 0 18px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-flex; }
.brand-dim { color: var(--text-muted); font-weight: 500; }
.topbar-spacer { flex: 1; }
.nav-filter {
  width: 260px; max-width: 40vw; height: 34px; padding: 0 12px; font-size: 13.5px;
  color: var(--text); background: var(--bg-subtle); border: 1px solid var(--border); border-radius: 20px;
}
.nav-filter:focus { outline: none; border-color: var(--accent); }
.theme-btn, .menu-btn {
  height: 34px; min-width: 34px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-secondary); border-radius: var(--radius); cursor: pointer; font-size: 15px;
}
.menu-btn { display: none; }

/* ── Layout ── */
.layout {
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  max-width: 1320px; margin: 0 auto; gap: 0;
}
.sidebar {
  position: sticky; top: var(--topbar-h); align-self: start; height: calc(100dvh - var(--topbar-h));
  overflow-y: auto; padding: 22px 14px 60px; border-right: 1px solid var(--border);
}
.nav-section { margin-bottom: 18px; }
.nav-section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700;
  color: var(--text-muted); padding: 0 10px 6px;
}
.sidebar a {
  display: block; padding: 6px 10px; margin: 1px 0; border-radius: 6px;
  color: var(--text-secondary); font-size: 14px;
}
.sidebar a:hover { background: var(--bg-subtle); text-decoration: none; color: var(--text); }
.sidebar a.active { background: var(--accent-subtle); color: var(--accent); font-weight: 600; }

.content { min-width: 0; padding: 34px 44px 80px; }
.doc { max-width: 780px; }

.toc {
  position: sticky; top: var(--topbar-h); align-self: start; height: calc(100dvh - var(--topbar-h));
  overflow-y: auto; padding: 34px 18px 60px;
}
.toc-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; color: var(--text-muted); margin-bottom: 8px; }
.toc a { display: block; padding: 3px 0; font-size: 13px; color: var(--text-muted); line-height: 1.4; }
.toc a:hover { color: var(--text); text-decoration: none; }
.toc a.toc-l3 { padding-left: 12px; font-size: 12.5px; }

/* ── Pager ── */
.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 48px; padding-top: 20px; border-top: 1px solid var(--border); }
.pager a { display: flex; flex-direction: column; gap: 2px; padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius); min-width: 180px; }
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager-next { text-align: right; }
.pager span { font-size: 12px; color: var(--text-muted); }
.pager strong { color: var(--text); font-size: 14px; }

/* ── Markdown content ── */
.md { overflow-wrap: anywhere; }
.md > *:first-child { margin-top: 0; }
.md h1 { font-size: 2em; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 8px; line-height: 1.2; }
.md h2 { font-size: 1.45em; font-weight: 650; margin: 34px 0 12px; padding-top: 8px; line-height: 1.3; }
.md h3 { font-size: 1.18em; font-weight: 600; margin: 26px 0 8px; }
.md h4 { font-size: 1.02em; font-weight: 600; margin: 20px 0 6px; }
.md h2, .md h3 { scroll-margin-top: calc(var(--topbar-h) + 12px); }
.md p { margin: 0 0 14px; }
.md ul, .md ol { margin: 0 0 14px; padding-left: 1.5em; }
.md li { margin: 4px 0; }
.md li > ul, .md li > ol { margin: 4px 0; }
.md strong { font-weight: 650; }
.md a { text-decoration: underline; text-underline-offset: 2px; }
.md a:hover { text-decoration: none; }
.md .anchor { float: left; margin-left: -1em; padding-right: 0.35em; color: var(--text-muted); opacity: 0; text-decoration: none; font-weight: 400; }
.md h2:hover .anchor, .md h3:hover .anchor { opacity: 1; }
.md code { font-family: var(--mono); font-size: 0.86em; background: var(--code-bg); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; }
.md pre { margin: 0 0 16px; padding: 14px 16px; background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
.md pre code { display: block; background: none; border: none; padding: 0; font-size: 12.8px; line-height: 1.55; white-space: pre; color: var(--text); }
.md blockquote { margin: 0 0 16px; padding: 8px 16px; border-left: 3px solid var(--accent); background: var(--accent-subtle); border-radius: 0 var(--radius) var(--radius) 0; color: var(--text-secondary); }
.md blockquote > *:last-child { margin-bottom: 0; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 28px 0; }
.md table { border-collapse: collapse; margin: 0 0 16px; display: block; overflow-x: auto; max-width: 100%; font-size: 14px; }
.md th, .md td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; vertical-align: top; }
.md th { background: var(--bg-subtle); font-weight: 650; }

/* ── Responsive ── */
@media (max-width: 1080px) {
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .menu-btn { display: inline-block; }
  .nav-filter { display: none; }
  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; width: 82vw; max-width: 320px; z-index: 40;
    background: var(--surface); transform: translateX(-102%); transition: transform 0.2s; box-shadow: 0 8px 40px rgba(0,0,0,0.25);
  }
  body.nav-open .sidebar { transform: none; }
  .content { padding: 24px 20px 70px; }
}
