:root { color-scheme: dark; }

body {
    margin: 0;
    overflow: hidden;
    background: #000;
}

#v3d-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.fullscreen-button {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 20px;
    height: 20px;
    cursor: pointer;
    background-size: 100% 100%;
    display: none !important; /* fullscreen handled by outer page */
    z-index: 1;
}

.fullscreen-open  { background-image: url('media/fullscreen_open.svg'); }
.fullscreen-close { background-image: url('media/fullscreen_close.svg'); }

/* Remove tap highlight on iOS */
* { -webkit-tap-highlight-color: rgba(0,0,0,0); }

/* Photo overlay */
#photo-overlay {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(0,0,0,0.88);
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.15s ease, visibility 0.15s ease;
}
#photo-overlay.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    cursor: zoom-out;
}

/* Wrapper keeps image + caption together */
#photo-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    max-width: 98vw;
    cursor: default;
}

#photo-img-wrap {
    position: relative;
    display: inline-block;
    line-height: 0;
}

#photo-img {
    max-width: 100%;
    max-height: 86vh;
    object-fit: contain;
    display: block;
    background: #000;
    opacity: 0;
    transition: opacity 0.2s ease;
}
#photo-overlay.open.img-loaded #photo-img {
    opacity: 1;
}

#photo-caption {
    text-align: center;
    color: rgba(255,255,255,0.85);
    font-family: 'Commissioner', sans-serif;
    font-weight: 300;
    font-size: 15px;
    letter-spacing: 0.06em;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding: 0 10px 4px;
    pointer-events: none;
    white-space: normal;
    opacity: 0;
}

#photo-overlay.open.img-loaded #photo-caption {
    animation: captionFadeIn 0.4s ease 0.2s forwards;
}

@keyframes captionFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

#photo-close {
    position: absolute;
    top: -28px;
    right: 0;
    font-size: 16px;
    color: rgba(255,255,255,0.8);
    background: none;
    border: none;
    cursor: pointer;
    z-index: 51;
    line-height: 1;
    padding: 4px 6px;
    opacity: 0;
    pointer-events: none;
}
#photo-overlay.img-loaded #photo-close {
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.2s ease;
}
#photo-close:hover { color: #fff; }

/* Mobile: image is centered in the full viewport (overlay uses align-items:center).
   X button sits 28px above the image top edge; it must clear the outer header bar.
   Outer header height = max(78px + safe-area-inset-top, 90px).
   Formula: max-height = 100vh - 2*(header + 28px + 20px buffer)
   Using env(safe-area-inset-top) makes standard phones bigger while DI stays safe.
   Caption allowed to wrap to 2 lines — max-height accounts for ~50px total below image. */
/* Tablet: maximize image, bigger X button. 100vh here = iframe height (already below the page header).
   Reserve ~100px for close button (32px) + gap + caption + breathing room. */
@media (min-width: 769px) and (max-width: 1024px) {
    #photo-overlay  { align-items: center; overflow: hidden; padding: 0; }
    #photo-content  { gap: 6px; }
    #photo-img      { max-height: 68vh; }
    #photo-caption  { font-size: 13px; }
    #photo-close    { font-size: 22px; top: -32px; padding: 4px 8px; }
}

/* Landscape iPad — maximise image, full caption visible */
@media (min-width: 1025px) and (max-width: 1250px) {
    #photo-overlay  { align-items: center; overflow: hidden; padding: 0; }
    #photo-content  { gap: 8px; max-width: 94vw; }
    #photo-img      { max-height: 72vh; max-width: 85vw; }
    #photo-caption  { font-size: 14px; }
    #photo-close    { font-size: 24px; top: -34px; padding: 4px 8px; }
}

@media (max-width: 767px) {
    #photo-content { max-width: 98vw; gap: 6px; }
    #photo-img     { max-height: calc(100vh - 256px - 2 * max(env(safe-area-inset-top, 0px), 6px)); }
    #photo-caption { font-size: 12px; padding: 0 6px 2px; white-space: normal; }
}
