
/* ============================
   RESET & BASE
   ============================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }
body {
  font-family: "Nunito", sans-serif;
  background: #29b6f6;
  color: white;
  min-height: 100vh;
  overflow-x: hidden;
  user-select: none;
}

/* ============================
   ANIMATED BACKGROUND
   ============================ */
.bg-canvas {
  position: fixed; inset: 0; z-index: 0;
  background: linear-gradient(180deg,
    #87CEEB 0%,
    #4FC3F7 20%,
    #29B6F6 45%,
    #81D4FA 70%,
    #B3E5FC 85%,
    #E1F5FE 100%
  );
}
.bg-canvas canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

/* ============================
   HEADER
   ============================ */
.site-header {
  position: relative; z-index: 10;
  text-align: center;
  padding: 20px 16px 0;
}
.header-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.55);
  border: 1px solid rgba(255,255,255,0.8);
  border-radius: 100px;
  padding: 5px 14px;
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.8px; text-transform: uppercase;
  color: #1565C0;
  margin-bottom: 10px;
}
.header-chip span { color: #E65100; }
.site-header h1 {
  font-family: "Fredoka One", cursive;
  font-size: clamp(22px, 4.5vw, 42px);
  background: linear-gradient(135deg, #FFE66D 0%, #FF6B35 40%, #FF85A1 70%, #4ECDC4 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  line-height: 1; margin-bottom: 4px;
}
.site-header p {
  color: rgba(13,71,161,0.75);
  font-size: clamp(10px, 1.4vw, 13px);
  margin-bottom: 14px;
}

/* ============================
   MAIN FLIPBOOK LAYOUT
   ============================ */
.flipbook-shell {
  position: relative; z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2vw, 24px);
  padding: 0 12px;
  width: 100%;
}

/* ============================
   BOOK WRAPPER (3D stage)
   ============================ */
.book-stage {
  perspective: 3000px;
  flex-shrink: 0;
}

.book-wrap {
  position: relative;
  display: flex;
  transform-style: preserve-3d;
  filter: drop-shadow(0 40px 80px rgba(0,0,0,0.8))
          drop-shadow(0 8px 20px rgba(0,0,0,0.5));
}

/* ============================
   PAGES
   ============================ */
.page {
  background: #fff;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
}

.page img {
  display: block;
  width: 100%; height: 100%;
  object-fit: contain;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

/* Page corners & shadow details */
.page-left {
  border-radius: 6px 0 0 6px;
  box-shadow:
    inset -6px 0 20px rgba(0,0,0,0.18),
    inset -1px 0 0 rgba(0,0,0,0.1);
}
.page-right {
  border-radius: 0 6px 6px 0;
  box-shadow:
    inset 6px 0 20px rgba(0,0,0,0.1),
    inset 1px 0 0 rgba(0,0,0,0.05);
}

/* Single page (cover / last page) */
.page-single {
  border-radius: 6px;
  box-shadow:
    inset -4px 0 15px rgba(0,0,0,0.15),
    4px 0 15px rgba(0,0,0,0.3);
}

/* Book spine */
.spine {
  width: 8px;
  background: linear-gradient(to right, #1a1a1a, #444, #2a2a2a);
  box-shadow: inset 2px 0 6px rgba(255,255,255,0.08), inset -2px 0 6px rgba(0,0,0,0.4);
  flex-shrink: 0;
  z-index: 50;
  position: relative;
}

/* Paper texture overlay on pages */
.page::after {
  content: "";
  position: absolute; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 5;
  opacity: 0.5;
}

/* ============================
   FLIP ANIMATION — Realistic Page Turn
   ============================ */

/* The "flipper" is the flying half-page that travels across the spine */
.page-flipper {
  position: absolute;
  top: 0;
  overflow: hidden;
  border-radius: 0;
  z-index: 50;
  transform-style: preserve-3d;
  pointer-events: none;
  background: #faf8f5;
}

/* Front face of the flipper (the page being turned away) */
.page-flipper-front {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}
.page-flipper-front img {
  display: block;
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: center;
}

/* Back face of the flipper (the next page peeking through) */
.page-flipper-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform: rotateY(180deg);
  overflow: hidden;
  background: #f5f2ec;
}
.page-flipper-back img {
  display: block;
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: center;
  transform: scaleX(-1); /* mirror because back-face is reflected */
}

/* Dynamic shadow overlay on the flipper face during flight */
.page-flipper-shadow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background: linear-gradient(to right, rgba(0,0,0,0.25) 0%, transparent 50%);
  opacity: 0;
  transition: opacity 0.05s;
}

/* Shadow cast on the static pages (left/right receiving shadow from flying page) */
.page-shadow-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 30;
  opacity: 0;
  border-radius: inherit;
  transition: opacity 0.1s;
}

/* Keyframes for FORWARD flip (right-page lifts, swings left across spine) */
@keyframes flipperForward {
  0%   {
    transform: rotateY(0deg);
    box-shadow: -8px 0 30px rgba(0,0,0,0.22), 0 8px 20px rgba(0,0,0,0.15);
  }
  15%  {
    transform: rotateY(-25deg);
    box-shadow: -12px 0 40px rgba(0,0,0,0.28), 0 10px 30px rgba(0,0,0,0.2);
  }
  40%  {
    transform: rotateY(-90deg);
    box-shadow: 0 12px 50px rgba(0,0,0,0.35), 0 0 20px rgba(0,0,0,0.2);
  }
  70%  {
    transform: rotateY(-155deg);
    box-shadow: 8px 0 30px rgba(0,0,0,0.22), 0 8px 20px rgba(0,0,0,0.15);
  }
  100% {
    transform: rotateY(-180deg);
    box-shadow: 4px 0 10px rgba(0,0,0,0.1);
  }
}

/* Keyframes for BACKWARD flip (left-page lifts, swings right across spine) */
@keyframes flipperBackward {
  0%   {
    transform: rotateY(0deg);
    box-shadow: 8px 0 30px rgba(0,0,0,0.22), 0 8px 20px rgba(0,0,0,0.15);
  }
  15%  {
    transform: rotateY(25deg);
    box-shadow: 12px 0 40px rgba(0,0,0,0.28), 0 10px 30px rgba(0,0,0,0.2);
  }
  40%  {
    transform: rotateY(90deg);
    box-shadow: 0 12px 50px rgba(0,0,0,0.35), 0 0 20px rgba(0,0,0,0.2);
  }
  70%  {
    transform: rotateY(155deg);
    box-shadow: -8px 0 30px rgba(0,0,0,0.22), 0 8px 20px rgba(0,0,0,0.15);
  }
  100% {
    transform: rotateY(180deg);
    box-shadow: -4px 0 10px rgba(0,0,0,0.1);
  }
}

/* Incoming page slides in smoothly */
@keyframes pageRevealLeft {
  0%   { opacity: 0.3; transform: rotateY(8deg); filter: brightness(0.85); }
  100% { opacity: 1;   transform: rotateY(0deg); filter: brightness(1); }
}
@keyframes pageRevealRight {
  0%   { opacity: 0.3; transform: rotateY(-8deg); filter: brightness(0.85); }
  100% { opacity: 1;   transform: rotateY(0deg); filter: brightness(1); }
}
.page-reveal-left {
  animation: pageRevealLeft 0.28s ease-out forwards;
  transform-origin: right center;
}
.page-reveal-right {
  animation: pageRevealRight 0.28s ease-out forwards;
  transform-origin: left center;
}

/* Page curl corner on hover — bottom-right for right page */
.page-right:not(.no-curl)::before {
  content: "";
  position: absolute;
  bottom: 0; right: 0;
  width: 0; height: 0;
  background: transparent;
  box-shadow: none;
  transition: width 0.35s ease, height 0.35s ease, background 0.35s ease, box-shadow 0.35s ease;
  z-index: 10;
  pointer-events: none;
}
.book-wrap:hover .page-right:not(.no-curl)::before {
  width: 36px; height: 36px;
  background: linear-gradient(
    225deg,
    #ede5d0 30%,
    rgba(210,198,178,0.7) 45%,
    rgba(0,0,0,0.07) 55%,
    transparent 72%
  );
  box-shadow: -4px -4px 8px rgba(0,0,0,0.14);
  border-radius: 0 0 0 4px;
}

/* ============================
   NAV BUTTONS
   ============================ */
.nav-btn {
  background: rgba(255,255,255,0.7);
  border: 2px solid rgba(255,255,255,0.9);
  backdrop-filter: blur(12px);
  color: #0277BD;
  width: clamp(40px, 5vw, 56px);
  height: clamp(40px, 5vw, 56px);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.25s ease;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(16px, 2.5vw, 24px);
  flex-shrink: 0;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15), 0 2px 8px rgba(255,255,255,0.5);
}
.nav-btn:hover:not(:disabled) {
  background: rgba(255,255,255,0.95);
  border-color: #FF6B35;
  color: #FF6B35;
  transform: scale(1.1);
  box-shadow: 0 0 20px rgba(255,107,53,0.35);
}
.nav-btn:active:not(:disabled) { transform: scale(0.93); }
.nav-btn:disabled { opacity: 0.2; cursor: not-allowed; }

/* ============================
   BOTTOM BAR
   ============================ */
.bottom-bar {
  position: relative; z-index: 10;
  display: flex; flex-direction: column;
  align-items: center; gap: 10px;
  padding: 10px 16px 14px;
}

/* Page counter */
.page-counter {
  font-family: "Fredoka One", cursive;
  font-size: clamp(11px, 1.8vw, 15px);
  color: rgba(13,71,161,0.8);
  letter-spacing: 1px;
}
.page-counter strong { color: #E65100; }

/* Dot strip */
.dot-strip {
  display: flex; gap: 5px; flex-wrap: wrap;
  justify-content: center;
  max-width: 500px;
}
.pg-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: rgba(2,119,189,0.3);
  cursor: pointer; transition: all 0.25s;
  border: 1px solid transparent;
}
.pg-dot.active {
  background: #FF6B35;
  transform: scale(1.4);
  box-shadow: 0 0 8px rgba(255,107,53,0.7);
}
.pg-dot:hover:not(.active) { background: rgba(2,119,189,0.6); }

/* Controls row */
.controls-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center;
}

.ctrl-btn {
  background: rgba(255,255,255,0.65);
  border: 2px solid rgba(255,255,255,0.9);
  border-radius: 10px;
  color: #0277BD;
  font-family: "Nunito", sans-serif;
  font-size: clamp(10px, 1.4vw, 12px);
  font-weight: 700;
  padding: 6px 14px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex; align-items: center; gap: 5px;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.ctrl-btn:hover { background: rgba(255,255,255,0.95); color: #FF6B35; border-color: #FF6B35; }
.ctrl-btn.active { background: rgba(255,107,53,0.15); border-color: #FF6B35; color: #BF360C; }

.toc-select {
  background: rgba(255,255,255,0.65);
  border: 2px solid rgba(255,255,255,0.9);
  border-radius: 10px;
  color: #0277BD;
  font-family: "Nunito", sans-serif;
  font-size: clamp(10px, 1.4vw, 12px);
  padding: 6px 10px;
  cursor: pointer;
  outline: none;
  max-width: 200px;
}
.toc-select option { background: #E1F5FE; color: #01579B; }

/* ============================
   TABLE OF CONTENTS PANEL
   ============================ */
.toc-panel {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: min(300px, 85vw);
  background: rgba(225,245,254,0.97);
  backdrop-filter: blur(20px);
  border-right: 2px solid rgba(2,119,189,0.2);
  z-index: 200;
  transform: translateX(-100%);
  transition: transform 0.35s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.toc-panel.open { transform: translateX(0); }
.toc-header {
  padding: 20px 16px 12px;
  border-bottom: 2px solid rgba(2,119,189,0.15);
  display: flex; justify-content: space-between; align-items: center;
}
.toc-header h2 {
  font-family: "Fredoka One", cursive;
  font-size: 18px;
  background: linear-gradient(135deg, #FF6B35, #E65100);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.toc-close {
  background: rgba(2,119,189,0.1); border: none; color: #0277BD;
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  font-size: 16px; display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.toc-close:hover { background: rgba(255,100,100,0.2); color: #c62828; }
.toc-list {
  overflow-y: auto; flex: 1; padding: 8px 0;
  scrollbar-width: thin; scrollbar-color: rgba(2,119,189,0.3) transparent;
}
.toc-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; cursor: pointer;
  transition: all 0.2s; border-left: 3px solid transparent;
}
.toc-item:hover { background: rgba(2,119,189,0.08); }
.toc-item.active { border-left-color: #FF6B35; background: rgba(255,107,53,0.08); }
.toc-thumb {
  width: 36px; height: 50px; border-radius: 3px;
  object-fit: cover; flex-shrink: 0;
  border: 1px solid rgba(2,119,189,0.2);
}
.toc-info { flex: 1; min-width: 0; }
.toc-pg { font-size: 10px; color: rgba(2,119,189,0.6); margin-bottom: 2px; }
.toc-title { font-size: 12px; font-weight: 700; color: #01579B; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============================
   ZOOM OVERLAY
   ============================ */
.zoom-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.92);
  display: none; align-items: center; justify-content: center;
  backdrop-filter: blur(8px);
}
.zoom-overlay.open { display: flex; }
.zoom-img {
  max-width: 95vw; max-height: 95vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 20px 80px rgba(0,0,0,0.8);
  cursor: zoom-out;
}
.zoom-close {
  position: absolute; top: 16px; right: 16px;
  background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2);
  color: white; border-radius: 50%; width: 40px; height: 40px;
  font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.zoom-close:hover { background: rgba(255,100,100,0.3); }
.zoom-nav {
  position: absolute;
  top: 50%; transform: translateY(-50%);
  background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2);
  color: white; border-radius: 50%; width: 44px; height: 44px;
  font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.zoom-nav:hover { background: rgba(255,255,255,0.2); }
.zoom-prev { left: 16px; }
.zoom-next { right: 16px; }

/* ============================
   KEYBOARD HINT
   ============================ */
.key-hint {
  position: relative; z-index: 10;
  text-align: center;
  font-size: 10px; color: rgba(1,87,155,0.5);
  padding-bottom: 10px; letter-spacing: 0.5px;
}

/* Grass strip at bottom */
body::after {
  content: "";
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 38px;
  background:
    radial-gradient(ellipse 6px 18px at 4% 100%, #4CAF50 49%, transparent 50%),
    radial-gradient(ellipse 6px 22px at 8% 100%, #66BB6A 49%, transparent 50%),
    radial-gradient(ellipse 6px 16px at 12% 100%, #43A047 49%, transparent 50%),
    radial-gradient(ellipse 6px 20px at 16% 100%, #4CAF50 49%, transparent 50%),
    radial-gradient(ellipse 6px 18px at 20% 100%, #81C784 49%, transparent 50%),
    radial-gradient(ellipse 6px 22px at 24% 100%, #4CAF50 49%, transparent 50%),
    radial-gradient(ellipse 6px 16px at 28% 100%, #66BB6A 49%, transparent 50%),
    radial-gradient(ellipse 6px 20px at 32% 100%, #43A047 49%, transparent 50%),
    radial-gradient(ellipse 6px 18px at 36% 100%, #4CAF50 49%, transparent 50%),
    radial-gradient(ellipse 6px 22px at 40% 100%, #81C784 49%, transparent 50%),
    radial-gradient(ellipse 6px 16px at 44% 100%, #4CAF50 49%, transparent 50%),
    radial-gradient(ellipse 6px 20px at 48% 100%, #66BB6A 49%, transparent 50%),
    radial-gradient(ellipse 6px 18px at 52% 100%, #43A047 49%, transparent 50%),
    radial-gradient(ellipse 6px 22px at 56% 100%, #4CAF50 49%, transparent 50%),
    radial-gradient(ellipse 6px 16px at 60% 100%, #81C784 49%, transparent 50%),
    radial-gradient(ellipse 6px 20px at 64% 100%, #4CAF50 49%, transparent 50%),
    radial-gradient(ellipse 6px 18px at 68% 100%, #66BB6A 49%, transparent 50%),
    radial-gradient(ellipse 6px 22px at 72% 100%, #43A047 49%, transparent 50%),
    radial-gradient(ellipse 6px 16px at 76% 100%, #4CAF50 49%, transparent 50%),
    radial-gradient(ellipse 6px 20px at 80% 100%, #81C784 49%, transparent 50%),
    radial-gradient(ellipse 6px 18px at 84% 100%, #4CAF50 49%, transparent 50%),
    radial-gradient(ellipse 6px 22px at 88% 100%, #66BB6A 49%, transparent 50%),
    radial-gradient(ellipse 6px 16px at 92% 100%, #43A047 49%, transparent 50%),
    radial-gradient(ellipse 6px 20px at 96% 100%, #4CAF50 49%, transparent 50%),
    linear-gradient(to top, #4CAF50 12px, #66BB6A 12px, transparent 22px);
  z-index: 5;
  pointer-events: none;
}

/* Sun in top-right corner */
.sun-deco {
  position: fixed;
  top: 12px; right: 20px;
  width: 56px; height: 56px;
  z-index: 6; pointer-events: none;
  animation: sunSpin 20s linear infinite;
}
@keyframes sunSpin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.sun-core {
  position: absolute; inset: 10px;
  background: radial-gradient(circle, #FFE066 40%, #FFB300 100%);
  border-radius: 50%;
  box-shadow: 0 0 18px rgba(255,200,0,0.6), 0 0 40px rgba(255,180,0,0.25);
}
.sun-ray {
  position: absolute;
  top: 50%; left: 50%;
  width: 6px; height: 14px;
  background: linear-gradient(to top, #FFB300, #FFE066);
  border-radius: 3px;
  transform-origin: 3px 28px;
}


/* ============================
   LOADING SCREEN
   ============================ */
#loader {
  position: fixed; inset: 0; z-index: 500;
  background: linear-gradient(180deg, #87CEEB 0%, #4FC3F7 60%, #B3E5FC 100%);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; transition: opacity 0.5s;
}
#loader h2 {
  font-family: "Fredoka One", cursive; font-size: 24px;
  background: linear-gradient(135deg, #FFE66D, #FF6B35);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.loader-bar-wrap {
  width: 240px; height: 6px;
  background: rgba(255,255,255,0.1); border-radius: 10px; overflow: hidden;
}
.loader-bar {
  height: 100%; width: 0; border-radius: 10px;
  background: linear-gradient(90deg, #FFE66D, #FF6B35);
  transition: width 0.3s ease;
}
#loader p { font-size: 12px; color: rgba(1,87,155,0.6); }

/* ============================
   FULLSCREEN PAGE LABEL
   ============================ */
.page-label {
  position: absolute;
  bottom: 6px; left: 50%; transform: translateX(-50%);
  font-size: 9px; color: rgba(0,0,0,0.3);
  font-family: "Nunito", sans-serif; font-weight: 700;
  letter-spacing: 0.5px; z-index: 10;
  white-space: nowrap;
}

/* ============================
   RESPONSIVE
   ============================ */
@media (max-width: 640px) {
  .site-header h1 { font-size: 20px; }
  .toc-panel { width: 90vw; }
}
