@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,700&family=DM+Sans:wght@400;500;700&display=swap");

/* ── Light mode (default) ── */
:root {
  --primary: #167e3d;
  --accent: #115c30;
  --bg-chat: #f0f7f2;
  --muted: rgba(6, 53, 36, 0.45);
  --text: #052617;
  --card: #ffffff;
  --border: rgba(6, 53, 36, 0.1);
  --input-bg: #f0f7f2;
  --meta: rgba(6, 53, 36, 0.4);
  --time: rgba(6, 53, 36, 0.35);
  --hear-bg: rgba(22, 126, 61, 0.08);
  --hear-border: rgba(22, 126, 61, 0.25);
  --hear-hover: rgba(22, 126, 61, 0.15);
}

/* ── Dark mode ── */
[data-theme="dark"] {
  --primary: #22c55e;
  --accent: #16a34a;
  --bg-chat: #0d1f14;
  --muted: rgba(134, 239, 172, 0.45);
  --text: #dcfce7;
  --card: #111f17;
  --border: rgba(134, 239, 172, 0.12);
  --input-bg: #0d1f14;
  --meta: rgba(134, 239, 172, 0.4);
  --time: rgba(134, 239, 172, 0.3);
  --hear-bg: rgba(34, 197, 94, 0.1);
  --hear-border: rgba(34, 197, 94, 0.25);
  --hear-hover: rgba(34, 197, 94, 0.2);
}

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

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family:
    "DM Sans",
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
  font-size: 13px;
  background: var(--bg-chat);
  color: var(--text);
  display: flex;
  justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  transition:
    background 0.25s,
    color 0.25s;
}

/* ── App shell ── */
.app {
  width: 100%;
  height: 100dvh;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-left: 0.5px solid var(--border);
  border-right: 0.5px solid var(--border);
  overflow: hidden;
  transition:
    background 0.25s,
    border-color 0.25s;
}

/* ── Header ── */
.app-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 18px;
  background: var(--primary);
  border-bottom: 1px solid var(--accent);
  z-index: 10;
  transition: background 0.25s;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 700;
  font-size: 11px;
  color: #fff;
  flex-shrink: 0;
}

.brand h1 {
  font-family: "Fraunces", Georgia, serif;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.brand p {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.65);
  margin-top: 1px;
}

/* ── Header right: status + theme toggle ── */
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.85);
  background: rgba(255, 255, 255, 0.12);
  border: 0.5px solid rgba(255, 255, 255, 0.25);
  border-radius: 20px;
  padding: 3px 10px;
  white-space: nowrap;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  flex-shrink: 0;
  transition: background 0.3s;
}
.status-dot.listening {
  background: #f87171;
  animation: blink 0.8s infinite;
}
.status-dot.thinking {
  background: #facc15;
  animation: blink 1.2s infinite;
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

/* ── Theme toggle button ── */
.theme-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: 0.5px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.theme-btn ion-icon {
  display: block;
  width: 17px;
  height: 17px;
}
.theme-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* ── App body ── */
.app-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Chat area ── */
.chat-box {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-chat);
  transition: background 0.25s;
}

.chat-box:empty::before {
  content: "Tap the mic and yan to Afrika Tori";
  display: block;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  margin-top: 48px;
}

.chat-divider {
  text-align: center;
  font-size: 10px;
  color: var(--muted);
  margin: 4px 0;
  letter-spacing: 0.04em;
}

/* ── Bubbles ── */
.msg {
  display: flex;
  flex-direction: column;
  max-width: 72%;
}

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

.meta {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 3px;
}

.msg.user .meta {
  color: var(--meta);
}

.bubble {
  padding: 9px 13px;
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
  transition:
    background 0.25s,
    color 0.25s,
    border-color 0.25s;
}

.msg.user .bubble {
  background: var(--primary);
  color: #fff;
  border-radius: 14px 14px 2px 14px;
}

.msg.assistant .bubble {
  background: var(--card);
  color: var(--text);
  border: 0.5px solid var(--border);
  border-radius: 14px 14px 14px 2px;
}

.msg-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.msg-time {
  font-size: 10px;
  color: var(--time);
}

/* ── Hear / Stop button ── */
.replay-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-family: inherit;
  color: var(--primary);
  background: var(--hear-bg);
  border: 0.5px solid var(--hear-border);
  border-radius: 20px;
  padding: 3px 9px;
  cursor: pointer;
  min-height: 28px;
  transition: background 0.15s;
}
.replay-btn:hover {
  background: var(--hear-hover);
}
.replay-btn.speaking {
  color: #b91c1c;
  background: rgba(185, 28, 28, 0.1);
  border-color: rgba(185, 28, 28, 0.3);
}

/* ── Text input bar ── */
.input-bar {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 14px;
  background: var(--card);
  border-top: 0.5px solid var(--border);
  transition:
    background 0.25s,
    border-color 0.25s;
}

.msg-input {
  flex: 1;
  min-height: 38px;
  max-height: 120px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--input-bg);
  border: 0.5px solid var(--border);
  border-radius: 20px;
  resize: none;
  outline: none;
  line-height: 1.5;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transition:
    border-color 0.15s,
    background 0.25s,
    color 0.25s;
}
.msg-input::placeholder {
  color: var(--muted);
}
.msg-input:focus {
  border-color: var(--primary);
}

.send-btn {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.15s,
    transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.send-btn:hover {
  background: var(--accent);
}
.send-btn:active {
  transform: scale(0.93);
}
.send-btn:disabled {
  background: rgba(22, 126, 61, 0.3);
  cursor: not-allowed;
  transform: none;
}

/* ── Bottom bar ── */
.bottom-bar {
  flex-shrink: 0;
  background: var(--card);
  border-top: 0.5px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  transition:
    background 0.25s,
    border-color 0.25s;
}

.player-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-bottom: 0.5px solid var(--border);
}

.player-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  white-space: nowrap;
}

audio {
  flex: 1;
  height: 26px;
  min-width: 0;
  max-width: 100%;
}

.action-row {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  gap: 10px;
}

.loader {
  display: none;
  font-size: 11px;
  font-style: italic;
  color: var(--primary);
  margin-right: auto;
}

.right-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

/* ── Clear button ── */
.clear-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-family: inherit;
  color: var(--muted);
  background: none;
  border: 0.5px solid var(--border);
  border-radius: 20px;
  padding: 6px 12px;
  cursor: pointer;
  min-height: 36px;
  white-space: nowrap;
  transition:
    color 0.15s,
    border-color 0.15s;
}
.clear-btn:hover {
  color: #b91c1c;
  border-color: rgba(185, 28, 28, 0.4);
}

/* ── Mic ── */
.mic-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.mic-button {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  transition:
    background 0.15s,
    transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.mic-button:hover {
  background: var(--accent);
}
.mic-button:active {
  transform: scale(0.94);
}
.mic-button.recording {
  background: #b91c1c;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(185, 28, 28, 0.5);
  }
  50% {
    box-shadow: 0 0 0 10px rgba(185, 28, 28, 0);
  }
}

.mic-label {
  font-size: 10px;
  color: var(--muted);
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .app {
    border-left: none;
    border-right: none;
  }
  .chat-box {
    padding: 12px 14px;
  }
  .msg {
    max-width: 80%;
  }
}

@media (max-width: 480px) {
  .app-header {
    padding: 9px 12px;
  }
  .brand h1 {
    font-size: 13px;
  }
  .brand p {
    display: none;
  }
  .logo {
    width: 30px;
    height: 30px;
    font-size: 10px;
  }
  .chat-box {
    padding: 10px;
    gap: 10px;
  }
  .msg {
    max-width: 88%;
  }
  .bubble {
    font-size: 13px;
    padding: 8px 11px;
  }
  .player-label {
    display: none;
  }
  .player-row {
    padding: 6px 12px;
  }
  .action-row {
    padding: 8px 12px;
  }
  .clear-btn span {
    display: none;
  }
  .clear-btn {
    padding: 6px 10px;
  }
  .right-actions {
    gap: 8px;
  }
  .input-bar {
    padding: 6px 10px;
    gap: 6px;
  }
  .msg-input {
    padding: 7px 11px;
  }
}

@media (max-width: 360px) {
  .brand h1 {
    font-size: 12px;
  }
  .msg {
    max-width: 92%;
  }
  .bubble {
    padding: 7px 10px;
  }
}
