/* Phonics Launch Reader — UI per Branding Design UI mockups:
   bright blue app, gold logo header + star pill, art in gold-bordered
   rounded card, sentence text in a white card below with speaker button,
   yellow circle pagination arrows + dots, white bottom tab bar with the
   rocket "Read" tab active. */

:root {
  --blue: #2196f3;
  --blue-deep: #1976d2;
  --navy: #1e2a4a;
  --gold: #ffc93c;
  --gold-deep: #f5a623;
  --card-border: #f6b73c;
  --white: #ffffff;
  --font: "Baloo 2", "Segoe UI Rounded", ui-rounded, "Comic Sans MS",
          system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--blue);
  color: var(--navy);
  font-family: var(--font);
  overscroll-behavior: none;
}

#app { height: 100%; }

.app-column {
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #2ba0f7 0%, var(--blue) 45%, var(--blue-deep) 100%);
}

.loading {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--white);
  font-size: 1.4rem;
  font-weight: 700;
}

/* ---------- Header ---------- */

.header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 4px;
}

.header .spacer { width: 40px; flex-shrink: 0; }

.round-btn {
  appearance: none;
  border: none;
  cursor: pointer;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--gold);
  color: var(--navy);
  display: grid;
  place-items: center;
  box-shadow: 0 2px 0 rgba(20, 65, 140, 0.35);
  -webkit-tap-highlight-color: transparent;
}

.round-btn:active { transform: translateY(1px); box-shadow: none; }
.round-btn svg { width: 22px; height: 22px; }

.logo {
  flex: 1;
  text-align: center;
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: 0.04em;
  line-height: 1;
  color: var(--gold);
  text-shadow:
    -2px 0 0 #14418c, 2px 0 0 #14418c, 0 -2px 0 #14418c, 0 2px 0 #14418c,
    -1px -1px 0 #14418c, 1px -1px 0 #14418c, -1px 1px 0 #14418c, 1px 2px 0 #14418c,
    0 4px 6px rgba(0, 0, 0, 0.25);
  text-transform: uppercase;
  user-select: none;
  white-space: nowrap;
}

.star-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  background: var(--gold);
  color: var(--navy);
  font-weight: 800;
  font-size: 0.95rem;
  border-radius: 999px;
  padding: 6px 12px 6px 9px;
  box-shadow: 0 2px 0 rgba(20, 65, 140, 0.35);
}

.star-pill svg { width: 18px; height: 18px; color: #ff9d2e; }

/* ---------- Sliding pages ---------- */

.viewport {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
  touch-action: pan-y;
}

.track {
  display: flex;
  height: 100%;
  will-change: transform;
}

.track.animate { transition: transform 260ms ease-out; }

.slide {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 8px 14px 12px;
}

/* ---------- Art card ---------- */

.art-card {
  border-radius: 22px;
  border: 6px solid var(--card-border);
  overflow: hidden;
  background: var(--white);
  box-shadow: 0 6px 18px rgba(13, 59, 140, 0.3);
  flex-shrink: 0;
}

.art-card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
}

.art-card.interior { aspect-ratio: 3 / 2; }
.art-card.cover    { aspect-ratio: 4 / 4.5; }

/* On the title page the cover fills the slide down to the arrows, with the
   title box overlaid on its bottom edge, so drop the fixed aspect ratio. */
.title-slide { padding-bottom: 8px; }

.title-slide .art-card.cover {
  aspect-ratio: auto;
  flex: 1;
  min-height: 0;
  position: relative;
}

/* ---------- Text card (sentences) ---------- */

.text-card {
  position: relative;
  background: var(--white);
  border-radius: 20px;
  margin-top: 12px;
  padding: 14px 58px 14px 14px;
  box-shadow: 0 6px 18px rgba(13, 59, 140, 0.3);
  flex-shrink: 0;
}

.speaker-btn {
  appearance: none;
  border: none;
  cursor: pointer;
  position: absolute;
  top: 12px;
  right: 12px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--blue);
  color: var(--white);
  display: grid;
  place-items: center;
  box-shadow: 0 2px 0 rgba(13, 59, 140, 0.4);
  -webkit-tap-highlight-color: transparent;
}

.speaker-btn:active { transform: translateY(1px); box-shadow: none; }
.speaker-btn svg { width: 22px; height: 22px; }

.sentence {
  cursor: pointer;
  font-size: clamp(1.1rem, 4.8vw, 1.35rem);
  font-weight: 700;
  line-height: 1.65;
  color: var(--navy);
  border-radius: 10px;
  -webkit-tap-highlight-color: transparent;
}

.sentence:active { background: rgba(33, 150, 243, 0.08); }

.word {
  appearance: none;
  border: none;
  background: transparent;
  font: inherit;
  color: inherit;
  cursor: pointer;
  padding: 0.08em 0.14em;
  margin: 0;
  border-radius: 0.3em;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 90ms ease, color 90ms ease, transform 90ms ease;
}

.word:active,
.word.flash {
  background: var(--gold);
  color: var(--navy);
}

/* karaoke highlight: the word currently being narrated */
.word.speaking {
  background: var(--gold);
  color: var(--navy);
  transform: scale(1.08);
  box-shadow: 0 0 0 2px rgba(245, 166, 35, 0.45);
}

/* ---------- Title page ---------- */

.title-card {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--white);
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: 0 6px 18px rgba(13, 59, 140, 0.35);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.title-card:active { transform: scale(0.99); }

.title-card .book-title {
  font-size: clamp(1.5rem, 7vw, 1.9rem);
  font-weight: 800;
  text-align: center;
  color: var(--navy);
  line-height: 1.15;
}

.title-card .speaker-btn { position: static; flex-shrink: 0; }

/* ---------- Pagination + rocket fuel meter ---------- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 14px 10px;
}

/* The fuel gauge replaces the old progress dots: a bordered bar that fills
   left→right with a heat-map rainbow as the reader advances, capped by a
   rocket that shakes on each page turn and roars to life when fully fueled. */
.fuel-meter {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
}

.fuel-meter.hidden { visibility: hidden; }

.fuel-track {
  position: relative;
  flex: 1;
  height: 24px;
  border: 2.5px solid var(--navy);
  border-radius: 6px;
  overflow: hidden;
  /* full heat-map; the gray overlay below hides the un-fueled right portion */
  background: linear-gradient(90deg,
    #ff2d2d 0%, #ff5a2d 16%, #ff8c1a 32%, #ffb300 48%,
    #ffe000 62%, #c8e021 78%, #6fcf32 92%, #43c12c 100%);
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.18);
}

/* fuel-cell divider lines, one per content page */
.fuel-track::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(90deg,
    transparent 0,
    transparent calc(100% / var(--cells) - 1.5px),
    rgba(0, 0, 0, 0.16) calc(100% / var(--cells) - 1.5px),
    rgba(0, 0, 0, 0.16) calc(100% / var(--cells)));
}

/* gray overlay covering the not-yet-fueled portion on the right */
.fuel-empty {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: calc(100% - var(--fuel, 0) * 1%);
  background: #c7ccd4;
  transition: width 320ms ease-out;
}

.fuel-rocket {
  flex-shrink: 0;
  width: 52px;
  height: 40px;
  margin-left: -8px;
  position: relative;
  z-index: 2;
}

.fuel-rocket svg { width: 100%; height: 100%; display: block; overflow: visible; }

/* exhaust flame flickers continuously, grows when the tank is full */
.fuel-rocket .flame {
  transform-box: fill-box;
  transform-origin: 100% 50%;
  animation: flame-flicker 280ms ease-in-out infinite alternate;
}

@keyframes flame-flicker {
  from { transform: scaleX(0.78) scaleY(0.92); }
  to   { transform: scaleX(1.12) scaleY(1.06); }
}

.fuel-rocket.full .flame { animation-name: flame-flicker-big; }

@keyframes flame-flicker-big {
  from { transform: scaleX(1) scaleY(0.98); }
  to   { transform: scaleX(1.55) scaleY(1.14); }
}

.fuel-rocket .sparkles {
  opacity: 0;
  transition: opacity 300ms ease;
}

.fuel-rocket.full .sparkles {
  opacity: 1;
  animation: sparkle-twinkle 850ms ease-in-out infinite alternate;
}

@keyframes sparkle-twinkle {
  from { opacity: 0.25; }
  to   { opacity: 1; }
}

/* a quick wobble each time a new page loads more fuel */
.fuel-rocket.shake { animation: rocket-shake 460ms ease-in-out; }

@keyframes rocket-shake {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  15%      { transform: translate(-1.5px, 1px) rotate(-4deg); }
  35%      { transform: translate(1.5px, -1px) rotate(4deg); }
  55%      { transform: translate(-1px, -1.5px) rotate(-3deg); }
  75%      { transform: translate(1px, 1.5px) rotate(2deg); }
}

/* ---------- Bottom tab bar ---------- */

.tabbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  background: var(--white);
  border-radius: 22px 22px 0 0;
  padding: 8px 4px max(8px, env(safe-area-inset-bottom));
  box-shadow: 0 -4px 16px rgba(13, 59, 140, 0.25);
}

.tab {
  appearance: none;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 64px;
  color: var(--gold-deep);
  -webkit-tap-highlight-color: transparent;
}

.tab svg { width: 26px; height: 26px; }

.tab .tab-label {
  font-size: 0.66rem;
  font-weight: 700;
  color: #7d8aa5;
}

.tab.active .tab-icon {
  width: 52px;
  height: 52px;
  margin-top: -26px;
  border-radius: 50%;
  background: var(--gold);
  display: grid;
  place-items: center;
  box-shadow: 0 3px 0 rgba(20, 65, 140, 0.3), 0 0 0 5px var(--white);
  color: var(--navy);
}

.tab.active .tab-label { color: var(--navy); }

/* ---------- Audio-stub toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(110px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  max-width: min(92vw, 440px);
  background: var(--navy);
  color: var(--white);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 10;
}

.toast.show {
  opacity: 0.94;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Book picker (Library) ---------- */

.picker {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 16px 20px;
}

.picker h1 {
  color: var(--white);
  text-align: center;
  font-size: 1.4rem;
  font-weight: 800;
  margin: 6px 0 12px;
}

.filters {
  display: flex;
  gap: 10px;
  margin: 0 0 16px;
  flex-wrap: wrap;
}

.filter {
  flex: 1 1 160px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--white);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.filter select {
  font: inherit;
  font-weight: 700;
  color: var(--navy);
  background: var(--white);
  border: 0;
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: 0 4px 14px rgba(13, 59, 140, 0.25);
  cursor: pointer;
  width: 100%;
}

.no-books {
  color: var(--white);
  text-align: center;
  font-weight: 700;
  padding: 24px 8px;
  opacity: 0.9;
}

.book-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--white);
  border-radius: 18px;
  padding: 12px;
  margin-bottom: 14px;
  text-decoration: none;
  color: var(--navy);
  box-shadow: 0 4px 14px rgba(13, 59, 140, 0.3);
}

.book-card:active { transform: scale(0.99); }

.book-card img {
  width: 92px;
  height: 92px;
  object-fit: cover;
  border-radius: 12px;
  border: 3px solid var(--card-border);
  flex-shrink: 0;
}

.book-card .title { font-size: 1.15rem; font-weight: 800; }
.book-card .sub { color: #7d8aa5; font-size: 0.8rem; font-weight: 600; }

/* ---------- Loud error surface ---------- */

.error-panel {
  margin: auto 16px;
  background: var(--white);
  border: 4px solid #c9402f;
  border-radius: 18px;
  padding: 18px 22px;
}

.error-panel h1 { color: #c9402f; font-size: 1.2rem; margin-top: 0; }
.error-panel ul { padding-left: 20px; }
.error-panel li {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.82rem;
  margin: 6px 0;
  word-break: break-word;
}

/* ---------- Wide layout: desktop + tablet/phone landscape ----------
   The mobile-first rules above stay the default. This block only switches on
   for wide or landscape viewports and renders content pages as a two-page book
   spread — two single pages (each keeping the mobile picture-on-top / text-
   below stack) shown side by side. The cover stays a single page. The reader's
   JS builds the matching DOM for this same query, so DOM and styling agree.
   iPad *portrait* (768px, portrait) does NOT match, so it keeps the mobile
   stack; desktop and any landscape tablet/phone get the spread. */
@media (min-width: 1024px), (min-width: 768px) and (orientation: landscape) {
  .app-column { max-width: 1100px; }

  /* The spread slide just centers the open book within its full width. */
  .slide.spread {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding: 8px 20px 12px;
  }

  /* The open book: two paper pages on one warm sheet, joined at a center
     spine. This is what makes the two-page layout read as a real book. */
  .book {
    flex: 1 1 auto;
    max-width: 1000px;
    max-height: 100%;
    display: flex;
    flex-direction: row;
    position: relative;
    border-radius: 14px;
    padding: 16px 14px;
    overflow: hidden;
    background: linear-gradient(180deg, #fffdf8 0%, #f6efdf 100%);
    box-shadow:
      0 14px 34px rgba(13, 59, 140, 0.40),  /* lift off the blue */
      0 0 0 1px rgba(120, 90, 40, 0.10);    /* faint page edge */
  }

  .book .page {
    flex: 1 1 50%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 4px 22px;
  }

  /* The illustration stays framed, like a picture mounted on the page. */
  .book .page .art-card.interior {
    box-shadow: 0 3px 10px rgba(13, 59, 140, 0.18);
  }

  /* The sentence is printed directly on the paper (no white card), so each
     side looks like a real book page rather than a floating card. */
  .book .page .text-card {
    background: transparent;
    box-shadow: none;
    margin-top: 12px;
    padding: 8px 48px 8px 2px;
  }
  .book .page .text-card .speaker-btn { top: 2px; right: 2px; }

  /* The empty filler for an odd last page shows bare paper, no frame. */
  .book .page-empty { box-shadow: none; }

  /* Center spine crease, drawn above the pages. */
  .book::before {
    content: '';
    position: absolute;
    top: 8px;
    bottom: 8px;
    left: 50%;
    width: 2px;
    transform: translateX(-1px);
    background: rgba(120, 90, 40, 0.35);
    z-index: 2;
  }

  /* Gutter shading: the paper darkens as it curves into the binding. A wider,
     deeper valley makes the two facing pages read as clearly separate. */
  .book::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    background: linear-gradient(90deg,
      transparent 38%,
      rgba(86, 60, 22, 0.05) 44%,
      rgba(86, 60, 22, 0.20) 49.4%,
      rgba(86, 60, 22, 0.26) 50%,
      rgba(86, 60, 22, 0.20) 50.6%,
      rgba(86, 60, 22, 0.05) 56%,
      transparent 62%);
  }

  /* Title page: keep the cover + overlaid title, centered and a touch bigger. */
  .title-slide .art-card.cover { max-width: 760px; margin: 0 auto; }

  .logo { font-size: 1.4rem; }
}
