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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #22263a;
  --border: #2a2e3f;
  --text: #e4e5eb;
  --text-muted: #8b8fa3;
  --azure: #0078d4;
  --azure-soft: rgba(0, 120, 212, 0.15);
  --eleven: #e946ff;
  --eleven-soft: rgba(233, 70, 255, 0.15);
  --gemini: #4285f4;
  --gemini-soft: rgba(66, 133, 244, 0.15);
  --accent: #6366f1;
  --success: #22c55e;
  --error: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
}

html {
  font-size: 15px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

header {
  text-align: center;
  margin-bottom: 2.5rem;
}

header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}

header h1 .azure-text {
  color: var(--azure);
}

header h1 .vs {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 1.2rem;
  margin: 0 0.3rem;
}

header h1 .eleven-text {
  color: var(--eleven);
}

header h1 .gemini-text {
  color: var(--gemini);
}

header p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.model-ref {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--surface);
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  display: inline-block;
  margin-top: 0.5rem;
  word-break: break-all;
}

/* Input section */
.input-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.input-section label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

textarea {
  width: 100%;
  min-height: 100px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  padding: 0.75rem 1rem;
  resize: vertical;
  transition: border-color 0.2s;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.presets button {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s;
}

.presets button:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* Language flag filter */
.lang-filter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.lang-filter-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 0.25rem;
}

.lang-flag {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.55rem;
  cursor: pointer;
  background: var(--bg);
  color: var(--text-muted);
  transition: all 0.15s;
  white-space: nowrap;
}

.lang-flag:hover {
  border-color: var(--accent);
  color: var(--text);
}

.lang-flag.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Voice selectors grid */
.voices-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.voices-grid.three-col {
  grid-template-columns: 1fr 1fr 1fr;
}

@media (max-width: 1000px) {
  .voices-grid.three-col {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .voices-grid {
    grid-template-columns: 1fr;
  }
}

.voice-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  position: relative;
}

.voice-panel.azure {
  border-top: 3px solid var(--azure);
}

.voice-panel.eleven {
  border-top: 3px solid var(--eleven);
}

.voice-panel.gemini {
  border-top: 3px solid var(--gemini);
}

.voice-panel h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.voice-panel.azure h2 {
  color: var(--azure);
}

.voice-panel.eleven h2 {
  color: var(--eleven);
}

.voice-panel.gemini h2 {
  color: var(--gemini);
}

.provider-badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
}

.azure .provider-badge {
  background: var(--azure-soft);
  color: var(--azure);
}

.eleven .provider-badge {
  background: var(--eleven-soft);
  color: var(--eleven);
}

.gemini .provider-badge {
  background: var(--gemini-soft);
  color: var(--gemini);
}

select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%238b8fa3'%3E%3Cpath d='M4.5 6l3.5 4 3.5-4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
}

select:focus {
  outline: none;
  border-color: var(--accent);
}

.field-group {
  margin-bottom: 0.75rem;
}

.field-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  font-weight: 500;
}

.voice-search {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
}

.voice-search:focus {
  outline: none;
  border-color: var(--accent);
}

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

.voice-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.3rem;
}

.status-dot.ok {
  background: var(--success);
}

.status-dot.err {
  background: var(--error);
}

.status-dot.loading {
  background: var(--text-muted);
  animation: pulse 1.2s infinite;
}

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

/* Synthesize button */
.action-bar {
  text-align: center;
  margin-bottom: 2rem;
}

.btn-compare {
  background: linear-gradient(135deg, var(--azure), var(--eleven));
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  padding: 0.85rem 2.5rem;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}

.btn-compare:hover:not(:disabled) {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-compare:active:not(:disabled) {
  transform: translateY(0);
}

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

/* Results */
.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.results-grid.three-col {
  grid-template-columns: 1fr 1fr 1fr;
}

@media (max-width: 1000px) {
  .results-grid.three-col {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .results-grid {
    grid-template-columns: 1fr;
  }
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  min-height: 140px;
  display: flex;
  flex-direction: column;
}

.result-card.azure {
  border-top: 3px solid var(--azure);
}

.result-card.eleven {
  border-top: 3px solid var(--eleven);
}

.result-card.gemini {
  border-top: 3px solid var(--gemini);
}

.result-card h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.result-card.azure h3 {
  color: var(--azure);
}

.result-card.eleven h3 {
  color: var(--eleven);
}

.result-card.gemini h3 {
  color: var(--gemini);
}

.result-card audio {
  width: 100%;
  margin-bottom: 0.75rem;
  border-radius: var(--radius-sm);
}

.metrics {
  display: flex;
  gap: 1rem;
  margin-top: auto;
}

.metric {
  display: flex;
  flex-direction: column;
}

.metric-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.metric-value {
  font-size: 1.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.metric-value.fast {
  color: var(--success);
}

.metric-value.slow {
  color: var(--error);
}

.result-error {
  color: var(--error);
  font-size: 0.85rem;
  background: rgba(239, 68, 68, 0.1);
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  word-break: break-word;
}

.result-placeholder {
  color: var(--text-muted);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}

/* Latency comparison bar */
.latency-bar-container {
  display: none;
  margin-bottom: 2rem;
}

.latency-bar-container.visible {
  display: block;
}

.latency-compare {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}

.latency-compare h3 {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
  text-align: center;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.bar-label {
  width: 100px;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: right;
  flex-shrink: 0;
}

.bar-label.azure {
  color: var(--azure);
}

.bar-label.eleven {
  color: var(--eleven);
}

.bar-label.gemini {
  color: var(--gemini);
}

.bar-track {
  flex: 1;
  height: 28px;
  background: var(--bg);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.6s ease;
  display: flex;
  align-items: center;
  padding-right: 0.5rem;
  justify-content: flex-end;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  min-width: 60px;
}

.bar-fill.azure {
  background: var(--azure);
}

.bar-fill.eleven {
  background: var(--eleven);
}

.bar-fill.gemini {
  background: var(--gemini);
}

.winner-label {
  text-align: center;
  margin-top: 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
}

/* History */
.history-section {
  margin-top: 2rem;
}

.history-section h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.history-table th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 2px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.history-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.history-table tr:hover td {
  background: var(--surface-hover);
}

.history-table .text-cell {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 0.5rem;
  vertical-align: middle;
}

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

/* SSML Editor */
.ssml-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid var(--azure);
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  background: transparent;
  color: var(--azure);
  transition: all 0.15s;
  margin-left: 0.5rem;
}

.ssml-toggle:hover {
  background: var(--azure-soft);
}

.ssml-toggle.active {
  background: var(--azure);
  color: #fff;
}

.ssml-editor {
  display: none;
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.ssml-editor.visible {
  display: block;
}

.ssml-segment {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.ssml-segment:last-child {
  border-bottom: none;
}

.ssml-segment-num {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 0.15rem;
}

.ssml-segment-text {
  flex: 1;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text);
}

.ssml-segment-style {
  flex-shrink: 0;
  width: 140px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.78rem;
  padding: 0.3rem 0.4rem;
  cursor: pointer;
}

.ssml-segment-style:focus {
  outline: none;
  border-color: var(--azure);
}

.ssml-hint {
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.ssml-preview {
  margin-top: 0.5rem;
  padding: 0.6rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 120px;
  overflow-y: auto;
  display: none;
}

.ssml-preview.visible {
  display: block;
}

.btn-regen {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  background: var(--bg);
  color: var(--text-muted);
  transition: all 0.15s;
  margin-top: 0.5rem;
}

.btn-regen:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--text-muted);
}

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

.btn-regen.azure:hover:not(:disabled) {
  border-color: var(--azure);
  color: var(--azure);
}

.btn-regen.eleven:hover:not(:disabled) {
  border-color: var(--eleven);
  color: var(--eleven);
}

.btn-regen.gemini:hover:not(:disabled) {
  border-color: var(--gemini);
  color: var(--gemini);
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.result-header h3 {
  margin-bottom: 0;
}

/* Advanced parameters */
.params-section {
  margin-top: 0.75rem;
}

.params-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  background: var(--bg);
  color: var(--text-muted);
  transition: all 0.15s;
  width: 100%;
  justify-content: center;
}

.params-toggle:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.params-toggle.active {
  border-color: var(--accent);
  color: var(--accent);
}

.params-grid {
  margin-top: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.param-control label {
  display: block;
  font-size: 0.78rem;
  color: var(--text);
  margin-bottom: 0.25rem;
  font-weight: 500;
}

.param-control label span {
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.param-control input[type="range"] {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

.param-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--surface);
}

.param-control input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--surface);
}

.param-hint {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.param-checkbox label {
  display: flex !important;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
}

.param-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Word timestamps / karaoke */
.word-timestamps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.35rem;
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 150px;
  overflow-y: auto;
  line-height: 1.7;
}

.word-ts {
  font-size: 0.85rem;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  transition: background 0.08s, color 0.08s;
  cursor: pointer;
  color: var(--text-muted);
}

.word-ts:hover {
  background: var(--surface-hover);
}

.word-ts.active {
  background: var(--accent);
  color: #fff;
}

.word-ts.past {
  color: var(--text);
}

.word-ts-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.word-ts-label span {
  font-weight: 600;
}

/* Style prompt presets */
.style-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.5rem;
}

.style-presets button {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.15s;
}

.style-presets button:hover {
  border-color: var(--gemini);
  color: var(--gemini);
}

.style-presets button.active {
  background: var(--gemini-soft);
  border-color: var(--gemini);
  color: var(--gemini);
}

footer {
  text-align: center;
  padding: 2rem 0 1rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

footer a {
  color: var(--accent);
  text-decoration: none;
}
