:root {
  --bg: #fbfbfd;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e5e5ea;
  --blue: #0071e3;
  --blue-hover: #0077ed;
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9500;
  --radius: 18px;
  --shadow: 0 2px 8px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --text: #f5f5f7;
    --muted: #a1a1a6;
    --line: #38383a;
    --blue: #0a84ff;
    --blue-hover: #409cff;
    --shadow: 0 2px 8px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Helvetica Neue", "Inter", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.47;
  letter-spacing: -0.011em;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px 100px; }

h1 { font-size: 40px; font-weight: 700; letter-spacing: -0.021em; margin: 0; }
h2 { font-size: 24px; font-weight: 600; letter-spacing: -0.014em; margin: 0; }
h3 { font-size: 19px; font-weight: 600; margin: 0; }

.subtitle { color: var(--muted); font-size: 17px; margin: 6px 0 0; }

header.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 0 26px; gap: 16px; flex-wrap: wrap;
}

.badge {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 980px; padding: 9px 16px; font-size: 15px;
  font-weight: 500; box-shadow: var(--shadow);
}
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.badge .dot.bad { background: var(--red); }

.card {
  background: var(--surface); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow); margin-bottom: 18px;
  border: 1px solid var(--line);
}
.card h2 { margin-bottom: 4px; }
.card .hint { color: var(--muted); font-size: 15px; margin: 0 0 18px; }

label.field { display: block; font-size: 15px; color: var(--muted); margin: 0 0 8px; font-weight: 500; }

textarea, input[type="text"], input[type="password"] {
  width: 100%; padding: 14px 16px; font: inherit; font-size: 17px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; resize: vertical;
  transition: border-color .2s, box-shadow .2s;
}
textarea:focus, input:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(0,113,227,0.12);
}
textarea { min-height: 110px; line-height: 1.5; }

button {
  font: inherit; font-size: 17px; font-weight: 500; cursor: pointer;
  border: none; border-radius: 12px; padding: 14px 22px;
  transition: transform .12s ease, opacity .2s, background .2s;
}
button:active:not(:disabled) { transform: scale(0.98); }
button:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blue-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.btn-secondary:hover:not(:disabled) { background: var(--bg); }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: 8px 14px; font-size: 14px; border-radius: 9px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

.drop {
  border: 2px dashed var(--line); border-radius: 14px;
  padding: 40px 24px; text-align: center; cursor: pointer;
  transition: border-color .2s, background .2s;
}
.drop:hover, .drop.over { border-color: var(--blue); background: rgba(0,113,227,0.04); }
.drop .big { font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.drop .small { color: var(--muted); font-size: 15px; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600;
  padding: 4px 11px; border-radius: 980px; }
.pill.queued { background: rgba(0,113,227,0.12); color: var(--blue); }
.pill.running { background: rgba(0,113,227,0.12); color: var(--blue); }
.pill.done { background: rgba(52,199,89,0.15); color: var(--green); }
.pill.failed { background: rgba(255,59,48,0.13); color: var(--red); }

.progress { height: 6px; background: var(--line); border-radius: 980px; overflow: hidden; margin: 14px 0; }
.progress > div { height: 100%; background: var(--blue); border-radius: 980px; transition: width .4s ease; }

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

.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.tile .pic { aspect-ratio: 1; background: var(--bg); display: flex; align-items: center; justify-content: center;
  position: relative; cursor: pointer; overflow: hidden; }
.tile .pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .pic .ph { color: var(--muted); font-size: 13px; padding: 10px; text-align: center; }
.tile .meta { padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tile .nm { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .bar { height: 3px; background: var(--line); overflow: hidden; }
.tile .bar > div { height: 100%; background: var(--blue); animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex;
  align-items: center; justify-content: center; padding: 24px; z-index: 100; }
.modal .box { background: var(--surface); border-radius: 18px; padding: 22px; max-width: 860px;
  max-height: 88vh; overflow: auto; width: 100%; }
.modal .box img { width: 100%; border-radius: 12px; display: block; }

table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 11px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }

.row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.big-num { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.hidden { display: none !important; }

.toast { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%);
  background: rgba(28,28,30,.94); color: #fff; padding: 13px 22px; border-radius: 980px;
  font-size: 15px; z-index: 200; box-shadow: 0 8px 28px rgba(0,0,0,.3); max-width: 90vw; }

.tabs { display: inline-flex; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 3px; margin-bottom: 18px; gap: 3px; }
.tabs button { padding: 8px 18px; font-size: 15px; border-radius: 9px; background: transparent; color: var(--muted); }
.tabs button.on { background: var(--text); color: var(--bg); }

.empty { text-align: center; padding: 50px 20px; color: var(--muted); }

.overlay { position: fixed; inset: 0; background: rgba(250,250,252,.82);
  backdrop-filter: blur(20px); display: flex; align-items: center; justify-content: center;
  z-index: 150; flex-direction: column; gap: 16px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line);
  border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  h1 { font-size: 30px; }
  .card { padding: 18px; border-radius: 15px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 11px; }
}

/* --- Сравнение «до / после» в плитке --- */

.compare {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: ew-resize;
  touch-action: pan-y;
}

.compare img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Поверх «после» кладём «до» и обрезаем по ползунку. */
.compare-before {
  z-index: 2;
}

.compare-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
  z-index: 3;
  pointer-events: none;
}

.compare-handle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.compare-handle::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-left: 2px solid #6e6e73;
  border-bottom: 2px solid #6e6e73;
  transform: rotate(45deg);
  z-index: 1;
}

.compare-tag {
  position: absolute;
  bottom: 8px;
  z-index: 4;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 3px 8px;
  border-radius: 980px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.compare-tag.left { left: 8px; }
.compare-tag.right { right: 8px; }

.tile .pic:hover .compare-tag,
.compare:hover .compare-tag {
  opacity: 1;
}

/* --- Промт: два пресета и кнопка «плюс» --- */

.prompt-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 15px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 980px;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}

.chip:hover { border-color: var(--blue); }

.chip.on {
  color: var(--blue);
  border-color: var(--blue);
  background: rgba(0, 113, 227, 0.08);
}

.chip.mine::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: .55;
}

/* Кнопка «плюс»: заметная, но не кричащая. */
.chip.add {
  width: 36px;
  height: 36px;
  padding: 0;
  justify-content: center;
  font-size: 19px;
  font-weight: 400;
  color: var(--blue);
  border-style: dashed;
}

.chip.add:hover { background: rgba(0, 113, 227, 0.08); }

.chip-x {
  margin-left: 2px;
  font-size: 16px;
  line-height: 1;
  opacity: .4;
  padding: 0 2px;
  border-radius: 50%;
}

.chip:hover .chip-x { opacity: .8; }
.chip-x:hover { opacity: 1; color: var(--red); }

/* Редактор своего промта — появляется по кнопке «плюс». */

.editor {
  margin-top: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
}

.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.editor-head h3 { margin: 0; }

/* Крестик очистки — внутри рамки, справа сверху. Появляется, когда что-то выбрано. */

.drop { position: relative; }

.drop-clear {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  border-radius: 50%;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease, background .15s ease, color .15s ease;
}

.drop.filled .drop-clear {
  opacity: 1;
  pointer-events: auto;
}

.drop-clear:hover {
  color: var(--red);
  background: rgba(255, 59, 48, 0.1);
}
