/* Flipbook viewer */
:root {
  --stage-bg-1: #262b36;
  --stage-bg-2: #16191f;
  --bar-bg: rgba(17, 20, 27, 0.92);
  --bar-border: rgba(255, 255, 255, 0.08);
  --icon: #e8ebf2;
  --icon-dim: #9aa3b5;
  --red: #d8232a;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: radial-gradient(1100px 700px at 50% 30%, var(--stage-bg-1), var(--stage-bg-2) 85%);
  color: var(--icon);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
#app:fullscreen { background: radial-gradient(1100px 700px at 50% 30%, var(--stage-bg-1), var(--stage-bg-2) 85%); }

/* ---------- Top bar ---------- */
#topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 10px 18px;
  background: var(--bar-bg);
  border-bottom: 1px solid var(--bar-border);
  z-index: 40;
  min-height: 52px;
}

#topbar .back {
  display: inline-flex; align-items: center; gap: 7px;
  color: var(--icon-dim); text-decoration: none; font-size: 13.5px; font-weight: 600;
  white-space: nowrap;
}
#topbar .back:hover { color: #fff; }
#topbar .back svg { width: 16px; height: 16px; }

#issue-title {
  flex: 1;
  text-align: center;
  font-size: 14.5px; font-weight: 700; letter-spacing: 0.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#issue-title .mag { color: var(--icon-dim); font-weight: 600; }

#page-indicator {
  font-size: 13px; color: var(--icon-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap; min-width: 90px; text-align: right;
}

body.embed #topbar { display: none; }

/* ---------- Stage ---------- */
#stage {
  position: relative;
  flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
}

#book-wrap { position: relative; }

#book { width: 100%; height: 100%; }

/* page elements handed to PageFlip */
.page {
  background: #fff;
  overflow: hidden;
}
.page .page-inner { position: absolute; inset: 0; }
.page img.page-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: fill;
  display: block;
  -webkit-user-drag: none;
  user-select: none;
}
.page .page-links { position: absolute; inset: 0; }
.page .page-links a {
  position: absolute; display: block;
  border-radius: 2px;
}
.page .page-links a:hover { background: rgba(45, 108, 223, 0.14); box-shadow: 0 0 0 2px rgba(45, 108, 223, 0.35); }

.page .page-loader {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(120deg, #f2f2f2, #fafafa 40%, #f2f2f2 60%);
}
.page .page-loader::after {
  content: "";
  width: 26px; height: 26px;
  border: 3px solid #d9d9d9; border-top-color: #8a8a8a;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
.page.loaded .page-loader { display: none; }

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

/* soft page edge + center fold shading over images */
.page::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06);
}
.page.--left::before {
  content: ""; position: absolute; top: 0; bottom: 0; right: 0; width: 7%;
  background: linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,0.12));
  pointer-events: none; z-index: 2;
}
.page.--right::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 7%;
  background: linear-gradient(to left, rgba(0,0,0,0), rgba(0,0,0,0.12));
  pointer-events: none; z-index: 2;
}

/* ---------- Nav arrows ---------- */
.nav-arrow {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 46px; height: 46px; border-radius: 50%;
  border: 0; cursor: pointer;
  background: rgba(20, 24, 32, 0.6);
  color: var(--icon);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s ease, opacity 0.2s ease, transform 0.15s ease;
  z-index: 30;
}
.nav-arrow:hover { background: rgba(216, 35, 42, 0.9); }
.nav-arrow svg { width: 22px; height: 22px; }
.nav-arrow[disabled] { opacity: 0; pointer-events: none; }
#nav-prev { left: 18px; }
#nav-next { right: 18px; }

/* ---------- Loading overlay ---------- */
#loading {
  position: absolute; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  background: radial-gradient(1100px 700px at 50% 30%, var(--stage-bg-1), var(--stage-bg-2) 85%);
  transition: opacity 0.4s ease;
}
#loading.hidden { opacity: 0; pointer-events: none; }
#loading .brand {
  font-size: 15px; font-weight: 800; letter-spacing: 0.24em; text-transform: uppercase;
  color: var(--icon-dim);
}
#loading .track { width: min(300px, 60vw); height: 4px; border-radius: 100px; background: rgba(255,255,255,0.12); overflow: hidden; }
#loading .fill { height: 100%; width: 0%; background: var(--red); border-radius: 100px; transition: width 0.2s ease; }
#loading .pct { font-size: 12.5px; color: var(--icon-dim); font-variant-numeric: tabular-nums; }

#load-error {
  position: absolute; inset: 0; z-index: 51;
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: var(--stage-bg-2); text-align: center; padding: 24px;
}
#load-error.active { display: flex; }
#load-error p { color: var(--icon-dim); font-size: 15px; max-width: 420px; line-height: 1.5; }

/* ---------- Empty state (no source → open local PDF) ---------- */
#empty-state {
  position: absolute; inset: 0; z-index: 52;
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  text-align: center; padding: 24px;
}
#empty-state.active { display: flex; }
#empty-state .icon { font-size: 44px; }
#empty-state h2 { font-size: 19px; letter-spacing: 0.02em; }
#empty-state p { color: var(--icon-dim); font-size: 14.5px; max-width: 380px; line-height: 1.55; }

.btn-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--red); color: #fff; border: 0; cursor: pointer;
  font: 700 14.5px/1 var(--font);
  padding: 12px 24px; border-radius: 100px; margin-top: 6px;
  text-decoration: none;
}
.btn-pill:hover { background: #b01b21; }

/* drag-over hint */
#drop-hint {
  position: absolute; inset: 14px; z-index: 60;
  border: 3px dashed rgba(255,255,255,0.5); border-radius: 18px;
  background: rgba(18, 34, 74, 0.72);
  display: none; align-items: center; justify-content: center;
  font-size: 19px; font-weight: 700; letter-spacing: 0.03em;
  pointer-events: none;
}
body.dragging #drop-hint { display: flex; }

/* ---------- Bottom toolbar ---------- */
#toolbar-zone {
  position: relative; z-index: 45;
  display: flex; flex-direction: column; align-items: center;
  padding: 10px 12px 14px;
  gap: 10px;
}

#toolbar {
  display: flex; align-items: center; gap: 2px;
  background: var(--bar-bg);
  border: 1px solid var(--bar-border);
  border-radius: 100px;
  padding: 6px 10px;
  box-shadow: 0 14px 40px -12px rgba(0, 0, 0, 0.6);
  max-width: calc(100vw - 20px);
}

.tb-btn {
  width: 40px; height: 40px; flex: 0 0 auto;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--icon);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
  position: relative;
}
.tb-btn:hover { background: rgba(255,255,255,0.1); }
.tb-btn.active { color: #ff6b70; }
.tb-btn svg { width: 20px; height: 20px; }
.tb-btn[disabled] { opacity: 0.35; pointer-events: none; }

.tb-sep { width: 1px; height: 22px; background: rgba(255,255,255,0.12); margin: 0 6px; flex: 0 0 auto; }

#slider-box { display: flex; align-items: center; gap: 10px; padding: 0 8px; }

#page-slider {
  -webkit-appearance: none; appearance: none;
  width: clamp(90px, 18vw, 200px); height: 4px;
  background: rgba(255,255,255,0.18); border-radius: 100px;
  outline: none; cursor: pointer;
}
#page-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff; border: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
#page-slider::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff; border: 0;
}

#slider-label {
  font-size: 12.5px; color: var(--icon-dim);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}

/* ---------- Thumbnails drawer ---------- */
#thumbs {
  position: absolute; left: 0; right: 0; bottom: 0;
  transform: translateY(105%);
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.3, 1);
  background: rgba(14, 17, 23, 0.96);
  border-top: 1px solid var(--bar-border);
  z-index: 46;
  padding: 14px 16px 16px;
}
#thumbs.open { transform: translateY(0); }

#thumbs .thumbs-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
#thumbs .thumbs-head span { font-size: 12.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--icon-dim); }
#thumbs .close-thumbs { background: none; border: 0; color: var(--icon-dim); cursor: pointer; padding: 4px; }
#thumbs .close-thumbs:hover { color: #fff; }
#thumbs .close-thumbs svg { width: 18px; height: 18px; }

#thumb-strip {
  display: flex; gap: 12px;
  overflow-x: auto; overscroll-behavior-x: contain;
  padding-bottom: 6px;
  scrollbar-width: thin;
}

.thumb {
  flex: 0 0 auto; cursor: pointer; text-align: center;
  background: none; border: 0; color: var(--icon-dim); font-family: inherit;
  padding: 0;
}
.thumb .thumb-frame {
  height: 108px; aspect-ratio: var(--page-ar, 0.7071);
  background: #2c3140; border-radius: 3px; overflow: hidden;
  outline: 2px solid transparent; outline-offset: 2px;
  transition: outline-color 0.15s ease;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .n { display: block; font-size: 11.5px; margin-top: 6px; }
.thumb:hover .thumb-frame { outline-color: rgba(255,255,255,0.4); }
.thumb.current .thumb-frame { outline-color: var(--red); }
.thumb.current .n { color: #fff; font-weight: 700; }

/* ---------- Zoom overlay ---------- */
#zoom-overlay {
  position: absolute; inset: 0; z-index: 55;
  background: rgba(10, 12, 16, 0.97);
  display: none;
}
#zoom-overlay.open { display: block; }

#zoom-scroller {
  position: absolute; inset: 0;
  overflow: auto;
  cursor: grab;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
}
#zoom-scroller.grabbing { cursor: grabbing; }

#zoom-canvas-box {
  display: flex;
  margin: 0 auto;
  width: max-content; min-height: 100%;
  align-items: center;
}
#zoom-canvas-box img {
  display: block;
  background: #fff;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

#zoom-ui {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 2px;
  background: var(--bar-bg); border: 1px solid var(--bar-border);
  border-radius: 100px; padding: 5px 8px; z-index: 57;
}
#zoom-level { font-size: 12.5px; color: var(--icon-dim); min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; }

#zoom-close {
  position: absolute; top: 14px; right: 14px; z-index: 57;
  width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: rgba(20, 24, 32, 0.8); color: var(--icon); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
#zoom-close:hover { background: var(--red); }
#zoom-close svg { width: 20px; height: 20px; }

#zoom-page-nav-prev, #zoom-page-nav-next { z-index: 57; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 86px; transform: translate(-50%, 16px);
  background: #fff; color: #131722; font-size: 14px; font-weight: 600;
  padding: 11px 20px; border-radius: 100px;
  box-shadow: 0 14px 40px rgba(0,0,0,0.5);
  opacity: 0; pointer-events: none;
  transition: all 0.25s ease; z-index: 200;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  #topbar { gap: 10px; padding: 8px 12px; min-height: 46px; }
  #topbar .back .txt { display: none; }
  #page-indicator { min-width: 0; }
  #issue-title { font-size: 13px; }
  #issue-title .mag { display: none; }
  .tb-btn { width: 38px; height: 38px; }
  #slider-box { display: none; }
  .hide-mobile { display: none; }
  .nav-arrow { width: 38px; height: 38px; }
  #nav-prev { left: 8px; }
  #nav-next { right: 8px; }
  .tb-sep { margin: 0 2px; }
}
