/* ═══════════════════════════════════════════════════════════
   The Discourses — Epictetus
   Ancient Roman theme · Minimalist · Optimised for reading
   ═══════════════════════════════════════════════════════════ */

/* ── Variables ── */
:root {
  --parchment:      #f5f0e8;
  --parchment-dark: #ede6d5;
  --ink:            #2a1f14;
  --ink-light:      #4a3728;
  --ink-faint:      #7a6455;
  --gold:           #8b6914;
  --gold-light:     #c8a84b;
  --gold-pale:      #e8d5a0;
  --burgundy:       #6b1a26;
  --burgundy-light: #922535;
  --terracotta:     #8b3a2a;
  --rule:           #c4a96b;
  --rule-light:     #ddd0b0;

  --sidebar-w:      320px;
  --sidebar-bg:     #201510;
  --sidebar-text:   #d4c4a8;
  --sidebar-accent: #c8a84b;
  --sidebar-hover:  rgba(200, 168, 75, 0.12);
  --sidebar-active: rgba(200, 168, 75, 0.22);

  --body-font:      'Crimson Pro', 'Palatino Linotype', Georgia, serif;
  --head-font:      'Cinzel', 'Trajan Pro', 'Times New Roman', serif;

  --reading-w:      68ch;
  --line-h:         1.85;
  --transition:     0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
  font-size: 18px;
}

body {
  font-family: var(--body-font);
  background: var(--parchment);
  color: var(--ink);
  display: flex;
  min-height: 100vh;
  line-height: var(--line-h);
}

/* ══════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════ */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 100;
  transition: transform var(--transition), width var(--transition);
  border-right: 1px solid #3a2a1a;
}

.sidebar.hidden {
  transform: translateX(-100%);
}

/* Sidebar header */
.sidebar-header {
  padding: 2rem 1.6rem 1.4rem;
  border-bottom: 1px solid rgba(200, 168, 75, 0.25);
  flex-shrink: 0;
  text-align: center;
}

.sidebar-laurel {
  color: var(--gold-light);
  font-size: 0.85rem;
  letter-spacing: 0.2em;
  margin-bottom: 0.7rem;
  opacity: 0.75;
}

.sidebar-title {
  font-family: var(--head-font);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--sidebar-accent);
  letter-spacing: 0.08em;
  line-height: 1.3;
}

.sidebar-author {
  font-family: var(--head-font);
  font-size: 0.75rem;
  color: var(--sidebar-text);
  letter-spacing: 0.15em;
  margin-top: 0.35rem;
  opacity: 0.85;
}

.sidebar-translator {
  font-size: 0.72rem;
  color: var(--sidebar-text);
  opacity: 0.45;
  margin-top: 0.25rem;
  font-style: italic;
}

/* TOC nav */
.toc {
  flex: 1;
  overflow-y: auto;
  padding: 0.8rem 0;
  scrollbar-width: thin;
  scrollbar-color: #4a3020 var(--sidebar-bg);
}

.toc::-webkit-scrollbar { width: 4px; }
.toc::-webkit-scrollbar-track { background: transparent; }
.toc::-webkit-scrollbar-thumb { background: #4a3020; border-radius: 2px; }

.toc-books { list-style: none; }

/* Book group */
.toc-book { margin-bottom: 0.15rem; }

.toc-book-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.6rem 1.4rem 0.6rem 1.6rem;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--sidebar-accent);
  font-family: var(--head-font);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  transition: background var(--transition);
}

.toc-book-toggle:hover { background: var(--sidebar-hover); }

.toc-chevron {
  font-size: 0.65rem;
  transition: transform var(--transition);
  opacity: 0.7;
  flex-shrink: 0;
}

/* Chapter list */
.toc-chapters {
  list-style: none;
  overflow: hidden;
  max-height: 9999px;
  transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
              opacity var(--transition);
  opacity: 1;
}

.toc-chapters.collapsed {
  max-height: 0;
  opacity: 0;
}

.toc-chapter { margin: 0; }

.toc-link {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.35rem 1.4rem 0.35rem 2rem;
  text-decoration: none;
  color: var(--sidebar-text);
  font-size: 0.78rem;
  line-height: 1.45;
  transition: background var(--transition), color var(--transition);
  border-left: 2px solid transparent;
}

.toc-link:hover {
  background: var(--sidebar-hover);
  color: #e8d8c0;
  border-left-color: rgba(200, 168, 75, 0.4);
}

.toc-link.active {
  background: var(--sidebar-active);
  color: var(--sidebar-accent);
  border-left-color: var(--sidebar-accent);
}

.toc-ch-num {
  font-family: var(--head-font);
  font-size: 0.65rem;
  color: var(--gold-light);
  opacity: 0.7;
  flex-shrink: 0;
  min-width: 1.5rem;
}

.toc-ch-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 1.2rem 1.6rem;
  border-top: 1px solid rgba(200, 168, 75, 0.2);
  flex-shrink: 0;
}

.sidebar-quote {
  font-size: 0.72rem;
  line-height: 1.6;
  font-style: italic;
  color: var(--sidebar-text);
  opacity: 0.45;
}

/* ══════════════════════════════════════════
   SIDEBAR TOGGLE BUTTON
══════════════════════════════════════════ */

.sidebar-toggle {
  position: fixed;
  top: 1.2rem;
  left: calc(var(--sidebar-w) + 1rem);
  z-index: 200;
  width: 2.2rem;
  height: 2.2rem;
  background: var(--parchment-dark);
  border: 1px solid var(--rule);
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0.45rem;
  transition: left var(--transition), background var(--transition), border-color var(--transition);
  box-shadow: 0 1px 4px rgba(42,31,20,0.12);
}

.sidebar-toggle span {
  display: block;
  width: 100%;
  height: 1.5px;
  background: var(--ink-light);
  border-radius: 1px;
  transition: opacity var(--transition), transform var(--transition), background var(--transition);
}

.sidebar-toggle:hover {
  background: var(--gold-pale);
  border-color: var(--gold);
}

.sidebar-toggle:hover span { background: var(--gold); }

/* When sidebar is hidden, button moves to left edge */
.sidebar.hidden ~ .sidebar-toggle,
.sidebar-toggle:not(.open) {
  left: 1rem;
}

/* ══════════════════════════════════════════
   MAIN CONTENT
══════════════════════════════════════════ */

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  padding: 0 2rem 6rem;
  transition: margin-left var(--transition);
}

.main-content.full-width {
  margin-left: 0;
}

/* ── Page Header ── */
.page-header {
  max-width: var(--reading-w);
  margin: 5rem auto 4rem;
  text-align: center;
  padding: 0 1rem;
}

.header-ornament {
  font-size: 1rem;
  color: var(--gold);
  letter-spacing: 0.5em;
  opacity: 0.6;
  margin-bottom: 1.8rem;
}

.page-title {
  font-family: var(--head-font);
  font-size: 2.6rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.06em;
  line-height: 1.2;
  margin-bottom: 1.2rem;
}

.page-subtitle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  font-family: var(--head-font);
  font-size: 0.8rem;
  letter-spacing: 0.2em;
  color: var(--ink-faint);
  margin-bottom: 1.8rem;
}

.header-rule {
  display: block;
  width: 2rem;
  height: 1px;
  background: var(--rule);
}

.author-name { color: var(--burgundy); }
.translator-note { font-style: normal; }

.epigraph {
  max-width: 46ch;
  margin: 0 auto;
  font-style: italic;
  font-size: 1.0rem;
  color: var(--ink-faint);
  line-height: 1.75;
  border-left: 2px solid var(--gold-pale);
  padding-left: 1.2rem;
  text-align: left;
}

/* ── Book Dividers ── */
.book-divider {
  max-width: var(--reading-w);
  margin: 5rem auto 3rem;
  text-align: center;
  padding: 2.5rem 1rem;
  position: relative;
}

.book-divider::before {
  content: '';
  display: block;
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--rule), transparent);
  margin-bottom: 2rem;
}

.book-divider::after {
  content: '';
  display: block;
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--rule), transparent);
  margin-top: 2rem;
}

.book-ornament {
  font-size: 0.9rem;
  color: var(--gold);
  letter-spacing: 0.5em;
  opacity: 0.5;
  margin: 0.6rem 0;
}

.book-ornament::before { content: '⸻  ✦  ⸻'; }

.book-heading {
  font-family: var(--head-font);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--burgundy);
  letter-spacing: 0.12em;
  line-height: 1.2;
}

.book-subtitle {
  font-family: var(--head-font);
  font-size: 0.72rem;
  letter-spacing: 0.3em;
  color: var(--ink-faint);
  text-transform: uppercase;
  margin-top: 0.4rem;
}

/* ── Chapter Sections ── */
.chapter-section {
  max-width: var(--reading-w);
  margin: 0 auto 0;
  padding: 2.8rem 1rem 0;
  position: relative;
}

.chapter-section + .chapter-section {
  border-top: 1px solid var(--rule-light);
  margin-top: 1.5rem;
  padding-top: 2.8rem;
}

/* Chapter header — clickable to collapse */
.chapter-header {
  cursor: pointer;
  margin-bottom: 1.6rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--gold-pale);
  user-select: none;
  position: relative;
}

.chapter-header::after {
  content: '▾';
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gold);
  opacity: 0.5;
  font-size: 0.85rem;
  transition: transform var(--transition), opacity var(--transition);
}

.chapter-section.collapsed .chapter-header::after {
  transform: translateY(-50%) rotate(-90deg);
}

.chapter-section.collapsed .chapter-body {
  display: none;
}

.chapter-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--head-font);
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  color: var(--ink-faint);
  text-transform: uppercase;
  margin-bottom: 0.55rem;
}

.chapter-book-label { color: var(--gold); opacity: 0.8; }
.chapter-divider { color: var(--rule); }
.chapter-num-label { }

.chapter-title {
  font-family: var(--head-font);
  font-size: 1.18rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.03em;
  line-height: 1.35;
  padding-right: 1.5rem;
}

/* Chapter body */
.chapter-body {
  overflow: hidden;
}

.chapter-body p {
  font-size: 1rem;
  line-height: var(--line-h);
  color: var(--ink);
  margin-bottom: 0;
  text-indent: 2em;
  text-align: justify;
  hyphens: auto;
  font-weight: 300;
}

/* First paragraph after the header gets no indent — the drop cap is the signal */
.chapter-body p:first-child {
  text-indent: 0;
}

.chapter-body p:first-child::first-letter {
  font-family: var(--head-font);
  font-size: 3.2em;
  float: left;
  line-height: 0.78;
  margin: 0.08em 0.1em -0.05em 0;
  color: var(--burgundy);
  font-weight: 400;
}

/* ── Page Footer ── */
.page-footer {
  max-width: var(--reading-w);
  margin: 6rem auto 0;
  padding: 2.5rem 1rem;
  text-align: center;
  border-top: 1px solid var(--rule-light);
}

.footer-ornament {
  font-size: 1.2rem;
  color: var(--gold);
  opacity: 0.4;
  margin-bottom: 1rem;
  display: block;
}

.page-footer p {
  font-size: 0.78rem;
  color: var(--ink-faint);
  opacity: 0.6;
  line-height: 1.7;
}

.footer-note { margin-top: 0.4rem; font-style: italic; }

/* ══════════════════════════════════════════
   PROGRESS BAR
══════════════════════════════════════════ */

.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0%;
  background: linear-gradient(90deg, var(--burgundy), var(--gold-light));
  z-index: 999;
  transition: width 0.1s linear;
  border-radius: 0 1px 1px 0;
}

/* ══════════════════════════════════════════
   SCROLLBAR (main)
══════════════════════════════════════════ */

html {
  scrollbar-width: thin;
  scrollbar-color: var(--rule) var(--parchment);
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--parchment-dark); }
::-webkit-scrollbar-thumb {
  background: var(--rule);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--gold); }

/* ══════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════ */

@media (max-width: 900px) {
  :root { --sidebar-w: 280px; }

  .main-content {
    padding: 0 1.2rem 4rem;
  }

  .page-title { font-size: 2rem; }
}

@media (max-width: 680px) {
  .sidebar {
    width: 100%;
    max-width: 320px;
    transform: translateX(-100%);
  }

  .sidebar.hidden { transform: translateX(-100%); }
  .sidebar:not(.hidden) { transform: translateX(0); }

  .main-content { margin-left: 0 !important; }

  .sidebar-toggle {
    left: 1rem !important;
  }

  .page-header { margin-top: 4rem; }

  .chapter-body p:first-child::first-letter {
    font-size: 2.5em;
  }
}

/* ══════════════════════════════════════════
   PRINT
══════════════════════════════════════════ */

@media print {
  .sidebar, .sidebar-toggle, .progress-bar { display: none; }
  .main-content { margin: 0; padding: 0; }
  .chapter-section.collapsed .chapter-body { display: block !important; }
}

/* ══════════════════════════════════════════
   SELECTION COLOUR
══════════════════════════════════════════ */

::selection {
  background: var(--gold-pale);
  color: var(--ink);
}
