:root {
  --paper: #ffffff;
  --accent: #c2185b;
  --accent-2: #ff5f8f;
  --book-w: min(1200px, 88vw);
  --book-h: min(735px, 75vh);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  color: #fff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 14%, rgba(194, 24, 91, .25), transparent 30%),
    radial-gradient(circle at 85% 82%, rgba(47, 201, 143, .15), transparent 32%),
    linear-gradient(135deg, #111827 0%, #192237 48%, #0d1320 100%);
}
button, a { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ambient {
  position: fixed;
  border-radius: 50%;
  filter: blur(70px);
  pointer-events: none;
  opacity: .28;
}
.ambient--one { width: 330px; height: 330px; background: #c2185b; left: -100px; top: 15%; }
.ambient--two { width: 360px; height: 360px; background: #16b981; right: -130px; bottom: 2%; }

.topbar {
  height: 85px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 6px clamp(18px, 4vw, 58px);
  border-bottom: 1px solid rgba(255,255,255,.08);
  background: rgba(10,16,28,.62);
  backdrop-filter: blur(18px);
  position: relative;
  z-index: 50;
}
.brand {
  display: inline-flex;
  align-items: center;
  color: #fff;
  text-decoration: none;
  width: max-content;
  max-width: 230px;
  height: 78px;
}
.brand img {
  display: block;
  width: auto;
  height: 52px;
  max-width: 100%;
  object-fit: contain;
}
.topbar__actions { display: flex; gap: 9px; }
.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px;
  color: #fff;
  background: rgba(255,255,255,.06);
  cursor: pointer;
  transition: .25s ease;
}
.icon-btn:hover { background: rgba(255,255,255,.13); transform: translateY(-2px); }
.icon-btn--dark { color: #101827; border-color: #e5e7eb; background: #fff; }

.reader {
  height: calc(100vh - 92px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 20px 14px;
  position: relative;
  z-index: 2;
}
.book-stage {
  position: relative;
  width: min(1260px, 96vw);
  height: var(--book-h);
  display: grid;
  place-items: center;
  perspective: 2400px;
}
.book {
  position: relative;
  width: var(--book-w);
  height: var(--book-h);
  transform-style: preserve-3d;
  filter: drop-shadow(0 26px 40px rgba(0,0,0,.22));
}
.book::before,
.book::after {
  content: "";
  position: absolute;
  top: 12px;
  bottom: 12px;
  width: 10px;
  background: linear-gradient(90deg, #d7d0c5, #f4efe7);
  z-index: -1;
}
.book::before { left: -8px; border-radius: 8px 0 0 8px; }
.book::after { right: -8px; border-radius: 0 8px 8px 0; }
.book__shadow {
  position: absolute;
  z-index: -2;
  left: 5%;
  right: 5%;
  bottom: -26px;
  height: 45px;
  border-radius: 50%;
  background: rgba(0,0,0,.45);
  filter: blur(22px);
}
.book__spine {
  position: absolute;
  z-index: 25;
  left: calc(50% - 12px);
  top: 0;
  bottom: 0;
  width: 24px;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(0,0,0,.14), rgba(255,255,255,.16) 42%, rgba(0,0,0,.22));
  box-shadow: inset 0 0 18px rgba(0,0,0,.2);
}

.book-page,
.turn-sheet {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  background: var(--paper);
  overflow: hidden;
  color: #101827;
}
.book-page--left {
  left: 0;
  border-radius: var(--radius) 2px 2px var(--radius);
  box-shadow: inset -20px 0 24px -25px rgba(0,0,0,.5);
}
.book-page--right {
  right: 0;
  border-radius: 2px var(--radius) var(--radius) 2px;
  box-shadow: inset 20px 0 24px -25px rgba(0,0,0,.5);
}
.book-page::after,
.turn-face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(0,0,0,.025), transparent 10%, transparent 90%, rgba(0,0,0,.045));
  mix-blend-mode: multiply;
}

.turn-sheet {
  right: 0;
  z-index: 30;
  overflow: visible;
  transform-style: preserve-3d;
  transform-origin: left center;
  pointer-events: none;
  visibility: hidden;
}
.turn-sheet--prev { left: 0; right: auto; transform-origin: right center; }
.turn-sheet.is-visible { visibility: visible; }
.turn-sheet--next.is-turning { animation: turnNext .82s cubic-bezier(.55,.02,.25,1) forwards; }
.turn-sheet--prev.is-turning { animation: turnPrev .82s cubic-bezier(.55,.02,.25,1) forwards; }
.turn-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  overflow: hidden;
  background: var(--paper);
  color: #101827;
}
.turn-face--front {
  border-radius: 2px var(--radius) var(--radius) 2px;
  box-shadow: inset 18px 0 24px -24px rgba(0,0,0,.7), 12px 4px 28px rgba(0,0,0,.22);
}
.turn-face--back {
  transform: rotateY(180deg);
  border-radius: var(--radius) 2px 2px var(--radius);
  box-shadow: inset -18px 0 24px -24px rgba(0,0,0,.7), -12px 4px 28px rgba(0,0,0,.22);
}
.turn-sheet--prev .turn-face--front { border-radius: var(--radius) 2px 2px var(--radius); }
.turn-sheet--prev .turn-face--back { border-radius: 2px var(--radius) var(--radius) 2px; }
@keyframes turnNext {
  0% { transform: rotateY(0); }
  48% { box-shadow: -24px 0 34px rgba(0,0,0,.24); }
  100% { transform: rotateY(-180deg); }
}
@keyframes turnPrev {
  0% { transform: rotateY(0); }
  48% { box-shadow: 24px 0 34px rgba(0,0,0,.24); }
  100% { transform: rotateY(180deg); }
}

.page-inner,
.template-page,
.template-scroll { width: 100%; height: 100%; }
.template-page { position: relative; overflow: hidden; background: #f4f4f4; }
.template-scroll {
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(194,24,91,.55) rgba(0,0,0,.06);
  -webkit-overflow-scrolling: touch;
}
.template-scroll::-webkit-scrollbar { width: 7px; }
.template-scroll::-webkit-scrollbar-track { background: rgba(0,0,0,.05); }
.template-scroll::-webkit-scrollbar-thumb { background: rgba(194,24,91,.55); border-radius: 20px; }
.template-scroll img {
  display: block;
  width: 100%;
  height: auto;
  min-height: 100%;
  object-fit: cover;
  object-position: top center;
  user-select: none;
}

.edge-nav {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 7%;
  min-width: 42px;
  z-index: 45;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.edge-nav--left { left: 0; }
.edge-nav--right { right: 0; }

.toolbar {
  width: min(760px, 92vw);
  display: grid;
  grid-template-columns: 1fr minmax(150px, 260px) 1fr;
  align-items: center;
  gap: 18px;
  margin-top: 20px;
}
.nav-btn {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 126px;
  justify-content: center;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 999px;
  padding: 11px 18px;
  color: #fff;
  background: rgba(255,255,255,.07);
  cursor: pointer;
  transition: .25s ease;
}
.nav-btn--next { justify-self: end; }
.nav-btn:hover:not(:disabled) { background: rgba(255,255,255,.15); transform: translateY(-2px); }
.nav-btn:disabled { opacity: .32; cursor: not-allowed; }
.page-status { text-align: center; }
.page-status strong { display: block; font-size: 13px; letter-spacing: .08em; }
.progress { height: 4px; margin-top: 9px; overflow: hidden; border-radius: 20px; background: rgba(255,255,255,.12); }
.progress span { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .35s ease; }

.drawer { position: fixed; inset: 0; z-index: 100; pointer-events: none; }
.drawer.is-open { pointer-events: auto; }
.drawer__backdrop { position: absolute; inset: 0; opacity: 0; background: rgba(5,9,16,.72); backdrop-filter: blur(7px); transition: opacity .3s ease; }
.drawer__panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(520px, 92vw);
  height: 100%;
  padding: 24px;
  color: #101827;
  background: #f8fafc;
  transform: translateX(100%);
  transition: transform .34s ease;
  overflow-y: auto;
  box-shadow: -30px 0 80px rgba(0,0,0,.28);
}
.drawer.is-open .drawer__backdrop { opacity: 1; }
.drawer.is-open .drawer__panel { transform: translateX(0); }
.drawer__header { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.drawer__header div { display: flex; flex-direction: column; }
.drawer__header strong { font-size: 21px; }
.drawer__header span { color: #667085; font-size: 13px; margin-top: 3px; }
.thumb-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 15px; }
.thumb {
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 8px;
  text-align: left;
  color: #101827;
  background: #fff;
  cursor: pointer;
  transition: .2s ease;
}
.thumb:hover { transform: translateY(-3px); box-shadow: 0 12px 30px rgba(16,24,39,.12); }
.thumb.is-active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(194,24,91,.12); }
.thumb__visual { height: 180px; overflow: hidden; border-radius: 8px; background: #eef1f5; }
.thumb__visual img { display: block; width: 100%; height: auto; min-height: 100%; object-fit: cover; object-position: top; }
.thumb > span { display: block; padding: 9px 3px 2px; font-size: 12px; font-weight: 700; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 140;
  transform: translate(-50%, 18px);
  padding: 10px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  background: rgba(8,12,20,.9);
  color: #fff;
  font-size: 13px;
  transition: .25s ease;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  :root { --book-w: min(940px, 94vw); --book-h: min(680px, 73vh); }
  .topbar { padding-inline: 20px; }
  .brand { max-width: 190px; }
  .brand img { height: 64px; }
}

@media (max-width: 620px) {
  :root { --book-w: min(430px, 92vw); --book-h: min(690px, 72vh); --radius: 14px; }
  .topbar { height: 82px; padding: 5px 14px; }
  .brand { height: 70px; max-width: 150px; }
  .brand img { height: 61px; }
  .topbar__actions { gap: 7px; }
  .icon-btn { width: 40px; height: 40px; }
  .reader { height: calc(100vh - 82px); padding: 12px 10px 9px; }
  .book-stage { width: 100%; }
  .book-page,
  .turn-sheet { width: 100%; }
  .book-page--left { display: none; }
  .book-page--right { left: 0; right: auto; border-radius: var(--radius); }
  .book__spine,
  .book::before,
  .book::after { display: none; }
  .turn-sheet,
  .turn-sheet--prev { left: 0; right: auto; transform-origin: left center; }
  .turn-sheet--prev { transform-origin: right center; }
  .turn-face--front,
  .turn-face--back { border-radius: var(--radius); }
  .toolbar { grid-template-columns: auto 1fr auto; gap: 10px; width: 94vw; margin-top: 14px; }
  .nav-btn { min-width: 44px; width: 44px; height: 44px; padding: 0; border-radius: 50%; }
  .nav-btn span { display: none; }
  .page-status strong { font-size: 12px; }
  .edge-nav { width: 11%; min-width: 32px; }
  .thumb-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .thumb__visual { height: 155px; }
}

@media (max-height: 760px) and (min-width: 621px) {
  :root { --book-h: 62vh; }
  .topbar { height: 82px; }
  .brand img { height: 62px; }
  .reader { height: calc(100vh - 82px); }
  .toolbar { margin-top: 14px; }
}
