:root, [data-theme="light"] {
  --bg: #fafafa;
  --fg: #1a1a1a;
  --sidebar-bg: #f0f0f0;
  --accent: #6640c0;
}
[data-theme="rust"] {
  --bg: #e1e1db;
  --fg: #262625;
  --sidebar-bg: #d1c7a5;
  --accent: #a72145;
}
[data-theme="rust"] .site-header,
[data-theme="rust"] .search-modal {
  background: #e1e1db;
  color: #262625;
  border-color: #d1c7a5;
}
[data-theme="coal"] {
  --bg: #141617;
  --fg: #98a3ad;
  --sidebar-bg: #292c2f;
  --accent: #3473ad;
}
[data-theme="coal"] .site-header,
[data-theme="coal"] .search-modal {
  background: #141617;
  color: #98a3ad;
  border-color: #292c2f;
}
[data-theme="navy"] {
  --bg: #161923;
  --fg: #bcbdd0;
  --sidebar-bg: #212942;
  --accent: #2b79a2;
}
[data-theme="navy"] .site-header,
[data-theme="navy"] .search-modal {
  background: #161923;
  color: #bcbdd0;
  border-color: #212942;
}
[data-theme="ayu"] {
  --bg: #0f1419;
  --fg: #c5c5c5;
  --sidebar-bg: #14191f;
  --accent: #ffb454;
}
[data-theme="ayu"] .site-header,
[data-theme="ayu"] .search-modal {
  background: #0f1419;
  color: #c5c5c5;
  border-color: #14191f;
}
body {
  background: var(--bg);
  color: var(--fg);
}

/* Theme picker (see header.html.tera). Plain <details> so it works without JS
   and stays keyboard accessible; theme-switch.js only handles the choice. */
.theme-menu {
  position: relative;
}

.theme-menu > summary {
  cursor: pointer;
  list-style: none;
}

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

.theme-menu .theme-list {
  position: absolute;
  right: 0;
  z-index: 20;
  margin: 0.25rem 0 0;
  padding: 0.25rem;
  min-width: 8rem;
  list-style: none;
  border-radius: 0.375rem;
  background: var(--bg, #fff);
  color: var(--fg, #1a1a1a);
  border: 1px solid var(--sidebar-bg, rgba(0, 0, 0, 0.15));
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.theme-menu .theme-list button {
  display: block;
  width: 100%;
  padding: 0.375rem 0.5rem;
  text-align: left;
  border: 0;
  border-radius: 0.25rem;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.theme-menu .theme-list button:hover,
.theme-menu .theme-list button:focus-visible {
  background: var(--sidebar-bg, rgba(0, 0, 0, 0.08));
}

.theme-menu .theme-list button[aria-current="true"]::after {
  content: " ✓";
}

/* Header utilities share one compact visual rhythm. This lives in the
   content-hashed theme bundle so deployed books cannot retain stale geometry. */
.header-right,
.header-links {
  gap: 0.25rem;
}

.header-search {
  margin-right: 0.75rem;
}

.header-action,
.theme-menu > summary.header-action {
  box-sizing: border-box;
  display: inline-grid;
  place-items: center;
  inline-size: 2rem;
  block-size: 2rem;
  flex: 0 0 2rem;
  padding: 0;
  border-radius: 0.375rem;
  color: var(--sl-color-neutral-600, var(--fg));
  line-height: 1;
}

.header-action:hover,
.header-action:focus-visible,
.theme-menu[open] > summary.header-action {
  color: var(--accent);
  background: var(--sl-color-neutral-100, var(--sidebar-bg));
}

.header-action:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.header-links .header-action sl-icon {
  margin: 0;
  font-size: 1.125rem;
}

.theme-swatch {
  display: block;
  box-sizing: border-box;
  inline-size: 1rem;
  block-size: 1rem;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  background: linear-gradient(90deg, currentColor 50%, transparent 50%);
}

/* Sidebar folding ([output.html.fold]). The list is hidden by class rather
   than removed, so expanding it needs no rebuild. */
.sidebar-items.folded {
  display: none;
}

.fold-toggle {
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  font: inherit;
  padding: 0 0.35rem 0 0;
  line-height: 1;
}

.fold-toggle::before {
  content: "\25B8";
  display: inline-block;
  transition: transform 0.15s ease;
}

.fold-toggle[aria-expanded="true"]::before {
  transform: rotate(90deg);
}

/* Skip link: off-screen until focused, so keyboard users can bypass the
   sidebar without it appearing for everyone else. */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 0.5rem 0.75rem;
  background: var(--bg, #fff);
  color: var(--fg, #000);
  border: 2px solid var(--accent, #6640c0);
  border-radius: 0 0 0.25rem 0;
}

.skip-link:focus {
  left: 0;
}

/* Complete Shoelace token mappings. These override the vendored light
   defaults so every surface and shadow component follows the explicit theme. */
:root,
[data-theme="light"] {
  --bg: #ffffff;
  --fg: #0f172a;
  --sidebar-bg: #f8fafc;
  --accent: #0284c7;
  --sl-color-neutral-0: #ffffff;
  --sl-color-neutral-50: #f8fafc;
  --sl-color-neutral-100: #f1f5f9;
  --sl-color-neutral-200: #e2e8f0;
  --sl-color-neutral-300: #cbd5e1;
  --sl-color-neutral-400: #94a3b8;
  --sl-color-neutral-500: #64748b;
  --sl-color-neutral-600: #475569;
  --sl-color-neutral-700: #334155;
  --sl-color-neutral-800: #1e293b;
  --sl-color-neutral-900: #0f172a;
  --sl-color-primary-50: #f0f9ff;
  --sl-color-primary-100: #e0f2fe;
  --sl-color-primary-200: #bae6fd;
  --sl-color-primary-300: #7dd3fc;
  --sl-color-primary-400: #38bdf8;
  --sl-color-primary-500: #0ea5e9;
  --sl-color-primary-600: #0284c7;
  --sl-color-primary-700: #0369a1;
  --sl-color-primary-800: #075985;
  --sl-color-primary-900: #0c4a6e;
}

[data-theme="rust"] {
  --bg: #e1e1db;
  --fg: #262625;
  --sidebar-bg: #d1c7a5;
  --accent: #a72145;
  --sl-color-neutral-0: #e1e1db;
  --sl-color-neutral-50: #d8d4c5;
  --sl-color-neutral-100: #d1c7a5;
  --sl-color-neutral-200: #b8ad8c;
  --sl-color-neutral-300: #968b70;
  --sl-color-neutral-400: #756d58;
  --sl-color-neutral-500: #5d5748;
  --sl-color-neutral-600: #474339;
  --sl-color-neutral-700: #37342e;
  --sl-color-neutral-800: #2e2c29;
  --sl-color-neutral-900: #262625;
  --sl-color-primary-50: #fbf3f5;
  --sl-color-primary-100: #f3dce2;
  --sl-color-primary-200: #e9b9c6;
  --sl-color-primary-300: #dc8ba2;
  --sl-color-primary-400: #ce5e7f;
  --sl-color-primary-500: #bd365b;
  --sl-color-primary-600: #a72145;
  --sl-color-primary-700: #8b1a39;
  --sl-color-primary-800: #71152e;
  --sl-color-primary-900: #531020;
}

[data-theme="coal"] {
  --bg: #141617;
  --fg: #d5dce2;
  --sidebar-bg: #292c2f;
  --accent: #70a8d8;
  --sl-color-neutral-0: #141617;
  --sl-color-neutral-50: #1d2022;
  --sl-color-neutral-100: #292c2f;
  --sl-color-neutral-200: #3a3e42;
  --sl-color-neutral-300: #596067;
  --sl-color-neutral-400: #7f8992;
  --sl-color-neutral-500: #98a3ad;
  --sl-color-neutral-600: #b3bdc6;
  --sl-color-neutral-700: #c8d0d7;
  --sl-color-neutral-800: #d5dce2;
  --sl-color-neutral-900: #edf1f4;
  --sl-color-primary-50: #101f2c;
  --sl-color-primary-100: #18344d;
  --sl-color-primary-200: #244f70;
  --sl-color-primary-300: #336b92;
  --sl-color-primary-400: #4380ad;
  --sl-color-primary-500: #5592c6;
  --sl-color-primary-600: #70a8d8;
  --sl-color-primary-700: #91bee1;
  --sl-color-primary-800: #b7d4eb;
  --sl-color-primary-900: #dcebf6;
}

[data-theme="navy"] {
  --bg: #161923;
  --fg: #d3d5e3;
  --sidebar-bg: #212942;
  --accent: #6db4d8;
  --sl-color-neutral-0: #161923;
  --sl-color-neutral-50: #1c2131;
  --sl-color-neutral-100: #212942;
  --sl-color-neutral-200: #313b58;
  --sl-color-neutral-300: #56617b;
  --sl-color-neutral-400: #7f849e;
  --sl-color-neutral-500: #9da0b7;
  --sl-color-neutral-600: #bcbdd0;
  --sl-color-neutral-700: #d3d5e3;
  --sl-color-neutral-800: #e6e7ef;
  --sl-color-neutral-900: #f5f5f8;
  --sl-color-primary-50: #101e29;
  --sl-color-primary-100: #173446;
  --sl-color-primary-200: #20506a;
  --sl-color-primary-300: #2b6f91;
  --sl-color-primary-400: #3587aa;
  --sl-color-primary-500: #4197bd;
  --sl-color-primary-600: #6db4d8;
  --sl-color-primary-700: #91cae1;
  --sl-color-primary-800: #b9deed;
  --sl-color-primary-900: #ddf0f7;
}

[data-theme="ayu"] {
  --bg: #0f1419;
  --fg: #e6e1cf;
  --sidebar-bg: #14191f;
  --accent: #ffb454;
  --sl-color-neutral-0: #0f1419;
  --sl-color-neutral-50: #14191f;
  --sl-color-neutral-100: #1b222a;
  --sl-color-neutral-200: #2d3640;
  --sl-color-neutral-300: #4b5661;
  --sl-color-neutral-400: #6c7680;
  --sl-color-neutral-500: #929aa3;
  --sl-color-neutral-600: #b3b8be;
  --sl-color-neutral-700: #c5c9cd;
  --sl-color-neutral-800: #e0ded5;
  --sl-color-neutral-900: #f3f0e8;
  --sl-color-primary-50: #2b2216;
  --sl-color-primary-100: #49351b;
  --sl-color-primary-200: #765024;
  --sl-color-primary-300: #a76e30;
  --sl-color-primary-400: #cd8739;
  --sl-color-primary-500: #e69f45;
  --sl-color-primary-600: #ffb454;
  --sl-color-primary-700: #ffc678;
  --sl-color-primary-800: #ffd6a1;
  --sl-color-primary-900: #ffead0;
}

body,
.site-header,
.sidebar,
doc-toc,
.search-modal,
.site-footer {
  background: var(--bg);
  color: var(--fg);
  border-color: var(--sidebar-bg);
}

.sidebar,
doc-toc,
.site-footer,
.search-footer {
  background: var(--sidebar-bg);
}

.content a,
.footer-link {
  color: var(--accent);
}
