:root {
  --reading-progress: 0%;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f172a;
  --surface: #111827;
  --surface-muted: #1f2937;
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --border: #293548;
  --border-strong: #3b485d;
  --accent: #818cf8;
  --accent-strong: #a5b4fc;
  --accent-soft: #252b5c;
  --success-soft: #12372b;
  --header: #070b16;
}

html[data-theme="sepia"] {
  color-scheme: light;
  --bg: #f3ead8;
  --surface: #fffaf0;
  --surface-muted: #f7efdf;
  --text: #3f3528;
  --text-muted: #746452;
  --border: #dfd0b7;
  --border-strong: #cdbb9f;
  --accent: #8b5e34;
  --accent-strong: #68411f;
  --accent-soft: #f1dfc6;
  --success-soft: #e5ecd8;
  --header: #2f281f;
}

/* Ensure the theme variables visibly apply to surfaces that use fixed colors in the base stylesheet. */
html[data-theme="dark"] .site-header,
html[data-theme="sepia"] .site-header {
  background: color-mix(in srgb, var(--header) 96%, transparent);
}

html[data-theme="dark"] .content-card,
html[data-theme="sepia"] .content-card {
  border-color: var(--border);
}

html[data-theme="dark"] .content-prose h1,
html[data-theme="dark"] .content-prose h2,
html[data-theme="dark"] .content-prose h3,
html[data-theme="dark"] .content-prose h4,
html[data-theme="dark"] .content-prose strong,
html[data-theme="sepia"] .content-prose h1,
html[data-theme="sepia"] .content-prose h2,
html[data-theme="sepia"] .content-prose h3,
html[data-theme="sepia"] .content-prose h4,
html[data-theme="sepia"] .content-prose strong {
  color: var(--text);
}

/* Dark-theme safety rules for nested elements and browser-rendered Markdown content. */
html[data-theme="dark"] .content-prose h1 *,
html[data-theme="dark"] .content-prose h2 *,
html[data-theme="dark"] .content-prose h3 *,
html[data-theme="dark"] .content-prose h4 *,
html[data-theme="dark"] .content-prose h5 *,
html[data-theme="dark"] .content-prose h6 *,
html[data-theme="dark"] .content-prose h5,
html[data-theme="dark"] .content-prose h6 {
  color: var(--text) !important;
}

html[data-theme="dark"] .content-prose p,
html[data-theme="dark"] .content-prose li,
html[data-theme="dark"] .content-prose td,
html[data-theme="dark"] .content-prose dt,
html[data-theme="dark"] .content-prose dd {
  color: var(--text);
}

html[data-theme="dark"] .content-prose a {
  color: var(--accent-strong);
}

html[data-theme="dark"] .content-prose a:hover {
  color: #c7d2fe;
}

html[data-theme="dark"] .nav-section__title,
html[data-theme="sepia"] .nav-section__title,
html[data-theme="dark"] .sidebar-footer strong,
html[data-theme="sepia"] .sidebar-footer strong,
html[data-theme="dark"] .content-prose th,
html[data-theme="sepia"] .content-prose th {
  color: var(--text);
}

html[data-theme="dark"] .sidebar-search input:focus,
html[data-theme="sepia"] .sidebar-search input:focus {
  background: var(--surface);
}

html[data-theme="dark"] .content-prose blockquote {
  border-left-color: var(--accent);
  background: linear-gradient(90deg, #1e2347, #171d31);
  color: var(--text-muted);
}

html[data-theme="sepia"] .content-prose blockquote {
  border-left-color: var(--accent);
  background: linear-gradient(90deg, #f2e1c8, #fbf3e5);
  color: var(--text-muted);
}

html[data-theme="dark"] .content-prose code,
html[data-theme="sepia"] .content-prose code {
  border-color: var(--border);
  background: var(--surface-muted);
  color: var(--text);
}

html[data-theme="dark"] .content-prose pre code,
html[data-theme="sepia"] .content-prose pre code {
  background: transparent;
  color: inherit;
}

html[data-theme="dark"] .mermaid-diagram {
  background: linear-gradient(180deg, #f8fbff, #eef6ff);
  border-color: #dbe7f3;
}

html[data-theme="dark"] .mermaid-diagram,
html[data-theme="dark"] .mermaid-diagram *,
html[data-theme="dark"] .mermaid-diagram text,
html[data-theme="dark"] .mermaid-diagram tspan,
html[data-theme="dark"] .mermaid-diagram foreignObject,
html[data-theme="dark"] .mermaid-diagram foreignObject * {
  color: #172033 !important;
}

html[data-theme="dark"] .mermaid-diagram text,
html[data-theme="dark"] .mermaid-diagram tspan {
  fill: #172033 !important;
}

html[data-theme="sepia"] .mermaid-diagram {
  background: linear-gradient(180deg, #fffaf0, #f7efdf);
}

.mermaid-diagram {
  position: relative;
}

.mermaid-diagram__fullscreen {
  position: absolute;
  top: 12px;
  right: 12px;
  left: auto;
  z-index: 5;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.72);
  color: #344054;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.12);
  cursor: pointer;
  appearance: none;
  backdrop-filter: blur(6px);
}

.mermaid-diagram__fullscreen svg {
  display: block;
  width: 20px;
  height: 20px;
}

.mermaid-diagram__fullscreen:hover {
  background: rgba(255, 255, 255, 0.94);
  color: #101828;
}

.mermaid-diagram__fullscreen:focus-visible {
  outline: 2px solid #4f46e5;
  outline-offset: 2px;
}

html[data-theme="dark"] .mermaid-diagram__fullscreen {
  background: rgba(255, 255, 255, 0.82);
  color: #172033 !important;
}

html[data-theme="dark"] .mermaid-diagram__fullscreen:hover {
  background: #ffffff;
  color: #0f172a !important;
}

html[data-theme="sepia"] .mermaid-diagram__fullscreen {
  background: rgba(255, 250, 240, 0.88);
  color: #4f3d2b;
}

html[data-theme="sepia"] .mermaid-diagram__fullscreen:hover {
  background: #fffaf0;
  color: #2f281f;
}

.mermaid-diagram:fullscreen .mermaid-diagram__fullscreen {
  top: 18px;
  right: 18px;
  left: auto;
}

html[data-theme="dark"] .site-footer,
html[data-theme="dark"] .site-footer a,
html[data-theme="sepia"] .site-footer,
html[data-theme="sepia"] .site-footer a,
html[data-theme="dark"] .sidebar-footer,
html[data-theme="sepia"] .sidebar-footer {
  color: var(--text-muted);
}

.theme-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.theme-picker select {
  min-height: 38px;
  padding: 0 30px 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: #e4e7ec;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.theme-picker select:focus-visible,
.back-to-top:focus-visible,
.on-this-page a:focus-visible {
  outline: 3px solid rgba(129, 140, 248, 0.45);
  outline-offset: 2px;
}

.theme-picker option {
  color: #172033;
}

.reading-progress {
  position: fixed;
  top: var(--header-height);
  right: 0;
  bottom: 0;
  z-index: 90;
  width: 4px;
  pointer-events: none;
  background: rgba(148, 163, 184, 0.18);
}

.reading-progress__bar {
  width: 100%;
  height: var(--reading-progress);
  background: var(--accent);
  transition: height 0.08s linear;
}

.back-to-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 95;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease, background 0.18s ease;
}

.back-to-top:hover {
  background: var(--surface-muted);
}

.back-to-top.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.on-this-page {
  position: fixed;
  top: calc(var(--header-height) + 28px);
  right: 28px;
  z-index: 70;
  width: 220px;
  max-height: calc(100vh - var(--header-height) - 56px);
  overflow-y: auto;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px);
}

.on-this-page__title {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.on-this-page ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.on-this-page li + li {
  margin-top: 4px;
}

.on-this-page a {
  display: block;
  padding: 5px 7px;
  border-radius: 7px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.35;
  transition: background 0.15s ease, color 0.15s ease;
}

.on-this-page a:hover,
.on-this-page a.is-active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.on-this-page .toc-level-3 a {
  padding-left: 18px;
  font-size: 12px;
}

@media (min-width: 1280px) {
  .content-wrap.has-on-this-page {
    padding-right: 276px;
  }
}

@media (max-width: 1279px) {
  .on-this-page {
    display: none;
  }
}

@media (max-width: 760px) {
  .theme-picker select {
    width: 44px;
    padding: 0;
    color: transparent;
  }

  .theme-picker::after {
    content: "◐";
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: #e4e7ec;
    pointer-events: none;
  }

  .back-to-top {
    right: 16px;
    bottom: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .reading-progress__bar,
  .back-to-top {
    transition: none;
  }
}