/* «Монтажная»: Telegram's own colours as the base, warm status colours and paper-like script cards on top. */
:root {
  --bg: #f4f1ec; --bg2: #efebe4; --surface: #ffffff; --text: #1c1a17; --hint: #8a8378; --link: #2f6fd6;
  --accent: #2f6fd6; --on-accent: #ffffff; --danger: #d63c3c; --line: rgba(28, 26, 23, .09);
  --wait: #e8913a; --work: #7a5af5; --ok: #2f9e62; --gone: #8a8378; --bad: #d63c3c;
  --paper: #fbf6ea; --paper-ink: #3a3326; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px -12px rgba(0,0,0,.18);
  --r-lg: 18px; --r-md: 14px; --r-sm: 10px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17181b; --bg2: #101113; --surface: #1f2125; --text: #f1efe9; --hint: #8d8f96; --link: #6ea8ff;
    --accent: #6ea8ff; --on-accent: #0d1117; --line: rgba(255,255,255,.08); --paper: #2a2620; --paper-ink: #efe6d2;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px -14px rgba(0,0,0,.7); color-scheme: dark;
  }
}
:root[data-theme="dark"] { --paper: #2a2620; --paper-ink: #efe6d2; --line: rgba(255,255,255,.08);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px -14px rgba(0,0,0,.7); color-scheme: dark; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }      /* layers with display:grid must still vanish when hidden */
html, body { margin: 0; background: var(--bg2); color: var(--text); font: 15px/1.4 var(--font); }
body.locked { overflow: hidden; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
button:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3, h4, p { margin: 0; }
.muted { color: var(--hint); }
.tiny { font-size: 12px; }
.clamp1, .clamp2 { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
.clamp1 { -webkit-line-clamp: 1; } .clamp2 { -webkit-line-clamp: 2; }
.pre { white-space: pre-wrap; }
.pad { padding: 8px 4px; }

/* ── top ── */
#app { max-width: 760px; margin: 0 auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); }
.boot { min-height: 70vh; display: grid; place-content: center; justify-items: center; gap: 14px; }
.top { display: flex; align-items: center; justify-content: space-between; padding: 14px 0 10px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 22px; letter-spacing: -.02em; font-weight: 750; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; flex: none; position: relative;
  background: conic-gradient(from 210deg, var(--wait), var(--work), var(--accent), var(--wait)); box-shadow: var(--shadow); }
.brand-mark::after { content: ""; position: absolute; inset: 0; margin: auto; width: 0; height: 0; transform: translateX(2px);
  border-left: 11px solid #fff; border-top: 7px solid transparent; border-bottom: 7px solid transparent; }
.brand-mark.big { width: 56px; height: 56px; border-radius: 16px; animation: breathe 1.6s var(--ease) infinite; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; background: var(--surface); font-size: 19px; box-shadow: var(--shadow);
  transition: transform .2s var(--ease); }
.icon-btn:active { transform: rotate(-90deg) scale(.92); }

/* ── live banner ── */
.live { width: 100%; display: flex; align-items: center; gap: 12px; text-align: left; padding: 12px 14px; margin: 4px 0 12px;
  border-radius: var(--r-lg); color: #f4f1ff; position: relative; isolation: isolate; overflow: hidden;
  background: linear-gradient(120deg, #2b2063, #4b2fb3 55%, #7a5af5); box-shadow: 0 10px 30px -14px #4b2fb3; }
.live::before { content: ""; position: absolute; inset: -40%; z-index: -1; opacity: .35;
  background: radial-gradient(closest-side, #b9a6ff, transparent 70%); animation: drift 6s ease-in-out infinite alternate; }
.live.idle { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.live.idle::before { display: none; }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: #7dffb2; flex: none; box-shadow: 0 0 0 0 rgba(125,255,178,.7);
  animation: pulse 1.8s infinite; }
.live-dot.idle { background: var(--wait); animation: none; }
.live-text { display: grid; gap: 1px; min-width: 0; flex: 1; }
.live-what { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; opacity: .75; }
.live-stage { font-size: 13px; opacity: .92; }
.live-time { display: grid; justify-items: end; gap: 2px; font-variant-numeric: tabular-nums; font-size: 13px; }
.live .muted { color: inherit; opacity: .7; }

/* ── tabs & chips ── */
.tabs { position: sticky; top: 0; z-index: 5; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
  margin: 0 -16px; padding: 8px 16px; background: color-mix(in srgb, var(--bg2) 88%, transparent); backdrop-filter: blur(12px); }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px;
  font-weight: 600; font-size: 14px; color: var(--hint); transition: background .2s, color .2s; }
.tab.on { background: var(--text); color: var(--bg2); }
.count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; display: inline-grid; place-items: center;
  font-size: 12px; background: var(--line); color: inherit; font-variant-numeric: tabular-nums; }
.tab.on .count { background: color-mix(in srgb, var(--bg2) 25%, transparent); }
.count.hot { background: var(--wait); color: #fff; }
.chips { display: flex; gap: 6px; align-items: center; }
.chips.wrap { flex-wrap: wrap; }
.chips.scroll { overflow-x: auto; scrollbar-width: none; margin: 6px -16px 2px; padding: 2px 16px; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; font-size: 13px;
  background: var(--surface); border: 1px solid var(--line); white-space: nowrap; }
.chip.on { border-color: var(--text); background: var(--text); color: var(--bg2); }
.chip-n { opacity: .55; font-variant-numeric: tabular-nums; }
.chip.tag { color: var(--link); background: color-mix(in srgb, var(--link) 10%, transparent); border-color: transparent; }
.section-head { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; padding: 12px 2px 10px; }

/* ── cards ── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.card { display: flex; flex-direction: column; text-align: left; background: var(--surface); border-radius: var(--r-md);
  overflow: hidden; box-shadow: var(--shadow); transition: transform .25s var(--ease); }
.card:active { transform: scale(.97); }
.card-media { position: relative; aspect-ratio: 9 / 14; background: #000; }
.poster { width: 100%; height: 100%; object-fit: cover; display: block; }
.poster.empty { display: grid; place-items: center; font-size: 34px; background: linear-gradient(160deg, #2a2d33, #121316); }
.poster.script { display: flex; flex-direction: column; justify-content: center; gap: 10px; padding: 16px 14px;
  background: var(--paper) repeating-linear-gradient(180deg, transparent 0 25px, color-mix(in srgb, var(--paper-ink) 9%, transparent) 25px 26px);
  color: var(--paper-ink); }
.script-mark { font-size: 22px; }
.script-title { font-family: var(--serif); font-size: 17px; line-height: 1.25; font-weight: 600;
  display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.card-media::after { content: ""; position: absolute; inset: auto 0 0; height: 42%; pointer-events: none;
  background: linear-gradient(transparent, rgba(0,0,0,.55)); }
.card.script .card-media::after { display: none; }
.badge { position: absolute; top: 8px; left: 8px; font-size: 11px; font-weight: 650; padding: 3px 8px; border-radius: 8px;
  color: #fff; background: rgba(0,0,0,.45); backdrop-filter: blur(8px); }
.card.script .badge { color: var(--paper-ink); background: color-mix(in srgb, var(--paper-ink) 12%, transparent); }
.card-pill { position: absolute; left: 8px; bottom: 8px; z-index: 1; }
.card-body { padding: 10px 12px 12px; display: grid; gap: 6px; }
.card-title { font-weight: 650; font-size: 14px; line-height: 1.3; }
.card-meta { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--hint); flex-wrap: wrap; }
.dot { width: 3px; height: 3px; border-radius: 50%; background: currentColor; }
.tiny.ok { color: var(--ok); } .tiny.bad { color: var(--bad); }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 650; padding: 4px 9px; border-radius: 999px;
  color: #fff; background: var(--gone); white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.pill.wait { background: var(--wait); } .pill.work, .pill.queue { background: var(--work); } .pill.ok { background: var(--ok); }
.pill.bad { background: var(--bad); } .pill.run { background: var(--work); }
.pill.run::before { background: #7dffb2; animation: pulse 1.8s infinite; }

/* ── work rows / tasks ── */
.rows { display: grid; gap: 10px; }
.row { display: flex; gap: 12px; text-align: left; padding: 10px; border-radius: var(--r-md); background: var(--surface);
  box-shadow: var(--shadow); }
.enter > .card, .enter > .row { animation: rise .35s var(--ease) both; }
.row.running { outline: 1.5px solid color-mix(in srgb, var(--work) 55%, transparent); }
.row-thumb { width: 64px; height: 96px; border-radius: var(--r-sm); object-fit: cover; flex: none; background: #000; }
.row-thumb.empty { display: grid; place-items: center; font-size: 24px; background: var(--paper); }
.row-body { min-width: 0; flex: 1; display: grid; align-content: start; gap: 5px; }
.row-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; }
.row-title { font-weight: 650; }
.row-asked { font-size: 13px; color: var(--hint); font-style: italic; }
.row-stage { font-size: 13px; color: var(--work); font-weight: 600; }
.tasks { display: grid; gap: 10px; padding-top: 12px; }
.composer, .task { background: var(--surface); border-radius: var(--r-md); padding: 14px; box-shadow: var(--shadow); display: grid; gap: 8px; }
.composer-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.composer-foot .btn { white-space: nowrap; flex: none; }
.task-text { white-space: pre-wrap; }
.task-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.task-result summary { cursor: pointer; color: var(--link); font-size: 13px; }
.task-result p { font-size: 13px; margin-top: 6px; max-height: 260px; overflow: auto; }

/* ── empty ── */
.empty { display: grid; justify-items: center; text-align: center; gap: 8px; padding: 48px 24px; }
.empty.fatal { min-height: 70vh; align-content: center; }
.empty-art { width: 64px; height: 64px; border-radius: 20px; margin-bottom: 6px;
  background: conic-gradient(from 90deg, var(--ok), var(--accent), var(--work), var(--ok)); opacity: .9;
  mask: radial-gradient(circle at 50% 50%, transparent 15px, #000 16px); }
.empty-art.lock { background: var(--bad); }
.empty p { max-width: 300px; }

/* ── buttons & fields ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 0 16px;
  border-radius: var(--r-md); font-weight: 650; background: var(--bg2); border: 1px solid var(--line); transition: transform .15s var(--ease), filter .15s; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: var(--r-sm); }
.btn.icon { width: 52px; padding: 0; font-size: 18px; flex: none; }
.btn.grow { flex: 1; }
.link { color: var(--link); font-size: 14px; text-align: left; }
.field { width: 100%; font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 10px 12px; resize: vertical; }
.field:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.label { display: flex; justify-content: space-between; font-size: 12.5px; font-weight: 650; color: var(--hint); }
.counter { font-variant-numeric: tabular-nums; font-weight: 500; } .counter.over { color: var(--bad); }

/* ── sheet ── */
.sheet-layer { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,0); transition: background .25s; }
.sheet-layer.open { background: rgba(0,0,0,.45); }
.sheet { position: absolute; inset: 0; top: max(8px, env(safe-area-inset-top)); overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 22px 22px 0 0; transform: translateY(100%); transition: transform .32s var(--ease);
  padding: 0 16px calc(24px + env(safe-area-inset-bottom)); }
.sheet-layer.open .sheet { transform: none; }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 6px; }
.item { max-width: 680px; margin: 0 auto; display: grid; gap: 14px; }
.item-head { display: grid; gap: 8px; padding-top: 4px; }
.item-title { font-size: 21px; line-height: 1.25; letter-spacing: -.01em; }
.kind { font-size: 12px; font-weight: 700; padding: 5px 10px; border-radius: 999px; background: var(--text); color: var(--bg); }
.kind.script { background: var(--paper); color: var(--paper-ink); border: 1px solid color-mix(in srgb, var(--paper-ink) 15%, transparent); }
.links { display: flex; gap: 14px; flex-wrap: wrap; }
.player { border-radius: var(--r-lg); overflow: hidden; background: #000; box-shadow: var(--shadow); display: grid; place-items: center; }
.player video { width: 100%; max-height: 68vh; aspect-ratio: 9 / 16; object-fit: contain; display: block; background: #000; }
.block { background: var(--surface); border-radius: var(--r-md); padding: 14px; display: grid; gap: 10px; box-shadow: var(--shadow); }
.block h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--hint); font-weight: 700; }
.lead { font-family: var(--serif); font-size: 18px; line-height: 1.35; }
.scenes { margin: 0; padding-left: 22px; display: grid; gap: 10px; font-family: var(--serif); font-size: 16.5px; line-height: 1.45; }
.scenes li::marker { color: var(--hint); font-family: var(--font); font-size: 13px; font-weight: 700; }
.sources { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: 13.5px; }
.sources li { display: grid; gap: 2px; }
.yt { display: grid; gap: 8px; }
.yt-title { font-weight: 700; font-size: 16px; }
.yt-desc { white-space: pre-wrap; }
.quote { margin: 0; padding: 10px 14px; border-left: 3px solid var(--work); background: color-mix(in srgb, var(--work) 8%, transparent);
  border-radius: 0 var(--r-sm) var(--r-sm) 0; display: grid; gap: 4px; }
.quote cite { font-size: 12px; color: var(--hint); font-style: normal; }
.alert { padding: 10px 14px; border-radius: var(--r-sm); background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); font-size: 14px; }
.path { font: 12.5px/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace; word-break: break-all; color: var(--hint); }
.job { display: grid; gap: 8px; }
.job-head { display: flex; align-items: center; gap: 10px; }
.job-head .muted { margin-left: auto; font-variant-numeric: tabular-nums; }
.job .live-dot { background: var(--ok); }
.steps { margin: 0; padding-left: 22px; display: grid; gap: 3px; font-size: 13.5px; color: var(--hint); }
.steps li::marker { content: "✓  "; color: var(--ok); }
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); display: grid; gap: 4px; }
.timeline li { position: relative; }
.timeline li::before { content: ""; position: absolute; left: -20px; top: 14px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--hint); }
.timeline li.current::before { background: var(--accent); border-color: var(--accent); }
.tl-btn { display: grid; gap: 2px; text-align: left; padding: 8px 10px; border-radius: var(--r-sm); width: 100%; }
.tl-btn:not(:disabled):hover { background: var(--bg2); }
.tl-btn:disabled { opacity: 1; }
.tl-kind { font-weight: 650; font-size: 14px; } .tl-status { font-size: 12.5px; color: var(--hint); }
.tl-feedback { font-size: 13px; font-style: italic; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; }
.actionbar { position: sticky; bottom: 0; z-index: 2; display: flex; gap: 8px; padding: 12px 0 calc(4px + env(safe-area-inset-bottom));
  margin: 0 -16px; padding-left: 16px; padding-right: 16px; padding-top: 22px;
  background: linear-gradient(transparent, var(--bg) 20px); }
.spacer { height: 12px; }
.editor { display: grid; gap: 14px; }
.edit-note { padding: 10px 14px; border-radius: var(--r-sm); background: color-mix(in srgb, var(--accent) 10%, transparent); font-size: 14px; }
.edit-field { display: grid; gap: 6px; }
.skeleton { height: 22px; border-radius: 10px; background: linear-gradient(90deg, var(--line), transparent, var(--line));
  background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
.skeleton.tall { height: 52vh; border-radius: var(--r-lg); } .skeleton.short { width: 60%; }

/* ── dialogs & toast ── */
.dialog-layer { position: fixed; inset: 0; z-index: 40; display: grid; place-items: end center; padding: 16px;
  background: rgba(0,0,0,0); transition: background .2s; }
.dialog-layer.open { background: rgba(0,0,0,.5); }
.dialog { width: min(520px, 100%); background: var(--surface); border-radius: 20px; padding: 18px; display: grid; gap: 12px;
  transform: translateY(24px); opacity: 0; transition: transform .25s var(--ease), opacity .2s;
  margin-bottom: env(safe-area-inset-bottom); }
.dialog-layer.open .dialog { transform: none; opacity: 1; }
.dialog h3 { font-size: 18px; }
.dialog-actions { display: flex; gap: 8px; } .dialog-actions .btn { flex: 1; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 60; max-width: calc(100% - 32px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; padding: 10px 16px; border-radius: 14px;
  background: var(--text); color: var(--bg); font-size: 14px; font-weight: 600; transition: transform .25s var(--ease), opacity .25s; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.error { background: var(--bad); color: #fff; } .toast.ok { background: var(--ok); color: #fff; } .toast.warn { background: var(--wait); color: #fff; }

@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(125,255,178,.7); } 70% { box-shadow: 0 0 0 8px rgba(125,255,178,0); } 100% { box-shadow: 0 0 0 0 rgba(125,255,178,0); } }
@keyframes drift { from { transform: translate(-10%, -5%); } to { transform: translate(15%, 10%); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes breathe { 50% { transform: scale(.92); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media (min-width: 600px) { .grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); } }
