/* ============================================================
   CORAL KINGDOM — kids app styles (ages 5-10)
   ============================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --deep: #023e6b;
  --sea: #0677b8;
  --aqua: #35c2e8;
  --foam: #baf0ff;
  --sand: #ffe9b8;
  --coral: #ff8a5c;
  --coral-dark: #f26a3d;
  --luno-blue: #4aa8ff;
  --gold: #ffd75e;
  --white: #ffffff;
  --card: rgba(255, 255, 255, 0.94);
  --shadow: 0 10px 30px rgba(2, 42, 76, 0.35);
  --radius: 26px;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: "Baloo 2", "Fredoka", "Comic Sans MS", cursive, sans-serif;
  background: linear-gradient(180deg, #0aa3d6 0%, #0677b8 40%, #045187 75%, #023e6b 100%);
  color: var(--deep);
  user-select: none;
  touch-action: manipulation;
}

/* ---------- animated ocean backdrop ---------- */
#ocean-bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }

.sunrays {
  position: absolute; top: -40%; left: 50%; width: 160%; height: 90%;
  transform: translateX(-50%);
  background: conic-gradient(from 180deg at 50% 0%,
    transparent 40%, rgba(255,255,255,.10) 44%, transparent 48%,
    rgba(255,255,255,.14) 52%, transparent 56%,
    rgba(255,255,255,.10) 60%, transparent 64%);
  animation: rays 14s ease-in-out infinite alternate;
}
@keyframes rays { from { transform: translateX(-52%) rotate(-3deg); } to { transform: translateX(-48%) rotate(3deg); } }

.bg-bubble {
  position: absolute; bottom: -60px; border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, rgba(255,255,255,.85), rgba(255,255,255,.12) 60%, rgba(255,255,255,.05));
  animation: rise linear infinite;
}
@keyframes rise {
  from { transform: translateY(0) translateX(0); opacity: .9; }
  50%  { transform: translateY(-55vh) translateX(18px); }
  to   { transform: translateY(-110vh) translateX(-14px); opacity: 0; }
}

.bg-fish { position: absolute; font-size: 30px; animation: swim linear infinite; filter: drop-shadow(0 4px 6px rgba(0,0,0,.2)); }
@keyframes swim {
  from { transform: translateX(-12vw) scaleX(1); }
  49%  { transform: translateX(105vw) scaleX(1); }
  50%  { transform: translateX(105vw) scaleX(-1); }
  99%  { transform: translateX(-12vw) scaleX(-1); }
  to   { transform: translateX(-12vw) scaleX(1); }
}

/* ---------- layout ---------- */
#app {
  position: relative; z-index: 2;
  height: 100dvh; padding-top: 78px;
  display: flex; flex-direction: column; align-items: center;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.screen { width: min(960px, 100%); padding: 12px 16px 40px; animation: pop-in .45s cubic-bezier(.2,1.4,.4,1); }
@keyframes pop-in { from { opacity: 0; transform: scale(.94) translateY(14px); } to { opacity: 1; transform: none; } }

#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(2,62,107,.85), rgba(2,62,107,.55) 70%, transparent);
  backdrop-filter: blur(3px);
}
#topbar.hidden { display: none; }
#topbar-title { color: var(--white); font-weight: 800; font-size: 20px; text-shadow: 0 2px 6px rgba(0,0,0,.35); }
.topbar-right { display: flex; gap: 8px; align-items: center; }

.chip-btn {
  border: none; cursor: pointer; font-size: 22px;
  width: 46px; height: 46px; border-radius: 16px;
  background: rgba(255,255,255,.92); box-shadow: 0 4px 0 rgba(2,42,76,.35);
  transition: transform .12s;
}
.chip-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(2,42,76,.35); }

.star-chip {
  background: var(--gold); color: #7a4d00; font-weight: 800; font-size: 18px;
  padding: 9px 14px; border-radius: 16px; box-shadow: 0 4px 0 rgba(122,77,0,.4);
}

/* ---------- big buttons ---------- */
.big-btn {
  display: inline-block; border: none; cursor: pointer;
  font-family: inherit; font-weight: 800; font-size: 24px; color: #fff;
  padding: 16px 34px; border-radius: 999px;
  background: linear-gradient(180deg, var(--coral), var(--coral-dark));
  box-shadow: 0 7px 0 #b8431e, 0 12px 24px rgba(0,0,0,.25);
  text-shadow: 0 2px 4px rgba(0,0,0,.25);
  transition: transform .12s;
}
.big-btn:active { transform: translateY(5px); box-shadow: 0 2px 0 #b8431e; }
.big-btn.blue { background: linear-gradient(180deg, #55b6ff, #2f8de0); box-shadow: 0 7px 0 #1c64a8, 0 12px 24px rgba(0,0,0,.25); }
.big-btn.blue:active { box-shadow: 0 2px 0 #1c64a8; }
.big-btn.green { background: linear-gradient(180deg, #5ede8a, #2eb45e); box-shadow: 0 7px 0 #1d8140, 0 12px 24px rgba(0,0,0,.25); }
.big-btn.green:active { box-shadow: 0 2px 0 #1d8140; }
.big-btn:disabled { filter: grayscale(.7); opacity: .6; }

/* ---------- title screen ---------- */
.title-hero {
  position: relative; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  border: 5px solid rgba(255,255,255,.85);
}
.title-hero img { width: 100%; display: block; }
.title-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: flex-end; padding: 18px;
  background: linear-gradient(180deg, transparent 45%, rgba(2,40,70,.72));
}
.game-logo { text-align: center; margin-bottom: 8px; }
.game-logo h1 {
  font-size: clamp(38px, 8vw, 64px); font-weight: 800; color: var(--gold); line-height: .95;
  text-shadow: 0 3px 0 #b07400, 0 8px 18px rgba(0,0,0,.5);
  letter-spacing: 1px;
}
.game-logo p { color: #eafaff; font-size: clamp(16px, 3.4vw, 22px); font-weight: 700; text-shadow: 0 2px 6px rgba(0,0,0,.5); }

/* ---------- talking intro stage ---------- */
.intro-stage { margin-top: 18px; text-align: center; }

.speech-bubble {
  position: relative; margin: 0 auto 20px; max-width: 620px; min-height: 86px;
  background: var(--card); border: 4px solid #fff; border-radius: 24px;
  box-shadow: var(--shadow); padding: 16px 20px; cursor: pointer;
  font-size: clamp(17px, 3.6vw, 21px); font-weight: 700; color: var(--deep);
  line-height: 1.45; display: flex; align-items: center; justify-content: center;
}
.speech-bubble::after {
  content: ""; position: absolute; bottom: -16px; width: 0; height: 0;
  border-left: 14px solid transparent; border-right: 14px solid transparent;
  border-top: 18px solid #fff; transition: left .3s;
}
.speech-bubble.from-left::after { left: 24%; }
.speech-bubble.from-right::after { left: 72%; }
.type-caret { animation: caret-blink .7s infinite; color: var(--coral); }
@keyframes caret-blink { 50% { opacity: 0; } }

/* highlighted key words — pop in with a bounce for easy, fun reading */
.pop-word {
  display: inline-block; font-weight: 800; color: var(--coral-dark);
  background: linear-gradient(180deg, #fff3d6, #ffe3a8);
  padding: 0 7px; border-radius: 10px; margin: 0 1px;
  animation: word-pop .45s cubic-bezier(.2,1.6,.4,1);
  box-shadow: 0 2px 0 rgba(242,106,61,.25);
}
.speech-bubble.from-right .pop-word { color: #1c64a8; background: linear-gradient(180deg, #ddf1ff, #bfe4ff); box-shadow: 0 2px 0 rgba(47,141,224,.25); }
@keyframes word-pop { from { transform: scale(.4) rotate(-4deg); opacity: 0; } 70% { transform: scale(1.15) rotate(2deg); } to { transform: scale(1) rotate(0); opacity: 1; } }

.duo-row { display: flex; gap: 16px; justify-content: center; align-items: flex-end; }
.char-portrait {
  position: relative; width: min(44%, 250px); border-radius: 24px; overflow: hidden;
  border: 5px solid #fff; box-shadow: var(--shadow); cursor: pointer;
  transition: transform .3s, filter .3s, border-color .3s, box-shadow .3s;
  animation: float-bob 3.2s ease-in-out infinite alternate;
}
.char-portrait.luno-p { animation-delay: -1.6s; }
@keyframes float-bob { from { translate: 0 0; } to { translate: 0 -10px; } }
.char-portrait img { width: 100%; display: block; aspect-ratio: 3/4; object-fit: cover; }
.char-portrait .name-tag {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  color: #fff; font-weight: 800; font-size: 16px; letter-spacing: 1px;
  padding: 6px 16px; border-radius: 999px; white-space: nowrap;
  text-shadow: 0 2px 4px rgba(0,0,0,.35); box-shadow: 0 4px 10px rgba(0,20,40,.35);
}
.name-tag.tag-ellio { background: linear-gradient(180deg, var(--coral), var(--coral-dark)); }
.name-tag.tag-luno { background: linear-gradient(180deg, #55b6ff, #2f8de0); }

.char-portrait.speaking {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(255,215,94,.45), 0 0 34px rgba(255,215,94,.65), var(--shadow);
  transform: scale(1.05);
  z-index: 2;
}
.char-portrait.dim { filter: brightness(.72) saturate(.75); transform: scale(.96); }

.tap-hint {
  margin-top: 14px; color: #dff4ff; font-weight: 700; font-size: 15px;
  text-shadow: 0 1px 4px rgba(0,0,0,.4); animation: caret-blink 2.4s infinite;
}

.start-pulse { animation: start-pulse 1.1s ease-in-out infinite; }
@keyframes start-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 7px 0 #b8431e, 0 12px 24px rgba(0,0,0,.25); }
  50% { transform: scale(1.07); box-shadow: 0 7px 0 #b8431e, 0 0 34px rgba(255,215,94,.8); }
}

.char-row { display: flex; gap: 14px; margin-top: 16px; flex-wrap: wrap; }
.char-card {
  flex: 1; min-width: 240px; background: var(--card); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); display: flex; gap: 12px; align-items: center;
}
.char-card .avatar { font-size: 44px; }
.char-card h3 { font-size: 20px; margin-bottom: 2px; }
.char-card p { font-size: 15px; line-height: 1.35; color: #22557d; }
.char-card.ellio { border-left: 8px solid var(--coral); }
.char-card.luno { border-left: 8px solid var(--luno-blue); }

.title-actions { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-top: 20px; }

/* ---------- chapter map ---------- */
.map-title { color: #fff; text-align: center; font-size: 30px; font-weight: 800; text-shadow: 0 2px 8px rgba(0,0,0,.4); margin: 8px 0 16px; }
.chapter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }

.chapter-card {
  position: relative; background: var(--card); border-radius: 22px; overflow: hidden;
  box-shadow: var(--shadow); cursor: pointer; border: 4px solid #fff;
  transition: transform .15s;
}
.chapter-card:not(.locked):hover { transform: translateY(-4px) scale(1.02); }
.chapter-card img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: #9fdcf2; }
.chapter-card .ch-body { padding: 10px 12px 12px; }
.chapter-card .ch-num { font-size: 12px; font-weight: 800; color: var(--sea); text-transform: uppercase; letter-spacing: 1px; }
.chapter-card h3 { font-size: 17px; line-height: 1.15; }
.chapter-card .ch-stars { margin-top: 5px; font-size: 15px; letter-spacing: 2px; }

.chapter-card.locked { cursor: default; }
.chapter-card.locked img { filter: grayscale(.9) brightness(.55) blur(1px); }
.lock-overlay {
  position: absolute; top: 0; left: 0; right: 0; aspect-ratio: 16/9;
  display: flex; align-items: center; justify-content: center; font-size: 42px;
  text-shadow: 0 4px 10px rgba(0,0,0,.6);
}

/* ---------- story reader ---------- */
.reader { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; border: 5px solid #fff; }
.reader-img-wrap { position: relative; }
.reader img.chapter-art { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: #9fdcf2; }
.reader-chip {
  position: absolute; top: 12px; left: 12px; background: rgba(2,62,107,.8); color: #fff;
  font-weight: 800; font-size: 14px; padding: 6px 14px; border-radius: 999px;
}
.reader-body { padding: 18px 22px 20px; }
.reader h2 { font-size: clamp(22px, 4.4vw, 30px); color: var(--deep); line-height: 1.1; }
.reader .subtitle { color: var(--sea); font-weight: 700; margin-bottom: 12px; }
.story-text {
  font-size: clamp(20px, 3.8vw, 25px); line-height: 1.7; color: #143a5c; font-weight: 500;
  letter-spacing: .2px; min-height: 130px;
}
.reader-controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.page-dots { display: flex; gap: 6px; flex-wrap: wrap; }
.page-dots span { width: 12px; height: 12px; border-radius: 50%; background: #c8e6f5; }
.page-dots span.on { background: var(--coral); transform: scale(1.2); }

.read-aloud-btn {
  border: none; cursor: pointer; font-family: inherit; font-weight: 800; font-size: 17px;
  padding: 10px 18px; border-radius: 999px; background: #e8f7ff; color: var(--sea);
  border: 3px solid var(--aqua);
}
.read-aloud-btn.playing { background: var(--aqua); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

/* ---------- fact card ---------- */
.fact-card {
  margin-top: 16px; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  background: linear-gradient(160deg, #fffbe8, #ffefc2); border: 5px solid var(--gold);
  padding: 20px 22px;
}
.fact-card .fact-tag { display: inline-block; background: var(--luno-blue); color: #fff; font-weight: 800; padding: 6px 16px; border-radius: 999px; font-size: 15px; margin-bottom: 10px; }
.fact-card h3 { font-size: 24px; margin-bottom: 8px; color: #6b4a00; }
.fact-card p { font-size: 19px; line-height: 1.5; color: #5c4a14; font-weight: 500; }

/* ---------- quiz ---------- */
.quiz-wrap { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; border: 5px solid #fff; }
.quiz-q { font-size: clamp(20px, 4vw, 26px); font-weight: 800; margin-bottom: 16px; color: var(--deep); }
.quiz-opts { display: grid; gap: 12px; }
.quiz-opt {
  border: none; cursor: pointer; font-family: inherit; text-align: left;
  font-size: 19px; font-weight: 700; color: var(--deep);
  background: #e8f7ff; border: 3px solid var(--aqua); border-radius: 18px; padding: 14px 18px;
  transition: transform .12s;
}
.quiz-opt:hover { transform: scale(1.015); }
.quiz-opt.correct { background: #d8ffe3; border-color: #2eb45e; animation: bounce .5s; }
.quiz-opt.wrong { background: #ffe0e0; border-color: #e05252; animation: shake .4s; }
@keyframes bounce { 30% { transform: scale(1.06); } 60% { transform: scale(.98); } }
@keyframes shake { 25% { transform: translateX(-7px); } 50% { transform: translateX(7px); } 75% { transform: translateX(-4px); } }

/* ---------- games shared ---------- */
.game-shell { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 5px solid #fff; overflow: hidden; }
.game-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; background: linear-gradient(90deg, var(--sea), var(--aqua)); color: #fff; }
.game-head h2 { font-size: 21px; }
.game-hud { font-weight: 800; font-size: 18px; background: rgba(255,255,255,.25); padding: 6px 14px; border-radius: 999px; }
.game-area { position: relative; height: min(58vh, 520px); overflow: hidden; background: linear-gradient(180deg, #7fd8f7, #2593c9 70%, #0c6ba3); }
.game-msg { padding: 12px 18px; text-align: center; font-weight: 700; font-size: 17px; color: var(--sea); }

/* bubble pop */
.pop-bubble {
  position: absolute; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; cursor: pointer; border: none; font-family: inherit;
  background: radial-gradient(circle at 32% 28%, rgba(255,255,255,.95), rgba(190,235,255,.55) 55%, rgba(140,215,255,.35));
  box-shadow: inset 0 0 14px rgba(255,255,255,.7), 0 4px 12px rgba(0,40,80,.2);
  animation: bob 2.2s ease-in-out infinite alternate;
}
@keyframes bob { from { transform: translateY(0); } to { transform: translateY(-14px); } }
.pop-bubble .inner { font-size: 30px; pointer-events: none; }
.pop-splash { position: absolute; font-size: 34px; pointer-events: none; animation: splash .5s forwards; }
@keyframes splash { from { transform: scale(.5); opacity: 1; } to { transform: scale(1.8); opacity: 0; } }

/* memory */
.mem-grid { display: grid; gap: 10px; padding: 16px; grid-template-columns: repeat(4, 1fr); height: 100%; align-content: center; }
.mem-card { perspective: 600px; cursor: pointer; border: none; background: none; padding: 0; aspect-ratio: 3/3.4; }
.mem-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .4s; }
.mem-card.flip .mem-inner { transform: rotateY(180deg); }
.mem-face {
  position: absolute; inset: 0; border-radius: 14px; display: flex; align-items: center; justify-content: center;
  font-size: clamp(26px, 7vw, 44px); backface-visibility: hidden; box-shadow: 0 4px 10px rgba(0,30,60,.25);
}
.mem-back { background: linear-gradient(160deg, var(--sea), var(--aqua)); color: #fff; font-size: 26px; }
.mem-front { background: #fff; transform: rotateY(180deg); border: 3px solid var(--aqua); }
.mem-card.matched .mem-front { background: #d8ffe3; border-color: #2eb45e; animation: bounce .5s; }

/* treasure catch */
#catcher {
  position: absolute; bottom: 6px; width: 92px; height: 60px; font-size: 52px; text-align: center;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.3)); pointer-events: none; line-height: 60px;
}
.faller { position: absolute; font-size: 36px; pointer-events: none; filter: drop-shadow(0 3px 4px rgba(0,0,0,.25)); }

/* ---------- celebration ---------- */
#confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
.confetti { position: absolute; font-size: 26px; animation: confetti-fall linear forwards; }
@keyframes confetti-fall {
  from { transform: translateY(-8vh) rotate(0); opacity: 1; }
  to   { transform: translateY(110vh) rotate(540deg); opacity: .6; }
}

.modal-veil {
  position: fixed; inset: 0; z-index: 60; background: rgba(2,30,55,.6);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fade-in .3s;
}
@keyframes fade-in { from { opacity: 0; } }
.modal-card {
  background: var(--card); border-radius: var(--radius); border: 5px solid var(--gold);
  box-shadow: var(--shadow); padding: 28px 26px; text-align: center; max-width: 440px; width: 100%;
  animation: pop-in .45s cubic-bezier(.2,1.4,.4,1);
}
.modal-card .modal-emoji { font-size: 58px; }
.modal-card h2 { font-size: 27px; margin: 8px 0 6px; color: var(--deep); }
.modal-card p { font-size: 18px; color: #2a5a82; line-height: 1.4; margin-bottom: 18px; }

.hidden { display: none !important; }

@media (max-width: 520px) {
  .mem-grid { grid-template-columns: repeat(4, 1fr); gap: 7px; padding: 10px; }
  .big-btn { font-size: 20px; padding: 14px 26px; }
}
