* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  font-family: Georgia, "Times New Roman", serif;
  color: #e2d5bd;
  background:
    radial-gradient(1100px 700px at 50% 12%, #52402e 0%, #3a2c1f 55%, #241a12 100%);
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 14px 20px;
  flex: 0 0 auto;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: normal;
  letter-spacing: 6px;
  text-transform: uppercase;
  color: #e6cfa3;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

#btn-fullscreen {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
}

/* ---------- stage / book ---------- */

#stage {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* StPageFlip forces the #book element itself to width:100%,
   so the fit-to-viewport size is set on this holder instead. */
#book-holder {
  margin: 0 auto;
  filter: drop-shadow(0 16px 28px rgba(0, 0, 0, 0.5));
}

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

.page-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  opacity: 0;
  transition: opacity 0.25s ease;
  user-select: none;
  -webkit-user-drag: none;
}

.page-img.loaded {
  opacity: 1;
}

.page-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: #c3b28c;
}

/* Gutter shadow: darkens each page along the spine so the open
   book reads as two curved sheets meeting in the middle.
   StPageFlip marks pages with --left / --right. */
.page::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.page.--left::after {
  background: linear-gradient(
    to right,
    rgba(66, 44, 22, 0) 82%,
    rgba(66, 44, 22, 0.1) 94%,
    rgba(46, 30, 15, 0.28) 100%
  );
}

.page.--right::after {
  background: linear-gradient(
    to left,
    rgba(66, 44, 22, 0) 82%,
    rgba(66, 44, 22, 0.1) 94%,
    rgba(46, 30, 15, 0.28) 100%
  );
}

/* In single-page (portrait) mode StPageFlip paints the fold of a
   forward-turning page with the page's own image; a real sheet would show
   its blank back. app.js tags that fold with .fold-hide (only when the fold
   duplicates the page beneath it — a backward flip's fold is the incoming
   page and must stay visible). Landscape spreads are left alone. */
.stf__wrapper.--portrait .page.fold-hide .page-img,
.stf__wrapper.--portrait .page.fold-hide .page-placeholder,
.stf__wrapper.--portrait .page.fold-hide .cover-content {
  visibility: hidden;
}

/* ---------- covers ---------- */

.page-cover {
  background:
    radial-gradient(130% 120% at 30% 18%, #7a5539 0%, #5a3a24 55%, #43290f 100%);
  color: #ecd9ab;
}

.page-cover::after {
  background: linear-gradient(
    to left,
    rgba(20, 12, 5, 0) 88%,
    rgba(20, 12, 5, 0.35) 100%
  ) !important;
}

.page-cover-back::after {
  background: linear-gradient(
    to right,
    rgba(20, 12, 5, 0) 88%,
    rgba(20, 12, 5, 0.35) 100%
  ) !important;
}

.cover-content {
  position: absolute;
  inset: 16px;
  border: 1px solid rgba(236, 217, 171, 0.55);
  outline: 1px solid rgba(236, 217, 171, 0.25);
  outline-offset: 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  text-align: center;
  padding: 20px;
}

.cover-title {
  font-size: clamp(20px, 5vmin, 34px);
  font-variant: small-caps;
  letter-spacing: 5px;
  line-height: 1.35;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}

.cover-ornament {
  font-size: clamp(16px, 3.5vmin, 24px);
  color: rgba(236, 217, 171, 0.8);
}

.cover-rule {
  width: 38%;
  height: 1px;
  background: linear-gradient(
    to right,
    transparent,
    rgba(236, 217, 171, 0.7),
    transparent
  );
}

/* ---------- buttons ---------- */

button {
  font-family: inherit;
  color: #e2d5bd;
  background: rgba(236, 217, 171, 0.08);
  border: 1px solid rgba(236, 217, 171, 0.28);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

button:hover {
  background: rgba(236, 217, 171, 0.18);
  border-color: rgba(236, 217, 171, 0.45);
}

/* ---------- bottom bar ---------- */

.bottombar {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 0 16px;
  min-height: 56px;
}

#nav-row {
  display: flex;
  align-items: center;
  gap: 22px;
}

#page-indicator {
  font-size: 14px;
  letter-spacing: 2px;
  color: #d9bd8c;
  min-width: 96px;
  text-align: center;
}

/* ---------- loader ---------- */

/* Full-screen dimming overlay; fades out via .fade-out so the book
   underneath is revealed without any layout shift. */
.loader {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(24, 17, 10, 0.85);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 1;
  transition: opacity 0.7s ease;
}

.loader.fade-out {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(236, 217, 171, 0.15);
  border-top-color: #e6cfa3;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

/* ---------- drop zone ---------- */

.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 40px 50px;
  border: 2px dashed rgba(236, 217, 171, 0.3);
  border-radius: 12px;
  text-align: center;
}

.drop-zone code {
  color: #f0e3c3;
}

.drop-zone .hint {
  margin: 0;
  font-size: 13px;
  color: #ab9878;
}

.file-btn {
  display: inline-block;
  padding: 10px 22px;
  border: 1px solid rgba(236, 217, 171, 0.35);
  border-radius: 6px;
  background: rgba(236, 217, 171, 0.08);
  cursor: pointer;
  transition: background 0.15s ease;
}

.file-btn:hover {
  background: rgba(236, 217, 171, 0.18);
}

.file-btn input {
  display: none;
}

@media (max-width: 640px) {
  .topbar h1 {
    font-size: 16px;
    letter-spacing: 4px;
  }

  #nav-row {
    gap: 14px;
  }
}
