:root {
  --bg1: #fff6ea;
  --bg2: #ffe3c4;
  --ink: #2d2340;
  --muted: #6b5f7a;
  --accent: #7c5cff;
  --accent-dark: #5b3fe0;
  --stop: #e2445c;
  --card: #ffffffcc;
  --radius: 22px;
  font-family: 'Rubik', 'Baloo Bhaijaan 2', system-ui, sans-serif;
  color: var(--ink);
}
html[lang='ar'] { font-family: 'Baloo Bhaijaan 2', 'Rubik', system-ui, sans-serif; }

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 50% 30%, var(--bg1), var(--bg2));
  display: flex;
  flex-direction: column;
}

.skip { position: absolute; inset-inline-start: -999px; }
.skip:focus { inset-inline-start: 12px; top: 12px; background: #fff; padding: 8px 12px; border-radius: 8px; z-index: 10; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.top {
  display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; justify-content: space-between;
  padding: 16px 24px;
}
.top h1 { margin: 0; font-size: clamp(1.4rem, 3vw, 2rem); }

.langs { display: flex; gap: 6px; background: var(--card); padding: 5px; border-radius: 999px; }
.lang {
  border: 0; background: transparent; color: var(--ink);
  font: inherit; font-weight: 600; padding: 8px 16px; border-radius: 999px; cursor: pointer;
}
.lang[aria-pressed='true'] { background: var(--accent); color: #fff; }

main {
  flex: 1; width: 100%; max-width: 640px; margin: 0 auto;
  padding: 0 20px 32px; display: flex; flex-direction: column; align-items: center; gap: 18px;
}

.stage { position: relative; display: flex; flex-direction: column; align-items: center; width: 100%; }
.zuzu { width: min(330px, 78vw); height: auto; overflow: visible; }
.shadow { fill: #00000014; }
.ring { fill: none; stroke: var(--accent); stroke-width: 6; opacity: 0; transform-origin: 150px 165px; transition: opacity .3s; }

/* --- character states --- */
.body { transform-origin: 150px 270px; }
.state-idle .body { animation: breathe 3.5s ease-in-out infinite; }
.state-listening .body { animation: breathe 2.4s ease-in-out infinite; }
.state-listening .ring { opacity: .5; }
.state-thinking .body { animation: tilt 1.6s ease-in-out infinite; }
.state-speaking .body { animation: bounce .5s ease-in-out infinite; }
.ears { transform-origin: 150px 90px; }
.state-listening .ears { animation: wiggle 1.2s ease-in-out infinite; }
.eyes { transform-origin: 150px 140px; }
.eyes.blink { transform: scaleY(.1); transition: transform .08s; }
#pupils { transition: transform .15s ease-out; }

@keyframes breathe { 50% { transform: scale(1.025, .985); } }
@keyframes bounce { 50% { transform: translateY(-6px) scale(1.01); } }
@keyframes tilt { 25% { transform: rotate(-4deg); } 75% { transform: rotate(4deg); } }
@keyframes wiggle { 50% { transform: rotate(2deg); } }

.bubble {
  position: absolute; top: 4%; inset-inline-end: 6%;
  background: #fff; border-radius: 20px; padding: 10px 14px; display: flex; gap: 5px;
  box-shadow: 0 4px 14px #0001; opacity: 0; transform: scale(.6); transition: .25s;
}
.bubble span { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); animation: dot 1s infinite; }
.bubble span:nth-child(2) { animation-delay: .15s; }
.bubble span:nth-child(3) { animation-delay: .3s; }
.bubble.show { opacity: 1; transform: scale(1); }
@keyframes dot { 50% { transform: translateY(-5px); opacity: .5; } }

.status { margin: 6px 0 0; font-weight: 600; color: var(--muted); min-height: 1.4em; }
.caption {
  margin: 8px 0 0; min-height: 3.2em; max-width: 520px; text-align: center;
  font-size: 1.15rem; line-height: 1.5; background: var(--card); padding: 10px 18px; border-radius: var(--radius);
}
.caption:empty { visibility: hidden; }

.talk {
  display: inline-flex; align-items: center; gap: 10px;
  font: inherit; font-size: 1.2rem; font-weight: 700; color: #fff;
  background: var(--accent); border: 0; border-radius: 999px; padding: 16px 34px;
  cursor: pointer; box-shadow: 0 8px 22px #7c5cff55; transition: transform .15s, background .2s;
}
.talk:hover { background: var(--accent-dark); }
.talk:active { transform: scale(.97); }
.talk[aria-pressed='true'] { background: var(--stop); box-shadow: 0 8px 22px #e2445c55; }
.talk:disabled { opacity: .6; cursor: wait; }
.mic-icon { width: 26px; height: 26px; fill: currentColor; }

.text-form { display: flex; gap: 8px; width: 100%; }
.text-form input {
  flex: 1; font: inherit; padding: 12px 16px; border-radius: 999px; border: 2px solid #e6d6c4; background: #fff;
}
.text-form button {
  font: inherit; font-weight: 600; border: 0; border-radius: 999px; padding: 0 20px;
  background: var(--ink); color: #fff; cursor: pointer;
}
.text-form :disabled { opacity: .5; cursor: not-allowed; }

.log-wrap { width: 100%; background: var(--card); border-radius: var(--radius); padding: 10px 18px; }
.log-wrap summary { cursor: pointer; font-weight: 600; }
.log { list-style: none; padding: 0; margin: 10px 0 0; max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.log li { padding: 8px 12px; border-radius: 14px; max-width: 85%; line-height: 1.45; }
.log li.user { align-self: flex-end; background: #e9e3ff; }
.log li.bot { align-self: flex-start; background: #fff; }

:focus-visible { outline: 3px solid var(--accent-dark); outline-offset: 3px; }

@media (prefers-reduced-motion: reduce) {
  .body, .ears, .bubble span { animation: none !important; }
}
