:root {
  --ink: #171713;
  --paper: #f0e8dc;
  --bronze: #b89b62;
  --bronze-soft: #d7c59f;
  --wine: #7b2b2f;
  --green: #314936;
  --chrome: rgba(23, 23, 19, 0.92);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  color: var(--paper);
  background:
    radial-gradient(circle at 50% -15%, rgba(184, 155, 98, 0.17), transparent 42%),
    linear-gradient(145deg, #1d211b 0%, #11130f 58%, #191513 100%);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

button, input, a { font: inherit; }

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

.masthead {
  height: 76px;
  padding: 0 clamp(18px, 3vw, 42px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid rgba(215, 197, 159, 0.22);
  background: rgba(14, 15, 12, 0.62);
  backdrop-filter: blur(16px);
}

.identity { display: flex; align-items: baseline; gap: 18px; min-width: 0; }

.wordmark {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.08rem, 2vw, 1.48rem);
  letter-spacing: 0.3em;
  color: var(--bronze-soft);
  white-space: nowrap;
}

.issue {
  font-size: 0.76rem;
  letter-spacing: 0.18em;
  color: rgba(240, 232, 220, 0.62);
  white-space: nowrap;
}

.download {
  color: var(--bronze-soft);
  border: 1px solid rgba(215, 197, 159, 0.34);
  border-radius: 999px;
  padding: 9px 15px;
  text-decoration: none;
  font-size: 0.82rem;
  white-space: nowrap;
  transition: background 160ms ease, border-color 160ms ease;
}

.download:hover, .download:focus-visible {
  background: rgba(215, 197, 159, 0.1);
  border-color: rgba(215, 197, 159, 0.72);
}

.reader {
  height: calc(100vh - 116px);
  min-height: 360px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 58px;
}

.stage {
  position: relative;
  overflow: auto;
  overscroll-behavior: contain;
  display: grid;
  place-items: center;
  padding: 24px clamp(28px, 5vw, 72px);
  perspective: 2200px;
}

.book {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: none;
  filter: drop-shadow(0 24px 30px rgba(0,0,0,.42));
  transition: width 180ms ease, height 180ms ease;
  transform-style: preserve-3d;
}

.book.is-single { grid-template-columns: 1fr; }
.book.is-single .left, .book.is-single .spine { display: none; }

.page-slot,
.turner-face {
  position: relative;
  overflow: hidden;
  background: #eee7dc;
  backface-visibility: hidden;
}

.page-slot.left { border-radius: 4px 0 0 4px; }
.page-slot.right { border-radius: 0 4px 4px 0; }
.book.is-single .page-slot.right { border-radius: 4px; }

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

.page-slot.blank::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #eee7dc;
}

.page-slot.left::after,
.page-slot.right::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  width: 8%;
  pointer-events: none;
}

.page-slot.left::after {
  right: 0;
  background: linear-gradient(to left, rgba(18,15,10,.18), transparent);
}

.page-slot.right::after {
  left: 0;
  background: linear-gradient(to right, rgba(18,15,10,.16), transparent);
}

.book.is-single .page-slot.right::after { display: none; }

.spine {
  position: absolute;
  inset: 0 auto 0 50%;
  width: 1px;
  z-index: 12;
  background: rgba(31,24,15,.5);
  box-shadow: 0 0 9px rgba(0,0,0,.32);
  pointer-events: none;
}

.turner {
  position: absolute;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  z-index: 10;
  transform-origin: left center;
  transform-style: preserve-3d;
  pointer-events: none;
}

.turner-face { position: absolute; inset: 0; }
.turner-face.front { border-radius: 0 4px 4px 0; }
.turner-face.back { transform: rotateY(180deg); border-radius: 4px 0 0 4px; }

.turner.forward { animation: turn-forward 720ms cubic-bezier(.63,.02,.34,1) both; }
.turner.backward { animation: turn-backward 720ms cubic-bezier(.63,.02,.34,1) both; }

@keyframes turn-forward {
  0% { transform: rotateY(0deg); filter: brightness(1); }
  46% { filter: brightness(.72); }
  100% { transform: rotateY(-180deg); filter: brightness(1); }
}

@keyframes turn-backward {
  0% { transform: rotateY(-180deg); filter: brightness(1); }
  54% { filter: brightness(.72); }
  100% { transform: rotateY(0deg); filter: brightness(1); }
}

.edge {
  position: fixed;
  top: 76px;
  bottom: 98px;
  width: min(12vw, 120px);
  z-index: 20;
  border: 0;
  cursor: pointer;
  opacity: 0;
  background: transparent;
}
.edge-left { left: 0; cursor: w-resize; }
.edge-right { right: 0; cursor: e-resize; }
.edge:disabled { cursor: default; }

.loading {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  color: rgba(240,232,220,.7);
  letter-spacing: .08em;
  transition: opacity 180ms ease;
}
.loading.hidden { opacity: 0; pointer-events: none; }

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 16px;
  border-top: 1px solid rgba(215, 197, 159, 0.18);
  background: var(--chrome);
  backdrop-filter: blur(18px);
  z-index: 30;
}

.control-button,
.icon-button {
  min-height: 38px;
  color: var(--paper);
  border: 1px solid rgba(215, 197, 159, 0.23);
  background: rgba(255,255,255,.035);
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease, opacity 150ms ease;
}

.control-button { padding: 7px 14px; border-radius: 999px; display: flex; gap: 8px; align-items: center; }
.icon-button { width: 38px; padding: 0; border-radius: 50%; font-size: 1.15rem; }
.fullscreen-button { margin-left: 2px; }

.control-button:hover:not(:disabled), .icon-button:hover:not(:disabled),
.control-button:focus-visible, .icon-button:focus-visible {
  background: rgba(215, 197, 159, 0.11);
  border-color: rgba(215, 197, 159, 0.62);
}

button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--bronze-soft);
  outline-offset: 2px;
}

button:disabled { opacity: .32; }

.position { display: flex; align-items: center; gap: 7px; color: rgba(240,232,220,.72); font-size: .86rem; }
.position label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.position input {
  width: 52px;
  min-height: 36px;
  border: 1px solid rgba(215, 197, 159, 0.22);
  border-radius: 8px;
  color: var(--paper);
  background: rgba(255,255,255,.04);
  text-align: center;
}

.divider { width: 1px; height: 26px; background: rgba(215,197,159,.2); margin: 0 4px; }
.zoom-readout { width: 48px; text-align: center; color: rgba(240,232,220,.62); font-size: .78rem; }

footer {
  height: 40px;
  padding: 0 clamp(18px, 3vw, 42px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: rgba(240,232,220,.42);
  font-family: Georgia, "Times New Roman", serif;
  font-size: .74rem;
  letter-spacing: .06em;
}

noscript { position: fixed; inset: 20px; padding: 20px; color: #111; background: #fff; z-index: 100; }

.reader:fullscreen { height: 100dvh; background: #12130f; }
.reader:fullscreen .stage { padding: 24px 54px; }
.reader:fullscreen .edge { top: 0; bottom: 58px; }

@media (max-width: 760px) {
  .masthead { height: 62px; padding: 0 14px; }
  .identity { display: block; }
  .wordmark { display: block; font-size: 1rem; }
  .issue { display: block; margin-top: 3px; font-size: .62rem; letter-spacing: .13em; }
  .download { padding: 8px 11px; font-size: .74rem; }
  .reader { height: calc(100dvh - 94px); grid-template-rows: minmax(0,1fr) 58px; }
  .stage { padding: 16px 42px; }
  .edge { top: 62px; bottom: 90px; width: 22vw; }
  .button-text, .divider, .zoom-readout { display: none; }
  .control-button { width: 40px; justify-content: center; padding: 0; border-radius: 50%; font-size: 1.15rem; }
  .controls { gap: 8px; }
  .position { order: 0; }
  footer { height: 32px; justify-content: center; }
  footer .hint { display: none; }
}

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