:root {
  color-scheme: dark;
  --bg: #101312;
  --panel: #171c1a;
  --panel-2: #202724;
  --line: #33413c;
  --text: #eef4ec;
  --muted: #9baa9b;
  --accent: #79d08d;
  --accent-2: #e0b46f;
  --accent-strong: #8ee7a1;
  --danger: #e46f61;
  --skin: #c99a78;
  --skin-2: #a87558;
  --hair: #2b211f;
  --hair-2: #4a302c;
  --radius: 8px;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 34%),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  height: calc(100svh - 32px);
  min-height: 560px;
  margin: 16px auto;
  display: grid;
  grid-template-columns: minmax(260px, 330px) minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
  box-shadow: var(--shadow);
  transition: grid-template-columns 220ms ease;
}

.shell.stage-collapsed {
  grid-template-columns: 112px minmax(0, 1fr);
}

.stage {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 18px;
  padding: 22px;
  background:
    linear-gradient(180deg, rgba(121, 208, 141, 0.05), transparent 42%),
    #151a16;
  border-right: 1px solid var(--line);
}

.status-bar,
.state-panel,
.connection-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
}

.connection-status {
  min-width: 0;
  justify-content: flex-start;
}

.stage-toggle {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(32, 39, 36, 0.82);
  color: var(--text);
  cursor: pointer;
}

.stage-toggle:hover,
.icon-button:hover {
  border-color: rgba(121, 208, 141, 0.62);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(198, 161, 91, 0.16);
}

.dot.online {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(121, 208, 141, 0.16);
}

.dot.error {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(228, 111, 97, 0.16);
}

.avatar {
  position: relative;
  align-self: center;
  justify-self: center;
  width: min(72vw, 284px);
  display: grid;
  justify-items: center;
  gap: 0;
}

.shell.stage-collapsed .stage {
  padding-inline: 14px;
}

.shell.stage-collapsed .connection-status span:last-child,
.shell.stage-collapsed .state-panel .label,
.shell.stage-collapsed .voice-wave {
  display: none;
}

.shell.stage-collapsed .status-bar,
.shell.stage-collapsed .state-panel {
  justify-content: center;
}

.shell.stage-collapsed .avatar {
  width: 86px;
  transform: scale(0.38);
}

.avatar-portrait {
  position: relative;
  width: min(100%, 284px);
  aspect-ratio: 0.72;
  display: grid;
  place-items: center;
  border: 1px solid rgba(224, 180, 111, 0.18);
  border-radius: 28px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 76%, rgba(224, 180, 111, 0.26), transparent 34%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 46%),
    #221b16;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 22px 46px rgba(0, 0, 0, 0.3);
}

.avatar-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  opacity: 0;
  transform: scale(1);
  transition: opacity 180ms ease, transform 260ms ease;
}

.avatar-image-default {
  opacity: 1;
}

.avatar.thinking .avatar-image-default,
.avatar.speaking .avatar-image-default {
  opacity: 0;
}

.avatar.thinking .avatar-image-thinking {
  opacity: 1;
  transform: scale(1.02);
}

.avatar.speaking .avatar-image-speaking {
  opacity: 1;
  transform: scale(1.02);
}

.avatar.listening .avatar-image-default {
  transform: scale(1.015);
}

.thoughts {
  position: absolute;
  top: -18px;
  right: 24px;
  width: 74px;
  height: 42px;
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.thoughts span {
  position: absolute;
  display: block;
  border: 1px solid rgba(121, 208, 141, 0.55);
  border-radius: 999px;
  background: rgba(32, 39, 32, 0.94);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
  animation: thoughtPulse 1.2s ease-in-out infinite;
}

.thoughts span:nth-child(1) {
  right: 0;
  top: 0;
  width: 32px;
  height: 22px;
}

.thoughts span:nth-child(2) {
  right: 36px;
  top: 18px;
  width: 18px;
  height: 14px;
  animation-delay: 120ms;
}

.thoughts span:nth-child(3) {
  right: 60px;
  top: 31px;
  width: 10px;
  height: 8px;
  animation-delay: 240ms;
}

.avatar-head {
  position: relative;
  width: 214px;
  height: 230px;
  border: 1px solid rgba(97, 76, 61, 0.8);
  border-radius: 48% 48% 43% 43% / 45% 45% 52% 52%;
  background:
    radial-gradient(circle at 48% 26%, rgba(255, 255, 255, 0.2), transparent 24%),
    radial-gradient(circle at 32% 60%, rgba(255, 130, 118, 0.2), transparent 11%),
    radial-gradient(circle at 68% 60%, rgba(255, 130, 118, 0.18), transparent 11%),
    linear-gradient(180deg, #e1b58f, var(--skin) 58%, #bd8465);
  box-shadow:
    inset 0 -18px 28px rgba(76, 43, 28, 0.2),
    0 24px 46px rgba(0, 0, 0, 0.26);
  z-index: 2;
}

.avatar-hair-back {
  position: absolute;
  top: 44px;
  width: 252px;
  height: 278px;
  border-radius: 112px 112px 88px 88px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.05), transparent 24% 76%, rgba(255, 255, 255, 0.035)),
    linear-gradient(180deg, var(--hair-2), var(--hair) 42%, #1d1918);
  box-shadow:
    inset 18px 0 28px rgba(255, 255, 255, 0.035),
    inset -18px 0 26px rgba(0, 0, 0, 0.18),
    0 26px 48px rgba(0, 0, 0, 0.28);
  z-index: 0;
}

.hair {
  position: absolute;
  top: -10px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 32%),
    var(--hair);
  z-index: 5;
}

.hair-left {
  left: 0;
  width: 134px;
  height: 84px;
  border-radius: 94px 54px 70px 22px;
  transform: rotate(-13deg);
}

.hair-right {
  right: 0;
  width: 116px;
  height: 82px;
  border-radius: 54px 96px 28px 76px;
  transform: rotate(13deg);
}

.ear {
  position: absolute;
  top: 94px;
  width: 22px;
  height: 38px;
  border: 1px solid rgba(97, 76, 61, 0.68);
  border-radius: 50%;
  background: #bd8569;
  z-index: 1;
}

.ear-left {
  left: -10px;
}

.ear-right {
  right: -10px;
}

.brow {
  position: absolute;
  top: 88px;
  width: 32px;
  height: 6px;
  border-radius: 999px;
  background: #352820;
  z-index: 4;
}

.brow-left {
  left: 58px;
  transform: rotate(-9deg);
}

.brow-right {
  right: 58px;
  transform: rotate(9deg);
}

.avatar-body {
  position: relative;
  width: 230px;
  height: 116px;
  margin-top: -16px;
  border: 1px solid #3e5148;
  border-radius: 84px 84px 8px 8px;
  background:
    radial-gradient(ellipse at 50% 0, rgba(121, 208, 141, 0.14), transparent 38%),
    linear-gradient(90deg, transparent 0 35%, rgba(255, 255, 255, 0.05) 35% 65%, transparent 65%),
    linear-gradient(180deg, #3a5147, #26322f);
  box-shadow: inset 0 18px 30px rgba(255, 255, 255, 0.03);
  z-index: 1;
}

.collar {
  position: absolute;
  top: 12px;
  width: 54px;
  height: 42px;
  background: #eef4ec;
  opacity: 0.92;
}

.collar-left {
  left: 72px;
  clip-path: polygon(0 0, 100% 0, 72% 100%);
}

.collar-right {
  right: 72px;
  clip-path: polygon(0 0, 100% 0, 28% 100%);
}

.avatar-neck {
  width: 50px;
  height: 40px;
  margin-top: -10px;
  border: 1px solid rgba(97, 76, 61, 0.55);
  border-radius: 18px;
  background: linear-gradient(180deg, #b98162, #9b654d);
  z-index: 1;
}

.eye {
  position: absolute;
  top: 104px;
  width: 22px;
  height: 17px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 62% 30%, #ffffff 0 2px, transparent 3px),
    #1d1d1b;
  z-index: 4;
}

.eye-left {
  left: 62px;
}

.eye-right {
  right: 62px;
}

.nose {
  position: absolute;
  left: 50%;
  top: 122px;
  width: 14px;
  height: 25px;
  transform: translateX(-50%);
  border-right: 2px solid rgba(100, 60, 42, 0.34);
  border-bottom: 2px solid rgba(100, 60, 42, 0.28);
  border-radius: 0 0 12px 8px;
  z-index: 4;
}

.cheek {
  position: absolute;
  top: 142px;
  width: 34px;
  height: 14px;
  border-radius: 50%;
  background: rgba(224, 108, 96, 0.18);
  filter: blur(0.2px);
}

.cheek-left {
  left: 44px;
}

.cheek-right {
  right: 44px;
}

.mouth {
  --mouth-open: 0;
  position: absolute;
  left: 50%;
  top: calc(166px - (6px * var(--mouth-open)));
  width: calc(36px + (18px * var(--mouth-open)));
  height: calc(7px + (24px * var(--mouth-open)));
  transform: translateX(-50%);
  border-radius: 999px;
  background:
    radial-gradient(ellipse at 50% 76%, #d78a80 0 34%, transparent 35%),
    #251718;
  transition: height 70ms linear, top 70ms linear, width 70ms linear;
  z-index: 4;
}

.avatar.thinking {
  animation: avatarThink 1.8s ease-in-out infinite;
}

.avatar.thinking .avatar-head {
  animation: headThink 1.8s ease-in-out infinite;
}

.avatar.thinking .thoughts {
  opacity: 1;
  transform: translateY(0);
}

.avatar.listening .eye,
.avatar.speaking .eye {
  animation: eyeFocus 1.6s ease-in-out infinite;
}

.avatar.thinking .mouth {
  width: 38px;
}

.avatar.speaking .mouth {
  box-shadow: inset 0 -5px 0 rgba(255, 255, 255, 0.08);
}

.avatar-portrait .mouth {
  --mouth-open: 0;
  left: 50%;
  top: calc(34.5% - (3.5% * var(--mouth-open)));
  width: calc(13% + (7% * var(--mouth-open)));
  height: calc(1.5% + (7% * var(--mouth-open)));
  opacity: calc(var(--mouth-open) * 0.92);
  background:
    radial-gradient(ellipse at 50% 78%, #f0a096 0 34%, transparent 36%),
    #2a1517;
  border: 1px solid rgba(58, 16, 18, 0.45);
  z-index: 4;
}

.avatar.speaking .avatar-portrait {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 24px 52px rgba(0, 0, 0, 0.34),
    0 0 0 1px rgba(121, 208, 141, 0.16);
}

.label,
.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.state-panel {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.state-panel strong {
  color: var(--text);
}

.voice-wave {
  height: 34px;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  align-items: center;
  gap: 6px;
  opacity: 0.52;
}

.voice-wave span {
  height: 8px;
  border-radius: 999px;
  background: rgba(121, 208, 141, 0.5);
  transform-origin: center;
  transition: height 160ms ease, background 160ms ease, opacity 160ms ease;
}

.voice-wave span:nth-child(2),
.voice-wave span:nth-child(6) {
  height: 14px;
}

.voice-wave span:nth-child(3),
.voice-wave span:nth-child(5) {
  height: 22px;
}

.voice-wave span:nth-child(4) {
  height: 28px;
}

.voice-wave.listening,
.voice-wave.speaking {
  opacity: 1;
}

.voice-wave.listening span,
.voice-wave.speaking span {
  background: var(--accent-strong);
  animation: waveLift 780ms ease-in-out infinite;
}

.voice-wave.thinking span {
  background: rgba(224, 180, 111, 0.72);
  animation: waveLift 1.1s ease-in-out infinite;
}

.voice-wave span:nth-child(2) {
  animation-delay: 70ms;
}

.voice-wave span:nth-child(3) {
  animation-delay: 140ms;
}

.voice-wave span:nth-child(4) {
  animation-delay: 210ms;
}

.voice-wave span:nth-child(5) {
  animation-delay: 280ms;
}

.voice-wave span:nth-child(6) {
  animation-delay: 350ms;
}

.conversation {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--panel);
}

.conversation-header {
  min-height: 84px;
  padding: 20px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

h1 {
  margin: 4px 0 0;
  font-size: 24px;
  font-weight: 720;
  letter-spacing: 0;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}

.messages {
  min-height: 0;
  height: 100%;
  overflow: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
}

.message {
  width: fit-content;
  max-width: min(58ch, 78%);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-wrap: pretty;
}

.message.user {
  align-self: flex-end;
  max-width: min(42ch, 70%);
  border-color: rgba(121, 208, 141, 0.44);
}

.message.assistant {
  align-self: flex-start;
}

.message.system,
.message.error {
  align-self: center;
  max-width: min(52ch, 86%);
  color: var(--muted);
  background: transparent;
}

.message.thinking {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 76px;
  color: var(--muted);
}

.message.thinking span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.48;
  animation: dotBounce 1s ease-in-out infinite;
}

.message.thinking span:nth-child(2) {
  animation-delay: 120ms;
}

.message.thinking span:nth-child(3) {
  animation-delay: 240ms;
}

.message.error {
  color: #ffc0b8;
  border-color: rgba(228, 111, 97, 0.42);
}

.message.audio-action {
  align-self: flex-start;
  border-color: rgba(121, 208, 141, 0.46);
  color: var(--text);
  cursor: pointer;
}

.message.audio-action:hover {
  border-color: var(--accent);
}

.composer {
  padding: 18px 22px 22px;
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) 96px;
  gap: 12px;
  border-top: 1px solid var(--line);
}

.record-button {
  --record-level: 0;
  width: 76px;
  height: 76px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background:
    linear-gradient(
      0deg,
      rgba(228, 111, 97, 0.22) calc(var(--record-level) * 100%),
      transparent calc(var(--record-level) * 100%)
    ),
    #111611;
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  touch-action: none;
  user-select: none;
  box-shadow:
    inset 0 0 0 calc(4px + var(--record-level) * 10px) rgba(228, 111, 97, 0.08),
    0 14px 26px rgba(0, 0, 0, 0.24);
  position: relative;
  overflow: visible;
}

.record-button::before,
.record-button::after {
  content: "";
  position: absolute;
  inset: -8px;
  border: 1px solid rgba(228, 111, 97, 0.34);
  border-radius: inherit;
  opacity: 0;
  pointer-events: none;
}

.record-button span {
  width: 18px;
  height: 28px;
  border: 2px solid currentColor;
  border-radius: 999px;
  position: relative;
}

.record-button span::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -10px;
  width: 24px;
  height: 10px;
  border-bottom: 2px solid currentColor;
  border-radius: 0 0 999px 999px;
  transform: translateX(-50%);
}

.record-button.recording {
  border-color: rgba(228, 111, 97, 0.72);
  color: #ffc0b8;
  animation: recordPulse 1s ease-in-out infinite;
}

.record-button.recording::before,
.record-button.recording::after {
  animation: micRipple 1.2s ease-out infinite;
}

.record-button.recording::after {
  animation-delay: 220ms;
}

.record-button.recording span {
  transform: scale(calc(1 + var(--record-level) * 0.18));
}

.composer input {
  min-width: 0;
  height: 56px;
  padding: 0 14px;
  border: 1px solid rgba(121, 208, 141, 0.22);
  border-radius: var(--radius);
  background: #111611;
  color: var(--text);
  outline: none;
}

.composer input:focus {
  border-color: var(--accent);
}

.composer button {
  height: 56px;
  border-radius: var(--radius);
  font-weight: 700;
  cursor: pointer;
}

.composer .record-button {
  width: 76px;
  height: 76px;
  border-radius: 50%;
}

.composer #sendButton {
  border: 0;
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  color: #0e150f;
  box-shadow: 0 12px 24px rgba(121, 208, 141, 0.14);
}

.composer #sendButton:hover {
  filter: brightness(1.05);
}

.composer button:disabled,
.composer input:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

@media (max-width: 760px) {
  body {
    overflow: hidden;
  }

  .shell {
    width: 100vw;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(238px, 34svh) minmax(0, 1fr);
    height: 100svh;
    min-height: 0;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .shell.stage-collapsed {
    grid-template-columns: 1fr;
    grid-template-rows: 74px minmax(0, 1fr);
  }

  .shell.stage-collapsed .avatar,
  .shell.stage-collapsed .voice-wave {
    display: none;
  }

  .stage {
    min-height: 0;
    max-height: none;
    gap: 8px;
    padding: 14px 18px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .avatar {
    width: 190px;
    transform: scale(0.68);
    transform-origin: center;
  }

  .conversation {
    min-height: 0;
  }

  .conversation-header {
    min-height: 64px;
    padding: 14px 16px;
  }

  h1 {
    font-size: 19px;
  }

  .messages {
    padding: 16px;
    gap: 10px;
  }

  .composer {
    grid-template-columns: 72px minmax(0, 1fr) 68px;
    align-items: center;
    padding: 12px max(12px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    gap: 10px;
  }

  .record-button {
    height: 72px;
    width: 72px;
  }

  .composer input {
    height: 50px;
    padding: 0 12px;
  }

  .composer #sendButton {
    height: 50px;
  }

  .message,
  .message.user,
  .message.system,
  .message.error {
    max-width: 92%;
  }
}

@keyframes avatarThink {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}

@keyframes headThink {
  0%,
  100% {
    transform: rotate(0deg);
  }
  50% {
    transform: rotate(-2deg);
  }
}

@keyframes thoughtPulse {
  0%,
  100% {
    transform: scale(0.92);
    opacity: 0.58;
  }
  50% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes dotBounce {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.42;
  }
  50% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

@keyframes recordPulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(228, 111, 97, 0.22);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(228, 111, 97, 0.08);
  }
}

@keyframes micRipple {
  0% {
    transform: scale(0.86);
    opacity: 0.62;
  }
  100% {
    transform: scale(1.22);
    opacity: 0;
  }
}

@keyframes waveLift {
  0%,
  100% {
    transform: scaleY(0.54);
  }
  50% {
    transform: scaleY(1.18);
  }
}

@keyframes eyeFocus {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-1px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .avatar.thinking,
  .avatar.thinking .avatar-head,
  .thoughts span,
  .message.thinking span,
  .record-button.recording,
  .record-button.recording::before,
  .record-button.recording::after,
  .voice-wave span,
  .avatar.listening .eye,
  .avatar.speaking .eye {
    animation: none;
  }
}
