@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,600;1,300;1,400&family=Crimson+Pro:ital,wght@0,300;0,400;0,600;1,300;1,400&family=EB+Garamond:ital,wght@0,400;0,500;1,400&family=Libre+Baskerville:ital,wght@0,400;0,700;1,400&family=Source+Sans+3:ital,wght@0,300;0,400;0,600;1,300;1,400&family=Lato:ital,wght@0,300;0,400;0,700;1,300;1,400&display=swap');

/* ───────── THEME VARIABLES ───────── */
:root {
  --font-size-base: 17px;
  --font-body: 'Crimson Pro', Georgia, serif;

  /* light themes */
  --bg-paper:   #f5f0e8;
  --bg-sepia:   #e8dcc8;
  --bg-warm:    #fdf6ec;
  --bg-cool:    #eef0f4;

  /* dark themes */
  --bg-inkwell: #1a1c22;
  --bg-slate:   #1e2535;
  --bg-storm:   #1c2030;
  --bg-charcoal:#212121;

  /* active theme (defaults to paper light) */
  --bg:         var(--bg-paper);
  --surface:    rgba(0,0,0,0.04);
  --surface2:   rgba(0,0,0,0.07);
  --border:     rgba(0,0,0,0.10);
  --text:       #2c2416;
  --text-muted: #7a6a52;
  --accent:     #8b5e3c;
  --accent2:    #c49a6c;
  --link:       #6b4226;
  --link-hover: #c49a6c;
  --shadow:     rgba(0,0,0,0.12);

  --radius: 6px;
  --radius-lg: 12px;
  --transition: 0.25s ease;
}

/* ── dark mode base ── */
[data-theme="dark"] {
  --bg:         var(--bg-inkwell);
  --surface:    rgba(255,255,255,0.05);
  --surface2:   rgba(255,255,255,0.09);
  --border:     rgba(255,255,255,0.10);
  --text:       #d8cfc4;
  --text-muted: #7a8090;
  --accent:     #7a9bb5;
  --accent2:    #4e7a9b;
  --link:       #9bbdd4;
  --link-hover: #cde3f0;
  --shadow:     rgba(0,0,0,0.4);
}

/* ── light palette overrides ── */
[data-theme="light"][data-palette="sepia"] { --bg: var(--bg-sepia); }
[data-theme="light"][data-palette="warm"]  { --bg: var(--bg-warm);  }
[data-theme="light"][data-palette="cool"]  { --bg: var(--bg-cool); --text: #1e2535; --text-muted: #556070; --accent: #4e7a9b; --link: #3a6285; --link-hover: #1e4a6e; }

/* ── dark palette overrides ── */
[data-theme="dark"][data-palette="slate"]    { --bg: var(--bg-slate); }
[data-theme="dark"][data-palette="storm"]    { --bg: var(--bg-storm); }
[data-theme="dark"][data-palette="charcoal"] { --bg: var(--bg-charcoal); }

/* ── font family overrides ── */
[data-font="serif-cormorant"] { --font-body: 'Cormorant Garamond', Georgia, serif; }
[data-font="serif-garamond"]  { --font-body: 'EB Garamond', Georgia, serif; }
[data-font="serif-baskerville"]{ --font-body: 'Libre Baskerville', Georgia, serif; }
[data-font="sans-source"]     { --font-body: 'Source Sans 3', sans-serif; }
[data-font="sans-lato"]       { --font-body: 'Lato', sans-serif; }

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

html {
  font-size: var(--font-size-base);
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.75;
  transition: background-color var(--transition), color var(--transition);
  min-height: 100vh;
  overflow-x: hidden;
}

a {
  color: var(--link);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover { color: var(--link-hover); }

/* ───────── LAYOUT ───────── */
.site-container {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 2.5rem;
}

.page-content {
  padding: 3rem 0 6rem;
}

/* ───────── HEADER / NAV ───────── */
.site-header {
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--border);
  background-color: var(--bg);
  z-index: 100;
  transition: background-color var(--transition), border-color var(--transition);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.site-name {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--text);
  white-space: nowrap;
}

.site-name a { color: inherit; }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--link-hover); }
.breadcrumb .sep { opacity: 0.5; }

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* icon buttons */
.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.icon-btn:hover {
  background: var(--surface2);
  color: var(--text);
}
.icon-btn.active {
  background: var(--surface2);
  border-color: var(--accent);
  color: var(--accent);
}

/* ───────── SETTINGS PANEL ───────── */
.settings-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 199;
}
.settings-backdrop.open { display: block; }

.settings-panel {
  position: fixed;
  top: 60px;
  right: 1rem;
  width: 300px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px var(--shadow);
  z-index: 200;
  padding: 1.25rem;
  display: none;
  flex-direction: column;
  gap: 1.25rem;
  transition: background-color var(--transition);
}
.settings-panel.open { display: flex; }

.settings-section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
  font-family: 'Source Sans 3', sans-serif;
  font-weight: 600;
}

/* font size slider */
.font-size-control {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.font-size-control span {
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 28px;
  text-align: center;
  font-family: 'Source Sans 3', sans-serif;
}
input[type="range"] {
  -webkit-appearance: none;
  flex: 1;
  height: 3px;
  background: var(--surface2);
  border-radius: 99px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

/* font picker */
.font-options {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.font-option {
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-muted);
  border: 1px solid transparent;
  transition: all var(--transition);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.font-option:hover { background: var(--surface); color: var(--text); }
.font-option.active {
  background: var(--surface2);
  border-color: var(--accent);
  color: var(--text);
}
.font-option .preview {
  font-size: 1rem;
  opacity: 0.6;
}

/* palette swatches */
.palette-grid {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
  position: relative;
}
.swatch:hover { transform: scale(1.15); }
.swatch.active { border-color: var(--accent); }
.swatch[title]:hover::after {
  content: attr(title);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  font-size: 0.65rem;
  white-space: nowrap;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'Source Sans 3', sans-serif;
  pointer-events: none;
}

/* theme toggle row */
.theme-toggle-row {
  display: flex;
  gap: 0.5rem;
}
.theme-btn {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  font-family: 'Source Sans 3', sans-serif;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}
.theme-btn:hover { background: var(--surface); color: var(--text); }
.theme-btn.active {
  background: var(--surface2);
  border-color: var(--accent);
  color: var(--text);
}

/* ───────── HOME — BOOK GRID ───────── */
.page-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 300;
  letter-spacing: -0.01em;
  margin-bottom: 0.4rem;
  line-height: 1.15;
}
.page-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 3rem;
  font-family: 'Source Sans 3', sans-serif;
  font-weight: 300;
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.5rem;
}

.book-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  cursor: pointer;
  display: block;
  color: inherit;
}
.book-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px var(--shadow);
  border-color: var(--accent2);
  color: inherit;
}

.book-cover {
  aspect-ratio: 2/3;
  background: var(--surface2);
  display: flex;
  align-items: flex-end;
  padding: 1rem;
  position: relative;
  overflow: hidden;
}

.book-cover-gradient {
  position: absolute;
  inset: 0;
  opacity: 0.6;
}

.book-cover-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.25;
  position: relative;
  z-index: 1;
  color: #fff;
  text-shadow: -1px -1px 0 #333, 1px -1px 0 #333, -1px 1px 0 #333, 1px 1px 0 #333, 0 3px 8px rgba(0,0,0,0.5);
}

/* ───────── TOC PAGE ───────── */
.toc-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.toc-book-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 300;
  margin-bottom: 0.3rem;
  line-height: 1.2;
}
.toc-description {
  color: var(--text-muted);
  font-size: 0.9rem;
  max-width: 560px;
  line-height: 1.6;
  font-family: 'Source Sans 3', sans-serif;
}

.toc-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.toc-item a {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius);
  color: var(--text);
  border: 1px solid transparent;
  transition: all 0.15s;
}
.toc-item a:hover {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.toc-num {
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 2.5rem;
  font-family: 'Source Sans 3', sans-serif;
  font-weight: 300;
}
.toc-title {
  flex: 1;
  font-size: 1rem;
}
.toc-arrow {
  color: var(--text-muted);
  font-size: 0.8rem;
  transition: transform 0.15s;
}
.toc-item a:hover .toc-arrow {
  transform: translateX(3px);
  color: var(--accent);
}
.toc-section-heading {
  margin-top: 2.5rem;
}
.toc-list li:last-child {
    margin-bottom: 2rem;
}

/* ───────── CHAPTER PAGE ───────── */
.chapter-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}
.chapter-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 300;
  line-height: 1.2;
}

.chapter-body {
  max-width: 680px;
}
.chapter-body p {
  margin-bottom: 1.4em;
  font-size: 1rem;
  line-height: 1.85;
}
.chapter-body p:first-child::first-letter {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 3.2em;
  font-weight: 600;
  float: left;
  line-height: 0.8;
  margin: 0.08em 0.1em 0 0;
  color: var(--accent);
}

/* chapter nav */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  gap: 1rem;
}
.chapter-nav-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.85rem;
  transition: all var(--transition);
  text-decoration: none;
}
.chapter-nav-btn:hover {
  background: var(--surface);
  color: var(--text);
  border-color: var(--accent2);
}
.chapter-nav-btn.disabled {
  opacity: 0.3;
  pointer-events: none;
}
.chapter-nav-center {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: 'Source Sans 3', sans-serif;
}

/* ───────── SCROLLBAR ───────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ───────── RESPONSIVE ───────── */
@media (max-width: 600px) {
  .settings-panel { width: calc(100vw - 2rem); right: 1rem; }
  .books-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; }
  .header-inner { flex-wrap: wrap; }
  .site-container {
      padding: 0 2.0rem;
      }
}