:root {
  --bg: #0e1013;
  --bg-raised: #14181e;
  --bg-sunken: #0a0c0f;
  --panel: #171b22;
  --line: #262c35;
  --line-soft: #1e232b;
  --text: #e8edf3;
  --text-dim: #9aa5b3;
  --text-faint: #6b7684;
  --accent: #4f9eff;
  --accent-dim: #2d5c99;
  --warn: #ffd24f;
  --topbar-h: 48px;
  --transport-h: auto;
  --sidebar-w: 310px;
  --radius: 7px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr auto;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 12px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: baseline; gap: 6px; }
.brand-mark {
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-size: 15px;
}
.brand-sub { color: var(--text-faint); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; }

.file-info { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.file-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-meta { color: var(--text-faint); font-size: 11px; font-family: var(--mono); white-space: nowrap; }

.topbar-actions { display: flex; gap: 6px; }

/* ------------------------------------------------------------------ layout */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 0;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.panel {
  background: var(--bg-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 10px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.panel-head h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.pill {
  background: var(--line);
  color: var(--text-dim);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 11px;
  font-family: var(--mono);
}

/* ------------------------------------------------------------- entity list */

.row-actions { display: flex; gap: 10px; margin: 8px 0 6px; }

.link-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 11px;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.link-btn:hover { color: var(--accent); }

.entity-list { display: flex; flex-direction: column; gap: 1px; }

.entity-group-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 8px 0 3px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.entity-group-head:first-child { margin-top: 0; }
.entity-group-head .swatch { width: 8px; height: 8px; border-radius: 2px; }
.entity-group-head .link-btn { margin-left: auto; }

.entity-row {
  display: grid;
  grid-template-columns: 16px 10px 1fr auto;
  align-items: center;
  gap: 7px;
  padding: 4px 6px;
  border-radius: 5px;
  cursor: pointer;
  border: 1px solid transparent;
}
.entity-row:hover { background: var(--line-soft); }
.entity-row.selected { background: #1d2733; border-color: var(--accent-dim); }
.entity-row.hidden-entity .entity-name { color: var(--text-faint); text-decoration: line-through; }
.entity-row.absent .entity-name { opacity: 0.5; }
.entity-row.absent .entity-swatch { opacity: 0.35; }
.entity-row.absent .live-dot { display: none; }

.entity-row input[type="checkbox"] { margin: 0; accent-color: var(--accent); }

.entity-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.14);
}

.entity-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.entity-name .num {
  font-family: var(--mono);
  color: var(--text-faint);
  margin-right: 4px;
}
.entity-name .live-dot {
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #4fd98a;
  margin-left: 5px;
  vertical-align: middle;
}

.entity-solo {
  background: none;
  border: 1px solid var(--line);
  color: var(--text-faint);
  border-radius: 4px;
  font-size: 9px;
  letter-spacing: 0.06em;
  padding: 1px 5px;
  cursor: pointer;
  opacity: 0;
}
.entity-row:hover .entity-solo, .entity-row.selected .entity-solo { opacity: 1; }
.entity-solo:hover { color: var(--accent); border-color: var(--accent-dim); }

/* ----------------------------------------------------------------- fields */

.input {
  width: 100%;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  padding: 5px 7px;
  font: inherit;
}
.input:focus { outline: none; border-color: var(--accent-dim); }
.input-sm { padding: 3px 5px; width: auto; }

.check, .field {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 0;
  color: var(--text-dim);
  cursor: pointer;
}
.check input { accent-color: var(--accent); margin: 0; }
.field { flex-direction: column; align-items: stretch; gap: 3px; margin-top: 7px; }
.field > span { font-size: 11px; color: var(--text-faint); display: flex; justify-content: space-between; }
.field em { font-style: normal; font-family: var(--mono); color: var(--text-dim); }
.field.inline, .check.inline { flex-direction: row; align-items: center; margin-top: 0; white-space: nowrap; }
.field input[type="range"] { width: 100%; accent-color: var(--accent); }

.info-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  margin: 0;
  font-size: 11px;
}
.info-grid dt { color: var(--text-faint); }
.info-grid dd { margin: 0; font-family: var(--mono); text-align: right; color: var(--text-dim); }

/* ------------------------------------------------------------------ stage */

.stage { position: relative; min-width: 0; background: var(--bg); }

#view { display: block; width: 100%; height: 100%; }

.hud {
  position: absolute;
  top: 10px;
  left: 10px;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.hud-entity {
  background: rgba(12,15,20,0.82);
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 12px;
  min-width: 190px;
}
.hud-entity .hud-title { font-weight: 600; margin-bottom: 3px; }
.hud-entity .hud-line { color: var(--text-dim); font-family: var(--mono); font-size: 11px; }

.view-tools {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 5px;
}
.view-tools[hidden] { display: none; }

/* -------------------------------------------------------------- drop zone */

.drop-zone {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 50% 40%, #171d26 0%, var(--bg) 70%);
  text-align: center;
  padding: 24px;
}
.drop-zone[hidden] { display: none; }
.drop-zone.dragging { background: radial-gradient(ellipse at 50% 40%, #1d2a3a 0%, var(--bg) 70%); }
.drop-zone.dragging .drop-inner { border-color: var(--accent); }

.drop-inner {
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  padding: 36px 44px;
  max-width: 540px;
}
.drop-inner h1 { margin: 0 0 8px; font-size: 20px; font-weight: 600; }
.drop-inner h1 code { font-family: var(--mono); color: var(--accent); font-size: 18px; }
.drop-inner p { margin: 0 0 16px; color: var(--text-dim); }
.drop-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.drop-note { margin: 18px 0 0 !important; font-size: 11px; color: var(--text-faint); }

/* --------------------------------------------------------------- progress */

.progress {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10,12,15,0.8);
  backdrop-filter: blur(2px);
}
.progress[hidden] { display: none; }
.progress-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 22px;
  min-width: 320px;
}
.progress-label { font-weight: 500; margin-bottom: 10px; }
.progress-track { height: 5px; background: var(--bg-sunken); border-radius: 3px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.1s linear; }
.progress-detail { margin-top: 8px; font-family: var(--mono); font-size: 11px; color: var(--text-faint); }

/* -------------------------------------------------------------- transport */

.transport {
  background: var(--bg-raised);
  border-top: 1px solid var(--line);
  padding: 7px 10px 9px;
}

.transport-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 7px;
}

.timecode {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-family: var(--mono);
  font-size: 12px;
  margin-left: 6px;
}
.tc-sep { color: var(--text-faint); }
#tcTotal { color: var(--text-dim); }
.tc-frame { color: var(--text-faint); font-size: 11px; margin-left: 6px; }

.region-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}
.region-label { font-family: var(--mono); font-size: 11px; color: var(--warn); min-width: 0; }

.timeline {
  display: block;
  width: 100%;
  height: 120px;
  border-radius: 5px;
  border: 1px solid var(--line);
  cursor: pointer;
  touch-action: none;
}

/* --------------------------------------------------------------- buttons */

.btn {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 5px;
  padding: 5px 11px;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent-dim); background: #1b2029; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #07101c; font-weight: 600; }
.btn-primary:hover { background: #65adff; border-color: #65adff; }
.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-sm { padding: 3px 8px; font-size: 12px; }
.btn.active { border-color: var(--accent); color: var(--accent); }

.icon-btn {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 5px;
  width: 32px;
  height: 28px;
  font-size: 12px;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon-btn:hover { border-color: var(--accent-dim); }
.icon-btn-primary { background: var(--accent); border-color: var(--accent); color: #07101c; width: 42px; font-size: 14px; }
.icon-btn-primary:hover { background: #65adff; }

button:disabled { opacity: 0.4; cursor: default; }

/* --------------------------------------------------------------- dialogs */

.dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0;
  max-width: 520px;
  width: calc(100% - 32px);
}
.dialog::backdrop { background: rgba(5,7,10,0.65); }
.dialog form { padding: 18px 20px 16px; }
.dialog h2 { margin: 0 0 10px; font-size: 15px; }
.dialog-note { color: var(--text-dim); font-size: 12px; margin: 0 0 14px; }
.dialog-note code { font-family: var(--mono); color: var(--accent); }
.dialog-actions { display: flex; gap: 8px; margin-top: 18px; align-items: center; }
.spacer { flex: 1; }

.shortcut-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 16px;
  margin: 0;
  font-size: 12px;
}
.shortcut-grid dt { font-family: var(--mono); color: var(--accent); white-space: nowrap; }
.shortcut-grid dd { margin: 0; color: var(--text-dim); }

/* ----------------------------------------------------------------- toast */

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: #2a1d1d;
  border: 1px solid #5c3030;
  color: #ffd7d7;
  padding: 9px 16px;
  border-radius: 7px;
  font-size: 12px;
  max-width: 70vw;
  z-index: 50;
}
.toast[hidden] { display: none; }
.toast.info { background: #1b2430; border-color: #2d5c99; color: #d7e7ff; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  body.sidebar-open .layout { grid-template-columns: 1fr; }
  body.sidebar-open .sidebar {
    display: flex;
    position: absolute;
    top: var(--topbar-h);
    bottom: 0;
    left: 0;
    width: var(--sidebar-w);
    z-index: 20;
  }
}
