:root {
  --sand: #f6f1e7;
  --paper: #ffffff;
  --ink: #0f172a;
  --muted: #5b6474;
  --accent: #e56a1a;
  --accent-2: #2f5f2e;
  --border: #e3e1da;
  --shadow: 0 16px 60px rgba(15, 23, 42, 0.12);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at 20% 20%, rgba(229, 106, 26, 0.08), transparent 40%),
    radial-gradient(circle at 80% 0%, rgba(47, 95, 46, 0.08), transparent 32%),
    linear-gradient(180deg, #fdfbf7 0%, #f7f2ea 100%);
  color: var(--ink);
  font-family: 'Bahnschrift', 'Trebuchet MS', 'Segoe UI', sans-serif;
  min-height: 100vh;
  padding: 32px clamp(16px, 3vw, 48px) 48px;
}

a {
  color: inherit;
  text-decoration: none;
}

.ambient {
  position: fixed;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.4;
  z-index: 0;
}

.ambient-one {
  width: 360px;
  height: 360px;
  background: rgba(229, 106, 26, 0.14);
  top: -120px;
  left: 20px;
}

.ambient-two {
  width: 420px;
  height: 420px;
  background: rgba(47, 95, 46, 0.18);
  bottom: -160px;
  right: 80px;
}

.hero {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  padding: 28px 32px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.94), rgba(255, 255, 255, 0.8));
  border: 1px solid rgba(227, 225, 218, 0.9);
  border-radius: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 28px;
}

.hero-text h1 {
  margin: 8px 0 4px;
  font-size: clamp(26px, 4vw, 34px);
}

.hero-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.hero-card {
  background: linear-gradient(160deg, rgba(229, 106, 26, 0.1), rgba(47, 95, 46, 0.08));
  border: 1px solid rgba(227, 225, 218, 0.8);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 10px 32px rgba(15, 23, 42, 0.06);
}

.hero-card__title {
  margin: 0 0 12px;
  font-weight: 700;
}

.hero-card ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.6;
}

.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 20px;
  align-self: start;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  max-height: calc(100vh - 80px);
  overflow: auto;
}

.sidebar-backdrop {
  display: none;
}

.filter {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.filter label {
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
}

.filter input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  font-size: 15px;
}

.chapter-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chapter-item {
  width: 100%;
  text-align: left;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  padding: 12px 14px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chapter-item__title {
  font-weight: 700;
  margin-bottom: 4px;
}

.chapter-item__summary {
  color: var(--muted);
  font-size: 14px;
}

.chapter-item:hover {
  transform: translateY(-1px);
  border-color: rgba(229, 106, 26, 0.6);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

.chapter-item.active {
  border-color: var(--accent);
  box-shadow: 0 12px 28px rgba(229, 106, 26, 0.18);
}

.reader {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.chapter-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.chapter-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.media-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  flex-wrap: wrap;
}

#audioPlayer {
  width: 100%;
  max-width: 540px;
}

.markdown {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  line-height: 1.6;
  color: var(--ink);
  min-height: 240px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.markdown h1, .markdown h2, .markdown h3, .markdown h4, .markdown h5, .markdown h6 {
  margin: 12px 0 8px;
}

.markdown p {
  margin: 0 0 12px;
}

.markdown ul {
  padding-left: 18px;
  margin: 0 0 12px;
}

.markdown code {
  background: #f1ece1;
  padding: 2px 6px;
  border-radius: 6px;
}

.pdf-preview {
  margin-top: 18px;
  background: #fff;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 12px;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.hint {
  color: var(--muted);
  font-size: 13px;
}

#pdfPreview {
  width: 100%;
  height: 380px;
  border: none;
  border-radius: 10px;
  background: #fdfbf7;
}

.footer {
  position: relative;
  z-index: 1;
  margin-top: 18px;
  color: var(--muted);
  text-align: center;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

.button.primary {
  background: linear-gradient(135deg, var(--accent), #f08b3f);
  color: #fff;
  border: none;
}

.button.secondary {
  background: #0f172a;
  color: #fff;
  border: none;
}

.button.ghost {
  background: transparent;
}

.sidebar-toggle {
  display: none;
  font-size: 15px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: #0f172a;
  color: #fff;
  font-weight: 700;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
  color: var(--accent-2);
  margin: 0;
}

.note {
  margin: 6px 0 0;
  color: var(--muted);
}

.loading, .error {
  padding: 12px;
  border-radius: 10px;
  background: #fdf2e9;
  color: var(--ink);
  border: 1px solid rgba(229, 106, 26, 0.2);
}

.error {
  background: #fff2f2;
  border-color: #f3b5b5;
}

.empty-state {
  color: var(--muted);
  padding: 10px 6px;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: none;
  }

  .hero {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  body {
    padding: 18px 14px 32px;
  }

  .hero {
    padding: 18px 16px;
  }

  .sidebar-toggle {
    display: inline-flex;
  }

  .chapter-header {
    flex-direction: column;
  }

  .media-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .layout {
    position: static;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    max-height: 100vh;
    width: 280px;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
    z-index: 5;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    z-index: 4;
  }

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

  body.sidebar-open .sidebar-backdrop {
    display: block;
  }

  .sidebar-toggle {
    display: inline-flex;
  }
}
