:root {
  --bg-1: #201a17;
  --bg-2: #3b2d27;
  --line: rgba(255,255,255,0.12);
  --text: #f7f3f0;
  --muted: rgba(247,243,240,0.72);
  --accent: #e58f74;
  --panel: rgba(33, 25, 22, 0.92);
  --shadow: 0 20px 60px rgba(0,0,0,0.35);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 15% 20%, #5a4035 0%, #241b17 38%, #15110f 100%);
  overflow: hidden;
}
.toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 14px;
  background: rgba(31, 24, 21, 0.94);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  backdrop-filter: blur(14px);
}
.brand { display: flex; flex-direction: column; }
.brand-title { font-weight: 700; font-size: 17px; }
.brand-sub { font-size: 11px; color: var(--muted); margin-top: 1px; }
.toolbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(255,255,255,0.05);
  color: var(--text);
  border-radius: 10px;
  height: 38px;
  min-width: 38px;
  padding: 0 12px;
  font-size: 17px;
  cursor: pointer;
}
.icon-btn.small { height: 32px; min-width: 32px; }
.page-readout { min-width: 78px; text-align: center; font-size: 14px; color: var(--muted); }
.viewer-shell {
  position: fixed;
  top: 64px;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  padding: 10px 0 8px;
}
.pan-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: default;
}
.pan-viewport.zoomed { cursor: grab; }
.pan-viewport.dragging { cursor: grabbing; }
.book-stage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(84vw, 1360px);
  height: calc(100% - 18px);
  transform: translate(-50%, -50%) scale(1);
  transform-origin: center center;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 180ms ease;
}
.flipbook { box-shadow: 0 26px 80px rgba(0,0,0,0.44); }
.flipbook .page { background: #fff; }
.flipbook .page-content { width: 100%; height: 100%; display: flex; background: #f4f1ee; }
.flipbook .page-content img { width: 100%; height: 100%; object-fit: contain; display: block; user-select: none; -webkit-user-drag: none; background:#f4f1ee; }
.thumbs-panel {
  position: fixed;
  top: 76px;
  left: 12px;
  bottom: 12px;
  width: 250px;
  z-index: 35;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  transform: translateX(-120%);
  transition: transform 180ms ease;
}
.thumbs-panel.open { transform: translateX(0); }
.thumbs-header { display: flex; align-items: center; justify-content: space-between; }
.thumbs-list { overflow: auto; display: grid; gap: 8px; }
.thumb-item {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 9px;
  align-items: center;
  border: 1px solid rgba(255,255,255,0.09);
  background: rgba(255,255,255,0.035);
  border-radius: 12px;
  padding: 7px;
  color: var(--text);
  cursor: pointer;
}
.thumb-item.active { outline: 2px solid var(--accent); background: rgba(229,143,116,0.10); }
.thumb-item img { width: 64px; aspect-ratio: 1 / 1.414; object-fit: cover; border-radius: 7px; background: #fff; }
.thumb-label { font-size: 12px; }
.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 16, 14, 0.4);
  z-index: 30;
}
.loader-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 24px 30px;
  border-radius: 16px;
  background: rgba(30,23,20,0.9);
  border: 1px solid var(--line);
}
.loader-spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.14); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
.loader-text { color: var(--muted); font-size: 13px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 920px) {
  .toolbar { height: 58px; padding: 7px 10px; }
  .brand-title { font-size: 15px; }
  .brand-sub { display: none; }
  .toolbar-actions { gap: 6px; }
  .page-readout { min-width: 58px; }
  .viewer-shell { top: 58px; padding: 8px 0 6px; }
  .book-stage { width: 100vw; height: calc(100% - 14px); }
  .thumbs-panel { top: 68px; left: 8px; bottom: 8px; width: min(82vw, 280px); }
}
