:root {
  --accent: #7658b2;
  --accent-ink: #6849a2;
  --surface: #fff;
  --hero: #191624;
  --quiet: var(--muted);
  --art-tint: none;
  --soft: color-mix(in srgb, var(--accent) 6%, var(--surface));
  --tint: color-mix(in srgb, var(--accent) 11%, var(--surface));
  --edge: color-mix(in srgb, var(--accent) 34%, var(--surface));
  --highlight: color-mix(in srgb, var(--accent) 48%, white);
  --code-bg: color-mix(in srgb, var(--hero) 94%, white);
  --prose: color-mix(in srgb, var(--ink) 92%, var(--surface));
  --purple: var(--accent-ink);
}
:root[data-theme="forest"] {
  --ink: #1b302b;
  --muted: #4a635a;
  --surface: #fdfffd;
  --rule: #d2e1d7;
}
:root[data-theme="vermilion"] {
  --ink: #332528;
  --muted: #6f5559;
  --surface: #fffdfc;
  --rule: #e8d9d9;
}
:root[data-theme="midnight"] {
  color-scheme: dark;
  --ink: #e5edf8;
  --muted: #acb9cb;
  --surface: #192333;
  --rule: #344256;
  --code-bg: #0d141e;
}

/* Navigation, reading surfaces and illustrations share the active palette. */
.top, .skip, dialog, .topic-panel, .topic-card, kbd { background: var(--surface); }
.brand b, .nav a, .row-body p, .item-meta, .count, .foot, .foot-brand strong,
.section-name span, .aside-head small, .author-panel div > span, .author-panel p,
.list-year span, .crumb, .toc a, .post-end, #search-status { color: var(--quiet); }
.brand b, kbd, .topic-row, .result { border-color: var(--rule); }
.nav a[aria-current], .nav a:hover, .text-link:hover, .row-body h3 a:hover,
footer a:hover, .crumb a:hover, .toc a:hover, .topic-row:hover strong,
.aside-head, .author-panel > a, .kicker, .prose a, .post-end a { color: var(--accent-ink); }
.nav a[aria-current]::after, .section-name i { background: var(--accent-ink); }
.brandmark, .hero-art img { filter: var(--art-tint); }
.hero { background: var(--hero); }
.hero::before {
  background-image: radial-gradient(ellipse at -5% 100%, color-mix(in srgb, var(--accent) 20%, transparent), transparent 65%),
                    radial-gradient(circle, #ffffff15 .8px, transparent 1px);
}
.feature-label, .plate-label { color: color-mix(in srgb, var(--highlight) 72%, white); }
.feature-label span, .item-meta i { background: var(--edge); }
.title-dot { color: var(--highlight); }
.hero-text p { color: #e1dfe4; }
.hero-cta { background: color-mix(in srgb, var(--accent) 8%, white); color: #272531; }
.hero-cta:hover { background: color-mix(in srgb, var(--accent) 20%, white); }
.author-panel { background: linear-gradient(120deg, var(--tint), var(--surface)); }
.avatar { color: #fff; background: color-mix(in srgb, var(--accent) 40%, #151922); }
.toc, footer { background: var(--soft); }
.search-trigger, .iconbtn { color: var(--muted); background: var(--soft); border-color: var(--rule); }
.search-trigger:hover { border-color: var(--edge); }
.search-field, .search-field:focus-within { border-color: var(--accent-ink); }
.search-field:focus-within { box-shadow: 0 0 0 2px var(--tint); }
kbd { color: var(--quiet); }
.prose { color: var(--prose); }
.prose blockquote { background: var(--soft); border-color: var(--accent-ink); }
.prose pre { background: var(--code-bg); color: #eef2f8; }
.prose a, .post-end a, .author-panel > a { text-decoration-color: var(--edge); }
:root[data-theme="midnight"] .tag.agents, :root[data-theme="midnight"] .topic-symbol.inference { background: #352d46; color: #dcc8ff; }
:root[data-theme="midnight"] .tag.training, :root[data-theme="midnight"] .topic-symbol.training { background: #223e35; color: #ade4cc; }
:root[data-theme="midnight"] .tag.inference, :root[data-theme="midnight"] .topic-symbol.agents { background: #243952; color: #b9d7ff; }
:root[data-theme="midnight"] .tag.notes, :root[data-theme="midnight"] .topic-symbol.notes { background: #45362a; color: #eed2ab; }
a:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible { outline-color: var(--accent-ink); }

.head-tools { display: flex; align-items: center; gap: 8px; }
.theme-picker { position: relative; }
.theme-picker summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 35px;
  padding: 7px 10px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  color: var(--accent-ink);
  font-size: 14px;
  line-height: 1.4;
  user-select: none;
  white-space: nowrap;
}
.theme-picker summary::-webkit-details-marker { display: none; }
.theme-picker[open] summary, .theme-picker summary:hover { border-color: var(--edge); background: var(--tint); }
.theme-popover {
  position: absolute;
  z-index: 12;
  right: 0;
  top: calc(100% + 12px);
  width: min(312px, calc(100vw - 32px));
  padding: 18px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 12px;
  box-shadow: 0 12px 40px #12152126, 0 2px 8px #1215210a;
  max-height: calc(100dvh - 74px);
  overflow-y: auto;
}
.theme-popover fieldset { border: 0; margin: 0; padding: 0; min-inline-size: 0; }
.theme-popover legend { padding: 0 0 11px; font-size: 16px; font-weight: 680; }
.theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.theme-choice { cursor: pointer; position: relative; }
.theme-choice input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.theme-tile {
  display: block;
  padding: 8px 10px 7px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 7px;
}
.theme-choice:hover .theme-tile { border-color: var(--edge); }
.theme-choice input:checked + .theme-tile { border-color: var(--accent-ink); background: var(--soft); }
.theme-choice input:focus-visible + .theme-tile { outline: 2px solid var(--accent-ink); outline-offset: 2px; }
.color-strip {
  display: block;
  height: 12px;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px #0000000f;
  background: linear-gradient(90deg, var(--sample-contrast) 30%, var(--sample-accent) 30% 65%, var(--sample-paper) 65%);
}
.tile-name { display: flex; align-items: center; justify-content: space-between; margin-top: 5px; font-size: 14px; }
.selected-mark { display: inline-flex; visibility: hidden; color: var(--accent-ink); }
.theme-choice input:checked + .theme-tile .selected-mark { visibility: visible; }
.accent-heading {
  margin: 15px 0 7px;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 600;
}
.accent-heading button { background: none; color: var(--accent-ink); border: 0; padding: 3px 0 3px 8px; font-size: 13px; }
.accent-heading button:disabled { color: var(--muted); opacity: .7; cursor: default; }
.accent-inputs { display: flex; gap: 8px; align-items: stretch; }
.accent-inputs input {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 6px;
}
#accent-color { width: 42px; height: 36px; cursor: pointer; padding: 4px; }
#accent-color::-webkit-color-swatch-wrapper { padding: 0; }
#accent-color::-webkit-color-swatch { border-radius: 3px; border: 1px solid #0002; }
#accent-hex { flex: 1; min-width: 0; padding: 4px 10px; font: 14px var(--mono); }
#accent-hex[aria-invalid="true"] { border-color: var(--accent-ink); }
#accent-error { display: block; color: var(--ink); font-size: 12px; margin-top: 6px; }
#accent-error[hidden] { display: none; }

@media (max-width: 620px) {
  .head {
    height: auto;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "brand tools" "nav nav";
    gap: 0 12px;
    padding-top: 9px;
  }
  .head .brand { grid-area: brand; justify-self: start; }
  .head-tools { grid-area: tools; }
  .nav { grid-area: nav; width: 100%; justify-content: space-between; gap: 12px; }
  .nav a { padding: 7px 2px 9px; font-size: 14px; }
  .nav a[aria-current]::after { bottom: 2px; }
  .head-tools .search-trigger { background: transparent; border: 0; padding: 8px; }
  .search-trigger span, .search-trigger kbd { display: none; }
  .theme-picker summary { min-height: 34px; padding: 6px 9px; }
}
