:root {
  --bg: #09121a;
  --panel: rgba(10, 19, 30, 0.82);
  --panel-border: rgba(154, 200, 255, 0.14);
  --text: #eef6ff;
  --muted: #9eb5ca;
  --accent: #8ff0d2;
  --accent-strong: #ffd36f;
  --danger: #ff8f8f;
  --surface: rgba(255, 255, 255, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 211, 111, 0.16), transparent 28%),
    radial-gradient(circle at bottom right, rgba(143, 240, 210, 0.12), transparent 26%),
    linear-gradient(180deg, #071018 0%, #09121a 100%);
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(440px, 1.25fr) minmax(360px, 0.95fr);
  gap: 22px;
  padding: 22px;
}

.stage-panel,
.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(20px);
  border-radius: 26px;
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.28);
}

.stage-panel {
  padding: 20px;
  display: flex;
  flex-direction: column;
}

.stage-header,
.actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stage-header {
  justify-content: space-between;
  margin-bottom: 18px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--muted);
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.08em;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 12px;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 42px);
  letter-spacing: 0.04em;
}

.subtitle,
.chat-help,
.note {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.stage-frame {
  position: relative;
  flex: 1;
  border-radius: 22px;
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(255, 211, 111, 0.22), transparent 32%),
    linear-gradient(180deg, rgba(16, 31, 48, 0.9), rgba(6, 13, 20, 0.98));
  min-height: 520px;
}

#avatar-canvas {
  width: 100%;
  height: 100%;
}

.orb {
  position: absolute;
  right: 30px;
  top: 28px;
  width: 120px;
  height: 120px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(143, 240, 210, 0.36), rgba(143, 240, 210, 0.04) 70%, transparent 72%);
  filter: blur(4px);
  pointer-events: none;
}

.status-bubble {
  position: absolute;
  left: 24px;
  bottom: 24px;
  max-width: 65%;
  padding: 14px 18px;
  border-radius: 18px;
  background: rgba(7, 17, 26, 0.92);
  border: 1px solid rgba(255, 211, 111, 0.18);
  color: var(--text);
  line-height: 1.45;
  transition: transform 180ms ease, opacity 180ms ease, border-color 180ms ease;
}

.speaker-tag {
  position: absolute;
  left: 24px;
  bottom: 112px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(143, 240, 210, 0.14);
  border: 1px solid rgba(143, 240, 210, 0.22);
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  padding: 18px;
}

.field {
  display: grid;
  gap: 10px;
}

.field span {
  color: var(--muted);
}

input,
textarea,
button,
select {
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font: inherit;
}

textarea {
  width: 100%;
  padding: 12px 14px;
  resize: vertical;
  min-height: 96px;
}

select {
  width: 100%;
  padding: 12px 14px;
}

button {
  padding: 12px 14px;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

button:hover {
  transform: translateY(-1px);
  background: rgba(143, 240, 210, 0.1);
  border-color: rgba(143, 240, 210, 0.3);
}

button.primary {
  background: linear-gradient(135deg, rgba(255, 211, 111, 0.2), rgba(143, 240, 210, 0.16));
  border-color: rgba(255, 211, 111, 0.26);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.actions {
  margin-top: 16px;
  flex-wrap: wrap;
}

.status-line {
  margin: 8px 0;
  font-size: 18px;
}

.status-help {
  margin: 0;
  color: var(--muted);
}

.log {
  max-height: 360px;
  overflow: auto;
  display: grid;
  gap: 10px;
}

.chat-card {
  display: grid;
  gap: 14px;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-history {
  max-height: 320px;
  overflow: auto;
  display: grid;
  gap: 10px;
  padding-right: 4px;
}

.chat-message {
  padding: 12px 14px;
  border-radius: 18px;
  line-height: 1.45;
}

.chat-message.user {
  background: rgba(255, 211, 111, 0.12);
  justify-self: end;
  max-width: 90%;
}

.chat-message.assistant {
  background: rgba(143, 240, 210, 0.1);
  justify-self: start;
  max-width: 92%;
}

.memory {
  display: grid;
  gap: 10px;
}

.log-entry {
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--surface);
}

.memory-entry {
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--surface);
  color: var(--muted);
}

.log-entry strong {
  color: var(--accent-strong);
}

body.state-listening .stage-frame {
  box-shadow: inset 0 0 0 2px rgba(143, 240, 210, 0.45);
}

body.state-listening .status-bubble {
  border-color: rgba(143, 240, 210, 0.4);
  transform: translateY(-4px);
}

body.state-thinking .stage-frame {
  box-shadow: inset 0 0 0 2px rgba(255, 211, 111, 0.45);
}

body.state-thinking .status-bubble {
  border-color: rgba(255, 211, 111, 0.42);
}

body.state-speaking .stage-frame {
  box-shadow: inset 0 0 0 2px rgba(143, 240, 210, 0.45);
}

body.state-speaking .status-bubble {
  border-color: rgba(143, 240, 210, 0.44);
  transform: translateY(-6px);
}

body.state-error .stage-frame {
  box-shadow: inset 0 0 0 2px rgba(255, 143, 143, 0.45);
}

body.state-error .status-bubble {
  border-color: rgba(255, 143, 143, 0.44);
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .stage-frame {
    min-height: 420px;
  }

  .status-bubble {
    max-width: calc(100% - 48px);
  }
}
