:root {
  --bg: #0b0f14;
  --panel: #121820;
  --panel2: #171f29;
  --line: #232d3a;
  --text: #dbe4ee;
  --dim: #8b98a8;
  --accent: #2dd4bf;
  --accent2: #f59e0b;
  --danger: #ef4444;
  --ok: #22c55e;
  --sel: #38bdf8;
  font-size: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: var(--panel); gap: 12px; flex-wrap: wrap;
}
.brand h1 { font-size: 16px; letter-spacing: .3px; }
.brand .sub { font-size: 12px; color: var(--dim); }
.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.btn {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 12px; cursor: pointer; font-size: 13px;
  transition: border-color .15s, background .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: #0e3b36; border-color: var(--accent); }
.btn.danger:hover { border-color: var(--danger); color: #fca5a5; }
.btn.mini { padding: 5px 9px; font-size: 12px; }
.side-actions { display: flex; gap: 6px; padding: 8px 10px 0; }
.side-actions .btn { flex: 1; }
.lib-actions { display: flex; gap: 6px; margin-bottom: 7px; }
.lib-actions .btn { flex: 1; }
.save-state { font-size: 12px; color: var(--dim); min-width: 90px; }
.save-state.dirty { color: var(--accent2); }

/* ---------- layout ---------- */
.layout {
  flex: 1; display: grid; min-height: 0;
  grid-template-columns: 300px 1fr 360px;
}
.left, .right { background: var(--panel); overflow-y: auto; min-height: 0; }
.left { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.right { border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.center { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 12px 14px; gap: 10px; }

/* ---------- tabs ---------- */
.tabs { display: flex; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.tab {
  flex: 1; background: none; border: none; color: var(--dim); padding: 10px 4px;
  cursor: pointer; font-size: 13px; border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-panel { display: none; padding: 10px; }
.tab-panel.active { display: block; }
.panel-note { font-size: 12px; color: var(--dim); margin-bottom: 10px; line-height: 1.4; }

/* ---------- phases ---------- */
.phase-list { display: flex; flex-direction: column; gap: 6px; }
.phase-item {
  text-align: left; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 11px; cursor: pointer; color: var(--text);
}
.phase-item:hover { border-color: var(--accent); }
.phase-item.active { border-color: var(--accent); background: #0e2a28; }
.phase-item .p-time { font-size: 11px; color: var(--accent2); letter-spacing: .4px; }
.phase-item .p-title { font-size: 13px; margin-top: 2px; line-height: 1.3; }
.phase-item .p-edited { font-size: 10px; color: var(--accent2); margin-top: 3px; display: none; }
.phase-item.has-edits .p-edited { display: block; }
.phase-item { position: relative; }
.phase-item .p-del {
  position: absolute; top: 6px; right: 8px; font-size: 11px; color: var(--dim);
  padding: 2px 5px; border-radius: 5px; display: none;
}
.phase-item:hover .p-del { display: inline; }
.phase-item .p-del:hover { color: #fca5a5; background: rgba(239,68,68,.15); }

/* ---------- runshow ---------- */
.runshow { width: 100%; border-collapse: collapse; font-size: 12px; }
.runshow td { padding: 7px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.runshow tr:hover td { background: var(--panel2); }
.runshow .t { color: var(--accent2); white-space: nowrap; width: 44px; }
.runshow .s { color: var(--dim); }

/* ---------- fights ---------- */
.fight-list { display: flex; flex-direction: column; gap: 10px; }
.fight-card { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px; }
.fight-card h4 { font-size: 12px; color: var(--accent2); margin-bottom: 7px; letter-spacing: .4px; }
.corner { display: flex; gap: 8px; align-items: center; margin: 5px 0; }
.corner img { width: 38px; height: 38px; border-radius: 6px; object-fit: cover; background: #000; }
.corner .who { min-width: 0; }
.corner .name { font-size: 13px; }
.corner .meta { font-size: 11px; color: var(--dim); }
.tag { font-size: 10px; padding: 1px 6px; border-radius: 4px; margin-right: 4px; white-space: nowrap; }
.tag.blue { background: #123a5e; color: #7cc4ff; }
.tag.red { background: #5e1b1b; color: #ff9a9a; }
.tag.vid { background: #14331f; color: #6ee7a0; }
.tag.novid { background: #3a3a20; color: #e7d06e; }
.vids { font-size: 11px; color: var(--dim); margin-top: 4px; }
.vids b { color: var(--ok); font-weight: 600; }

/* ---------- phase bar ---------- */
.phase-bar {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px;
}
.phase-bar h2 { font-size: 16px; }
.phase-note { font-size: 12.5px; color: var(--dim); margin-top: 4px; line-height: 1.45; max-width: 900px; }
.phase-time { font-size: 12px; color: var(--accent2); white-space: nowrap; border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; }

/* ---------- stage ---------- */
.stage-viewport {
  flex: 1; min-height: 0; position: relative;
  background: radial-gradient(ellipse at 50% 30%, #101923 0%, #0a0e13 70%);
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
}
.stage { position: absolute; left: 50%; top: 50%; width: 1600px; height: 900px; transform-origin: center; }
.floor {
  position: absolute; left: 3%; right: 3%; top: 66%; height: 30%;
  background: linear-gradient(180deg, rgba(45,212,191,.05), rgba(0,0,0,0));
  border-top: 1px solid rgba(45,212,191,.15); border-radius: 50% 50% 0 0 / 18% 18% 0 0;
}
.zone-label {
  position: absolute; font-size: 11px; letter-spacing: 1.6px; color: #47606f;
  white-space: nowrap; transform: translateX(-50%);
}
.lbl-sides-l { left: 9.7%; top: 190px; }
.lbl-sides-r { left: 90.3%; top: 190px; }
.lbl-cube { left: 50%; top: 30px; }

.zone {
  position: absolute; border: 1.5px solid #2b3b4d; border-radius: 6px;
  background: #05080c; overflow: hidden; cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.zone:hover { border-color: #4b6478; }
.zone.selected { border-color: var(--sel); box-shadow: 0 0 0 2px rgba(56,189,248,.35), 0 0 18px rgba(56,189,248,.25); z-index: 5; }
.zone.drag-over { border-color: var(--accent2); box-shadow: 0 0 0 3px rgba(245,158,11,.4); }
.zone video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.zone.empty { border-style: dashed; display: flex; align-items: center; justify-content: center; }
.zone .empty-hint {
  font-size: 12px; color: #44606f; text-align: center; padding: 4px; line-height: 1.35;
}
.zone .z-head {
  position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 5px;
  padding: 3px 6px; font-size: 10.5px; z-index: 3;
  background: linear-gradient(180deg, rgba(0,0,0,.78), rgba(0,0,0,0));
  pointer-events: none;
}
.zone .z-name { color: #cfe3f5; text-shadow: 0 1px 2px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.zone .z-fit { margin-left: auto; font-size: 10px; padding: 0 5px; border-radius: 4px; white-space: nowrap; }
.zone .z-fit.ok { background: rgba(34,197,94,.25); color: #86efac; }
.zone .z-fit.warn { background: rgba(245,158,11,.28); color: #fcd34d; }
.zone .z-file {
  position: absolute; left: 6px; bottom: 4px; right: 6px; font-size: 10px; color: #9fb6c9;
  text-shadow: 0 1px 2px #000; z-index: 3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  pointer-events: none;
}
.zone .z-tools {
  position: absolute; right: 4px; bottom: 4px; display: none; gap: 4px; z-index: 4;
}
.zone:hover .z-tools { display: flex; }
.z-tool {
  width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--line);
  background: rgba(10,14,20,.85); color: var(--text); cursor: pointer; font-size: 12px;
}
.z-tool:hover { border-color: var(--accent); }
.zone .z-err {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #fca5a5; font-size: 12px; text-align: center; padding: 6px; z-index: 2;
}

/* ---------- inspector ---------- */
.zone-inspector {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 14px; min-height: 58px; font-size: 12.5px;
}
.zone-inspector .insp-title { font-size: 13px; margin-bottom: 3px; }
.zone-inspector .insp-body { color: var(--dim); line-height: 1.45; }
.zone-inspector .insp-actions { margin-top: 7px; display: flex; gap: 8px; }
.zone-inspector .btn { padding: 5px 10px; font-size: 12px; }

/* ---------- library ---------- */
.lib-head { padding: 12px 12px 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.lib-head h3 { font-size: 14px; margin-bottom: 8px; }
.lib-head input[type="search"], .lib-head select {
  width: 100%; background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 7px 9px; font-size: 13px; margin-bottom: 7px;
}
.all-phases { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--dim); cursor: pointer; }
.lib-grid { flex: 1; overflow-y: auto; padding: 10px 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-content: start; }
.lib-card {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; cursor: grab; transition: border-color .15s;
}
.lib-card:hover { border-color: var(--accent); }
.lib-card .thumb { position: relative; aspect-ratio: 16/9; background: #000; }
.lib-card .thumb video, .lib-card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lib-card .thumb .dur {
  position: absolute; right: 4px; bottom: 4px; font-size: 10px; background: rgba(0,0,0,.75);
  padding: 1px 5px; border-radius: 4px;
}
.lib-card .meta { padding: 6px 8px 7px; }
.lib-card .name { font-size: 11.5px; line-height: 1.3; word-break: break-word; }
.lib-card .dims { font-size: 10px; color: var(--dim); margin-top: 3px; }
.lib-card .grp { font-size: 10px; color: var(--accent); margin-top: 2px; }
.lib-foot { padding: 8px 12px; border-top: 1px solid var(--line); font-size: 11px; color: var(--dim); }

@media (max-width: 1200px) {
  .layout { grid-template-columns: 240px 1fr 300px; }
}

/* ---------- view switch ---------- */
.bar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.view-switch { display: flex; gap: 3px; background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 3px; }
.view-switch button { background: none; border: none; color: var(--dim); padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 12.5px; white-space: nowrap; }
.view-switch button:hover { color: var(--text); }
.view-switch button.active { background: #0e3b36; color: var(--accent); }
.btn.toggle.active { border-color: var(--accent2); color: var(--accent2); }

/* ---------- фотореалистичные виды сцены ---------- */
.scene-view { position: absolute; inset: 0; display: none; }
.scene-view.active { display: block; }
.photo {
  position: absolute; left: 50%; top: 50%; width: 1280px; height: 720px;
  transform-origin: center; background-size: contain; background-repeat: no-repeat;
  background-position: center;
}
.stage.hidden { display: none; }
.szone { position: absolute; inset: 0; pointer-events: none; }
.squad {
  position: absolute; left: 0; top: 0; width: 1280px; height: 720px;
  transform-origin: 0 0; pointer-events: auto; cursor: pointer;
}
.squad video { width: 100%; height: 100%; object-fit: fill; display: block; background: transparent; }
.squad:hover video { outline: 1.5px solid #4b6478; }
.squad.selected video { outline: 2.5px solid var(--sel); box-shadow: 0 0 22px rgba(56,189,248,.4); }
.squad.drag-over video { outline: 3px solid var(--accent2) !important; }
.squad-ui { position: absolute; pointer-events: none; z-index: 3; }
.squad-ui .z-head { position: absolute; left: 0; right: 0; top: 0; display: flex; gap: 5px; padding: 3px 6px; font-size: 10.5px; background: linear-gradient(180deg, rgba(0,0,0,.8), rgba(0,0,0,0)); }
.squad-ui .z-name { color: #cfe3f5; text-shadow: 0 1px 2px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.squad-ui .z-fit { margin-left: auto; font-size: 10px; padding: 0 5px; border-radius: 4px; white-space: nowrap; }
.squad-ui .z-fit.ok { background: rgba(34,197,94,.3); color: #86efac; }
.squad-ui .z-fit.warn { background: rgba(245,158,11,.32); color: #fcd34d; }
.squad-ui .z-file { position: absolute; left: 6px; bottom: 4px; right: 6px; font-size: 10px; color: #cfe3f5; text-shadow: 0 1px 2px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.squad-ui .z-err { position: absolute; left: 0; right: 0; top: 40%; text-align: center; color: #fca5a5; font-size: 12px; text-shadow: 0 1px 3px #000; padding: 4px; }
.squad-empty {
  position: absolute; border: 1.5px dashed rgba(90,130,160,.55); border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: rgba(140,180,210,.75); text-align: center; line-height: 1.35;
  background: rgba(10,16,24,.25); padding: 3px;
}

/* ---------- подписи в фотовидах (вкл кнопкой) ---------- */
.scene-view .z-head, .scene-view .z-file { display: none; }
.stage-viewport.labels-on .scene-view.active .z-head { display: flex; }
.stage-viewport.labels-on .scene-view.active .z-file { display: block; }

/* ---------- редактор фреймов ---------- */
.editor-layer { position: absolute; inset: 0; z-index: 20; pointer-events: none; }
.editor-hint {
  position: absolute; left: 10px; bottom: 8px; font-size: 11.5px; color: var(--accent2);
  background: rgba(10,14,20,.85); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px;
}
.qdot {
  position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%;
  background: var(--accent2); border: 2px solid #0a0e13; pointer-events: auto; cursor: grab;
  z-index: 21; box-shadow: 0 0 6px rgba(0,0,0,.6);
}
.qdot:active { cursor: grabbing; }
.qdot.sel { background: var(--sel); }
.qtag {
  position: absolute; transform: translate(-50%, -140%); font-size: 10px; color: #ffe9b0;
  background: rgba(10,14,20,.8); padding: 1px 5px; border-radius: 4px; white-space: nowrap;
  pointer-events: none; text-shadow: none;
}
