.editor-tools-panel {
    width: 260px;
    min-width: 260px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1rem;
    overflow: visible;
    transition: width 0.75s cubic-bezier(0.16, 1, 0.3, 1),
                min-width 0.75s cubic-bezier(0.16, 1, 0.3, 1),
                opacity 0.6s ease,
                padding 0.5s ease;
    z-index: 100;
    height: 100%;
    position: relative;
    box-sizing: border-box;
}

.editor-tools-panel.is-empty {
    width: 130px;
    min-width: 130px;
    padding: 0.8rem;
    overflow: visible;
}

.editor-tools-panel.is-empty:hover,
.editor-tools-panel.is-fixed {
    width: 260px;
    min-width: 260px;
    padding: 1rem;
    box-shadow: -4px 0 15px rgba(0, 0, 0, 0.3);
}


.tools-close-btn:hover {
    color: var(--text);
}

.tools-add-elements {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.4rem;
    margin-bottom: 0.5rem;
}

.is-empty:not(:hover) .tools-add-elements {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.6rem;
}

.add-el-btn {
    background: transparent;
    border: none;
    color: var(--muted);
    border-radius: 4px;
    padding: 0.5rem 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.65rem;
    font-family: var(--font-body);
}

.add-el-btn:disabled,
.tool-btn:disabled {
    opacity: 0.3;
    filter: grayscale(1);
    cursor: not-allowed;
    background: transparent !important;
    pointer-events: none;
}

.add-el-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    transform: none;
    /* No jump */
}

.tools-divider {
    height: 1px;
    background: var(--border);
    margin: 0.8rem 0;
}

/* Dynamic Tools Container */
.dynamic-tools-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 2rem;
    padding-right: 8px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.empty-tools-state {
    color: var(--muted);
    font-size: 0.85rem;
    text-align: center;
    padding: 2rem 1rem;
}

.tool-section {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.tool-section-title {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: var(--muted);
}

.tool-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.tool-label {
    font-size: 0.9rem;
    color: var(--text);
    white-space: nowrap;
    transition: opacity 0.2s;
}

/* Hide everything below simple add buttons when collapsed to avoid floating bits */
.is-empty:not(:hover) .dynamic-tools-container,
.is-empty:not(:hover) .tools-divider {
    display: none;
}

/* Hide labels when the panel is collapsed to prevent layout breaks */
.is-empty:not(:hover) .tool-label,
.is-empty:not(:hover) .tool-section-title {
    opacity: 0;
    pointer-events: none;
    position: absolute;
    /* Take out of flow to prevent width push */
}

.is-empty:not(:hover) .tool-row {
    justify-content: center;
}

.tool-input {
    background: var(--surface2) !important;
    border: 1px solid var(--border) !important;
    color: var(--text) !important;
    padding: 0.4rem 0.6rem !important;
    border-radius: 4px !important;
    font-family: var(--font-body) !important;
    font-size: 0.9rem !important;
    outline: none !important;
    min-width: 40px;
    text-align: center;
}

.tool-input[type="number"] {
    width: 50px !important;
    -moz-appearance: textfield;
    appearance: textfield;
}

.tool-input[type="number"]::-webkit-outer-spin-button,
.tool-input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}

select.tool-input {
    width: 100% !important;
    text-align: left;
    padding-right: 1.5rem !important;
    /* Allow native dropdown popup to overflow the panel */
    position: relative;
    z-index: 200;
}

.color-picker-wrapper {
    position: relative;
    width: 34px;
    /* Slightly larger for the border */
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
    border-radius: 50%;
    background: var(--surface);
}

/* RGB Animated Border Glow */
.color-picker-wrapper::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.6);
    z-index: 0;
    filter: blur(2px);
    /* Softer edges */
    opacity: 0.6;
    /* More subtle */
    pointer-events: none;
    /* Crucial: clicks must pass through to the input */
}

/* Inner masking */
.color-picker-wrapper::after {
    content: '';
    position: absolute;
    inset: 1px;
    background: var(--surface);
    border-radius: 50%;
    z-index: 1;
    pointer-events: none;
    /* Crucial: clicks must pass through to the input */
}

.tool-input[type="color"] {
    position: absolute;
    right: 0;
    top: 0;
    width: 250px !important;
    /* Forces Chrome to open the popup far to the left */
    height: 34px !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    background: none !important;
    cursor: pointer;
    z-index: 10;
    -webkit-appearance: none;
    appearance: none;
    outline: none;
    /* Only allow clicks on the circle at the far right of this huge 250px box */
    clip-path: circle(17px at calc(100% - 17.5px) 17px) !important;
}

.tool-input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0 !important;
    background: none !important;
}

.tool-input[type="color"]::-webkit-color-swatch {
    border: none !important;
    border-radius: 16px !important;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15) !important;
}

.tool-input[type="color"]::-moz-color-swatch {
    border: none !important;
    border-radius: 16px !important;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15) !important;
}

.tool-input[type="text"] {
    width: 100% !important;
    text-align: left;
}

.tool-input:focus {
    border-color: var(--accent) !important;
}

.tool-btn-group {
    display: flex;
    background: var(--surface2);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border);
    width: 100%;
}

.tool-btn {
    flex: 1;
    background: transparent;
    border: none;
    border-right: 1px solid var(--border);
    color: var(--muted);
    padding: 0.4rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tool-btn:last-child {
    border-right: none;
}

.tool-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

.tool-btn.active {
    background: var(--surface2);
    color: var(--text);
}

.tool-slider-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tool-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    outline: none;
}

:root[data-theme="light"] .tool-slider {
    background: rgba(0, 0, 0, 0.15);
}

.tool-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--text);
    cursor: pointer;
}

/* Library Pickers */
.lib-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 8px;
    padding: 10px 12px 10px 4px; /* More right padding so icons aren't glued to scrollbar */
}

.lib-item {
    aspect-ratio: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--muted);
}

.lib-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent);
    color: var(--text);
    transform: translateY(-2px);
}

.shape-preview .card {
    pointer-events: none;
}

/* Categorized Libraries */
.lib-category {
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
}

.lib-category:last-child {
    border-bottom: none;
}

.lib-category-summary {
    padding: 10px 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}

.lib-category-summary::-webkit-details-marker {
    display: none;
}

.lib-category-summary::after {
    content: '❯';
    font-size: 0.7rem;
    transition: transform 0.2s ease;
    color: var(--muted);
}

.lib-category[open] .lib-category-summary::after {
    transform: rotate(90deg);
}

.lib-category .lib-grid {
    padding-top: 5px;
    padding-bottom: 15px;
}

