/* =====================================================
   Story Times — child-friendly, responsive stylesheet
   Flexbox/Grid layout, big touch targets, playful colors
   ===================================================== */

:root {
  --abby: #7c4dff;        /* purple */
  --abby-light: #ede7ff;
  --bella: #ff4d94;       /* pink */
  --bella-light: #ffe7f1;
  --sky1: #a5d8ff;
  --sky2: #fff3bf;
  --ink: #35315e;
  --radius: 28px;
  --shadow: 0 10px 30px rgba(53, 49, 94, .18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Comic Sans MS", "Chalkboard SE", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  min-height: 100vh;
  background: linear-gradient(160deg, var(--sky1), var(--sky2));
}

.hidden { display: none !important; }

/* ---------------- Landing page ---------------- */

.landing {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
  position: relative;
}

.landing-card {
  background: rgba(255,255,255,.85);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 48px 32px;
  text-align: center;
  max-width: 760px;
  width: 100%;
  z-index: 1;
}

.site-title { font-size: clamp(2.2rem, 6vw, 3.5rem); }
.tagline { font-size: 1.2rem; margin: 12px 0 32px; }

/* Two big buttons, side by side on wide screens, stacked on phones */
.child-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 24px;
}

.child-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 32px 16px;
  border-radius: var(--radius);
  text-decoration: none;
  color: #fff;
  box-shadow: var(--shadow);
  transition: transform .15s ease;
}
.child-btn:hover { transform: scale(1.05) rotate(-1deg); }
.child-btn .emoji { font-size: 3.2rem; }
.child-btn .name { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.child-btn .age { font-size: .95rem; opacity: .9; }

.child-btn.abby  { background: linear-gradient(145deg, var(--abby), #b388ff); }
.child-btn.bella { background: linear-gradient(145deg, var(--bella), #ff8ab8); }

.footer-note { margin-top: 32px; opacity: .7; }

/* Floating background emoji */
.float { position: absolute; font-size: 2.5rem; animation: drift 12s ease-in-out infinite; opacity: .8; }
.f1 { top: 8%;  left: 6%; }
.f2 { top: 15%; right: 8%;  animation-delay: -3s; }
.f3 { bottom: 20%; left: 10%; animation-delay: -6s; }
.f4 { bottom: 12%; right: 12%; animation-delay: -2s; }
.f5 { top: 45%; left: 2%;  animation-delay: -8s; }
.f6 { top: 55%; right: 3%; animation-delay: -5s; }
@keyframes drift {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50%      { transform: translateY(-22px) rotate(6deg); }
}

/* ---------------- Story page ---------------- */

.storybody {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
}

.home-link {
  align-self: flex-start;
  text-decoration: none;
  font-size: 1.1rem;
  background: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  color: var(--ink);
  margin-bottom: 12px;
}

/* Loading */
.loading { text-align: center; margin-top: 18vh; font-size: 1.3rem; }
.spinner { font-size: 4rem; animation: bounce 1s infinite alternate ease-in-out; }
@keyframes bounce { to { transform: translateY(-18px) rotate(8deg); } }

/* Start gate */
.start-gate { margin-top: 20vh; text-align: center; }

/* Book */
.book {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.story-title { font-size: clamp(1.5rem, 5vw, 2.4rem); text-align: center; }

.page-card {
  background: #fffef8;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 32px 36px;
  width: 100%;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  border: 6px solid #fff;
}

/* AI illustration */
.illustration-wrap {
  width: 100%;
  aspect-ratio: 8 / 5;
  border-radius: 20px;
  overflow: hidden;
  background: linear-gradient(145deg, #f1ecff, #ffeef6);
  display: flex; align-items: center; justify-content: center;
}
.page-image { width: 100%; height: 100%; object-fit: cover; }
.img-loading { font-size: 1.1rem; opacity: .7; animation: bounce 1s infinite alternate ease-in-out; }

.page-text { font-size: 1.35rem; line-height: 1.7; }
body.theme-bella .page-text { font-size: 1.6rem; line-height: 1.9; } /* bigger for the 5-year-old */

/* Controls */
.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  gap: 12px;
  flex-wrap: wrap;
}

.nav-btn, .icon-btn, .big-btn {
  font-family: inherit;
  font-size: 1.1rem;
  border: none;
  border-radius: 999px;
  padding: 14px 22px;
  cursor: pointer;
  box-shadow: var(--shadow);
  background: #fff;
  color: var(--ink);
  transition: transform .12s ease;
}
.nav-btn:hover, .icon-btn:hover, .big-btn:hover { transform: scale(1.06); }
.nav-btn:disabled { opacity: .35; cursor: default; transform: none; }

.audio-controls { display: flex; gap: 10px; }

.big-btn {
  font-size: 1.4rem;
  padding: 18px 34px;
  color: #fff;
  background: linear-gradient(145deg, #ff9f1c, #ffbf69);
  text-decoration: none;
  display: inline-block;
}

.page-indicator { opacity: .6; }

/* Per-child theming */
body.theme-abby  .page-card { border-color: var(--abby-light); }
body.theme-abby  .story-title { color: var(--abby); }
body.theme-bella .page-card { border-color: var(--bella-light); }
body.theme-bella .story-title { color: var(--bella); }

/* ---------------- Games ---------------- */

.game-area {
  width: 100%;
  max-width: 720px;
  background: #fffef8;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
}

.game-area h2 { font-size: 1.8rem; }

/* Bella: color matching — grid of paint blobs + word targets */
.color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 16px;
  width: 100%;
}
.color-blob {
  height: 90px;
  border-radius: 24px;
  cursor: pointer;
  border: 5px solid #fff;
  box-shadow: var(--shadow);
  transition: transform .12s;
  font-size: 2rem;
  display: flex; align-items: center; justify-content: center;
}
.color-blob:hover { transform: scale(1.06); }
.color-blob.selected { outline: 6px dashed var(--ink); }
.color-word {
  padding: 18px;
  border-radius: 24px;
  background: #fff;
  box-shadow: var(--shadow);
  font-size: 1.5rem;
  font-weight: 700;
  cursor: pointer;
}
.color-word.matched, .color-blob.matched { opacity: .35; pointer-events: none; }
.color-word.wrong { animation: shake .35s; }
@keyframes shake { 25% {transform: translateX(-8px);} 75% {transform: translateX(8px);} }

/* Abby: spelling scramble — letter tiles */
.tile-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; min-height: 66px; }
.tile {
  width: 56px; height: 56px;
  display: flex; align-items: center; justify-content: center;
  background: var(--abby);
  color: #fff;
  font-size: 1.6rem;
  font-weight: 700;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: var(--shadow);
  border: none;
  font-family: inherit;
  transition: transform .1s;
}
.tile:hover { transform: translateY(-4px); }
.tile.answer { background: #2ec4b6; }
.answer-row { border-bottom: 4px dashed rgba(53,49,94,.25); padding-bottom: 8px; min-width: 240px; }
.game-msg { font-size: 1.2rem; min-height: 1.5em; }
.game-progress { opacity: .6; }

/* ---------------- Celebration ---------------- */

.celebrate {
  position: fixed; inset: 0;
  background: rgba(53,49,94,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.celebrate-inner {
  background: #fff;
  border-radius: var(--radius);
  padding: 48px 40px;
  text-align: center;
  display: flex; flex-direction: column; gap: 18px;
  animation: pop .45s cubic-bezier(.2, 1.6, .4, 1);
  margin: 20px;
}
@keyframes pop { from { transform: scale(.4); opacity: 0; } }

/* Confetti pieces (created in JS) */
.confetti {
  position: fixed;
  top: -20px;
  font-size: 1.6rem;
  z-index: 60;
  animation: fall linear forwards;
  pointer-events: none;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(720deg); }
}

/* ---------------- Small screens ---------------- */
@media (max-width: 520px) {
  .page-card { padding: 24px 18px; }
  .controls { justify-content: center; }
}
