body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top, rgba(42, 93, 255, 0.16), transparent 36%),
    radial-gradient(circle at right, rgba(15, 173, 129, 0.12), transparent 28%),
    linear-gradient(180deg, #091018 0%, #111827 46%, #0b1018 100%);
  color: #f2f2f2;
}

.wrap {
  max-width: 1120px;
  margin: 24px auto;
  padding: 0 16px;
}

.stage-box {
  width: 100%;
  border: 1px solid rgba(116, 139, 166, 0.22);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(18, 25, 36, 0.94), rgba(12, 18, 28, 0.96));
  overflow: hidden;
  padding: 18px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.32);
}

.stage-copy {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.stage-copy strong {
  font-size: 20px;
  letter-spacing: 0.01em;
}

.stage-copy span {
  font-size: 13px;
  color: #7dd3fc;
}

.stage-toolbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 12px;
  align-items: center;
}

.stage-toolbar input[type="text"] {
  min-width: 0;
  background: rgba(10, 15, 24, 0.78);
  color: #e5eef8;
  border: 1px solid rgba(112, 146, 190, 0.3);
  border-radius: 12px;
  padding: 10px 12px;
}

.stage-toolbar input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 999px;
  border: 1px solid rgba(102, 199, 255, 0.28);
  background: rgba(9, 60, 86, 0.32);
  color: #d7f2ff;
  padding: 0 16px;
  cursor: pointer;
  white-space: nowrap;
}

.canvas-shell {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 18px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 28%, rgba(148, 196, 255, 0.18), transparent 24%),
    linear-gradient(180deg, #152235 0%, #0c131d 52%, #0a1017 100%);
  border: 1px solid rgba(95, 128, 160, 0.18);
}

#avatarCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.canvas-overlay {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  pointer-events: none;
}

.overlay-card {
  border: 1px solid rgba(144, 170, 197, 0.18);
  background: rgba(7, 11, 18, 0.68);
  backdrop-filter: blur(10px);
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.overlay-card span {
  color: #8ea6c3;
  font-size: 12px;
}

.overlay-card strong {
  font-size: 14px;
}

.stage-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.stage-metrics div {
  border: 1px solid rgba(52, 72, 96, 0.7);
  border-radius: 14px;
  background: rgba(14, 22, 33, 0.7);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stage-metrics span {
  color: #94a3b8;
  font-size: 12px;
}

.stage-metrics strong {
  font-size: 16px;
}

#animationPreview {
  flex: 1;
  min-height: 180px;
  max-height: 260px;
}

.actions {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-box {
  margin-top: 12px;
  display: flex;
  gap: 8px;
}

.chat-box input {
  flex: 1;
  background: rgba(13, 19, 29, 0.9);
  color: #f3f4f6;
  border: 1px solid #374151;
  border-radius: 12px;
  padding: 10px;
}

.messages {
  margin-top: 14px;
  min-height: 180px;
  max-height: 360px;
  overflow: auto;
  border: 1px solid #1f2937;
  border-radius: 16px;
  padding: 10px;
  background: rgba(10, 18, 32, 0.82);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.diag {
  margin-top: 12px;
  border: 1px solid #1f2937;
  border-radius: 16px;
  background: rgba(8, 13, 18, 0.78);
  padding: 10px;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.diag-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #d1d5db;
  font-size: 13px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
  background: #4b5563;
  box-shadow: 0 0 0 1px #374151 inset;
}

.dot.ok {
  background: #22c55e;
  box-shadow: 0 0 0 1px #166534 inset;
}

.dot.warn {
  background: #f59e0b;
  box-shadow: 0 0 0 1px #92400e inset;
}

.dot.bad {
  background: #ef4444;
  box-shadow: 0 0 0 1px #991b1b inset;
}

.msg {
  max-width: 80%;
  padding: 8px 10px;
  border-radius: 10px;
  line-height: 1.4;
  white-space: pre-wrap;
}

.msg-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
}

.msg.ai {
  align-self: flex-start;
  background: linear-gradient(135deg, #334155, #475569);
}

.panel {
  margin-top: 14px;
}

.metrics {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 8px;
}

.metric {
  border: 1px solid #1f2937;
  background: rgba(8, 13, 18, 0.78);
  border-radius: 14px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric span {
  color: #9ca3af;
  font-size: 12px;
}

.metric strong {
  font-size: 14px;
}

.panel h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: #9ca3af;
}

button {
  background: linear-gradient(135deg, #2563eb, #0891b2);
  color: white;
  border: 0;
  border-radius: 12px;
  padding: 8px 12px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.badge {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.badge.neutral {
  background: #111827;
  border-color: #374151;
  color: #d1d5db;
}

.badge.ok {
  background: #052e16;
  border-color: #166534;
  color: #86efac;
}

.badge.warn {
  background: #3f1d0a;
  border-color: #92400e;
  color: #fdba74;
}

.msg.system {
  align-self: center;
  background: #1f2937;
  color: #d1d5db;
  font-size: 12px;
}

.msg-time {
  font-size: 11px;
  color: #9ca3af;
}

.msg-time.user {
  align-self: flex-end;
}

.msg-time.ai {
  align-self: flex-start;
}

.msg-time.system {
  align-self: center;
}

pre {
  margin-top: 0;
  background: rgba(8, 13, 18, 0.84);
  border: 1px solid #222;
  border-radius: 14px;
  padding: 12px;
  overflow: auto;
}

audio {
  display: none;
}

@media (max-width: 720px) {
  .metrics {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .stage-toolbar {
    grid-template-columns: 1fr;
  }

  .stage-metrics {
    grid-template-columns: 1fr;
  }

  .canvas-overlay {
    grid-template-columns: 1fr;
  }
}
