/* ===================================================================
   Editor Layout — CSS Grid Shell
   Defines the structural layout for the editor chrome:
   toolbar (top), tool rail (left), canvas (center),
   sidebar (right), status bar (bottom).

   The grid activates only when .editor-shell--editing is set.
   Wedding content renders inside .editor-canvas untouched.
   =================================================================== */

/* ── Shell Container ──────────────────────────────────────────────── */

.editor-shell {
    position: fixed;
    inset: 0;
    z-index: var(--editor-z-toolbar, 10000);
    pointer-events: none;
    /* Grid only matters when editing; default is transparent overlay.
       Toolbar always visible (has pointer-events: auto) for edit toggle. */
}

.editor-shell--editing {
    display: grid;
    grid-template-areas:
        "toolbar  toolbar  toolbar"
        "toolrail canvas   sidebar"
        "status   status   status";
    grid-template-columns: var(--editor-toolrail-width) 1fr var(--editor-sidebar-width);
    grid-template-rows: var(--editor-toolbar-height) 1fr var(--editor-statusbar-height);
    pointer-events: auto;
}

/* Collapsed sidebar — canvas expands to fill */
.editor-shell--editing.editor-shell--sidebar-collapsed {
    grid-template-columns: var(--editor-toolrail-width) 1fr 0px;
}

/* Preview mode — hide all chrome, full canvas */
.editor-shell--editing.editor-shell--preview {
    display: block;
    pointer-events: none;
}

.editor-shell--preview .editor-toolbar,
.editor-shell--preview .editor-toolrail,
.editor-shell--preview .editor-sidebar,
.editor-shell--preview .editor-statusbar,
.editor-shell--preview .editor-float-panel {
    opacity: 0 !important;
    pointer-events: none !important;
    transition: opacity 0.2s ease;
}


/* ── Toolbar (Top Bar) ────────────────────────────────────────────── */

.editor-toolbar {
    grid-area: toolbar;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
    height: var(--editor-toolbar-height);
    background: var(--editor-bg-primary);
    border-bottom: 1px solid var(--editor-border);
    font-family: var(--font-body, 'Lato', sans-serif);
    font-size: 0.8rem;
    color: var(--editor-text-primary);
    /* position: relative required for z-index to work (static ignores z-index).
       Without this, the fixed .book-desk-scene paints over the toolbar. */
    position: relative;
    z-index: var(--editor-z-toolbar);
    overflow: hidden;
    pointer-events: auto; /* Always clickable — even when shell is not editing */
}

.editor-toolbar__brand {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.editor-toolbar__title {
    font-family: var(--font-heading, 'Playfair Display', serif);
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--editor-accent);
    white-space: nowrap;
    user-select: none;
}

.editor-toolbar__group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.editor-toolbar__spacer {
    flex: 1 1 auto;
    min-width: 8px;
}


/* ── Tool Rail (Left Icon Strip) ──────────────────────────────────── */

.editor-toolrail {
    grid-area: toolrail;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 8px 6px;
    width: var(--editor-toolrail-width);
    background: var(--editor-bg-primary);
    border-right: 1px solid var(--editor-border);
    z-index: var(--editor-z-toolrail);
    overflow-y: auto;
    overflow-x: hidden;
}

.editor-toolrail__section {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: 4px 0;
    width: 100%;
}

.editor-toolrail__divider {
    width: 28px;
    height: 1px;
    border: none;
    background: var(--editor-border-subtle);
    margin: 4px 0;
    flex-shrink: 0;
}

.editor-toolrail__spacer {
    flex: 1 1 auto;
    min-height: 8px;
}

/* Tool rail buttons — icon + text label side by side */
.editor-toolrail__btn {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    width: 100%;
    height: 32px;
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--editor-text-secondary);
    cursor: pointer;
    transition:
        background var(--editor-transition-fast),
        color var(--editor-transition-fast),
        border-color var(--editor-transition-fast);
    position: relative;
}

.editor-toolrail__btn:hover {
    background: var(--editor-bg-hover);
    color: var(--editor-text-primary);
}

.editor-toolrail__btn--active,
.editor-toolrail__btn[aria-pressed="true"] {
    background: var(--editor-accent-muted);
    color: var(--editor-accent);
    border-color: rgba(212, 184, 150, 0.2);
}

.editor-toolrail__btn:focus-visible {
    outline: 2px solid var(--editor-accent);
    outline-offset: -2px;
}

/* Icon sizing within tool rail buttons */
.editor-toolrail__btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* Tool rail text label — visible next to icon */
.editor-toolrail__btn-label {
    font-size: 0.6875rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    color: inherit;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1;
}


/* ── Canvas (Center Content Area) ─────────────────────────────────── */

.editor-canvas {
    grid-area: canvas;
    position: relative;
    overflow: visible; /* Critical: allows 3D transforms to extend beyond bounds */
    z-index: var(--editor-z-canvas);
    /* No background — wedding content shows through.
       pointer-events: none so clicks pass through to the book content underneath.
       Interactive children (effects, panels) re-enable pointer-events individually. */
    pointer-events: none;
    transition: transform 0.2s ease;
    transform-origin: center center;
}


/* ── Sidebar (Right Docked Panel) ─────────────────────────────────── */

.editor-sidebar {
    grid-area: sidebar;
    display: flex;
    flex-direction: column;
    width: var(--editor-sidebar-width);
    background: var(--editor-bg-primary);
    border-left: 1px solid var(--editor-border);
    z-index: var(--editor-z-sidebar);
    transition: width var(--editor-transition-panel), opacity var(--editor-transition-panel);
    overflow: hidden;
}

/* Collapsed state */
.editor-shell--sidebar-collapsed .editor-sidebar {
    width: 0;
    opacity: 0;
    border-left: none;
    pointer-events: none;
}

/* ── Sidebar Tab Bar ── */

.editor-sidebar__tabs {
    display: flex;
    align-items: stretch;
    height: 38px;
    border-bottom: 1px solid var(--editor-border);
    flex-shrink: 0;
    background: var(--editor-bg-secondary);
}

.editor-sidebar__tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0 8px;
    border: none;
    background: transparent;
    color: var(--editor-text-muted);
    font-family: var(--font-body, 'Lato', sans-serif);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
    position: relative;
    transition:
        color var(--editor-transition-fast),
        background var(--editor-transition-fast);
}

.editor-sidebar__tab:hover {
    color: var(--editor-text-secondary);
    background: var(--editor-bg-primary);
}

/* Active tab — gold underline indicator */
.editor-sidebar__tab[aria-selected="true"],
.editor-sidebar__tab--active {
    color: var(--editor-accent);
}

.editor-sidebar__tab[aria-selected="true"]::after,
.editor-sidebar__tab--active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 12px;
    right: 12px;
    height: 2px;
    background: var(--editor-accent);
    border-radius: 1px 1px 0 0;
}

.editor-sidebar__tab:focus-visible {
    outline: 2px solid var(--editor-accent);
    outline-offset: -2px;
}

/* Collapse toggle button at end of tab bar */
.editor-sidebar__collapse {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    flex-shrink: 0;
    border: none;
    border-left: 1px solid var(--editor-border-subtle);
    background: transparent;
    color: var(--editor-text-muted);
    cursor: pointer;
    transition:
        color var(--editor-transition-fast),
        background var(--editor-transition-fast);
}

.editor-sidebar__collapse:hover {
    color: var(--editor-text-primary);
    background: var(--editor-bg-hover);
}

.editor-sidebar__collapse svg {
    width: 14px;
    height: 14px;
    transition: transform var(--editor-transition);
}

.editor-shell--sidebar-collapsed .editor-sidebar__collapse svg {
    transform: rotate(180deg);
}

/* ── Sidebar Content ── */

.editor-sidebar__content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--editor-bg-hover) transparent;
}

.editor-sidebar__content::-webkit-scrollbar {
    width: 5px;
}

.editor-sidebar__content::-webkit-scrollbar-track {
    background: transparent;
}

.editor-sidebar__content::-webkit-scrollbar-thumb {
    background: var(--editor-bg-hover);
    border-radius: 3px;
}

.editor-sidebar__content::-webkit-scrollbar-thumb:hover {
    background: var(--editor-bg-active);
}

/* Tab panel visibility */
.editor-sidebar__panel {
    display: none;
}

.editor-sidebar__panel--active {
    display: block;
}


/* ── Status Bar (Bottom) ──────────────────────────────────────────── */

.editor-statusbar {
    grid-area: status;
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0 12px;
    height: var(--editor-statusbar-height);
    background: var(--editor-bg-secondary);
    border-top: 1px solid var(--editor-border);
    font-family: var(--font-body, 'Lato', sans-serif);
    font-size: 0.68rem;
    color: var(--editor-text-muted);
    z-index: var(--editor-z-statusbar);
    overflow: hidden;
    user-select: none;
}

.editor-statusbar__item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
    white-space: nowrap;
}

.editor-statusbar__item--accent {
    color: var(--editor-accent);
}

.editor-statusbar__separator {
    width: 1px;
    height: 14px;
    background: var(--editor-border-subtle);
    flex-shrink: 0;
}

.editor-statusbar__spacer {
    flex: 1 1 auto;
    min-width: 8px;
}

/* Unsaved changes indicator */
.editor-statusbar__unsaved {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--editor-warning);
    font-weight: 600;
}

.editor-statusbar__unsaved::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--editor-warning);
}

/* Snap toggle — active state highlight */
.editor-statusbar__toggle {
    border: 1px solid transparent;
    border-radius: 4px;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.editor-statusbar__toggle--active {
    background: var(--editor-accent-muted);
    color: var(--editor-accent);
    border-color: rgba(212, 184, 150, 0.25);
}

/* Snap grid size selector — inline dropdown */
.editor-statusbar__select {
    height: 20px;
    padding: 0 4px;
    font-family: inherit;
    font-size: 0.65rem;
    color: var(--editor-text-primary);
    background: var(--editor-bg-primary);
    border: 1px solid var(--editor-border-subtle);
    border-radius: 4px;
    cursor: pointer;
    outline: none;
}

.editor-statusbar__select:focus-visible {
    border-color: var(--editor-accent);
}


/* ── Floating Panels (Glass Morphism) ─────────────────────────────── */

.editor-float-panel {
    position: fixed;
    z-index: var(--editor-z-float);
    border-radius: var(--editor-panel-radius-lg);
    background: var(--editor-glass-bg);
    backdrop-filter: blur(var(--editor-glass-blur));
    -webkit-backdrop-filter: blur(var(--editor-glass-blur));
    border: 1px solid var(--editor-glass-border);
    box-shadow: var(--editor-glass-shadow);
    color: var(--editor-text-primary);
    font-family: var(--font-body, 'Lato', sans-serif);
    overflow: hidden;

    /* Entrance animation */
    animation: editor-float-in 0.2s ease-out;
}

@keyframes editor-float-in {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.editor-float-panel__header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--editor-glass-border);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--editor-text-primary);
    user-select: none;
}

.editor-float-panel__title {
    flex: 1;
}

.editor-float-panel__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--editor-text-muted);
    cursor: pointer;
    transition:
        background var(--editor-transition-fast),
        color var(--editor-transition-fast);
}

.editor-float-panel__close:hover {
    background: var(--editor-bg-hover);
    color: var(--editor-text-primary);
}

.editor-float-panel__body {
    padding: 12px 14px;
    overflow-y: auto;
    max-height: calc(100vh - var(--editor-toolbar-height) - var(--editor-statusbar-height) - 80px);
    scrollbar-width: thin;
    scrollbar-color: var(--editor-bg-hover) transparent;
}

.editor-float-panel__body::-webkit-scrollbar {
    width: 4px;
}

.editor-float-panel__body::-webkit-scrollbar-thumb {
    background: var(--editor-bg-hover);
    border-radius: 2px;
}

.editor-float-panel__footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid var(--editor-glass-border);
}

/* ── Floating panel position offsets ──
   Accounts for tool rail (left) and sidebar (right). */

.editor-float-panel--left {
    top: calc(var(--editor-toolbar-height) + 8px);
    left: calc(var(--editor-toolrail-width) + 8px);
}

.editor-float-panel--right {
    top: calc(var(--editor-toolbar-height) + 8px);
    right: calc(var(--editor-sidebar-width) + 8px);
}

.editor-shell--sidebar-collapsed .editor-float-panel--right {
    right: 8px;
}

.editor-float-panel--bottom {
    bottom: calc(var(--editor-statusbar-height) + 8px);
    left: calc(var(--editor-toolrail-width) + 8px);
    right: calc(var(--editor-sidebar-width) + 8px);
}

.editor-shell--sidebar-collapsed .editor-float-panel--bottom {
    right: 8px;
}

/* ── Floating panel width presets ── */

.editor-float-panel--sm { width: 280px; }
.editor-float-panel--md { width: 340px; }
.editor-float-panel--lg { width: 400px; }


/* ── Modal Overlay (Glass Morphism) ───────────────────────────────── */

.editor-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: var(--editor-z-modal);
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: editor-backdrop-in 0.15s ease-out;
}

@keyframes editor-backdrop-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.editor-modal {
    position: relative;
    z-index: calc(var(--editor-z-modal) + 1);
    border-radius: var(--editor-panel-radius-lg);
    background: var(--editor-glass-bg-heavy);
    backdrop-filter: blur(var(--editor-glass-blur));
    -webkit-backdrop-filter: blur(var(--editor-glass-blur));
    border: 1px solid var(--editor-glass-border);
    box-shadow: var(--editor-shadow-xl);
    color: var(--editor-text-primary);
    animation: editor-modal-in 0.2s ease-out;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

@keyframes editor-modal-in {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}


/* ── Preview Mode Badge ───────────────────────────────────────────── */

.editor-preview-badge {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--editor-z-tooltip);
    padding: 8px 16px;
    border-radius: 20px;
    background: var(--editor-glass-bg-heavy);
    backdrop-filter: blur(var(--editor-glass-blur));
    -webkit-backdrop-filter: blur(var(--editor-glass-blur));
    border: 1px solid var(--editor-glass-border);
    box-shadow: var(--editor-shadow-md);
    color: var(--editor-text-secondary);
    font-size: 0.75rem;
    font-family: var(--font-body, 'Lato', sans-serif);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.editor-shell--preview .editor-preview-badge {
    opacity: 1;
    pointer-events: auto;
}


/* ── Reduced Motion ───────────────────────────────────────────────── */

/* ── Context Menu ─────────────────────────────────────────────────── */

.editor-context-backdrop {
    position: fixed;
    inset: 0;
    z-index: var(--editor-z-context);
    background: transparent;
    cursor: default;
}

.editor-context-menu {
    position: fixed;
    z-index: calc(var(--editor-z-context) + 1);
    min-width: 180px;
    padding: 4px 0;
    background: var(--editor-glass-bg-heavy);
    backdrop-filter: blur(var(--editor-glass-blur));
    -webkit-backdrop-filter: blur(var(--editor-glass-blur));
    border: 1px solid var(--editor-glass-border);
    border-radius: var(--editor-panel-radius);
    box-shadow: var(--editor-shadow-lg);
    animation: editor-float-in 0.12s ease-out;
    overflow: hidden;
}

.editor-context-menu__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    width: 100%;
    padding: 6px 12px;
    border: none;
    background: transparent;
    color: var(--editor-text-primary);
    font-family: var(--font-body, 'Lato', sans-serif);
    font-size: 0.78rem;
    line-height: 1.4;
    cursor: pointer;
    user-select: none;
    transition: background var(--editor-transition-fast);
}

.editor-context-menu__item:hover {
    background: var(--editor-bg-hover);
}

.editor-context-menu__item:focus-visible {
    outline: 2px solid var(--editor-accent);
    outline-offset: -2px;
}

.editor-context-menu__item--danger {
    color: var(--editor-danger);
}

.editor-context-menu__item--danger:hover {
    background: var(--editor-danger-muted);
}

.editor-context-menu__item--disabled {
    opacity: 0.35;
    pointer-events: none;
    cursor: not-allowed;
}

.editor-context-menu__label {
    flex: 1;
    text-align: left;
    white-space: nowrap;
}

.editor-context-menu__separator {
    height: 1px;
    background: var(--editor-glass-border);
    margin: 4px 8px;
}


/* ── Command Palette (Ctrl+K) ────────────────────────────────────── */

.command-palette {
    position: relative;
    z-index: calc(var(--editor-z-modal) + 1);
    width: 480px;
    max-height: 420px;
    border-radius: var(--editor-panel-radius-lg);
    background: var(--editor-glass-bg-heavy);
    backdrop-filter: blur(var(--editor-glass-blur));
    -webkit-backdrop-filter: blur(var(--editor-glass-blur));
    border: 1px solid var(--editor-glass-border);
    box-shadow: var(--editor-shadow-xl);
    color: var(--editor-text-primary);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: editor-modal-in 0.15s ease-out;
    /* Position toward top third for quick access feel */
    margin-bottom: 15vh;
}

/* ── Search bar ── */

.command-palette__search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--editor-glass-border);
    flex-shrink: 0;
}

.command-palette__search-icon {
    flex-shrink: 0;
    color: var(--editor-text-muted);
}

.command-palette__input {
    flex: 1;
    min-width: 0;
    height: 28px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--editor-text-primary);
    font-family: var(--font-body, 'Lato', sans-serif);
    font-size: 0.88rem;
    line-height: 28px;
    outline: none;
    caret-color: var(--editor-accent);
}

.command-palette__input::placeholder {
    color: var(--editor-text-muted);
}

.command-palette__hint {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.68rem;
    color: var(--editor-text-muted);
}

/* ── Results list ── */

.command-palette__results {
    flex: 1;
    overflow-y: auto;
    max-height: 320px;
    padding: 4px 0;
}

.command-palette__empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--editor-text-muted);
    font-size: 0.78rem;
}

.command-palette__item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 14px;
    border: none;
    border-left: 2px solid transparent;
    background: transparent;
    color: var(--editor-text-primary);
    font-family: var(--font-body, 'Lato', sans-serif);
    font-size: 0.78rem;
    line-height: 1.4;
    cursor: pointer;
    user-select: none;
    text-align: left;
    transition:
        background var(--editor-transition-fast),
        border-color var(--editor-transition-fast);
}

.command-palette__item--selected {
    background: var(--editor-bg-hover);
    border-left-color: var(--editor-accent);
}

.command-palette__item:focus-visible {
    outline: 2px solid var(--editor-accent);
    outline-offset: -2px;
}

.command-palette__name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.command-palette__shortcut {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 3px;
    margin-left: auto;
}

.command-palette__kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 4px;
    background: var(--editor-bg-tertiary);
    border: 1px solid var(--editor-border);
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.62rem;
    color: var(--editor-text-muted);
    line-height: 1;
}

/* ── Footer ── */

.command-palette__footer {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    border-top: 1px solid var(--editor-glass-border);
    flex-shrink: 0;
}

.command-palette__footer-hint {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.65rem;
    color: var(--editor-text-muted);
}

.command-palette__kbd--sm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    padding: 0 3px;
    border-radius: 3px;
    background: var(--editor-bg-tertiary);
    border: 1px solid var(--editor-border);
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.55rem;
    color: var(--editor-text-muted);
    line-height: 1;
}

.command-palette__footer-count {
    margin-left: auto;
    font-size: 0.65rem;
    color: var(--editor-text-muted);
    font-variant-numeric: tabular-nums;
}

/* ── Responsive ── */

@media (max-width: 540px) {
    .command-palette {
        width: calc(100vw - 32px);
        margin-bottom: 0;
    }
}


/* ── Debug/Inspect Mode ───────────────────────────────────────────── */

[data-debug-mode] .visual-effect {
    outline: 1px dashed rgba(137, 180, 250, 0.5) !important;
    outline-offset: 1px;
}

[data-debug-mode] .visual-effect::after {
    content: attr(data-effect-id) " z:" attr(data-z-index);
    position: absolute;
    top: -16px;
    left: 0;
    padding: 1px 4px;
    background: rgba(30, 30, 46, 0.9);
    color: #89b4fa;
    font-size: 0.6rem;
    font-family: 'Consolas', monospace;
    border-radius: 2px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 10000;
}

/* Selected effects in debug mode get a brighter outline */
[data-debug-mode] .visual-effect--selected {
    outline-color: rgba(250, 179, 135, 0.8) !important;
}

[data-debug-mode] .visual-effect--selected::after {
    color: #fab387;
}


/* ── Testing Options Flyout Menu ─────────────────────────────────── */

.editor-toolrail__flyout-anchor {
    position: static; /* No stacking context — flyout escapes via fixed positioning */
}

.editor-testing-flyout {
    position: fixed;
    left: var(--editor-toolrail-width, 112px);
    bottom: var(--editor-statusbar-height, 28px);
    z-index: var(--editor-z-context, 10004);
    width: 220px;
    margin-left: 8px;
    background: var(--editor-glass-bg-heavy);
    backdrop-filter: blur(var(--editor-glass-blur));
    -webkit-backdrop-filter: blur(var(--editor-glass-blur));
    border: 1px solid var(--editor-glass-border);
    border-radius: 8px;
    box-shadow: var(--editor-glass-shadow);
    padding: 8px 0;
    pointer-events: auto;
    animation: editor-flyout-in 0.15s ease-out;
}

@keyframes editor-flyout-in {
    from { opacity: 0; transform: translateX(-6px); }
    to   { opacity: 1; transform: translateX(0); }
}

.editor-testing-flyout__header {
    padding: 4px 14px 8px;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--editor-text-muted);
}

.editor-testing-flyout__section {
    padding: 4px 10px;
}

.editor-testing-flyout__label {
    display: block;
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--editor-text-secondary);
    margin-bottom: 4px;
    padding: 0 4px;
}

.editor-testing-flyout__options {
    display: flex;
    gap: 2px;
    background: var(--editor-bg-deep);
    border-radius: 4px;
    padding: 2px;
}

.editor-testing-flyout__option {
    flex: 1;
    padding: 4px 6px;
    border: none;
    border-radius: 3px;
    background: transparent;
    color: var(--editor-text-secondary);
    font-size: 0.625rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: center;
}

.editor-testing-flyout__option:hover {
    background: var(--editor-bg-hover);
    color: var(--editor-text-primary);
}

.editor-testing-flyout__option--active {
    background: var(--editor-accent-muted);
    color: var(--editor-accent);
}

.editor-testing-flyout__color-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    padding: 0 4px;
}

.editor-testing-flyout__color-input {
    width: 28px;
    height: 22px;
    border: 1px solid var(--editor-border);
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
    padding: 0;
}

.editor-testing-flyout__color-input::-webkit-color-swatch-wrapper {
    padding: 1px;
}

.editor-testing-flyout__color-input::-webkit-color-swatch {
    border-radius: 2px;
    border: none;
}

.editor-testing-flyout__color-value {
    font-size: 0.625rem;
    font-family: 'Consolas', monospace;
    color: var(--editor-text-muted);
}

.editor-testing-flyout__divider {
    height: 1px;
    border: none;
    background: var(--editor-glass-border);
    margin: 4px 10px;
}

.editor-testing-flyout__toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 5px 6px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--editor-text-secondary);
    font-size: 0.6875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: left;
}

.editor-testing-flyout__toggle:hover {
    background: var(--editor-bg-hover);
    color: var(--editor-text-primary);
}

.editor-testing-flyout__toggle--active {
    color: var(--editor-accent);
}

.editor-testing-flyout__toggle-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.editor-testing-flyout__toggle-state {
    margin-left: auto;
    font-size: 0.5625rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    padding: 1px 5px;
    border-radius: 3px;
    background: var(--editor-bg-tertiary);
    color: var(--editor-text-muted);
}

.editor-testing-flyout__toggle--active .editor-testing-flyout__toggle-state {
    background: var(--editor-accent-muted);
    color: var(--editor-accent);
}

.editor-testing-flyout__hint {
    display: block;
    font-size: 0.5625rem;
    color: var(--editor-text-muted);
    padding: 2px 6px 0;
    line-height: 1.3;
}


/* ── Asset Library Panel ─────────────────────────────────────────── */

.asset-library__search {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--editor-glass-border);
}

.asset-library__search-icon {
    flex-shrink: 0;
    color: var(--editor-text-muted);
    width: 14px;
    height: 14px;
}

.asset-library__input {
    flex: 1;
    min-width: 0;
    height: 26px;
    padding: 0 6px;
    border: 1px solid var(--editor-border-subtle);
    border-radius: 4px;
    background: var(--editor-bg-deep, var(--editor-bg-secondary));
    color: var(--editor-text-primary);
    font-family: var(--font-body, 'Lato', sans-serif);
    font-size: 0.75rem;
    outline: none;
    caret-color: var(--editor-accent);
    transition: border-color var(--editor-transition-fast);
}

.asset-library__input:focus {
    border-color: var(--editor-accent);
}

.asset-library__input::placeholder {
    color: var(--editor-text-muted);
}

.asset-library__grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 8px;
}

.asset-library__card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px;
    border-radius: 6px;
    border: 1px solid var(--editor-border-subtle);
    cursor: pointer;
    transition:
        border-color var(--editor-transition-fast),
        background var(--editor-transition-fast);
}

.asset-library__card:hover {
    border-color: var(--editor-accent);
    background: var(--editor-accent-subtle, rgba(212, 184, 150, 0.08));
}

.asset-library__card:focus-visible {
    outline: 2px solid var(--editor-accent);
    outline-offset: -2px;
}

.asset-library__thumb {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 4px;
    background: var(--editor-bg-deep, var(--editor-bg-secondary));
}

.asset-library__name {
    font-size: 0.65rem;
    color: var(--editor-text-secondary);
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
}

.asset-library__size {
    font-size: 0.6rem;
    color: var(--editor-text-muted);
}

.asset-library__empty {
    grid-column: 1 / -1;
    padding: 24px 16px;
    text-align: center;
    color: var(--editor-text-muted);
    font-size: 0.78rem;
}

.asset-library__count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--editor-accent-muted, rgba(212, 184, 150, 0.15));
    color: var(--editor-accent);
    font-size: 0.62rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}


/* ── History Panel ────────────────────────────────────────────────── */

.history-panel__body {
    padding: 8px 0;
    max-height: 400px;
}

.history-panel__entry {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 14px;
    border: none;
    background: transparent;
    color: var(--editor-text-primary);
    font-family: var(--font-body, 'Lato', sans-serif);
    font-size: 0.78rem;
    line-height: 1.4;
    text-align: left;
    width: 100%;
    cursor: pointer;
    user-select: none;
    transition: background var(--editor-transition-fast);
    position: relative;
}

.history-panel__entry:hover {
    background: var(--editor-bg-hover);
}

.history-panel__entry:focus-visible {
    outline: 2px solid var(--editor-accent);
    outline-offset: -2px;
}

/* Current state marker — not clickable */
.history-panel__entry--current {
    cursor: default;
    padding-bottom: 10px;
}

.history-panel__entry--current:hover {
    background: transparent;
}

/* Redo entries — muted appearance */
.history-panel__entry--redo {
    opacity: 0.55;
}

.history-panel__entry--redo:hover {
    opacity: 0.85;
}

/* Timeline marker dots */
.history-panel__marker {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--editor-text-muted);
    flex-shrink: 0;
    margin-top: 4px;
    transition: background var(--editor-transition-fast);
}

.history-panel__marker--current {
    width: 10px;
    height: 10px;
    background: var(--editor-accent);
    box-shadow: 0 0 6px rgba(212, 175, 55, 0.4);
    margin-top: 3px;
}

.history-panel__marker--redo {
    background: var(--editor-bg-active);
    border: 1px solid var(--editor-text-muted);
}

.history-panel__entry:hover .history-panel__marker {
    background: var(--editor-accent);
}

.history-panel__entry--current:hover .history-panel__marker--current {
    background: var(--editor-accent);
}

/* Entry content */
.history-panel__entry-content {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
    flex: 1;
}

.history-panel__entry-label {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-panel__entry--current .history-panel__entry-label {
    color: var(--editor-accent);
    font-weight: 600;
}

.history-panel__entry-time {
    font-size: 0.65rem;
    color: var(--editor-text-muted);
    font-variant-numeric: tabular-nums;
}

/* Divider between undo and redo */
.history-panel__divider {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    user-select: none;
}

.history-panel__divider-line {
    flex: 1;
    height: 1px;
    background: var(--editor-glass-border);
}

.history-panel__divider-text {
    font-size: 0.62rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--editor-text-muted);
    flex-shrink: 0;
}

/* Empty state */
.history-panel__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 24px 16px;
    text-align: center;
    color: var(--editor-text-muted);
    font-size: 0.78rem;
}

.history-panel__empty-hint {
    font-size: 0.68rem;
    opacity: 0.7;
}

/* Footer */
.history-panel__footer {
    justify-content: center;
    gap: 4px;
    font-size: 0.68rem;
    color: var(--editor-text-muted);
}

.history-panel__footer-stat {
    font-variant-numeric: tabular-nums;
}

.history-panel__footer-separator {
    opacity: 0.4;
}


/* ── Effect Preview Thumbnails ───────────────────────────────────── */

.effect-preview {
    width: 40px;
    height: 40px;
    position: relative;
    overflow: hidden;
    border-radius: 6px;
    background: var(--editor-bg-deep, rgba(20, 20, 30, 0.5));
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.effect-preview__dot {
    position: absolute;
    border-radius: 50%;
    animation-iteration-count: infinite;
}

/* ── Butterfly: wing flap ── */

.effect-preview--butterfly {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1px;
}

.effect-preview__wing {
    width: 10px;
    height: 14px;
    border-radius: 50% 50% 50% 0;
    background: rgba(212, 175, 55, 0.7);
    animation: ep-wing-flap 0.6s ease-in-out infinite alternate;
    transform-origin: right center;
}

.effect-preview__wing--right {
    border-radius: 50% 50% 0 50%;
    transform-origin: left center;
    animation-direction: alternate-reverse;
}

@keyframes ep-wing-flap {
    0%   { transform: scaleX(1) rotateY(0deg); }
    100% { transform: scaleX(0.3) rotateY(60deg); }
}

/* ── Firefly: glow pulse ── */

.effect-preview--firefly .effect-preview__dot--glow {
    width: 6px;
    height: 6px;
    background: #e8d44d;
    box-shadow: 0 0 8px 3px rgba(232, 212, 77, 0.6);
    top: 12px;
    left: 10px;
    animation: ep-firefly-glow 1.8s ease-in-out infinite;
}

.effect-preview--firefly .effect-preview__dot--glow.effect-preview__dot--delayed {
    width: 4px;
    height: 4px;
    top: 22px;
    left: 24px;
    animation-delay: 0.9s;
    opacity: 0;
}

@keyframes ep-firefly-glow {
    0%, 100% { opacity: 0.15; transform: scale(0.6); }
    50%      { opacity: 1; transform: scale(1); }
}

/* ── Petal: float down ── */

.effect-preview__petal {
    position: absolute;
    width: 8px;
    height: 12px;
    background: rgba(219, 150, 167, 0.8);
    border-radius: 50% 0 50% 50%;
    top: -4px;
    left: 16px;
    animation: ep-petal-fall 2.5s ease-in-out infinite;
}

@keyframes ep-petal-fall {
    0%   { transform: translateY(0) rotate(0deg); opacity: 0; }
    10%  { opacity: 1; }
    90%  { opacity: 0.8; }
    100% { transform: translateY(40px) rotate(120deg); opacity: 0; }
}

/* ── Leaf: sway side to side ── */

.effect-preview__leaf {
    position: absolute;
    width: 12px;
    height: 8px;
    background: rgba(164, 180, 148, 0.85);
    border-radius: 0 50% 50% 0;
    top: 16px;
    left: 14px;
    animation: ep-leaf-sway 2s ease-in-out infinite;
}

@keyframes ep-leaf-sway {
    0%, 100% { transform: translateX(-6px) rotate(-15deg); }
    50%      { transform: translateX(6px) rotate(15deg); }
}

/* ── Sparkle: twinkle ── */

.effect-preview--sparkle .effect-preview__dot--sparkle {
    width: 5px;
    height: 5px;
    background: var(--color-gold, #D4AF37);
    top: 8px;
    left: 10px;
    animation: ep-sparkle-twinkle 1.2s ease-in-out infinite;
}

.effect-preview--sparkle .effect-preview__dot--sparkle.effect-preview__dot--delayed {
    width: 3px;
    height: 3px;
    top: 22px;
    left: 26px;
    animation-delay: 0.4s;
}

.effect-preview--sparkle .effect-preview__dot--sparkle.effect-preview__dot--delayed2 {
    width: 4px;
    height: 4px;
    top: 14px;
    left: 28px;
    animation-delay: 0.8s;
}

@keyframes ep-sparkle-twinkle {
    0%, 100% { transform: scale(0.3); opacity: 0.2; }
    50%      { transform: scale(1.2); opacity: 1; }
}

/* ── Star: rotate slowly ── */

.effect-preview__star {
    position: absolute;
    width: 14px;
    height: 14px;
    top: 13px;
    left: 13px;
    animation: ep-star-rotate 4s linear infinite;
}

.effect-preview__star::before,
.effect-preview__star::after {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--color-gold, #D4AF37);
    clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}

.effect-preview__star::after {
    opacity: 0.4;
    filter: blur(2px);
    transform: scale(1.3);
}

@keyframes ep-star-rotate {
    0%   { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ── Candle Flame: flicker ── */

.effect-preview__flame {
    position: absolute;
    width: 8px;
    height: 14px;
    background: linear-gradient(to top, #e8a630, #f0d060 40%, rgba(255, 200, 50, 0));
    border-radius: 50% 50% 20% 20%;
    bottom: 10px;
    left: 16px;
    animation: ep-flame-flicker 0.3s ease-in-out infinite alternate;
    filter: blur(0.5px);
}

.effect-preview__wick {
    position: absolute;
    width: 2px;
    height: 5px;
    background: rgba(100, 80, 60, 0.8);
    bottom: 6px;
    left: 19px;
    border-radius: 1px;
}

@keyframes ep-flame-flicker {
    0%   { transform: scaleY(1) scaleX(1) translateX(0); }
    33%  { transform: scaleY(1.15) scaleX(0.85) translateX(-1px); }
    66%  { transform: scaleY(0.9) scaleX(1.1) translateX(1px); }
    100% { transform: scaleY(1.05) scaleX(0.95) translateX(0); }
}

/* ── Bokeh Orb: slow float ── */

.effect-preview__orb {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(212, 175, 55, 0.6), rgba(212, 175, 55, 0.1));
    border: 1px solid rgba(212, 175, 55, 0.25);
    top: 8px;
    left: 8px;
    animation: ep-bokeh-float 3s ease-in-out infinite;
}

.effect-preview__orb--sm {
    width: 7px;
    height: 7px;
    top: 22px;
    left: 24px;
    animation-delay: 1.5s;
    opacity: 0.6;
}

@keyframes ep-bokeh-float {
    0%, 100% { transform: translateY(0); opacity: 0.4; }
    50%      { transform: translateY(-6px); opacity: 1; }
}

/* ── Mist / Steam: drift ── */

.effect-preview__wisp {
    position: absolute;
    width: 20px;
    height: 6px;
    background: rgba(200, 200, 210, 0.35);
    border-radius: 50%;
    top: 14px;
    left: 2px;
    filter: blur(2px);
    animation: ep-wisp-drift 3s ease-in-out infinite;
}

.effect-preview__wisp--delayed {
    width: 14px;
    height: 4px;
    top: 22px;
    animation-delay: 1.5s;
}

@keyframes ep-wisp-drift {
    0%   { transform: translateX(0); opacity: 0; }
    20%  { opacity: 0.5; }
    80%  { opacity: 0.3; }
    100% { transform: translateX(18px); opacity: 0; }
}

/* ── Dandelion Seed: float up ── */

.effect-preview__seed {
    position: absolute;
    width: 3px;
    height: 3px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    bottom: 4px;
    left: 18px;
    animation: ep-seed-float 3s ease-out infinite;
}

.effect-preview__seed::after {
    content: '';
    position: absolute;
    top: -6px;
    left: -2px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

@keyframes ep-seed-float {
    0%   { transform: translate(0, 0) rotate(0deg); opacity: 0; }
    10%  { opacity: 1; }
    80%  { opacity: 0.6; }
    100% { transform: translate(4px, -36px) rotate(90deg); opacity: 0; }
}

/* ── Feather: drift down ── */

.effect-preview__feather {
    position: absolute;
    width: 4px;
    height: 16px;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.7), rgba(200, 195, 180, 0.5));
    border-radius: 2px 8px 2px 8px;
    top: -2px;
    left: 18px;
    animation: ep-feather-drift 3s ease-in-out infinite;
}

@keyframes ep-feather-drift {
    0%   { transform: translateY(0) rotate(-20deg); opacity: 0; }
    10%  { opacity: 0.9; }
    50%  { transform: translateY(18px) rotate(25deg); opacity: 0.8; }
    100% { transform: translateY(40px) rotate(-10deg); opacity: 0; }
}

/* ── Music Note: bounce up ── */

.effect-preview__note {
    position: absolute;
    width: 6px;
    height: 6px;
    background: var(--editor-accent, #C9A86A);
    border-radius: 50%;
    bottom: 10px;
    left: 14px;
    animation: ep-note-bounce 2s ease-out infinite;
}

.effect-preview__note::before {
    content: '';
    position: absolute;
    width: 2px;
    height: 12px;
    background: var(--editor-accent, #C9A86A);
    right: -2px;
    bottom: 3px;
    border-radius: 1px;
}

.effect-preview__note::after {
    content: '';
    position: absolute;
    width: 6px;
    height: 3px;
    border-top: 2px solid var(--editor-accent, #C9A86A);
    right: -5px;
    bottom: 13px;
    border-radius: 0 2px 0 0;
}

@keyframes ep-note-bounce {
    0%   { transform: translateY(0) scale(0.8); opacity: 0; }
    15%  { opacity: 1; transform: scale(1); }
    70%  { opacity: 0.7; }
    100% { transform: translateY(-20px) scale(0.6); opacity: 0; }
}

/* ── Fairy Light: twinkling string ── */

.effect-preview--fairy .effect-preview__dot--fairy {
    width: 4px;
    height: 4px;
    background: #ffeaa7;
    box-shadow: 0 0 4px 1px rgba(255, 234, 167, 0.5);
    top: 12px;
    left: 6px;
    animation: ep-fairy-twinkle 1.5s ease-in-out infinite;
}

.effect-preview--fairy .effect-preview__dot--fairy.effect-preview__dot--delayed {
    top: 16px;
    left: 18px;
    animation-delay: 0.5s;
}

.effect-preview--fairy .effect-preview__dot--fairy.effect-preview__dot--delayed2 {
    top: 10px;
    left: 30px;
    animation-delay: 1s;
}

@keyframes ep-fairy-twinkle {
    0%, 100% { opacity: 0.3; transform: scale(0.7); }
    50%      { opacity: 1; transform: scale(1.3); box-shadow: 0 0 8px 3px rgba(255, 234, 167, 0.7); }
}

/* ── Ink Bleed: spread ── */

.effect-preview__ink {
    position: absolute;
    width: 8px;
    height: 8px;
    background: rgba(60, 50, 40, 0.7);
    border-radius: 50%;
    top: 16px;
    left: 16px;
    animation: ep-ink-spread 3s ease-out infinite;
}

@keyframes ep-ink-spread {
    0%   { transform: scale(0.3); opacity: 0; filter: blur(0); }
    20%  { opacity: 0.8; }
    100% { transform: scale(2.5); opacity: 0; filter: blur(3px); }
}

/* ── Dust Mote: drift ── */

.effect-preview--dust .effect-preview__dot--dust {
    width: 3px;
    height: 3px;
    background: rgba(200, 195, 180, 0.6);
    top: 10px;
    left: 8px;
    animation: ep-dust-drift 4s ease-in-out infinite;
}

.effect-preview--dust .effect-preview__dot--dust.effect-preview__dot--delayed {
    width: 2px;
    height: 2px;
    top: 20px;
    left: 22px;
    animation-delay: 2s;
}

@keyframes ep-dust-drift {
    0%   { transform: translate(0, 0); opacity: 0; }
    20%  { opacity: 0.6; }
    80%  { opacity: 0.3; }
    100% { transform: translate(12px, -8px); opacity: 0; }
}

/* ── Water Ripple: expanding rings ── */

.effect-preview__ring {
    position: absolute;
    width: 10px;
    height: 10px;
    border: 1px solid rgba(164, 180, 200, 0.6);
    border-radius: 50%;
    top: 15px;
    left: 15px;
    animation: ep-ripple-expand 2.5s ease-out infinite;
}

.effect-preview__ring--delayed {
    animation-delay: 0.8s;
}

@keyframes ep-ripple-expand {
    0%   { transform: scale(0.3); opacity: 0.8; }
    100% { transform: scale(2.5); opacity: 0; }
}

/* ── Botanical / Lily Pad: gentle sway ── */

.effect-preview__leaf--sway {
    position: absolute;
    width: 14px;
    height: 10px;
    background: rgba(61, 89, 65, 0.65);
    border-radius: 0 50% 50% 0;
    top: 15px;
    left: 13px;
    animation: ep-botanical-sway 3s ease-in-out infinite;
    transform-origin: left center;
}

@keyframes ep-botanical-sway {
    0%, 100% { transform: rotate(-8deg); }
    50%      { transform: rotate(8deg); }
}

/* ── Bird: glide ── */

.effect-preview__bird-body {
    position: absolute;
    width: 0;
    height: 0;
    top: 16px;
    left: 10px;
    animation: ep-bird-glide 3s ease-in-out infinite;
}

.effect-preview__bird-body::before,
.effect-preview__bird-body::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 3px;
    background: rgba(80, 70, 60, 0.7);
    border-radius: 50% 50% 0 0;
    top: 0;
}

.effect-preview__bird-body::before {
    left: -8px;
    transform-origin: right center;
    animation: ep-bird-wing 0.8s ease-in-out infinite alternate;
}

.effect-preview__bird-body::after {
    left: 0;
    transform-origin: left center;
    animation: ep-bird-wing 0.8s ease-in-out infinite alternate-reverse;
}

@keyframes ep-bird-glide {
    0%, 100% { transform: translate(0, 0); }
    50%      { transform: translate(12px, -4px); }
}

@keyframes ep-bird-wing {
    0%   { transform: rotate(-20deg); }
    100% { transform: rotate(20deg); }
}

/* ── Default: simple pulse ── */

.effect-preview--default .effect-preview__dot--pulse {
    width: 10px;
    height: 10px;
    background: var(--editor-text-muted, rgba(150, 150, 160, 0.5));
    top: 15px;
    left: 15px;
    animation: ep-default-pulse 2s ease-in-out infinite;
}

@keyframes ep-default-pulse {
    0%, 100% { transform: scale(0.7); opacity: 0.3; }
    50%      { transform: scale(1.2); opacity: 0.8; }
}


/* ── Minimap ──────────────────────────────────────────────────────── */

.editor-minimap {
    position: fixed;
    bottom: calc(var(--editor-statusbar-height) + 8px);
    right: calc(var(--editor-sidebar-width) + 8px);
    z-index: var(--editor-z-float);
    width: 160px;
    border-radius: var(--editor-panel-radius);
    background: var(--editor-glass-bg-heavy);
    backdrop-filter: blur(var(--editor-glass-blur));
    -webkit-backdrop-filter: blur(var(--editor-glass-blur));
    border: 1px solid var(--editor-glass-border);
    box-shadow: var(--editor-shadow-md);
    overflow: hidden;
    animation: editor-float-in 0.15s ease-out;
}

.editor-shell--sidebar-collapsed .editor-minimap {
    right: 8px;
}

.editor-minimap__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    border-bottom: 1px solid var(--editor-glass-border);
}

.editor-minimap__title {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--editor-text-secondary);
}

.editor-minimap__canvas {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4;
    background: var(--editor-bg-deep);
}

.editor-minimap__page {
    position: absolute;
    inset: 4px;
    border: 1px solid var(--editor-border-subtle);
    border-radius: 2px;
    background: rgba(250, 245, 240, 0.05);
}

.editor-minimap__dot {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--editor-info);
    border: 1px solid var(--editor-bg-deep);
    transform: translate(-50%, -50%);
    cursor: pointer;
    transition: transform var(--editor-transition-fast), box-shadow var(--editor-transition-fast);
}

.editor-minimap__dot:hover {
    transform: translate(-50%, -50%) scale(1.5);
    box-shadow: 0 0 4px var(--editor-info);
}

.editor-minimap__dot--selected {
    background: var(--editor-accent);
    box-shadow: 0 0 4px var(--editor-accent-glow);
}


/* ── Easing Curve Editor ─────────────────────────────────────────── */

.easing-editor__presets {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 12px;
}

.easing-editor__canvas-wrap {
    display: flex;
    justify-content: center;
    padding: 8px;
    margin-bottom: 12px;
    background: var(--editor-bg-deep);
    border: 1px solid var(--editor-border-subtle);
    border-radius: var(--editor-panel-radius);
}

.easing-editor__canvas {
    width: 200px;
    height: 200px;
    cursor: crosshair;
    touch-action: none;
    user-select: none;
}

.easing-editor__handle {
    cursor: grab;
    transition: r var(--editor-transition-fast);
}

.easing-editor__handle:hover {
    r: 10;
    filter: drop-shadow(0 0 4px var(--editor-accent-glow));
}

.easing-editor__value-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.easing-editor__value-input {
    flex: 1;
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.72rem;
    text-align: center;
    cursor: text;
    user-select: all;
}

.easing-editor__preview {
    display: flex;
    align-items: center;
    gap: 8px;
}

.easing-editor__preview-track {
    flex: 1;
    height: 6px;
    background: var(--editor-bg-tertiary);
    border-radius: 3px;
    position: relative;
    overflow: visible;
}

.easing-editor__preview-ball {
    position: absolute;
    top: 50%;
    left: 0;
    width: 10px;
    height: 10px;
    margin-top: -5px;
    margin-left: -5px;
    border-radius: 50%;
    background: var(--editor-accent);
    box-shadow: 0 0 6px var(--editor-accent-glow);
    animation: easing-editor-slide 2s infinite alternate;
}

@keyframes easing-editor-slide {
    0%   { left: 5px; }
    100% { left: calc(100% - 5px); }
}


/* ── CSS Animation Editor ────────────────────────────────────────── */

.css-anim-editor__textarea-wrap {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
}

.css-anim-editor__label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--editor-text-secondary);
}

.css-anim-editor__textarea {
    height: auto;
    min-height: 200px;
    max-height: 400px;
    padding: 10px 12px;
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.75rem;
    line-height: 1.6;
    tab-size: 2;
    resize: vertical;
    white-space: pre;
    overflow-wrap: normal;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--editor-bg-hover) transparent;
}

.css-anim-editor__textarea::placeholder {
    color: var(--editor-text-muted);
    opacity: 0.6;
}

.css-anim-editor__line-count {
    font-size: 0.65rem;
    color: var(--editor-text-muted);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.css-anim-editor__info {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 8px 10px;
    margin-bottom: 8px;
    border-radius: 6px;
    background: var(--editor-info-muted);
    color: var(--editor-info);
    font-size: 0.72rem;
    line-height: 1.5;
}

.css-anim-editor__info svg {
    flex-shrink: 0;
    margin-top: 1px;
}

.css-anim-editor__char-count {
    font-size: 0.65rem;
    color: var(--editor-text-muted);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.css-anim-editor__char-count--warn {
    color: var(--editor-warning);
}


/* ── Effect Animation Panel (Inline Timeline) ───────────────────── */

.effect-anim-panel {
    padding: 8px 0;
}

.effect-anim-panel--empty {
    padding: 12px 0;
    text-align: center;
}

.effect-anim-timeline {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 24px;
}

.effect-anim-timeline__track {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: var(--editor-bg-tertiary);
    position: relative;
    overflow: hidden;
}

.effect-anim-timeline__delay {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: var(--editor-bg-hover);
    border-radius: 3px 0 0 3px;
}

.effect-anim-timeline__duration {
    position: absolute;
    top: 0;
    height: 100%;
    background: var(--editor-accent);
    border-radius: 0 3px 3px 0;
}

.effect-anim-timeline__iter {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    min-width: 20px;
    color: var(--editor-text-secondary);
}

.effect-anim-timeline__iter svg {
    color: var(--editor-accent);
}

.effect-anim-timeline__iter-count {
    font-size: 0.68rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--editor-text-secondary);
}

.effect-anim-timeline__info-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 4px;
}

.effect-anim-timeline__info {
    font-size: 0.65rem;
    color: var(--editor-text-muted);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.effect-anim-timeline__speed {
    font-size: 0.6rem;
    padding: 1px 6px;
}


/* ── Sidebar Transform Tab Component Styles ──────────────────────── */

.sidebar-transform-tab__unit-toggle {
    display: flex;
    gap: 2px;
    background: var(--editor-bg-deep);
    border-radius: 6px;
    padding: 2px;
}

.sidebar-transform-tab__unit-toggle .editor-btn {
    min-width: 36px;
    height: 24px;
    padding: 0 8px;
    font-size: 0.72rem;
    border-radius: 4px;
}

.sidebar-transform-tab__unit-toggle .editor-btn--active {
    background: var(--editor-accent-muted);
    color: var(--editor-accent);
    border-color: rgba(212, 184, 150, 0.3);
}

.sidebar-transform-tab__padding-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.sidebar-transform-tab__padding-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.sidebar-transform-tab__padding-field label {
    font-size: 0.68rem;
    color: var(--editor-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.sidebar-transform-tab__actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 0 4px;
}

.sidebar-transform-tab__error {
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    background: var(--editor-danger-muted);
    color: var(--editor-danger);
    font-size: 0.75rem;
}


/* ===================================================================
   Responsive — Tablet (max-width: 992px)
   Auto-collapse sidebar. Tool rail stays visible.
   Canvas expands to fill the sidebar gap.
   =================================================================== */

@media (max-width: 992px) {
    /* Force sidebar column to 0 — --editor-sidebar-width is overridden to 0px in editor-theme.css */
    .editor-shell--editing {
        grid-template-columns: var(--editor-toolrail-width) 1fr var(--editor-sidebar-width);
    }

    /* Hide sidebar visually */
    .editor-sidebar {
        width: 0;
        opacity: 0;
        border-left: none;
        pointer-events: none;
        overflow: hidden;
    }

    /* Floating panels reposition to viewport edge */
    .editor-float-panel--right {
        right: 8px;
    }

    .editor-float-panel--bottom {
        right: 8px;
    }

    .editor-minimap {
        right: 8px;
    }

    /* Page selector narrower */
    .editor-toolbar .editor-select {
        max-width: 140px;
    }
}


/* ===================================================================
   Responsive — Mobile (max-width: 768px)
   Tool rail converts to bottom horizontal strip.
   Toolbar wraps to 2 rows. Status bar hidden.
   Floating panels become full-width bottom sheets.
   =================================================================== */

@media (max-width: 768px) {
    /* Restructure grid: remove sidebar, tool rail to bottom */
    .editor-shell--editing {
        grid-template-areas:
            "toolbar  toolbar"
            "canvas   canvas"
            "toolrail toolrail";
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto 1fr auto;
    }

    /* Collapsed sidebar variant also uses mobile layout */
    .editor-shell--editing.editor-shell--sidebar-collapsed {
        grid-template-columns: 1fr 1fr;
    }

    /* ── Toolbar becomes flex-wrap ── */
    .editor-toolbar {
        height: auto;
        min-height: 44px;
        flex-wrap: wrap;
        gap: 4px;
        padding: 6px 8px;
    }

    /* Hide text labels on toolbar buttons — icon-only */
    .editor-toolbar .editor-btn > span {
        display: none;
    }

    /* Keep the brand title visible */
    .editor-toolbar__title {
        display: inline;
    }

    /* Narrower page selector */
    .editor-toolbar .editor-select {
        max-width: 120px;
        font-size: 0.72rem;
    }

    /* Hide vertical dividers */
    .editor-toolbar .editor-divider--vertical {
        display: none;
    }

    /* Toolbar spacer shrinks */
    .editor-toolbar__spacer {
        flex: 0 0 0px;
        min-width: 0;
    }

    /* ── Tool Rail becomes horizontal bottom bar ── */
    .editor-toolrail {
        flex-direction: row;
        width: 100%;
        height: auto;
        min-height: 48px;
        padding: 4px 8px;
        border-right: none;
        border-top: 1px solid var(--editor-border);
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .editor-toolrail__section {
        flex-direction: row;
        gap: 4px;
        padding: 0 4px;
    }

    .editor-toolrail__divider {
        width: 1px;
        height: 28px;
        margin: 0 4px;
    }

    .editor-toolrail__spacer {
        flex: 0;
        min-height: 0;
        min-width: 0;
    }

    /* Touch-friendly tool rail buttons — revert to icon-only square on mobile */
    .editor-toolrail__btn {
        width: 44px;
        height: 44px;
        flex-shrink: 0;
        justify-content: center;
        padding: 0;
    }

    /* Hide text labels on mobile — icon-only with tooltips */
    .editor-toolrail__btn-label {
        display: none;
    }

    /* ── Status bar: hidden on mobile ── */
    .editor-statusbar {
        display: none;
    }

    /* ── Canvas fills available space ── */
    .editor-canvas {
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* ── Floating panels become bottom sheets ── */
    .editor-float-panel {
        position: fixed;
        top: auto !important;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100% !important;
        max-width: 100%;
        max-height: 65vh;
        border-radius: var(--editor-panel-radius-lg) var(--editor-panel-radius-lg) 0 0;
        animation: editor-sheet-up 0.25s ease-out;
    }

    .editor-float-panel--left,
    .editor-float-panel--right,
    .editor-float-panel--bottom {
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
    }

    /* All floating panel widths become full */
    .editor-float-panel--sm,
    .editor-float-panel--md,
    .editor-float-panel--lg {
        width: 100%;
    }

    /* Minimap becomes bottom-positioned */
    .editor-minimap {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 40vh;
        border-radius: var(--editor-panel-radius-lg) var(--editor-panel-radius-lg) 0 0;
    }

    /* Command palette: full width */
    .command-palette {
        width: calc(100vw - 16px);
        margin-bottom: 0;
    }

    /* Context menu: constrain to viewport */
    .editor-context-menu {
        max-width: calc(100vw - 16px);
    }

    /* Modals adapt to mobile */
    .editor-modal {
        width: calc(100vw - 24px);
        max-height: 80vh;
    }
}

/* Bottom sheet slide-up animation */
@keyframes editor-sheet-up {
    from {
        opacity: 0;
        transform: translateY(100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* ===================================================================
   Responsive — Small Mobile (max-width: 375px)
   Minimal chrome. Larger touch targets. Only essentials visible.
   =================================================================== */

@media (max-width: 375px) {
    .editor-toolbar {
        padding: 4px 6px;
        gap: 2px;
    }

    /* Hide the brand title */
    .editor-toolbar__title {
        display: none;
    }

    /* Hide viewport selector on very small screens */
    .viewport-selector {
        display: none;
    }

    /* Compact page selector */
    .editor-toolbar .editor-select {
        max-width: 100px;
        font-size: 0.68rem;
    }

    /* Floating panels: more height on small screens */
    .editor-float-panel {
        max-height: 75vh;
    }

    /* Tool rail: compact */
    .editor-toolrail {
        padding: 2px 4px;
        gap: 2px;
    }

    /* Maintain 44px touch target */
    .editor-toolrail__btn {
        width: 44px;
        height: 44px;
    }

    /* Prevent iOS zoom on input focus */
    .editor-input,
    .editor-select {
        min-height: 44px;
        font-size: 16px;
    }

    /* Touch-friendly interactive elements */
    .history-panel__entry {
        padding: 12px 14px;
        min-height: 44px;
    }

    .editor-context-menu__item {
        padding: 10px 12px;
        min-height: 44px;
    }

    .command-palette__item {
        padding: 12px 14px;
        min-height: 44px;
    }
}


/* ===================================================================
   Responsive — Landscape Mobile
   Reduce floating panel heights when vertical space is limited.
   =================================================================== */

@media (max-width: 768px) and (orientation: landscape) {
    .editor-float-panel {
        max-height: 50vh;
    }

    .editor-toolrail {
        min-height: 40px;
    }

    .editor-toolrail__btn {
        width: 40px;
        height: 40px;
    }
}


/* ── Reduced Motion ───────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .editor-float-panel,
    .editor-modal,
    .editor-modal-backdrop,
    .editor-sidebar,
    .editor-context-menu,
    .command-palette,
    .editor-shell--preview .editor-toolbar,
    .editor-shell--preview .editor-toolrail,
    .editor-shell--preview .editor-sidebar,
    .editor-shell--preview .editor-statusbar {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }

    /* Disable easing preview animation for reduced motion */
    .easing-editor__preview-ball {
        animation: none !important;
    }

    /* Disable effect preview animations for reduced motion */
    .effect-preview *,
    .effect-preview__dot,
    .effect-preview__wing,
    .effect-preview__petal,
    .effect-preview__leaf,
    .effect-preview__star,
    .effect-preview__flame,
    .effect-preview__orb,
    .effect-preview__wisp,
    .effect-preview__seed,
    .effect-preview__feather,
    .effect-preview__note,
    .effect-preview__ink,
    .effect-preview__ring,
    .effect-preview__bird-body,
    .effect-preview__bird-body::before,
    .effect-preview__bird-body::after {
        animation: none !important;
    }
}
