/*
  Layout goals
  - Book stays perfectly centered (equal left/right + top/bottom spacing)
  - Mobile Safari friendly (avoids 100vh "jump" / off-center issues)
  - Simple to edit: one place controls spacing + control-bar height
*/

:root {
  --controls-h: 64px; /* bottom bar height (excluding safe area) */
  --stage-pad: 24px;  /* equal spacing around the book */
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: #555;
  overflow: hidden;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
	display: flex;
  justify-content: center;
}

/* Fullscreen container */
.viewport {
  position: fixed;
  inset: 0;
	margin-left: auto !important;
  margin-right: auto !important;
  left: 0 !important;
  right: 0 !important;
  transform-origin: center center !important;
	transition: transform 0.2s ease, left 0.2s ease;
}

/*
  The stage is the "usable" area ABOVE the bottom bar.
  We pin it with top/left/right/bottom so it stays stable on mobile browsers.
*/
.stage {
  position: absolute;
  top: env(safe-area-inset-top);
  left: env(safe-area-inset-left);
  right: env(safe-area-inset-right);
  bottom: calc(var(--controls-h) + env(safe-area-inset-bottom));

  display: flex;
  align-items: center;
  justify-content: center;

  padding: var(--stage-pad);
  box-sizing: border-box;

  /* JS updates this to fit the available space */
  --book-scale: 1;
}

.flipbook {
  width: 922px;
  height: 650px;

  /* Responsive fit without changing Turn.js' internal size */
  transform: scale(var(--book-scale));
  transform-origin: center center;

  /* Smoother during turning */
  will-change: transform;

  /* Enable swipe/drag handling (we preventDefault on horizontal drags in JS) */
  touch-action: pan-y;
  cursor: grab;
}

.flipbook:active { cursor: grabbing; }

.page {
  width: 461px;
  height: 650px;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.flipbook .page {
  box-shadow: 0 0 20px rgba(0,0,0,.2);
}

/* Optional: reduce motion */
@media (prefers-reduced-motion: reduce) {
  .flipbook { will-change: auto; }
}

/* Side nav buttons */
.nav-btn {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 999px;
  background: rgba(0,0,0,0.35);
  color: #fff;
  font-size: 22px;
  line-height: 56px;
  text-align: center;

  cursor: pointer;
  user-select: none;
  z-index: 20;
}

.nav-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.nav-prev { left: 28px; }
.nav-next { right: 28px; }

/* Bottom bar */
.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--controls-h);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  box-sizing: border-box;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: center;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(6px);
  z-index: 30;
}

.page-label {
  color: #fff;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  min-width: 78px;
  text-align: center;
  opacity: 0.9;
}

.page-slider {
  width: 100%;
  accent-color: #fff;
  height: 28px; /* easier to grab on touch */
}

/* Mobile tweaks */
@media (max-width: 600px) {
  :root {
    --controls-h: 56px;
    --stage-pad: 16px;
  }

  .nav-btn {
    width: 48px;
    height: 48px;
    font-size: 24px;
    line-height: 48px;
  }

  .nav-prev { left: 10px; }
  .nav-next { right: 10px; }
  .page-label { min-width: 70px; }
	
	#flipbook {
    max-height: 70vh;
  }
}
