:root {
  --bg-top: #0b1024;
  --bg-mid: #192448;
  --card: rgba(9, 15, 33, 0.72);
  --card-border: rgba(255, 255, 255, 0.16);
  --text: #eef2ff;
  --muted: #b7c0e7;
  --accent: #ff8fab;
  --accent-2: #7dd3fc;
  --send: #fdba74;
  --recv: #bfdbfe;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Pretendard", "Noto Sans KR", sans-serif;
  color: var(--text);
  background: linear-gradient(165deg, var(--bg-top), var(--bg-mid));
  position: relative;
  overflow-x: hidden;
}

.backdrop {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 18% 24%, rgba(255, 143, 171, 0.26), transparent 34%),
    radial-gradient(circle at 82% 17%, rgba(125, 211, 252, 0.24), transparent 29%),
    radial-gradient(circle at 50% 100%, rgba(56, 189, 248, 0.15), transparent 45%);
  pointer-events: none;
}

.topbar {
  width: min(1100px, 94%);
  margin: 24px auto 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  position: relative;
  z-index: 1;
}

.kicker {
  margin: 0;
  color: var(--accent-2);
  font-size: 12px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

h1 {
  margin: 6px 0 0;
  font-size: clamp(1.7rem, 3vw, 2.4rem);
}

.status {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.layout {
  width: min(1100px, 94%);
  margin: 0 auto 28px;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 14px;
  position: relative;
  z-index: 1;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  backdrop-filter: blur(5px);
  box-shadow: 0 14px 36px rgba(2, 6, 23, 0.35);
}

.stage {
  padding: 16px;
}

.scene-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

#scene-label {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

.scene-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.scene-btn {
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

.stage-area {
  margin-top: 12px;
  border-radius: 14px;
  padding: 14px;
  min-height: 280px;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(15, 23, 52, 0.2), rgba(9, 14, 32, 0.9)),
    repeating-linear-gradient(120deg, rgba(255, 255, 255, 0.03) 0, rgba(255, 255, 255, 0.03) 1px, transparent 1px, transparent 18px);
}

.moon {
  position: absolute;
  top: 20px;
  right: 30px;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fff7d1, #d1d7ff);
  box-shadow: 0 0 30px rgba(254, 240, 138, 0.45);
}

.avatar-wrap {
  --x: 48%;
  position: absolute;
  left: var(--x);
  bottom: 14px;
  transform: translateX(-50%);
  transition: left 0.4s ease;
}

.avatar {
  width: 158px;
  height: 210px;
  position: relative;
  transform-origin: bottom center;
  animation: idle 2.5s ease-in-out infinite;
}

.hair {
  position: absolute;
  inset: 6px 12px 34px;
  border-radius: 48% 48% 40% 40%;
  background: linear-gradient(155deg, #5b5fae, #2c2f67);
  box-shadow: inset 0 8px 20px rgba(255, 255, 255, 0.15);
}

.bang {
  position: absolute;
  top: 38px;
  height: 44px;
  background: linear-gradient(165deg, #7678d7, #41458e);
  border-radius: 42% 42% 58% 58%;
}

.bang-left {
  left: 28px;
  width: 34px;
  transform: rotate(16deg);
}

.bang-mid {
  left: 50%;
  width: 40px;
  transform: translateX(-50%);
}

.bang-right {
  right: 28px;
  width: 34px;
  transform: rotate(-16deg);
}

.ribbon {
  position: absolute;
  top: 54px;
  width: 20px;
  height: 20px;
  background: linear-gradient(140deg, #ff7fb8, #ec4899);
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(255, 127, 184, 0.45);
}

.ribbon-left {
  left: 14px;
  transform: rotate(-28deg);
}

.ribbon-right {
  right: 14px;
  transform: rotate(28deg);
}

.face {
  position: absolute;
  inset: 52px 30px 56px;
  background: linear-gradient(180deg, #ffe6da, #ffd8ca);
  border-radius: 44% 44% 50% 50%;
  box-shadow: inset 0 -4px 12px rgba(255, 181, 163, 0.5);
}

.blush {
  position: absolute;
  top: 56%;
  width: 16px;
  height: 8px;
  border-radius: 999px;
  background: rgba(251, 113, 133, 0.45);
  filter: blur(0.3px);
}

.blush.left {
  left: 14%;
}

.blush.right {
  right: 14%;
}

.eye {
  position: absolute;
  width: 22px;
  height: 30px;
  top: 33%;
  border-radius: 50% 50% 46% 46%;
  background: #fff;
  border: 2px solid #263252;
  overflow: hidden;
  transition: transform 0.2s ease, height 0.2s ease;
}

.eye.left {
  left: 23%;
}

.eye.right {
  right: 23%;
}

.eye::before {
  content: "";
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  height: 9px;
  background: #263252;
  border-radius: 9px;
}

.iris {
  position: absolute;
  left: 50%;
  bottom: 2px;
  width: 15px;
  height: 18px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 32%, #f5f3ff 0 2px, #9f7aea 3px, #6d28d9 60%, #312e81 100%);
}

.spark {
  position: absolute;
  top: 9px;
  left: 50%;
  width: 8px;
  height: 8px;
  transform: translateX(-50%) rotate(45deg);
  background: rgba(255, 255, 255, 0.95);
  clip-path: polygon(50% 0%, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0% 50%, 38% 38%);
}

.mouth {
  position: absolute;
  width: 20px;
  height: 9px;
  border-bottom: 3px solid #d94675;
  border-radius: 0 0 20px 20px;
  left: 50%;
  top: 72%;
  transform: translateX(-50%);
  transition: all 0.2s ease;
}

.name-tag {
  margin: 4px 0 0;
  text-align: center;
  font-weight: 700;
  color: #fda4af;
}

.speech-bubble {
  position: absolute;
  left: 12px;
  top: 14px;
  max-width: min(72%, 420px);
  background: rgba(9, 14, 30, 0.85);
  border: 1px solid rgba(191, 219, 254, 0.4);
  border-radius: 12px;
  padding: 10px 12px;
  line-height: 1.45;
}

.config-panel {
  margin-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  padding-top: 14px;
}

h2 {
  margin: 0 0 10px;
  font-size: 1.1rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

input, button {
  font: inherit;
}

input[type="text"],
input[type="url"],
input[type="password"] {
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(4, 8, 20, 0.6);
  border-radius: 10px;
  color: var(--text);
  padding: 10px;
}

select {
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(4, 8, 20, 0.6);
  border-radius: 10px;
  color: var(--text);
  padding: 8px 10px;
}

.config-actions {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.chat-form button {
  border: 0;
  border-radius: 10px;
  background: linear-gradient(120deg, var(--accent), #fb7185);
  color: #140b16;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

.voice-toggle {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.voice-style {
  min-width: 140px;
}

.notice {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.engine-name {
  margin: 0;
  color: var(--accent-2);
  font-size: 13px;
  font-weight: 700;
}

.chat {
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-height: 640px;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 12px;
  background: rgba(2, 6, 23, 0.45);
}

.msg {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg .who {
  font-size: 12px;
  color: var(--muted);
}

.msg .text {
  display: inline-block;
  max-width: 92%;
  padding: 9px 11px;
  border-radius: 12px;
  line-height: 1.5;
  word-break: break-word;
}

.msg.user {
  align-items: flex-end;
}

.msg.user .text {
  background: rgba(251, 191, 36, 0.18);
  border: 1px solid rgba(251, 191, 36, 0.3);
  color: var(--send);
}

.msg.assistant .text {
  background: rgba(191, 219, 254, 0.15);
  border: 1px solid rgba(191, 219, 254, 0.3);
  color: var(--recv);
}

.chat-form {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.chat-form input {
  border-radius: 10px;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.mood-happy .mouth {
  width: 24px;
  height: 11px;
  border-bottom-width: 4px;
}

.mood-happy .eye {
  transform: scaleY(0.9);
}

.mood-sad .mouth {
  border-bottom: 0;
  border-top: 3px solid #7f1d1d;
  top: 74%;
}

.mood-sad .eye {
  transform: translateY(1px) scaleY(0.93);
}

.mood-surprised .mouth {
  width: 11px;
  height: 11px;
  border: 3px solid #d94675;
  border-radius: 50%;
  top: 70%;
}

.mood-thinking .eye.left {
  transform: translateX(-2px);
}

.mood-thinking .eye.right {
  transform: translateX(2px);
}

.mood-shy .face::after {
  content: "";
  position: absolute;
  left: 15%;
  right: 15%;
  top: 62%;
  height: 7px;
  background: radial-gradient(circle at 10% 50%, rgba(251, 113, 133, 0.7), transparent 45%),
              radial-gradient(circle at 90% 50%, rgba(251, 113, 133, 0.7), transparent 45%);
}

@keyframes idle {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-4px) rotate(-1deg); }
}

.avatar-wrap.excite .avatar {
  animation: jump 0.45s ease;
}

@keyframes jump {
  0% { transform: translateY(0); }
  45% { transform: translateY(-18px) rotate(-2deg); }
  100% { transform: translateY(0); }
}

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

  .chat {
    min-height: 420px;
  }
}
