:root {
  color-scheme: light;
  --bg: #f4efe4;
  --panel: rgba(255, 250, 240, 0.86);
  --ink: #1f1e1b;
  --muted: #6c665b;
  --accent: #c95b2b;
  --accent-strong: #9e3c16;
  --line: rgba(31, 30, 27, 0.12);
  --shadow: 0 24px 60px rgba(86, 56, 28, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top, rgba(245, 213, 179, 0.7), transparent 32%),
    linear-gradient(135deg, #efe7d8 0%, #f7f2e9 45%, #ead9c7 100%);
  overflow-y: auto;
}

.layout {
  width: min(580px, calc(100% - 24px));
  margin: 12px auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Session buttons row */
.session-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-small {
  font: inherit;
  font-size: 0.75rem;
  border: 0;
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  background: var(--accent);
  color: #fff7f0;
  transition: transform 120ms ease, background 120ms ease;
}

.btn-small:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.btn-small.secondary {
  background: rgba(31, 30, 27, 0.1);
  color: var(--ink);
}

.btn-small:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

.status-text {
  font-size: 0.8rem;
  color: var(--ink);
}

.status-text.muted {
  color: var(--muted);
}

/* Avatar */
.avatar-frame {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 18px;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 244, 219, 0.38), transparent 24%),
    linear-gradient(180deg, #cbb59d 0%, #9f7e60 100%);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.avatar-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border: 0;
  z-index: 2;
  background: #000;
}

.hidden {
  display: none;
}

.avatar-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at center, rgba(255, 244, 219, 0.28), rgba(255, 244, 219, 0));
  z-index: 1;
}

.placeholder-copy {
  width: min(320px, calc(100% - 32px));
  padding: 18px 20px;
  border: 1px solid rgba(255, 250, 240, 0.28);
  border-radius: 16px;
  background: rgba(40, 27, 18, 0.3);
  color: #fff7f0;
  text-align: center;
  backdrop-filter: blur(8px);
}

.placeholder-copy strong {
  display: block;
  margin-bottom: 8px;
  font-size: 1.2rem;
}

.placeholder-copy span {
  display: block;
  line-height: 1.4;
  font-size: 0.9rem;
}

/* Sections */
.input-section,
.response-section,
.history-section,
.persona-section {
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  backdrop-filter: blur(18px);
}

.field {
  display: block;
}

.field span {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

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

textarea,
input,
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(43, 31, 22, 0.14);
  border-radius: 12px;
  background: rgba(255, 252, 247, 0.9);
  color: var(--ink);
  font-size: 0.95rem;
}

textarea {
  resize: none;
  min-height: 0;
}

#text {
  height: 56px;
}

#spokenText {
  height: 56px;
}

#persona {
  height: 64px;
}

/* Actions */
.actions {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  background: var(--accent);
  color: #fff7f0;
  font-size: 0.9rem;
  transition: transform 120ms ease, background 120ms ease;
}

button:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

button.secondary {
  background: rgba(31, 30, 27, 0.1);
  color: var(--ink);
}

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

/* Chat thread */
.chat-thread {
  min-height: 80px;
  max-height: 160px;
  overflow-y: auto;
  padding: 10px;
  border: 1px solid rgba(43, 31, 22, 0.14);
  border-radius: 12px;
  background: rgba(255, 252, 247, 0.78);
}

.chat-message + .chat-message {
  margin-top: 8px;
}

.chat-bubble {
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  font-size: 0.9rem;
}

.chat-message.user {
  display: flex;
  justify-content: flex-end;
}

.chat-message.user .chat-bubble {
  background: rgba(201, 91, 43, 0.14);
  border-top-right-radius: 4px;
}

.chat-message.assistant {
  display: flex;
  justify-content: flex-start;
}

.chat-message.assistant .chat-bubble {
  background: rgba(31, 30, 27, 0.08);
  border-top-left-radius: 4px;
}

.chat-empty {
  color: var(--muted);
  font-size: 0.88rem;
}

/* Mobile tweaks */
@media (max-width: 640px) {
  .layout {
    width: calc(100% - 16px);
    margin: 8px auto;
    gap: 8px;
  }

  .avatar-frame {
    border-radius: 14px;
  }

  .input-section,
  .response-section,
  .history-section,
  .persona-section {
    padding: 10px 12px;
    border-radius: 12px;
  }

  .placeholder-copy {
    width: calc(100% - 20px);
    padding: 14px;
  }

  .placeholder-copy strong {
    font-size: 1rem;
  }

  .chat-thread {
    max-height: 140px;
  }
}
