/* 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;
    line-height: 1.6;
    color: #e0e0e0;
    background: #1a1a1a;
    min-height: 100vh;
}

/* Header */
header {
    text-align: center;
    padding: 2rem 1rem;
    background: #2d2d2d;
    border-bottom: 1px solid #404040;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 0.5rem;
}

header p {
    font-size: 1.1rem;
    color: #b0b0b0;
    font-weight: 300;
}

/* Main content */
main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* Loading */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 50vh;
    color: #e0e0e0;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #404040;
    border-top: 4px solid #ffffff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.hidden {
    display: none;
}

/* Filters */
.filters {
    background: #2d2d2d;
    padding: 1.5rem;
    border-radius: 4px;
    margin-bottom: 2rem;
    border: 1px solid #404040;
}

.filters label {
    font-weight: 600;
    margin-right: 1rem;
    color: #e0e0e0;
}

.filters select {
    padding: 0.5rem 1rem;
    border: 1px solid #555;
    border-radius: 4px;
    font-size: 1rem;
    background: #1a1a1a;
    color: #e0e0e0;
    cursor: pointer;
}

.filters select:focus {
    outline: none;
    border-color: #888;
}

/* Results container */
.results-container {
    display: grid;
    gap: 2rem;
}

/* Feature section */
.feature-section {
    background: #2d2d2d;
    border-radius: 4px;
    border: 1px solid #404040;
    margin-bottom: 1rem;
    overflow: hidden;
}

.feature-section:hover {
    border-color: #555;
}

.feature-section.collapsed .feature-content {
    display: none;
}

.feature-section.expanded .feature-content {
    display: block;
}

.feature-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2rem;
    border-bottom: 1px solid #404040;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.feature-header:hover {
    background-color: #333;
}

.feature-content {
    padding: 0 2rem 2rem 2rem;
}

.expand-icon {
    font-size: 1.2rem;
    color: #b0b0b0;
    transition: transform 0.3s ease;
    user-select: none;
}

.feature-section.expanded .expand-icon {
    transform: rotate(180deg);
}

.feature-title-group {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.feature-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #ffffff;
}

.delta-freq {
    font-size: 1rem;
    font-weight: 500;
    color: #4CAF50;
    margin-left: 0.5rem;
}

.top-ranking-link {
    color: #4CAF50;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: color 0.3s ease;
}

.top-ranking-link:hover {
    color: #66BB6A;
    text-decoration: underline;
}

.top-ranking-badge {
    color: #FFD700;
    font-size: 0.85rem;
    font-weight: 600;
}

.emotion-label {
    background: #555;
    color: #ffffff;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.9rem;
}

.emotion-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #ffffff;
    margin: 0;
    text-transform: capitalize;
}

.feature-element {
    background: #404040;
    color: #ffffff;
    padding: 0.3rem 0.8rem;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.9rem;
    display: inline-block;
}

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-item {
    background: #1a1a1a;
    padding: 1rem;
    border-radius: 4px;
    text-align: center;
    border-left: 3px solid #888;
}

.stat-label {
    font-size: 0.85rem;
    color: #b0b0b0;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: #ffffff;
}

/* Images grid */
.images-section h3 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: #ffffff;
    font-weight: 600;
}

.images-grid-masonry {
    min-height: 100px;
}

.masonry-grid {
    column-count: 4;
    column-gap: 0.75rem;
    max-width: 1200px;
    margin: 0 auto;
}

.image-slot {
    background: #1a1a1a;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid #404040;
    position: relative;
    margin-bottom: 0.75rem;
    break-inside: avoid;
    display: inline-block;
    width: 100%;
}

.image-slot.loading {
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-placeholder {
    width: 20px;
    height: 20px;
    border: 2px solid #404040;
    border-top: 2px solid #ffffff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.image-slot.empty {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0f0f0f;
    border-color: #2a2a2a;
}

.empty-slot {
    color: #444;
    font-size: 1.2rem;
}

.image-slot.loaded:hover {
    border-color: #555;
}

.image-slot img {
    width: 100%;
    height: auto;
    object-fit: cover;
    display: block;
}

.image-slot .image-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.8));
    padding: 0.5rem 0.25rem 0.25rem;
    color: white;
}

.image-slot .similarity-score {
    font-size: 0.7rem;
    font-weight: 600;
    text-align: center;
}

.also-expressed-note {
    background: #2a2a2a;
    padding: 1rem;
    margin: 1rem 0;
    border-radius: 4px;
    border-left: 3px solid #4CAF50;
    color: #e0e0e0;
    font-size: 0.9rem;
}

.also-expressed-note strong {
    color: #4CAF50;
}

.image-item {
    background: #1a1a1a;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid #404040;
}

.image-item:hover {
    border-color: #555;
}

.image-item img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
}

.image-info {
    padding: 1rem;
}

.similarity-score {
    font-weight: 600;
    color: #ffffff;
    font-size: 0.9rem;
}

.image-dimensions {
    font-size: 0.8rem;
    color: #b0b0b0;
    margin-top: 0.25rem;
}

/* Responsive design */
@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }
    
    main {
        padding: 1rem;
    }
    
    .feature-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .masonry-grid {
        column-count: 2;
    }
    
    .filters {
        padding: 1rem;
    }
    
    .filters label {
        display: block;
        margin-bottom: 0.5rem;
        margin-right: 0;
    }
}

/* Error handling */
.error-message {
    background: #3d1a1a;
    color: #ff6b6b;
    padding: 1rem;
    border-radius: 4px;
    margin: 1rem 0;
    border-left: 3px solid #ff6b6b;
}

.image-error {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    background: #1a1a1a;
    color: #b0b0b0;
    font-size: 0.9rem;
}

.no-images-message {
    text-align: center;
    padding: 2rem;
    color: #b0b0b0;
    font-style: italic;
    background: #1a1a1a;
    border-radius: 4px;
    border: 1px solid #404040;
}
