/* ============================================================
   American Yawp MS — Shared Chapter Stylesheet
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Libre+Baskerville:ital,wght@0,400;0,700;1,400&family=Source+Sans+3:wght@400;600;700&display=swap');

:root {
  --navy: #1B3A5C;
  --teal: #2A7F8E;
  --gold: #C4941D;
  --cream: #FAFAF8;
  --dark-gray: #2C2C2C;
  --light-gray: #F5F5F5;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Libre Baskerville', Georgia, serif;
  color: var(--dark-gray);
  background: var(--cream);
  line-height: 1.8;
}

/* ---- Skip Link (Accessibility) ---- */

.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--teal);
  color: white;
  padding: 12px 20px;
  text-decoration: none;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 14px;
  font-weight: 600;
  z-index: 1000;
  border-radius: 0 0 4px 0;
}
.skip-link:focus {
  top: 0;
}

/* ---- Focus Indicators (Accessibility) ---- */

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

a:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 2px;
}

button:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 2px;
}

/* ---- Title Page ---- */

.title-page {
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 80px 24px;
  background: linear-gradient(170deg, #0D2137 0%, var(--navy) 40%, #2B5A7C 100%);
  color: white;
}
.series { font-family: 'Source Sans 3', sans-serif; font-size: 13px; letter-spacing: 4px; text-transform: uppercase; opacity: .5; margin-bottom: 16px; }
.chapter-num { font-size: 20px; font-weight: 400; opacity: .7; margin-bottom: 12px; }
.chapter-title { font-size: 52px; line-height: 1.2; margin-bottom: 20px; font-weight: 700; }
.chapter-subtitle { font-size: 22px; font-style: italic; opacity: .75; margin-bottom: 32px; }
.divider { width: 100px; height: 3px; background: var(--gold); margin: 0 auto 24px; }
.attribution { font-family: 'Source Sans 3', sans-serif; font-size: 13px; opacity: .5; line-height: 1.6; max-width: 600px; }

/* ---- Chapter Navigation Bar ---- */

.chapter-nav {
  background: white;
  border-bottom: 1px solid #ddd;
  padding: 10px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 14px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.chapter-nav a {
  color: var(--navy);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 4px;
  transition: background .2s, color .2s;
}
.chapter-nav a:hover {
  background: var(--navy);
  color: white;
}
.chapter-nav .nav-center {
  font-weight: 600;
  color: var(--navy);
  font-size: 13px;
  letter-spacing: .5px;
}
.chapter-nav .nav-center a {
  padding: 6px 10px;
}

/* ---- Reading Progress Bar ---- */

.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--gold);
  z-index: 200;
  width: 0%;
  transition: width .1s linear;
}

/* ---- Container ---- */

.container { max-width: 640px; margin: 0 auto; padding: 48px 24px; }

/* ---- Table of Contents ---- */

.toc {
  background: white;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 32px;
  margin-bottom: 48px;
}
.toc h2 { font-size: 18px; color: var(--navy); margin-bottom: 20px; text-align: center; }
.toc ol { list-style: none; counter-reset: toc-counter; padding: 0; }
.toc li { counter-increment: toc-counter; margin-bottom: 12px; }
.toc li::before { content: counter(toc-counter, upper-roman) ". "; color: var(--gold); font-weight: 700; margin-right: 8px; }
.toc a { color: var(--navy); text-decoration: none; border-bottom: 1px dotted transparent; transition: border-color .2s; }
.toc a:hover { border-bottom-color: var(--navy); }

/* ---- Overview & Big Questions ---- */

.overview {
  background: #F0F4F8;
  border-left: 5px solid var(--teal);
  padding: 28px 32px;
  margin-bottom: 48px;
  border-radius: 0 8px 8px 0;
}
.overview h2 { font-size: 20px; color: var(--teal); margin-bottom: 16px; }
.overview p { font-family: 'Source Sans 3', sans-serif; font-size: 16px; line-height: 1.7; }

.big-questions {
  background: white;
  border: 2px solid var(--gold);
  border-radius: 8px;
  padding: 28px 32px;
  margin-bottom: 48px;
}
.big-questions h2 { font-size: 18px; color: var(--gold); margin-bottom: 16px; text-align: center; }
.big-questions ul { list-style: none; padding: 0; }
.big-questions li {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 15px;
  padding-left: 28px;
  position: relative;
  margin-bottom: 12px;
  line-height: 1.6;
}
.big-questions li::before { content: "?"; color: var(--gold); font-weight: 700; font-size: 20px; position: absolute; left: 0; top: -2px; }

/* ---- Sections ---- */

section { margin-bottom: 64px; }
section h2 {
  font-size: 28px;
  color: var(--navy);
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 2px solid #E0E0E0;
}
section h3 {
  font-size: 20px;
  color: var(--navy);
  margin: 32px 0 16px;
}

p { margin-bottom: 20px; font-size: 17px; line-height: 1.8; }
p:last-child { margin-bottom: 0; }

/* ---- Callout Boxes (shared) ---- */

.vocab-box, .stop-think, .perspectives, .key-idea, .primary-source, .story-box, .activity-box, .voices-left-out {
  border-radius: 6px;
  padding: 22px 26px;
  margin: 28px 0;
}

/* Shared header style for all callout boxes */
.vocab-box h3, .stop-think h3, .perspectives h3, .key-idea h3,
.primary-source h3, .story-box h3, .voices-left-out h3 {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin: 0 0 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(0,0,0,.08);
}

/* Vocabulary */
.vocab-box { background: #F0F7FA; border-left: 4px solid var(--teal); }
.vocab-box h3 { color: var(--teal); }
.vocab-box p {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 16px;
  margin-bottom: 0;
  line-height: 1.7;
  padding: 10px 4px;
  border-bottom: 1px solid #D6E8EF;
}
.vocab-box p:last-child { margin-bottom: 0; border-bottom: none; }
.vocab-box strong {
  display: block;
  color: var(--teal);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .2px;
  margin-bottom: 2px;
}

/* Stop and Think */
.stop-think { background: #FFFBF0; border-left: 4px solid var(--gold); }
.stop-think h3 { color: #9A7410; }
.stop-think p {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 15px;
  font-style: italic;
  margin-bottom: 0;
  line-height: 1.65;
  color: #555;
}

/* Multiple Perspectives */
.perspectives { background: #F7F2FD; border-left: 4px solid #7C3AED; }
.perspectives h3 { color: #7C3AED; border-bottom-color: rgba(124,58,237,.15); }
.perspectives .perspective {
  margin-bottom: 14px;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 16px;
  line-height: 1.7;
  padding-left: 14px;
  border-left: 3px solid rgba(124,58,237,.2);
}
.perspectives .perspective + .perspective {
  padding-top: 14px;
  border-top: 1px solid rgba(124,58,237,.08);
}
.perspectives .perspective:last-child { margin-bottom: 0; }
.perspectives .perspective strong {
  color: #5B21B6;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .3px;
  display: block;
  margin-bottom: 4px;
}

/* Key Idea */
.key-idea { background: #F0F7F0; border-left: 4px solid #2E7D32; }
.key-idea h3 { color: #2E7D32; border-bottom-color: rgba(46,125,50,.18); }
.key-idea p {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 16px;
  line-height: 1.75;
  margin-bottom: 10px;
}
.key-idea p:last-child { margin-bottom: 0; }

/* Primary Source */
.primary-source {
  background: #FFFAF5;
  border-left: 4px solid #BF360C;
  padding-left: 30px;
}
.primary-source h3 { color: #BF360C; font-style: normal; }
.primary-source p {
  font-size: 15.5px;
  font-style: italic;
  line-height: 1.75;
  margin-bottom: 12px;
  color: #444;
}
.primary-source .source-citation {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 13px;
  font-style: normal;
  color: #999;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(0,0,0,.06);
}

/* Story Behind the Story */
.story-box { background: #FFFAF2; border-left: 4px solid #E67E22; }
.story-box h3 { color: #C56A12; }
.story-box p {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 15px;
  line-height: 1.7;
  margin-bottom: 10px;
}
.story-box p:last-child { margin-bottom: 0; }

/* Whose Voices Were Left Out */
.voices-left-out { background: #FDF2F5; border-left: 4px solid #C2185B; }
.voices-left-out h3 { color: #C2185B; border-bottom-color: rgba(194,24,91,.15); }
.voices-left-out p {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 16px;
  line-height: 1.75;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(194,24,91,.08);
}
.voices-left-out p:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }
.voices-left-out strong {
  color: #AD1457;
  font-size: 14px;
  letter-spacing: .3px;
}

/* Activity Box */
.activity-box {
  background: #FAFAFA;
  border: 1px solid #ddd;
  border-top: 4px solid var(--navy);
  border-radius: 6px;
  padding: 28px;
}
.activity-box h3 {
  font-family: 'Source Sans 3', sans-serif;
  color: var(--navy);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin: 0 0 18px;
  padding-bottom: 10px;
  border-bottom: 1px solid #E0E0E0;
  text-align: center;
}
.activity-box h4 { color: var(--navy); font-size: 16px; margin: 18px 0 10px; }
.activity-box p, .activity-box li { font-family: 'Source Sans 3', sans-serif; font-size: 15px; line-height: 1.7; }
.activity-box ul, .activity-box ol { margin-left: 24px; margin-bottom: 14px; }
.activity-box li { margin-bottom: 6px; }

/* ---- Figures / Images ---- */

figure {
  margin: 32px 0;
  text-align: center;
  background: var(--light-gray);
  border-radius: 6px;
  overflow: hidden;
}
figure img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
  border-radius: 0;
  box-shadow: none;
}
/* Graceful fallback when image is missing or fails to load.
   Browsers render alt text inside the element when the src fails,
   so we style the img itself as a visible placeholder. */
figure img[alt] {
  min-height: 180px;
  object-fit: cover;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 14px;
  color: #999;
  text-align: center;
}
figure img[alt]::after {
  content: attr(alt);
  display: block;
  padding: 24px 20px;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 14px;
  font-style: italic;
  color: #888;
  line-height: 1.6;
}
/* Broken-image indicator: show alt text in a styled box */
figure img:not([src]),
figure img[src=""] {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  background: #F5F5F5;
  border: 2px dashed #ccc;
  border-radius: 6px;
  padding: 24px;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 14px;
  font-style: italic;
  color: #888;
}
figcaption {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 13px;
  color: #666;
  padding: 12px 20px 14px;
  line-height: 1.55;
  font-style: italic;
  background: white;
  border-top: 1px solid #eee;
}

/* ---- Map Figures ---- */

figure.map-figure {
  border: 2px solid var(--navy);
  background: #fafcfe;
}
figure.map-figure img {
  min-height: 0;
  object-fit: contain;
  padding: 8px;
  background: white;
}
figure.map-figure figcaption {
  background: #eef3f8;
  border-top: 2px solid var(--navy);
  color: var(--navy);
  font-style: normal;
  font-size: 13px;
}
figure.map-figure figcaption .map-label {
  display: block;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ---- Footer ---- */

footer {
  border-top: 2px solid #E0E0E0;
  margin-top: 64px;
  padding-top: 24px;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 13px;
  color: #999;
  line-height: 1.7;
}
footer a { color: var(--teal); text-decoration: none; border-bottom: 1px dotted var(--teal); }
footer a:hover { border-bottom-style: solid; }

/* ---- Back to Top Button ---- */

.back-to-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--navy);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity .3s, visibility .3s;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.back-to-top.visible {
  opacity: 1;
  visibility: visible;
}
.back-to-top:hover { background: var(--teal); }

/* ---- Reader Toolbar ---- */

.reader-toolbar {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
}

.reader-toggle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--teal);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  transition: background .2s;
}
.reader-toggle:hover { background: var(--navy); }

.reader-panel {
  background: white;
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
  display: none;
  min-width: 260px;
  font-family: 'Source Sans 3', sans-serif;
}
.reader-panel.open { display: block; }

.reader-panel h4 {
  font-size: 14px;
  color: var(--navy);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #eee;
}

.reader-section {
  margin-bottom: 14px;
}
.reader-section:last-child { margin-bottom: 0; }
.reader-section label {
  display: block;
  font-size: 12px;
  color: #666;
  margin-bottom: 6px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.reader-btn-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.reader-btn {
  padding: 6px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: white;
  cursor: pointer;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 13px;
  color: var(--dark-gray);
  transition: background .15s, border-color .15s;
}
.reader-btn:hover { background: #f0f0f0; }
.reader-btn.active {
  background: var(--teal);
  color: white;
  border-color: var(--teal);
}

.reader-slider {
  width: 100%;
  margin: 4px 0;
}

/* ---- Line Focus Overlay ---- */

.line-focus-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 90;
  display: none;
}
.line-focus-overlay.active { display: block; }
.line-focus-top, .line-focus-bottom {
  position: absolute;
  left: 0;
  width: 100%;
  background: rgba(0,0,0,.55);
}
.line-focus-top { top: 0; }
.line-focus-bottom { bottom: 0; }

/* ---- Highlight Styles ---- */

.user-highlight-yellow { background: rgba(255,235,59,.4); border-radius: 2px; }
.user-highlight-green { background: rgba(129,199,132,.4); border-radius: 2px; }
.user-highlight-blue { background: rgba(100,181,246,.4); border-radius: 2px; }
.user-highlight-pink { background: rgba(244,143,177,.4); border-radius: 2px; }

/* ---- Notes Sidebar ---- */

.notes-panel {
  position: fixed;
  top: 0;
  right: -360px;
  width: 340px;
  height: 100%;
  background: white;
  border-left: 1px solid #ddd;
  box-shadow: -4px 0 20px rgba(0,0,0,.1);
  z-index: 160;
  transition: right .3s ease;
  font-family: 'Source Sans 3', sans-serif;
  display: flex;
  flex-direction: column;
}
.notes-panel.open { right: 0; }

.notes-header {
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.notes-header h4 { font-size: 16px; color: var(--navy); }
.notes-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: #999;
  padding: 4px;
}
.notes-close:hover { color: var(--dark-gray); }

.notes-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.note-item {
  background: #FAFAF8;
  border: 1px solid #eee;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 10px;
  position: relative;
}
.note-item .note-text-preview {
  font-size: 13px;
  color: var(--teal);
  font-style: italic;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px dotted #ddd;
}
.note-item .note-content {
  font-size: 14px;
  color: var(--dark-gray);
  line-height: 1.5;
}
.note-item .note-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  color: #ccc;
  cursor: pointer;
  font-size: 16px;
}
.note-item .note-delete:hover { color: #C62828; }

.notes-empty {
  text-align: center;
  padding: 40px 20px;
  color: #999;
  font-size: 14px;
}

.add-note-area {
  padding: 12px 20px;
  border-top: 1px solid #eee;
}
.add-note-area textarea {
  width: 100%;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 10px;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 14px;
  resize: vertical;
  min-height: 60px;
}
.add-note-area button {
  margin-top: 8px;
  width: 100%;
  padding: 8px;
  background: var(--teal);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 14px;
  font-weight: 600;
}
.add-note-area button:hover { background: var(--navy); }

/* ---- Body State Classes ---- */

body.font-large { font-size: 19px; }
body.font-large p { font-size: 19px; }
body.font-large .vocab-box p,
body.font-large .stop-think p,
body.font-large .primary-source p,
body.font-large .story-box p,
body.font-large .activity-box p,
body.font-large .activity-box li { font-size: 17px; }
body.font-large .perspectives .perspective,
body.font-large .key-idea p,
body.font-large .voices-left-out p { font-size: 18px; }

body.font-xlarge { font-size: 21px; }
body.font-xlarge p { font-size: 21px; }
body.font-xlarge .vocab-box p,
body.font-xlarge .stop-think p,
body.font-xlarge .primary-source p,
body.font-xlarge .story-box p,
body.font-xlarge .activity-box p,
body.font-xlarge .activity-box li { font-size: 19px; }
body.font-xlarge .perspectives .perspective,
body.font-xlarge .key-idea p,
body.font-xlarge .voices-left-out p { font-size: 20px; }

body.spacing-wide { line-height: 2.2; }
body.spacing-wide p { line-height: 2.2; }

body.spacing-xwide { line-height: 2.5; }
body.spacing-xwide p { line-height: 2.5; }

body.font-sans { font-family: 'Source Sans 3', 'Segoe UI', sans-serif; }
body.font-sans .series,
body.font-sans .attribution,
body.font-sans .vocab-box p,
body.font-sans .stop-think p,
body.font-sans .key-idea p,
body.font-sans .primary-source p,
body.font-sans .story-box p,
body.font-sans .voices-left-out p,
body.font-sans .activity-box p,
body.font-sans .activity-box li,
body.font-sans .perspectives .perspective,
body.font-sans figcaption,
body.font-sans footer { font-family: 'Source Sans 3', 'Segoe UI', sans-serif; }

body.dyslexia-font { font-family: 'OpenDyslexic', 'Comic Sans MS', sans-serif; word-spacing: 0.12em; letter-spacing: 0.03em; }
body.dyslexia-font .series,
body.dyslexia-font .attribution,
body.dyslexia-font .vocab-box p,
body.dyslexia-font .stop-think p,
body.dyslexia-font .key-idea p,
body.dyslexia-font .primary-source p,
body.dyslexia-font .story-box p,
body.dyslexia-font .voices-left-out p,
body.dyslexia-font .activity-box p,
body.dyslexia-font .activity-box li,
body.dyslexia-font .perspectives .perspective,
body.dyslexia-font figcaption,
body.dyslexia-font footer { font-family: 'OpenDyslexic', 'Comic Sans MS', sans-serif; }

body.high-contrast { background: #fff; color: #000; }
body.high-contrast .title-page { background: #000; }
body.high-contrast .vocab-box { background: #e0f7fa; }
body.high-contrast .stop-think { background: #fff8e1; }
body.high-contrast .perspectives { background: #f3e5f5; }
body.high-contrast .key-idea { background: #e8f5e9; }
body.high-contrast .primary-source { background: #fff3e0; }
body.high-contrast .story-box { background: #fff3e0; }
body.high-contrast .voices-left-out { background: #fce4ec; }
body.high-contrast section h2 { border-bottom-color: #000; }

body.sepia { background: #F4EDDE; }
body.sepia .container { background: #F4EDDE; }
body.sepia .toc { background: #FAF5EA; }
body.sepia .overview { background: #EDE6D6; }
body.sepia .big-questions { background: #FAF5EA; }

/* ---- Dark Mode ---- */

body.dark-mode {
  background: #121212;
  color: #e0e0e0;
}
body.dark-mode a { color: #7ab8e0; }
body.dark-mode .title-page {
  background: linear-gradient(170deg, #080e18 0%, #0d1b2a 40%, #152535 100%);
}
body.dark-mode .chapter-nav {
  background: #1a1a1a;
  border-bottom-color: #333;
}
body.dark-mode .chapter-nav a { color: #7ab8e0; }
body.dark-mode .chapter-nav a:hover { background: #333; color: #fff; }
body.dark-mode .chapter-nav .nav-center { color: #7ab8e0; }
body.dark-mode .chapter-nav .nav-center a { color: #7ab8e0; }

body.dark-mode .toc { background: #1e1e1e; border-color: #333; }
body.dark-mode .toc h2 { color: #7ab8e0; }
body.dark-mode .toc a { color: #7ab8e0; }
body.dark-mode .toc li::before { color: #e8b94e; }

body.dark-mode .overview { background: #14222e; border-left-color: #4dd0c8; }
body.dark-mode .overview h2 { color: #4dd0c8; }
body.dark-mode .overview p { color: #ccc; }

body.dark-mode .big-questions { background: #1e1e1e; border-color: #e8b94e; }
body.dark-mode .big-questions h2 { color: #e8b94e; }
body.dark-mode .big-questions li { color: #ccc; }
body.dark-mode .big-questions li::before { color: #e8b94e; }

body.dark-mode section h2 { color: #7ab8e0; border-bottom-color: #333; }
body.dark-mode section h3 { color: #7ab8e0; }
body.dark-mode p { color: #d0d0d0; }

body.dark-mode .vocab-box { background: #0f1e25; border-left-color: #4dd0c8; }
body.dark-mode .vocab-box h3 { color: #4dd0c8; }
body.dark-mode .vocab-box p { color: #ccc; border-bottom-color: #1a2e38; }
body.dark-mode .vocab-box strong { color: #4dd0c8; }

body.dark-mode .stop-think { background: #1c1810; border-left-color: #e8b94e; }
body.dark-mode .stop-think h3 { color: #c9a035; }
body.dark-mode .stop-think p { color: #b0b0b0; }

body.dark-mode .perspectives { background: #1a1525; border-left-color: #a78bfa; }
body.dark-mode .perspectives h3 { color: #a78bfa; border-bottom-color: rgba(167,139,250,.2); }
body.dark-mode .perspectives .perspective { color: #ccc; border-left-color: rgba(167,139,250,.25); }
body.dark-mode .perspectives .perspective + .perspective { border-top-color: rgba(167,139,250,.12); }
body.dark-mode .perspectives .perspective strong { color: #c4b5fd; }

body.dark-mode .key-idea { background: #101e10; border-left-color: #66bb6a; }
body.dark-mode .key-idea h3 { color: #66bb6a; border-bottom-color: rgba(102,187,106,.2); }
body.dark-mode .key-idea p { color: #ccc; }

body.dark-mode .primary-source { background: #1c1410; border-left-color: #e57652; }
body.dark-mode .primary-source h3 { color: #e57652; }
body.dark-mode .primary-source p { color: #b8b8b8; }
body.dark-mode .primary-source .source-citation { color: #777; border-top-color: rgba(255,255,255,.08); }

body.dark-mode .story-box { background: #1c1710; border-left-color: #f0a050; }
body.dark-mode .story-box h3 { color: #e0952a; }
body.dark-mode .story-box p { color: #ccc; }

body.dark-mode .voices-left-out { background: #1c1018; border-left-color: #e05588; }
body.dark-mode .voices-left-out h3 { color: #e05588; border-bottom-color: rgba(224,85,136,.2); }
body.dark-mode .voices-left-out p { color: #ccc; border-bottom-color: rgba(224,85,136,.1); }
body.dark-mode .voices-left-out strong { color: #f06090; }

body.dark-mode .activity-box { background: #1e1e1e; border-color: #333; border-top-color: #7ab8e0; }
body.dark-mode .activity-box h3 { color: #7ab8e0; border-bottom-color: #333; }
body.dark-mode .activity-box h4 { color: #7ab8e0; }
body.dark-mode .activity-box p,
body.dark-mode .activity-box li { color: #ccc; }

body.dark-mode figure { background: #1a1a1a; }
body.dark-mode figcaption { background: #222; border-top-color: #333; color: #999; }
body.dark-mode figure.map-figure { border-color: #3a5a7a; background: #1a2a3a; }
body.dark-mode figure.map-figure img { background: #1e1e1e; }
body.dark-mode figure.map-figure figcaption { background: #1a2a3a; border-top-color: #3a5a7a; color: #8ab4d8; }

body.dark-mode footer { border-top-color: #333; color: #777; }
body.dark-mode footer a { color: #4dd0c8; border-bottom-color: #4dd0c8; }

body.dark-mode .back-to-top { background: #333; }
body.dark-mode .back-to-top:hover { background: #4dd0c8; }

body.dark-mode .reader-toggle { background: #4dd0c8; }
body.dark-mode .reader-panel { background: #1e1e1e; border-color: #333; box-shadow: 0 4px 20px rgba(0,0,0,.4); }
body.dark-mode .reader-panel h4 { color: #7ab8e0; border-bottom-color: #333; }
body.dark-mode .reader-section label { color: #888; }
body.dark-mode .reader-btn { background: #252525; border-color: #444; color: #ddd; }
body.dark-mode .reader-btn:hover { background: #333; }
body.dark-mode .reader-btn.active { background: #4dd0c8; color: #111; border-color: #4dd0c8; }

body.dark-mode .notes-panel { background: #1e1e1e; border-left-color: #333; box-shadow: -4px 0 20px rgba(0,0,0,.4); }
body.dark-mode .notes-header { border-bottom-color: #333; }
body.dark-mode .notes-header h4 { color: #7ab8e0; }
body.dark-mode .notes-close { color: #777; }
body.dark-mode .note-item { background: #252525; border-color: #333; }
body.dark-mode .note-item .note-text-preview { color: #4dd0c8; border-bottom-color: #444; }
body.dark-mode .note-item .note-content { color: #ddd; }
body.dark-mode .add-note-area { border-top-color: #333; }
body.dark-mode .add-note-area textarea { background: #252525; border-color: #444; color: #ddd; }
body.dark-mode .add-note-area button { background: #4dd0c8; color: #111; }

body.dark-mode .pdf-modal { background: #1e1e1e; box-shadow: 0 8px 32px rgba(0,0,0,.5); }
body.dark-mode .pdf-modal h3 { color: #7ab8e0; }
body.dark-mode .pdf-modal .pdf-subtitle { color: #888; }
body.dark-mode .pdf-section-list li { border-color: #333; }
body.dark-mode .pdf-section-list li:hover { background: #252525; }
body.dark-mode .pdf-section-list li label { color: #ddd; }
body.dark-mode .pdf-btn-cancel { background: #333; color: #ddd; }
body.dark-mode .pdf-select-all { color: #4dd0c8; }

body.dark-mode .glossary-panel { background: #1e1e1e; border-left-color: #333; box-shadow: -4px 0 20px rgba(0,0,0,.4); }
body.dark-mode .glossary-header { border-bottom-color: #333; }
body.dark-mode .glossary-header h4 { color: #7ab8e0; }
body.dark-mode .glossary-search-input { background: #252525; border-color: #444; color: #ddd; }
body.dark-mode .glossary-term-item { border-bottom-color: #333; }
body.dark-mode .glossary-term-word { color: #4dd0c8; }
body.dark-mode .glossary-term-def { color: #ccc; }
body.dark-mode .dict-popup { background: #1e1e1e; border-color: #444; box-shadow: 0 4px 24px rgba(0,0,0,.5); }
body.dark-mode .dict-word { color: #7ab8e0; }
body.dark-mode .dict-def { color: #ccc; }

body.dark-mode .line-focus-top,
body.dark-mode .line-focus-bottom { background: rgba(0,0,0,.75); }

body.dark-mode .progress-bar { background: #e8b94e; }

/* ---- Chapter Header Image Overlay ---- */

.title-page[style*="background-image"] {
  background-size: cover;
  background-position: center;
  position: relative;
}
.title-page[style*="background-image"]::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(170deg, rgba(13,33,55,.78) 0%, rgba(27,58,92,.70) 40%, rgba(43,90,124,.65) 100%);
  z-index: 0;
}
.title-page[style*="background-image"] > * {
  position: relative;
  z-index: 1;
}
body.dark-mode .title-page[style*="background-image"]::before {
  background: linear-gradient(170deg, rgba(8,14,24,.82) 0%, rgba(13,27,42,.75) 40%, rgba(21,37,53,.70) 100%);
}

/* ---- Glossary Panel ---- */

.glossary-panel {
  position: fixed;
  top: 0;
  right: -400px;
  width: 380px;
  height: 100%;
  background: white;
  border-left: 1px solid #ddd;
  box-shadow: -4px 0 20px rgba(0,0,0,.1);
  z-index: 160;
  transition: right .3s ease;
  font-family: 'Source Sans 3', sans-serif;
  display: flex;
  flex-direction: column;
}
.glossary-panel.open { right: 0; }

.glossary-header {
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.glossary-header h4 { font-size: 16px; color: var(--navy); }
.glossary-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: #999;
  padding: 4px;
}
.glossary-close:hover { color: var(--dark-gray); }

.glossary-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.glossary-search {
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
  position: sticky;
  top: 0;
  background: inherit;
  z-index: 1;
}
.glossary-search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 14px;
  outline: none;
}
.glossary-search-input:focus { border-color: var(--teal); }

.glossary-term-item {
  padding: 14px 20px;
  border-bottom: 1px solid #f0f0f0;
}
.glossary-term-item:last-child { border-bottom: none; }
.glossary-term-word {
  font-weight: 700;
  color: var(--navy);
  font-size: 15px;
  margin-bottom: 4px;
}
.glossary-term-def {
  font-size: 14px;
  color: #555;
  line-height: 1.55;
}
.glossary-empty {
  text-align: center;
  padding: 40px 20px;
  color: #999;
  font-size: 14px;
}
.glossary-hint {
  padding: 12px 16px;
  background: #f8f9fa;
  border-top: 1px solid #eee;
  font-size: 12px;
  color: #888;
  text-align: center;
}

/* ---- Dictionary Popup ---- */

.dict-popup {
  position: absolute;
  z-index: 500;
  background: white;
  border: 1px solid #ddd;
  border-radius: 10px;
  box-shadow: 0 4px 24px rgba(0,0,0,.15);
  padding: 16px 20px;
  max-width: 340px;
  min-width: 240px;
  font-family: 'Source Sans 3', sans-serif;
}
.dict-popup .dict-word {
  font-size: 18px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 2px;
}
.dict-popup .dict-phonetic {
  font-size: 13px;
  color: #999;
  font-style: italic;
  margin-bottom: 10px;
}
.dict-popup .dict-pos {
  font-size: 12px;
  font-weight: 700;
  color: var(--teal);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-top: 8px;
  margin-bottom: 4px;
}
.dict-popup .dict-def {
  font-size: 14px;
  color: #444;
  line-height: 1.5;
  margin-bottom: 6px;
  padding-left: 10px;
  border-left: 2px solid #eee;
}
.dict-popup .dict-loading {
  font-size: 14px;
  color: #888;
  font-style: italic;
}
.dict-popup .dict-error {
  font-size: 14px;
  color: #999;
}

/* ---- Universal Search Modal ---- */

.search-btn {
  background: none;
  border: 1px solid #ddd;
  border-radius: 6px;
  cursor: pointer;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 13px;
  color: var(--navy);
  padding: 4px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background .2s, border-color .2s;
}
.search-btn:hover { background: #f0f4f8; border-color: var(--teal); }
.search-btn .search-btn-icon {
  font-size: 14px;
  line-height: 1;
}
.search-btn kbd {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 11px;
  background: #f0f0f0;
  border: 1px solid #ddd;
  border-radius: 3px;
  padding: 1px 5px;
  color: #888;
}

.search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 900;
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s, visibility .2s;
}
.search-overlay.active { opacity: 1; visibility: visible; }

.search-modal {
  position: fixed;
  top: 15%;
  left: 50%;
  transform: translateX(-50%) scale(.96);
  width: 560px;
  max-width: 92vw;
  max-height: 70vh;
  background: white;
  border-radius: 12px;
  box-shadow: 0 16px 60px rgba(0,0,0,.25);
  z-index: 910;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s, transform .2s, visibility .2s;
  font-family: 'Source Sans 3', sans-serif;
}
.search-modal.active {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) scale(1);
}

.search-header {
  display: flex;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid #eee;
  gap: 10px;
}
.search-icon {
  font-size: 18px;
  color: #999;
  flex-shrink: 0;
}
.search-input {
  flex: 1;
  border: none;
  outline: none;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 16px;
  color: var(--dark-gray);
  background: transparent;
}
.search-input::placeholder { color: #bbb; }
.search-kbd {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 11px;
  background: #f0f0f0;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 2px 7px;
  color: #999;
  flex-shrink: 0;
}

.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}
.search-result-item {
  display: block;
  padding: 10px 18px;
  text-decoration: none;
  color: var(--dark-gray);
  border-left: 3px solid transparent;
  transition: background .1s, border-color .1s;
}
.search-result-item:hover,
.search-result-item.selected {
  background: #f0f6fa;
  border-left-color: var(--teal);
}
.search-result-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.search-result-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  background: var(--teal);
  color: white;
  padding: 1px 6px;
  border-radius: 3px;
}
.search-result-preview {
  font-size: 13px;
  color: #777;
  line-height: 1.45;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search-result-meta {
  font-size: 12px;
  color: #aaa;
  margin-top: 2px;
}

.search-hint {
  padding: 10px 18px;
  border-top: 1px solid #eee;
  font-size: 12px;
  color: #bbb;
  text-align: center;
}
.search-empty {
  padding: 24px 18px;
  text-align: center;
  font-size: 14px;
  color: #999;
}

/* Search — Dark Mode */
body.dark-mode .search-btn { border-color: #444; color: #7ab8e0; }
body.dark-mode .search-btn:hover { background: #252525; border-color: #4dd0c8; }
body.dark-mode .search-btn kbd { background: #333; border-color: #555; color: #888; }
body.dark-mode .search-overlay { background: rgba(0,0,0,.65); }
body.dark-mode .search-modal { background: #1e1e1e; box-shadow: 0 16px 60px rgba(0,0,0,.5); }
body.dark-mode .search-header { border-bottom-color: #333; }
body.dark-mode .search-icon { color: #666; }
body.dark-mode .search-input { color: #e0e0e0; }
body.dark-mode .search-input::placeholder { color: #555; }
body.dark-mode .search-kbd { background: #333; border-color: #555; color: #777; }
body.dark-mode .search-result-item { color: #ddd; }
body.dark-mode .search-result-item:hover,
body.dark-mode .search-result-item.selected { background: #252a30; border-left-color: #4dd0c8; }
body.dark-mode .search-result-badge { background: #4dd0c8; color: #111; }
body.dark-mode .search-result-preview { color: #888; }
body.dark-mode .search-result-meta { color: #666; }
body.dark-mode .search-hint { border-top-color: #333; color: #555; }
body.dark-mode .search-empty { color: #666; }

/* ---- Reading Time Estimate ---- */

.reading-time {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 13px;
  color: #999;
  text-align: center;
  margin-bottom: 32px;
  letter-spacing: .3px;
}

/* ---- Read Aloud Controls ---- */

.tts-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.tts-speed {
  width: 80px;
  height: 4px;
  accent-color: var(--teal);
}
.tts-speed-label {
  font-size: 11px;
  color: #888;
  min-width: 32px;
}

body.dark-mode .tts-speed-label { color: #888; }

/* ---- TTS Paragraph Highlighting ---- */

.tts-speaking {
  background: #fff3cd;
  border-left: 4px solid var(--gold);
  padding-left: 12px;
  transition: background 0.3s ease;
}
body.dark-mode .tts-speaking {
  background: #332b00;
  border-left-color: #e8b94e;
}
body.sepia .tts-speaking {
  background: #f0e4c0;
}
body.high-contrast .tts-speaking {
  background: #ffffcc;
  border-left-color: #000;
}

/* Start-here marker (user picked a start paragraph) */
.tts-start-mark {
  border-left: 4px solid var(--teal);
  padding-left: 12px;
  background: #e0f7fa;
}
body.dark-mode .tts-start-mark {
  background: #0a2025;
  border-left-color: #4dd0c8;
}

/* Pick-mode cursor: show pointer over readable content */
body.tts-pick-mode section p,
body.tts-pick-mode section h2,
body.tts-pick-mode section h3,
body.tts-pick-mode section li,
body.tts-pick-mode .overview p,
body.tts-pick-mode .overview h2,
body.tts-pick-mode .big-questions li {
  cursor: pointer;
  outline: 2px dashed transparent;
  transition: outline-color 0.15s;
}
body.tts-pick-mode section p:hover,
body.tts-pick-mode section h2:hover,
body.tts-pick-mode section h3:hover,
body.tts-pick-mode section li:hover,
body.tts-pick-mode .overview p:hover,
body.tts-pick-mode .overview h2:hover,
body.tts-pick-mode .big-questions li:hover {
  outline-color: var(--teal);
  background: rgba(42, 127, 142, 0.07);
}

/* ---- Reduced Motion ---- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .progress-bar { transition: none; }
  .notes-panel { transition: none; }
  .glossary-panel { transition: none; }
  .search-overlay { transition: none; }
  .search-modal { transition: none; }
}

/* ---- Print Styles ---- */

@media print {
  .title-page { page-break-after: always; }
  section { page-break-inside: avoid; }
  figure { page-break-inside: avoid; }
  .chapter-nav, .reader-toolbar, .reader-panel, .back-to-top, .progress-bar,
  .notes-panel, .glossary-panel, .line-focus-overlay, .pdf-modal-overlay, .dict-popup,
  .search-overlay, .search-modal { display: none !important; }
}

@media (max-width: 768px) {
  .container { max-width: 90%; padding: 36px 20px; }
  .chapter-title { font-size: 40px; }
  section h2 { font-size: 26px; }
  .vocab-box, .key-idea, .perspectives, .story-box, .stop-think,
  .primary-source, .voices-left-out, .activity-box { padding: 18px 22px; }
  figure img { border-radius: 4px; }
}

@media (max-width: 600px) {
  .chapter-title { font-size: 36px; }
  .container { padding: 32px 16px; }
  section h2 { font-size: 24px; }
  .chapter-nav { padding: 8px 12px; font-size: 13px; }
  .chapter-nav a { padding: 6px 8px; }
  .reader-panel { min-width: 220px; }
  .notes-panel { width: 280px; right: -300px; }
  .glossary-panel { width: 300px; right: -320px; }
}

/* ---- PDF Builder Modal ---- */

.pdf-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,.5);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
}
.pdf-modal-overlay.open { display: flex; }

.pdf-modal {
  background: white;
  border-radius: 12px;
  padding: 32px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
  font-family: 'Source Sans 3', sans-serif;
}
.pdf-modal h3 {
  font-size: 20px;
  color: var(--navy);
  margin-bottom: 4px;
}
.pdf-modal .pdf-subtitle {
  font-size: 13px;
  color: #999;
  margin-bottom: 20px;
}

.pdf-section-list {
  list-style: none;
  padding: 0;
  margin-bottom: 20px;
}
.pdf-section-list li {
  padding: 10px 12px;
  border: 1px solid #eee;
  border-radius: 6px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background .15s;
}
.pdf-section-list li:hover { background: #f9f9f9; }
.pdf-section-list li input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}
.pdf-section-list li label {
  font-size: 14px;
  cursor: pointer;
  flex: 1;
}

.pdf-actions {
  display: flex;
  gap: 10px;
}
.pdf-actions button {
  flex: 1;
  padding: 10px;
  border-radius: 6px;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
}
.pdf-btn-print {
  background: var(--navy);
  color: white;
}
.pdf-btn-print:hover { background: var(--teal); }
.pdf-btn-cancel {
  background: #f0f0f0;
  color: var(--dark-gray);
}
.pdf-btn-cancel:hover { background: #e0e0e0; }
.pdf-select-all {
  font-size: 13px;
  color: var(--teal);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  margin-bottom: 12px;
  font-family: 'Source Sans 3', sans-serif;
  text-decoration: underline;
}
