/* The play feel shared by every game (js/games/core.js): the bar with Noor, the star counter and the meter for
   answers right in a row; questions sliding in and out; the island whose lantern lights at the end; and the guided
   steps of letter tracing. Motion is transform and opacity only; kids.css stills it all for reduced motion. */

.k-stage-wrap { position: relative; --dir: 1; }
:root[dir="rtl"] .k-stage-wrap { --dir: -1; }

/* ---------- The play bar ---------- */
.sg-playbar {
    position: sticky; top: calc(var(--top-h) + 4px); z-index: 6;
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 14px; margin-bottom: 16px;
    pointer-events: none;
}
.sg-playbar > * { pointer-events: auto; }
.k-stage-wrap:has(.k-result-card) .sg-playbar { position: relative; top: auto; }
.sg-playbar .k-back-levels { margin: 0; }
.sg-hud {
    display: flex; align-items: center; gap: 14px; margin-inline-start: auto; padding-block: 5px; padding-inline: 5px 16px; border-radius: 999px;
    background: var(--glass-strong); backdrop-filter: blur(16px) saturate(1.3); -webkit-backdrop-filter: blur(16px) saturate(1.3);
    box-shadow: inset 0 0 0 1.5px var(--glass-edge), 0 16px 30px -18px rgba(76, 52, 150, .6);
    font-family: var(--font-display);
}
.sg-hud-noor {
    position: relative; flex: none; display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%;
    background: radial-gradient(circle at 50% 58%, #FFF5CF 0%, #FFE08A 55%, #FFC86B 100%);
    box-shadow: inset 0 -3px 0 rgba(200, 120, 0, .22), 0 6px 14px -6px rgba(245, 163, 30, .9);
}
.sg-hud-noor .k-mascot-svg { width: 36px; height: 45px; filter: none; }
.sg-hud-noor .noor-glow, .sg-hud-noor .noor-spark { display: none; }
.sg-hud-noor.is-hmm .k-mascot-svg .noor-body { animation: noor-hmm .8s ease; }
@keyframes noor-hmm { 30% { transform: rotate(-12deg) translateX(-3px); } 60% { transform: rotate(8deg); } }
.sg-hud-say {
    position: absolute; top: 50%; inset-inline-end: calc(100% + 12px); z-index: 2; margin-top: -17px; padding: 6px 14px; border-radius: 14px;
    background: var(--paper); color: var(--grape-deep); box-shadow: var(--shadow); white-space: nowrap; line-height: 22px;
    font-weight: 700; font-size: .95rem; opacity: 0; transform: translateX(calc(10px * var(--dir, 1))) scale(.7);
    transition: opacity .2s, transform .35s var(--ease-bounce); pointer-events: none;
}
.sg-hud-say::before { content: ""; position: absolute; top: 50%; inset-inline-end: -5px; width: 12px; height: 12px; margin-top: -6px; background: inherit; transform: rotate(45deg); border-radius: 0 3px 0 0; z-index: -1; }
.sg-hud-noor.is-hmm .sg-hud-say { color: var(--sun-deep); }
.sg-hud-say.is-on { opacity: 1; transform: none; }
:root[data-theme="dark"] .sg-hud-say { color: #FFE3A0; }

.sg-hud-stars { display: inline-flex; align-items: center; gap: 6px; }
.sg-hud-stars .sg-ico { width: 32px; height: 32px; filter: drop-shadow(0 3px 4px rgba(227, 158, 0, .45)); }
.sg-hud-stars b { min-width: 1.4ch; font-size: 1.55rem; line-height: 1; color: var(--ink); font-variant-numeric: tabular-nums; }
.sg-hud-stars small, .sg-hud-combo small { font-size: .78rem; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .05em; }
:root[lang="ar"] .sg-hud small, :root[lang="ur"] .sg-hud small { text-transform: none; letter-spacing: 0; font-size: .9rem; }
.sg-hud-stars.is-bump .sg-ico { animation: sg-hud-bump .45s var(--ease-bounce); }
.sg-hud-stars.is-bump b { animation: sg-hud-bump .45s var(--ease-bounce) .05s; }
@keyframes sg-hud-bump { 40% { transform: scale(1.45) rotate(-12deg); } }

.sg-hud-combo { position: relative; display: inline-flex; align-items: center; gap: 7px; padding-inline-start: 14px; border-inline-start: 2px solid var(--line); }
.sg-hud-meter { display: inline-flex; gap: 3px; }
.sg-hud-meter i { position: relative; width: 13px; height: 18px; border-radius: 6px; background: color-mix(in srgb, var(--ink) 12%, transparent); overflow: hidden; }
.sg-hud-meter i::after {
    content: ""; position: absolute; inset: 0; border-radius: inherit; background: linear-gradient(180deg, #FFD45C, #FF7F6E);
    transform: scaleY(0); transform-origin: bottom; transition: transform .3s var(--ease-bounce);
}
.sg-hud-meter i.is-on::after { transform: scaleY(1); }
.sg-hud-meter i:nth-child(2)::after { transition-delay: .03s; } .sg-hud-meter i:nth-child(3)::after { transition-delay: .06s; }
.sg-hud-combo b { min-width: 2.2ch; font-size: 1.15rem; color: var(--coral-deep); font-variant-numeric: tabular-nums; }
.sg-hud-combo::after {
    content: ""; position: absolute; inset: -6px -8px; border-radius: 16px; pointer-events: none; opacity: 0;
    background: radial-gradient(closest-side, rgba(255, 170, 80, .45), transparent);
}
.sg-hud.is-hot .sg-hud-combo::after { animation: sg-hot 1s ease-in-out infinite alternate; }
@keyframes sg-hot { from { opacity: .25; transform: scale(.94); } to { opacity: 1; transform: scale(1.06); } }
.sg-hud-combo.is-reset { animation: k-wiggle .4s; }
.sg-hud-keys {
    padding: 4px 10px; border-radius: 10px; font-family: var(--font-body); font-size: .8rem; font-weight: 700; color: var(--ink-soft);
    background: color-mix(in srgb, var(--ink) 7%, transparent); box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--ink) 10%, transparent);
}
@media (hover: none), (pointer: coarse), (max-width: 760px) { .sg-hud-keys { display: none; } }

/* A star flying from the right answer to the counter (moved by the Web Animations API). */
.sg-fly-star { position: fixed; z-index: 96; width: 46px; height: 46px; pointer-events: none; transform: translate(-50%, -50%); will-change: transform, opacity; }
.sg-fly-star .sg-ico { width: 100%; height: 100%; filter: drop-shadow(0 6px 10px rgba(227, 158, 0, .55)); }

/* "3 in a row!" */
.sg-combo-pop {
    position: absolute; inset-inline: 0; top: 18%; z-index: 7; display: flex; flex-direction: column; align-items: center; gap: 2px; pointer-events: none;
    animation: sg-combo 1.45s var(--ease-soft) forwards;
}
.sg-combo-pop b {
    font-family: var(--font-display); font-size: clamp(3.4rem, 9vw, 5.6rem); line-height: 1; color: #FF7F6E;
    text-shadow: 0 3px 0 #fff, 0 6px 0 #FFC7BC, 0 18px 30px rgba(240, 90, 70, .35);
}
.sg-combo-pop span {
    padding: 6px 16px; border-radius: 999px; background: linear-gradient(180deg, #FFE27A, #FFB400); color: #5A3500;
    font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; box-shadow: 0 10px 20px -10px rgba(200, 120, 0, .8);
}
@keyframes sg-combo {
    0% { opacity: 0; transform: scale(.4) rotate(-8deg); }
    18% { opacity: 1; transform: scale(1.12) rotate(3deg); }
    30% { transform: scale(1) rotate(0); }
    75% { opacity: 1; transform: translateY(-10px); }
    100% { opacity: 0; transform: translateY(-46px) scale(.9); }
}

/* ---------- Questions sliding in and out ---------- */
.sg-enter { animation: sg-slide-in .5s var(--ease-bounce) both; }
.sg-leave { animation: sg-slide-out .21s ease-in forwards; pointer-events: none; }
@keyframes sg-slide-in { from { opacity: 0; transform: translateX(calc(46px * var(--dir, 1))) scale(.96) rotate(calc(.8deg * var(--dir, 1))); } }
@keyframes sg-slide-out { to { opacity: 0; transform: translateX(calc(-56px * var(--dir, 1))) scale(.96) rotate(calc(-.8deg * var(--dir, 1))); } }
.sg-nudge { animation: k-wiggle .4s; }
.sg-wave { animation: sg-wave .55s var(--ease-bounce) both; }
@keyframes sg-wave { 45% { transform: translateY(-10px) scale(1.06); } }

/* Number keys on the story choices; letters already show on the answer buttons. */
.k-choice { display: flex; align-items: center; gap: 12px; }
.k-key {
    flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 11px;
    background: color-mix(in srgb, var(--t, var(--grape)) 18%, var(--paper)); color: var(--td, var(--grape-deep));
    font-family: var(--font-display); font-weight: 700; font-size: 1rem;
}
.k-choice.is-right .k-key { background: var(--leaf); color: #fff; }

/* ---------- The island whose lantern lights up ---------- */
.k-result-card.has-lantern { padding-top: 18px; overflow: hidden; position: relative; }
.sg-lit { position: relative; width: 300px; height: 200px; margin: 0 auto -4px; }
.sg-lit-isle {
    position: absolute; left: 50%; bottom: -34px; width: 200px; margin-left: -100px; height: auto;
    filter: drop-shadow(0 18px 18px rgba(91, 63, 208, .25)); animation: sg-game-isle 6s ease-in-out infinite;
    -webkit-mask-image: radial-gradient(ellipse 50% 50% at 50% 47%, #000 74%, transparent 100%); mask-image: radial-gradient(ellipse 50% 50% at 50% 47%, #000 74%, transparent 100%);
}
.sg-lit-lantern { position: absolute; left: 50%; top: -4px; width: 52px; height: 88px; margin-left: 58px; animation: sg-lit-sway 3.4s ease-in-out infinite; transform-origin: 50% 0; }
.sg-lit-lantern svg { position: relative; z-index: 1; width: 100%; height: 100%; overflow: visible; }
.sg-lit-lantern::before {
    content: ""; position: absolute; left: 50%; top: 52%; width: 190px; height: 190px; margin: -95px 0 0 -95px; border-radius: 50%;
    background: radial-gradient(closest-side, rgba(255, 214, 110, .95), rgba(255, 190, 80, .45) 45%, rgba(255, 190, 80, 0));
    opacity: 0; transform: scale(.3); transition: opacity .8s ease, transform 1s var(--ease-bounce);
}
@keyframes sg-lit-sway { 50% { transform: rotate(4deg); } }
.sg-lit-glass { fill: rgba(255, 255, 255, .55); stroke: #E39E00; stroke-width: 3; }
.sg-lit-warm { fill: #FFD86B; opacity: 0; transition: opacity .7s ease .1s; }
.sg-lit-flame { fill: #FF9A3C; opacity: .18; transform: scale(.4); transform-box: fill-box; transform-origin: 50% 100%; transition: opacity .5s ease .15s, transform .7s var(--ease-bounce) .15s; }
.sg-lit.is-lit .sg-lit-lantern::before { opacity: 1; transform: scale(1); }
.sg-lit.is-lit .sg-lit-warm { opacity: .9; }
.sg-lit.is-lit .sg-lit-flame { opacity: 1; transform: scale(1); animation: sg-flicker 1.2s ease-in-out 1s infinite alternate; }
@keyframes sg-flicker { to { transform: scale(.92, 1.06); } }
.sg-lit-rays {
    position: absolute; left: 50%; top: 40px; margin-left: -96px !important; width: 360px; height: 360px; margin: -180px 0 0 -180px; border-radius: 50%; opacity: 0;
    background: repeating-conic-gradient(from 0deg, rgba(255, 214, 107, .5) 0deg 7deg, rgba(255, 214, 107, 0) 7deg 20deg);
    -webkit-mask: radial-gradient(closest-side, #000 20%, transparent 100%); mask: radial-gradient(closest-side, #000 20%, transparent 100%);
    transition: opacity 1s ease;
}
.sg-lit.is-lit .sg-lit-rays { opacity: 1; animation: sg-spin 14s linear infinite; }
.sg-lit-spark { position: absolute; left: 50%; top: 44px; margin-left: 80px; width: 10px; height: 10px; border-radius: 50%; background: #FFE27A; box-shadow: 0 0 10px 3px rgba(255, 200, 90, .9); opacity: 0; }
.sg-lit.is-lit .sg-lit-spark { animation: sg-lit-spark 1.6s ease-out .2s 2; }
.sg-lit.is-lit .sg-lit-spark:nth-of-type(2) { --sx: -70px; animation-delay: .4s; }
.sg-lit.is-lit .sg-lit-spark:nth-of-type(3) { --sx: 64px; animation-delay: .65s; }
@keyframes sg-lit-spark { 0% { opacity: 1; transform: translate(0, 0) scale(1); } 100% { opacity: 0; transform: translate(var(--sx, 10px), -90px) scale(.3); } }
.sg-lit-line { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; color: var(--sun-deep); }
:root[data-theme="dark"] .sg-lit-line { color: #FFD45C; }
.sg-run-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.sg-run-chip {
    display: inline-flex; align-items: center; gap: 6px; padding-block: 5px 5px; padding-inline: 8px 14px; border-radius: 999px; background: var(--sun-soft); color: #6B3A00;
    font-family: var(--font-display); font-weight: 600; font-size: .98rem;
}
.sg-run-chip .sg-ico { width: 22px; height: 22px; }
.sg-run-chip.is-combo { background: var(--coral-soft); color: var(--coral-deep); padding-inline-start: 6px; }
.sg-run-chip.is-combo b { display: inline-grid; place-items: center; min-width: 30px; height: 24px; padding: 0 6px; border-radius: 999px; background: var(--coral); color: #fff; font-size: .9rem; }
:root[data-theme="dark"] .sg-run-chip { background: rgba(255, 216, 107, .16); color: #FFE3A0; }
:root[data-theme="dark"] .sg-run-chip.is-combo { background: rgba(255, 127, 110, .18); color: #FFC7BC; }
.sg-visit-isle .sg-ico { width: 24px; height: 24px; }

/* ---------- Letter tracing: watch, trace, collect ---------- */
.sg-steps { display: flex; gap: 8px; margin: 0 0 12px; padding: 0; list-style: none; counter-reset: none; }
.sg-steps li {
    flex: 1; display: flex; align-items: center; gap: 8px; min-height: 46px; padding-block: 6px 6px; padding-inline: 6px 12px; border-radius: 16px;
    background: color-mix(in srgb, var(--ink) 6%, var(--paper)); color: var(--ink-soft); font-family: var(--font-display); font-weight: 600; font-size: .98rem;
    transition: background .3s, color .3s;
}
.sg-steps b {
    flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
    background: var(--paper); color: var(--ink-soft); box-shadow: inset 0 0 0 2px var(--line); transition: transform .4s var(--ease-bounce);
}
.sg-steps li.is-now { background: var(--grape-soft); color: var(--grape-deep); }
.sg-steps li.is-now b { background: var(--grape); color: #fff; box-shadow: none; transform: scale(1.12); }
.sg-steps li.is-done { background: var(--leaf-soft); color: var(--leaf-deep); }
.sg-steps li.is-done b { background: var(--leaf); color: transparent; box-shadow: none; position: relative; }
.sg-steps li.is-done b::after { content: ""; position: absolute; width: 14px; height: 8px; border: solid #fff; border-width: 0 0 3px 3px; transform: translateY(-2px) rotate(-45deg); }
:root[data-theme="dark"] .sg-steps li.is-now { background: rgba(141, 114, 240, .3); color: #fff; }
:root[data-theme="dark"] .sg-steps li.is-done { background: rgba(93, 191, 115, .22); color: #DDF8EE; }
@media (max-width: 560px) { .sg-steps li { font-size: .85rem; padding-inline-end: 8px; } .sg-steps b { width: 28px; height: 28px; } }

@media (max-width: 760px) {
    .sg-playbar { top: calc(var(--top-h) - 6px); }
    .sg-hud { gap: 10px; padding-inline-end: 12px; }
    .sg-hud-noor { width: 44px; height: 44px; }
    .sg-hud-noor .k-mascot-svg { width: 30px; height: 38px; }
    .sg-hud-stars small { display: none; }
    .sg-hud-say { top: calc(100% + 10px); inset-inline-end: auto; inset-inline-start: -2px; margin-top: 0; transform: translateY(-6px) scale(.7); }
    .sg-hud-say::before { top: -5px; inset-inline-end: auto; inset-inline-start: 20px; margin-top: 0; }
    .sg-lit { width: 240px; height: 190px; }
}

/* The whole word grid fits on the screen below the play bar, so a finger can drag from any letter to any other. */
@media (min-width: 761px) {
    .k-ws-grid { max-width: min(620px, calc(100vh - var(--top-h) - 110px)); }
}
