/* Iyan's screen: one character, one bubble, one big button. Calm colors, big targets, nothing to scroll. */
:root {
  --sky1: #fff3d6;
  --sky2: #ffe0b8;
  --ink: #3b2a1a;
  --muted: #8a6a4e;
  --card: #ffffff;
  --orange: #ff9a3c;
  --orange-dark: #f07c1c;
  --red: #ff6b6b;
  --green: #5cc48a;
  --blue: #5aa9e6;
  --font: "Fredoka", "Nunito", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body.kid {
  font-family: var(--font);
  color: var(--ink);
  background: radial-gradient(circle at 20% 10%, #fff8e8 0, var(--sky1) 40%, var(--sky2) 100%);
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
button { font-family: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* faint floating food shapes in the background */
.doodles { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.doodle { position: absolute; opacity: .13; animation: drift 14s ease-in-out infinite; }
.doodle:nth-child(2) { animation-delay: -4s; animation-duration: 17s; }
.doodle:nth-child(3) { animation-delay: -8s; animation-duration: 19s; }
.doodle:nth-child(4) { animation-delay: -2s; animation-duration: 15s; }
.doodle:nth-child(5) { animation-delay: -10s; animation-duration: 21s; }
@keyframes drift { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-18px) rotate(5deg); } }

main.stage {
  position: relative; z-index: 1;
  width: min(100vw, 520px);
  padding: 18px 20px 24px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  text-align: center;
}

.topbar { width: 100%; display: flex; justify-content: space-between; align-items: center; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 2px solid #ffd9a8; color: var(--orange-dark);
  border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: 14px; letter-spacing: .02em;
}
.iconbtn {
  width: 40px; height: 40px; border-radius: 50%; border: 2px solid #ffd9a8; background: #fff; color: var(--muted);
  display: grid; place-items: center; font-size: 18px;
}

/* ------------------------------------------------------------ the character */
.pip { width: min(58vw, 230px); height: auto; filter: drop-shadow(0 14px 22px rgba(240, 124, 28, .25)); transition: transform .3s ease; }
.pip .eye { transform-box: fill-box; transform-origin: center; animation: blink 4.6s infinite; }
.pip .eye.right { animation-delay: .15s; }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.08); } }
.pip .pupils { transition: transform .25s ease; }
.pip .mouth-smile, .pip .mouth-open, .pip .mouth-o, .pip .mouth-flat, .pip .eyes-closed, .pip .zzz,
.pip .hand, .pip .waves, .pip .thought { opacity: 0; transition: opacity .2s ease; }
.pip .ear { transition: transform .25s ease; transform-box: fill-box; transform-origin: center; }

.state-idle .pip .mouth-smile { opacity: 1; }
.state-idle .pip { animation: breathe 3.2s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

.state-listening .pip .mouth-o { opacity: 1; }
.state-listening .pip .waves { opacity: 1; animation: wave 1s ease-in-out infinite; }
.state-listening .pip .ear { transform: translateY(-6px) scale(1.15); }
.state-listening .pip .eye { transform: scale(1.12); animation: none; }
@keyframes wave { 0%, 100% { opacity: .4; } 50% { opacity: 1; } }

.state-thinking .pip .mouth-flat { opacity: 1; }
.state-thinking .pip .pupils { transform: translate(4px, -5px); }
.state-thinking .pip .thought { opacity: 1; }
.state-thinking .pip .thought circle { animation: dots 1.2s ease-in-out infinite; }
.state-thinking .pip .thought circle:nth-child(2) { animation-delay: .2s; }
.state-thinking .pip .thought circle:nth-child(3) { animation-delay: .4s; }
.state-thinking .pip .glass { animation: peek 1.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes dots { 0%, 100% { transform: scale(.7); opacity: .5; } 50% { transform: scale(1.15); opacity: 1; } }
@keyframes peek { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-12deg) translateY(-3px); } }

.state-speaking .pip .mouth-open { animation: talk .34s steps(1) infinite; }
.state-speaking .pip .mouth-smile { animation: talk-inv .34s steps(1) infinite; }
.state-speaking .pip { animation: bob .6s ease-in-out infinite; }
@keyframes talk { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes talk-inv { 0%, 49% { opacity: 0; } 50%, 100% { opacity: 1; } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }

.state-bye .pip .mouth-smile { opacity: 1; }
.state-bye .pip .hand { opacity: 1; animation: waveHand .7s ease-in-out infinite; transform-box: fill-box; transform-origin: bottom center; }
@keyframes waveHand { 0%, 100% { transform: rotate(-18deg); } 50% { transform: rotate(22deg); } }

.state-sleep .pip .eyes-closed { opacity: 1; }
.state-sleep .pip .eye { opacity: 0; }
.state-sleep .pip .mouth-smile { opacity: 1; }
.state-sleep .pip .zzz { opacity: 1; animation: floatz 2.4s ease-in-out infinite; }
@keyframes floatz { 0% { transform: translateY(0); opacity: 0; } 30% { opacity: 1; } 100% { transform: translateY(-14px); opacity: 0; } }

/* ------------------------------------------------------------ speech */
.name { margin: 0; font-size: 26px; font-weight: 700; color: var(--orange-dark); }
.status { margin: 0; color: var(--muted); font-size: 17px; min-height: 22px; }
.bubble {
  position: relative; width: 100%; margin: 4px 0 0;
  background: var(--card); border: 3px solid #ffd9a8; border-radius: 24px;
  padding: 16px 20px; font-size: 22px; line-height: 1.35; min-height: 64px;
  box-shadow: 0 8px 20px rgba(240,124,28,.12);
}
.bubble::before {
  content: ""; position: absolute; top: -14px; left: 50%; transform: translateX(-50%) rotate(45deg);
  width: 22px; height: 22px; background: var(--card); border-left: 3px solid #ffd9a8; border-top: 3px solid #ffd9a8;
}
.bubble.you { background: #eef6ff; border-color: #cfe4fb; font-size: 16px; color: #4a6a8a; min-height: 0; padding: 10px 16px; margin-top: 10px; }
.bubble.you::before { display: none; }

/* ------------------------------------------------------------ controls */
.micwrap { position: relative; margin-top: 6px; }
.ring { position: absolute; inset: -14px; border-radius: 50%; border: 4px solid rgba(255,107,107,.45); opacity: 0; }
.state-listening .ring { opacity: 1; animation: ring 1.1s ease-out infinite; }
.state-listening .ring.two { animation-delay: .35s; }
@keyframes ring { 0% { transform: scale(.85); opacity: .9; } 100% { transform: scale(1.35); opacity: 0; } }
.mic {
  width: 150px; height: 150px; border-radius: 50%; border: none; color: #fff;
  background: radial-gradient(circle at 35% 30%, #ffb46b, var(--orange) 55%, var(--orange-dark));
  box-shadow: 0 14px 28px rgba(240,124,28,.45), inset 0 -6px 0 rgba(0,0,0,.08);
  display: grid; place-items: center; transition: transform .1s ease, background .2s ease;
}
.mic svg { width: 64px; height: 64px; }
.mic:active { transform: scale(.95); }
.state-listening .mic { background: radial-gradient(circle at 35% 30%, #ff9c9c, var(--red) 55%, #e04e4e); box-shadow: 0 14px 28px rgba(224,78,78,.45); }
.mic:disabled { background: #e6d9c8; box-shadow: none; }
.hint { margin: 0; color: var(--muted); font-size: 15px; }

.smallrow { display: flex; gap: 10px; align-items: center; margin-top: 4px; }
.pill {
  border: 2px solid #ffd9a8; background: #fff; color: var(--muted); border-radius: 999px;
  padding: 9px 16px; font-size: 15px; font-weight: 600;
}
.typeform { display: flex; gap: 8px; width: 100%; }
.typeform input { flex: 1; padding: 12px 14px; border-radius: 16px; border: 2px solid #ffd9a8; font-size: 17px; font-family: inherit; }
.typeform button { padding: 12px 18px; border-radius: 16px; border: none; background: var(--blue); color: #fff; font-size: 16px; font-weight: 700; }

.trail { width: 100%; height: 10px; background: #fff; border: 2px solid #ffd9a8; border-radius: 999px; overflow: hidden; margin-top: 4px; }
.trail div { height: 100%; width: 100%; background: linear-gradient(90deg, var(--green), #9be1b8); transition: width 1s linear; }

.errbar { width: 100%; background: #fff4f4; color: #b43b3b; border: 2px solid #ffcaca; border-radius: 16px; padding: 10px 14px; font-size: 14px; }

/* sparkles when the companion celebrates */
.spark { position: absolute; width: 14px; height: 14px; pointer-events: none; animation: spark 900ms ease-out forwards; }
@keyframes spark { 0% { transform: translate(0, 0) scale(.4); opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) scale(1.2); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (max-height: 640px) {
  .pip { width: 150px; }
  .mic { width: 120px; height: 120px; }
  .bubble { font-size: 19px; padding: 12px 16px; }
}
