/* ═══════════════════════════════════════════════════════════════════
   Vocal Splitter — оформлення.
   Темна тема, один акцентний колір, жодних зовнішніх ресурсів:
   шрифт системний, іконки — інлайновий SVG у розмітці.
   ═══════════════════════════════════════════════════════════════════ */

:root {
  /* color-scheme: dark вмикає темні системні контроли — зокрема
     нативний плеєр <audio>, який інакше був би світлою плямою. */
  color-scheme: dark;

  --bg:          #0b0e14;
  --surface:     #141924;
  --line:        rgba(255, 255, 255, 0.08);
  --line-hi:     rgba(255, 255, 255, 0.18);

  --text:        #e7ebf2;
  --text-dim:    #97a1b3;
  --text-faint:  #6a7385;

  --accent:      #7aa2f7;
  --accent-hi:   #9dbaff;
  --accent-soft: rgba(122, 162, 247, 0.13);

  --ok:   #6ee7a8;
  --warn: #f2c26b;
  --bad:  #f58a8a;

  --radius:    16px;
  --radius-sm: 10px;
  --stage-w:   680px;

  --ease: cubic-bezier(0.22, 0.7, 0.28, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0 20px 64px;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* Ледь помітне світіння вгорі — щоб плаский темний фон мав глибину. */
body::before {
  content: "";
  position: fixed;
  inset: -20% 0 auto;
  height: 60vh;
  background: radial-gradient(60% 100% at 50% 0%,
              rgba(122, 162, 247, 0.10), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* Весь вміст лежить над фоновим світінням. */
.topbar, .stage { position: relative; z-index: 1; }

[hidden] { display: none !important; }

/* ── Шапка ─────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  flex-wrap: wrap;
  max-width: var(--stage-w);
  margin: 0 auto;
  padding: 22px 0 40px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand__mark { width: 22px; height: 22px; color: var(--accent); }
.brand__name { font-size: 15px; }

/* Індикатор рушія. Колір крапки задають модифікатори engine--* з JS. */
.engine {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.02);
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
}

.engine__text { overflow: hidden; text-overflow: ellipsis; }

.engine__dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
}

.engine--pending .engine__dot { animation: pulse 1.4s ease-in-out infinite; }
.engine--gpu     .engine__dot { background: var(--ok); box-shadow: 0 0 8px rgba(110, 231, 168, 0.5); }
.engine--cpu     .engine__dot { background: var(--warn); }
.engine--offline .engine__dot { background: var(--bad); }
.engine--offline { color: var(--bad); border-color: rgba(245, 138, 138, 0.28); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* ── Сцена й екрани ────────────────────────────────────────────────── */

.stage {
  max-width: var(--stage-w);
  margin: 0 auto;
}

/* Кожен стан — окрема section. Видимий рівно один; перемикає їх JS
   атрибутом hidden. Поява елемента з display:none щоразу перезапускає
   анімацію — саме тому перехід між станами плавний без зайвого коду. */
.screen {
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: screen-in 340ms var(--ease) both;
}

@keyframes screen-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

.title {
  margin: 0;
  font-size: clamp(24px, 5vw, 32px);
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.title--sm {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: clamp(20px, 4vw, 25px);
}

.title__tick { width: 22px; height: 22px; color: var(--ok); flex: none; }

.lead {
  margin: -8px 0 6px;
  color: var(--text-dim);
  font-size: 15px;
}

.track-name {
  margin: -10px 0 0;
  color: var(--text-dim);
  font-size: 14px;
  overflow-wrap: anywhere;
}

/* ── Зона перетягування ────────────────────────────────────────────── */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 52px 24px;
  border: 1.5px dashed var(--line-hi);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.015);
  text-align: center;
  cursor: pointer;
  transition: border-color 180ms var(--ease),
              background-color 180ms var(--ease),
              transform 180ms var(--ease);
}

.dropzone:hover {
  border-color: rgba(122, 162, 247, 0.45);
  background: rgba(255, 255, 255, 0.03);
}

/* Клас вішає JS, поки файл висить над зоною. */
.dropzone.is-drag {
  border-color: var(--accent);
  border-style: solid;
  background: var(--accent-soft);
  transform: scale(1.012);
}

.dropzone__icon {
  width: 34px;
  height: 34px;
  margin-bottom: 6px;
  color: var(--accent);
}

.dropzone__title { margin: 0; font-size: 17px; font-weight: 500; }
.dropzone__hint  { margin: 0; color: var(--text-dim); font-size: 14px; }

.dropzone__formats {
  margin: 10px 0 0;
  color: var(--text-faint);
  font-size: 12.5px;
  letter-spacing: 0.01em;
}

/* ── Обраний файл ──────────────────────────────────────────────────── */

.picked {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.picked__icon { width: 24px; height: 24px; flex: none; color: var(--accent); }

.picked__meta {
  display: flex;
  flex-direction: column;
  min-width: 0;          /* без цього довга назва розпирає флекс-рядок */
  flex: 1;
}

.picked__name {
  font-size: 14.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.picked__size { color: var(--text-faint); font-size: 12.5px; }

/* ── Вибір моделі ──────────────────────────────────────────────────── */

/* fieldset/legend узяті заради доступності: екранний читач озвучує
   «Separation model» як назву групи перемикачів. Дефолтну рамку й
   відступи браузера при цьому доводиться скидати вручну. */
.models {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.models__legend {
  padding: 0 0 8px;
  color: var(--text-dim);
  font-size: 13px;
  letter-spacing: 0.02em;
}

.models__list {
  display: grid;
  gap: 8px;
}

.model {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: border-color 0.16s var(--ease), background 0.16s var(--ease);
}

.model:hover { border-color: var(--line-hi); }

/* Обраний пункт підсвічуємо цілою карткою, а не самим кружечком:
   так видно, що клікати можна будь-де по рядку. */
.model:has(input:checked) {
  border-color: rgba(122, 162, 247, 0.55);
  background: var(--accent-soft);
}

.model:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.model input {
  margin: 3px 0 0;
  accent-color: var(--accent);
  flex: none;
}

.model__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.model__label { font-size: 14.5px; }

.model__hint {
  color: var(--text-faint);
  font-size: 12.5px;
  line-height: 1.4;
}

/* Рядок «Model: ...» на екранах обробки й результату. */
/* Стоїть одразу під назвою треку, тому від'ємний відступ гасить
   міжелементний gap екрана — інакше рядок «відпливав» би вниз. */
.model-line {
  margin: -14px 0 0;
  color: var(--text-faint);
  font-size: 13px;
  overflow-wrap: anywhere;
}

/* ── Повідомлення ──────────────────────────────────────────────────── */

.notice {
  margin: 0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}

.notice--error {
  border: 1px solid rgba(245, 138, 138, 0.3);
  background: rgba(245, 138, 138, 0.08);
  color: #ffc9c9;
}

/* Нейтральне повідомлення — наприклад, після скасування обробки. */
.notice--info {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-dim);
}

.hint {
  margin: 0;
  padding: 12px 14px;
  border-left: 2px solid var(--line-hi);
  color: var(--text-dim);
  font-size: 13.5px;
}

/* ── Оцінка вхідного файлу ─────────────────────────────────────────── */

/* Смужка збоку — єдине, що відрізняє три рівні вердикту. Ніяких червоних
   плашок на весь екран: це підказка, а не аварія, і розділення однаково
   йде своїм ходом. */
.quality {
  margin: 0;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--text-faint);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  text-align: left;
}

.quality--good { border-left-color: var(--ok); }
.quality--fair { border-left-color: var(--warn); }
.quality--weak { border-left-color: var(--bad); }

.quality__headline {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.quality--good .quality__label { color: var(--ok); }
.quality--fair .quality__label { color: var(--warn); }
.quality--weak .quality__label { color: var(--bad); }

.quality__summary {
  margin: 4px 0 0;
  color: var(--text-faint);
  font-size: 12.5px;
}

.quality__notes {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.55;
}

.quality__notes li + li { margin-top: 6px; }

/* ── Кнопки ────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 160ms var(--ease),
              border-color 160ms var(--ease),
              color 160ms var(--ease),
              opacity 160ms var(--ease);
}

.btn svg { width: 17px; height: 17px; flex: none; }

.btn--primary { background: var(--accent); color: #0b0e14; }
.btn--primary:hover:not(:disabled) { background: var(--accent-hi); }

.btn--soft {
  background: var(--accent-soft);
  border-color: rgba(122, 162, 247, 0.25);
  color: var(--accent-hi);
}
.btn--soft:hover { background: rgba(122, 162, 247, 0.2); }

.btn--ghost {
  background: transparent;
  border-color: var(--line-hi);
  color: var(--text-dim);
}
.btn--ghost:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }

.btn--wide { width: 100%; }
.btn--sm { padding: 8px 14px; font-size: 13.5px; }

/* Вимкнена кнопка не просто бліда: вона втрачає акцентний фон, щоб її не
   плутали з активною й одразу було видно — спершу треба обрати файл. */
.btn:disabled {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--line);
  color: var(--text-faint);
  cursor: not-allowed;
}

/* Обводка тільки для клавіатури — миша її не викликає. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* Кнопки, що завершують екран, не мають розтягуватись на всю ширину. */
#btn-cancel, #btn-again, #btn-retry { align-self: flex-start; }

/* ── Прогрес ───────────────────────────────────────────────────────── */

.progress {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.progress__fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-hi));
  /* Плавно доїжджає до нового значення, а не стрибає щосекунди. */
  transition: width 500ms var(--ease);
}

.progress__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  margin-top: -8px;
  font-size: 14px;
}

.progress__message { color: var(--text-dim); }

.progress__percent {
  font-variant-numeric: tabular-nums;  /* цифри не сіпають рядок */
  color: var(--text);
  font-weight: 500;
}

.elapsed {
  margin: -10px 0 0;
  color: var(--text-faint);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* ── Результат ─────────────────────────────────────────────────────── */

.stems {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.stem {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

/* Запасний текст, коли браузер не грає обраний формат. Доріжку все одно
   можна завантажити, тому картка не повинна виглядати зламаною. */
.stem__no-preview {
  margin: 0;
  padding: 12px 14px;
  border: 1px dashed var(--line-hi);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13px;
}

.stem__title {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.stem__title svg { width: 18px; height: 18px; color: var(--accent); }

.stem audio {
  width: 100%;
  height: 38px;
  border-radius: var(--radius-sm);
}

/* ── Екран помилки ─────────────────────────────────────────────────── */

.screen--error { align-items: flex-start; }

.error__icon { width: 34px; height: 34px; color: var(--bad); }

.error__text {
  margin: 0;
  padding: 14px 16px;
  border: 1px solid rgba(245, 138, 138, 0.25);
  border-radius: var(--radius-sm);
  background: rgba(245, 138, 138, 0.07);
  color: #ffd4d4;
  font-size: 14.5px;
  overflow-wrap: anywhere;
  width: 100%;
}

/* ── Вузькі екрани (до 560 px) ─────────────────────────────────────── */

@media (max-width: 560px) {
  body { padding: 0 16px 48px; }
  .topbar { padding: 18px 0 30px; }
  .dropzone { padding: 38px 18px; }
  .stems { grid-template-columns: 1fr; }
  #btn-cancel, #btn-again, #btn-retry { align-self: stretch; }

  /* На вузькому кнопка «Інший файл» їде під назву файлу. */
  .picked { flex-wrap: wrap; }
  .picked .btn { width: 100%; }
}

/* ── Повага до налаштування «менше руху» ───────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .dropzone.is-drag { transform: none; }
}
