:root {
  --bg: #f7f8fb;
  --card: #ffffff;
  --text: #16181d;
  --muted: #5b6470;
  --border: #e4e7ee;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.04);
  --radius: 12px;
  --mono: 'SF Mono', Monaco, Menlo, Consolas, 'Liberation Mono', monospace;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1015;
    --card: #181a21;
    --text: #f0f2f7;
    --muted: #98a0ad;
    --border: #2a2e38;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.4);
  }
}

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

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 14px; }
.logo { font-size: 28px; }
.brand h1 { font-size: 20px; font-weight: 600; }
.version {
  font-size: 12px;
  background: var(--accent);
  color: white;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: middle;
}
.tagline { font-size: 13px; color: var(--muted); }

.info-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  transition: all 0.15s;
}
.info-btn:hover { color: var(--accent); border-color: var(--accent); }

.container {
  max-width: 880px;
  width: 100%;
  margin: 24px auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex: 1;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.card h2 { font-size: 16px; font-weight: 600; margin-bottom: 16px; }

/* Record controls */
.record-controls {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  transition: background 0.15s;
}
.primary:hover { background: var(--accent-hover); }
.primary.big { padding: 14px 26px; font-size: 15px; }
.primary.recording { background: var(--danger); }
.primary.recording:hover { background: #b91c1c; }

.rec-dot {
  width: 10px; height: 10px;
  background: white;
  border-radius: 50%;
  display: inline-block;
}
.primary.recording .rec-dot { animation: pulse 1s infinite; }

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

.rec-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 200px;
}

#rec-timer {
  font-family: var(--mono);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  min-width: 50px;
}

.vu-meter {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  min-width: 100px;
}
#vu-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--success), #f59e0b, var(--danger));
  transition: width 0.06s linear;
}

.hint { color: var(--muted); font-size: 13px; margin-top: 12px; }

/* Drop zone */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  transition: all 0.15s;
  cursor: pointer;
}
.drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(37, 99, 235, 0.04);
}
.drop-hint { font-size: 15px; font-weight: 500; }
.drop-sub { color: var(--muted); margin: 8px 0; font-size: 13px; }
.drop-formats { color: var(--muted); font-size: 12px; margin-top: 14px; }

.file-btn {
  display: inline-block;
  background: var(--accent);
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.file-btn:hover { background: var(--accent-hover); }

/* Status */
.status {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
}

.spinner {
  width: 18px; height: 18px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Result */
.result-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 12px;
}

.toggles { display: flex; gap: 14px; align-items: center; }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.switch input[type="checkbox"] {
  appearance: none;
  width: 34px; height: 18px;
  background: var(--border);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
}
.switch input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  background: white;
  border-radius: 50%;
  transition: transform 0.15s;
}
.switch input[type="checkbox"]:checked { background: var(--accent); }
.switch input[type="checkbox"]:checked::after { transform: translateX(16px); }

.transcript {
  font-size: 18px;
  line-height: 1.7;
  padding: 18px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-wrap: break-word;
  min-height: 80px;
  font-family: var(--sans);
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.ghost:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
.ghost:disabled { opacity: 0.4; cursor: not-allowed; }
.ghost.small { padding: 6px 12px; font-size: 12px; }

.meta-details {
  margin-top: 16px;
  font-size: 13px;
  color: var(--muted);
}
.meta-details summary {
  cursor: pointer;
  padding: 4px 0;
}
.meta-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 14px;
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 12px;
  padding: 10px 0;
}
.meta-grid .k { font-weight: 600; color: var(--text); }
.meta-grid .v { color: var(--muted); word-break: break-all; }

/* History */
.history-list {
  list-style: none;
  margin-bottom: 12px;
}
.history-list li {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.history-list li:hover {
  border-color: var(--accent);
}
.history-list .h-text {
  flex: 1;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-list .h-time {
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
  white-space: nowrap;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-content {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-content h2 { margin-bottom: 14px; font-size: 18px; }
.modal-content p { margin-bottom: 10px; font-size: 14px; }
.modal-content ul {
  margin: 0 0 14px 18px;
  font-size: 14px;
}
.modal-content li { margin-bottom: 4px; }
.modal-content code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 12px;
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: transparent;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

.hidden { display: none !important; }

.footer {
  text-align: center;
  padding: 20px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

.error-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--danger);
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(220,38,38,0.3);
  z-index: 200;
  max-width: 90%;
  text-align: center;
}

@media (max-width: 600px) {
  .container { margin: 12px auto; padding: 0 12px; }
  .card { padding: 18px; }
  .topbar { padding: 12px 16px; }
  .brand h1 { font-size: 17px; }
  .tagline { font-size: 12px; }
  .transcript { font-size: 16px; padding: 14px; }
}

/* ---------------- TTS ---------------- */

.tts-card .hint {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
  line-height: 1.45;
}
.tts-card .hint code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
#tts-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  min-height: 80px;
}
#tts-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.tts-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.tts-status {
  font-size: 13px;
  color: var(--muted);
}
.tts-status-ok { color: var(--success); }
.tts-status-error { color: var(--danger); }
.tts-player {
  width: 100%;
  margin-top: 12px;
  border-radius: 8px;
}

/* ---------------- Chat (cascade / chat LLM) ---------------- */
.chat-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.chat-head-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}
.badge {
  font-size: 12px;
  font-family: var(--mono);
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 480px;
  min-height: 80px;
  overflow-y: auto;
  padding: 8px 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.chat-log:empty::before {
  content: "Start the conversation below — try Fon, French, or mix both.";
  display: block;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 16px;
}
.chat-bubble {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  word-wrap: break-word;
  white-space: pre-wrap;
}
.chat-user {
  align-self: flex-end;
  background: var(--accent);
  color: white;
  border-color: transparent;
}
.chat-user .chat-lang-tag { background: rgba(255,255,255,0.22); color: white; }
.chat-user .chat-who { color: rgba(255,255,255,0.85); }
.chat-assistant { align-self: flex-start; }
.chat-bubble-head {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--muted);
}
.chat-who { font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.chat-lang-tag {
  font-family: var(--mono);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.chat-lang-fon .chat-lang-tag { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.chat-user.chat-lang-fon .chat-lang-tag { background: rgba(255,255,255,0.22); color: white; border-color: transparent; }
.chat-bubble-body {
  font-size: 15px;
  line-height: 1.55;
}
.chat-bubble-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 8px;
  font-size: 11px;
}
.chat-bubble-actions .ghost { padding: 3px 8px; font-size: 12px; }
.chat-meta {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  margin-left: auto;
}
.chat-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 12px 14px;
}
.chat-typing .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: chat-typing-bounce 1.2s infinite;
}
.chat-typing .dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing .dot:nth-child(3) { animation-delay: 0.30s; }
@keyframes chat-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}
.chat-input-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
#chat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  min-height: 56px;
}
#chat-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
#chat-send-btn { align-self: stretch; padding: 0 22px; }
kbd {
  font-family: var(--mono);
  font-size: 11px;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--muted);
}

@media (prefers-color-scheme: dark) {
  .chat-lang-fon .chat-lang-tag { background: rgba(16,185,129,0.16); color: #6ee7b7; border-color: rgba(16,185,129,0.35); }
}
