:root {
  --ink: #f3f8ff;
  --muted: #9fb2c7;
  --navy: #07182d;
  --navy-2: #0b2442;
  --cyan: #21b8f3;
  --line: rgba(255, 255, 255, .14);
  --page-ratio: 1.4084;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 12%, rgba(20, 105, 171, .24), transparent 36rem),
    linear-gradient(145deg, #030b16 0%, var(--navy) 54%, #061221 100%);
  font-family: "Gill Sans", "Trebuchet MS", sans-serif;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .18;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='90' viewBox='0 0 90 90'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.22'/%3E%3C/svg%3E");
}

button, a { font: inherit; }
button { color: inherit; }

.viewer {
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto 1fr;
  position: relative;
  isolation: isolate;
}

.topbar {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 20px clamp(18px, 4vw, 58px) 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.identity { min-width: 0; }
.eyebrow {
  color: var(--cyan);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .28em;
}

h1 {
  margin: 3px 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(20px, 3vw, 31px);
  font-weight: 500;
  letter-spacing: -.02em;
}

.top-actions { display: flex; gap: 8px; }
.icon-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255, 255, 255, .055);
  text-decoration: none;
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: border-color .2s ease, background .2s ease, transform .2s ease;
}
.icon-button:hover { border-color: rgba(33, 184, 243, .65); background: rgba(33, 184, 243, .11); transform: translateY(-1px); }
.icon-button span { color: var(--cyan); font-size: 18px; }
.icon-button b { font-size: 12px; letter-spacing: .04em; }

.reading-room {
  min-height: 0;
  padding: 4px clamp(14px, 3vw, 42px) 18px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  place-items: center;
  position: relative;
}

.book-area {
  width: 100%;
  min-height: 0;
  display: grid;
  place-items: center;
}

.book-shell {
  width: min(92vw, calc(73svh * var(--page-ratio)));
  aspect-ratio: var(--page-ratio);
  position: relative;
  perspective: 2400px;
  filter: drop-shadow(0 26px 28px rgba(0, 0, 0, .42));
  animation: reveal .7s cubic-bezier(.2, .75, .25, 1) both;
}

.book {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
}

.book::before {
  content: "";
  position: absolute;
  z-index: 30;
  left: 50%;
  top: .6%;
  bottom: .6%;
  width: 1px;
  background: rgba(255,255,255,.3);
  box-shadow: 0 0 16px 4px rgba(0,0,0,.3);
  pointer-events: none;
}

.book::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 5px;
  background: #e6ebf0;
  clip-path: polygon(0 0, 50% 0, 50% 100%, 0 100%);
  box-shadow: inset -18px 0 24px rgba(22,35,52,.11);
  z-index: 0;
}

.sheet {
  width: 50%;
  height: 100%;
  position: absolute;
  left: 50%;
  top: 0;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform .82s cubic-bezier(.19, .76, .24, 1);
  will-change: transform;
}
.sheet.flipped { transform: rotateY(-180deg); }

.page-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #fff;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  cursor: zoom-in;
  box-shadow: inset 0 0 24px rgba(13, 34, 56, .07);
}
.page-face.front { border-radius: 0 5px 5px 0; }
.page-face.back { transform: rotateY(180deg); border-radius: 5px 0 0 5px; }
.page-face img { width: 100%; height: 100%; display: block; object-fit: cover; }
.page-face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(to var(--shade-direction, left), rgba(3, 13, 25, .18), transparent 8%, transparent 88%, rgba(3, 13, 25, .05));
  opacity: .55;
}
.page-face.back { --shade-direction: right; }

.page-zone {
  position: absolute;
  z-index: 50;
  top: 0;
  bottom: 0;
  width: 9%;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.page-zone--previous { left: 0; cursor: w-resize; }
.page-zone--next { right: 0; cursor: e-resize; }

.controls {
  width: min(780px, 92vw);
  padding-top: 16px;
  display: grid;
  grid-template-columns: 130px 1fr 130px;
  align-items: center;
  gap: 18px;
}

.nav-button {
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255, 255, 255, .055);
  font-weight: 700;
  letter-spacing: .02em;
  cursor: pointer;
  transition: transform .18s ease, opacity .18s ease, background .18s ease;
}
.nav-button:hover:not(:disabled) { transform: translateY(-2px); background: rgba(255,255,255,.1); }
.nav-button--primary { color: #04111e; background: var(--cyan); border-color: transparent; }
.nav-button--primary:hover:not(:disabled) { background: #52cafa; }
.nav-button:disabled { opacity: .28; cursor: not-allowed; }
.nav-button span { font-size: 18px; }

.status { text-align: center; }
.status > span { display: block; margin-top: 7px; color: var(--muted); font-size: 12px; letter-spacing: .08em; }
.progress { display: flex; justify-content: center; gap: 7px; }
.progress button {
  width: 23px;
  height: 3px;
  padding: 0;
  border: 0;
  border-radius: 99px;
  background: rgba(255,255,255,.23);
  cursor: pointer;
  transition: width .2s ease, background .2s ease;
}
.progress button.active { width: 42px; background: var(--cyan); }

.hint { margin: 10px 0 0; color: rgba(210,224,239,.54); font-size: 11px; letter-spacing: .04em; }

.thumbnail-drawer {
  position: fixed;
  z-index: 100;
  left: 18px;
  top: 82px;
  bottom: 22px;
  width: min(360px, calc(100vw - 36px));
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(4, 16, 31, .94);
  box-shadow: 0 22px 80px rgba(0,0,0,.55);
  backdrop-filter: blur(18px);
  transform: translateX(calc(-100% - 40px));
  transition: transform .35s cubic-bezier(.2,.78,.2,1);
  overflow: auto;
}
.thumbnail-drawer.open { transform: translateX(0); }
.drawer-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 13px; font-family: Georgia, serif; font-size: 19px; }
.drawer-heading button { border: 0; background: transparent; color: var(--muted); font-size: 28px; cursor: pointer; }
.thumbnail-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 11px; }
.thumbnail {
  padding: 7px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--muted);
  background: rgba(255,255,255,.05);
  cursor: pointer;
}
.thumbnail:hover, .thumbnail.active { border-color: var(--cyan); color: var(--ink); }
.thumbnail img { width: 100%; display: block; border-radius: 4px; }
.thumbnail span { display: block; padding: 7px 2px 1px; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.mobile-page { display: none; }

.lightbox {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  padding: 28px;
  border: 0;
  background: rgba(2, 8, 16, .92);
  overflow: auto;
}
.lightbox::backdrop { background: rgba(0,0,0,.75); }
.lightbox img { display: block; width: min(92vw, 850px); height: auto; margin: 0 auto; box-shadow: 0 18px 80px #000; }
.lightbox-close { position: fixed; z-index: 2; top: 18px; right: 22px; width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 50%; color: #fff; background: rgba(4,16,31,.8); font-size: 27px; cursor: pointer; }

@keyframes reveal { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes mobile-in { from { opacity: .25; transform: translateX(18px) rotateY(-4deg); } to { opacity: 1; transform: none; } }

@media (max-width: 720px) {
  .topbar { padding-top: 13px; }
  .identity h1 { font-size: 18px; }
  .eyebrow { font-size: 8px; }
  .icon-button { min-width: 41px; padding: 0 11px; justify-content: center; }
  .icon-button b { display: none; }
  .book-shell { display: none; }
  .book-area { align-items: start; }
  .mobile-page {
    display: block;
    position: relative;
    height: min(68svh, calc(88vw / .704));
    aspect-ratio: .704;
    border-radius: 5px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 22px 42px rgba(0,0,0,.48);
    cursor: zoom-in;
  }
  .mobile-page.animate { animation: mobile-in .34s ease both; }
  .mobile-page img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .mobile-page-number { position: absolute; right: 9px; bottom: 8px; padding: 4px 7px; border-radius: 99px; color: #fff; background: rgba(4,16,31,.72); font-size: 10px; }
  .reading-room { padding-bottom: 14px; }
  .controls { grid-template-columns: 102px 1fr 102px; gap: 8px; padding-top: 13px; }
  .nav-button { font-size: 12px; height: 40px; }
  .hint { display: none; }
  .progress button { width: 14px; }
  .progress button.active { width: 24px; }
}

@media (max-height: 700px) and (min-width: 721px) {
  .book-shell { width: min(82vw, calc(66svh * var(--page-ratio))); }
  .topbar { padding-top: 10px; }
  .controls { padding-top: 10px; }
  .hint { display: none; }
}

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