/* ================================================================
   LUMEN READER — Stylesheet v3 (Bug-Free Version)
   ================================================================ */

:root {
  /* App chrome (terintegrasi tema) */
  --bg: #0a0a0c;
  --bg-elev: #141418;
  --bg-elev-2: #1d1d23;
  --fg: #f5f5f7;
  --fg-dim: #a1a1aa;
  --fg-mute: #6b6b73;
  --accent: #7c9eff;
  --accent-2: #b794ff;
  --accent-glow: rgba(124, 158, 255, 0.45);
  --border: rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.16);
  --glass: rgba(20,20,24,0.55);
  --glass-strong: rgba(18,18,22,0.82);
  --shadow-1: 0 2px 12px rgba(0,0,0,0.25);
  --shadow-2: 0 8px 32px rgba(0,0,0,0.35);
  --shadow-glow: 0 0 24px var(--accent-glow);
  --radius-s: 10px;
  --radius-m: 14px;
  --radius-l: 22px;
  --radius-xl: 30px;
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);

  /* Reader-specific */
  --reader-font: 'Lora', Georgia, serif;
  --reader-size: 18px;
  --reader-lh: 1.7;
  --reader-fg: #e8e6e1;
  --reader-bg: #0a0a0c;
  --reader-bg-2: #0a0a0c;

  /* Transitions */
  --theme-transition: background 0.6s var(--ease-in-out), color 0.6s var(--ease-in-out), border-color 0.6s var(--ease-in-out);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
* { -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: var(--theme-transition);
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
code { font-family: 'JetBrains Mono', monospace; font-size: 0.9em; background: var(--bg-elev); padding: 2px 6px; border-radius: 6px; transition: background 0.4s; }
kbd {
  font-family: 'JetBrains Mono', monospace; font-size: 12px;
  background: var(--bg-elev-2); border: 1px solid var(--border-strong);
  padding: 4px 10px; border-radius: 6px; min-width: 32px; text-align: center;
  box-shadow: 0 2px 0 rgba(0,0,0,0.3);
}

/* ===== Screen Transitions ===== */
.screen {
  position: fixed; inset: 0;
  opacity: 0; pointer-events: none;
  transform: scale(0.98);
  transition: opacity 0.4s var(--ease-out), transform 0.5s var(--ease-spring), visibility 0s linear 0.5s;
  overflow: hidden;
  background: var(--bg);
  visibility: hidden;
}
.screen.active {
  opacity: 1; pointer-events: auto; transform: scale(1);
  visibility: visible;
  transition: opacity 0.4s var(--ease-out), transform 0.5s var(--ease-spring), visibility 0s linear 0s;
}
.screen.slide-from-right { transform: translateX(40px) scale(0.98); }
.screen.slide-from-right.active { transform: translateX(0) scale(1); }
.screen.slide-from-bottom { transform: translateY(40px) scale(0.98); }
.screen.slide-from-bottom.active { transform: translateY(0) scale(1); }

/* ===== Splash ===== */
#splash {
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); position: fixed;
}
.splash-aurora {
  position: absolute; inset: -20%;
  background:
    radial-gradient(circle at 20% 30%, var(--accent-glow), transparent 40%),
    radial-gradient(circle at 80% 20%, var(--accent-glow), transparent 45%),
    radial-gradient(circle at 50% 80%, var(--accent-glow), transparent 50%);
  animation: auroraDrift 18s ease-in-out infinite alternate;
  filter: blur(40px);
  opacity: 0.6;
  pointer-events: none;
  transition: background 0.8s;
}
.splash-particles {
  position: absolute; inset: 0; overflow: hidden; pointer-events: none;
}
.splash-particles::before, .splash-particles::after {
  content: ''; position: absolute; width: 4px; height: 4px;
  background: var(--accent); border-radius: 50%;
  box-shadow:
    100px 200px rgba(255,255,255,0.6), 300px 400px var(--accent-glow),
    500px 100px var(--accent-glow), 700px 350px rgba(255,255,255,0.5),
    200px 600px var(--accent-glow), 800px 500px var(--accent-glow),
    400px 700px rgba(255,255,255,0.4), 900px 200px var(--accent-glow),
    150px 450px rgba(255,255,255,0.5), 600px 650px var(--accent-glow);
  animation: particleFloat 14s linear infinite;
  opacity: 0.6;
}
.splash-particles::after { animation-delay: -7s; animation-duration: 20s; opacity: 0.4; }

.splash-inner { text-align: center; padding: 32px; animation: fadeUp 0.9s var(--ease-out) both; position: relative; z-index: 1; }
.logo-mark { color: var(--accent); margin-bottom: 24px; display: inline-block; animation: float 4s ease-in-out infinite; filter: drop-shadow(0 0 24px var(--accent-glow)); transition: color 0.6s; }

.brand {
  font-family: 'Playfair Display', serif; font-size: 56px; font-weight: 600;
  letter-spacing: -1px; position: relative; display: inline-block;
}
.brand span {
  background: linear-gradient(110deg, var(--fg) 30%, var(--accent) 50%, var(--fg) 70%);
  background-size: 200% 100%;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  animation: shimmer 4s ease-in-out infinite;
}
.brand-sub { color: var(--fg-dim); margin-top: 8px; margin-bottom: 40px; font-size: 15px; }
.splash-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.splash-doc {
  display: inline-block; margin-top: 32px; color: var(--fg-mute);
  font-size: 13px; transition: color 0.25s; background: none; border: none;
  cursor: pointer; padding: 8px 16px; border-radius: 999px;
}
.splash-doc:hover { color: var(--accent); background: var(--bg-elev); }

/* ===== Buttons ===== */
.btn {
  padding: 12px 24px; border-radius: 999px; font-weight: 500; font-size: 15px;
  transition: transform 0.25s var(--ease-spring), background 0.25s, box-shadow 0.25s, color 0.25s;
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
}
.btn:active { transform: scale(0.96); }
.btn.primary { background: var(--fg); color: var(--bg); }
.btn.primary:hover { box-shadow: 0 8px 24px rgba(255,255,255,0.15); }
.btn.ghost { background: transparent; border: 1px solid var(--border-strong); color: var(--fg); }
.btn.ghost:hover { background: var(--bg-elev); }
.btn.small { padding: 8px 16px; font-size: 13px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.25s, transform 0.2s var(--ease-spring);
  position: relative;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-elev); }
.icon-btn:active { transform: scale(0.9); }
.icon-btn img { width: 20px; height: 20px; filter: invert(1); opacity: 0.9; }
.icon-btn.glass {
  background: var(--glass); backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--border);
}
.icon-btn.big { width: 56px; height: 56px; }
.icon-btn.big img { width: 26px; height: 26px; }
.icon-btn.active { background: var(--accent); }
.icon-btn.active img { filter: invert(1) brightness(2); }

.ripple-ring {
  position: absolute; inset: -4px; border-radius: 50%;
  border: 2px solid var(--accent); opacity: 0; pointer-events: none;
}
.autoread-btn.playing .ripple-ring { animation: rippleOut 1.8s var(--ease-out) infinite; }
.autoread-btn.playing { box-shadow: 0 0 24px var(--accent-glow); }

/* UI Lock Floating Button Fixing */
.lock-floating {
  position: fixed;
  bottom: calc(20px + max(70px, env(safe-area-inset-bottom)));
  right: 20px;
  z-index: 40;
  opacity: 0.4;
  transition: opacity 0.3s, transform 0.2s var(--ease-spring), background-color 0.3s;
}
.lock-floating:hover, .lock-floating.locked { opacity: 1; }
.lock-floating.locked { background: var(--accent); }
.lock-floating.locked img { filter: invert(1) brightness(2); }

/* ===== Topbar ===== */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  transition: var(--theme-transition);
  z-index: 5;
  position: relative;
}
.topbar h2 { font-size: 18px; font-weight: 600; flex: 1; text-align: center; }
.topbar .spacer { width: 40px; }

/* ===== Sort Bar ===== */
.sort-bar {
  display: flex; gap: 8px; padding: 12px 20px; overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  scrollbar-width: none;
  transition: var(--theme-transition);
}
.sort-bar::-webkit-scrollbar { display: none; }
.chip {
  padding: 6px 14px; border-radius: 999px; background: var(--bg-elev);
  border: 1px solid var(--border); font-size: 13px; white-space: nowrap;
  transition: all 0.25s var(--ease-spring);
  color: var(--fg);
}
.chip:hover { background: var(--bg-elev-2); }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ===== Library — KOMPAK 3:4 ===== */
.library-grid {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  padding: 18px;
  overflow-y: auto;
  height: calc(100% - 122px);
  align-content: start;
}
.library-card {
  background: var(--bg-elev); border-radius: var(--radius-m);
  padding: 10px 10px 14px; cursor: pointer; border: 1px solid var(--border);
  transition: opacity 0.35s var(--ease-out), transform 0.4s var(--ease-spring), background 0.3s, box-shadow 0.3s, border-color 0.3s;
  display: flex; flex-direction: column;
  position: relative;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
}
.library-card.card-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}
.library-card:hover {
  transform: translateY(-3px);
  background: var(--bg-elev-2);
  box-shadow: var(--shadow-2);
  border-color: var(--border-strong);
}
.library-card .cover {
  aspect-ratio: 3/4;
  border-radius: var(--radius-s);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  margin-bottom: 10px;
  display: flex; align-items: flex-end;
  padding: 10px;
  font-family: 'Playfair Display', serif; font-size: 13px;
  color: rgba(255,255,255,0.95); position: relative; overflow: hidden;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
.library-card .cover::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 55%, rgba(0,0,0,0.55));
  pointer-events: none;
}
.library-card .cover > span {
  position: relative; z-index: 1; flex: 1;
  line-height: 1.2; font-weight: 600;
}
.library-card h3 {
  font-size: 13px; font-weight: 600; margin-bottom: 2px; line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.library-card p {
  font-size: 11px; color: var(--fg-mute);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.library-card .progress {
  height: 3px; background: var(--border); border-radius: 2px;
  margin-top: 8px; overflow: hidden;
}
.library-card .progress > div {
  height: 100%; background: var(--accent); border-radius: 2px;
  transition: width 0.4s var(--ease-out);
}
.library-card .progress-text { font-size: 10px; color: var(--fg-mute); margin-top: 3px; }

.library-card .del-btn {
  position: absolute; top: 16px; right: 16px;
  width: 26px; height: 26px;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.25s, background 0.2s, transform 0.2s var(--ease-spring);
  display: flex; align-items: center; justify-content: center;
  z-index: 3;
}
.library-card:hover .del-btn,
.library-card:focus-within .del-btn { opacity: 1; }
.library-card .del-btn:hover {
  background: rgba(255,80,80,0.75);
  transform: scale(1.1);
}
.library-card .del-btn img { width: 12px; height: 12px; filter: invert(1); opacity: 0.95; }

@media (hover: none) {
  .library-card .del-btn { opacity: 0.85; }
}

.library-card .bookmark-flag {
  position: absolute; top: 10px; left: 18px; width: 14px; height: 20px;
  background: var(--accent); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 75%, 0 100%);
  opacity: 0.95;
  z-index: 2;
}

.empty-state {
  display: none; flex-direction: column; align-items: center; justify-content: center;
  height: calc(100% - 122px); padding: 40px; text-align: center; gap: 16px;
  color: var(--fg-dim);
}
.empty-state.show { display: flex; }
.empty-illustration { color: var(--accent); opacity: 0.7; }

/* ===== Upload ===== */
.upload-area {
  margin: 20px; padding: 40px 20px; border: 2px dashed var(--border-strong);
  border-radius: var(--radius-l); text-align: center; display: flex;
  flex-direction: column; align-items: center; gap: 12px;
  transition: border-color 0.3s, background 0.3s, transform 0.3s var(--ease-spring);
  background: var(--bg-elev);
}
.upload-area.drag {
  border-color: var(--accent); background: var(--accent-glow);
  transform: scale(1.01);
}
.upload-area .upload-icon { color: var(--fg-dim); opacity: 0.8; }
.upload-area .muted { color: var(--fg-mute); }
.upload-area .small { font-size: 12px; }
.upload-log {
  padding: 0 20px 20px; font-family: 'JetBrains Mono', monospace; font-size: 12px;
  color: var(--fg-dim); max-height: 200px; overflow-y: auto;
}
.upload-log .err { color: #ff7a7a; }
.upload-log .ok { color: #7aff9e; }

.storage-meter { width: 80%; max-width: 320px; margin-top: 8px; }
.storage-meter-bar {
  height: 4px; background: var(--border); border-radius: 2px; overflow: hidden;
  position: relative;
}
.storage-meter-bar::after {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: var(--storage-pct, 0%); background: var(--accent);
  transition: width 0.4s var(--ease-out);
}
.storage-meter-bar.warn::after { background: #ffb84a; }
.storage-meter-bar.full::after { background: #ff5e5e; }
.storage-meter small { display: block; margin-top: 4px; color: var(--fg-mute); font-size: 11px; }

/* ===== Guide ===== */
.guide-stage {
  display: grid;
  grid-template-columns: 220px 1fr;
  height: calc(100% - 60px);
  overflow: hidden;
}
.guide-nav {
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 8px;
  background: var(--bg);
}
.guide-nav-item {
  padding: 9px 14px;
  border-radius: var(--radius-s);
  cursor: pointer;
  font-size: 13px;
  color: var(--fg-dim);
  margin-bottom: 2px;
  transition: background 0.2s, color 0.2s;
}
.guide-nav-item:hover { background: var(--bg-elev); color: var(--fg); }
.guide-nav-item.active { background: var(--accent-glow); color: var(--accent); font-weight: 600; }
.guide-content {
  overflow-y: auto;
  padding: 28px 36px 60px;
  max-width: 820px;
}
.guide-content h2 { font-family: 'Playfair Display', serif; font-size: 28px; margin-bottom: 8px; color: var(--fg); }
.guide-content h3 { font-size: 18px; margin: 28px 0 10px; color: var(--accent); }
.guide-content h4 { font-size: 14px; margin: 18px 0 6px; color: var(--fg); text-transform: uppercase; letter-spacing: 0.08em; }
.guide-content p { font-size: 14px; line-height: 1.7; color: var(--fg-dim); margin-bottom: 10px; }
.guide-content ul { margin: 10px 0 14px 20px; color: var(--fg-dim); font-size: 14px; line-height: 1.7; }
.guide-content pre {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-s);
  padding: 14px 16px; overflow-x: auto; font-family: 'JetBrains Mono', monospace;
  font-size: 12px; line-height: 1.6; color: var(--fg); margin: 10px 0 18px;
}
.guide-content code { color: var(--accent); }

@media (max-width: 700px) {
  .guide-stage { grid-template-columns: 1fr; }
  .guide-nav {
    border-right: none; border-bottom: 1px solid var(--border);
    height: auto; max-height: 120px; display: flex; overflow-x: auto; padding: 10px; gap: 6px;
  }
  .guide-nav-item { white-space: nowrap; margin-bottom: 0; flex-shrink: 0; }
  .guide-content { padding: 20px; }
}

/* ===== Reader ===== */
#reader { background: var(--reader-bg); }
/* Saat reader tidak aktif, paksa background transparan agar tidak
   muncul sebagai layer hitam di belakang screen lain di Chrome stable */
#reader:not(.active) { background: transparent !important; }
.reader-bg {
  position: absolute; inset: 0; z-index: 0;
  background: linear-gradient(160deg, var(--reader-bg), var(--reader-bg-2));
  transition: background 1.2s var(--ease-in-out), opacity 1s;
}
/* Pastikan reader-bg dan reader-overlay tidak bocor ke screen lain.
   Pakai opacity+pointer-events (bukan display:none) agar lebih reliable
   di Chrome stable yang kadang terlambat evaluate :not(.active) selector */
#reader:not(.active) .reader-bg,
#reader:not(.active) .reader-overlay {
  opacity: 0 !important;
  pointer-events: none !important;
  transition: none !important;
}
.reader-overlay { position: absolute; inset: 0; z-index: 1; pointer-events: none; transition: background 1s, opacity 1s; }
.reader-top, .reader-bottom {
  position: absolute; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px; padding: 14px 16px;
  transition: opacity 0.5s, transform 0.5s var(--ease-out);
}
.reader-top { top: 0; padding-top: max(14px, env(safe-area-inset-top)); }
.reader-bottom { bottom: 0; padding-bottom: max(14px, env(safe-area-inset-bottom)); }
.reader-top.hidden { opacity: 0; transform: translateY(-20px); pointer-events: none; }
.reader-bottom.hidden { opacity: 0; transform: translateY(20px); pointer-events: none; }

.reader-title { flex: 1; text-align: center; min-width: 0; }
.reader-title span { display: block; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-title small { display: block; font-size: 11px; color: var(--fg-dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.reader-progress { flex: 1; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; margin: 0 8px; position: relative; }
.reader-progress-bar {
  height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2));
  width: 0%; transition: width 0.6s var(--ease-out); position: relative;
  box-shadow: 0 0 8px var(--accent-glow);
}
.reader-stats { font-size: 11px; color: var(--fg-dim); min-width: 32px; text-align: center; }

.reader-stage { position: absolute; inset: 0; z-index: 5; overflow-y: auto; overflow-x: hidden; padding: 90px 24px 110px; scroll-behavior: smooth; }
.reader-content { max-width: 680px; margin: 0 auto; font-family: var(--reader-font); font-size: var(--reader-size); line-height: var(--reader-lh); color: var(--reader-fg); transition: font-size 0.3s, line-height 0.3s; }

/* Blocks Typography & States */
.block { margin-bottom: 1.6em; opacity: 0; transform: translateY(20px); position: relative; }
.block.in { animation: blockIn 0.8s var(--ease-out) forwards; }
.block.fade { animation: fadeOnly 1.2s var(--ease-out) forwards; }
.block.slide-left { animation: slideLeft 0.9s var(--ease-out) forwards; }
.block.slide-right { animation: slideRight 0.9s var(--ease-out) forwards; }
.block.slide-up { animation: slideUp 0.9s var(--ease-out) forwards; }
.block.slide-down { animation: slideDown 0.9s var(--ease-out) forwards; }
.block.zoom { animation: zoomIn 0.9s var(--ease-spring) forwards; }
.block.zoom-out { animation: zoomOut 0.9s var(--ease-out) forwards; }
.block.blur { animation: blurIn 1.2s var(--ease-out) forwards; }
.block.dream { animation: dreamIn 2s var(--ease-in-out) forwards; }
.block.bounce { animation: bounceIn 1s var(--ease-spring) forwards; }
.block.flip-x { animation: flipX 1.1s var(--ease-out) forwards; transform-origin: center; perspective: 800px; }
.block.flip-y { animation: flipY 1.1s var(--ease-out) forwards; transform-origin: center; perspective: 800px; }
.block.unfold { animation: unfold 1.1s var(--ease-out) forwards; transform-origin: top; }
.block.tremor { animation: blockIn 0.8s var(--ease-out) forwards, tremor 0.18s infinite 0.8s; }
.block.neon-pulse { animation: blockIn 0.8s var(--ease-out) forwards, neonPulse 2.4s ease-in-out infinite 0.8s; }
.block.heartbeat { animation: blockIn 0.8s var(--ease-out) forwards, heartbeat 1.4s ease-in-out infinite 0.8s; }
.block.breathe { animation: blockIn 0.8s var(--ease-out) forwards, breathe 4s ease-in-out infinite 0.8s; }

/* Glitch Core Custom Visuals */
.block.glitch { animation: glitchIn 0.6s var(--ease-out) forwards; }
.block.glitch[data-animated="true"]::before,
.block.glitch[data-animated="true"]::after {
  content: attr(data-text); position: absolute; inset: 0; pointer-events: none; opacity: 0;
}
.block.glitch[data-animated="true"]::before { color: rgba(255, 0, 70, 0.55); animation: glitchShift1 0.45s var(--ease-out) forwards; mix-blend-mode: screen; }
.block.glitch[data-animated="true"]::after { color: rgba(0, 200, 255, 0.55); animation: glitchShift2 0.45s var(--ease-out) forwards; mix-blend-mode: screen; }

.block.cinematic { animation: cinematicIn 1.2s var(--ease-out) forwards; }
.block.rain { animation: blockIn 0.6s var(--ease-out) forwards; }
.block.rain .rain-char { display: inline-block; opacity: 0; transform: translateY(-20px); animation: rainDrop 0.8s var(--ease-spring) forwards; }
.block.wave { animation: fadeOnly 0.4s var(--ease-out) forwards; }
.block.wave .wave-char { display: inline-block; opacity: 0; animation: waveIn 0.8s var(--ease-out) forwards; }
.block.shimmer .shimmer-overlay {
  background: linear-gradient(110deg, transparent 30%, var(--accent-glow) 50%, transparent 70%);
  background-size: 200% 100%; background-clip: text; -webkit-background-clip: text; color: transparent; animation: shimmerText 2.5s ease-in-out infinite;
}
.block.typewriter-anim { animation: fadeOnly 0.3s forwards; }
.block.tilt { animation: tiltIn 0.8s var(--ease-spring) forwards; }
.block.skip-anim { opacity: 1 !important; transform: none !important; animation: none !important; }

/* Novel Semantics Styles */
.block.heading-1 { font-size: 2em; font-weight: 600; font-family: 'Playfair Display', serif; text-align: center; margin: 1.5em 0 1em; }
.block.heading-2 { font-size: 1.5em; font-weight: 600; margin: 1.2em 0 0.8em; }
.block.dialogue { font-style: italic; padding-left: 1.5em; border-left: 2px solid currentColor; }
.block.thought { font-style: italic; text-align: center; }
.block.scene-break { text-align: center; margin: 2.5em 0; letter-spacing: 0.5em; }
.block.quote { font-family: 'Playfair Display', serif; font-style: italic; font-size: 1.2em; text-align: center; padding: 1em 0; }
.block.image img { display: block; max-width: 100%; max-height: 60vh; border-radius: var(--radius-m); margin: 0 auto; box-shadow: var(--shadow-2); }
.block.divider { height: 1px; background: currentColor; margin: 2em 0; opacity: 0.15; }
.block.poetry { text-align: center; font-family: 'Fraunces', serif; font-style: italic; line-height: 2; }
.block.letter { font-family: 'Crimson Text', serif; padding: 1.2em 1.5em; border: 1px solid currentColor; border-radius: 8px; }

/* Inline styles */
.inline-emphasis { font-weight: 600; }
.inline-whisper { opacity: 0.5; font-size: 0.9em; letter-spacing: 0.05em; }
.inline-shout { font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; }
.inline-shake { display: inline-block; animation: tremor 0.15s infinite; }
.inline-glow { text-shadow: 0 0 12px currentColor; }
.inline-wave { display: inline-block; animation: inlineWave 2s ease-in-out infinite; }
.inline-flicker { animation: flicker 3s infinite; }
.tw-caret::after { content: '▍'; opacity: 1; animation: blink 1s steps(2) infinite; margin-left: 2px; }

/* ===== Panels (Settings & TOC) ===== */
.settings-panel, .toc-panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50;
  width: min(400px, 92vw); background: var(--glass-strong);
  backdrop-filter: blur(40px) saturate(180%); -webkit-backdrop-filter: blur(40px) saturate(180%);
  border-left: 1px solid var(--border); transform: translateX(110%); transition: transform 0.5s var(--ease-spring);
  display: flex; flex-direction: column;
}
.settings-panel.open { transform: translateX(0); }
.toc-panel { left: 0; right: auto; border-left: none; border-right: 1px solid var(--border); transform: translateX(-110%); }
.toc-panel.open { transform: translateX(0); }

.settings-panel header, .toc-panel header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.settings-panel h3, .toc-panel h3 { font-size: 16px; font-weight: 600; color: var(--fg); }
.settings-body { padding: 16px 20px 32px; overflow-y: auto; display: flex; flex-direction: column; gap: 20px; }
.settings-section { padding-bottom: 18px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 14px; }
.settings-section:last-child { border-bottom: none; }
.settings-section h4 { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.12em; color: var(--fg-mute); margin-bottom: 4px; }

.setting-row { display: flex; flex-direction: column; gap: 6px; }
.setting-row.toggle { flex-direction: row; align-items: center; justify-content: space-between; }
.setting-row label { font-size: 13px; color: var(--fg); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.value-pill { background: var(--bg-elev); padding: 2px 8px; border-radius: 999px; font-size: 11px; font-family: 'JetBrains Mono', monospace; color: var(--fg-dim); border: 1px solid var(--border); }
.setting-row input[type="range"] { width: 100%; accent-color: var(--accent); }
.setting-row select, .setting-row input[type="color"] { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-s); padding: 8px 10px; }
.setting-row input[type="color"] { width: 100%; height: 38px; padding: 4px; cursor: pointer; }

/* Custom Checkbox Toggle Styles */
.setting-row input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; width: 44px; height: 26px;
  background: var(--bg-elev); border-radius: 13px; position: relative; cursor: pointer; transition: background 0.3s; flex-shrink: 0;
}
.setting-row input[type="checkbox"]::before {
  content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; background: #fff; border-radius: 50%; transition: transform 0.3s var(--ease-spring);
}
.setting-row input[type="checkbox"]:checked { background: var(--accent); }
.setting-row input[type="checkbox"]:checked::before { transform: translateX(18px); }

.mini-preview { background: var(--bg-elev); border-radius: var(--radius-s); padding: 12px; font-family: var(--reader-font); font-size: 15px; color: var(--fg-dim); border: 1px solid var(--border); }
.mini-preview.small { font-size: 13px; }

.font-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.font-tile { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-s); padding: 10px; cursor: pointer; transition: all 0.25s var(--ease-spring); text-align: center; }
.font-tile:hover { background: var(--bg-elev-2); transform: translateY(-1px); }
.font-tile.active { border-color: var(--accent); background: var(--accent-glow); }
.font-tile .name { font-size: 11px; color: var(--fg-mute); margin-bottom: 4px; font-family: 'Inter', sans-serif; }
.font-tile .sample { font-size: 18px; color: var(--fg); }

.theme-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { padding: 6px 12px; border-radius: 999px; background: var(--bg-elev); border: 1px solid var(--border); font-size: 12px; color: var(--fg); transition: background 0.25s, transform 0.2s var(--ease-spring); }
.pill.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.accent-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.accent-swatch { aspect-ratio: 1; border-radius: 50%; cursor: pointer; border: 2px solid transparent; transition: transform 0.25s var(--ease-spring); }
.accent-swatch.active { border-color: var(--fg); transform: scale(1.05); }

.custom-theme summary { cursor: pointer; padding: 8px 0; font-size: 13px; color: var(--fg-dim); list-style: none; }
.custom-theme summary::-webkit-details-marker { display: none; }
.custom-theme summary::before { content: '▸ '; transition: transform 0.3s; display: inline-block; }
.custom-theme[open] summary::before { transform: rotate(90deg); }

/* ===== TOC & Overlays ===== */
.toc-list { padding: 8px; overflow-y: auto; }
.toc-item { padding: 9px 14px; border-radius: var(--radius-s); cursor: pointer; transition: background 0.2s; display: flex; align-items: center; justify-content: space-between; margin-bottom: 2px; }
.toc-item:hover { background: var(--bg-elev); }
.toc-item.active { background: var(--accent-glow); color: var(--accent); }

.modal-backdrop, .shortcuts-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,0.6); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity 0.3s, visibility 0.3s;
}
.modal-backdrop.show, .shortcuts-overlay.show { opacity: 1; visibility: visible; pointer-events: auto; }
.modal-card, .shortcuts-card { max-width: 400px; width: 90%; padding: 24px; border-radius: var(--radius-l); animation: zoomIn 0.4s var(--ease-spring); }
.glass-card { background: var(--glass-strong); border: 1px solid var(--border-strong); box-shadow: var(--shadow-2); }
.kbd-grid { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; align-items: center; margin-bottom: 20px; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: max(20px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%) translateY(140%);
  background: var(--glass-strong); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border: 1px solid var(--border);
  padding: 9px 18px; border-radius: 999px; font-size: 13px; z-index: 1000; transition: transform 0.45s var(--ease-spring); box-shadow: var(--shadow-2); color: var(--fg);
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ===== Static Preset Themes ===== */
[data-theme="dark"]      { --reader-bg: #0a0a0c; --reader-bg-2: #14141a; --reader-fg: #e8e6e1; }
[data-theme="light"]     { --reader-bg: #fafaf7; --reader-bg-2: #f0f0eb; --reader-fg: #1a1a1c; }
[data-theme="sepia"]     { --reader-bg: #f4ecd8; --reader-bg-2: #ebe1c8; --reader-fg: #4a3a26; }
[data-theme="midnight"]  { --reader-bg: #050510; --reader-bg-2: #0a0a25; --reader-fg: #c8c8e0; }
[data-theme="forest"]    { --reader-bg: #0d1410; --reader-bg-2: #152018; --reader-fg: #d4e0d2; }
[data-theme="ocean"]     { --reader-bg: #061626; --reader-bg-2: #0a2440; --reader-fg: #d4e4ff; }
[data-theme="rose"]      { --reader-bg: #faf0eb; --reader-bg-2: #f0e0d5; --reader-fg: #2c1a1d; }
[data-theme="neon-noir"] { --reader-bg: #0d0d12; --reader-bg-2: #12121a; --reader-fg: #e0e0ff;
                           --accent: #ff2d78; --accent-2: #00f0ff; --accent-glow: rgba(255,45,120,0.4); }
[data-theme="parchment"] { --reader-bg: #f2e8d5; --reader-bg-2: #e8dbc2; --reader-fg: #3b2f1e; }
[data-theme="lavender"]  { --reader-bg: #f4f0fb; --reader-bg-2: #ebe4f5; --reader-fg: #2d2040; }
[data-theme="amber"]     { --reader-bg: #1a1200; --reader-bg-2: #241a00; --reader-fg: #f5d97a; }
[data-theme="ember"]     { --reader-bg: #120606; --reader-bg-2: #1e0a0a; --reader-fg: #f0c8b0; }

/* ===== KEYFRAMES CORE ANIMATIONS ===== */
@keyframes auroraDrift {
  0% { transform: translateY(0) rotate(0deg) scale(1); }
  100% { transform: translateY(10px) rotate(10deg) scale(1.1); }
}
@keyframes particleFloat {
  0% { transform: translateY(100vh); }
  100% { transform: translateY(-100px); }
}
@keyframes fadeUp {
  0% { opacity: 0; transform: translateY(16px); }
  100% { opacity: 1; transform: translateY(0); }
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
@keyframes ringPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.08); opacity: 0.6; }
}
@keyframes dotPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.4); }
}
@keyframes rippleOut {
  0% { transform: scale(0.9); opacity: 0.8; }
  100% { transform: scale(1.8); opacity: 0; }
}
@keyframes blockIn {
  0% { opacity: 0; transform: translateY(14px); }
  100% { opacity: 1; transform: translateY(0); }
}
@keyframes fadeOnly { 0% { opacity: 0; } 100% { opacity: 1; } }
@keyframes slideLeft { 0% { opacity: 0; transform: translateX(30px); } 100% { opacity: 1; transform: translateX(0); } }
@keyframes slideRight { 0% { opacity: 0; transform: translateX(-30px); } 100% { opacity: 1; transform: translateX(0); } }
@keyframes slideUp { 0% { opacity: 0; transform: translateY(40px); } 100% { opacity: 1; transform: translateY(0); } }
@keyframes slideDown { 0% { opacity: 0; transform: translateY(-40px); } 100% { opacity: 1; transform: translateY(0); } }
@keyframes zoomIn { 0% { opacity: 0; transform: scale(0.93); } 100% { opacity: 1; transform: scale(1); } }
@keyframes zoomOut { 0% { opacity: 0; transform: scale(1.05); } 100% { opacity: 1; transform: scale(1); } }
@keyframes blurIn { 0% { opacity: 0; filter: blur(12px); transform: scale(0.98); } 100% { opacity: 1; filter: blur(0); transform: scale(1); } }
@keyframes dreamIn { 0% { opacity: 0; filter: blur(8px); background: rgba(255,255,255,0.05); } 100% { opacity: 1; filter: blur(0); background: transparent; } }
@keyframes bounceIn { 0% { opacity: 0; transform: scale(0.3); } 50% { transform: scale(1.05); } 70% { transform: scale(0.9); } 100% { opacity: 1; transform: scale(1); } }
@keyframes flipX { 0% { opacity: 0; transform: rotateX(-90deg); } 100% { opacity: 1; transform: rotateX(0deg); } }
@keyframes flipY { 0% { opacity: 0; transform: rotateY(-90deg); } 100% { opacity: 1; transform: rotateY(0deg); } }
@keyframes unfold { 0% { opacity: 0; transform: scaleY(0); } 100% { opacity: 1; transform: scaleY(1); } }
@keyframes tremor { 0%, 100% { transform: translateX(0) translateY(0); } 25% { transform: translateX(-1.5px) translateY(-1px); } 75% { transform: translateX(1.5px) translateY(1px); } }
@keyframes neonPulse { 0%, 100% { filter: drop-shadow(0 0 2px var(--accent)); text-shadow: 0 0 4px var(--accent-glow); } 50% { filter: drop-shadow(0 0 10px var(--accent)); text-shadow: 0 0 14px var(--accent); } }
@keyframes heartbeat { 0%, 100%, 60% { transform: scale(1); } 20% { transform: scale(1.04); } 40% { transform: scale(1.02); } }
@keyframes breathe { 0%, 100% { opacity: 0.8; transform: scale(1); } 50% { opacity: 1; transform: scale(1.015); } }
@keyframes glitchIn { 0% { opacity: 0; transform: skewX(-10deg); } 100% { opacity: 1; transform: skewX(0); } }
@keyframes glitchShift1 { 0%, 100% { transform: translate(0); opacity: 0; } 20% { transform: translate(-2px, 1px); opacity: 0.5; } 60% { transform: translate(1px, -1px); opacity: 0.3; } }
@keyframes glitchShift2 { 0%, 100% { transform: translate(0); opacity: 0; } 30% { transform: translate(2px, -1px); opacity: 0.4; } 70% { transform: translate(-1px, 1px); opacity: 0.5; } }
@keyframes cinematicIn { 0% { opacity: 0; filter: brightness(0.2) contrast(1.4); transform: scale(0.99); } 100% { opacity: 1; filter: brightness(1) contrast(1); transform: scale(1); } }
@keyframes rainDrop { 0% { opacity: 0; transform: translateY(-16px); } 100% { opacity: 1; transform: translateY(0); } }
@keyframes waveIn { 0% { opacity: 0; transform: translateY(8px); } 100% { opacity: 1; transform: translateY(0); } }
@keyframes shimmerText { 0% { background-position: -150%; } 100% { background-position: 150%; } }
@keyframes inlineWave { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes flicker { 0%, 100%, 40%, 80% { opacity: 1; } 42%, 45%, 82% { opacity: 0.3; } }
@keyframes tiltIn { 0% { opacity: 0; transform: rotate(-4deg) translateY(16px); } 100% { opacity: 1; transform: rotate(0deg) translateY(0); } }
@keyframes blink { from, to { opacity: 1; } 50% { opacity: 0; } }

/* ===== ACCESSIBILITY: REDUCE MOTION IMPLEMENTATION ===== */
body.reduce-motion *,
body.reduce-motion *::before,
body.reduce-motion *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}

/* ===== SCROLLBAR UTILITIES ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--fg-mute); }

/* ===== MOBILE RESPONSIVE REFINEMENTS ===== */
@media (max-width: 600px) {
  .brand { font-size: 44px; }
  .reader-stage { padding: 80px 16px 100px; }
  .library-grid { grid-template-columns: repeat(auto-fill, minmax(115px, 1fr)); gap: 12px; padding: 12px; height: calc(100% - 114px); }
  .settings-panel, .toc-panel { width: 100vw; }
}
/* ===== TOC SORT BAR ===== */
.toc-sort-bar {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.toc-sort-bar::-webkit-scrollbar { display: none; }

/* ===== TOC NOVEL GROUPING ===== */
.toc-novel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 6px;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
  margin-top: 4px;
}
.toc-novel-header:first-child { margin-top: 0; }
.toc-novel-header:hover { opacity: 1; }
.toc-novel-header.current {
  opacity: 1;
  cursor: default;
}
.toc-novel-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.toc-novel-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.toc-novel-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toc-novel-header.current .toc-novel-title {
  color: var(--accent);
}
.toc-novel-author {
  font-size: 10px;
  color: var(--fg-mute);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* TOC items from other novels */
.toc-item.other-novel {
  opacity: 0.65;
}
.toc-item.other-novel:hover {
  opacity: 1;
}

/* Adjust toc-panel flex layout so sort bar is sticky */
.toc-panel {
  display: flex;
  flex-direction: column;
}
.toc-list {
  flex: 1;
  overflow-y: auto;
}
