:root {
  --sidebar-w: 17rem;
  --aside-w: 15rem;
  --measure: 46rem;
  --topbar-h: 3.25rem;
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }
/* The heading a contents link jumps to must not land under the sticky bar. */
:target, h2[id], h3[id] { scroll-margin-top: calc(var(--topbar-h) + 1rem); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 var(--font-sans);
  font-feature-settings: var(--font-variants-sans);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--brand-hovered); }

.skip {
  position: absolute; left: -9999px;
  background: var(--panel); color: var(--text); padding: 0.6rem 1rem; z-index: 10;
}
.skip:focus { left: 0.5rem; top: 0.5rem; }

/* --- the bar across the top ------------------------------------------------ */

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 1.5rem;
  height: var(--topbar-h);
  padding: 0 1.25rem;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex; align-items: center; gap: 0.55rem;
  color: var(--text); text-decoration: none; font-weight: 600; white-space: nowrap;
}
.brand img { display: block; border-radius: 5px; }

.tabs { display: flex; gap: 0.35rem; }
.tabs a {
  padding: 0.3rem 0.7rem; border-radius: 6px;
  color: var(--muted); text-decoration: none; font-size: 0.9rem;
}
.tabs a:hover { color: var(--text); background: rgba(36, 50, 71, 0.05); }
.tabs a[aria-current="page"] { color: var(--brand); background: var(--selected); font-weight: 600; }

.menu-toggle {
  margin-left: auto; display: none;
  background: transparent; border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); padding: 0.35rem 0.7rem; font: inherit; font-size: 0.85rem; cursor: pointer;
}

/* --- three columns --------------------------------------------------------- */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--aside-w);
  gap: 2.5rem;
  max-width: 84rem;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
  align-items: start;
}

.sidebar, .aside {
  position: sticky;
  top: calc(var(--topbar-h) + 1.5rem);
  max-height: calc(100vh - var(--topbar-h) - 3rem);
  overflow-y: auto;
  font-size: 0.9rem;
}

.sidebar h2 {
  margin: 1.4rem 0 0.45rem;
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--muted);
}
.sidebar h2:first-child { margin-top: 0; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li { margin: 0; }
.sidebar a {
  display: block; padding: 0.28rem 0.6rem; border-radius: 5px;
  color: var(--muted); text-decoration: none; border-left: 2px solid transparent;
}
.sidebar a:hover { color: var(--text); background: rgba(36, 50, 71, 0.04); }
.sidebar a[aria-current="page"] {
  color: var(--text); background: var(--selected);
  border-left-color: var(--brand); font-weight: 600;
}
.sidebar .ext { color: var(--muted); font-size: 0.8em; }

/* --- the page itself ------------------------------------------------------- */

.doc { max-width: var(--measure); min-width: 0; }

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

.doc h1 {
  font-size: 2rem; line-height: 1.2; margin: 0 0 1rem;
  letter-spacing: -0.015em;
}
.doc h2 {
  font-size: 1.35rem; margin: 2.75rem 0 0.75rem;
  padding-bottom: 0.35rem; border-bottom: 1px solid var(--border);
}
.doc h3 { font-size: 1.1rem; margin: 2rem 0 0.5rem; }
.doc h4 { font-size: 1rem; margin: 1.5rem 0 0.4rem; color: var(--text); }

.doc p, .doc li { overflow-wrap: break-word; }
.doc ul, .doc ol { padding-left: 1.35rem; }
.doc li + li { margin-top: 0.3rem; }

.doc strong { color: var(--text); }
.doc em { color: var(--text); }

/* The italic one-liner under an h1, which most of these documents open with. */
.doc h1 + p > em:only-child { color: var(--muted); font-size: 1.05rem; }

.doc blockquote {
  margin: 1.5rem 0; padding: 0.85rem 1.1rem;
  background: var(--sky-soft);
  border-left: 3px solid var(--brand);
  border-radius: 0 6px 6px 0;
}
.doc blockquote > :first-child { margin-top: 0; }
.doc blockquote > :last-child { margin-bottom: 0; }

.doc code {
  font-family: var(--font-mono);
  font-feature-settings: var(--font-variants-mono);
  font-size: 0.88em;
  background: rgba(36, 50, 71, 0.07);
  padding: 0.12em 0.36em; border-radius: 4px;
}
.doc pre {
  background: var(--surface-soft); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.9rem 1.1rem; overflow-x: auto; line-height: 1.5;
}
.doc pre code { background: none; padding: 0; font-size: 0.85rem; }

.doc table {
  width: 100%; border-collapse: collapse; margin: 1.5rem 0;
  font-size: 0.92rem; display: block; overflow-x: auto;
}
.doc th, .doc td {
  text-align: left; vertical-align: top;
  padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border);
}
.doc th { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
.doc tbody tr:hover { background: rgba(36, 50, 71, 0.025); }

.doc img { max-width: 100%; height: auto; border-radius: 8px; }

.doc hr { border: 0; border-top: 1px solid var(--border); margin: 2.5rem 0; }

/* --- on this page --------------------------------------------------------- */

.aside h2 {
  margin: 0 0 0.5rem;
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--muted);
}
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc ul ul { padding-left: 0.8rem; }
.toc a {
  display: block; padding: 0.22rem 0.55rem; border-radius: 4px;
  color: var(--muted); text-decoration: none;
  border-left: 2px solid transparent;
  font-size: 0.85rem;
}
.toc a:hover { color: var(--text); }
/* Set by docs.js as the reader scrolls. */
.toc a.here { color: var(--brand); border-left-color: var(--brand); background: var(--selected); }

/* --- the landing page ------------------------------------------------------ */

.doorway {
  max-width: 52rem;
  margin: 0 auto;
  padding: 3rem 1.25rem 3rem;
}
.doorway-eyebrow { color: var(--muted); font-size: var(--text-body); font-weight: 600; margin: 0 0 12px; }
.doorway h1 { font-size: 2.75rem; margin: 0 0 0.75rem; letter-spacing: -0.02em; }
.doorway .lede { font-size: 1.1rem; color: var(--muted); margin: 0 0 2.5rem; max-width: 40rem; }

.doorway .hero { margin: 2.5rem 0; }
.doorway .hero img {
  display: block; width: 100%; height: auto;
  border: 1px solid var(--border); border-radius: 10px;
}
.doorway .hero figcaption {
  margin-top: 0.6rem; color: var(--muted); font-size: 0.88rem; text-align: center;
}

.doors { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }

.door {
  display: flex; flex-direction: column;
  padding: 1.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-surface);
  color: var(--text); text-decoration: none;
  transition: border-color 0.15s, transform 0.15s;
}
.door:hover { border-color: var(--brand); transform: translateY(-2px); color: var(--text); }
.door-spot { display: block; width: 112px; height: 80px; object-fit: contain; object-position: left bottom; margin-bottom: 20px; }
.door h2 { margin: 0 0 0.35rem; font-size: 1.2rem; }
.door p { margin: 0 0 1rem; color: var(--muted); font-size: 0.95rem; }
.door ul {
  list-style: none; margin: 0 0 1.25rem; padding: 0;
  color: var(--muted); font-size: 0.85rem; flex: 1;
}
.door li { padding: 0.1rem 0; }
.door .go { color: var(--brand); font-weight: 600; font-size: 0.9rem; }
.door:hover .go { color: var(--brand-hovered); }

.doorway .aside-note {
  margin: 2rem 0 0; padding: 0.9rem 1.1rem;
  background: var(--surface-soft);
  border-left: 3px solid var(--sage);
  border-radius: 0 6px 6px 0;
  font-size: 0.95rem;
}
.doorway .libs-heading {
  margin: 3rem 0 0.5rem; font-size: 1.2rem;
  padding-bottom: 0.35rem; border-bottom: 1px solid var(--border);
}
.doorway .libs { padding-left: 1.35rem; color: var(--muted); }
.doorway .libs li { margin: 0.35rem 0; }

@media (max-width: 700px) {
  .doors { grid-template-columns: 1fr; }
  .doorway h1 { font-size: 1.9rem; }
}

/* --- footer --------------------------------------------------------------- */

.footer {
  border-top: 1px solid var(--border);
  padding: 1.75rem 1.25rem 3rem;
  color: var(--muted); font-size: 0.88rem;
  text-align: center;
}
.footer p { margin: 0.3rem 0; }
.footer .wink { color: var(--muted); font-size: 0.82rem; }

/* --- narrower ------------------------------------------------------------- */

@media (max-width: 1180px) {
  .shell { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .aside { display: none; }
}

@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); gap: 1.5rem; }
  .menu-toggle { display: block; }
  .sidebar {
    position: static; max-height: none; display: none;
    padding-bottom: 1.25rem; border-bottom: 1px solid var(--border);
  }
  .sidebar.open { display: block; }
  .tabs a { padding: 0.3rem 0.55rem; }
  .brand span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0s !important; }
}
