:root {
  --bg: #25201d;
  --paper: #fffaf5;
  --gold: #c7a96b;
  --text: #f8efe5;
  --shadow: rgba(0, 0, 0, 0.45);
  --nav-size: 54px;
  --nav-gap: 24px;
  --book-max: 980px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--text);
  background:
    radial-gradient(circle at center, rgba(255, 244, 224, 0.12), transparent 35%),
    linear-gradient(135deg, #1c1715, var(--bg));
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 16px;
  padding: 18px;
}

.topbar, .controls {
  width: min(1120px, 100%);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar h1 { margin: 0; font-size: clamp(1.35rem, 3vw, 2.2rem); }
.topbar p { margin: 4px 0 0; opacity: .78; }

.pdf-link, button {
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  background: rgba(255,255,255,.1);
  color: var(--text);
  padding: 10px 15px;
  text-decoration: none;
  cursor: pointer;
  backdrop-filter: blur(8px);
  user-select: none;
}

.person-title{
  font-size:medium!important;
}
.smaller{
  font-size: smaller;
}

.pdf-link:hover, button:hover:not(:disabled) { background: rgba(255,255,255,.18); }
button:disabled { opacity: .35; cursor: not-allowed; }

.viewer {
  width: min(1320px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: var(--nav-size) minmax(0, 1fr) var(--nav-size);
  gap: var(--nav-gap);
  align-items: center;
}

.book-wrap {
  width: 100%;
  min-height: 70vh;
  display: flex;
  justify-content: center;
  align-items: center;
  perspective: 2400px;
  overflow: visible;
}

.book {
  position: relative;
  width: min(100%, var(--book-max), 104vh);
  aspect-ratio: 1.5;
  transform-style: preserve-3d;
  filter: drop-shadow(0 22px 28px var(--shadow));
  transition: width .25s ease;
}

.book.zoomed { width: min(100%, 1160px, 116vh); }

.page,
.turn-face {
  background: var(--paper);
  overflow: hidden;
  border: 1px solid rgba(199,169,107,.55);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.28);
}

.page {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
}

.page.left { left: 0; border-radius: 13px 8px 8px 13px; }
.page.right { right: 0; border-radius: 8px 13px 13px 8px; }
.page.blank { background: linear-gradient(90deg, #f3eadf, #fffaf5 86%, #e2d1b5); }

.page img,
.turn-face img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #fff;
}

.page::after,
.turn-face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(0,0,0,.18), transparent 9%, transparent 90%, rgba(0,0,0,.12));
  mix-blend-mode: multiply;
}

.book::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 22px;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 20;
  background: linear-gradient(90deg, rgba(0,0,0,.16), rgba(255,255,255,.2), rgba(0,0,0,.18));
  opacity: .8;
  border-radius: 999px;
}

.turning-page {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  z-index: 40;
  transform-style: preserve-3d;
  transition: transform .85s cubic-bezier(.2,.65,.18,1);
}

.turning-page.right {
  left: 50%;
  transform-origin: left center;
}

.turning-page.left {
  left: 0;
  transform-origin: right center;
}

.turning-page.right.flipped { transform: rotateY(-180deg); }
.turning-page.left.flipped { transform: rotateY(180deg); }

.turn-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform-style: preserve-3d;
}

.turn-front { transform: rotateY(0deg); }
.turn-back { transform: rotateY(180deg); }

.turning-page.right .turn-front { border-radius: 8px 13px 13px 8px; }
.turning-page.right .turn-back { border-radius: 13px 8px 8px 13px; }
.turning-page.left .turn-front { border-radius: 13px 8px 8px 13px; }
.turning-page.left .turn-back { border-radius: 8px 13px 13px 8px; }

/* Keeps the page content itself readable while the sheet flips. */
.turn-face img { transform: translateZ(0.1px); }

.nav {
  width: var(--nav-size);
  height: var(--nav-size);
  font-size: 34px;
  line-height: 1;
  display: grid;
  place-items: center;
  padding: 0;
  z-index: 80;
}

.controls { justify-content: center; flex-wrap: wrap; }

#pageInfo {
  min-width: 170px;
  text-align: center;
  font-size: 1.05rem;
  color: #fff7ea;
}

button, .nav, .pdf-link { touch-action: manipulation; }

@media (max-width: 760px) {
  :root { --nav-size: 48px; --nav-gap: 0px; }

  html, body { height: 100%; }

  body { overflow-x: hidden; }

  .app {
    min-height: 100svh;
    padding: 8px;
    gap: 8px;
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .topbar h1 { font-size: clamp(1.05rem, 5vw, 1.35rem); }
  .topbar p { display: none; }
  .pdf-link { padding: 8px 12px; }

  .viewer {
    position: relative;
    width: 100%;
    min-height: 0;
    grid-template-columns: 1fr;
    gap: 0;
    align-items: stretch;
  }

  .book-wrap {
    min-height: 0;
    height: 100%;
    align-items: center;
    justify-content: center;
    overflow: visible;
  }

  .book,
  .book.zoomed {
    /* Fill the phone screen as much as possible while keeping the whole page visible. */
    width: min(calc(100vw - 16px), calc((100svh - 150px) * 0.707));
    max-height: calc(100svh - 150px);
    aspect-ratio: 0.707;
  }

  .book.mobile::after { display: none; }

  .book.mobile .page.single {
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 13px;
  }

  .book.mobile .page.single::after {
    background: linear-gradient(90deg, rgba(0,0,0,.1), transparent 14%, transparent 86%, rgba(0,0,0,.1));
  }

  .nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: var(--nav-size);
    height: var(--nav-size);
    min-width: var(--nav-size);
    min-height: var(--nav-size);
    font-size: 30px;
    z-index: 120;
    background: rgba(0,0,0,.32);
  }

  #prevBtn { left: 4px; }
  #nextBtn { right: 4px; }

  .controls {
    gap: 7px;
    justify-content: center;
    padding-bottom: max(2px, env(safe-area-inset-bottom));
  }

  .controls button,
  .pdf-link {
    min-height: 44px;
    padding: 9px 12px;
    font-size: .95rem;
  }

  #pageInfo {
    order: -1;
    flex-basis: 100%;
    min-width: 100%;
    font-size: 1rem;
    margin-bottom: 0;
  }
}

@media (max-width: 420px) {
  :root { --nav-size: 44px; }
  .app { padding: 6px; gap: 6px; }
  .controls { gap: 6px; }
  .controls button { padding: 8px 10px; }
  .book, .book.zoomed {
    width: min(calc(100vw - 12px), calc((100svh - 138px) * 0.707));
    max-height: calc(100svh - 138px);
  }
  #zoomBtn{
    display:none;
  }
}
