/* Curiosity Buddy: a picture-book diorama. The buddy is a puppet on a little hill; the sky turns to night
   while it sleeps and to day when it wakes. Character colours come from heads.js (renderHead). */

:root {
  --bg: #f6e9d2;        /* daytime sky near the horizon */
  --face: #8a5a3c;      /* head colour */
  --hill: #c9a26b;      /* the buddy's hills */
  --lid: #f2d8a7;       /* around the eyes: eyelids are this colour */
  --closed: #6b4630;    /* closed-eye curve while asleep */
  --ink: #4a2f1d;       /* text and accents in daylight */
  --iris: #f4b942;
  --pupil: #2b1d0e;
  --px: 0;              /* pupil offset, -1..1 */
  --py: 0;
  --lid-ease: 180ms ease;
  --head: min(84vw, 46vh);

  --cream: #fff7e8;
  --night-top: #141a3a;
  --night-low: #3a3f7a;
  --sun: #ffc94a;
  --brass: #e3a93f;
  --font-play: "Sniglet", "ZCOOL KuaiLe", ui-rounded, system-ui, sans-serif;
  --font-zh: "ZCOOL KuaiLe", "Sniglet", sans-serif;
  --font-ui: "Atkinson Hyperlegible", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--night-top);
  font-family: var(--font-play);
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
:lang(zh), [lang="zh"] { font-family: var(--font-zh); }

/* The head is a little smaller while asleep, and grows as the buddy wakes up. */
@property --head { syntax: "<length>"; inherits: true; initial-value: 300px; }
#face {
  --head: min(84vw, 46vh);
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Seat the head on the back hill: its bottom sits just above the crest, at about 57% of the screen. */
  padding-top: max(calc(57vh - var(--head)), calc(7vh + env(safe-area-inset-top)));
  overflow: hidden;
  transition: --head 900ms cubic-bezier(.2, 1.3, .4, 1), padding-top 900ms ease;
}
#face.asleep { --head: min(68vw, 33vh); padding-top: calc(8vh + env(safe-area-inset-top)); }

/* ---------- The scene ---------- */
.scene { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.sky {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 70% at 50% 108%, color-mix(in oklab, var(--bg) 70%, #fff) 0 30%, transparent 62%),
    linear-gradient(color-mix(in oklab, var(--bg) 62%, #a9dcff), var(--bg) 70%);
}
.night {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(90% 60% at 80% 12%, rgba(120, 130, 255, 0.25), transparent 60%),
    linear-gradient(var(--night-top), var(--night-low) 75%);
  opacity: 0;
  transition: opacity 1.4s ease;
}
.asleep .night { opacity: 1; }
.stars, .stars-far {
  position: absolute;
  inset: 0 0 35% 0;
  background-image:
    radial-gradient(2px 2px at 12% 18%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 28% 42%, #fff, transparent),
    radial-gradient(2.5px 2.5px at 44% 12%, #fff9d6, transparent),
    radial-gradient(1.5px 1.5px at 63% 30%, #fff, transparent),
    radial-gradient(2px 2px at 86% 46%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 92% 14%, #fff, transparent),
    radial-gradient(2px 2px at 6% 52%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 72% 58%, #fff, transparent);
  animation: twinkle 3.2s ease-in-out infinite;
}
.stars-far {
  transform: translate(7%, 9%) scale(1.1);
  opacity: 0.6;
  animation-delay: 1.6s;
}
@keyframes twinkle { 50% { opacity: 0.35; } }
.moon {
  position: absolute;
  top: calc(6vh + env(safe-area-inset-top));
  right: 9vw;
  width: 16vmin;
  height: 16vmin;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fffbe8, #f3e3a6 70%);
  box-shadow: 0 0 6vmin rgba(255, 240, 180, 0.35);
  -webkit-mask: radial-gradient(circle at 78% 30%, transparent 34%, #000 35%);
  mask: radial-gradient(circle at 78% 30%, transparent 34%, #000 35%);
}
.hills {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 58vh;
  transition: filter 1.4s ease;
}
.hill-back { fill: color-mix(in oklab, var(--hill) 62%, var(--bg)); }
.hill-front { fill: var(--hill); }
.asleep .hills { filter: brightness(0.42) saturate(0.7) hue-rotate(-12deg); }
.grain {
  position: absolute;
  inset: 0;
  opacity: 0.16;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .3  0 0 0 0 .25  0 0 0 0 .2  0 0 0 .55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

/* ---------- The puppet (head on its stage) ---------- */
.puppet { position: relative; z-index: 1; flex: none; }
.ground-shadow {
  position: absolute;
  left: 50%;
  bottom: calc(var(--head) * -0.06);
  width: calc(var(--head) * 0.72);
  height: calc(var(--head) * 0.09);
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(30, 20, 10, 0.35), transparent);
  animation: shadow-breathe 4.5s ease-in-out infinite;
}
@keyframes shadow-breathe { 50% { transform: translateX(-50%) scale(0.94); opacity: 0.8; } }

.head {
  position: relative;
  width: var(--head);
  height: var(--head);
  transform-origin: 50% 85%;
  animation: head-breathe 4.5s ease-in-out infinite;
  filter: drop-shadow(0 1.2vmin 0 rgba(0, 0, 0, 0.12));
  transition: filter 1.4s ease;
}
#headArt { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
#headArt .tuft, #headArt .ear, #headArt .spikes, #headArt .bolt { transform-box: fill-box; }
#headArt .tuft { transform-origin: 50% 100%; }
#headArt .ear { transform-origin: 50% 80%; }
#headArt .spikes { transform-origin: 50% 100%; }
#headArt .cheek { opacity: 0; transition: opacity 300ms ease; }
.emo-happy #headArt .cheek, .emo-excited #headArt .cheek { opacity: 0.75; }

@keyframes head-breathe { 50% { transform: translateY(-0.8%) scale(1.012); } }
@keyframes head-tilt { 50% { transform: rotate(-6deg) scale(1.03); } }
@keyframes head-ponder { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg); } }
@keyframes head-talk { 50% { transform: translateY(-2%) rotate(1.5deg); } }
@keyframes head-hop { 30% { transform: translateY(-7%) scale(1.03); } 60% { transform: translateY(0) scale(0.98, 1.02); } }
@keyframes head-sleep { 0%, 100% { transform: translateY(3%) rotate(5deg); } 50% { transform: translateY(4%) rotate(6deg) scale(0.99); } }

.hearing .head { animation: head-tilt 1.6s ease-in-out infinite; }
.thinking .head { animation: head-ponder 1.6s ease-in-out infinite; }
.speaking .head { animation: head-talk 520ms ease-in-out infinite; }
.emo-excited.speaking .head { animation: head-hop 600ms ease-in-out infinite; }
.asleep .head {
  animation: head-sleep 6s ease-in-out infinite;
  filter: drop-shadow(0 1.2vmin 0 rgba(0, 0, 0, 0.18)) brightness(0.86) saturate(0.85);
}

/* Character touches */
@keyframes tuft-wiggle { 50% { transform: rotate(-9deg); } }
@keyframes tuft-wiggle-r { 50% { transform: rotate(9deg); } }
.listening #headArt .tuft-l, .hearing #headArt .tuft-l { animation: tuft-wiggle 2.2s ease-in-out infinite; }
.listening #headArt .tuft-r, .hearing #headArt .tuft-r { animation: tuft-wiggle-r 2.2s ease-in-out infinite; }

@keyframes blink-light { 50% { opacity: 0.2; } }
#headArt .antenna-light { fill: #ff5d6c; }
.listening #headArt .antenna-light, .hearing #headArt .antenna-light { fill: #4cd964; animation: blink-light 1.6s ease-in-out infinite; }
.thinking #headArt .antenna-light { fill: #ffcc00; animation: blink-light 0.35s linear infinite; }
.asleep #headArt .antenna-light { fill: #6f7d8f; }

@keyframes ear-twitch { 0%, 88%, 100% { transform: rotate(0); } 92% { transform: rotate(-12deg); } 96% { transform: rotate(8deg); } }
#headArt .ear-l { animation: ear-twitch 5s ease-in-out infinite; }
#headArt .ear-r { animation: ear-twitch 5s ease-in-out 2.5s infinite; }
.asleep #headArt .ear { animation: none; }

@keyframes spikes-wave { 50% { transform: translateY(-4%) scaleY(1.08); } }
.speaking #headArt .spikes, .hearing #headArt .spikes { animation: spikes-wave 500ms ease-in-out infinite; }

/* ---------- Eyes (HTML, laid over the head) ---------- */
.eyes {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--head) * 0.345);
  display: flex;
  justify-content: center;
  gap: calc(var(--head) * 0.1);
}
.eye {
  position: relative;
  width: calc(var(--head) * 0.25);
  height: calc(var(--head) * 0.27);
  border-radius: 50%;
  background: #fff;
  overflow: hidden;
  transition: transform 250ms ease;
  box-shadow: inset 0 calc(var(--head) * -0.012) 0 rgba(0, 0, 0, 0.1);
}
.iris {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 64%;
  height: 59%;
  border-radius: 50%;
  background: var(--iris);
  transform: translate(calc(-50% + var(--px) * 30%), calc(-50% + var(--py) * 30%));
  transition: transform 350ms cubic-bezier(.3, 1.4, .5, 1), width 250ms ease, height 250ms ease;
}
.pupil { position: absolute; inset: 24%; border-radius: 50%; background: var(--pupil); }
.shine {
  position: absolute;
  width: 24%;
  height: 24%;
  left: 20%;
  top: 16%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
}
.lid {
  position: absolute;
  left: -10%;
  width: 120%;
  height: 58%;
  background: var(--lid);
  transition: transform var(--lid-ease), border-radius var(--lid-ease);
}
.lid.top { top: 0; transform: translateY(-100%); }
.lid.bottom { bottom: 0; transform: translateY(100%); border-radius: 50% 50% 0 0 / 40% 40% 0 0; }
.eye::after {
  content: "";
  position: absolute;
  left: 16%;
  right: 16%;
  top: 36%;
  height: 22%;
  border-bottom: calc(var(--head) * 0.018) solid var(--closed);
  border-radius: 0 0 50% 50%;
  opacity: 0;
  transition: opacity 200ms ease;
}
.asleep .eye { background: var(--lid); box-shadow: none; }
.asleep .eye::after { opacity: 1; }
.asleep .iris { opacity: 0; }
.asleep .lid.top, .blink .lid.top { transform: translateY(0); }
.asleep .lid.bottom, .blink .lid.bottom { transform: translateY(0); }
.blink { --lid-ease: 70ms ease-in; }

/* ---------- Mouths: one shape per head ---------- */
.mouth {
  position: absolute;
  left: 0;
  right: 0;
  margin: 0 auto;
  transform-origin: 50% 0;
  transition: transform 200ms ease, height 200ms ease;
}
/* Owl: a two-part beak. The lower half drops with --open and shows a dark mouth inside. */
[data-mouth="beak"] .mouth {
  top: calc(var(--head) * 0.575);
  width: calc(var(--head) * 0.13);
  height: calc(var(--head) * 0.15);
  background: radial-gradient(ellipse 34% calc(var(--open) * 30%) at 50% 40%, #5a2614 98%, transparent 100%);
}
[data-mouth="beak"] .mouth::before, [data-mouth="beak"] .mouth::after {
  content: "";
  position: absolute;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}
[data-mouth="beak"] .mouth::before {      /* upper beak, fixed */
  left: 0;
  right: 0;
  top: 0;
  height: 60%;
  background: linear-gradient(#ffb547, #f08a24);
  z-index: 1;
}
[data-mouth="beak"] .mouth::after {       /* lower beak, drops open */
  left: 24%;
  right: 24%;
  top: 30%;
  height: 34%;
  background: #d9741a;
  transform: translateY(calc(var(--open) * 85%));
}
[data-mouth="grille"] .mouth {
  top: calc(var(--head) * 0.73);
  width: calc(var(--head) * 0.32);
  height: calc(var(--head) * 0.075);
  border-radius: 99px;
  background: repeating-linear-gradient(90deg, var(--iris) 0 9%, #22303f 9% 15%);
  box-shadow: 0 0 0 calc(var(--head) * 0.012) #22303f;
  opacity: 0.55;
}
[data-mouth="grin"] .mouth {
  top: calc(var(--head) * 0.7);
  width: calc(var(--head) * 0.36);
  height: calc(var(--head) * 0.09);
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
  background:
    linear-gradient(135deg, #fff 25%, transparent 25%) 0 0 / calc(var(--head) * 0.04) calc(var(--head) * 0.03) repeat-x,
    #4a1f1f;
}
[data-mouth="small"] .mouth {
  top: calc(var(--head) * 0.7);
  width: calc(var(--head) * 0.1);
  height: calc(var(--head) * 0.045);
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
  border: calc(var(--head) * 0.012) solid #1f1f1f;
  border-top: 0;
}
@property --open { syntax: "<number>"; inherits: true; initial-value: 0; }
@keyframes beak { 50% { --open: 0.75; } }
@keyframes grille { 50% { transform: scaleY(1.6); opacity: 1; } }
@keyframes grin { 50% { transform: scaleY(1.7); } }
@keyframes small-mouth { 50% { transform: scale(1.3, 1.8); background: #1f1f1f; } }
.speaking[data-mouth="beak"] .mouth { animation: beak 260ms ease-in-out infinite; }
.speaking[data-mouth="grille"] .mouth { animation: grille 220ms steps(2) infinite; }
.speaking[data-mouth="grin"] .mouth { animation: grin 280ms ease-in-out infinite; }
.speaking[data-mouth="small"] .mouth { animation: small-mouth 280ms ease-in-out infinite; }
.listening[data-mouth="grille"] .mouth, .hearing[data-mouth="grille"] .mouth { opacity: 0.8; }

/* Lip sync (app.js sets --open 0..1 and --wide ~0.7..1.25 from Polly's visemes) */
#face { --open: 0; --wide: 1; }
.lipsync .mouth { animation: none !important; transition: none; }
.lipsync[data-mouth="beak"] .mouth { transform: scaleX(var(--wide)); }
.lipsync[data-mouth="grille"] .mouth {
  transform: scale(var(--wide), calc(0.65 + var(--open) * 1.3));
  opacity: calc(0.55 + var(--open) * 0.45);
}
.lipsync[data-mouth="grin"] .mouth { transform: scale(var(--wide), calc(0.5 + var(--open) * 1.5)); }
.lipsync[data-mouth="small"] .mouth {
  transform: scale(calc(var(--wide) * (1 + var(--open) * 0.35)), calc(1 + var(--open) * 1.8));
  background: rgb(31 31 31 / calc(var(--open) * 1.6));
}
.emo-surprised .mouth { transform: scale(1.25); }
.asleep .mouth { transform: scaleY(0.6); }

/* ---------- Emotions (eyes) ---------- */
.emo-happy .lid.bottom { transform: translateY(42%); border-radius: 50% 50% 0 0 / 70% 70% 0 0; }
.emo-calm .lid.top { transform: translateY(-48%); }
.emo-thinking .lid.top { transform: translateY(-72%); }
.emo-surprised .eye, .emo-excited .eye { transform: scale(1.1); }
.emo-surprised .iris { width: 54%; height: 50%; }
.emo-concerned .eye:first-child .lid.top { transform: translateY(-58%) rotate(-14deg); }
.emo-concerned .eye:last-child .lid.top { transform: translateY(-58%) rotate(14deg); }
.emo-curious .eye:first-child { transform: scale(1.08); }
.emo-curious .eye:last-child .lid.top { transform: translateY(-62%); }

/* ---------- Sleep screen ---------- */
.zzz {
  position: absolute;
  top: calc(var(--head) * 0.06);
  left: calc(var(--head) * -0.04);
  font-size: 8vmin;
  font-weight: 400;
  color: var(--cream);
  display: none;
}
.zzz span { display: inline-block; animation: float 2.4s ease-in-out infinite; }
.zzz span:last-child { animation-delay: .6s; font-size: 1.3em; }
.asleep .zzz { display: block; }
@keyframes float { 50% { transform: translateY(-2vmin); opacity: .45; } }

#wake {
  position: relative;
  z-index: 2;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 1.2vmin;
  margin-top: 4.5vh;
  padding: 0;
  border: 0;
  background: none;
  color: var(--cream);
  font: inherit;
  cursor: pointer;
  animation: rise 900ms cubic-bezier(.2, 1.4, .4, 1) both;
}
.asleep #wake { display: flex; }
@keyframes rise { from { transform: translateY(6vh); opacity: 0; } }
.sun {
  display: grid;
  place-items: center;
  width: 30vmin;
  height: 30vmin;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 210, 90, 0.4), transparent 65%);
  transition: transform 150ms ease;
}
.sun svg { width: 100%; height: 100%; overflow: visible; }
.sun circle { fill: var(--sun); stroke: #f0a72c; stroke-width: 3; }
.sun .rays { stroke: var(--sun); stroke-width: 6; stroke-linecap: round; transform-origin: 50% 50%; animation: spin 18s linear infinite; }
@keyframes spin { to { transform: rotate(1turn); } }
#wake:active .sun { transform: scale(0.92); }
.wake-label {
  font-size: 6.4vmin;
  font-weight: 400;
  letter-spacing: 0.01em;
  text-shadow: 0 0.4vmin 0 rgba(0, 0, 0, 0.3);
}
.wake-label [lang="zh"] { margin-left: 1.5vmin; font-weight: 400; opacity: 0.85; }

/* ---------- Who's playing (name tag) ---------- */
#profileBtn {
  position: relative;
  z-index: 2;
  display: none;
  align-items: center;
  gap: 2vmin;
  margin-top: 3vh;
  padding: 1.4vmin 3.2vmin 1.4vmin 1.6vmin;
  border: 0;
  border-radius: 99px;
  background: var(--cream);
  color: #2b2433;
  font: inherit;
  font-size: 4.8vmin;
  font-weight: 800;
  box-shadow: 0 0.9vmin 0 rgba(0, 0, 0, 0.3);
  transform: rotate(-2deg);
  cursor: pointer;
}
#profileBtn:active { transform: rotate(-2deg) translateY(0.6vmin); box-shadow: 0 0.3vmin 0 rgba(0, 0, 0, 0.3); }
#profileEmoji {
  display: grid;
  place-items: center;
  width: 9vmin;
  height: 9vmin;
  border-radius: 50%;
  background: color-mix(in oklab, var(--hill) 45%, #fff);
  font-size: 6vmin;
  line-height: 1;
}
#profileBtn .chev { width: 5vmin; height: 5vmin; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; opacity: 0.55; }
.asleep #profileBtn { display: flex; }

#profilePicker {
  width: min(92vw, 34rem);
  padding: 6vmin 5vmin;
  border-radius: 7vmin;
  background: linear-gradient(var(--night-top), var(--night-low));
  color: var(--cream);
  text-align: center;
  font-family: var(--font-play);
  -webkit-user-select: none;
  user-select: none;
}
#profilePicker h2 { font-size: 7vmin; font-weight: 800; margin: 0 0 5vmin; }
#profileTiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(30vmin, 1fr)); gap: 4vmin; }
#profileTiles button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5vmin;
  padding: 3.5vmin 2vmin 3vmin;
  border: 1.2vmin solid #fff;
  border-radius: 5vmin;
  background: var(--cream);
  color: #2b2433;
  font: inherit;
  font-size: 5vmin;
  font-weight: 800;
  box-shadow: 0 1.2vmin 0 rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: transform 150ms ease;
}
#profileTiles button:nth-child(odd) { transform: rotate(-3deg); }
#profileTiles button:nth-child(even) { transform: rotate(2.5deg); }
#profileTiles button:active { transform: scale(0.95); }
#profileTiles button.active { border-color: var(--sun); }
#profileTiles .big { font-size: 17vmin; line-height: 1; }

/* ---------- Story time badge: title and progress dots while a story is told ---------- */
#storyBadge {
  position: fixed;
  z-index: 3;
  top: calc(3.6vh + env(safe-area-inset-top));
  left: 50%;
  display: flex;
  align-items: center;
  gap: 1.8vmin;
  max-width: 62vw;
  padding: 1.4vmin 3.2vmin 1.4vmin 2.2vmin;
  border-radius: 99px;
  background: var(--cream);
  color: #2b2433;
  font-size: 4vmin;
  box-shadow: 0 0.9vmin 0 rgba(0, 0, 0, 0.22);
  transform: translateX(-50%) rotate(-1.5deg);
  animation: rise 600ms cubic-bezier(.2, 1.4, .4, 1) both;
}
#storyBadge[hidden], #face.asleep #storyBadge { display: none; }
#storyBadge .book { flex: none; width: 6vmin; height: 6vmin; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
#storyTitle { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 800; }
#storyDots { display: flex; gap: 0.9vmin; flex: none; }
#storyDots i { width: 1.8vmin; height: 1.8vmin; border-radius: 50%; background: #ddd3c3; }
#storyDots i.done { background: var(--ink); }

/* ---------- Awake: camera porthole, caption bubble, sleep button ---------- */
#camWrap {
  position: fixed;
  z-index: 2;
  left: 6vw;
  bottom: calc(5vh + env(safe-area-inset-bottom));
  width: 30vmin;
  height: 30vmin;
  border-radius: 50%;
  overflow: hidden;
  border: 1.6vmin solid var(--brass);
  background: #20283b;
  box-shadow:
    inset 0 0 0 0.7vmin #b97d24,
    0 0 0 0.6vmin #8a5a17,
    0 1.6vmin 0 rgba(0, 0, 0, 0.25);
  transition: transform 150ms ease, box-shadow 150ms ease;
  animation: rise 700ms cubic-bezier(.2, 1.4, .4, 1) both;
}
#camWrap::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.5) 0 8%, transparent 9%),
              radial-gradient(circle at 50% 50%, transparent 60%, rgba(0, 0, 0, 0.3));
  pointer-events: none;
}
#cam { width: 100%; height: 100%; object-fit: cover; }
#camWrap.mirror #cam { transform: scaleX(-1); }
#camWrap.flash {
  transform: scale(1.06);
  box-shadow: inset 0 0 0 0.7vmin #b97d24, 0 0 0 0.6vmin #8a5a17, 0 0 6vmin rgba(255, 230, 150, 0.9);
}
.asleep #camWrap, .asleep #sleepBtn, .asleep #caption { display: none; }

#caption {
  position: fixed;
  z-index: 2;
  right: 5vw;
  bottom: calc(9vh + env(safe-area-inset-bottom));
  max-width: 58vw;
  margin: 0;
  padding: 2.6vmin 3.6vmin;
  border-radius: 5vmin 5vmin 5vmin 1.2vmin;
  background: var(--cream);
  color: #2b2433;
  font-size: 4vmin;
  line-height: 1.35;
  box-shadow: 0 1vmin 0 rgba(0, 0, 0, 0.18);
  display: none;
  white-space: pre-line;
}
.captions #caption:not(:empty) { display: block; }
#face.asleep #caption { display: none; }

.toy {
  position: fixed;
  z-index: 3;
  top: calc(3vh + env(safe-area-inset-top));
  width: 14vmin;
  height: 14vmin;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--cream);
  color: #2b2433;
  box-shadow: 0 1vmin 0 rgba(0, 0, 0, 0.28);
  cursor: pointer;
  transition: transform 100ms ease, box-shadow 100ms ease;
}
.toy:active { transform: translateY(0.7vmin); box-shadow: 0 0.3vmin 0 rgba(0, 0, 0, 0.28); }
.toy svg { width: 58%; height: 58%; }
#sleepBtn { right: 5vw; }
#sleepBtn svg path { fill: #5b5fb0; }

/* Parent settings: only on the sleep screen, opened by press-and-hold (the ring fills up) */
@property --hold { syntax: "<number>"; inherits: false; initial-value: 0; }
@keyframes hold-fill { to { --hold: 1; } }
#settingsBtn {
  left: 5vw;
  display: none;
  touch-action: none;
  -webkit-touch-callout: none;
  background: rgba(255, 247, 232, 0.16);
  color: var(--cream);
  box-shadow: inset 0 0 0 0.5vmin rgba(255, 247, 232, 0.3);
}
.asleep #settingsBtn { display: grid; }
.cog { fill: none; stroke: currentColor; stroke-width: 3.4; stroke-dasharray: 3.1 2.55; }
#settingsBtn circle:not(.cog), .sheet-badge circle:not(.cog) { fill: currentColor; }
#settingsBtn::after {
  content: "";
  position: absolute;
  inset: -1.4vmin;
  border-radius: 50%;
  background: conic-gradient(var(--sun) calc(var(--hold) * 1turn), transparent 0);
  -webkit-mask: radial-gradient(circle, transparent 62%, #000 64%);
  mask: radial-gradient(circle, transparent 62%, #000 64%);
  opacity: 0;
}
#settingsBtn.holding::after { opacity: 1; animation: hold-fill 1s linear forwards; }

#toast {
  position: fixed;
  z-index: 10;
  top: calc(3vh + env(safe-area-inset-top));
  left: 50%;
  max-width: 70vw;
  padding: 2.2vmin 4vmin;
  border-radius: 99px;
  background: #2b2433;
  color: var(--cream);
  font-size: 3.8vmin;
  text-align: center;
  box-shadow: 0 0.8vmin 0 rgba(0, 0, 0, 0.25);
  opacity: 0;
  transform: translate(-50%, -2vh);
  pointer-events: none;
  transition: opacity 200ms ease, transform 300ms cubic-bezier(.2, 1.4, .4, 1);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Grown-ups' corner (parent settings) ---------- */
#settings {
  width: min(94vw, 30rem);
  max-height: 92vh;
  padding: 0 1.1rem;
  border: 0;
  border-radius: 1.75rem;
  background: #fbf4e6;
  color: #2b2433;
  font-family: var(--font-ui);
  font-size: 0.98rem;
  -webkit-user-select: text;
  user-select: text;
  box-shadow: 0 1.5rem 3rem rgba(10, 10, 30, 0.45);
}
dialog::backdrop { background: rgba(14, 16, 40, 0.62); backdrop-filter: blur(3px); }
#settings[open] { animation: sheet-in 380ms cubic-bezier(.2, 1.2, .4, 1); }
@keyframes sheet-in { from { transform: translateY(4vh) scale(0.97); opacity: 0; } }

.sheet-head { display: flex; align-items: center; gap: 0.9rem; padding: 1.3rem 0.2rem 0.9rem; }
.sheet-badge {
  flex: none;
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border-radius: 1rem;
  background: var(--ink);
  color: var(--cream);
  transform: rotate(-6deg);
}
.sheet-badge svg { width: 60%; height: 60%; }
.sheet-head h2 { margin: 0; font-family: var(--font-play); font-size: 1.5rem; font-weight: 800; line-height: 1.1; }
.sheet-head p { margin: 0.15rem 0 0; color: #7a7065; font-size: 0.88rem; }

.card {
  margin: 0 0 0.8rem;
  padding: 0.95rem 1rem 0.3rem;
  border-radius: 1.25rem;
  background: #fff;
  box-shadow: 0 1px 0 rgba(43, 36, 51, 0.06), 0 0 0 1px rgba(43, 36, 51, 0.06);
}
.card h3 {
  margin: 0 0 0.75rem;
  font-family: var(--font-play);
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink);
}
.field { display: flex; flex-direction: column; gap: 0.3rem; margin: 0 0 0.8rem; font-weight: 700; font-size: 0.9rem; }
.field small, .field-label small { font-weight: 400; color: #8a8077; }
.field-label { display: block; margin: 0 0 0.4rem; font-weight: 700; font-size: 0.9rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.7rem; }
#settings input:not([type="checkbox"]):not([type="radio"]), #settings select {
  width: 100%;
  min-width: 0;
  font: inherit;
  font-weight: 400;
  padding: 0.65rem 0.75rem;
  border: 1.5px solid #e6dccb;
  border-radius: 0.85rem;
  background: #fffdf8;
  color: inherit;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
#settings input:focus, #settings select:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ink) 18%, transparent);
}
#settings input::placeholder { color: #b5aa9c; }

.profile-row { display: flex; gap: 0.45rem; margin: 0 0 0.8rem; }
/* Voice: this child's voiceprint, learned here or copied from the server */
.voice-box { margin-top: 0.9rem; padding-top: 0.8rem; border-top: 1.5px dashed #e6dccb; }
.voice-box[hidden], .voice-box [hidden] { display: none; }
.voice-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; }
.voice-head > span { flex: 1 0 100%; margin-bottom: 0.15rem; }
.voice-head b { display: block; font-size: 0.92rem; }
.voice-head small { display: block; margin-top: 0.1rem; color: #8a8077; font-size: 0.8rem; line-height: 1.3; }
.voice-msg { margin: 0.5rem 0 0; font-size: 0.85rem; font-weight: 700; color: #3f6b3a; }
.voice-msg.problem { color: #a3473b; }
.voice-msg:empty { display: none; }
.voice-import { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.55rem; }
.voice-import:empty { display: none; }
.voice-learning { margin-top: 0.7rem; padding: 0.75rem 0.85rem; border-radius: 14px; background: #fbf3e4; }
.voice-learning p { margin: 0 0 0.5rem; font-size: 0.88rem; line-height: 1.4; }
.voice-progress { display: flex; align-items: center; gap: 0.6rem; }
.voice-progress b { flex: 1; font-size: 0.85rem; }
#voiceDots { display: flex; gap: 0.35rem; }
#voiceDots i { width: 0.7rem; height: 0.7rem; border-radius: 50%; background: #e2d6c2; transition: background 200ms; }
#voiceDots i.done { background: var(--ink); }
.voice-learning.listening #voiceDots i.next { animation: voice-pulse 1s ease-in-out infinite; }
.face-learning video { display: block; width: 9rem; height: 9rem; margin: 0 auto 0.6rem; border-radius: 50%;
  object-fit: cover; transform: scaleX(-1); background: #2b2433; box-shadow: 0 0 0 4px #fff, 0 0 0 6px #e2d6c2; }
#faceDots { display: flex; gap: 0.35rem; }
#faceDots i { width: 0.7rem; height: 0.7rem; border-radius: 50%; background: #e2d6c2; transition: background 200ms; }
#faceDots i.done { background: var(--ink); }
@keyframes voice-pulse { 50% { background: #c9b48f; transform: scale(1.25); } }
.profile-row select { flex: 1; }
.chip-btn {
  flex: none;
  font: inherit;
  font-weight: 700;
  padding: 0 0.85rem;
  border: 0;
  border-radius: 0.85rem;
  background: var(--ink);
  color: var(--cream);
  cursor: pointer;
}
.chip-btn.ghost { background: transparent; color: #a3473b; box-shadow: inset 0 0 0 1.5px #ecc9c2; }
.chip-btn:disabled { opacity: 0.35; cursor: default; }

/* Character choices: picture tiles (radio inputs hidden, the tile is the choice) */
.char-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.55rem; margin: 0 0 0.9rem; }
.char-grid label {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.15rem 0.6rem;
  padding: 0.6rem 0.7rem;
  border-radius: 1rem;
  background: #fffdf8;
  box-shadow: inset 0 0 0 1.5px #ece2d1;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.char-grid label:has(input:checked) {
  background: color-mix(in oklab, var(--ink) 9%, #fff);
  box-shadow: inset 0 0 0 2.5px var(--ink);
  transform: rotate(-1.5deg);
}
.char-grid input { position: absolute; opacity: 0; pointer-events: none; }
.char-emoji { grid-row: span 2; font-size: 1.9rem; line-height: 1; }
.char-name { font-family: var(--font-play); font-weight: 800; font-size: 1rem; line-height: 1.1; }
.char-zh { font-family: var(--font-zh); font-size: 0.85rem; color: #8a8077; line-height: 1.1; }

/* Switches */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  margin: 0;
  padding: 0.7rem 0;
  border-top: 1px dashed #eadfcd;
  cursor: pointer;
}
.switch-row b { display: block; font-size: 0.92rem; }
.switch-row small { display: block; margin-top: 0.1rem; color: #8a8077; font-size: 0.8rem; line-height: 1.3; }
.switch-row input {
  flex: none;
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 3rem;
  height: 1.8rem;
  margin: 0;
  border-radius: 99px;
  background: #ddd3c3;
  cursor: pointer;
  transition: background 200ms ease;
}
.switch-row input::before {
  content: "";
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 220ms cubic-bezier(.3, 1.4, .5, 1);
}
.switch-row input:checked { background: var(--ink); }
.switch-row input:checked::before { transform: translateX(1.2rem); }

#settings .hint { margin: 0.2rem 0.3rem 0.4rem; color: #8a8077; font-size: 0.8rem; text-align: center; }
#settings .actions {
  position: sticky;
  bottom: 0;
  display: flex;
  margin: 0 -1.1rem;
  padding: 0.8rem 1.1rem calc(1rem + env(safe-area-inset-bottom));
  background: linear-gradient(rgba(251, 244, 230, 0), #fbf4e6 35%);
}
.btn-primary {
  flex: 1;
  font-family: var(--font-play);
  font-size: 1.15rem;
  font-weight: 800;
  padding: 0.85rem 1rem;
  border: 0;
  border-radius: 1.1rem;
  background: var(--ink);
  color: var(--cream);
  box-shadow: 0 0.3rem 0 color-mix(in oklab, var(--ink) 55%, #000);
  cursor: pointer;
  transition: transform 100ms ease, box-shadow 100ms ease;
}
.btn-primary:active { transform: translateY(0.2rem); box-shadow: 0 0.1rem 0 color-mix(in oklab, var(--ink) 55%, #000); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
