:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --text: #17181c;
  --muted: #6b6e78;
  --line: #e6e6e3;
  --accent: #17181c;
  --accent-text: #ffffff;
  --warn: #8a6d1f;
  --warn-bg: #fdf7e6;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1013;
    --surface: #17181c;
    --text: #f2f2f0;
    --muted: #adb1bb;
    --line: #2a2c32;
    --accent: #f2f2f0;
    --accent-text: #17181c;
    --warn: #e0c069;
    --warn-bg: #241f12;
  }
}

* { box-sizing: border-box; }

/* Системное выделение — насыщенно-синее, и на жёлтой плашке предупреждений
   оно выглядело грязно. Задаём своё: полупрозрачное, поверх любого фона
   читается одинаково. */
::selection {
  background: color-mix(in srgb, var(--text) 18%, transparent);
  color: inherit;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

main {
  /* Ширина под длину строки: примерно 80–90 знаков основного текста. Уже
     колонка на большом мониторе выглядит потерянной, шире — строка
     становится длинной и читать труднее. */
  max-width: 780px;
  margin: 0 auto;
  padding: 64px 28px 120px;
}

/* На очень широком экране даём ещё немного воздуха внутрь, а не по краям:
   в предпросмотре правится текст, и лишние 80 пикселей там полезнее
   пустых полей. */
@media (min-width: 1500px) {
  main { max-width: 880px; }
}
/* На мониторе шириной под два килопикселя колонка в 800 пикселей выглядит
   потерянной. Дальше расширять нельзя: строка основного текста перевалит
   за сотню знаков, и читать станет тяжелее, чем смотреть на поля. */
@media (min-width: 1800px) {
  main { max-width: 960px; }
}

.head { margin-bottom: 40px; }

h1 {
  margin: 0 0 10px;
  font-size: 42px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0 0 6px;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.lede { margin: 0; color: var(--muted); }

/* ---------- Загрузка ---------- */

.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 168px;
  padding: 24px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.drop:hover, .drop.over { border-color: var(--muted); }
.drop.over { background: color-mix(in srgb, var(--surface) 92%, var(--text)); }
.drop-title { font-weight: 500; }
.drop-hint { color: var(--muted); font-size: 15.5px; }

.step { margin-top: 36px; }
.step:first-of-type { margin-top: 0; }
.step-title {
  margin: 0 0 12px;
  font-size: 16.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.step .hint { margin: 0 0 12px; }
.step textarea { margin-top: 12px; }
/* Вторая зона — вспомогательная, поэтому ниже и визуально тише основной. */
.drop-small { min-height: 104px; }
.drop-small .drop-title { font-weight: 400; font-size: 15px; }

.files {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.files li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 15px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 15.5px;
}
.files li:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.files li:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.files li:only-child { border-radius: var(--radius); }
.files .size { color: var(--muted); white-space: nowrap; }

/* ---------- Поля ---------- */

.field { margin-top: 24px; }
.field label { display: block; margin-bottom: 8px; font-size: 14px; font-weight: 500; }
.opt { color: var(--muted); font-weight: 400; }

textarea, input {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  font-size: 16.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  resize: vertical;
}
textarea:focus, input:focus { outline: none; border-color: var(--muted); }
textarea::placeholder, input::placeholder { color: var(--muted); }

.more { margin-top: 20px; }
.more summary {
  cursor: pointer;
  font-size: 15.5px;
  font-weight: 500;
  color: var(--muted);
  list-style: none;
  padding: 4px 0;
}
.more summary::-webkit-details-marker { display: none; }
.more summary::before { content: '+'; margin-right: 8px; }
.more[open] summary::before { content: '–'; }
.hint { margin: 8px 0 14px; font-size: 15.5px; line-height: 1.5; color: var(--muted); }
.field .hint { margin: 8px 0 0; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

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

button, .primary, .ghost {
  font: inherit;
  font-size: 16.5px;
  font-weight: 500;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: opacity .15s ease;
}

.primary {
  display: block;
  width: 100%;
  margin-top: 28px;
  padding: 14px 20px;
  color: var(--accent-text);
  background: var(--accent);
  border: 1px solid var(--accent);
}
.primary:hover { opacity: .85; }
.primary:disabled { opacity: .3; cursor: not-allowed; }

.ghost {
  display: inline-block;
  padding: 13px 20px;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
}
.ghost:hover { border-color: var(--muted); }
.ghost.wide { display: block; width: 100%; margin-top: 20px; }

/* Неброская текстовая кнопка: предлагает попробовать, но не спорит за
   внимание с основным действием. */
.link {
  margin-top: 14px;
  padding: 0;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 16.5px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link:hover { color: var(--text); }
.link:disabled { opacity: .5; cursor: default; text-decoration: none; }
/* После загрузки кнопка превращается в подпись о том, что за пример взят. */
.link-done { text-align: left; line-height: 1.45; }

.note {
  margin: 14px 0 0;
  font-size: 14px;
  color: var(--warn);
  background: var(--warn-bg);
  padding: 12px 14px;
  border-radius: 10px;
}

/* ---------- Прогресс ---------- */

.progress { margin-top: 36px; }
.progress ol { margin: 0; padding: 0; list-style: none; }
.progress li {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 0;
  color: var(--muted);
  font-size: 16.5px;
  animation: rise .25s ease;
}
.progress li.current { color: var(--text); }
.progress li::before {
  content: '';
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--line);
  transform: translateY(-2px);
}
.progress li.done::before { background: var(--muted); }
.progress li.current::before {
  background: var(--text);
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

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

.result, .error { margin-top: 40px; animation: rise .3s ease; }
.result-head { margin-bottom: 20px; }
.actions { display: flex; gap: 10px; }
.actions .primary { margin-top: 0; flex: 1; padding: 13px 20px; }

.notice {
  margin: 20px 0 0;
  padding: 16px 18px;
  background: var(--warn-bg);
  border: 1px solid color-mix(in srgb, var(--warn) 25%, transparent);
  border-radius: var(--radius);
}
.notice-title {
  margin: 0 0 4px;
  font-size: 15.5px;
  font-weight: 600;
  color: var(--warn);
}
.notice-lede {
  margin: 0 0 12px;
  font-size: 15.5px;
  line-height: 1.45;
  color: var(--muted);
}
.warnings {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 16px;
  line-height: 1.5;
  color: var(--warn);
}
.warnings li { padding-left: 16px; position: relative; }
.warnings li::before { content: '•'; position: absolute; left: 2px; }
.warnings li + li { margin-top: 9px; }

/* Служебное сообщение — не предупреждение: рассказывает, как сервис
   отработал, и не требует от человека никаких действий. */
.quiet {
  margin: 12px 0 0;
  font-size: 15.5px;
  color: var(--muted);
}

.error p { color: var(--muted); }
.error .ghost { margin-top: 16px; }

@media (max-width: 560px) {
  main { padding: 48px 20px 80px; }
  h1 { font-size: 33px; }
  .grid { grid-template-columns: 1fr; }
  .actions { flex-direction: column; }
}

/* ---------- Поле, которое растёт под текст ---------- */

/* Обёртка — грид с одной ячейкой: в ней лежат само поле и невидимая копия
   его текста. Высоту диктует копия, поэтому поле всегда ровно по
   содержимому — без единой строчки JS и без пересчётов при изменении
   ширины. Ключевое условие: копия и поле должны иметь одинаковые шрифт,
   отступы и рамку, иначе высота разойдётся. */
.grow {
  display: grid;
  font-size: 17px;
  line-height: 1.55;
}
.grow > textarea,
.grow::after {
  grid-area: 1 / 1 / 2 / 2;
  font: inherit;
  padding: 11px 13px;
  border: 1px solid transparent;
  border-radius: 8px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  overflow: hidden;
}
.grow::after {
  content: attr(data-value) ' ';
  visibility: hidden;
}
.grow > textarea {
  width: 100%;
  color: var(--text);
  background: var(--surface);
  border-color: var(--line);
  resize: none;
}
.grow > textarea:focus { outline: none; border-color: var(--muted); }

/* ---------- Предпросмотр содержания ---------- */

.preview { margin-top: 40px; animation: rise .3s ease; }
.preview-head { margin-bottom: 20px; }
.preview-head h2 { margin-bottom: 6px; }

.section-card {
  margin-top: 16px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.section-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}
.section-num {
  flex: 0 0 auto;
  width: 24px;
  padding-top: 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
}
/* Заголовок раздела правится там же, где читается: отдельная форма
   редактирования для одной строки была бы лишним экраном. */
/* Заголовок правится там же, где читается: рамка появляется только при
   наведении, чтобы карточка не выглядела формой. */
.section-title {
  flex: 1 1 auto;
  font-size: 19.5px;
  font-weight: 600;
  line-height: 1.35;
}
.section-title > textarea,
.section-title::after { padding: 8px 10px; }
.section-title > textarea {
  background: transparent;
  border-color: transparent;
}
.section-title > textarea:hover { border-color: var(--line); }
.section-title > textarea:focus { border-color: var(--muted); }

.regen {
  flex: 0 0 auto;
  padding: 9px 13px;
  font-size: 14.5px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  white-space: nowrap;
}
.regen:hover:not(:disabled) { color: var(--text); border-color: var(--muted); }
.regen:disabled { opacity: .5; cursor: default; }

.block { margin-top: 12px; }
.block-kind {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
}
.block .grow { font-size: 17px; }

/* Таблица правится по ячейкам: переписывать её текстом означало бы
   гадать, где границы колонок. */
.block table { width: 100%; border-collapse: collapse; }
.block table .grow { font-size: 15.5px; line-height: 1.45; }
.block table .grow > textarea,
.block table .grow::after { padding: 9px 10px; border-radius: 6px; }
.block table th, .block table td {
  padding: 0 3px 3px 0;
  vertical-align: top;
}
.block table th .grow { font-weight: 600; }

.section-card.busy { opacity: .55; pointer-events: none; }

/* ---------- Правка структуры ---------- */

/* Кнопки действий держатся тихо, пока на карточку не навели мышь: иначе
   страница превращается в панель управления и за ней не видно текста. */
.icon-btn {
  padding: 4px 8px;
  font-size: 14px;
  line-height: 1.2;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
}
.icon-btn:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--line);
}
.icon-btn:disabled { opacity: .28; cursor: default; }

.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 26px;
}
.block-head .block-kind { margin-bottom: 0; }

.block-tools {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity .12s ease;
}
.section-card:hover .block-tools,
.block:focus-within .block-tools { opacity: 1; }

/* Кнопка удаления раздела стоит рядом с «Переписать», но выглядит тише:
   это действие, которое почти всегда делают один раз и осознанно. */
.section-drop {
  flex: 0 0 auto;
  align-self: flex-start;
  margin-top: 2px;
  opacity: 0;
  transition: opacity .12s ease;
}
.section-card:hover .section-drop { opacity: 1; }

/* Удаление колонки — над самой колонкой, чтобы было видно, что исчезнет. */
.col-bar {
  display: flex;
  justify-content: flex-end;
  height: 22px;
}
.col-bar .icon-btn { padding: 2px 5px; font-size: 12px; }
.block table th .col-bar { opacity: 0; transition: opacity .12s ease; }
.section-card:hover .block table th .col-bar { opacity: 1; }

.row-tools { width: 34px; vertical-align: middle; }
.row-tools .icon-btn { padding: 4px 6px; font-size: 12px; opacity: 0; transition: opacity .12s ease; }
.section-card:hover .row-tools .icon-btn { opacity: 1; }

.table-tools {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

/* Список типов блоков: появляется только под наведённой карточкой, иначе
   девять кнопок под каждым разделом забивают собой весь экран. */
.adder {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  opacity: 0;
  transition: opacity .12s ease;
}
.section-card:hover .adder,
.section-card:focus-within .adder { opacity: 1; }
.adder .icon-btn { font-size: 13.5px; }

.add-section { margin-top: 18px; }
