/* ============================================================
   .reader — Apple-grade Glassmorphism
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,600;0,700;1,400&family=Lora:ital,wght@0,400;0,500;1,400&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --ease-spring:  cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth:  cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out:     cubic-bezier(0, 0, 0.2, 1);
  --dur-fast:   0.2s;
  --dur-med:    0.35s;
  --dur-slow:   0.5s;
  --hdr-h:      64px;
  --r-xl:       24px;
  --r-lg:       18px;
  --r-md:       12px;
  --max-w:      820px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Lora', Georgia, serif;
  min-height: 100vh;
  padding-top: var(--hdr-h);
  transition:
    background var(--dur-slow) var(--ease-smooth),
    color      var(--dur-slow) var(--ease-smooth);
  overflow-x: hidden;
}

/* ── Gradient mesh background ── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -2;
  transition: background var(--dur-slow) var(--ease-smooth);
}

body.light {
  color: #1a1625;
  background: #ede0d4;
}
body.light::before {
  background:
    radial-gradient(ellipse 60% 50% at 20% 10%,  rgba(255,200,170,0.65) 0%, transparent 70%),
    radial-gradient(ellipse 50% 60% at 80% 20%,  rgba(200,170,230,0.4)  0%, transparent 70%),
    radial-gradient(ellipse 70% 50% at 50% 90%,  rgba(255,180,150,0.45) 0%, transparent 70%),
    radial-gradient(ellipse 40% 40% at 90% 70%,  rgba(170,200,255,0.35) 0%, transparent 70%),
    #ede0d4;
}

body.dark {
  color: #f0ece8;
  background: #0b0b0f;
}
body.dark::before {
  background:
    radial-gradient(ellipse 55% 45% at 15% 15%,  rgba(255,65,61,0.18)  0%, transparent 70%),
    radial-gradient(ellipse 45% 55% at 85% 20%,  rgba(120,60,200,0.15) 0%, transparent 70%),
    radial-gradient(ellipse 60% 50% at 50% 85%,  rgba(255,65,61,0.12)  0%, transparent 70%),
    radial-gradient(ellipse 40% 40% at 90% 65%,  rgba(60,80,200,0.10)  0%, transparent 70%),
    #0b0b0f;
}

/* ============================================================
   HEADER
   ============================================================ */
header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--hdr-h);
  z-index: 1000;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 28px;
  transition:
    background     var(--dur-slow) var(--ease-smooth),
    border-color   var(--dur-slow) var(--ease-smooth),
    box-shadow     var(--dur-slow) var(--ease-smooth);
}

body.light header {
  background: rgba(237,224,212,0.72);
  backdrop-filter: blur(32px) saturate(200%);
  -webkit-backdrop-filter: blur(32px) saturate(200%);
  border-bottom: 1px solid rgba(255,255,255,0.65);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.8) inset,
    0 1px 12px rgba(0,0,0,0.06);
}

body.dark header {
  background: rgba(11,11,15,0.72);
  backdrop-filter: blur(32px) saturate(180%);
  -webkit-backdrop-filter: blur(32px) saturate(180%);
  border-bottom: 1px solid rgba(255,255,255,0.07);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.04) inset,
    0 1px 16px rgba(0,0,0,0.45),
    0 0 0 0.5px rgba(255,65,61,0.12);
}

.site-title {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  font-size: 21px;
  letter-spacing: 0.3px;
  cursor: default;
  user-select: none;
  position: relative;
  transition: opacity var(--dur-fast);
}
.site-title::after {
  content: '';
  position: absolute;
  bottom: -2px; left: 0;
  width: 0; height: 1.5px;
  background: currentColor;
  opacity: 0.4;
  transition: width var(--dur-med) var(--ease-spring);
}
.site-title:hover { opacity: 0.75; }
.site-title:hover::after { width: 100%; }

/* ============================================================
   HAMBURGER & MENU
   ============================================================ */
.menu-container {
  position: relative;
  display: flex;
  align-items: center;
}

.hamburger {
  width: 28px;
  height: 28px;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform var(--dur-fast) var(--ease-spring), opacity var(--dur-fast);
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1));
}
.hamburger:hover  { opacity: 0.6; transform: scale(1.08); }
.hamburger:active { transform: scale(0.86); }

/* ── Dropdown scrollable when many chapters ── */
.menu-list {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 250px;
  border-radius: var(--r-lg);
  padding: 6px 0;
  list-style: none;
  overflow-y: auto;
  max-height: calc(100vh - var(--hdr-h) - 20px);
  opacity: 0;
  transform: translateY(-10px) scale(0.95);
  transform-origin: top right;
  pointer-events: none;
  transition:
    opacity   var(--dur-med) var(--ease-smooth),
    transform var(--dur-med) var(--ease-spring);
  z-index: 1001;
}

body.light .menu-list {
  background: rgba(248,240,234,0.88);
  backdrop-filter: blur(40px) saturate(200%);
  -webkit-backdrop-filter: blur(40px) saturate(200%);
  border: 1px solid rgba(255,255,255,0.82);
  box-shadow:
    0 2px 0 rgba(255,255,255,0.9) inset,
    0 20px 60px rgba(0,0,0,0.14),
    0 4px 16px rgba(0,0,0,0.07);
}

body.dark .menu-list {
  background: rgba(24,22,34,0.9);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid rgba(255,255,255,0.09);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.06) inset,
    0 20px 60px rgba(0,0,0,0.6),
    0 4px 16px rgba(0,0,0,0.4),
    0 0 0 0.5px rgba(255,65,61,0.18);
}

.menu-list.show {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* staggered items */
.menu-list li {
  opacity: 0;
  transform: translateX(8px);
  transition:
    opacity   0.22s var(--ease-out),
    transform 0.22s var(--ease-spring),
    background var(--dur-fast);
}
/* All items become visible when menu is shown — stagger capped at 6 for perf */
.menu-list.show li { opacity: 1; transform: none; }
.menu-list.show li:nth-child(1) { transition-delay: 0.04s; }
.menu-list.show li:nth-child(2) { transition-delay: 0.07s; }
.menu-list.show li:nth-child(3) { transition-delay: 0.10s; }
.menu-list.show li:nth-child(4) { transition-delay: 0.13s; }
.menu-list.show li:nth-child(5) { transition-delay: 0.16s; }
.menu-list.show li:nth-child(6) { transition-delay: 0.19s; }

.menu-list li a {
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px;
  font-family: 'Lora', serif;
  font-size: 13.5px;
  transition: background var(--dur-fast), color var(--dur-fast), padding-left var(--dur-fast);
}
.menu-list li a::before {
  content: '§';
  font-size: 10px;
  opacity: 0.35;
  flex-shrink: 0;
  transition: opacity var(--dur-fast), transform var(--dur-fast);
}
.menu-list li a:hover { padding-left: 24px; }
.menu-list li a:hover::before { opacity: 0.7; transform: scale(1.2); }

body.light .menu-list li a { color: #1a1625; }
body.dark  .menu-list li a { color: #f0ece8; }
body.light .menu-list li a:hover { background: rgba(0,0,0,0.055); }
body.dark  .menu-list li a:hover { background: rgba(255,65,61,0.09); color: #FF413D; }

.menu-list li:last-child { padding: 8px 12px; margin-top: 2px; }
body.light .menu-list li:last-child { border-top: 1px solid rgba(0,0,0,0.07); }
body.dark  .menu-list li:last-child { border-top: 1px solid rgba(255,255,255,0.06); }

/* ── Theme button ── */
.theme-button {
  width: 100%;
  padding: 9px 14px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.2px;
  cursor: pointer;
  border: none;
  border-radius: var(--r-md);
  position: relative;
  overflow: hidden;
  transition:
    background var(--dur-fast),
    color      var(--dur-fast),
    transform  var(--dur-fast) var(--ease-spring),
    box-shadow var(--dur-fast);
}
.theme-button::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.12);
  opacity: 0;
  transition: opacity var(--dur-fast);
}
.theme-button:hover::before { opacity: 1; }
.theme-button:hover  { transform: translateY(-1px); }
.theme-button:active { transform: scale(0.96); }

body.light .theme-button {
  background: linear-gradient(135deg, #1a1625 0%, #2e2940 100%);
  color: #f0ece8;
  box-shadow: 0 2px 8px rgba(26,22,37,0.28), 0 1px 0 rgba(255,255,255,0.1) inset;
}
body.dark .theme-button {
  background: linear-gradient(135deg, #FF413D 0%, #ff6b68 100%);
  color: #fff;
  box-shadow: 0 2px 12px rgba(255,65,61,0.4), 0 1px 0 rgba(255,255,255,0.18) inset;
}

/* ============================================================
   BOOK INFO
   ============================================================ */
.book-info {
  display: flex;
  align-items: flex-start;
  padding: 40px 28px 28px;
  gap: 28px;
  max-width: var(--max-w);
  margin: 0 auto;
  animation: fadeUp 0.6s var(--ease-spring) both;
}

.cover {
  width: 128px;
  aspect-ratio: 2/3;
  object-fit: cover;
  border-radius: 12px;
  flex-shrink: 0;
  transition: transform var(--dur-med) var(--ease-spring), box-shadow var(--dur-med);
}
body.light .cover {
  box-shadow: 0 12px 28px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.10);
}
body.dark .cover {
  box-shadow: 0 12px 32px rgba(0,0,0,0.55), 0 2px 8px rgba(0,0,0,0.3);
}
.cover:hover { transform: translateY(-4px) rotate(-1deg) scale(1.02); }
body.light .cover:hover { box-shadow: 0 20px 40px rgba(0,0,0,0.22), 0 4px 12px rgba(0,0,0,0.12); }
body.dark  .cover:hover { box-shadow: 0 20px 48px rgba(0,0,0,0.65), 0 4px 12px rgba(0,0,0,0.4); }

.description { padding-top: 4px; }
.description h2 {
  font-family: 'Playfair Display', serif;
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 12px;
  line-height: 1.3;
}
.description p {
  margin: 6px 0;
  font-size: 13.5px;
  opacity: 0.6;
  font-style: italic;
}

/* ============================================================
   CHAPTERS — glass cards
   ============================================================ */
.chapters-container {
  padding: 0 28px 72px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: var(--max-w);
  margin: 0 auto;
}

.chapter-card {
  border-radius: var(--r-xl);
  padding: 28px 32px;
  position: relative;
  overflow: hidden;
  animation: cardIn 0.6s var(--ease-spring) both;
  transition:
    transform    var(--dur-med) var(--ease-spring),
    box-shadow   var(--dur-med) var(--ease-smooth),
    background   var(--dur-slow) var(--ease-smooth),
    border-color var(--dur-slow) var(--ease-smooth);
}

.chapter-card:nth-child(1) { animation-delay: 0.05s; }
.chapter-card:nth-child(2) { animation-delay: 0.12s; }
.chapter-card:nth-child(3) { animation-delay: 0.19s; }
.chapter-card:nth-child(4) { animation-delay: 0.26s; }
.chapter-card:nth-child(5) { animation-delay: 0.33s; }

/* top-edge highlight */
.chapter-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  pointer-events: none;
}
body.light .chapter-card::before { background: rgba(255,255,255,0.9); }
body.dark  .chapter-card::before { background: rgba(255,255,255,0.08); }

/* inner ring on hover */
.chapter-card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur-med);
}
body.light .chapter-card::after { box-shadow: 0 0 0 1px rgba(255,255,255,0.7) inset; }
body.dark  .chapter-card::after { box-shadow: 0 0 0 1px rgba(255,255,255,0.05) inset; }
.chapter-card:hover::after { opacity: 1; }

/* LIGHT */
body.light .chapter-card {
  background: rgba(255,255,255,0.48);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid rgba(255,255,255,0.72);
  box-shadow:
    0 2px 0 rgba(255,255,255,0.7) inset,
    0 4px 20px rgba(0,0,0,0.06),
    0 1px 4px rgba(0,0,0,0.04);
}
body.light .chapter-card:hover {
  transform: translateY(-4px) scale(1.005);
  box-shadow:
    0 2px 0 rgba(255,255,255,0.8) inset,
    0 16px 48px rgba(0,0,0,0.10),
    0 4px 12px rgba(0,0,0,0.06);
}

/* DARK */
body.dark .chapter-card {
  background: rgba(255,255,255,0.042);
  backdrop-filter: blur(24px) saturate(150%);
  -webkit-backdrop-filter: blur(24px) saturate(150%);
  border: 1px solid rgba(255,255,255,0.07);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.05) inset,
    0 4px 20px rgba(0,0,0,0.3),
    0 1px 4px rgba(0,0,0,0.2);
}
body.dark .chapter-card:hover {
  transform: translateY(-4px) scale(1.005);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.07) inset,
    0 16px 48px rgba(0,0,0,0.5),
    0 4px 12px rgba(0,0,0,0.35),
    0 0 0 1px rgba(255,65,61,0.12);
}

.chapter-title {
  font-family: 'Playfair Display', serif;
  font-weight: 600;
  font-size: 17.5px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  letter-spacing: 0.1px;
  transition: border-color var(--dur-slow);
}
body.light .chapter-title { border-bottom: 1px solid rgba(0,0,0,0.08); }
body.dark  .chapter-title { border-bottom: 1px solid rgba(255,255,255,0.07); }

.chapter-text {
  font-family: 'Lora', Georgia, serif;
  line-height: 1.88;
  font-size: 16px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-weight: 400;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
body { scrollbar-width: thin; }
body.light { scrollbar-color: rgba(26,22,37,0.18) transparent; }
body.dark  { scrollbar-color: rgba(255,65,61,0.25) transparent; }
body::-webkit-scrollbar { width: 7px; }
body::-webkit-scrollbar-track { background: transparent; }
body.light::-webkit-scrollbar-thumb { background: rgba(26,22,37,0.16); border-radius: 6px; }
body.light::-webkit-scrollbar-thumb:hover { background: rgba(26,22,37,0.30); }
body.dark::-webkit-scrollbar-thumb  { background: rgba(255,65,61,0.22); border-radius: 6px; }
body.dark::-webkit-scrollbar-thumb:hover { background: rgba(255,65,61,0.42); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 640px) {
  header { padding: 0 18px; }
  .book-info {
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 28px 18px 20px;
    gap: 18px;
  }
  .cover { width: 150px; }
  .chapters-container { padding: 0 14px 56px; gap: 14px; }
  .chapter-card { padding: 22px 20px; border-radius: 20px; }
  .description h2 { font-size: 22px; }
  .chapter-text { font-size: 15px; }
  .menu-list { width: 220px; }
}

/* ============================================================
   "MORE" BUTTON & EXPANDED CHAPTER PANEL
   ============================================================ */

/* The "More..." button — sits above theme button */
.more-button {
  width: 100%;
  padding: 9px 14px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.2px;
  cursor: pointer;
  border: none;
  border-radius: var(--r-md);
  position: relative;
  overflow: hidden;
  transition:
    background var(--dur-fast),
    color      var(--dur-fast),
    transform  var(--dur-fast) var(--ease-spring),
    box-shadow var(--dur-fast);
  margin-bottom: 6px;
}
.more-button::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.12);
  opacity: 0;
  transition: opacity var(--dur-fast);
}
.more-button:hover::before { opacity: 1; }
.more-button:hover  { transform: translateY(-1px); }
.more-button:active { transform: scale(0.96); }

body.light .more-button {
  background: linear-gradient(135deg, #3b3560 0%, #5a4f82 100%);
  color: #f0ece8;
  box-shadow: 0 2px 8px rgba(58,48,96,0.28), 0 1px 0 rgba(255,255,255,0.1) inset;
}
body.dark .more-button {
  background: linear-gradient(135deg, #cc3330 0%, #ff413d 100%);
  color: #fff;
  box-shadow: 0 2px 12px rgba(200,50,46,0.35), 0 1px 0 rgba(255,255,255,0.15) inset;
}

/* The expanded floating panel */
.more-panel {
  position: fixed;
  z-index: 2000;
  border-radius: var(--r-lg);
  padding: 16px 18px;
  display: none;
  opacity: 0;
  transform: scale(0.96) translateY(-6px);
  transform-origin: top right;
  pointer-events: none;
  transition:
    opacity   var(--dur-med) var(--ease-smooth),
    transform var(--dur-med) var(--ease-spring);
  max-height: 80vh;
  overflow-y: auto;
  min-width: 220px;
}

.more-panel.show {
  display: flex;
  flex-direction: row;
  gap: 0;
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

body.light .more-panel {
  background: rgba(248,240,234,0.96);
  backdrop-filter: blur(40px) saturate(200%);
  -webkit-backdrop-filter: blur(40px) saturate(200%);
  border: 1px solid rgba(255,255,255,0.82);
  box-shadow:
    0 2px 0 rgba(255,255,255,0.9) inset,
    0 20px 60px rgba(0,0,0,0.18),
    0 4px 16px rgba(0,0,0,0.09);
}
body.dark .more-panel {
  background: rgba(24,22,34,0.96);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid rgba(255,255,255,0.09);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.06) inset,
    0 20px 60px rgba(0,0,0,0.7),
    0 4px 16px rgba(0,0,0,0.5),
    0 0 0 0.5px rgba(255,65,61,0.2);
}

/* Each column */
.more-panel-col {
  display: flex;
  flex-direction: column;
  min-width: 190px;
}
.more-panel-col + .more-panel-col {
  border-left: 1px solid rgba(0,0,0,0.07);
  padding-left: 10px;
  margin-left: 10px;
}
body.dark .more-panel-col + .more-panel-col {
  border-left-color: rgba(255,255,255,0.07);
}

/* Links inside panel */
.more-panel a {
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  font-family: 'Lora', serif;
  font-size: 13px;
  transition: background var(--dur-fast), color var(--dur-fast), padding-left var(--dur-fast);
  white-space: nowrap;
}
.more-panel a::before {
  content: '§';
  font-size: 9px;
  opacity: 0.35;
  flex-shrink: 0;
  transition: opacity var(--dur-fast), transform var(--dur-fast);
}
.more-panel a:hover { padding-left: 16px; }
.more-panel a:hover::before { opacity: 0.7; transform: scale(1.2); }

body.light .more-panel a { color: #1a1625; }
body.dark  .more-panel a { color: #f0ece8; }
body.light .more-panel a:hover { background: rgba(0,0,0,0.055); }
body.dark  .more-panel a:hover { background: rgba(255,65,61,0.09); color: #FF413D; }

/* Scrollbar inside more-panel */
.more-panel { scrollbar-width: thin; }
body.light .more-panel { scrollbar-color: rgba(26,22,37,0.18) transparent; }
body.dark  .more-panel { scrollbar-color: rgba(255,65,61,0.25) transparent; }

/* Menu list scrollbar */
.menu-list { scrollbar-width: thin; }
body.light .menu-list { scrollbar-color: rgba(26,22,37,0.18) transparent; }
body.dark  .menu-list { scrollbar-color: rgba(255,65,61,0.25) transparent; }
