:root {
  color-scheme: dark;
  --gold: #d6a548;
  --gold-soft: #f0d79b;
  --ink: #0e0907;
  --panel: #17100c;
  --paper: #fffdf8;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background:
    radial-gradient(circle at 50% 10%, rgba(151, 91, 37, .26), transparent 32rem),
    linear-gradient(145deg, #080504, #1a0e08 55%, #060403);
  color: #f9f3e8;
  font-family: Georgia, "Times New Roman", serif;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .26;
  background-image: repeating-linear-gradient(115deg, transparent 0 5px, rgba(255,255,255,.018) 6px 7px);
}

button, a { font: inherit; }

.reader-shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 20px max(22px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.topbar h1 {
  margin: 0;
  color: var(--gold-soft);
  font-size: clamp(1.05rem, 2.4vw, 1.55rem);
  font-weight: 500;
  letter-spacing: .025em;
}

.topbar p {
  margin: 4px 0 0;
  color: rgba(255,255,255,.68);
  font: .82rem/1.3 system-ui, sans-serif;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.top-actions { display: flex; gap: 8px; }

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid rgba(214,165,72,.42);
  border-radius: 50%;
  background: rgba(21,13,9,.76);
  color: var(--gold-soft);
  text-decoration: none;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: .2s ease;
}

.icon-button:hover { background: rgba(214,165,72,.16); transform: translateY(-1px); }

.stage {
  min-height: 0;
  display: grid;
  place-items: center;
  perspective: 2400px;
}

.book-wrap {
  width: min(1040px, 92vw, calc((100vh - 188px) * 1.545));
  aspect-ratio: 1224 / 792;
  filter: drop-shadow(0 28px 38px rgba(0,0,0,.65));
}

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

.book::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 1%;
  bottom: 1%;
  width: 14px;
  transform: translateX(-50%);
  z-index: 200;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(0,0,0,.24), rgba(255,255,255,.09), rgba(0,0,0,.32));
  filter: blur(3px);
}

.inside-cover {
  position: absolute;
  inset: 0 50% 0 0;
  border-radius: 9px 0 0 9px;
  background:
    radial-gradient(circle at 100% 45%, rgba(214,165,72,.18), transparent 42%),
    linear-gradient(135deg, #2a160d, #100906 68%);
  box-shadow: inset -18px 0 34px rgba(0,0,0,.46), inset 0 0 0 1px rgba(214,165,72,.12);
}

.inside-cover::before {
  content: "";
  position: absolute;
  inset: 6%;
  border: 1px solid rgba(214,165,72,.17);
  border-radius: 5px;
}

.sheet {
  position: absolute;
  right: 0;
  top: 0;
  width: 50%;
  height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform .82s cubic-bezier(.65,.05,.36,1);
  cursor: pointer;
}

.sheet.flipped { transform: rotateY(-180deg); }

.page-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--paper);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.page-face.front { border-radius: 0 8px 8px 0; box-shadow: inset 13px 0 22px rgba(0,0,0,.07); }
.page-face.back { transform: rotateY(180deg); border-radius: 8px 0 0 8px; box-shadow: inset -13px 0 22px rgba(0,0,0,.07); }

.page-face img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.blank-page { background: linear-gradient(100deg, #f7f3e9, #fffdf8); }

.controls {
  display: grid;
  grid-template-columns: minmax(106px, 1fr) minmax(150px, 280px) minmax(106px, 1fr);
  align-items: center;
  gap: 16px;
}

.controls button {
  min-height: 46px;
  border: 1px solid rgba(214,165,72,.34);
  border-radius: 999px;
  background: rgba(23,16,12,.82);
  color: #fff8ec;
  cursor: pointer;
  transition: .2s ease;
}

.controls button:first-child { justify-self: end; padding: 0 22px; }
.controls button:last-child { justify-self: start; padding: 0 22px; }
.controls button:hover:not(:disabled) { border-color: var(--gold); background: rgba(214,165,72,.14); }
.controls button:disabled { opacity: .32; cursor: default; }

.progress-wrap { text-align: center; font: .86rem/1.2 system-ui, sans-serif; color: rgba(255,255,255,.76); }
.progress-track { height: 3px; margin-top: 8px; overflow: hidden; border-radius: 4px; background: rgba(255,255,255,.12); }
#progressBar { width: 0; height: 100%; background: linear-gradient(90deg, #9f6a28, #edc875); transition: width .35s ease; }
.hint { margin: 0; text-align: center; color: rgba(255,255,255,.48); font: .78rem/1.4 system-ui, sans-serif; }

@media (max-width: 680px) {
  .reader-shell { padding-inline: 10px; gap: 10px; }
  .book-wrap { width: 98vw; }
  .topbar p { display: none; }
  .top-actions .icon-button { width: 40px; height: 40px; }
  .controls { grid-template-columns: 52px 1fr 52px; gap: 8px; }
  .controls button { width: 48px; min-width: 48px; padding: 0 !important; font-size: 1.55rem; }
  .controls button span { display: none; }
  .hint { font-size: .72rem; }
}

@media (prefers-reduced-motion: reduce) {
  .sheet { transition-duration: .01ms; }
}

:fullscreen .reader-shell { width: 100%; }
:fullscreen .book-wrap { width: min(1180px, 96vw, calc((100vh - 154px) * 1.545)); }
