@import url('https://fonts.googleapis.com/css2?family=Poetsen+One&display=swap');

body {
  margin: 0;
  padding: 0;
  background: #1a3a1f url('https://www.transparenttextures.com/patterns/natural-paper.png');
  font-family: 'Poetsen One', cursive;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  overflow: hidden;
  transition: background-color 2.5s ease;
}

.book-wrapper {
  perspective: 2000px;
  width: 90vw;
  max-width: 1000px;
  height: 60vh;
  max-height: 600px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 20px auto;
  position: relative;
  z-index: 1;
  transition: width 0.7s ease-in-out, max-width 0.7s ease-in-out;
}

.book-wrapper.cover-mode {
  width: 45vw;
  max-width: 500px;
}

#flipbook {
  width: 100%;
  height: 100%;
  border: 10px solid #5d4037; 
  background: #fdf6e7; 
  border-radius: 12px;
  box-shadow: inset 0 0 8px rgba(0,0,0,0.2), 0 10px 25px rgba(0, 0, 0, 0.4), -8px 0 20px rgba(0, 0, 0, 0.2);
  position: relative;
  overflow: hidden;
  transform-origin: left center;
  /* Stops native browser gestures (like back-swipe) from intercepting our page turns */
  touch-action: pan-y pinch-zoom; 
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

#flipbook.animate-opening {
  transform: rotateY(90deg);
  animation: openBook 1.5s ease-out forwards;
}

@keyframes openBook {
  0% { transform: rotateY(90deg); }
  100% { transform: rotateY(0deg); }
}

#flipbook::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 40px; 
  height: 100%;
  background: linear-gradient(to right, #4e342e 80%, transparent);
  box-shadow: inset -3px 0 8px rgba(0, 0, 0, 0.4);
  z-index: 5;
  pointer-events: none;
}

#flipbook .page {
  width: 100%;
  height: 100%;
  border-radius: 6px;
  background: #fdf6e7 url('https://www.transparenttextures.com/patterns/paper-fibers.png');
  box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.15);
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 20px;
}

.page .text-box {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: hidden;
  padding: 10px;
  box-sizing: border-box;
}

.page .text-box .text {
  font-size: clamp(1rem, 1.2vw, 1.6rem);
  line-height: 1.2; 
  text-align: left;
  color: #44281d; 
  max-width: 90%;
  margin: 0;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.page.image-page .image-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page.image-page .image-container img {
  max-width: 95%;
  max-height: 95%;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.page.cover-page {
  background: #795548; 
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  overflow: hidden;
  transform: scale(1);
  transition: transform 0.3s ease;
}

.page.cover-page:hover {
  transform: scale(1.02);
}

.cover-container {
  width: 100%;
  height: 100%;
  position: relative;
}

.cover-container img {
  width: 100%;
  height: 100%;
  object-fit: contain; 
  filter: brightness(0.95) contrast(1.05);
}

/* --- BUTTONS & CONTROLS CONTAINER --- */
.controls-container {
  position: relative;
  z-index: 10;
  margin-top: 15px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

.nav-controls, .audio-controls {
  display: flex;
  gap: 15px;
  justify-content: center;
}

@media (min-width: 769px) and (orientation: landscape) {
  .controls-container {
    flex-direction: row;
  }
}

.controls-container button {
  font-size: 1.8rem;
  padding: 10px 22px;
  border: 3px solid #795548; 
  background: #d7ccc8; 
  color: #4e342e; 
  border-radius: 50px; 
  cursor: pointer;
  transition: all 0.2s ease-in-out;
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
  /* Make buttons feel more app-like */
  user-select: none;
  touch-action: manipulation; 
}

.controls-container button:hover {
  background: #bcaaa4;
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0,0,0,0.25);
}

.audio-controls button {
  width: 50px;
  height: 50px;
  border-radius: 50%; 
  padding: 0;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.audio-controls button.muted {
  background-color: #ef9a9a;
  color: #fff;
  text-decoration: line-through;
}

/* --- MOBILE SPECIFIC OVERRIDES --- */
@media (max-width: 768px), (orientation: portrait) {
  .nav-controls {
    display: none; 
  }

  .controls-container {
    margin-top: 8px; 
  }

  .audio-controls button {
    width: 40px; 
    height: 40px;
    font-size: 1.1rem;
    border-width: 2px;
  }

  .book-wrapper {
    height: 84vh !important; 
    max-height: none !important; 
    width: 92vw !important;
    max-width: none !important;
  }

  .book-wrapper.cover-mode {
    width: 92vw !important; 
    max-width: none !important;
  }

  .page.combined-page {
    display: flex;
    flex-direction: column;
    padding: 12px;
    box-sizing: border-box; 
    height: 100%;
    gap: 8px; 
  }
  
  .page.combined-page .image-container {
    flex: 0 1 45%; 
    max-height: 45%; 
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0;
  }
  
  .page.combined-page .image-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
  }
  
  .page.combined-page .text-box {
    flex: 1 1 55%; 
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: center; 
    justify-content: center;
    padding: 0 5px;
    box-sizing: border-box;
  }

  .page.combined-page .text-box .text {
    font-size: clamp(0.85rem, 3.6vw, 1.25rem); 
    line-height: 1.15;
    text-align: left;
    margin: 0;
  }
}

/* --- FIREFLIES & PARALLAX --- */
#firefly-canvas {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
}
.parallax-bg {
  position: fixed;
  top: 0;
  left: 0;
  z-index: -10;
  width: 100vw;
  height: 100vh;
  background: url('images/forest.gif') no-repeat center center;
  background-size: cover;
  will-change: transform, filter;
  pointer-events: none;
  transition: filter 3s ease-in-out, background-color 3s ease-in-out;
}

body.daytime .parallax-bg {
  filter: brightness(1) contrast(1);
}

body.nighttime {
    background-color: #0b1028; 
}

body.nighttime .parallax-bg {
  filter: brightness(0.4) contrast(1.2);
}

body.nighttime .text-box .text {
  color: #3b2a24; 
}