* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #0ea5e9;
    --primary-hover: #0284c7;
    --background: #ffffff;
    --surface: #f8fafc;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --error: #ef4444;
    --border: #e2e8f0;
    --shadow: rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

header h1 {
    font-size: clamp(1.75rem, 5vw, 2.5rem);
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, #0ea5e9 0%, #06b6d4 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

header p {
    color: var(--text-secondary);
    font-size: clamp(0.9rem, 2.5vw, 1.1rem);
}

.search-section {
    background: var(--surface);
    padding: clamp(1rem, 3vw, 2rem);
    border-radius: 1rem;
    margin-bottom: 2rem;
    box-shadow: 0 1px 3px var(--shadow);
}

.search-box {
    display: flex;
    margin-bottom: 1.5rem;
    gap: 0;
}

#searchInput {
    flex: 1;
    padding: clamp(0.75rem, 2vw, 1rem) clamp(1rem, 2vw, 1.5rem);
    font-size: clamp(0.9rem, 2vw, 1.1rem);
    border: 2px solid var(--border);
    border-right: none;
    border-radius: 0.5rem 0 0 0.5rem;
    transition: border-color 0.3s;
    min-width: 0;
}

#searchInput:focus {
    outline: none;
    border-color: var(--primary-color);
}

.search-btn {
    padding: 0 clamp(1rem, 3vw, 2rem);
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0 0.5rem 0.5rem 0;
    cursor: pointer;
    transition: background-color 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-btn:hover {
    background: var(--primary-hover);
}

.search-icon {
    display: block;
    width: 20px;
    height: 20px;
}

.filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
}

select {
    width: 100%;
    padding: clamp(0.5rem, 1.5vw, 0.75rem) clamp(0.75rem, 1.5vw, 1rem);
    font-size: clamp(0.85rem, 1.5vw, 1rem);
    border: 2px solid var(--border);
    border-radius: 0.5rem;
    background: white;
    cursor: pointer;
    transition: border-color 0.3s;
}

select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.loading-container {
    display: none;
    text-align: center;
    padding: clamp(2rem, 5vw, 4rem) 0;
}

.loading-container.show {
    display: block;
}

.spinner {
    width: clamp(40px, 8vw, 50px);
    height: clamp(40px, 8vw, 50px);
    margin: 0 auto 1rem;
    border: 4px solid var(--border);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.error-message {
    display: none;
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
    padding: clamp(0.75rem, 2vw, 1rem);
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    border: 1px solid rgba(239, 68, 68, 0.3);
    font-size: clamp(0.85rem, 1.5vw, 1rem);
}

.error-message.show {
    display: block;
}

.results-info {
    display: none;
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
    font-size: clamp(0.85rem, 1.5vw, 1rem);
    text-align: center;
}

.results-info.show {
    display: block;
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
    gap: clamp(0.75rem, 2vw, 1.5rem);
    margin-bottom: 3rem;
}

.image-card {
    position: relative;
    background: var(--surface);
    border-radius: 0.75rem;
    overflow: hidden;
    box-shadow: 0 2px 8px var(--shadow);
    transition: transform 0.3s, box-shadow 0.3s;
    cursor: pointer;
    aspect-ratio: 1 / 0.75;
}

.image-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px var(--shadow);
}

.image-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.image-overlay {
    display: none;
}

.load-more-btn {
    display: none;
    margin: 0 auto;
    padding: clamp(0.75rem, 2vw, 1rem) clamp(1.5rem, 3vw, 2rem);
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: clamp(0.9rem, 1.5vw, 1rem);
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.3s;
}

.load-more-btn.show {
    display: block;
}

.load-more-btn:hover {
    background: var(--primary-hover);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    animation: fadeIn 0.3s;
    padding: 1rem;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.modal-close {
    position: absolute;
    top: clamp(10px, 2vw, 20px);
    right: clamp(15px, 3vw, 40px);
    color: white;
    font-size: clamp(30px, 5vw, 40px);
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s;
    z-index: 1001;
}

.modal-close:hover {
    color: var(--primary-color);
}

.modal-content {
    max-width: 90%;
    max-height: 70vh;
    object-fit: contain;
    border-radius: 0.5rem;
}

.modal-info {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    padding: clamp(1rem, 2vw, 1.5rem);
    border-radius: 0.5rem;
    margin-top: 1rem;
    text-align: center;
    color: white;
    max-width: 90%;
    width: 100%;
    max-width: 600px;
}

.modal-info h3 {
    margin-bottom: 0.5rem;
    font-size: clamp(1rem, 2vw, 1.25rem);
}

.modal-info p {
    font-size: clamp(0.85rem, 1.5vw, 1rem);
}

.modal-actions {
    display: flex;
    gap: clamp(0.5rem, 2vw, 1rem);
    justify-content: center;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.download-btn, .unsplash-link {
    padding: clamp(0.4rem, 1vw, 0.5rem) clamp(1rem, 2vw, 1.5rem);
    background: var(--primary-color);
    color: white;
    text-decoration: none;
    border-radius: 0.25rem;
    transition: background-color 0.3s;
    font-size: clamp(0.85rem, 1.5vw, 0.9rem);
}

.download-btn:hover, .unsplash-link:hover {
    background: var(--primary-hover);
}

.unsplash-link {
    background: #1d1d1d;
}

.unsplash-link:hover {
    background: #000;
}

footer {
    text-align: center;
    margin-top: clamp(2rem, 5vw, 4rem);
    padding-top: clamp(1rem, 3vw, 2rem);
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: clamp(0.85rem, 1.5vw, 1rem);
}

/* CSS for smooth image loading */
.card-image {
    opacity: 0;
    transition: opacity 0.3s;
}

.card-image.loaded {
    opacity: 1;
}

/* Tablet Styles (768px - 1024px) */
@media (max-width: 1024px) {
    .container {
        padding: 1.5rem;
    }

    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    }
}

/* Mobile Landscape (568px - 768px) */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .search-box {
        flex-direction: column;
        gap: 0.75rem;
    }

    #searchInput {
        border-radius: 0.5rem;
        border-right: 2px solid var(--border);
    }

    .search-btn {
        border-radius: 0.5rem;
        padding: 0.75rem;
        width: 100%;
    }

    .filters {
        grid-template-columns: 1fr;
    }

    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }

    .modal-info {
        margin-top: 0.5rem;
        padding: 1rem;
    }

    .modal-actions {
        flex-direction: column;
        width: 100%;
    }

    .download-btn, .unsplash-link {
        width: 100%;
        text-align: center;
    }
}

/* Small Mobile (320px - 568px) */
@media (max-width: 568px) {
    .container {
        padding: 0.75rem;
    }

    header {
        margin-bottom: 2rem;
    }

    .search-section {
        padding: 1rem;
        border-radius: 0.75rem;
    }

    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 0.5rem;
    }

    .image-card {
        border-radius: 0.5rem;
    }

    .modal {
        padding: 0.5rem;
    }

    .modal-content {
        max-width: 95%;
        max-height: 60vh;
    }
}

/* Very Small Mobile (below 320px) */
@media (max-width: 320px) {
    .image-grid {
        grid-template-columns: 1fr;
    }

    .filters {
        font-size: 0.85rem;
    }

    select {
        font-size: 0.85rem;
    }
}

/* Landscape Mode Adjustments */
@media (max-height: 600px) and (orientation: landscape) {
    header {
        margin-bottom: 1.5rem;
    }

    header h1 {
        font-size: 1.75rem;
    }

    .modal-content {
        max-height: 80vh;
    }

    .modal-info {
        display: none;
    }
}

/* High Resolution Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .image-card {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    }

    .image-card:hover {
        box-shadow: 0 8px 16px rgba(0, 0, 0, 0.12);
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    :root {
        --background: #0f172a;
        --surface: #1e293b;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --border: #334155;
        --shadow: rgba(0, 0, 0, 0.3);
    }

    select {
        background: var(--surface);
        color: var(--text-primary);
    }

    #searchInput {
        background: var(--surface);
        color: var(--text-primary);
    }
}

/* Accessibility - Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

.site-title {
    display: flex;
    align-items: center;
    gap: 18px;
}
.site-logo {
    width: 64px;
    height: 64px;
    object-fit: contain;
}
