:root {
  --skin: #e8c4a8;
  --skin-shadow: #c9a088;
  --skin-light: #f5dcc8;
  --bg0: #0d0f14;
  --bg1: #1a1e2a;
  --accent: #7eb8da;
  --mouth-inner: #6b3a3a;
  --text: #e8eaef;
  --muted: #8b92a5;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "DM Sans", system-ui, sans-serif;
  background: radial-gradient(ellipse 120% 80% at 50% -20%, #2a3148 0%, var(--bg0) 55%);
  color: var(--text);
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.25rem 1rem 2rem;
}

header {
  text-align: center;
  margin-bottom: 1rem;
  max-width: 36rem;
}

header h1 {
  font-weight: 600;
  font-size: 1.65rem;
  letter-spacing: -0.02em;
  margin: 0 0 0.35rem;
}

header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.stage-wrap {
  perspective: 1200px;
  margin: 0 auto 1.5rem;
}

.stage {
  width: min(92vw, 380px);
  height: min(92vw, 420px);
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.12s ease-out;
}

.face-shell {
  position: absolute;
  inset: 8% 10%;
  border-radius: 50% 50% 48% 48% / 46% 46% 52% 52%;
  background: linear-gradient(
    165deg,
    var(--skin-light) 0%,
    var(--skin) 42%,
    var(--skin-shadow) 100%
  );
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.45),
    inset 0 -20px 35px rgba(180, 120, 90, 0.25),
    inset 8px 8px 24px rgba(255, 255, 255, 0.35);
  transform: translateZ(0);
}

.hair {
  position: absolute;
  top: 2%;
  left: 6%;
  right: 6%;
  height: 28%;
  background: linear-gradient(180deg, #2c2420 0%, #1a1512 100%);
  border-radius: 50% 50% 30% 30% / 60% 60% 40% 40%;
  box-shadow: inset 0 -8px 16px rgba(255, 255, 255, 0.06);
  z-index: 2;
}

.face-inner {
  position: absolute;
  inset: 22% 14% 12%;
  z-index: 1;
}

.brow {
  position: absolute;
  top: 0;
  width: 26%;
  height: 8px;
  background: #3d3530;
  border-radius: 40% 60% 50% 50%;
  opacity: 0.92;
  transition: transform 0.08s ease-out;
}

.brow.left {
  left: 8%;
  transform: rotate(-6deg);
}

.brow.right {
  right: 8%;
  transform: rotate(6deg);
}

.eye {
  position: absolute;
  top: 14%;
  width: 22%;
  height: 14%;
  background: #fff;
  border-radius: 50%;
  box-shadow: inset 0 -2px 6px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.eye.left {
  left: 12%;
}

.eye.right {
  right: 12%;
}

.eyelid {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 0%;
  background: var(--skin);
  border-radius: 50% 50% 0 0;
  z-index: 2;
  transition: height 0.05s linear;
}

.pupil {
  position: absolute;
  top: 28%;
  width: 38%;
  height: 46%;
  left: 31%;
  background: radial-gradient(circle at 35% 35%, #6b8cae 0%, #2c3d52 55%, #0f141c 100%);
  border-radius: 50%;
  transition: transform 0.15s ease-out;
  box-shadow: inset -1px -2px 4px rgba(0, 0, 0, 0.35);
}

.pupil::after {
  content: "";
  position: absolute;
  top: 14%;
  left: 18%;
  width: 32%;
  height: 32%;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 50%;
}

.nose {
  position: absolute;
  top: 38%;
  left: 42%;
  width: 16%;
  height: 18%;
  border-radius: 40% 40% 50% 50%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(0, 0, 0, 0.06) 50%,
    transparent 100%
  );
  box-shadow: inset -4px 4px 8px rgba(0, 0, 0, 0.07);
}

.mouth-wrap {
  position: absolute;
  bottom: 12%;
  left: 28%;
  width: 44%;
  height: 14%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.mouth {
  width: 72%;
  height: var(--mouth-h, 28%);
  min-height: 4px;
  background: var(--mouth-inner);
  border-radius: 50% / 40%;
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.35),
    0 1px 0 rgba(255, 255, 255, 0.15);
  transform-origin: center top;
  transition: height 0.03s linear, border-radius 0.05s ease;
}

.mouth.speaking {
  border-radius: 45% 45% 50% 50% / 30% 30% 70% 70%;
}

.cheek {
  position: absolute;
  top: 52%;
  width: 18%;
  height: 10%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 120, 100, 0.35) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.cheek.left {
  left: 4%;
}

.cheek.right {
  right: 4%;
}

.cheek.glow {
  opacity: 1;
}

.subtle-ring {
  position: absolute;
  inset: -4%;
  border-radius: 50%;
  border: 1px solid rgba(126, 184, 218, 0.12);
  pointer-events: none;
}

.chat-panel {
  width: min(100%, 440px);
  background: rgba(26, 30, 42, 0.65);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  padding: 1rem 1.1rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.log {
  max-height: 160px;
  overflow-y: auto;
  font-size: 0.88rem;
  line-height: 1.45;
  margin-bottom: 0.85rem;
  padding-right: 4px;
}

.log .msg {
  margin-bottom: 0.55rem;
}

.log .role {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.log .you .role {
  color: #c4a5e8;
}

.row {
  display: flex;
  gap: 0.5rem;
}

input[type="text"] {
  flex: 1;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(13, 15, 20, 0.8);
  color: var(--text);
  font: inherit;
}

input[type="text"]:focus {
  outline: none;
  border-color: rgba(126, 184, 218, 0.45);
}

button {
  padding: 0.65rem 1.1rem;
  border: none;
  border-radius: 12px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: linear-gradient(135deg, #5a8fb8 0%, #3d6a94 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(61, 106, 148, 0.45);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.status {
  margin-top: 0.65rem;
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 1.2em;
}

.status.error {
  color: #e8a0a0;
}

@media (prefers-reduced-motion: reduce) {
  .stage {
    transition: none;
  }

  .mouth {
    transition: none;
  }
}
