:root {
    /* Material Design 3 Color System */
    --md-sys-color-primary: #1976d2;
    --md-sys-color-primary-container: #e3f2fd;
    --md-sys-color-on-primary: #ffffff;
    --md-sys-color-secondary: #00796b;
    --md-sys-color-secondary-container: #e0f2f1;
    --md-sys-color-tertiary: #7b1fa2;
    --md-sys-color-surface: #ffffff;
    --md-sys-color-surface-variant: #f5f5f5;
    --md-sys-color-background: #fafafa;
    --md-sys-color-error: #d32f2f;
    --md-sys-color-on-surface: #1c1b1f;
    --md-sys-color-on-surface-variant: #49454e;
    --md-sys-color-outline: #79747e;
    --md-sys-color-shadow: #000000;
    
    /* Elevation Shadows */
    --md-elevation-1: 0px 2px 1px -1px rgba(0,0,0,0.2), 0px 1px 1px 0px rgba(0,0,0,0.14), 0px 1px 3px 0px rgba(0,0,0,0.12);
    --md-elevation-2: 0px 3px 1px -2px rgba(0,0,0,0.2), 0px 2px 2px 0px rgba(0,0,0,0.14), 0px 1px 5px 0px rgba(0,0,0,0.12);
    --md-elevation-3: 0px 3px 3px -2px rgba(0,0,0,0.2), 0px 3px 4px 0px rgba(0,0,0,0.14), 0px 1px 8px 0px rgba(0,0,0,0.12);
    --md-elevation-4: 0px 2px 4px -1px rgba(0,0,0,0.2), 0px 4px 5px 0px rgba(0,0,0,0.14), 0px 1px 10px 0px rgba(0,0,0,0.12);
    
    /* Category Colors */
    --cat-systems: #1e3a8a;
    --cat-cognitive: #6b3aa0;
    --cat-game-theory: #14532d;
    --cat-fallacies: #7f1d1d;
    --cat-social: #7c2d12;
}

/* Dark Theme */
[data-theme="dark"] {
    --md-sys-color-primary: #90caf9;
    --md-sys-color-primary-container: #0d47a1;
    --md-sys-color-on-primary: #003c8f;
    --md-sys-color-secondary: #4db6ac;
    --md-sys-color-secondary-container: #00695c;
    --md-sys-color-surface: #1e1e1e;
    --md-sys-color-surface-variant: #2c2c2c;
    --md-sys-color-background: #121212;
    --md-sys-color-on-surface: #e0e0e0;
    --md-sys-color-on-surface-variant: #b0b0b0;
    --md-sys-color-outline: #938f99;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Roboto', 'Google Sans', sans-serif;
    background-color: var(--md-sys-color-background);
    color: var(--md-sys-color-on-surface);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Top App Bar Customization */
.mdc-top-app-bar {
    background-color: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    box-shadow: var(--md-elevation-2);
}

.mdc-top-app-bar__title {
    font-family: 'Google Sans', sans-serif;
    font-weight: 500;
    font-size: 20px;
}

/* Search Container */
.search-container {
    position: relative;
    margin-right: 16px;
    background-color: var(--md-sys-color-surface-variant);
    border-radius: 28px;
    transition: all 0.3s ease;
    width: 280px;
}

.search-container:focus-within {
    box-shadow: var(--md-elevation-2);
    background-color: var(--md-sys-color-surface);
}

.search-input {
    width: 100%;
    padding: 10px 40px 10px 48px;
    border: none;
    background: transparent;
    font-size: 14px;
    color: var(--md-sys-color-on-surface);
    outline: none;
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--md-sys-color-on-surface-variant);
}

/* Navigation Drawer */
.mdc-drawer {
    background-color: var(--md-sys-color-surface);
}

.mdc-drawer__header {
    padding: 24px 16px;
    background: linear-gradient(135deg, var(--md-sys-color-primary), var(--md-sys-color-secondary));
    color: white;
}

.category-count {
    margin-left: auto;
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-primary);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.mdc-list-item {
    border-radius: 0 24px 24px 0;
    margin: 4px 8px 4px 0;
    transition: all 0.2s ease;
}

.mdc-list-item:hover {
    background-color: var(--md-sys-color-surface-variant);
}

.mdc-list-item--activated {
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-primary);
}

/* Main Content */
.main-content {
    min-height: calc(100vh - 64px);
    padding: 24px;
    max-width: 1600px;
    margin: 0 auto;
}

/* Filter Chips */
.filter-chips-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding: 16px;
    background-color: var(--md-sys-color-surface);
    border-radius: 12px;
    box-shadow: var(--md-elevation-1);
}

.results-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

#results-count {
    color: var(--md-sys-color-on-surface-variant);
    font-size: 14px;
}

.sort-select {
    padding: 8px 12px;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 8px;
    background-color: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sort-select:hover {
    background-color: var(--md-sys-color-surface-variant);
}

/* Cards Container */
.cards-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
    animation: fadeIn 0.5s ease;
}

.cards-container.list-view {
    grid-template-columns: 1fr;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Card Styles */
.idea-card {
    background-color: var(--md-sys-color-surface);
    border-radius: 16px;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    box-shadow: var(--md-elevation-1);
    animation: cardEntry 0.4s ease backwards;
}

.idea-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--md-elevation-3);
}

@keyframes cardEntry {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.card-image-container {
    position: relative;
    width: 100%;
    padding-top: 100%;
    overflow: hidden;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.card-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.idea-card:hover .card-image {
    transform: scale(1.05);
}

.card-favorite {
    position: absolute;
    top: 8px;
    right: 8px;
    background-color: rgba(255, 255, 255, 0.95);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 2;
}

.card-favorite:hover {
    background-color: white;
    transform: scale(1.1);
}

.card-favorite.favorited {
    color: #e91e63;
}

.card-content {
    padding: 16px;
}

.card-title {
    font-size: 18px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--md-sys-color-on-surface);
}

.card-category {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 12px;
    text-transform: uppercase;
}

.category-systems {
    background-color: #e3f2fd;
    color: #1565c0;
}

.category-cognitive {
    background-color: #f3e5f5;
    color: #7b1fa2;
}

.category-game {
    background-color: #e8f5e9;
    color: #2e7d32;
}

.category-fallacies {
    background-color: #ffebee;
    color: #c62828;
}

.category-social {
    background-color: #fff3e0;
    color: #ef6c00;
}

.card-stats {
    display: flex;
    gap: 12px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--md-sys-color-outline);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--md-sys-color-on-surface-variant);
}

.stat-icon {
    font-size: 16px;
}

/* Loading State */
.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
}

.mdc-circular-progress {
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    text-align: center;
}

.empty-icon {
    font-size: 120px;
    color: var(--md-sys-color-outline);
    margin-bottom: 24px;
}

/* Detail Modal */
.detail-modal, .stats-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    animation: modalOpen 0.3s ease;
}

.detail-modal.active, .stats-modal.active {
    display: block;
}

@keyframes modalOpen {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 1200px;
    max-height: 90vh;
    background-color: var(--md-sys-color-surface);
    border-radius: 24px;
    overflow: hidden;
    box-shadow: var(--md-elevation-4);
    animation: modalSlide 0.3s ease;
}

@keyframes modalSlide {
    from {
        transform: translate(-50%, -45%);
        opacity: 0;
    }
    to {
        transform: translate(-50%, -50%);
        opacity: 1;
    }
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border: none;
    background-color: var(--md-sys-color-surface-variant);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background-color: var(--md-sys-color-primary-container);
    transform: scale(1.1);
}

.modal-navigation {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0 24px;
    pointer-events: none;
    z-index: 5;
}

.nav-btn {
    width: 48px;
    height: 48px;
    border: none;
    background-color: var(--md-sys-color-surface);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--md-elevation-2);
    transition: all 0.2s ease;
    pointer-events: all;
}

.nav-btn:hover {
    background-color: var(--md-sys-color-primary-container);
    transform: scale(1.1);
}

.nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.modal-body {
    display: flex;
    height: 100%;
    overflow: auto;
}

.modal-image {
    flex: 1;
    max-width: 50%;
    object-fit: contain;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.modal-info {
    flex: 1;
    padding: 32px;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.modal-header h2 {
    font-size: 28px;
    font-weight: 400;
    color: var(--md-sys-color-on-surface);
}

.favorite-btn {
    width: 48px;
    height: 48px;
    border: none;
    background-color: var(--md-sys-color-surface-variant);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.favorite-btn:hover {
    background-color: var(--md-sys-color-primary-container);
    transform: scale(1.1);
}

.favorite-btn.favorited {
    background-color: #ffebee;
    color: #e91e63;
}

.modal-category {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 24px;
    text-transform: uppercase;
}

.modal-stats {
    display: flex;
    gap: 24px;
    margin-bottom: 24px;
    padding: 16px;
    background-color: var(--md-sys-color-surface-variant);
    border-radius: 12px;
}

.modal-stat {
    flex: 1;
    text-align: center;
}

.stat-value {
    font-size: 24px;
    font-weight: 500;
    color: var(--md-sys-color-primary);
}

.stat-label {
    font-size: 12px;
    color: var(--md-sys-color-on-surface-variant);
    text-transform: uppercase;
}

.modal-description {
    margin-bottom: 24px;
}

.modal-description h3 {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 12px;
    color: var(--md-sys-color-on-surface);
}

.modal-description p {
    color: var(--md-sys-color-on-surface-variant);
    line-height: 1.6;
    margin-bottom: 12px;
}

.modal-related {
    margin-bottom: 24px;
}

.modal-related h3 {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 12px;
}

.related-chips {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.related-chip {
    padding: 6px 12px;
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-primary);
    border-radius: 16px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.related-chip:hover {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}

.modal-actions {
    display: flex;
    gap: 12px;
    padding-top: 24px;
    border-top: 1px solid var(--md-sys-color-outline);
}

/* Stats Modal Specific */
.stats-content {
    max-width: 800px;
    padding: 32px;
    overflow-y: auto;
    max-height: 90vh;
}

.stats-content h2 {
    font-size: 28px;
    font-weight: 400;
    margin-bottom: 24px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    background-color: var(--md-sys-color-surface-variant);
    padding: 20px;
    border-radius: 12px;
    text-align: center;
    transition: all 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--md-elevation-2);
}

.stat-icon {
    font-size: 36px;
    color: var(--md-sys-color-primary);
    margin-bottom: 8px;
}

.category-breakdown {
    margin-bottom: 32px;
}

.category-breakdown h3 {
    font-size: 20px;
    font-weight: 400;
    margin-bottom: 16px;
}

#category-chart {
    max-height: 300px;
}

.top-ideas {
    margin-bottom: 24px;
}

.top-ideas h3 {
    font-size: 20px;
    font-weight: 400;
    margin-bottom: 16px;
}

.top-idea-item {
    display: flex;
    align-items: center;
    padding: 12px;
    margin-bottom: 8px;
    background-color: var(--md-sys-color-surface-variant);
    border-radius: 8px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.top-idea-item:hover {
    background-color: var(--md-sys-color-primary-container);
}

.top-idea-rank {
    font-size: 24px;
    font-weight: 500;
    color: var(--md-sys-color-primary);
    margin-right: 16px;
}

.top-idea-info {
    flex: 1;
}

.top-idea-title {
    font-weight: 500;
    margin-bottom: 4px;
}

.top-idea-score {
    font-size: 12px;
    color: var(--md-sys-color-on-surface-variant);
}

/* Floating Action Button */
.mdc-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    opacity: 0;
    transform: scale(0);
    transition: all 0.3s ease;
}

.mdc-fab.visible {
    opacity: 1;
    transform: scale(1);
}

/* Snackbar */
.mdc-snackbar {
    z-index: 2000;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .cards-container {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    }
}

@media (max-width: 768px) {
    .search-container {
        width: 200px;
    }
    
    .main-content {
        padding: 16px;
    }
    
    .cards-container {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        gap: 16px;
    }
    
    .modal-body {
        flex-direction: column;
    }
    
    .modal-image {
        max-width: 100%;
        max-height: 400px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .search-container {
        width: 150px;
    }
    
    .cards-container {
        grid-template-columns: 1fr;
    }
    
    .filter-chips-container {
        flex-direction: column;
        gap: 12px;
    }
    
    .modal-content {
        width: 95%;
        max-height: 95vh;
    }
}