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

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

:root {
  --black:      #0f0f0f;
  --surface:    #1e1e1e;
  --surface2:   #2a2a2a;
  --surface3:   #333333;
  --gold:       #c8a96e;
  --gold-dim:   #9a7d4e;
  --parchment:  #f5f0e8;
  --muted:      #888880;
  --muted2:     #555550;
  --yellow:     #f5c842;
  --blue:       #5b8dd9;
  --green:      #5fad6f;
  --pink:       #d9608a;
  --radius:     12px;
  --radius-sm:  8px;
  --nav-h:      64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--black);
  color: var(--parchment);
  font-family: 'Inter', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Splash ── */
#splash {
  position: fixed;
  inset: 0;
  background: var(--black);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.6s ease;
}
#splash.fade-out { opacity: 0; pointer-events: none; }
.splash-logo { text-align: center; }
.splash-title {
  display: block;
  font-family: 'Playfair Display', serif;
  font-size: 32px;
  color: var(--gold);
  letter-spacing: 0.02em;
}
.splash-sub {
  display: block;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-top: 8px;
}

/* ── Layout ── */
#main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom));
}

/* ── Bottom Nav ── */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  background: rgba(15,15,15,0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--surface2);
  display: flex;
  align-items: flex-start;
  padding-top: 8px;
  padding-bottom: var(--safe-bottom);
  z-index: 100;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  cursor: pointer;
  color: var(--muted);
  transition: color 0.2s;
  background: none;
  border: none;
  font-family: 'Inter', sans-serif;
  -webkit-tap-highlight-color: transparent;
}
.nav-item.active { color: var(--gold); }
.nav-item svg { width: 22px; height: 22px; stroke-width: 1.5; }
.nav-label { font-size: 10px; letter-spacing: 0.05em; font-weight: 500; }

/* ── Views ── */
.view {
  display: none;
  min-height: 100%;
  padding: 0 0 24px;
  animation: fadeIn 0.25s ease;
}
.view.active { display: block; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── Page Header ── */
.page-header {
  padding: 56px 20px 24px;
  position: sticky;
  top: 0;
  background: rgba(15,15,15,0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 10;
  border-bottom: 1px solid var(--surface2);
}
.page-title {
  font-family: 'Playfair Display', serif;
  font-size: 28px;
  color: var(--parchment);
  letter-spacing: -0.01em;
}
.page-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* ── Search Bar ── */
.search-bar {
  margin: 16px 20px 0;
  position: relative;
}
.search-bar input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--surface3);
  border-radius: 10px;
  padding: 12px 16px 12px 42px;
  color: var(--parchment);
  font-size: 15px;
  font-family: 'Inter', sans-serif;
  outline: none;
  transition: border-color 0.2s;
}
.search-bar input:focus { border-color: var(--gold); }
.search-bar input::placeholder { color: var(--muted2); }
.search-bar svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--muted);
  pointer-events: none;
}

/* ── Book Grid ── */
.book-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  padding: 20px;
}
@media (min-width: 480px) { .book-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 768px) { .book-grid { grid-template-columns: repeat(4, 1fr); } }

.book-card {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.book-cover {
  aspect-ratio: 2/3;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
  position: relative;
  margin-bottom: 10px;
  border: 1px solid var(--surface2);
}
.book-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.book-cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: linear-gradient(145deg, var(--surface2), var(--surface));
}
.book-cover-placeholder .ph-title {
  font-family: 'Playfair Display', serif;
  font-size: 13px;
  color: var(--parchment);
  text-align: center;
  line-height: 1.3;
}
.book-cover-placeholder .ph-author {
  font-size: 10px;
  color: var(--muted);
  margin-top: 6px;
  text-align: center;
}
.book-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--gold);
  color: var(--black);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 4px;
}
.book-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--surface3);
}
.book-progress-bar {
  height: 100%;
  background: var(--gold);
  transition: width 0.3s;
}
.book-card-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--parchment);
  line-height: 1.3;
  margin-bottom: 2px;
}
.book-card-author {
  font-size: 11px;
  color: var(--muted);
}
.book-card-price {
  font-size: 12px;
  color: var(--gold);
  font-weight: 600;
  margin-top: 4px;
}

/* ── Section Label ── */
.section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  padding: 20px 20px 4px;
}

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 64px 32px;
  color: var(--muted);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 16px; opacity: 0.4; }
.empty-state h3 { font-family: 'Playfair Display', serif; font-size: 20px; color: var(--parchment); margin-bottom: 8px; }
.empty-state p { font-size: 14px; line-height: 1.6; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 24px;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--gold); color: var(--black); }
.btn-primary:active { background: var(--gold-dim); }
.btn-ghost { background: transparent; color: var(--parchment); border: 1px solid var(--surface3); }
.btn-ghost:active { background: var(--surface); }
.btn-full { width: 100%; }
.btn svg { width: 18px; height: 18px; }

/* ── Upload Zone ── */
.upload-zone {
  margin: 20px;
  border: 2px dashed var(--surface3);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--muted);
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--gold);
  background: rgba(200,169,110,0.05);
  color: var(--parchment);
}
.upload-zone svg { width: 36px; height: 36px; margin-bottom: 12px; display: block; margin-inline: auto; }
.upload-zone p { font-size: 14px; margin-bottom: 6px; }
.upload-zone small { font-size: 12px; color: var(--muted2); }

/* ── Reader ── */
#reader-view {
  position: fixed;
  inset: 0;
  background: var(--black);
  z-index: 200;
  display: none;
  flex-direction: column;
}
#reader-view.open { display: flex; }

#reader-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: rgba(15,15,15,0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 10;
  border-bottom: 1px solid var(--surface2);
  transform: translateY(-100%);
  transition: transform 0.3s ease;
}
#reader-topbar.visible { transform: none; }

.reader-back-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--parchment);
  flex-shrink: 0;
}
.reader-back-btn svg { width: 18px; height: 18px; }
#reader-title {
  flex: 1;
  font-size: 14px;
  color: var(--parchment);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reader-action-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--muted);
  transition: color 0.2s;
}
.reader-action-btn:hover, .reader-action-btn.active { color: var(--gold); }
.reader-action-btn svg { width: 20px; height: 20px; }

#reader-frame {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#epub-container {
  width: 100%;
  height: 100%;
}

#pdf-container {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: none;
}

/* The vignette — reading by glass, darkly */
#reader-frame::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(15,15,15,0.4) 100%);
  pointer-events: none;
  z-index: 1;
}

#reader-bottombar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 20px calc(12px + var(--safe-bottom));
  background: rgba(15,15,15,0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--surface2);
  transform: translateY(100%);
  transition: transform 0.3s ease;
}
#reader-bottombar.visible { transform: none; }

.reader-progress-track {
  width: 100%;
  height: 3px;
  background: var(--surface3);
  border-radius: 2px;
  margin-bottom: 10px;
  cursor: pointer;
}
.reader-progress-fill {
  height: 100%;
  background: var(--gold);
  border-radius: 2px;
  transition: width 0.3s;
}
.reader-progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
}

/* Reader settings panel */
#reader-settings {
  position: absolute;
  top: 56px;
  right: 16px;
  width: 240px;
  background: var(--surface);
  border: 1px solid var(--surface3);
  border-radius: var(--radius);
  padding: 16px;
  z-index: 20;
  display: none;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
#reader-settings.open { display: block; }

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.settings-label { font-size: 13px; color: var(--muted); }
.settings-controls { display: flex; gap: 8px; align-items: center; }
.settings-btn {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: var(--surface2);
  border: 1px solid var(--surface3);
  color: var(--parchment);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.settings-value { font-size: 14px; min-width: 32px; text-align: center; }

.theme-options { display: flex; gap: 8px; }
.theme-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.2s;
}
.theme-swatch.active { border-color: var(--gold); }

/* ── Highlights Panel ── */
#highlights-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 60vh;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  border-top: 1px solid var(--surface3);
  padding: 16px 20px calc(16px + var(--safe-bottom));
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32,0.72,0,1);
  z-index: 30;
}
#highlights-panel.open { transform: none; }
.panel-handle {
  width: 36px;
  height: 4px;
  background: var(--surface3);
  border-radius: 2px;
  margin: 0 auto 16px;
}
.panel-title {
  font-family: 'Playfair Display', serif;
  font-size: 18px;
  margin-bottom: 16px;
}
.highlight-item {
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  margin-bottom: 10px;
  border-left: 3px solid var(--yellow);
}
.highlight-item.blue { border-left-color: var(--blue); }
.highlight-item.green { border-left-color: var(--green); }
.highlight-item.pink { border-left-color: var(--pink); }
.highlight-text { font-size: 14px; line-height: 1.5; margin-bottom: 6px; }
.highlight-note { font-size: 12px; color: var(--muted); font-style: italic; }
.highlight-actions { display: flex; gap: 8px; margin-top: 8px; }
.highlight-action-btn {
  font-size: 11px;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
}
.highlight-action-btn:hover { color: var(--gold); }

/* Color picker */
.color-picker { display: flex; gap: 10px; margin-bottom: 12px; }
.color-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s;
}
.color-dot.yellow { background: var(--yellow); }
.color-dot.blue { background: var(--blue); }
.color-dot.green { background: var(--green); }
.color-dot.pink { background: var(--pink); }
.color-dot.active { transform: scale(1.2); border-color: var(--parchment); }

/* ── Book Detail ── */
#book-detail {
  position: fixed;
  inset: 0;
  background: var(--black);
  z-index: 150;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.32,0.72,0,1);
}
#book-detail.open { transform: none; }

.book-detail-hero {
  padding: 56px 20px 24px;
  display: flex;
  gap: 20px;
  align-items: flex-start;
}
.book-detail-cover {
  width: 110px;
  flex-shrink: 0;
  aspect-ratio: 2/3;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--surface2);
}
.book-detail-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-detail-meta { flex: 1; padding-top: 8px; }
.book-detail-title {
  font-family: 'Playfair Display', serif;
  font-size: 22px;
  line-height: 1.2;
  margin-bottom: 6px;
}
.book-detail-author { font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.star-rating { display: flex; gap: 3px; margin-bottom: 12px; }
.star { font-size: 14px; color: var(--gold-dim); }
.star.filled { color: var(--gold); }
.book-detail-price {
  font-size: 20px;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 16px;
}

.book-detail-body { padding: 0 20px 32px; }
.book-detail-desc {
  font-size: 15px;
  line-height: 1.7;
  color: var(--parchment);
  opacity: 0.85;
  margin-bottom: 24px;
}

.detail-back-btn {
  position: fixed;
  top: 16px;
  left: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(15,15,15,0.8);
  backdrop-filter: blur(8px);
  border: 1px solid var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--parchment);
  z-index: 10;
}

/* ── Auth View ── */
.auth-container {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
}
.auth-card {
  width: 100%;
  max-width: 360px;
}
.auth-logo {
  font-family: 'Playfair Display', serif;
  font-size: 28px;
  color: var(--gold);
  margin-bottom: 4px;
}
.auth-tagline {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 40px;
}
.auth-label { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.auth-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--surface3);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  color: var(--parchment);
  font-size: 16px;
  font-family: 'Inter', sans-serif;
  outline: none;
  margin-bottom: 16px;
  transition: border-color 0.2s;
}
.auth-input:focus { border-color: var(--gold); }
.auth-notice { font-size: 13px; color: var(--muted); margin-top: 16px; line-height: 1.5; }
.auth-success {
  text-align: center;
  padding: 20px 0;
  display: none;
}
.auth-success svg { width: 48px; height: 48px; color: var(--gold); margin-bottom: 16px; }
.auth-success h3 { font-family: 'Playfair Display', serif; font-size: 22px; margin-bottom: 8px; }
.auth-success p { font-size: 14px; color: var(--muted); line-height: 1.6; }

/* ── Profile View ── */
.profile-section { padding: 0 20px 24px; }
.profile-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--surface2);
  cursor: pointer;
}
.profile-row:last-child { border-bottom: none; }
.profile-row-label { font-size: 15px; }
.profile-row-value { font-size: 14px; color: var(--muted); }
.profile-row svg { width: 18px; height: 18px; color: var(--muted2); }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 0 20px 24px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 16px 12px;
  text-align: center;
  border: 1px solid var(--surface2);
}
.stat-value {
  font-family: 'Playfair Display', serif;
  font-size: 24px;
  color: var(--gold);
  display: block;
}
.stat-label { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface2);
  color: var(--parchment);
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 14px;
  opacity: 0;
  transition: all 0.3s;
  white-space: nowrap;
  z-index: 500;
  pointer-events: none;
  border: 1px solid var(--surface3);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Loading ── */
.spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--surface3);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Highlight Popup (selection) ── */
#highlight-popup {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--surface3);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  display: none;
  gap: 12px;
  z-index: 300;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
#highlight-popup.open { display: flex; }
.popup-color {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.15s;
}
.popup-color:hover { transform: scale(1.2); }

/* ── Review Form ── */
.review-form { padding: 0 20px 24px; }
.star-input { display: flex; gap: 8px; margin-bottom: 16px; cursor: pointer; }
.star-input span { font-size: 28px; color: var(--surface3); transition: color 0.15s; }
.star-input span.on { color: var(--gold); }
.review-textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--surface3);
  border-radius: var(--radius-sm);
  padding: 14px;
  color: var(--parchment);
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  resize: vertical;
  min-height: 100px;
  outline: none;
  margin-bottom: 16px;
}
.review-textarea:focus { border-color: var(--gold); }

/* Desktop layout */
@media (min-width: 768px) {
  #bottom-nav { display: none; }
  #sidebar {
	position: fixed;
	left: 0; top: 0; bottom: 0;
	width: 220px;
	background: var(--surface);
	border-right: 1px solid var(--surface2);
	display: flex;
	flex-direction: column;
	padding: 32px 0;
	z-index: 100;
  }
  .sidebar-logo {
	padding: 0 24px 32px;
	font-family: 'Playfair Display', serif;
	font-size: 20px;
	color: var(--gold);
	border-bottom: 1px solid var(--surface2);
	margin-bottom: 16px;
  }
  .sidebar-item {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 12px 24px;
	cursor: pointer;
	color: var(--muted);
	font-size: 14px;
	font-weight: 500;
	transition: color 0.2s;
	background: none;
	border: none;
	font-family: 'Inter', sans-serif;
	width: 100%;
	text-align: left;
  }
  .sidebar-item.active { color: var(--gold); background: rgba(200,169,110,0.08); }
  .sidebar-item svg { width: 18px; height: 18px; flex-shrink: 0; }
  #main-content { margin-left: 220px; padding-bottom: 40px; }
}
@media (max-width: 767px) { #sidebar { display: none; } }