/* Cartoon Factory — интерфейс студии.
   Палитра взята у героя проекта (Рук): тёмный металл, бирюзовая броня, оранжевые накладки, голубой глаз-линза. */

:root {
  --bg: #0e1317;
  --panel: #151c22;
  --raised: #1c2630;
  --line: #26313b;
  --line-strong: #364552;
  --text: #e8eef1;
  --muted: #8d9ea9;
  --dim: #5f707c;

  --teal: #52b8aa;
  --teal-deep: #1d4a45;
  --cyan: #38e8e0;
  --orange: #ea8240;
  --orange-ink: #2b1303;
  --danger: #ff8f7e;

  --r-lg: 18px;
  --r-md: 12px;
  --r-sm: 8px;

  --font-display: 'Unbounded', 'Onest', system-ui, sans-serif;
  --font-body: 'Onest', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
img, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 8px; }

/* ---------- каркас ---------- */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }

.rail {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #11181e 0%, var(--bg) 100%);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 26px; }
.brand-mark { width: 38px; height: 38px; flex: none; }
.brand-name, .brand-sub { display: block; }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 14px; line-height: 1.15; letter-spacing: -0.01em; }
.brand-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--r-sm);
  color: var(--muted); font-weight: 500;
  transition: background .15s, color .15s;
}
.nav a:hover { background: var(--panel); color: var(--text); }
.nav a[aria-current="page"] { background: var(--raised); color: var(--text); box-shadow: inset 3px 0 0 var(--orange); }
.nav svg { width: 18px; height: 18px; flex: none; }

.gpu {
  margin-top: auto; padding: 12px; border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--panel);
  font-size: 13px; color: var(--muted);
}
.gpu-row { display: flex; align-items: center; gap: 9px; color: var(--text); font-weight: 500; }
.gpu-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dim); flex: none; }
.gpu[data-state="on"] .gpu-dot { background: var(--cyan); box-shadow: 0 0 0 4px rgba(56,232,224,.14); }
.gpu[data-state="off"] .gpu-dot { background: var(--danger); }
.gpu-name { margin-top: 4px; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gpu a { display: inline-block; margin-top: 8px; font-size: 12px; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
.gpu a:hover { color: var(--text); }

.main { padding: 34px clamp(18px, 4vw, 52px) 80px; max-width: 1180px; width: 100%; }
.stack { display: flex; flex-direction: column; gap: 26px; }

/* ---------- заголовки ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: clamp(22px, 3vw, 30px); line-height: 1.15; letter-spacing: -0.02em; }
.page-head p { margin: 8px 0 0; color: var(--muted); max-width: 62ch; }
.back { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 14px; color: var(--muted); font-size: 14px; }
.back:hover { color: var(--text); }
.back svg { width: 16px; height: 16px; }
.section-title { margin: 0 0 14px; font-size: 17px; font-weight: 600; }
.hint { color: var(--muted); font-size: 13px; }

/* ---------- кнопки, поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: transparent;
  font-weight: 600; font-size: 14px; cursor: pointer;
  transition: background .15s, border-color .15s, filter .15s;
}
.btn:hover { background: var(--raised); }
.btn svg { width: 16px; height: 16px; }
.btn--primary { background: var(--orange); border-color: var(--orange); color: var(--orange-ink); }
.btn--primary:hover { background: var(--orange); filter: brightness(1.08); }
.btn--ok { background: var(--teal); border-color: var(--teal); color: #072320; }
.btn--ok:hover { background: var(--teal); filter: brightness(1.08); }
.btn--danger { color: var(--danger); }
.btn--sm { padding: 7px 12px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: wait; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 24px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field > label, .label { font-size: 13px; font-weight: 500; color: var(--muted); }
.field .opt { color: var(--dim); font-weight: 400; }
.input, .select, .textarea {
  width: 100%; padding: 10px 12px; border-radius: var(--r-sm);
  background: var(--bg); border: 1px solid var(--line-strong);
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(82,184,170,.2); }
.textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 13px; }
.form-grid { display: grid; gap: 16px; }
.form-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.file { font-size: 13px; color: var(--muted); }
.file::file-selector-button { margin-right: 12px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--raised); color: var(--text); cursor: pointer; }

.notice { display: flex; gap: 12px; align-items: flex-start; padding: 13px 16px; border-radius: var(--r-md); font-size: 14px; border: 1px solid; }
.notice svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.notice--err { background: rgba(255,143,126,.08); border-color: rgba(255,143,126,.35); color: #ffd3cb; }
.notice--ok { background: rgba(82,184,170,.1); border-color: rgba(82,184,170,.4); color: #c5efe9; }

/* ---------- статусы ---------- */
.badge { display: inline-flex; align-items: center; gap: 7px; padding: 4px 11px 4px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--raised); color: var(--muted); white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge--queued { color: var(--muted); }
.badge--generating { color: var(--cyan); background: rgba(56,232,224,.1); }
.badge--generating::before { animation: pulse 1.2s ease-in-out infinite; }
.badge--assembling { color: var(--cyan); background: rgba(56,232,224,.1); }
.badge--assembling::before { animation: pulse 1.2s ease-in-out infinite; }
.badge--ready { color: var(--orange); background: rgba(234,130,64,.12); }
.badge--approved, .badge--done { color: var(--teal); background: rgba(82,184,170,.12); }
.badge--failed { color: var(--danger); background: rgba(255,143,126,.1); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }

/* ---------- кадр (превью картинки или видео) ---------- */
.frame { position: relative; overflow: hidden; background: #070a0d; border-radius: var(--r-md); aspect-ratio: var(--ar, 16 / 9); border: 1px solid var(--line); }
.frame > img, .frame > video { width: 100%; height: 100%; object-fit: cover; }
.frame-empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 14px; color: var(--dim); font-size: 13px; background:
  repeating-linear-gradient(135deg, rgba(255,255,255,.02) 0 12px, transparent 12px 24px); }
.frame-live { color: var(--cyan); }
.frame-live .spin { margin: 0 auto 10px; }
.frame .badge { position: absolute; top: 10px; left: 10px; backdrop-filter: blur(6px); background: rgba(10,14,18,.72); }
.spin { width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(56,232,224,.25); border-top-color: var(--cyan); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- лента сцен ---------- */
.reel { display: flex; gap: 4px; align-items: stretch; }
.reel-seg {
  flex: 1 1 0; min-width: 44px; max-width: 220px; height: 46px; padding: 6px 10px;
  display: flex; flex-direction: column; justify-content: space-between;
  border-radius: 7px; background: var(--raised); border: 1px solid var(--line-strong);
  font-size: 11px; line-height: 1.2; color: var(--muted);
  transition: border-color .15s;
}
.reel-seg b { font-size: 13px; color: var(--text); font-weight: 600; }
.reel-seg:hover { border-color: var(--muted); }
.reel-seg[data-s="approved"] { background: var(--teal-deep); border-color: var(--teal); }
.reel-seg[data-s="ready"] { background: rgba(234,130,64,.14); border-color: var(--orange); }
.reel-seg[data-s="generating"], .reel-seg[data-s="queued"] { background: rgba(56,232,224,.08); border-color: rgba(56,232,224,.55); }
.reel-seg[data-s="failed"] { background: rgba(255,143,126,.1); border-color: var(--danger); }
.reel-add { flex: 0 0 46px; min-width: 46px; display: grid; place-items: center; border-radius: 7px; border: 1px dashed var(--line-strong); color: var(--muted); }
.reel-add:hover { border-color: var(--teal); color: var(--teal); }
.reel-add svg { width: 18px; height: 18px; }
.reel-total { margin-top: 10px; font-size: 13px; color: var(--muted); }
.reel-total strong { color: var(--text); font-weight: 600; }
.mini-reel { display: flex; gap: 3px; }
.mini-reel i { flex: 1 1 0; height: 5px; border-radius: 3px; background: var(--line-strong); }
.mini-reel i[data-s="approved"] { background: var(--teal); }
.mini-reel i[data-s="ready"] { background: var(--orange); }
.mini-reel i[data-s="generating"], .mini-reel i[data-s="queued"] { background: var(--cyan); }
.mini-reel i[data-s="failed"] { background: var(--danger); }

/* ---------- список проектов ---------- */
.projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 22px; align-items: start; }
.project .frame { aspect-ratio: 16 / 10; }
.project { display: flex; flex-direction: column; gap: 14px; padding: 12px 12px 18px; border-radius: var(--r-lg); background: var(--panel); border: 1px solid var(--line); transition: border-color .15s, transform .15s; }
.project:hover { border-color: var(--line-strong); }
.project h3 { margin: 0; font-size: 16px; font-weight: 600; line-height: 1.3; }
.project .meta { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 13px; }
.project-body { padding: 0 6px; display: flex; flex-direction: column; gap: 10px; }

/* ---------- клип ---------- */
.clip { display: grid; grid-template-columns: var(--media, 440px) minmax(0, 1fr); gap: 24px; padding: 18px; border-radius: var(--r-lg); background: var(--panel); border: 1px solid var(--line); }
.clip--port { --media: 220px; }
.clip--focus { border-color: rgba(234,130,64,.55); }
.clip-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.clip-num { font-family: var(--font-display); font-weight: 600; font-size: 22px; letter-spacing: -0.03em; }
.tag { padding: 3px 10px; border-radius: 999px; background: var(--raised); color: var(--muted); font-size: 12px; }
.clip-body { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.clip-prompt { margin: 0; color: #cfdae0; line-height: 1.6; }
.clip-meta { margin-top: auto; font-size: 12px; color: var(--dim); }
.clip-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.clip-err { margin: 0; color: var(--danger); font-size: 14px; word-break: break-word; }

/* ---------- выбор стартового кадра ---------- */
.seg { display: inline-grid; grid-auto-flow: column; gap: 4px; padding: 4px; border-radius: var(--r-md); background: var(--bg); border: 1px solid var(--line); }
.seg a { padding: 8px 16px; border-radius: var(--r-sm); color: var(--muted); font-weight: 500; font-size: 14px; }
.seg a:hover { color: var(--text); }
.seg a[aria-current="true"] { background: var(--raised); color: var(--text); box-shadow: inset 0 -2px 0 var(--orange); }
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.pick { position: relative; cursor: pointer; }
.pick input { position: absolute; opacity: 0; inset: 0; }
.pick .frame { aspect-ratio: 1; border-radius: var(--r-sm); transition: border-color .15s, box-shadow .15s; }
.pick span { display: block; margin-top: 6px; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick input:checked + .frame { border-color: var(--orange); box-shadow: 0 0 0 2px var(--orange); }
.pick input:focus-visible + .frame { outline: 2px solid var(--cyan); outline-offset: 2px; }
.continue-box { display: flex; gap: 16px; align-items: center; padding: 12px; border-radius: var(--r-md); background: var(--bg); border: 1px solid var(--line); }
.continue-box img { height: 96px; width: auto; border-radius: var(--r-sm); border: 1px solid var(--line); }

/* ---------- два столбца: форма и библиотека ---------- */
.split { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 28px; align-items: start; }
.split > .panel { position: sticky; top: 24px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; align-items: start; }
.ref .frame { aspect-ratio: 1; }
.ref .frame > img { object-fit: contain; }
.ref { display: flex; flex-direction: column; gap: 10px; padding: 10px 10px 14px; border-radius: var(--r-lg); background: var(--panel); border: 1px solid var(--line); }
.ref-body { padding: 0 6px; display: flex; flex-direction: column; gap: 6px; }
.ref-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ref-prompt { margin: 0; font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ref-meta { font-size: 12px; color: var(--dim); }
.ref-actions { display: flex; gap: 6px; padding: 4px 6px 0; }

.empty { padding: 44px 24px; text-align: center; border: 1px dashed var(--line-strong); border-radius: var(--r-lg); color: var(--muted); }
.empty strong { display: block; margin-bottom: 6px; color: var(--text); font-size: 16px; }
.empty a { color: var(--teal); text-decoration: underline; text-underline-offset: 3px; }

.final { display: grid; grid-template-columns: minmax(0, 520px) minmax(0, 1fr); gap: 26px; align-items: start; }

/* ---------- адаптив ---------- */
@media (max-width: 960px) {
  .split { grid-template-columns: 1fr; }
  .split > .panel { position: static; }
  .clip, .final { grid-template-columns: 1fr; }
  .clip--port { --media: 100%; }
  .clip--port .frame { max-width: 260px; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 6px 16px; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0; }
  .brand-sub { display: none; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav a { padding: 8px 10px; }
  .gpu { display: none; }
  .main { padding-top: 24px; }
}
@media (max-width: 560px) { .form-grid--2 { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- герои: выбор фаса, проекции, варианты ---------- */
.char-stage { display: grid; grid-template-columns: minmax(240px, 340px) minmax(0, 1fr); gap: 28px; align-items: start; }
.char-stage .frame { --ar: 928 / 1664; max-height: 74vh; margin-inline: auto; }
.char-side { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.char-desc { margin: 0; color: #cfdae0; line-height: 1.6; }
.step-note { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-md); background: rgba(234,130,64,.1); border: 1px solid rgba(234,130,64,.4); color: #ffe3cf; font-size: 14px; }
.step-note > svg { width: 18px; height: 18px; flex: none; margin-top: 2px; color: var(--orange); }
.step-note .btn { margin-top: 10px; }
.details { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg); }
.details > summary { cursor: pointer; padding: 11px 14px; font-weight: 500; color: var(--muted); list-style: none; }
.details > summary::-webkit-details-marker { display: none; }
.details > summary::before { content: "+"; display: inline-block; width: 18px; color: var(--teal); }
.details[open] > summary::before { content: "−"; }
.details > div { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 12px; }

.variants-title { font-size: 13px; font-weight: 500; color: var(--muted); margin: 0 0 8px; }
.variants { display: flex; gap: 8px; overflow-x: auto; padding: 3px 3px 8px; }
.vthumb { position: relative; flex: none; width: 72px; }
.vthumb form { margin: 0; }
.vthumb button.pick-btn { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: pointer; }
.vthumb .frame { --ar: 928 / 1664; border-radius: var(--r-sm); transition: border-color .15s, box-shadow .15s; }
.vthumb button.pick-btn:hover .frame { border-color: var(--muted); }
.vthumb[data-sel="1"] .frame { border-color: var(--orange); box-shadow: 0 0 0 2px var(--orange); }
.vthumb-label { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 12px; color: var(--muted); }
.vthumb[data-sel="1"] .vthumb-label { color: var(--text); }
.vthumb .x { border: 0; background: none; padding: 2px 4px; color: var(--dim); cursor: pointer; border-radius: 4px; line-height: 1; }
.vthumb .x:hover { color: var(--danger); background: var(--raised); }
.vthumb .frame-empty { padding: 4px; font-size: 11px; }
.vthumb .spin { width: 16px; height: 16px; margin: 0; }
.vthumb[data-st="failed"] .frame { border-color: var(--danger); }

.board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; align-items: start; }
.view-card { display: flex; flex-direction: column; gap: 12px; padding: 10px 10px 14px; border-radius: var(--r-lg); background: var(--panel); border: 1px solid var(--line); min-width: 0; }
.view-card .frame { --ar: 928 / 1664; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 6px 0; }
.view-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.view-body { padding: 0 6px; display: flex; flex-direction: column; gap: 10px; }
.view-card .tag-stale { color: var(--orange); background: rgba(234,130,64,.12); }
.view-err { margin: 0; font-size: 12px; color: var(--danger); word-break: break-word; }
.view-card .variants { padding-bottom: 4px; }
.view-card .vthumb { width: 54px; }

.char-card { display: flex; flex-direction: column; gap: 12px; padding: 12px 12px 16px; border-radius: var(--r-lg); background: var(--panel); border: 1px solid var(--line); transition: border-color .15s; }
.char-card:hover { border-color: var(--line-strong); }
.char-card .frame { --ar: 3 / 4; }
.char-card .frame > img { object-fit: contain; }
.char-card h3 { margin: 0; font-size: 16px; font-weight: 600; }
.char-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 20px; align-items: start; }
.char-card .mini-views { display: flex; gap: 6px; }
.char-card .mini-views .frame { --ar: 3 / 5; flex: 1 1 0; border-radius: 6px; }

@media (max-width: 1080px) { .board { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .char-stage { grid-template-columns: 1fr; } .char-stage .frame { max-width: 300px; } }
@media (max-width: 420px) { .board { grid-template-columns: 1fr; } .view-card .frame { max-width: 280px; } }

/* картинки героев показываем целиком: проекции приходят чуть другого размера, чем фас */
.char-stage .frame > img, .view-card .frame > img, .vthumb .frame > img { object-fit: contain; }

/* ---------- выбор стиля героя ---------- */
.style-field { border: 0; padding: 0; margin: 0; min-width: 0; }
.style-field legend { padding: 0; margin-bottom: 8px; }
.style-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 10px; }
.style-opt { position: relative; cursor: pointer; display: block; }
.style-opt input { position: absolute; opacity: 0; inset: 0; }
.style-card { display: flex; flex-direction: column; gap: 4px; height: 100%; padding: 12px 14px; border-radius: var(--r-md); background: var(--bg); border: 1px solid var(--line-strong); transition: border-color .15s, background .15s; }
.style-card b { font-size: 14px; font-weight: 600; }
.style-card small { font-size: 12px; line-height: 1.35; color: var(--muted); }
.style-opt:hover .style-card { border-color: var(--muted); }
.style-opt input:checked + .style-card { border-color: var(--orange); background: rgba(234,130,64,.1); box-shadow: inset 0 0 0 1px var(--orange); }
.style-opt input:focus-visible + .style-card { outline: 2px solid var(--cyan); outline-offset: 2px; }
.char-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(100%, 380px); display: flex; flex-direction: column; gap: 18px; padding: 28px; border-radius: var(--r-lg); background: var(--panel); border: 1px solid var(--line); }
.login-brand { display: flex; align-items: center; gap: 14px; }
.login-brand h1 { margin: 0; font-family: var(--font-display); font-size: 20px; font-weight: 600; letter-spacing: -0.02em; }
.login-brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.login-card .btn { width: 100%; padding: 12px; }
.logout { display: inline-flex; align-items: center; gap: 8px; margin-top: 10px; padding: 9px 12px; border-radius: var(--r-sm); color: var(--muted); font-size: 14px; }
.logout:hover { background: var(--panel); color: var(--text); }
.logout svg { width: 16px; height: 16px; }

/* ---------- герои и изображения в сцене ---------- */
.cast-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 12px; }
.cast-card { display: flex; flex-direction: column; gap: 8px; padding: 10px; border-radius: var(--r-md); background: var(--bg); border: 1px solid var(--line-strong); transition: border-color .15s, background .15s; }
.cast-card.is-on { border-color: var(--orange); background: rgba(234,130,64,.08); box-shadow: inset 0 0 0 1px var(--orange); }
.cast-pick { position: relative; display: flex; flex-direction: column; gap: 6px; cursor: pointer; }
.cast-pick input { position: absolute; top: 8px; left: 8px; z-index: 2; width: 18px; height: 18px; accent-color: var(--orange); cursor: pointer; }
.cast-pick .frame { --ar: 3 / 4; }
.cast-pick .frame > img { object-fit: contain; background: #0a0e12; }
.cast-name { font-weight: 600; font-size: 14px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cast-pick small { color: var(--muted); font-size: 12px; margin-top: -4px; }
.view-seg { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; }
.view-seg label { position: relative; }
.view-seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.view-seg span { display: block; padding: 6px 4px; text-align: center; font-size: 12px; font-weight: 500; border-radius: 6px; background: var(--raised); color: var(--muted); border: 1px solid transparent; transition: background .15s, color .15s; }
.view-seg label:hover span { color: var(--text); }
.view-seg input:checked + span { background: var(--teal-deep); color: var(--text); border-color: var(--teal); }
.view-seg input:focus-visible + span { outline: 2px solid var(--cyan); outline-offset: 1px; }
.view-seg .is-off { opacity: .4; }
.view-seg .is-off input { cursor: not-allowed; }

.upload-box { display: flex; flex-direction: column; gap: 12px; padding: 14px; border-radius: var(--r-md); background: var(--bg); border: 1px dashed var(--line-strong); }
.upload-preview { display: flex; align-items: center; gap: 14px; }
.upload-preview[hidden] { display: none; }
.upload-preview img { height: 92px; width: auto; max-width: 160px; object-fit: contain; border-radius: var(--r-sm); border: 1px solid var(--line); background: #0a0e12; }
.upload-preview > div { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; min-width: 0; }
.role-pick { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.role-pick .select { width: auto; min-width: 230px; }

.scene-inputs { display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.scene-thumb { margin: 0; width: 84px; }
.scene-thumb img { width: 84px; height: 84px; object-fit: contain; border-radius: var(--r-sm); border: 1px solid var(--line); background: #0a0e12; }
.scene-thumb figcaption { margin-top: 5px; font-size: 11px; line-height: 1.3; color: var(--muted); word-break: break-word; }
.scene-thumb--result { width: 128px; }
.scene-thumb--result img { width: 128px; border-color: var(--teal); }
.scene-arrow { align-self: center; color: var(--dim); font-size: 20px; padding-bottom: 18px; }

/* ---------- дополнительные ракурсы героя и окно «Сгенерировать ракурс» ---------- */
.extras-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.extras-head .section-title { margin: 0; }
.extras-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.details--mini > summary { padding: 7px 10px; font-size: 12px; }
.details--mini > div { padding: 0 10px 10px; gap: 6px; }
.meta-line { margin: 0; font-size: 12px; color: var(--muted); word-break: break-word; }
.meta-line span { display: block; color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.meta-line code { color: var(--text); font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace; font-size: 12px; }
.gen-dialog { width: min(560px, calc(100vw - 32px)); padding: 22px; border: 1px solid var(--line-strong); border-radius: var(--r-lg); background: var(--panel); color: var(--text); }
.gen-dialog::backdrop { background: rgba(5, 8, 11, .72); }
.gen-dialog .form-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- пересборка кадра ---------- */
.recompose { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.recompose .select { width: auto; min-width: 190px; }

/* ---------- Авто-генерация ---------- */
.auto-list { display: grid; gap: 12px; }
.auto-item { display: block; padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--panel); color: inherit; text-decoration: none; }
.auto-item:hover { border-color: var(--line-strong); }
.auto-item__head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 6px; }
.auto-item__idea { color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.auto-item__meta { color: var(--dim); font-size: 12px; margin-top: 8px; }
.auto-bar { height: 6px; border-radius: 999px; background: var(--raised); overflow: hidden; }
.auto-bar > span { display: block; height: 100%; background: var(--teal); border-radius: 999px; transition: width .4s; }
.auto-bar--big { height: 8px; margin: 12px 0 16px; }
.auto-status { margin-bottom: 20px; }
.auto-status__row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.auto-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 800px) { .auto-cols { grid-template-columns: 1fr; } }
.auto-locs { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.auto-loc { margin: 0; border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; background: var(--panel); }
.auto-loc img { display: block; width: 100%; aspect-ratio: var(--ar, 16 / 9); object-fit: cover; }
.auto-loc figcaption { padding: 10px 12px; font-size: 13px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.auto-clips { display: grid; gap: 14px; }
.auto-clip { display: grid; grid-template-columns: 280px 1fr; gap: 16px; padding: 14px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--panel); }
@media (max-width: 800px) { .auto-clip { grid-template-columns: 1fr; } }
.auto-clip__media video, .auto-clip__media img { display: block; width: 100%; border-radius: var(--r-md); background: #000; }
.auto-log { margin: 0; white-space: pre-wrap; font-size: 12px; color: var(--muted); max-height: 320px; overflow: auto; }

/* ---------- проверка подключения Gemini ---------- */
.gresult { padding: 12px 14px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--bg); font-size: 14px; }
.gresult ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.gresult li.ok { color: var(--teal); }
.gresult li.bad { color: var(--danger); }
.gresult--ok { border-color: rgba(82,184,170,.5); }
.gresult--bad { border-color: rgba(255,143,126,.5); }
.gresult .gmodels { margin-top: 10px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.gresult .gm { cursor: pointer; border: 0; }

/* Заглушка вместо картинки. Обычная (не absolute): на странице авто-генерации нет контейнера .frame. */
.auto-empty { display: grid; place-items: center; text-align: center; padding: 14px; aspect-ratio: var(--ar, 16 / 9); border-radius: var(--r-md); border: 1px solid var(--line); color: var(--dim); font-size: 13px; background: #070a0d repeating-linear-gradient(135deg, rgba(255,255,255,.02) 0 12px, transparent 12px 24px); }
.auto-clip__media video, .auto-clip__media img { aspect-ratio: var(--ar, 16 / 9); object-fit: cover; }
.auto-clips--port .auto-clip { grid-template-columns: 180px 1fr; }

/* ---------- полный референс героя: группы ракурсов ---------- */
.ref-group { margin-bottom: 12px; }
.ref-group > summary { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ref-group > div { padding-top: 4px; }

/* ---------- Gemini пишет описание героя ---------- */
.ai-modes { display: flex; gap: 18px; flex-wrap: wrap; }
.ai-modes label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.ai-modes input:disabled + * , .ai-modes label:has(input:disabled) { opacity: .55; cursor: not-allowed; }
.ai-row { display: grid; gap: 10px; }
.ai-row__controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.ai-row__controls .input { flex: 1; min-width: 220px; }

/* ---------- просмотр картинок внутри сайта (assets/lightbox.js) ---------- */
html.lb-open { overflow: hidden; }
.lb { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; }
.lb[hidden] { display: none; }
.lb__backdrop { position: absolute; inset: 0; background: rgba(5, 8, 11, .92); }
.lb__stage { position: relative; z-index: 1; max-width: 96vw; max-height: calc(100vh - 92px); margin-bottom: 56px; display: grid; place-items: center; overflow: auto; }
.lb__img { display: block; max-width: 96vw; max-height: calc(100vh - 92px); width: auto; height: auto; object-fit: contain; border-radius: 8px; cursor: zoom-in; background: #070a0d; transition: filter .2s; }
.lb__img--loading { filter: blur(3px) brightness(.8); }
.lb--zoom .lb__img { max-width: none; max-height: none; cursor: zoom-out; border-radius: 0; }
.lb--zoom .lb__stage { display: block; }
.lb__spin { position: absolute; z-index: 2; width: 34px; height: 34px; border: 3px solid rgba(255, 255, 255, .25); border-top-color: #38e8e0; border-radius: 50%; animation: lbspin .8s linear infinite; }
@keyframes lbspin { to { transform: rotate(360deg); } }
.lb__btn { position: absolute; z-index: 2; border: 0; cursor: pointer; color: #fff; background: rgba(21, 28, 34, .78); border-radius: 999px; width: 44px; height: 44px; font-size: 28px; line-height: 1; display: grid; place-items: center; }
.lb__btn:hover, .lb__btn:focus-visible { background: rgba(56, 232, 224, .28); outline: none; }
.lb__btn[hidden] { display: none; }
.lb__close { top: 14px; right: 14px; }
.lb__nav { top: 50%; transform: translateY(-50%); }
.lb__prev { left: 14px; }
.lb__next { right: 14px; }
.lb__bar { position: absolute; z-index: 2; left: 0; right: 0; bottom: 0; display: flex; gap: 14px; align-items: center; justify-content: center; flex-wrap: wrap; padding: 12px 70px; color: #cfd8de; font-size: 13px; background: linear-gradient(transparent, rgba(5, 8, 11, .85)); }
.lb__cap { max-width: 50vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb__count { color: #8d9aa3; }
.lb__link { color: #38e8e0; text-decoration: none; }
.lb__link:hover { text-decoration: underline; }
@media (max-width: 600px) { .lb__nav { width: 38px; height: 38px; } .lb__bar { padding: 10px 14px; } .lb__cap { max-width: 90vw; } }
img[data-full] { cursor: zoom-in; }
a[target="_blank"] > img { cursor: zoom-in; }

/* Режим «по референс-листу» */
.sheet-build { border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 16px; margin: 14px 0 20px; background: var(--bg); }
.sheet-build > summary { cursor: pointer; font-weight: 600; margin-bottom: 4px; }
.sheet-build[open] > summary { margin-bottom: 14px; }
.sh-view-list, .sh-loc-list, .sh-sheets { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.sh-sheets { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.sh-view, .sh-loc, .sh-sheet label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); cursor: pointer; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 6px; background: var(--panel); }
.sh-view img, .sh-loc img, .sh-sheet img { width: 100%; height: auto; border-radius: 4px; display: block; }
.sh-sheet { position: relative; }
.sh-sheet .btn { position: absolute; top: 8px; right: 8px; }
.sh-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.sh-board { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.form-grid--3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 700px) { .form-grid--3 { grid-template-columns: 1fr; } }
.scene-thumb--sheet { max-width: 220px; }
