/* ============================================
   CSS Variables - Design System
   ============================================ */
:root {
    /* Colors */
    --color-bg-primary: #ffffff;
    --color-bg-secondary: #f5f9fe;
    --color-bg-tertiary: #eef4fb;
    --color-bg-card: rgba(255, 255, 255, 0.92);
    --color-bg-card-hover: #f2f7fd;

    --color-text-primary: #0f1c2d;
    --color-text-secondary: #1f4e7a;
    --color-text-muted: #4f6f90;

    --color-accent-primary: #1f4e7a;
    --color-accent-secondary: #6fa7da;
    --color-accent-gradient: linear-gradient(135deg, #0f1c2d 0%, #1f4e7a 55%, #6fa7da 100%);
    --color-accent-glow: rgba(31, 78, 122, 0.28);

    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-error: #ef4444;

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    --space-3xl: 4rem;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(15, 28, 45, 0.08);
    --shadow-md: 0 4px 20px rgba(15, 28, 45, 0.14);
    --shadow-lg: 0 8px 40px rgba(15, 28, 45, 0.18);
    --shadow-glow: 0 0 40px var(--color-accent-glow);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 400ms ease;

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 2rem;
    --font-size-4xl: 2.5rem;
    --mobile-filter-top: 0px;
}

/* ============================================
   Base Styles
   ============================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: 1.6;
    color: var(--color-text-primary);
    background-color: var(--color-bg-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Background Effects */
.bg-gradient {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(ellipse at 20% 20%, rgba(111, 167, 218, 0.2) 0%, transparent 52%),
        radial-gradient(ellipse at 80% 80%, rgba(31, 78, 122, 0.1) 0%, transparent 55%),
        radial-gradient(ellipse at 50% 50%, rgba(15, 28, 45, 0.04) 0%, transparent 72%);
    pointer-events: none;
    z-index: -2;
}

.bg-grid {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image:
        linear-gradient(rgba(15, 28, 45, 0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(15, 28, 45, 0.04) 1px, transparent 1px);
    background-size: 50px 50px;
    pointer-events: none;
    z-index: -1;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 var(--space-lg);
}

/* ============================================
   Header
   ============================================ */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(31, 78, 122, 0.14);
    padding: var(--space-md) 0;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-lg);
    flex-wrap: wrap;
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: var(--font-size-xl);
    font-weight: 700;
    text-decoration: none;
    color: var(--color-text-primary);
}

.logo-icon {
    font-size: 1.5em;
}

.logo-text .accent {
    background: var(--color-accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.search-container {
    position: relative;
    flex: 1;
    max-width: 400px;
    min-width: 200px;
}

.search-icon {
    position: absolute;
    left: var(--space-md);
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--color-text-muted);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: var(--space-sm) var(--space-md) var(--space-sm) calc(var(--space-md) * 2 + 20px);
    background: var(--color-bg-tertiary);
    border: 1px solid rgba(31, 78, 122, 0.2);
    border-radius: var(--radius-full);
    color: var(--color-text-primary);
    font-size: var(--font-size-sm);
    transition: all var(--transition-base);
}

.search-input::placeholder {
    color: var(--color-text-muted);
}

.search-input:focus {
    outline: none;
    border-color: var(--color-accent-primary);
    box-shadow: 0 0 0 3px var(--color-accent-glow);
}

.header-stats {
    display: flex;
    gap: var(--space-sm);
}

.stat-badge {
    padding: var(--space-xs) var(--space-md);
    background: var(--color-accent-gradient);
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: white;
}

/* ============================================
   Filter Section
   ============================================ */
.filter-section {
    padding: var(--space-lg) 0;
    background: rgba(111, 167, 218, 0.12);
    backdrop-filter: blur(10px);
}

.filter-scroll-wrap {
    position: relative;
}

.filter-container {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    justify-content: center;
}

.filter-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    background: var(--color-bg-tertiary);
    border: 1px solid rgba(31, 78, 122, 0.2);
    border-radius: var(--radius-full);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-base);
    white-space: nowrap;
}

.filter-btn:focus-visible {
    outline: 2px solid var(--color-accent-secondary);
    outline-offset: 2px;
}

.filter-btn:hover {
    background: var(--color-bg-card-hover);
    border-color: rgba(31, 78, 122, 0.4);
    color: var(--color-text-primary);
    transform: translateY(-2px);
}

.filter-btn.active {
    background: var(--color-accent-gradient);
    border-color: transparent;
    color: white;
    box-shadow: var(--shadow-glow);
}

.filter-icon {
    font-size: 1.1em;
}

/* ============================================
   Main Content
   ============================================ */
.main-content {
    padding: var(--space-2xl) 0;
    min-height: 60vh;
}

/* Theme Grid */
.theme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: var(--space-lg);
}

/* Theme Card */
.theme-card {
    position: relative;
    background: var(--color-bg-card);
    border: 1px solid rgba(31, 78, 122, 0.16);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: all var(--transition-slow);
    cursor: pointer;
}

.theme-card:hover {
    transform: translateY(-8px);
    border-color: rgba(31, 78, 122, 0.45);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.theme-card-image {
    position: relative;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    background: var(--color-bg-tertiary);
}

.theme-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--transition-slow);
}

.theme-card:hover .theme-card-image img {
    transform: scale(1.05);
}

.theme-card-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom,
            transparent 0%,
            rgba(15, 28, 45, 0.18) 50%,
            rgba(15, 28, 45, 0.58) 100%);
    opacity: 0;
    transition: opacity var(--transition-base);
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-card:hover .theme-card-overlay {
    opacity: 1;
}

.theme-card-preview-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-lg);
    background: rgba(255, 255, 255, 0.95);
    border: none;
    border-radius: var(--radius-full);
    color: var(--color-text-primary);
    font-weight: 600;
    font-size: var(--font-size-sm);
    text-decoration: none;
    cursor: pointer;
    transform: translateY(20px);
    transition: all var(--transition-base);
}

.theme-card:hover .theme-card-preview-btn {
    transform: translateY(0);
}

.theme-card-preview-btn:hover {
    background: white;
    transform: scale(1.05);
}

.theme-card-preview-btn svg {
    width: 16px;
    height: 16px;
}

.theme-card-body {
    padding: var(--space-md);
}

.theme-card-category {
    display: inline-block;
    padding: var(--space-xs) var(--space-sm);
    background: rgba(111, 167, 218, 0.22);
    color: var(--color-accent-primary);
    font-size: var(--font-size-xs);
    font-weight: 600;
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.theme-card-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--color-text-primary);
    margin-bottom: var(--space-xs);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ============================================
   Loading & No Results
   ============================================ */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-3xl);
    color: var(--color-text-muted);
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--color-bg-tertiary);
    border-top-color: var(--color-accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: var(--space-md);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.no-results {
    text-align: center;
    padding: var(--space-3xl);
    color: var(--color-text-secondary);
}

.no-results-icon {
    font-size: 4rem;
    margin-bottom: var(--space-md);
    opacity: 0.5;
}

.no-results h3 {
    font-size: var(--font-size-xl);
    color: var(--color-text-primary);
    margin-bottom: var(--space-sm);
}

/* ============================================
   Modal
   ============================================ */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 28, 45, 0.65);
    backdrop-filter: blur(8px);
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    background: var(--color-bg-secondary);
    border-radius: var(--radius-xl);
    border: 1px solid rgba(31, 78, 122, 0.2);
    overflow: hidden;
    transform: scale(0.9) translateY(20px);
    transition: transform var(--transition-base);
}

.modal.active .modal-content {
    transform: scale(1) translateY(0);
}

.modal-close {
    position: absolute;
    top: var(--space-md);
    right: var(--space-md);
    z-index: 10;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 28, 45, 0.6);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: rgba(15, 28, 45, 0.82);
    transform: rotate(90deg);
}

.modal-close svg {
    width: 20px;
    height: 20px;
}

.modal-body {
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    overflow-y: auto;
}

@media (min-width: 768px) {
    .modal-body {
        display: grid;
        grid-template-columns: 1.2fr 1fr;
        overflow: hidden;
    }
}

.modal-image-container {
    position: relative;
    min-height: 250px;
    max-height: 400px;
    background: var(--color-bg-tertiary);
}

@media (min-width: 768px) {
    .modal-image-container {
        min-height: 100%;
        max-height: none;
    }
}

.modal-image-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.modal-info {
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    overflow-y: auto;
    max-height: 50vh;
}

@media (min-width: 768px) {
    .modal-info {
        max-height: 90vh;
        padding: var(--space-xl);
    }
}

.modal-info h2 {
    font-size: var(--font-size-xl);
    font-weight: 700;
    line-height: 1.3;
    color: var(--color-text-primary);
    word-wrap: break-word;
}

@media (min-width: 768px) {
    .modal-info h2 {
        font-size: var(--font-size-2xl);
    }
}

.modal-subtitle {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    word-wrap: break-word;
}

.modal-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.modal-category {
    display: inline-block;
    padding: var(--space-xs) var(--space-md);
    background: var(--color-accent-gradient);
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: white;
    white-space: nowrap;
}

.modal-author {
    display: inline-block;
    padding: var(--space-xs) var(--space-md);
    background: var(--color-bg-tertiary);
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    white-space: nowrap;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-top: auto;
    padding-top: var(--space-md);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.btn-primary {
    background: var(--color-accent-gradient);
    color: white;
    border: none;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.btn-secondary {
    background: transparent;
    color: var(--color-text-secondary);
    border: 1px solid rgba(31, 78, 122, 0.3);
}

.btn-secondary:hover {
    background: rgba(111, 167, 218, 0.14);
    color: var(--color-text-primary);
    border-color: rgba(31, 78, 122, 0.55);
}

/* ============================================
   Footer
   ============================================ */
.footer {
    padding: var(--space-2xl) 0;
    text-align: center;
    color: var(--color-text-muted);
    border-top: 1px solid rgba(31, 78, 122, 0.14);
}

.footer-note {
    font-size: var(--font-size-sm);
    margin-top: var(--space-sm);
    opacity: 0.6;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: var(--space-md);
    }

    .search-container {
        width: 100%;
        max-width: none;
        order: 1;
    }

    .logo {
        order: 0;
    }

    .header-stats {
        order: 0;
    }

    .theme-grid {
        grid-template-columns: 1fr;
    }

    .filter-section {
        position: sticky;
        top: var(--mobile-filter-top);
        z-index: 95;
        padding: var(--space-sm) 0;
        background: rgba(255, 255, 255, 0.95);
        border-bottom: 1px solid rgba(31, 78, 122, 0.14);
    }

    .filter-scroll-wrap {
        overflow: hidden;
        margin: 0 calc(-1 * var(--space-xs));
    }

    .filter-scroll-wrap::before,
    .filter-scroll-wrap::after {
        content: '';
        position: absolute;
        top: 0;
        bottom: 0;
        width: 22px;
        pointer-events: none;
        z-index: 3;
        transition: opacity var(--transition-fast);
    }

    .filter-scroll-wrap::before {
        left: 0;
        background: linear-gradient(to right, rgba(255, 255, 255, 0.98), rgba(255, 255, 255, 0));
    }

    .filter-scroll-wrap::after {
        right: 0;
        background: linear-gradient(to left, rgba(255, 255, 255, 0.98), rgba(255, 255, 255, 0));
    }

    .filter-scroll-wrap.at-start::before {
        opacity: 0;
    }

    .filter-scroll-wrap.at-end::after {
        opacity: 0;
    }

    .filter-container {
        justify-content: flex-start;
        overflow-x: auto;
        flex-wrap: nowrap;
        gap: 0.375rem;
        padding: 0 var(--space-xs) var(--space-xs);
        scroll-snap-type: x proximity;
        scroll-padding-inline: var(--space-xs);
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .filter-container::-webkit-scrollbar {
        display: none;
    }

    .filter-btn {
        flex: 0 0 auto;
        min-height: 34px;
        padding: 0.375rem 0.72rem;
        font-size: 0.78rem;
        gap: 0.3rem;
        scroll-snap-align: start;
    }

    .filter-btn.active {
        box-shadow: 0 6px 14px rgba(15, 28, 45, 0.2);
    }

    .modal-content {
        max-height: 100vh;
        border-radius: 0;
    }
}

/* ============================================
   Animations
   ============================================ */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.theme-card {
    animation: fadeIn 0.5s ease forwards;
    opacity: 0;
}

.theme-card:nth-child(1) {
    animation-delay: 0.05s;
}

.theme-card:nth-child(2) {
    animation-delay: 0.1s;
}

.theme-card:nth-child(3) {
    animation-delay: 0.15s;
}

.theme-card:nth-child(4) {
    animation-delay: 0.2s;
}

.theme-card:nth-child(5) {
    animation-delay: 0.25s;
}

.theme-card:nth-child(6) {
    animation-delay: 0.3s;
}

.theme-card:nth-child(7) {
    animation-delay: 0.35s;
}

.theme-card:nth-child(8) {
    animation-delay: 0.4s;
}

.theme-card:nth-child(9) {
    animation-delay: 0.45s;
}

.theme-card:nth-child(10) {
    animation-delay: 0.5s;
}

.theme-card:nth-child(11) {
    animation-delay: 0.55s;
}

.theme-card:nth-child(12) {
    animation-delay: 0.6s;
}
