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

:root {
  --bg: #faf9f6;
  --bg-alt: #f0eeeb;
  --text: #2c2c2c;
  --text-muted: #6b6b6b;
  --accent: #8b4513;
  --border: #d4d0c8;
  --sidebar-bg: #f5f3f0;
  --link: #5b3a1a;
  --link-hover: #8b4513;
  --blockquote-bg: #f5f0e8;
  --blockquote-border: #c4a87c;
  --code-bg: #f0eeeb;
  --max-width: 42em;
  --font-body: "Latin Modern Roman", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-heading: "Fira Sans", "DejaVu Sans", "Liberation Sans", sans-serif;
  --font-mono: "Fira Mono", "DejaVu Sans Mono", "Liberation Mono", monospace;
}

/* ── Dark Mode ── */
.theme-toggle-input { display: none; }
html.dark {
  --bg: #1a1a1f;
  --bg-alt: #24242a;
  --text: #d8d4cf;
  --text-muted: #8a8680;
  --accent: #c4956a;
  --border: #3a3a40;
  --sidebar-bg: #202025;
  --link: #c4956a;
  --link-hover: #e0b08a;
  --blockquote-bg: #24221e;
  --blockquote-border: #8a7550;
  --code-bg: #24242a;
}

.theme-toggle-label {
  cursor: pointer;
  font-size: 1.3rem;
  user-select: none;
  line-height: 1;
}
.icon-dark { display: none; }
html.dark .icon-light { display: none; }
html.dark .icon-dark { display: inline; }

/* ── Body ── */
html { font-size: 18px; }
body {
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
  line-height: 1.7;
  min-height: 100vh;
}

/* ── Header ── */
.site-header {
  border-bottom: 1px solid var(--border);
  padding: 0.8rem 1.5rem;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  max-width: 72em;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.site-title {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
.site-title:hover { color: var(--accent); }

/* ── Layout ── */
.layout {
  max-width: 72em;
  margin: 0 auto;
  display: flex;
  gap: 2rem;
  padding: 2rem 1.5rem;
}

/* ── Sidebar ── */
.sidebar {
  width: 16em;
  flex-shrink: 0;
  position: sticky;
  top: 4rem;
  align-self: flex-start;
  max-height: calc(100vh - 5rem);
  overflow-y: auto;
  padding-right: 1rem;
}
.toc-title {
  font-family: var(--font-heading);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 0.8rem;
}
.toc-list {
  list-style: none;
  font-size: 0.85rem;
  line-height: 1.4;
}
.toc-list li { margin-bottom: 0.4rem; }
.toc-list a {
  color: var(--text-muted);
  text-decoration: none;
  display: block;
  padding: 0.15rem 0;
}
.toc-list a:hover { color: var(--accent); }
.toc-list .active a {
  color: var(--accent);
  font-weight: 600;
}

/* ── Main Content ── */
.content {
  flex: 1;
  min-width: 0;
  max-width: var(--max-width);
}

/* ── Typography ── */
h1, h2, h3, h4 {
  font-family: var(--font-heading);
  line-height: 1.3;
  margin-top: 2em;
  margin-bottom: 0.6em;
}
.chapter-title {
  font-size: 2rem;
  margin-top: 0;
  margin-bottom: 1.2em;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.4em;
}
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; font-style: italic; }

p { margin-bottom: 1.2em; }
a { color: var(--link); }
a:hover { color: var(--link-hover); }

em { font-style: italic; }
strong { font-weight: 700; }

/* ── Blockquotes (Reviewer Notes / Alternative Perspectives) ── */
blockquote {
  background: var(--blockquote-bg);
  border-left: 4px solid var(--blockquote-border);
  padding: 1rem 1.2rem;
  margin: 1.5em 0;
  border-radius: 0 4px 4px 0;
  font-size: 0.95rem;
}
blockquote p:last-child { margin-bottom: 0; }

/* ── Tables ── */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5em 0;
  font-size: 0.9rem;
}
th, td {
  border: 1px solid var(--border);
  padding: 0.5em 0.7em;
  text-align: left;
  vertical-align: top;
}
th {
  background: var(--bg-alt);
  font-family: var(--font-heading);
  font-weight: 600;
}

/* ── Footnotes ── */
.footnotes {
  margin-top: 3em;
  padding-top: 1em;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}
.footnote-ref { font-size: 0.75em; vertical-align: super; }

/* ── Code ── */
code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.15em 0.3em;
  border-radius: 3px;
}
pre {
  background: var(--code-bg);
  padding: 1em;
  overflow-x: auto;
  border-radius: 4px;
  margin: 1.5em 0;
}
pre code { background: none; padding: 0; }

/* ── Horizontal Rule ── */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

/* ── Chapter Navigation ── */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 3em;
  padding-top: 1.5em;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
}
.chapter-nav a {
  color: var(--accent);
  text-decoration: none;
  max-width: 45%;
}
.chapter-nav a:hover { text-decoration: underline; }
.nav-next { margin-left: auto; text-align: right; }

/* ── Footer ── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Support Page ── */
.support-page {
  text-align: center;
  max-width: 28em;
  margin: 2em auto;
}
.support-page p { text-align: center; }
.support-page .qr-code {
  display: block;
  width: 160px;
  margin: 1.5em auto;
}
.support-page code {
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

/* ── Responsive ── */
@media (max-width: 52em) {
  html { font-size: 16px; }
  .layout { flex-direction: column; padding: 1rem; }
  .sidebar {
    width: 100%;
    position: static;
    max-height: none;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
  }
  .toc-list { columns: 2; column-gap: 1em; }
  .chapter-title { font-size: 1.6rem; }
}
@media (max-width: 30em) {
  .toc-list { columns: 1; }
}
