/* ============================================================
   chapter.css — styles scoped to individual chapter reading pages
   Loaded after main.css + components.css.
   ============================================================ */

/* ── Override the dashboard content cap so chapters can host
      a wider grid (body column + sticky TOC rail) ───────────── */
.dashboard-content.dashboard-content--chapter {
  max-width: 1200px;
  padding: 1.5rem 2rem 4rem;
}

/* ── Reading progress bar (fixed top) ───────────────────────── */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--grad-purple-teal);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.08s linear;
  z-index: 1000;
  pointer-events: none;
}

/* ── Chapter article shell ──────────────────────────────────── */
.chapter {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  grid-template-areas:
    "intro intro"
    "mobiletoc mobiletoc"
    "body  toc"
    "nav   nav";
  gap: 0 3rem;
  align-items: start;
}
.chapter > .chapter-intro { grid-area: intro; }
.chapter > .chapter-toc--mobile { grid-area: mobiletoc; }
.chapter > .chapter-body { grid-area: body; }
.chapter > .chapter-toc { grid-area: toc; }
.chapter > .chapter-nav { grid-area: nav; }

@media (max-width: 1100px) {
  .chapter {
    grid-template-columns: 1fr;
    grid-template-areas:
      "intro"
      "mobiletoc"
      "body"
      "nav";
    gap: 1rem;
  }
}

/* ── Chapter intro header ───────────────────────────────────── */
.chapter-intro {
  grid-column: 1 / -1;
  padding-bottom: 1.5rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.chapter-intro__meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}

.chapter-intro__reading-time {
  font-size: 0.78rem;
  color: var(--muted);
  font-family: var(--font-body);
  letter-spacing: 0.04em;
}

.chapter-intro__title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.7rem, 3.2vw, 2.6rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--white);
  margin: 0 0 1rem;
}

.chapter-intro__epigraph {
  margin: 1.25rem 0 0;
  padding: 0.6rem 0 0.6rem 1rem;
  border-left: 3px solid var(--purple-light);
  font-family: var(--font-display);
  font-weight: 300;
  font-style: italic;
  font-size: 1.05rem;
  line-height: 1.55;
  color: var(--white);
  max-width: 680px;
}

/* ── Body content ───────────────────────────────────────────── */
.chapter-body {
  min-width: 0;
  max-width: 720px;
  font-size: 1.125rem;       /* 18px — long-form reading size */
  color: var(--white);
  line-height: 1.8;
}

.chapter-body > * + * { margin-top: 1.1rem; }

.chapter-body h2 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.85rem;
  line-height: 1.2;
  color: var(--white);
  margin-top: 3rem;
  margin-bottom: 0.6rem;
  letter-spacing: -0.015em;
  scroll-margin-top: 80px;
}

.chapter-body h2::before {
  content: "";
  display: block;
  width: 42px;
  height: 3px;
  margin-bottom: 1rem;
  border-radius: 2px;
  background: var(--grad-purple-teal);
}

.chapter-body h3 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
  line-height: 1.3;
  color: var(--white);
  margin-top: 2.25rem;
  margin-bottom: 0.5rem;
  scroll-margin-top: 80px;
}

.chapter-body h4 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--purple-light);
  margin-top: 1.75rem;
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.chapter-body p {
  color: var(--white);
  font-weight: 300;
  font-size: 1.125rem;
  line-height: 1.8;
}

.chapter-body ul,
.chapter-body ol {
  font-size: 1.0625rem;
  line-height: 1.75;
}

.chapter-body p > strong,
.chapter-body li > strong {
  color: var(--white);
  font-weight: 700;
}

.chapter-body em { color: inherit; }

.chapter-body a {
  color: var(--teal);
  text-decoration: none;
  border-bottom: 1px solid rgba(45,212,191,0.3);
  transition: border-color 0.15s, color 0.15s;
}
.chapter-body a:hover { color: var(--white); border-color: var(--teal); }

.chapter-body ul,
.chapter-body ol {
  padding-left: 1.5rem;
  color: var(--white);
  font-weight: 300;
}

.chapter-body li + li { margin-top: 0.5rem; }

.chapter-body ul li::marker { color: var(--purple-light); }
.chapter-body ol li::marker { color: var(--purple-light); font-weight: 700; }

.chapter-body hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: 2.5rem 0;
}

/* Inline code */
.chapter-body code:not(pre code) {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.86em;
  background: rgba(124,58,237,0.12);
  color: var(--purple-light);
  padding: 0.1em 0.4em;
  border-radius: 4px;
  border: 1px solid rgba(124,58,237,0.18);
}

/* Pre/code blocks */
.code-block {
  position: relative;
  margin: 1.5rem 0;
  background: #0a0a14;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.code-block__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.8rem 0.45rem 1rem;
  background: rgba(255,255,255,0.025);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.code-block__lang { color: var(--purple-light); }

.code-copy-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.code-copy-btn:hover {
  color: var(--white);
  border-color: var(--purple-light);
  background: rgba(124,58,237,0.08);
}
.code-copy-btn.is-copied {
  color: var(--teal);
  border-color: var(--teal);
  background: rgba(45,212,191,0.08);
}

.code-block pre {
  margin: 0;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.83rem;
  line-height: 1.6;
  color: #d4d3e8;
  background: transparent;
}

.code-block pre code { background: transparent; padding: 0; border: 0; color: inherit; font-size: inherit; }

/* Tables */
.chapter-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.chapter-body th,
.chapter-body td {
  padding: 0.7rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.chapter-body th {
  background: rgba(124,58,237,0.08);
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--white);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
}
.chapter-body td { color: var(--white); font-weight: 300; }
.chapter-body tr:last-child td { border-bottom: none; }
.chapter-body tr:nth-child(even) td { background: rgba(255,255,255,0.015); }

/* Pull-quote / callout */
.chapter-body .callout-quote {
  margin: 1.75rem 0;
  padding: 1.1rem 1.4rem;
  background: rgba(124,58,237,0.08);
  border-left: 3px solid var(--purple-light);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 300;
  font-size: 1.05rem;
  line-height: 1.6;
  color: var(--white);
}
.chapter-body .callout-quote p { margin: 0; }
.chapter-body .callout-quote.teal {
  background: rgba(45,212,191,0.08);
  border-left-color: var(--teal);
}
.chapter-body .callout-quote.yellow {
  background: rgba(245,200,66,0.08);
  border-left-color: var(--yellow);
}

/* Figure (diagram image) */
.chapter-figure {
  margin: 2rem 0;
  text-align: center;
  position: relative;
}
.chapter-figure img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg2);
  padding: 0.75rem;
  cursor: zoom-in;
  transition: border-color 0.15s, transform 0.15s;
}
.chapter-figure img:hover {
  border-color: var(--purple-light);
}
.chapter-figure__hint {
  position: absolute;
  top: 1.25rem;
  right: 1.25rem;
  background: rgba(0,0,0,0.6);
  color: var(--white);
  font-family: var(--font-display);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.25rem 0.6rem;
  border-radius: 100px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}
.chapter-figure:hover .chapter-figure__hint { opacity: 1; }
.chapter-figure figcaption {
  margin-top: 0.6rem;
  font-size: 0.82rem;
  color: var(--muted);
  font-style: italic;
}

/* Lightbox overlay */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 12, 0.92);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 2rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.lightbox.is-open {
  opacity: 1;
  pointer-events: auto;
}
.lightbox__img {
  max-width: 95vw;
  max-height: 90vh;
  width: auto;
  height: auto;
  border-radius: var(--radius-md);
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  cursor: zoom-out;
  background: var(--bg2);
  padding: 1rem;
}
.lightbox__close {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border);
  color: var(--white);
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}
.lightbox__close:hover {
  background: rgba(124,58,237,0.18);
  border-color: var(--purple-light);
}
@media (prefers-reduced-motion: reduce) {
  .lightbox { transition: none; }
}

/* Accordion section in body (What You'll Learn / Key Takeaways) */
.chapter-body .accordion { margin: 1.25rem 0 2rem; }
.chapter-body .accordion__content-inner { color: var(--white); }
.chapter-body .accordion__content-inner ul {
  padding-left: 1.25rem;
  margin: 0;
}
.chapter-body .accordion__content-inner li { line-height: 1.7; }

/* ── Sticky TOC rail (right side, ≥1100px) ──────────────────── */
.chapter-toc {
  position: sticky;
  top: 80px;
  align-self: start;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  padding: 1rem 0 1rem 1rem;
  border-left: 1px solid var(--border);
}
.chapter-toc__label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.85rem;
}
.chapter-toc ol {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.chapter-toc a {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  padding: 0.15rem 0 0.15rem 0.7rem;
  margin-left: -2px;
  line-height: 1.4;
  transition: color 0.15s, border-color 0.15s;
}
.chapter-toc a:hover { color: var(--white); }
.chapter-toc a.is-active {
  color: var(--purple-light);
  border-left-color: var(--purple-light);
  font-weight: 600;
}
.chapter-toc li.is-h3 a { padding-left: 1.4rem; font-size: 0.78rem; }

/* Mobile TOC = <details> dropdown */
.chapter-toc--mobile {
  display: none;
  margin-bottom: 1.5rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.4rem 0.9rem;
}
.chapter-toc--mobile summary {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--white);
  cursor: pointer;
  padding: 0.5rem 0;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chapter-toc--mobile summary::after {
  content: "+";
  color: var(--purple-light);
  font-size: 1.1rem;
  transition: transform 0.2s;
}
.chapter-toc--mobile[open] summary::after { transform: rotate(45deg); }
.chapter-toc--mobile ol { padding: 0.5rem 0 0.75rem; }

@media (max-width: 1100px) {
  .chapter-toc { display: none; }
  .chapter-toc--mobile { display: block; }
}

/* ── Prev / Next chapter footer ─────────────────────────────── */
.chapter-nav {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 3.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}
.chapter-nav a {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1rem 1.25rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--white);
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.chapter-nav a:hover {
  border-color: var(--purple-light);
  background: rgba(124,58,237,0.06);
  transform: translateY(-2px);
}
.chapter-nav__label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-family: var(--font-display);
  font-weight: 600;
}
.chapter-nav__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
}
.chapter-nav__next { text-align: right; align-items: flex-end; }
.chapter-nav__disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Reveal-on-scroll fade-in (works with .reveal from main.js) ── */
.reveal { opacity: 0; transform: translateY(12px); transition: opacity 0.6s ease, transform 0.6s ease; }
.reveal.visible { opacity: 1; transform: none; }
.reveal-delay-1 { transition-delay: 0.05s; }
.reveal-delay-2 { transition-delay: 0.12s; }

@media (prefers-reduced-motion: reduce) {
  .reveal, .reveal.visible { opacity: 1; transform: none; transition: none; }
  .reading-progress { transition: none; }
}
