/* 🎭 Режиссёр — Mini App styling.
   Colors bind to Telegram theme params (set on :root by app.js) with a
   cinematic dark fallback so it also looks right in a plain browser. */

:root {
  --bg:           var(--tg-bg, #0e0f13);
  --surface:      var(--tg-secondary-bg, #171a22);
  --surface-2:    var(--tg-section-bg, #1d2129);
  --text:         var(--tg-text, #f2f3f5);
  --hint:         var(--tg-hint, #8b909c);
  --link:         var(--tg-link, #e0a35e);
  --accent:       var(--tg-button, #d9a14e);
  --accent-text:  var(--tg-button-text, #1a1206);
  --danger:       var(--tg-destructive, #e5635b);
  --border:       rgba(255, 255, 255, 0.09);
  --border-soft:  rgba(255, 255, 255, 0.05);
  --radius:       14px;
  --radius-sm:    10px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 14px 0;
}

/* ---- header ---- */
.hero { padding: 8px 2px 14px; }
.hero-title { font-size: 22px; font-weight: 700; letter-spacing: .2px; }
.hero-sub { color: var(--hint); font-size: 13px; margin-top: 4px; }

/* ---- blocks ---- */
.block { margin-bottom: 16px; }
.block-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.block-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 8px;
  cursor: default;
}
.block-head .block-label { margin-bottom: 0; }
.counter { font-size: 12px; color: var(--hint); }
.hint { color: var(--hint); font-size: 12px; margin: 8px 2px 0; }
.hidden { display: none !important; }
.spacer { height: 12px; }

.link-btn {
  background: none;
  border: none;
  color: var(--link);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 2px;
}
.link-btn:active { opacity: .6; }

/* ---- text inputs ---- */
textarea, input[type="text"] {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 13px;
  font: inherit;
  resize: vertical;
  outline: none;
}
textarea:focus, input:focus { border-color: var(--accent); }
textarea::placeholder { color: var(--hint); }
.idea { min-height: 64px; }
.prompt { min-height: 120px; font-size: 14px; line-height: 1.5; }

/* ---- reference thumbnails ---- */
.thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
  gap: 8px;
}
.thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.add {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-style: dashed;
  color: var(--hint);
  cursor: pointer;
}
.thumb.add:active { background: var(--surface-2); }
.add-plus { font-size: 26px; line-height: 1; font-weight: 300; }
.add-hint { font-size: 11px; }
.thumb-x {
  position: absolute;
  top: 4px; right: 4px;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: 14px;
  line-height: 22px;
  text-align: center;
  cursor: pointer;
  padding: 0;
}
.thumb.busy::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 50 50'%3E%3Cpath fill='%23fff' d='M25 5a20 20 0 1 0 20 20h-4a16 16 0 1 1-16-16z'%3E%3CanimateTransform attributeName='transform' type='rotate' from='0 25 25' to='360 25 25' dur='0.8s' repeatCount='indefinite'/%3E%3C/path%3E%3C/svg%3E") center / 28px no-repeat;
}
.thumb.failed { border-color: var(--danger); }

/* ---- analyzed role cards ---- */
.cards { display: flex; flex-direction: column; gap: 10px; }
.card {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px;
}
.card.locked { border-color: var(--accent); }
.card-thumb {
  width: 56px; height: 56px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--surface-2);
  align-self: start;
}
.card-body { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.card-tag { font-size: 11px; font-weight: 700; color: #fff; }
.card-tag .img-no { color: var(--accent); margin-right: 4px; }
.card-subject { font-size: 13px; color: var(--hint); }
.card-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card select {
  flex: 1 1 auto;
  min-width: 130px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font: inherit;
  outline: none;
}
.card select:focus { border-color: var(--accent); }
.card-desc { min-height: 44px; font-size: 13px; }

.lock-btn {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--hint);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.lock-btn.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge.low      { background: rgba(139,144,156,.22); color: #aeb3bd; }
.badge.medium   { background: rgba(217,161,78,.20);  color: #e0b167; }
.badge.high     { background: rgba(224,123,67,.22);  color: #ef9e6e; }
.badge.critical { background: rgba(229,99,91,.22);   color: #f08a82; }

/* ---- settings segmented controls ---- */
.settings { display: flex; flex-direction: column; gap: 12px; padding-top: 12px; }
.setting-row { display: flex; flex-direction: column; gap: 6px; }
.setting-name { font-size: 12px; color: var(--hint); }
.segments { display: flex; flex-wrap: wrap; gap: 6px; }
.seg {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13px;
  cursor: pointer;
}
.seg.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }

/* ---- preset chips ---- */
.presets { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
}
.chip:active { opacity: .7; }
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }

/* ---- result ---- */
.result-head { display: flex; align-items: center; gap: 9px; }
.status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--hint); flex: 0 0 auto;
}
.status-dot.queued  { background: #8b909c; }
.status-dot.running { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.status-dot.done    { background: #54c08a; }
.status-dot.error   { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
.status-text { font-weight: 600; }
.credits { margin-left: auto; color: var(--hint); font-size: 12px; }
.result-video { width: 100%; border-radius: var(--radius); margin-top: 12px; background: #000; }

/* ---- sticky action bar ---- */
.action-bar {
  position: sticky;
  bottom: 0;
  left: 0; right: 0;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 72%, transparent);
}
.primary {
  display: block;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font-size: 16px;
  font-weight: 700;
  padding: 15px;
  cursor: pointer;
}
.primary:active { filter: brightness(.93); }
.primary:disabled { opacity: .4; cursor: default; }
.primary.busy { opacity: .8; cursor: progress; }

/* ---- toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  max-width: 90%;
  background: #2a2f3a;
  color: #fff;
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 50;
}
.toast.err { background: #5a2a2a; }
