:root {
  color-scheme: light;
  --ink: #171717;
  --muted: #6d6a66;
  --line: #d9d7d1;
  --line-strong: #b9b6ae;
  --paper: #ffffff;
  --ground: #f4f3ef;
  --soft: #ebe9e3;
  --accent: #e64b2f;
  --accent-dark: #bd351f;
  --green: #16745d;
  --yellow: #f2c14e;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--ground);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--ground);
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
a,
label,
summary {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
summary:focus-visible,
[role="radio"]:focus-visible {
  outline: 3px solid rgba(230, 75, 47, 0.24);
  outline-offset: 2px;
}

.topbar {
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
}

.topbar-inner,
.title-band,
.studio,
footer {
  width: min(1220px, calc(100% - 48px));
  margin: 0 auto;
}

.topbar-inner {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  color: inherit;
  text-decoration: none;
}

.brand img {
  display: block;
  width: 142px;
  height: 40px;
  object-fit: contain;
}

.brand-divider {
  width: 1px;
  height: 22px;
  background: var(--line-strong);
}

.brand-product {
  overflow: hidden;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-link,
.runtime-status {
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #4c4945;
  font-size: 13px;
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
}

.icon-link:hover {
  border-color: var(--line);
  background: var(--ground);
}

.icon-link svg {
  width: 16px;
  height: 16px;
}

.runtime-status {
  border-color: var(--line);
  background: var(--ground);
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 0 3px rgba(242, 193, 78, 0.18);
}

.runtime-status.ready .status-dot {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(22, 116, 93, 0.16);
}

main {
  padding-bottom: 40px;
}

.title-band {
  min-height: 158px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  padding: 46px 0 28px;
}

.eyebrow {
  margin: 0 0 9px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 680px;
  margin-bottom: 0;
  font-size: 34px;
  line-height: 1.1;
  font-weight: 750;
}

.engine-mark {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-bottom: 5px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: nowrap;
}

.engine-separator {
  color: var(--accent);
}

.studio {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(360px, 0.88fr);
  min-height: 690px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 18px 60px rgba(32, 29, 25, 0.07);
}

.controls-column,
.output-column {
  min-width: 0;
}

.control-section {
  padding: 28px 30px;
}

.control-section + .control-section {
  border-top: 1px solid var(--line);
}

.section-heading,
.output-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.section-heading > div:first-child,
.output-heading-row > div:first-child {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.step-index {
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  font-weight: 800;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
  line-height: 1.2;
  font-weight: 750;
}

.source-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 150px;
  height: 34px;
  padding: 3px;
  border-radius: 6px;
  background: var(--soft);
}

.source-tab {
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
}

.source-tab.active {
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 1px 3px rgba(28, 25, 22, 0.14);
}

.voice-library {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 22px;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.voice-option {
  position: relative;
  min-width: 0;
  height: 104px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  grid-template-rows: auto 30px;
  column-gap: 10px;
  align-items: center;
  padding: 13px 12px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  cursor: pointer;
  transition: background 140ms ease, box-shadow 140ms ease;
}

.voice-option:hover {
  background: #faf9f6;
}

.voice-option.selected {
  z-index: 1;
  background: #fff8f5;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.voice-play {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  grid-row: 1;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  color: var(--ink);
  background: var(--paper);
  cursor: pointer;
}

.voice-play:hover {
  color: var(--paper);
  border-color: var(--ink);
  background: var(--ink);
}

.voice-play svg {
  width: 14px;
  height: 14px;
}

.voice-meta {
  min-width: 0;
  grid-row: 1;
}

.voice-meta strong,
.voice-meta span {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.voice-meta strong {
  margin-bottom: 3px;
  font-size: 13px;
}

.voice-meta span {
  color: var(--muted);
  font-size: 10px;
}

.voice-option canvas {
  width: 100%;
  height: 28px;
  grid-column: 1 / -1;
  grid-row: 2;
}

.upload-panel {
  margin-bottom: 20px;
}

.upload-target {
  min-height: 108px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px;
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  background: #faf9f6;
  cursor: pointer;
}

.upload-target:hover {
  border-color: var(--accent);
  background: #fff8f5;
}

.upload-target svg {
  width: 22px;
  height: 22px;
  color: var(--accent);
}

.upload-target strong,
.upload-target small {
  display: block;
}

.upload-target strong {
  margin-bottom: 4px;
  font-size: 13px;
}

.upload-target small {
  color: var(--muted);
  font-size: 11px;
}

#referenceAudio {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

#uploadPreview {
  width: 100%;
  height: 42px;
  margin-top: 12px;
}

.field-label,
.settings-grid label {
  display: block;
  color: #4f4b47;
  font-size: 11px;
  font-weight: 750;
}

.field-label input,
.settings-grid input {
  width: 100%;
  height: 42px;
  margin-top: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink);
  background: var(--paper);
}

.field-label .reference-transcript {
  min-height: 62px;
  margin-top: 8px;
  padding: 10px 12px;
  resize: vertical;
  font-size: 12px;
  line-height: 1.55;
}

.field-label input:focus,
.settings-grid input:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 0;
  box-shadow: 0 0 0 3px rgba(230, 75, 47, 0.11);
}

.character-count {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
}

textarea {
  width: 100%;
  min-height: 142px;
  resize: vertical;
  display: block;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink);
  background: #fdfcf9;
  font-size: 15px;
  line-height: 1.65;
}

.text-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 11px;
}

.text-presets button {
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: #4f4b47;
  background: var(--paper);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}

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

.settings {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.settings summary {
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #4f4b47;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  list-style: none;
}

.settings summary::-webkit-details-marker {
  display: none;
}

.settings summary span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.settings summary svg {
  width: 15px;
  height: 15px;
}

.settings .chevron {
  transition: transform 160ms ease;
}

.settings[open] .chevron {
  transform: rotate(180deg);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 4px 0 16px;
}

.consent-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 18px 0 15px;
  color: #4f4b47;
  cursor: pointer;
  font-size: 12px;
}

.consent-row input {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--accent);
}

.generate-button,
.download-button {
  width: 100%;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  border-radius: 6px;
  color: var(--paper);
  background: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 750;
  text-decoration: none;
}

.generate-button:hover:not(:disabled),
.download-button:hover {
  background: var(--accent-dark);
}

.generate-button:disabled {
  color: #a5a29c;
  background: #dedcd6;
  cursor: not-allowed;
}

.generate-button svg,
.download-button svg {
  width: 18px;
  height: 18px;
}

.generate-button kbd {
  position: absolute;
  right: 44px;
  padding: 3px 6px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 4px;
  color: rgba(255, 255, 255, 0.68);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 9px;
  font-weight: 600;
}

.generate-button {
  position: relative;
}

.output-column {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 28px 30px 30px;
  border-left: 1px solid var(--line-strong);
  background: #f8f7f3;
}

.result-badge {
  padding: 5px 8px;
  border-radius: 4px;
  color: var(--green);
  background: rgba(22, 116, 93, 0.1);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.empty-output,
.loading-output {
  min-height: 400px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.empty-output p {
  margin: 22px 0 7px;
  font-size: 14px;
  font-weight: 700;
}

.empty-output > span {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px;
}

.wave-display {
  height: 84px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.wave-display span {
  width: 4px;
  border-radius: 2px;
  background: #cbc8c0;
}

.wave-display span:nth-child(1),
.wave-display span:nth-child(15) { height: 16px; }
.wave-display span:nth-child(2),
.wave-display span:nth-child(14) { height: 28px; }
.wave-display span:nth-child(3),
.wave-display span:nth-child(13) { height: 42px; }
.wave-display span:nth-child(4),
.wave-display span:nth-child(12) { height: 25px; }
.wave-display span:nth-child(5),
.wave-display span:nth-child(11) { height: 58px; }
.wave-display span:nth-child(6),
.wave-display span:nth-child(10) { height: 34px; }
.wave-display span:nth-child(7),
.wave-display span:nth-child(9) { height: 70px; }
.wave-display span:nth-child(8) { height: 48px; background: var(--accent); }

.loading-output strong {
  margin-top: 22px;
  font-size: 14px;
}

.loading-output > span {
  margin-top: 7px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
}

.processing-mark {
  height: 74px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.processing-mark span {
  width: 5px;
  height: 32px;
  border-radius: 3px;
  background: var(--accent);
  animation: processing 900ms ease-in-out infinite alternate;
}

.processing-mark span:nth-child(2) { animation-delay: 120ms; }
.processing-mark span:nth-child(3) { animation-delay: 240ms; }
.processing-mark span:nth-child(4) { animation-delay: 360ms; }
.processing-mark span:nth-child(5) { animation-delay: 480ms; }

@keyframes processing {
  from { height: 18px; opacity: 0.45; }
  to { height: 62px; opacity: 1; }
}

.result-output {
  flex: 1;
}

#resultWaveform {
  width: 100%;
  height: 180px;
  display: block;
  margin: 20px 0 26px;
  border-bottom: 1px solid var(--line);
}

#resultAudio {
  width: 100%;
  height: 48px;
}

.result-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 24px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.result-metrics div {
  min-width: 0;
  padding: 14px 12px;
}

.result-metrics div + div {
  border-left: 1px solid var(--line);
}

.result-metrics span,
.result-metrics strong {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.result-metrics span {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
}

.result-metrics strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.error-output {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  padding: 15px;
  border: 1px solid rgba(189, 53, 31, 0.35);
  border-radius: 6px;
  color: #8f2919;
  background: #fff3ef;
}

.error-output svg {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
}

.error-output strong {
  font-size: 13px;
}

.error-output p {
  margin: 4px 0 0;
  font-size: 12px;
  line-height: 1.5;
}

footer {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  color: var(--muted);
  font-size: 11px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

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

  .output-column {
    min-height: 560px;
    border-top: 1px solid var(--line-strong);
    border-left: 0;
  }

  .voice-library {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .topbar-inner,
  .title-band,
  .studio,
  footer {
    width: min(100% - 24px, 1220px);
  }

  .topbar-inner {
    min-height: 58px;
    gap: 10px;
  }

  .brand {
    gap: 8px;
  }

  .brand img {
    width: 100px;
    height: 34px;
  }

  .brand-product,
  .brand-divider,
  .icon-link span,
  .runtime-status span:last-child {
    display: none;
  }

  .icon-link,
  .runtime-status {
    width: 34px;
    padding: 0;
    justify-content: center;
  }

  .title-band {
    min-height: 138px;
    align-items: flex-start;
    flex-direction: column;
    justify-content: flex-end;
    gap: 16px;
    padding: 34px 0 24px;
  }

  h1 {
    font-size: 28px;
  }

  .engine-mark {
    padding: 0;
  }

  .control-section,
  .output-column {
    padding: 23px 18px;
  }

  .section-heading,
  .output-heading-row {
    gap: 12px;
  }

  .source-tabs {
    width: 132px;
  }

  .voice-option {
    height: 100px;
    padding: 11px 9px;
  }

  .settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .generate-button kbd {
    display: none;
  }

  .empty-output,
  .loading-output {
    min-height: 320px;
  }

  footer {
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    padding: 18px 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
