/* =========================================================
   Chapter Content Styling (Academic / Book)
   Scoped to .chapter-content — Drupal-safe
   Uses Linear Book theme tokens (supports html.dark-mode toggle)
   ========================================================= */

.chapter-content {
  /* Comfortable reading measure */
  max-width: 880px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem;
  line-height: 1.75;
  font-size: 1.05rem;
  text-rendering: optimizeLegibility;

  /* Book panel */
  color: var(--text-primary);
  background: var(--bg-surface-soft);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
}

/* Slightly tighter on small screens */
@media (max-width: 768px) {
  .chapter-content {
    font-size: 1rem;
    line-height: 1.7;
    padding: 1rem 1rem;
  }
}

/* ---------------------------------------------------------
   Headings (book-like hierarchy + spacing)
   --------------------------------------------------------- */

.chapter-content h2,
.chapter-content h3,
.chapter-content h4 {
  line-height: 1.25;
  margin-top: 2.4rem;
  margin-bottom: 0.9rem;
  scroll-margin-top: 6rem;
}

.chapter-content h2 {
  font-size: 1.9rem;
  letter-spacing: -0.01em;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border-subtle); /* ✅ token */
}

.chapter-content h3 {
  font-size: 1.45rem;
  letter-spacing: -0.01em;
}

.chapter-content h4 {
  font-size: 1.18rem;
  opacity: 0.95;
}

/* ---------------------------------------------------------
   Paragraphs (academic rhythm)
   --------------------------------------------------------- */

.chapter-content p {
  margin: 0 0 1.15rem 0;
}

.chapter-content p + p {
  margin-top: 0.9rem;
}

/* Optional: justify only on wide screens */
@media (min-width: 1024px) {
  .chapter-content p {
    text-align: justify;
    hyphens: auto;
  }
}

/* ---------------------------------------------------------
   Links
   --------------------------------------------------------- */

.chapter-content a {
  color: var(--accent);
  text-underline-offset: 0.14em;
  text-decoration-thickness: 1px;
}

/* ---------------------------------------------------------
   Lists
   --------------------------------------------------------- */

.chapter-content ul,
.chapter-content ol {
  margin: 1.1rem 0 1.1rem 1.6rem;
  padding: 0;
}

.chapter-content li {
  margin: 0.35rem 0;
}

.chapter-content li > ul,
.chapter-content li > ol {
  margin-top: 0.6rem;
}

/* ---------------------------------------------------------
   Blockquotes (academic callout)
   --------------------------------------------------------- */

.chapter-content blockquote {
  margin: 1.5rem 0;
  padding: 0.9rem 1.1rem;
  border-left: 4px solid var(--accent);     /* ✅ token */
  background: var(--accent-soft);           /* ✅ token */
  border-radius: 10px;
  color: var(--text-primary);
}

/* ---------------------------------------------------------
   Code + Pre (neutral, theme-friendly)
   --------------------------------------------------------- */

.chapter-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.92em;
  padding: 0.15em 0.35em;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.05);
}

/* Dark-mode inline code background (toggle-based) */
html.dark-mode .chapter-content code {
  background: rgba(255, 255, 255, 0.08);
}

.chapter-content pre {
  margin: 1.6rem 0;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.06);
  border: 1px solid var(--border-subtle); /* ✅ token */
  line-height: 1.55;
  font-size: 0.92rem;
}

html.dark-mode .chapter-content pre {
  background: rgba(255, 255, 255, 0.06);
}

.chapter-content pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: 0.92rem;
}

/* ---------------------------------------------------------
   Tables (clean, academic, mobile scroll)
   --------------------------------------------------------- */

.chapter-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.8rem 0;
  font-size: 0.96rem;
  border: 1px solid var(--border-subtle); /* ✅ token */
  border-radius: 12px;
  overflow: hidden;
}

.chapter-content thead {
  background: rgba(0, 0, 0, 0.04);
}

html.dark-mode .chapter-content thead {
  background: rgba(255, 255, 255, 0.06);
}

.chapter-content th,
.chapter-content td {
  padding: 0.65rem 0.8rem;
  border-bottom: 1px solid var(--border-subtle); /* ✅ token */
  text-align: left;
  vertical-align: top;
}

.chapter-content th {
  font-weight: 650;
}

/* Subtle zebra striping */
.chapter-content tbody tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.02);
}

html.dark-mode .chapter-content tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.04);
}

/* Mobile table scroll */
@media (max-width: 768px) {
  .chapter-content table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

/* ---------------------------------------------------------
   Horizontal rules
   --------------------------------------------------------- */

.chapter-content hr {
  margin: 2.4rem 0;
  border: none;
  border-top: 1px solid var(--border-subtle); /* ✅ token */
}

/* ---------------------------------------------------------
   MathJax (CHTML) spacing + overflow safety
   --------------------------------------------------------- */

.chapter-content mjx-container {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
}

.chapter-content mjx-container[display="true"] {
  margin: 1.5rem 0;
}

.chapter-content mjx-container:not([display="true"]) {
  margin: 0 0.06em;
}
