:root {
  --ink: #3f5262; --muted: #6d7d8b; --line: #e3e6ea; --accent: #4f8a7e; --paper: #fdfaf3;
  --bg1: #fdf6e3; --bg2: #e8f4f8;
  --friend: min(max(34vmin, min(58vw, 38vh)), 300px);
  --round: "Nunito", "Trebuchet MS", "Arial Rounded MT Bold", system-ui, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--paper); color: var(--ink); font-family: system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Grown-up screen ---------- */
.parent { max-width: 940px; margin: 0 auto; padding: 28px 20px 48px; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--round); font-weight: 800; font-size: 22px; }
.brand-mark { font-size: 26px; }
.intro { margin: 34px 0 24px; }
.eyebrow { margin: 0 0 8px; font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
h1 { margin: 0 0 10px; font-family: var(--round); font-weight: 800; font-size: clamp(26px, 4vw, 38px); line-height: 1.15; letter-spacing: -.02em; max-width: 22ch; }
.intro p { margin: 0; color: var(--muted); line-height: 1.6; }

.levels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.level { position: relative; text-align: left; display: flex; flex-direction: column; gap: 10px; padding: 18px; background: #fff; border: 1px solid var(--line); border-radius: 18px; cursor: pointer; }
.level:hover:not(:disabled) { border-color: #c9d6d2; }
.level[aria-checked="true"] { border: 2px solid var(--accent); padding: 17px; box-shadow: 0 4px 0 #dbe8e4; }
.level:disabled { cursor: default; background: #f6f5f0; color: #8a929a; }
.level-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.level-num { font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.level-age { font-size: 13px; font-weight: 600; padding: 3px 10px; border-radius: 99px; background: #e9f2ef; color: #3e6e64; white-space: nowrap; }
.level:disabled .level-age { background: #ecebe5; color: #8a929a; }
.level-title { font-family: var(--round); font-weight: 800; font-size: 21px; display: flex; align-items: center; gap: 8px; }
.level-desc { font-size: 14px; line-height: 1.55; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; padding: 4px 9px; border-radius: 99px; background: #fbf0dc; color: #86663a; }
.level:disabled .chip { background: #efeee8; color: #8a929a; }
.soon { font-size: 12px; font-weight: 700; color: #9aa0a6; }

.options { display: flex; flex-wrap: wrap; gap: 18px 36px; margin: 26px 0 24px; }
.option-label { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 600; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: #efefe8; border-radius: 12px; }
.seg button { min-height: 40px; padding: 8px 14px; border: 0; border-radius: 9px; background: transparent; font-size: 14px; cursor: pointer; }
.seg button[aria-checked="true"] { background: #fff; font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.start { display: inline-flex; align-items: center; gap: 10px; padding: 15px 26px; border: 0; border-radius: 16px; background: var(--ink); color: #fff; font-family: var(--round); font-weight: 800; font-size: 19px; cursor: pointer; box-shadow: 0 5px 0 #26333f; }
.start:active { transform: translateY(3px); box-shadow: 0 2px 0 #26333f; }
.quit { padding: 13px 18px; border: 1px solid var(--line); border-radius: 14px; background: #fff; cursor: pointer; }
.lock-status { margin-top: 18px; font-size: 14px; line-height: 1.55; color: var(--muted); max-width: 70ch; }
.lock-status:empty { display: none; }
.lock-status b { color: var(--ink); }
.lock-status button { margin-left: 6px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; }
.tips { margin: 22px 0 0; padding-left: 18px; color: var(--muted); font-size: 14px; line-height: 1.7; max-width: 70ch; }
.credits { margin-top: 18px; font-size: 13px; color: var(--muted); line-height: 1.6; max-width: 70ch; }
.credits summary { cursor: pointer; }
.credits a { color: var(--ink); }
.old-link { margin-top: 18px; font-size: 13px; }
.old-link a { color: var(--muted); }
@media (max-width: 680px) { .levels { grid-template-columns: 1fr; } }

/* ---------- Play screen ---------- */
.play {
  position: fixed; inset: 0; overflow: hidden; cursor: pointer;
  background: linear-gradient(160deg, var(--bg1), var(--bg2));
  font-family: var(--round);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none;
}
.play::before { content: ""; position: absolute; inset: 0; background: var(--tint, transparent); transition: background-color 1.2s ease; }
.play:not([data-mode="free"]) .free, .play[data-mode="free"] .story { display: none; }
.play[data-mode="level-3"] .friend, .play:not([data-mode="level-3"]) .thing { display: none; }

/* Level 1: one friend at a time */
.story { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.bubble-row { position: relative; z-index: 1; height: max(15vmin, 72px); display: flex; align-items: flex-end; justify-content: center; padding-bottom: 14px; }
.bubble {
  position: relative; max-width: 90vw; padding: .22em .7em; border-radius: 1em; background: #fff; color: var(--ink);
  font-weight: 900; font-size: clamp(26px, 6.5vmin, 68px); line-height: 1.2; text-align: center;
  box-shadow: 0 6px 0 rgba(63, 82, 98, .08); opacity: 0; transform: scale(.6);
}
.bubble::after { content: ""; position: absolute; left: 50%; bottom: -13px; margin-left: -13px; border: 13px solid transparent; border-top-color: #fff; border-bottom: 0; }
.bubble.on { opacity: 1; transform: scale(1); transition: opacity .18s, transform .4s cubic-bezier(.3, 1.6, .5, 1); }
.friend { position: relative; width: calc(var(--friend) * 1.25); height: calc(var(--friend) * 1.15); flex-shrink: 0; }
.ground { position: absolute; left: 14%; right: 14%; bottom: 2%; height: 14%; border-radius: 50%; background: rgba(63, 82, 98, .08); }
.body, .squish { position: absolute; inset: 0; transform-origin: 50% 90%; }
.sprite {
  position: absolute; left: 50%; top: 0; width: calc(var(--friend) * 1.15); height: calc(var(--friend) * 1.15); margin-left: calc(var(--friend) * -0.575);
  background: url("assets/animals.png") no-repeat; background-size: 400% 200%; background-position: var(--ax, 0%) var(--ay, 0%); transform-origin: 50% 85%;
}
.friend.gone .body { opacity: 0; }
.sprite.anim-rig-host { position: absolute; } /* rig.css sets relative; the sprite must stay absolute. */
/* Peekaboo covers. The app picks the kind, color and pattern at random. */
.cover {
  --cover: #8cc4b6; --trim: #fff;
  position: absolute; left: -4%; right: -4%; top: -6%; bottom: 0; background-color: var(--cover);
  box-shadow: 0 10px 24px rgba(63, 82, 98, .16);
  transform: translateY(-140vh); transition: transform .8s cubic-bezier(.34, 1.25, .5, 1);
}
.friend.covered .cover { transform: translateY(0); }
.cover[data-kind="blanket"] { border-radius: 26% 26% 22% 22% / 18% 18% 14% 14%; box-shadow: inset 0 -14px 0 rgba(0,0,0,.12), 0 10px 24px rgba(63, 82, 98, .16); }
.cover[data-kind="blanket"][data-pattern="dots"] { background-image: radial-gradient(circle, rgba(255,255,255,.45) 17%, transparent 18%); background-size: 18% 18%; background-position: center; }
.cover[data-kind="blanket"][data-pattern="stripes"] { background-image: repeating-linear-gradient(-45deg, rgba(255,255,255,.35) 0 16px, transparent 16px 34px); }
.cover[data-kind="blanket"][data-pattern="checks"] { background-image: linear-gradient(90deg, rgba(255,255,255,.28) 50%, transparent 0), linear-gradient(rgba(255,255,255,.28) 50%, transparent 0); background-size: 48px 48px; }
.cover[data-kind="gift"] {
  left: 2%; right: 2%; top: -2%; border-radius: 7%;
  background-image: linear-gradient(90deg, transparent 44%, var(--trim) 44% 56%, transparent 56%), linear-gradient(transparent 30%, var(--trim) 30% 40%, transparent 40%), linear-gradient(rgba(0,0,0,.1) 0 18%, transparent 18%);
}
.cover[data-kind="box"] {
  left: 2%; right: 2%; top: -2%; border-radius: 9%;
  background-image: linear-gradient(rgba(0,0,0,.14) 0 16%, transparent 16%), radial-gradient(circle, rgba(255,255,255,.3) 12%, transparent 13%);
  background-size: 100% 100%, 22% 22%;
}
.cover-mark { display: none; }
.cover[data-kind="gift"] .cover-mark { display: block; position: absolute; left: 50%; top: 2%; width: 40%; height: 15%; transform: translateX(-50%); }
.cover[data-kind="gift"] .cover-mark::before, .cover[data-kind="gift"] .cover-mark::after {
  content: ""; position: absolute; top: 0; width: 50%; height: 100%; border: 10px solid var(--trim); border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
}
.cover[data-kind="gift"] .cover-mark::before { left: 0; transform: rotate(-18deg); }
.cover[data-kind="gift"] .cover-mark::after { right: 0; transform: rotate(18deg); }
.cover[data-kind="box"] .cover-mark { display: flex; position: absolute; inset: 16% 0 0; align-items: center; justify-content: center; font-size: calc(var(--friend) * .55); font-weight: 900; color: var(--trim); text-shadow: 0 4px 0 rgba(0,0,0,.12); }
.cover[data-kind="box"] .cover-mark::before { content: "?"; }
/* Wave: a big hand waves beside the friend (Level 1 and 2, hello and bye bye). */
.wave-hand { position: absolute; right: -19%; top: 8%; font-size: calc(var(--friend) * .36); line-height: 1; opacity: 0; transform: scale(.4); transform-origin: 70% 90%; pointer-events: none; transition: opacity .25s, transform .3s cubic-bezier(.3, 1.6, .5, 1); }
.wave-hand.on { opacity: 1; transform: scale(1); animation: hand-wave .5s ease-in-out .15s infinite alternate; }
@keyframes hand-wave { from { transform: rotate(-18deg); } to { transform: rotate(22deg); } }
.wave-hand.on.clap { animation: hand-clap .48s ease-in-out infinite; }
@keyframes hand-clap { 0%, 100% { transform: scale(1); } 35% { transform: scale(1.25) rotate(-6deg); } }
@media (prefers-reduced-motion: reduce) { .wave-hand.on, .wave-hand.on.clap { animation: none; } }
/* Level 2: a soft glow ring on a body part. Left/top/size are in % of the sprite. */
.spot { position: absolute; z-index: 2; width: var(--d); height: var(--d); transform: translate(-50%, -50%); border-radius: 50%; pointer-events: none;
  border: calc(var(--friend) * .014) solid #fff; box-shadow: 0 0 0 calc(var(--friend) * .012) rgba(255, 196, 64, .85), 0 0 calc(var(--friend) * .08) rgba(255, 210, 90, .9);
  animation: spot-in .35s cubic-bezier(.3, 1.6, .5, 1), spot-pulse 1.1s ease-in-out .35s infinite; }
@keyframes spot-in { from { transform: translate(-50%, -50%) scale(2.2); opacity: 0; } }
@keyframes spot-pulse { 50% { transform: translate(-50%, -50%) scale(1.15); } }
@media (prefers-reduced-motion: reduce) { .spot { animation: none; } }
/* Level 3: one thing (a big emoji) in the middle. */
.thing { position: relative; width: calc(var(--friend) * 1.25); height: calc(var(--friend) * 1.15); flex-shrink: 0; transition: opacity .3s; }
.thing.gone, .thing.away { opacity: 0; }
.thing .ground { left: 22%; right: 22%; }
.thing-body { position: absolute; inset: 0; display: grid; place-items: center; transform-origin: 50% 90%; }
.thing-emoji { font-size: calc(var(--friend) * .78); line-height: 1; filter: drop-shadow(0 8px 10px rgba(63, 82, 98, .18)); }
.thing[data-id="car"] .thing-emoji, .thing[data-id="car"] .thing-img { transform: scaleX(-1); } /* The car emoji and the car picture face left; the drive move goes right. */
/* Level 3 pictures (2026-12-02, house style, assets/things/<id>.webp). The emoji shows only when the picture does not load. */
.thing-img { width: 84%; height: 84%; object-fit: contain; filter: drop-shadow(0 8px 10px rgba(63, 82, 98, .18)); user-select: none; pointer-events: none; }
.thing-img[hidden] { display: none; }
.caption { height: 1.25em; margin-top: 1vmin; font-weight: 900; font-size: clamp(40px, 9vmin, 100px); line-height: 1.2; letter-spacing: -.01em; color: var(--ink); opacity: 0; transition: opacity .4s; }
.caption.on { opacity: 1; }
.paw { position: absolute; left: 50%; top: 50%; font-size: 18vmin; opacity: 0; transform: translate(-50%, -50%); pointer-events: none; transition: opacity .6s; }
.paw.on { opacity: .2; animation: paw 2.4s ease-in-out infinite; }

.a-enter { animation: enter .75s cubic-bezier(.3, 1.3, .5, 1) both; }
.a-leave { animation: leave 1.5s ease-in forwards; }
.a-jump { animation: jump .8s ease-out; }
.a-wiggle { animation: wiggle .9s ease-in-out; }
.a-squish { animation: squish .24s ease-out; }
.a-bounce { animation: bounce 1.4s ease-in-out; }
.a-tilt { animation: tilt 1.4s ease-in-out; }
.a-sway { animation: sway 1.6s ease-in-out; }
.a-waddle { animation: waddle 1.4s ease-in-out; }
.a-nod { animation: nod 1.4s ease-in-out; }
.a-stretch { animation: stretch 1.6s ease-in-out; }
@keyframes enter { 0% { transform: translateY(35%) scale(.3); opacity: 0; } 60% { transform: translateY(-5%) scale(1.08); opacity: 1; } 80% { transform: scale(.97); } 100% { transform: none; opacity: 1; } }
@keyframes leave { 0% { transform: none; } 12% { transform: rotate(-8deg); } 24% { transform: rotate(8deg); } 36% { transform: rotate(-8deg); } 48% { transform: rotate(0); } 100% { transform: translateX(130vw) rotate(12deg); } }
@keyframes jump { 0% { transform: translateY(14%) scale(.9); } 40% { transform: translateY(-12%) scale(1.06, 1.04); } 65% { transform: scale(1.04, .96); } 100% { transform: none; } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-5deg); } 50% { transform: rotate(5deg); } 75% { transform: rotate(-2deg); } }
@keyframes squish { 50% { transform: scale(1.06, .94); } }
@keyframes bounce { 0%, 100% { transform: none; } 20% { transform: scale(1.05, .95); } 40% { transform: translateY(-14%) scale(.97, 1.04); } 60% { transform: scale(1.04, .96); } 75% { transform: translateY(-6%); } }
@keyframes tilt { 0%, 100% { transform: none; } 25%, 55% { transform: rotate(-10deg) translateY(-2%); } 80% { transform: rotate(4deg); } }
@keyframes sway { 0%, 100% { transform: none; } 25% { transform: rotate(-7deg) translateX(-4%); } 60% { transform: rotate(7deg) translateX(4%); } 85% { transform: rotate(-2deg); } }
@keyframes waddle { 0%, 100% { transform: none; } 15%, 45%, 75% { transform: rotate(-9deg) translateX(-3%); } 30%, 60%, 90% { transform: rotate(9deg) translateX(3%); } }
@keyframes nod { 0%, 100% { transform: none; } 20%, 60% { transform: rotate(6deg) translateY(3%); } 40%, 80% { transform: rotate(-3deg); } }
@keyframes stretch { 0%, 100% { transform: none; } 40% { transform: scale(1.12, 1.1) translateY(-4%); } 70% { transform: scale(1.03) rotate(-3deg); } }
@keyframes paw { 50% { transform: translate(-50%, -54%) scale(1.06); } }

/* Free play (the first fun3 game) */
.free { position: absolute; inset: 0; }
.free-hint { position: absolute; inset: auto 0 8vh 0; text-align: center; font-size: clamp(1.4rem, 4vw, 2.6rem); color: #7a8a99; animation: breathe 3s ease-in-out infinite; transition: opacity 1s; pointer-events: none; }
.free-hint.gone { opacity: 0; }
@keyframes breathe { 50% { transform: scale(1.05); opacity: .7; } }
.item { position: absolute; pointer-events: none; will-change: transform, opacity; }
.f-animal { text-align: center; transform: translate(-50%, -50%); animation: pop 2.8s ease-in-out forwards; }
.f-animal .emoji-big { font-size: clamp(7rem, 22vw, 15rem); line-height: 1; }
.f-animal .name { font-size: clamp(1.6rem, 5vw, 3.2rem); font-weight: 800; color: #5b6b7b; margin-top: .2em; }
@keyframes pop { 0% { transform: translate(-50%, -50%) scale(.2); opacity: 0; } 18% { transform: translate(-50%, -50%) scale(1.08); opacity: 1; } 30% { transform: translate(-50%, -50%) scale(1); } 80% { transform: translate(-50%, -52%) scale(1); opacity: 1; } 100% { transform: translate(-50%, -60%) scale(.9); opacity: 0; } }
.f-letter { font-weight: 900; transform: translate(-50%, -50%); animation: floatup 3s ease-out forwards; }
@keyframes floatup { 0% { transform: translate(-50%, -30%) scale(.3); opacity: 0; } 20% { transform: translate(-50%, -50%) scale(1); opacity: .9; } 100% { transform: translate(-50%, -150%) scale(1); opacity: 0; } }
.f-bubble { border-radius: 50%; bottom: -120px; background: radial-gradient(circle at 30% 30%, #fff, rgba(255,255,255,.2) 40%, rgba(150,200,255,.35)); border: 2px solid rgba(255,255,255,.7); animation: rise linear forwards; }
@keyframes rise { to { transform: translateY(-120vh) translateX(var(--dx)); opacity: .6; } }
.f-star { transform: translate(-50%, -50%); animation: twinkle 2.5s ease-in-out forwards; }
@keyframes twinkle { 0% { transform: translate(-50%, -50%) scale(0) rotate(0); opacity: 0; } 30% { opacity: 1; } 100% { transform: translate(-50%, -50%) scale(1.3) rotate(120deg); opacity: 0; } }
.f-ring { border-radius: 50%; border: 6px solid; transform: translate(-50%, -50%); animation: ripple 2.4s ease-out forwards; }
@keyframes ripple { from { width: 20px; height: 20px; opacity: .8; } to { width: 40vmin; height: 40vmin; opacity: 0; } }
.f-shape { transform: translate(-50%, -50%); animation: wobble 3s ease-in-out forwards; }
@keyframes wobble { 0% { transform: translate(-50%, -50%) scale(0); opacity: 0; } 25% { transform: translate(-50%, -50%) scale(1.1) rotate(-6deg); opacity: .9; } 50% { transform: translate(-50%, -50%) scale(1) rotate(6deg); } 100% { transform: translate(-50%, -50%) scale(.6) rotate(0); opacity: 0; } }
.f-drift { transform: translate(-50%, -50%); animation: drift 4s ease-in-out forwards; }
@keyframes drift { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.5); } 20% { opacity: 1; } 100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), -200%) scale(1); } }

/* Small reply to presses that come while a step still plays */
.boops { position: absolute; inset: 0; pointer-events: none; }
.boop { position: absolute; bottom: -60px; left: var(--x); width: var(--s); height: var(--s); border-radius: 50%; background: var(--c); opacity: .75; animation: boop 1.6s ease-out forwards; }
.boop.star { background: none; width: auto; height: auto; font-size: var(--s); line-height: 1; }
@keyframes boop { to { transform: translateY(-45vh) scale(.6); opacity: 0; } }

/* Session end */
.done { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4vmin; background: linear-gradient(#2f3e58, #4a5d80); color: #fdf3d8; opacity: 0; transition: opacity 1.4s; z-index: 2; }
.done.on { opacity: 1; }
.moon { position: absolute; top: 9vmin; right: 14vmin; width: 13vmin; height: 13vmin; border-radius: 50%; box-shadow: -3vmin 2vmin 0 0 #f7e3a1; }
.sleepers { display: flex; flex-wrap: wrap; justify-content: center; gap: 2vmin; max-width: 92vw; font-size: min(10vmin, 96px); }
.sleeper { width: min(10vmin, 96px); height: min(10vmin, 96px); background: url("assets/animals.png") no-repeat; background-size: 400% 200%; background-position: var(--ax) var(--ay); }
.sleepers span { animation: rock 3.2s ease-in-out infinite; animation-delay: var(--d); }
@keyframes rock { 50% { transform: rotate(-6deg) translateY(4%); } }
.done-word { font-weight: 900; font-size: clamp(44px, 10vmin, 110px); }

/* Corner buttons for grown-ups */
.corner { position: absolute; z-index: 5; display: grid; place-items: center; width: 56px; height: 56px; padding: 0; border: 0; border-radius: 50%; background: rgba(255,255,255,.5); cursor: pointer; opacity: .55; }
.hold { top: max(14px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right)); }
.fs { top: max(14px, env(safe-area-inset-top)); left: max(14px, env(safe-area-inset-left)); }
.corner svg { width: 56px; height: 56px; fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; }
.fs svg { width: 26px; height: 26px; stroke-width: 2; }
.hold .ring-bg { stroke: rgba(63,82,98,.15); }
.hold .ring { stroke: var(--accent); stroke-width: 4; stroke-dasharray: 151; stroke-dashoffset: 151; transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset .2s; }
.hold.holding { opacity: 1; }
.hold.holding .ring { stroke-dashoffset: 0; transition: stroke-dashoffset 2s linear; }
.hold-tip { position: absolute; right: 64px; top: 16px; white-space: nowrap; font-size: 14px; font-weight: 700; color: var(--ink); opacity: 0; }
.hold.holding .hold-tip { opacity: 1; }
.done ~ .corner svg { stroke: #fdf3d8; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .boops, .f-bubble, .f-star, .f-drift { display: none; }
}
