:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #0f172a;
  background: #f8fafc;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: radial-gradient(circle at top left, rgba(79, 70, 229, .11), transparent 36rem), #f8fafc;
}

button, input, select, textarea { font: inherit; }
button { touch-action: manipulation; }
code { font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace; }

.app-shell {
  width: min(1160px, calc(100% - 32px));
  margin: 0 auto;
  padding: 44px 0 56px;
}

.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: #4f46e5;
  font-size: .82rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1 {
  margin-bottom: 10px;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1.05;
  letter-spacing: -.045em;
}
h2 { display: inline; margin: 0 0 6px 8px; font-size: 1.3rem; }
h3 { margin-bottom: 0; font-size: 1rem; }

.subtitle, .section-heading p, .notice p, .field-help {
  color: #64748b;
  line-height: 1.6;
}
.subtitle { max-width: 760px; margin-bottom: 0; }
.badges { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

.badge {
  flex: 0 0 auto;
  border: 1px solid;
  border-radius: 999px;
  padding: 9px 13px;
  font-size: .8rem;
  font-weight: 800;
  white-space: nowrap;
}
.badge-waiting { border-color: #cbd5e1; color: #475569; background: #fff; }
.badge-success { border-color: #86efac; color: #166534; background: #f0fdf4; }
.badge-error { border-color: #fecaca; color: #991b1b; background: #fef2f2; }
.badge-warning { border-color: #fde68a; color: #92400e; background: #fffbeb; }

.card {
  margin-bottom: 20px;
  border: 1px solid #e2e8f0;
  border-radius: 22px;
  padding: 24px;
  background: rgba(255, 255, 255, .95);
  box-shadow: 0 18px 48px rgba(15, 23, 42, .07);
  backdrop-filter: blur(14px);
}

.section-heading { margin-bottom: 18px; }
.section-heading p { margin: 7px 0 0; }
.step {
  display: inline-grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 9px;
  color: #fff;
  background: #4f46e5;
  font-size: .82rem;
  font-weight: 900;
}

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; }
.button {
  min-height: 44px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 10px 15px;
  color: #334155;
  background: #fff;
  font-weight: 750;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}
.button:hover:not(:disabled) {
  border-color: #818cf8;
  box-shadow: 0 8px 22px rgba(79, 70, 229, .12);
  transform: translateY(-1px);
}
.button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, .file-picker:focus-within {
  outline: 3px solid rgba(99, 102, 241, .25);
  outline-offset: 2px;
}
.button:disabled { opacity: .48; cursor: not-allowed; }
.button-primary { border-color: #4f46e5; color: #fff; background: #4f46e5; }
.button-danger-outline { border-color: #fecaca; color: #b91c1c; background: #fff; }
.button-small { min-height: 34px; padding: 6px 10px; font-size: .78rem; }

.recording-line {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
  color: #64748b;
}
.recording-line strong { margin-left: auto; color: #0f172a; font-variant-numeric: tabular-nums; }
.recording-indicator { width: 11px; height: 11px; border-radius: 50%; background: #cbd5e1; }
.recording-indicator.active {
  background: #ef4444;
  box-shadow: 0 0 0 7px rgba(239, 68, 68, .13);
  animation: pulse 1.2s infinite;
}
@keyframes pulse { 50% { opacity: .45; } }

.file-picker {
  display: grid;
  gap: 5px;
  margin-top: 18px;
  border: 1px dashed #a5b4fc;
  border-radius: 16px;
  padding: 18px;
  color: #3730a3;
  background: #eef2ff;
  font-weight: 800;
  cursor: pointer;
}
.file-picker small { color: #6366f1; font-weight: 600; }
.file-picker input { margin-top: 8px; color: #334155; font-weight: 600; }

.file-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 12px 14px;
  background: #f8fafc;
}
.file-info div { display: grid; gap: 3px; min-width: 0; }
.file-info strong, .file-info span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-info span { color: #64748b; font-size: .86rem; }
audio, video { width: 100%; margin-top: 16px; border-radius: 14px; background: #020617; }
video { max-height: 520px; object-fit: contain; }

.settings-grid { display: grid; gap: 16px; margin-bottom: 18px; }
.settings-grid-four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.settings-grid-three { grid-template-columns: 1.4fr 1fr 1fr; }
.settings-grid label { display: grid; align-content: start; gap: 8px; color: #334155; font-weight: 750; }
select, input[type="number"] {
  width: 100%;
  min-height: 44px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 9px 12px;
  color: #0f172a;
  background: #fff;
}
input[type="range"] { width: 100%; accent-color: #4f46e5; }
.range-row { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.range-row output {
  min-width: 48px;
  border-radius: 8px;
  padding: 5px 8px;
  color: #3730a3;
  background: #eef2ff;
  text-align: center;
  font-size: .84rem;
}
.field-help { margin-top: -4px; font-size: .76rem; font-weight: 500; }
.input-with-suffix { position: relative; }
.input-with-suffix input { padding-right: 36px; }
.input-with-suffix span { position: absolute; right: 12px; top: 50%; color: #64748b; transform: translateY(-50%); }

.progress-card {
  margin: 18px 0;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 13px;
  background: #f8fafc;
}
.progress-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 9px;
  color: #475569;
  font-size: .88rem;
  font-weight: 750;
}
.progress-track { height: 8px; overflow: hidden; border-radius: 999px; background: #e2e8f0; }
.progress-bar { width: 0%; height: 100%; border-radius: inherit; background: #4f46e5; transition: width 180ms linear; }
.progress-bar.indeterminate { width: 34%; animation: indeterminate 1.2s ease-in-out infinite; }
@keyframes indeterminate { from { transform: translateX(-120%); } to { transform: translateX(320%); } }

.speaker-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 18px;
}
.speaker-card {
  border: 1px solid #e2e8f0;
  border-left: 5px solid var(--speaker-color, #4f46e5);
  border-radius: 14px;
  padding: 13px;
  background: #fff;
}
.speaker-card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 9px; }
.speaker-card label { display: grid; gap: 6px; color: #64748b; font-size: .76rem; font-weight: 700; }
.speaker-card input {
  width: 100%;
  min-height: 38px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 7px 10px;
  color: #0f172a;
  background: #fff;
  font-weight: 700;
}
.speaker-stats { color: #64748b; font-size: .8rem; }

.segments-container { margin-top: 20px; }
.segments-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 10px; }
.segments-header span { color: #64748b; font-size: .84rem; }
.segments-list { display: grid; gap: 8px; max-height: 520px; overflow: auto; padding-right: 4px; }
.segment-row {
  display: grid;
  grid-template-columns: 122px minmax(140px, 190px) minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px solid #e2e8f0;
  border-left: 5px solid var(--speaker-color, #4f46e5);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
}
.segment-time { color: #475569; font-size: .8rem; font-variant-numeric: tabular-nums; }
.segment-speaker {
  width: 100%;
  min-height: 34px;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  padding: 5px 8px;
  color: #0f172a;
  background: #fff;
  font-weight: 700;
}
.segment-text { min-width: 0; color: #64748b; font-size: .84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.segment-text.has-text { color: #0f172a; }
.segment-actions { display: flex; gap: 6px; }
.segment-row.processing { box-shadow: 0 0 0 3px rgba(99, 102, 241, .15); }
.segment-row.error { border-color: #fecaca; }

.transcript-label { display: block; margin-bottom: 8px; color: #334155; font-weight: 800; }
textarea {
  width: 100%;
  min-height: 320px;
  resize: vertical;
  border: 1px solid #cbd5e1;
  border-radius: 16px;
  padding: 16px;
  color: #0f172a;
  background: #fff;
  line-height: 1.65;
}
.interim-text { min-height: 28px; margin-top: 10px; color: #6366f1; font-style: italic; line-height: 1.5; }

.notice {
  border: 1px solid #fde68a;
  border-radius: 18px;
  padding: 18px 20px;
  color: #713f12;
  background: #fffbeb;
}
.notice p { margin: 8px 0 0; color: #854d0e; }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(440px, calc(100% - 44px));
  border-radius: 13px;
  padding: 12px 15px;
  color: #fff;
  background: #0f172a;
  box-shadow: 0 16px 38px rgba(15, 23, 42, .26);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 920px) {
  .settings-grid-four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .segment-row { grid-template-columns: 110px minmax(130px, 170px) minmax(0, 1fr); }
  .segment-actions { grid-column: 1 / -1; justify-content: flex-end; }
}

@media (max-width: 720px) {
  .app-shell { width: min(100% - 20px, 1160px); padding-top: 24px; }
  .hero { flex-direction: column; }
  .badges { justify-content: flex-start; }
  .card { border-radius: 18px; padding: 18px; }
  .settings-grid-four, .settings-grid-three { grid-template-columns: 1fr; }
  .button { flex: 1 1 150px; }
  .file-info { align-items: stretch; flex-direction: column; }
  .segment-row { grid-template-columns: 1fr; }
  .segment-actions { grid-column: auto; justify-content: stretch; }
  .segment-actions .button { flex: 1; }
  .segment-text { white-space: normal; }
}

@media (prefers-color-scheme: dark) {
  :root { color: #e2e8f0; background: #020617; }
  body { background: radial-gradient(circle at top left, rgba(99, 102, 241, .18), transparent 36rem), #020617; }
  .card { border-color: #1e293b; background: rgba(15, 23, 42, .95); }
  .subtitle, .section-heading p, .field-help { color: #94a3b8; }
  .button, select, input[type="number"], textarea, .speaker-card input, .segment-speaker {
    border-color: #334155;
    color: #e2e8f0;
    background: #0f172a;
  }
  .recording-line strong { color: #e2e8f0; }
  .file-picker { border-color: #4f46e5; color: #c7d2fe; background: #1e1b4b; }
  .file-picker small { color: #a5b4fc; }
  .file-info, .progress-card { border-color: #334155; background: #0f172a; }
  .progress-track { background: #334155; }
  .speaker-card, .segment-row { border-color: #334155; background: #0f172a; }
  .segment-text.has-text { color: #e2e8f0; }
  .notice { border-color: #854d0e; background: #422006; }
  .notice, .notice p { color: #fde68a; }
  .badge-waiting { border-color: #475569; color: #cbd5e1; background: #0f172a; }
  .badge-success { border-color: #166534; color: #bbf7d0; background: #052e16; }
  .badge-error { border-color: #991b1b; color: #fecaca; background: #450a0a; }
  .badge-warning { border-color: #92400e; color: #fde68a; background: #422006; }
  .range-row output { color: #c7d2fe; background: #1e1b4b; }
}

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

.field-span-two {
  grid-column: 1 / -1;
}

.status-panel {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 13px 15px;
  color: #475569;
  background: #f8fafc;
}

.status-panel strong {
  color: #334155;
}

.api-result-meta {
  margin: 16px 0;
  border: 1px solid #c7d2fe;
  border-radius: 14px;
  padding: 12px 14px;
  color: #3730a3;
  background: #eef2ff;
  line-height: 1.5;
}

@media (max-width: 720px) {
  .settings-grid-two {
    grid-template-columns: 1fr;
  }

  .field-span-two {
    grid-column: auto;
  }

  .status-panel {
    flex-direction: column;
  }
}

@media (prefers-color-scheme: dark) {
  .status-panel {
    border-color: #334155;
    color: #94a3b8;
    background: #0f172a;
  }

  .status-panel strong {
    color: #e2e8f0;
  }

  .api-result-meta {
    border-color: #4338ca;
    color: #c7d2fe;
    background: #1e1b4b;
  }
}
