:root {
  color-scheme: dark;
  --bg: #07080d;
  --panel: rgba(11, 14, 24, .72);
  --panel-border: rgba(149, 233, 255, .22);
  --text: #f4f7fb;
  --muted: #aeb8c8;
  --cyan: #00d7ff;
  --cyan-soft: rgba(0, 215, 255, .36);
  --violet: #a77cff;
  --violet-soft: rgba(167, 124, 255, .32);
  --error: #ff7a90;
  --success: #7dffca;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  color: var(--text);
  background:
    radial-gradient(circle at 50% 24%, rgba(0, 215, 255, .18), transparent 28rem),
    radial-gradient(circle at 70% 58%, rgba(167, 124, 255, .14), transparent 22rem),
    linear-gradient(145deg, #06070b 0%, #11131b 52%, #06070b 100%);
  overflow-x: hidden;
}

button {
  font: inherit;
}

.app-shell {
  position: relative;
  min-height: 100svh;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: clamp(.35rem, 1.2vh, 1rem);
  align-items: end;
  justify-items: center;
  padding: clamp(1rem, 2vw, 2rem);
  isolation: isolate;
}

.zappy-stage {
  position: relative;
  width: min(74vw, 31rem);
  min-height: 0;
  display: grid;
  place-items: center;
  align-self: center;
}

.ambient {
  position: absolute;
  width: 42%;
  aspect-ratio: 1;
  border-radius: 50%;
  filter: blur(42px);
  opacity: .34;
  transform: translateZ(0);
  transition: opacity .25s ease, scale .25s ease;
}

.ambient-cyan {
  top: 10%;
  left: 16%;
  background: var(--cyan);
}

.ambient-violet {
  right: 10%;
  bottom: 16%;
  background: var(--violet);
}

.status-orbit {
  position: absolute;
  width: min(96%, 34rem);
  aspect-ratio: 1;
  border: 1px solid rgba(164, 237, 255, .12);
  border-radius: 50%;
  opacity: .72;
  transition: opacity .25s ease, border-color .25s ease;
}

.status-orbit span {
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  border: 1px solid rgba(0, 215, 255, .12);
}

.status-orbit span:nth-child(2) {
  inset: 18%;
  border-color: rgba(167, 124, 255, .14);
}

.status-orbit span:nth-child(3) {
  inset: 30%;
}

.zappy-portrait {
  --look-x: 0px;
  --talk: 0;
  position: relative;
  width: min(58vw, 22.5rem);
  aspect-ratio: 647 / 809;
  overflow: hidden;
  filter: drop-shadow(0 2rem 3.6rem rgba(0, 0, 0, .58));
  animation: breathe 7s ease-in-out infinite;
  transform-origin: 50% 32%;
}

.zappy-image {
  position: absolute;
  inset: 0 auto 0 0;
  width: 300.2%;
  height: 100%;
  object-fit: cover;
  object-position: left center;
  pointer-events: none;
  user-select: none;
}

.eye {
  position: absolute;
  top: 25.4%;
  width: 4.2%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 42% 40%, #eaffff 0 8%, #39e4ff 14%, #078fe2 44%, #001328 73%);
  box-shadow: 0 0 .75rem rgba(0, 215, 255, .86);
  transform: translateX(var(--look-x));
  transition: transform .6s ease;
  mix-blend-mode: screen;
}

.eye-left {
  left: 35.4%;
}

.eye-right {
  right: 34.2%;
}

.lid {
  position: absolute;
  top: 23.2%;
  width: 10%;
  height: 0;
  border-radius: 0 0 999px 999px;
  background: linear-gradient(#d8d8d8, #a8a9ad);
  opacity: .96;
  animation: blink 6.4s infinite;
  box-shadow: 0 .25rem .5rem rgba(0, 0, 0, .28);
}

.lid-left {
  left: 31.7%;
}

.lid-right {
  right: 30.9%;
  animation-delay: .05s;
}

.mouth {
  position: absolute;
  left: 42.2%;
  top: 38.9%;
  width: 15.6%;
  height: calc(.35% + (var(--talk) * 2.8%));
  border-radius: 0 0 999px 999px;
  border-bottom: .18rem solid rgba(24, 29, 34, .95);
  background: radial-gradient(ellipse at 50% 15%, rgba(0, 0, 0, .42), rgba(0, 0, 0, .04) 70%);
  box-shadow: 0 .2rem .35rem rgba(255, 255, 255, .22) inset;
  transform: translateY(calc(var(--talk) * .3rem));
  opacity: .92;
  transition: height .08s linear, transform .08s linear;
}

.chest-pulse {
  position: absolute;
  left: 42.3%;
  top: 55.4%;
  width: 15.4%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: .22rem solid rgba(0, 215, 255, .92);
  box-shadow:
    0 0 .8rem rgba(0, 215, 255, .95),
    0 0 1.9rem rgba(0, 215, 255, .48),
    inset 0 0 1rem rgba(0, 215, 255, .55);
  opacity: .84;
  mix-blend-mode: screen;
}

.voice-panel {
  width: min(100%, 34rem);
  margin-bottom: max(1rem, env(safe-area-inset-bottom));
  padding: .85rem 1rem;
  border: 1px solid var(--panel-border);
  border-radius: 1.2rem;
  background: linear-gradient(180deg, rgba(14, 17, 29, .7), rgba(8, 10, 17, .86));
  box-shadow: 0 1.2rem 3rem rgba(0, 0, 0, .42);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  text-align: center;
}

.brand {
  margin: 0;
  font-size: clamp(2rem, 5.5vw, 3.45rem);
  line-height: .96;
  font-weight: 760;
  letter-spacing: 0;
}

.state-text {
  min-height: 1.6rem;
  margin: .45rem 0 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.helper-text,
.privacy-note {
  margin: .35rem auto 0;
  max-width: 30rem;
  color: var(--muted);
  line-height: 1.45;
}

.privacy-note {
  font-size: .88rem;
}

.controls {
  display: flex;
  justify-content: center;
  margin-top: .75rem;
}

.voice-button {
  min-height: 3.55rem;
  display: inline-flex;
  align-items: center;
  gap: .75rem;
  padding: .95rem 1.25rem;
  border: 1px solid rgba(0, 215, 255, .46);
  border-radius: 999px;
  color: var(--text);
  background: linear-gradient(135deg, rgba(0, 215, 255, .24), rgba(167, 124, 255, .22));
  box-shadow:
    0 0 0 .45rem rgba(0, 215, 255, .06),
    0 .9rem 2rem rgba(0, 0, 0, .36);
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.voice-button:hover {
  transform: translateY(-1px);
  border-color: rgba(125, 255, 202, .72);
}

.voice-button:focus-visible {
  outline: .2rem solid var(--success);
  outline-offset: .3rem;
}

.mic-icon {
  position: relative;
  width: 1.15rem;
  height: 1.65rem;
  border: .16rem solid currentColor;
  border-radius: 999px;
}

.mic-icon::before,
.mic-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  background: currentColor;
}

.mic-icon::before {
  bottom: -.55rem;
  width: .16rem;
  height: .46rem;
}

.mic-icon::after {
  bottom: -.7rem;
  width: .78rem;
  height: .16rem;
  border-radius: 999px;
}

.debug-panel {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 5;
  width: min(90vw, 28rem);
  max-height: 45vh;
  overflow: auto;
  padding: 1rem;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: .75rem;
  background: rgba(0, 0, 0, .78);
  color: #d8fff9;
  text-align: left;
}

.debug-panel h2 {
  margin: 0 0 .5rem;
  font-size: 1rem;
}

.debug-panel pre {
  margin: 0;
  white-space: pre-wrap;
  font-size: .78rem;
}

[data-state="listening"] .ambient,
[data-state="speaking"] .ambient,
[data-state="thinking"] .ambient {
  opacity: .64;
  scale: 1.08;
}

[data-state="listening"] .status-orbit,
[data-state="speaking"] .status-orbit {
  border-color: rgba(0, 215, 255, .38);
  animation: orbitPulse 2.4s ease-in-out infinite;
}

[data-state="thinking"] .status-orbit {
  border-color: rgba(167, 124, 255, .46);
  animation: thinkSpin 5s linear infinite;
}

[data-state="speaking"] .chest-pulse,
[data-state="listening"] .chest-pulse {
  animation: chestGlow 1.2s ease-in-out infinite;
}

[data-state="error"] .state-text {
  color: var(--error);
}

[data-state="demo"] .state-text {
  color: var(--success);
}

@keyframes breathe {
  0%, 100% {
    transform: translateY(0) rotate(-.2deg);
  }
  50% {
    transform: translateY(.55rem) rotate(.4deg);
  }
}

@keyframes blink {
  0%, 92%, 100% {
    height: 0;
  }
  94%, 96% {
    height: 5.8%;
  }
}

@keyframes orbitPulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(0, 215, 255, .24);
  }
  50% {
    box-shadow: 0 0 0 1rem rgba(0, 215, 255, 0);
  }
}

@keyframes thinkSpin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes chestGlow {
  0%, 100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.7);
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: .8rem;
  }

  .zappy-stage {
    width: min(94vw, 24rem);
  }

  .zappy-portrait {
    width: min(72vw, 18.5rem);
  }

  .voice-panel {
    border-radius: 1rem;
  }

  .privacy-note {
    display: none;
  }
}

@media (max-height: 760px) {
  .app-shell {
    padding-top: .45rem;
    padding-bottom: .45rem;
  }

  .zappy-portrait {
    width: min(50vw, 19rem);
  }

  .voice-panel {
    padding: .7rem .9rem;
    margin-bottom: .25rem;
  }

  .brand {
    font-size: clamp(1.85rem, 4.8vw, 3rem);
  }

  .privacy-note {
    display: none;
  }
}

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