/* ==========================================================================
   Design System & Tokens (Ultra-Minimalist Light Theme & Paper Aesthetic)
   ========================================================================== */
:root {
  /* Warm Alabaster Paper Tone Palette */
  --bg-deep: #f7f6f2;
  --bg-surface: #ffffff;
  --bg-elevated: #eae9e4;
  
  --text-primary: #2b2b2b;
  --text-secondary: #6e6d68;
  --text-muted: #9e9d97;
  
  --accent-gold: #d4a017;
  --accent-blue: #3b82f6;
  --accent-rose: #e11d48;
  
  /* Soft Editorial Light Glassmorphism */
  --glass-bg: rgba(255, 255, 255, 0.82);
  --glass-border: rgba(0, 0, 0, 0.06);
  --glass-blur: backdrop-filter: blur(20px) saturate(160%);
  --glass-shadow: 0 10px 30px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.03);

  /* Typography & Sizing */
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --transition-smooth: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-fast: all 0.2s ease-out;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  background-color: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.reading-mode {
  overflow: hidden;
}

/* ==========================================================================
   Subtle Warm Ambient Daylight Glow
   ========================================================================== */
.ambient-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.light-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.6;
}

.blob-1 {
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(255, 248, 231, 0.8) 0%, rgba(247, 246, 242, 0) 70%);
  top: 5%;
  left: 15%;
}

.blob-2 {
  width: 700px;
  height: 700px;
  background: radial-gradient(circle, rgba(235, 233, 226, 0.7) 0%, rgba(247, 246, 242, 0) 70%);
  bottom: 5%;
  right: 15%;
}

/* ==========================================================================
   Layout Containers & View Transitions
   ========================================================================== */
.view-container {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1), transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.view-container.hidden {
  display: none;
  opacity: 0;
  pointer-events: none;
}

/* ==========================================================================
   LIBRARY VIEW (Pure Cover & Progress Bar)
   ========================================================================== */
#library-view {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2rem;
  height: 100vh;
}

.book-grid {
  display: flex;
  justify-content: center;
  align-items: center;
}

.book-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  padding: 2.5rem;
  border-radius: 24px;
  cursor: pointer;
  outline: none;
  transition: var(--transition-smooth);
}

.book-card:hover, .book-card:focus {
  transform: translateY(-8px);
}

.book-cover-wrapper {
  position: relative;
  width: 300px;
  height: 440px;
  border-radius: 12px;
  perspective: 1200px;
  transform-style: preserve-3d;
  transition: var(--transition-smooth);
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.12), 0 6px 16px rgba(0, 0, 0, 0.08);
}

.book-card:hover .book-cover-wrapper {
  transform: scale(1.025);
  box-shadow: 0 32px 70px rgba(0, 0, 0, 0.18), 0 8px 24px rgba(0, 0, 0, 0.1);
}

.book-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 10px;
}

.book-spine-effect {
  position: absolute;
  top: 0;
  left: 0;
  width: 14px;
  height: 100%;
  background: linear-gradient(90deg, rgba(255,255,255,0.2) 0%, rgba(255,255,255,0) 100%, rgba(0,0,0,0.15) 100%);
  border-top-left-radius: 10px;
  border-bottom-left-radius: 10px;
  pointer-events: none;
}

.cover-shine {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, rgba(255,255,255,0) 50%);
  pointer-events: none;
}

.progress-container {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: 260px;
}

.progress-bar-bg {
  width: 100%;
  height: 5px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 10px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--text-primary);
  border-radius: 10px;
  transition: width 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.progress-badge {
  font-weight: 600;
  color: var(--text-primary);
}

/* ==========================================================================
   READER VIEW & AUTO-HIDING HEADER (Zero-Distraction UI)
   ========================================================================== */
#reader-view {
  position: relative;
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: var(--bg-deep);
}

.glass-ui {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--glass-shadow);
}

.reader-header {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  width: auto;
  min-width: 480px;
  height: 54px;
  border-radius: 27px;
  padding: 0 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 2rem;
  z-index: 100;
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s ease;
}

.reader-header.auto-hide {
  transform: translateX(-50%) translateY(-140%);
  opacity: 0;
  pointer-events: none;
}

.header-trigger {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 24px;
  z-index: 99;
  cursor: pointer;
}

.header-left, .header-center, .header-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.ctrl-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.45rem;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
  position: relative;
}

.ctrl-btn:hover {
  color: var(--text-primary);
  background: rgba(0, 0, 0, 0.05);
}

.ctrl-btn.active {
  color: var(--accent-gold);
  background: rgba(212, 160, 23, 0.1);
}

.nav-arrow {
  padding: 0.3rem 0.6rem;
  font-size: 0.95rem;
}

/* Page Selector Input */
.page-navigator {
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  padding: 0.15rem 0.35rem;
  gap: 0.2rem;
}

.page-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--text-primary);
}

#page-input {
  width: 44px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  outline: none;
}

#page-input::-webkit-outer-spin-button,
#page-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.page-total {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.count-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: var(--text-primary);
  color: #ffffff;
  font-size: 0.6rem;
  font-weight: 700;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==========================================================================
   Drawing / Highlighting Sub-toolbar
   ========================================================================== */
.drawing-toolbar {
  position: absolute;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  height: 44px;
  border-radius: 22px;
  padding: 0 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  z-index: 95;
  transition: var(--transition-smooth);
}

.color-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: var(--transition-fast);
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.color-swatch:hover, .color-swatch.active {
  transform: scale(1.25);
  border-color: var(--text-primary);
}

.divider {
  width: 1px;
  height: 18px;
  background: var(--glass-border);
  margin: 0 0.3rem;
}

.btn-tool-action {
  background: transparent;
  border: none;
  color: var(--accent-rose);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
}

.btn-tool-action:hover {
  text-decoration: underline;
}

/* ==========================================================================
   Page-Flip Book Viewport & Real Physics Canvas
   ========================================================================== */
.flip-viewport {
  flex: 1;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  perspective: 2000px;
  padding: 20px;
  min-height: 500px;
}

.book-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  flex: 1;
}

.st-page-flip {
  margin: 0 auto;
  width: 100%;
  height: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15), 0 5px 20px rgba(0,0,0,0.06);
  border-radius: 4px;
}

/* Individual Page Styling (Warm White Paper) */
.st-page-flip .page {
  background: #ffffff;
  border-right: 1px solid rgba(0,0,0,0.1);
  box-shadow: inset -5px 0 15px rgba(0,0,0,0.03);
  overflow: hidden;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.st-page-flip .page.-left {
  border-right: 1px solid rgba(0,0,0,0.05);
  border-left: 1px solid rgba(0,0,0,0.1);
  box-shadow: inset 5px 0 15px rgba(0,0,0,0.03);
}

.page-content {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: auto;
}

.pdf-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.annotation-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.annotation-canvas.drawing-active {
  pointer-events: auto;
  cursor: crosshair;
}

.placeholder {
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--text-muted);
}

.loading-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(0, 0, 0, 0.05);
  border-top-color: var(--text-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ==========================================================================
   Notes & Bookmarks Drawer (Clean Light Paper Drawer)
   ========================================================================== */
.notes-drawer {
  position: absolute;
  right: 0;
  top: 0;
  width: 340px;
  height: 100%;
  z-index: 200;
  display: flex;
  flex-direction: column;
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  background: #ffffff;
  border-left: 1px solid var(--glass-border);
  box-shadow: -15px 0 40px rgba(0,0,0,0.08);
}

.notes-drawer.hidden {
  display: flex;
  opacity: 1;
  pointer-events: none;
  transform: translateX(100%);
}

.drawer-header {
  padding: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--glass-border);
}

.drawer-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.drawer-body {
  padding: 1.5rem;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.current-page-note-input {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.current-page-note-input label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

#new-note-text {
  width: 100%;
  background: var(--bg-deep);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 12px;
  padding: 0.8rem;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  outline: none;
  resize: vertical;
}

#new-note-text:focus {
  border-color: var(--text-primary);
}

.primary-btn {
  background: var(--text-primary);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  padding: 0.6rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
  align-self: flex-end;
}

.primary-btn:hover {
  background: #000000;
}

.drawer-divider {
  border: none;
  height: 1px;
  background: rgba(0,0,0,0.06);
}

.saved-notes-list {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.note-item {
  background: var(--bg-deep);
  border: 1px solid rgba(0,0,0,0.04);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  cursor: pointer;
  transition: var(--transition-fast);
}

.note-item:hover {
  background: var(--bg-elevated);
}

.note-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-primary);
  font-weight: 600;
}

.note-delete-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
}

.note-delete-btn:hover {
  color: var(--accent-rose);
}

.note-content {
  font-size: 0.85rem;
  color: var(--text-primary);
  line-height: 1.4;
  word-break: break-word;
}

.note-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 2rem 0;
}
