:root {
  --bg-primary: #0d0f12;
  --bg-secondary: #161920;
  --bg-glass: rgba(22, 25, 32, 0.75);
  --bg-glass-hover: rgba(35, 40, 52, 0.85);
  --border-glass: rgba(255, 255, 255, 0.1);
  --border-accent: rgba(212, 175, 55, 0.3);
  --accent-gold: #d4af37;
  --accent-gold-light: #f3e5ab;
  --accent-gold-glow: rgba(212, 175, 55, 0.4);
  --text-primary: #f5f6f8;
  --text-secondary: #9da3af;
  --text-muted: #6b7280;
  --shadow-main: 0 20px 50px rgba(0, 0, 0, 0.6);
  --shadow-book: 0 25px 60px -15px rgba(0, 0, 0, 0.8), 0 0 40px rgba(0, 0, 0, 0.5);
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: radial-gradient(circle at 50% 20%, #1e222d 0%, #0d0f12 70%);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  user-select: none;
}

/* Background Ambient Lighting */
.ambient-glow {
  position: fixed;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, var(--accent-gold-glow) 0%, transparent 70%);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  filter: blur(80px);
  opacity: 0.15;
  pointer-events: none;
  z-index: 0;
}

/* TOP HEADER BAR */
.header-bar {
  position: relative;
  z-index: 10;
  height: 60px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-glass);
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, var(--accent-gold), #9a7b20);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #0d0f12;
  font-weight: 800;
  font-size: 16px;
  box-shadow: 0 4px 12px var(--accent-gold-glow);
}

.brand-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text-primary);
  white-space: nowrap;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--accent-gold);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-left: 6px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* BUTTONS & CONTROLS */
.btn-icon {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
  position: relative;
}

.btn-icon:hover {
  background: var(--bg-glass-hover);
  color: var(--text-primary);
  border-color: var(--border-glass);
}

.btn-icon.active {
  color: var(--accent-gold);
  background: rgba(212, 175, 55, 0.12);
  border-color: var(--border-accent);
}

.btn-icon svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* Tooltip on hover */
.tooltip {
  position: relative;
}

.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: -32px;
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: rgba(10, 12, 16, 0.95);
  color: var(--text-primary);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: var(--transition-fast);
  border: 1px solid var(--border-glass);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  z-index: 50;
}

.tooltip:hover::after {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* MAIN FLIPBOOK STAGE */
.stage-container {
  position: relative;
  flex: 1;
  width: 100%;
  height: calc(100vh - 130px);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  z-index: 1;
}

.zoom-viewport {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease-out;
  transform-origin: center center;
}

.book-wrapper {
  position: relative;
  box-shadow: var(--shadow-book);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Flipbook Pages Styling */
#flipbook {
  position: relative;
  margin: 0 auto;
}

.page {
  background-color: #ffffff;
  overflow: hidden;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
}

.page-content {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
}

.page-content canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.page-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 13px;
  height: 100%;
  width: 100%;
  background: #fdfdfd;
}

.page-number-corner {
  position: absolute;
  bottom: 8px;
  font-size: 11px;
  font-weight: 500;
  color: #888;
  z-index: 2;
}

.page-left .page-number-corner {
  left: 14px;
}

.page-right .page-number-corner {
  right: 14px;
}

/* Hard Cover spine lighting effect */
.page[data-density="hard"] {
  box-shadow: 0 5px 25px rgba(0,0,0,0.35);
}

/* SIDE NAVIGATION BUTTONS */
.nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  background: var(--bg-glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border-glass);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  cursor: pointer;
  z-index: 5;
  transition: var(--transition-fast);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.nav-arrow:hover {
  background: var(--accent-gold);
  color: #0d0f12;
  border-color: var(--accent-gold);
  transform: translateY(-50%) scale(1.1);
}

.nav-prev {
  left: 24px;
}

.nav-next {
  right: 24px;
}

.nav-arrow svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

/* BOTTOM CONTROL BAR */
.bottom-dock {
  position: relative;
  z-index: 10;
  height: 70px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-glass);
}

.dock-group {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.25);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-glass);
}

.page-jump-container {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.page-input {
  width: 44px;
  height: 28px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  color: var(--accent-gold-light);
  text-align: center;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  outline: none;
  transition: var(--transition-fast);
}

.page-input:focus {
  border-color: var(--accent-gold);
  background: rgba(212, 175, 55, 0.15);
}

.zoom-level-text {
  font-size: 12px;
  font-weight: 600;
  min-width: 42px;
  text-align: center;
  color: var(--text-secondary);
}

/* THUMBNAILS DRAWER */
.thumbnail-drawer {
  position: fixed;
  top: 60px;
  left: -320px;
  width: 300px;
  height: calc(100vh - 130px);
  background: rgba(16, 19, 25, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--border-glass);
  z-index: 20;
  transition: left 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
}

.thumbnail-drawer.open {
  left: 0;
}

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

.drawer-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.5px;
}

.thumbnail-grid {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.thumbnail-grid::-webkit-scrollbar {
  width: 5px;
}

.thumbnail-grid::-webkit-scrollbar-thumb {
  background: var(--border-glass);
  border-radius: 4px;
}

.thumb-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: var(--transition-fast);
  padding: 6px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
}

.thumb-card:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border-glass);
}

.thumb-card.active {
  border-color: var(--accent-gold);
  background: rgba(212, 175, 55, 0.1);
}

.thumb-preview {
  width: 100%;
  aspect-ratio: 1 / 1.414;
  background: #ffffff;
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
}

.thumb-preview canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-label {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* LOADING OVERLAY */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 100;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-overlay.fade-out {
  opacity: 0;
  visibility: hidden;
}

.loading-brand {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 1px;
  background: linear-gradient(135deg, #ffffff, var(--accent-gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 3px solid rgba(212, 175, 55, 0.15);
  border-top-color: var(--accent-gold);
  border-radius: 50%;
  animation: spin 1s infinite linear;
}

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

.loading-progress-container {
  width: 260px;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

.loading-progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #c5a059, #f3e5ab);
  transition: width 0.3s ease;
  box-shadow: 0 0 10px var(--accent-gold-glow);
}

.loading-text {
  font-size: 13px;
  color: var(--text-secondary);
}

/* MODAL / HELP POPUP */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition-fast);
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  width: 90%;
  max-width: 480px;
  padding: 24px;
  box-shadow: var(--shadow-main);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent-gold-light);
}

.shortcut-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 13px;
}

.shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

kbd {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border-glass);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 11px;
  font-family: monospace;
  color: var(--accent-gold-light);
}

/* RESPONSIVE DESIGN */
@media (max-width: 768px) {
  .header-bar {
    padding: 0 12px;
  }
  .brand-subtitle {
    display: none;
  }
  .nav-arrow {
    display: none; /* Rely on touch swiping on mobile */
  }
  .bottom-dock {
    padding: 0 8px;
    gap: 6px;
  }
  .dock-group {
    padding: 2px 6px;
  }
  .btn-hide-mobile {
    display: none;
  }
}
