*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f8f7fb;
  --accent: #4a4a4a;
  --accent-hover: #222;
  --text: #333;
  --text-muted: #777;
  --book-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
  --arrow-size: clamp(44px, 4vw, 52px);
  --stage-gap: clamp(16px, 2vw, 28px);
  --app-padding-x: clamp(16px, 3vw, 32px);
  --app-padding-y: clamp(12px, 2vh, 20px);
}

html,
body {
  min-width: 1024px;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ebook-loader {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  background: var(--bg);
  transition: opacity 0.45s ease, visibility 0.45s ease;
}

.ebook-loader.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.ebook-loader__spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(74, 74, 74, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: loader-spin 0.85s linear infinite;
}

@keyframes loader-spin {
  to {
    transform: rotate(360deg);
  }
}

.ebook-loader__bar {
  width: min(320px, 70vw);
  height: 6px;
  border-radius: 999px;
  background: rgba(74, 74, 74, 0.12);
  overflow: hidden;
}

.ebook-loader__bar-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.2s ease;
}

.ebook-loader__text {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.ebook-app--hidden {
  visibility: hidden;
}

.ebook-app {
  width: 100%;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: var(--app-padding-y) var(--app-padding-x) 16px;
  overflow: hidden;
}

.ebook-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: clamp(10px, 1.5vh, 16px);
  flex-shrink: 0;
}

.ebook-title {
  font-size: clamp(0.8rem, 1vw, 0.95rem);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text);
}

.page-indicator {
  font-size: clamp(0.75rem, 0.9vw, 0.85rem);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.ebook-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--stage-gap);
  min-height: 0;
  width: 100%;
  max-width: 100%;
}

.book-shell {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  max-width: calc(100% - (var(--arrow-size) * 2) - (var(--stage-gap) * 2));
  max-height: 100%;
  filter: drop-shadow(var(--book-shadow));
}

.book,
.book .stf__parent,
.book .stf__wrapper,
.book .stf__block {
  width: 100%;
  height: 100%;
}

.book {
  background: transparent;
  display: block;
}

/* Page-flip library overrides */
.stf__parent {
  border-radius: 2px;
}

.stf__wrapper {
  width: 100%;
  height: 100%;
}

.stf__block {
  border-radius: 2px;
  width: 100% !important;
  height: 100% !important;
}

.stf__shadow,
.stf__outerShadow,
.stf__innerShadow {
  display: none !important;
  opacity: 0 !important;
}

.page {
  background: #fff;
  overflow: hidden;
}

.page--cover .page__inner,
.page--hard .page__inner {
  background: #f5f5f5;
}

.page__inner {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  overflow: hidden;
}

.page__inner img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.page--cover .page__inner img {
  object-fit: cover;
}

.nav-arrow {
  flex-shrink: 0;
  width: var(--arrow-size);
  height: var(--arrow-size);
  border: 1px solid #ccc;
  border-radius: 50%;
  background: #fff;
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s, border-color 0.2s, opacity 0.2s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.nav-arrow:hover:not(:disabled) {
  background: #fafafa;
  color: var(--accent-hover);
  border-color: #999;
}

.nav-arrow:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.ebook-footer {
  flex-shrink: 0;
  text-align: center;
  padding-top: clamp(8px, 1.5vh, 14px);
}

.ebook-footer p {
  font-size: clamp(0.7rem, 0.85vw, 0.75rem);
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* Compact desktop (1024–1280px) */
@media (max-width: 1280px) {
  :root {
    --stage-gap: 16px;
  }
}

/* Large / 4K desktops */
@media (min-width: 1920px) {
  :root {
    --stage-gap: 32px;
  }
}

/* Ultra-wide: limit book from stretching too wide */
@media (min-aspect-ratio: 21/9) {
  .book-shell {
    max-width: min(
      calc(100% - (var(--arrow-size) * 2) - (var(--stage-gap) * 2)),
      2200px
    );
  }
}
