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

/* Force hidden attribute to work even when CSS sets display */
[hidden] { display: none !important; }

:root {
  /* Light SpeechLab-inspired palette */
  --bg:          #f4f6f9;
  --bg-subtle:   #ffffff;
  --surface:     #ffffff;
  --surface-2:   #f0f2f5;
  --surface-3:   #e8ebf0;
  --border:      #d5dae3;
  --border-light:#c0c8d6;

  --text:        #1a2332;
  --text-2:      #3d4f66;
  --text-dim:    #7a8ba3;

  --accent:      #00997e;
  --accent-hover:#00b895;
  --accent-bg:   rgba(0, 153, 126, 0.06);
  --accent-bg-2: rgba(0, 153, 126, 0.12);

  --blue:        #3b82f6;
  --blue-bg:     rgba(59, 130, 246, 0.08);

  --danger:      #dc2626;
  --danger-bg:   rgba(220, 38, 38, 0.06);
  --success:     #059669;
  --warn:        #d97706;
  --warn-bg:     rgba(217, 119, 6, 0.07);

  --radius:      10px;
  --radius-sm:   6px;
  --radius-xs:   4px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
}

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

/* ── Top Bar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar-brand h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.01em;
}
.topbar-badge {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--accent-bg-2);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid rgba(0, 153, 126, 0.2);
}
.topbar-servers {
  display: flex;
  align-items: center;
  gap: 16px;
}
.topbar-server {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
}
.topbar-server label {
  color: var(--text-dim);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.topbar-server input {
  width: 200px;
  padding: 5px 8px;
  font-size: 0.78rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-2);
  outline: none;
}
.topbar-server input:focus { border-color: var(--accent); }
.server-status {
  font-size: 0.72rem;
  min-width: 60px;
}
.server-status.ok { color: var(--success); }
.server-status.err { color: var(--danger); }

/* ── App & Workspace ── */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 20px 24px 24px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}
.workspace-main {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
  margin-top: 20px;
}
@media (max-width: 900px) {
  .workspace-main { grid-template-columns: 1fr; }
}

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  color: var(--text-2);
}
.card-header h2 {
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-2);
}
.card-header svg { color: var(--accent); flex-shrink: 0; }

/* ── Config Card ── */
.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
}

/* ── Field ── */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field > label, .field-label-row > label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}
.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.field-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.select-examples {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-dim);
  font-size: 0.7rem;
  padding: 3px 6px;
  cursor: pointer;
  max-width: 200px;
}
.select-examples:focus { border-color: var(--accent); }
.field-hint {
  font-size: 0.7rem;
  color: var(--text-dim);
  line-height: 1.3;
}

/* ── Inputs ── */
select, input[type="text"], input[type="number"], textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 10px;
  font-size: 0.85rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
select:focus, input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg);
}
select { cursor: pointer; }
textarea { resize: vertical; }
input[type="number"] { width: 100%; }
.input-sm { flex: 1; font-size: 0.8rem; padding: 5px 8px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  line-height: 1;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
  padding: 10px 20px;
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-sm {
  background: var(--surface);
  color: var(--text-2);
  padding: 5px 10px;
  font-size: 0.75rem;
}
.btn-sm:hover { border-color: var(--accent); color: var(--accent); }
.btn-xs {
  background: var(--surface);
  color: var(--text-dim);
  padding: 3px 8px;
  font-size: 0.7rem;
  border-radius: var(--radius-xs);
}
.btn-xs:hover { color: var(--accent); border-color: var(--accent); }
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-2);
  padding: 5px 10px;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.btn-synthesize {
  width: 100%;
  justify-content: center;
  margin-top: 4px;
  font-size: 0.9rem;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
}
.btn-icon-svg { flex-shrink: 0; }
.btn-icon-sm {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
}
.btn-icon-sm:hover { color: var(--danger); background: var(--danger-bg); }
.btn-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
.btn-close:hover { color: var(--text); }

.btn-record svg { color: var(--danger); }
.btn-record.recording {
  border-color: var(--danger);
  animation: pulse-border 1.2s infinite;
}
@keyframes pulse-border {
  50% { border-color: transparent; }
}

/* ── Spinner ── */
.btn-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* ── Voice Section ── */
.voice-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.voice-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.voice-header h3 {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Profile List ── */
.profile-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 160px;
  overflow-y: auto;
}
.profile-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 20px 16px;
  color: var(--text-dim);
  font-size: 0.82rem;
  text-align: center;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}
.profile-empty svg { opacity: 0.35; }
.profile-empty-sub { font-size: 0.7rem; opacity: 0.7; }

.profile-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}
.profile-item:hover { border-color: var(--border-light); background: var(--surface-3); }
.profile-item.selected {
  border-color: var(--accent);
  background: var(--accent-bg);
}
.profile-item .profile-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-light);
  flex-shrink: 0;
}
.profile-item.selected .profile-dot { background: var(--accent); }
.profile-item .profile-name {
  flex: 1;
  font-size: 0.82rem;
  font-weight: 500;
}
.profile-item .profile-meta {
  font-size: 0.68rem;
  color: var(--text-dim);
}
.profile-item .btn-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1rem;
  padding: 0 2px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.1s;
}
.profile-item:hover .btn-delete { opacity: 1; }
.profile-item .btn-delete:hover { color: var(--danger); }

/* ── Profile Form (Modal) ── */
.profile-form-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.profile-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 90%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-lg);
}
.profile-form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.profile-form-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}
.profile-form-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}
.profile-form-footer .btn { padding: 8px 16px; }

/* ── Audio Upload ── */
.audio-upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 20px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}
.audio-upload-area:hover, .audio-upload-area.dragover {
  border-color: var(--accent);
  background: var(--accent-bg);
}
.audio-upload-area svg { color: var(--text-dim); }
.audio-upload-area .link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}
.upload-hint {
  font-size: 0.68rem;
  opacity: 0.6;
}
.audio-record-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.or-divider {
  font-size: 0.7rem;
  color: var(--text-dim);
}
.record-status {
  font-size: 0.72rem;
  color: var(--danger);
}
.recording-pulse { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }

/* ── Audio Preview ── */
.audio-preview-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.audio-preview-card audio {
  height: 32px;
  flex: 1;
  min-width: 0;
}
.audio-filename {
  font-size: 0.7rem;
  color: var(--text-dim);
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Tag Palette ── */
.tag-palette {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tag-section {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.tag-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}
.badge-future {
  font-size: 0.58rem;
  font-weight: 500;
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid rgba(217, 119, 6, 0.2);
}
.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-2);
  font-size: 0.7rem;
  font-family: var(--mono);
  padding: 3px 7px;
  cursor: pointer;
  transition: all 0.12s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip-future {
  opacity: 0.5;
  border-style: dashed;
}
.chip-future:hover { opacity: 0.8; }

/* ── IPA ── */
.ipa-row {
  display: flex;
  gap: 4px;
}
.ipa-keyboard {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 3px;
}
.ipa-key {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-2);
  font-size: 0.82rem;
  width: 28px;
  height: 26px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s;
}
.ipa-key:hover { border-color: var(--accent); color: var(--accent); }

/* ── Output Card ── */
.card-output {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.output-player {
  min-height: 80px;
}
.output-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 24px;
  color: var(--text-dim);
  font-size: 0.82rem;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
}
.output-empty svg { opacity: 0.25; }
.output-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#audio-output {
  width: 100%;
  height: 44px;
  border-radius: var(--radius-sm);
}
.output-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.output-stat {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ── Status Bar ── */
.status-bar {
  font-size: 0.75rem;
  color: var(--text-dim);
  min-height: 18px;
  padding-top: 4px;
}
.status-bar.error { color: var(--danger); }
.status-bar.success { color: var(--success); }

/* ── VoxCPM2 / IPA active chip ── */
.chip-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.chip-active:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.audio-upload-area-sm {
  padding: 0.6rem 0.8rem;
}
.audio-upload-area-sm svg { width: 18px; height: 18px; }

.ipa-disabled { opacity: 0.5; pointer-events: none; }

/* ── Transcribe button states ── */
.btn-transcribing {
  color: var(--accent) !important;
  border-color: var(--accent) !important;
  pointer-events: none;
}
.transcribe-hint-busy { color: var(--accent); }
.transcribe-hint-ok { color: var(--success); }
.transcribe-hint-err { color: var(--danger); }

/* ── Footer ── */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  font-size: 0.72rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
}
.app-footer a {
  color: var(--accent);
  text-decoration: none;
}
.app-footer a:hover { text-decoration: underline; }
.footer-sep { opacity: 0.4; }

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