:root {
  --bg: #F7F4EE;
  --ink: #12100E;
  --muted: rgba(18, 16, 14, 0.7);
  --orb-idle-a: #4a4a4a;
  --orb-idle-b: #1a1a1a;
  --orb-listening-a: #2b2b2b;
  --orb-listening-b: #050505;
  --orb-talking-a: #ff6b5e;
  --orb-talking-b: #c81324;
  --ring-listening: rgba(18, 16, 14, 0.3);
  --ring-talking: rgba(196, 39, 31, 0.45);
  --pill-bg: rgba(18, 16, 14, 0.06);
  --danger: #c4271f;
  --radius-lg: 28px;
  --level: 0; /* live audio volume 0-1, set from JS */

  /* Blob palette — idle (high-contrast grayscale water drift) */
  --blob-base-a: #5a5a5a;
  --blob-base-b: #050505;
  --blob-a: rgba(225, 225, 225, 0.8);
  --blob-b: rgba(70, 70, 70, 0.65);
  --blob-c: rgba(190, 190, 190, 0.6);
  --blob-d: rgba(20, 20, 20, 0.75);
  --blob-e: rgba(140, 140, 140, 0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  touch-action: manipulation;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom)) 20px;
  padding-top: calc(20px + env(safe-area-inset-top));
}

.status {
  margin-top: 22px;
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--pill-bg);
  color: var(--muted);
  font-size: 12px;
  transition: background 0.3s ease, color 0.3s ease;
  backdrop-filter: blur(8px);
}

.status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  transition: background 0.3s ease;
}

.status.live {
  background: rgba(196, 39, 31, 0.12);
  color: #A31E17;
}

.status.live::before {
  background: #C4271F;
  animation: dot-breathe 1.8s ease-in-out infinite;
}

@keyframes dot-breathe {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 36px;
  min-height: 0;
}

.title {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.85;
  gap: 2px;
}

.title .atom {
  font-family: "Bebas Neue", "Inter", sans-serif;
  font-weight: 400;
  font-size: clamp(48px, 12vw, 88px);
  letter-spacing: 4px;
  color: #12100E;
  text-shadow: 2px 4px 16px rgba(18, 16, 14, 0.14);
}

.title .voice {
  font-family: "Bebas Neue", "Inter", sans-serif;
  font-weight: 400;
  font-size: clamp(16px, 4vw, 26px);
  letter-spacing: 6px;
  text-transform: lowercase;
  color: #C4271F;
  opacity: 1;
  text-shadow: 1px 2px 8px rgba(196, 39, 31, 0.22);
}

.orb-wrap {
  position: relative;
  --size: clamp(158px, 40vw, 224px);
  width: clamp(182px, 46vw, 256px);
  height: clamp(182px, 46vw, 256px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.orb {
  width: var(--size);
  height: var(--size);
  border: none;
  cursor: pointer;
  background: transparent;
  overflow: hidden;
  clip-path: url(#heartClip);
  -webkit-clip-path: url(#heartClip);
  /* clip-path clips box-shadow away entirely, so the depth and the state
     glows both have to come from drop-shadow, which follows the clipped
     alpha and therefore hugs the heart's real outline. */
  filter: drop-shadow(0 10px 24px rgba(18, 16, 14, 0.22));
  position: relative;
  z-index: 2;
  user-select: none;
  -webkit-user-select: none;
  animation: breathe 1.9s ease-in-out infinite;
  transform: scale(calc(1 + var(--level) * 0.18));
  transition: box-shadow 0.15s ease;
  will-change: transform;
}

/* Glossy glass sheen — sits above the liquid noise layer, gives the
   frosted/refractive "liquid glass" look via a specular highlight
   and a soft rim light around the edge. */
.orb::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  z-index: 3;
  pointer-events: none;
  background: radial-gradient(
      circle at 32% 26%,
      rgba(255, 255, 255, 0.55) 0%,
      rgba(255, 255, 255, 0.18) 18%,
      rgba(255, 255, 255, 0) 42%
    ),
    radial-gradient(circle at 70% 78%, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0) 30%);
  mix-blend-mode: screen;
}

.orb::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  z-index: 3;
  pointer-events: none;
  box-shadow: inset 0 -8px 16px rgba(0, 0, 0, 0.35), inset 0 6px 10px rgba(255, 255, 255, 0.15);
}

/* Two beats then a rest, the way a heart actually sounds. The scale sits on
   top of the --level transform, so a loud voice still swells it further. */
@keyframes breathe {
  0%   { transform: scale(calc(1 + var(--level) * 0.18)); }
  8%   { transform: scale(calc(1.055 + var(--level) * 0.18)); }
  16%  { transform: scale(calc(1 + var(--level) * 0.18)); }
  26%  { transform: scale(calc(1.035 + var(--level) * 0.18)); }
  36%  { transform: scale(calc(1 + var(--level) * 0.18)); }
  100% { transform: scale(calc(1 + var(--level) * 0.18)); }
}

.orb:hover .orb-inner {
  filter: brightness(1.08);
}

.orb:active .orb-inner {
  filter: brightness(0.93);
}

.orb-inner {
  position: absolute;
  inset: -35%;
  border-radius: 50%;
  background: radial-gradient(circle at 22% 28%, var(--blob-a) 0%, transparent 46%),
    radial-gradient(circle at 78% 22%, var(--blob-b) 0%, transparent 50%),
    radial-gradient(circle at 65% 75%, var(--blob-c) 0%, transparent 52%),
    radial-gradient(circle at 25% 78%, var(--blob-d) 0%, transparent 50%),
    radial-gradient(circle at 55% 45%, var(--blob-e) 0%, transparent 48%),
    radial-gradient(circle at 50% 50%, var(--blob-base-a), var(--blob-base-b));
  background-size: 260% 260%, 260% 260%, 260% 260%, 260% 260%, 240% 240%, 100% 100%;
  filter: blur(16px) saturate(1.4) contrast(1.25);
  animation: flow 7s ease-in-out infinite;
  transition: filter 0.4s ease;
}

/* Rotating conic sweep — a soft blurred band of light continuously
   circling the sphere. This is the main thing that reads as "liquid
   swirl" (same trick behind the ChatGPT-style orb). Pure transform
   rotation, no SVG filter dependency, so it renders everywhere. */
.orb-inner::before {
  content: "";
  position: absolute;
  inset: -20%;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    rgba(255, 255, 255, 0.5) 40deg,
    transparent 100deg,
    rgba(0, 0, 0, 0.55) 170deg,
    transparent 230deg,
    rgba(255, 255, 255, 0.3) 300deg,
    transparent 360deg
  );
  filter: blur(20px);
  mix-blend-mode: overlay;
  animation: spin-sweep 9s linear infinite;
  will-change: transform;
}

/* Slower counter-drifting wash for parallax depth. */
.orb-inner::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 65%, rgba(255, 255, 255, 0.4) 0%, transparent 40%),
    radial-gradient(circle at 68% 30%, rgba(0, 0, 0, 0.5) 0%, transparent 42%),
    radial-gradient(circle at 40% 15%, rgba(255, 255, 255, 0.25) 0%, transparent 38%);
  background-size: 220% 220%;
  filter: blur(10px);
  mix-blend-mode: overlay;
  animation: flow2 12s ease-in-out infinite reverse;
}

@keyframes flow {
  0% {
    background-position: 0% 0%, 100% 0%, 60% 100%, 0% 100%, 50% 50%, 0 0;
    transform: rotate(0deg) scale(1.05);
  }
  20% {
    background-position: 35% 55%, 70% 30%, 40% 75%, 20% 60%, 65% 25%, 0 0;
    transform: rotate(10deg) scale(1.15);
  }
  40% {
    background-position: 65% 15%, 45% 65%, 75% 45%, 45% 85%, 30% 60%, 0 0;
    transform: rotate(-8deg) scale(1.1);
  }
  60% {
    background-position: 20% 70%, 80% 55%, 25% 35%, 60% 25%, 70% 70%, 0 0;
    transform: rotate(9deg) scale(1.18);
  }
  80% {
    background-position: 55% 25%, 30% 80%, 65% 20%, 35% 55%, 20% 30%, 0 0;
    transform: rotate(-6deg) scale(1.08);
  }
  100% {
    background-position: 0% 0%, 100% 0%, 60% 100%, 0% 100%, 50% 50%, 0 0;
    transform: rotate(0deg) scale(1.05);
  }
}

@keyframes spin-sweep {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes flow2 {
  0% {
    background-position: 0% 0%, 100% 100%, 50% 0%;
  }
  33% {
    background-position: 60% 70%, 30% 40%, 80% 30%;
  }
  66% {
    background-position: 20% 30%, 70% 80%, 20% 60%;
  }
  100% {
    background-position: 0% 0%, 100% 100%, 50% 0%;
  }
}

/* Connecting: dashed ring spins around the orb while the session sets up */
.orb.connecting {
  animation: none;
}

.orb.connecting::after {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px dashed rgba(245, 245, 245, 0.3);
  animation: spin 2.2s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* Listening: mic is capturing — the heart darkens to near-black and beats faster */
.orb.listening {
  animation: breathe 1.5s ease-in-out infinite;
  filter: drop-shadow(0 10px 24px rgba(18, 16, 14, 0.22))
    drop-shadow(0 0 calc(10px + var(--level) * 34px)
                rgba(18, 16, 14, calc(0.28 + var(--level) * 0.42)));
}

.orb.listening .orb-inner {
  /* Listening is a solid black heart on purpose: every blob resolves to the
     same colour, so the liquid motion has nothing to reveal and the fill
     reads as one flat mass. Idle stays grey and liquid, talking stays red. */
  --blob-base-a: #050505;
  --blob-base-b: #050505;
  --blob-a: rgba(5, 5, 5, 1);
  --blob-b: rgba(5, 5, 5, 1);
  --blob-c: rgba(5, 5, 5, 1);
  --blob-d: rgba(5, 5, 5, 1);
  --blob-e: rgba(5, 5, 5, 1);
}

/* Talking: bot audio is playing — the heart flows red and quickens further */
.orb.talking {
  animation: breathe 1.05s ease-in-out infinite;
  filter: drop-shadow(0 10px 24px rgba(18, 16, 14, 0.22))
    drop-shadow(0 0 calc(12px + var(--level) * 40px)
                rgba(196, 39, 31, calc(0.45 + var(--level) * 0.55)));
}

.orb.listening .orb-inner::before,
.orb.listening .orb-inner::after {
  opacity: 0;
}

.orb.talking .orb-inner {
  --blob-base-a: #ff3b30;
  --blob-base-b: #7a0d16;
  --blob-a: rgba(255, 107, 94, 0.85);
  --blob-b: rgba(229, 9, 20, 0.75);
  --blob-c: rgba(255, 150, 130, 0.55);
  --blob-d: rgba(150, 10, 20, 0.75);
}

.error-banner {
  font-size: 13px;
  color: #8E1A14;
  background: rgba(196, 39, 31, 0.12);
  padding: 8px 14px;
  border-radius: 10px;
  max-width: 320px;
  text-align: center;
  display: none;
  animation: fade-in 0.25s ease;
}

.error-banner.visible {
  display: block;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  .orb,
  .orb.connecting::after,
  .status.live::before,
  .error-banner,
  }

/* Small phones: tighten spacing a bit */
@media (max-height: 640px) {
  .stage {
    gap: 20px;
  }
  .app {
    padding-left: 16px;
    padding-right: 16px;
  }
}
