/* ============================================================
   Feed — chrome del editor + slides
   Paleta del editor: neutros tintados (no negro puro), acento esmeralda
   ============================================================ */
:root {
    --app-bg: #0e1116;
    --panel: #161a22;
    --panel-2: #1c2230;
    --line: #262d3a;
    --line-soft: #202634;
    --text: #e7ebf2;
    --text-dim: #9aa4b5;
    --text-mute: #838da0;   /* 5.2:1 sobre --panel; el anterior (#6b7486) daba 3.7:1 */
    --accent: #34d399;
    --accent-ink: #06231a;
    --danger: #f87171;
    --radius: 12px;

    /* Movimiento: una sola voz para todo el editor. Nunca ease-in: retrasa el
       arranque justo cuando el ojo está mirando y hace lento lo que es rápido. */
    --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
    --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
    --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);

    /* Chasis. El JS (16-responsive.js) recalcula --sheet-peek con el alto real
       de la cabecera de la hoja, que depende de cuántas pestañas tenga la pieza. */
    --topbar-h: 56px;
    --sheet-peek: 132px;
    --safe-b: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    background: var(--app-bg);
    color: var(--text);
    font-family: 'Sora', system-ui, sans-serif;
    min-height: 100vh;
    /* Las barras de scroll heredan de aquí. Con solo las reglas -webkit- Chrome
       seguía pintando el carril blanco del carrusel cruzando el editor oscuro;
       `scrollbar-color` es la propiedad estándar y sí manda. */
    scrollbar-width: thin;
    scrollbar-color: #39435a transparent;
}

/* ---------- BARRA SUPERIOR ---------- */
/* Móvil primero: UNA fila y una jerarquía. Marca, deshacer/rehacer, la accion
   primaria de la pieza y un menú "···" con el resto. Antes envolvía en cuatro
   filas (~190px) y todas las acciones pesaban lo mismo. */
.topbar {
    position: sticky;
    top: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 5px;
    height: var(--topbar-h);
    padding: 0 12px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    background: rgba(14, 17, 22, 0.88);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
}
.brand {
    /* Es un <h1>: la portada es el editor, y el nombre de la app tiene que ser
       el encabezado de la página, no un div suelto. El margen del h1 se quita
       aquí porque la barra es flex y lo desplazaría. */
    margin: 0;
    display: flex; align-items: center; gap: 5px;
    flex: 0 1 auto; min-width: 0; overflow: hidden;
    font-size: 0.95rem; font-weight: 700; letter-spacing: -0.02em;
    white-space: nowrap; margin-right: auto;
}
.brand .brand-accent { color: var(--accent); }
/* `flex-shrink` por defecto encogía esta caja y sus botones (que son nowrap)
   se salían 8px del padding: el "···" quedaba a 4px del filo de la pantalla.
   La presión tiene que caer en la marca, que sí se puede recortar. */
.topbar-actions { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.topbar-actions .sep { display: none; }
/* Acciones de la pieza activa: mismo hueco, contenido variable */
.topbar-piece-actions { display: flex; align-items: center; gap: 6px; }
.topbar-piece-actions[hidden] { display: none; }
/* Sin acciones (pestaña Marca) tampoco sobra el separador */
.topbar-piece-actions[hidden] + .sep { display: none; }
/* En pantalla estrecha la barra solo enseña la acción primaria de la pieza;
   las secundarias las repite el menú "···", que se pinta de la MISMA lista
   (pieceActions), así que no hay dos sitios donde mantenerlas. */
.topbar-piece-actions .btn:not(.primary) { display: none; }
/* La acción primaria se recorta antes que empujar a la marca fuera de la barra. */
.topbar .btn { max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- BOTONES DE ACCIÓN: ICONO EN MÓVIL ---------- */
/* Las filas de acciones van con el icono solo. La etiqueta no se pierde: sale al
   mantener pulsado (16-responsive.js la guarda en data-tip). Truncar el texto
   —"Descarg…"— no dice nada; un icono con su etiqueta a demanda, sí. */
#pieceActions .btn-txt,
#canvasActions .btn-txt,
.stage-actions .btn-txt,
.tl-transport .btn-txt { display: none; }
#pieceActions .btn,
#canvasActions .btn,
.stage-actions .btn,
.tl-transport .btn {
    min-width: 44px;
    justify-content: center;
    padding-inline: 12px;
    /* Mantener pulsado no debe seleccionar el icono ni abrir el menú de iOS. */
    -webkit-touch-callout: none;
    user-select: none;
}
.btn-ico { font-size: 1.05rem; line-height: 1; }

/* Etiqueta al mantener pulsado. Clara sobre oscuro: se lee como lo que es, un
   apunte del sistema, no un elemento más de la interfaz. */
.press-tip {
    position: fixed; top: 0; left: 0; z-index: 90;
    max-width: 74vw; padding: 7px 11px;
    background: var(--text); color: var(--app-bg);
    border-radius: 9px;
    font-family: inherit; font-size: 0.8rem; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    pointer-events: none;
    box-shadow: 0 14px 28px -14px rgba(0, 0, 0, 0.9);
    /* Nada aparece de la nada: entra desde 0.96, no desde cero. */
    transform: translate(var(--tx, 0), var(--ty, 0)) scale(0.96);
    opacity: 0;
    transition: opacity 140ms var(--ease-out), transform 140ms var(--ease-out);
}
.press-tip.on { opacity: 1; transform: translate(var(--tx, 0), var(--ty, 0)) scale(1); }
/* Mientras se mide para colocarla no debe verse pasar por la esquina. */
.press-tip.measuring { transition: none; }

/* ---------- FILAS QUE RUEDAN DE LADO ---------- */
/* Piezas, pestañas, acciones de la slide y miniaturas. Sin barra de scroll (en
   táctil es una barra fantasma que además roba alto) y con un desvanecido en el
   extremo que tiene más contenido: es la señal de "sigue" que sustituye a la
   barra. Las clases las pone updateHScrollHints() en 16-responsive.js. */
.hrow {
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}
.hrow::-webkit-scrollbar { height: 0; }
.hrow.more-r:not(.more-l) {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 34px), transparent);
            mask-image: linear-gradient(to right, #000 calc(100% - 34px), transparent);
}
.hrow.more-l:not(.more-r) {
    -webkit-mask-image: linear-gradient(to right, transparent, #000 34px);
            mask-image: linear-gradient(to right, transparent, #000 34px);
}
.hrow.more-l.more-r {
    -webkit-mask-image: linear-gradient(to right, transparent, #000 34px, #000 calc(100% - 34px), transparent);
            mask-image: linear-gradient(to right, transparent, #000 34px, #000 calc(100% - 34px), transparent);
}

/* Menú de desbordamiento (móvil) */
.more-wrap { position: relative; display: flex; }
.more-menu {
    position: absolute; top: calc(100% + 8px); right: 0; z-index: 70;
    min-width: 208px; padding: 6px;
    background: var(--panel); border: 1px solid var(--line);
    border-radius: 14px; box-shadow: 0 24px 48px -24px rgba(0,0,0,0.85);
    display: flex; flex-direction: column; gap: 2px;
    /* Nada aparece de la nada: entra desde 0.96 y desde su origen, la esquina
       del botón que lo abre. */
    transform-origin: top right;
    animation: menuIn 160ms var(--ease-out);
}
.more-menu[hidden] { display: none; }
@keyframes menuIn { from { opacity: 0; transform: scale(0.96) translateY(-4px); } to { opacity: 1; transform: none; } }
.more-menu button {
    display: flex; align-items: center; gap: 10px;
    width: 100%; min-height: 44px; padding: 10px 12px;
    background: transparent; border: none; border-radius: 9px;
    color: var(--text); font-family: inherit; font-size: 0.9rem; font-weight: 500;
    text-align: left; cursor: pointer;
    transition: background 140ms var(--ease-out);
}
.more-menu button:hover, .more-menu button:focus-visible { background: var(--panel-2); }
.more-menu button.is-danger { color: var(--danger); }
.more-menu .menu-sep { height: 1px; margin: 5px 8px; background: var(--line-soft); }
/* Los botones que se mudan aquí desde la barra (Guardar / Abrir / Reset) se
   visten de opción de menú sin dejar de ser los mismos nodos. */
.topbar-fixed { display: flex; align-items: center; gap: 6px; }
.topbar-fixed:empty { display: none; }
.more-menu .btn, .more-menu .file-btn {
    width: 100%; min-height: 44px; padding: 10px 12px;
    justify-content: flex-start; gap: 10px;
    background: transparent; border: none; border-radius: 9px;
    font-size: 0.9rem; font-weight: 500; max-width: none;
    display: flex;
}
.more-menu .btn:hover, .more-menu .file-btn:hover { background: var(--panel-2); }
.more-menu .btn.danger-ghost { color: var(--danger); }
.more-menu .menu-head {
    padding: 8px 12px 4px; font-size: 0.68rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-mute);
}

/* ---------- BOTONES ---------- */
.btn {
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: 9px;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: transform 140ms ease-out, background 140ms ease-out, border-color 140ms ease-out;
    color: var(--text);
    background: var(--panel-2);
    border-color: var(--line);
    line-height: 1;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    /* Hay botones que son <a> (los del chasis que llevan a otra página): sin
       esto salen subrayados y desentonan con los demás. */
    text-decoration: none;
}
.btn:hover { background: #232b3a; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { background: #2bbe88; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.accent-outline { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn.accent-outline:hover { background: rgba(52, 211, 153, 0.12); }
.btn.danger-ghost { background: transparent; color: var(--danger); border-color: transparent; }
.btn.danger-ghost:hover { background: rgba(248, 113, 113, 0.12); }
.btn.tiny { padding: 6px 12px; font-size: 0.8rem; }
.btn.icon-btn { padding: 8px 12px; font-size: 1.05rem; line-height: 1; }
.btn:disabled { opacity: 0.35; cursor: default; transform: none; }
.btn:disabled:hover { background: transparent; }
.file-btn { cursor: pointer; }
.save-indicator { font-size: 0.78rem; color: var(--text-mute); min-width: 60px; }
.save-indicator.saved { color: var(--accent); }

/* ---------- LAYOUT ---------- */
/* Móvil: una columna y el lienzo manda. Los controles NO empujan al lienzo
   fuera de la pantalla — viven en una hoja inferior que se desliza encima. */
.layout {
    display: flex;
    flex-direction: column;
    width: 100%;
    padding: 0;
    margin: 0 auto;
}

/* ---------- PANEL EDITOR = HOJA INFERIOR (móvil) ---------- */
.editor-panel {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 55;
    height: 92dvh;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border-top: 1px solid var(--line);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -20px 50px -28px rgba(0, 0, 0, 0.9);
    overflow: hidden;
    /* La altura visible la escribe el JS en `transform`. Solo transform y
       opacity: cualquier otra propiedad haría layout en cada frame del gesto. */
    transform: translateY(calc(100% - var(--sheet-peek)));
    transition: transform 300ms var(--ease-drawer);
}
.editor-panel.dragging { transition: none; }

/* Asa: es el tirador y también el botón. Arrastras para graduar, tocas para
   abrir o cerrar; las dos cosas que la mano intenta sin que se lo expliquen. */
.sheet-grip {
    flex: 0 0 auto;
    display: grid; place-items: center;
    width: 100%; height: 26px;
    background: transparent; border: none; cursor: grab;
    touch-action: none;
}
.sheet-grip::before {
    content: ''; width: 38px; height: 4px; border-radius: 999px;
    background: #39415400; background: var(--line);
    transition: background 140ms var(--ease-out), width 200ms var(--ease-out);
}
.sheet-grip:hover::before { background: #3b455c; }
.sheet-grip:active { cursor: grabbing; }
body.sheet-open .sheet-grip::before { width: 48px; }

.sheet-scrim {
    position: fixed; inset: 0; z-index: 54;
    background: rgba(6, 8, 12, 0.5);
    opacity: 0; pointer-events: none;
    transition: opacity 240ms var(--ease-out);
}
body.sheet-open .sheet-scrim { opacity: 1; pointer-events: auto; }

/* Pestañas de la pieza: fichas en una fila que se desplaza. Con seis pestañas
   una fila que envuelve empujaba el contenido y cambiaba de alto al cambiar
   de pieza; la fila deslizable siempre mide lo mismo. */
.tabs {
    flex: 0 0 auto;
    display: flex;
    gap: 6px;
    padding: 2px 12px calc(10px + var(--safe-b));
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}
.tabs::-webkit-scrollbar { display: none; }
.tabs[hidden] { display: none; }
.tab-btn {
    flex: 0 0 auto;
    min-height: 38px;
    padding: 8px 14px;
    background: var(--panel-2);
    border: 1px solid transparent;
    border-radius: 999px;
    color: var(--text-dim);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 140ms var(--ease-out), color 140ms var(--ease-out), border-color 140ms var(--ease-out);
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
    background: rgba(52, 211, 153, 0.13);
    border-color: rgba(52, 211, 153, 0.42);
    color: var(--accent);
}
.tab-panels {
    flex: 1 1 auto; min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 16px 16px calc(28px + var(--safe-b));
}
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn 180ms var(--ease-out); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.section-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-mute);
    margin-bottom: 10px;
}

/* ---------- CAMPOS ---------- */
.editor-field { margin-bottom: 16px; }
.editor-field > label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 6px;
    font-weight: 500;
}
.hint { font-size: 0.74rem; color: var(--text-mute); font-weight: 400; }
.accent { color: var(--accent); font-weight: 700; }
.mini { font-size: 0.72rem; color: var(--text-mute); }

input, textarea, select {
    width: 100%;
    padding: 10px 11px;
    background: var(--app-bg);
    border: 1px solid var(--line);
    border-radius: 9px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    transition: border-color 140ms ease-out;
}
textarea { min-height: 78px; resize: vertical; line-height: 1.4; }
textarea.one-line { min-height: 44px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
input[type="color"] { height: 44px; padding: 4px; cursor: pointer; }
input[type="range"] { padding: 0; height: 26px; accent-color: var(--accent); cursor: pointer; }

.dual-input { display: flex; gap: 10px; }
.dual-input > div { flex: 1; }
.preset-row, .apply-row, .palette-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.apply-row { align-items: center; }
.apply-row select { flex: 1; min-width: 110px; }

.editor-subhead { color: var(--accent); font-size: 0.95rem; font-weight: 700; margin: 2px 0 14px; letter-spacing: -0.01em; }
.inline-select {
    width: auto; display: inline-block; margin-left: 8px;
    padding: 3px 6px; font-size: 0.72rem; vertical-align: middle;
}
/* --- Video de código --- */
.cv-panel-edit { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 10px; background: var(--app-bg); }
.cv-code { min-height: 96px; font-family: 'JetBrains Mono', monospace; font-size: 0.82rem; line-height: 1.45; margin-top: 6px; white-space: pre; overflow-x: auto; }
.cv-preview-wrap { display: flex; justify-content: center; margin-top: 14px; }
/* El tamaño en pantalla lo fija fitActiveStageCanvas(); aquí solo lo cosmético. */
#codePreview { border-radius: 10px; border: 1px solid var(--line); background: #000; }

/* --- Editor de secciones (bloques) --- */
.blocks-list { display: flex; flex-direction: column; gap: 10px; }
.block-item { border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: var(--app-bg); }
.block-item.dragging { opacity: 0.4; }
.block-item.drag-over { border-color: var(--accent); border-style: dashed; }
.block-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; cursor: grab; }
.block-head:active { cursor: grabbing; }
.block-head .drag-handle { color: var(--text-mute); font-size: 0.9rem; letter-spacing: -2px; user-select: none; }
.block-head .block-type { flex: 1; font-size: 0.78rem; font-weight: 600; color: var(--text-dim); }
.block-del {
    width: 20px; height: 20px; border-radius: 5px; border: none;
    background: transparent; color: var(--text-mute); cursor: pointer; font-size: 0.72rem;
}
.block-del:hover { color: var(--danger); background: rgba(248,113,113,0.12); }
.add-block { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.fmt-bar { display: flex; gap: 5px; margin-bottom: 6px; }
.fmt-bar button {
    min-width: 30px; padding: 5px 8px;
    background: var(--app-bg); border: 1px solid var(--line); border-radius: 6px;
    color: var(--text-dim); font-family: inherit; font-size: 0.8rem; cursor: pointer;
    transition: background 140ms ease-out, color 140ms ease-out;
}
.fmt-bar button:hover { background: var(--panel-2); color: var(--accent); }
.fmt-bar button:active { transform: scale(0.95); }

.checkbox-row { display: flex; gap: 18px; flex-wrap: wrap; }
.checkbox-row .check { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; color: var(--text); margin: 0; cursor: pointer; }
.checkbox-row .check input { width: auto; }

.bg-section { border-top: 1px solid var(--line-soft); padding-top: 14px; margin-top: 16px; }
.bg-upload-row { display: flex; gap: 8px; flex-wrap: wrap; }
.reel-panel { border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-top: 4px; background: rgba(52,211,153,0.03); }

/* --- Modal genérico (editor de tema, etc.) --- */
.modal-overlay {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(6, 8, 12, 0.8); backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center; padding: 24px;
    animation: fadeIn 160ms ease-out;
}
.modal-box {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: 16px; padding: 18px;
    display: flex; flex-direction: column; gap: 10px;
    width: min(94vw, 440px); max-height: 92vh; overflow-y: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; font-size: 0.95rem; }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.color-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ce-item { display: flex; flex-direction: column; gap: 4px; font-size: 0.72rem; color: var(--text-dim); }
.ce-item input[type="color"] { height: 38px; padding: 3px; width: 100%; cursor: pointer; }
.seg-toggle { display: inline-flex; gap: 0; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; margin-left: 8px; vertical-align: middle; }
.seg-toggle button {
    padding: 4px 10px; background: transparent; border: none; color: var(--text-dim);
    font-family: inherit; font-size: 0.72rem; cursor: pointer;
}
.seg-toggle button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.grad-builder { display: flex; flex-direction: column; gap: 8px; }
.grad-preview { height: 34px; border-radius: 8px; border: 1px solid var(--line); }
.fill-swatches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
.fill-sw {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 7px; background: var(--app-bg); border: 1px solid var(--line); border-radius: 8px;
    cursor: pointer; color: var(--text-dim); font-family: inherit; font-size: 0.68rem;
    transition: border-color 140ms ease-out;
}
.fill-sw:hover { border-color: var(--text-mute); }
.fill-sw.active { border-color: var(--accent); color: var(--text); }
.fsw-chip { flex: 0 0 16px; width: 16px; height: 16px; border-radius: 4px; border: 1px solid rgba(255,255,255,0.15); }
.fsw-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fill-editor { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: rgba(255,255,255,0.02); }

.gstops { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.gstop { position: relative; }
.gstop input[type="color"] { width: 42px; height: 38px; padding: 3px; cursor: pointer; }
.gstop-del {
    position: absolute; top: -6px; right: -6px;
    width: 16px; height: 16px; border-radius: 50%;
    background: var(--danger); border: none; color: #fff;
    font-size: 0.58rem; cursor: pointer; display: grid; place-items: center; line-height: 1;
}

/* --- Modal de previsualización del Reel --- */
.reel-modal {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(6, 8, 12, 0.8);
    backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
    animation: fadeIn 160ms ease-out;
}
.reel-modal-box {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: 16px; padding: 16px;
    display: flex; flex-direction: column; gap: 12px;
    max-width: min(92vw, 460px); max-height: 92vh;
}
.reel-modal-head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; font-size: 0.95rem; }
.reel-modal-box video {
    width: 100%; max-height: 70vh; border-radius: 10px;
    background: #000; display: block;
}
.reel-modal-actions { display: flex; align-items: center; gap: 12px; }

.text-sizes-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.text-sizes-grid > div { display: flex; flex-direction: column; }
.text-sizes-grid label { font-size: 0.7rem; color: var(--text-mute); margin-bottom: 3px; }
.text-sizes-grid input { padding: 7px 8px; font-size: 0.82rem; }

/* ---------- PLANTILLAS DE CONTENIDO ---------- */
.template-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.template-chip {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 7px 11px;
    background: var(--app-bg); border: 1px solid var(--line); border-radius: 8px;
    color: var(--text); font-family: inherit; font-size: 0.8rem; font-weight: 500;
    cursor: pointer; transition: border-color 140ms ease-out, background 140ms ease-out, transform 140ms ease-out;
}
.template-chip:hover { border-color: var(--accent); background: var(--panel-2); }
.template-chip:active { transform: scale(0.97); }
.template-chip .tc-icon { font-size: 0.95rem; }
.template-chip.custom { border-color: #3a3d2a; }
.template-chip.custom .chip-actions {
    display: inline-flex; gap: 2px; margin-left: 4px;
    max-width: 0; overflow: hidden;
    transition: max-width 160ms ease-out;
}
.template-chip.custom:hover .chip-actions { max-width: 70px; }
.chip-actions .ca-btn {
    width: 18px; height: 18px; font-size: 0.62rem;
    background: var(--app-bg); color: var(--text-mute); border: 1px solid var(--line);
}
.chip-actions .ca-btn:hover { background: var(--panel-2); color: var(--accent); }
.chip-actions .ca-btn.ca-del:hover { color: var(--danger); border-color: var(--danger); background: rgba(248,113,113,0.12); }
.template-chip.save-tpl { border-style: dashed; color: var(--accent); }
.template-chip.bt-full { border-color: var(--accent); color: var(--accent); }

/* --- Montar desde la marca (pestaña Contenido) --- */
.brand-templates { display: flex; flex-direction: column; gap: 9px; }
.brand-templates .bt-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.brand-templates .bt-row select { width: 100%; }
.bt-preview {
    align-self: flex-start;
    padding: 5px 11px; border-radius: 5px;
    font-size: 0.72rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase;
}
.bt-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.template-chip.save-tpl:hover { border-color: var(--accent); background: rgba(52,211,153,0.08); }

/* --- PORTADAS PREDISEÑADAS --- */
.cover-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.cover-card {
    border: 1px solid var(--line); border-radius: 11px; overflow: hidden;
    cursor: pointer; background: var(--app-bg); padding: 0;
    display: flex; flex-direction: column;
    transition: transform 140ms ease-out, border-color 140ms ease-out;
}
.cover-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.cover-swatch { aspect-ratio: 4/5; padding: 10px; display: flex; flex-direction: column; justify-content: center; gap: 3px; }
.cover-swatch .cv-title { font-weight: 800; font-size: 0.82rem; line-height: 1.05; }
.cover-swatch .cv-sub { font-size: 0.6rem; opacity: 0.9; }
.cover-name { font-size: 0.72rem; color: var(--text-dim); padding: 6px 8px; text-align: center; }

/* ---------- MINIATURAS DE SLIDE ---------- */
.slide-selector {
    display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px;
    max-height: 210px; overflow-y: auto; padding-right: 4px;
}
.slide-selector::-webkit-scrollbar { width: 7px; }
.slide-selector::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.slide-thumb {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 11px;
    background: var(--app-bg);
    border: 1px solid var(--line);
    border-radius: 10px;
    cursor: pointer;
    text-align: left;
    transition: border-color 140ms ease-out, background 140ms ease-out;
    width: 100%;
}
.slide-thumb:hover { background: var(--panel-2); }
.slide-thumb.active { border-color: var(--accent); background: var(--panel-2); }
.slide-thumb.dragging { opacity: 0.4; }
.slide-thumb.drag-over { border-color: var(--accent); border-style: dashed; }
.slide-thumb .drag-handle { color: var(--text-mute); cursor: grab; font-size: 0.9rem; letter-spacing: -2px; user-select: none; }
.slide-thumb:active .drag-handle { cursor: grabbing; }
.slide-thumb .num {
    flex: 0 0 24px; height: 24px; border-radius: 6px;
    display: grid; place-items: center;
    background: var(--panel-2); color: var(--text-dim);
    font-size: 0.78rem; font-weight: 700;
}
.slide-thumb.active .num { background: var(--accent); color: var(--accent-ink); }
.slide-thumb .thumb-title {
    flex: 1; font-size: 0.82rem; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.slide-thumb .thumb-type { font-size: 0.66rem; color: var(--text-mute); text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- PALETA ---------- */
.palette-section, .gradient-section { border-top: 1px solid var(--line-soft); padding-top: 16px; margin-top: 16px; }
.palette-colors { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.palette-color-item {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    background: var(--app-bg); padding: 6px; border-radius: 9px; border: 1px solid var(--line);
}
.palette-color-item input[type="color"] { width: 38px; height: 38px; padding: 2px; border: none; border-radius: 6px; }
.palette-color-item .color-label { font-size: 0.66rem; color: var(--text-mute); }
.remove-color { background: rgba(248,113,113,0.15); border: none; color: var(--danger); border-radius: 5px; padding: 2px 7px; font-size: 0.7rem; cursor: pointer; }
.remove-color:hover { background: rgba(248,113,113,0.28); }
.gradient-colors { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.gradient-color-chip { display: flex; align-items: center; gap: 4px; }
.gradient-color-chip input[type="color"] { width: 38px; height: 38px; padding: 2px; border: none; border-radius: 6px; }

/* ---------- TEMAS ---------- */
.theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.theme-card {
    border: 1px solid var(--line);
    border-radius: 11px;
    overflow: hidden;
    cursor: pointer;
    background: var(--app-bg);
    transition: transform 140ms ease-out, border-color 140ms ease-out;
    text-align: left;
    padding: 0;
    color: var(--text);
    font-family: inherit;
}
.theme-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.theme-card.active { border-color: var(--accent); }
.theme-swatch {
    height: 62px; padding: 10px;
    display: flex; flex-direction: column; justify-content: center; gap: 3px;
}
.theme-swatch .t-title { font-weight: 800; font-size: 0.92rem; line-height: 1; }
.theme-swatch .t-sub { font-size: 0.66rem; opacity: 0.85; }
.theme-swatch .t-dots { display: flex; gap: 4px; margin-top: 4px; }
.theme-swatch .t-dots span { width: 9px; height: 9px; border-radius: 50%; }
.theme-meta { padding: 8px 10px; display: flex; align-items: center; justify-content: space-between; }
.theme-meta .name { font-size: 0.82rem; font-weight: 600; }
.theme-meta .font { font-size: 0.68rem; color: var(--text-mute); }
.theme-card { position: relative; }
.card-actions {
    position: absolute; top: 5px; right: 5px;
    display: flex; gap: 3px;
    opacity: 0; transition: opacity 140ms ease-out;
}
.theme-card:hover .card-actions { opacity: 1; }
.ca-btn {
    width: 20px; height: 20px; border-radius: 50%;
    background: rgba(6,8,12,0.72); border: none; color: #fff;
    font-size: 0.68rem; cursor: pointer; display: grid; place-items: center;
    line-height: 1;
}
.ca-btn:hover { background: var(--accent); color: var(--accent-ink); }
.ca-btn.ca-del:hover { background: var(--danger); color: #fff; }
.theme-create {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 4px; min-height: 96px;
    border-style: dashed; color: var(--accent); text-align: center;
    font-size: 0.8rem; font-weight: 600; line-height: 1.2;
}
.theme-create small { color: var(--text-mute); font-weight: 400; font-size: 0.66rem; }
.theme-create .tc-plus { font-size: 1.4rem; line-height: 1; }
.theme-create:hover { background: rgba(52,211,153,0.06); border-color: var(--accent); }

/* ---------- PREVIEW ---------- */
/* Móvil: el lienzo es lo primero y ocupa lo que deja la barra y la hoja.
   Nunca hay que hacer scroll para ver lo que estás editando. */
.preview-panel {
    --stage-pad: 10px;
    flex: 1 1 auto; min-width: 0; width: 100%;
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    height: calc(100dvh - var(--topbar-h) - var(--sheet-peek));
    padding: 4px var(--stage-pad) 0;
}

/* Lienzo horizontal con scroll-snap */
.canvas-wrap { position: relative; width: 100%; display: flex; align-items: center; }
#slides-container.slides-h {
    display: flex; flex-direction: row;
    overflow-x: auto; overflow-y: hidden;
    scroll-snap-type: x mandatory;
    width: 100%;
    padding: 12px 0;
    scrollbar-width: thin;
    gap: 0;
}
#slides-container.slides-h::-webkit-scrollbar { height: 8px; }
/* Sin regla de carril, Chrome pinta el suyo, que es blanco: una banda clara
   cruzando el editor oscuro de lado a lado. */
#slides-container.slides-h::-webkit-scrollbar-track { background: transparent; }
#slides-container.slides-h::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.slide-wrap {
    flex: 0 0 100%;
    scroll-snap-align: center;
    display: flex; justify-content: center; align-items: center;
    min-width: 0;
}
.canvas-arrow {
    position: absolute; top: 50%; transform: translateY(-50%);
    z-index: 5;
    width: 40px; height: 40px; border-radius: 50%;
    background: rgba(28, 34, 48, 0.9); border: 1px solid var(--line);
    color: var(--text); font-size: 1.4rem; line-height: 1; cursor: pointer;
    display: grid; place-items: center;
    transition: background 140ms ease-out, transform 140ms ease-out;
    backdrop-filter: blur(6px);
}
.canvas-arrow:hover { background: var(--panel-2); }
.canvas-arrow:active { transform: translateY(-50%) scale(0.92); }
.canvas-arrow.left { left: 4px; }
.canvas-arrow.right { right: 4px; }

.canvas-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
.canvas-counter { font-size: 0.8rem; color: var(--text-mute); margin-right: 6px; }

/* Filmstrip inferior */
.filmstrip {
    display: flex; gap: 8px;
    overflow-x: auto; overflow-y: hidden;
    width: 100%; padding: 8px 4px;
    scrollbar-width: thin;
}
.filmstrip::-webkit-scrollbar { height: 7px; }
.filmstrip::-webkit-scrollbar-track { background: transparent; }
.filmstrip::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.film-cell {
    position: relative; flex: 0 0 auto;
    padding: 3px; border: 2px solid transparent; border-radius: 8px;
    background: transparent; cursor: pointer;
    transition: border-color 140ms ease-out;
}
.film-cell:hover { border-color: var(--line); }
.film-cell.active { border-color: var(--accent); }
.film-cell.dragging { opacity: 0.4; }
.film-cell.drag-over { border-color: var(--accent); border-style: dashed; }
.film-mini { overflow: hidden; border-radius: 5px; display: block; pointer-events: none; }
.film-mini .slide {
    border: none !important; box-shadow: none !important; border-radius: 0 !important;
    transition: none !important; max-width: none;
}
.film-num {
    position: absolute; bottom: 4px; left: 6px;
    font-size: 0.62rem; font-weight: 700; color: #fff;
    text-shadow: 0 1px 3px rgba(0,0,0,0.9); pointer-events: none;
}

/* ============================================================
   SLIDE — todo en em, escala con su ancho
   ============================================================ */
.slide {
    --slide-width: 432px;
    --slide-height: 540px;
    --slide-ar: 432 / 540;
    width: var(--slide-width);
    aspect-ratio: var(--slide-ar);
    height: auto;
    max-width: 100%;
    background-color: #0B0E14;
    padding: 2.6em 2.9em;
    border-radius: 16px;
    /* El filo va como sombra interior, no como borde: un borde metería 1px
       entre el lienzo y el origen de las cajas colocadas a mano (los % de
       position:absolute se miden contra el padding box). */
    box-shadow: 0 20px 50px -20px rgba(0,0,0,0.6), inset 0 0 0 1px rgba(255,255,255,0.06);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
    font-family: var(--slide-font, 'Sora', sans-serif);
    font-size: 16px; /* el JS lo recalcula = ancho * 0.04 * escala */
    transition: background-color 200ms ease-out;
}
.slide-type-portada { justify-content: center; text-align: center; }
.slide-type-cta { justify-content: center; }

/* --- capas de fondo (imagen / video) + scrim de contraste --- */
.slide-media, .slide-scrim { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.slide-media > img, .slide-media > video {
    width: 100%; height: 100%; display: block;
    object-fit: var(--bg-fit, cover);
    object-position: var(--bg-pos, center);
}
/* El contenido va por encima de las capas */
.slide > .title, .slide > .subtitle, .slide > .body,
.slide > .code-block, .slide > .tip, .slide > .cta,
.slide > .footer, .slide > .arrow { position: relative; z-index: 1; }
.slide > .footer, .slide > .arrow { position: absolute; }

.slide .title,
.slide .subtitle,
.slide .cta { font-family: var(--slide-font-display, var(--slide-font, 'Sora', sans-serif)); }

.slide .title {
    font-size: calc(var(--title-em, 2.6) * 1em);
    font-weight: 800;
    color: var(--title-color, #F4F7FB);
    margin-bottom: 0.5em;
    line-height: 1.08;
    letter-spacing: -0.021em;
}
.slide .highlight { color: var(--highlight-color, #34d399); }

/* Resaltado de sintaxis (highlight.js) dentro del bloque de código */
/* El relleno debe seguir el color de cada token (si no, hereda el text-fill del código) */
.slide .code-block span[class*="hljs-"] { -webkit-text-fill-color: currentColor; }
.slide .code-block .hljs-comment, .slide .code-block .hljs-quote { color: #7d8590; font-style: italic; }
.slide .code-block .hljs-keyword, .slide .code-block .hljs-selector-tag,
.slide .code-block .hljs-built_in, .slide .code-block .hljs-meta .hljs-keyword,
.slide .code-block .hljs-doctag { color: #ff7b72; }
.slide .code-block .hljs-string, .slide .code-block .hljs-attr,
.slide .code-block .hljs-regexp, .slide .code-block .hljs-addition,
.slide .code-block .hljs-meta .hljs-string { color: #a5d6ff; }
.slide .code-block .hljs-number, .slide .code-block .hljs-literal,
.slide .code-block .hljs-symbol, .slide .code-block .hljs-bullet { color: #79c0ff; }
.slide .code-block .hljs-title, .slide .code-block .hljs-title.function_,
.slide .code-block .hljs-section, .slide .code-block .hljs-name { color: #d2a8ff; }
.slide .code-block .hljs-variable, .slide .code-block .hljs-template-variable,
.slide .code-block .hljs-params, .slide .code-block .hljs-attribute { color: #ffa657; }
.slide .code-block .hljs-type, .slide .code-block .hljs-class .hljs-title { color: #7ee787; }
.slide .code-block .hljs-meta { color: #79c0ff; }
.slide .code-block .hljs-deletion { color: #ffa198; }
.slide .code-block .hljs-emphasis { font-style: italic; }
.slide .code-block .hljs-strong { font-weight: 700; }
.slide strong, .slide b { font-weight: 900; }
.slide mark.hl {
    background: color-mix(in srgb, var(--highlight-color, #34d399) 35%, transparent);
    color: inherit;
    -webkit-text-fill-color: currentColor;
    padding: 0.02em 0.22em;
    border-radius: 0.22em;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

.slide .subtitle {
    font-size: calc(var(--subtitle-em, 1.4) * 1em);
    color: var(--subtitle-color, #97A0B5);
    font-weight: 400;
    margin-bottom: 0.85em;
    line-height: 1.35;
}

.slide .body {
    font-size: calc(var(--body-em, 1.2) * 1em);
    color: var(--body-color, #C9D0DE);
    line-height: 1.62;
}
.slide-type-contenido .body { flex-grow: 1; }

.slide .body code {
    background: var(--code-bg, #161B26);
    padding: 0.14em 0.5em;
    border-radius: 0.4em;
    font-family: var(--slide-font-mono, 'JetBrains Mono', monospace);
    color: var(--code-color, #34d399);
    font-size: 0.9em;
}

.slide .code-block {
    background: var(--code-bg, #161B26);
    padding: 0.95em 1.15em;
    border-radius: 0.7em;
    font-family: var(--slide-font-mono, 'JetBrains Mono', monospace);
    color: var(--code-color, #34d399);
    font-size: calc(var(--code-em, 0.9) * 1em);
    margin: 0.9em 0;
    white-space: pre-wrap;
    line-height: 1.5;
    border-left: 0.22em solid var(--highlight-color, #34d399);
}

.slide .tip {
    background: var(--tip-bg, #10201B);
    padding: 0.75em 0.95em;
    border-radius: 0.6em;
    color: var(--tip-color, #A7F3D0);
    font-size: calc(var(--tip-em, 1) * 1em);
    line-height: 1.4;
    margin-top: 0.6em;
}

.slide .cta {
    font-size: calc(var(--cta-em, 1.8) * 1em);
    font-weight: 700;
    color: var(--title-color, #F4F7FB);
    margin-top: auto;
    text-align: center;
    line-height: 1.5;
}
.slide .cta .emoji { font-size: 1.25em; }

.slide .footer {
    position: absolute;
    bottom: 1.1em; right: 1.5em;
    font-size: 0.8em;
    color: var(--subtitle-color, #97A0B5);
    opacity: 0.7;
    font-weight: 600;
}
.slide .arrow {
    position: absolute;
    bottom: 1.3em; left: 1.5em;
    font-size: 2em;
    color: var(--highlight-color, #34d399);
}

.slide-actions { display: flex; gap: 8px; justify-content: center; }
.slide-actions button {
    padding: 6px 14px; background: var(--panel-2); color: var(--text);
    border: 1px solid var(--line); border-radius: 7px; cursor: pointer; font-size: 0.76rem;
    font-family: inherit;
    transition: background 140ms ease-out, transform 140ms ease-out;
}
.slide-actions button:hover { background: #232b3a; }
.slide-actions button:active { transform: scale(0.97); }
.slide-actions button.del { color: var(--danger); }


/* ===== QUIZ ===== */
.quiz-stage { display:flex; justify-content:center; margin-bottom:14px; }
.quiz-canvas-holder { position:relative; display:inline-block; }
#quizCanvas { display:block;
  border-radius:10px; box-shadow:0 10px 40px rgba(0,0,0,.45); }
.quiz-overlay { position:absolute; inset:0; }
.quiz-el-box { position:absolute; box-sizing:border-box; cursor:move; }
.quiz-el-box.selected { outline:2px solid #34d399; outline-offset:2px; }
.quiz-handle { position:absolute; width:12px; height:12px; background:#34d399;
  border:2px solid #05060f; border-radius:50%; }
.quiz-handle.nw{left:-6px;top:-6px;cursor:nwse-resize;} .quiz-handle.ne{right:-6px;top:-6px;cursor:nesw-resize;}
.quiz-handle.sw{left:-6px;bottom:-6px;cursor:nesw-resize;} .quiz-handle.se{right:-6px;bottom:-6px;cursor:nwse-resize;}
.quiz-guide { position:absolute; background:#f472b6; pointer-events:none; z-index:5; }
.quiz-guide.v{width:1px;} .quiz-guide.h{height:1px;}
.quiz-actions-row, .quiz-add-row { display:flex; gap:8px; flex-wrap:wrap; margin:8px 0; }
.quiz-list { display:flex; flex-direction:column; gap:4px; margin:8px 0; }
.quiz-row { display:flex; align-items:center; gap:4px; }
.quiz-row.sel { background:rgba(52,211,153,.12); border-radius:8px; }
.quiz-row-name { flex:1; text-align:left; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

/* ============================================================
   PESTAÑA MARCA (Brand Kit)
   ============================================================ */

/* --- Selector de marca --- */
.brand-switcher {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
}
.brand-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: transparent;
    color: var(--text-dim);
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    transition: color 140ms ease-out, border-color 140ms ease-out, background 140ms ease-out;
}
.brand-chip:hover { color: var(--text); border-color: var(--line); background: var(--panel-2); }
.brand-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.brand-chip.active { color: var(--text); border-color: var(--accent); background: var(--panel-2); }
.brand-chip.new { color: var(--text-mute); border-style: dashed; }
.brand-chip.new:hover { color: var(--accent); border-color: var(--accent); }
.brand-chip-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.14) inset;
}

/* --- Preview de identidad --- */
/* Mini slide con los roles reales de color, alineada a la izquierda:
   se lee como una slide, no como una tarjeta de muestra. */
.brand-preview {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 22px 20px 18px;
    aspect-ratio: 4 / 5;
    max-height: 300px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.brand-prev-title { font-size: 1.35rem; font-weight: 700; line-height: 1.2; letter-spacing: -0.015em; }
.brand-prev-sub { font-size: 0.82rem; line-height: 1.4; }
.brand-prev-code {
    align-self: flex-start;
    padding: 7px 11px;
    border-radius: 8px;
    font-size: 0.76rem;
}
.brand-prev-foot { margin-top: auto; font-size: 0.72rem; }
.brand-prev-logo { position: absolute; max-width: 30%; height: auto; }
.brand-prev-logo.pos-top-left { top: 14px; left: 14px; }
.brand-prev-logo.pos-top-right { top: 14px; right: 14px; }
.brand-prev-logo.pos-bottom-left { bottom: 14px; left: 14px; }
.brand-prev-logo.pos-bottom-right { bottom: 14px; right: 14px; }

/* --- Logo --- */
.brand-logo-row { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.brand-logo-slot {
    flex: 0 0 78px;
    height: 78px;
    display: grid;
    place-items: center;
    border: 1px dashed var(--line);
    border-radius: 10px;
    background: var(--panel-2);
    padding: 8px;
}
.brand-logo-slot.has { border-style: solid; }
.brand-logo-slot img { max-width: 100%; max-height: 100%; object-fit: contain; }
.brand-logo-actions { display: flex; flex-direction: column; gap: 7px; align-items: flex-start; }
.file-btn { cursor: pointer; display: inline-flex; align-items: center; }

.logo-pos-row { display: flex; gap: 6px; }
.logo-pos {
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: transparent;
    color: var(--text-mute);
    font-size: 1rem;
    cursor: pointer;
    transition: color 140ms ease-out, border-color 140ms ease-out;
}
.logo-pos:hover { color: var(--text); }
.logo-pos:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.logo-pos.active { color: var(--accent); border-color: var(--accent); }

/* --- Colores de marca --- */
.brand-colors { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; }
.brand-color-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 7px 0;
    border-bottom: 1px solid var(--line-soft);
}
.brand-color-row:last-child { border-bottom: none; }
.brand-color-row input[type="color"] {
    flex: 0 0 38px;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: transparent;
    cursor: pointer;
}
.brand-color-meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.brand-color-name { font-size: 0.84rem; color: var(--text); }
.brand-color-hex { margin-left: auto; font-size: 0.72rem; color: var(--text-mute); font-family: 'JetBrains Mono', monospace; }

.brand-warn {
    border-left: 2px solid var(--danger);
    padding: 9px 0 9px 12px;
    margin: 4px 0 6px;
}
.brand-warn strong { display: block; font-size: 0.8rem; color: var(--danger); margin-bottom: 4px; }
.brand-warn ul { list-style: none; margin-bottom: 5px; }
.brand-warn li { font-size: 0.78rem; color: var(--text-dim); }

/* --- Acciones --- */
.brand-actions { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.brand-actions > .btn.primary { width: 100%; justify-content: center; }
.brand-actions-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

/* --- Colecciones de la marca (logos, mascotas) --- */
.asset-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}
.asset-thumb {
    position: relative;
    width: 62px;
    height: 62px;
    display: grid;
    place-items: center;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel-2);
    transition: border-color 140ms ease-out;
}
.asset-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.asset-thumb.active { border-color: var(--accent); }
.asset-thumb.add {
    border-style: dashed;
    color: var(--text-mute);
    font-size: 1.1rem;
    cursor: pointer;
}
.asset-thumb.add:hover { color: var(--accent); border-color: var(--accent); }
.asset-pick {
    all: unset;
    cursor: pointer;
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
}
.asset-pick:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.asset-del {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--panel);
    color: var(--text-mute);
    font-size: 0.9rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity 140ms ease-out, color 140ms ease-out;
}
.asset-thumb:hover .asset-del, .cat-row:hover .asset-del, .font-chip:hover .asset-del { opacity: 1; }
.asset-del:hover { color: var(--danger); border-color: var(--danger); }
.asset-del:focus-visible { opacity: 1; outline: 2px solid var(--accent); outline-offset: 1px; }
.asset-del.inline { position: static; width: 18px; height: 18px; border: none; background: transparent; }

/* --- Categorías --- */
.cat-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.cat-row { display: flex; align-items: center; gap: 8px; }
.cat-row input[type="color"] {
    flex: 0 0 30px;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
}
.cat-row .cat-label { flex: 1 1 90px; min-width: 0; }
.cat-preview {
    flex: 0 0 auto;
    max-width: 40%;
    padding: 4px 9px;
    border-radius: 5px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- Tipografías subidas --- */
.font-upload { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }
.font-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 0.72rem;
    color: var(--text-dim);
}

/* --- Añadidos al preview de identidad --- */
.brand-prev-badge {
    align-self: flex-start;
    padding: 5px 11px;
    border-radius: 5px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.brand-prev-mascot {
    position: absolute;
    right: -6%;
    bottom: -4%;
    width: 46%;
    opacity: 0.95;
    pointer-events: none;
}

/* --- Logo de marca estampado en la slide --- */
/* Offsets en em: escalan con el tamaño de export igual que la tipografía. */
/* --- Badge de categoría: el color sale de la marca, en el style inline --- */
.slide .slide-badge {
    position: relative;   /* si no, su fondo queda por debajo del scrim */
    z-index: 1;
    align-self: flex-start;
    display: inline-block;
    font-family: var(--slide-font-display, var(--slide-font, 'Sora', sans-serif));
    font-size: calc(var(--badge-em, 0.78) * 1em);
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0.5em 0.95em;
    border-radius: 0.25em;
    margin-bottom: 0.9em;
    line-height: 1;
}
.slide-type-portada .slide-badge { align-self: center; }

/* --- Mascota: sangra por el borde inferior; la slide recorta con overflow --- */
.slide .slide-mascot {
    position: absolute;
    bottom: -6%;   /* sangra por abajo: en los posts de la marca el pato va cortado */
    height: auto;
    z-index: 2;
    pointer-events: none;
}
.slide .slide-mascot.pos-bottom-right { right: -2%; }
.slide .slide-mascot.pos-bottom-left { left: -2%; }
.slide .slide-mascot.pos-bottom-center { left: 50%; transform: translateX(-50%); }

.slide .brand-mark {
    position: absolute;
    height: auto;
    pointer-events: none;
    z-index: 3;
}
.slide .brand-mark.pos-top-left { top: 1.1em; left: 1.2em; }
.slide .brand-mark.pos-top-right { top: 1.1em; right: 1.2em; }
.slide .brand-mark.pos-bottom-left { bottom: 1.1em; left: 1.2em; }
.slide .brand-mark.pos-bottom-right { bottom: 1.1em; right: 1.2em; }

/* --- Guías de zona segura (solo preview, nunca se exportan) --- */
.safe-areas {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 4;
}
.safe-band {
    position: absolute;
    background: rgba(248, 113, 113, 0.13);
    border-color: rgba(248, 113, 113, 0.4);
    border-style: dashed;
    border-width: 0;
}
.safe-band.top { top: 0; left: 0; right: 0; border-bottom-width: 1px; }
.safe-band.bottom { bottom: 0; left: 0; right: 0; border-top-width: 1px; }
.safe-band.left { top: 0; bottom: 0; left: 0; border-right-width: 1px; }
.safe-band.right { top: 0; bottom: 0; right: 0; border-left-width: 1px; }

.check-row {
    display: flex !important;
    align-items: center;
    gap: 7px;
    margin-top: 8px;
    font-size: 0.78rem;
    color: var(--text-dim);
    cursor: pointer;
}
.check-row input { width: auto; margin: 0; }

/* --- Selector del pack multi-formato --- */
.pack-picker { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 12px; }
.pack-net { display: flex; flex-direction: column; gap: 3px; }
.pack-net-name {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-mute);
    margin-bottom: 2px;
}
.pack-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 3px 0 3px 8px;
    font-size: 0.79rem;
    color: var(--text-dim);
    cursor: pointer;
    transition: color 140ms ease-out;
}
.pack-item:hover { color: var(--text); }
.pack-item input { width: auto; margin: 0; }

/* ---------- BARRA DE PIEZAS (post / reel / código / quiz) ---------- */
/* Nivel superior de navegación: qué estás haciendo. Debajo van las pestañas
   de esa pieza. Marca queda aparte porque es global, no una pieza. */
/* Móvil: fichas en una fila que se desplaza. Con `flex-wrap: nowrap` y cinco
   piezas, "Quiz" y "Marca" se montaban una encima de otra a 390px. */
.pieces {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 2px 12px 10px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
}
.pieces::-webkit-scrollbar { display: none; }
/* `min-width: 0` dejaba que la fila se encogiera por debajo de sus fichas y
   "Quiz" y "Marca" acababan una encima de otra. Ocupa lo suyo y la fila rueda. */
.piece-bar { display: flex; gap: 6px; flex-wrap: nowrap; flex: 0 0 auto; min-width: max-content; }
.pieces > .piece-btn.global { flex: 0 0 auto; }
.piece-btn {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 8px 14px;
    white-space: nowrap;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: transparent;
    color: var(--text-dim);
    font-family: inherit;
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 140ms var(--ease-out), background 140ms var(--ease-out), border-color 140ms var(--ease-out);
}
.piece-btn:hover { color: var(--text); }
.piece-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 999px; }
/* La pieza activa es el nivel de arriba de la navegación: se marca con peso
   (ficha sólida), no con otro color. El acento se reserva para las pestañas. */
.piece-btn.active { background: var(--text); color: var(--app-bg); border-color: transparent; }
/* Marca es global, no una pieza: va detrás de un filo que lo dice. */
.piece-btn.global {
    margin-left: 4px;
    padding-left: 14px;
    border-color: transparent;
    box-shadow: inset 1px 0 0 var(--line-soft);
    border-radius: 999px;
}
.piece-btn.global:hover { color: var(--text); }
.piece-btn.global.active { background: transparent; color: var(--accent); border-color: var(--accent); box-shadow: none; }

/* ============================================================
   TIMELINE
   ============================================================ */
.tl-stage {
    display: grid;
    place-items: center;
    padding: 10px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: 10px;
}
/* El tamaño en pantalla lo fija fitActiveStageCanvas(); aquí solo lo cosmético. */
#tlCanvas { border-radius: 6px; background: #000; }

/* --- Transporte --- */
.tl-transport {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.tl-time { font-size: 0.78rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.tl-time strong { color: var(--text); }
.tl-transport label { display: inline-flex; align-items: center; gap: 5px; }
.tl-transport input { width: 58px; }

/* --- Regla y pistas --- */
/* Ancho de la columna de nombres. Lo lee el JS (tlHeadWidth) para convertir
   píxeles en segundos, así que vive en :root y no repetido en cada regla. */
:root { --tl-head-w: 92px; }

.tl-tracks {
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: auto;
    margin-bottom: 10px;
    /* Arrastrar por los nombres o por los huecos desplaza el timeline; sobre un
       clip manda el arrastre del clip (.tl-clip lo apaga). */
    touch-action: pan-x pan-y;
    overscroll-behavior: contain;
}
/* La rejilla entera es tan ancha como pida el zoom; la regla y las pistas van
   dentro del MISMO desplazable o se descuadran entre ellas. */
.tl-grid { position: relative; width: max-content; min-width: 100%; }
.tl-ruler-row { display: flex; position: sticky; top: 0; z-index: 4; }
.tl-ruler-head {
    flex: 0 0 var(--tl-head-w);
    /* `min-width: auto` en un ítem flex es su tamaño min-content: la columna
       aportaba el ancho de sus botones al max-content de la fila y la rejilla
       salía 40px más ancha de la cuenta (barra de scroll fantasma al ajustar). */
    min-width: 0;
    position: sticky; left: 0; z-index: 5;
    background: var(--panel-2);
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}
/* Línea del cursor cruzando todas las pistas. La fracción la escribe el JS. */
.tl-playline {
    position: absolute;
    top: 0; bottom: 0;
    width: 1px;
    left: calc(var(--tl-head-w) + var(--tl-lane-w, 0px) * var(--tl-play, 0));
    background: var(--accent);
    opacity: 0.45;
    pointer-events: none;
    z-index: 2;
}
.tl-ruler {
    position: relative;
    flex: 0 0 var(--tl-lane-w, auto);
    width: var(--tl-lane-w, auto);
    height: 22px;
    border-bottom: 1px solid var(--line);
    background: var(--panel-2);
    cursor: pointer;
    touch-action: none;
}
.tl-mark {
    position: absolute;
    top: 0;
    height: 100%;
    padding-left: 3px;
    border-left: 1px solid var(--line-soft);
    font-size: 0.6rem;
    color: var(--text-mute);
    line-height: 22px;
    pointer-events: none;
}
.tl-mark.major { border-left-color: var(--line); }
.tl-playhead {
    position: absolute;
    top: 0;
    width: 2px;
    height: 100%;
    margin-left: -1px;
    background: var(--accent);
    pointer-events: none;
}

.tl-row { display: flex; align-items: stretch; border-top: 1px solid var(--line-soft); }
.tl-row:first-of-type { border-top: none; }
.tl-row-head {
    flex: 0 0 var(--tl-head-w);
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 4px 0 8px;
    background: var(--panel-2);
    border-right: 1px solid var(--line);
    /* Se queda a la vista al rodar el timeline de lado: sin esto, al acercar
       dejas de saber qué pista estás tocando. */
    position: sticky;
    left: 0;
    z-index: 3;
}
.tl-row-name {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.66rem;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Los tres controles de la pista compiten con su nombre por 92px: se aprietan
   para que el nombre siga siendo legible, que es lo que se lee de un vistazo. */
.tl-row-btn {
    flex: 0 0 auto;
    padding: 2px 1px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 0.7rem;
    cursor: pointer;
    opacity: 0.75;
    transition: opacity 140ms ease-out;
}
.tl-row-btn:hover { opacity: 1; }
.tl-row-btn.off { opacity: 0.4; }

.tl-lane {
    position: relative;
    flex: 0 0 var(--tl-lane-w, auto);
    min-width: 0;
    width: var(--tl-lane-w, auto);
    height: 34px;
    /* La rejilla de fondo sigue al zoom: es la misma que la regla. */
    background-image: linear-gradient(90deg, var(--line-soft) 0 1px, transparent 1px);
    background-size: var(--tl-grid-px, 40px) 100%;
    touch-action: pan-x pan-y;
    /* Un clip diminuto se estira hasta `min-width` y asoma por el final de la
       pista: sin esto, ajustado al ancho aparecía una barra de scroll fantasma. */
    overflow: hidden;
}
.tl-clip {
    position: absolute;
    top: 4px;
    height: 26px;
    /* Sobre el clip manda arrastrar el clip, no desplazar el timeline. */
    touch-action: none;
    display: flex;
    align-items: center;
    min-width: 14px;
    padding: 0 4px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
    cursor: grab;
    overflow: hidden;
    transition: border-color 140ms ease-out;
}
.tl-clip:hover { border-color: var(--text-mute); }
.tl-clip.selected { border-color: var(--accent); background: rgba(52, 211, 153, 0.1); }
.tl-clip-label {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.64rem;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}
.tl-clip-grip {
    flex: 0 0 5px;
    align-self: stretch;
    cursor: ew-resize;
    border-radius: 2px;
}
.tl-clip-grip:hover { background: var(--accent); }

/* Las pistas de audio se distinguen de un vistazo: no se dibujan, suenan. */
.tl-row.audio .tl-lane { background-color: rgba(129, 140, 248, 0.06); }
.tl-clip.audio { background: rgba(129, 140, 248, 0.16); border-color: rgba(129, 140, 248, 0.5); }
.tl-clip.audio.selected { background: rgba(129, 140, 248, 0.28); border-color: var(--accent); }
/* Sin archivo cargado: el clip sigue ahí pero mudo, y se ve. */
.tl-clip.missing { border-style: dashed; opacity: 0.6; }
.hint.warn { color: #fbbf24; }

/* --- Añadir e inspector --- */
.tl-add { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-bottom: 12px; }
.tl-inspector { border-top: 1px solid var(--line); padding-top: 12px; }
.tl-insp-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: 0.8rem;
    color: var(--text);
}
.quad-input { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.quad-input input { width: 100%; }
.tl-export { margin-top: 14px; }
.tl-export .btn { width: 100%; justify-content: center; }

/* ============================================================
   ESCENARIOS DEL PANEL DERECHO
   ============================================================ */
/* Un escenario por pieza. Lo que se está editando se ve aquí, grande;
   la barra lateral se queda solo con los controles. */
/* Con un lienzo activo el panel se acota a la ventana: si no, un 9:16 crece
   más alto que la pantalla y hay que hacer scroll para ver lo que editas. */
.preview-panel.bounded .stage.active { height: 100%; }

.preview-panel .stage { display: none; }
.preview-panel .stage.active {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1 1 auto;
    /* Sin esto el escenario se encoge al contenido y el ancho disponible que
       mide fitActiveStageCanvas() depende del propio canvas: bucle. */
    width: 100%;
}
.stage-canvas {
    flex: 1 1 auto;
    display: grid;
    place-items: center;
    min-height: 0;
    width: 100%;
    padding: 20px;
}
.stage-canvas canvas {
    max-width: 100%;
    max-height: 100%;
    border-radius: 10px;
    box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.6);
    background: #000;
}
.stage-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 0 20px 16px;
}

/* El timeline ocupa la franja inferior del escenario, como un editor de video. */
/* En móvil el transporte no envuelve ni se corta: rueda de lado como las demás
   filas (16-responsive.js le pone .hrow, que es lo que trae el desvanecido). */
#stage-timeline .tl-transport {
    padding: 0 12px;
    margin-bottom: 10px;
    flex-wrap: nowrap;
    align-self: stretch;
}
#stage-timeline .tl-transport > * { flex: 0 0 auto; }
#stage-timeline .tl-tracks {
    flex: 0 0 auto;
    max-height: 34vh;
    margin: 0 12px 12px;
}
#stage-timeline .stage-canvas { padding: 16px 20px 10px; }

/* Colocación a mano del clip sobre el preview: cajas y asas encima del lienzo.
   El holder se ciñe al canvas para que el overlay cuadre al píxel. */
.tl-canvas-holder { position: relative; display: inline-block; line-height: 0; max-width: 100%; }
.tl-overlay { position: absolute; inset: 0; }
.tl-el-box {
    position: absolute;
    box-sizing: border-box;
    cursor: move;
    outline: 1px dashed rgba(255, 255, 255, 0.22);
}
.tl-el-box:hover { outline-color: rgba(52, 211, 153, 0.65); }
.tl-el-box.selected { outline: 2px solid #34d399; outline-offset: 2px; }
.tl-handle {
    position: absolute; width: 12px; height: 12px;
    background: #34d399; border: 2px solid #05060f; border-radius: 50%;
}
.tl-handle.nw { left: -6px; top: -6px; cursor: nwse-resize; }
.tl-handle.ne { right: -6px; top: -6px; cursor: nesw-resize; }
.tl-handle.sw { left: -6px; bottom: -6px; cursor: nesw-resize; }
.tl-handle.se { right: -6px; bottom: -6px; cursor: nwse-resize; }
.tl-guide { position: absolute; background: #f472b6; pointer-events: none; z-index: 5; }
.tl-guide.v { width: 1px; }
.tl-guide.h { height: 1px; }
#stage-timeline .tl-transport { flex: 0 0 auto; }


/* El tamaño en pantalla de los lienzos lo calcula fitActiveStageCanvas() en JS.
   Con CSS no basta: `max-height:100%` contra un contenedor de altura automática
   no acota nada, y el overlay del quiz tiene que cuadrar al píxel con el canvas. */
#stage-quiz .quiz-stage { width: 100%; height: 100%; align-items: center; margin: 0; }
#stage-quiz .quiz-canvas-holder { max-width: 100%; }


/* ---------- COLOCACIÓN LIBRE EN EL LIENZO ---------- */
/* Un bloque colocado a mano sale del flujo. La caja lleva left/top/width en %
   y, si es texto, un font-size en em: como toda la tipografía de la slide está
   en em, ese font-size es la escala del bloque entero. */
.slide .free-el { position: absolute; z-index: 2; }
/* Colocado a mano manda la caja: los anclajes de las clases pos-* se apagan. */
.slide .slide-mascot.free-el,
.slide .brand-mark.free-el { right: auto; bottom: auto; transform: none; }

.canvas-ov { position: absolute; inset: 0; z-index: 6; }
.canvas-ov .tl-el-box { touch-action: none; }
.tl-handle.w { left: -6px; top: 50%; margin-top: -6px; cursor: ew-resize; }
.tl-handle.e { right: -6px; top: 50%; margin-top: -6px; cursor: ew-resize; }

.canvas-sel { font-size: 0.72rem; color: var(--text-dim); padding: 0 4px; }
.block-item.sel { border-color: var(--accent); }
.free-row {
    display: flex; align-items: center; gap: 8px;
    font-size: 0.7rem; color: var(--text-mute); margin: 4px 0 6px;
}



/* ============================================================
   RESPONSIVE — base móvil arriba, escritorio aquí
   ============================================================ */
/* El editor se diseña para el móvil en las reglas de arriba y se ENSANCHA aquí.
   Antes había una sola media query que apilaba el escritorio: el lienzo caía al
   final de una página larguísima y la barra superior comía cuatro filas. */

/* --- El carrusel acotado a la ventana (móvil siempre; escritorio, nunca) --- */
.preview-panel.bounded #stage-post .canvas-wrap { flex: 1 1 auto; min-height: 0; }
.preview-panel.bounded #stage-post .slides-h { height: 100%; padding: 6px 0; }
.preview-panel.bounded #stage-post .slide-wrap { height: 100%; }
.preview-panel.bounded .canvas-actions,
.preview-panel.bounded .filmstrip { flex: 0 0 auto; }
/* El ancho de la slide lo topa --fit-w, que calcula fitPostSlides() con el hueco
   real. En CSS no basta: con `aspect-ratio` puesto, un `max-height` no encoge el
   ancho, deforma la caja. Es el mismo motivo por el que existe fitActiveStageCanvas. */
.slide-wrap > .slide { width: min(var(--slide-width), var(--fit-w, 100%)); }
/* Con el panel acotado la slide OCUPA el hueco, no solo se topa a él: en una
   tablet el ancho de "Tamaño en pantalla" dejaría media pantalla vacía. Lo que
   se conserva es la proporción, que es lo que ese control fija de verdad. */
.preview-panel.bounded .slide-wrap > .slide { width: var(--fit-w, 100%); }

/* Acciones de la slide: una fila que rueda, no cinco botones envueltos. Rueda de
   filo a filo (sale del padding del panel con margen negativo) y lleva el suyo,
   así el último botón no acaba pegado al borde de la pantalla. */
.canvas-actions {
    align-self: stretch;
    width: auto;
    margin-inline: calc(-1 * var(--stage-pad, 10px));
    padding-inline: 12px;
    flex-wrap: nowrap;
    justify-content: flex-start;
}
.canvas-actions > * { flex: 0 0 auto; }
.filmstrip {
    align-self: stretch;
    width: auto;
    margin-inline: calc(-1 * var(--stage-pad, 10px));
    padding: 4px 12px;
}
#slides-container.slides-h { scrollbar-width: none; }
#slides-container.slides-h::-webkit-scrollbar { height: 0; }

/* Teléfono tumbado: el alto manda. La tira de miniaturas se retira (el contador
   y el deslizamiento siguen navegando) para que el lienzo tenga sitio. */
@media (max-height: 560px) and (orientation: landscape) {
    .preview-panel.bounded .filmstrip { display: none; }
    .preview-panel { padding-top: 2px; gap: 4px; }
}

/* En pantalla estrecha las flechas se montaban sobre el texto de la slide.
   Se quitan: el gesto nativo es deslizar, y el contador dice dónde estás. */
.canvas-arrow { display: none; }

/* Indicador de guardado: en móvil es un punto, no una frase. */
.save-indicator {
    flex: 0 0 8px; width: 8px; height: 8px; min-width: 0;
    border-radius: 50%; background: var(--line); color: transparent;
    overflow: hidden; white-space: nowrap;
    transition: background 200ms var(--ease-out);
}
.save-indicator.saved { background: var(--accent); color: transparent; }

/* --- Escritorio: barra lateral + lienzo, como estaba --- */
@media (min-width: 900px) {
    .topbar {
        height: auto; min-height: 60px;
        flex-wrap: wrap; gap: 16px; padding: 12px 20px;
    }
    .brand { font-size: 1.1rem; }
    .topbar-actions { gap: 8px; flex-wrap: wrap; margin-left: auto; }
    .topbar-actions .sep { display: block; width: 1px; height: 22px; background: var(--line); margin: 0 2px; }
    .topbar-piece-actions { flex-wrap: wrap; }
    .topbar-piece-actions .btn:not(.primary) { display: inline-flex; }
    .topbar .btn { max-width: none; display: inline-flex; }
    .more-wrap { display: none; }
    #pieceActions .btn-txt,
    #canvasActions .btn-txt,
    .stage-actions .btn-txt,
    .tl-transport .btn-txt { display: inline; }
    #pieceActions .btn,
    #canvasActions .btn,
    .stage-actions .btn,
    .tl-transport .btn { min-width: 0; padding-inline: 16px; }
    #pieceActions .btn.tiny,
    #canvasActions .btn.tiny,
    .stage-actions .btn.tiny,
    .tl-transport .btn.tiny { padding-inline: 12px; }
    .save-indicator {
        flex: 0 0 auto; width: auto; height: auto; min-width: 60px;
        border-radius: 0; background: none; overflow: visible;
        font-size: 0.78rem; color: var(--text-mute);
    }
    .save-indicator.saved { background: none; color: var(--accent); }

    .layout {
        flex-direction: row;
        align-items: flex-start;
        gap: 22px;
        padding: 22px;
        max-width: 1500px;
    }

    /* La hoja vuelve a ser una barra lateral: ni fija, ni desplazada, ni con asa. */
    .editor-panel {
        position: sticky;
        top: 78px;
        left: auto; right: auto; bottom: auto;
        z-index: 1;
        flex: 0 0 400px;
        max-width: 400px;
        height: auto;
        max-height: calc(100vh - 100px);
        transform: none;
        border: 1px solid var(--line);
        border-radius: var(--radius);
        box-shadow: none;
    }
    .sheet-grip, .sheet-scrim { display: none; }

    .pieces {
        padding: 10px 12px 0;
        gap: 8px;
        justify-content: space-between;
        border-bottom: 1px solid var(--line);
        overflow: visible;
    }
    .piece-bar { gap: 0; }
    .piece-btn {
        min-height: 0;
        padding: 9px 9px;
        border: none;
        border-bottom: 2px solid transparent;
        border-radius: 0;
        background: transparent;
        color: var(--text-mute);
        font-size: 0.8rem;
        font-weight: 500;
    }
    .piece-btn:focus-visible { outline-offset: -2px; border-radius: 6px; }
    .piece-btn.active { background: transparent; color: var(--text); border-bottom-color: var(--accent); }
    .piece-btn.global {
        margin: 0 0 8px 0;
        padding: 6px 10px;
        border: 1px solid var(--line);
        border-radius: 999px;
        font-size: 0.76rem;
        box-shadow: none;
    }
    .piece-btn.global.active { color: var(--accent); border-color: var(--accent); }

    .tabs { flex-wrap: wrap; overflow: visible; padding: 6px; gap: 4px; }
    .tab-btn {
        flex: 1 1 auto;
        min-height: 0;
        padding: 9px 6px;
        background: transparent;
        border: none;
        border-radius: 8px;
    }
    .tab-btn:hover { background: var(--panel-2); color: var(--text); }
    .tab-btn.active { background: var(--panel-2); border-color: transparent; color: var(--accent); }
    .tab-panels { padding: 18px; }

    .preview-panel {
        position: sticky;
        top: 78px;
        align-self: stretch;
        height: auto;
        gap: 14px;
        padding: 0;
    }
    .preview-panel.bounded { height: calc(100vh - 108px); }

    .preview-panel { --stage-pad: 0px; }
    .canvas-actions { width: auto; flex-wrap: wrap; justify-content: center; overflow: visible; padding-inline: 0; }
    #stage-timeline .tl-transport { padding: 0 20px; flex-wrap: wrap; overflow: visible; }
    /* Con seis pistas, 26vh cortaba la última en cuanto aparecía la barra de
       scroll horizontal. */
    #stage-timeline .tl-tracks { max-height: 30vh; margin: 0 20px 16px; }
    :root { --tl-head-w: 110px; }
    .tl-row-name { font-size: 0.68rem; }
    .filmstrip { padding: 8px 4px; scrollbar-width: thin; }
    .filmstrip::-webkit-scrollbar { height: 7px; }
    #slides-container.slides-h { scrollbar-width: thin; }
    #slides-container.slides-h::-webkit-scrollbar { height: 8px; }
    .canvas-arrow { display: grid; }
}

/* --- Pantallas anchas: el panel puede respirar --- */
@media (min-width: 1400px) {
    .editor-panel { flex-basis: 440px; max-width: 440px; }
}

/* --- Dedo, no ratón: 44px de objetivo y sin zoom al enfocar --- */
/* También por ancho: a menos de 900px es un teléfono o una ventana del tamaño
   de uno, y ahí un objetivo grande nunca estorba. */
@media (pointer: coarse), (max-width: 899px) {
    .btn { min-height: 44px; padding: 11px 16px; }
    .btn.tiny { min-height: 40px; padding: 10px 14px; font-size: 0.82rem; }
    .btn.icon-btn { min-width: 44px; justify-content: center; }
    .piece-btn, .tab-btn { min-height: 44px; }
    /* Menos de 16px y iOS hace zoom al enfocar el campo, y ya no vuelve. */
    input[type="text"], input[type="number"], input[type="url"], textarea, select { font-size: 16px; min-height: 44px; }
    input[type="color"] { min-height: 40px; }
    .film-cell { padding: 4px; }
    .canvas-arrow { display: none; }
}

/* ============================================================
   CHASIS — PANTALLAS DE CUENTA (entrar, registro, contraseña)
   ============================================================
   The editor's stylesheet is also the chassis's, so these screens borrow its
   tokens instead of starting a second look. One column, one primary action,
   and the same 44px touch targets the mobile pass settled on. */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 20px calc(32px + var(--safe-b));
}
.auth-card {
    width: 100%;
    max-width: 380px;
    padding: 28px 26px 24px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: 0 32px 64px -32px rgba(0, 0, 0, 0.9);
}
.auth-brand {
    display: inline-block;
    margin-bottom: 22px;
    color: var(--text);
    font-weight: 800;
    font-size: 0.95rem;
    letter-spacing: -0.01em;
    text-decoration: none;
}
.auth-title { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.02em; }
.auth-sub { margin-top: 7px; font-size: 0.85rem; line-height: 1.45; color: var(--text-dim); }

.auth-form { margin-top: 20px; display: flex; flex-direction: column; gap: 14px; }
.auth-field { display: flex; flex-direction: column; gap: 6px; }
.auth-field label { font-size: 0.78rem; font-weight: 600; color: var(--text-dim); }
/* 16px so iOS does not zoom the page on focus, and 44px of target. */
.auth-field input { min-height: 44px; font-size: 16px; }
.auth-submit { justify-content: center; min-height: 46px; margin-top: 4px; font-size: 0.95rem; }

.auth-alt {
    margin-top: 18px;
    font-size: 0.82rem;
    color: var(--text-dim);
    text-align: center;
}
.auth-alt a { color: var(--accent); text-decoration: none; font-weight: 600; }
.auth-alt a:hover { text-decoration: underline; }
.auth-dot { margin: 0 6px; color: var(--text-mute); }

.auth-flash {
    margin-top: 16px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    font-size: 0.82rem;
    line-height: 1.4;
}
.auth-flash.is-alert { color: var(--danger); border-color: rgba(248, 113, 113, 0.35); background: rgba(248, 113, 113, 0.08); }
.auth-flash.is-notice { color: var(--accent); border-color: rgba(52, 211, 153, 0.35); background: rgba(52, 211, 153, 0.08); }

.auth-errors {
    margin: 0 0 2px;
    padding: 10px 12px 10px 28px;
    border: 1px solid rgba(248, 113, 113, 0.35);
    border-radius: 10px;
    background: rgba(248, 113, 113, 0.08);
    color: var(--danger);
    font-size: 0.82rem;
    line-height: 1.5;
}

/* La cuenta vive dentro de #topbarFixed, así que en pantalla estrecha se muda
   sola al menú "···" con Guardar / Abrir / Reset. `display: contents` quita de
   en medio el <form> de button_to para que el botón sea hijo directo de la
   barra (flex) y del menú (columna), sin una caja intermedia en ninguno. */
.topbar-account { display: contents; }

/* ============================================================
   CHASIS — MIS PROYECTOS
   ============================================================ */
/* Alpine pinta después de que el navegador ya haya mostrado el HTML, así que
   sin esto se ve un fogonazo del formulario "nuevo" abierto antes de cerrarse. */
[x-cloak] { display: none !important; }

.chassis { min-height: 100vh; display: flex; flex-direction: column; }
.chassis-bar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    height: var(--topbar-h);
    padding: 0 max(14px, env(safe-area-inset-left)) 0 max(14px, env(safe-area-inset-right));
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}
.chassis-brand { color: var(--text); font-weight: 800; font-size: 0.95rem; text-decoration: none; }
.chassis-bar-actions { display: flex; align-items: center; gap: 6px; }
/* button_to envuelve el botón en un <form>; sacarlo de la maquetación deja el
   botón como hijo directo del flex, igual que en la barra del editor. */
.chassis-inline { display: contents; }

.chassis-main {
    width: 100%; max-width: 640px;
    margin: 0 auto;
    padding: 26px 18px calc(40px + var(--safe-b));
}
.chassis-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.chassis-title { font-size: 1.4rem; font-weight: 800; letter-spacing: -0.02em; }

.chassis-new { display: flex; gap: 8px; margin-bottom: 18px; }
.chassis-new input { min-height: 44px; font-size: 16px; }
.chassis-new input[type="submit"] { width: auto; white-space: nowrap; }
.chassis-filter { min-height: 44px; font-size: 16px; margin-bottom: 12px; }
.chassis-empty { color: var(--text-dim); font-size: 0.88rem; line-height: 1.55; }

.project-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.project-row {
    display: flex; align-items: center; gap: 6px;
    padding: 4px 8px 4px 4px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    transition: border-color 140ms var(--ease-out);
}
.project-row:hover { border-color: #33405a; }
.project-open {
    flex: 1; min-width: 0;
    display: flex; flex-direction: column; gap: 3px;
    padding: 10px 12px;
    color: var(--text); text-decoration: none;
}
.project-name { font-weight: 600; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-meta { font-size: 0.74rem; color: var(--text-mute); }

@media (max-width: 560px) {
    .chassis-head { flex-direction: column; align-items: stretch; }
    .chassis-head .btn { justify-content: center; min-height: 44px; }
    .chassis-new { flex-direction: column; }
    .chassis-new input[type="submit"] { width: 100%; justify-content: center; min-height: 44px; }
}

/* ---------- CHASIS — AJUSTES ---------- */
.setting-form { display: flex; flex-direction: column; gap: 12px; }
.setting-form input, .setting-form select { min-height: 44px; font-size: 16px; }
.setting-form input[type="submit"] { width: auto; align-self: flex-start; }

.setting-block {
    padding: 18px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
}
.setting-title { font-size: 1rem; font-weight: 700; margin-bottom: 8px; }
.setting-help { font-size: 0.82rem; line-height: 1.55; color: var(--text-dim); margin-bottom: 14px; }
.setting-help code { font-size: 0.78rem; }
.token-row { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
/* El token se parte en varias líneas antes que salirse: es para copiarlo. */
.token {
    flex: 1; min-width: 0;
    padding: 10px 12px;
    background: var(--app-bg);
    border: 1px solid var(--line);
    border-radius: 9px;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 0.78rem;
    word-break: break-all;
}

/* ---------- ENTRAR CON GOOGLE ---------- */
.auth-google { display: contents; }
.google-btn {
    width: 100%;
    min-height: 46px;
    /* El mismo aire que .auth-form deja bajo el título: si no, el botón se pega
       al "Entrar" y parece parte del encabezado. */
    margin: 20px 0 16px;
    justify-content: center;
    background: var(--panel-2);
    border-color: var(--line);
    font-size: 0.95rem;
}
.google-g {
    display: inline-flex; align-items: center; justify-content: center;
    width: 20px; height: 20px; border-radius: 50%;
    background: #fff; color: #4285f4;
    font-weight: 800; font-size: 0.8rem; line-height: 1;
}
/* El separador: una raya a cada lado de la etiqueta, sin caja ni fondo. */
.auth-or {
    display: flex; align-items: center; gap: 10px;
    margin: 2px 0 4px;
    font-size: 0.74rem; color: var(--text-mute);
}
.auth-or::before, .auth-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- EL ASISTENTE ---------- */
/* Flota sobre el editor en vez de robarle sitio al lienzo: se abre, se usa y se
   cierra. En móvil ocupa el ancho entero, que es lo único que cabe. */
.assistant-panel {
    position: fixed;
    right: 16px; bottom: 16px;
    z-index: 80;
    display: flex; flex-direction: column;
    width: min(380px, calc(100vw - 32px));
    max-height: min(560px, calc(100vh - 96px));
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 32px 64px -24px rgba(0, 0, 0, 0.9);
    animation: menuIn 180ms var(--ease-out);
}
.assistant-panel[hidden] { display: none; }
.asst-head {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 10px 10px 10px 14px;
    border-bottom: 1px solid var(--line);
    font-weight: 700; font-size: 0.88rem;
}
.asst-messages {
    flex: 1; min-height: 0;
    overflow-y: auto;
    padding: 12px 14px;
    display: flex; flex-direction: column; gap: 10px;
}
.asst-msg { display: flex; flex-direction: column; gap: 3px; font-size: 0.84rem; line-height: 1.5; }
.asst-text { white-space: pre-wrap; }
.asst-user .asst-text {
    align-self: flex-end;
    max-width: 88%;
    padding: 8px 11px;
    background: var(--panel-2);
    border-radius: 12px 12px 3px 12px;
}
.asst-error .asst-text { color: var(--danger); }
/* Qué herramientas usó: se ve, pero no compite con la respuesta. */
.asst-tools { font-size: 0.68rem; color: var(--text-mute); }
.asst-empty { font-size: 0.8rem; line-height: 1.55; color: var(--text-dim); }
.asst-form { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px 12px; border-top: 1px solid var(--line); }
.asst-form textarea { font-size: 16px; }
.asst-form .btn { white-space: nowrap; min-height: 44px; }

@media (max-width: 560px) {
    .assistant-panel {
        right: 8px; left: 8px; bottom: 8px;
        width: auto;
        max-height: min(70vh, calc(100vh - 80px));
    }
}

/* ---------- AVISO EN VIVO ---------- */
/* Abajo a la izquierda: el asistente vive a la derecha y no se pisan. */
.live-banner {
    position: fixed;
    left: 16px; bottom: 16px;
    z-index: 85;
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    max-width: min(420px, calc(100vw - 32px));
    padding: 12px 14px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 24px 48px -24px rgba(0, 0, 0, 0.85);
    font-size: 0.84rem;
    animation: menuIn 180ms var(--ease-out);
}

/* --- Foco visible en todo lo que se puede enfocar --- */
:where(button, a, input, select, textarea, [tabindex]):focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* --- Menos movimiento: se reduce, no se apaga --- */
@media (prefers-reduced-motion: reduce) {
    .editor-panel { transition-duration: 1ms; }
    .tab-panel.active, .more-menu { animation: none; }
    .btn:active { transform: none; }
    .sheet-scrim { transition-duration: 1ms; }
    * { scroll-behavior: auto !important; }
}

/* ============================================================
   CHASIS — DOCUMENTOS LEGALES (privacidad, condiciones)
   ============================================================
   Same tokens as the account screens; only the measure changes. A form wants
   380px and a text wants around 70 characters, and forcing the text into the
   card's width would make it unreadable. */
.legal-shell {
    max-width: 720px;
    margin: 0 auto;
    padding: 40px 22px calc(56px + var(--safe-b));
}
.legal-title {
    margin-top: 8px;
    font-size: 1.7rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}
.legal-updated {
    margin-top: 6px;
    font-size: 0.8rem;
    color: var(--text-mute);
}
.legal-body {
    margin-top: 30px;
    font-size: 0.95rem;
    line-height: 1.65;
    color: var(--text-dim);
}
.legal-lead {
    padding-bottom: 22px;
    border-bottom: 1px solid var(--line);
    color: var(--text);
}
.legal-body h2 {
    margin-top: 34px;
    margin-bottom: 10px;
    font-size: 1.02rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text);
}
.legal-body p + p,
.legal-body ul + p { margin-top: 12px; }
.legal-body ul {
    margin: 12px 0 0;
    padding-left: 20px;
    list-style: disc;
}
.legal-body li + li { margin-top: 9px; }
.legal-body strong { color: var(--text); font-weight: 650; }
.legal-body code {
    padding: 1px 5px;
    border-radius: 5px;
    background: var(--panel-2);
    font-size: 0.87em;
}
.legal-foot {
    margin-top: 40px;
    padding-top: 22px;
    border-top: 1px solid var(--line);
}

/* An unfilled placeholder has to be impossible to miss: a policy that ships
   saying RELLENAR in grey body text is worse than one that shouts. */
.legal-todo {
    padding: 1px 6px;
    border-radius: 5px;
    background: var(--danger);
    color: #2a0b0b;
    font-weight: 700;
}

/* The account card is centred by the shell's flex, so the links underneath it
   need their own width to stay centred with it. */
.auth-legal { width: 100%; max-width: 380px; margin-top: 20px; font-size: 0.78rem; }
.auth-shell { flex-direction: column; }
