/* ============================================================================
   The Sourdough Framework — "Warm Artisan Editorial" redesign
   Durable customization layer. Loaded as the LAST <head> stylesheet (injected
   by customize.rb -> inject_redesign_assets), so it wins the cascade over
   book.css / style.css at equal specificity without needing !important.

   NEVER edit static_website_html/style.css or book.css — they are LaTeX build
   artifacts wiped by `make copy`. All durable styling lives here.
   ============================================================================ */

/* ----------------------------------------------------------------------------
   1. Self-hosted fonts (SIL OFL, variable, latin subset) — see assets/fonts/
   ---------------------------------------------------------------------------- */
@font-face{
  font-family:'Source Serif 4';font-style:normal;font-weight:200 900;
  font-display:swap;src:url('/fonts/source-serif-4-var.woff2') format('woff2');
}
@font-face{
  font-family:'Source Serif 4';font-style:italic;font-weight:200 900;
  font-display:swap;src:url('/fonts/source-serif-4-italic-var.woff2') format('woff2');
}
@font-face{
  font-family:'Fraunces';font-style:normal;font-weight:100 900;
  font-display:swap;src:url('/fonts/fraunces-var.woff2') format('woff2');
}
@font-face{
  font-family:'JetBrains Mono';font-style:normal;font-weight:100 800;
  font-display:swap;src:url('/fonts/jetbrains-mono-var.woff2') format('woff2');
}

/* ----------------------------------------------------------------------------
   2. Design tokens
   ---------------------------------------------------------------------------- */
:root{
  /* Surfaces & ink */
  --sd-bg:        #FBF7F0;   /* cream page */
  --sd-surface:   #FFFFFF;   /* content panel / cards */
  --sd-surface-2: #F4ECDF;   /* raised: callouts, code, zebra */
  --sd-ink:       #2B2118;   /* espresso body text */
  --sd-ink-soft:  #6A5B49;   /* captions, meta, muted */
  --sd-hairline:  #E7DDCE;   /* rules, borders */

  /* Brand accent (burnt amber) */
  --sd-accent:       #C2410C;
  --sd-accent-hover: #9A3412;
  --sd-accent-soft:  #FBEAE0;
  --sd-on-accent:    #FFFFFF;

  /* Semantic callouts */
  --sd-tip:#2F7D52;     --sd-tip-bg:#E9F4EE;
  --sd-warn:#B45309;    --sd-warn-bg:#FBEFD6;
  --sd-science:#2563EB; --sd-science-bg:#E8EFFD;

  /* Header */
  --sd-header-bg: #1C1714;

  /* Typography */
  --sd-font-serif:   'Source Serif 4', Georgia, 'Times New Roman', serif;
  --sd-font-display: 'Fraunces', 'Source Serif 4', Georgia, serif;
  --sd-font-mono:    'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sd-font-ui:      'Open Sans', system-ui, -apple-system, sans-serif;

  --sd-measure: 38rem;       /* reading column (~68ch) */
  --sd-leading: 1.75;

  /* Shape / depth / motion */
  --sd-radius:   10px;
  --sd-radius-lg:16px;
  --sd-shadow-sm: 0 1px 2px rgba(43,33,24,.05), 0 1px 1px rgba(43,33,24,.04);
  --sd-shadow-md: 0 10px 30px -16px rgba(43,33,24,.35);
  --sd-ease: .2s ease;
  --sd-focus: var(--sd-accent);

  /* Re-point the book's legacy variables to the new system so any un-ported
     rule (and the old dark-mode overrides) still resolve on-brand. */
  --c-beige: var(--sd-bg);
  --c-black: var(--sd-ink);
  --c-black-background: var(--sd-header-bg);
  --image-background: var(--sd-surface);
}

[data-theme="dark"]{
  --sd-bg:        #161210;
  --sd-surface:   #211B16;
  --sd-surface-2: #2A221A;
  --sd-ink:       #ECE3D6;
  --sd-ink-soft:  #B4A693;
  --sd-hairline:  #392F25;

  --sd-accent:       #F59E5B;
  --sd-accent-hover: #FBBF77;
  --sd-accent-soft:  #2E2317;
  --sd-on-accent:    #1A1411;

  --sd-tip:#7BD9A6;     --sd-tip-bg:#15241C;
  --sd-warn:#FBBF77;    --sd-warn-bg:#2A2012;
  --sd-science:#9DBBFF; --sd-science-bg:#161E2E;

  --sd-header-bg: #100C0A;

  --sd-shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --sd-shadow-md: 0 10px 30px -16px rgba(0,0,0,.65);
}

/* ----------------------------------------------------------------------------
   3. Base / page
   ---------------------------------------------------------------------------- */
html{ -webkit-text-size-adjust:100%; }
body{
  background-color: var(--sd-bg);
  color: var(--sd-ink);
  font-family: var(--sd-font-ui);
}

::selection{ background: var(--sd-accent-soft); color: var(--sd-ink); }

:focus-visible{
  outline: 2px solid var(--sd-focus);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Header banner backdrop */
.header{ background-color: var(--sd-header-bg); }

/* Two-column shell (sidebar + reading card) */
@media (min-width: 769px){
  .book-content{ align-items: flex-start; gap: 8px; }
}

/* ----------------------------------------------------------------------------
   4. Reading surface (the "page")
   ---------------------------------------------------------------------------- */
main.main-content,
main.titlepage,
div.footnotes{
  background-color: var(--sd-surface);
  color: var(--sd-ink);
  max-width: var(--sd-measure);
}

main.main-content{
  font-family: var(--sd-font-serif);
  font-size: 1.06rem;
  line-height: var(--sd-leading);
  font-feature-settings: "kern" 1, "liga" 1, "onum" 1;
  border: 1px solid var(--sd-hairline);
  border-radius: var(--sd-radius-lg);
  box-shadow: var(--sd-shadow-sm);
  padding: 2.6rem 2.9rem 3rem;
}

/* readable, un-justified body */
main.main-content p,
main.main-content p.indent,
main.main-content p.noindent,
main.main-content li{
  text-align: left;
  hyphens: auto;
  text-wrap: pretty;
}
main.main-content p{ margin: 0 0 1.15em; }

/* keep tex4ht semantic emphasis intact; only remap monospace family */
main.main-content .ec-lmtt-12,
main.main-content code,
main.main-content kbd,
main.main-content pre,
main.main-content tt{
  font-family: var(--sd-font-mono);
  font-size: .92em;
}

/* inline code chips (only standalone code, not inside listing figures) */
main.main-content :not(pre) > code{
  background: var(--sd-surface-2);
  border: 1px solid var(--sd-hairline);
  border-radius: 5px;
  padding: .08em .35em;
}

/* links */
main.main-content a{
  color: var(--sd-accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, var(--sd-accent) 38%, transparent);
  text-underline-offset: 2px;
  transition: color var(--sd-ease), text-decoration-color var(--sd-ease);
}
main.main-content a:hover{
  color: var(--sd-accent-hover);
  text-decoration-color: currentColor;
}

/* ----------------------------------------------------------------------------
   5. Headings
   ---------------------------------------------------------------------------- */
main.main-content h1,
main.main-content h2,
main.main-content h3,
main.main-content h4,
main.main-content h5,
main.main-content .chapterHead,
main.main-content .likechapterHead,
main.main-content .sectionHead,
main.main-content .subsectionHead{
  font-family: var(--sd-font-display);
  text-transform: none;
  color: var(--sd-ink);
  line-height: 1.15;
  letter-spacing: -0.01em;
}

main.main-content h2.chapterHead,
main.main-content h2.likechapterHead{
  font-size: clamp(2rem, 1.5rem + 1.6vw, 2.8rem);
  font-weight: 600;
  margin: .2em 0 .7em;
}
main.main-content h3.sectionHead{
  font-size: 1.6rem; font-weight: 600;
  margin: 2.2em 0 .6em; scroll-margin-top: 1.2rem;
}
main.main-content h4.subsectionHead{
  font-size: 1.22rem; font-weight: 650;
  margin: 1.8em 0 .5em; scroll-margin-top: 1.2rem;
}

/* "Chapter N" eyebrow above numbered chapter titles */
main.main-content h2.chapterHead .titlemark{
  display: block;
  font-family: var(--sd-font-ui);
  font-weight: 700;
  font-size: .8rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--sd-accent);
  margin-bottom: .35em;
}
main.main-content h2.chapterHead .titlemark::before{ content: "Chapter "; }

/* section numbers stay inline, tinted */
main.main-content h3.sectionHead .titlemark,
main.main-content h4.subsectionHead .titlemark{
  color: var(--sd-accent);
  font-variant-numeric: tabular-nums;
  margin-right: .5rem;
}

/* permalink fades in on hover */
main.main-content .permalink{
  color: var(--sd-ink-soft);
  opacity: 0;
  transition: opacity var(--sd-ease);
}
main.main-content .sectionHead:hover .permalink,
main.main-content .subsectionHead:hover .permalink{ opacity: .65; }

/* ----------------------------------------------------------------------------
   6. Lead / blockquotes / callouts
   ---------------------------------------------------------------------------- */
main.main-content blockquote{
  margin: 1.4em 0;
  padding: 1.05rem 1.3rem;
  background: var(--sd-accent-soft);
  border-left: 3px solid var(--sd-accent);
  border-radius: 0 var(--sd-radius) var(--sd-radius) 0;
  color: var(--sd-ink);
}
main.main-content blockquote p{ margin: 0; }
main.main-content blockquote p + p{ margin-top: .7em; }

/* reusable callout component (available for future tip/warning/science boxes) */
.sd-callout{
  margin: 1.4em 0; padding: 1rem 1.2rem 1rem 3rem;
  position: relative; border-radius: var(--sd-radius);
  background: var(--sd-surface-2); border: 1px solid var(--sd-hairline);
}
.sd-callout::before{
  position: absolute; left: 1rem; top: .95rem; font-size: 1.1rem; line-height: 1;
}
.sd-callout--tip{ background: var(--sd-tip-bg); border-color: color-mix(in srgb, var(--sd-tip) 30%, transparent); }
.sd-callout--tip::before{ content: "💡"; }
.sd-callout--warn{ background: var(--sd-warn-bg); border-color: color-mix(in srgb, var(--sd-warn) 30%, transparent); }
.sd-callout--warn::before{ content: "⚠️"; }
.sd-callout--science{ background: var(--sd-science-bg); border-color: color-mix(in srgb, var(--sd-science) 30%, transparent); }
.sd-callout--science::before{ content: "🔬"; }

/* ----------------------------------------------------------------------------
   7. Lists
   ---------------------------------------------------------------------------- */
main.main-content ul.itemize,
main.main-content ol.enumerate,
main.main-content ul, main.main-content ol{ padding-left: 1.4em; }
main.main-content li{ margin: .35em 0; }
main.main-content ul.itemize li::marker{ color: var(--sd-accent); }
main.main-content dl.description dt{ font-weight: 700; }

/* ----------------------------------------------------------------------------
   8. Figures, captions
   ---------------------------------------------------------------------------- */
main.main-content figure.figure,
main.main-content figure.float,
main.main-content div.figure{
  background: var(--sd-surface);
  border: 1px solid var(--sd-hairline);
  border-radius: var(--sd-radius);
  padding: 14px;
  margin: 1.8em 0;
  box-shadow: var(--sd-shadow-sm);
}
main.main-content figure img,
main.main-content .figure img{ border-radius: 6px; }

main.main-content figcaption.caption{
  font-family: var(--sd-font-serif);
  font-style: italic;
  font-size: .9rem;
  line-height: 1.5;
  color: var(--sd-ink-soft);
  margin-top: .85em;
  text-align: left;
}
main.main-content figcaption.caption .id{
  font-style: normal;
  font-weight: 700;
  color: var(--sd-accent);
}

/* ----------------------------------------------------------------------------
   9. Tables
   ---------------------------------------------------------------------------- */
main.main-content table.tabular,
main.main-content .table table{
  width: 100%;
  border-collapse: collapse;
  font-size: .96rem;
  margin: 1.4em 0;
}
main.main-content table.tabular td,
main.main-content table.tabular th{
  border: 1px solid var(--sd-hairline);
  padding: .5rem .7rem;
  text-align: left;
  vertical-align: top;
}
main.main-content table.tabular tr:nth-child(even) td{ background: var(--sd-surface-2); }
main.main-content table.tabular th{
  background: var(--sd-accent-soft);
  font-family: var(--sd-font-ui);
  font-weight: 700;
}

/* ----------------------------------------------------------------------------
   10. Code / listings (override style.css green blocks)
   ---------------------------------------------------------------------------- */
main.main-content figure.texsource,
main.main-content figure.shellcommand,
main.main-content figure.htmlsource,
main.main-content figure.luasource,
main.main-content figure.textsource{
  background: var(--sd-surface-2);
  border: 1px solid var(--sd-hairline);
  border-radius: var(--sd-radius);
  padding: 1rem 1.1rem;
  margin: 1.4em 0;
  overflow: auto;
}
main.main-content figure pre.listings,
main.main-content pre{ font-family: var(--sd-font-mono); font-size: .9rem; line-height: 1.55; }

/* ----------------------------------------------------------------------------
   11. Footnotes
   ---------------------------------------------------------------------------- */
div.footnotes{
  border-top: 1px solid var(--sd-hairline);
  margin-top: 2.5rem;
  padding-top: 1rem;
  font-size: .88rem;
  color: var(--sd-ink-soft);
  max-width: var(--sd-measure);
}
.footnote-mark a{ color: var(--sd-accent); text-decoration: none; }

/* ----------------------------------------------------------------------------
   12. Reading time (injected after chapter h2 by customize.rb)
   ---------------------------------------------------------------------------- */
.sd-readtime{
  font-family: var(--sd-font-ui);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--sd-ink-soft);
  margin: -.4em 0 1.6em !important;
  display: flex; align-items: center; gap: .4em;
}

/* "In this chapter" index — built per chapter by customize.rb -> inject_chapter_toc,
   inserted right after the chapter's lead blockquote (so it sits near the top).
   A <details> disclosure: collapsed on mobile (long chapters would otherwise push
   the content a full viewport down), auto-opened on desktop by an inline script. */
.sd-chapter-toc{
  margin: 1.4em 0 2em;
  background: var(--sd-surface-2);
  border: 1px solid var(--sd-hairline);
  border-radius: var(--sd-radius);
  font-family: var(--sd-font-ui);
}
.sd-chapter-toc summary.sd-chapter-toc-title{
  display: flex; align-items: center; gap: .6rem;
  margin: 0; padding: .85rem 1.25rem;
  font-family: var(--sd-font-display);
  font-size: .76rem; font-weight: 700; letter-spacing: .13em; text-transform: uppercase;
  color: var(--sd-ink-soft);
  cursor: pointer; list-style: none; user-select: none;
}
.sd-chapter-toc summary.sd-chapter-toc-title::-webkit-details-marker{ display: none; }
/* caret — rotates when open */
.sd-chapter-toc summary.sd-chapter-toc-title::after{
  content: ""; margin-left: auto;
  width: .55em; height: .55em; flex: 0 0 auto;
  border-right: 2px solid var(--sd-accent); border-bottom: 2px solid var(--sd-accent);
  transform: rotate(45deg) translateY(-15%);
  transition: transform var(--sd-ease);
}
.sd-chapter-toc details[open] summary.sd-chapter-toc-title::after{ transform: rotate(225deg) translateY(15%); }
.sd-chapter-toc summary.sd-chapter-toc-title:hover{ color: var(--sd-accent); }
.sd-chapter-toc-list{ list-style: none; margin: 0; padding: .1rem 1.25rem 1rem; }
.sd-chapter-toc-list li{ margin: 0; }
/* scoped under .sd-chapter-toc so these beat the §4 main-content link styling
   (otherwise every title inherits the accent + underline reading-link look). */
.sd-chapter-toc .sd-chapter-toc-list a{
  display: flex; align-items: baseline; gap: .5em;
  padding: .28rem 0;
  color: var(--sd-ink); text-decoration: none; font-size: .92rem; line-height: 1.45;
}
.sd-chapter-toc .sd-chapter-toc-list a:hover{ color: var(--sd-accent); text-decoration: underline; text-underline-offset: 2px; }
.sd-ct-num{ color: var(--sd-accent); font-weight: 700; font-variant-numeric: tabular-nums; font-size: .82rem; flex: 0 0 auto; }
.sd-ct-sub{ padding-left: 1.5rem; }
.sd-chapter-toc .sd-ct-sub a{ font-size: .86rem; color: var(--sd-ink-soft); }
@media (max-width: 768px){
  /* roomier touch rows when collapsed-by-default on phones */
  .sd-chapter-toc summary.sd-chapter-toc-title{ padding: 1rem 1.1rem; }
  .sd-chapter-toc-list{ padding: .1rem 1.1rem 1rem; }
  .sd-chapter-toc .sd-chapter-toc-list a{ padding: .55rem 0; }
}

/* ----------------------------------------------------------------------------
   13. Prev / next — labeled with the destination chapter (customize.rb ->
       label_crosslinks rewrites "Previous page"/"Next page" into
       .sd-xl-dir + .sd-xl-title spans; plain-text links still render fine)
   ---------------------------------------------------------------------------- */
nav.crosslinks-bottom{
  display: flex; justify-content: space-between; gap: .8rem;
  margin-top: 2.5rem; padding-top: 1.5rem;
  border-top: 1px solid var(--sd-hairline);
}
nav.crosslinks-bottom a.prev,
nav.crosslinks-bottom a.next{
  display: flex; flex-direction: column; gap: .15rem;
  flex: 0 1 auto; min-width: 0; max-width: 48%;
  font-family: var(--sd-font-ui);
  font-weight: 600; font-size: .92rem;
  border: 1px solid var(--sd-hairline);
  border-radius: var(--sd-radius);
  background: var(--sd-surface);
  color: var(--sd-ink);
  padding: .7rem 1rem;
  text-decoration: none;
  transition: border-color var(--sd-ease), color var(--sd-ease), transform var(--sd-ease);
}
nav.crosslinks-bottom a.next{ margin-left: auto; text-align: right; align-items: flex-end; }
/* arrows live on the direction kicker (fallback: on the link itself when the
   build hasn't been relabeled and the link is plain "Previous page" text) */
nav.crosslinks-bottom a.prev:not(:has(.sd-xl-dir))::before{ content: "← "; color: var(--sd-accent); }
nav.crosslinks-bottom a.next:not(:has(.sd-xl-dir))::after{ content: " →"; color: var(--sd-accent); }
.sd-xl-dir{
  font-size: .68rem; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--sd-ink-soft);
}
a.prev .sd-xl-dir::before{ content: "← "; color: var(--sd-accent); }
a.next .sd-xl-dir::after{ content: " →"; color: var(--sd-accent); }
/* titles wrap to a second line rather than ellipsizing — "Sourdough st…"
   tells the reader nothing; books name the destination in full */
.sd-xl-title{
  min-width: 0; max-width: 100%;
  overflow-wrap: break-word;
  hyphens: manual;            /* "How sour-/dough works" is not a book look */
  text-wrap: balance;
  line-height: 1.35;
}
nav.crosslinks-bottom a:hover{
  border-color: var(--sd-accent); color: var(--sd-accent);
  transform: translateY(-1px);
}

/* ----------------------------------------------------------------------------
   14. Sidebar / Table of contents
   ---------------------------------------------------------------------------- */
nav.TOC.menu{ font-family: var(--sd-font-ui); }

.logo{
  display: block;
  font-family: var(--sd-font-display) !important;
  font-weight: 600;
  color: var(--sd-ink) !important;
  font-size: .92rem !important;
  line-height: 1.15;
  text-wrap: balance;
  padding: 2px 6px 10px;
  letter-spacing: 0;
}

/* hide the decorative arrows between menu groups (picture is display:contents) */
.menu-arrow{ display: none !important; }

/* desktop: the sidebar scrolls WITH the page (no separate inner scroll container). */
@media (min-width: 769px){
  nav.TOC.menu{ align-self: flex-start; padding: 4px 4px 24px; }
}

/* the logo already links home → drop the duplicate "home" menu box */
.menu-group:has(.home-link){ display: none; }

/* ===== "Quiet Editorial Index" — sidebar redesign (from menu design DD) =====
   Dissolves the 28 stacked bordered cards into one calm printed-contents column:
   borderless rows, an accent number gutter so titles align, Fraunces small-caps
   group headings (injected by snippets/menu-groups.html), a subtle "you are
   here", a hover that's clearly NOT the selected wash, and the two money links
   as standout pills. Token-driven so light/dark flip automatically. */

/* kill the boxes — .menu-inner is now a transparent passthrough */
nav.TOC .menu-inner{
  border: 0 !important; border-radius: 0 !important;
  background: transparent !important; box-shadow: none !important; overflow: visible !important;
}
nav.TOC .menu-group{ margin: 0 !important; }
nav.TOC .menu-entry{
  border-radius: 7px !important; margin: 0;
  transition: background var(--sd-ease), box-shadow var(--sd-ease);
}

/* keep the build-injected section/subsection rows hidden (uniform 1 row/chapter) */
nav.TOC .menu-entry:has(.sectionToc),
nav.TOC .menu-entry:has(.subsectionToc){ display: none !important; }

/* the row: one quiet line, number in a fixed accent gutter.
   Sizes are PX on purpose: the book inflates the root font on desktop, and its
   `nav.TOC span{font-size:16px}` only hits rows whose text is wrapped in a
   .link_text span — rem/em sizing made bare rows (Preface, Glossary…) render
   bigger and the title column drift a few px. Px + inherit = one uniform list. */
nav.TOC .chapterToc > a{
  display: flex; align-items: baseline; gap: .55rem;
  padding: 6px 10px; border-radius: 7px;
  color: var(--sd-ink); font-weight: 600; font-size: 16px; line-height: 1.3;
  text-decoration: none;
  transition: color var(--sd-ease), background var(--sd-ease);
}
nav.TOC .chapterToc > a .link_text{ font-size: inherit; }
nav.TOC .chapter_number{
  flex: 0 0 24px; text-align: right;
  margin-right: 0;   /* the book CSS adds 7px here, skewing the title column */
  color: var(--sd-accent); font-weight: 700; font-variant-numeric: tabular-nums; font-size: 13px;
}
nav.TOC .link_text{ min-width: 0; }

/* numberless items (Preface, Acknowledgments, Glossary, the lists, Bibliography)
   indent to the same title column so the whole list shares one left edge
   (10px row padding + 24px number gutter + the .55rem flex gap) */
nav.TOC .menu-group:not(:has(.chapter_number)) .chapterToc > a{
  padding-left: calc(10px + 24px + .55rem);
}

/* hover — neutral warm tint + faint hairline; NOT the accent-soft "selected" wash */
nav.TOC .menu-group:not(.selected) .chapterToc > a:hover{
  background: var(--sd-surface-2);
  box-shadow: inset 0 0 0 1px var(--sd-hairline);
  color: var(--sd-ink);
}

/* selected — subtle "you are here": accent wash + inset accent edge + bold accent */
nav.TOC .menu-group.selected .chapterToc > a{
  background: var(--sd-accent-soft);
  background: color-mix(in srgb, var(--sd-accent) 8%, transparent);
  box-shadow: inset 3px 0 0 var(--sd-accent);
  color: var(--sd-accent); font-weight: 700;
}

/* group headings (inserted by snippets/menu-groups.html) */
nav.TOC .sd-toc-head{
  margin: 0; padding: 16px 10px 5px;
  font-family: var(--sd-font-display); font-weight: 600;
  font-size: .72rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--sd-ink-soft);
}
nav.TOC .menu-group.sd-section-start{ border-top: 1px solid var(--sd-hairline); margin-top: 2px !important; }
nav.TOC .sd-toc-head--first{ padding-top: 6px; }
nav.TOC .sd-toc-head--first + .menu-group.sd-section-start{ border-top: 0; margin-top: 0 !important; }

/* "Get the book" action footer — extra air + stronger divider */
nav.TOC .sd-toc-head--actions{ margin-top: 14px; padding-top: 14px; border-top: 2px solid var(--sd-hairline); }
nav.TOC .sd-toc-head--actions + .menu-group.sd-section-start{ border-top: 0; margin-top: 0 !important; }

/* quiet utility rows (PDF / EPUB / TL;DR / Source code): muted, emoji as glyph */
nav.TOC .menu-group:has(a[href*=".pdf"]) .chapterToc > a,
nav.TOC .menu-group:has(a[href*=".epub"]) .chapterToc > a,
nav.TOC .menu-group:has(a[href*="github"]) .chapterToc > a{
  color: var(--sd-ink-soft); font-weight: 600; font-size: 15px;
}
nav.TOC .menu-group:has(a[href*=".pdf"]) .chapter_number,
nav.TOC .menu-group:has(a[href*=".epub"]) .chapter_number,
nav.TOC .menu-group:has(a[href*="github"]) .chapter_number{ flex: 0 0 auto; font-size: .95rem; color: inherit; }

/* money links — break the calm so they read as CTAs */
nav.TOC .menu-group:has(a[href*="hardcover"]){ margin-top: 4px !important; }
nav.TOC .menu-group:has(a[href*="hardcover"]) .chapterToc > a{
  background: var(--sd-accent); border-radius: var(--sd-radius); font-weight: 700;
  box-shadow: 0 8px 18px -12px color-mix(in srgb, var(--sd-accent) 70%, transparent);
}
nav.TOC .menu-group:has(a[href*="hardcover"]) .link_text,
nav.TOC .menu-group:has(a[href*="hardcover"]) .chapter_number{ color: var(--sd-on-accent) !important; }
nav.TOC .menu-group:has(a[href*="hardcover"]) .chapterToc > a:hover{ background: var(--sd-accent-hover); box-shadow: none; }

nav.TOC .menu-group:has(a[href*="kofi"], a[href*="breadco.de/support"]){ margin-top: 4px !important; }
nav.TOC .menu-group:has(a[href*="kofi"], a[href*="breadco.de/support"]) .chapterToc > a{
  border: 1.5px solid var(--sd-accent); border-radius: var(--sd-radius);
  padding-block: calc(6px - 1.5px); font-weight: 700;
}
nav.TOC .menu-group:has(a[href*="kofi"], a[href*="breadco.de/support"]) .link_text,
nav.TOC .menu-group:has(a[href*="kofi"], a[href*="breadco.de/support"]) .chapter_number{ color: var(--sd-accent) !important; }
nav.TOC .menu-group:has(a[href*="kofi"], a[href*="breadco.de/support"]) .chapterToc > a:hover{ background: var(--sd-accent-soft); }

/* focus ring on every link (visible on the filled Hardcover pill too) */
nav.TOC .chapterToc > a:focus-visible{ outline: 2px solid var(--sd-focus); outline-offset: 2px; border-radius: 7px; }
nav.TOC .menu-group:has(a[href*="hardcover"]) .chapterToc > a:focus-visible{ outline-color: var(--sd-on-accent); outline-offset: -3px; }

/* mobile (<=768px): the open menu is a full-screen, token-themed panel (see
   §18) — the "Quiet Editorial Index" styles above apply as-is in both themes,
   so no per-color overrides are needed here. */

/* ----------------------------------------------------------------------------
   15. Search (UI from search.html; index lazy-loaded)
   ---------------------------------------------------------------------------- */
.sd-search{ position: relative; margin: 0 0 14px; }
.sd-search-trigger{ display: none; }   /* mobile-only search icon in the top bar (see §18) */
/* beat the book's `.menu input{display:none}` (which hides the nav checkbox) */
nav.TOC .sd-search-input{
  display: block;
  width: 100%; box-sizing: border-box;
  font-family: var(--sd-font-ui); font-size: .92rem;
  color: var(--sd-ink);
  background: var(--sd-surface);
  border: 1px solid var(--sd-hairline);
  border-radius: var(--sd-radius);
  padding: .55rem .7rem .55rem 2rem;
}
.sd-search-input::placeholder{ color: var(--sd-ink-soft); }
.sd-search-input:focus{ outline: none; border-color: var(--sd-accent); }
.sd-search-icon{
  position: absolute; left: .65rem; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--sd-ink-soft); pointer-events: none;
}
.sd-search-kbd{
  position: absolute; right: .55rem; top: 50%; transform: translateY(-50%);
  font-family: var(--sd-font-mono); font-size: .7rem;
  color: var(--sd-ink-soft);
  border: 1px solid var(--sd-hairline); border-radius: 5px;
  padding: .05rem .35rem; pointer-events: none;
}
.sd-search-results{
  position: absolute; z-index: 9997; left: 0; right: 0; top: calc(100% + 6px);
  background: var(--sd-surface);
  border: 1px solid var(--sd-hairline);
  border-radius: var(--sd-radius);
  box-shadow: var(--sd-shadow-md);
  max-height: 60vh; overflow-y: auto;
  display: none; padding: 4px;
}
.sd-search-results.open{ display: block; }
.sd-result{
  display: block; text-decoration: none; color: var(--sd-ink);
  padding: .5rem .6rem; border-radius: 7px; font-family: var(--sd-font-ui);
}
/* out-specify the book's `nav.TOC a, nav.TOC a:visited{color:#fff}` — result
   links live inside the nav and would otherwise render white-on-white */
nav.TOC .sd-result, nav.TOC .sd-result:visited{ color: var(--sd-ink); }
.sd-result:hover, .sd-result.sd-active{ background: var(--sd-accent-soft); }
.sd-result-title{ font-weight: 700; font-size: .85rem; }
.sd-result-crumb{ font-size: .72rem; color: var(--sd-accent); margin-bottom: 2px; }
.sd-result-excerpt{ font-size: .78rem; color: var(--sd-ink-soft); line-height: 1.4; }
.sd-result mark{ background: var(--sd-accent-soft); color: inherit; padding: 0 1px; }
.sd-search-empty{ padding: .7rem; font-family: var(--sd-font-ui); font-size: .82rem; color: var(--sd-ink-soft); }

/* ----------------------------------------------------------------------------
   16. Home page (markup from customize.rb -> rebuild_home)
   ---------------------------------------------------------------------------- */
main.main-content.sd-home{ max-width: 60rem; }

.sd-hero{
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(140px, 26%, 190px);
  gap: 2rem; align-items: center;
  margin: .5rem 0 2.5rem;
}
.sd-hero-text{ min-width: 0; }
.sd-eyebrow{
  font-family: var(--sd-font-ui); font-weight: 700;
  font-size: .78rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--sd-accent); margin: 0 0 .6rem !important;
}
.sd-hero-title{
  font-family: var(--sd-font-display) !important;
  font-weight: 600 !important;
  font-size: clamp(1.9rem, 1.3rem + 1.6vw, 2.5rem) !important;
  line-height: 1.08 !important; letter-spacing: -0.02em;
  text-transform: none !important;
  margin: 0 0 .5rem !important; color: var(--sd-ink);
}
.sd-hero-lead{
  font-family: var(--sd-font-serif); font-size: 1.18rem; line-height: 1.55;
  color: var(--sd-ink-soft); margin: 0 0 .7rem !important;
}
/* author + honest-proof line — answers "who wrote this" before the first CTA */
.sd-byline{
  font-family: var(--sd-font-ui); font-size: .82rem;
  color: var(--sd-ink-soft); margin: 0 0 1.4rem !important;
}
.sd-byline a{
  color: var(--sd-ink); font-weight: 600;
  text-decoration: underline; text-decoration-color: var(--sd-hairline);
  text-underline-offset: 2px;
}
.sd-byline a:hover{ color: var(--sd-accent); text-decoration-color: currentColor; }
.sd-hero-actions{ display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.sd-hero-cover{ display: block; }
.sd-hero-cover img{
  width: 100%; height: auto; border-radius: var(--sd-radius);
  box-shadow: var(--sd-shadow-md); border: 1px solid var(--sd-hairline);
  transition: transform var(--sd-ease);
  cursor: pointer;            /* navigates to chapter 1, not a zoom target */
}
/* images that link to a page (not a full-size image) navigate → normal cursor */
main a[href$=".html"] img{ cursor: pointer; }
.sd-hero-cover:hover img{ transform: translateY(-3px) rotate(-.6deg); }

.sd-btn{
  display: inline-flex; align-items: center; gap: .45rem;
  box-sizing: border-box;   /* so width:100% (mobile) includes padding + border */
  font-family: var(--sd-font-ui); font-weight: 700; font-size: .9rem;
  padding: .6rem 1.1rem; border-radius: 50px; text-decoration: none !important;
  border: 2px solid transparent; cursor: pointer; white-space: nowrap;
  transition: transform var(--sd-ease), box-shadow var(--sd-ease), background var(--sd-ease), color var(--sd-ease);
}
.sd-btn-primary{
  background: var(--sd-accent); color: var(--sd-on-accent) !important;
  box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--sd-accent) 75%, transparent);
}
.sd-btn-primary:hover{ background: var(--sd-accent-hover); transform: translateY(-2px); }
.sd-btn-ghost{
  border-color: var(--sd-ink); color: var(--sd-ink) !important; background: transparent;
}
.sd-btn-ghost:hover{ border-color: var(--sd-accent); color: var(--sd-accent) !important; }

.sd-section{ margin: 2.8rem 0; }
.sd-section-title{
  font-family: var(--sd-font-display) !important; font-weight: 600 !important;
  font-size: 1.7rem !important; text-transform: none !important;
  margin: 0 0 1.2rem !important; color: var(--sd-ink);
}

/* "Ask Loafy" prompt card on the home page */
.sd-ask-loafy{
  display: flex; align-items: center; gap: 1.4rem;
  background: var(--sd-accent-soft);
  border: 1px solid color-mix(in srgb, var(--sd-accent) 22%, transparent);
  border-radius: var(--sd-radius-lg);
  padding: 1.3rem 1.6rem; margin: 0 0 2.8rem;
}
.sd-loafy-mascot{
  width: 92px; height: auto; flex: 0 0 auto;
  filter: drop-shadow(0 6px 10px rgba(120, 60, 0, .22));
}
.sd-ask-loafy-title{
  font-family: var(--sd-font-display) !important; font-weight: 600 !important;
  font-size: 1.3rem !important; text-transform: none !important;
  margin: 0 0 .35rem !important; color: var(--sd-ink);
}
.sd-ask-loafy-body p{ margin: 0 0 1rem; color: var(--sd-ink-soft); font-family: var(--sd-font-serif); }
@media (max-width: 768px){
  .sd-ask-loafy{ flex-direction: column; text-align: center; gap: .8rem; padding: 1.3rem; }
  /* same 420px cap as the hero CTAs so all pills share one sizing behavior */
  .sd-ask-loafy .sd-btn{ width: 100%; max-width: 420px; margin-inline: auto; justify-content: center; }
}

.sd-chapter-grid{
  display: grid; grid-template-columns: repeat(auto-fill, minmax(225px, 1fr)); gap: 1rem;
}
.sd-card{
  display: flex; flex-direction: column; gap: .35rem;
  background: var(--sd-surface); border: 1px solid var(--sd-hairline);
  border-radius: var(--sd-radius); padding: 1.1rem 1.2rem;
  text-decoration: none !important; color: var(--sd-ink);
  transition: transform var(--sd-ease), box-shadow var(--sd-ease), border-color var(--sd-ease);
}
.sd-card:hover{ transform: translateY(-3px); box-shadow: var(--sd-shadow-md); border-color: var(--sd-accent); }
.sd-card-num{
  font-family: var(--sd-font-ui); font-weight: 800; font-size: .76rem;
  letter-spacing: .1em; color: var(--sd-accent);
}
.sd-card-title{ font-family: var(--sd-font-display); font-weight: 600; font-size: 1.12rem; }
.sd-card-desc{ font-family: var(--sd-font-serif); font-size: .92rem; color: var(--sd-ink-soft); line-height: 1.45; }

.sd-download-grid{ display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .7rem; }
.sd-dl{
  display: flex; align-items: center; gap: .7rem;
  background: var(--sd-surface); border: 1px solid var(--sd-hairline);
  border-radius: var(--sd-radius); padding: .8rem 1rem;
  text-decoration: none !important; color: var(--sd-ink); font-family: var(--sd-font-ui);
  transition: border-color var(--sd-ease), transform var(--sd-ease);
}
.sd-dl:hover{ border-color: var(--sd-accent); transform: translateY(-2px); }
.sd-dl-ico{ display: inline-flex; color: var(--sd-accent); flex: 0 0 auto; }
.sd-dl-ico svg{ width: 22px; height: 22px; }
/* the hardcover tile stands out from the free formats and bridges into the
   support box right below */
.sd-dl-buy{ border-color: color-mix(in srgb, var(--sd-accent) 45%, transparent); background: var(--sd-accent-soft); }
.sd-dl-buy .sd-dl-label{ color: var(--sd-accent); }
.sd-dl-buy .sd-dl-sub{ color: var(--sd-ink-soft); }
.sd-dl-label{ font-weight: 700; font-size: .92rem; }
.sd-dl-sub{ display: block; font-weight: 400; font-size: .76rem; color: var(--sd-ink-soft); }

/* the home support section reuses the end-of-chapter "Bookshop Shelf"
   (.support-box.sb-shelf) — its styles live in snippets/support-box.html,
   which is injected on every page including the home. */

/* auto-hyphenation suits book prose, not short UI/marketing copy in narrow
   boxes ("sci-/ence-backed" in the hero reads as a typo on phones).
   main.main-content prefix: must out-specify §4's `main.main-content p`. */
main.main-content .sd-hero-lead, main.main-content .sd-card-desc,
main.main-content .sd-ask-loafy-body p,
main.main-content .sd-eyebrow{ hyphens: manual; }
.sd-eyebrow .sd-nowrap{ white-space: nowrap; }
/* true 16:9 (the legacy .videoWrapper padding-top:25px hack letterboxes it) */
.sd-home .videoWrapper{
  padding: 0; height: auto; aspect-ratio: 16 / 9;
  border-radius: var(--sd-radius); overflow: hidden; box-shadow: var(--sd-shadow-sm);
}
.sd-watch-link{ margin: .8rem 0 0; font-family: var(--sd-font-ui); font-size: .85rem; }
.sd-watch-link a{
  color: var(--sd-ink-soft); font-weight: 600;
  text-decoration: underline; text-decoration-color: var(--sd-hairline);
  text-underline-offset: 2px;
}
.sd-watch-link a:hover{ color: var(--sd-accent); text-decoration-color: currentColor; }

/* a reading-progress bar is meaningless on the landing page */
body:has(main.sd-home) #reading-progress-container{ display: none !important; }

/* quiet page-ending colophon line */
.sd-footer{
  margin-top: 2.2rem; padding-top: 1.1rem;
  border-top: 1px solid var(--sd-hairline);
}
.sd-footer p{
  margin: 0;
  font-family: var(--sd-font-ui); font-size: .78rem; line-height: 1.8;
  color: var(--sd-ink-soft); text-align: center; text-wrap: balance;
}
.sd-footer a{
  color: var(--sd-ink-soft); text-decoration: underline;
  text-decoration-color: var(--sd-hairline); text-underline-offset: 2px;
}
.sd-footer a:hover{ color: var(--sd-accent); text-decoration-color: currentColor; }

/* ----------------------------------------------------------------------------
   17. Floating widget alignment (snippets carry their own structural CSS;
        these just keep colors on-brand & token-driven)
   ---------------------------------------------------------------------------- */
#reading-progress-bar{ background: linear-gradient(90deg, var(--sd-accent), var(--sd-accent-hover)) !important; }

/* ----------------------------------------------------------------------------
   18. Responsive — mobile reading + the full-screen menu panel
   ---------------------------------------------------------------------------- */
@media (max-width: 768px){
  main.main-content{
    border: none; border-radius: 0; box-shadow: none;
    padding: 1.5rem 1.25rem 2.25rem; max-width: 100%;
  }
  main.main-content.sd-home{ max-width: 100%; }
  .sd-hero{ grid-template-columns: 1fr; gap: 1.3rem; }
  .sd-hero-cover{ max-width: 240px; }
  /* full-width stacked CTAs = clean, big tap targets on mobile — but capped,
     so they don't balloon on phablet/small-tablet widths (560-768px) */
  .sd-hero-actions{ flex-direction: column; align-items: stretch; max-width: 420px; }
  /* white-space normal: the "Continue: <chapter>" label must wrap, not clip */
  .sd-hero-actions .sd-btn{ width: 100%; justify-content: center; white-space: normal; }
  div.footnotes{ max-width: 100%; }

  /* ===== mobile menu: compact sticky bar + full-screen THEMED panel =====
     The bar stays brand-espresso in both themes; the open panel uses the page
     tokens (cream in light, near-black in dark) so the whole "Quiet Editorial
     Index" — rows, group heads, pills, search, theme toggle — is legible and
     on-brand without per-color overrides. (VitePress nav-screen pattern.) */
  nav.TOC.menu{
    position: sticky; top: 0; z-index: 50;
    background: var(--sd-header-bg);
    min-height: 56px; box-sizing: border-box;
    padding: 6px 10px 6px 16px;
  }
  .logo{
    color: #fff !important; flex: 1;
    padding: 12px 0;                /* tall hit area inside the 56px bar */
    font-size: 1.05rem !important;
  }

  /* the open panel: fixed under the bar, inset-anchored (no 100vh bugs),
     scrolls internally, safe-area padding so the last row is never clipped */
  nav.TOC .menu-items{
    position: fixed; z-index: 60;
    top: 56px; left: 0; right: 0; bottom: 0;
    width: auto;
    background: var(--sd-bg);
    border-top: 1px solid var(--sd-hairline);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
    padding: 12px 14px calc(28px + env(safe-area-inset-bottom, 0px));
  }
  #toggle-menu:checked ~ .menu-items{ animation: sd-menu-in .22s cubic-bezier(.05,.7,.1,1); }

  /* lock the page while the menu is open (panel is opaque + scrolls itself) */
  body:has(#toggle-menu:checked){ overflow: hidden; }

  /* comfortable touch rows (>=44px) */
  nav.TOC .chapterToc > a{ padding: 13px 10px; border-radius: 9px; }
  nav.TOC .sd-toc-head{ padding: 18px 10px 7px; }
  nav.TOC .menu-group:has(a[href*="kofi"], a[href*="breadco.de/support"]) .chapterToc > a{ padding-block: calc(13px - 1.5px); }

  /* search inside the panel: 16px input (prevents iOS focus auto-zoom),
     no "/" keyboard hint on touch */
  nav.TOC .sd-search{ margin: 4px 0 12px; }
  nav.TOC .sd-search-input{ font-size: 16px; padding: .7rem .7rem .7rem 2.1rem; }
  .sd-search-kbd{ display: none; }

  /* theme toggle: a real touch row at the panel's end (panel padding keeps it
     clear of the iOS home indicator) */
  nav.TOC .dark-mode-toggle{ padding: 14px 10px; min-height: 48px; font-size: 13.5px; }

  /* hamburger: 44x44 hit area (icon stays 30px) */
  nav.TOC .hamb{ padding: 7px; margin-right: -7px; }

  /* search icon in the bar (one tap to search) */
  .sd-search-trigger{
    display: inline-flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; margin-right: 2px;
    background: transparent; border: 0; color: #fff; cursor: pointer; border-radius: 8px;
  }
  .sd-search-trigger svg{ width: 22px; height: 22px; }
  .sd-search-trigger:hover{ background: rgba(255,255,255,.12); }

  /* floating chrome never competes with the open menu; the reading-progress
     bar (z 10000) would otherwise draw across the panel top */
  body:has(#toggle-menu:checked) #loafy-chat-button,
  body:has(#toggle-menu:checked) #back-to-top,
  body:has(#toggle-menu:checked) #reading-progress-container{ display: none !important; }

  /* ===== mobile reading polish ===== */
  /* back-to-top stacked over the Loafy button occluded body text mid-scroll;
     on phones the sticky bar + flick gestures cover the same need */
  #back-to-top{ display: none !important; }

  /* tables: tighter type fits more columns; thin scrollbar hints at overflow */
  main.main-content table.tabular{ font-size: .85rem; }
  main.main-content table.tabular td,
  main.main-content table.tabular th{ padding: .45rem .55rem; }
  main.main-content div.tabular,
  main.main-content .table{ scrollbar-width: thin; overscroll-behavior-x: contain; }

  /* list pages (figures/tables/flowcharts): hanging indent + roomier rows.
     The legacy <br> separators would double the row pitch on top of the
     padding — hide them while rows are block-level. */
  main.main-content span.lofToc,
  main.main-content span.lotToc{
    display: block;
    padding: .45rem 0 .45rem 2.6rem;
    text-indent: -2.6rem;
    line-height: 1.5;
  }
  main.main-content span.lofToc + br,
  main.main-content span.lotToc + br{ display: none; }

  /* glossary + bibliography: shallow indents buy back line length on 390px */
  main.main-content dl.description dd,
  main.main-content dl.thebibliography dd{ margin-left: 1.4rem; }

  /* prev/next: split the row evenly so wrapped titles get equal room */
  nav.crosslinks-bottom a.prev,
  nav.crosslinks-bottom a.next{ flex: 1 1 0; max-width: none; }
}

@keyframes sd-menu-in{
  from{ opacity: 0; transform: translateY(-10px); }
}

/* touch devices have no hover: keep section/term permalinks reachable */
@media (hover: none){
  main.main-content .permalink{ opacity: .4; padding: .25em .4em; }
}

/* ----------------------------------------------------------------------------
   19. Motion preferences
   ---------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce){
  *, *::before, *::after{
    transition: none !important;
    animation: none !important;
  }
}
/* NO global `html{scroll-behavior:smooth}`: iOS Safari routes its
   scroll-to-top-on-navigation through the smooth-scroll machinery, where a
   touch or late layout shift can cancel it — readers tapping Next would
   "stay at the bottom" of the new page. In-page anchor clicks get smooth
   scrolling via snippets/scroll-behavior.html instead. */
