:root {
  color-scheme: light;
  --page-ratio: 1.2727;
  --book-width: 720px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background-color: #f4efe6;
  background-image:
    radial-gradient(ellipse 70% 45% at 0% 0%, rgba(125, 154, 120, 0.28), transparent 60%),
    radial-gradient(ellipse 55% 40% at 100% 0%, rgba(196, 165, 116, 0.22), transparent 55%),
    radial-gradient(ellipse 50% 35% at 50% 100%, rgba(30, 74, 56, 0.08), transparent 60%);
}

.brand-logo {
  height: 5.25rem;
  width: auto;
  flex: none;
  mix-blend-mode: multiply;
}

@media (min-width: 640px) {
  .brand-logo {
    height: 6.5rem;
  }
}

.app-shell {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.viewer {
  position: relative;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem 1rem 1.5rem;
}

.viewer.is-zoomed {
  overflow: auto;
  align-items: flex-start;
  justify-content: flex-start;
}

.book-frame {
  position: relative;
  flex: 0 0 auto;
  width: var(--book-width);
  max-width: none;
  margin: auto;
  filter: drop-shadow(0 18px 18px rgba(22, 40, 32, 0.18));
}

.viewer.is-zoomed .book-frame {
  margin: 1rem;
}

.book-frame::after {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: -22px;
  height: 36px;
  background: radial-gradient(ellipse at center, rgba(16, 38, 29, 0.28), transparent 70%);
  pointer-events: none;
}

#book {
  background: transparent;
}

#book.stf__parent {
  overflow: clip;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: 100% !important;
  touch-action: none;
}

#book.stf__parent.allow-pan {
  touch-action: pan-x pan-y;
}

.page {
  background: #fffdf8;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(30, 74, 56, 0.06);
}

.page img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.page-pending {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #8d6844;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 2rem;
  background:
    linear-gradient(110deg, rgba(255, 253, 248, 0) 30%, rgba(239, 230, 214, 0.9) 50%, rgba(255, 253, 248, 0) 70%),
    #fffdf8;
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.page.is-ready .page-pending {
  display: none;
}

.loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: rgba(244, 239, 230, 0.72);
  backdrop-filter: blur(8px);
}

.loader.is-hidden {
  display: none;
}

.loader-card {
  width: min(100%, 22rem);
  padding: 1.75rem 1.5rem 1.5rem;
  text-align: center;
  border-radius: 1.25rem;
  background: rgba(255, 253, 248, 0.92);
  box-shadow: 0 16px 40px rgba(16, 38, 29, 0.12);
}

.spinner {
  width: 3rem;
  height: 3rem;
  margin: 0 auto 1rem;
  border-radius: 999px;
  background: conic-gradient(from 90deg, #1e4a38, #c4a574, #7d9a78, #1e4a38);
  -webkit-mask: radial-gradient(farthest-side, transparent 58%, #000 60%);
  mask: radial-gradient(farthest-side, transparent 58%, #000 60%);
  animation: spin 0.9s linear infinite;
}

progress {
  width: 100%;
  height: 0.45rem;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  accent-color: #1e4a38;
  background: #e3d5c0;
}

progress::-webkit-progress-bar {
  background: #e3d5c0;
}

progress::-webkit-progress-value {
  background: #1e4a38;
  border-radius: 999px;
}

.toolbar {
  container-type: inline-size;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem 1.25rem;
  margin: 0 auto 1rem;
  width: min(100% - 1.5rem, 52rem);
  padding: 0.55rem 0.7rem;
  border: 1px solid rgba(30, 74, 56, 0.08);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.88);
  box-shadow: 0 10px 30px rgba(16, 38, 29, 0.08);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.tool-btn {
  display: inline-grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 0;
  border-radius: 999px;
  color: #16382b;
  background: transparent;
  cursor: pointer;
}

.tool-btn svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool-btn:hover:not(:disabled) {
  background: #efe6d6;
}

.tool-btn:focus-visible {
  outline: 2px solid #1e4a38;
  outline-offset: 2px;
}

.tool-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.tool-btn-text {
  width: auto;
  min-width: 3.25rem;
  padding: 0 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.page-jump input {
  width: 3.6rem;
  height: 2.5rem;
  border: 1px solid #e3d5c0;
  border-radius: 0.7rem;
  background: #fffdf8;
  color: #16382b;
  font: inherit;
  font-weight: 600;
  text-align: center;
}

.page-jump input:focus-visible {
  outline: 2px solid #1e4a38;
  outline-offset: 2px;
}

.page-label {
  min-width: 5.5rem;
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: #1e4a38;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@container (width < 640px) {
  .toolbar {
    border-radius: 1.25rem;
  }

  .page-label {
    min-width: 4.5rem;
  }
}

@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner,
  .page-pending {
    animation: none;
  }
}
