/* Substack-inspired typography for mdbook */
@import url('https://fonts.googleapis.com/css2?family=Newsreader:ital,opsz,wght@0,6..72,300;0,6..72,400;0,6..72,500;0,6..72,600;1,6..72,300;1,6..72,400;1,6..72,500&family=Inter:wght@400;500;600;700&display=swap');

/* ===== Light theme ===== */
.light {
  --bg: #ffffff;
  --fg: #242424;
  --sidebar-bg: #fafafa;
  --sidebar-fg: #555;
  --sidebar-active: #242424;
  --sidebar-non-existant: #aaa;
  --links: #242424;
  --inline-code-color: #c7254e;
  --theme-popup-bg: #fff;
  --theme-popup-border: #e0e0e0;
  --quote-bg: #fafafa;
  --quote-border: #e0e0e0;
  --table-border-color: #e0e0e0;
  --table-header-bg: #fafafa;
  --searchbar-border-color: #e0e0e0;
  --searchbar-bg: #fff;
  --searchbar-fg: #242424;
  --searchbar-shadow-color: rgba(0,0,0,0.05);
  --searchresults-header-fg: #242424;
  --searchresults-border-color: #e0e0e0;
  --searchresults-li-bg: #fff;
  --search-mark-bg: #fff3cd;
}

/* ===== Content typography ===== */
.content {
  font-family: 'Newsreader', 'Charter', Georgia, 'Times New Roman', serif !important;
  font-size: 19px !important;
  line-height: 1.8 !important;
  color: var(--fg) !important;
  max-width: 680px !important;
  margin: 0 auto !important;
  padding: 0 1.5rem !important;
}

.content main {
  padding-top: 2rem;
  padding-bottom: 4rem;
}

/* Paragraphs — Substack spacing */
.content p {
  margin-bottom: 1.4em !important;
  font-weight: 400;
  letter-spacing: -0.003em;
}

/* Headings */
.content h1 {
  font-family: 'Inter', -apple-system, 'Helvetica Neue', sans-serif !important;
  font-size: 2.2rem !important;
  font-weight: 700 !important;
  letter-spacing: -0.02em !important;
  line-height: 1.2 !important;
  margin-top: 3rem !important;
  margin-bottom: 1.5rem !important;
  color: var(--fg) !important;
  border-bottom: none !important;
}

/* First h1 in chapter — extra top space */
.content main > h1:first-child {
  margin-top: 1rem !important;
  font-size: 2.5rem !important;
  margin-bottom: 2rem !important;
}

.content h2 {
  font-family: 'Inter', -apple-system, 'Helvetica Neue', sans-serif !important;
  font-size: 1.5rem !important;
  font-weight: 600 !important;
  letter-spacing: -0.015em !important;
  line-height: 1.3 !important;
  margin-top: 2.5rem !important;
  margin-bottom: 1rem !important;
  color: var(--fg) !important;
  border-bottom: none !important;
}

.content h3 {
  font-family: 'Inter', -apple-system, 'Helvetica Neue', sans-serif !important;
  font-size: 1.2rem !important;
  font-weight: 600 !important;
  letter-spacing: -0.01em !important;
  line-height: 1.4 !important;
  margin-top: 2rem !important;
  margin-bottom: 0.8rem !important;
  color: var(--fg) !important;
}

.content h4 {
  font-family: 'Inter', -apple-system, 'Helvetica Neue', sans-serif !important;
  font-size: 1.05rem !important;
  font-weight: 600 !important;
  margin-top: 1.5rem !important;
  margin-bottom: 0.6rem !important;
}

/* Blockquotes — elegant left border */
.content blockquote {
  border-left: 3px solid #ccc !important;
  margin: 1.8em 0 !important;
  padding: 0.2em 0 0.2em 1.5em !important;
  color: #555 !important;
  font-style: italic !important;
  background: transparent !important;
}

.content blockquote p {
  margin-bottom: 0.8em !important;
}

/* Horizontal rules — thin elegant lines */
.content hr {
  border: none !important;
  border-top: 1px solid #e0e0e0 !important;
  margin: 3rem auto !important;
  max-width: 100px !important;
}

/* Lists */
.content ul, .content ol {
  margin-bottom: 1.4em !important;
  padding-left: 1.5em !important;
}

.content li {
  margin-bottom: 0.5em !important;
  line-height: 1.7 !important;
}

/* Bold & italic */
.content strong {
  font-weight: 600 !important;
  color: var(--fg) !important;
}

.content em {
  font-style: italic !important;
}

/* Code / inline code */
.content code {
  font-size: 0.88em !important;
  padding: 0.15em 0.4em !important;
  border-radius: 3px !important;
  background: #f5f5f5 !important;
}

/* ===== Sidebar styling ===== */
.sidebar {
  font-family: 'Inter', -apple-system, 'Helvetica Neue', sans-serif !important;
  font-size: 13.5px !important;
  background: var(--sidebar-bg) !important;
}

.sidebar .sidebar-scrollbox {
  padding: 1.5rem 1rem !important;
}

/* Part titles (the --- separated sections) */
.sidebar ol.chapter li.part-title {
  font-weight: 700 !important;
  font-size: 12px !important;
  text-transform: uppercase !important;
  letter-spacing: 0.08em !important;
  color: #999 !important;
  margin-top: 1.5rem !important;
  margin-bottom: 0.5rem !important;
  padding-left: 0 !important;
}

.sidebar ol.chapter li.part-title:first-child {
  margin-top: 0.5rem !important;
}

/* Chapter links */
.sidebar ol.chapter li a {
  color: var(--sidebar-fg) !important;
  padding: 0.3em 0.8em !important;
  border-radius: 4px !important;
  display: block !important;
  line-height: 1.5 !important;
  transition: background 0.15s, color 0.15s !important;
}

.sidebar ol.chapter li a:hover {
  background: rgba(0,0,0,0.04) !important;
  color: var(--sidebar-active) !important;
  text-decoration: none !important;
}

.sidebar ol.chapter li.chapter-item.expanded > a,
.sidebar ol.chapter li a.active {
  background: rgba(0,0,0,0.06) !important;
  color: var(--sidebar-active) !important;
  font-weight: 500 !important;
}

/* ===== Nav buttons (prev/next) ===== */
.nav-chapters {
  font-family: 'Inter', -apple-system, 'Helvetica Neue', sans-serif !important;
  font-size: 14px !important;
  color: #666 !important;
  max-width: 680px !important;
}

/* ===== Menu bar ===== */
.menu-bar {
  background: var(--bg) !important;
  border-bottom: 1px solid #eee !important;
}

/* ===== Ayu dark theme overrides ===== */
.ayu {
  --bg: #1a1a2e;
  --fg: #e0ddd5;
  --sidebar-bg: #16162a;
  --sidebar-fg: #888;
  --sidebar-active: #e0ddd5;
  --links: #e0ddd5;
  --quote-border: #333;
}

.ayu .content hr {
  border-top-color: #333 !important;
}

.ayu .content blockquote {
  border-left-color: #444 !important;
  color: #999 !important;
}

.ayu .content code {
  background: #252540 !important;
}

/* ===== Print styles ===== */
@page {
  margin: 0;
}

@media print {
  body {
    padding: 0.75in 1in !important;
  }

  .content {
    font-size: 11pt !important;
    line-height: 1.6 !important;
    max-width: 100% !important;
  }

  .sidebar, .menu-bar, .nav-chapters {
    display: none !important;
  }
}

/* ===== Mobile responsive ===== */
@media (max-width: 768px) {
  .content {
    font-size: 17px !important;
    line-height: 1.7 !important;
    padding: 0 1rem !important;
  }

  .content main > h1:first-child {
    font-size: 1.8rem !important;
  }

  .content h2 {
    font-size: 1.3rem !important;
  }
}
