/* ============================================
   THE FORGOTTEN CODE — Multi-Page Ebook
   Leanpub-style Premium Design
   ============================================ */

:root {
  --bg: #faf9f6;
  --text: #2d2d2d;
  --text-light: #5a5a5a;
  --text-muted: #8a8a8a;
  --accent: #c9a84c;
  --accent-glow: #e8c84c;
  --accent-deep: #8b6914;
  --purple: #6b4c9a;
  --purple-light: #8b6cba;
  --purple-dark: #4a3370;
  --border: #e0ddd5;
  --surface: #f5f3ee;
  --surface-dark: #eae7df;
  --serif: 'Crimson Pro', 'Georgia', serif;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --max-width: 740px;
  --reading-width: 680px;
  --nav-height: 56px;
}

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

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

body {
  font-family: var(--serif);
  color: var(--text);
  background: var(--bg);
  line-height: 1.8;
  padding-top: var(--nav-height);
}

/* ===========================================
   TOP NAVIGATION BAR
   =========================================== */
.top-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: rgba(250, 249, 246, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
}

.top-nav .nav-brand {
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.top-nav .nav-brand span {
  color: var(--accent-deep);
}

.top-nav .nav-center {
  font-family: var(--sans);
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 40%;
}

.top-nav .nav-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.nav-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.55rem;
  cursor: pointer;
  color: var(--text-light);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.nav-btn:hover {
  background: var(--surface);
  color: var(--purple);
  border-color: var(--purple-light);
}

/* ===========================================
   READING PROGRESS BAR
   =========================================== */
.progress-bar {
  position: fixed;
  top: var(--nav-height);
  left: 0;
  width: 0%;
  height: 2px;
  background: linear-gradient(90deg, var(--purple), var(--accent));
  z-index: 101;
  transition: width 0.08s;
}

/* ===========================================
   SIDEBAR
   =========================================== */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.sidebar-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.sidebar {
  position: fixed;
  top: 0;
  left: -380px;
  width: 360px;
  height: 100vh;
  background: var(--bg);
  box-shadow: 4px 0 30px rgba(0,0,0,0.12);
  z-index: 201;
  transition: left 0.3s ease;
  overflow-y: auto;
  padding: 1.5rem;
}

.sidebar.open {
  left: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--accent);
}

.sidebar-header h2 {
  font-family: var(--sans);
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--accent-deep);
  font-weight: 700;
}

.sidebar .close-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.2rem;
}

.sidebar .part-group {
  margin-bottom: 1.25rem;
}

.sidebar .part-label {
  font-family: var(--sans);
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 0.4rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.sidebar .part-group:first-of-type .part-label {
  border-top: none;
  padding-top: 0;
}

.sidebar a {
  display: block;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--text-light);
  padding: 0.3rem 0 0.3rem 0.75rem;
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: all 0.15s;
  line-height: 1.4;
}

.sidebar a:hover {
  color: var(--purple);
  border-left-color: var(--purple-light);
}

.sidebar a.active {
  color: var(--purple);
  font-weight: 600;
  border-left-color: var(--purple);
  background: rgba(107, 76, 154, 0.05);
}

.sidebar a.chapter-link {
  font-weight: 600;
  color: var(--text);
  font-size: 0.82rem;
  padding: 0.4rem 0 0.4rem 0.75rem;
}

.sidebar a.chapter-link:hover {
  color: var(--purple);
}

.sidebar a.chapter-link.active {
  color: var(--purple);
}

/* ===========================================
   MAIN CONTENT
   =========================================== */
.book-container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
  min-height: calc(100vh - var(--nav-height) - 200px);
}

@media (min-width: 768px) {
  .book-container {
    padding: 3.5rem 2rem 5rem;
  }
}

/* ===========================================
   TYPOGRAPHY
   =========================================== */
p {
  margin-bottom: 1.35rem;
  font-size: 1rem;
  line-height: 1.85;
  max-width: var(--reading-width);
}

strong { font-weight: 600; color: var(--text); }
em { font-style: italic; }

h1, h2, h3, h4, h5, h6 {
  font-family: var(--sans);
  line-height: 1.3;
  color: var(--text);
}

/* Book title (index page) */
h1.book-title {
  font-size: 3.2rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  text-align: center;
  margin-top: 4rem;
  margin-bottom: 0.3rem;
  line-height: 1.1;
}

h1.book-title + .book-subtitle {
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 400;
  font-style: italic;
  color: var(--text-light);
  text-align: center;
  margin-bottom: 0.5rem;
}

.book-author {
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 3rem;
  letter-spacing: 0.03em;
}

/* Part headers */
h1.part-header {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--accent);
  text-align: center;
  margin-top: 3rem;
  margin-bottom: 0.3rem;
}

h1.part-title {
  font-size: 1.5rem;
  font-weight: 300;
  letter-spacing: 0.06em;
  color: var(--text);
  text-align: center;
  margin-bottom: 2rem;
}

/* Chapter headers */
h1.chapter-header {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 0;
  margin-bottom: 1.8rem;
  letter-spacing: -0.01em;
}

h1.section-header {
  font-size: 1.6rem;
  font-weight: 600;
  margin-top: 3rem;
  margin-bottom: 1.5rem;
}

/* Law headers */
h2.law-header {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--purple);
  margin-top: 3.5rem;
  margin-bottom: 1.2rem;
  padding-top: 2rem;
  padding-bottom: 0.5rem;
  border-top: 2px solid var(--purple);
  position: relative;
}

h2.law-header::before {
  content: '';
  position: absolute;
  top: -2px;
  left: 0;
  width: 50px;
  height: 2px;
  background: var(--accent);
}

h2.summary-header {
  font-size: 1.2rem;
  font-weight: 600;
  margin-top: 3rem;
  margin-bottom: 1rem;
}

h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-top: 2.5rem;
  margin-bottom: 0.8rem;
}

h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  letter-spacing: 0.01em;
}

h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

/* ===========================================
   ELEMENTS
   =========================================== */
hr.section-break {
  border: none;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--border), transparent);
  margin: 2.5rem auto;
  max-width: 180px;
}

blockquote {
  border-left: 3px solid var(--accent);
  background: linear-gradient(135deg, #faf8f0, #f6f3e8);
  padding: 1.1rem 1.4rem;
  margin: 1.8rem 0;
  border-radius: 0 8px 8px 0;
  font-style: italic;
  color: var(--text-light);
}

blockquote p {
  margin-bottom: 0;
  font-size: 1.02rem;
  line-height: 1.75;
}

ul, ol {
  margin: 1rem 0 1.5rem 1.5rem;
  max-width: var(--reading-width);
}

li {
  margin-bottom: 0.5rem;
  line-height: 1.7;
  padding-left: 0.2rem;
}

li::marker { color: var(--accent); }

pre {
  background: #2d2d3d;
  color: #e0e0e0;
  padding: 1.3rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 1.5rem 0;
  font-size: 0.82rem;
  line-height: 1.6;
}

code { font-family: var(--mono); }

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

a:hover { color: var(--purple-light); }

/* ===========================================
   CHAPTER NAVIGATION (BOTTOM)
   =========================================== */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 1rem;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 2px solid var(--border);
}

.chapter-nav a {
  display: flex;
  flex-direction: column;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  transition: all 0.2s;
  flex: 1;
  max-width: 48%;
}

.chapter-nav a:hover {
  border-color: var(--purple-light);
  background: rgba(107, 76, 154, 0.03);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(107, 76, 154, 0.08);
}

.chapter-nav a.next {
  text-align: right;
  margin-left: auto;
}

.chapter-nav .nav-label {
  font-family: var(--sans);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  font-weight: 600;
}

.chapter-nav .nav-title {
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--purple);
  line-height: 1.35;
}

/* ===========================================
   FOOTER
   =========================================== */
.site-footer {
  text-align: center;
  padding: 2rem 1.5rem 3rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
  max-width: var(--max-width);
  margin-left: auto;
  margin-right: auto;
}

.site-footer p {
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0 auto 0.3rem;
  text-align: center;
}

.site-footer a {
  color: var(--accent-deep);
  font-weight: 600;
}

/* ===========================================
   INDEX PAGE — TABLE OF CONTENTS
   =========================================== */
.toc-page .toc-part {
  margin-bottom: 2rem;
}

.toc-page .toc-part-label {
  font-family: var(--sans);
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 0.6rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.toc-page .toc-chapter {
  display: block;
  padding: 0.6rem 0;
  border-bottom: 1px solid rgba(0,0,0,0.04);
  text-decoration: none;
  transition: all 0.15s;
}

.toc-page .toc-chapter:hover {
  padding-left: 0.5rem;
}

.toc-page .toc-chapter .toc-ch-title {
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  display: block;
  line-height: 1.4;
}

.toc-page .toc-chapter:hover .toc-ch-title {
  color: var(--purple);
}

.toc-page .toc-chapter .toc-ch-laws {
  font-family: var(--serif);
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
  display: block;
  font-style: italic;
}

/* ===========================================
   COVER SECTION
   =========================================== */
.cover-section {
  text-align: center;
  padding: 4rem 0 3rem;
  border-bottom: 3px solid var(--accent);
  margin-bottom: 3rem;
}

.cover-badge {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent-deep);
  border: 1px solid var(--accent);
  padding: 0.3rem 1rem;
  border-radius: 20px;
  margin-bottom: 2rem;
  font-weight: 600;
}

.cover-epigraph {
  font-family: var(--serif);
  font-size: 1rem;
  font-style: italic;
  color: var(--text-light);
  max-width: 520px;
  margin: 0 auto;
  line-height: 1.7;
}

/* ===========================================
   DARK MODE
   =========================================== */
body.dark {
  --bg: #131320;
  --text: #e0ddd5;
  --text-light: #b0ada5;
  --text-muted: #6a6a6a;
  --border: #2a2a3a;
  --surface: #1a1a2e;
  --surface-dark: #222236;
}

body.dark .top-nav {
  background: rgba(19, 19, 32, 0.92);
  border-bottom-color: #2a2a3a;
}

body.dark .sidebar {
  background: #1a1a2e;
  box-shadow: 4px 0 30px rgba(0,0,0,0.4);
}

body.dark blockquote {
  background: linear-gradient(135deg, #1a1a2e, #222236);
}

body.dark pre { background: #0d0d1a; }

body.dark h2.law-header { border-top-color: #3a3560; }

body.dark .chapter-nav a {
  border-color: #2a2a3a;
}

body.dark .chapter-nav a:hover {
  border-color: var(--purple-light);
  background: rgba(107, 76, 154, 0.08);
}

body.dark .cover-section {
  border-bottom-color: var(--accent-deep);
}

body.dark .nav-btn {
  border-color: #333;
  color: var(--text-light);
}

body.dark .nav-btn:hover {
  background: #222236;
}

/* ===========================================
   PRINT
   =========================================== */
@media print {
  .top-nav, .progress-bar, .sidebar, .sidebar-overlay, .chapter-nav, .site-footer { display: none !important; }
  body { padding-top: 0; font-size: 11pt; }
}

/* ===========================================
   RESPONSIVE
   =========================================== */
@media (max-width: 480px) {
  html { font-size: 16px; }
  h1.book-title { font-size: 2.2rem; }
  h1.chapter-header { font-size: 1.5rem; }
  h2.law-header { font-size: 1.1rem; }
  .sidebar { width: 300px; left: -320px; }
  .chapter-nav { flex-direction: column; }
  .chapter-nav a { max-width: 100%; }
  .top-nav .nav-center { display: none; }
}
