:root {
  --bar-h: 58px;
  --bottom-h: 54px;
  --bg: #161616;
  --panel: #232323;
  --panel2: #2e2e2e;
  --text: #f6f6f6;
  --muted: #bfbfbf;
  --accent: #e31b23;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; font-family: Arial, Helvetica, sans-serif; background: var(--bg); color: var(--text); }
button, input, a { font: inherit; }
button { color: inherit; }
.topbar {
  height: var(--bar-h); display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; background: #0f0f0f; border-bottom: 1px solid #333; position: relative; z-index: 20;
}
.brand { display: flex; gap: 10px; align-items: baseline; min-width: 0; }
.brand strong { font-size: 18px; white-space: nowrap; }
.brand span { color: var(--muted); font-size: 13px; white-space: nowrap; }
.actions { display: flex; gap: 6px; align-items: center; }
.actions button, .bottombar button, .sidebar button, .pdf-link {
  border: 0; background: var(--panel2); color: #fff; min-width: 36px; height: 36px; border-radius: 7px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
}
.actions button:hover, .bottombar button:hover, .sidebar button:hover, .pdf-link:hover { background: #444; }
#zoomLabel { width: 48px; text-align: center; font-size: 12px; color: var(--muted); }
.viewer-shell { height: calc(100% - var(--bar-h) - var(--bottom-h)); display: flex; position: relative; }
.stage { flex: 1; position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; padding: 18px 56px; }
.book-wrap { max-width: 100%; max-height: 100%; transform-origin: center center; transition: transform .15s ease; }
.book {
  display: flex; align-items: stretch; justify-content: center; height: min(calc(100vh - 150px), 860px);
  aspect-ratio: 1.555 / 1; filter: drop-shadow(0 12px 22px rgba(0,0,0,.55));
  perspective: 2200px;
}
.page-slot { height: 100%; aspect-ratio: 595 / 765; background: #fff; overflow: hidden; position: relative; }
.page-slot.left { transform-origin: right center; border-radius: 4px 0 0 4px; }
.page-slot.right { transform-origin: left center; border-radius: 0 4px 4px 0; }
.page-slot img { width: 100%; height: 100%; object-fit: contain; display: block; user-select: none; -webkit-user-drag: none; }
.page-slot::after { content: ''; position: absolute; inset: 0; pointer-events: none; }
.page-slot.left::after { background: linear-gradient(to left, rgba(0,0,0,.16), transparent 5%); }
.page-slot.right::after { background: linear-gradient(to right, rgba(0,0,0,.14), transparent 5%); }
.page-slot.empty { visibility: hidden; }
.flip-next { animation: flipNext .34s ease; }
.flip-prev { animation: flipPrev .34s ease; }
@keyframes flipNext { from { transform: rotateY(0deg); opacity: 1; } 45% { transform: rotateY(-18deg); opacity: .72; } to { transform: rotateY(0deg); opacity: 1; } }
@keyframes flipPrev { from { transform: rotateY(0deg); opacity: 1; } 45% { transform: rotateY(18deg); opacity: .72; } to { transform: rotateY(0deg); opacity: 1; } }
.nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 10; width: 46px; height: 72px; border: 0; border-radius: 10px; background: rgba(0,0,0,.48); color: white; font-size: 44px; line-height: 1; cursor: pointer; }
.nav:hover { background: rgba(0,0,0,.75); }
.nav.prev { left: 8px; }
.nav.next { right: 8px; }
.nav:disabled { opacity: .22; cursor: default; }
.bottombar { height: var(--bottom-h); background: #0f0f0f; border-top: 1px solid #333; display: flex; align-items: center; justify-content: center; gap: 8px; position: relative; z-index: 20; }
.bottombar button { width: 36px; height: 34px; }
.page-indicator { color: var(--muted); font-size: 13px; }
.page-indicator input { width: 52px; padding: 5px; text-align: center; border-radius: 5px; border: 1px solid #555; color: white; background: #222; }
.sidebar { width: 220px; height: 100%; background: #1b1b1b; border-right: 1px solid #333; position: absolute; left: 0; top: 0; z-index: 18; transform: translateX(-100%); transition: transform .2s ease; }
.sidebar.open { transform: translateX(0); }
.sidebar-head { height: 48px; padding: 0 10px 0 14px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #333; }
.sidebar-head button { background: transparent; font-size: 24px; }
.thumbs { height: calc(100% - 48px); overflow-y: auto; padding: 10px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.thumb { border: 2px solid transparent; background: transparent; padding: 0; cursor: pointer; border-radius: 4px; overflow: hidden; position: relative; }
.thumb img { width: 100%; display: block; }
.thumb span { position: absolute; right: 3px; bottom: 3px; background: rgba(0,0,0,.72); color: white; border-radius: 3px; padding: 2px 5px; font-size: 10px; }
.thumb.active { border-color: var(--accent); }

@media (max-width: 760px) {
  .brand span, #zoomLabel, #zoomOut, #zoomIn { display: none; }
  .brand strong { font-size: 15px; }
  .stage { padding: 10px 42px; }
  .book { height: min(calc(100vh - 138px), 760px); aspect-ratio: 595 / 765; }
  .page-slot.left { display: none; }
  .page-slot.right { border-radius: 4px; }
  .nav { width: 36px; height: 62px; font-size: 38px; }
  .sidebar { width: min(76vw, 260px); }
}

@media (max-width: 430px) {
  .pdf-link { display: none; }
  .topbar { padding: 0 8px; }
  .actions { gap: 4px; }
  .actions button { min-width: 33px; }
  .stage { padding-left: 36px; padding-right: 36px; }
}
