:root {
  --bg: #1a1c20;
  --bg2: #23262c;
  --card: #2a2d34;
  --fg: #e7e9ee;
  --muted: #8a8f99;
  --accent: #6aa8ff;
  --danger: #e85a5a;
  --border: #393c44;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #11131a; padding: 1px 6px; border-radius: 4px; }
button, .btn {
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
button.danger { background: var(--danger); }
button:hover { filter: brightness(1.1); }
input, select, textarea {
  background: var(--bg2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 13px;
  font-family: inherit;
}
textarea { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
label { display: block; margin: 8px 0; }
label.checkbox { display: flex; align-items: center; gap: 8px; }
label.checkbox input { margin: 0; }
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 24px; background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.topbar .brand a { color: var(--fg); font-weight: 600; font-size: 16px; }
.topbar nav { display: flex; gap: 16px; flex: 1; }
.topbar nav a { color: var(--muted); }
.topbar nav a:hover { color: var(--fg); }
.topbar .logout { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.content { padding: 24px; max-width: 1280px; margin: 0 auto; }
h1 { margin: 0 0 16px; }
h2 { margin: 0 0 12px; font-size: 16px; }
.muted { color: var(--muted); }
.error { background: #3a1f1f; color: #ffd3d3; padding: 10px 14px; border-radius: 4px; margin-bottom: 12px; }
.inline { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  margin: 16px 0;
}
.grid {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  background: var(--card);
  border-radius: 6px;
  overflow: hidden;
}
.grid th, .grid td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.grid thead th { background: var(--bg2); color: var(--muted); font-weight: 500; }
.grid tr:last-child td { border-bottom: 0; }
.actions { white-space: nowrap; }
.actions .inline { display: inline-flex; }
.login-card {
  max-width: 360px; margin: 80px auto; background: var(--card);
  padding: 24px; border-radius: 6px; border: 1px solid var(--border);
}
.login-card h1 { font-size: 18px; margin-bottom: 16px; }
.login-card input { width: 100%; }

@media (max-width: 768px) {
  .topbar { flex-wrap: wrap; gap: 12px; padding: 10px 14px; }
  .topbar nav { order: 3; width: 100%; overflow-x: auto; }
  .content { padding: 14px; }
  .grid { font-size: 13px; }
}
@media (max-width: 480px) {
  .grid th, .grid td { padding: 6px 8px; }
}

/* ---------- Visual layout editor ---------- */
.settings-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
.settings-row label { margin: 0; }

.editor-toolbar {
  display: flex; flex-wrap: wrap; gap: 12px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px; margin-bottom: 12px;
}
.editor-toolbar .tb-group { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.editor-toolbar .tb-label { color: var(--muted); font-size: 12px; }
.editor-toolbar input[type=number] { width: 80px; }
.editor-toolbar select, .editor-toolbar input { padding: 4px 8px; font-size: 12px; }
.editor-toolbar button { padding: 4px 10px; font-size: 12px; }

/* Редактор занимает всю ширину карточки — настройки во плавающем окне. */
.editor-main {
  position: relative;
  display: block;
}
.editor-canvas-wrap {
  position: relative;
  background: #0f1115;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0;
  /* без прокрутки — канвас вписывается transform-scale. */
  overflow: hidden;
  /* высоту считаем из доступной высоты экрана, чтобы не было пустоты снизу */
  height: calc(100vh - 320px);
  min-height: 480px;
}
.editor-canvas {
  position: relative;
  background: #202428;
  outline: 1px dashed rgba(255,255,255,.15);
  user-select: none;
  touch-action: none;
}
/* Фон-калька: прозрачный скрин из OBS под слоем элементов. По сети не уходит. */
.editor-canvas .ed-bg-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
  z-index: 1;
  display: none;
}
/* Превью таймера в редакторе — никаких авто-эффектов, как и в реальном оверлее. */
.ed-item-lane .ed-timer { font-variant-numeric: tabular-nums; }
.editor-canvas-info {
  position: absolute;
  top: 4px; right: 8px;
  font-size: 11px; color: var(--muted);
  display: flex; gap: 12px; pointer-events: none;
  background: rgba(0,0,0,.4); padding: 2px 6px; border-radius: 3px;
}

/* Border заменён на inset box-shadow — он не занимает layout-пространства,
   значит геометрия .ed-item ≡ геометрия .item в реальном оверлее. */
.ed-item {
  position: absolute;
  box-shadow: inset 0 0 0 1px rgba(106,168,255,.35);
  cursor: move;
  box-sizing: border-box;
}
.ed-item:hover    { box-shadow: inset 0 0 0 1px rgba(106,168,255,.7); }
.ed-item.selected { box-shadow: inset 0 0 0 2px var(--accent); }
/* Заблокированный элемент — жёлтый рамка-индикатор + не-двигательный курсор. */
.ed-item.locked            { box-shadow: inset 0 0 0 1px rgba(255,209,102,.7); cursor: default; }
.ed-item.locked:hover      { box-shadow: inset 0 0 0 1px rgba(255,209,102,1); }
.ed-item.locked.selected   { box-shadow: inset 0 0 0 2px rgba(255,209,102,1); }
.ed-item-inner {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; justify-content: center;
  overflow: hidden; pointer-events: none;
  line-height: 1;
}
/* Inner — без padding, чтобы геометрия точно совпадала с оверлеем. */
.ed-item-lane .ed-runner { font-size: .25em; opacity: .8; margin-bottom: .25em; }
.ed-placeholder { color: var(--muted); font-size: 12px; padding: 8px; }

.ed-handle {
  position: absolute; width: 10px; height: 10px;
  background: var(--accent); border: 1px solid #fff;
  border-radius: 2px; z-index: 99;
}
.ed-h-nw { top: -5px; left: -5px; cursor: nwse-resize; }
.ed-h-n  { top: -5px; left: calc(50% - 5px); cursor: ns-resize; }
.ed-h-ne { top: -5px; right: -5px; cursor: nesw-resize; }
.ed-h-e  { top: calc(50% - 5px); right: -5px; cursor: ew-resize; }
.ed-h-se { bottom: -5px; right: -5px; cursor: nwse-resize; }
.ed-h-s  { bottom: -5px; left: calc(50% - 5px); cursor: ns-resize; }
.ed-h-sw { bottom: -5px; left: -5px; cursor: nesw-resize; }
.ed-h-w  { top: calc(50% - 5px); left: -5px; cursor: ew-resize; }

/* ---------- Плавающее окно свойств ---------- */
.ed-panel {
  position: absolute;
  width: 320px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  z-index: 100;
  box-shadow: 0 10px 28px rgba(0,0,0,.45);
  user-select: none;
  display: flex;
  flex-direction: column;
  max-height: calc(100% - 24px);
}
.ed-panel[hidden] { display: none; }
.ed-panel-head {
  display: flex; align-items: center;
  padding: 6px 10px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  border-radius: 6px 6px 0 0;
  cursor: move;
  font-weight: 600;
}
.ed-panel-title { flex: 1; font-size: 12px; }
.ed-panel-close {
  background: transparent; color: var(--muted); border: 0;
  font-size: 16px; line-height: 1; padding: 2px 6px; cursor: pointer;
}
.ed-panel-close:hover { color: var(--fg); }
.ed-panel-tabs {
  display: flex; gap: 2px;
  padding: 4px 6px; background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.ed-panel-tabs button {
  background: transparent; color: var(--muted);
  border: 0; padding: 4px 8px;
  cursor: pointer; font-size: 11px;
  border-radius: 3px;
}
.ed-panel-tabs button:hover { color: var(--fg); }
.ed-panel-tabs button.active { background: var(--accent); color: #fff; }
.ed-panel-body {
  padding: 10px 12px;
  overflow-y: auto;
  flex: 1;
}
.ed-panel-body fieldset {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 10px 8px;
  margin: 0 0 10px;
}
.ed-panel-body legend { color: var(--muted); padding: 0 4px; font-size: 11px; }
.ed-panel-body label { margin: 6px 0; display: block; }
.ed-panel-body input, .ed-panel-body select { width: 100%; }
.ed-panel-body input[type=color] { padding: 0; height: 28px; }
.ed-panel-body .grid2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px;
}
.ed-panel-body .grid2 label { margin: 0; }
.ed-panel-empty { color: var(--muted); padding: 12px 4px; }

@media (max-width: 700px) {
  .ed-panel { width: calc(100% - 24px); }
}
