/* =============================================
   The Long Middle — Reading Experience
   Premium long-form literary styling
   ============================================= */

/* --- Custom Properties (Light Theme) --- */
:root {
  --bg: #faf9f6;
  --bg-surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #5a5a5a;
  --text-faint: #8a8a8a;
  --accent: #8b5e3c;
  --accent-hover: #6d4a2e;
  --border: #e0ddd8;
  --progress: #8b5e3c;
  --toc-bg: #f5f3ef;
  --shadow: rgba(0, 0, 0, 0.08);
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --content-width: 680px;
  --gutter: 1.5rem;
}

/* --- Dark Theme --- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121212;
    --bg-surface: #1e1e1e;
    --text: #e8e6e3;
    --text-muted: #a0a0a0;
    --text-faint: #6a6a6a;
    --accent: #c9956b;
    --accent-hover: #daa882;
    --border: #2e2e2e;
    --progress: #c9956b;
    --toc-bg: #1a1a1a;
    --shadow: rgba(0, 0, 0, 0.3);
  }
}

[data-theme="dark"] {
  --bg: #121212;
  --bg-surface: #1e1e1e;
  --text: #e8e6e3;
  --text-muted: #a0a0a0;
  --text-faint: #6a6a6a;
  --accent: #c9956b;
  --accent-hover: #daa882;
  --border: #2e2e2e;
  --progress: #c9956b;
  --toc-bg: #1a1a1a;
  --shadow: rgba(0, 0, 0, 0.3);
}

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

html {
  font-size: 18px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-serif);
  color: var(--text);
  background: var(--bg);
  line-height: 1.75;
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

a { color: var(--accent); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--accent-hover); }

img { max-width: 100%; height: auto; }

/* --- Progress Bar --- */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 0%;
  height: 3px;
  background: var(--progress);
  z-index: 1000;
  transition: width 0.1s linear;
}

/* --- TOC Toggle Button --- */
.toc-toggle {
  position: fixed;
  top: 1.2rem;
  left: 1.2rem;
  z-index: 999;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  cursor: pointer;
  color: var(--text);
  box-shadow: 0 2px 8px var(--shadow);
  transition: background 0.2s, transform 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.toc-toggle:hover { transform: scale(1.05); }

/* --- TOC Sidebar --- */
.toc-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 320px;
  max-width: 85vw;
  height: 100vh;
  background: var(--toc-bg);
  border-right: 1px solid var(--border);
  z-index: 1001;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  overflow-y: auto;
  padding: 1.5rem;
}
.toc-sidebar.open { transform: translateX(0); }

.toc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.toc-header h2 {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.toc-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 0.25rem;
}

.toc-list {
  list-style: none;
  counter-reset: toc;
}
.toc-list li { counter-increment: toc; }
.toc-link {
  display: block;
  padding: 0.5rem 0;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  transition: color 0.2s, padding-left 0.2s;
}
.toc-link::before {
  content: counter(toc, decimal-leading-zero);
  margin-right: 0.75rem;
  font-weight: 600;
  color: var(--text-faint);
  font-size: 0.75rem;
}
.toc-link:hover {
  color: var(--accent);
  padding-left: 0.5rem;
}

/* --- TOC Overlay --- */
.toc-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.toc-overlay.active { opacity: 1; pointer-events: auto; }

/* --- Theme Toggle --- */
.theme-toggle {
  position: fixed;
  top: 1.2rem;
  right: 1.2rem;
  z-index: 999;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  cursor: pointer;
  color: var(--text);
  box-shadow: 0 2px 8px var(--shadow);
  font-size: 1rem;
  line-height: 1;
  transition: background 0.2s, transform 0.2s;
}
.theme-toggle:hover { transform: scale(1.05); }

/* --- Main Content --- */
.content {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 4rem var(--gutter) 3rem;
}

/* --- Landing Page --- */
.landing { padding-top: 2rem; }

.hero {
  text-align: center;
  padding: 3rem 0 2.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.5rem;
}
.hero-title {
  font-size: 2.8rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin-bottom: 0.4rem;
}
.hero-subtitle {
  font-size: 1.2rem;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 1rem;
}
.hero-tagline {
  font-size: 1rem;
  color: var(--accent);
  margin-bottom: 1.5rem;
}
.hero-author {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.book-intro {
  font-size: 1.05rem;
  color: var(--text-muted);
  text-align: center;
  max-width: 560px;
  margin: 0 auto 3rem;
  line-height: 1.8;
}

/* --- Chapter Index on Landing --- */
.chapter-index { margin-bottom: 3rem; }
.chapter-index-title {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 1.2rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}
.chapter-list { list-style: none; }
.chapter-item { border-bottom: 1px solid var(--border); }
.chapter-link {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.75rem 0;
  transition: padding-left 0.2s, color 0.2s;
}
.chapter-link:hover { padding-left: 0.5rem; }
.chapter-number {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-faint);
  min-width: 1.8rem;
}
.chapter-name {
  font-size: 1rem;
  color: var(--text);
}
.chapter-link:hover .chapter-name { color: var(--accent); }

/* --- CTA Buttons --- */
.cta {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
  padding: 2rem 0 1rem;
}
.cta-button {
  display: inline-block;
  padding: 0.75rem 2rem;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 6px;
  transition: background 0.2s, transform 0.15s;
}
.cta-button:hover { background: var(--accent-hover); color: #fff; transform: translateY(-1px); }
.cta-secondary {
  display: inline-block;
  padding: 0.75rem 2rem;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 6px;
  transition: border-color 0.2s, color 0.2s;
}
.cta-secondary:hover { border-color: var(--accent); color: var(--accent); }

/* --- Chapter Reading View --- */
.chapter-header {
  text-align: center;
  padding: 2rem 0 2.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.5rem;
}
.chapter-label {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  display: block;
  margin-bottom: 0.5rem;
}
.chapter-title {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.chapter-body p {
  margin-bottom: 1.4rem;
  text-indent: 0;
  orphans: 3;
  widows: 3;
}
.chapter-body p:first-child::first-letter {
  font-size: 3.2em;
  float: left;
  line-height: 0.8;
  margin: 0.05em 0.1em 0 0;
  color: var(--accent);
  font-weight: 700;
}

/* --- Chapter Navigation --- */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2rem 0;
  margin-top: 3rem;
  border-top: 1px solid var(--border);
  gap: 1rem;
}
.chapter-nav-link {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: border-color 0.2s, color 0.2s;
}
.chapter-nav-link:hover { border-color: var(--accent); color: var(--accent); }
.chapter-nav-link.home {
  border: none;
  color: var(--text-faint);
}
.chapter-nav-link.prev { margin-right: auto; }
.chapter-nav-link.next { margin-left: auto; }

/* --- Footer --- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 2rem var(--gutter);
  margin-top: 4rem;
}
.footer-inner {
  max-width: var(--content-width);
  margin: 0 auto;
  text-align: center;
}
.footer-credit {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}
.footer-actions {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 0.75rem;
}
.footer-download {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
}
.footer-download:hover { color: var(--accent-hover); }
.footer-framework {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  color: var(--text-faint);
}
.footer-framework a {
  color: var(--text-faint);
  font-weight: 500;
}
.footer-framework a:hover { color: var(--accent); }
.oxidite-logo {
  vertical-align: middle;
  margin-left: 0.2rem;
  opacity: 0.7;
}

/* --- Responsive --- */
@media (max-width: 640px) {
  html { font-size: 16px; }
  .hero-title { font-size: 2rem; }
  .chapter-title { font-size: 1.5rem; }
  .content { padding: 3rem 1rem 2rem; }
  .toc-sidebar { width: 280px; }
  .chapter-nav { flex-direction: column; gap: 0.75rem; }
  .chapter-nav-link { width: 100%; text-align: center; }
}

@media (min-width: 1200px) {
  .toc-sidebar { width: 340px; }
}

/* --- Print --- */
@media print {
  .progress-bar, .toc-toggle, .toc-sidebar, .toc-overlay, .theme-toggle,
  .chapter-nav, .site-footer, .cta { display: none !important; }
  .content { max-width: 100%; padding: 0; }
  body { font-size: 12pt; background: #fff; color: #000; }
  .chapter-body p { margin-bottom: 0.8rem; }
}
