:root {
  --bg: #0f0f12; --bg2: #16161b; --panel: #1b1b21; --panel2: #23232b; --line: #2d2d36; --line2: #3a3a45;
  --text: #ecebe8; --muted: #9b9aa3; --dim: #6c6b75; --accent: #c96442; --accent2: #e07a52; --accent-soft: rgba(201,100,66,.18);
  --ok: #3ccf8e; --warn: #f5b942; --bad: #ef5b5b; --sel: #ffd166;
  --k-bg: #475569; --k-image: #16a34a; --k-video: #15803d; --k-emoji: #d97706; --k-shape: #0d9488; --k-text: #7c3aed; --k-counter: #9333ea;
  --k-captions: #2563eb; --k-particles: #db2777; --k-fx: #be185d; --k-progress: #64748b; --k-voice: #ea580c; --k-music: #4f46e5; --k-sfx: #0891b2;
  --radius: 10px; --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --tl-h: 290px; --left-w: 330px; --right-w: 300px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.4 var(--font); }
body { overflow: hidden; }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent2); }
.muted { color: var(--muted); }
.err { color: var(--bad); min-height: 1.2em; }
.spacer { flex: 1; }
h3 { margin: 14px 0 8px; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
h3:first-child { margin-top: 2px; }

/* ---------- boot / login ---------- */
.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 20% 0%, rgba(201,100,66,.18), transparent), var(--bg); }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: grid; gap: 14px; }
.login-card label { display: grid; gap: 6px; color: var(--muted); }
.brand { display: flex; align-items: center; gap: 8px; font-size: 16px; letter-spacing: -.01em; white-space: nowrap; }
.brand img { width: 26px; height: 26px; }
.brand b { color: var(--accent2); }
.brand.big { font-size: 26px; } .brand.big img { width: 40px; height: 40px; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line2); background: var(--panel2);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: #2c2c36; border-color: #4a4a57; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent2); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel2); border-color: var(--line); }
.btn.icon { padding: 6px 8px; font-size: 15px; line-height: 1; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.wide { width: 100%; padding: 9px; }
.btn.danger { color: #ffb4b4; border-color: #5a2a2a; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: #ffd9cc; }
.btn.play { width: 42px; height: 42px; border-radius: 50%; background: var(--text); color: #111; border: 0; font-size: 16px; }
.btn.play:hover { background: #fff; }
input[type=text], input[type=password], input[type=number], input[type=search], input:not([type]), select, textarea {
  width: 100%; background: var(--bg2); border: 1px solid var(--line2); border-radius: 8px; padding: 7px 9px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=color] { width: 34px; height: 28px; padding: 0; border: 1px solid var(--line2); border-radius: 6px; background: none; cursor: pointer; }
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line2); background: var(--bg2); border-radius: 999px; padding: 5px 12px; cursor: pointer; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.field { display: grid; gap: 5px; margin-bottom: 10px; }
.field > span { color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.check { display: flex; gap: 8px; align-items: center; cursor: pointer; padding: 3px 0; }
.card { background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.note { font-size: 12px; color: var(--muted); }
.kbd { font: 11px ui-monospace, monospace; background: var(--bg2); border: 1px solid var(--line2); border-radius: 4px; padding: 0 4px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-rows: 50px 1fr var(--tl-h); height: 100vh; height: 100dvh; }
.topbar { display: flex; align-items: center; gap: 6px; padding: 0 10px; border-bottom: 1px solid var(--line); background: var(--bg2); min-width: 0; }
.title-input { max-width: 340px; background: transparent !important; border-color: transparent !important; font-weight: 600; font-size: 14px; }
.title-input:hover, .title-input:focus { border-color: var(--line2) !important; background: var(--bg) !important; }
.save-state { color: var(--dim); font-size: 12px; white-space: nowrap; }
.queue-state { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.workspace { display: grid; grid-template-columns: var(--left-w) 1fr var(--right-w); min-height: 0; }
.left, .right { background: var(--panel); min-height: 0; display: flex; flex-direction: column; }
.left { border-right: 1px solid var(--line); }
.right { border-left: 1px solid var(--line); }
.panel { overflow-y: auto; padding: 12px; flex: 1; min-height: 0; }
.tabs { display: flex; gap: 2px; padding: 6px 6px 0; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; flex-shrink: 0; }
.tab { border: 0; background: none; padding: 8px 9px 9px; border-bottom: 2px solid transparent; cursor: pointer; color: var(--muted); white-space: nowrap; }
.tab .ico { font-size: 15px; display: block; text-align: center; }
.tab .lbl { font-size: 11px; }
.tab.on { color: var(--text); border-bottom-color: var(--accent); }
.center { display: grid; grid-template-rows: 1fr auto; min-height: 0; min-width: 0; background: #0b0b0d; }
.stage { position: relative; min-height: 0; display: grid; place-items: center; padding: 12px; overflow: hidden; }
.canvas-wrap { position: relative; aspect-ratio: 9/16; height: 100%; max-width: 100%; border-radius: 12px; overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,.6), 0 0 0 1px #26262e; background: #000; }
#preview { width: 100%; height: 100%; display: block; touch-action: none; cursor: default; }
.safe-zones > div { position: absolute; background: rgba(255,60,60,.16); border: 1px dashed rgba(255,120,120,.6); pointer-events: none; }
.sz-top { left: 0; right: 0; top: 0; height: 8%; }
.sz-right { right: 0; top: 40%; width: 15%; height: 42%; }
.sz-bottom { left: 0; right: 0; bottom: 0; height: 18%; }
.stage-empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; color: var(--muted);
  background: radial-gradient(circle at 50% 30%, #2a1d18, #0c0c0e 70%); }
.stage-empty .big { font-size: 46px; }
.transport { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--line); background: var(--bg2); }
.time { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); margin-left: 6px; }

/* ---------- timeline ---------- */
.timeline { border-top: 1px solid var(--line); background: var(--bg2); display: grid; grid-template-rows: 38px 1fr; min-height: 0; position: relative; }
.timeline::before { content: ""; position: absolute; top: -4px; left: 0; right: 0; height: 7px; cursor: ns-resize; z-index: 5; }
.tl-toolbar { display: flex; align-items: center; gap: 4px; padding: 0 8px; border-bottom: 1px solid var(--line); }
.tl-toolbar .zoom { width: 120px; }
.tl-body { display: grid; grid-template-columns: 150px 1fr; min-height: 0; overflow: hidden; }
.tl-heads { overflow: hidden; border-right: 1px solid var(--line); background: var(--panel); }
.tl-heads .hspacer { height: 26px; border-bottom: 1px solid var(--line); }
.tl-head { height: 40px; display: flex; align-items: center; gap: 4px; padding: 0 6px; border-bottom: 1px solid var(--line); font-size: 12px; }
.tl-head.audio { height: 46px; }
.tl-head .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-head button { border: 0; background: none; cursor: pointer; color: var(--dim); padding: 2px 3px; border-radius: 4px; font-size: 12px; }
.tl-head button:hover { color: var(--text); background: var(--panel2); }
.tl-head button.off { color: var(--bad); }
.tl-scroll { overflow: auto; position: relative; }
.tl-inner { position: relative; min-width: 100%; }
.tl-ruler { height: 26px; position: sticky; top: 0; z-index: 3; background: var(--bg2); border-bottom: 1px solid var(--line); cursor: pointer; }
.tl-ruler .tick { position: absolute; bottom: 0; width: 1px; background: var(--line2); }
.tl-ruler .lab { position: absolute; top: 3px; font: 10px ui-monospace, monospace; color: var(--dim); transform: translateX(3px); }
.tl-ruler .end { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); opacity: .7; }
.tl-lane { position: relative; height: 40px; border-bottom: 1px solid var(--line); }
.tl-lane.audio { height: 46px; }
.tl-lane.drop { background: rgba(201,100,66,.08); }
.tl-lane .past-end { position: absolute; top: 0; bottom: 0; background: repeating-linear-gradient(45deg, transparent 0 6px, rgba(255,255,255,.025) 6px 12px); pointer-events: none; }
.clip { position: absolute; top: 4px; bottom: 4px; border-radius: 6px; background: var(--kc, #555); border: 1px solid rgba(255,255,255,.14);
  color: #fff; font-size: 11px; overflow: hidden; cursor: grab; display: flex; align-items: center; gap: 4px; padding: 0 8px; user-select: none;
  box-shadow: inset 0 -12px 18px rgba(0,0,0,.18); }
.clip:active { cursor: grabbing; }
.clip.sel { outline: 2px solid var(--sel); outline-offset: 0; z-index: 2; }
.clip .lab { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative; z-index: 1; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
.clip .emo { font-size: 15px; position: relative; z-index: 1; }
.clip canvas.wave { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .55; pointer-events: none; }
.clip .h { position: absolute; top: 0; bottom: 0; width: 8px; cursor: ew-resize; z-index: 2; }
.clip .h.l { left: 0; } .clip .h.r { right: 0; }
.clip .h:hover { background: rgba(255,255,255,.25); }
.clip.locked { opacity: .6; cursor: not-allowed; }
.tl-playhead { position: absolute; top: 0; bottom: 0; width: 0; z-index: 4; pointer-events: none; }
.tl-playhead::after { content: ""; position: absolute; top: 0; bottom: 0; left: -1px; width: 2px; background: var(--sel); }
.ph-knob { position: absolute; top: 2px; left: -7px; width: 14px; height: 14px; background: var(--sel); border-radius: 3px 3px 7px 7px; pointer-events: auto; cursor: ew-resize; }
.snapline { position: absolute; top: 0; bottom: 0; width: 1px; background: #4cc9f0; z-index: 3; pointer-events: none; }

/* ---------- left panel content ---------- */
.lib-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.lib-item { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 4px 7px; text-align: center; cursor: pointer; }
.lib-item:hover { border-color: var(--accent); background: #2a2420; }
.lib-item .i { font-size: 22px; display: block; }
.lib-item .n { font-size: 11px; color: var(--muted); display: block; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 2px; }
.emoji-grid button { border: 0; background: none; font-size: 24px; padding: 4px 0; border-radius: 6px; cursor: pointer; }
.emoji-grid button img { width: 28px; height: 28px; display: block; margin: auto; }
.emoji-grid button:hover { background: var(--panel2); }
.list { display: grid; gap: 4px; }
.list-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; }
.list-item .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.media-item { position: relative; aspect-ratio: 9/14; border-radius: 8px; overflow: hidden; background: var(--panel2); border: 1px solid var(--line); cursor: pointer; }
.media-item img, .media-item video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-item .badge { position: absolute; left: 4px; top: 4px; background: rgba(0,0,0,.65); border-radius: 4px; padding: 0 4px; font-size: 10px; }
.media-item .x { position: absolute; right: 3px; top: 3px; background: rgba(0,0,0,.6); border: 0; color: #fff; border-radius: 4px; cursor: pointer; padding: 0 5px; }
.media-item .lic { position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(transparent, rgba(0,0,0,.85)); font-size: 9.5px; padding: 10px 4px 3px; color: #ddd;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-item.audio { aspect-ratio: auto; padding: 8px; }
.dropzone { border: 1.5px dashed var(--line2); border-radius: 10px; padding: 14px; text-align: center; color: var(--muted); cursor: pointer; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.steps { display: grid; gap: 4px; }
.step { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px; background: var(--panel2); border: 1px solid var(--line); }
.step .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line2); flex-shrink: 0; }
.step.done .dot { background: var(--ok); } .step.stale .dot { background: var(--warn); } .step.run .dot { background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.step .nm { flex: 1; }
.step .info { color: var(--dim); font-size: 11px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress { height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); width: 0; transition: width .3s; }
.joblog { font: 11px/1.45 ui-monospace, monospace; color: var(--muted); max-height: 160px; overflow: auto; white-space: pre-wrap; background: var(--bg); border-radius: 8px; padding: 8px; margin-top: 8px; }
.live-script { font-size: 12px; color: #d6d3cf; background: var(--bg); border-radius: 8px; padding: 8px; max-height: 140px; overflow: auto; white-space: pre-wrap; margin-top: 8px; }
.script-line { display: grid; grid-template-columns: 22px 1fr; gap: 6px; padding: 8px; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; }
.script-line .num { color: var(--dim); font-size: 11px; padding-top: 6px; }
.script-line textarea { min-height: 44px; }
.script-line .meta { display: grid; grid-template-columns: 1fr 64px; gap: 6px; margin-top: 6px; }
.script-line.dropped { opacity: .5; }
.facts li { margin-bottom: 4px; color: #cfccc8; }

/* ---------- inspector ---------- */
.insp-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.insp-head .kicon { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-size: 16px; background: var(--kc); }
.insp-head input { font-weight: 600; }
.insp-sec { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.f { display: grid; grid-template-columns: 92px 1fr; gap: 8px; align-items: center; margin-bottom: 7px; }
.f > label { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.f .rng { display: grid; grid-template-columns: 1fr 58px; gap: 6px; align-items: center; }
.f .rng input[type=number] { padding: 4px 6px; }
.f .col { display: flex; gap: 6px; align-items: center; }
.f .col input[type=text] { padding: 4px 6px; font: 11px ui-monospace, monospace; }
.colors { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.emoji-btn { font-size: 26px; background: var(--bg2); border: 1px solid var(--line2); border-radius: 8px; cursor: pointer; padding: 2px 10px; }
.kf-list { display: grid; gap: 3px; }
.kf-list .list-item { padding: 3px 6px; font-size: 11px; }

/* ---------- modals / toasts ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line2); border-radius: 14px; width: min(860px, 100%); max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.modal.narrow { width: min(520px, 100%); }
.modal header { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); gap: 8px; }
.modal header h2 { margin: 0; font-size: 15px; flex: 1; }
.modal .body { padding: 16px; overflow: auto; }
.proj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.proj { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; display: flex; flex-direction: column; }
.proj:hover { border-color: var(--accent); }
.proj .th { aspect-ratio: 9/12; background: #0b0b0d center/cover no-repeat; display: grid; place-items: center; font-size: 34px; }
.proj .meta { padding: 8px; display: grid; gap: 2px; }
.proj .meta b { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj .meta span { font-size: 11px; color: var(--dim); }
.proj .acts { display: flex; gap: 4px; padding: 0 8px 8px; }
.renders { display: grid; gap: 12px; }
.render { display: grid; grid-template-columns: 150px 1fr; gap: 14px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.render video { width: 150px; aspect-ratio: 9/16; border-radius: 8px; background: #000; }
.render .links { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.sheet { white-space: pre-wrap; font-size: 12px; background: var(--bg); border-radius: 8px; padding: 10px; max-height: 220px; overflow: auto; color: #d6d3cf; }
.toasts { position: fixed; right: 14px; bottom: 14px; display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--panel2); border: 1px solid var(--line2); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 8px; max-width: 360px; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.toast.bad { border-left-color: var(--bad); } .toast.ok { border-left-color: var(--ok); }
.picker { position: fixed; z-index: 55; width: 340px; max-height: 380px; background: var(--panel); border: 1px solid var(--line2); border-radius: 12px; padding: 8px; display: flex; flex-direction: column; gap: 6px; box-shadow: 0 20px 50px rgba(0,0,0,.5); }
.picker .emoji-grid { overflow: auto; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) { :root { --left-w: 290px; --right-w: 260px; } }
@media (max-width: 920px) {
  body { overflow: auto; }
  .app { grid-template-rows: auto auto auto; height: auto; }
  .topbar { flex-wrap: wrap; padding: 6px 8px; height: auto; }
  .title-input { order: 10; max-width: none; flex-basis: 100%; }
  .workspace { grid-template-columns: 1fr; }
  .center { order: -1; }
  .stage { height: 62vh; }
  .left, .right { border: 0; border-top: 1px solid var(--line); }
  .left .panel, .right .panel { max-height: 60vh; }
  .timeline { height: 300px; }
  .tl-body { grid-template-columns: 96px 1fr; }
  .queue-state, .save-state { display: none; }
}
