/* Riley's First Dental Visit — Storybook Styles (Figma match) */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #FFEED3;
}

img {
  -webkit-user-drag: none;
  user-drag: none;
}

/* ========================================
   Page Container
   ======================================== */

#storybook {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ========================================
   Background Image Layer
   ======================================== */

#page-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  /* Clip per-page art zoom (imageScale, SCRUM-30) to the page bounds. */
  overflow: hidden;
}

#page-background img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

/* ========================================
   Back Button (exit storybook)
   ======================================== */

#back-btn {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  z-index: 20;
  width: 49px;
  height: 49px;
  border: none;
  border-radius: 50%;
  background: transparent;
  padding: 0;
  cursor: pointer;
  transition: transform 0.15s ease;
}

#back-btn:active {
  transform: scale(0.92);
}

#back-btn img {
  width: 100%;
  height: 100%;
  display: block;
}

/* On iPhone (<768px) the native Flutter teal header is shown above the
   storybook and provides the back control, so hide the in-page one to
   avoid duplicate back buttons. iPad (>=768px) has no Flutter header and
   keeps this button. (The Read-to-Me button no longer needs special
   handling here — it lives in the nav bar now, immune to header overlap.) */
@media (max-width: 767px) {
  #back-btn {
    display: none;
  }
}

/* ========================================
   Text Panel (bottom card)
   ======================================== */

#text-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  background: #FFEED3;
  border-top-left-radius: 23px;
  border-top-right-radius: 23px;
  box-shadow: 0 -4px 45px rgba(0, 0, 0, 0.25);
  padding: 24px 20px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  min-height: 30vh;
  max-height: 42vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

#story-text {
  font-family: 'Poppins', sans-serif;
  font-size: clamp(18px, 4.5vw, 24px);
  line-height: 1.45;
  color: #1a1a1a;
  text-align: center;
  font-weight: 400;
  padding: 0 8px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Hide text panel on cover (full-screen play overlay takes over) */
#storybook.cover-page #text-panel {
  display: none;
}

/* On interactive pages, the text panel keeps its full story-page chrome
   (cream bg, shadow, padding, min/max-height) so all three interactive
   activities share the same visual structure as story pages. The inner
   story-text and read-to-me toggle stay hidden (no narration on activity
   pages). justify-content:flex-end keeps the nav-bar pinned to the bottom
   of the tray (since #story-text is hidden, the default space-between
   alone would float the nav-bar to the top of the panel). */
#storybook.interactive-page #text-panel {
  justify-content: flex-end;
}
#storybook.interactive-page #story-text,
#storybook.interactive-page #read-to-me-btn {
  display: none;
}

/* Round directional dial for the chair activity. Lives inside #text-panel,
   absolutely positioned at the top-center of the cream tray so it sits
   above the nav-bar. Hidden by default; shown only when chair is active. */
#chair-dial {
  display: none;
}
#storybook.activity-chair-control #chair-dial {
  display: block;
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 140px;
  height: 140px;
  background: url("../images/interactive/chair/chair-dial.png") center/contain no-repeat;
  touch-action: none; /* let chair.js own gesture handling */
  -webkit-user-select: none;
  user-select: none;
}

/* ========================================
   Cover Page Overlay
   ======================================== */

#cover-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 15;
  height: 35%;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 20px;
  padding-top: 0;
  padding-bottom: 55px;
}

#storybook.cover-page #cover-overlay {
  display: flex;
}

#cover-play-btn {
  width: 162px;
  height: 162px;
  order: -1;
  border: none;
  border-radius: 50%;
  background: transparent;
  padding: 0;
  margin-bottom: -12px;
  cursor: pointer;
  transition: transform 0.15s ease;
}

#cover-play-btn:active {
  transform: scale(0.92);
}

#cover-play-btn img {
  width: 100%;
  height: 100%;
  display: block;
}

#cover-title {
  max-width: 80%;
  max-height: 45%;
  object-fit: contain;
  margin-top: 25px;
}

/* ========================================
   Navigation Bar (inside text panel)
   ======================================== */

#nav-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding-top: 12px;
}

#nav-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 12px;
}

#page-indicator {
  font-family: 'Poppins', sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: #AEA5A5;
  white-space: nowrap;
}

/* ========================================
   Progress Bar
   ======================================== */

#progress-track {
  width: 100%;
  max-width: 219px;
  height: 14px;
  background: #DEDEDE;
  border-radius: 151px;
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  background: #FF9317;
  border-radius: 70px;
  transition: width 0.3s ease;
  min-width: 14px;
}

/* ========================================
   Navigation Arrows (inside nav bar)
   ======================================== */

.nav-arrow {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: transparent;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

.nav-arrow:active {
  transform: scale(0.92);
}

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

.nav-arrow:disabled:active {
  transform: none;
}

.nav-arrow img {
  width: 100%;
  height: 100%;
  display: block;
}

/* ========================================
   Read-to-Me Button
   ======================================== */

/* Read-to-me toggle: floats just above the bottom bar's top-right edge,
   hovering over the art. Anchored to #text-panel (a positioned ancestor)
   so it tracks the panel's top edge regardless of the panel's dynamic
   height. z-index keeps it above the art. .hidden hides it on
   cover/interactive pages. No JS — bound by id. */
#read-to-me-btn {
  position: absolute;
  top: -56px; /* 44px button + 12px gap above the panel's top edge */
  right: 16px;
  z-index: 11; /* above #text-panel (z-index:10) and the art */
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #00B5B5;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

#read-to-me-btn:active {
  transform: scale(0.92);
}

#read-to-me-btn img {
  width: 100%;
  height: 100%;
  display: block;
}

#read-to-me-btn.hidden {
  display: none;
}

/* Tap feedback (SCRUM-22): a soft teal pulse acknowledges a replay tap.
   (Was a 50ms flash to white, which read as a rendering glitch. The color
   transition lives in the consolidated #story-text rule below.) */
#story-text.replay-flash {
  color: #00B5B5;
}

/* Next-button attention pulse (SCRUM-23): toggled by the engine when a
   page's narration finishes and read-to-me is on. Gentle breathing scale;
   removed on tap or navigation. */
@keyframes next-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.18); }
}

#next-arrow.pulse-attention {
  animation: next-pulse 1.2s ease-in-out infinite;
}

/* Tool discoverability pulse (SCRUM-31): a soft breathing scale used as the
   reference feel for the canvas-drawn tool pulse in suction.js and
   cleaning.js. Those activities implement the same rhythm (1.0↔1.08 scale,
   1.2s ease-in-out, stops on first interaction) directly in their render
   loops — this class is available if any DOM tool ever needs the same cue. */
@keyframes tool-pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.08); }
}

.tool-pulse-attention {
  animation: tool-pulse 1.2s ease-in-out infinite;
  transform-origin: center;
}

/* ========================================
   Interactive Page Container
   ======================================== */

#interactive-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  display: none;
}

#storybook.interactive-page #interactive-container {
  display: block;
}

#storybook.interactive-page #page-background {
  display: none;
}

/* ========================================
   Loading State
   ======================================== */

#loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #FFEED3;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transition: opacity 0.3s ease;
}

#loading.hidden {
  opacity: 0;
  pointer-events: none;
}

#loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(0, 181, 181, 0.2);
  border-top-color: #00B5B5;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* ========================================
   Page Transition
   ======================================== */

/* Page content fade transition (art + text only).
   SCRUM-21: fade-IN decelerates (ease-out) so the new page settles in
   smoothly; fade-OUT accelerates (ease-in) via the .page-fading-out class
   the engine adds for the outgoing half of the transition. */
#page-background img {
  transition: opacity 0.25s ease-out;
}

#story-text {
  transition: opacity 0.25s ease-out, color 0.2s ease;
}

#storybook.page-fading-out #page-background img {
  transition-timing-function: ease-in;
}

#storybook.page-fading-out #story-text {
  transition-timing-function: ease-in, ease;
}

/* ========================================
   Ending Page Overlay (SCRUM-32)
   ======================================== */

/* Shown only on the final "the-end" page. The cover art is the page
   background; this card sits near the bottom, mirroring the cover
   overlay's placement and the leave-card's look. */
#ending-overlay {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 20px;
  padding-bottom: max(48px, env(safe-area-inset-bottom));
}

#storybook.ending-page #ending-overlay {
  display: flex;
}

/* Like the cover page, the ending page replaces the text panel with its
   own overlay (Read Again / All Done are the navigation here). */
#storybook.ending-page #text-panel {
  display: none;
}

#ending-card {
  background: #FFEED3;
  border-radius: 24px;
  padding: 28px 24px;
  max-width: 340px;
  width: 100%;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.25);
  text-align: center;
  font-family: 'Poppins', sans-serif;
  animation: ending-pop 0.35s ease-out;
}

@keyframes ending-pop {
  from {
    transform: translateY(16px) scale(0.96);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

#ending-title {
  margin: 0 0 8px;
  font-size: 34px;
  font-weight: 700;
  color: #FF7639;
}

#ending-message {
  margin: 0 0 20px;
  font-size: 17px;
  line-height: 1.4;
  color: #1a1a1a;
}

#ending-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

#ending-buttons button {
  flex: 1;
  padding: 14px 16px;
  border-radius: 24px;
  font-family: 'Poppins', sans-serif;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  border: none;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

#ending-buttons button:active {
  transform: scale(0.96);
}

#ending-restart-btn {
  background: #00B5B5;
  color: white;
}

#ending-done-btn {
  background: #FF7639;
  color: white;
}

/* ========================================
   Leave-the-Story Confirmation Overlay
   ======================================== */

#leave-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#leave-overlay.visible {
  display: flex;
}

#leave-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#leave-card {
  position: relative;
  background: #FFEED3;
  border-radius: 24px;
  padding: 28px 24px;
  max-width: 340px;
  width: 100%;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.25);
  text-align: center;
  font-family: 'Poppins', sans-serif;
}

#leave-title {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
  color: #1a1a1a;
}

#leave-message {
  margin: 0 0 20px;
  font-size: 16px;
  color: #4a4a4a;
}

#leave-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

#leave-buttons button {
  flex: 1;
  padding: 12px 16px;
  border-radius: 24px;
  font-family: 'Poppins', sans-serif;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  border: none;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

#leave-buttons button:active {
  transform: scale(0.96);
}

#leave-confirm-btn {
  background: #00B5B5;
  color: white;
}

#leave-cancel-btn {
  background: white;
  color: #00B5B5;
  border: 2px solid #00B5B5;
}

/* ========================================
   Responsive Adjustments
   ======================================== */

@media (min-width: 768px) {
  #page-background img {
    object-position: center top;
  }

  #text-panel {
    min-height: 20vh;
    max-height: 28vh;
    padding: 24px 40px;
  }

  #story-text {
    max-width: 600px;
    margin: 0 auto;
  }

  .nav-arrow {
    width: 52px;
    height: 52px;
  }

  #back-btn {
    width: 56px;
    height: 56px;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  #text-panel {
    min-height: 35vh;
    max-height: 50vh;
    padding: 16px 20px;
  }

  #story-text {
    font-size: clamp(14px, 3vw, 18px);
  }

  .nav-arrow {
    width: 36px;
    height: 36px;
  }
}

/* ========================================
   Activity Canvas
   ======================================== */

#activity-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ========================================
   Placeholder Activity
   ======================================== */

.placeholder-activity {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #00B5B5 0%, #00ACAC 100%);
  color: white;
  text-align: center;
  padding: 20px;
}

.placeholder-title {
  font-family: 'Poppins', sans-serif;
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 12px;
}

.placeholder-subtitle {
  font-family: 'Poppins', sans-serif;
  font-size: 18px;
  opacity: 0.8;
  margin-bottom: 32px;
}

.placeholder-btn {
  font-family: 'Poppins', sans-serif;
  padding: 16px 32px;
  font-size: 18px;
  border: 2px solid white;
  background: transparent;
  color: white;
  border-radius: 30px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.placeholder-btn:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.1);
}
