/* The course: map of worlds + lesson flow (read, quiz, play, done). */
body.learn { background: var(--cream); min-height: 100vh; }
.app { padding: 84px clamp(12px, 3vw, 32px) 60px; max-width: 1240px; margin: 0 auto; }
.app-loading { display: grid; place-items: center; min-height: 60vh; font-family: var(--font-hand); font-size: 1.5rem; color: var(--ink-soft); }

/* page transitions (View Transitions API where supported) */
::view-transition-old(root) { animation: vt-out 0.28s ease both; }
::view-transition-new(root) { animation: vt-in 0.42s var(--ease-pop) both; }
@keyframes vt-out { to { opacity: 0; transform: translateY(-14px) scale(0.98); } }
@keyframes vt-in { from { opacity: 0; transform: translateY(18px) scale(0.98); } }
.enter > * { animation: rise-in 0.55s var(--ease-pop) both; }
.enter > *:nth-child(2) { animation-delay: 0.06s; }
.enter > *:nth-child(3) { animation-delay: 0.12s; }
.enter > *:nth-child(4) { animation-delay: 0.18s; }
.enter > *:nth-child(5) { animation-delay: 0.24s; }

/* ---------- map ---------- */
.map-hero {
  display: grid; grid-template-columns: 1fr auto; gap: 20px; align-items: center; background: var(--navy); color: var(--cream);
  border-radius: 30px; padding: clamp(18px, 4vw, 34px); position: relative; overflow: hidden; box-shadow: var(--shadow);
}
.map-hero::before {
  content: ''; position: absolute; inset: 0; opacity: 0.5; pointer-events: none;
  background: radial-gradient(2px 2px at 10% 20%, #fff 50%, transparent 51%), radial-gradient(1.5px 1.5px at 30% 70%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 55% 30%, #f4c652 50%, transparent 51%), radial-gradient(1.5px 1.5px at 75% 60%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 90% 25%, #fff 50%, transparent 51%), radial-gradient(1.5px 1.5px at 45% 85%, #82f0f2 50%, transparent 51%);
  animation: twinkle 4s ease-in-out infinite;
}
.map-hero h1 { color: var(--cream); font-size: clamp(1.9rem, 4.5vw, 3rem); }
.map-hero .robot-helper .bubble { color: var(--ink); }
.star-total { text-align: center; font-family: var(--font-title); }
.star-total .big { font-size: clamp(2.6rem, 7vw, 4.2rem); font-weight: 700; color: var(--gold-hi); line-height: 1; }
.star-total .small { font-size: 0.95rem; opacity: 0.85; }
.map-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

.world { margin-top: 38px; border-radius: 30px; padding: clamp(16px, 3vw, 28px); position: relative; overflow: hidden; }
.world-day { background: linear-gradient(180deg, #d8ecf7, #f7ecd4); }
.world-golden { background: linear-gradient(180deg, #f8d9a6, #f3c08a); }
.world-night { background: linear-gradient(180deg, #2b2f6b, #1d264d); color: var(--cream); }
.world-dawn { background: linear-gradient(180deg, #3c3a78, #a46a9a 55%, #f2b98a); color: var(--cream); }
.world-night h2, .world-dawn h2 { color: var(--cream); }
.world-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.world-head h2 { margin: 0; font-size: clamp(1.6rem, 3.5vw, 2.3rem); }
.world-head .tag { font-family: var(--font-hand); font-size: 1.3rem; opacity: 0.85; }
.lesson-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 18px; }
.lesson-card {
  position: relative; display: flex; flex-direction: column; text-decoration: none; color: var(--ink); background: var(--paper);
  border-radius: 22px; overflow: hidden; box-shadow: 0 10px 24px rgba(0, 0, 0, 0.14); transition: transform 0.25s var(--ease-pop), box-shadow 0.25s;
}
.lesson-card:hover { transform: translateY(-6px) rotate(-0.8deg); box-shadow: 0 18px 34px rgba(0, 0, 0, 0.2); }
.lesson-card .thumb { aspect-ratio: 4 / 3; overflow: hidden; background: #eadfca; }
.lesson-card .thumb img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 0; transition: transform 0.6s ease; }
.lesson-card:hover .thumb img { transform: scale(1.06); }
.lesson-card .num {
  position: absolute; top: 10px; left: 10px; width: 38px; height: 38px; border-radius: 50%; background: var(--navy); color: var(--gold-hi);
  display: grid; place-items: center; font-family: var(--font-title); font-weight: 700; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}
.lesson-card .info { padding: 12px 14px 14px; display: grid; gap: 4px; }
.lesson-card h3 { margin: 0; font-size: 1.15rem; }
.lesson-card .game-line { font-family: var(--font-hand); font-size: 1.1rem; color: var(--ink-soft); }
.stars { font-size: 1.3rem; letter-spacing: 3px; color: #d8cdb6; }
.stars .on { color: var(--gold); text-shadow: 0 0 10px rgba(244, 198, 82, 0.6); display: inline-block; animation: pop-in 0.5s var(--ease-pop) both; }

/* ---------- lesson shell ---------- */
.lesson-top { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; margin-bottom: 18px; }
.back { text-decoration: none; font-family: var(--font-title); font-weight: 600; color: var(--navy); background: var(--paper); border-radius: 999px; padding: 8px 14px; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.12); }
.lesson-title .where { font-family: var(--font-title); font-weight: 600; font-size: 0.85rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold); }
.lesson-title h1 { margin: 0; font-size: clamp(1.4rem, 3.2vw, 2.1rem); }
.steps { display: flex; gap: 6px; background: var(--paper); padding: 5px; border-radius: 999px; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.1); }
.steps button {
  border: 0; background: transparent; border-radius: 999px; padding: 8px 12px; cursor: pointer; font-family: var(--font-title); font-weight: 600;
  font-size: 0.92rem; color: var(--ink-soft); white-space: nowrap;
}
.steps button[aria-current='step'] { background: var(--navy); color: var(--cream); }
.steps button.done::after { content: ' ✓'; color: var(--grass); }
.steps button[aria-current='step'].done::after { color: var(--gold-hi); }

.lesson[data-theme='night'], .lesson[data-theme='dawn'] { --panel-ink: var(--ink); }
body.theme-night { background: linear-gradient(180deg, #1d264d, #121838); }
body.theme-dawn { background: linear-gradient(180deg, #2b2f6b, #6a4a85 60%, #c98a7e); }
body.theme-golden { background: linear-gradient(180deg, #fbe6c2, #f6d2a2); }
body.theme-day { background: linear-gradient(180deg, #e3f1f8, #fcf5eb 40%); }
body.theme-night .lesson-title h1, body.theme-dawn .lesson-title h1 { color: var(--cream); }

/* ---------- read along ---------- */
.read { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(300px, 1fr); gap: 20px; align-items: start; }
.viewer {
  position: relative; height: min(76vh, 760px); border-radius: 26px; overflow: hidden; background: #2a2f55;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25), inset 0 0 0 4px rgba(255, 255, 255, 0.08);
}
.viewer .page { position: absolute; top: 0; left: 0; transform-origin: 0 0; transition: transform 1s cubic-bezier(0.65, 0, 0.35, 1); will-change: transform; }
.viewer .page img { width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
.viewer .focus {
  position: absolute; border: 4px solid var(--gold-hi); border-radius: 18px; box-shadow: 0 0 0 9999px rgba(18, 24, 56, 0.35), 0 0 24px rgba(244, 198, 82, 0.7);
  pointer-events: none; transition: all 1s cubic-bezier(0.65, 0, 0.35, 1);
}
.viewer.whole .focus { box-shadow: 0 0 0 9999px rgba(18, 24, 56, 0.2), 0 0 24px rgba(244, 198, 82, 0.7); }
.viewer-tools { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 8px; }
.viewer-tools button { border: 0; border-radius: 999px; padding: 8px 14px; background: rgba(255, 250, 242, 0.92); color: var(--navy); font-family: var(--font-title); font-weight: 600; cursor: pointer; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.18); }
.panel { background: var(--paper); border-radius: 26px; padding: clamp(18px, 3vw, 28px); box-shadow: var(--shadow); color: var(--ink); position: sticky; top: 80px; }
.sec-dots { display: flex; gap: 6px; margin-bottom: 12px; }
.sec-dots button { width: 14px; height: 14px; border-radius: 50%; border: 0; background: #e3d8c4; cursor: pointer; padding: 0; transition: transform 0.2s var(--ease-pop), background 0.2s; }
.sec-dots button.on { background: var(--gold); transform: scale(1.25); }
.sec-dots button.seen { background: #c9b48a; }
.sec-heading { font-size: clamp(1.4rem, 2.6vw, 1.9rem); }
.sec-text { font-size: 1.22rem; line-height: 1.6; }
.sec-body.swap { animation: rise-in 0.5s var(--ease-pop); }
.term {
  font: inherit; color: var(--navy); background: linear-gradient(180deg, transparent 55%, rgba(244, 198, 82, 0.55) 55%); border: 0; padding: 0 2px;
  border-radius: 3px; cursor: pointer; font-weight: 700; transition: background 0.2s;
}
.term:hover, .term[aria-expanded='true'] { background: rgba(244, 198, 82, 0.6); }
.speech { display: grid; gap: 8px; margin: 10px 0 4px; }
.speech-line { display: flex; gap: 10px; align-items: flex-start; }
.speech-line .who { flex: none; width: 40px; height: 40px; border-radius: 50%; background: #e8eefb; display: grid; place-items: center; overflow: hidden; }
.speech-line .who img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 8%; }
.speech-line .say { background: #f1ecff; border-radius: 16px; padding: 8px 12px; font-family: var(--font-hand); font-size: 1.2rem; line-height: 1.3; }
.speech-line.kid .say { background: #e3f1fb; }
.speech-line.robot .say { background: #e5fbfb; }
.panel-nav { display: flex; gap: 10px; justify-content: space-between; margin-top: 18px; flex-wrap: wrap; }
.speak-btn[aria-pressed='true'] { background: var(--navy); color: var(--cream); }
.your-turn { margin-top: 16px; }
.your-turn b { font-family: var(--font-title); color: var(--red); display: block; font-size: 1rem; letter-spacing: 0.05em; }

.glossary-pop {
  position: absolute; z-index: 80; width: min(320px, calc(100vw - 24px)); background: var(--navy); color: var(--cream); border-radius: 18px;
  padding: 14px 16px; box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35); animation: pop-in 0.3s var(--ease-pop); font-size: 1.02rem;
}
.glossary-pop h4 { margin: 0 0 4px; font-family: var(--font-title); color: var(--gold-hi); font-size: 1.2rem; }
.glossary-pop .more { color: #cfd6ff; margin-top: 6px; }
.glossary-pop .row { display: flex; gap: 8px; margin-top: 10px; }
.glossary-pop button { border: 0; border-radius: 999px; padding: 5px 12px; background: rgba(255, 255, 255, 0.14); color: var(--cream); cursor: pointer; font-family: var(--font-title); }

/* ---------- quiz ---------- */
.quiz { max-width: 760px; margin: 0 auto; }
.quiz-card { background: var(--paper); border-radius: 28px; padding: clamp(20px, 4vw, 34px); box-shadow: var(--shadow); color: var(--ink); }
.quiz-progress { display: flex; gap: 8px; margin-bottom: 14px; }
.quiz-progress span { flex: 1; height: 10px; border-radius: 999px; background: #e9dfcb; overflow: hidden; }
.quiz-progress span.done { background: var(--gold); }
.quiz-q { font-size: clamp(1.4rem, 3vw, 1.9rem); }
.quiz-options { display: grid; gap: 12px; margin-top: 16px; }
.quiz-option {
  text-align: left; border: 3px solid #e6dcc8; background: #fff; border-radius: 18px; padding: 14px 18px; cursor: pointer;
  font: inherit; font-size: 1.2rem; color: var(--ink); transition: transform 0.18s var(--ease-pop), border-color 0.2s, background 0.2s;
}
.quiz-option:hover:not([disabled]) { transform: translateX(6px); border-color: var(--gold); }
.quiz-option.right { border-color: var(--grass); background: #eef6dc; animation: pop-in 0.45s var(--ease-pop); }
.quiz-option.wrong { border-color: var(--red); background: #fbe7e2; animation: shake 0.45s ease; }
.quiz-option[disabled] { cursor: default; }
.quiz-why { margin-top: 14px; font-family: var(--font-hand); font-size: 1.3rem; }
.quiz-why.good { color: var(--grass); }
.quiz-why.oops { color: #8a3a2a; }
.quiz-end { text-align: center; }
.quiz-end .big-stars { font-size: 3rem; letter-spacing: 6px; }

/* ---------- play ---------- */
.play { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 20px; align-items: start; }
.play-side { position: sticky; top: 84px; display: grid; gap: 14px; }
.play-side .robot-helper { flex-direction: column; align-items: flex-start; }
.play-side .robot-helper img { width: 110px; }
.play-side .bubble::after { left: 30px; bottom: auto; top: -9px; border: 10px solid transparent; border-bottom-color: var(--paper); border-top: 0; }
.game-card { background: var(--paper); border-radius: 26px; padding: clamp(14px, 3vw, 24px); box-shadow: var(--shadow); color: var(--ink); }
.game-card > header h2 { margin: 0; }
.game-card > header p { color: var(--ink-soft); margin: 4px 0 14px; }
.win-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 16px; background: var(--navy); color: var(--cream);
  border-radius: 20px; padding: 14px 18px; animation: rise-in 0.5s var(--ease-pop);
}
.win-banner b { font-family: var(--font-title); font-size: 1.2rem; color: var(--gold-hi); }

/* ---------- done ---------- */
.done { text-align: center; max-width: 820px; margin: 0 auto; display: grid; gap: 22px; }
.done-card { background: var(--paper); border-radius: 30px; padding: clamp(22px, 4vw, 40px); box-shadow: var(--shadow); color: var(--ink); }
.done .earned { display: flex; justify-content: center; gap: clamp(10px, 4vw, 34px); flex-wrap: wrap; margin: 18px 0; }
.earned .slot { display: grid; justify-items: center; gap: 4px; font-family: var(--font-title); font-weight: 600; }
.earned .slot .s { font-size: 3.2rem; color: #ddd2bd; }
.earned .slot.got .s { color: var(--gold); animation: star-spin 0.9s var(--ease-pop) both; text-shadow: 0 0 18px rgba(244, 198, 82, 0.8); }
.earned .slot:nth-child(2).got .s { animation-delay: 0.25s; }
.earned .slot:nth-child(3).got .s { animation-delay: 0.5s; }
.done .mantra { border-radius: 24px; }
.done .mantra .w { display: inline-block; animation: rise-in 0.5s var(--ease-pop) both; animation-delay: calc(0.6s + var(--i) * 0.08s); }
.done-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
@keyframes star-spin { from { transform: scale(0) rotate(-180deg); } to { transform: none; } }

@media (max-width: 900px) {
  .read { grid-template-columns: 1fr; }
  .viewer { height: 48vh; }
  .panel { position: static; }
  .play { grid-template-columns: 1fr; }
  .play-side { position: static; }
  .play-side .robot-helper { flex-direction: row; align-items: flex-end; }
  .play-side .robot-helper img { width: 76px; }
  .play-side .bubble::after { left: -9px; top: auto; bottom: 16px; border: 10px solid transparent; border-right-color: var(--paper); border-left: 0; }
  .lesson-top { grid-template-columns: auto 1fr; }
  .steps { grid-column: 1 / -1; justify-content: space-between; }
  .map-hero { grid-template-columns: 1fr; }
}
