body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #0a0a0a;
    color: #e0e0e0;
    line-height: 1.6;
}

header {
    background-color: #0f0f0f;
    padding: 25px 20px;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(8px);
    background-color: rgba(15, 15, 15, 0.8);
}

header h1 {
    margin: 0;
    color: #f5f5f5;
    font-weight: 300;
    letter-spacing: 1px;
    font-size: 2.2em;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

.texture-category {
    background-color: rgba(20, 20, 20, 0.6);
    margin-bottom: 12px;
    border-radius: 4px;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(4px);
    border-left: 3px solid transparent;
}

.texture-category:hover {
    background-color: rgba(30, 30, 30, 0.8);
    border-left-color: #444;
}

.category-header {
    padding: 20px 24px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #f0f0f0;
    font-size: 1.2em;
    font-weight: 400;
    transition: all 0.3s ease;
    position: relative;
}

.category-header:hover {
    background-color: rgba(40, 40, 40, 0.4);
}

.category-header h2 {
    margin: 0;
    font-weight: 400;
    font-size: 1.1em;
    letter-spacing: 0.5px;
}

.category-header .arrow {
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0.6;
    font-size: 0.9em;
    margin-left: 12px;
    display: inline-block;
    transform-origin: center center;
    will-change: transform;
}

.category-header.expanded .arrow {
    transform: rotate(90deg);
    opacity: 1;
}

/* Add subtle hover effect on header */
.category-header {
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.category-header:active {
    transform: translateY(1px);
}

/* Improve performance of animations */
.texture-category {
    will-change: transform;
    contain: content;
}

/* Smooth scroll for when sections are opened */
.category-content:target {
    scroll-margin-top: 20px;
}

/* Section content animation */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-5px); }
}

@keyframes collapseHeight {
    from { 
        grid-template-rows: 1fr;
        opacity: 1;
    }
    to { 
        grid-template-rows: 0fr;
        opacity: 0;
    }
}

.category-content {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    will-change: max-height, opacity, padding;
    transition: 
        max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        opacity 0.3s ease-out,
        padding 0.3s ease;
    padding: 0 24px;
    transform-origin: top center;
    display: grid;
    grid-template-rows: 0fr;
}

.category-content.expanded {
    max-height: 5000px; /* Fallback for browsers that don't support grid */
    grid-template-rows: 1fr;
    opacity: 1;
    padding: 0 24px 24px;
}

/* Content wrapper for better animation control */
.category-content > .content-wrapper {
    min-height: 0; /* Needed for grid animation */
    overflow: hidden;
}

/* Ensure smooth height transitions */
.category-content > .content-wrapper > * {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.category-content.expanded > .content-wrapper > * {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 0.1s;
}

/* Animation classes */
.category-content.animating {
    pointer-events: none;
}

.category-content.animating-in {
    animation: fadeIn 0.3s ease-out forwards;
}

.category-content.animating-out {
    animation: fadeOut 0.3s ease-out forwards, collapseHeight 0.3s ease-out forwards;
    pointer-events: none;
}

/* Preview notice styles */
.preview-notice {
    background-color: rgba(30, 30, 30, 0.5);
    border: 1px dashed #444;
    border-radius: 4px;
    padding: 15px;
    margin: 20px 0;
    text-align: center;
    font-size: 0.9em;
    color: #888;
    position: relative;
    z-index: 1;
}

.preview-notice code {
    background-color: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Consolas', 'Monaco', monospace;
    word-break: break-all;
    opacity: 0.8;
}

/* Loading and error states */
.loading-indicator,
.error {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 15px 25px;
    border-radius: 4px;
    font-size: 16px;
    font-weight: 500;
    z-index: 1002;
}

.loading-indicator {
    background-color: rgba(0, 0, 0, 0.8);
    color: #fff;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

.error {
    background-color: rgba(231, 76, 60, 0.9);
    color: #fff;
    text-align: center;
    max-width: 80%;
    word-break: break-word;
    white-space: normal;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* Ensure content stays hidden after collapse */
.category-content:not(.expanded) {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
}

.category-info {
    margin: 0 0 24px 0;
    padding: 0 0 0 12px;
    font-size: 0.95em;
    line-height: 1.6;
    color: #aaa;
    border-left: 2px solid #333;
    font-style: italic;
}

.texture-subsection {
    margin: 0 0 32px 0;
    padding: 0;
}

.texture-subsection h3 {
    margin: 0 0 16px 0;
    color: #e0e0e0;
    padding-bottom: 8px;
    font-weight: 400;
    font-size: 1.1em;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    font-size: 0.9em;
    opacity: 0.8;
}

.thumbnail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
    margin: 15px 0;
    position: relative;
    min-height: 100px; /* Ensure there's space for loading state */
}

.thumbnail-grid.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
}

.thumbnail-container {
    position: relative;
    overflow: hidden;
    border-radius: 4px;
    background: rgba(40, 40, 40, 0.5);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.thumbnail-container:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.thumbnail-container img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    display: block;
    transition: opacity 0.3s ease;
    background: #1a1a1a;
}

.thumbnail-container p {
    margin: 5px 0 0;
    padding: 5px 8px;
    font-size: 12px;
    color: #aaa;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: rgba(20, 20, 20, 0.7);
}

.thumbnail-container {
    text-align: center;
    background-color: rgba(30, 30, 30, 0.6);
    padding: 12px;
    border-radius: 4px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.thumbnail-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.03) 0%, rgba(0,0,0,0.3) 100%);
    z-index: 1;
    pointer-events: none;
}

.thumbnail-container:hover {
    background-color: rgba(50, 50, 50, 0.4);
    transform: translateY(-4px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.thumbnail-container img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto 8px auto;
    border-radius: 3px;
    border: 1px solid #0f3460;
}

.thumbnail-container p {
    font-size: 0.75em;
    word-break: break-all;
    margin: 10px 0 0 0;
    color: #888;
    font-family: 'Consolas', 'Monaco', monospace;
    position: relative;
    z-index: 2;
    transition: color 0.2s ease;
}

.thumbnail-container:hover p {
    color: #ccc;
}

/* Lightbox Modal */
#lightbox-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    z-index: 1000;
    overflow: hidden;
    padding: 20px;
    box-sizing: border-box;
}

#lightbox-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
    box-sizing: border-box;
}

#modal-image {
    max-width: 90vw;
    max-height: 90vh;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    margin: auto;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.6);
    border-radius: 4px;
    background-color: #1a1a1a;
    padding: 10px;
    box-sizing: border-box;
    transition: transform 0.2s ease-out;
}

/* Ensure pixel-perfect rendering for pixel art/textures */
#modal-image[style*="image-rendering: pixelated"] {
    image-rendering: -moz-crisp-edges;
    image-rendering: pixelated;
    -ms-interpolation-mode: nearest-neighbor;
}

#caption {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    color: #fff;
    padding: 10px 20px;
    background-color: rgba(0, 0, 0, 0.8);
    border-radius: 4px;
    max-width: 90%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 14px;
}

.close-button {
    position: fixed;
    top: 20px;
    right: 20px;
    color: #fff;
    font-size: 35px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1001;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.5);
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #444;
}

.close-button:hover,
.close-button:focus {
    color: #fff;
    background: rgba(50, 50, 50, 0.9);
    text-decoration: none;
    cursor: pointer;
    border-color: #666;
}