/* --- Page background --- */
body {
  background: #e6e1dc url("/images/paper-fibers.png") repeat;
  background-size: 300px 300px;
  -webkit-font-smoothing:antialiased;
  -moz-osx-font-smoothing:grayscale;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

main { flex: 1; }

/* ---------- Top header/nav ---------- */
header {
  background: transparent;
  padding: 16px 0;
}

header .logo {
  font-size: 1.8rem;
  font-weight: 900;
  color: #1630ff;
  text-decoration: none;
}

header .logo span { color: #000; }

/* ---------- Story Header (title + prev/next) ---------- */
.story-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 20px 0;
}

.story-header .section-title {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 800;
  text-align: center;
  flex: 1;
  letter-spacing: -0.4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #1630ff;
}

.story-header .btn {
  flex: 0 0 auto;
  min-width: 110px;
  padding: 10px 16px;
}

/* --- Disabled Button Style --- */
.story-header .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none; /* Override hover effects */
    box-shadow: none; /* Override hover effects */
}

/* ---------- Mobile: shrink header + nav ---------- */
@media (max-width: 768px) {
  header {
    padding: 8px 0;
  }

  header .logo {
    font-size: 1.3rem;
  }

  .story-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    margin: 8px 0;
  }

  .story-header .section-title {
    flex: 1 1 auto;
    text-align: center;
    font-size: 1rem;
    margin: 0 6px;
    white-space: normal;
  }

  .story-header .btn {
    flex: 0 0 auto;
    min-width: 96px;
    padding: 6px 12px;
    font-size: 0.9rem;
  }
}

@media (max-width: 420px) {
  header .logo { font-size: 1.1rem; }
  .story-header .section-title { font-size: 0.9rem; }
  .story-header .btn {
    min-width: 84px;
    font-size: 0.8rem;
    padding: 5px 10px;
  }
}

/* ---------- Book two-page spread (desktop) ---------- */
.book-view {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto;
  perspective: 2000px;
  height: calc((100vh - 160px) * 0.9);
  max-width: 100%;
  aspect-ratio: 1792 / 1280;
  gap: 24px;
}

.page {
  flex: 1 1 50%;
  height: 100%;
  background: #fdfdfb url("/images/paper-fibers.png") repeat;
  background-size: 400px 400px;
  border-radius: 12px;
  box-shadow:
    inset 6px 0 12px -8px rgba(0,0,0,0.18),
    inset -6px 0 12px -8px rgba(0,0,0,0.08),
    0 12px 28px rgba(0,0,0,0.22);
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- Image loading styles --- */
#page-image {
    transition: opacity 0.3s ease-in-out;
}

.loading-spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border-left-color: #1630ff;
    animation: spin 1s ease-in-out infinite;
    position: absolute;
    display: none; /* Hidden by default */
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.page.image-page img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px 0 0 12px;
  display: block;
}

.page.text-page {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 6% 7% 60px;
  background-color: #f4f4f4;
  color: #111;
  font-size: clamp(1.05rem, 1rem + 0.4vw, 1.5rem);
  line-height: 1.95;
  overflow-y: auto;
}

.page.text-page p { margin: 0; white-space: pre-wrap; }

.page::before {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.65), rgba(255,255,255,0.0) 60%);
  pointer-events: none;
  mix-blend-mode: screen;
  opacity: 0.9;
}

/* ---------- Mobile: book-view stacked ---------- */
@media (max-width: 768px) {
  .book-view {
    flex-direction: column;
    height: auto;
    aspect-ratio: auto;
    gap: 10px;
    max-width: 100%;
    width: 100%;
    padding: 0 8px;
    box-sizing: border-box;
  }

  .page {
    width: 100%;
    height: auto;
    border-radius: 12px;
    box-shadow: 0 8px 18px rgba(0,0,0,0.15);
  }

  .page.image-page img {
    width: 80%;
    height: auto;
    aspect-ratio: 892 / 1280;
    object-fit: cover;
    border-radius: 12px;
    display: block;
    margin: 12px auto; /* Centered */
  }

  .page.text-page {
    padding: 12px 12px 30px;
    font-size: 0.95rem;
    line-height: 1.35;
    max-height: 40vh;
    overflow-y: auto;
  }

  .page::before { display: none; }
}

/* ---------- Footer ---------- */
footer {
  text-align: center;
  padding: 10px 0;
  font-size: 0.85rem;
  background: #000;
  color: #fff;
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
}

@media (max-width: 768px) {
  footer { padding: 1px 0; font-size: 0.75rem; }
}
