:root {
  --bg: #0e1013;
  --panel: #171a1f;
  --panel-2: #1f232a;
  --line: #2a2f38;
  --text: #e8eaed;
  --muted: #9aa1ad;
  --accent: #ff5a36;
  --accent-2: #ff7a5c;
  --clip: #2f6fed;
  --clip-img: #8a5cf6;
  --txt: #e0a500;
  --aud: #1fa971;
  --danger: #e5484d;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button, .btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
}
button:hover, .btn:hover { border-color: #3b424e; background: #262b33; }
button:disabled { opacity: .45; cursor: default; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover, .btn.primary:hover { background: var(--accent-2); }
button.danger { color: #ff8a8d; }
button.small, .btn.small { padding: 4px 10px; min-height: 30px; font-size: 13px; }
button.icon { padding: 6px 10px; }
button.icon.big { width: 44px; height: 44px; justify-content: center; font-size: 18px; border-radius: 50%; }
input[type=text], input[type=number], input:not([type]), select, textarea {
  background: #0f1216;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
  min-height: 34px;
  width: 100%;
}
textarea { resize: vertical; min-height: 64px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=color] { width: 44px; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 7px; background: #0f1216; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- barra superior ---------- */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 20; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.logo { background: var(--accent); width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; font-size: 12px; }
#projectSelect { width: auto; max-width: 180px; }
.project-name { flex: 1 1 160px; min-width: 120px; max-width: 360px; }
.top-actions { display: flex; gap: 6px; margin-left: auto; }
.save-state { color: var(--muted); font-size: 12px; min-width: 70px; text-align: right; }

/* ---------- distribución ---------- */
.layout {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr) 320px;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "lib preview insp" "tl tl tl";
  gap: 8px; padding: 8px;
  height: calc(100vh - 54px);
}
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); min-height: 0; min-width: 0; }
.library { grid-area: lib; display: flex; flex-direction: column; overflow: hidden; }
.preview { grid-area: preview; display: flex; flex-direction: column; overflow: hidden; }
.inspector { grid-area: insp; display: flex; flex-direction: column; overflow: hidden; }
.timeline-panel { grid-area: tl; }

.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: 14px; margin: 0; }

/* ---------- biblioteca ---------- */
.drop-zone {
  margin: 10px; padding: 14px; border: 1.5px dashed var(--line); border-radius: 9px;
  color: var(--muted); text-align: center; font-size: 13px;
}
.drop-zone.over { border-color: var(--accent); color: var(--text); background: #ff5a3612; }
.media-list { list-style: none; margin: 0; padding: 0 10px 10px; overflow-y: auto; flex: 1; }
.media-item {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 8px; align-items: center;
  padding: 6px; border-radius: 8px; border: 1px solid transparent;
}
.media-item:hover { background: var(--panel-2); border-color: var(--line); }
.media-thumb {
  width: 56px; height: 36px; border-radius: 5px; background: #0b0d10 center/cover no-repeat;
  display: grid; place-items: center; font-size: 18px; color: var(--muted);
}
.media-meta { min-width: 0; }
.media-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.media-sub { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-actions { display: flex; gap: 3px; }
.media-actions button { min-height: 30px; min-width: 30px; padding: 2px 6px; justify-content: center; }
.upload-row { margin: 0 10px 8px; font-size: 12px; color: var(--muted); }
.bar { height: 4px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 3px; }
.bar > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* ---------- vista previa ---------- */
.stage-wrap { flex: 1; display: grid; place-items: center; padding: 10px; min-height: 0; background: #0a0b0d; border-radius: var(--radius) var(--radius) 0 0; overflow: hidden; }
.stage {
  position: relative; background: #000; overflow: hidden;
  aspect-ratio: 16 / 9; max-width: 100%; max-height: 100%; height: 100%;
  container-type: size;
}
.stage video, .stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: none; }
.stage .on { display: block; }
.pv-texts { position: absolute; inset: 0; pointer-events: none; }
.pv-text {
  position: absolute; transform: translate(-50%, -50%); text-align: center; font-weight: 700;
  white-space: pre-wrap; max-width: 90%; width: max-content; line-height: 1.3;
  font-family: "DejaVu Sans", Verdana, system-ui, sans-serif;
  pointer-events: auto; cursor: move;
}
.pv-text span { -webkit-box-decoration-break: clone; box-decoration-break: clone; padding: 0 .22em; }
.pv-text.sel { outline: 1px dashed #fff8; outline-offset: 4px; }
.pv-empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 20px; font-size: 14px; }
.transport { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--line); }
.time { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--muted); white-space: nowrap; }
#seek { flex: 1; }

/* ---------- inspector ---------- */
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab { flex: 1; border: 0; border-radius: 0; background: transparent; border-bottom: 2px solid transparent; justify-content: center; }
.tab.active { border-bottom-color: var(--accent); color: #fff; }
.tab-body { padding: 12px; overflow-y: auto; flex: 1; }
.badge { background: var(--accent); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; }
.insp-title { font-size: 13px; font-weight: 700; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.insp-title .chip { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 9px; background: var(--panel-2); color: var(--muted); }
.group { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 12px; }
.group h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
label > input, label > select, label > textarea { margin-top: 3px; color: var(--text); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.field-row.three { grid-template-columns: 1fr 1fr 1fr; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.range-label { display: flex; justify-content: space-between; }
.range-label b { color: var(--text); font-weight: 500; font-variant-numeric: tabular-nums; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.inline { display: flex; gap: 6px; align-items: end; }
.inline > :first-child { flex: 1; }
.inline button { min-height: 34px; margin-bottom: 8px; }

.export-box { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.render-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; }
.render-item { background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; }
.render-item .row { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.render-item .name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.render-item .st { font-size: 11px; color: var(--muted); }
.render-item .st.error { color: #ff8a8d; white-space: pre-wrap; }
.render-item .st.done { color: #5fd49b; }
.render-item video { width: 100%; margin-top: 8px; border-radius: 6px; max-height: 220px; background: #000; }
.render-item .btn-row a { text-decoration: none; }

/* ---------- línea de tiempo ---------- */
.timeline-tools { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.spacer { flex: 1; }
.zoom { display: flex; align-items: center; gap: 6px; margin: 0; }
.zoom input { width: 120px; }
.timeline { overflow-x: auto; overflow-y: hidden; position: relative; padding-bottom: 6px; }
.tl-inner { position: relative; min-width: 100%; padding-left: 64px; }
.ruler { height: 22px; position: relative; border-bottom: 1px solid var(--line); cursor: pointer; }
.ruler .tick { position: absolute; top: 0; height: 100%; border-left: 1px solid var(--line); font-size: 10px; color: var(--muted); padding-left: 3px; line-height: 22px; }
.track { position: relative; height: 46px; border-bottom: 1px solid #22262d; }
.track-label {
  position: sticky; left: 0; margin-left: -64px; width: 64px; height: 100%; float: left;
  display: grid; place-items: center; font-size: 11px; color: var(--muted); background: var(--panel); z-index: 3;
  border-right: 1px solid var(--line);
}
.track-body { position: relative; height: 100%; }
.block {
  position: absolute; top: 5px; bottom: 5px; border-radius: 6px; overflow: hidden;
  font-size: 11px; padding: 3px 6px; cursor: pointer; white-space: nowrap; text-overflow: ellipsis;
  border: 1px solid #0006; color: #fff; user-select: none; touch-action: pan-x;
  background-size: auto 100%; background-repeat: repeat-x;
}
.block.clip { background-color: var(--clip); }
.block.clip.img { background-color: var(--clip-img); }
.block.text { background: var(--txt); color: #1d1600; font-weight: 600; }
.block.audio { background: var(--aud); }
.block .lbl { position: relative; z-index: 1; text-shadow: 0 1px 2px #0009; }
.block.text .lbl { text-shadow: none; }
.block.sel { outline: 2px solid #fff; outline-offset: -1px; z-index: 2; }
.block.dragging { opacity: .6; }
.block.drop-before { box-shadow: -4px 0 0 var(--accent); }
.block .handle { position: absolute; top: 0; bottom: 0; width: 10px; cursor: ew-resize; z-index: 2; }
.block .handle.l { left: 0; }
.block .handle.r { right: 0; }
.block.sel .handle { background: #ffffff40; }
.playhead { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); pointer-events: none; z-index: 5; left: 64px; }
.playhead::before { content: ""; position: absolute; top: 0; left: -5px; border: 6px solid transparent; border-top-color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50;
  background: #262b33; border: 1px solid var(--line); padding: 10px 16px; border-radius: 9px;
  box-shadow: 0 8px 30px #0008; max-width: calc(100vw - 32px);
}
.toast.error { border-color: var(--danger); }

/* ---------- móvil / tablet ---------- */
@media (max-width: 980px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    grid-template-areas: "preview" "tl" "insp" "lib";
    height: auto;
  }
  .stage-wrap { height: 46vh; min-height: 220px; }
  .inspector, .library { max-height: none; }
  .tab-body, .media-list { overflow: visible; }
  .brand-name { display: none; }
  .project-name { order: 5; flex-basis: 100%; max-width: none; }
  .save-state { order: 6; text-align: left; }
  .preview { position: sticky; top: 54px; z-index: 10; }
}
@media (max-width: 480px) {
  .topbar { padding: 6px 10px; }
  #newProjectBtn { padding: 6px 8px; }
  .layout { padding: 6px; gap: 6px; }
  .stage-wrap { height: 38vh; }
  .preview { position: static; }
  .zoom input { width: 90px; }
}
a.btn { text-decoration: none; color: inherit; }
