/* Sparkle's Rainbow Rescue — styles */

:root {
    --pink: #FF7BAC;
    --purple: #B565D8;
    --blue: #00B4D8;
    --green: #7CB518;
    --yellow: #FCBF49;
    --orange: #F77F00;
    --red: #E63946;
    --cream: #FFF8EC;
    --dark-text: #4A3B5C;
    --white: #FFFFFF;
    --card-shadow: 0 10px 30px rgba(90, 60, 130, 0.18);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

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

body {
    font-family: 'Comic Sans MS', 'Chalkboard SE', 'Segoe UI', Arial, sans-serif;
    color: var(--dark-text);
    background: #C8E8FA;
    touch-action: manipulation;
}

button, .screen a {
    font-family: inherit;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

#game-container {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    position: relative;
    overflow: hidden;
}

.hidden { display: none !important; }

/* ─── Screens ────────────────────────────────────────────────────────────── */

.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
}

.screen-in { animation: screen-in 0.45s ease-out; }

@keyframes screen-in {
    from { opacity: 0; transform: translateY(18px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ─── HUD ────────────────────────────────────────────────────────────────── */

#hud {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 100;
    display: flex;
    gap: 10px;
}

.hud-btn {
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 4px 12px rgba(90, 60, 130, 0.25);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.15s;
}

.hud-btn:hover  { transform: scale(1.1); }
.hud-btn:active { transform: scale(0.92); }

/* ─── Title screen ───────────────────────────────────────────────────────── */

#screen-title {
    justify-content: center;
    gap: 10px;
    background: linear-gradient(180deg, #FDE7F3 0%, #E3F2FD 45%, #E8F8E8 100%);
    text-align: center;
}

.title-art {
    width: min(88vw, 470px);
    margin-bottom: -12px;
}

.title-art svg { width: 100%; height: auto; }

.game-title {
    font-size: clamp(2.1rem, 7vw, 3.4rem);
    line-height: 1.05;
    background: linear-gradient(90deg, var(--red), var(--orange), var(--yellow), var(--green), var(--blue), var(--purple));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-stroke: 1.5px rgba(74, 59, 92, 0.25);
    filter: drop-shadow(0 3px 0 rgba(255, 255, 255, 0.9));
}

.tagline {
    font-size: clamp(1rem, 3.2vw, 1.3rem);
    background: var(--white);
    padding: 8px 22px;
    border-radius: 30px;
    box-shadow: var(--card-shadow);
}

.tagline strong { color: var(--purple); }

/* ─── Big buttons ────────────────────────────────────────────────────────── */

.big-btn {
    min-height: 68px;
    padding: 14px 44px;
    font-size: clamp(1.2rem, 4vw, 1.5rem);
    font-weight: bold;
    color: var(--white);
    background: linear-gradient(135deg, var(--pink) 0%, var(--purple) 100%);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(181, 101, 216, 0.45);
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
}

.big-btn:hover:not(:disabled) { transform: translateY(-3px) scale(1.03); }
.big-btn:active:not(:disabled) { transform: translateY(0) scale(0.97); }
.big-btn:disabled { opacity: 0.45; cursor: default; }

.big-btn.secondary {
    background: linear-gradient(135deg, var(--blue) 0%, #5FB0E8 100%);
    box-shadow: 0 6px 20px rgba(0, 180, 216, 0.4);
}

.links-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.other-game-link {
    display: inline-block;
    margin-top: 6px;
    padding: 15px 28px;
    font-size: 1rem;
    font-weight: bold;
    color: var(--white);
    text-decoration: none;
    background: linear-gradient(135deg, #5BA4D4 0%, #E8723D 100%);
    border-radius: 50px;
    box-shadow: 0 5px 16px rgba(91, 164, 212, 0.4);
    transition: transform 0.2s;
}

.other-game-link:hover { transform: translateY(-3px); }

/* ─── Sticker book row ───────────────────────────────────────────────────── */

.sticker-row {
    display: flex;
    gap: 10px;
    margin: 8px 0;
}

.sticker {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.7rem;
    background: var(--white);
    box-shadow: var(--card-shadow);
    border: 3px solid var(--yellow);
}

.sticker.locked {
    border-color: #D8D0E0;
    color: #B8AECB;
    background: #F3F0F8;
    font-weight: bold;
}

.sticker.owned.secret {
    border-color: #FFD700;
    background: linear-gradient(135deg, #FFF8DC, #FFEFB0);
    box-shadow: 0 0 16px rgba(255, 215, 0, 0.7);
}

/* ─── Character select ───────────────────────────────────────────────────── */

#screen-select {
    gap: 12px;
    background: linear-gradient(180deg, #E3F2FD 0%, #FDE7F3 100%);
    padding-top: 20px;
    padding-bottom: 28px;
}

.select-heading {
    font-size: clamp(1.3rem, 4.5vw, 2rem);
    color: var(--purple);
    text-shadow: 2px 2px 0 var(--white);
    text-align: center;
    margin-top: 6px;
    max-width: calc(100% - 150px);
}

#franchise-groups {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    justify-content: center;
    width: 100%;
    max-width: 1100px;
}

.franchise-card {
    background: rgba(255, 255, 255, 0.75);
    border-radius: 24px;
    padding: 14px 16px 16px;
    box-shadow: var(--card-shadow);
    text-align: center;
    flex: 1 1 300px;
    max-width: 360px;
}

.franchise-card h3 {
    font-size: clamp(1rem, 3vw, 1.2rem);
    margin-bottom: 10px;
    color: var(--dark-text);
}

.hero-grid {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.hero-btn {
    flex: 1 1 0;
    min-width: 88px;
    max-width: 110px;
    padding: 10px 6px 12px;
    background: var(--white);
    border: 4px solid transparent;
    border-radius: 20px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(90, 60, 130, 0.15);
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.hero-btn span {
    font-size: 0.95rem;
    font-weight: bold;
    color: var(--dark-text);
}

.hero-btn:hover { transform: translateY(-4px); }

.hero-btn.selected {
    border-color: var(--hero-color);
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.7), 0 8px 20px rgba(90, 60, 130, 0.3);
    transform: translateY(-4px) scale(1.05);
}

.hero-avatar { width: 78px; height: 91px; }
.hero-avatar svg { width: 100%; height: 100%; }

.hero-hello {
    font-size: clamp(1rem, 3.4vw, 1.25rem);
    font-weight: bold;
    color: var(--hero-color, var(--purple));
    background: var(--white);
    border-radius: 26px;
    padding: 10px 24px;
    box-shadow: var(--card-shadow);
    text-align: center;
    max-width: 90%;
}

/* ─── Story screen ───────────────────────────────────────────────────────── */

#screen-story {
    padding: 0;
    background: #EAF6FD;
    flex-direction: column;
    overflow: hidden;
}

#scene-stage {
    position: relative;
    width: 100%;
    flex: 1 1 52%;
    min-height: 0;
    overflow: hidden;
}

#scene-bg, #scene-bg svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

/* Foreground plate: framing elements that render IN FRONT of the actors */
#scene-bg .fg-svg {
    z-index: 2;
    pointer-events: none;
}

#scene-actors {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 2%;
    height: 68%;
    display: flex;
    align-items: flex-end;
    justify-content: space-evenly;
    pointer-events: none;
}

.actor-slot {
    width: 27%;
    max-width: 240px;
    height: 100%;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.actor-slot svg {
    width: 100%;
    height: auto;
    max-height: 100%;
    filter: drop-shadow(0 6px 6px rgba(40, 40, 70, 0.25));
    animation:
        actor-in 0.55s cubic-bezier(0.2, 1.5, 0.4, 1) backwards,
        bob 3s ease-in-out 0.55s infinite;
}

.slot-center svg { animation-delay: 0.12s, 0.9s; }
.slot-right svg  { animation-delay: 0.24s, 1.3s; }

@keyframes actor-in {
    from { opacity: 0; transform: translateY(46px) scale(0.55); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* The character who is currently speaking wiggles */
.actor-slot.talking {
    animation: talk 0.34s ease-in-out infinite alternate;
    transform-origin: bottom center;
}

@keyframes talk {
    from { transform: translateY(0) rotate(-1.8deg); }
    to   { transform: translateY(-7px) rotate(1.8deg); }
}

#chapter-badge {
    position: absolute;
    top: 12px;
    left: 12px;
    background: rgba(255, 255, 255, 0.9);
    color: var(--purple);
    font-weight: bold;
    font-size: clamp(0.85rem, 2.6vw, 1.05rem);
    padding: 8px 18px;
    border-radius: 24px;
    box-shadow: var(--card-shadow);
}

#story-panel {
    flex: 0 0 auto;
    width: 100%;
    max-height: 56%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.55), var(--cream) 30%);
    overflow-y: auto;
}

#choose-banner {
    font-size: clamp(1rem, 3.6vw, 1.35rem);
    font-weight: bold;
    color: #7A4A00;
    background: linear-gradient(90deg, var(--yellow), #FFE29A, var(--yellow));
    border-radius: 30px;
    padding: 10px 26px;
    box-shadow: 0 4px 14px rgba(252, 191, 73, 0.55);
    text-align: center;
}

#choose-banner.pop { animation: banner-pulse 1.1s ease-in-out 2; }

@keyframes banner-pulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.07); }
}

#story-card {
    width: 100%;
    max-width: 760px;
    background: var(--white);
    border-radius: 24px;
    padding: 20px 22px 16px;
    box-shadow: var(--card-shadow);
    position: relative;
}

#speaker-chip {
    position: absolute;
    top: -14px;
    left: 22px;
    color: var(--white);
    font-weight: bold;
    font-size: 0.9rem;
    padding: 5px 16px;
    border-radius: 20px;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
}

#story-text {
    font-size: clamp(1.05rem, 3.4vw, 1.35rem);
    line-height: 1.45;
}

#story-flavor {
    margin-top: 10px;
    font-size: clamp(0.95rem, 3vw, 1.15rem);
    font-style: italic;
    font-weight: bold;
}

#choice-area {
    width: 100%;
    max-width: 760px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.choice-btn {
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
    min-height: 76px;
    padding: 12px 22px;
    border: none;
    border-radius: 24px;
    cursor: pointer;
    font-weight: bold;
    color: var(--white);
    text-align: left;
    box-shadow: 0 6px 18px rgba(90, 60, 130, 0.3);
    animation: pop-in 0.4s ease-out backwards;
    transition: transform 0.15s, filter 0.15s;
}

.choice-0 { background: linear-gradient(135deg, var(--green) 0%, #A2D149 100%); }
.choice-1 { background: linear-gradient(135deg, var(--blue) 0%, #5FD0F0 100%); }
.next-btn { background: linear-gradient(135deg, var(--pink) 0%, var(--purple) 100%); justify-content: center; text-align: center; }
.celebrate-btn { background: linear-gradient(135deg, var(--orange) 0%, var(--yellow) 100%); }

.choice-btn:hover:not(:disabled)  { transform: translateY(-3px) scale(1.02); }
.choice-btn:active:not(:disabled) { transform: scale(0.97); }
.choice-btn:disabled { cursor: default; filter: saturate(0.4) opacity(0.6); }
.choice-btn.picked   { filter: none; transform: scale(1.03); box-shadow: 0 0 0 5px var(--yellow), 0 6px 18px rgba(90, 60, 130, 0.3); }

.choice-emoji { font-size: 2.3rem; line-height: 1; }
.choice-label { font-size: clamp(1.15rem, 3.8vw, 1.45rem); }

@keyframes pop-in {
    from { opacity: 0; transform: scale(0.75) translateY(14px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.page-in { animation: page-in 0.4s ease-out; }

@keyframes page-in {
    from { opacity: 0.35; transform: translateX(26px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ─── Ending screen ──────────────────────────────────────────────────────── */

#screen-ending {
    justify-content: center;
    gap: 10px;
    text-align: center;
    background: linear-gradient(180deg, #FFF3D6 0%, #FDE7F3 55%, #E3F2FD 100%);
}

.ending-hooray {
    font-size: clamp(2rem, 7vw, 3rem);
    color: var(--orange);
    text-shadow: 3px 3px 0 var(--white);
}

#ending-title {
    font-size: clamp(1.3rem, 4.6vw, 2rem);
    color: var(--purple);
    text-shadow: 2px 2px 0 var(--white);
}

#sticker-reveal {
    width: 130px;
    height: 130px;
    border-radius: 50%;
    background: var(--white);
    border: 6px solid var(--yellow);
    box-shadow: 0 0 30px rgba(252, 191, 73, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
}

#sticker-reveal.sticker-stamp { animation: sticker-stamp 0.6s cubic-bezier(0.2, 1.6, 0.4, 1); }

@keyframes sticker-stamp {
    from { transform: scale(3) rotate(-18deg); opacity: 0; }
    to   { transform: scale(1) rotate(0deg); opacity: 1; }
}

#sticker-caption {
    font-size: clamp(1.05rem, 3.4vw, 1.3rem);
    font-weight: bold;
    color: var(--dark-text);
    background: var(--white);
    padding: 8px 24px;
    border-radius: 26px;
    box-shadow: var(--card-shadow);
}

#golden-bonus {
    background: linear-gradient(135deg, #FFF8DC, #FFE9A8);
    border: 3px solid #FFD700;
    border-radius: 24px;
    padding: 12px 26px;
    box-shadow: 0 0 26px rgba(255, 215, 0, 0.75);
    animation: pop-in 0.5s ease-out 0.4s backwards;
    font-size: clamp(1rem, 3.2vw, 1.2rem);
}

.golden-art { font-size: 2.6rem; }

.ending-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    margin-top: 6px;
}

#confetti-layer {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 50;
}

.confetti-bit {
    position: absolute;
    top: -20px;
    animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
    from { transform: translateY(-4vh) rotate(0turn); opacity: 1; }
    to   { transform: translateY(112vh) rotate(3turn); opacity: 0.85; }
}

/* ─── SVG scene animations ───────────────────────────────────────────────── */

.drift      { animation: drift 16s ease-in-out infinite alternate; }
.drift-slow { animation: drift 26s ease-in-out infinite alternate; }

@keyframes drift {
    from { transform: translateX(-55px); }
    to   { transform: translateX(75px); }
}

.flag-wave { animation: flag-wave 1.5s ease-in-out infinite; }

@keyframes flag-wave {
    0%, 100% { transform: scaleX(1) skewY(0deg); }
    30%      { transform: scaleX(0.84) skewY(5deg); }
    60%      { transform: scaleX(0.94) skewY(-3deg); }
}

.window-glow { animation: window-glow 2.8s ease-in-out infinite; }

@keyframes window-glow {
    0%, 100% { opacity: 0.55; }
    50%      { opacity: 1; }
}

.fly-across {
    animation: fly-across 24s linear infinite;
    animation-fill-mode: backwards;
}

.fly-across.delay2 { animation-delay: 9s; animation-duration: 30s; }

@keyframes fly-across {
    from { transform: translate(-150px, 0); }
    50%  { transform: translate(390px, -22px); }
    to   { transform: translate(950px, 6px); }
}

/* Blinking eyes on every character */
.actor-svg .eyes, svg .eyes {
    transform-box: fill-box;
    transform-origin: center;
    animation: blink 4.6s infinite;
}

@keyframes blink {
    0%, 93%, 100% { transform: scaleY(1); }
    95.5%, 97.5%  { transform: scaleY(0.08); }
}

/* Floating magic dust over every scene */
.dust-layer {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.dust-bit {
    position: absolute;
    bottom: -20px;
    border-radius: 50%;
    opacity: 0;
    animation: dust-rise linear infinite;
}

@keyframes dust-rise {
    0%   { transform: translate(0, 0) scale(1); opacity: 0; }
    12%  { opacity: 0.85; }
    80%  { opacity: 0.4; }
    100% { transform: translate(26px, -72vh) scale(0.6); opacity: 0; }
}

.twinkle { animation: twinkle 2.2s ease-in-out infinite; }

@keyframes twinkle {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.15; }
}

.bob { animation: bob 2.6s ease-in-out infinite; }

@keyframes bob {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-7px); }
}

.sway { animation: sway 4.5s ease-in-out infinite alternate; }

@keyframes sway {
    from { transform: rotate(-2.5deg); }
    to   { transform: rotate(2.5deg); }
}

.pulse { animation: pulse 2.4s ease-in-out infinite; }

@keyframes pulse {
    0%, 100% { opacity: 0.15; }
    50%      { opacity: 0.4; }
}

.spin-slow { animation: spin 30s linear infinite; }

@keyframes spin {
    to { transform: rotate(1turn); }
}

.rainbow-grow {
    stroke-dasharray: 1100;
    stroke-dashoffset: 1100;
    stroke-linecap: round;
    animation: rainbow-grow 2.2s ease-out forwards;
}

@keyframes rainbow-grow {
    to { stroke-dashoffset: 0; }
}

.glow-soft { opacity: 0.7; animation: glow-soft 4s ease-in-out infinite; }

@keyframes glow-soft {
    0%, 100% { opacity: 0.55; }
    50%      { opacity: 0.9; }
}

/* Second twinkle flavor: scale pulse, so star fields don't blink in unison */
.twinkle-b {
    transform-box: fill-box;
    transform-origin: center;
    animation: twinkle-b 3.4s ease-in-out infinite;
}

@keyframes twinkle-b {
    0%, 100% { transform: scale(0.65); opacity: 0.5; }
    50%      { transform: scale(1.2); opacity: 1; }
}

/* Butterflies / dragonflies wandering */
.flutter { animation: flutter 5.5s ease-in-out infinite alternate; }

@keyframes flutter {
    0%   { transform: translate(0, 0) rotate(-6deg); }
    25%  { transform: translate(12px, -14px) rotate(5deg); }
    50%  { transform: translate(26px, -2px) rotate(-5deg); }
    75%  { transform: translate(38px, -18px) rotate(6deg); }
    100% { transform: translate(52px, -6px) rotate(-4deg); }
}

/* Water highlights sliding across the river */
.shimmer { animation: shimmer 3.2s ease-in-out infinite alternate; }

@keyframes shimmer {
    from { transform: translateX(-13px); opacity: 0.3; }
    to   { transform: translateX(13px); opacity: 0.8; }
}

/* Boingy mushrooms squash and stretch */
.boing {
    transform-box: fill-box;
    transform-origin: 50% 100%;
    animation: boing 2.9s ease-in-out infinite;
}

@keyframes boing {
    0%, 55%, 100% { transform: scale(1, 1); }
    68%           { transform: scale(1.08, 0.9); }
    82%           { transform: scale(0.95, 1.07); }
}

/* Forest light shafts breathing */
.shaft { opacity: 0.1; animation: shaft 7s ease-in-out infinite alternate; }

@keyframes shaft {
    from { opacity: 0.06; }
    to   { opacity: 0.18; }
}

/* Halo pulse behind glowing mushrooms */
.glow-pulse { animation: glow-pulse 3s ease-in-out infinite; }

@keyframes glow-pulse {
    0%, 100% { opacity: 0.16; }
    50%      { opacity: 0.45; }
}

/* Magic color orbs breathing */
.orb-pulse {
    transform-box: fill-box;
    transform-origin: center;
    animation: orb-pulse 2.4s ease-in-out infinite;
}

@keyframes orb-pulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.22); }
}

/* Grumbles' drizzle */
.rain-fall { animation: rain-fall 1.1s linear infinite; }

@keyframes rain-fall {
    from { transform: translateY(0); opacity: 0.9; }
    to   { transform: translateY(24px); opacity: 0; }
}

/* Lightning bolt flicker */
.flash { animation: flash 3.5s ease-in-out infinite; }

@keyframes flash {
    0%, 86%, 100% { opacity: 0.95; }
    90%           { opacity: 0.25; }
    93%           { opacity: 1; }
    96%           { opacity: 0.4; }
}

/* Rainbow sheen on the finale */
.shine-arc { animation: shine-arc 3.8s ease-in-out infinite; }

@keyframes shine-arc {
    0%, 100% { opacity: 0; }
    50%      { opacity: 0.4; }
}

/* Rare shooting star at dusk */
.shoot { opacity: 0; animation: shoot 9s linear infinite; }

@keyframes shoot {
    0%, 80% { transform: translate(0, 0); opacity: 0; }
    83%     { opacity: 0.9; }
    92%     { transform: translate(-200px, 130px); opacity: 0; }
    100%    { transform: translate(-200px, 130px); opacity: 0; }
}

/* Character secondary motion (origins set inline per element) */
.tail-sway {
    transform-box: fill-box;
    animation: tail-sway 2.8s ease-in-out infinite alternate;
}

@keyframes tail-sway {
    from { transform: rotate(-7deg); }
    to   { transform: rotate(8deg); }
}

.mane-sway {
    transform-box: fill-box;
    animation: mane-sway 3.4s ease-in-out infinite alternate;
}

@keyframes mane-sway {
    from { transform: rotate(-2.5deg); }
    to   { transform: rotate(3deg); }
}

.ear-twitch {
    transform-box: fill-box;
    transform-origin: 50% 90%;
    animation: ear-twitch 6s ease-in-out infinite;
}

@keyframes ear-twitch {
    0%, 88%, 100% { transform: rotate(0deg); }
    91%           { transform: rotate(-9deg); }
    95%           { transform: rotate(4deg); }
}

.wing-flap-l {
    transform-box: fill-box;
    transform-origin: 90% 60%;
    animation: wing-flap-l 1.3s ease-in-out infinite;
}

.wing-flap-r {
    transform-box: fill-box;
    transform-origin: 10% 60%;
    animation: wing-flap-r 1.3s ease-in-out infinite;
}

@keyframes wing-flap-l {
    0%, 100% { transform: rotate(6deg); }
    50%      { transform: rotate(-16deg); }
}

@keyframes wing-flap-r {
    0%, 100% { transform: rotate(-6deg); }
    50%      { transform: rotate(16deg); }
}

/* ─── Act-it-out: the actor row performs what the words describe ──────────── */
/* One class on #scene-actors, set per scene (scene.anim). Composes on top of
   each actor's own bob/blink, so the whole group flies, bounces, sneezes… */

#scene-actors.act-fly    { animation: act-fly 3.2s ease-in-out infinite; }
#scene-actors.act-bounce { animation: act-bounce 0.9s cubic-bezier(0.3, 0, 0.4, 1) infinite; }
#scene-actors.act-slide  { animation: act-slide 1.15s cubic-bezier(0.4, 0, 0.2, 1) 1 backwards; }
#scene-actors.act-float  { animation: act-float 4s ease-in-out infinite; }
#scene-actors.act-hug    { animation: act-hug 2.4s ease-in-out infinite; }
#scene-actors.act-sneeze { animation: act-sneeze 1.7s ease-in-out infinite; }
#scene-actors.act-dance  { animation: act-dance 1.15s ease-in-out infinite; }
#scene-actors.act-shower { animation: act-shower 3s ease-in-out infinite; }
#scene-actors.act-glow   { animation: act-glow 3.6s ease-in-out infinite; }

@keyframes act-fly {
    0%   { transform: translate(-6%, 0) rotate(-2.5deg); }
    50%  { transform: translate(6%, -7%) rotate(2.5deg); }
    100% { transform: translate(-6%, 0) rotate(-2.5deg); }
}

@keyframes act-bounce {
    0%   { transform: translateY(0) scaleY(1); }
    25%  { transform: translateY(-20%) scaleY(1.05); }
    50%  { transform: translateY(0) scaleY(0.94); }
    58%  { transform: translateY(-4%) scaleY(1); }
    100% { transform: translateY(0) scaleY(1); }
}

@keyframes act-slide {
    0%   { transform: translate(-32%, -42%) rotate(-9deg); }
    60%  { transform: translate(6%, 4%) rotate(3deg); }
    100% { transform: translate(0, 0) rotate(0); }
}

@keyframes act-float {
    0%, 100% { transform: translateY(0) rotate(-1.5deg); }
    50%      { transform: translateY(-5%) rotate(1.5deg); }
}

@keyframes act-hug {
    0%, 100% { transform: scale(1); }
    45%, 60% { transform: scale(1.05) translateY(-2%); }
}

@keyframes act-sneeze {
    0%   { transform: translateY(0) rotate(0); }
    32%  { transform: translateY(-5%) rotate(-4deg); }   /* ahh… lean back */
    46%  { transform: translateY(-7%) rotate(-5deg); }
    53%  { transform: translateY(4%) rotate(5deg) scale(1.05); } /* CHOO! */
    62%  { transform: translateY(0) rotate(-1.5deg); }
    72%  { transform: translateY(0) rotate(1.5deg); }
    100% { transform: translateY(0) rotate(0); }
}

@keyframes act-dance {
    0%, 100% { transform: translateY(0) rotate(-4deg); }
    25%      { transform: translateY(-8%) rotate(4deg); }
    50%      { transform: translateY(0) rotate(-4deg); }
    75%      { transform: translateY(-8%) rotate(4deg); }
}

@keyframes act-shower {
    0%, 100% { transform: rotate(-2deg); }
    50%      { transform: rotate(2deg); }
}

@keyframes act-glow {
    0%, 100% { transform: scale(1) translateY(0); }
    50%      { transform: scale(1.03) translateY(-2%); }
}

/* ─── Landscape layout (tablets held sideways / desktop) ─────────────────── */

@media (orientation: landscape) and (min-width: 700px) {
    #screen-story { flex-direction: row; }

    #scene-stage {
        flex: 1 1 55%;
        height: 100%;
    }

    #story-panel {
        flex: 1 1 45%;
        max-height: none;
        height: 100%;
        justify-content: center;
        background: var(--cream);
    }
}

@media (max-width: 480px) {
    .hud-btn { width: 48px; height: 48px; font-size: 1.3rem; }
    .hero-btn { min-width: 78px; }
    .hero-avatar { width: 62px; height: 72px; }
}

/* ─── Rainbow-wipe scene transition ──────────────────────────────────────── */

.rainbow-wipe {
    position: absolute;
    inset: 0;
    z-index: 60;
    display: flex;
    overflow: hidden;
    pointer-events: none;
    border-radius: inherit;
}

.rw-band {
    flex: 1 1 0;
    height: 100%;
    transform: translateY(-104%);
    animation: rw-sweep 0.8s cubic-bezier(0.55, 0, 0.45, 1) forwards;
}

@keyframes rw-sweep {
    0%       { transform: translateY(-104%); }
    38%, 62% { transform: translateY(0); }
    100%     { transform: translateY(104%); }
}

/* ─── Ending: the rainbow paints itself back ─────────────────────────────── */

#ending-rainbow {
    position: absolute;
    top: 4%;
    left: 50%;
    transform: translateX(-50%);
    width: min(88%, 460px);
    height: 40%;
    max-height: 220px;
    z-index: 0;                 /* pure backdrop — all text/sticker sit above it */
    pointer-events: none;
    opacity: 0.9;
}

/* Lift the ending's headline, title and sticker clear of the rainbow backdrop */
.ending-hooray, #ending-title { position: relative; z-index: 3; }
#sticker-reveal { position: relative; z-index: 2; }

.er-arc {
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    animation: er-draw 0.9s ease-out forwards;
    filter: drop-shadow(0 2px 5px rgba(120, 80, 160, 0.25));
}

@keyframes er-draw {
    to { stroke-dashoffset: 0; }
}

/* ─── Ending: the little-lesson card ─────────────────────────────────────── */

#lesson-card {
    position: relative;
    z-index: 55;
    max-width: min(92%, 460px);
    background: linear-gradient(135deg, #FFFDF6 0%, #FBF2FF 100%);
    border: 2.5px solid var(--yellow);
    border-radius: 22px;
    padding: 14px 22px 16px;
    box-shadow: 0 12px 30px rgba(120, 80, 160, 0.22);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

#lesson-card.reveal { animation: lesson-in 0.6s cubic-bezier(0.2, 1.5, 0.4, 1) 0.5s backwards; }

@keyframes lesson-in {
    from { opacity: 0; transform: translateY(24px) scale(0.9); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.lesson-eyebrow {
    font-size: clamp(0.82rem, 2.6vw, 0.98rem);
    font-weight: bold;
    color: var(--orange);
    letter-spacing: 0.01em;
}

#lesson-text {
    font-size: clamp(0.98rem, 3vw, 1.14rem);
    line-height: 1.5;
    color: var(--dark-text);
    margin: 0;
}

/* ─── Ending: firework bursts ────────────────────────────────────────────── */

#firework-layer {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 52;
}

.firework {
    position: absolute;
    width: 0;
    height: 0;
}

.fw-dot {
    position: absolute;
    left: 0;
    top: 0;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    opacity: 0;
    animation: fw-burst 1s ease-out forwards;
    animation-delay: inherit;
}

@keyframes fw-burst {
    0%   { opacity: 0; transform: translate(0, 0) scale(0.3); }
    15%  { opacity: 1; }
    100% { opacity: 0; transform: translate(var(--tx), var(--ty)) scale(1); }
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
    .drift, .drift-slow, .bob, .sway, .twinkle, .pulse, .spin-slow,
    .twinkle-b, .flutter, .shimmer, .boing, .shaft, .glow-pulse, .orb-pulse,
    .rain-fall, .flash, .shine-arc, .shoot, .tail-sway, .mane-sway,
    .ear-twitch, .wing-flap-l, .wing-flap-r, .fly-across, .flag-wave,
    .window-glow, .glow-soft { animation: none; }
    /* Act-it-out motions off; the scene still reads, just still */
    #scene-actors[class*="act-"] { animation: none; transform: none; }
    /* Show the new flourishes in their final state, without motion */
    .er-arc { animation: none; stroke-dashoffset: 0; }
    #lesson-card.reveal { animation: none; }
    .rw-band { animation: none; transform: translateY(-104%); }
}
