:root {
  --bg-deep: #0d1117;
  --bg-stage: radial-gradient(circle at 50% 48%, #222936 0%, #11161f 58%, #090c10 100%);
  --surface: rgba(22, 27, 34, 0.88);
  --surface-solid: #161b22;
  --surface-hover: rgba(48, 54, 61, 0.75);
  --border: rgba(255, 255, 255, 0.1);
  --text: #f0f6fc;
  --text-muted: #8b949e;
  --accent: #f97316;
  --accent-soft: rgba(249, 115, 22, 0.18);
  --shadow-book: 0 26px 65px rgba(0, 0, 0, 0.75), 0 8px 24px rgba(0, 0, 0, 0.5);
  --radius: 10px;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* Topbar */
.topbar {
  height: 58px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.brand-text h1 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-text span {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
}

/* Search */
.search-wrapper {
  position: relative;
  flex: 1;
  max-width: 440px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(13, 17, 23, 0.85);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-box .icon {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-box input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 13px;
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.shortcut-hint {
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: inherit;
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 380px;
  overflow-y: auto;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.65);
  z-index: 60;
  padding: 6px;
}

.search-results.hidden {
  display: none;
}

.search-meta {
  padding: 6px 10px;
  font-size: 11px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.search-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s;
}

.search-item:hover {
  background: var(--surface-hover);
}

.search-page-pill {
  flex-shrink: 0;
  background: var(--accent-soft);
  color: #fb923c;
  font-weight: 700;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
}

.search-snippet {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.search-snippet mark {
  background: rgba(249, 115, 22, 0.35);
  color: #fff;
  padding: 0 2px;
  border-radius: 2px;
}

/* Toolbar buttons */
.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.icon-btn.small {
  width: 30px;
  height: 30px;
}

.icon-btn:hover {
  background: var(--surface-hover);
}

.icon-btn.active {
  background: var(--accent-soft);
  color: #fb923c;
  border-color: rgba(249, 115, 22, 0.35);
}

.icon-btn .icon {
  width: 18px;
  height: 18px;
}

.divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.zoom-label {
  min-width: 46px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
}

.zoom-label:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* Stage */
.stage-container {
  position: relative;
  flex: 1;
  display: flex;
  overflow: hidden;
  background: var(--bg-stage);
}

/* Thumbnails Drawer */
.thumbs-drawer {
  width: 280px;
  background: var(--surface-solid);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 30;
  margin-left: -280px;
  transition: margin-left 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.thumbs-drawer.open {
  margin-left: 0;
}

.drawer-header {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
}

.thumbs-grid {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  align-content: start;
}

.thumb-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 6px;
  border-radius: 8px;
  border: 2px solid transparent;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.thumb-card:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-1px);
}

.thumb-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.thumb-card img {
  width: 100%;
  aspect-ratio: 0.70667;
  object-fit: cover;
  border-radius: 4px;
  background: #21262d;
  display: block;
}

.thumb-card span {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

.thumb-card.active span {
  color: #fb923c;
}

/* Viewport */
.viewport {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.zoom-stage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center center;
  transition: transform 0.15s ease-out;
  will-change: transform;
}

.zoom-stage.panning {
  transition: none;
  cursor: grabbing;
}

.flipbook-container {
  box-shadow: var(--shadow-book);
}

/* Page elements inside StPageFlip */
.flip-page {
  background: #ffffff;
  overflow: hidden;
  position: relative;
}

.flip-page.hard-cover {
  background: #1b1f26;
}

.flip-page img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  position: relative;
  z-index: 2;
}

.page-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #6e7681;
  font-size: 13px;
  background: linear-gradient(135deg, #f3f4f6, #e5e7eb);
  z-index: 1;
}

.page-link-hotspot {
  position: absolute;
  z-index: 5;
  display: block;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.page-link-hotspot:hover {
  background: rgba(249, 115, 22, 0.18);
  box-shadow: inset 0 0 0 1px rgba(249, 115, 22, 0.45);
}

.page-toc-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(13, 17, 23, 0.72);
  backdrop-filter: blur(6px);
  color: #f0f6fc;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

.page-toc-btn:hover {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  transform: translateY(-1px);
}

.page-toc-btn svg {
  width: 12px;
  height: 12px;
}

/* Subtle book spine shadow */
.flip-page.--left::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 28px;
  height: 100%;
  background: linear-gradient(to left, rgba(0, 0, 0, 0.16), transparent);
  pointer-events: none;
}

.flip-page.--right::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 28px;
  height: 100%;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.14), transparent);
  pointer-events: none;
}

/* Side Navigation Arrows */
.nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 64px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(22, 27, 34, 0.65);
  backdrop-filter: blur(8px);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 25;
  transition: background 0.15s, transform 0.15s, opacity 0.15s;
}

.nav-arrow:hover {
  background: rgba(249, 115, 22, 0.88);
  border-color: transparent;
}

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

.nav-prev { left: 16px; }
.nav-next { right: 16px; }

/* Bottom Bar */
.bottombar {
  height: 54px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  background: var(--surface);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  z-index: 40;
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.page-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 6px;
}

.page-indicator input {
  width: 54px;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(13, 17, 23, 0.85);
  color: var(--text);
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  outline: none;
}

.page-indicator input:focus {
  border-color: var(--accent);
}

.page-indicator strong {
  color: var(--text);
}

.scrubber-wrap {
  flex: 1;
  display: flex;
  align-items: center;
}

#page-slider {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
  height: 6px;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.28);
}

@media (max-width: 768px) {
  .brand-text span,
  .shortcut-hint,
  #zoom-label,
  #btn-zoom-in,
  #btn-zoom-out {
    display: none;
  }
  .topbar {
    padding: 0 10px;
    gap: 8px;
  }
  .nav-arrow {
    width: 36px;
    height: 48px;
  }
  .nav-prev { left: 6px; }
  .nav-next { right: 6px; }
  .bottombar {
    padding: 0 12px;
    gap: 10px;
  }
}
