/* Sofia v2 — Avatar-first, dark, warm */

:root {
  --bg:           #12121e;
  --surface:      #1c1c2e;
  --text:         #f0ece0;
  --text-muted:   #a09880;
  --border:       #2e2e4a;
  --user-bubble:  #1e3a2e;
  --sofia-bubble: #1e2a3a;
  --radius:       16px;
  --radius-sm:    10px;
  --avatar-size:  260px;

  /* Ring colours — swapped per state via class */
  --ring-color:   #8a9a80;
  --ring-glow:    rgba(138, 154, 128, 0.25);

  --accent:       #4499cc;
  --accent-hover: #3388bb;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 22px;
  line-height: 1.55;
}

/* ── Layout ─────────────────────────────────────────── */

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 700px;
  margin: 0 auto;
  padding: 0 16px;
}

header {
  flex-shrink: 0;
  text-align: center;
  padding: 20px 0 10px;
}

header h1 {
  font-size: 1.6rem;
  color: var(--text-muted);
  letter-spacing: 0.12em;
  font-weight: normal;
  text-transform: uppercase;
}

/* ── Avatar section ──────────────────────────────────── */

#avatar-section {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 0 12px;
  min-height: 45vh;
}

/* The ring: coloured border + glow that pulses per state */
#avatar-ring {
  position: relative;
  width: var(--avatar-size);
  height: var(--avatar-size);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow:
    0 0 0 4px var(--ring-color),
    0 0 28px var(--ring-glow);
}

#avatar-ring:focus-visible {
  outline: 3px solid var(--ring-color);
  outline-offset: 6px;
}

#avatar-ring.avatar-busy {
  cursor: default;
}

/* State-specific ring colours */
#avatar-ring.ring-idle {
  --ring-color: #8a9a80;
  --ring-glow:  rgba(138, 154, 128, 0.25);
  animation: ring-breathe 3.5s ease-in-out infinite;
}

#avatar-ring.ring-checking {
  --ring-color: #555570;
  --ring-glow:  rgba(85, 85, 112, 0.2);
}

#avatar-ring.ring-offline {
  --ring-color: #e05555;
  --ring-glow:  rgba(224, 85, 85, 0.4);
  animation: ring-pulse-fast 0.9s ease-in-out infinite;
}

#avatar-ring.ring-recording {
  --ring-color: #44cc66;
  --ring-glow:  rgba(68, 204, 102, 0.45);
  animation: ring-pulse-fast 0.65s ease-in-out infinite;
}

#avatar-ring.ring-processing {
  --ring-color: #ccaa44;
  --ring-glow:  rgba(204, 170, 68, 0.4);
  animation: ring-pulse-medium 1.1s ease-in-out infinite;
}

#avatar-ring.ring-speaking {
  --ring-color: #4499cc;
  --ring-glow:  rgba(68, 153, 204, 0.4);
  animation: ring-pulse-slow 1.6s ease-in-out infinite;
}

/* The lottie canvas lives here; fills the ring */
#avatar-container {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  position: relative;
}

/* Each lottie instance gets its own wrapper div (created by avatar.js) */
.anim-layer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.anim-layer.hidden {
  display: none;
}

/* ── Ring keyframes ──────────────────────────────────── */

@keyframes ring-breathe {
  0%, 100% {
    box-shadow: 0 0 0 4px var(--ring-color), 0 0 20px var(--ring-glow);
  }
  50% {
    box-shadow: 0 0 0 7px var(--ring-color), 0 0 38px var(--ring-glow);
  }
}

@keyframes ring-pulse-fast {
  0%, 100% {
    box-shadow: 0 0 0 4px var(--ring-color), 0 0 16px var(--ring-glow);
  }
  50% {
    box-shadow: 0 0 0 12px var(--ring-color), 0 0 45px var(--ring-glow);
  }
}

@keyframes ring-pulse-medium {
  0%, 100% {
    box-shadow: 0 0 0 4px var(--ring-color), 0 0 18px var(--ring-glow);
  }
  50% {
    box-shadow: 0 0 0 10px var(--ring-color), 0 0 40px var(--ring-glow);
  }
}

@keyframes ring-pulse-slow {
  0%, 100% {
    box-shadow: 0 0 0 4px var(--ring-color), 0 0 18px var(--ring-glow);
  }
  50% {
    box-shadow: 0 0 0 9px var(--ring-color), 0 0 36px var(--ring-glow);
  }
}

/* ── Status bar ──────────────────────────────────────── */

#status-bar {
  margin-top: 18px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  min-height: 28px;
  font-style: italic;
  letter-spacing: 0.02em;
}

/* ── Chat history ────────────────────────────────────── */

#chat-history {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 0;
  display: block;
  scrollbar-width: none;        /* Firefox */
}

#chat-history::-webkit-scrollbar {
  display: none;                /* Chrome, Safari, Edge */
}

.message {
  display: block;
  max-width: 88%;
  margin-bottom: 16px;
}

.message.user {
  margin-left: auto;
  text-align: right;
}

.message.assistant {
  margin-right: auto;
  text-align: left;
}

.bubble {
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  line-height: 1.55;
  word-break: break-word;
}

.message.user .bubble {
  background: var(--user-bubble);
  border: 1px solid rgba(68, 204, 102, 0.2);
  border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
  background: var(--sofia-bubble);
  border: 1px solid rgba(68, 153, 204, 0.2);
  border-bottom-left-radius: 4px;
}

.label {
  font-size: 0.55rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ── Text input row (TEXT_ONLY mode) ─────────────────── */

#text-input-row {
  flex-shrink: 0;
  display: flex;
  gap: 10px;
  padding: 10px 0;
}

#text-input-row.hidden {
  display: none;
}

#text-input {
  flex: 1;
  font-size: 0.9rem;
  font-family: Georgia, serif;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  min-height: 52px;
}

#text-input:focus {
  outline: none;
  border-color: var(--accent);
}

#btn-send {
  font-size: 0.9rem;
  padding: 0 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: 52px;
  font-family: Georgia, serif;
}

#btn-send:hover {
  background: var(--accent-hover);
}

/* ── Footer ──────────────────────────────────────────── */

footer {
  flex-shrink: 0;
  padding: 10px 0 20px;
  text-align: center;
}

#btn-new-conversation {
  font-size: 0.7rem;
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

#btn-new-conversation:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

/* ── Overlays ────────────────────────────────────────── */

.overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 32px;
  z-index: 100;
  gap: 28px;
}

.overlay.hidden {
  display: none;
}

.overlay p {
  font-size: 1rem;
  color: var(--text);
  max-width: 480px;
  line-height: 1.65;
}

.overlay-btn {
  font-size: 1rem;
  padding: 16px 32px;
  border-radius: var(--radius);
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  min-height: 60px;
  font-family: Georgia, serif;
}

.overlay-btn:hover {
  background: var(--accent-hover);
}

.overlay-btn.secondary {
  background: transparent;
  color: var(--text-muted);
  border: 2px solid var(--border);
}

.overlay-btn.secondary:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.offline-icon {
  font-size: 3rem;
}

/* ── Landscape / small height ────────────────────────── */

@media (orientation: landscape) and (max-height: 520px) {
  #avatar-section {
    min-height: 55vw;
    padding: 8px 0 6px;
  }
  :root {
    --avatar-size: 180px;
  }
  header {
    padding: 8px 0 4px;
  }
  header h1 {
    font-size: 1.1rem;
  }
}

/* ── Larger screens ──────────────────────────────────── */

@media (min-width: 768px) {
  :root {
    --avatar-size: 300px;
  }
  html, body {
    font-size: 24px;
  }
  #app {
    padding: 0 32px;
  }
}
