/* kids-fx.css: owned by the foundation (tools/kids/FUN.md section 3; the record is tools/kids/CONTRACT.md section 16a). Class prefix kx-.
 * The shared fun layer's look (platform/kids/js/47-fx.js, LR.fx): the colour tokens, the pictures' colour classes, scenes, particles,
 * the meter, the streak mark and the one end panel. Light only. No sound anywhere. Under prefers-reduced-motion nothing moves:
 * the script fades and every keyframe below is switched off. It loads before the areas' own sheets, so an area may restyle a kx- part. */

/* ---- the six colours: bright and warm on the light page. On a colour or its tint, write in var(--ink) or the colour's -deep
 *      (4.5:1 or better, checked by tools/kids/smoke_fx.js); on a -deep, write in white. ---- */
:root {
  --kx-rose: #FF8FA8;   --kx-rose-tint: #FFE8EE;   --kx-rose-deep: #86123A;
  --kx-sky: #6CC4FF;    --kx-sky-tint: #E3F3FF;    --kx-sky-deep: #08477F;
  --kx-mint: #6FDDA4;   --kx-mint-tint: #E1F8EB;   --kx-mint-deep: #075C36;
  --kx-amber: #FFC247;  --kx-amber-tint: #FFF1D0;  --kx-amber-deep: #6F4300;
  --kx-violet: #B9A0FF; --kx-violet-tint: #EFE9FF; --kx-violet-deep: #45259A;
  --kx-teal: #4FD5CE;   --kx-teal-tint: #DDF7F5;   --kx-teal-deep: #04574F;
  --kx-on-deep: #FFFFFF;
}
/* one class picks the colour for everything inside it: a picture, a card, a meter (--kx-c, --kx-c-tint, --kx-c-deep) */
.kx-c-rose { --kx-c: var(--kx-rose); --kx-c-tint: var(--kx-rose-tint); --kx-c-deep: var(--kx-rose-deep); }
.kx-c-sky { --kx-c: var(--kx-sky); --kx-c-tint: var(--kx-sky-tint); --kx-c-deep: var(--kx-sky-deep); }
.kx-c-mint { --kx-c: var(--kx-mint); --kx-c-tint: var(--kx-mint-tint); --kx-c-deep: var(--kx-mint-deep); }
.kx-c-amber { --kx-c: var(--kx-amber); --kx-c-tint: var(--kx-amber-tint); --kx-c-deep: var(--kx-amber-deep); }
.kx-c-violet { --kx-c: var(--kx-violet); --kx-c-tint: var(--kx-violet-tint); --kx-c-deep: var(--kx-violet-deep); }
.kx-c-teal { --kx-c: var(--kx-teal); --kx-c-tint: var(--kx-teal-tint); --kx-c-deep: var(--kx-teal-deep); }

/* ---- pictures (LR.fx.art): the parts that follow the colour ---- */
.kx-art { display: block; flex: none; width: var(--kx-art-size, 64px); height: var(--kx-art-size, 64px); overflow: visible; }
.kx-art--flip { transform: scaleX(-1); }
.kx-a { fill: var(--kx-c, var(--kx-amber)); }
.kx-b { fill: var(--kx-c-tint, var(--kx-amber-tint)); }
.kx-d { fill: var(--kx-c-deep, var(--kx-amber-deep)); }
.kx-l { fill: none; stroke: var(--kx-c-deep, var(--kx-amber-deep)); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.kx-l--fat { stroke-width: 5; }
.kx-l--ring { stroke-width: 9; }
.kx-l--xl { stroke-width: 11; }
.kx-sa { fill: none; stroke: var(--kx-c, var(--kx-amber)); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.kx-sa--fat { stroke-width: 6; }
.kx-sa--ring { stroke-width: 9; }
.kx-sa--road { stroke-width: 10; }
.kx-o { stroke: var(--kx-c-deep, var(--kx-amber-deep)); stroke-width: 2.5; stroke-linejoin: round; }

/* ---- scenes (LR.fx.scene): a full-bleed background behind whatever follows it inside a .kx-stage ----
 * The stage clips with `overflow: clip` (hidden where a browser has no clip): `hidden` would make the host a scroll container, and every
 * position: sticky key or bar inside a game (the practice games' answer keys, the race bar, the mixer's top) would stop sticking to the screen.
 * The drift, the waves and the twinkle repaint their SVG at every frame, and the clouds move about two pixels a second, so they step instead of gliding:
 * the clouds about 4 times a second (a step is under a pixel), the waves 8 times, the twinkle 5 times: the same look for a fraction of the main-thread work on a slow tablet. */
.kx-stage { position: relative; isolation: isolate; overflow: hidden; overflow: clip; border-radius: var(--r-panel, 16px); }
.kx-scene { position: absolute; inset: 0; z-index: -1; display: block; width: 100%; height: 100%; pointer-events: none; }
.kx-drift { animation: kx-drift 26s steps(100, end) infinite alternate; }
.kx-drift--b { animation-duration: 38s; animation-timing-function: steps(150, end); animation-direction: alternate-reverse; }
.kx-bob { animation: kx-bob 7s steps(56, end) infinite alternate; }
.kx-bob--b { animation-duration: 9s; animation-timing-function: steps(72, end); animation-direction: alternate-reverse; }
.kx-twinkle { animation: kx-twinkle 3.2s steps(16, end) infinite alternate; }
.kx-twinkle--1 { animation-duration: 4.1s; animation-timing-function: steps(20, end); animation-delay: -1.3s; }
.kx-twinkle--2 { animation-duration: 5s; animation-timing-function: steps(25, end); animation-delay: -2.2s; }
.kx-scene--still * { animation: none; }
@keyframes kx-drift { from { transform: translateX(-14px); } to { transform: translateX(22px); } }
@keyframes kx-bob { from { transform: translateX(0); } to { transform: translateX(40px); } }
@keyframes kx-twinkle { from { opacity: .45; } to { opacity: 1; } }

/* ---- calm loops for objects in a scene (the individual transform properties, so an element keeps its own transform): each turns in 2 seconds or more,
 *      --kx-d (a negative delay, e.g. -1.3s) keeps a group from moving together. kx-pulse animates `scale`: do not pop() the same element.
 *      kx-enter is a one-time arrival (a thing that appears: the next set of balloons). Under reduced motion: no loop, and an arrival is a fade.
 *      The arrival fills `backwards` only: it holds its first frame during a delay, and once it has arrived the element is its own again
 *      (a game may dim it, fade it, pop it or give it a :hover scale; `both` would have pinned opacity 1 and scale 1 for ever). ---- */
.kx-float { animation: kx-float 3.6s ease-in-out infinite alternate; animation-delay: var(--kx-d, 0s); }
.kx-sway { animation: kx-sway 4.2s ease-in-out infinite alternate; animation-delay: var(--kx-d, 0s); transform-origin: 50% 100%; }
.kx-pulse { animation: kx-pulse 2.4s ease-in-out infinite alternate; animation-delay: var(--kx-d, 0s); }
.kx-enter { animation: kx-enter .42s cubic-bezier(.3, .8, .4, 1) backwards; animation-delay: var(--kx-d, 0s); }
@keyframes kx-float { from { translate: 0 3px; } to { translate: 0 -7px; } }
@keyframes kx-sway { from { rotate: -3deg; } to { rotate: 3deg; } }
@keyframes kx-pulse { from { scale: 1; } to { scale: 1.06; } }
@keyframes kx-enter { from { opacity: 0; scale: .6; } to { opacity: 1; scale: 1; } }
@keyframes kx-fade { from { opacity: 0; } to { opacity: 1; } }

/* ---- particles, flying pictures, celebrations: clipped boxes that take no taps and never widen the page ---- */
.kx-layer { position: fixed; inset: 0; z-index: var(--z-toast, 70); overflow: hidden; pointer-events: none; contain: strict; }
/* no will-change on a particle: the script keeps at most ~120 alive, and a transform or opacity animation is lifted to the compositor while it runs anyway */
.kx-p { position: absolute; display: block; background: var(--kx-pc, var(--kx-amber)); pointer-events: none; }
.kx-p--stars { clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.kx-p--confetti { border-radius: 2px; }
.kx-p--round { border-radius: 50%; }
.kx-p--petals { border-radius: 80% 10% 80% 10%; }
/* the box of a flying picture is the picture's own size (a square for a drawing; the element's own width and height for a clone of a card), so what flies keeps its shape */
.kx-fly { position: absolute; display: grid; place-items: center; pointer-events: none; will-change: transform, opacity; }
.kx-fly > .kx-art { width: 100%; height: 100%; }
.kx-rel { position: relative; }
.kx-celebrate { position: absolute; inset: 0; z-index: 1; overflow: hidden; border-radius: inherit; pointer-events: none; contain: strict; }
.kx-rays {
  position: absolute; left: 50%; top: 34%; width: 150%; min-width: 480px; aspect-ratio: 1; border-radius: 50%; opacity: 0;
  transform: translate(-50%, -50%);
  background: repeating-conic-gradient(from 0deg, var(--kx-amber-tint) 0 12deg, transparent 12deg 30deg);
  -webkit-mask: radial-gradient(closest-side, #000 0, #000 28%, transparent 76%); mask: radial-gradient(closest-side, #000 0, #000 28%, transparent 76%);
}

/* ---- the meter (LR.fx.meter): a track that fills and a picture that advances along it ---- */
.kx-meter {
  --kx-p: 0; --kx-m-art: 44px;
  position: relative; display: block; width: 100%; max-width: 560px; height: calc(var(--kx-m-art) + 12px); margin-inline: auto;
}
html[data-band="little"] .kx-meter { --kx-m-art: 56px; }
.kx-meter__track {
  position: absolute; inset-inline: 0; bottom: 2px; height: 16px; overflow: hidden; border-radius: var(--r-pill, 999px);
  background: var(--kx-c-tint); box-shadow: inset 0 0 0 2px var(--kx-c-deep);
}
.kx-meter__fill {
  position: absolute; inset-block: 0; inset-inline-start: 0; width: calc(var(--kx-p) * 100%); border-radius: inherit;
  background: var(--kx-c); box-shadow: inset 0 0 0 2px var(--kx-c-deep); transition: width 450ms var(--ease, ease);
}
.kx-meter__tick { position: absolute; inset-block: 4px; inset-inline-start: calc(var(--kx-t) * 100%); width: 2px; margin-inline-start: -1px; background: var(--kx-c-deep); opacity: .4; }
.kx-meter__art {
  position: absolute; z-index: 1; bottom: 10px; inset-inline-start: calc(var(--kx-p) * (100% - var(--kx-m-art)));
  width: var(--kx-m-art); height: var(--kx-m-art); transition: inset-inline-start 450ms var(--ease, ease), left 450ms var(--ease, ease), right 450ms var(--ease, ease);
}
.kx-meter__end { position: absolute; bottom: 12px; inset-inline-end: 2px; width: calc(var(--kx-m-art) * .68); height: calc(var(--kx-m-art) * .68); }
.kx-meter__art > .kx-art, .kx-meter__end > .kx-art { width: 100%; height: 100%; }
.kx-meter.is-full .kx-meter__end { visibility: hidden; }
.kx-meter[dir="rtl"] .kx-meter__art > .kx-art { transform: scaleX(-1); }   /* a picture that faces right travels right to left: turn it round */

/* ---- the streak mark (LR.fx.streak): keeps its room, shows from three in a row, grows at five and eight ---- */
.kx-streak {
  display: inline-flex; align-items: center; justify-content: center; gap: 2px; min-width: 104px; min-height: 40px; padding: 2px 12px;
  border-radius: var(--r-pill, 999px); visibility: hidden;
}
.kx-streak:not([data-level="0"]) { visibility: visible; background: var(--kx-c-tint); box-shadow: inset 0 0 0 2px var(--kx-c); }
.kx-streak__star { display: none; width: 24px; height: 24px; }
.kx-streak[data-level="1"] .kx-streak__star--1,
.kx-streak[data-level="2"] .kx-streak__star--1, .kx-streak[data-level="2"] .kx-streak__star--2,
.kx-streak[data-level="3"] .kx-streak__star { display: block; }
.kx-streak[data-level="2"] .kx-streak__star { width: 28px; height: 28px; }
.kx-streak[data-level="3"] .kx-streak__star { width: 32px; height: 32px; }
.kx-streak__n { margin-inline-start: 6px; font: 800 1.125rem/1 var(--font-body, sans-serif); font-variant-numeric: tabular-nums; color: var(--kx-c-deep); }

/* ---- the end panel (LR.fx.endPanel): the one ending. Its root is also a .kg-end (the hooks the hosts and the smokes know).
 *      The panel never grows wider than its host: its one grid column is minmax(0, 1fr), the card and the star row may shrink (min-width: 0), and the stars
 *      take the room there is (10 to 46 px), so a bigger text size (Aa, a zoom of up to 1.5 on a phone) or a long best line cannot push the card sideways. ---- */
div.kx-end {
  position: relative; overflow: hidden; overflow: clip; display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; align-content: center; gap: 0;
  width: 100%; max-width: 100%; min-height: 300px; padding: 20px 12px 24px; box-sizing: border-box; text-align: center;
  border-radius: var(--r-sheet, 20px);
  background: radial-gradient(120% 90% at 50% 0%, var(--kx-c-tint) 0%, var(--paper, #FFFDF7) 72%);
}
div.kx-end.kx-end--empty { min-height: 0; padding: 20px 12px; background: none; }
/* 640 px: Again + Next: <a long game name> + Home is about 580 px wide, so the three keys stay in one row on a tablet and on a phone on its side */
.kx-end__card { position: relative; z-index: 2; display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; gap: 12px; width: 100%; min-width: 0; max-width: 640px; }
.kx-end .kx-end__pic { display: grid; place-items: center; margin: 0; }
.kx-end .kx-end__title { display: block; margin: 0; font: 800 var(--t-h1, 1.75rem)/1.15 var(--font-display, serif); color: var(--kx-c-deep); }
.kx-end .kx-end__stars { display: flex; flex-wrap: nowrap; justify-content: center; gap: 4px; width: 100%; min-width: 0; max-width: 100%; }
div.kx-end .kx-end__star {
  display: block; flex: none; width: clamp(10px, calc((100% - (var(--kx-n, 5) - 1) * 4px) / var(--kx-n, 5)), 46px); height: auto; aspect-ratio: 1;
  fill: none; stroke: none;
}
.kx-end__star > .kx-art { width: 100%; height: 100%; }
.kx-end__star:not(.is-on) .kx-a { fill: #F2EFE6; }
.kx-end__star:not(.is-on) .kx-o { stroke: var(--edge, #7A8A82); }
.kx-end__star:not(.is-on) path:not(.kx-a) { display: none; }
.kx-end .kx-end__score { margin: 0; font: 700 var(--t-h3, 1.25rem)/1.3 var(--font-body, sans-serif); color: var(--ink, #1A1F1C); }
.kx-end--empty .kx-end__score { max-width: 26em; font: 400 var(--t-body, 1.0625rem)/1.45 var(--font-body, sans-serif); color: var(--ink-soft, #4A5751); text-wrap: balance; }
.kx-end__praise { margin: 0; font: 400 var(--t-body, 1.0625rem)/1.45 var(--font-body, sans-serif); color: var(--ink-soft, #4A5751); }
.kx-end .kx-end__best {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; box-sizing: border-box; margin: 0; padding: 4px 14px 4px 8px; border-radius: var(--r-pill, 999px);
  background: var(--kx-violet-tint); color: var(--kx-violet-deep); font: 700 var(--t-sm, .9375rem)/1.3 var(--font-body, sans-serif); font-variant-numeric: tabular-nums;
}
.kx-end .kx-end__best.is-new { background: var(--kx-rose-tint); color: var(--kx-rose-deep); }
.kx-end__bestval { white-space: pre-wrap; }   /* keeps the space after "A new best!", and a long best line wraps inside the pill instead of running out of the panel */
.kx-end[data-band="little"] .kx-end__best { gap: 8px; padding: 4px 18px 4px 10px; }
.kx-end[data-band="little"] .kx-end__bestval { font: 800 1.5rem/1 var(--font-body, sans-serif); }   /* a Little reader's best: a ribbon and its number */
/* the keys keep their order (Again, Next, Home) whatever the width: they wrap in that order, never reorder */
.kx-end .kx-end__keys { display: flex; flex-wrap: wrap; align-items: stretch; justify-content: center; gap: 12px; width: 100%; margin-top: 8px; }
.kx-end__keys .key { min-width: var(--kids-target, 56px); min-height: max(var(--kids-target, 56px), 56px); }
.kx-end[data-band="little"] .kx-end__keys .key { min-width: 88px; min-height: 72px; padding: 0 16px; }
.kx-end[data-band="little"] .kx-end__keys .key.primary { min-width: 128px; }
.kx-end[data-band="little"] .kx-end__keys .key .icon { width: 36px; height: 36px; stroke-width: 2.4; }

/* A short window (a phone on its side, a small phone, a laptop with its bars open): the decoration gives way, a step at a time, so the three keys stay
 * on the first screen. The page's own bar and title above a game take about 135 px, so these heights are measured with them in place (tools/kids/smoke_fx.js,
 * "keys on the first screen"). 700: the picture shrinks; 600: it goes (Little ones, who have no words, keep a small one) and so does the praise line; 460: tighter still.
 * html.lr-short is the app's own mark for "under 500 px tall at the words' zoom" (Aa makes a window shorter); it takes the 460 rules too. */
@media (max-height: 700px) {
  div.kx-end { min-height: 0; }
  .kx-end__card { gap: 8px; }
  .kx-end .kx-end__pic .kx-art { width: 64px !important; height: 64px !important; }
  .kx-end[data-band="little"] .kx-end__pic .kx-art { width: 72px !important; height: 72px !important; }
}
@media (max-height: 600px) {
  div.kx-end { padding: 10px 12px 14px; }
  .kx-end[data-band="readers"] .kx-end__pic, .kx-end[data-band="big"] .kx-end__pic { display: none; }
  .kx-end[data-band="little"] .kx-end__pic .kx-art { width: 56px !important; height: 56px !important; }
  .kx-end .kx-end__praise { display: none; }
  .kx-end .kx-end__title { font-size: 1.375rem; }
  div.kx-end .kx-end__star { max-width: 34px; }
  .kx-end .kx-end__keys { margin-top: 4px; }
}
@media (max-height: 460px) {
  div.kx-end { padding: 6px 12px 8px; }
  .kx-end__card { gap: 4px; }
  .kx-end .kx-end__pic { display: none; }
  .kx-end .kx-end__title { font-size: 1.25rem; }
  div.kx-end .kx-end__star { max-width: 28px; }
  .kx-end[data-band="little"] .kx-end__keys .key { min-height: 64px; }
}
/* a small phone on its side (568 x 320, 640 x 360: the page's bar and title leave only 185 px of 320, and a card is 512 to 584 px wide): Again and Home are pictures
 * (their words stay for a screen reader), so Again, Next: <any game's name> and Home share one row; and under 340 px the title is for a screen reader only
 * (the stars and the score say it) */
@media (max-height: 460px) and (max-width: 640px) {
  .kx-end .kx-end__keys { gap: 8px; }
  .kx-end__keys .key { padding-inline: 12px; }
  .kx-end__keys .kx-end__again .key__label, .kx-end__keys .kx-end__home .key__label {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
  }
}
@media (max-height: 340px) {
  .kx-end .kx-end__title { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }
}
html.lr-short div.kx-end { padding: 6px 12px 8px; }
html.lr-short .kx-end__card { gap: 4px; }
html.lr-short .kx-end .kx-end__pic { display: none; }
html.lr-short .kx-end .kx-end__title { font-size: 1.25rem; }
html.lr-short div.kx-end .kx-end__star { max-width: 28px; }
html.lr-short .kx-end[data-band="little"] .kx-end__keys .key { min-height: 64px; }

/* ---- reduced motion: nothing moves. The script fades instead (pop, wobble, fly, burst, celebrate); a wrong answer shows a dashed outline. ---- */
@media (prefers-reduced-motion: reduce) {
  .kx-scene *, .kx-drift, .kx-bob, .kx-twinkle, .kx-float, .kx-sway, .kx-pulse { animation: none !important; }
  .kx-enter { animation: kx-fade .3s linear backwards !important; animation-delay: var(--kx-d, 0s) !important; }
  .kx-meter__fill, .kx-meter__art { transition: none !important; }
  .kx-wobble { outline: 3px dashed var(--kx-rose-deep); outline-offset: 3px; }
}
