:root {
  --bg-top: #e8fbff;
  --bg-bottom: #fff4d8;
  --text: #152238;
  --muted: #526174;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-border: rgba(21, 34, 56, 0.12);
  --shadow: 0 24px 60px rgba(35, 60, 95, 0.18);
  --accent: #17bebb;
  --accent-strong: #0b9292;
  --warm: #ffb703;
  --heart: #ff4f8b;
  --danger: #ff5a5f;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: "Nunito", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 20% 12%, rgba(23, 190, 187, 0.26), transparent 34%),
    radial-gradient(circle at 86% 18%, rgba(255, 183, 3, 0.30), transparent 28%),
    linear-gradient(160deg, var(--bg-top), var(--bg-bottom));
}

button {
  font: inherit;
}

.robot-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
  overflow: hidden;
}

.robot-stage {
  width: min(100%, 520px);
  margin: 0 auto;
  display: grid;
  gap: 14px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 800;
}

.brand-row p {
  margin: 0;
}

.brand-dot {
  width: 13px;
  height: 13px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 7px rgba(23, 190, 187, 0.16);
}

.robot-card {
  position: relative;
  min-height: calc(100vh - 226px);
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 22px;
  padding: 26px 18px 24px;
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.energy-field {
  position: absolute;
  inset: 10px;
  pointer-events: none;
}

.energy-field span {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--accent);
  opacity: 0.6;
}

.energy-field span:nth-child(1) {
  top: 13%;
  left: 16%;
}

.energy-field span:nth-child(2) {
  top: 24%;
  right: 13%;
  background: var(--warm);
}

.energy-field span:nth-child(3) {
  right: 18%;
  bottom: 19%;
  background: var(--heart);
}

.robot-avatar {
  position: relative;
  width: min(68vw, 245px);
  min-width: 190px;
  aspect-ratio: 1 / 1.18;
  display: grid;
  justify-items: center;
  align-content: end;
  animation: idleFloat 4s ease-in-out infinite;
}

.antenna {
  position: absolute;
  top: 0;
  width: 8px;
  height: 36px;
  border-radius: 999px;
  background: #39536f;
}

.antenna::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -13px;
  width: 26px;
  height: 26px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: var(--warm);
  box-shadow: 0 0 0 8px rgba(255, 183, 3, 0.18);
}

.robot-head {
  position: relative;
  z-index: 2;
  width: 82%;
  aspect-ratio: 1.22 / 1;
  border: 5px solid #39536f;
  border-radius: 34px;
  background: linear-gradient(145deg, #ffffff, #dff8ff);
  box-shadow: inset 0 -12px 0 rgba(23, 190, 187, 0.10), 0 18px 28px rgba(35, 60, 95, 0.16);
}

.robot-face {
  position: absolute;
  inset: 22% 15%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  justify-items: center;
  align-items: center;
}

.eye {
  width: clamp(24px, 9vw, 38px);
  height: clamp(24px, 9vw, 38px);
  border-radius: 999px;
  background: var(--accent-strong);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.16);
}

.mouth {
  grid-column: 1 / -1;
  width: 54px;
  height: 20px;
  margin-top: 18px;
  border: 5px solid var(--accent-strong);
  border-top: 0;
  border-radius: 0 0 999px 999px;
}

.cheek {
  position: absolute;
  bottom: 23%;
  width: 18px;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 79, 139, 0.28);
}

.cheek-left {
  left: 13%;
}

.cheek-right {
  right: 13%;
}

.robot-body {
  position: relative;
  width: 62%;
  height: 76px;
  margin-top: -8px;
  border: 5px solid #39536f;
  border-radius: 26px 26px 32px 32px;
  background: linear-gradient(145deg, #fefefe, #d7f5ff);
  box-shadow: 0 20px 30px rgba(35, 60, 95, 0.13);
}

.heart-core {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 30px;
  height: 30px;
  transform: translate(-50%, -50%) rotate(45deg);
  background: var(--heart);
  border-radius: 8px 8px 4px 8px;
  box-shadow: 0 0 0 8px rgba(255, 79, 139, 0.14);
}

.heart-core::before,
.heart-core::after {
  content: "";
  position: absolute;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: var(--heart);
}

.heart-core::before {
  left: -15px;
}

.heart-core::after {
  top: -15px;
}

.state-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  display: grid;
  justify-items: center;
  gap: 6px;
  text-align: center;
}

h1 {
  margin: 0;
  font-family: "Baloo 2", "Nunito", sans-serif;
  font-size: clamp(4rem, 22vw, 7rem);
  line-height: 0.86;
  letter-spacing: 0;
  color: #183654;
}

.state-kicker {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 900;
  text-transform: uppercase;
}

.state-label {
  width: 100%;
  min-height: 60px;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 10px 14px;
  color: #ffffff;
  font-size: clamp(1.65rem, 8vw, 2.55rem);
  font-weight: 900;
  line-height: 1.04;
  border-radius: 24px;
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  box-shadow: 0 14px 30px rgba(11, 146, 146, 0.25);
}

.signal-bars {
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 7px;
  min-height: 34px;
  margin-top: 6px;
}

.signal-bars span {
  width: 11px;
  height: 14px;
  border-radius: 999px;
  background: var(--accent);
  opacity: 0.86;
  animation: signalPulse 1.2s ease-in-out infinite;
}

.signal-bars span:nth-child(2) {
  height: 23px;
  animation-delay: 0.12s;
}

.signal-bars span:nth-child(3) {
  height: 30px;
  animation-delay: 0.24s;
}

.signal-bars span:nth-child(4) {
  height: 19px;
  animation-delay: 0.36s;
}

.dev-controls {
  width: min(100%, 520px);
  margin: 0 auto;
  padding: 14px;
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.70);
  backdrop-filter: blur(14px);
}

.dev-controls h2 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
  text-transform: uppercase;
}

.state-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.state-button {
  min-height: 44px;
  padding: 9px 8px;
  border: 2px solid rgba(21, 34, 56, 0.12);
  border-radius: 16px;
  color: var(--text);
  background: #ffffff;
  font-weight: 900;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.state-button:active {
  transform: scale(0.97);
}

.state-button.active {
  color: #ffffff;
  border-color: transparent;
  background: var(--accent-strong);
}

.robot-shell[data-state="LISTENING"] {
  --accent: #00c2ff;
  --accent-strong: #087fc0;
}

.robot-shell[data-state="LISTENING"] .robot-avatar {
  animation: listenFloat 1.45s ease-in-out infinite;
}

.robot-shell[data-state="LISTENING"] .energy-field span {
  animation: orbitBlink 1.1s ease-in-out infinite;
}

.robot-shell[data-state="THINKING"] {
  --accent: #9b5cff;
  --accent-strong: #6c3bd5;
}

.robot-shell[data-state="THINKING"] .antenna::before {
  animation: thinkingGlow 1.15s ease-in-out infinite;
}

.robot-shell[data-state="THINKING"] .eye {
  animation: blink 1.55s ease-in-out infinite;
}

.robot-shell[data-state="SPEAKING"] {
  --accent: #ff8a00;
  --accent-strong: #df6400;
}

.robot-shell[data-state="SPEAKING"] .mouth {
  height: 28px;
  animation: talk 0.52s ease-in-out infinite;
}

.robot-shell[data-state="SPEAKING"] .signal-bars span {
  animation-duration: 0.54s;
}

.robot-shell[data-state="PAUSED"] {
  --accent: #7c8a99;
  --accent-strong: #5b6875;
}

.robot-shell[data-state="PAUSED"] .robot-avatar,
.robot-shell[data-state="PAUSED"] .signal-bars span {
  animation-play-state: paused;
}

.robot-shell[data-state="PAUSED"] .eye {
  height: 9px;
  border-radius: 999px;
}

.robot-shell[data-state="ERROR"] {
  --accent: #ff5a5f;
  --accent-strong: #cf3038;
  --bg-top: #fff1f1;
  --bg-bottom: #ffe8c7;
}

.robot-shell[data-state="ERROR"] .robot-avatar {
  animation: errorShake 0.55s ease-in-out infinite;
}

.robot-shell[data-state="ERROR"] .mouth {
  width: 42px;
  height: 18px;
  border-top: 5px solid var(--accent-strong);
  border-bottom: 0;
  border-radius: 999px 999px 0 0;
}

.robot-shell[data-state="ERROR"] .heart-core {
  background: var(--danger);
}

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

@keyframes listenFloat {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-10px) scale(1.025); }
}

@keyframes signalPulse {
  0%, 100% { transform: scaleY(0.62); opacity: 0.55; }
  50% { transform: scaleY(1); opacity: 1; }
}

@keyframes orbitBlink {
  0%, 100% { transform: scale(0.8); opacity: 0.35; }
  50% { transform: scale(1.7); opacity: 0.9; }
}

@keyframes thinkingGlow {
  0%, 100% { box-shadow: 0 0 0 8px rgba(155, 92, 255, 0.16); }
  50% { box-shadow: 0 0 0 18px rgba(155, 92, 255, 0.07); }
}

@keyframes blink {
  0%, 72%, 100% { transform: scaleY(1); }
  80% { transform: scaleY(0.18); }
}

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

@keyframes errorShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

@media (min-width: 620px) {
  .robot-shell {
    justify-content: center;
    padding: 28px;
  }

  .robot-card {
    min-height: 610px;
    padding: 34px 32px;
  }

  .state-buttons {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-height: 700px) {
  .robot-card {
    min-height: auto;
    padding-top: 18px;
    padding-bottom: 18px;
    gap: 12px;
  }

  .robot-avatar {
    width: min(54vw, 190px);
    min-width: 150px;
  }

  .state-label {
    min-height: 52px;
  }
}

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

.microphone-status {
  min-height: 22px;
  margin: 2px 0 0;
  padding: 5px 10px;
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.74);
  font-size: 0.82rem;
  font-weight: 800;
}

.microphone-status::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 999px;
  background: var(--warm);
  vertical-align: 1px;
}

.microphone-status[data-status="active"]::before {
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(23, 190, 187, 0.14);
}

.microphone-status[data-status="error"]::before {
  background: var(--danger);
  box-shadow: 0 0 0 5px rgba(255, 90, 95, 0.13);
}

.backend-status {
  min-height: 22px;
  margin: 2px 0 0;
  padding: 5px 10px;
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.74);
  font-size: 0.82rem;
  font-weight: 800;
}

.backend-status::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 999px;
  background: var(--warm);
  vertical-align: 1px;
}

.backend-status[data-status="connected"]::before {
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(23, 190, 187, 0.14);
}

.backend-status[data-status="disconnected"]::before {
  background: var(--danger);
  box-shadow: 0 0 0 5px rgba(255, 90, 95, 0.13);
}

.ai-test-button {
  grid-column: 1 / -1;
}

.ai-connection-status {
  min-height: 22px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
}

.ai-connection-status[data-status="ready"] {
  color: var(--accent-strong);
}

.ai-connection-status[data-status="error"] {
  color: var(--danger);
}

.session-code-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  min-height: 36px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  color: #21406b;
  font-size: 0.95rem;
  font-weight: 800;
  box-shadow: inset 0 0 0 1px rgba(64, 113, 196, 0.14);
}

.session-code-status[data-status="ready"] {
  color: #0e6a51;
}

.session-code-status[data-status="error"] {
  color: #a53535;
}
