/* ==========================================================================
   Nexo Flipbook Platform — Editorial Design System & Responsive Styles
   ========================================================================== */

:root {
  --font-serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* Default Theme: Obsidian (Noche Editorial) */
  --bg-center: #1a1d28;
  --bg-edge: #08090e;
  --surface: rgba(18, 20, 29, 0.84);
  --surface-solid: #151823;
  --surface-elevated: #1d2130;
  --surface-hover: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.11);
  --border-strong: rgba(255, 255, 255, 0.2);
  --text: #f3f1ec;
  --text-muted: #a3a7b7;
  --accent: #d8aa54;
  --accent-contrast: #12100b;
  --danger: #ef5b5b;
  --success: #3ecf8e;
  --book-shadow: 0 28px 65px rgba(0, 0, 0, 0.65), 0 8px 20px rgba(0, 0, 0, 0.45);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --topbar-h: 58px;
  --dock-h: 82px;
}

/* Midnight Theme */
:root[data-theme='midnight'] {
  --bg-center: #13233d;
  --bg-edge: #070d19;
  --surface: rgba(11, 20, 36, 0.86);
  --surface-solid: #0f1b2e;
  --surface-elevated: #172742;
  --text: #eef4fc;
  --text-muted: #98aec9;
  --accent: #62b6ff;
  --accent-contrast: #061424;
}

/* Velvet Theme */
:root[data-theme='velvet'] {
  --bg-center: #2b141c;
  --bg-edge: #10070a;
  --surface: rgba(28, 13, 19, 0.86);
  --surface-solid: #221017;
  --surface-elevated: #311721;
  --text: #f9f2ed;
  --text-muted: #c2a4ad;
  --accent: #e0a96d;
  --accent-contrast: #1c0c09;
}

/* Parchment Light Theme */
:root[data-theme='parchment'] {
  --bg-center: #f4eee1;
  --bg-edge: #dfd4be;
  --surface: rgba(250, 246, 238, 0.9);
  --surface-solid: #faf6ee;
  --surface-elevated: #ffffff;
  --surface-hover: rgba(45, 34, 22, 0.07);
  --border: rgba(45, 34, 22, 0.14);
  --border-strong: rgba(45, 34, 22, 0.25);
  --text: #221b14;
  --text-muted: #6c5e4f;
  --accent: #8c5a2b;
  --accent-contrast: #ffffff;
  --book-shadow: 0 22px 52px rgba(42, 30, 16, 0.24), 0 6px 16px rgba(42, 30, 16, 0.14);
}

/* Gallery Light Theme */
:root[data-theme='gallery'] {
  --bg-center: #f7f8fa;
  --bg-edge: #e2e6ee;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-solid: #ffffff;
  --surface-elevated: #f3f5f9;
  --surface-hover: rgba(15, 23, 42, 0.06);
  --border: rgba(15, 23, 42, 0.12);
  --border-strong: rgba(15, 23, 42, 0.22);
  --text: #0f172a;
  --text-muted: #5b667a;
  --accent: #2563eb;
  --accent-contrast: #ffffff;
  --book-shadow: 0 24px 55px rgba(15, 23, 42, 0.18), 0 6px 18px rgba(15, 23, 42, 0.1);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  color: var(--text);
  background: radial-gradient(ellipse at 50% 44%, var(--bg-center) 0%, var(--bg-edge) 100%);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: -100px;
  left: 16px;
  z-index: 9999;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus {
  top: 14px;
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.icon {
  width: 19px;
  height: 19px;
  flex-shrink: 0;
}

/* ==========================================================================
   App Shell Layout
   ========================================================================== */
.app-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 42%, var(--bg-center) 0%, var(--bg-edge) 100%);
}

.app-shell.is-embed-mode #btn-open-library,
.app-shell.is-embed-mode #btn-quick-upload {
  display: none;
}

.app-shell.is-fullscreen .reader-topbar {
  background: transparent;
  border-bottom-color: transparent;
  backdrop-filter: none;
}

/* Fullscreen & Sound icon state switching */
.icon-fs-exit,
.icon-sound-off {
  display: none;
}
.is-fullscreen .icon-fs-enter,
.is-muted .icon-sound-on {
  display: none;
}
.is-fullscreen .icon-fs-exit,
.is-muted .icon-sound-off {
  display: block;
}

/* ==========================================================================
   Top Editorial Header
   ========================================================================== */
.reader-topbar {
  position: relative;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--topbar-h);
  padding: calc(8px + env(safe-area-inset-top, 0px)) 16px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.topbar-left {
  flex: 1;
}

.book-identity {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  padding-left: 6px;
}

.book-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.38rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-subtitle {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Buttons */
.icon-btn,
.pill-btn,
.dock-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease, transform 0.12s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn,
.dock-btn {
  width: 38px;
  height: 38px;
  padding: 0;
}

.pill-btn {
  height: 36px;
  padding: 0 13px;
  font-size: 0.83rem;
  font-weight: 600;
  border-radius: 999px;
}

.pill-brand {
  background: var(--surface-hover);
  border-color: var(--border);
}

.pill-accent {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  color: var(--accent);
}
.pill-accent:hover {
  background: var(--accent);
  color: var(--accent-contrast);
}

.icon-btn:hover,
.dock-btn:hover,
.pill-brand:hover {
  background: var(--surface-hover);
  border-color: var(--border);
}

.dock-btn.is-active,
.icon-btn.is-active {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 42%, transparent);
}

.dock-btn:disabled,
.icon-btn:disabled,
.nav-edge-btn:disabled {
  opacity: 0.32;
  pointer-events: none;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.16s ease, transform 0.12s ease;
}
.btn-primary:hover {
  filter: brightness(1.08);
}
.btn-primary:disabled {
  opacity: 0.55;
  cursor: wait;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.16s ease;
}
.btn-ghost:hover {
  background: var(--surface-hover);
}
.btn-danger-ghost:hover {
  border-color: var(--danger);
  color: var(--danger);
}
.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 8px;
}

/* Theme Popover */
.popover-anchor {
  position: relative;
}

.floating-popover {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 215px;
  padding: 8px;
  border-radius: var(--radius-md);
  background: var(--surface-solid);
  border: 1px solid var(--border-strong);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.45);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.popover-title {
  padding: 6px 10px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.theme-swatch-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}
.theme-swatch-btn:hover {
  background: var(--surface-hover);
}
.theme-swatch-btn.is-active {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}

.swatch-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid;
  flex-shrink: 0;
}

/* ==========================================================================
   Flipbook Stage & Realistic Book Presentation
   ========================================================================== */
.stage-viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.stage-viewport.is-zoomed {
  cursor: grab;
}
.stage-viewport.is-panning {
  cursor: grabbing;
}

/* Critical: when zoomed or pinching, prevent accidental StPageFlip turns so dragging pans smoothly */
.stage-viewport.is-zoomed .book-shell,
.stage-viewport.is-pinching .book-shell {
  pointer-events: none;
}

.zoom-layer {
  position: relative;
  transform-origin: center center;
  will-change: transform;
  display: flex;
  align-items: center;
  justify-content: center;
}

.zoom-layer.is-animating {
  transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}

.book-shift {
  transition: transform 0.56s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}
.book-shift.no-transition {
  transition: none !important;
}

.book-stage-frame {
  position: relative;
  display: inline-block;
}

.book-shell {
  position: relative;
  border-radius: 3px;
  filter: drop-shadow(0 26px 42px rgba(0, 0, 0, 0.5));
}

:root[data-theme='parchment'] .book-shell,
:root[data-theme='gallery'] .book-shell {
  filter: drop-shadow(0 20px 36px rgba(15, 23, 42, 0.22));
}

/* Subtle paper thickness stack edges when open in 2-page spread */
.book-shell[data-spread-state='open']::before,
.book-shell[data-spread-state='open']::after {
  content: '';
  position: absolute;
  top: 4px;
  bottom: 4px;
  width: 6px;
  pointer-events: none;
  z-index: 0;
  opacity: 0.72;
}
.book-shell[data-spread-state='open']::before {
  left: -5px;
  border-radius: 2px 0 0 2px;
  background: repeating-linear-gradient(
    90deg,
    #d6d1c6 0px,
    #f6f4ee 1px,
    #c7c1b5 2px
  );
  box-shadow: -2px 0 6px rgba(0, 0, 0, 0.35);
}
.book-shell[data-spread-state='open']::after {
  right: -5px;
  border-radius: 0 2px 2px 0;
  background: repeating-linear-gradient(
    90deg,
    #c7c1b5 0px,
    #f6f4ee 1px,
    #d6d1c6 2px
  );
  box-shadow: 2px 0 6px rgba(0, 0, 0, 0.35);
}

/* Override StPageFlip touch-action so two-finger pinch works cleanly on mobile */
.stf__parent {
  touch-action: none !important;
}

.flip-page {
  position: relative;
  width: 100%;
  height: 100%;
  background: #fdfcf9;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

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

.page-skeleton {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f8f6f1 0%, #ebe6dc 100%);
  color: #8b8579;
  font-family: var(--font-serif);
  font-size: 1.5rem;
  transition: opacity 0.24s ease;
  pointer-events: none;
}
.page-skeleton.is-hidden {
  opacity: 0;
}

/* Realistic Book Spine Gutter Shading */
.page-spine-shadow {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 30px;
  pointer-events: none;
  z-index: 3;
}
.flip-page.page-left .page-spine-shadow {
  right: 0;
  background: linear-gradient(
    to left,
    rgba(0, 0, 0, 0.24) 0%,
    rgba(0, 0, 0, 0.08) 28%,
    rgba(0, 0, 0, 0) 100%
  );
}
.flip-page.page-right .page-spine-shadow {
  left: 0;
  background: linear-gradient(
    to right,
    rgba(0, 0, 0, 0.22) 0%,
    rgba(255, 255, 255, 0.14) 12%,
    rgba(0, 0, 0, 0.06) 34%,
    rgba(0, 0, 0, 0) 100%
  );
}
.flip-page.is-hard-cover .page-spine-shadow {
  opacity: 0.45;
}
.flip-page.page-single .page-spine-shadow {
  left: 0;
  width: 14px;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0));
}

/* Razor-Sharp Hi-DPI Zoom Overlay */
.hires-overlay {
  position: absolute;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.14s ease;
}
.hires-overlay.is-visible {
  opacity: 1;
}
.hires-page-canvas {
  position: absolute;
  display: block;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
}

/* Edge Navigation Chevrons */
.nav-edge-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 32;
  width: 48px;
  height: 76px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.18s ease, opacity 0.2s ease, border-color 0.18s ease;
}
.nav-edge-btn svg {
  width: 24px;
  height: 24px;
}
.nav-edge-prev {
  left: 16px;
}
.nav-edge-next {
  right: 16px;
}
.nav-edge-btn:hover {
  background: var(--surface-elevated);
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-50%) scale(1.04);
}

/* Floating Zoom Pan Hint Banner */
.zoom-hint-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 35;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  font-size: 0.78rem;
  font-weight: 500;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  white-space: nowrap;
}
.zoom-banner-reset {
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
}

/* ==========================================================================
   Loading Curtain & Error State
   ========================================================================== */
.book-loader,
.book-error {
  position: absolute;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at center, var(--bg-center) 0%, var(--bg-edge) 100%);
  transition: opacity 0.38s ease, visibility 0.38s ease;
}

.book-loader.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-card,
.error-card {
  width: 100%;
  max-width: 380px;
  padding: 30px 28px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(18px);
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.loader-book-anim {
  position: relative;
  width: 58px;
  height: 42px;
  margin: 0 auto 18px;
  perspective: 220px;
}
.loader-page {
  position: absolute;
  top: 0;
  right: 0;
  width: 29px;
  height: 42px;
  border: 2px solid var(--accent);
  border-radius: 2px 5px 5px 2px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  transform-origin: left center;
  animation: flipLoader 1.5s infinite ease-in-out;
}
.loader-page:nth-child(2) { animation-delay: 0.25s; }
.loader-page:nth-child(3) { animation-delay: 0.5s; }

@keyframes flipLoader {
  0% { transform: rotateY(0deg); opacity: 0.9; }
  50% { transform: rotateY(-180deg); opacity: 0.95; }
  100% { transform: rotateY(-180deg); opacity: 0.25; }
}

.loader-title {
  margin: 0 0 6px;
  font-family: var(--font-serif);
  font-size: 1.55rem;
  font-weight: 600;
}
.loader-stage {
  margin: 0 0 16px;
  font-size: 0.84rem;
  color: var(--text-muted);
}
.loader-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-hover);
  overflow: hidden;
}
.loader-bar {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #ffffff));
  transition: width 0.2s ease;
}
.loader-percent {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
}

/* ==========================================================================
   Floating Accessible Bottom Dock
   ========================================================================== */
.reader-dock-wrap {
  position: relative;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.25) 0%, transparent 100%);
}

:root[data-theme='parchment'] .reader-dock-wrap,
:root[data-theme='gallery'] .reader-dock-wrap {
  background: linear-gradient(to top, rgba(0, 0, 0, 0.05) 0%, transparent 100%);
}

.scrubber-row {
  width: 100%;
  max-width: 780px;
  padding: 0 12px 4px;
}

.scrubber-track-wrap {
  position: relative;
  display: flex;
  align-items: center;
  height: 18px;
}

.scrubber-tooltip {
  position: absolute;
  bottom: 22px;
  transform: translateX(-50%);
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.14s ease;
}
.scrubber-tooltip.is-visible {
  opacity: 1;
}

.page-scrubber {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) var(--progress, 0%),
    var(--border-strong) var(--progress, 0%),
    var(--border-strong) 100%
  );
  cursor: pointer;
}
.page-scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface-solid);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: transform 0.14s ease;
}
.page-scrubber::-webkit-slider-thumb:hover {
  transform: scale(1.22);
}
.page-scrubber::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface-solid);
}

.reader-dock {
  width: 100%;
  max-width: 900px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.34);
}

.dock-group {
  display: flex;
  align-items: center;
  gap: 3px;
}

.page-counter {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
  height: 34px;
  border-radius: 9px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  font-size: 0.84rem;
  font-weight: 600;
}

.page-jump-input {
  width: 38px;
  border: none;
  background: transparent;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  padding: 2px 0;
  -moz-appearance: textfield;
}
.page-jump-input::-webkit-inner-spin-button,
.page-jump-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.page-total-label {
  color: var(--text-muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.zoom-cluster {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  padding: 0 3px;
  border-radius: 10px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
}

.zoom-readout {
  min-width: 48px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  border-radius: 7px;
  padding: 0 6px;
}
.zoom-readout:hover {
  color: var(--accent);
}

/* ==========================================================================
   Slide-Over Side Drawer (TOC, Thumbnails, Search)
   ========================================================================== */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  transition: opacity 0.22s ease;
}
.drawer-backdrop.is-open {
  opacity: 1;
}

.side-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 60;
  width: min(360px, 90vw);
  background: var(--surface-solid);
  border-right: 1px solid var(--border-strong);
  box-shadow: 20px 0 55px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.side-drawer.is-open {
  transform: translateX(0);
}

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

.drawer-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 600;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
}

.drawer-empty {
  padding: 20px 10px;
  text-align: center;
  font-size: 0.88rem;
  line-height: 1.55;
}

.toc-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.toc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  font-size: 0.86rem;
  text-align: left;
  cursor: pointer;
}
.toc-item:hover {
  background: var(--surface-hover);
  border-color: var(--border);
}
.toc-item.level-1 { padding-left: 24px; font-size: 0.83rem; }
.toc-item.level-2 { padding-left: 38px; font-size: 0.8rem; color: var(--text-muted); }
.toc-item-page {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}

.thumbs-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.thumb-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: var(--surface-hover);
  cursor: pointer;
  transition: border-color 0.16s ease, transform 0.14s ease;
}
.thumb-item:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
}
.thumb-item.is-active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.thumb-canvas-wrap {
  width: 100%;
  aspect-ratio: 0.72;
  background: #f3f0e8;
  border-radius: 5px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}
.thumb-canvas-wrap canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.thumb-num {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-muted);
}
.thumb-item.is-active .thumb-num {
  color: var(--accent);
}

/* Search Panel */
.search-form {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.search-status {
  margin: 0 0 12px;
  font-size: 0.8rem;
}
.search-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.search-result-item {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-hover);
  text-align: left;
  cursor: pointer;
}
.search-result-item:hover {
  border-color: var(--accent);
}
.search-result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
  font-size: 0.82rem;
}
.search-match-badge {
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
  font-weight: 700;
}
.search-result-snippet {
  margin: 0;
  font-size: 0.79rem;
  line-height: 1.45;
  color: var(--text-muted);
}
.search-result-snippet mark {
  background: color-mix(in srgb, var(--accent) 32%, transparent);
  color: var(--text);
  padding: 0 2px;
  border-radius: 3px;
}

/* ==========================================================================
   Modals: Studio Platform, Share/Embed & Help
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(5, 7, 12, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.modal-backdrop.is-open {
  opacity: 1;
}

.modal-window {
  width: 100%;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  background: var(--surface-solid);
  border: 1px solid var(--border-strong);
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  transform: translateY(10px) scale(0.985);
  transition: transform 0.22s ease;
}
.modal-backdrop.is-open .modal-window {
  transform: translateY(0) scale(1);
}

.studio-window { max-width: 960px; }
.share-window { max-width: 660px; }
.help-window { max-width: 640px; }

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.55rem;
  font-weight: 600;
}
.modal-subtitle {
  margin: 3px 0 0;
  font-size: 0.83rem;
  color: var(--text-muted);
}

.studio-status-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 22px;
  background: var(--surface-hover);
  border-bottom: 1px solid var(--border);
  font-size: 0.79rem;
}
.studio-mode-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.is-online { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-dot.is-local { background: var(--accent); box-shadow: 0 0 8px var(--accent); }

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

.studio-tabs {
  display: flex;
  gap: 6px;
  padding: 12px 22px 0;
  border-bottom: 1px solid var(--border);
}
.studio-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}
.studio-tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.tab-pill {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-hover);
  font-size: 0.74rem;
}

.studio-panel {
  flex: 1;
  overflow-y: auto;
  padding: 20px 22px 24px;
}

/* Library Grid & 3D Book Cards */
.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 18px;
}

.book-card {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  overflow: hidden;
  transition: transform 0.2s ease, border-color 0.2s ease;
}
.book-card:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
}

.book-card-cover {
  position: relative;
  height: 195px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--card-accent) 22%, var(--card-bg)), var(--card-bg));
}

.book-card-thumb {
  height: 162px;
  aspect-ratio: 0.7;
  border-radius: 3px 6px 6px 3px;
  overflow: hidden;
  background: #1a1e2b;
  box-shadow: -4px 0 0 rgba(255, 255, 255, 0.12) inset, 0 14px 28px rgba(0, 0, 0, 0.45);
}
.book-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.book-card-placeholder {
  width: 100%;
  height: 100%;
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  color: #f3efe6;
  border-left: 3px solid var(--card-accent);
}
.book-card-placeholder-title {
  font-family: var(--font-serif);
  font-size: 0.96rem;
  font-weight: 600;
}
.book-card-placeholder-sub {
  margin-top: 4px;
  font-size: 0.68rem;
  opacity: 0.7;
  text-transform: uppercase;
}

.book-card-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(0, 0, 0, 0.62);
  color: #f8fafc;
  backdrop-filter: blur(6px);
}

.book-card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 14px 15px 15px;
}
.book-card-title {
  margin: 0 0 4px;
  font-family: var(--font-serif);
  font-size: 1.24rem;
  font-weight: 600;
}
.book-card-meta {
  margin: 0 0 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.76rem;
  color: var(--text-muted);
}
.book-card-desc {
  margin: 0 0 12px;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-card-actions {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Upload Form */
.section-heading {
  margin: 0 0 14px;
  font-family: var(--font-serif);
  font-size: 1.35rem;
}
.upload-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.source-mode-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}
.radio-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.pdf-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 26px 18px;
  border-radius: var(--radius-md);
  border: 2px dashed var(--border-strong);
  background: var(--surface-hover);
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease;
}
.pdf-dropzone:hover,
.pdf-dropzone.is-dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.dropzone-icon {
  width: 38px;
  height: 38px;
  color: var(--accent);
  margin-bottom: 8px;
}
.dropzone-title {
  margin: 0 0 4px;
  font-size: 0.92rem;
}
.dropzone-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.upload-preview-card {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-elevated);
}
.upload-preview-img {
  width: 56px;
  height: 78px;
  object-fit: cover;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}
.upload-preview-meta {
  font-size: 0.83rem;
  line-height: 1.45;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.form-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}
.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.form-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}
.form-input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--surface-elevated);
  color: var(--text);
  font-size: 0.87rem;
}
.form-input-sm {
  padding: 6px 10px;
  font-size: 0.8rem;
}
.form-color {
  width: 100%;
  height: 39px;
  padding: 3px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--surface-elevated);
  cursor: pointer;
}
.field-hint {
  font-size: 0.74rem;
  color: var(--text-muted);
  word-break: break-all;
}
.field-hint code {
  color: var(--accent);
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}
.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
  cursor: pointer;
}
.checkbox-label input {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 4px;
}

/* Share & Help Modals */
.share-body {
  padding: 18px 22px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.input-action-row {
  display: flex;
  gap: 8px;
}
.share-split {
  display: grid;
  grid-template-columns: 1fr 190px;
  gap: 18px;
  align-items: start;
}
.code-area {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.76rem;
  line-height: 1.45;
  resize: vertical;
}
.share-qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.qr-canvas-box {
  width: 156px;
  height: 156px;
  padding: 8px;
  border-radius: 12px;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qr-canvas-box svg {
  width: 100%;
  height: 100%;
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  padding: 18px 22px 24px;
  overflow-y: auto;
}
.help-grid h3 {
  margin: 0 0 10px;
  font-size: 0.92rem;
  color: var(--accent);
}
.help-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.83rem;
  line-height: 1.45;
  color: var(--text-muted);
}
.help-list strong {
  color: var(--text);
}
kbd {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background: var(--surface-elevated);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 700;
}

.muted-note {
  color: var(--text-muted);
  font-size: 0.8rem;
}
.mt-xs { margin-top: 8px; }

/* Toasts */
.toast-container {
  position: fixed;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--surface-solid);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}
.toast-success { border-color: var(--success); }
.toast-error { border-color: var(--danger); }

/* ==========================================================================
   Responsive Mobile & Tablet Refinements
   ========================================================================== */
@media (max-width: 860px) {
  .nav-edge-btn {
    width: 36px;
    height: 56px;
    border-radius: 10px;
    opacity: 0.78;
  }
  .nav-edge-prev { left: 6px; }
  .nav-edge-next { right: 6px; }
  .hide-sm { display: none !important; }
  .book-subtitle { display: none; }
}

@media (max-width: 680px) {
  .reader-topbar {
    padding: calc(6px + env(safe-area-inset-top, 0px)) 10px 6px;
    min-height: 52px;
  }
  .pill-brand .btn-label { display: none; }
  .pill-brand {
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: 10px;
  }
  .book-title {
    font-size: 1.12rem;
  }
  .reader-topbar .hide-xs { display: none !important; }

  .reader-dock-wrap {
    padding: 2px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  }
  .scrubber-row {
    padding: 0 6px 4px;
  }
  .reader-dock {
    flex-wrap: wrap;
    row-gap: 6px;
    column-gap: 6px;
    padding: 7px 8px;
    border-radius: 16px;
  }
  .dock-center {
    order: 1;
    flex: 1 0 100%;
    justify-content: center;
    gap: 6px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
  }
  .dock-left {
    order: 2;
    gap: 2px;
  }
  .dock-right {
    order: 3;
    gap: 3px;
    margin-left: auto;
  }
  .dock-btn,
  .icon-btn {
    width: 36px;
    height: 36px;
  }
  .zoom-cluster .dock-btn {
    width: 32px;
    height: 32px;
  }
  .zoom-readout {
    min-width: 42px;
    height: 30px;
    font-size: 0.74rem;
    padding: 0 4px;
  }
  .page-counter {
    padding: 0 10px;
    height: 34px;
  }
  .page-jump-input {
    width: 34px;
  }
  .nav-edge-btn {
    width: 30px;
    height: 48px;
    background: color-mix(in srgb, var(--surface) 65%, transparent);
  }
  .zoom-hint-banner {
    font-size: 0.72rem;
    max-width: 92vw;
  }

  .form-grid,
  .form-grid-3,
  .share-split,
  .help-grid {
    grid-template-columns: 1fr;
  }
  .modal-backdrop {
    padding: 8px;
  }
  .studio-panel {
    padding: 14px;
  }
}

@media (max-width: 360px) {
  .zoom-readout {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .book-shift,
  .zoom-layer,
  .side-drawer,
  .modal-window {
    transition: none !important;
  }
}

@media print {
  body {
    display: none !important;
  }
}
