:root {
  color-scheme: dark;
  --bg: #111;
  --surface: #181818;
  --surface-2: #202020;
  --border: #2a2a2a;
  --border-strong: #3a3a3a;
  --text: #f0f0f0;
  --muted: #888;
  --accent: #e07030;
  --accent-hover: #eb8345;
  --accent-soft: rgba(224, 112, 48, 0.14);
  --accent-text: #141414;
  --danger: #d97070;
  --interim: #999;
  --radius: 10px;
  --radius-sm: 6px;
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-family: var(--font);
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f4f4f3;
    --surface: #fff;
    --surface-2: #f0f0ee;
    --border: #e6e6e3;
    --border-strong: #d2d2cd;
    --text: #171717;
    --muted: #6e6e6e;
    --accent: #c45f1e;
    --accent-hover: #a84f16;
    --accent-soft: rgba(196, 95, 30, 0.12);
    --accent-text: #fff;
    --danger: #c44a4a;
    --interim: #7a7a7a;
  }
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 680px;
  margin: 0 auto;
  padding: 2.75rem 1.25rem 3rem;
}

/* —— Header —— */
.header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8125rem;
  color: var(--muted);
  min-height: 1.25rem;
}

.status-dot {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  opacity: 0.65;
}

.status-dot.listening,
.status-dot.speaking {
  background: var(--accent);
  opacity: 1;
  animation: pulse 1.5s ease-in-out infinite;
}

.status-dot.error {
  background: var(--danger);
  opacity: 1;
}

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

/* —— Shell —— */
.shell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  /* Keep visible so combo lists can extend outside toolbars */
  overflow: visible;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius) var(--radius) 0 0;
  position: relative;
  z-index: 2;
}

.toolbar-tts {
  background: var(--surface);
  border-radius: 0;
  z-index: 1;
}

.select-grow {
  flex: 1 1 10rem;
  min-width: 9rem;
  margin-right: 0.25rem;
}

/* —— Searchable combobox —— */
.combo {
  position: relative;
  min-width: 9rem;
}

.combo-input {
  width: 100%;
  appearance: none;
  padding: 0.5rem 1.9rem 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  cursor: text;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.toolbar-tts .combo-input {
  background: var(--surface-2);
}

.combo-input::placeholder {
  color: var(--muted);
}

.combo-input:hover:not(:disabled) {
  border-color: var(--border-strong);
}

.combo-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.combo-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.combo::after {
  content: "";
  position: absolute;
  right: 0.75rem;
  top: 50%;
  width: 0.35rem;
  height: 0.35rem;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
  transition: transform 0.12s ease;
}

.combo.is-open::after {
  transform: translateY(-30%) rotate(225deg);
}

.combo-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 30;
  margin: 0;
  padding: 0.3rem;
  list-style: none;
  max-height: 220px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.combo-list[hidden] {
  display: none;
}

.combo-option {
  display: block;
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  text-align: left;
  cursor: pointer;
  line-height: 1.35;
}

.combo-option:hover,
.combo-option.is-active {
  background: var(--accent-soft);
}

.combo-option.is-selected {
  color: var(--accent);
  font-weight: 550;
}

.combo-option.is-selected.is-active,
.combo-option.is-selected:hover {
  background: var(--accent-soft);
}

.combo-empty {
  padding: 0.55rem 0.6rem;
  font-size: 0.8125rem;
  color: var(--muted);
}

/* —— Buttons —— */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.85rem;
  font: inherit;
  font-weight: 550;
  font-size: 0.875rem;
  line-height: 1.2;
  cursor: pointer;
  transition:
    background 0.12s ease,
    border-color 0.12s ease,
    color 0.12s ease,
    opacity 0.12s ease;
}

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

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

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

.btn-primary:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--surface-2), 0 0 0 4px var(--accent);
}

.btn-secondary {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface);
  border-color: var(--muted);
}

.btn-secondary:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--surface-2), 0 0 0 4px var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  padding-inline: 0.7rem;
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface);
}

.btn-ghost:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--surface-2), 0 0 0 4px var(--border-strong);
}

/* —— Text —— */
.text-panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
}

.text-input {
  display: block;
  width: 100%;
  min-height: 280px;
  max-height: min(58vh, 480px);
  margin: 0;
  padding: 1.15rem 1.1rem 1.35rem;
  border: 0;
  resize: vertical;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
  line-height: 1.65;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.text-input::placeholder {
  color: var(--muted);
}

.text-input:focus {
  outline: none;
}

.text-input:focus-visible {
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.interim-text {
  margin: 0;
  padding: 0 1.1rem 1rem;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--interim);
  font-style: italic;
}

.interim-text[hidden] {
  display: none;
}

/* —— Responsive —— */
@media (max-width: 520px) {
  .app {
    padding-top: 1.75rem;
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }

  .select-grow {
    flex: 1 1 100%;
    margin-right: 0;
    margin-bottom: 0.15rem;
  }

  .btn {
    flex: 1 1 calc(50% - 0.25rem);
  }
}
