:root {
  --toolbar-height: 56px;
  --stage-padding: 24px;
  --background: #e9e9e9;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: radial-gradient(circle at 50% 8%, #fafafa 0%, #eeeeee 40%, #dedede 100%);
  color: #222;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.flipbook-app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 360px;
}

/* ---------- toolbar ---------- */

.toolbar {
  min-height: var(--toolbar-height);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: #fff;
  border-bottom: 1px solid #d9d9d9;
  z-index: 10;
}

.nav-button {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: #ff4f00;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
  transition: background 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}

.nav-button svg {
  display: block;
}

.nav-button:hover:not(:disabled) {
  background: #f5f5f5;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.nav-button:active:not(:disabled) {
  transform: scale(0.95);
}

.nav-button:focus-visible {
  outline: 2px solid #ff4f00;
  outline-offset: 2px;
}

.nav-button:disabled {
  opacity: 0.35;
  cursor: default;
  box-shadow: none;
}

.page-counter {
  min-width: 120px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ---------- stage / loading / error ---------- */

.stage-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  padding: var(--stage-padding);
  display: flex;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 2400px;
  touch-action: pan-y;
}

.viewer {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: stretch;
  justify-content: center;
  opacity: 1;
  transition: opacity 200ms ease;
}

/* Kept measurable (not display:none) while loading, so the stage's real
   pixel size is always available for layout math -- see flipbook.js. */
.viewer.is-hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.stage__overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  text-align: center;
}

.status-message {
  padding: 24px;
}

.status-message--error {
  max-width: 640px;
  color: #951b1b;
  border: 1px solid #efcaca;
  background: #fff6f6;
  border-radius: 10px;
}

/* ---------- book spread / slots ---------- */

.spread {
  position: relative;
  display: flex;
  flex-direction: row;
  margin: auto;
  filter: drop-shadow(0 18px 26px rgba(0, 0, 0, 0.16));
}

.slot {
  position: relative;
  overflow: hidden;
  flex: none;
  width: var(--page-width);
  height: var(--page-height);
  background: #fff;
}

.slot--left {
  border-right: 1px solid rgba(0, 0, 0, 0.08);
}

/* ---------- the live PDF page itself ---------- */

.fit-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}

.pdf-page {
  position: relative;
  background: #fff;
}

.pdf-page__canvas {
  display: block;
}

/* Selectable-but-invisible text, aligned exactly over the canvas glyphs. */
.textLayer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  line-height: 1;
  text-align: initial;
}

.textLayer span,
.textLayer br {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
}

.textLayer ::selection {
  background: rgba(0, 100, 255, 0.3);
}

/* Clickable link / form regions from the PDF. */
.annotationLayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.annotationLayer section,
.annotationLayer div {
  position: absolute;
  pointer-events: auto;
}

.annotationLayer a {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- corner hotzones (click-to-turn + decorative hover peel) ---------- */

.corner-hotzone {
  position: absolute;
  bottom: 0;
  width: 15%;
  height: 15%;
  min-width: 44px;
  min-height: 44px;
  max-width: 90px;
  max-height: 90px;
  z-index: 6;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.corner-hotzone--next {
  right: 0;
}

.corner-hotzone--prev {
  left: 0;
}

.corner-hotzone.is-disabled {
  pointer-events: none;
  cursor: default;
}

.corner-hotzone::before {
  content: "";
  position: absolute;
  inset: 0;
  clip-path: polygon(100% 100%, 100% 35%, 35% 100%);
  background: linear-gradient(135deg, transparent 50%, rgba(0, 0, 0, 0.14) 100%);
  transform-origin: 100% 100%;
  transform: scale(0.8);
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms ease;
}

.corner-hotzone--prev::before {
  clip-path: polygon(0 100%, 0 35%, 65% 100%);
  transform-origin: 0% 100%;
}

.corner-hotzone:hover:not(.is-disabled)::before,
.corner-hotzone:focus-visible:not(.is-disabled)::before {
  opacity: 1;
  transform: scale(1);
}

/* ---------- the animated flipping leaf ---------- */

.flip-leaf {
  position: absolute;
  z-index: 8;
  transform-style: preserve-3d;
  will-change: transform;
}

.flip-leaf__face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #fff;
  backface-visibility: hidden;
  box-shadow: 0 0 26px rgba(0, 0, 0, 0.28);
}

.flip-leaf__face--back {
  transform: rotateY(180deg);
}

@media (prefers-reduced-motion: reduce) {
  .flip-leaf {
    transition-duration: 1ms !important;
  }
}

/* ---------- offscreen holding area for pages not currently shown ---------- */

.page-pool {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  visibility: hidden;
}

/* ---------- screen-reader-only live region for page announcements ---------- */

.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;
}

@media (max-width: 560px) {
  .toolbar {
    gap: 10px;
  }
  .page-counter {
    min-width: 90px;
  }
}
