:root {
  --color-text: #1f2328;
  --color-text-muted: #59636e;
  --color-bg: #ffffff;
  --color-bg-subtle: #f6f8fa;
  --color-border: #d1d9e0;
  --color-link: #0969da;
  --font-sans:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial,
    sans-serif;
  --font-mono:
    ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --content-width: 1200px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-text: #e6edf3;
    --color-text-muted: #9198a1;
    --color-bg: #0d1117;
    --color-bg-subtle: #161b22;
    --color-border: #30363d;
    --color-link: #4493f8;
    color-scheme: dark;
  }
}

:root[data-theme="light"] {
  --color-text: #1f2328;
  --color-text-muted: #59636e;
  --color-bg: #ffffff;
  --color-bg-subtle: #f6f8fa;
  --color-border: #d1d9e0;
  --color-link: #0969da;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --color-text: #e6edf3;
  --color-text-muted: #9198a1;
  --color-bg: #0d1117;
  --color-bg-subtle: #161b22;
  --color-border: #30363d;
  --color-link: #4493f8;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
}

a {
  color: var(--color-link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 0.2em 0.4em;
  background: var(--color-bg-subtle);
  border-radius: 4px;
}

main {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

header {
  border-bottom: 1px solid var(--color-border);
}

.header-inner {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-inner > a {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text);
}

.header-subnav {
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-subtle);
}

.subnav-inner {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: stretch;
  gap: 1.5rem;
  min-height: 2.5rem;
}

.subnav-crumbs {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.875rem;
  white-space: nowrap;
}

.subnav-crumbs .crumb-sep,
.subnav-crumbs span {
  color: var(--color-text-muted);
}

.subnav-tabs {
  display: flex;
  align-items: stretch;
  gap: 0.25rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.subnav-tabs a {
  display: flex;
  align-items: center;
  padding: 0 0.625rem;
  font-size: 0.875rem;
  color: var(--color-text-muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.subnav-tabs a:hover {
  color: var(--color-text);
  text-decoration: none;
}

.subnav-tabs a[aria-current="page"] {
  color: var(--color-text);
  font-weight: 600;
  border-bottom-color: var(--color-link);
}

.subnav-links {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.875rem;
  white-space: nowrap;
}

.header-end {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.worker-version {
  color: var(--color-text-muted);
}

.theme-switcher {
  position: relative;
}

.theme-switcher > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-bg-subtle);
  color: var(--color-text);
}

.theme-switcher > summary::-webkit-details-marker {
  display: none;
}

.theme-switcher > summary::marker {
  content: "";
}

.theme-switcher > summary:hover {
  background: var(--color-bg);
}

.theme-switcher > summary svg {
  display: none;
}

:root[data-theme-pref="system"]
  .theme-switcher
  > summary
  svg[data-icon="system"],
:root[data-theme-pref="light"] .theme-switcher > summary svg[data-icon="light"],
:root[data-theme-pref="dark"] .theme-switcher > summary svg[data-icon="dark"] {
  display: inline-block;
}

:root:not([data-theme-pref]) .theme-switcher > summary svg[data-icon="system"] {
  display: inline-block;
}

.theme-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 10;
  min-width: 40px;
}

.theme-menu li {
  margin: 0;
  padding: 0;
}

.theme-menu button {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.theme-menu button:hover {
  background: var(--color-bg-subtle);
  color: var(--color-text);
}

.theme-menu button[aria-pressed="true"] {
  background: var(--color-bg-subtle);
  color: var(--color-link);
}

.hero {
  padding: 2rem 0;
  margin-bottom: 2rem;
}

.hero h1 {
  font-size: 2rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
  line-height: 1.2;
}

.hero-intro {
  font-size: 1rem;
  color: var(--color-text-muted);
  max-width: 720px;
}

.hero-intro p {
  margin: 0;
}

.section-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 1rem;
}

.link-list {
  list-style: none;
  margin: 0;
  padding: 0;
  column-count: 4;
  column-gap: 2rem;
}

.link-list li {
  break-inside: avoid;
  padding: 0.25rem 0;
  font-size: 0.9375rem;
}

@media (max-width: 900px) {
  .link-list {
    column-count: 3;
  }
}

@media (max-width: 640px) {
  .link-list {
    column-count: 2;
  }
}

@media (max-width: 400px) {
  .link-list {
    column-count: 1;
  }
}

.doc-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 0 0 0.25rem;
  padding-bottom: 0.25rem;
}

.doc-title {
  font-size: 2rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.2;
}

.doc-edit,
.doc-md {
  font-size: 0.875rem;
  white-space: nowrap;
  margin-left: 0.375rem;
}

.doc-md svg {
  vertical-align: text-bottom;
}

.doc-updated {
  margin: 0 0 1.5rem;
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

/* Card grid emitted by the builder's landing.njk layout */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0 0;
}

.card {
  display: block;
  padding: 1rem 1.25rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.card:hover {
  text-decoration: none;
  border-color: var(--color-link);
  background: var(--color-bg-subtle);
}

.card-title {
  margin: 0 0 0.25rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-link);
}

.card-desc {
  margin: 0;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

/* Card groups: landing.njk wraps card grids in sections with optional
   headings taken from the TOC's {section, pages} groups. */

.card-groups {
  margin: 1.5rem 0 0;
}

.card-group + .card-group {
  margin-top: 2rem;
}

.card-group-title {
  margin: 0 0 1rem;
  padding-bottom: 0.375rem;
  font-size: 1.25rem;
  font-weight: 600;
  border-bottom: 1px solid var(--color-border);
}

.card-group > .card-grid {
  margin-top: 0; /* .card-groups already provides the outer offset */
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Doc page layout: collapsible sidebar + article */

.page {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}

.page > article {
  flex: 1;
  min-width: 0;
}

.toc-panel {
  flex-shrink: 0;
  width: 220px;
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 5rem); /* ~header height + page padding */
  overflow-y: auto;
}

.toc-panel:not([open]) {
  width: auto;
}

.toc-toggle {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text-muted);
  padding: 0.25rem 0 0.5rem;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 0.25rem;
  user-select: none;
  white-space: nowrap;
}

.toc-toggle::-webkit-details-marker {
  display: none;
}

.toc-toggle::marker {
  content: "";
}

.toc-toggle::before {
  content: "▸";
  font-size: 0.75rem;
  line-height: 1;
}

.toc-panel[open] > .toc-toggle::before {
  content: "▾";
}

.toc-toggle:hover {
  color: var(--color-text);
}

.toc-panel:not([open]) .toc-toggle-label {
  display: none;
}

.toc-panel:not([open]) .toc-toggle {
  border-bottom-color: transparent;
  margin-bottom: 0;
  padding-bottom: 0.25rem;
}

.toc-rail ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-rail > ul > li {
  margin-bottom: 0.125rem;
}

.toc-rail > ul > li > span {
  display: block;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  padding: 0.625rem 0.5rem 0.25rem;
}

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

.toc-rail a:hover {
  color: var(--color-text);
  background: var(--color-bg-subtle);
  text-decoration: none;
}

.toc-rail a[aria-current="page"] {
  color: var(--color-link);
  background: var(--color-bg-subtle);
  font-weight: 500;
}

/* Cap entry: the leaf pointing at the TOC directory's own landing page
   (page: index), set off as the tree's title. */

.toc-rail > ul > li.toc-cap {
  padding-bottom: 0.375rem;
  margin-bottom: 0.375rem;
  border-bottom: 1px solid var(--color-border);
}

.toc-rail > ul > li.toc-cap > a {
  color: var(--color-text);
  font-weight: 600;
}

.toc-rail > ul > li.toc-cap > a[aria-current="page"] {
  color: var(--color-link);
}

.toc-rail ul ul {
  padding-left: 0.75rem;
}

@media (max-width: 768px) {
  .page {
    flex-direction: column;
  }

  .toc-panel {
    width: 100%;
    position: static;
    max-height: none;
  }

  .toc-panel:not([open]) {
    width: 100%;
  }

  .subnav-inner {
    flex-wrap: wrap;
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
    column-gap: 1rem;
    row-gap: 0;
  }

  .subnav-tabs {
    order: 3;
    flex-basis: 100%;
  }
}
