.gallery {
    max-width: var(--page-max);
    margin: 0 auto;
    padding: 2rem 1rem 3rem;
}
.gallery h1 {
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 2.4rem;
    font-weight: 400;
    margin: 0 0 1rem;
    color: var(--ink);
}
.gallery-controls {
    display: flex;
    gap: .75rem;
    flex-wrap: wrap;
    align-items: center;
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px dashed rgba(107, 81, 55, 0.2);
}
.gallery-controls .spacer { flex: 1; }
.gallery-upload-status {
    font-size: .85rem;
    font-variant-numeric: tabular-nums;
    color: var(--ink-soft);
    text-align: right;
}
.gallery-controls label { margin: 0; display: inline-flex; gap: .4rem; align-items: baseline; font-size: .85rem; }
.gallery-controls select, .gallery-controls input {
    font: inherit;
    padding: .35rem .5rem;
    border: 1px solid rgba(107, 81, 55, 0.25);
    background: var(--bg);
    color: var(--ink);
    border-radius: var(--radius);
    margin: 0;
    width: auto;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: .5rem;
}
.gallery-item {
    position: relative;
    aspect-ratio: 1 / 1;
    background: var(--envelope);
    border-radius: var(--radius);
    overflow: hidden;
    transition: transform .15s ease;
}
.gallery-item:hover { transform: scale(1.02); }

.gallery-item-media {
    border: 0;
    padding: 0;
    margin: 0;
    width: 100%;
    height: 100%;
    display: block;
    cursor: zoom-in;
    background: transparent;
}
.gallery-item-media img,
.gallery-item-media video {
    width: 100%; height: 100%; object-fit: cover; display: block;
}

.gallery-item-info {
    position: absolute;
    top: .4rem;
    left: .4rem;
    width: 1.8rem;
    height: 1.8rem;
    border: 0;
    border-radius: 50%;
    background: rgba(30, 22, 14, .65);
    color: white;
    font: inherit;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s ease;
    z-index: 2;
}
.gallery-item:hover .gallery-item-info,
.gallery-item:focus-within .gallery-item-info {
    opacity: 1;
}
.gallery-item-info:focus-visible { opacity: 1; outline: 2px solid var(--accent); }

.gallery-item .badge {
    position: absolute;
    right: .3rem; bottom: .3rem;
    background: rgba(30, 22, 14, .55);
    color: white;
    font-family: var(--font-sans);
    font-size: .7rem;
    padding: .1rem .35rem;
    border-radius: 3px;
    pointer-events: none;
}

.attachment-info-root {
    position: fixed;
    inset: 0;
    z-index: 75;
    display: none;
    background: rgba(15, 10, 5, 0.8);
    padding: 2rem 1rem;
    overflow-y: auto;
}
.attachment-info-root[aria-hidden="false"] { display: block; }

.info-panel {
    max-width: 32rem;
    margin: 0 auto;
    background: var(--paper);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
    font-family: var(--font-sans);
    color: var(--ink);
}
.info-preview {
    width: 100%;
    max-height: 46vh;
    object-fit: contain;
    border-radius: var(--radius);
    background: var(--envelope);
    display: block;
    margin: 0 auto 1rem;
}
.info-preview.pdf {
    min-height: 6rem;
    display: grid;
    place-items: center;
    text-decoration: none;
    font-family: var(--font-serif);
    font-size: 1.1rem;
    color: var(--ink);
}
.info-id {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .9rem;
    margin-bottom: 1rem;
}
.info-id code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    background: var(--bg);
    padding: .1rem .5rem;
    border-radius: 3px;
}
.info-meta {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: .35rem .75rem;
    margin: 0 0 1rem;
    font-size: .9rem;
}
.info-meta dt { color: var(--ink-soft); }
.info-meta dd { margin: 0; color: var(--ink); }
.caption-cell .caption-text { white-space: pre-wrap; word-wrap: break-word; }
.caption-cell textarea.caption-input {
    width: 100%;
    font: inherit;
    color: var(--ink);
    background: var(--bg);
    border: 1px solid rgba(107, 81, 55, 0.25);
    border-radius: var(--radius);
    padding: .4rem .55rem;
    resize: vertical;
    min-height: 2.6rem;
}
.caption-cell .caption-actions {
    display: flex; gap: .35rem;
    margin-top: .25rem;
}
.info-panel h3 {
    font-family: var(--font-serif);
    font-style: italic;
    font-weight: 400;
    font-size: 1.15rem;
    margin: 1rem 0 .5rem;
    color: var(--ink);
}
.info-letters {
    list-style: none;
    padding: 0;
    margin: 0 0 1rem;
}
.info-letters li {
    padding: .35rem 0;
    border-bottom: 1px solid rgba(107, 81, 55, 0.08);
}
.info-letters li:last-child { border-bottom: 0; }
.info-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    justify-content: flex-end;
    padding-top: 1rem;
    border-top: 1px dashed rgba(107, 81, 55, 0.2);
}

/* Crop picker inside the info panel */
.crop-source-wrap {
    position: relative;
    display: block;
    cursor: crosshair;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--envelope);
    max-width: 100%;
    margin-bottom: 1rem;
}
.crop-source {
    width: 100%;
    height: auto;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
}
.crop-marker {
    position: absolute;
    width: 14px;
    height: 14px;
    margin-left: -7px;
    margin-top: -7px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid white;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .35);
    pointer-events: none;
}
.crop-circle {
    position: absolute;
    box-sizing: border-box;
    border: 2px dashed rgba(255, 255, 255, .9);
    border-radius: 50%;
    box-shadow: 0 0 0 9999px rgba(30, 22, 14, .45);
    pointer-events: none;
}

.crop-preview-row {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1rem;
}
.crop-preview-col { display: flex; flex-direction: column; gap: .35rem; }

.crop-preview {
    position: relative;
    width: 9rem;
    height: 9rem;
    border-radius: 50%;
    overflow: hidden;
    background: var(--envelope);
    box-shadow: var(--shadow-sm);
    border: 3px solid var(--paper);
}
.crop-preview-img {
    position: absolute;
    left: 0;
    top: 0;
    display: block;
    max-width: none;
    user-select: none;
    -webkit-user-drag: none;
}

.crop-zoom-row {
    display: flex;
    gap: .5rem;
    align-items: center;
    font-size: .9rem;
    color: var(--ink-soft);
}
.crop-zoom-row input[type="range"] {
    flex: 1;
    accent-color: var(--accent-dark);
}
.crop-zoom-val { min-width: 3.5rem; text-align: right; }

.lightbox-root {
    position: fixed; inset: 0; z-index: 70;
    display: none;
    background: rgba(15, 10, 5, 0.9);
}
.lightbox-root[aria-hidden="false"] { display: grid; place-items: center; }
.lightbox-inner {
    max-width: 96vw; max-height: 92vh;
    display: flex; flex-direction: column; gap: .5rem; align-items: center;
}
.lightbox-inner img, .lightbox-inner video {
    max-width: 100%; max-height: 86vh; object-fit: contain;
    background: black;
    border-radius: var(--radius);
}
.lightbox-meta {
    color: rgba(255, 255, 255, .85);
    font-family: var(--font-sans);
    font-size: .85rem;
    max-width: 600px;
    text-align: center;
}
.lightbox-close {
    position: fixed;
    top: 1rem; right: 1rem;
    background: rgba(255, 255, 255, .9);
    border: 0;
    font: inherit;
    padding: .5rem .9rem;
    border-radius: var(--radius);
    cursor: pointer;
}

.lightbox-nav {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, .15);
    color: var(--paper);
    border: 0;
    font-size: 2.4rem;
    line-height: 1;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    cursor: pointer;
    display: grid;
    place-items: center;
    padding: 0;
    padding-bottom: .2rem;
    transition: background .15s ease;
}
.lightbox-nav:hover { background: rgba(255, 255, 255, .28); }
.lightbox-nav:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lightbox-nav.prev { left: 1rem; }
.lightbox-nav.next { right: 1rem; }

.lightbox-counter {
    color: rgba(255, 255, 255, .75);
    font-family: var(--font-sans);
    font-size: .8rem;
    text-align: center;
    letter-spacing: .05em;
}

@media (max-width: 520px) {
    .lightbox-nav {
        width: 2.25rem;
        height: 2.25rem;
        font-size: 1.8rem;
    }
    .lightbox-nav.prev { left: .4rem; }
    .lightbox-nav.next { right: .4rem; }
}
