:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --bg2: #11141b;
  --panel: #161a23;
  --panel2: #1d2230;
  --line: #262c3a;
  --text: #e6e9ef;
  --muted: #8b93a7;
  --accent: #5b8cff;
  --accent2: #36d399;
  --danger: #f87272;
  --warn: #fbbd23;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); overflow: hidden; }

button {
  font: inherit; color: var(--text); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px;
  cursor: pointer; transition: background .15s, border-color .15s;
}
button:hover { background: #262c3a; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); border-color: #3a2630; }
button.sm { padding: 5px 9px; font-size: 13px; }

input, select {
  font: inherit; color: var(--text); background: var(--bg2);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }

.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); }

/* ---------- Centered screens (auth / projects) ---------- */
.center { height: 100vh; display: grid; place-items: center; padding: 20px; overflow: auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 26px; width: 100%; max-width: 420px; }
.logo { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; display: block; margin: 0 auto 10px; box-shadow: 0 4px 20px rgba(91,140,255,.25); }
.logo.sm { width: 38px; height: 38px; margin: 0 10px 0 0; display: inline-block; vertical-align: middle; }
.brand { font-size: 1.5rem; font-weight: 700; margin: 0 0 2px; }
.brand span { color: var(--muted); font-weight: 400; }
.tabs { display: flex; gap: 6px; margin: 16px 0; }
.tabs button { flex: 1; }
.tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* ---------- Projects grid ---------- */
.projects-wrap { max-width: 920px; }
.proj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-top: 16px; }
.proj { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; cursor: pointer; }
.proj:hover { border-color: var(--accent); }
.proj h3 { margin: 0 0 6px; font-size: 1rem; }
.proj .meta { font-size: 12px; color: var(--muted); }
.proj-new { display: grid; place-items: center; border: 1px dashed var(--line); color: var(--muted); min-height: 96px; }

/* ---------- Editor layout ---------- */
.editor { display: grid; grid-template-rows: 52px 1fr auto; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 0 14px; background: var(--bg2); border-bottom: 1px solid var(--line); }
.topbar .name { font-weight: 600; }
.saved { font-size: 12px; color: var(--accent2); }

.stage { display: grid; grid-template-columns: 240px 1fr 260px; min-height: 0; }
.panel { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.panel.right { border-right: none; border-left: 1px solid var(--line); }
.panel h4 { margin: 0; padding: 12px 14px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); text-transform: uppercase; letter-spacing: .04em; }
.panel .body { padding: 12px; overflow: auto; }

.media-item { display: flex; gap: 8px; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; cursor: pointer; background: var(--bg2); }
.media-item:hover { border-color: var(--accent); }
.media-thumb { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: #000; flex: none; display: grid; place-items: center; font-size: 18px; color: var(--muted); }
.media-item .info { min-width: 0; }
.media-item .info b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-item .info small { color: var(--muted); font-size: 11px; }

/* Preview */
.preview-wrap { display: flex; flex-direction: column; min-height: 0; background: #06070a; }
.preview { flex: 1; display: grid; place-items: center; position: relative; min-height: 0; overflow: hidden; padding: 14px; }
/* El marco se dimensiona SOLO por el contenedor (aspect-ratio + max-*), nunca por el tamaño
   natural del medio: por eso video/img van en position:absolute y no "inflan" el marco. */
.stageframe { position: relative; background: #000; max-width: 100%; max-height: 100%; box-shadow: 0 8px 30px rgba(0,0,0,.5); overflow: hidden; }
.stageframe video, .stageframe img.frame { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.overlay-layer { position: absolute; inset: 0; pointer-events: none; }
.txt-overlay { position: absolute; transform: translate(-50%, -50%); font-weight: 700; text-align: center; text-shadow: 0 2px 6px rgba(0,0,0,.8); white-space: pre-wrap; line-height: 1.15; }
.txt-overlay.sub { color: #fff; background: rgba(0,0,0,.55); padding: 2px 10px; border-radius: 6px; max-width: 90%; font-weight: 700; text-shadow: none; }
.subs-list { max-height: 260px; overflow: auto; margin-top: 10px; }
.sub-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.sub-row input.t { width: 56px; flex: none; }
.sub-row input.x { flex: 1; }
.transport { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); background: var(--bg2); }
.time { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); }

/* Timeline */
.timeline { background: var(--bg2); border-top: 1px solid var(--line); padding: 10px 14px 14px; }
.tl-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.tracks { position: relative; }
.ruler { height: 18px; position: relative; margin-left: 56px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.ruler .tick { position: absolute; top: 0; font-size: 10px; color: var(--muted); border-left: 1px solid var(--line); padding-left: 3px; height: 18px; }
.track { display: flex; align-items: stretch; gap: 0; margin-bottom: 6px; }
.track .tlabel { width: 56px; flex: none; font-size: 11px; color: var(--muted); display: flex; align-items: center; }
.track .lane { position: relative; flex: 1; height: 46px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.lane { position: relative; height: 46px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 6px; }
.track.audio .lane { height: 34px; }
.track.text .lane { height: 28px; }
.clip { position: absolute; top: 3px; bottom: 3px; background: linear-gradient(180deg, #2b3550, #222a40); border: 1px solid #3a4568; border-radius: 6px; overflow: hidden; cursor: pointer; display: flex; align-items: center; padding: 0 6px; font-size: 11px; white-space: nowrap; user-select: none; }
.clip.audio { background: linear-gradient(180deg, #1f4036, #1a3a30); border-color: #2c5a4a; }
.clip.text { background: linear-gradient(180deg, #4a3a1f, #3a2f1a); border-color: #6a5425; top: 2px; bottom: 2px; }
.clip.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.clip .handle { position: absolute; top: 0; bottom: 0; width: 7px; cursor: ew-resize; background: rgba(91,140,255,.35); }
.clip .handle.l { left: 0; } .clip .handle.r { right: 0; }
.playhead { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--danger); left: 56px; pointer-events: none; z-index: 5; }

/* Properties */
.prop-empty { color: var(--muted); font-size: 13px; }
.field-row { display: flex; gap: 8px; }
.field-row > div { flex: 1; }
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 60; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: 100%; max-width: 420px; }
.modal h3 { margin: 0 0 14px; }
.progbar { height: 12px; background: var(--bg2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; margin: 14px 0 8px; }
.progfill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .3s; }
.dlbtn { display: inline-block; text-decoration: none; text-align: center; width: 100%; background: var(--accent2); color: #04110b; font-weight: 700; padding: 11px; border-radius: 9px; margin-top: 8px; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; z-index: 50; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }
.toast.err { border-color: var(--danger); color: var(--danger); }
