/*
 * Страница белая, чёрный текст, оранжевый — только там, где он что-то значит:
 * выбранный логотип, полоса сборки, ошибка. Цвет текста идёт по смыслу, а не
 * по красоте: заголовок и имя файла — чёрные, обычная речь — серая, подсказки
 * и сноски — светло-серые. Шрифт Geist, начертание Medium.
 */

/* Начертание одно на всю страницу — Medium. Разницу в важности показывает
   цвет, а не жирность. */
@font-face {
  font-family: 'Geist';
  src: url('/fonts/Geist-Medium.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
}

:root {
  --paper: #ffffff;
  --ink: #0b0b0b;
  --ink-2: #5c5c5c;
  --ink-3: #a8a8a8;
  --line: #ebebeb;
  --soft: #f6f6f6;
  --accent: #fd6027;
  --accent-soft: #fff2ec;
  /* Красный — только для отказа, который человек должен заметить сразу:
     слишком большое видео. Оранжевый рядом с ним читался бы как акцент. */
  --danger: #e5383b;
  --radius: 26px;
  --radius-sm: 18px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

/* Спрятанное прячем сильнее собственного `display` этих блоков: почти у всех
   он `flex`, а он старше правила браузера для `hidden`. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  background: var(--paper);
}

body {
  font-family: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-weight: 500;
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink-2);
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}

/* Иконки Gravity UI: одна сетка 16×16, цвет берут у текста. */
.i {
  width: 1em;
  height: 1em;
  flex: none;
  fill: currentColor;
}

.i.big {
  width: 26px;
  height: 26px;
}

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

.top {
  padding: 22px 20px 0;
  display: flex;
  justify-content: center;
}

.wordmark {
  display: block;
  height: 28px;
  width: auto;
}

.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 40px 20px 72px;
}

.hero {
  text-align: center;
  padding-bottom: 8px;
}

h1 {
  margin: 0 auto;
  /* Заголовок длинный, и ему важнее читаться строками в меру, чем быть
     крупным: отсюда и предел по ширине, и потолок кегля пониже. */
  max-width: 15em;
  font-size: clamp(28px, 5.6vw, 44px);
  line-height: 1.08;
  letter-spacing: -0.035em;
  font-weight: 500;
  color: var(--ink);
}

.lead {
  margin: 18px auto 0;
  max-width: 30em;
  font-size: 17px;
  color: var(--ink-2);
}

/* Плашка строчная, чтобы встать по центру под описанием и быть не шире
   своего текста; на узком экране текст внутри переносится. */
.too-big {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  margin: 22px 0 0;
  padding: 12px 18px;
  border: 1.5px solid rgb(229 56 59 / 0.35);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 15px;
  line-height: 1.35;
  text-align: left;
}

.too-big .i {
  font-size: 18px;
}

.step {
  margin-top: 56px;
}

.step-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 16px;
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--soft);
  color: var(--ink-3);
  font-size: 14px;
}

.step-title.done .num {
  background: var(--accent);
  color: #fff;
}

.hint {
  margin: -6px 0 18px;
  font-size: 14px;
  color: var(--ink-3);
}

/* ── Видео ─────────────────────────────────────────────────────────────── */

.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 44px 24px;
  border: 1.5px dashed #dcdcdc;
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink-3);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

/*
 * Само поле выбора файла не прячем, а уводим с глаз: спрятанное `hidden`
 * выпадает из обхода по Tab, и до зоны загрузки нельзя было бы добраться
 * с клавиатуры. Открывать диалог ему помогает `label` вокруг — своего
 * обработчика на клик не нужно, иначе диалог открывался бы дважды.
 */
.drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.drop:hover,
.drop:focus-within {
  border-color: var(--ink-3);
  background: var(--soft);
}

.drop.over {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.drop-main {
  margin-top: 8px;
  font-size: 17px;
  color: var(--ink);
}

.drop.over .drop-main {
  color: var(--accent);
}

.drop-sub {
  font-size: 14px;
}

.picked {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.picked-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 18px;
}

.picked-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.picked-name {
  font-weight: 500;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.picked-note {
  font-size: 14px;
  color: var(--ink-3);
}

.icon-button {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-3);
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.icon-button:hover {
  background: var(--soft);
  color: var(--ink);
}

/* ── Логотипы ──────────────────────────────────────────────────────────── */

.logos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 16px 12px;
}

.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-3);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

/* У готовых логотипов кружок — просто картинка, у своего это кнопка:
   сбрасываем ей всё, что браузер рисует кнопкам сам. */
.logo-face {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--soft);
  color: inherit;
  font: inherit;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--line) inset;
  transition: box-shadow 0.15s, transform 0.15s;
}

.logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.logo:hover .logo-face {
  transform: translateY(-2px);
}

.logo.own .logo-face {
  background: var(--paper);
  box-shadow: 0 0 0 1.5px #dcdcdc inset;
  font-size: 20px;
}

.logo.chosen .logo-face {
  box-shadow: 0 0 0 2.5px var(--accent);
}

.logo.chosen {
  color: var(--ink);
}

.logo.chosen .logo-face::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 4px var(--paper) inset;
}

/*
 * Подпись есть только у плитки своей картинки, и это кнопка: ею загружают
 * картинку, а потом меняют. В два слова, поэтому даём ей перенестись на
 * вторую строку, а не обрезаться многоточием.
 */
.logo-name {
  max-width: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 13px;
  line-height: 1.25;
  cursor: pointer;
}

.logo-name:hover {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ── Кнопки ────────────────────────────────────────────────────────────── */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 15px 26px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 16px;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
}

.button.primary {
  background: var(--ink);
  color: #fff;
}

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

.button.ghost {
  background: var(--soft);
  color: var(--ink);
}

.button.ghost:hover {
  background: #ededed;
}

.button:disabled {
  background: var(--soft);
  color: var(--ink-3);
  cursor: default;
}

.button.wide {
  width: 100%;
  padding: 18px 26px;
  font-size: 17px;
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

/* ── Добавки к ролику ──────────────────────────────────────────────────── */

.options {
  display: grid;
  gap: 16px;
  margin-bottom: 24px;
}

/* Строка флажка — опора для подсказки: та встаёт под строкой во всю её
   ширину и не вылезает за край экрана, где бы ни стоял вопросик. */
.option {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.option-check {
  flex: none;
  cursor: pointer;
}

/* Родной флажок прячем, но оставляем в строю: по нему ходят с клавиатуры и
   его читает экранный диктор. Видно нарисованный рядом. */
.option-check input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.option-box {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1.5px solid #d6d6d6;
  border-radius: 8px;
  background: var(--paper);
  color: #fff;
  font-size: 14px;
  transition: background 0.15s, border-color 0.15s;
}

.option-box .i {
  opacity: 0;
  transition: opacity 0.15s;
}

.option:has(label:hover) .option-box {
  border-color: var(--ink-3);
}

.option-check input:checked + .option-box {
  border-color: var(--accent);
  background: var(--accent);
}

.option-check input:checked + .option-box .i {
  opacity: 1;
}

.option-check input:focus-visible + .option-box {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Подпись, плашка и вопросик идут одной строкой, а на узком экране плашка
   с вопросиком переносятся — и встают под текстом, а не под квадратиком.
   Все трое ростом в квадратик, иначе строка вышла бы выше него, и квадратик
   съехал бы с первой строки текста. */
.option-words {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}

.option-name {
  color: var(--ink);
  line-height: 24px;
  cursor: pointer;
}

.option-boost {
  padding: 0 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  line-height: 24px;
  white-space: nowrap;
  cursor: pointer;
}

/* Пока ролик собирается, добавки уже уехали в заказ. */
.option:has(input:disabled) label {
  opacity: 0.5;
  cursor: default;
}

.option-help {
  position: relative;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin-left: -4px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-3);
  font-size: 18px;
  cursor: help;
  transition: color 0.15s;
}

/* Значок маленький, а попадать по нему пальцем: нажимается поле вокруг. */
.option-help::before {
  content: '';
  position: absolute;
  inset: -10px;
}

.option-help:hover,
.option-help[aria-expanded='true'] {
  color: var(--ink);
}

.option-tip {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  right: 0;
  z-index: 10;
  margin: 0;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.18);
}

/* ── Сборка ────────────────────────────────────────────────────────────── */

.working {
  margin-top: 18px;
}

.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--soft);
  overflow: hidden;
}

.bar-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.3s ease-out;
}

/* Пока ffmpeg не сказал, докуда дошёл, полоса ходит сама: молчащая
   полоса читается как зависшая. */
.bar.unknown .bar-fill {
  width: 40%;
  animation: slide 1.4s ease-in-out infinite;
}

@keyframes slide {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(250%);
  }
}

.working-text {
  margin: 10px 0 0;
  font-size: 14px;
  color: var(--ink-3);
}

.failed {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 0;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 15px;
}

/* ── Ссылка на ролик ───────────────────────────────────────────────────── */

.share {
  margin-top: 18px;
  padding: 18px 20px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.share-why {
  display: flex;
  gap: 10px;
  margin: 0 0 14px;
  font-size: 14px;
  color: var(--ink-2);
}

/* Строка длинная и на телефоне переносится: значок держим у первой строки,
   а не посередине всего абзаца. */
.share-why .i {
  flex: none;
  margin-top: 3px;
}

.share-note {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--ink-3);
}

.share-row {
  display: flex;
  gap: 10px;
}

/* Ссылка лежит в поле, а не в строке текста: так её выделяет один клик,
   и так она копируется там, где браузер не дал доступ к буферу обмена. */
.share-link {
  flex: 1 1 auto;
  min-width: 0;
  height: 46px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  font: inherit;
  color: var(--ink);
  text-overflow: ellipsis;
}

.share-link:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Результат ─────────────────────────────────────────────────────────── */

.result {
  margin-top: 56px;
}

#player {
  display: block;
  margin: 0 auto;
  /* Размер берём у самого ролика: вертикальному ни к чему широкая рамка
     с чёрными полями по бокам. */
  max-width: 100%;
  max-height: 72vh;
  border-radius: var(--radius);
  background: #000;
}

/* ── Обрезка ───────────────────────────────────────────────────────────── */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(8px);
}

.sheet-card {
  width: min(560px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.12);
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.sheet-head h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 19px;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.stage {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--soft);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
}

.stage img {
  display: block;
  max-width: 100%;
  max-height: min(56vh, 420px);
  pointer-events: none;
}

/* Затемнение вокруг рамки — её же тенью: так дырка в затемнении всегда
   ровно там, где рамка, и второй элемент двигать не нужно. */
.frame {
  position: absolute;
  box-shadow: 0 0 0 9999px rgba(255, 255, 255, 0.74);
  outline: 2px solid var(--accent);
  cursor: grab;
}

.frame:active {
  cursor: grabbing;
}

.grip {
  position: absolute;
  width: 16px;
  height: 16px;
  background: var(--paper);
  border: 2px solid var(--accent);
  border-radius: 5px;
}

.grip.nw {
  top: -9px;
  left: -9px;
  cursor: nwse-resize;
}

.grip.ne {
  top: -9px;
  right: -9px;
  cursor: nesw-resize;
}

.grip.sw {
  bottom: -9px;
  left: -9px;
  cursor: nesw-resize;
}

.grip.se {
  bottom: -9px;
  right: -9px;
  cursor: nwse-resize;
}

@media (max-width: 520px) {
  .page {
    padding-top: 28px;
  }

  /* На телефоне логотипы встают по четыре в ряд: девять кругов размером
     с палец занимают три экрана, а выбирать из них надо взглядом. */
  .logos {
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  }

  .step {
    margin-top: 44px;
  }

  .drop {
    padding: 34px 18px;
  }

  .buttons .button {
    flex: 1 1 100%;
  }

  /* Ссылка и кнопка в одну строку на телефоне не встают: от ссылки осталась
     бы пара знаков. Пусть кнопка идёт под ней, во всю ширину. */
  .share-row {
    flex-direction: column;
  }
}
