:root {
  color-scheme: light;
  --bg: #f6eadc;
  --bg-soft: #efe0cf;
  --card: rgba(255, 250, 245, 0.82);
  --card-border: rgba(123, 87, 58, 0.12);
  --text: #402d22;
  --muted: #7a6657;
  --accent: #c77c59;
  --accent-strong: #a65c3f;
  --shadow: 0 24px 80px rgba(99, 67, 44, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top, rgba(255, 239, 214, 0.92), transparent 32%),
    linear-gradient(180deg, #fbf2e7 0%, var(--bg) 42%, var(--bg-soft) 100%);
  color: var(--text);
}

.shell {
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
  display: grid;
  gap: 20px;
}

.stage-card,
.controls-card,
.log-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.stage-card {
  padding: 20px;
}

.stage-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.stage-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

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

h1,
h2 {
  margin: 0;
}

.badge {
  border: 1px solid rgba(166, 92, 63, 0.24);
  color: var(--accent-strong);
  background: rgba(255, 247, 240, 0.74);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
}

.avatar-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid rgba(146, 107, 75, 0.18);
  background:
    radial-gradient(circle at 24% 18%, rgba(255, 246, 228, 0.95), transparent 18%),
    radial-gradient(circle at 76% 22%, rgba(255, 239, 212, 0.78), transparent 16%),
    linear-gradient(180deg, #fbf1e5 0%, #f2dfcb 36%, #dfc0a3 62%, #b98358 62%, #9c6846 100%);
}

.avatar-stage::before,
.avatar-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.avatar-stage::before {
  background:
    linear-gradient(90deg, transparent 0 16%, rgba(122, 82, 52, 0.16) 16% 16.8%, transparent 16.8% 83.2%, rgba(122, 82, 52, 0.16) 83.2% 84%, transparent 84%),
    linear-gradient(180deg, transparent 0 14%, rgba(255, 249, 239, 0.48) 14% 33%, transparent 33% 100%),
    linear-gradient(180deg, transparent 0 58%, rgba(108, 74, 49, 0.18) 58% 60%, transparent 60% 100%),
    radial-gradient(circle at 18% 24%, rgba(255, 252, 246, 0.45), transparent 10%),
    radial-gradient(circle at 84% 26%, rgba(255, 249, 242, 0.34), transparent 9%);
  opacity: 0.78;
}

.avatar-stage::after {
  background:
    radial-gradient(circle at 10% 84%, rgba(86, 119, 88, 0.26), transparent 18%),
    radial-gradient(circle at 88% 80%, rgba(122, 81, 53, 0.22), transparent 16%),
    radial-gradient(circle at 50% 70%, rgba(255, 214, 170, 0.18), transparent 22%);
  filter: blur(24px);
  opacity: 0.9;
}

.avatar-bg-glow {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 28%, rgba(255, 236, 202, 0.30), transparent 22%),
    radial-gradient(circle at 24% 24%, rgba(255, 251, 244, 0.22), transparent 14%),
    radial-gradient(circle at 80% 22%, rgba(255, 247, 232, 0.18), transparent 12%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 38%);
  pointer-events: none;
}

.avatar-shell {
  --float-y: 0px;
  --talk-scale: 1;
  --head-rotate: 0deg;
  --head-shift-x: 0px;
  --jaw-open: 0px;
  --blink: 0;
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px 24px 28px;
}

.assistant-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 160ms ease;
  z-index: 4;
  pointer-events: none;
  background: transparent;
}

.avatar-stage[data-video-renderer="livetalking"][data-video-active="1"] .assistant-video {
  opacity: 1;
}

.avatar-stage[data-video-renderer="livetalking"][data-video-active="1"] .avatar-shell {
  opacity: 0;
}

/* Broken synthetic blink overlay removed: it could drift over the painted eyes and create a fake extra-eye artifact. Reintroduce blinking only with dedicated eye-safe assets. */

.avatar-shell::after {
  content: "";
  position: absolute;
  bottom: 7%;
  width: min(44vw, 500px);
  height: 56px;
  background: radial-gradient(circle, rgba(99, 67, 44, 0.34), rgba(99, 67, 44, 0.06) 62%, transparent 74%);
  filter: blur(16px);
  transform: scaleX(1.18);
  pointer-events: none;
}

.avatar-stack {
  position: relative;
  width: min(50vw, 500px);
  max-width: 100%;
  aspect-ratio: 896 / 1200;
  overflow: visible;
  transform: none;
  z-index: 2;
}

.avatar-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 120ms linear, transform 220ms ease;
  transform-origin: 50% 86%;
  user-select: none;
  -webkit-user-drag: none;
}

.avatar-layer.is-base {
  z-index: 1;
}

.avatar-layer.is-active {
  opacity: 1;
}

.avatar-layer.is-mouth-viseme {
  z-index: 6;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 36ms linear, transform 36ms linear, filter 90ms ease;
  transform-origin: 50% 49.8%;
  clip-path: ellipse(13.8% 8.8% at 50% 49.9%);
  pointer-events: none;
  filter: saturate(1) brightness(1);
}

.avatar-layer.is-eye-expression,
.avatar-layer.is-blink-expression {
  opacity: 0;
  transition: opacity 80ms linear, transform 70ms linear, filter 120ms ease;
  transform-origin: 50% 31%;
  transform-box: fill-box;
  clip-path: ellipse(18% 10% at 50% 31%);
  pointer-events: none;
}

.avatar-layer.is-eye-expression {
  z-index: 7;
}

.avatar-layer.is-blink-expression {
  z-index: 8;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 14px;
}

.controls-card,
.log-card {
  padding: 20px;
}

.preview-lite-card {
  display: grid;
  gap: 18px;
}

.preview-advanced-fields,
.preview-hidden-action,
#debug-card,
.log-card,
.avatar-slider-grid,
.avatar-actions,
.compact-note {
  display: none !important;
}

.preview-primary-actions {
  margin-top: 0;
  justify-content: center;
}

.preview-primary-actions > #preview-lipsync {
  min-width: 220px;
}

.grid {
  display: grid;
  gap: 16px;
}

.two-up {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

input,
textarea,
select,
button {
  font: inherit;
}

input,
textarea,
select {
  width: 100%;
  border-radius: 14px;
  border: 1px solid rgba(146, 107, 75, 0.18);
  background: rgba(255, 248, 240, 0.92);
  color: var(--text);
  padding: 14px 16px;
}

input[type="range"] {
  padding: 0;
}

input[type="file"] {
  padding: 12px;
}

textarea {
  resize: vertical;
}

.avatar-manager {
  margin-top: 20px;
  padding: 18px;
  border-radius: 20px;
  background: rgba(255, 246, 236, 0.92);
  border: 1px solid rgba(199, 124, 89, 0.14);
}

.avatar-manager-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.avatar-slider-grid {
  margin-top: 14px;
}

.slider-value {
  font-size: 12px;
  color: var(--accent-strong);
}

.avatar-actions {
  margin-top: 14px;
}

.compact-note {
  margin-top: 12px;
}

.avatar-layer.is-flat-base {
  transform-origin: 50% 78%;
}

.avatar-layer.is-custom-mouth {
  z-index: 9;
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(60, 33, 20, 0.18));
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  background: linear-gradient(135deg, #d89068, #b86445);
  color: #fff9f4;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(184, 100, 69, 0.18);
}

button.secondary {
  background: rgba(255, 247, 238, 0.95);
  color: var(--text);
  border: 1px solid rgba(146, 107, 75, 0.16);
  box-shadow: none;
}

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

.note-box {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(255, 245, 235, 0.82);
  border: 1px solid rgba(199, 124, 89, 0.16);
  color: var(--muted);
}

#event-log,
#debug-status {
  margin: 12px 0 0;
  min-height: 180px;
  max-height: 300px;
  overflow: auto;
  padding: 16px;
  border-radius: 18px;
  background: rgba(98, 69, 49, 0.92);
  border: 1px solid rgba(146, 107, 75, 0.18);
  color: #f7ede3;
  white-space: pre-wrap;
}

.debug-card {
  display: grid;
  gap: 12px;
}

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

.bot-mode #controls-card,
.bot-mode #debug-card {
  display: none;
}

.bot-mode .shell {
  width: 100vw;
  min-height: 100vh;
  padding: 0;
}

.bot-mode body {
  background:
    radial-gradient(circle at top, rgba(255, 241, 221, 0.92), transparent 34%),
    linear-gradient(180deg, #fbf2e7 0%, #f2dfcb 44%, #e1c2a6 100%);
}

.bot-mode .stage-card {
  border-radius: 0;
  min-height: 100vh;
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
}

.bot-mode .stage-header,
.bot-mode .status-bar,
.bot-mode .log-card {
  display: none;
}

.bot-mode .avatar-stage {
  height: 100vh;
  aspect-ratio: auto;
  border-radius: 0;
  border: 0;
  background:
    radial-gradient(circle at 22% 18%, rgba(255, 247, 231, 0.94), transparent 18%),
    radial-gradient(circle at 78% 18%, rgba(255, 238, 210, 0.78), transparent 15%),
    linear-gradient(180deg, #fcf1e5 0%, #f0dcc8 34%, #e1c0a1 60%, #ba865e 60%, #9d6947 100%);
}

.bot-mode .avatar-shell {
  place-items: end center;
  padding: 0 56px 52px;
}

.bot-mode .avatar-stack {
  width: min(58vw, 620px, calc((100vh - 72px) * 0.7466667));
}

@media (max-width: 720px) {
  .shell {
    width: min(100vw - 20px, 1120px);
  }

  .two-up {
    grid-template-columns: 1fr;
  }

  .stage-header {
    flex-direction: column;
  }

}
