:root,
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1419;
  --bg-glow: #1a2430;
  --surface: #171e27;
  --ink: #e8eef4;
  --muted: #9aa7b5;
  --line: #2a3542;
  --brand: #3ecfb4;
  --brand-soft: rgba(62, 207, 180, 0.16);
  --brand-strong: #2aa890;
  --accent: #e08a4f;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --header-bg: rgba(15, 20, 25, 0.88);
  --code-bg: #0b1016;
  --code-ink: #e8eef4;
  --inline-code-bg: #243041;
  --figure-bg: #121820;
  --tag-bg: #243041;
  --badge-bg: #4f6b3a;
  --badge-ink: #f4f7f2;
  --radius: 14px;
  --max: 1120px;
  --sidebar: 260px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, monospace;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f4ef;
  --bg-glow: #efe7d8;
  --surface: #ffffff;
  --ink: #1c2430;
  --muted: #5b6675;
  --line: #d9d2c5;
  --brand: #0f6b5c;
  --brand-soft: #d8efe9;
  --brand-strong: #0c564a;
  --accent: #c45c26;
  --shadow: 0 10px 30px rgba(28, 36, 48, 0.08);
  --header-bg: rgba(246, 244, 239, 0.9);
  --code-bg: #152029;
  --code-ink: #e8eef4;
  --inline-code-bg: #eef2f5;
  --figure-bg: #fbfaf7;
  --tag-bg: #eef2f5;
  --badge-bg: #8da363;
  --badge-ink: #ffffff;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, var(--bg-glow) 0, transparent 32%),
    linear-gradient(180deg, var(--bg-glow) 0%, var(--bg) 100%);
  min-height: 100vh;
  line-height: 1.65;
  transition: background-color 0.2s ease, color 0.2s ease;
}

a {
  color: var(--brand);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}

a:hover {
  color: var(--accent);
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(10px);
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
}

.header-inner,
.footer-inner,
.shell {
  width: min(var(--max), calc(100% - 2rem));
  margin-inline: auto;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-height: 4rem;
  flex-wrap: wrap;
}

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

.brand {
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}

.main-nav ul,
.lang-switcher ul,
.plain-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.main-nav a,
.lang-switcher a {
  text-decoration: none;
  color: var(--muted);
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
}

.main-nav a:hover,
.lang-switcher a:hover,
.main-nav a.active,
.lang-switcher a.active {
  color: var(--brand);
  background: var(--brand-soft);
}

.lang-switcher {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
}

.lang-label {
  color: var(--muted);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.theme-toggle:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.theme-toggle-icon {
  display: inline-flex;
  width: 18px;
  height: 18px;
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  display: none;
}

html[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

html[data-theme="light"] .theme-toggle .icon-moon {
  display: block;
}

.shell {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  padding: 1.5rem 0 3rem;
}

.page-inner .shell {
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 5rem;
  align-self: start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.sidebar-title {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.chapter-nav {
  margin: 0;
  padding-left: 1.1rem;
  display: grid;
  gap: 0.45rem;
}

.chapter-nav a {
  text-decoration: none;
  color: var(--ink);
}

.chapter-nav a.active,
.chapter-nav a[aria-current="page"] {
  color: var(--brand);
  font-weight: 600;
}

.sidebar-cta {
  display: inline-block;
  margin-top: 1rem;
  padding: 0.55rem 0.8rem;
  border-radius: 999px;
  background: var(--brand);
  color: white;
  text-decoration: none;
  font-size: 0.92rem;
}

.sidebar-cta:hover {
  background: var(--brand-strong);
  color: white;
}

.content {
  min-width: 0;
}

.hero,
.page-header,
.card,
.chapter-item,
.toc,
.chapter-page,
.single-page-view,
.home-intro {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero,
.page-header,
.chapter-page,
.single-page-view,
.home-intro {
  padding: 1.5rem;
}

.hero {
  margin-bottom: 1.25rem;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--brand) 14%, transparent), transparent 55%),
    var(--surface);
}

.badge {
  display: inline-block;
  margin: 0 0 0.75rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--badge-ink);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.hero h1,
.page-header h1,
.chapter-page h1 {
  margin: 0 0 0.6rem;
  font-size: clamp(1.8rem, 3vw, 2.5rem);
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.lede {
  color: var(--muted);
  font-size: 1.08rem;
  max-width: 48rem;
}

.hero-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 1.05rem;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 600;
}

.btn.primary {
  background: var(--brand);
  color: white;
}

.btn.primary:hover {
  background: var(--brand-strong);
  color: white;
}

.btn.ghost {
  border: 1px solid var(--line);
  color: var(--ink);
  background: transparent;
}

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

.card,
.chapter-item {
  padding: 1.15rem;
}

.card-meta,
.eyebrow,
.meta,
.muted,
.chapter-source {
  color: var(--muted);
  font-size: 0.92rem;
}

.card h2,
.chapter-item h2 {
  margin: 0.2rem 0 0.55rem;
  font-size: 1.2rem;
  line-height: 1.3;
}

.card h2 a,
.chapter-item h2 a {
  color: inherit;
  text-decoration: none;
}

.text-link {
  font-weight: 600;
  text-decoration: none;
}

.chapter-list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: grid;
  gap: 1rem;
}

.chapter-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.7rem;
  height: 1.7rem;
  margin-right: 0.35rem;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 0.85rem;
  font-weight: 700;
}

.prose {
  max-width: 70ch;
}

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

.prose p {
  margin: 0 0 1rem;
}

.prose h2,
.prose h3,
.prose h4 {
  line-height: 1.3;
  letter-spacing: -0.02em;
  margin: 1.75rem 0 0.75rem;
  scroll-margin-top: 5rem;
}

.prose h2 {
  font-size: 1.4rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--line);
}

.prose h3 {
  font-size: 1.15rem;
  color: var(--ink);
}

.prose h4 {
  font-size: 1.02rem;
  color: var(--muted);
  text-transform: none;
}

.prose ul,
.prose ol {
  margin: 0 0 1.1rem;
  padding-left: 1.35rem;
  display: grid;
  gap: 0.45rem;
}

.prose li {
  padding-left: 0.15rem;
}

.prose li > ul,
.prose li > ol {
  margin-top: 0.45rem;
  margin-bottom: 0.2rem;
}

.prose strong {
  font-weight: 700;
  color: var(--ink);
}

.prose hr {
  border: 0;
  border-top: 1px dashed var(--line);
  margin: 1.75rem 0;
}

.prose pre,
.prose code {
  font-family: var(--mono);
}

.prose pre {
  overflow-x: auto;
  padding: 1rem;
  border-radius: 10px;
  background: var(--code-bg);
  color: var(--code-ink);
  margin: 0 0 1.1rem;
}

.prose :not(pre) > code {
  background: var(--inline-code-bg);
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
  font-size: 0.92em;
}

.prose blockquote {
  margin: 0 0 1.1rem;
  padding: 0.35rem 0 0.35rem 1rem;
  border-left: 4px solid var(--brand);
  color: var(--muted);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 1.25rem;
  font-size: 0.95rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.prose th,
.prose td {
  border: 1px solid var(--line);
  padding: 0.55rem 0.7rem;
  text-align: left;
  vertical-align: top;
}

.prose th {
  background: var(--brand-soft);
  font-weight: 700;
}

.prose dl {
  margin: 0 0 1.25rem;
  display: grid;
  gap: 0.85rem;
}

.prose dt {
  font-weight: 700;
  margin: 0;
}

.prose dd {
  margin: 0.25rem 0 0;
  color: var(--muted);
  padding-left: 0.1rem;
}

.term-list {
  list-style: none;
  margin: 0 0 1.25rem;
  padding: 0;
  display: grid;
  gap: 0.9rem;
}

.term-list li {
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 88%, var(--brand-soft));
}

.term-list strong {
  display: inline;
}

.content-figure {
  margin: 1.25rem 0;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--figure-bg);
}

.content-figure img {
  border-radius: 8px;
  margin-inline: auto;
}

.content-figure figcaption {
  margin-top: 0.55rem;
  color: var(--muted);
  font-size: 0.92rem;
  text-align: center;
}

.tags {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
}

.tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--tag-bg);
  font-size: 0.82rem;
}

.pager {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.75rem;
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  align-items: center;
}

.pager-next {
  text-align: right;
}

.pager a {
  text-decoration: none;
  font-weight: 600;
}

.toc {
  padding: 1rem 1.25rem;
  margin: 1rem 0 1.5rem;
}

.toc h2 {
  margin: 0 0 0.6rem;
  font-size: 1rem;
}

.toc ol {
  margin: 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 0.35rem;
}

.combined-chapter {
  padding-top: 0.5rem;
  margin-top: 1.5rem;
  border-top: 1px dashed var(--line);
  max-width: none;
}

.combined-chapter:first-of-type {
  border-top: 0;
}

.site-footer {
  border-top: 1px solid var(--line);
  padding: 1.5rem 0 2rem;
  color: var(--muted);
  font-size: 0.95rem;
}

@media (max-width: 860px) {
  .page-inner .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .pager {
    grid-template-columns: 1fr;
  }

  .pager-next {
    text-align: left;
  }

  .header-controls {
    width: 100%;
    margin-left: 0;
  }
}
