:root {
  --bg: #f9fafb; --surface: #ffffff; --fg: #111827; --muted: #6b7280;
  --border: #e5e7eb; --accent: #4f46e5; --accent-2: #a5b4fc;
  --code-bg: #0d1117; --code-fg: #e6edf3; --soft: #eef2ff; --on-accent: #ffffff;
  --font: Manrope, "Avenir Next", "Trebuchet MS", sans-serif;
  --mono: Menlo, Consolas, Monaco, monospace;
  --gutter: clamp(16px, 4vw, 48px);
  --page-max: 1440px;
  --edge: max(var(--gutter), calc((100% - var(--page-max)) / 2));
  --nav-h: 4rem;
}
:root[data-theme="dark"] {
  --bg: #0f1014; --surface: #17181f; --fg: #e5e7eb; --muted: #8b93a8;
  --border: #26283a; --accent: #a5b4fc; --accent-2: #c7d2fe;
  --code-bg: #0d0e12; --soft: #1e1b4b; --on-accent: #1e1b4b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1014; --surface: #17181f; --fg: #e5e7eb; --muted: #8b93a8;
    --border: #26283a; --accent: #a5b4fc; --accent-2: #c7d2fe;
    --code-bg: #0d0e12; --soft: #1e1b4b; --on-accent: #1e1b4b;
  }
}
* { box-sizing: border-box; }
html { font-size: clamp(0.9375rem, 0.35vw + 0.84rem, 1.125rem); }
html, body { margin: 0; }
h1, h2, h3, h4 { scroll-margin-top: calc(var(--nav-h) + 0.75rem); }
body { background: var(--bg); color: var(--fg); font-family: var(--font); line-height: 1.6; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, kbd { font-family: var(--mono); }

/* Nav */
.ms-nav { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem;
  padding: 0.6rem var(--edge); background: var(--surface); border-bottom: 1px solid var(--border); }
.ms-brand { display: flex; align-items: center; gap: 8px; color: var(--fg); }
.ms-brand:hover { text-decoration: none; }
.ms-avatar { width: 1.75rem; height: 1.75rem; border-radius: 50%; object-fit: cover; object-position: 50% 30%;
  border: 1.5px solid var(--accent); }
.ms-word { font-weight: 800; font-size: 1.125rem; letter-spacing: -0.02em; }
.ms-accent { color: var(--accent); }
.ms-links { display: flex; gap: 1rem; flex: 1; }
.ms-links a { color: var(--muted); }
.ms-search-btn { display: flex; gap: 1.5rem; align-items: center; min-width: 12rem; padding: 0.4rem 0.65rem;
  border: 1px solid var(--border); border-radius: 0.5rem; background: var(--bg); color: var(--muted);
  font: inherit; cursor: pointer; }
.ms-search-btn kbd { font-size: 0.75rem; border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }
.ms-version { display: flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.ms-version-link { padding: 0.15rem 0.65rem; font-size: 0.8rem; color: var(--muted); }
.ms-version-current { background: var(--soft); color: var(--accent); font-weight: 700; }
.ms-theme, .ms-menu { border: 0; background: none; color: var(--fg); font-size: 1.125rem; cursor: pointer; }
.ms-menu { display: none; }

/* Buttons and code */
.ms-btn { display: inline-block; padding: 0.5rem 0.9rem; border-radius: 0.5rem; border: 1px solid var(--border);
  color: var(--fg); font-weight: 600; }
.ms-btn:hover { text-decoration: none; }
.ms-btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.ms-code { background: var(--code-bg); color: var(--code-fg); padding: 0.9rem 1rem; border-radius: 0.6rem;
  overflow-x: auto; font-size: 0.85rem; line-height: 1.55; }
.ms-code code { background: none; padding: 0; color: inherit; }
.tk-kw { color: #a5b4fc; font-weight: 700; }
.tk-str { color: #a5d6ff; }
.tk-com { color: #8b93a8; font-style: italic; }
.tk-num { color: #f0abfc; }
.tk-tag { color: #fbbf24; }

/* Landing */
.ms-landing { width: min(100% - 2 * var(--gutter), var(--page-max)); margin: 0 auto; padding: 0 0 3rem; }
.ms-hero { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 2rem; align-items: center;
  padding: 3.5rem 0; }
.ms-hero h1 { font-size: clamp(2rem, 1.2rem + 3vw, 3.75rem); line-height: 1.1; letter-spacing: -0.03em; margin: 0.5rem 0 1rem; }
.ms-hero h1 em { font-style: normal; color: var(--accent); }
.ms-eyebrow { color: var(--accent); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700;
  font-size: 0.75rem; margin: 0; }
.ms-lead { color: var(--muted); font-size: 1.125rem; }
.ms-cta { display: flex; flex-wrap: wrap; gap: 0.65rem; margin-top: 1.25rem; }
.ms-hero-code { display: grid; gap: 0.75rem; min-width: 0; }
.ms-hero-text { min-width: 0; }
.ms-why, .ms-start { padding: 2rem 0; border-top: 1px solid var(--border); }
.ms-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 0.9rem; margin-top: 1rem; }
.ms-tile { background: var(--surface); border: 1px solid var(--border); border-radius: 0.6rem; padding: 1rem; }
.ms-tile h3 { margin: 0 0 0.4rem; font-size: 1rem; }
.ms-tile p { margin: 0; color: var(--muted); font-size: 0.875rem; }
.ms-tabs { display: flex; gap: 0.4rem; margin: 1rem 0 0; }
.ms-tab { border: 1px solid var(--border); border-bottom: 0; border-radius: 0.5rem 0.5rem 0 0; padding: 0.4rem 0.75rem;
  background: var(--surface); color: var(--fg); font: inherit; cursor: pointer; }
.ms-tab-active { background: var(--code-bg); color: var(--code-fg); border-color: var(--code-bg); }
.ms-start .ms-code { border-top-left-radius: 0; margin-top: 0; }

/* Docs */
.ms-docs { display: grid; grid-template-columns: minmax(13rem, 17rem) minmax(0, 1fr) minmax(11rem, 15rem); gap: 2rem;
  width: min(100% - 2 * var(--gutter), var(--page-max)); margin: 0 auto; padding: 1.5rem 0 3rem; }
.ms-sidebar { position: sticky; top: calc(var(--nav-h) + 1rem); align-self: start; display: flex; flex-direction: column; gap: 2px; max-height: calc(100vh - var(--nav-h) - 2rem); overflow-y: auto; }
.ms-side-group { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.75rem; color: var(--muted);
  margin: 0.9rem 0 0.25rem; }
.ms-side-link { color: var(--fg); padding: 0.25rem 0.5rem; border-radius: 0.4rem; }
.ms-side-current { background: var(--soft); color: var(--accent); font-weight: 700; }
.ms-article { min-width: 0; }
.ms-banner { background: var(--soft); border: 1px solid var(--accent-2); border-radius: 0.5rem; padding: 0.5rem 0.75rem;
  margin-bottom: 1rem; }
.ms-crumbs { color: var(--muted); font-size: 0.875rem; }
.ms-md h1 { font-size: clamp(1.75rem, 1.2rem + 1.5vw, 2.5rem); letter-spacing: -0.02em; }
.ms-md p, .ms-md li, .ms-md blockquote { max-width: 80ch; }
.ms-md h2 { margin-top: 2em; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.ms-md :not(pre) > code { background: var(--soft); padding: 1px 0.3rem; border-radius: 0.25rem; font-size: 0.9em; overflow-wrap: anywhere; }
.ms-md li > p { margin: 0.2em 0; }
.ms-md blockquote { border-left: 3px solid var(--accent-2); margin: 1em 0; padding: 0 1em; color: var(--muted); }
.ms-anchor { margin-left: 8px; opacity: 0; font-weight: 400; }
.ms-md h1:hover .ms-anchor, .ms-md h2:hover .ms-anchor, .ms-md h3:hover .ms-anchor { opacity: 0.6; }
.ms-table-wrap { overflow-x: auto; }
.ms-md table { border-collapse: collapse; margin: 1em 0; }
.ms-md th, .ms-md td { border: 1px solid var(--border); padding: 0.4rem 0.65rem; text-align: left; vertical-align: top; }
.ms-md th { background: var(--surface); }
.ms-prevnext { display: flex; justify-content: space-between; gap: 0.75rem; margin-top: 2.5rem; }
.ms-prev, .ms-next { border: 1px solid var(--border); border-radius: 0.5rem; padding: 0.65rem 0.9rem; }
.ms-edit { display: inline-block; margin-top: 1rem; font-size: 0.875rem; }
.ms-toc { position: sticky; top: calc(var(--nav-h) + 1rem); align-self: start; display: flex; flex-direction: column; gap: 4px;
  font-size: 0.875rem; max-height: calc(100vh - var(--nav-h) - 2rem); overflow-y: auto; }
.ms-toc-title { font-weight: 700; margin: 0 0 4px; }
.ms-toc-link { color: var(--muted); }
.ms-toc-l3 { padding-left: 12px; }
.ms-toc-mobile { display: none; margin: 12px 0; }
.ms-loading, .ms-error { color: var(--muted); }
.ms-notfound { max-width: 45rem; margin: 4rem auto; padding: 0 var(--gutter); text-align: center; }

/* Footer */
.ms-footer { display: flex; align-items: center; justify-content: center; gap: 1rem; padding: 1.5rem var(--edge);
  border-top: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 0.875rem; }

/* Search */
.ms-search-backdrop { position: fixed; inset: 0; background: rgba(15, 16, 20, 0.45); z-index: 40; }
.ms-search { position: fixed; z-index: 50; top: 10vh; left: 50%; transform: translateX(-50%);
  width: min(680px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 16px 48px rgba(0, 0, 0, 0.3); overflow: hidden; }
.ms-search-input { width: 100%; border: 0; border-bottom: 1px solid var(--border); padding: 14px 16px;
  font: inherit; font-size: 16px; background: var(--surface); color: var(--fg); outline: none; }
.ms-search-results { max-height: 60vh; overflow-y: auto; }
.ms-search-group { margin: 0; padding: 8px 16px 2px; text-transform: uppercase; letter-spacing: 0.08em;
  font-size: 0.75rem; color: var(--muted); }
.ms-search-item { display: block; padding: 8px 16px; border-left: 3px solid transparent; color: var(--fg); }
.ms-search-item:hover { text-decoration: none; background: var(--soft); }
.ms-search-selected { background: var(--soft); border-left-color: var(--accent); }
.ms-search-title { display: block; font-weight: 700; }
.ms-search-excerpt { display: block; color: var(--muted); font-size: 0.8125rem; }
.ms-search-excerpt mark { background: var(--accent-2); color: #1e1b4b; border-radius: 3px; padding: 0 2px; }
.ms-search-note { padding: 16px; margin: 0; color: var(--muted); }
.ms-search-hint { display: flex; gap: 14px; padding: 8px 16px; border-top: 1px solid var(--border);
  color: var(--muted); font-size: 0.75rem; }
.ms-search-scope { margin-left: auto; }

.ms-sidebar-backdrop { display: none; }

/* Medium: sidebar and article, TOC folds into the article */
@media (max-width: 1399px) {
  .ms-docs { grid-template-columns: minmax(12rem, 13rem) minmax(0, 1fr); }
  .ms-toc { display: none; }
  .ms-toc-mobile { display: block; }
}

/* Phone */
@media (max-width: 899px) {
  /* Measured: the wrapped docs nav is 112px (7.43rem) at 390px. */
  :root { --nav-h: 7.5rem; }
  .ms-hero { grid-template-columns: 1fr; padding: 2rem 0; }
  .ms-nav { flex-wrap: wrap; gap: 8px 12px; }
  .ms-links { order: 9; flex: 1 0 100%; gap: 0.9rem; font-size: 0.8125rem; }
  .ms-search-btn span { display: none; }
  .ms-search-btn { min-width: 0; }
  .ms-menu { display: block; }
  .ms-docs { grid-template-columns: 1fr; padding: 1rem 0; }
  .ms-sidebar { display: none; }
  .ms-sidebar-open { display: flex; position: fixed; top: 0; left: 0; bottom: 0; width: 260px; z-index: 50;
    background: var(--surface); border-right: 1px solid var(--border); padding: 12px 16px; overflow-y: auto; align-content: flex-start; }
  .ms-sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.4); }
  .ms-footer { flex-wrap: wrap; }
}

/* Wide phone and tablet: the nav still wraps, but less. */
@media (min-width: 600px) and (max-width: 899px) {
  :root { --nav-h: 5.5rem; }
}
