:root {
  --bg: #101114;
  --surface: #fffaf0;
  --surface-strong: #fffdf7;
  --ink: #171717;
  --muted: #6d6258;
  --line: rgba(223, 207, 177, 0.42);
  --accent: #8f1238;
  --accent-strong: #6d0b28;
  --gold: #c8a661;
  --gold-strong: #8d6a2f;
  --panel: rgba(255, 250, 240, 0.88);
  --shadow: 0 34px 90px rgba(0, 0, 0, 0.42);
  --soft-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
  --book-pad: clamp(9px, 1vw, 14px);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -10%, rgba(255, 239, 190, 0.28), transparent 34rem),
    radial-gradient(circle at 8% 16%, rgba(143, 18, 56, 0.22), transparent 26rem),
    radial-gradient(circle at 92% 30%, rgba(200, 166, 97, 0.18), transparent 28rem),
    linear-gradient(135deg, #141418 0%, #22171b 46%, #111114 100%),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.024) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.95), transparent 86%);
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 22px clamp(12px, 3vw, 38px) 26px;
}

.topbar {
  position: relative;
  z-index: 20;
  width: min(100%, 1360px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  margin: 0 auto 18px;
  padding: 18px 20px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 18px;
  background: rgba(255, 250, 240, 0.1);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(18px);
}

.brand {
  min-width: 0;
}

.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: #fff9ed;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.45rem, 2.8vw, 2.55rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.brand p {
  max-width: 540px;
  margin: 8px 0 0;
  color: rgba(255, 250, 240, 0.72);
  font-size: 0.95rem;
  line-height: 1.45;
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.download-link,
.fullscreen-button,
.icon-button,
.edge-nav,
.thumb-button {
  cursor: pointer;
}

.download-link,
.fullscreen-button,
.icon-button,
.edge-nav {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 250, 240, 0.2);
  color: #fff9ed;
  background: rgba(255, 250, 240, 0.11);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(12px);
  transition: color 180ms ease, background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.download-link {
  gap: 8px;
  padding: 0 16px;
  border-radius: 999px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.9rem;
  font-weight: 800;
  text-decoration: none;
}

.fullscreen-button {
  gap: 8px;
  padding: 0 16px;
  border-radius: 999px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.9rem;
  font-weight: 800;
}

.icon-button,
.edge-nav {
  border-radius: 999px;
}

.download-link:hover,
.fullscreen-button:hover,
.icon-button:hover,
.edge-nav:hover {
  border-color: rgba(200, 166, 97, 0.58);
  color: #ffffff;
  background: rgba(143, 18, 56, 0.46);
  box-shadow: 0 16px 34px rgba(143, 18, 56, 0.22);
}

.download-link:focus-visible,
.fullscreen-button:focus-visible,
.icon-button:focus-visible,
.edge-nav:focus-visible,
.thumb-button:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.45);
  outline-offset: 3px;
}

.icon-button:disabled,
.edge-nav:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  box-shadow: none;
}

.reader {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0;
}

.book-frame {
  position: relative;
  overflow: hidden;
  padding: clamp(14px, 2.5vw, 30px);
  border: 1px solid rgba(255, 250, 240, 0.14);
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(255, 250, 240, 0.12), rgba(255, 250, 240, 0.035)),
    rgba(255, 255, 255, 0.035);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.35);
}

.fullscreen-exit {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 80;
  min-width: 44px;
  min-height: 44px;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border: 1px solid rgba(255, 250, 240, 0.22);
  border-radius: 999px;
  color: #fff9ed;
  background: rgba(16, 17, 20, 0.72);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(14px);
  cursor: pointer;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.9rem;
  font-weight: 800;
}

.fullscreen-exit:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.45);
  outline-offset: 3px;
}

.book-frame::before {
  content: "";
  position: absolute;
  inset: 16% -12% auto;
  height: 46%;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(255, 250, 240, 0.2), transparent 66%);
}

.reader-status {
  display: grid;
  grid-template-columns: minmax(118px, max-content) minmax(120px, 420px);
  align-items: center;
  justify-content: center;
  gap: 14px;
  position: relative;
  margin-bottom: clamp(14px, 2vw, 24px);
}

.reader-status p {
  margin: 0;
  color: rgba(255, 250, 240, 0.78);
  font-size: 0.94rem;
  font-weight: 800;
}

.progress-track {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 250, 240, 0.16);
}

#progressFill {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--gold), #fff1bc);
  transition: width 240ms ease;
}

.book-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 2vw, 24px);
  min-height: 0;
}

.book-scroll {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  width: min(100%, 1210px);
  overflow: visible;
  padding: 24px 28px 36px;
}

.book-stage {
  position: relative;
  overflow: visible;
  width: min(100%, 1160px);
  perspective: 2200px;
  transform-style: preserve-3d;
}

.book-stage::after {
  content: "";
  position: absolute;
  inset: auto 4% -34px;
  height: 58px;
  z-index: -2;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.52), transparent 70%);
  filter: blur(7px);
}

.spread {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  padding: var(--book-pad);
  border-radius: 18px;
  background:
    linear-gradient(90deg, #4a141e, #6f1828 3%, #2b1618 49.6%, #1a1011 50%, #6f1828 97%, #3e1018),
    #351016;
  box-shadow:
    inset 0 0 0 1px rgba(255, 244, 218, 0.18),
    inset 0 0 44px rgba(0, 0, 0, 0.44),
    var(--shadow);
}

.book-stage::before {
  content: "";
  position: absolute;
  top: var(--book-pad);
  bottom: var(--book-pad);
  left: 50%;
  width: clamp(10px, 1.1vw, 16px);
  z-index: 5;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, rgba(0, 0, 0, 0.32), transparent 70%),
    linear-gradient(90deg, rgba(0, 0, 0, 0.18), rgba(255, 246, 226, 0.36) 44%, rgba(0, 0, 0, 0.26) 100%);
  filter: blur(0.2px);
  opacity: 0.58;
  transform: translateX(-50%);
}

.page,
.turn-sheet {
  position: relative;
  margin: 0;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: #fffdf8;
  box-shadow:
    inset 0 0 0 1px rgba(96, 65, 36, 0.1),
    inset 0 0 34px rgba(125, 85, 41, 0.08);
}

.page-left {
  border-radius: 10px 0 0 10px;
  transform: rotateY(1.1deg);
  transform-origin: right center;
}

.page-right {
  border-radius: 0 10px 10px 0;
  transform: rotateY(-1.1deg);
  transform-origin: left center;
}

.page::after,
.turn-sheet::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.2), transparent 17%, transparent 82%, rgba(0, 0, 0, 0.12)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(44, 29, 19, 0.08));
  mix-blend-mode: multiply;
}

.page-left::after {
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.14), transparent 24%, rgba(0, 0, 0, 0.22) 100%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(44, 29, 19, 0.06));
}

.page-right::after {
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.21), transparent 22%, rgba(255, 255, 255, 0.16) 100%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(44, 29, 19, 0.06));
}

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

.page-placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.turn-sheet {
  position: absolute;
  top: var(--book-pad);
  bottom: var(--book-pad);
  z-index: 9;
  width: calc((100% - (var(--book-pad) * 2)) / 2);
  backface-visibility: hidden;
  transform-style: preserve-3d;
  pointer-events: none;
}

.turn-next {
  right: var(--book-pad);
  transform-origin: left center;
  border-radius: 0 10px 10px 0;
}

.turn-prev {
  left: var(--book-pad);
  transform-origin: right center;
  border-radius: 10px 0 0 10px;
}

.turn-next.is-turning {
  animation: turnNext 680ms cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

.turn-prev.is-turning {
  animation: turnPrev 680ms cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

.edge-nav {
  flex: 0 0 auto;
  width: 58px;
  height: 58px;
  color: #fff9ed;
}

.thumbs-shell {
  margin: 18px auto 0;
  max-width: 980px;
  overflow-x: auto;
  padding: 8px 2px 12px;
  scrollbar-width: thin;
}

.thumbs {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.thumb-button {
  position: relative;
  flex: 0 0 auto;
  width: 58px;
  height: 82px;
  overflow: hidden;
  padding: 0;
  border: 1px solid rgba(255, 250, 240, 0.24);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.12);
  box-shadow: var(--soft-shadow);
  transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.thumb-button:hover {
  border-color: rgba(200, 166, 97, 0.76);
  transform: translateY(-2px);
}

.thumb-button.is-active {
  border-color: var(--gold);
  box-shadow: 0 14px 28px rgba(200, 166, 97, 0.2);
}

.thumb-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-button span {
  position: absolute;
  right: 4px;
  bottom: 4px;
  min-width: 20px;
  padding: 2px 5px;
  border-radius: 999px;
  color: #fff;
  background: rgba(16, 17, 20, 0.78);
  font-size: 0.72rem;
  font-weight: 800;
}

.noscript {
  margin: 16px auto;
  max-width: 720px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@keyframes turnNext {
  0% {
    filter: brightness(1);
    transform: rotateY(0deg);
  }
  52% {
    filter: brightness(0.88);
  }
  100% {
    filter: brightness(0.72);
    transform: rotateY(-178deg);
  }
}

@keyframes turnPrev {
  0% {
    filter: brightness(1);
    transform: rotateY(0deg);
  }
  52% {
    filter: brightness(0.88);
  }
  100% {
    filter: brightness(0.72);
    transform: rotateY(178deg);
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 12px 10px 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 12px;
    padding: 15px;
    border-radius: 16px;
  }

  .actions {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .download-link,
  .fullscreen-button {
    flex: 1 1 calc(50% - 6px);
  }

  .reader {
    padding-top: 14px;
  }

  .book-frame {
    padding: 12px 0 14px;
    border-radius: 20px;
  }

  .reader-status {
    grid-template-columns: 1fr;
    justify-items: stretch;
    gap: 8px;
    padding: 0 12px;
  }

  .book-wrap {
    gap: 8px;
    align-items: stretch;
  }

  .book-scroll {
    justify-content: center;
    width: 100%;
    overflow: visible;
    padding: 14px 12px 30px;
  }

  .book-stage {
    min-width: 0;
  }

  .spread {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .turn-sheet {
    width: calc((100% - (clamp(9px, 1vw, 14px) * 2)) / 2);
  }

  .edge-nav {
    position: absolute;
    top: 50%;
    z-index: 12;
    width: 48px;
    height: 48px;
    background: rgba(24, 18, 18, 0.7);
    transform: translateY(-50%);
  }

  .edge-nav-left {
    left: 8px;
  }

  .edge-nav-right {
    right: 8px;
  }

  .thumbs {
    justify-content: flex-start;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 1.28rem;
  }

  .download-link,
  .fullscreen-button {
    padding: 0 12px;
    font-size: 0.84rem;
  }

  .icon-button {
    width: 44px;
    height: 44px;
  }

  .reader {
    padding-inline: 10px;
  }

  .thumb-button {
    width: 50px;
    height: 70px;
  }
}

body.is-fullscreen {
  overflow: hidden;
}

body.is-fullscreen .app-shell {
  width: 100vw;
  min-height: 100dvh;
  padding: 0;
}

body.is-fullscreen .topbar,
body.is-fullscreen .thumbs-shell {
  display: none;
}

body.is-fullscreen .reader {
  position: fixed;
  inset: 0;
  z-index: 60;
  max-width: none;
  width: 100vw;
  height: 100dvh;
  padding: 0;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 239, 190, 0.2), transparent 34rem),
    linear-gradient(135deg, #171316, #0d0d10);
}

body.is-fullscreen .book-frame {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

body.is-fullscreen .fullscreen-exit {
  display: inline-flex;
}

body.is-fullscreen .reader-status {
  flex: 0 0 auto;
  width: min(560px, calc(100vw - 32px));
  margin: 0 auto 12px;
  padding-right: 112px;
}

body.is-fullscreen .book-wrap {
  min-height: 0;
  flex: 1 1 auto;
}

body.is-fullscreen .book-scroll {
  width: 100%;
  height: 100%;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  overflow-y: hidden;
  padding: 10px max(18px, env(safe-area-inset-right)) 22px max(18px, env(safe-area-inset-left));
}

body.is-fullscreen .book-stage {
  flex: 0 0 auto;
  scroll-snap-align: center;
}

body.is-fullscreen .edge-nav {
  position: fixed;
  top: 50%;
  bottom: auto;
  z-index: 78;
  width: 52px;
  height: 52px;
  background: rgba(16, 17, 20, 0.74);
  transform: translateY(-50%);
}

body.is-fullscreen .edge-nav-left {
  left: max(16px, env(safe-area-inset-left));
}

body.is-fullscreen .edge-nav-right {
  right: max(16px, env(safe-area-inset-right));
}

@media (max-width: 820px) {
  body.is-fullscreen .reader-status {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 0 104px 0 12px;
    width: 100%;
  }

  body.is-fullscreen .book-scroll {
    justify-content: center;
    padding-top: 4px;
    padding-inline: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
