.header-content { position: relative; }

main {
    padding: 0 1rem;
    max-width: 720px;
    margin: 0 auto;
}

h1[id], h2[id], section[id], article[id] { scroll-margin-top: 140px; }
h3[id]                                    { scroll-margin-top: 80px; }
.topic[id], .subtopic[id]                 { scroll-margin-top: 60px; }

.topic {
    margin-bottom: 2rem;
    background-color: #f5f5f5;
}

.gallery-container {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    justify-content: center;
    padding: 20px;
}

figure {
    margin: 0;
    border: 1px solid #ddd;
    padding: 10px;
    background-color: #fff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease-in-out;
}

figure:hover { transform: translateY(-5px); cursor: pointer; }
figure img   { display: block; max-width: 100%; }

figcaption {
    text-align: center;
    margin-top: 10px;
    font-size: 0.9em;
    color: #555;
}

#lightbox {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    visibility: hidden;
    opacity: 0;
    transition: visibility 0.3s, opacity 0.3s;
}

#lightbox.active { visibility: visible; opacity: 1; }

.lightbox-content {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
    max-width: 70vw;
    max-height: 70vh;
}

.lightbox-image-wrapper {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    overflow: hidden;
    min-height: 0;
}

#lightbox-img {
    max-width: 100%;
    max-height: 100%;
    height: auto;
    width: auto;
    object-fit: contain;
}

#lightbox-caption {
    color: #333;
    font-size: 1.1em;
    text-align: center;
    margin: 0;
    padding: 10px 0 0;
    flex-shrink: 0;
    height: 40px;
}

.lightbox-close {
    position: absolute;
    top: 20px; right: 20px;
    background: none;
    border: none;
    font-size: 2.5em;
    color: #fff;
    text-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 5px;
    transition: color 0.2s, background-color 0.2s;
    z-index: 1001;
}

.lightbox-close:hover { color: #f0f0f0; background-color: rgba(255, 255, 255, 0.2); }

.lightbox-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.3);
    border: none;
    font-size: 3em;
    color: #fff;
    cursor: pointer;
    padding: 10px 15px;
    border-radius: 5px;
    line-height: 1;
    transition: background-color 0.2s, color 0.2s;
    z-index: 1001;
}

.lightbox-arrow:hover   { background-color: rgba(255, 255, 255, 0.5); color: #eee; }
.lightbox-arrow-left    { left: 20px; }
.lightbox-arrow-right   { right: 20px; }
.lightbox-arrow.hidden  { visibility: hidden; opacity: 0; pointer-events: none; }

@media (max-width: 768px) {
    section[id], article[id] { scroll-margin-top: 160px; }
    h2, h3 { line-height: 1.7rem; }

    .header-content {
        display: flex;
        justify-content: flex-end;
        align-items: center;
    }
}
