/* Talking Billu — styled after the Bulbul V4 Figma ad kit */
:root {
  --bg: #f6f3ec;
  --card: #ffffff;
  --line: rgba(20, 27, 52, 0.1);
  --ink: #141b34;
  --ink-2: #4c526b;
  --ink-3: #8f8f8f;
  --cobalt: #3333cc;
  --lime: #83c040;
  --plum: #871f4b;
  --saffron: #f7b548;
  --coral: #f2876b;
  --sky: #dfe9f7;
  --font: "Figtree", "Noto Sans Devanagari", "Noto Sans Bengali", "Noto Sans Tamil", "Noto Sans Telugu", "Noto Sans Gujarati", "Noto Sans Kannada", "Noto Sans Malayalam", "Noto Sans Oriya", "Noto Sans Gurmukhi", system-ui, sans-serif;
  --serif: "Newsreader", Georgia, serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 760px; margin: 0 auto; padding: 20px 16px 0;
}
.wordmark { height: 24px; display: block; }
.pill {
  font: 600 12px var(--font); letter-spacing: 0.06em; text-transform: uppercase;
  padding: 6px 12px; border-radius: 99px; border: 1.5px solid var(--ink);
}

.wrap { max-width: 760px; margin: 0 auto; padding: 8px 16px 32px; display: flex; flex-direction: column; align-items: center; }

.hero { text-align: center; margin: 18px 0 14px; }
.hero h1 { font: 400 clamp(40px, 8vw, 60px)/1 var(--serif); margin: 0 0 10px; letter-spacing: -0.02em; }
.hero h1 em { color: var(--plum); }
.lede { color: var(--ink-2); margin: 0 auto; max-width: 30em; font-size: 16px; }

/* ---------- mode switch ---------- */
.modes {
  display: inline-flex; padding: 4px; gap: 4px; margin: 10px 0 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 99px;
}
.mode {
  font: 600 14px var(--font); color: var(--ink-2); background: none; border: 0; cursor: pointer;
  padding: 9px 16px; border-radius: 99px; transition: background .2s, color .2s;
}
.mode[aria-checked="true"] { background: var(--ink); color: #fff; }
.mode:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; }

.speak { display: inline-flex; align-items: center; gap: 8px; margin: 4px 0 0; font-size: 13px; color: var(--ink-2); }
.speak select { width: auto; padding: 6px 10px; border-radius: 99px; font-size: 13px; background: var(--card); }

/* ---------- stage ---------- */
.stage {
  position: relative; width: min(100%, 520px); aspect-ratio: 1 / 1.02;
  display: grid; place-items: end center; margin-top: 6px;
}
.sun {
  position: absolute; left: 50%; top: 48%; width: 86%; aspect-ratio: 1; translate: -50% -50%;
  border-radius: 50%; background: radial-gradient(circle at 50% 40%, #fbe1a8, var(--saffron));
}
.stage[data-state="listening"] .sun { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { scale: 1.05; } }

.cat { position: relative; width: 74%; overflow: visible; cursor: pointer; user-select: none; touch-action: none; filter: drop-shadow(0 18px 18px rgba(20,27,52,.18)); }
.cat * { transform-box: fill-box; }
.cat .bow { transform-box: view-box; }

.head { transform-origin: 50% 85%; transition: rotate .35s cubic-bezier(.3,1.6,.5,1); }
.ear { transition: rotate .3s cubic-bezier(.3,1.6,.5,1); }
.earL { transform-origin: 80% 100%; }
.earR { transform-origin: 20% 100%; }
.tail { transform-origin: 0% 100%; animation: wag 3.2s ease-in-out infinite; }
@keyframes wag { 50% { rotate: 9deg; } }
.body { transform-origin: 50% 100%; animation: breathe 3.6s ease-in-out infinite; }
@keyframes breathe { 50% { scale: 1.015 1.03; } }
.paw { transform-origin: 50% 0%; transition: rotate .3s; }

.eye { transform-origin: 50% 50%; animation: blink 5.2s infinite; }
@keyframes blink { 0%, 95%, 100% { scale: 1 1; } 97% { scale: 1 .08; } }
.pupil { transition: translate .25s ease; }
.happy-eyes { opacity: 0; }
.brow { transition: translate .25s; }

.mouth { transform-origin: 50% 0%; scale: 1 0.02; }
.smile { transition: opacity .1s; }
.dots { fill: #fff; stroke: var(--line); stroke-width: 2; opacity: 0; }

/* listening: ears perk, head tilts, brows up, eyes wide */
.stage[data-state="listening"] .head { rotate: -7deg; }
.stage[data-state="listening"] .earL { rotate: -10deg; }
.stage[data-state="listening"] .earR { rotate: 12deg; }
.stage[data-state="listening"] .brow { translate: 0 -8px; }
.stage[data-state="listening"] .pupil { translate: -4px 0; }
.stage[data-state="listening"] .pawR { rotate: -14deg; }

/* thinking: eyes look up, dots bubble */
.stage[data-state="thinking"]:not(.reacting) .pupil { translate: 6px -12px; }
.stage[data-state="thinking"]:not(.reacting) .head { rotate: 5deg; }
.stage[data-state="thinking"]:not(.reacting) .dots { opacity: 1; }
.stage[data-state="thinking"] .dots circle { animation: pop 1.1s infinite; }
.stage[data-state="thinking"] .dots circle:nth-child(2) { animation-delay: .15s; }
.stage[data-state="thinking"] .dots circle:nth-child(3) { animation-delay: .3s; }
@keyframes pop { 50% { opacity: .35; } }

/* talking: the smile gives way to the open mouth (JS drives the mouth scale) */
.stage[data-state="talking"] .smile { opacity: 0; }

/* ---------- Talking Tom reactions ----------
   JS adds atomic classes to .stage for a moment; each one changes one thing. */
.dizzy-eyes, .tongue, .mustache, .prop { opacity: 0; transition: opacity .2s; }
.eye, .happy-eyes, .dizzy-eyes { transition: opacity .12s; }

.stage.eyes-happy .eye, .stage.eyes-dizzy .eye { opacity: 0; }
.stage.eyes-happy .happy-eyes { opacity: 1; }
.stage.eyes-dizzy .dizzy-eyes { opacity: 1; animation: spiral .6s linear infinite; }
@keyframes spiral { to { rotate: 360deg; } }
.dizzy-eyes path { transform-origin: 50% 50%; }
.stage.eyes-cross #eyeL .pupil { translate: 9px 2px; }
.stage.eyes-cross #eyeR .pupil { translate: -9px 2px; }
.stage.eyes-wide .pupil { scale: .72; }
.stage.eyes-squint .eye { scale: 1 .45; animation: none; }

.stage.angry .browL { rotate: 18deg; translate: 0 10px; stroke: #8a5a3a; }
.stage.angry .browR { rotate: -18deg; translate: 0 10px; stroke: #8a5a3a; }
.stage.ears-back .earL { rotate: 24deg; }
.stage.ears-back .earR { rotate: -24deg; }
.stage.ears-up .earL { rotate: -12deg; }
.stage.ears-up .earR { rotate: 12deg; }
.stage.ear-stretch .earL { scale: 1 1.3; rotate: -8deg; }
.stage.head-tilt .head { rotate: 8deg; }
.stage.tail-puff .tail { scale: 1.18; animation-duration: .4s; }
.stage.mouth-open .mouth { scale: 1 .95; transition: scale .5s; }
.stage.mouth-open .smile { opacity: 0; }
.stage.tongue-out .tongue { opacity: 1; animation: lick .35s ease-in-out infinite; }
@keyframes lick { 50% { translate: 0 4px; } }
.stage.milk-mustache .mustache { opacity: 1; }
.stage.paw-up .pawR { rotate: -150deg; transition: rotate .25s cubic-bezier(.3,1.6,.5,1); }
.stage.paw-mouth .pawL { translate: 38px -96px; rotate: 18deg; transition: translate .3s, rotate .3s; }
.stage.paws-up .pawL { rotate: 150deg; transition: rotate .3s; }
.stage.paws-up .pawR { rotate: -150deg; transition: rotate .3s; }

.stage.hop .cat { animation: hop .32s ease-out 2; }
@keyframes hop { 50% { translate: 0 -22px; } }
.stage.jump .cat { animation: jump .9s cubic-bezier(.2,.8,.3,1); }
@keyframes jump { 25% { translate: 6px -90px; scale: 1.06; } 55% { translate: -4px -70px; scale: 1.06; } 100% { translate: 0 0; scale: 1; } }
.stage.pounce .cat { animation: pounce .55s cubic-bezier(.3,1.4,.5,1); }
@keyframes pounce { 40% { translate: 0 -40px; scale: 1.04; } 100% { translate: 0 0; } }
.stage.wiggle .cat { animation: wiggle .3s ease-in-out 4; }
.stage.squish .body { animation: squish .22s ease-in-out 4; }
@keyframes squish { 50% { scale: 1.06 .92; } }
.stage.spin .head { animation: spinhead .9s cubic-bezier(.3,.7,.4,1); }
@keyframes spinhead { 70% { rotate: 380deg; } 85% { rotate: 350deg; } 100% { rotate: 360deg; } }
.stage.stretch .body { animation: stretch 2s ease-in-out; }
@keyframes stretch { 40%, 60% { scale: 1.05 .93; } }
.stage.fur-puff .cat { scale: 1.05; }

/* props */
.stage.prop-milk .glass { opacity: 1; animation: drink 2.2s ease-in-out forwards; transform-box: view-box; transform-origin: 253px 327px; }
@keyframes drink { 0% { translate: 0 30px; } 25% { translate: -30px -40px; rotate: -30deg; } 85% { translate: -30px -44px; rotate: -70deg; } 100% { translate: -30px -44px; rotate: -70deg; opacity: 0; } }
.stage.prop-milk .milk-level { animation: empty 1.4s .6s linear forwards; transform-origin: 50% 100%; }
@keyframes empty { to { scale: 1 0; } }
.stage.prop-fish .fish { opacity: 1; animation: eat 2s ease-in-out forwards; transform-origin: 0% 50%; }
@keyframes eat { 0% { translate: 0 40px; } 25% { translate: 0 -40px; } 45% { translate: 0 -40px; scale: .7 1; } 65% { translate: 0 -40px; scale: .4 1; } 85% { translate: 0 -40px; scale: .1 1; opacity: 1; } 100% { translate: 0 -40px; scale: 0 1; opacity: 0; } }
.stage.prop-cucumber .cucumber { opacity: 1; animation: sneak .5s ease-out; }
@keyframes sneak { from { translate: -120px 0; } }

/* particles (hearts, stars, sparkles, !) */
.fx-layer { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.fx {
  position: absolute; translate: -50% -50%; font: 700 22px/1 var(--font); color: var(--coral);
  animation: floatup 1.2s ease-out forwards; text-shadow: 0 2px 0 rgba(255,255,255,.6);
}
.fx.star { color: var(--saffron); font-size: 26px; }
.fx.sparkle { color: var(--cobalt); font-size: 18px; }
.fx.bang { color: var(--plum); font: 400 54px/1 var(--serif); animation: bang .9s cubic-bezier(.3,1.6,.5,1) forwards; }
.fx.zzz { color: var(--ink-2); font: 400 26px/1 var(--serif); animation-duration: 2s; }
@keyframes floatup { from { opacity: 0; scale: .4; } 15% { opacity: 1; scale: 1; } to { opacity: 0; translate: calc(-50% + var(--dx, 0px)) calc(-50% - 90px); scale: 1.1; } }
@keyframes bang { from { opacity: 0; scale: .2; } 30% { opacity: 1; scale: 1.2; } 80% { opacity: 1; scale: 1; } to { opacity: 0; } }
.orbit { position: absolute; width: 0; height: 0; animation: orbit .8s linear infinite; }
.orbit span { position: absolute; font: 700 24px/1 var(--font); color: var(--saffron); translate: -50% -50%; }
@keyframes orbit { to { rotate: 360deg; } }

.laser {
  position: absolute; z-index: 3; width: 16px; height: 16px; border-radius: 50%; translate: -50% -50%;
  background: radial-gradient(circle, #fff 0 18%, #ff2d2d 30%, rgba(255,45,45,.35) 60%, transparent 72%);
  box-shadow: 0 0 14px 6px rgba(255, 45, 45, .45); opacity: 0; pointer-events: none;
}
.laser.on { opacity: 1; }

/* ---------- action bar ---------- */
.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 18px 0 6px; }
.act {
  display: flex; flex-direction: column; align-items: center; gap: 4px; width: 76px; padding: 10px 4px 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 18px; cursor: pointer;
  font: 600 12px var(--font); color: var(--ink-2); transition: translate .15s, box-shadow .15s;
}
.act svg { width: 34px; height: 34px; }
.act:hover { translate: 0 -2px; box-shadow: 0 10px 20px -14px rgba(20,27,52,.5); }
.act:active { translate: 0 1px; }
.act:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; }
.act:disabled { opacity: .5; cursor: default; translate: none; box-shadow: none; }

.note { margin: 6px 0 0; font-size: 13px; color: var(--plum); text-align: center; }

/* ---------- speech bubbles ---------- */
.bubble {
  position: absolute; z-index: 2; max-width: 62%; padding: 12px 16px; border-radius: 20px;
  font-size: 16px; line-height: 1.4; box-shadow: 0 14px 30px -18px rgba(20,27,52,.45);
  animation: rise .25s cubic-bezier(.3,1.4,.5,1);
}
.bubble.you { top: 2%; left: 0; background: var(--ink); color: #fff; border-bottom-left-radius: 6px; }
.bubble.cat { top: 14%; right: 0; background: var(--card); border: 1px solid var(--line); border-bottom-right-radius: 6px; }
.bubble.cat::before { content: "Billu"; display: block; font: 700 11px var(--font); letter-spacing: .08em; text-transform: uppercase; color: var(--plum); margin-bottom: 2px; }
.bubble.you::before { content: "You"; display: block; font: 700 11px var(--font); letter-spacing: .08em; text-transform: uppercase; opacity: .6; margin-bottom: 2px; }
.bubble.error { background: #fff0ed; border-color: #f4c3b6; }
@keyframes rise { from { opacity: 0; translate: 0 10px; scale: .96; } }

/* ---------- mic ---------- */
.controls { display: flex; flex-direction: column; align-items: center; margin-top: 10px; }
.mic {
  position: relative; width: 84px; height: 84px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--plum); color: #fff; display: grid; place-items: center;
  box-shadow: 0 16px 30px -14px rgba(135, 31, 75, .8); transition: scale .15s, background .2s;
}
.mic svg { width: 36px; height: 36px; fill: currentColor; position: relative; z-index: 1; }
.mic:hover { scale: 1.04; }
.mic:active { scale: .96; }
.mic:focus-visible { outline: 3px solid var(--cobalt); outline-offset: 4px; }
.mic .level {
  position: absolute; inset: 0; border-radius: 50%; background: currentColor; opacity: 0;
  scale: var(--lvl, 1); transition: scale .08s linear;
}
.mic[data-phase="ready"], .mic[data-phase="hearing"] { background: #2f8f4e; box-shadow: 0 16px 30px -14px rgba(47, 143, 78, .9); }
.mic[data-phase="ready"] .level, .mic[data-phase="hearing"] .level { background: #2f8f4e; opacity: .25; }
.mic[data-phase="ready"]::after {
  content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid #2f8f4e; opacity: .5;
  animation: breathe-ring 1.8s ease-in-out infinite;
}
@keyframes breathe-ring { 50% { scale: 1.12; opacity: 0; } }
.mic[data-phase="thinking"] { background: var(--ink-3); box-shadow: none; }
.mic[data-phase="talking"] { background: var(--ink); }
.mic-label { margin-top: 10px; font: 700 12px var(--font); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }

.status { margin: 6px 0 2px; font-weight: 600; text-align: center; min-height: 1.5em; }
.status.error { color: #b3261e; }
.hint { margin: 0; color: var(--ink-3); font-size: 13px; text-align: center; }
kbd { font: 600 11px var(--font); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 1px 6px; background: var(--card); }

/* ---------- record button ---------- */
.mic-row { display: flex; align-items: center; gap: 18px; }
.rec {
  width: 84px; display: flex; flex-direction: column; align-items: center; gap: 4px; background: none; border: 0;
  font: 700 11px var(--font); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); cursor: pointer; padding: 6px 0;
}
.rec i { width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--ink); display: grid; place-items: center; background: var(--card); }
.rec i::after { content: ""; width: 16px; height: 16px; border-radius: 50%; background: #d6334a; transition: border-radius .2s, width .2s, height .2s; }
.rec[aria-pressed="true"] i::after { border-radius: 3px; width: 14px; height: 14px; }
.rec[aria-pressed="true"] { color: #d6334a; }
.rec[aria-pressed="true"] i { border-color: #d6334a; animation: recpulse 1.2s ease-in-out infinite; }
@keyframes recpulse { 50% { box-shadow: 0 0 0 6px rgba(214, 51, 74, .15); } }
.rec:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; border-radius: 12px; }
.rec-spacer { visibility: hidden; pointer-events: none; }
.stage.recording::after {
  content: "● REC"; position: absolute; top: 8px; left: 50%; translate: -50% 0; z-index: 4;
  font: 700 12px var(--font); letter-spacing: .1em; color: #fff; background: #d6334a; padding: 4px 10px; border-radius: 99px;
}

/* ---------- tongue-twister challenge ---------- */
.challenge {
  width: 100%; margin-top: 22px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 18px 20px;
}
.ch-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ch-head h2 { margin: 0; font: 400 26px/1.1 var(--serif); }
.streak { font: 700 12px var(--font); color: var(--plum); background: #f8e8ef; padding: 5px 10px; border-radius: 99px; white-space: nowrap; }
.ch-beat { margin: 10px 0 0; padding: 10px 12px; border-radius: 12px; background: #fff6e3; color: var(--ink); font-weight: 600; font-size: 14px; }
.ch-langs { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 4px; }
.ch-langs button {
  font: 600 13px var(--font); padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--bg); color: var(--ink-2); cursor: pointer;
}
.ch-langs button[aria-checked="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.ch-text { font: 400 clamp(22px, 4.6vw, 30px)/1.35 var(--serif); margin: 12px 0 14px; }
.ch-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
  font: 600 14px var(--font); padding: 11px 18px; border-radius: 99px; border: 1.5px solid var(--ink); background: var(--ink); color: #fff;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
}
.btn.ghost { background: transparent; color: var(--ink); }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; }
.btn.armed { background: #2f8f4e; border-color: #2f8f4e; }
.ch-result { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.ch-score { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.ch-score span { font: 400 54px/1 var(--serif); color: var(--plum); }
.ch-score small { color: var(--ink-2); font-size: 14px; }
.ch-words { font: 400 20px/1.6 var(--serif); margin: 10px 0 14px; }
.ch-words .ok { color: #2f8f4e; }
.ch-words .miss { color: #c2410c; text-decoration: underline wavy rgba(194, 65, 12, .5); text-underline-offset: 4px; }

/* ---------- share dialog ---------- */
.share {
  width: min(92vw, 440px); max-height: 92vh; overflow: auto; border: 0; border-radius: 24px; padding: 22px; background: var(--card); color: var(--ink);
  box-shadow: 0 30px 80px -30px rgba(20, 27, 52, .6);
}
.share::backdrop { background: rgba(20, 27, 52, .45); }
.share h2 { margin: 0 0 12px; font: 400 26px var(--serif); }
.sh-preview img, .sh-preview video { display: block; width: 100%; max-height: 56vh; object-fit: contain; border-radius: 16px; background: var(--bg); }
.sh-text { color: var(--ink-2); font-size: 14px; margin: 12px 0; }
.sh-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sh-actions .btn[hidden] { display: none; }
.sh-close { position: absolute; top: 12px; right: 14px; width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--bg); font-size: 22px; cursor: pointer; color: var(--ink); }

.vad-debug {
  position: fixed; left: 8px; bottom: 8px; z-index: 50; margin: 0; padding: 10px 12px; border-radius: 12px;
  background: rgba(20, 27, 52, .92); color: #d6f5d6; font: 11px/1.45 ui-monospace, Menlo, monospace; pointer-events: none; max-width: calc(100vw - 16px); white-space: pre-wrap;
}

/* ---------- settings ---------- */
.settings {
  width: 100%; margin-top: 22px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 4px 18px;
}
.settings summary { cursor: pointer; font-weight: 600; padding: 12px 0; }
.settings-grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 16px; padding: 4px 0 18px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-2); min-width: 0; }
.field output { color: var(--ink-3); }
select {
  font: 500 14px var(--font); color: var(--ink); padding: 9px 10px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); width: 100%;
}
input[type="range"] { accent-color: var(--plum); width: 100%; }

.foot { text-align: center; color: var(--ink-3); font-size: 12px; padding: 8px 16px 28px; }
.foot p { margin: 0; }
.foot-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.foot-links a {
  font: 600 14px var(--font); color: var(--ink); text-decoration: none;
  padding: 10px 16px; border-radius: 99px; border: 1.5px solid var(--ink); background: var(--card);
}
.foot-links a:hover { background: var(--ink); color: #fff; }
.foot-links a:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; }

@media (max-width: 560px) {
  .settings-grid { grid-template-columns: 1fr 1fr; }
  .settings-grid .field:first-child { grid-column: 1 / -1; }
  .bubble { max-width: 74%; font-size: 15px; }
  .mode { padding: 8px 12px; font-size: 13px; }
  .act { width: 68px; }
}

@media (prefers-reduced-motion: reduce) {
  .tail, .body, .sun, .eye, .cat, .head, .orbit, .dizzy-eyes { animation: none !important; }
}
