:root {
  --bg: #0e1015;
  --panel: #161921;
  --panel-2: #1d212b;
  --line: #2a2f3b;
  --text: #eef0f5;
  --muted: #9aa1b2;
  --accent: #ff5f6d;
  --accent-2: #8f5bff;
  --grad: linear-gradient(135deg, #ff5f6d, #8f5bff);
  --ok: #3ddc97;
  --warn: #ffc857;
  --danger: #ff4d5e;
  --clip: #3b5bdb;
  --sub: #e8590c;
  --audio: #2b9a66;
  --radius: 12px;
  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 'Poppins', system-ui, -apple-system, 'Segoe UI', sans-serif;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }
h3 .count { color: var(--text); background: var(--panel-2); border-radius: 99px; padding: 0 8px; margin-left: 4px; letter-spacing: 0; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0; }
b { color: var(--text); }

button, .btn {
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
button:hover, .btn:hover { border-color: #444b5c; background: #252a36; }
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
.primary { background: var(--grad); border-color: transparent; color: #fff; }
.primary:hover { background: var(--grad); filter: brightness(1.08); border-color: transparent; }
.ghost { background: transparent; }
.danger { color: #ffb3ba; border-color: #5a2a31; background: #2a1619; }
.sm { padding: 7px 11px; font-size: 13px; }
.icon-btn { padding: 7px 10px; min-width: 38px; justify-content: center; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: #0f1218;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  width: 100%;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #8f5bff88; border-color: transparent; }
textarea { resize: vertical; line-height: 1.45; }
input[type=range] { padding: 0; accent-color: var(--accent); background: none; border: 0; height: 22px; }
input[type=color] { padding: 2px; height: 36px; width: 56px; cursor: pointer; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }

/* ---------- Barra superior ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { font-size: 17px; display: block; line-height: 1.1; }
.brand small { color: var(--muted); font-size: 11.5px; }
.logo { width: 34px; height: 34px; border-radius: 10px; background: var(--grad); position: relative; flex: none; }
.logo::after { content: ''; position: absolute; left: 13px; top: 10px; border-left: 11px solid #fff; border-top: 7px solid transparent; border-bottom: 7px solid transparent; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.format-pick { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; }
.format-pick select { width: auto; }

/* ---------- Área de trabajo ---------- */
.workspace {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr) 310px;
  min-height: 0;
}
.panel { background: var(--panel); min-height: 0; overflow-y: auto; }
.panel.left { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.panel.right { border-left: 1px solid var(--line); }
.panel-title { padding: 14px 16px 4px; font-weight: 700; font-size: 15px; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 10px; position: sticky; top: 0; background: var(--panel); z-index: 2; border-bottom: 1px solid var(--line); }
.tabs button { padding: 8px 4px; font-size: 12px; border-radius: 8px; justify-content: center; background: transparent; border-color: transparent; color: var(--muted); flex-direction: column; gap: 0; }
.tabs button.active { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.tab-body { padding: 12px 16px 24px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px;
  border: 2px dashed #3a4050; border-radius: var(--radius); padding: 22px 14px; cursor: pointer;
  background: #12151c; transition: border-color .15s, background .15s;
}
.dropzone:hover { border-color: var(--accent); background: #171a22; }
.dropzone small { color: var(--muted); font-size: 12px; }
.dz-icon { width: 42px; height: 42px; border-radius: 50%; background: var(--grad); display: grid; place-items: center; font-size: 24px; margin-bottom: 4px; }

.media-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px; }
.media-card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; }
.media-card .thumb { aspect-ratio: 16/10; background: #0b0d11 center/cover no-repeat; position: relative; display: grid; place-items: center; font-size: 26px; }
.media-card .badge { position: absolute; left: 6px; bottom: 6px; font-size: 11px; background: #000a; padding: 1px 6px; border-radius: 6px; }
.media-card .name { font-size: 12px; padding: 6px 8px 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-card .acts { display: flex; gap: 4px; padding: 4px 6px 6px; }
.media-card .acts button { padding: 4px 8px; font-size: 12px; flex: 1; justify-content: center; }
.media-card .acts button.del { flex: 0; }
.wave { width: 100%; height: 100%; }

.fields { display: grid; gap: 10px; }
.field { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.field > .ctl { display: flex; align-items: center; gap: 8px; color: var(--text); }
.field .val { min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; color: var(--text); }
.field.inline { display: flex; align-items: center; gap: 8px; }
.field.inline select { width: auto; }
.field.check { display: flex; align-items: center; gap: 8px; color: var(--text); cursor: pointer; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btns { display: flex; flex-wrap: wrap; gap: 6px; }
.btns button { font-size: 12px; padding: 6px 9px; }
.seg { display: flex; background: #0f1218; border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 3px; }
.seg button { flex: 1; justify-content: center; padding: 6px 4px; font-size: 12px; border: 0; background: transparent; color: var(--muted); }
.seg button.on { background: var(--panel-2); color: var(--text); box-shadow: 0 0 0 1px var(--line); }

.tts-box { margin-top: 16px; padding: 4px 12px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: #12151c; display: grid; gap: 8px; }
.tts-box h3 { margin-top: 12px; }
.tts-box .row, .tts-box .hint { margin: 0; }
.presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; }
.preset { height: 52px; border-radius: 9px; justify-content: center; padding: 4px; font-size: 13px; background: #2a3140 linear-gradient(160deg, #3b4252, #1f242e); }

.item-list { display: grid; gap: 6px; }
.item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 7px 8px; cursor: pointer;
}
.item.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.item .tm { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.item input { padding: 5px 8px; font-size: 13px; }
.item .x { padding: 3px 8px; font-size: 12px; background: transparent; border-color: transparent; color: var(--muted); }
.item .x:hover { color: var(--danger); }
.item .vol { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.empty { color: var(--muted); font-size: 12.5px; padding: 10px; border: 1px dashed var(--line); border-radius: 10px; text-align: center; }

/* ---------- Escenario ---------- */
.stage { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: radial-gradient(ellipse at center, #1a1d26, #0b0c10 70%); }
.canvas-wrap { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; padding: 14px; }
#preview { max-width: 100%; max-height: 100%; border-radius: 10px; box-shadow: 0 10px 40px #0009, 0 0 0 1px #ffffff14; background: #000; }
.empty-msg { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 4px; pointer-events: none; padding: 30px; }
.empty-msg span { color: var(--muted); font-size: 13px; max-width: 260px; }
.empty-msg .primary { pointer-events: auto; margin-top: 12px; padding: 12px 18px; font-size: 15px; }
.stage.is-empty .transport { visibility: hidden; }
.transport { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 12px 10px; flex-wrap: wrap; }
.play { width: 48px; height: 48px; border-radius: 50%; justify-content: center; font-size: 18px; background: var(--grad); border: 0; padding: 0; }
.play:hover { background: var(--grad); filter: brightness(1.1); }
.time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; min-width: 120px; text-align: center; }

.sync-bar, .rec-bar {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: #0d0f14ee; border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px;
  display: flex; align-items: center; gap: 10px; box-shadow: 0 10px 30px #000a; width: min(560px, calc(100% - 28px));
}
.sync-text { flex: 1; min-width: 0; }
.sync-text small { color: var(--muted); display: block; font-size: 11px; }
.sync-text strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#btnSyncNext { padding: 12px 18px; font-size: 15px; }
.rec-bar { justify-content: center; width: auto; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* ---------- Inspector ---------- */
.inspector { padding: 6px 16px 24px; }
.inspector .sect { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 14px; }
.inspector .sect:first-child { border-top: 0; margin-top: 0; }
.inspector .kind { display: inline-block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; padding: 2px 8px; border-radius: 99px; background: var(--panel-2); color: var(--muted); }
.inspector .title { font-weight: 700; margin: 6px 0 2px; word-break: break-word; }
.inspector .sub-t { color: var(--muted); font-size: 12px; }
.inspector .placeholder { color: var(--muted); text-align: center; padding: 30px 10px; font-size: 13px; }

/* ---------- Línea de tiempo ---------- */
.timeline { background: var(--panel); border-top: 1px solid var(--line); user-select: none; -webkit-user-select: none; }
.tl-toolbar { display: flex; align-items: center; gap: 12px; padding: 6px 12px; border-bottom: 1px solid var(--line); }
.tl-title { font-weight: 700; font-size: 13px; }
.tl-toolbar .hint { flex: 1; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.zoom { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.zoom input { width: 120px; }
.tl-body { display: grid; grid-template-columns: 74px minmax(0, 1fr); max-height: 34vh; overflow-y: auto; }
.tl-labels { border-right: 1px solid var(--line); }
.tl-labels div { height: 46px; display: flex; align-items: center; padding: 0 8px; font-size: 11.5px; color: var(--muted); border-bottom: 1px solid #ffffff08; gap: 4px; }
.tl-labels .lr { height: 24px; }
.tl-scroll { overflow-x: auto; overflow-y: hidden; position: relative; touch-action: pan-x; }
.tl-inner { position: relative; min-width: 100%; }
.tl-ruler { height: 24px; position: relative; border-bottom: 1px solid var(--line); cursor: pointer; background: #12151b; }
.tick { position: absolute; top: 0; bottom: 0; border-left: 1px solid #3a4050; font-size: 10px; color: var(--muted); padding-left: 3px; }
.tick.minor { top: 16px; border-color: #2a2f3b; }
.tl-row { height: 46px; position: relative; border-bottom: 1px solid #ffffff08; }
.blk {
  position: absolute; top: 5px; bottom: 5px; border-radius: 7px; overflow: hidden; cursor: grab;
  font-size: 11px; color: #fff; padding: 2px 6px; white-space: nowrap; text-overflow: ellipsis; touch-action: none;
  box-shadow: inset 0 0 0 1px #ffffff26;
}
.blk.sel { box-shadow: inset 0 0 0 2px #fff, 0 0 0 1px #000; z-index: 3; }
.blk .lbl { position: relative; z-index: 1; text-shadow: 0 1px 2px #000; font-weight: 600; pointer-events: none; display: block; overflow: hidden; text-overflow: ellipsis; }
.blk.clip { background: var(--clip) left/auto 100% repeat-x; padding-top: 22px; }
.blk.clip .lbl { position: absolute; top: 2px; left: 6px; right: 6px; }
.blk.sub { background: var(--sub); line-height: 32px; }
.blk.audio { background: var(--audio); }
.blk.audio canvas { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .55; pointer-events: none; }
.blk.dragging { opacity: .75; z-index: 5; cursor: grabbing; }
.handle { position: absolute; top: 0; bottom: 0; width: 10px; cursor: ew-resize; z-index: 2; }
.handle.l { left: 0; } .handle.r { right: 0; }
.handle::after { content: ''; position: absolute; top: 30%; bottom: 30%; left: 4px; width: 2px; border-radius: 2px; background: #fffa; }
.trans {
  position: absolute; top: 12px; width: 22px; height: 22px; margin-left: -11px; border-radius: 50%; z-index: 4;
  background: #fff; color: #222; font-size: 11px; display: grid; place-items: center; cursor: pointer; box-shadow: 0 2px 6px #0008; padding: 0; border: 0;
}
.trans.none { background: #4a5163; color: #fff; }
.playhead { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); z-index: 6; pointer-events: none; }
.playhead::before { content: ''; position: absolute; top: 0; left: -6px; border-left: 7px solid transparent; border-right: 7px solid transparent; border-top: 9px solid var(--accent); }
.drop-marker { position: absolute; top: 2px; bottom: 2px; width: 3px; background: #fff; border-radius: 2px; z-index: 7; pointer-events: none; }
.tl-empty { position: absolute; left: 12px; top: 10px; color: var(--muted); font-size: 12px; pointer-events: none; }

/* ---------- Diálogo y avisos ---------- */
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--text); padding: 0; width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
dialog::backdrop { background: #000b; backdrop-filter: blur(3px); }
.dlg { padding: 18px 20px; display: grid; gap: 12px; }
.dlg h2 { margin: 0; font-size: 18px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.progress { height: 10px; border-radius: 99px; background: #0f1218; overflow: hidden; border: 1px solid var(--line); }
.progress div { height: 100%; width: 0; background: var(--grad); transition: width .2s; }
#expVideo { width: 100%; max-height: 50dvh; border-radius: 10px; background: #000; }

.toasts { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; pointer-events: none; width: min(420px, calc(100vw - 24px)); }
.toast { background: #23283399; backdrop-filter: blur(8px); border: 1px solid var(--line); padding: 10px 14px; border-radius: 12px; box-shadow: 0 10px 30px #0008; animation: tin .2s ease-out; font-size: 13px; }
.toast.err { border-color: #7a2b35; background: #3a1820ee; }
.toast.ok { border-color: #1f6b4b; }
@keyframes tin { from { opacity: 0; transform: translateY(-6px); } }
.drop-overlay { position: fixed; inset: 0; background: #0e1015cc; border: 3px dashed var(--accent); z-index: 40; display: grid; place-items: center; font-size: 20px; font-weight: 700; pointer-events: none; }

/* ---------- Celular y tablet ---------- */
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 300px minmax(0, 1fr); }
  .panel.right { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); max-height: 40vh; }
}
@media (max-width: 760px) {
  /* En el celular: video, línea de tiempo, propiedades y después las pestañas */
  body { display: flex; flex-direction: column; height: auto; min-height: 100dvh; overflow: visible; }
  .workspace { display: contents; }
  .topbar { order: 0; position: sticky; top: 0; z-index: 10; padding: 8px 12px; }
  .brand small, .format-pick span, .hide-sm { display: none; }
  .format-pick select { max-width: 132px; padding: 8px 6px; }
  body, .stage, .timeline, .panel { max-width: 100vw; }
  .brand strong { font-size: 15px; }
  .top-actions { gap: 6px; }
  #btnExport { padding: 9px 12px; }
  .stage { order: 1; flex: none; }
  /* Safari no respeta el alto con flex: 1 dentro de una columna de alto automático */
  .canvas-wrap { flex: none; height: 52vh; height: 52svh; min-height: 300px; padding: 10px; }
  .timeline { order: 2; }
  .panel.right { order: 3; max-height: none; border: 0; border-top: 1px solid var(--line); }
  .panel.right:has(.placeholder) { display: none; }
  .transport { gap: 6px; }
  .time { min-width: 0; font-size: 12px; }
  .panel.left { order: 4; border: 0; border-top: 1px solid var(--line); }
  .panel { overflow: visible; }
  .tabs { top: 54px; }
  .tl-toolbar .hint { display: none; }
  .tl-body { max-height: none; }
  .media-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 420px) {
  .brand > div { display: none; }
  .media-grid { grid-template-columns: repeat(2, 1fr); }
}
