/* 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;
}

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

/* ---------- 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 ---------- */

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

.dots { display: flex; gap: 9px; }

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.4);
}

.dot.current { background: var(--white); }

/* ---------- 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;
}

.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;
}
