:root {
  --cream: #f6f0e9;
  --paper: #fffdf9;
  --wine: #6f3744;
  --sage: #8e9c88;
  --petrol: #315c62;
  --ink: #342f30;
  --muted: #776d6d;
  --line: rgba(81, 58, 61, .15);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}
button { font: inherit; }

.app-shell {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: 62px minmax(0, 1fr);
  padding: 0 clamp(14px, 2.5vw, 36px) 6px;
}
.viewer-header {
  height: 62px;
  display: grid;
  grid-template-columns: minmax(44px, 1fr) auto minmax(140px, 1fr);
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 4px 0;
}
.identity { text-align: center; }
.brand { color: var(--wine); font-family: Georgia, serif; letter-spacing: .06em; }
h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.08rem, 1.7vw, 1.45rem); font-weight: 500; line-height: 1.15; }
.format-line { margin: 3px 0 0; color: var(--muted); font-size: .72rem; line-height: 1.2; white-space: nowrap; }

.icon-button, .control-button, .page-arrow {
  border: 1px solid var(--line);
  background: rgba(255, 253, 249, .78);
  color: var(--wine);
  cursor: pointer;
  transition: background .2s, color .2s, border-color .2s, opacity .2s;
}
.icon-button:hover, .control-button:hover, .page-arrow:hover { background: #fff; border-color: rgba(111, 55, 68, .35); }
.icon-button:focus-visible, .control-button:focus-visible, .page-arrow:focus-visible, .buy-button:focus-visible { outline: 3px solid rgba(49, 92, 98, .28); outline-offset: 2px; }
.icon-button:disabled, .page-arrow:disabled, .control-button:disabled { opacity: .35; cursor: default; }
.back-button { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; }
.back-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.buy-button { justify-self: end; border: 0; border-radius: 999px; padding: 9px 16px; background: var(--wine); color: #fff; cursor: default; font-size: .82rem; }
.buy-button[href] { cursor: pointer; text-decoration: none; }

.book-workspace {
  min-height: 0;
  position: relative;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  align-items: center;
  gap: clamp(2px, .8vw, 10px);
  padding: 6px 0 0;
}
.book-viewport {
  min-height: 0;
  height: 100%;
  display: grid;
  place-items: center;
  position: relative;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  padding-bottom: 30px;
}
.book-position { transform-origin: center; transition: none; }
.book-scale { position: relative; transform-origin: center; transition: transform .2s ease; }
.book-viewport.is-zoom-layout {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
}
.book-viewport.is-zoom-layout .book-position {
  position: relative;
  flex: 0 0 auto;
  margin: auto;
}
.book-viewport.is-zoom-layout .book-scale {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: top left;
}

#book {
  position: relative;
  filter: drop-shadow(0 9px 20px rgba(69,45,49,.11)) drop-shadow(0 2px 4px rgba(69,45,49,.05));
}
.public-flip-page {
  position: relative;
  overflow: hidden;
  background: #fff !important;
  opacity: 1 !important;
  box-shadow: inset 0 0 0 1px rgba(60,45,48,.035);
}
.public-flip-page > img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: fill;
  background: #fff;
  opacity: 1 !important;
  user-select: none;
  pointer-events: none;
  -webkit-user-drag: none;
}

/* Capa de papel real bajo cada hoja blanda. StPageFlip clona la página durante el giro;
   esta base blanca se clona con ella y evita ver otras páginas a través del PNG. */
.public-flip-page[data-density="soft"]::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #fff;
  opacity: 1;
  pointer-events: none;
}

/* Profundidad localizada en el canal central. Cada mitad lleva su propia sombra
   únicamente en el borde que toca el lomo; no existe ninguna capa sobre todo el libro. */
body.is-spread-open .public-flip-page[data-density="soft"].--left::after,
body.is-spread-open .public-flip-page[data-density="soft"].--right::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 14px;
  z-index: 2;
  pointer-events: none;
}
body.is-spread-open .public-flip-page[data-density="soft"].--left::after {
  right: 0;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(52,47,48,.025) 35%,
    rgba(52,47,48,.075) 68%,
    rgba(52,47,48,.17) 100%);
}
body.is-spread-open .public-flip-page[data-density="soft"].--right::after {
  left: 0;
  background: linear-gradient(90deg,
    rgba(52,47,48,.17) 0%,
    rgba(52,47,48,.075) 32%,
    rgba(52,47,48,.025) 65%,
    transparent 100%);
}

.public-flip-page[data-density="hard"]::before,
.public-flip-page[data-density="hard"]::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 6;
  pointer-events: none;
}

/* StPageFlip conserva --right/--left al posicionar las tapas. Así portada y
   contraportada reciben el mismo lomo fino y el mismo canto, en espejo. */
.public-flip-page[data-density="hard"].--right::before {
  left: 0;
  width: 12px;
  background: linear-gradient(90deg, rgba(52,47,48,.20), rgba(52,47,48,.07) 40%, transparent 100%);
}
.public-flip-page[data-density="hard"].--right::after {
  right: 0;
  width: 3px;
  background: linear-gradient(270deg, rgba(52,47,48,.24), rgba(52,47,48,.055) 62%, transparent 100%);
}
.public-flip-page[data-density="hard"].--left::before {
  right: 0;
  width: 12px;
  background: linear-gradient(270deg, rgba(52,47,48,.20), rgba(52,47,48,.07) 40%, transparent 100%);
}
.public-flip-page[data-density="hard"].--left::after {
  left: 0;
  width: 3px;
  background: linear-gradient(90deg, rgba(52,47,48,.24), rgba(52,47,48,.055) 62%, transparent 100%);
}

.page-arrow { width: 46px; height: 52px; border: 0; border-radius: 14px; display: grid; place-items: center; background: rgba(255, 253, 249, .52); box-shadow: 0 5px 18px rgba(69,45,49,.07); }
.page-arrow svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.page-arrow:hover { color: var(--wine); background: rgba(255,255,255,.9); box-shadow: 0 7px 22px rgba(69,45,49,.11); }
.loading-state { position: absolute; color: var(--muted); font-size: .9rem; }
.loading-state[hidden] { display: none; }
.viewer-controls {
  position: absolute;
  z-index: 60;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 249, .88);
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 26px rgba(69,45,49,.11);
}
.control-button { width: 36px; height: 36px; border: 0; border-radius: 50%; display: grid; place-items: center; }
.control-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#soundIcon { display: grid; place-items: center; }
#soundButton[aria-pressed="false"] .sound-wave { opacity: .38; }
.control-button[aria-pressed="true"] { background: rgba(142, 156, 136, .22); color: var(--petrol); }
.page-status { min-width: 112px; text-align: center; font-size: .83rem; color: var(--ink); }
.zoom-value { min-width: 43px; text-align: center; color: var(--muted); font-size: .75rem; }
.control-divider { width: 1px; height: 22px; background: var(--line); margin: 0 3px; }
.mobile-page-button { display: none; }

body.is-fullscreen .app-shell { grid-template-rows: minmax(0, 1fr); padding: 6px 16px; }
body.is-fullscreen .viewer-header { display: none; }
body.is-fullscreen .book-workspace { padding-top: 0; }
body.is-fullscreen .buy-button { display: none; }

@media (max-width: 700px) {
  .app-shell { padding: 0 10px max(5px, env(safe-area-inset-bottom)); grid-template-rows: 58px minmax(0, 1fr); }
  .viewer-header { height: 58px; grid-template-columns: 38px 1fr 38px; padding: 3px 0; gap: 4px; }
  .brand { font-size: .66rem; }
  h1 { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 72vw; }
  .format-line { max-width: 72vw; overflow: hidden; text-overflow: ellipsis; font-size: .66rem; }
  .buy-button { display: none; }
  .back-button { width: 38px; height: 38px; }
  .book-workspace { display: block; padding: 4px 0 0; }
  .book-viewport { min-height: 0; height: 100%; overflow: auto; padding-bottom: 44px; }
  .page-arrow { display: none; }
  .mobile-page-button { display: inline-grid; place-items: center; }
  .viewer-controls { bottom: 6px; max-width: calc(100% - 8px); gap: 2px; }
  .page-status { min-width: 96px; font-size: .76rem; }
  .zoom-value { display: none; }
}

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