/* AvaTails premium layer: one design language for every game and lesson.
   Loaded after app.css. Each screen gets its own accent through body[data-screen]; everything else is shared:
   a slim screen bar, soft layered depth, a speech bubble from Ava, segmented tabs, chunky page chips,
   a glossy colour dock and a gentle entrance. Motion is switched off for people who ask for less. */

:root {
  --accent: #D9467F; --accent-soft: #FDE3EE; --wash: #FFF6E8;
  --lift: 0 5px 0 var(--ink), 0 14px 30px rgba(31, 42, 68, .12);
  --lift-sm: 0 3px 0 var(--ink), 0 8px 18px rgba(31, 42, 68, .1);
  --r-lg: 30px; --r-md: 22px;
}
body[data-screen="bookView"]  { --accent: #E8A20A; --accent-soft: #FFF1C2; --wash: #FFF4D6; }
body[data-screen="paintView"] { --accent: #2E9E5B; --accent-soft: #DDF3E5; --wash: #ECF8F0; }
body[data-screen="trace"]     { --accent: #F06A2A; --accent-soft: #FFE6D8; --wash: #FFF0E6; }
body[data-screen="words"]     { --accent: #D9467F; --accent-soft: #FDE3EE; --wash: #FFEFF5; }
body[data-screen="garden"]    { --accent: #2E9E5B; --accent-soft: #DDF3E5; --wash: #EEF9F1; }
body[data-screen="pizza"]     { --accent: #E15E22; --accent-soft: #FFE4D4; --wash: #FFF1E8; }
body[data-screen="monsters"]  { --accent: #8A5BD6; --accent-soft: #EEE5FB; --wash: #F5F0FD; }
body[data-screen="build"]     { --accent: #D9468A; --accent-soft: #FDE4EF; --wash: #FFF0F6; }
body[data-screen="world"]     { --accent: #2F6FD0; --accent-soft: #E0EDFF; --wash: #EEF5FF; }

/* A soft coloured wash behind each activity, fading into the cream page. */
body:not(.on-home) { background-image: linear-gradient(180deg, var(--wash) 0, var(--wash) 220px, rgba(255, 246, 232, 0) 520px), none; background-color: var(--ground); }

/* ---------- Screen bar ---------- */
body:not(.on-home) header { background: rgba(255, 255, 255, .78); border: 3px solid var(--ink); border-radius: 999px; padding: 6px 8px 6px 10px; box-shadow: var(--lift-sm);
  -webkit-backdrop-filter: saturate(1.4) blur(8px); backdrop-filter: saturate(1.4) blur(8px); position: sticky; top: max(8px, env(safe-area-inset-top, 0px)); z-index: 20; }
body:not(.on-home) .brand .duo.small svg { width: 36px; } body:not(.on-home) .brand .duo.small svg + svg { width: 32px; }
body:not(.on-home) .brand h1 { font-size: 1.05rem; color: var(--ink-soft); }
body:not(.on-home) .brand small { font-size: clamp(1.15rem, 2.6vw, 1.5rem); font-family: var(--display); letter-spacing: 0; text-transform: none; color: var(--ink); margin-top: 0; }
body:not(.on-home) #musicLabel, body:not(.on-home) #soundLabel { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
body:not(.on-home) #musicBtn, body:not(.on-home) #soundBtn { width: 46px; padding: 0; }
#homeBtn { background: var(--accent); color: #fff; }
.tally { background: var(--page); border: 3px solid var(--ink); border-radius: 999px; padding: 2px 12px 2px 6px; box-shadow: var(--lift-sm); }
body:not(.on-home) .foot-row { display: none; }

/* ---------- Buttons ---------- */
.btn { transition: transform .12s ease, box-shadow .12s ease, background-color .15s ease; }
@media (hover: hover) { .btn:not(:disabled):hover { transform: translateY(-2px); box-shadow: 0 6px 0 var(--ink); } }
.btn.mode[aria-pressed="true"], .btn[aria-pressed="true"].mode { background: var(--accent); color: #fff; }

/* ---------- Segmented tabs (Capital / Little / Numbers, Say it / Spell it ...) ---------- */
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 5px; background: var(--page); border: 3px solid var(--ink); border-radius: 999px; box-shadow: var(--lift-sm); justify-self: start; width: max-content; max-width: 100%; }
.seg .btn { border-color: transparent; box-shadow: none; min-height: 42px; background: transparent; }
.seg .btn:hover { transform: none; box-shadow: none; background: var(--accent-soft); }
.seg .btn[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--ink); box-shadow: 0 3px 0 var(--ink); }
.build-bar .seg { justify-self: auto; }

/* ---------- Ava's speech bubble ---------- */
.game-head { gap: 12px; }
.game-head .listen { order: 2; width: 54px; height: 54px; min-height: 0; padding: 0; border-radius: 50%; font-size: 0; gap: 0; background: var(--accent); flex: none; }
.game-head .listen .spk svg { width: 26px; height: 26px; }
.game-head .listen::after { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 3px solid var(--accent); opacity: 0; animation: ring 2.4s ease-out infinite; pointer-events: none; }
.game-head .listen { position: relative; }
.bubble { order: 1; position: relative; display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 8px 18px 8px 8px; border-radius: 999px; box-shadow: var(--lift-sm);
  font-size: clamp(1.05rem, 2.4vw, 1.3rem); line-height: 1.2; }
.bubble::before { content: ""; flex: none; width: 48px; height: 48px; border-radius: 50%; border: 3px solid var(--ink); background: #F8D7B5 url("../art/ava-face.jpg") center / cover; }
.game-head .chip { order: 3; }
.chip { background: var(--page); box-shadow: 0 2px 0 var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- Side card with the big letter and page chips ---------- */
.letter-card { border-radius: var(--r-lg); box-shadow: var(--lift); background: linear-gradient(180deg, var(--accent-soft) 0, var(--page) 46%); }
.letter { color: var(--accent); filter: drop-shadow(0 2px 0 rgba(31, 42, 68, .15)); }
.dots { gap: 6px; }
.dot { min-width: 34px; height: 34px; border-radius: 11px; border-width: 2.5px; box-shadow: 0 2px 0 var(--ink); transition: transform .12s ease; }
.dot:hover { transform: translateY(-1px); }
.dot.done { background: #DDF3E5; position: relative; }
.dot.done::after { content: ""; position: absolute; right: -5px; top: -5px; width: 13px; height: 13px; border-radius: 50%; background: #2E9E5B; border: 2px solid var(--ink); }
.dot[aria-current="true"] { background: var(--accent); color: #fff; transform: translateY(-2px); box-shadow: 0 4px 0 var(--ink); }
.arrow { width: 48px; height: 48px; border-radius: 50%; }
.letter-card .nav .arrow { width: 42px; height: 42px; }
.letter-card .dots { gap: 5px; }
.letter-card .dot { min-width: 31px; height: 31px; font-size: .8rem; }
.actions .arrow:not(:disabled) { background: var(--accent); color: #fff; }
.nav .arrow:not(:disabled) { background: var(--accent); color: #fff; }

/* ---------- Stages: the page, scenes and play fields ---------- */
.page, .scene, .field, .stage-box { border-radius: var(--r-lg); box-shadow: var(--lift); }
.page { background: #fff; background-image: radial-gradient(circle at 1px 1px, rgba(31, 42, 68, .05) 1px, transparent 0); background-size: 22px 22px; }
.pizza-stage { padding: clamp(14px, 3vw, 26px); border: 3px solid var(--ink); border-radius: var(--r-lg); box-shadow: var(--lift);
  background: repeating-linear-gradient(90deg, #EFC79D 0 46px, #E9BD8F 46px 92px); }
.pizza-stage svg#pizzaArt { filter: drop-shadow(0 10px 0 rgba(31, 42, 68, .18)); }
.kip-side svg { width: clamp(96px, 16vw, 150px); height: auto; filter: drop-shadow(0 4px 0 rgba(31, 42, 68, .2)); }
.sum { font-family: var(--display); font-weight: 800; font-size: clamp(1.4rem, 3.4vw, 2rem); }

/* ---------- Colour dock ---------- */
.tray { border-radius: var(--r-lg); box-shadow: var(--lift); background: rgba(255, 255, 255, .92); }
.fam { width: 42px; height: 42px; background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, .55) 0 18%, transparent 19%), var(--c); box-shadow: 0 2px 0 var(--ink); }
.shade { width: 58px; height: 58px; background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, .5) 0 16%, transparent 17%), var(--c); box-shadow: 0 3px 0 var(--ink); }
.shade.eraser { background: repeating-linear-gradient(45deg, #fff 0 6px, #E8EEF2 6px 12px); }
.fam[aria-pressed="true"], .shade[aria-pressed="true"] { box-shadow: 0 0 0 4px var(--page), 0 0 0 7px var(--accent); }
.tools .btn { min-height: 46px; }
@media (max-width: 760px) {
  /* One slim bar on phones: back, title, stars and sound, all on one line. */
  body:not(.on-home) header { flex-wrap: nowrap; gap: 6px; padding: 5px 6px 5px 8px; }
  body:not(.on-home) header .brand { flex: 1 1 auto; min-width: 0; }
  body:not(.on-home) .brand .duo, body:not(.on-home) .brand h1 { display: none; }
  body:not(.on-home) .brand small { font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  body:not(.on-home) header .right { flex-wrap: nowrap; gap: 5px; flex: none; }
  body:not(.on-home) #homeBtn { order: -1; width: 42px; min-height: 42px; padding: 0; font-size: 0; gap: 0; }
  body:not(.on-home) header .right .btn { min-height: 42px; }
  body:not(.on-home) #musicBtn, body:not(.on-home) #soundBtn { width: 42px; }
  .tally { font-size: 1rem; padding: 1px 9px 1px 4px; } .tally svg { width: 22px; height: 22px; }
  .seg { display: flex; width: 100%; }
  .seg .btn { flex: 1 1 auto; padding: 6px 10px; font-size: .92rem; }
  .game-head .bubble { flex: 1 1 calc(100% - 66px); }
  .game-head .chip { order: 4; }
}

/* ---------- Game pieces ---------- */
.pots .pot, .tile, .pic-btn, .topping-btn { transition: transform .14s ease, box-shadow .14s ease; }
@media (hover: hover) { .pots .pot:hover, .pic-btn:hover { transform: translateY(-4px); } }
.gallery-box, .book-strip { border: 3px solid var(--ink); border-radius: var(--r-lg); background: var(--page); box-shadow: var(--lift-sm); padding: 14px 18px; }

/* ---------- Entrance and idle motion ---------- */
.screen-in > .stack > *, .screen-in > .spread > *, .screen-in > .stack > .spread > * { animation: riseIn .5s cubic-bezier(.2, .8, .3, 1) both; }
.screen-in > .stack > *:nth-child(2), .screen-in > .spread > *:nth-child(2), .screen-in > .stack > .spread > *:nth-child(2) { animation-delay: .06s; }
.screen-in > .stack > *:nth-child(3) { animation-delay: .12s; }
.screen-in > .stack > *:nth-child(4) { animation-delay: .18s; }
@keyframes riseIn { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes ring { 0% { opacity: .7; transform: scale(.9); } 70%, 100% { opacity: 0; transform: scale(1.25); } }
@media (prefers-reduced-motion: reduce) {
  .screen-in > .stack > *, .screen-in > .spread > *, .screen-in > .stack > .spread > * { animation: none; }
  .game-head .listen::after { animation: none; }
  .btn:hover, .dot:hover, .pots .pot:hover, .pic-btn:hover { transform: none; }
}

/* ---------- Logo: Ava and Tuppy badge (reacts like the old drawn pair) ---------- */
.logo { display: inline-flex; flex: none; transform-origin: 50% 90%; }
.logo img { width: 52px; height: 52px; border-radius: 50%; display: block; filter: drop-shadow(0 3px 0 rgba(31, 42, 68, .25)); }
body:not(.on-home) .logo img { width: 40px; height: 40px; }
#buddy.talking img { animation: talk .5s ease-in-out infinite alternate; }
#buddy.yay img { animation: hop .45s ease-out 2; }
#buddy.cheer img { animation: hop .5s ease-out 3; }
#buddy.oops img { animation: wobble .5s ease-in-out; }
@media (max-width: 760px) { body:not(.on-home) .logo { display: none; } }
@media (prefers-reduced-motion: reduce) { #buddy img { animation: none !important; } }
.kip-side .tuppy-pic { width: clamp(110px, 18vw, 170px); height: auto; border-radius: 50%; filter: drop-shadow(0 6px 0 rgba(31, 42, 68, .2)); }
img.cover-kip { border-radius: 50%; filter: drop-shadow(0 3px 0 rgba(31, 42, 68, .25)); }
.win-logo img { width: clamp(96px, 16vw, 140px); height: auto; border-radius: 50%; animation: hop 1s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .win-logo img { animation: none; } }

/* ================= Home: hello hero, six category tiles, progress ================= */
body.on-home { background-image: linear-gradient(180deg, #CFEAFB 0, #EAF6FE 340px, rgba(255, 246, 232, 0) 640px), none; }
.home-hero { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); align-items: end; gap: 8px 24px;
  border: 3px solid var(--ink); border-radius: 34px; overflow: hidden; box-shadow: var(--lift);
  background: radial-gradient(circle at 18% 22%, rgba(255, 255, 255, .85) 0 7%, transparent 7.4%), radial-gradient(circle at 34% 12%, rgba(255, 255, 255, .7) 0 4%, transparent 4.3%),
    linear-gradient(180deg, #8FD0F5 0%, #C7E8FB 55%, #FFF3D6 100%); min-height: clamp(260px, 34vw, 380px); }
.hh-text { position: relative; z-index: 2; align-self: center; padding: clamp(18px, 3.4vw, 40px) 0 clamp(18px, 3vw, 34px) clamp(18px, 3.6vw, 44px); display: grid; gap: 10px; justify-items: start; }
.hh-kicker { margin: 0; display: inline-flex; align-items: center; gap: 8px; font-family: var(--display); font-weight: 800; color: var(--pink); background: rgba(255, 255, 255, .85);
  border: 2.5px solid var(--ink); border-radius: 999px; padding: 3px 14px 3px 4px; }
.hh-kicker img { width: 32px; height: 32px; border-radius: 50%; }
.hh-hello { margin: 0; font-family: var(--display); font-weight: 800; font-size: clamp(2.4rem, 6.4vw, 4.6rem); line-height: .95; letter-spacing: -.01em; color: var(--ink);
  text-shadow: 0 3px 0 #fff, 0 6px 18px rgba(255, 255, 255, .6); }
.hh-hello #kidName { color: var(--pink); }
.hh-sub { margin: 0; font-weight: 800; font-size: clamp(1.05rem, 2.2vw, 1.35rem); color: #2E3B5C; }
.hh-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 6px; }
#tryFirst { background: linear-gradient(180deg, #FF9A3D, #F06A2A); font-size: clamp(1.05rem, 2vw, 1.25rem); min-height: 56px; padding: 10px 24px 10px 18px; }
#tryFirst svg { width: 24px; height: 24px; }
.home-hero .hero-stars { background: rgba(255, 255, 255, .92); }
.hh-art { position: relative; z-index: 1; width: 100%; height: 100%; max-height: 420px; object-fit: cover; object-position: 50% 20%; align-self: stretch;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 16%); mask-image: linear-gradient(90deg, transparent 0, #000 16%); }

.cats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: clamp(10px, 1.6vw, 18px); }
.cat { --c1: #FFD95C; --c2: #FFC21F; position: relative; display: grid; grid-template-rows: 1fr auto auto; justify-items: center; text-align: center; gap: 2px;
  min-height: clamp(170px, 19vw, 230px); padding: 14px 10px 46px; border: 3px solid var(--ink); border-radius: 28px; color: var(--ink);
  background: radial-gradient(circle at 30% 18%, rgba(255, 255, 255, .55) 0 22%, transparent 23%), linear-gradient(170deg, var(--c1), var(--c2));
  box-shadow: 0 6px 0 var(--ink), 0 16px 30px rgba(31, 42, 68, .14); transition: transform .16s ease, box-shadow .16s ease; animation: riseIn .5s cubic-bezier(.2, .8, .3, 1) both; animation-delay: calc(var(--i) * 45ms); }
@media (hover: hover) { .cat:hover { transform: translateY(-5px) rotate(-.6deg); box-shadow: 0 10px 0 var(--ink), 0 22px 36px rgba(31, 42, 68, .16); } .cat:hover .cat-icon, .cat:hover .cat-fan { transform: scale(1.06); } }
.cat:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
.cat-teal { --c1: #7FE0D8; --c2: #2FC2B5; } .cat-sun { --c1: #FFE27A; --c2: #FFC21F; } .cat-sky { --c1: #9DD6FF; --c2: #4FA8F0; }
.cat-lime { --c1: #C9EE7A; --c2: #8DD435; } .cat-grape { --c1: #D2B8FF; --c2: #A77BF0; } .cat-rose { --c1: #FFB5D3; --c2: #F477A8; }
.cat-art { display: grid; place-items: center; width: 100%; min-height: 0; }
.cat-icon { width: 92%; max-width: 170px; max-height: 120px; object-fit: contain; filter: drop-shadow(0 6px 6px rgba(31, 42, 68, .18)); transition: transform .2s ease; }
.cat-fan { position: relative; display: block; width: 120px; height: 112px; transition: transform .2s ease; }
.cat-fan img { position: absolute; bottom: 0; left: 50%; width: 68px; border: 2.5px solid var(--ink); border-radius: 6px; box-shadow: 0 4px 0 rgba(31, 42, 68, .3); }
.cat-fan img:nth-child(1) { transform: translateX(-95%) rotate(-12deg); } .cat-fan img:nth-child(2) { transform: translateX(-5%) rotate(12deg); } .cat-fan img:nth-child(3) { transform: translateX(-50%) translateY(-6px); z-index: 1; }
.cat-name { font-family: var(--display); font-weight: 800; font-size: clamp(1.1rem, 1.7vw, 1.4rem); line-height: 1.05; }
.cat-meta { font-size: .82rem; font-weight: 800; color: rgba(31, 42, 68, .72); }
.cat-go { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); width: 34px; height: 34px; border-radius: 50%; background: #fff; border: 2.5px solid var(--ink); display: grid; place-items: center; }
.cat-go svg { width: 18px; height: 18px; }

.home-pills { display: flex; justify-content: center; }
.pill-btn { display: inline-flex; align-items: center; gap: 10px; min-height: 52px; padding: 8px 22px; border: 3px solid var(--ink); border-radius: 999px; background: #fff;
  font: 800 1.1rem var(--display); color: var(--ink); box-shadow: var(--lift-sm); cursor: pointer; }
.pill-btn span { font-size: 1.4rem; }

.prog-card { max-width: 560px; width: min(560px, 94vw); max-height: 86vh; overflow: auto; text-align: left; }
.prog-total { font-weight: 800; color: var(--ink-soft); margin: 4px 0 12px; }
.prog-list { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 10px; }
.prog-list li { display: grid; grid-template-columns: minmax(0, 1fr) 30% auto; align-items: center; gap: 10px; font-weight: 800; }
.prog-list .meter { margin: 0; } .prog-list .meter > span { background: #2E9E5B; }
.pl-text { font-size: .85rem; color: var(--ink-soft); white-space: nowrap; }

@media (max-width: 1080px) { .cats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 640px) {
  .home-hero { grid-template-columns: 1fr; }
  .hh-art { order: -1; max-height: 230px; -webkit-mask-image: linear-gradient(180deg, #000 78%, transparent); mask-image: linear-gradient(180deg, #000 78%, transparent); }
  .hh-text { padding: 0 18px 20px; margin-top: -26px; justify-items: center; text-align: center; }
  .hh-actions { justify-content: center; }
  .cats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cat { min-height: 160px; }
  .prog-list li { grid-template-columns: 1fr auto; } .prog-list .meter { grid-column: 1 / -1; grid-row: 2; }
}
@media (prefers-reduced-motion: reduce) { .cat { animation: none; } .cat:hover { transform: none; } }
/* Washes paint once at the top, never repeat down the page. */
body { background-repeat: no-repeat; }
body.on-home, body:not(.on-home) { background-repeat: no-repeat; }
.cat-fan { width: 104px; height: 92px; }
.cat-fan img { width: 56px; }
@media (max-width: 640px) {
  body.on-home header { flex-wrap: nowrap; }
  body.on-home #musicLabel, body.on-home #soundLabel { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  body.on-home #musicBtn, body.on-home #soundBtn { width: 46px; padding: 0; }
}
.prog-list li { grid-template-columns: minmax(0, 1fr) auto; row-gap: 4px; }
.prog-list .meter { grid-column: 1 / -1; grid-row: 2; }
.prog-card h2 { margin-top: 0; }
@media (max-width: 640px) { body.on-home header .right { flex-wrap: nowrap; } }
.ul-code { margin-top: 10px; font-weight: 700; color: var(--ink-soft); }
.ul-code summary { cursor: pointer; text-decoration: underline; }
.ul-code .field-row { margin-top: 8px; }
