:root {
  color-scheme: light;
  --bg: #ffffff;
  --card: #ffffff;
  --muted: #666666;
  --text: #000000;
  --accent: #000000;
  --accent-blue: #0070f3;
  --accent-green: #10b981;
  --accent-yellow: #f59e0b;
  --soft: #fafafa;
  --border: #cbd5e1;
  --border-hover: #94a3b8;
  --shadow: 0 0 0 1px #cbd5e1;
  --radius: 8px;
  --button-height: 38px;
  --topbar-bg: #ffffff;
  --vrm-bg: radial-gradient(circle at center, #f3f4f6 0%, #e5e7eb 100%);
}

body.dark-theme {
  color-scheme: dark;
  --bg: #000000;
  --card: #0a0a0a;
  --muted: #888888;
  --text: #ffffff;
  --accent: #ffffff;
  --accent-blue: #0070f3;
  --accent-green: #10b981;
  --accent-yellow: #f59e0b;
  --soft: #111111;
  --border: #333333;
  --border-hover: #444444;
  --shadow: 0 0 0 1px #333333;
  --topbar-bg: #000000;
  --vrm-bg: radial-gradient(circle at center, #1e293b 0%, #090d16 100%);
}

body {
  margin: 0;
  background-color: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: background-color 0.15s ease, color 0.15s ease;
}

/* Unified topbar styling */
.topbar {
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.brand-block h1 {
  color: var(--text);
}

.brand-subtitle {
  color: var(--muted);
}

.nav-pill {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
  border-radius: 6px;
  transition: all 0.15s ease;
}

.nav-pill:hover {
  background: var(--soft);
  color: var(--text);
}

.nav-pill.active {
  background: var(--soft);
  border-color: var(--border);
  color: var(--text);
}

/* Theme actions in header */
.theme-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s ease;
}

.theme-toggle-btn:hover {
  background: var(--soft);
  border-color: var(--border-hover);
}

/* Chat container viewport lock */
.chat-container {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 20px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 24px;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.avatar-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

/* แถบเลือกอวาตาร์เหนือจอ VRM + ป้ายบอกว่ากำลังเล่นท่าจากไฟล์ชนิดไหน */
.avatar-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.avatar-picker-label {
  font-size: 0.85rem;
  color: var(--muted, #6b7280);
}

.avatar-picker {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font: inherit;
  min-height: 34px;
}

/* Pin the popup option colours so the native dropdown stays readable in
   both themes — options otherwise inherit the box's bg/color and render
   wrong (the old --vrm-bg gradient leaked into the list). */
.avatar-picker option {
  background: var(--card);
  color: var(--text);
}

.motion-badge {
  margin-left: auto;
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted, #6b7280);
  white-space: nowrap;
}

.motion-badge.is-fbx {
  border-color: #5b8def;
  color: #5b8def;
}

.vrm-card {
  background: var(--vrm-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  flex: 1;
  min-height: 0;
  position: relative;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.vrm-card:hover {
  border-color: var(--border-hover);
}

.vrm-viewport {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 6px;
  background-color: transparent;
  border: 1px solid var(--border);
}

.translation-meta-card {
  margin-top: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  flex: 0 0 auto;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.translation-meta-card:hover {
  border-color: var(--border-hover);
}

.meta-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13.5px;
}

.border-top {
  border-top: 1px solid var(--border);
}

.meta-label {
  color: var(--muted);
  font-weight: 500;
}

.meta-val {
  color: var(--text);
  font-weight: 600;
}

.meta-val.highlight {
  color: var(--accent-blue);
}

/* Chat interface section styling */
.chat-interface {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.chat-interface:hover {
  border-color: var(--border-hover);
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Premium monochrome high-contrast bubbles */
.chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  line-height: 1.5;
  word-wrap: break-word;
}

.bot-bubble {
  background-color: var(--soft);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 2px;
  border: 1px solid var(--border);
}

.user-bubble {
  background-color: var(--text);
  color: var(--bg);
  align-self: flex-end;
  border-bottom-right-radius: 2px;
  border: 1px solid var(--text);
  font-weight: 500;
}

.chat-bubble.loading {
  color: var(--muted);
  font-style: italic;
  animation: pulse 1.5s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.chat-bubble.error {
  background-color: rgba(255, 69, 58, 0.1);
  border: 1px solid rgba(255, 69, 58, 0.3);
  color: #ff453a;
}

.chat-controls {
  padding: 8px 16px;
  background: var(--soft);
  display: flex;
  justify-content: flex-end;
  border-top: 1px solid var(--border);
}

.tts-replay-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.tts-replay-btn:hover:not(:disabled) {
  background: var(--soft);
  border-color: var(--border-hover);
}

.tts-replay-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chat-input-area {
  padding: 12px 16px;
  background: var(--card);
  display: flex;
  gap: 10px;
  border-top: 1px solid var(--border);
}

#chatInput {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13.5px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s ease;
}

#chatInput:focus {
  border-color: var(--text);
}

.send-btn {
  background: var(--text);
  color: var(--bg);
  border: 1px solid var(--text);
  padding: 0 16px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.send-btn:hover {
  opacity: 0.9;
}

.chat-bubble.warning-bubble {
  background-color: rgba(245, 158, 11, 0.05);
  border: 1px solid rgba(245, 158, 11, 0.25);
  color: #f59e0b;
  font-size: 12px;
}

/* RESPONSIVE DESIGN */
@media (max-width: 900px) {
  body {
    overflow-y: auto;
    height: auto;
  }

  .chat-container {
    grid-template-columns: 1fr;
    height: auto;
    padding: 12px;
    overflow: visible;
  }

  .avatar-view {
    height: 440px;
  }

  .chat-interface {
    height: 480px;
    margin-top: 16px;
  }
}

/* SMALL-PHONE REFINEMENTS */
@media (max-width: 640px) {
  .avatar-view {
    height: 340px;
  }

  .chat-interface {
    height: 420px;
  }

  .chat-input-area {
    flex-wrap: wrap;
  }

  #chatInput {
    flex-basis: 100%;
  }

  .send-btn {
    flex: 1;
    min-height: 40px;
  }

  .tts-replay-btn,
  .nav-pill,
  .theme-toggle-btn {
    min-height: 40px;
  }
}
