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

:root {
  --bg: #0e0e0c;
  --surface: #161613;
  --card: #1c1c18;
  --border: rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.18);
  --text: #f0ede4;
  --muted: #8a8880;
  --accent: #c9a84c;
  --accent-dim: rgba(201,168,76,0.12);
  --reader-bg: #111110;
  --serif: 'Playfair Display', Georgia, serif;
  --sans: 'DM Sans', system-ui, sans-serif;
}

html { background: var(--bg); color: var(--text); font-family: var(--sans); scroll-behavior: smooth; }
body { min-height: 100vh; }
#app-root { min-height: 100vh; }


/* ── NAV (home) ── */
nav {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 3rem; height: 64px;
  background: rgba(14,14,12,0.88); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.nav-logo {
  font-family: var(--serif); font-size: 1.5rem;
  letter-spacing: -0.01em; color: var(--text);
}
.nav-logo span { color: var(--accent); }
.nav-count { font-size: 0.8rem; color: var(--muted); }

.nav-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 40px; padding: 8px 16px; width: 280px;
  transition: border-color 0.2s;
}
.nav-search:focus-within { border-color: var(--border-hover); }
.nav-search input {
  background: none; border: none; outline: none;
  color: var(--text); font-family: var(--sans); font-size: 0.875rem; width: 100%;
}
.nav-search input::placeholder { color: var(--muted); }
.search-icon { color: var(--muted); font-size: 14px; flex-shrink: 0; }
.nav-actions { display: flex; gap: 12px; align-items: center; min-width: 90px; justify-content: flex-end; }


/* ── BOOK PAGE NAV ── */
.book-nav {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 3rem; height: 64px;
  background: rgba(14,14,12,0.92); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.back-btn {
  display: flex; align-items: center; gap: 6px;
  background: none; border: 1px solid var(--border);
  color: var(--muted); font-family: var(--sans); font-size: 0.8125rem;
  padding: 7px 14px; border-radius: 40px; cursor: pointer;
  transition: all 0.15s;
}
.back-btn:hover { border-color: var(--border-hover); color: var(--text); }


/* ── HERO ── */
.hero {
  padding: 5rem 3rem 3.5rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-end; justify-content: space-between; gap: 2rem;
}
.hero-headline {
  font-family: var(--serif); font-size: clamp(2.5rem, 5vw, 4rem);
  line-height: 1.1; font-weight: 400;
}
.hero-headline em { color: var(--accent); font-style: italic; }
.hero-sub { margin-top: 1rem; color: var(--muted); font-size: 1rem; line-height: 1.6; max-width: 36ch; }
.hero-stats { display: flex; gap: 2.5rem; flex-shrink: 0; }
.stat-num { font-family: var(--serif); font-size: 2rem; font-weight: 600; color: var(--accent); }
.stat-label { font-size: 0.75rem; color: var(--muted); margin-top: 2px; letter-spacing: 0.08em; text-transform: uppercase; }


/* ── FILTER TABS ── */
.filter-bar {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 1.5rem 3rem;
  overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid var(--border);
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-tab {
  flex-shrink: 0; padding: 6px 18px;
  border-radius: 40px; border: 1px solid var(--border);
  background: none; cursor: pointer; color: var(--muted);
  font-family: var(--sans); font-size: 0.8125rem; font-weight: 400;
  transition: all 0.15s; white-space: nowrap;
}
.filter-tab.active, .filter-tab:hover {
  background: var(--accent-dim); border-color: var(--accent); color: var(--accent);
}


/* ── LIBRARY GRID ── */
.library { padding: 3rem; }
.section { margin-bottom: 3.5rem; }
.section-header {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem; border-bottom: 1px solid var(--border);
}
.section-title { font-family: var(--serif); font-size: 1.375rem; font-weight: 400; }
.section-count { font-size: 0.8125rem; color: var(--muted); }

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


/* ── PDF CARD ── */
.pdf-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden; cursor: pointer;
  transition: border-color 0.2s, transform 0.2s;
  display: flex; flex-direction: column;
}
.pdf-card:hover { border-color: var(--border-hover); transform: translateY(-3px); }
.pdf-thumb {
  height: 160px; position: relative;
  display: flex; align-items: center; justify-content: center;
  font-size: 3rem; flex-shrink: 0; overflow: hidden;
}
.thumb-bg {
  position: absolute; inset: 0; opacity: 0.9;
}
.thumb-icon {
  position: relative; z-index: 1;
  font-size: 2.8rem;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.5));
}
.pdf-body { padding: 1rem; flex: 1; display: flex; flex-direction: column; }
.pdf-title { font-size: 0.9375rem; font-weight: 500; line-height: 1.4; margin-bottom: 0.4rem; }
.pdf-meta { font-size: 0.75rem; color: var(--muted); line-height: 1.5; flex: 1; }
.pdf-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; border-top: 1px solid var(--border);
}
.pdf-pages { font-size: 0.7rem; color: var(--muted); letter-spacing: 0.04em; }
.pdf-tag {
  font-size: 0.6875rem; padding: 2px 8px; border-radius: 20px;
  background: var(--accent-dim); color: var(--accent); border: 1px solid rgba(201,168,76,0.2);
}


/* ── BOOK HERO ── */
.book-hero {
  position: relative; overflow: hidden;
  padding: 5rem 3rem 4rem;
  border-bottom: 1px solid var(--border);
  min-height: 400px;
  display: flex; align-items: center;
}
.book-hero-bg-pattern {
  position: absolute; inset: 0;
  background-image:
    radial-gradient(circle at 80% 20%, rgba(255,255,255,0.04) 0%, transparent 50%),
    radial-gradient(circle at 20% 80%, rgba(0,0,0,0.3) 0%, transparent 50%);
  pointer-events: none;
}
.book-hero::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(to right, rgba(14,14,12,0) 0%, rgba(14,14,12,0.15) 100%);
  pointer-events: none;
}
.book-hero-content {
  position: relative; z-index: 2;
  display: flex; align-items: flex-start; gap: 3rem;
  max-width: 900px; width: 100%;
  animation: fadeUp 0.5s ease both;
}
@keyframes fadeUp { from { opacity:0; transform:translateY(20px); } to { opacity:1; transform:translateY(0); } }

.book-emoji-large {
  font-size: 5rem; flex-shrink: 0;
  filter: drop-shadow(0 4px 20px rgba(0,0,0,0.5));
  margin-top: 0.25rem;
}
.book-hero-text { flex: 1; }
.book-category-badge {
  display: inline-block;
  font-size: 0.6875rem; letter-spacing: 0.12em; text-transform: uppercase;
  padding: 4px 12px; border-radius: 20px;
  background: rgba(255,255,255,0.12); color: rgba(255,255,255,0.7);
  margin-bottom: 1rem;
}
.book-hero-title {
  font-family: var(--serif); font-size: clamp(1.8rem, 3.5vw, 3rem);
  font-weight: 600; line-height: 1.15; color: #fff;
  margin-bottom: 0.5rem;
  text-shadow: 0 2px 12px rgba(0,0,0,0.4);
}
.book-hero-author {
  font-size: 0.9375rem; color: rgba(255,255,255,0.6);
  margin-bottom: 1.25rem;
}
.book-hero-desc {
  font-size: 0.9375rem; line-height: 1.7;
  color: rgba(255,255,255,0.8);
  max-width: 52ch; margin-bottom: 1.5rem;
}
.book-tags { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.25rem; }
.book-tag {
  font-size: 0.75rem; padding: 4px 12px; border-radius: 20px;
  background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.7);
  border: 1px solid rgba(255,255,255,0.15);
}
.book-meta-row { display: flex; gap: 0.75rem; }
.book-meta-pill {
  font-size: 0.75rem; color: rgba(255,255,255,0.5);
  padding: 3px 10px; border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.12);
}


/* ── READER SECTION (book page) ── */
.reader-section {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.reader-section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 2rem; background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap; gap: 0.5rem;
}
.reader-section-title {
  font-family: var(--serif); font-size: 1rem; font-weight: 400; color: var(--muted);
}
.reader-controls-top {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
}

/* immersive reader frame */
.immersive-reader {
  display: flex; height: 75vh; min-height: 500px;
  overflow: hidden;
}
.immersive-reader:fullscreen,
.immersive-reader:-webkit-full-screen {
  height: 100vh;
  border-radius: 0;
}

.reader-sidebar-book {
  width: 160px; background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto; padding: 1rem 0.75rem;
  flex-shrink: 0;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.reader-main-book {
  flex: 1; overflow-y: auto; overflow-x: auto;
  background: var(--reader-bg);
  display: flex; flex-direction: column; align-items: center;
  padding: 2rem;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
  position: relative;
}


/* ── RELATED SECTION ── */
.related-section {
  padding: 3rem;
  border-top: 1px solid var(--border);
}


/* ── SHARED READER ELEMENTS ── */
.sidebar-label {
  font-size: 0.6875rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 0.75rem; padding: 0 4px;
}
.thumb-item {
  margin-bottom: 10px; cursor: pointer; border-radius: 6px; overflow: hidden;
  border: 1px solid var(--border); transition: border-color 0.15s;
  background: var(--card);
}
.thumb-item:hover, .thumb-item.active { border-color: var(--accent); }
.thumb-preview {
  width: 100%; height: 80px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; color: var(--muted);
  background: var(--card);
}
.thumb-num { font-size: 0.6875rem; color: var(--muted); text-align: center; padding: 4px; }

.reader-canvas-wrap {
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  border-radius: 4px; overflow: hidden;
  flex-shrink: 0;
}
#pdf-canvas { display: block; }

.reader-loading {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  background: var(--reader-bg); z-index: 5;
}
.loader-ring {
  width: 36px; height: 36px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.reader-loading p { font-size: 0.875rem; color: var(--muted); }

.reader-statusbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 1.25rem; background: var(--surface);
  border-top: 1px solid var(--border); flex-shrink: 0;
}
.status-left { font-size: 0.75rem; color: var(--muted); }
.progress-track {
  flex: 1; height: 2px; background: var(--border);
  margin: 0 1rem; border-radius: 2px; overflow: hidden;
}
.progress-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.2s; }
.status-right { font-size: 0.75rem; color: var(--muted); }


/* ── TOOLBAR BUTTONS ── */
.toolbar-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.tb-btn {
  background: none; border: 1px solid transparent; color: var(--muted); cursor: pointer;
  border-radius: 6px; padding: 5px 9px; font-size: 0.8125rem;
  font-family: var(--sans); transition: all 0.12s;
  display: flex; align-items: center; gap: 4px; white-space: nowrap;
}
.tb-btn:hover { background: var(--card); border-color: var(--border); color: var(--text); }
.tb-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.page-input {
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 4px 6px; font-size: 0.8125rem; width: 44px;
  text-align: center; font-family: var(--sans); outline: none;
  transition: border-color 0.12s;
}
.page-input:focus { border-color: var(--accent); }
.page-of { font-size: 0.8125rem; color: var(--muted); }
.zoom-val { font-size: 0.75rem; color: var(--muted); min-width: 38px; text-align: center; }


/* ── EMPTY STATE ── */
.empty-state { text-align: center; padding: 5rem 2rem; color: var(--muted); }
.empty-state h3 { font-family: var(--serif); font-size: 1.5rem; margin-bottom: 0.5rem; color: var(--text); }


/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  nav, .book-nav { padding: 0 1.25rem; }
  .hero { padding: 2.5rem 1.25rem 2rem; flex-direction: column; }
  .hero-stats { gap: 1.5rem; }
  .filter-bar, .library, .related-section { padding-left: 1.25rem; padding-right: 1.25rem; }
  .book-hero { padding: 3rem 1.25rem 2.5rem; }
  .book-hero-content { flex-direction: column; gap: 1.5rem; }
  .book-emoji-large { font-size: 3.5rem; }
  .reader-sidebar-book { display: none; }
  .immersive-reader { height: 60vh; }
  .reader-section-header { padding: 0.75rem 1.25rem; }
  .nav-search { display: none; }
  .reader-controls-top { gap: 2px; }
}
