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

:root {
  --bg:           #212121;
  --surface:      #2f2f2f;
  --surface2:     #3a3a3a;
  --border:       #3f3f3f;
  --accent:       #10a37f;
  --accent-hover: #0d8a6c;
  --text:         #ececec;
  --text-dim:     #8e8ea0;
  --user-bg:      #2f2f2f;
  --connected:    #10a37f;
  --listening:    #facc15;
  --error:        #ef4444;
  --muted:        #6b7280;
  --max-w:        720px;
}

html, body {
  height: 100%;
}

body {
  font-family: 'Söhne', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 16px;
}

/* ── Layout ── */
.layout {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}

.header-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ── Settings / gear button ── */
.btn-icon {
  position: relative;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.btn-icon:hover {
  background: var(--surface);
  color: var(--text);
}

.key-indicator {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1.5px solid var(--bg);
  background: var(--text-dim);
}

.key-indicator.set {
  background: var(--connected);
}

.key-indicator.missing {
  background: var(--error);
}

.status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
  transition: background 0.3s;
}

.status-dot.connected { background: var(--connected); }
.status-dot.listening {
  background: var(--listening);
  animation: pulse 1s ease-in-out infinite;
}
.status-dot.connecting {
  background: var(--accent);
  animation: pulse 0.7s ease-in-out infinite;
}
.status-dot.error  { background: var(--error); }
.status-dot.muted  { background: var(--muted); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.8); }
}

/* ── Transcript (main) ── */
main {
  flex: 1;
  overflow-y: auto;
  padding: 32px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.empty-state {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--text-dim);
  text-align: center;
}

.empty-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
}

.empty-state p {
  font-size: 0.95rem;
}

/* ── Messages ── */
.message {
  display: flex;
  gap: 16px;
  padding: 20px 0;
  max-width: var(--max-w);
  width: 100%;
  margin: 0 auto;
  animation: fadeIn 0.2s ease;
}

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

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
  letter-spacing: 0.02em;
}

.message.user .avatar {
  background: #5c5c7a;
  color: #d0d0f0;
}

.message.assistant .avatar {
  background: var(--accent);
  color: #fff;
}

.message-content {
  flex: 1;
  min-width: 0;
  font-size: 0.95rem;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user .message-content {
  color: #d1d5db;
}

/* pending (placeholder while transcribing) */
.message.pending .message-content {
  color: var(--text-dim);
  font-style: italic;
}

/* streaming AI response */
.message.streaming .message-content::after {
  content: '▋';
  display: inline-block;
  animation: blink 0.6s step-end infinite;
  color: var(--accent);
  margin-left: 1px;
}

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

/* ── Footer ── */
footer {
  flex-shrink: 0;
  padding: 12px 20px 20px;
  background: var(--bg);
}

.controls-wrap {
  max-width: var(--max-w);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Text input row ── */
.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 10px 10px 16px;
  transition: border-color 0.2s;
}

.input-row:focus-within {
  border-color: #555;
}

#text-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  max-height: 160px;
  overflow-y: auto;
  padding: 2px 0;
}

#text-input::placeholder {
  color: var(--text-dim);
}

#text-input:disabled::placeholder {
  opacity: 0.5;
}

#btn-send {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  width: 36px;
  height: 36px;
  padding: 0;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

#btn-send:disabled {
  background: var(--surface2);
  color: var(--text-dim);
  opacity: 1;
}

/* ── Voice controls row ── */
.controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 4px 4px 8px;
}

/* ── Voice selector ── */
.voice-select-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-dim);
}

#voice-select {
  background: transparent;
  color: var(--text);
  border: none;
  font-size: 0.85rem;
  cursor: pointer;
  outline: none;
  padding: 2px 4px;
}

#voice-select option {
  background: var(--surface2);
}

#voice-select:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ── Button group ── */
.btn-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border: none;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.2s, transform 0.1s;
  white-space: nowrap;
}

button:active { transform: scale(0.97); }
button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

#btn-connect {
  background: var(--accent);
  color: #fff;
}

#btn-connect:hover:not(:disabled) {
  background: var(--accent-hover);
}

#btn-connect.disconnect {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

#btn-connect.disconnect:hover:not(:disabled) {
  background: #4a2a2a;
  border-color: #7a3a3a;
  color: #f87171;
}

#btn-mute {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

#btn-mute:hover:not(:disabled) {
  background: var(--border);
}

#btn-mute.active {
  background: #3d2e0a;
  border-color: #7a5f1a;
  color: var(--listening);
}

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.15s ease;
}

.modal {
  background: #2a2a38;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 440px;
  margin: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 4px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.modal-close:hover {
  background: var(--surface2);
  color: var(--text);
}

.modal-desc {
  font-size: 0.875rem;
  color: var(--text-dim);
  line-height: 1.55;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.input-wrap {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.2s;
}

.input-wrap:focus-within {
  border-color: var(--accent);
}

.input-wrap input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 0.9rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
  padding: 10px 12px;
}

.input-wrap input::placeholder {
  color: var(--text-dim);
  font-family: inherit;
}

.btn-eye {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 0 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  height: 100%;
  transition: color 0.15s;
}

.btn-eye:hover { color: var(--text); }

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}

.modal-actions-right {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 9px;
  padding: 9px 20px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

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

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 20px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-secondary:hover { background: var(--border); }

.btn-danger {
  background: transparent;
  color: var(--error);
  border: 1px solid #5a2222;
  border-radius: 9px;
  padding: 9px 16px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-danger:hover {
  background: #3a1a1a;
  border-color: var(--error);
}

/* ── Scrollbar ── */
::-webkit-scrollbar       { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
