:root {
  color-scheme: light dark;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-strong: #eef3ff;
  --text: #182033;
  --muted: #5c667d;
  --border: #d8deea;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --code-bg: #101827;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.10);
  --radius: 1rem;
  --sidebar-width: 19rem;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --surface: #121a2d;
    --surface-strong: #17223a;
    --text: #edf2ff;
    --muted: #b7c2d8;
    --border: #293653;
    --accent: #78a6ff;
    --accent-strong: #a8c4ff;
    --shadow: 0 18px 45px rgba(0, 0, 0, 0.32);
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: radial-gradient(circle at top left, color-mix(in srgb, var(--accent) 14%, transparent), transparent 32rem), var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.65;
}

a { color: var(--accent); text-underline-offset: 0.18em; }
a:hover { color: var(--accent-strong); }
a:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: 0.25rem;
}

.container { width: min(1120px, calc(100% - 2rem)); margin: 0 auto; }
.skip-link {
  position: absolute;
  left: 1rem;
  top: 0.75rem;
  z-index: 20;
  transform: translateY(-140%);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.6rem 0.9rem;
  border-radius: 999px;
}
.skip-link:focus { transform: translateY(0); }

.site-header { padding: 5rem 0 3rem; }
.hero {
  background: linear-gradient(135deg, color-mix(in srgb, var(--surface) 88%, var(--accent)), var(--surface));
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 1.5);
  box-shadow: var(--shadow);
  padding: clamp(2rem, 6vw, 4.5rem);
}
h1, h2, h3 { line-height: 1.16; margin: 0 0 0.65em; }
h1 { font-size: clamp(2.2rem, 7vw, 4.9rem); letter-spacing: -0.055em; }
h2 { font-size: clamp(1.45rem, 3vw, 2rem); letter-spacing: -0.025em; }
.lead { color: var(--muted); font-size: clamp(1.1rem, 2vw, 1.35rem); max-width: 70ch; }
.eyebrow { color: var(--accent); font-size: 0.78rem; font-weight: 700; letter-spacing: 0.11em; margin: 0 0 0.7rem; text-transform: uppercase; }

.intro-panel, .chapter-section, .metadata-card, .chapter-card {
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.05);
}
.intro-panel { margin-bottom: 2rem; padding: 1.5rem; }
.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin: 1rem 0 4rem;
}
.chapter-card { padding: 1.35rem; display: flex; flex-direction: column; gap: 0.55rem; }
.chapter-card h2 { font-size: 1.35rem; margin-bottom: 0; }
.chapter-card p { margin: 0; }
.component-list summary { cursor: pointer; color: var(--muted); font-weight: 700; }
.component-list ul, .tag-list { display: flex; flex-wrap: wrap; gap: 0.45rem; list-style: none; margin: 0.75rem 0 0; padding: 0; }
.component-list li, .tag-list li {
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.86rem;
  padding: 0.2rem 0.55rem;
}

.page-shell { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: color-mix(in srgb, var(--surface) 94%, var(--accent));
  border-right: 1px solid var(--border);
}
.sidebar-inner { position: sticky; top: 0; max-height: 100vh; overflow-y: auto; padding: 1.25rem; }
.site-title { display: inline-block; color: var(--text); font-weight: 800; margin-bottom: 1rem; text-decoration: none; }
.chapter-nav ol { list-style: none; margin: 0; padding: 0; }
.chapter-nav a {
  align-items: flex-start;
  border-radius: 0.75rem;
  color: var(--text);
  display: flex;
  gap: 0.7rem;
  padding: 0.65rem 0.75rem;
  text-decoration: none;
}
.chapter-nav a:hover, .chapter-nav a.is-current { background: var(--surface-strong); color: var(--accent-strong); }
.chapter-number { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: 0.85rem; }

.content-shell { min-width: 0; }
.chapter-header { border-bottom: 1px solid var(--border); padding: clamp(2rem, 5vw, 4rem); }
.breadcrumb { color: var(--muted); font-size: 0.95rem; margin-bottom: 1rem; }
.chapter-main { margin: 0 auto; max-width: 980px; padding: clamp(1.25rem, 4vw, 3rem); }
.chapter-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.metadata-card { padding: 1rem; }
.metadata-card h2 { font-size: 1rem; margin-bottom: 0.75rem; }
.metadata-card ol, .metadata-card ul { margin: 0; padding-left: 1.15rem; }
.chapter-section { margin: 1.25rem 0; padding: clamp(1.25rem, 3vw, 2rem); scroll-margin-top: 1.25rem; }
.anchor-link { color: inherit; text-decoration: none; }
.anchor-link:hover::after { content: " #"; color: var(--accent); }
.section-content { min-height: 5rem; }
.pending-note {
  background: color-mix(in srgb, var(--accent) 9%, transparent);
  border: 1px dashed color-mix(in srgb, var(--accent) 55%, var(--border));
  border-radius: 0.75rem;
  color: var(--muted);
  margin: 0;
  padding: 1rem;
}

pre {
  background: var(--code-bg);
  border-radius: 0.85rem;
  color: #e8eefc;
  overflow-x: auto;
  padding: 1rem;
}
code { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: 0.95em; }
:not(pre) > code { background: color-mix(in srgb, var(--accent) 10%, transparent); border-radius: 0.3rem; padding: 0.1rem 0.25rem; }
.code-block { position: relative; }
.copy-code {
  position: absolute;
  right: 0.65rem;
  top: 0.65rem;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  color: #0f172a;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
}

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 2rem 0 1rem; }
.pager-link { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; text-decoration: none; }
.pager-link[rel="next"] { text-align: right; }
.pager-link.is-disabled { color: var(--muted); }
.site-footer { border-top: 1px solid var(--border); color: var(--muted); margin-top: 2rem; padding: 1.5rem 0; }
.chapter-footer { padding: 1.5rem clamp(1.25rem, 4vw, 3rem); }
.sidebar-toggle { display: none; }

@media (max-width: 860px) {
  .page-shell { display: block; }
  .sidebar-toggle {
    display: inline-flex;
    position: fixed;
    z-index: 30;
    right: 1rem;
    bottom: 1rem;
    background: var(--accent);
    border: 0;
    border-radius: 999px;
    color: white;
    cursor: pointer;
    font-weight: 700;
    padding: 0.75rem 1rem;
    box-shadow: var(--shadow);
  }
  .sidebar {
    bottom: 0;
    left: 0;
    max-width: 22rem;
    position: fixed;
    top: 0;
    transform: translateX(-105%);
    transition: transform 180ms ease;
    width: min(86vw, var(--sidebar-width));
    z-index: 25;
  }
  .sidebar.is-open { transform: translateX(0); }
  .chapter-header { padding-top: 3rem; }
  .pager { grid-template-columns: 1fr; }
  .pager-link[rel="next"] { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
