:root {
  --bg: #15171c;
  --bg2: #1d2027;
  --panel: rgba(28, 31, 38, .78);
  --line: rgba(255, 255, 255, .09);
  --text: #f2f3f5;
  --muted: #9aa1ad;
  --red: #e5202e;
  --purple: #8e3a96;
  --blue: #00a2e2;
  --brand: linear-gradient(90deg, var(--red), var(--purple) 50%, var(--blue));
  --ease: cubic-bezier(.22, 1, .36, 1);
  --top: 64px;
  --bottom: 56px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Poppins', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 50% 45%, #262a33 0%, var(--bg) 70%) fixed,
    var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- loader ---------- */
.loader {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-content: center; justify-items: center; gap: 28px;
  background: var(--bg);
  transition: opacity .6s var(--ease), visibility .6s;
}
body:not(.is-loading) .loader { opacity: 0; visibility: hidden; }
.loader-bolt img { width: 84px; animation: bolt 1.6s var(--ease) infinite; filter: drop-shadow(0 0 18px rgba(0, 162, 226, .35)); }
.loader-bar { width: 160px; height: 3px; border-radius: 3px; background: var(--line); overflow: hidden; }
.loader-bar span { display: block; height: 100%; width: 0; background: var(--brand); transition: width .3s var(--ease); }
@keyframes bolt {
  0%, 100% { transform: translateY(0) scale(1); opacity: 1; }
  50% { transform: translateY(-6px) scale(1.05); opacity: .75; }
}

/* ---------- top bar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  height: var(--top);
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 18px;
  background: var(--panel);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--line);
  animation: slideDown .7s var(--ease) both .15s;
}
.topbar::after { content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--brand); opacity: .85; }
.brand { flex: none; display: flex; align-items: center; background: #fff; border-radius: 10px; padding: 5px 10px; transition: transform .3s var(--ease); }
.brand:hover { transform: translateY(-1px); }
.brand img { display: block; height: 26px; width: auto; }
.title { min-width: 0; flex: 1; }
.title h1 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title p { margin: 1px 0 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tools { display: flex; gap: 6px; flex: none; }
.tool {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; min-width: 40px; padding: 0 9px;
  border: 1px solid transparent; border-radius: 10px; background: transparent; cursor: pointer;
  color: var(--text); text-decoration: none; font-size: 13px; font-weight: 500;
  transition: background .25s var(--ease), border-color .25s, transform .25s var(--ease);
}
.tool:hover { background: rgba(255, 255, 255, .08); border-color: var(--line); }
.tool:active { transform: scale(.94); }
.tool-cta { background: var(--brand); border: 0; padding: 0 14px; }
.tool-cta:hover { background: var(--brand); filter: brightness(1.12); box-shadow: 0 6px 20px rgba(142, 58, 150, .35); }

@keyframes slideDown { from { transform: translateY(-100%); opacity: 0; } }
@keyframes slideUp { from { transform: translateY(100%); opacity: 0; } }

/* ---------- stage / book ---------- */
.stage {
  position: fixed; left: 0; right: 0; top: var(--top); bottom: var(--bottom);
  display: flex; align-items: center; justify-content: center;
  padding: 22px 70px;
}
.book-wrap {
  position: relative; width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  transition: transform .5s var(--ease);
}
body.is-loading .book { opacity: 0; }
body.ready .book { animation: bookIn 1s var(--ease) both; }
@keyframes bookIn {
  from { opacity: 0; transform: translateY(30px) scale(.94) rotateX(8deg); }
  to { opacity: 1; transform: none; }
}
/* closed on the cover: keep it centred instead of hugging the right half */
.book-wrap.at-cover { transform: translateX(calc(var(--pw, 0px) * -.5)); }
.book-wrap.at-end { transform: translateX(calc(var(--pw, 0px) * .5)); }
.book { margin: 0 auto; }
.book .stf__parent { margin: 0 auto; }

.page { background: #fff; overflow: hidden; }
.page-in { position: relative; width: 100%; height: 100%; background: #f1f2f4; }
.page-in::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, .7) 50%, transparent 70%) #eceef1;
  background-size: 250% 100%;
  animation: shimmer 1.4s linear infinite;
  transition: opacity .4s;
}
.page-in.loaded::before { opacity: 0; animation: none; }
.page-in img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .45s var(--ease); user-select: none; -webkit-user-drag: none; pointer-events: none; }
.page-in.loaded img { opacity: 1; }
/* soft spine shading */
.page-in::after { content: ''; position: absolute; top: 0; bottom: 0; width: 8%; pointer-events: none; }
.page.--left .page-in::after { right: 0; background: linear-gradient(to left, rgba(0, 0, 0, .14), transparent); }
.page.--right .page-in::after { left: 0; background: linear-gradient(to right, rgba(0, 0, 0, .14), transparent); }
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -100% 0; } }

.stf__block { filter: drop-shadow(0 22px 40px rgba(0, 0, 0, .55)); }

.nav {
  position: absolute; top: 50%; z-index: 5;
  width: 50px; height: 50px; margin-top: -25px;
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 50%;
  background: var(--panel); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  cursor: pointer; color: var(--text);
  transition: transform .35s var(--ease), opacity .35s, background .25s;
}
.nav:hover { background: rgba(60, 64, 74, .9); transform: scale(1.08); }
.nav:active { transform: scale(.95); }
.nav[disabled] { opacity: 0; pointer-events: none; }
.nav-prev { left: 12px; }
.nav-next { right: 12px; }
.nav-next.nudge { animation: nudge 1.6s var(--ease) 3 .8s; }
@keyframes nudge { 0%, 100% { transform: translateX(0); } 40% { transform: translateX(7px); } }

/* ---------- bottom bar ---------- */
.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: var(--bottom);
  padding: 0 max(20px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(20px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 18px;
  animation: slideUp .7s var(--ease) both .25s;
}
.counter { flex: none; font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--muted); }
.counter #cur { color: var(--text); }
.counter .sep { margin: 0 5px; opacity: .5; }
#scrub {
  flex: 1; -webkit-appearance: none; appearance: none; height: 4px; border-radius: 4px; cursor: pointer;
  background: linear-gradient(90deg, var(--red), var(--purple), var(--blue)) 0 0 / var(--fill, 0%) 100% no-repeat, rgba(255, 255, 255, .12);
  max-width: 900px; margin: 0 auto;
}
#scrub::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .5); transition: transform .2s var(--ease); }
#scrub::-webkit-slider-thumb:hover { transform: scale(1.25); }
#scrub::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .5); }

/* ---------- hint ---------- */
.hint {
  position: fixed; left: 50%; bottom: calc(var(--bottom) + 18px); z-index: 15;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  padding: 9px 16px; border-radius: 999px; font-size: 12.5px;
  background: var(--panel); border: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: opacity .5s var(--ease), transform .5s var(--ease);
  white-space: nowrap;
}
.hint.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- drawer (thumbnails) ---------- */
.drawer {
  position: fixed; inset: 0; z-index: 30;
  display: flex; flex-direction: column;
  background: rgba(16, 18, 22, .9);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  opacity: 0; visibility: hidden;
  transition: opacity .4s var(--ease), visibility .4s;
}
.drawer.open { opacity: 1; visibility: visible; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.grid {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 22px 18px;
  padding: 24px max(20px, env(safe-area-inset-right)) 40px max(20px, env(safe-area-inset-left));
  align-content: start;
}
.thumb {
  display: block; padding: 0; border: 0; background: none; cursor: pointer; text-align: center;
  opacity: 0; transform: translateY(14px);
  transition: opacity .5s var(--ease), transform .5s var(--ease);
  transition-delay: calc(min(var(--i), 24) * 18ms);
}
.drawer.open .thumb { opacity: 1; transform: none; }
.thumb-img { position: relative; border-radius: 4px; overflow: hidden; background: #2a2e36; box-shadow: 0 6px 18px rgba(0, 0, 0, .4); transition: transform .3s var(--ease), box-shadow .3s; }
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.thumb:hover .thumb-img { transform: translateY(-4px) scale(1.03); box-shadow: 0 14px 28px rgba(0, 0, 0, .5); }
.thumb.current .thumb-img { outline: 2px solid var(--blue); outline-offset: 3px; }
.thumb span { display: block; margin-top: 8px; font-size: 12px; color: var(--muted); }

/* ---------- zoom ---------- */
.zoom {
  position: fixed; inset: 0; z-index: 40; background: #0e0f12;
  opacity: 0; visibility: hidden; transition: opacity .35s var(--ease), visibility .35s;
}
.zoom.open { opacity: 1; visibility: visible; }
.zoom-view { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab; }
.zoom-view.dragging { cursor: grabbing; }
.zoom-view img {
  position: absolute; left: 0; top: 0; transform-origin: 0 0; max-width: none;
  user-select: none; -webkit-user-drag: none; box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
  background: #fff;
}
.zoom-view img.anim { transition: transform .35s var(--ease); }
.zoom-bar {
  position: absolute; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 4px; padding: 6px;
  border-radius: 14px; background: var(--panel); border: 1px solid var(--line);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.zoom-page { min-width: 74px; text-align: center; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; top: calc(var(--top) + 16px); z-index: 60;
  transform: translate(-50%, -10px); opacity: 0; pointer-events: none;
  padding: 10px 18px; border-radius: 10px; font-size: 13px;
  background: #fff; color: #15171c; box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
  transition: opacity .35s var(--ease), transform .35s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.noscript { position: fixed; inset: auto 0 50% 0; text-align: center; }
.noscript a { color: var(--blue); }

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  :root { --top: 58px; --bottom: 52px; }
  .topbar { gap: 10px; }
  .brand { padding: 4px 7px; border-radius: 8px; }
  .brand img { height: 20px; }
  .title h1 { font-size: 13.5px; }
  .title p { display: none; }
  .tools { gap: 2px; }
  .tool { min-width: 38px; height: 38px; padding: 0 7px; }
  .tool-cta { padding: 0 10px; }
  .hide-sm { display: none; }
  .stage { padding: 12px 10px; }
  .nav { display: none; }
  .book-wrap.at-cover, .book-wrap.at-end { transform: none; }
}
@media (max-width: 380px) {
  .brand { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
