/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #334155 100%);
    color: #e2e8f0;
    min-height: 100vh;
}

/* Header */
header {
    text-align: center;
    padding: 3rem 2rem;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(99, 102, 241, 0.3);
}

header h1 {
    font-size: 2.5rem;
    background: linear-gradient(135deg, #818cf8 0%, #c084fc 50%, #f472b6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
    font-weight: 700;
}

header p {
    font-size: 1.1rem;
    color: #94a3b8;
}

/* Controls */
.controls {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 2rem;
}

#searchBar {
    width: 100%;
    padding: 1rem;
    font-size: 1rem;
    background: rgba(30, 41, 59, 0.8);
    border: 2px solid rgba(99, 102, 241, 0.3);
    border-radius: 12px;
    margin-bottom: 1rem;
    outline: none;
    color: #e2e8f0;
    transition: all 0.3s;
}

#searchBar:focus {
    border-color: #818cf8;
    background: rgba(30, 41, 59, 1);
    box-shadow: 0 0 20px rgba(129, 140, 248, 0.2);
}

#searchBar::placeholder {
    color: #64748b;
}

.filters {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 0.75rem 1.5rem;
    background: rgba(30, 41, 59, 0.8);
    border: 2px solid rgba(99, 102, 241, 0.3);
    border-radius: 12px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    color: #818cf8;
    transition: all 0.3s;
}

.filter-btn:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: #818cf8;
    transform: translateY(-2px);
}

.filter-btn.active {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    border-color: transparent;
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

/* Gallery Grid */
.gallery-grid {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 2rem 4rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
}

.gallery-item {
    background: rgba(30, 41, 59, 0.8);
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid rgba(99, 102, 241, 0.2);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    transition: all 0.3s;
    cursor: pointer;
}

.gallery-item:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 30px rgba(99, 102, 241, 0.3);
    border-color: rgba(129, 140, 248, 0.5);
}

.gallery-item.hidden {
    display: none;
}

.item-preview {
    width: 100%;
    height: 250px;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.item-preview canvas {
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.3s ease-in;
}

.item-preview.loaded canvas {
    opacity: 1;
}

/* Loading spinner */
.item-preview::before {
    content: '';
    position: absolute;
    width: 40px;
    height: 40px;
    border: 3px solid rgba(129, 140, 248, 0.2);
    border-top-color: #818cf8;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    opacity: 1;
    transition: opacity 0.3s ease-out;
}

.item-preview.loaded::before {
    opacity: 0;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.item-info {
    padding: 1.5rem;
}

.item-info h3 {
    font-size: 1.25rem;
    color: #f1f5f9;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.item-info p {
    font-size: 0.9rem;
    color: #94a3b8;
    margin-bottom: 1rem;
}

.item-tags {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.tag {
    padding: 0.25rem 0.75rem;
    background: rgba(99, 102, 241, 0.2);
    color: #a5b4fc;
    border-radius: 12px;
    font-size: 0.8rem;
    border: 1px solid rgba(99, 102, 241, 0.3);
    cursor: pointer;
    transition: all 0.3s;
    user-select: none;
}

.tag:hover {
    background: rgba(99, 102, 241, 0.3);
    border-color: #818cf8;
    transform: translateY(-1px);
}

.tag.active {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    border-color: transparent;
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

.clear-tags-btn {
    background: rgba(239, 68, 68, 0.2) !important;
    border-color: rgba(239, 68, 68, 0.3) !important;
    color: #fca5a5 !important;
}

.clear-tags-btn:hover {
    background: rgba(239, 68, 68, 0.3) !important;
    border-color: #ef4444 !important;
}

.item-actions {
    display: flex;
    gap: 0.5rem;
}

.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.3s;
}

.btn-primary {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    border: none;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: rgba(99, 102, 241, 0.2);
    color: #a5b4fc;
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.btn-secondary:hover {
    background: rgba(99, 102, 241, 0.3);
    border-color: #818cf8;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.8);
}

.modal.active {
    display: block;
}

.modal-content {
    background: rgba(30, 41, 59, 0.95);
    backdrop-filter: blur(20px);
    margin: 2% auto;
    padding: 2rem;
    border-radius: 16px;
    border: 1px solid rgba(99, 102, 241, 0.3);
    width: 90%;
    max-width: 1000px;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.close {
    color: #94a3b8;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 20px;
    transition: color 0.3s;
}

.close:hover,
.close:focus {
    color: #f1f5f9;
}

#previewCanvas {
    width: 100%;
    height: 600px;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border-radius: 12px;
    margin-top: 1rem;
    border: 1px solid rgba(99, 102, 241, 0.2);
}

#previewCanvas canvas {
    width: 100%;
    height: 100%;
    border-radius: 8px;
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.code-header h2 {
    color: #f1f5f9;
}

#copyCodeBtn {
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s;
}

#copyCodeBtn:hover {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
    transform: translateY(-2px);
}

pre {
    background: #1e1e1e;
    border-radius: 8px;
    padding: 1.5rem;
    overflow-x: auto;
    max-height: 500px;
}

code {
    color: #d4d4d4;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    line-height: 1.6;
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(10px);
    color: #94a3b8;
    border-top: 1px solid rgba(99, 102, 241, 0.3);
}

/* Responsive */
@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }

    .gallery-grid {
        grid-template-columns: 1fr;
    }

    .modal-content {
        width: 95%;
        padding: 1rem;
    }

    #previewCanvas {
        height: 400px;
    }
}
