:root {
  --book-bg: #f4efe4;
  --book-surface: #fbf7ef;
  --book-text: #2b2d2f;
  --book-heading: #24334a;
  --book-accent: #1a5f8a;
  --book-accent-soft: #5ea6d3;
  --book-muted: #5f6670;
  --book-border: rgba(22, 38, 65, 0.2);
  --book-shadow: 0 14px 30px rgba(24, 35, 56, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: linear-gradient(140deg, #efe8d9, #e4dac2);
  color: var(--book-text);
  font-family: "Georgia", "Times New Roman", serif;
  min-height: 100vh;
}

.reader-shell {
  width: min(1150px, 96vw);
  margin: 10px auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.reader-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(28, 48, 78, 0.9);
  color: #f6f9ff;
  box-shadow: var(--book-shadow);
}

.reader-header h1 {
  margin: 4px 0 1px;
  font-family: "Trebuchet MS", "Gill Sans", sans-serif;
  letter-spacing: 0.2px;
  font-size: clamp(1.1rem, 2vw, 1.45rem);
  line-height: 1.25;
}

.reader-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.reader-title {
  min-width: 0;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: rgba(240, 245, 255, 0.86);
  font-size: 11px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
}

.control-form {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.menu-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
  justify-content: flex-end;
}

.control-form label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  white-space: nowrap;
}

select, .cta {
  border: 1px solid var(--book-border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
  font-family: "Inter", "Segoe UI", sans-serif;
  line-height: 1.2;
}

.cta {
  height: 31px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: #f0f4ff;
  background: #325d84;
  border-color: #84b6da;
  padding-inline: 10px;
  white-space: nowrap;
}

.chapter-nav {
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(255, 253, 246, 0.9);
  border: 1px solid var(--book-border);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  flex-wrap: wrap;
}

.chapter-nav select {
  flex: 1;
  min-height: 31px;
  border-radius: 8px;
  font-size: 12px;
}

.chapter-nav label {
  font-size: 12px;
  color: var(--book-muted);
}

.reader-layout {
  display: grid;
  gap: 14px;
}

.toc-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.toc-item {
  border-bottom: 1px solid var(--book-border);
  padding: 10px 0;
}

.toc-item.level-3 {
  padding-left: 14px;
}

.toc-item.level-4 {
  padding-left: 28px;
}

.toc-link {
  color: var(--book-heading);
  text-decoration: none;
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toc-link:hover {
  text-decoration: underline;
}

.toc-title {
  font-weight: 700;
}

.toc-subtitle {
  color: var(--book-muted);
  font-size: 14px;
}

.compare-mode {
  grid-template-columns: 1fr 1fr;
}

.single-mode {
  grid-template-columns: 1fr;
}

.hidden-mobile {
  display: none;
}

.page-card {
  background: linear-gradient(180deg, #fffef8, #f3eedd);
  border-radius: 14px;
  border: 1px solid var(--book-border);
  box-shadow: var(--book-shadow);
  padding: 16px 18px;
  min-height: 65vh;
}

.page-title {
  margin-bottom: 12px;
  color: var(--book-heading);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--book-border);
  padding-bottom: 8px;
}

.reading-page {
  max-width: 72ch;
  margin: 0 auto;
  line-height: 1.72;
  font-size: 18px;
  letter-spacing: 0.1px;
}

.reading-page h1,
.reading-page h2,
.reading-page h3,
.reading-page h4,
.reading-page h5,
.reading-page h6 {
  color: var(--book-heading);
  scroll-margin-top: 84px;
}

.reading-page h1 {
  margin-top: 0.4em;
}

.reading-page h2,
.reading-page h3,
.reading-page h4 {
  margin-top: 1em;
}

.reading-page p {
  margin: 0.7em 0;
}

.reading-page ul {
  padding-left: 1.2em;
  margin: 0.8em 0;
}

.reading-page li {
  margin: 0.25em 0;
}

.reading-page .chapter-figure {
  max-width: 100%;
  width: 100%;
  display: block;
  margin: 14px 0;
  border: 1px solid var(--book-border);
  border-radius: 10px;
}

.reader-note {
  margin: 0;
  color: var(--book-muted);
  font-size: 13px;
}

@media (max-width: 900px) {
  .reader-header-top {
    align-items: stretch;
    flex-direction: column;
  }

  .reader-layout.compare-mode {
    grid-template-columns: 1fr;
  }

  .controls {
    gap: 6px;
  }

  .control-form {
    width: 100%;
  }

  .cta {
    width: 100%;
    text-align: center;
    justify-content: center;
    min-height: 34px;
    font-size: 13px;
  }

  .menu-actions {
    width: 100%;
  }

  .chapter-nav {
    gap: 8px;
  }

  .chapter-nav {
    flex-direction: column;
    align-items: stretch;
  }

  .chapter-nav select {
    width: 100%;
  }
}

@media (max-width: 720px) {
  .reader-shell {
    width: 100%;
    padding: 8px;
    gap: 8px;
  }

  .reader-header {
    border-radius: 10px;
    padding: 8px;
  }

  .reader-header h1 {
    font-size: 1rem;
    line-height: 1.28;
  }

  .reader-title {
    min-width: 0;
  }

  .reader-title p,
  .reader-header h1 {
    overflow-wrap: anywhere;
  }

  .menu-actions {
    gap: 4px;
  }

  .control-form label {
    width: 100%;
    justify-content: space-between;
  }

  .control-form label select {
    width: 120px;
  }
}

a[aria-disabled='true'] {
  opacity: 0.45;
  pointer-events: none;
}
