:root {
  --paper: #f7f5f0;
  --panel: #ffffff;
  --panel-subtle: #eeece6;
  --panel-warm: #fbf7ee;
  --ink: #282724;
  --heading: #1f211f;
  --muted: #68645d;
  --line: #d8d3c8;
  --teal: #3b746e;
  --teal-dark: #275652;
  --berry: #8f2d46;
  --gold: #9a6b1d;
  --code-bg: #20211f;
  --code-text: #f4f1e9;
  --focus-ring: rgba(59, 116, 110, 0.34);
  --backdrop: rgba(28, 28, 25, 0.38);
  --shadow: 0 18px 45px rgba(38, 38, 31, 0.12);
  --sidebar-width: 318px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --paper: #121313;
  --panel: #1c1d1d;
  --panel-subtle: #171818;
  --panel-warm: #211f1b;
  --ink: #e8e4dc;
  --heading: #f4efe6;
  --muted: #aaa39a;
  --line: #353532;
  --teal: #7ca7a1;
  --teal-dark: #a8c5bf;
  --berry: #d48a9b;
  --gold: #d4b06a;
  --code-bg: #0d0e0e;
  --code-text: #eee9df;
  --focus-ring: rgba(124, 167, 161, 0.34);
  --backdrop: rgba(0, 0, 0, 0.58);
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.34);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.65;
}
a { color: var(--teal-dark); }
a:hover { color: var(--berry); }
a:focus-visible,
button:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  transform: translateY(-150%);
  z-index: 60;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--panel);
  color: var(--teal-dark);
  font-weight: 800;
  box-shadow: var(--shadow);
}
.skip-link:focus { transform: translateY(0); }

.reading-progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 4px;
  background: transparent;
  z-index: 30;
}
.reading-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--gold), var(--berry));
}

.book-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  padding: 26px 18px;
  overflow-y: auto;
  background: var(--panel-subtle);
  border-right: 1px solid var(--line);
  z-index: 20;
}
.book-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 24px;
}
.book-brand img { width: 42px; height: 42px; object-fit: contain; }
.book-brand-text {
  display: grid;
  gap: 3px;
}
.book-version {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: -4px 0 20px;
}
.source-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 1.42rem;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
}
.source-link:hover {
  color: var(--teal-dark);
}
.source-link svg {
  flex: 0 0 auto;
}

.theme-toggle {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 999px;
  padding: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.theme-toggle:hover {
  color: var(--teal-dark);
}
.theme-toggle-icon {
  display: inline-grid;
  place-items: center;
  font-size: 1.55rem;
  line-height: 1;
}
:root[data-theme="dark"] .theme-toggle-icon {
  color: var(--teal-dark);
}

.search-label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
  margin-bottom: 8px;
}
.pagefind-search-shell { margin-bottom: 18px; }
.pagefind-search-shell pagefind-modal-trigger {
  --pagefind-ui-primary: var(--teal-dark);
  --pagefind-ui-text: var(--ink);
  --pagefind-ui-background: var(--panel);
  --pagefind-ui-border: var(--line);
  --pagefind-ui-border-radius: 8px;
  --pagefind-ui-font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  display: block;
}
.pagefind-search-shell pagefind-modal {
  --pagefind-ui-primary: var(--teal-dark);
  --pagefind-ui-text: var(--ink);
  --pagefind-ui-background: var(--panel);
  --pagefind-ui-border: var(--line);
  --pagefind-ui-tag: var(--panel-subtle);
  --pagefind-ui-border-radius: 8px;
  --pagefind-ui-font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.chapter-nav {
  display: grid;
  gap: 6px;
  margin-top: 18px;
}
.chapter-group {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  line-height: 1.2;
  margin: 14px 10px 2px;
  text-transform: uppercase;
}
.chapter-link {
  display: grid;
  grid-template-columns: 44px 1fr;
  align-items: start;
  min-height: 44px;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.84rem;
  line-height: 1.22;
  overflow-wrap: anywhere;
}
.chapter-link span:last-child { padding-top: 4px; }
.chapter-link:hover,
.chapter-link.active {
  background: var(--panel);
  color: var(--teal-dark);
  box-shadow: 0 1px 0 rgba(59, 116, 110, 0.12);
}
.chapter-code {
  display: inline-grid;
  place-items: center;
  min-width: 36px;
  height: 28px;
  border-radius: 999px;
  background: #ddebe7;
  color: var(--teal-dark);
  font-size: 0.76rem;
  font-weight: 800;
}
:root[data-theme="dark"] .chapter-code {
  background: #27302e;
  color: #b7d0cb;
}

.book-main {
  min-height: 100vh;
  margin-left: var(--sidebar-width);
}
.nav-toggle {
  display: none;
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 35;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--panel);
  color: var(--teal-dark);
  font-weight: 800;
  box-shadow: var(--shadow);
}
.nav-backdrop { display: none; }

.book-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 520px);
  align-items: center;
  column-gap: clamp(28px, 5vw, 72px);
  row-gap: 12px;
  min-height: 72vh;
  padding: clamp(38px, 7vw, 86px);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(135deg, var(--panel) 0%, var(--panel-subtle) 54%, rgba(159, 18, 57, 0.08) 100%);
}
.hero-title {
  grid-column: 1 / -1;
  font-size: clamp(2rem, 4vw, 3.8rem);
}
.author-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 700;
}
.author-links {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.author-links a {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: var(--teal-dark);
  text-decoration: none;
}
.author-links a:hover {
  background: var(--panel-subtle);
  color: var(--berry);
}
.author-links svg { display: block; }
.book-hero-copy {
  max-width: 760px;
  margin-top: clamp(10px, 2vw, 24px);
}
.eyebrow {
  margin: 0 0 12px;
  color: var(--berry);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}
h1, h2, h3, h4 {
  color: var(--heading);
  line-height: 1.18;
  letter-spacing: 0;
}
h1 { margin: 0; font-size: clamp(2.25rem, 5vw, 4.9rem); }
h2 { font-size: clamp(1.7rem, 3vw, 2.6rem); }
.lede,
.chapter-summary {
  max-width: 760px;
  color: var(--muted);
  font-size: 1.14rem;
}
.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 28px;
}
.primary-action,
.secondary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  min-width: 164px;
  border-radius: 8px;
  padding: 0 18px;
  font-weight: 800;
  text-decoration: none;
}
.primary-action { background: var(--teal-dark); color: #fff; }
.primary-action:hover { background: var(--berry); color: #fff; }
.secondary-action { border: 1px solid var(--line); background: var(--panel); color: var(--teal-dark); }
.hero-image {
  width: 100%;
  max-height: 480px;
  object-fit: contain;
}

.chapter-grid-section { padding: clamp(34px, 6vw, 74px); }
.section-heading { max-width: 900px; margin-bottom: 24px; }
.section-heading h2 { margin: 0; }
.chapter-group-section + .chapter-group-section { margin-top: 34px; }
.chapter-grid-heading {
  color: var(--heading);
  font-size: 1.3rem;
  line-height: 1.2;
  margin: 0 0 14px;
}
.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 14px;
}
.chapter-card {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 12px;
  min-height: 210px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  text-decoration: none;
  box-shadow: 0 8px 22px rgba(44, 47, 43, 0.06);
}
.chapter-card:hover {
  border-color: rgba(59, 116, 110, 0.48);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.chapter-card strong { font-size: 1.16rem; line-height: 1.25; }
.chapter-card span:last-child { color: var(--muted); }

.chapter-page {
  width: min(100%, 1040px);
  margin: 0 auto;
  padding: clamp(32px, 6vw, 74px) clamp(20px, 5vw, 72px) 58px;
}
.chapter-header {
  margin-bottom: 24px;
  padding-bottom: 26px;
  border-bottom: 1px solid var(--line);
}
.chapter-header h1 { font-size: clamp(2rem, 4vw, 4.1rem); }
.back-link {
  display: inline-flex;
  margin-bottom: 22px;
  color: var(--teal-dark);
  font-weight: 800;
  text-decoration: none;
}
.chapter-toc {
  display: grid;
  gap: 7px;
  margin: 0 0 32px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.chapter-toc strong {
  color: var(--teal-dark);
  font-size: 0.9rem;
}
.chapter-toc a {
  color: var(--ink);
  line-height: 1.3;
  text-decoration: none;
}
.chapter-toc a:hover { color: var(--berry); }
.chapter-toc .toc-h4 { padding-left: 16px; color: var(--muted); }

.notebook-content { padding: 0; background: transparent; }
.notebook-content .cell { margin: 0 0 18px; }
.notebook-content .prompt { display: none; }
.notebook-content .inner_cell,
.notebook-content .text_cell_render { width: 100%; }
.notebook-content p { margin: 0 0 1rem; }
.notebook-content img { max-width: 100%; height: auto; }
.notebook-content blockquote {
  margin: 24px 0;
  padding: 18px 22px;
  border-left: 4px solid var(--gold);
  background: var(--panel-warm);
  color: var(--ink);
}
.notebook-content table {
  display: block;
  width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 22px 0;
  background: var(--panel);
  border: 1px solid var(--line);
}
.notebook-content th,
.notebook-content td {
  padding: 12px 14px;
  border: 1px solid var(--line);
  vertical-align: top;
}
.notebook-content th {
  background: var(--panel-subtle);
  color: var(--teal-dark);
}
.notebook-content code,
.notebook-content pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.notebook-content pre {
  overflow-x: auto;
  padding: 16px;
  border-radius: 8px;
  background: var(--code-bg);
  color: var(--code-text);
}
.notebook-content .highlight.hl-csharp pre {
  color: #d4d4d4;
  font-size: 0.86rem;
  line-height: 1.45;
}
.notebook-content .highlight.hl-csharp .k,
.notebook-content .highlight.hl-csharp .kt { color: #569cd6; }
.notebook-content .highlight.hl-csharp .s,
.notebook-content .highlight.hl-csharp .s1,
.notebook-content .highlight.hl-csharp .s2,
.notebook-content .highlight.hl-csharp .se { color: #ce9178; }
.notebook-content .highlight.hl-csharp .c,
.notebook-content .highlight.hl-csharp .c1,
.notebook-content .highlight.hl-csharp .cm { color: #6a9955; }
.notebook-content .highlight.hl-csharp .n { color: #d4d4d4; }
.notebook-content .highlight.hl-csharp .na,
.notebook-content .highlight.hl-csharp .nf { color: #dcdcaa; }
.notebook-content .highlight.hl-csharp .nn { color: #4ec9b0; }
.notebook-content .highlight.hl-csharp .mi,
.notebook-content .highlight.hl-csharp .mf { color: #b5cea8; }
.notebook-content .highlight.hl-csharp .p,
.notebook-content .highlight.hl-csharp .o { color: #c8c8c8; }
.notebook-content h2,
.notebook-content h3,
.notebook-content h4 { position: relative; }
.anchor-link {
  color: #a0a09a;
  text-decoration: none;
  padding-left: 0.35rem;
}
.section-copy {
  margin-left: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px 7px;
  background: var(--panel);
  color: var(--teal-dark);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 800;
  vertical-align: middle;
}

.chapter-pager {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 48px;
  padding-top: 26px;
  border-top: 1px solid var(--line);
}
.pager-link {
  display: grid;
  gap: 4px;
  min-height: 88px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  text-decoration: none;
}
.pager-link span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}
.pager-link strong { line-height: 1.25; }
.pager-link.align-right { text-align: right; }
.pager-link:not(.disabled):hover { border-color: var(--teal); box-shadow: var(--shadow); }
.pager-link.disabled { opacity: 0.48; }

@media (max-width: 900px) {
  .book-sidebar {
    transform: translateX(-100%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }
  body.nav-open .book-sidebar { transform: translateX(0); }
  .book-main { margin-left: 0; }
  .nav-toggle { display: inline-flex; align-items: center; }
  body.nav-open .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: var(--backdrop);
    z-index: 15;
  }
  .book-hero {
    grid-template-columns: 1fr;
    min-height: auto;
    padding-top: 78px;
  }
  .hero-image { max-height: 340px; }
}

@media (max-width: 620px) {
  :root { --sidebar-width: min(86vw, 318px); }
  h1 { font-size: 2.25rem; }
  .book-hero,
  .chapter-grid-section { padding-left: 20px; padding-right: 20px; }
  .chapter-page { padding-top: 74px; }
  .chapter-pager { grid-template-columns: 1fr; }
  .pager-link.align-right { text-align: left; }
}

@media print {
  body { background: #fff; color: #111; }
  .book-sidebar,
  .nav-toggle,
  .nav-backdrop,
  .reading-progress,
  .back-link,
  .chapter-pager,
  .chapter-toc,
  .section-copy,
  .skip-link { display: none !important; }
  .book-main { margin-left: 0; }
  .chapter-page { width: 100%; padding: 0; }
  .chapter-header { break-after: avoid; }
  a { color: #111; text-decoration: underline; }
  .notebook-content blockquote,
  .notebook-content table { break-inside: avoid; }
}
