 :root {
            --bg-body: #1a1a1a;
            --bg-panel: #2c2c2c;
            --bg-panel-secondary: #232323;
            --bg-canvas: #e5e5e5;
            --text-main: #ffffff;
            --text-secondary: #b3b3b3;
            --text-muted: #888888;
            --accent: #7C60E0;
            --accent-hover: #6347D3;
            --accent-light: rgba(91, 58, 255, 0.15);
            --border: #3a3a3a;
            --border-light: #444444;
            --item-hover: #3a3a3a;
            --item-active: #1e3a5f;
            --danger: #f2483d;
            --danger-hover: #d63e34;
            --warning: #ffa629;
            --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
            --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
            --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
            --radius-sm: 6px;
            --radius-md: 8px;
            --radius-lg: 12px;
            --font-xs: 11px;
            --font-sm: 12px;
            --font-md: 13px;
            --font-lg: 14px;
            --transition-fast: 0.12s ease;
            --transition-smooth: 0.2s ease;
            --handle-size: 9px;
            --handle-border: 2px;
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            touch-action: manipulation; 
        }

        body {
            font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
            background-color: var(--bg-body);
            color: var(--text-main);
            height: 100vh;
            display: flex;
            flex-direction: column;
            overflow: hidden;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
            letter-spacing: -0.01em;
        }

 
.sprite-category-tabs {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 4px;
    padding-bottom: 4px;
    user-select: none; 
    -webkit-user-select: none;
    
    
    scrollbar-width: none; /* Firefox */
}
.sprite-category-tabs::-webkit-scrollbar {
    display: none; /* Для Chrome, Safari и Opera */
}

.sprite-category-tabs.expanded {
    flex-wrap: wrap !important;
    white-space: normal !important;
    max-height: 250px !important;    
    overflow-y: auto !important;     
    overflow-x: hidden !important;   
}

/* Курсор захвата при наведении (только когда табы свернуты в линию) */
.sprite-category-tabs:not(.expanded) {
    cursor: grab;
}

.sprite-category-tabs:not(.expanded):active {
    cursor: grabbing;
}

.sprite-category-btn {
    background: #1a1a1a;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 11px;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    flex-shrink: 0; 
}
.sprite-category-btn:hover {
    background: #2a2a2a;
    color: #fff;
}
.sprite-category-btn.active {
    background: rgba(127, 107, 206, 0.2);
    color: #fff;
    border-color: var(--accent);
}
        .sr-only {
            position: absolute;
            width: 1px;
            height: 1px;
            padding: 0;
            margin: -1px;
            overflow: hidden;
            clip: rect(0, 0, 0, 0);
            border: 0;
        }

   
        .toolbar {
            height: 50px;
            background-color: var(--bg-panel);
            border-bottom: 1px solid var(--border);
            display: flex;
            align-items: center;
            padding: 0 16px;
            gap: 8px;
            z-index: 100;
            box-shadow: var(--shadow-sm);
        }
        .sub-toolbar {
            height: 40px;
            background-color: var(--bg-panel-secondary);
            position: absolute;
            top: 50px;
            left: 0;
            width: 100%;
            z-index: 99;
        }
        .toolbar-divider {
            width: 1px;
            height: 24px;
            background: var(--border);
            margin: 0 4px;
            flex-shrink: 0;
        }
        .logo {
            font-weight: 700;
            font-size: 14px;
            color: #ffffff;
            margin-right: 8px;
            display: flex;
            align-items: center;
            gap: 8px;
            letter-spacing: -0.02em;
            flex-shrink: 0;
        }
        .logo:hover {
            opacity: 0.8;
        }
        .logo .logo-icon {
            width: 28px;
            height: 28px;
            background: var(--accent);
            border-radius: 6px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 16px;
        }
        .btn {
            background: transparent;
            color: var(--text-secondary);
            border: none;
            padding: 7px 10px;
            border-radius: var(--radius-sm);
            cursor: pointer;
            font-size: var(--font-sm);
            display: flex;
            align-items: center;
            gap: 6px;
            transition: all var(--transition-fast);
            white-space: nowrap;
            font-weight: 500;
            letter-spacing: -0.01em;
            position: relative;
            flex-shrink: 0;
        }
        .btn svg {
            width: 18px;
            height: 18px;
        }
        .btn:hover {
            background-color: var(--item-hover);
            color: #fff;
        }
        .btn:active {
            background-color: #444;
            transform: scale(0.97);
        }
        .btn.primary {
            background-color: var(--accent);
            color: #fff;
            font-weight: 600;
            padding: 8px 16px;
            border-radius: var(--radius-sm);
        }
        .btn.primary:hover {
            background-color: var(--accent-hover);
            box-shadow: 0 2px 8px rgba(91, 58, 255, 0.35);
        }
        .btn.active {
            background-color: var(--accent);
            color: #fff;
            box-shadow: 0 0 0 2px rgba(91, 58, 255, 0.3);
        }
        .btn.active:hover {
            background-color: var(--accent-hover);
        }
        .btn.danger {
            color: var(--danger);
        }
        .btn.danger:hover {
            background-color: rgba(242, 72, 61, 0.15);
            color: #ff6b63;
        }
        .btn-icon {
            padding: 6px 8px;
            min-width: 32px;
            justify-content: center;
            font-size: 16px;
        }
        
      
        .shape-popup {
            position: absolute;
            background: #2c2c2c;
            border: 1px solid var(--border);
            border-radius: var(--radius-md);
            box-shadow: var(--shadow-lg);
            padding: 6px;
            z-index: 200;
            display: none;
            flex-direction: column;
            gap: 4px;
            min-width: 140px;
        }
        .shape-popup .menu-item {
            padding: 6px 12px;
            cursor: pointer;
            font-size: 13px;
            color: var(--text-secondary);
            border-radius: 4px;
            transition: all var(--transition-fast);
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .shape-popup .menu-item:hover {
            background: var(--accent);
            color: #fff;
        }

     
        .popup-section-title {
            font-size: 11px;
            color: var(--text-muted);
            text-transform: uppercase;
            font-weight: 700;
            margin-bottom: 6px;
        }

     
        .sprite-style-item {
            padding: 6px 10px;
            background: #6C6565;
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 12px;
            transition: all var(--transition-fast);
        }
        .sprite-style-item:hover {
            border-color: #555;
            background: #544F4F;
        }
        .sprite-style-item.active {
            border-color: var(--accent);
            background: rgba(91, 58, 255, 0.1);
        }
        .sprite-style-name {
            font-size: var(--font-sm);
            color: var(--text-secondary);
            width: 10px;
            flex-shrink: 0;
            white-space: nowrap;
        }
        .sprite-style-preview {
            height: 74px;
        }


        .workspace {
            display: flex;
            flex: 1;
            height: calc(100vh - 50px);
            position: relative;
        }

    
        .sidebar {
            width: 260px;
            background-color: var(--bg-panel);
            display: flex;
            flex-direction: column;
            border-right: 1px solid var(--border);
            flex-shrink: 0;
            z-index: 10;
            overflow: hidden;
        }
        .sidebar.right {
            border-right: none;
            border-left: 1px solid var(--border);
            width: 280px;
        }
        .sidebar .sidebar-scroll {
            flex: 1;
            overflow-y: auto;
            overflow-x: hidden;
            scrollbar-width: thin;
            scrollbar-color: #555 #2c2c2c;
        }
        .sidebar .sidebar-scroll::-webkit-scrollbar {
            width: 5px;
        }
        .sidebar .sidebar-scroll::-webkit-scrollbar-track {
            background: transparent;
        }
        .sidebar .sidebar-scroll::-webkit-scrollbar-thumb {
            background: #555;
            border-radius: 10px;
        }
        
     
        .sidebar-tabs {
            display: flex;
            border-bottom: 1px solid var(--border);
            background: var(--bg-panel-secondary);
            flex-shrink: 0;
        }
        .sidebar-tab {
            flex: 1;
            background: transparent;
            color: var(--text-secondary);
            border: none;
            padding: 10px 0;
            font-size: 11px;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.04em;
            cursor: pointer;
            transition: all var(--transition-fast);
            border-bottom: 2px solid transparent;
            outline: none;
        }
        .sidebar-tab:hover {
            background: var(--item-hover);
            color: #fff;
        }
        .sidebar-tab.active {
            color: var(--accent);
            border-bottom-color: var(--accent);
            background: rgba(91, 58, 255, 0.05);
        }

 
        .preset-item {
            background: #1a1a1a;
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            cursor: pointer;
            overflow: hidden;
            transition: border-color var(--transition-fast);
            display: flex;
            flex-direction: column;
            min-height: 100px; 
        }
        .preset-item img, .preset-item video {
            width: 100%;
            height: 70px !important;
            min-height: 70px !important;
            flex-shrink: 0; 
            object-fit: contain;
            display: block;
            background: #222;
            border-bottom: 1px solid var(--border);
        }
        .preset-item-name {
            padding: 6px;
            font-size: 10px;
            text-align: center;
            color: var(--text-secondary);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            font-weight: 500;
            flex-shrink: 0; 
            display: flex;
            align-items: center;
            justify-content: center;
            min-height: 28px;
        }

        .panel-header {
            padding: 14px 16px 10px;
            font-size: var(--font-xs);
            font-weight: 700;
            text-transform: uppercase;
            color: var(--text-muted);
            border-bottom: 1px solid var(--border);
            letter-spacing: 0.04em;
            display: flex;
            align-items: center;
            justify-content: space-between;
            flex-shrink: 0;
        }
        .panel-header .count-badge {
            font-size: 10px;
            background: var(--border);
            padding: 2px 7px;
            border-radius: 10px;
            font-weight: 500;
            color: var(--text-secondary);
        }
        
        #text-popup-sprite-previews,
        #sprite-style-container {
            max-height: 190px; 
            overflow-y: auto;
            padding-right: 4px; 
            
          
            scrollbar-width: thin;
            scrollbar-color: #555 transparent;
        }

        #text-popup-sprite-previews::-webkit-scrollbar,
        #sprite-style-container::-webkit-scrollbar {
            width: 5px;
        }
        #text-popup-sprite-previews::-webkit-scrollbar-track,
        #sprite-style-container::-webkit-scrollbar-track {
            background: transparent;
        }
        #text-popup-sprite-previews::-webkit-scrollbar-thumb,
        #sprite-style-container::-webkit-scrollbar-thumb {
            background: #555;
            border-radius: 10px;
        }
        
        #layer-list {
            flex: 1;
            overflow-y: auto;
            scrollbar-width: thin;
            scrollbar-color: #555 transparent;
        }
        #layer-list::-webkit-scrollbar {
            width: 5px;
        }
        #layer-list::-webkit-scrollbar-track {
            background: transparent;
        }
        #layer-list::-webkit-scrollbar-thumb {
            background: #555;
            border-radius: 10px;
        }
        .layer-item {
            padding: 10px 12px;
            font-size: var(--font-md);
            cursor: pointer;
            border-bottom: 1px solid rgba(255, 255, 255, 0.04);
            display: flex;
            align-items: center;
            gap: 10px;
            transition: background var(--transition-fast), border var(--transition-fast), opacity var(--transition-fast);
            min-height: 40px;
            border-left: 3px solid transparent;
        }
        .layer-item[draggable="true"] {
            user-select: none;
            -webkit-user-select: none;
        }
        .layer-item.active {
            background: var(--accent-light);
            border-left-color: var(--accent);
        }
        .layer-item:hover {
            background: var(--item-hover);
        }
        .layer-item.active:hover {
            background: rgba(91, 58, 255, 0.2);
        }
        .layer-item .layer-thumb {
            width: 28px;
            height: 28px;
            border-radius: 4px;
            background: #1a1a1a;
            border: 1px solid var(--border);
            flex-shrink: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 14px;
            overflow: hidden;
        }
        .layer-item .layer-thumb canvas {
            width: 100%;
            height: 100%;
            object-fit: contain;
        }
        .layer-name {
            flex: 1;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            font-weight: 500;
            font-size: var(--font-sm);
        }
        .layer-actions {
            display: flex;
            gap: 2px;
            margin-left: auto;
            opacity: 0;
            transition: opacity var(--transition-fast);
        }
        .layer-item:hover .layer-actions {
            opacity: 1;
        }
        .layer-action-btn {
            background: none;
            border: none;
            color: var(--text-muted);
            cursor: pointer;
            font-size: 12px;
            width: 22px;
            height: 22px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 4px;
            transition: all var(--transition-fast);
            padding: 0;
        }
        .layer-action-btn:hover {
            background: var(--border);
            color: #fff;
        }
        .layer-action-btn.danger:hover {
            background: rgba(242, 72, 61, 0.25);
            color: var(--danger);
        }
        .layer-visibility {
            width: 18px;
            height: 18px;
            cursor: pointer;
            opacity: 0.6;
            font-size: 14px;
            flex-shrink: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: opacity var(--transition-fast);
        }
        .layer-visibility:hover {
            opacity: 1;
        }
      
        .layer-group-header {
            padding: 8px 12px;
            background: #1f1f1f;
            color: var(--text-secondary);
            font-size: 11px;
            font-weight: 700;
            text-transform: uppercase;
            border-bottom: 1px solid var(--border);
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: inset 0 1px 0 rgba(255,255,255,0.02);
        }
        .layer-group-header .ungroup-btn {
            background: none;
            border: none;
            color: var(--text-muted);
            cursor: pointer;
            font-size: 14px;
            padding: 0;
            transition: color 0.1s;
            display: flex;
            align-items: center;
        }
        .layer-group-header .ungroup-btn:hover {
            color: var(--danger);
        }


        .prop-section {
            padding: 14px 16px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.06);
        }
        .prop-section:last-child {
            border-bottom: none;
        }
        .prop-row {
            margin-bottom: 12px;
        }
        .prop-row:last-child {
            margin-bottom: 0;
        }
        .prop-label {
            font-size: var(--font-xs);
            color: var(--text-muted);
            margin-bottom: 6px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            letter-spacing: 0.02em;
        }
        .prop-label span {
            color: var(--text-secondary);
            font-weight: 500;
            font-variant-numeric: tabular-nums;
            font-family: 'SF Mono', 'JetBrains Mono', 'Consolas', monospace;
            font-size: 10px;
            background: #1a1a1a;
            padding: 2px 6px;
            border-radius: 3px;
        }
        .prop-header {
            font-size: var(--font-xs);
            color: var(--text-secondary);
            margin-bottom: 14px;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            display: flex;
            align-items: center;
            gap: 6px;
        }
        .prop-header::after {
            content: '';
            flex: 1;
            height: 1px;
            background: var(--border);
        }

        input[type="text"],
        input[type="number"],
        select,
        textarea {
            width: 100%;
            background: #1a1a1a;
            border: 1px solid var(--border);
            color: #fff;
            padding: 8px 10px;
            border-radius: var(--radius-sm);
            font-size: var(--font-sm);
            outline: none;
            font-family: inherit;
            transition: border-color var(--transition-fast);
        }
        input:focus,
        select:focus,
        textarea:focus {
            border-color: var(--accent);
            box-shadow: 0 0 0 3px rgba(91, 58, 255, 0.1);
        }
        input[type="range"] {
            width: 100%;
            accent-color: var(--accent);
            cursor: pointer;
            height: 4px;
            background: #333;
            border-radius: 2px;
            -webkit-appearance: none;
            appearance: none;
            outline: none;
            touch-action: none; 
        }
        input[type="range"]::-webkit-slider-thumb {
            -webkit-appearance: none;
            width: 14px;
            height: 14px;
            background: #fff;
            border-radius: 50%;
            cursor: pointer;
            border: 2px solid var(--accent);
            box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
        }
        textarea {
            resize: vertical;
            min-height: 40px;
            line-height: 1.4;
        }
        select {
            cursor: pointer;
            appearance: none;
            -webkit-appearance: none;
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' fill='none' stroke='%23999' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
            background-repeat: no-repeat;
            background-position: right 8px center;
            padding-right: 28px;
        }

 
        .checkbox-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 8px;
            margin-bottom: 12px;
            font-size: var(--font-sm);
            color: var(--text-main);
            cursor: pointer;
            flex-direction: row-reverse;
        }
        .checkbox-row input[type="checkbox"], input[type="checkbox"].toggle-switch {
            -webkit-appearance: none;
            appearance: none;
            width: 32px !important;
            height: 18px !important;
            background: #1a1a1a;
            border-radius: 9px;
            position: relative;
            cursor: pointer;
            outline: none;
            border: 1px solid var(--border) !important;
            transition: background 0.2s, border-color 0.2s;
            flex-shrink: 0;
            margin: 0 !important;
        }
        .checkbox-row input[type="checkbox"]::after, input[type="checkbox"].toggle-switch:checked::after {
            content: '';
            position: absolute;
            top: 1px;
            left: 1px;
            width: 14px;
            height: 14px;
            background: #888;
            border-radius: 50%;
            transition: transform 0.2s, background 0.2s;
            box-shadow: 0 1px 2px rgba(0,0,0,0.2);
        }
        .checkbox-row input[type="checkbox"]:checked, input[type="checkbox"].toggle-switch:checked {
            background: var(--accent);
            border-color: var(--accent) !important;
        }
        .checkbox-row input[type="checkbox"]:checked::after, input[type="checkbox"].toggle-switch:checked::after {
            transform: translateX(14px);
            background: #fff;
        }

        .file-upload-btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 100%;
            background: #1a1a1a;
            border: 1px dashed var(--border-light);
            color: var(--text-secondary);
            padding: 8px 10px;
            border-radius: var(--radius-sm);
            font-size: var(--font-sm);
            cursor: pointer;
            transition: all var(--transition-fast);
        }
        .file-upload-btn:hover {
            border-color: var(--accent);
            color: #fff;
        }

        .gradient-stop-row {
            display: flex;
            align-items: center;
            gap: 8px;
            margin-bottom: 8px;
            background: #1a1a1a;
            padding: 6px;
            border-radius: var(--radius-sm);
            border: 1px solid var(--border);
        }
        .gradient-stop-color {
            width: 24px !important;
            height: 24px !important;
            padding: 0 !important;
            border-radius: 4px;
            cursor: pointer;
        }
        .gradient-stop-offset {
            flex: 1;
            margin: 0 !important;
        }
        .gradient-stop-remove {
            background: none;
            border: none;
            color: var(--text-muted);
            cursor: pointer;
            font-size: 14px;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 0 4px;
        }
        .gradient-stop-remove:hover:not([disabled]) {
            color: var(--danger);
        }

        #color-map-container, #svg-color-map-container {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 6px;
            margin-top: 6px;
        }
        .color-map-item {
            background: #1a1a1a;
            padding: 6px 8px;
            border-radius: var(--radius-sm);
            display: flex;
            align-items: center;
            gap: 8px;
            border: 1px solid var(--border);
            transition: border-color var(--transition-fast);
        }
        .color-map-item:hover {
            border-color: #555;
        }
        .swatch-orig {
            width: 18px;
            height: 18px;
            border-radius: 4px;
            border: 2px solid #333;
            flex-shrink: 0;
        }
        input[type="color"] {
            background: none;
            border: none;
            width: 26px;
            height: 26px;
            cursor: pointer;
            padding: 0;
            border-radius: 4px;
            flex-shrink: 0;
        }
        input[type="color"]::-webkit-color-swatch-wrapper {
            padding: 0;
        }
        input[type="color"]::-webkit-color-swatch {
            border: 2px solid #444;
            border-radius: 4px;
        }

        /* Interactive Inline Spans */
        span[id^="val-"] {
            cursor: text;
            padding: 0 2px;
            border-radius: 2px;
            transition: background 0.1s;
        }
        span[id^="val-"]:hover {
            background: rgba(255,255,255,0.15);
        }

  
        .canvas-container {
            flex: 1;
            background: var(--bg-canvas);
            overflow: hidden; 
            background-image: radial-gradient(#c5c5c5 1px, transparent 1px);
            background-size: 20px 20px;
            position: relative;
            z-index: 1;
            touch-action: none; 
        }
        .canvas-wrapper {
            position: absolute;
            top: 0;
            left: 0;
            box-shadow: var(--shadow-lg);
            border-radius: 2px;
            overflow: hidden;
            transform-origin: 0 0; 
        }
        canvas#main-canvas {
            display: block;
            background: white;
            cursor: crosshair;
        }
        canvas#main-canvas.grabbing {
            cursor: grabbing;
        }
        canvas#main-canvas.bg-removing {
            cursor: crosshair;
        }
      
        #rulers-canvas {
            position: absolute;
            top: 0;
            left: 0;
            pointer-events: none;
            z-index: 90;
        }


        .context-menu {
            position: fixed;
            background: #2c2c2c;
            border: 1px solid var(--border);
            border-radius: var(--radius-md);
            box-shadow: var(--shadow-lg);
            z-index: 2000;
            min-width: 180px;
            padding: 6px 0;
            display: none;
            animation: fadeIn 0.1s ease;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: scale(0.95); }
            to { opacity: 1; transform: scale(1); }
        }
        .context-menu .menu-item {
            padding: 8px 14px;
            font-size: var(--font-sm);
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 10px;
            transition: background var(--transition-fast);
            color: var(--text-secondary);
            font-weight: 500;
        }
        .context-menu .menu-item:hover {
            background: var(--accent);
            color: #fff;
        }
        .context-menu .menu-item.danger:hover {
            background: var(--danger);
        }
        .context-menu .menu-separator {
            height: 1px;
            background: var(--border);
            margin: 4px 0;
        }
        .context-menu .menu-shortcut {
            margin-left: auto;
            color: var(--text-muted);
            font-size: 10px;
        }
        .context-menu .menu-item:hover .menu-shortcut {
            color: rgba(255, 255, 255, 0.7);
        }

    
        .toast {
            position: fixed;
            bottom: 24px;
            left: 50%;
            transform: translateX(-50%);
            background: #3a3a3a;
            color: #fff;
            padding: 10px 18px;
            border-radius: 20px;
            font-size: var(--font-sm);
            font-weight: 500;
            z-index: 3000;
            pointer-events: none;
            animation: toastIn 0.3s ease, toastOut 0.3s ease 1.5s forwards;
            box-shadow: var(--shadow-md);
        }
        @keyframes toastIn {
            from { opacity: 0; transform: translateX(-50%) translateY(10px); }
            to { opacity: 1; transform: translateX(-50%) translateY(0); }
        }
        @keyframes toastOut {
            from { opacity: 1; transform: translateX(-50%) translateY(0); }
            to { opacity: 0; transform: translateX(-50%) translateY(-10px); }
        }

       
        .bezier-point-row {
            display: flex;
            gap: 8px;
            align-items: center;
            margin-bottom: 8px;
        }
        .bezier-point-row label {
            font-size: 10px;
            color: var(--accent);
            width: 24px;
            font-weight: 700;
        }
        .bezier-point-row input {
            width: 56px;
            text-align: center;
            padding: 6px;
        }
        

        .timeline-btn {
            background: #333; color: #fff; border: 1px solid #444; border-radius: 4px; padding: 4px 8px; cursor: pointer; font-size: 11px; font-weight: bold;
        }
        .timeline-btn:hover { background: #444; }
        .timeline-btn.active { background: var(--accent); border-color: var(--accent); }
        .keyframe-point:hover { transform: scale(1.3) rotate(45deg) !important; }


        .media-block {
            box-sizing: border-box;
            overflow: hidden;
            white-space: nowrap;
            font-size: 10px;
            padding-left: 5px;
            line-height: 32px;
            color: #fff;
            user-select: none;
        }
        .trim-handle {
            position: absolute;
            top: 0;
            bottom: 0;
            width: 6px;
            background: rgba(255,255,255,0.4);
            cursor: ew-resize;
            z-index: 2;
        }
        .trim-handle:hover { background: #fff; }
        .trim-handle.left { left: 0; }
        .trim-handle.right { right: 0; }

       
        .modal-overlay {
            position: fixed; top: 0; left: 0; width: 100%; height: 100%;
            background: rgba(0,0,0,0.6); z-index: 5000;
            display: none; align-items: center; justify-content: center;
            backdrop-filter: blur(3px);
        }
        .modal-content {
            background: var(--bg-panel); border: 1px solid var(--border);
            border-radius: var(--radius-md); padding: 20px;
            min-width: 350px; max-width: 500px;
            box-shadow: var(--shadow-lg); color: var(--text-main);
        }
        .modal-header { font-size: 16px; font-weight: bold; margin-bottom: 15px; color: #fff; }
        .modal-body { margin-bottom: 20px; max-height: 400px; overflow-y: auto; }
        .modal-footer { display: flex; justify-content: flex-end; gap: 10px; }
        
        .project-list-item {
            padding: 10px; background: #1a1a1a; border: 1px solid var(--border);
            margin-bottom: 8px; border-radius: 6px; cursor: pointer;
            display: flex; justify-content: space-between; align-items: center;
        }
        .project-list-item:hover { border-color: var(--accent); }
        .project-list-item-title { font-size: 13px; font-weight: 500; }
        .project-list-item-date { font-size: 11px; color: var(--text-muted); }
        .project-list-delete { background: none; border: none; color: var(--danger); cursor: pointer; padding: 5px; }
        .project-list-delete:hover { background: rgba(242, 72, 61, 0.2); border-radius: 4px; }


        #text-popup {
            width: 280px;
            padding: 12px;
            cursor: default;
        }


        .behavior-item {
            background: #1a1a1a;
            border: 1px solid var(--border);
            padding: 8px;
            border-radius: var(--radius-sm);
            display: flex;
            flex-direction: column;
            gap: 6px;
        }
        .behavior-header {
            display: flex; justify-content: space-between; align-items: center;
            font-size: 11px; font-weight: bold; color: var(--accent);
        }
        .behavior-row {
            display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11px;
        }
        .behavior-row input[type="range"] {
            flex: 1;
        }



        .top-drawer-mobile { display: contents; }
        .drawer-handle { display: none; }
        .drawer-content { display: contents; }
        .mobile-bottom-island { display: none; }

        @media (max-width: 800px) {
         
            .mobile-overlay { display: none !important; }

            .logo .logo-text { display: none; } 
            
            .toolbar {
                overflow-x: auto;
                -webkit-overflow-scrolling: touch;
                flex-wrap: nowrap;
                justify-content: flex-start;
                padding: 0 8px;
            }
            .toolbar::-webkit-scrollbar { display: none; }

         
            .toolbar .mobile-toggle-btn { display: none !important; }
            .toolbar > .btn[id="btn-tool-animate"],
            .toolbar > .btn[id="btn-project-menu"],
            .toolbar > .btn[id="btn-export-menu"] { display: none !important; }


            .sidebar {
                position: fixed;
                top: auto !important;
                bottom: 0 !important;
                width: 100% !important;
                height: 60vh !important;
                border-radius: 16px 16px 0 0;
                transform: translateY(100%);
                transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
                box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
                z-index: 1010; 
                border-left: none;
                border-right: none;
                border-top: 1px solid var(--border);
            }
            .sidebar.left.mobile-open, 
            .sidebar.right.mobile-open { 
                transform: translateY(0); 
            }

 
            .mobile-bottom-island {
                display: flex; 
                position: fixed; 
                bottom: 20px; 
                left: 50%; 
                transform: translateX(-50%);
                background: rgba(44, 44, 44, 0.9); 
                backdrop-filter: blur(10px);
                padding: 8px 16px; 
                border-radius: 30px; 
                gap: 16px; 
                z-index: 2000;
                box-shadow: 0 8px 24px rgba(0,0,0,0.5); 
                border: 1px solid rgba(255,255,255,0.1);
            }
            .mobile-island-btn { 
                flex-direction: column; gap: 4px; font-size: 10px; color: #fff; 
                padding: 4px 10px;
            }
            .mobile-island-btn svg { width: 20px; height: 20px; }


            .top-drawer-mobile {
                position: fixed;
                top: 0px; 
                left: 50%;
                transform: translateX(-50%) translateY(-100%);
                background: var(--bg-panel);
                border-radius: 0 0 16px 16px;
                z-index: 2000;
                box-shadow: var(--shadow-lg);
                transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
                padding: 10px;
                display: flex; flex-direction: column; gap: 8px;
                border: 1px solid var(--border);
                border-top: none;
            }
            .top-drawer-mobile.open {
                transform: translateX(-50%) translateY(0);
            }
            .drawer-content {
                display: flex; flex-direction: row; gap: 8px; flex-wrap: wrap; justify-content: center;
            }
            .drawer-handle {
                z-index: 2000;
                display: flex; justify-content: center; align-items: flex-end;
                position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%);
                width: 60px; height: 20px;
                background: var(--bg-panel);
                border-radius: 0 0 12px 12px;
                cursor: pointer;
                box-shadow: 0 4px 6px rgba(0,0,0,0.3);
                border: 1px solid var(--border);
                border-top: none;
            }
            .drawer-handle span {
                display: block; width: 30px; height: 4px; background: #666; border-radius: 2px; margin-bottom: 6px;
            }

            .sub-toolbar {
                overflow-x: auto;
                -webkit-overflow-scrolling: touch;
            }
            .sub-toolbar::-webkit-scrollbar { display: none; }

            .shape-popup {
                position: fixed !important;
                top: 50px !important;
                left: 50% !important;
                right: auto !important;
                transform: translateX(-50%) !important;
                width: 90%;
                max-width: 350px;
            }
            .modal-content {
                min-width: 90%;
                max-width: 95%;
                margin: 0 auto;
            }
            
         
            #timeline-panel {
                height: 180px !important;
                position: fixed;
                bottom: 80px; 
                width: 100%;
                border-radius: 16px 16px 0 0;
                z-index: 1500;
                box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
            }
            #timeline-layers { width: 100px !important; }
            .timeline-btn span { display: none; } 
            .timeline-toolbar {
                overflow-x: auto;
                flex-wrap: nowrap;
                -webkit-overflow-scrolling: touch;
                font-size: 10px;
            }
            .timeline-toolbar::-webkit-scrollbar { display: none; }
        }

        /* ===== СПЕЦИАЛЬНЫЙ CSS ДЛЯ IOS ===== */
        @supports (-webkit-touch-callout: none) {
            .shape-popup, .context-menu {
                z-index: 9999 !important;
                transform: translateZ(0); 
                -webkit-transform: translateZ(0);
            }
            @media (max-width: 800px) {
                .top-drawer-mobile {
                    z-index: 999 !important;
                    transform: translateX(-50%) translateY(-120%);
                    -webkit-transform: translateX(-50%) translateY(-120%);
                }
                .top-drawer-mobile.open {
                    transform: translateX(-50%) translateY(0) !important;
                    -webkit-transform: translateX(-50%) translateY(0) !important;
                    padding-top: calc(10px + env(safe-area-inset-top));
                }
                .toolbar {
                    z-index: 5000;
                    overscroll-behavior-x: contain;
                }
                .mobile-bottom-island {
                    padding-bottom: calc(8px + env(safe-area-inset-bottom));
                }
                  .top-drawer-mobile {
                position: fixed;
                top: 50px; 
                left: 50%;
                transform: translateX(-50%) translateY(-100%);
                background: var(--bg-panel);
                border-radius: 0 0 16px 16px;
                z-index: 2000;
                box-shadow: var(--shadow-lg);
                transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
                padding: 10px;
                display: flex; flex-direction: column; gap: 8px;
                border: 1px solid var(--border);
                border-top: none;
            }
                .sidebar, #timeline-panel {
                    padding-bottom: env(safe-area-inset-bottom);
                }
            }
        }