/* --- Global Styles & Variables --- */
:root {
    --primary-color: #d58fdf; /* A warm, gold-like accent */
    --dark-bg: #121212;
    --light-dark-bg: #1a1a1a;
    --text-color: #f0f0f0;
    --text-secondary: #a0a0a0;
    --font-family: 'Montserrat', sans-serif;
}

/* Light theme overrides */
[data-theme="light"] {
    --dark-bg: #ffffff;
    --light-dark-bg: #f5f5f5;
    --text-color: #111111;
    --text-secondary: #555555;
    --primary-color: #4db8fb; /* Slightly darker purple for light mode */
}

/* Native UI colors */
:root { 
    color-scheme: dark light; 
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-family);
    background-color: var(--dark-bg);
    color: var(--text-color);
    line-height: 1.6;
}

h1, h2, h3 {
    font-weight: 700;
    color: var(--text-color);
}

h1 { font-size: 3rem; }
h2 { font-size: 2.5rem; text-align: center; margin-bottom: 2rem; }
h3 { font-size: 2rem; margin-bottom: 1rem; }

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.3s ease;
}

a:hover {
    color: var(--text-color);
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* --- Header & Navigation --- */
.main-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: rgba(18, 18, 18, 0.8);
    backdrop-filter: blur(10px);
    z-index: 1000;
    padding: 1rem 5%;
    box-sizing: border-box;
}

[data-theme="light"] .main-header {
    background-color: rgba(255, 255, 255, 0.8);
}

.main-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.nav-logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-color);
}

.nav-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-links {
    list-style: none;
    display: flex;
    margin: 0;
    padding: 0;
}

.nav-links li {
    margin-left: 2rem;
}

.nav-links a {
    font-weight: 400;
    color: var(--text-color);
}

/* Theme Toggle Button */
#theme-toggle {
    background: transparent;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    border-radius: 20px;
    padding: 0.4rem 0.8rem;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s ease;
    min-width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#theme-toggle:hover {
    background: var(--primary-color);
    color: var(--dark-bg);
    transform: scale(1.05);
}

/* --- Sections --- */
.content-section {
    padding: 6rem 5%;
    max-width: 1200px;
    margin: 0 auto;
}

.bg-darker {
    background-color: var(--light-dark-bg);
}

/* --- Hero Section --- */
.hero-section {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    color: white;
    background-image: linear-gradient(rgba(0,0,0,0.6), rgba(0,0,0,0.6)), url('/bilder/tor-bakgrund.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed; /* Parallax effect */
}

[data-theme="light"] .hero-section {
    background-image: linear-gradient(rgba(0,0,0,0.4), rgba(0,0,0,0.4)), url('/bilder/tor-bakgrund.jpg');
    color: white; /* Override to white for better contrast */
}

[data-theme="light"] .hero-section h1 {
    color: white;
}

[data-theme="light"] .hero-section .hero-content p {
    color: #e0e0e0; /* Light gray for subtitle */
}

.hero-content p {
    font-size: 1.6rem;
    font-weight: 300;
    color: var(--text-secondary);
}

/* Mobile-specific hero background */
@media (max-width: 768px) {
    .hero-section {
        background-attachment: scroll; /* Fix for mobile */
        background-image: linear-gradient(rgba(0,0,0,0.6), rgba(0,0,0,0.6)), url('/bilder/tor-bakgrund.jpg');
        background-size: cover;
        background-position: center;
    }
    
    [data-theme="light"] .hero-section {
        background-image: linear-gradient(rgba(0,0,0,0.4), rgba(0,0,0,0.4)), url('/bilder/tor-bakgrund.jpg');
    }
}

/* --- Gallery Sections --- */
.gallery-section {
    margin-bottom: 4rem;
    padding-bottom: 3rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

[data-theme="light"] .gallery-section {
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.gallery-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.gallery-section-title {
    text-align: center;
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.gallery-section-description {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
    font-size: 1.1rem;
    line-height: 1.6;
}

/* --- Masonry Gallery --- */
.masonry-gallery {
    column-count: 3;
    column-gap: 1.5rem;
    column-fill: balance;
}

.gallery-item {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    background: var(--light-dark-bg);
    transition: transform 0.3s ease, box-shadow 0.3s ease, opacity 0.3s ease;
    cursor: pointer;
    opacity: 1; /* Ensure items are visible by default */
    min-height: 200px; /* Ensure minimum height for visibility */
    break-inside: avoid; /* Prevent breaking in masonry */
    margin-bottom: 1.5rem; /* Space between items */
    display: block;
}

.gallery-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

[data-theme="light"] .gallery-item:hover {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.gallery-item img {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
    transition: transform 0.3s ease;
    min-height: 200px; /* Ensure minimum height */
}

.gallery-item:hover img {
    transform: scale(1.05);
}

/* Loading and error states */
.gallery-item.loaded {
    opacity: 1;
}

.gallery-item.error {
    background: var(--light-dark-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-align: center;
    padding: 1rem;
}

.gallery-item.error::before {
    content: "Image not available";
}

/* Optimize for different image orientations */
.gallery-item[data-category="portraits"] {
    grid-row: span 1;
}

.gallery-item[data-category="nature"] {
    grid-row: span 1;
}

.gallery-item[data-category="street"] {
    grid-row: span 1;
}

/* Responsive adjustments for masonry */
@media (max-width: 1200px) {
    .masonry-gallery {
        column-count: 2;
    }
}

@media (max-width: 768px) {
    .masonry-gallery {
        column-count: 1;
        column-gap: 1rem;
    }
    
    .gallery-item {
        margin-bottom: 1rem;
    }
}

/* --- About Section --- */
.about-content {
    display: flex;
    align-items: center;
    gap: 3rem;
    max-width: 900px;
    margin: 0 auto;
    text-align: left;
}

.about-photo {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

/* --- Contact Section --- */
#contact {
    text-align: center;
}

.contact-email a {
    font-size: 1.5rem;
    font-weight: bold;
}

.social-links {
    margin-top: 2rem;
}

.social-links a {
    margin: 0 1rem;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* --- Footer --- */
footer {
    text-align: center;
    padding: 2rem;
    background-color: var(--light-dark-bg);
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* --- Lightbox --- */
.lightbox {
    display: none; /* Hidden by default */
    position: fixed;
    z-index: 2000;
    padding-top: 50px;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.95);
    justify-content: center;
    align-items: center;
}

.lightbox-content {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 85vh;
    animation: zoom 0.4s ease-in-out;
}

@keyframes zoom {
    from {transform: scale(0.8);}
    to {transform: scale(1);}
}

.lightbox-close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
    cursor: pointer;
}

.lightbox-close:hover,
.lightbox-close:focus {
    color: #bbb;
    text-decoration: none;
}

/* --- Gallery Navigation --- */
.gallery-nav {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 3rem;
    flex-wrap: wrap;
}

.gallery-nav-link {
    padding: 0.75rem 1.5rem;
    background: var(--light-dark-bg);
    border: 2px solid var(--primary-color);
    border-radius: 25px;
    color: var(--primary-color);
    font-weight: 500;
    text-decoration: none;
    transition: all 0.3s ease;
    text-align: center;
    min-width: 120px;
}

.gallery-nav-link:hover,
.gallery-nav-link:focus {
    background: var(--primary-color);
    color: var(--dark-bg);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(224, 168, 0, 0.3);
}

/* Mobile Gallery Navigation */
.mobile-gallery-nav {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(18, 18, 18, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 25px;
    padding: 0.5rem;
    z-index: 1000;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.mobile-gallery-nav.active {
    display: flex;
    gap: 0.5rem;
}

.mobile-nav-btn {
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid var(--primary-color);
    border-radius: 20px;
    color: var(--primary-color);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    position: relative;
}

.mobile-nav-btn:hover,
.mobile-nav-btn.active {
    background: var(--primary-color);
    color: var(--dark-bg);
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(224, 168, 0, 0.3);
}

.mobile-nav-btn.active {
    font-weight: 600;
    border-width: 2px;
}

/* Gallery section scroll offset for mobile nav */
.gallery-section {
    scroll-margin-top: 100px; /* Account for fixed header */
}

/* Responsive adjustments for gallery nav */
@media (max-width: 768px) {
    .gallery-nav {
        display: none; /* Hide desktop nav on mobile */
    }
    
    .mobile-gallery-nav {
        display: flex; /* Show mobile nav by default on mobile */
        gap: 0.5rem;
    }
    
    .gallery-section {
        scroll-margin-top: 120px; /* More space for mobile nav */
    }
    
    /* Mobile nav adjustments */
    .nav-right {
        gap: 0.5rem;
    }
    
    .nav-links li {
        margin-left: 1rem;
    }
    
    #theme-toggle {
        min-width: 36px;
        height: 36px;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .masonry-gallery {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .gallery-section {
        margin-bottom: 3rem;
        padding-bottom: 2rem;
    }
    
    /* Even smaller nav adjustments */
    .nav-links li {
        margin-left: 0.75rem;
    }
    
    .nav-links a {
        font-size: 0.9rem;
    }
    
    #theme-toggle {
        min-width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }
}

/* --- Responsive Design --- */
@media (max-width: 768px) {
    h1 { font-size: 2.5rem; }
    h2 { font-size: 2rem; }
    h3 { font-size: 1.5rem; }
    
    .main-nav {
        flex-direction: column;
        align-items: center;
    }

    .nav-links {
        margin-top: 1rem;
    }

    .nav-links li {
        margin: 0 0.75rem;
    }
    
    .content-section {
        padding: 4rem 5%;
    }

    .about-content {
        flex-direction: column;
        text-align: center;
    }

    .masonry-gallery {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        gap: 1rem;
    }

    .gallery-section-description {
        font-size: 1rem;
        padding: 0 1rem;
    }
}

@media (max-width: 480px) {
    .masonry-gallery {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .gallery-section {
        margin-bottom: 3rem;
        padding-bottom: 2rem;
    }
}