:root {
  --bg: #f6f1e8;
  --paper: #fffaf1;
  --ink: #1d1814;
  --muted: #73685d;
  --line: #ddd1c0;
  --accent: #bd2e26;
  --accent-2: #116a7a;
  --shadow: 0 24px 70px rgba(45, 31, 20, 0.14);
  --serif: Georgia, "Times New Roman", serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  --bg: #141211;
  --paper: #201d1a;
  --ink: #f4eadc;
  --muted: #b9ab9b;
  --line: #3a332e;
  --accent: #f05a4c;
  --accent-2: #6dc5d1;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(189, 46, 38, 0.1), transparent 34rem),
    linear-gradient(135deg, rgba(17, 106, 122, 0.08), transparent 32rem),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(18rem, 23rem) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 1.5rem;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(18px);
}

.brand {
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--line);
}

.eyebrow,
.chapter-meta span,
.search-box span {
  margin: 0 0 0.4rem;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2rem, 7vw, 3rem);
  line-height: 0.95;
}

.subtitle {
  margin: 0.75rem 0 0;
  color: var(--muted);
}

.search-box {
  display: grid;
  gap: 0.45rem;
  margin: 1rem 0;
}

.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  padding: 0.8rem 0.85rem;
  background: var(--bg);
  color: var(--ink);
}

.search-results {
  display: grid;
  gap: 0.45rem;
  margin-bottom: 1rem;
}

.search-hit {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  padding: 0.75rem;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.search-hit strong {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--accent-2);
}

.search-hit span {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.35;
}

.chapter-list ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
}

.chapter-link {
  width: 100%;
  display: grid;
  grid-template-columns: 2.4rem minmax(0, 1fr);
  gap: 0.75rem;
  align-items: center;
  border: 0;
  border-radius: 0.45rem;
  padding: 0.65rem 0.55rem;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.chapter-link:hover,
.chapter-link.active {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.chapter-link b {
  display: grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent);
  font-size: 0.78rem;
}

.chapter-link span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: center;
  padding: 1rem clamp(1rem, 4vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(18px);
}

.chapter-meta {
  min-width: 0;
}

.chapter-meta span,
.chapter-meta strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-meta strong {
  font-family: var(--serif);
  font-size: 1.1rem;
}

.icon-button,
.theme-button,
.reader-nav button {
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 2px 0 color-mix(in srgb, var(--line) 50%, transparent);
}

.icon-button {
  display: none;
  width: 2.65rem;
  height: 2.65rem;
  padding: 0.7rem;
}

.icon-button span {
  display: block;
  height: 2px;
  margin: 0.22rem 0;
  background: var(--ink);
}

.theme-button {
  min-width: 4.5rem;
  justify-self: end;
  height: 2.65rem;
  padding: 0 0.85rem;
}

.progress-track {
  position: sticky;
  top: 4.75rem;
  z-index: 9;
  height: 4px;
  background: color-mix(in srgb, var(--line) 70%, transparent);
}

.progress-bar {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.12s linear;
}

.chapter-content {
  width: min(100% - 2rem, 48rem);
  margin: 0 auto;
  padding: clamp(2rem, 7vw, 5rem) 0;
  outline: 0;
}

.chapter-content h1 {
  margin-bottom: 1.5rem;
  font-size: clamp(2.05rem, 6vw, 3.65rem);
  line-height: 1;
  overflow-wrap: anywhere;
}

.chapter-content .book-title {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 1.2rem;
}

.chapter-content p,
.chapter-content li,
.chapter-content blockquote {
  font-family: var(--serif);
  font-size: clamp(1.12rem, 2vw, 1.28rem);
  line-height: 1.78;
}

.chapter-content p {
  margin: 0 0 1.25rem;
}

.chapter-content blockquote {
  margin: 2rem 0;
  padding: 0.25rem 0 0.25rem 1.25rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.chapter-content hr {
  width: 6rem;
  margin: 3rem auto;
  border: 0;
  border-top: 1px solid var(--line);
}

.reader-nav {
  width: min(100% - 2rem, 48rem);
  margin: 0 auto 4rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.reader-nav button {
  min-height: 2.8rem;
  padding: 0 1rem;
}

.reader-nav button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

body.sidebar-open {
  overflow: hidden;
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(88vw, 23rem);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .icon-button {
    display: block;
  }

  .topbar {
    gap: 0.65rem;
  }

  .theme-button {
    min-width: 3.9rem;
  }

  .progress-track {
    top: 4.7rem;
  }
}
