:root {
  --bg: #0a0604;
  --bg-panel: #14100c;
  --red: #8a0303;
  --red-bright: #b3121b;
  --ember: #ff6a00;
  --ember-light: #ffae42;
  --parchment: #e8d8b0;
  --parchment-dim: #b8a888;
  --border: #2a1a14;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--parchment);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  height: 100%;
}

body {
  background:
    radial-gradient(ellipse at 50% 20%, rgba(138, 3, 3, 0.18), transparent 60%),
    var(--bg);
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 4px 6px;
}

.brand {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.3rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ember-light);
  text-shadow: 0 0 18px rgba(255, 106, 0, 0.35);
}

.lang-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--parchment-dim);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  cursor: pointer;
}
.lang-toggle:hover { border-color: var(--ember); color: var(--ember-light); }

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 8px;
  min-height: 0;
}

.avatar-wrap {
  position: relative;
  width: min(78vw, 340px);
  aspect-ratio: 400 / 460;
  margin: 4px auto 0;
}

#ember-canvas {
  position: absolute;
  inset: -20%;
  width: 140%;
  height: 140%;
  pointer-events: none;
}

#lucifer-svg {
  position: relative;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0 30px rgba(179, 18, 27, 0.35));
}

.wing {
  transform-origin: 200px 220px;
  animation: wing-sway 6s ease-in-out infinite;
}
#wing-right { animation-delay: -3s; }

@keyframes wing-sway {
  0%, 100% { transform: rotate(-2deg); }
  50% { transform: rotate(2deg); }
}

#eye-left, #eye-right {
  transition: filter 0.08s linear;
}

@keyframes idle-blink-glow {
  0%, 92%, 100% { opacity: 1; }
  95% { opacity: 0.55; }
}
#eye-left, #eye-right { animation: idle-blink-glow 4.2s ease-in-out infinite; }

#mouth {
  transform-box: fill-box;
  transform-origin: center;
}

.response-panel {
  min-height: 74px;
  max-width: 92%;
  margin: 10px auto 0;
  text-align: center;
}

.response-text {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.05rem;
  line-height: 1.5;
  color: var(--parchment);
  margin: 0;
}

.response-text .cursor {
  display: inline-block;
  width: 0.5em;
  animation: blink 1s step-end infinite;
  color: var(--ember);
}
@keyframes blink { 50% { opacity: 0; } }

.error-banner {
  max-width: 92%;
  margin: 8px auto 0;
  padding: 8px 14px;
  border: 1px solid var(--red-bright);
  border-radius: 8px;
  background: rgba(138, 3, 3, 0.15);
  color: var(--ember-light);
  font-size: 0.9rem;
  text-align: center;
}

.chat-log {
  max-height: 22vh;
  overflow-y: auto;
  margin: 10px 0 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  scrollbar-width: thin;
}

.chat-log .msg {
  padding: 6px 10px;
  border-radius: 10px;
  max-width: 82%;
}
.chat-log .msg.user {
  align-self: flex-end;
  background: var(--bg-panel);
  color: var(--parchment-dim);
  border: 1px solid var(--border);
}
.chat-log .msg.assistant {
  align-self: flex-start;
  color: var(--parchment-dim);
  opacity: 0.75;
}

.chatbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 4px 18px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

.text-input {
  flex: 1;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 11px 16px;
  color: var(--parchment);
  font-size: 0.95rem;
  outline: none;
}
.text-input:focus { border-color: var(--ember); }
.text-input::placeholder { color: var(--parchment-dim); opacity: 0.6; }

.mic-btn, .send-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--parchment-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.mic-btn:hover, .send-btn:hover { color: var(--ember-light); border-color: var(--ember); }

.mic-btn.recording {
  background: var(--red-bright);
  color: #fff;
  border-color: var(--red-bright);
  animation: pulse-rec 1.2s ease-in-out infinite;
}
@keyframes pulse-rec {
  0%, 100% { box-shadow: 0 0 0 0 rgba(179, 18, 27, 0.55); }
  50% { box-shadow: 0 0 0 8px rgba(179, 18, 27, 0); }
}

.mic-btn[hidden], .mic-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.send-btn:disabled, .text-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.avatar-wrap.thinking #aura {
  animation: aura-think 1.1s ease-in-out infinite;
}
@keyframes aura-think {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

@media (max-width: 420px) {
  .avatar-wrap { width: 84vw; }
  .brand { font-size: 1.1rem; }
}
