:root {
  color-scheme: light;
  --bg: #f6f5ef;
  --surface: #fffdfa;
  --surface-soft: #f0f2ec;
  --ink: #17211c;
  --muted: #5c675f;
  --line: #d7d4c8;
  --accent: #2e436b;
  --accent-strong: #20345b;
  --clay: #a65a3f;
  --ok: #5d7a4c;
  --shadow: rgba(23, 33, 28, 0.1);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 13px;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  border-color: #b9b4a5;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fffdfa;
}

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

.shell {
  width: min(1440px, calc(100% - 36px));
  margin: 0 auto;
  padding: 22px 0 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.15;
}

.subtle {
  margin: 5px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.health {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.health-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #b8a86d;
}

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

.health.error .health-dot {
  background: var(--clay);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(380px, 0.95fr) minmax(520px, 1.2fr);
  gap: 16px;
  align-items: start;
}

.input-panel,
.output-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 42px var(--shadow);
}

.input-panel {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.output-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.field label,
.field > span,
.field > legend,
label.field,
legend {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

fieldset {
  margin: 0;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefb;
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(46, 67, 107, 0.14);
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

#text {
  min-height: 344px;
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr 132px;
  gap: 12px;
}

.stt-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 9px;
  align-items: end;
}

.stt-controls .upload-status {
  grid-column: 1 / -1;
}

.mode-field {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
}

.mode-field legend {
  width: 100%;
  margin-bottom: 2px;
}

.mode-field label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.mode-field input {
  width: auto;
}

.compact {
  align-content: start;
}

.voice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.voice-grid fieldset {
  display: grid;
  gap: 8px;
}

.file-picker {
  position: relative;
  display: grid;
  gap: 7px;
}

.file-picker span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.file-picker input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-status {
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.upload-status.error {
  color: var(--clay);
}

.voice-preview {
  display: grid;
  gap: 8px;
}

.voice-preview[hidden] {
  display: none;
}

.voice-waveform {
  width: 100%;
  height: 76px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefb;
}

.voice-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.voice-buttons button {
  flex: 1 1 110px;
}

.actions,
.examples,
.output-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.examples {
  padding-top: 2px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.summary > div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 11px;
}

.metric {
  display: block;
  overflow-wrap: anywhere;
  font-size: 23px;
  line-height: 1.15;
  font-weight: 850;
}

.metric-label {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.table-wrap {
  max-height: 400px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
  background: #fffefb;
}

th,
td {
  padding: 10px 11px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  line-height: 1.35;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td:nth-child(1),
td:nth-child(3) {
  width: 64px;
  font-variant-numeric: tabular-nums;
}

td:nth-child(2) {
  width: 112px;
  font-weight: 800;
}

.role-speaker {
  color: var(--accent);
}

.role-narrator {
  color: var(--clay);
}

.raw-output textarea {
  min-height: 190px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

@media (max-width: 980px) {
  .workspace,
  .voice-grid,
  .stt-controls,
  .control-grid {
    grid-template-columns: 1fr;
  }

  #text {
    min-height: 260px;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(354px, calc(100% - 24px));
    margin-left: 12px;
    margin-right: auto;
    padding-top: 14px;
  }

  .topbar,
  .summary {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  h1 {
    font-size: 22px;
  }

  .input-panel,
  .output-panel {
    padding: 12px;
  }

  .actions button,
  .examples button,
  .output-actions button {
    flex: 1 1 140px;
  }
}
