*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:      #0d0d0d;
  --surface: #1a1a1a;
  --border:  #2a2a2a;
  --accent:  #7c3aed;
  --accent2: #a855f7;
  --text:    #e8e8e8;
  --muted:   #888;
  --green:   #22c55e;
  --yellow:  #eab308;
  --red:     #ef4444;
  --radius:  10px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

/* ── header ── */
header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-size: 17px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.3px;
  white-space: nowrap;
}

nav { display: flex; gap: 4px; }

.tab {
  padding: 6px 16px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tab:hover  { background: var(--border); color: var(--text); }
.tab.active { background: var(--accent); color: #fff; }

/* ── content ── */
main { padding: 24px; max-width: 1400px; margin: 0 auto; }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── toolbar ── */
.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.toolbar input[type=search],
.toolbar select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
}
.toolbar input[type=search] { flex: 1; min-width: 200px; }
.toolbar input[type=search]:focus,
.toolbar select:focus { border-color: var(--accent); }

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

/* ── card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color .2s;
}
.card:hover { border-color: #444; }

.card-media {
  background: #111;
  aspect-ratio: 16/9;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.card-media video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
}
.card-media .placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.card-body { padding: 12px; flex: 1; display: flex; flex-direction: column; gap: 8px; }

.card-prompt {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 99px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.cost-badge      { background: rgba(34,197,94,.12);  color: #4ade80; font-weight: 700; }
.badge-done      { background: rgba(34,197,94,.15);  color: var(--green); }
.badge-generating{ background: rgba(234,179,8,.15);  color: var(--yellow); }
.badge-error     { background: rgba(239,68,68,.15);  color: var(--red); }
.badge-pending   { background: rgba(136,136,136,.15); color: var(--muted); }
.badge-model     { background: rgba(124,58,237,.15); color: var(--accent2); }

.card-date { font-size: 11px; color: var(--muted); margin-left: auto; }

.card-comment {
  display: flex;
  gap: 6px;
  align-items: flex-start;
}
.card-comment textarea {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  padding: 6px 8px;
  resize: none;
  height: 48px;
  font-family: inherit;
  outline: none;
}
.card-comment textarea:focus { border-color: var(--accent); }

.card-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--border); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); border-color: var(--accent2); }
.btn-danger:hover { background: rgba(239,68,68,.15); border-color: var(--red); color: var(--red); }
.btn-sm { padding: 4px 8px; font-size: 11px; }

.error-text { font-size: 12px; color: var(--red); word-break: break-word; }

/* ── form ── */
.form-wrap {
  max-width: 720px;
}

h2 { font-size: 18px; font-weight: 600; margin-bottom: 20px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--muted); }

.form-group textarea,
.form-group input[type=text],
.form-group input[type=number],
.form-group select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
.form-group textarea { resize: vertical; }
.form-group textarea:focus,
.form-group input:focus,
.form-group select:focus { border-color: var(--accent); }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }

.fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}
.fieldset legend { padding: 0 8px; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }

.radio-group { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.radio-group label { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; color: var(--text); }

.ref-slot { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.ref-slot input[type=file] { flex: 1; min-width: 140px; background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 6px; font-size: 12px; }
.ref-slot select { width: 90px; }

.hint { font-size: 12px; color: var(--muted); margin-bottom: 10px; line-height: 1.5; }
.badge-warn { font-size: 11px; color: var(--yellow); font-weight: normal; text-transform: none; letter-spacing: 0; margin-left: 6px; }

.lib-pick-row { display: flex; align-items: center; gap: 8px; }
.lib-preview   { height: 56px; width: auto; border-radius: 4px; object-fit: cover; border: 1px solid var(--border); }
.lib-preview-sm{ height: 32px; width: auto; border-radius: 3px; object-fit: cover; border: 1px solid var(--border); }

.hidden { display: none !important; }

/* ── images tab ── */
.images-layout { display: grid; grid-template-columns: 380px 1fr; gap: 24px; align-items: start; }
@media (max-width: 900px) { .images-layout { grid-template-columns: 1fr; } }

.img-form-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; position: sticky; top: 76px; }

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

.img-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.img-card-media { background: #111; aspect-ratio: 1/1; overflow: hidden; }
.img-card-media img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.img-card:hover .img-card-media img { transform: scale(1.03); }
.img-card-body { padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.img-card-actions { display: flex; gap: 4px; flex-wrap: wrap; }

/* ── sprites tab ── */
.sprite-intro { margin-bottom: 20px; }
.sprite-intro h2 { margin-bottom: 6px; }
.sprite-intro p { color: var(--muted); font-size: 13px; }

.sprite-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}
@media (max-width: 980px) { .sprite-layout { grid-template-columns: 1fr; } }

.sprite-panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.sprite-panel-wide { grid-column: 1 / -1; }
.sprite-panel h3 { font-size: 16px; margin: 0 0 18px 38px; }
.sprite-step {
  position: absolute;
  top: 16px;
  left: 18px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}
.sprite-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sprite-actions .hint { margin: 0; }
.sprite-source-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sprite-source-preview {
  width: 150px;
  height: 84px;
  object-fit: contain;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.sprite-checkbox { display: flex; align-items: center; gap: 8px; }
.sprite-checkbox label { margin: 0; color: var(--text); cursor: pointer; }
.sprite-export-success {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding: 12px;
  border: 1px solid rgba(34,197,94,.35);
  border-radius: 8px;
  background: rgba(34,197,94,.08);
}
.sprite-exports-list { margin-top: 22px; }
.sprite-exports-list h3 { margin: 0 0 10px; font-size: 14px; }
.sprite-export-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 6px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
}
.sprite-export-entry > div { flex: 1; min-width: 0; }
.sprite-export-entry strong { display: block; font-size: 13px; }
.sprite-export-entry span { display: block; margin-top: 3px; font-size: 11px; color: var(--muted); }
.sprite-export-entry .sprite-pack-select {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  accent-color: var(--accent2);
  cursor: pointer;
}
.sprite-pack-builder {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.sprite-pack-builder > h3 { margin-bottom: 6px; }

/* ── modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%; max-width: 1200px; max-height: 88vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-header span { font-size: 15px; font-weight: 600; }
.modal-body { overflow-y: auto; padding: 16px; }

.modal-image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.modal-img-card { border-radius: 6px; overflow: hidden; cursor: pointer; border: 2px solid transparent; transition: border-color .15s; }
.modal-img-card:hover { border-color: var(--accent); }
.modal-img-card img { width: 100%; aspect-ratio: 1/1; object-fit: cover; display: block; }
.modal-img-prompt { font-size: 11px; color: var(--muted); padding: 4px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: var(--surface); }
.modal-img-id {
  font-size: 11px; font-weight: 700; color: var(--accent);
  background: var(--surface); padding: 4px 6px 0;
}

/* ── compile ── */
.compile-layout { display: grid; grid-template-columns: 1fr 360px; gap: 24px; align-items: start; }

@media (max-width: 800px) {
  .compile-layout { grid-template-columns: 1fr; }
}

.compile-list { display: flex; flex-direction: column; gap: 8px; min-height: 60px; }

.compile-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: grab;
  transition: border-color .2s, opacity .2s;
  user-select: none;
}
.compile-item.drag-over { border-color: var(--accent); }
.compile-item.dragging  { opacity: .4; }

.compile-num {
  width: 24px; height: 24px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
}

.compile-thumb {
  width: 64px; height: 36px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  background: #111;
}

.compile-info { flex: 1; min-width: 0; }
.compile-info p { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.compile-info strong { font-size: 13px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.compile-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; position: sticky; top: 76px; }
.compile-panel h3 { margin-bottom: 14px; font-size: 15px; }

.gallery-for-compile { display: flex; flex-direction: column; gap: 6px; max-height: 400px; overflow-y: auto; padding-right: 4px; }

.compile-pick {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color .15s;
}
.compile-pick:hover { border-color: var(--accent); }
.compile-pick.selected { border-color: var(--accent); background: rgba(124,58,237,.1); }
.compile-pick video { width: 60px; height: 34px; object-fit: cover; border-radius: 3px; pointer-events: none; }
.compile-pick-info { flex: 1; min-width: 0; font-size: 12px; }
.compile-pick-info p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }

.compilations-done { margin-top: 24px; }
.compilations-done h3 { font-size: 15px; margin-bottom: 12px; }
.comp-entry { display: flex; align-items: center; gap: 10px; padding: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; margin-bottom: 6px; }
.comp-entry strong { flex: 1; font-size: 13px; }
.comp-entry span   { font-size: 11px; color: var(--muted); }

/* ── mode explain block ── */
.mode-explain {
  background: rgba(124,58,237,.08);
  border: 1px solid rgba(124,58,237,.2);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 14px;
}
.mode-explain code {
  background: rgba(255,255,255,.12);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
  font-family: monospace;
}
.mode-explain em { color: var(--muted); font-style: normal; }

/* ── mask painter ── */
.mask-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.mask-canvas-area {
  position: relative;
  display: inline-block;
  max-width: 100%;
  width: 100%;
}
.mask-canvas-area .mask-bg {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  opacity: 0.38;
  pointer-events: none;
  border-radius: 4px;
}
#mask-canvas {
  display: block;
  max-width: 100%;
  width: 100%;
  cursor: crosshair;
  border: 1px solid var(--border);
  border-radius: 4px;
  touch-action: none;
}

/* ── lightbox ── */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000; padding: 20px; cursor: zoom-out;
}
.lightbox-inner {
  position: relative; max-width: 90vw; max-height: 90vh;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  cursor: default;
}
.lightbox-inner img {
  max-width: 100%; max-height: 75vh; object-fit: contain;
  border-radius: 8px; box-shadow: 0 8px 40px rgba(0,0,0,.6);
}
.lightbox-close {
  position: absolute; top: -12px; right: -12px;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--surface); border-color: var(--border);
  font-size: 16px; display: flex; align-items: center; justify-content: center;
  z-index: 10; padding: 0;
}
.lightbox-info {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 16px; width: 100%; max-width: 600px;
}
.lb-prompt { font-size: 13px; line-height: 1.5; color: var(--text); }

/* ── image cards — improved ── */
.img-card-actions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }

/* ── scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

@media (max-width: 760px) {
  header {
    height: auto;
    min-height: 56px;
    padding: 8px 12px;
    gap: 6px;
    align-items: flex-start;
    flex-direction: column;
  }
  nav { flex-wrap: wrap; }
  .tab { padding: 6px 11px; }
  main { padding: 14px; }
}

/* ── покадровый редактор экспорта ── */
.fe-layout { display: grid; grid-template-columns: 1fr 260px; gap: 16px; align-items: start; }
.fe-stage { min-width: 0; }
#fe-canvas {
  max-width: 100%; max-height: 46vh; display: block; margin: 0 auto 10px;
  cursor: crosshair; border-radius: 6px;
  background-color: #2a2a2a;
  background-image:
    linear-gradient(45deg, #333 25%, transparent 25%, transparent 75%, #333 75%),
    linear-gradient(45deg, #333 25%, transparent 25%, transparent 75%, #333 75%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
}
.fe-controls { display: flex; gap: 8px; align-items: center; justify-content: center; margin-bottom: 8px; flex-wrap: wrap; }
.fe-side { display: flex; flex-direction: column; gap: 10px; }
.fe-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.fe-strip { display: flex; gap: 6px; overflow-x: auto; margin-top: 14px; padding-bottom: 6px; }
.fe-thumb {
  position: relative; flex: 0 0 auto; width: 66px; cursor: pointer;
  border: 2px solid transparent; border-radius: 4px; background: #2a2a2a;
}
.fe-thumb img { width: 100%; height: 64px; object-fit: contain; display: block; }
.fe-thumb span {
  position: absolute; bottom: 2px; right: 4px; font-size: 10px;
  color: var(--muted); background: rgba(0,0,0,.6); padding: 0 3px; border-radius: 3px;
}
.fe-thumb.fe-current { border-color: var(--accent); }
.fe-thumb.fe-dropped { opacity: .3; }
.fe-thumb.fe-dropped::after {
  content: "✕"; position: absolute; inset: 0; display: flex;
  align-items: center; justify-content: center; font-size: 22px; color: #ef4444;
}

/* Цена в кредитах рядом с кнопкой запуска. Раньше стоимость не показывалась
   нигде до нажатия, а в галерее висела закупочная цена у Google. */
.cost-hint {
  margin-left: 12px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
.cost-hint.warn { color: #f0a05a; }

/* Переключатель языка в топбаре. Интерфейс исходно русский; для англоязычных
   клиентов, приходящих с лендинга, он переводится словарём (static/i18n.js). */
.lang-switch {
  margin-left: 10px;
  min-width: 34px;
  font-weight: 600;
  letter-spacing: .04em;
}

/* ── Персонажи и очередь набора ─────────────────────────────────────────
   Набор анимаций заказывается одной кнопкой, поэтому нужен видимый
   прогресс: без него человек не понимает, что происходит минутами. */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.preset-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.preset-grid label:hover { background: rgba(255, 255, 255, .07); }
.preset-grid .preset-cost { margin-left: auto; color: var(--muted); font-size: 12px; }

.char-list { display: grid; gap: 12px; margin-top: 14px; }
.char-card {
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 8px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, .03);
}
.char-card.selected { border-color: var(--accent, #7c5cff); }
.char-card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.char-card-head strong { font-size: 15px; }
.char-progress-bar {
  height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .08);
  overflow: hidden; margin: 10px 0 8px;
}
.char-progress-bar > span { display: block; height: 100%; background: #4ade80; transition: width .3s; }
.char-anims { display: flex; flex-wrap: wrap; gap: 6px; }
.char-anim {
  font-size: 11px; padding: 3px 7px; border-radius: 4px;
  background: rgba(255, 255, 255, .06); color: var(--muted);
}
.char-anim.done { background: rgba(74, 222, 128, .15); color: #4ade80; }
.char-anim.generating, .char-anim.pending { background: rgba(96, 165, 250, .15); color: #60a5fa; }
.char-anim.queued { background: rgba(255, 255, 255, .07); }
.char-anim.error { background: rgba(248, 113, 113, .15); color: #f87171; }
.lib-row { display: flex; align-items: center; gap: 10px; }
