/* Base 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.8);
}

.modal.hidden {
    display: none;
}

.modal-content {
    position: relative;
    margin: auto;
    padding: 20px;
    width: 80%;
    max-width: 700px;
    text-align: center;
    top: 50%;
    transform: translateY(-50%);
}

.close-button {
    color: #fff;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    margin-bottom: 10px;
}

/* Present Modal Specific Styles */
#present-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg,
            rgba(253, 235, 170, 0.95),
            rgba(255, 223, 128, 0.95));
    padding: 20px;
    border-radius: 20px;
    z-index: 22000;
    display: none;
    grid-template-rows: minmax(0, 1fr) auto auto;
    justify-items: center;
    align-items: center;
    gap: 12px;
    width: 85vw;
    max-width: 800px;
    height: min(85vh, 760px);
    height: min(85dvh, 760px);
    max-height: calc(100vh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    overflow: hidden;
    box-sizing: border-box;
    isolation: isolate;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    transition: opacity 0.2s ease;
}

#present-modal.hidden {
    opacity: 0;
    pointer-events: none;
}

#present-modal:not(.hidden) {
    display: grid !important;
    opacity: 1;
    pointer-events: auto;
}

#present-modal img {
    min-width: 0;
    min-height: 0;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    transform: scale(0.95);
    transition: transform 0.2s ease-out;
    border-radius: 15px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
    touch-action: pinch-zoom;
}

#close-modal {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 18px;
    color: #8B4513;
    cursor: pointer;
    z-index: 1001;
    background-color: rgba(255, 255, 255, 0.9);
    padding: 4px;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(139, 69, 19, 0.3);
}

#close-modal:hover {
    background-color: white;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    color: #5C2C0E;
}

/* Image and Description Styles */
#present-image {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.3s ease, transform 0.3s ease;
    touch-action: pinch-zoom;
}

#present-image.enlarged {
    opacity: 1;
    transform: scale(1);
}

#image-description {
    color: white;
    margin: 0;
    padding: 12px 16px;
    font-size: clamp(0.95rem, 4vw, 1.2rem);
    line-height: 1.4;
    display: none;
    white-space: pre-line;
    width: 100%;
    max-width: 100%;
    max-height: min(28vh, 14rem);
    max-height: min(28dvh, 14rem);
    overflow-y: auto;
    box-sizing: border-box;
    border-radius: 12px;
    background: rgba(62, 38, 13, 0.92);
    text-shadow: none;
    scrollbar-gutter: stable;
    position: relative;
    z-index: 1;
    text-align: center;
    unicode-bidi: plaintext;
}

/* Navigation Dots Styles */
.navigation-dots {
    text-align: center;
    margin: 0;
    min-height: 10px;
}

.dot {
    height: 10px;
    width: 10px;
    margin: 0 4px;
    background-color: #bbb;
    border-radius: 50%;
    display: inline-block;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.dot.active {
    background-color: #fff;
}

/* Responsive Styles */
@media (max-width: 768px) {
    #present-modal {
        width: calc(100vw - 24px);
        height: min(88vh, 760px);
        height: min(88dvh, 760px);
        max-height: calc(100vh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        max-height: calc(100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        padding: 12px;
        margin-bottom: 0;
        gap: 8px;
    }

    #present-modal img {
        max-height: 100%;
    }

    #image-description {
        padding: 10px 14px;
        margin: 0;
    }
}

@media (max-width: 480px) {
    #image-description {
        padding: 10px 12px;
        margin: 0;
    }
}

/* Image Counter Styles */
#image-counter {
    position: absolute;
    top: 10px;
    left: 10px;
    color: black;
    font-size: 16px;
    text-align: center;
    z-index: 1002;
    background-color: white;
    animation: flash 1s ease-in-out infinite alternate;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 30px;
}

/*
 * Keep the authored portrait composition intact on pointer-driven desktop
 * screens. Phones remain immersive and fill their viewport; larger screens
 * present the same experience inside a centered 4:5 card stage.
 */
@media (min-width: 769px) and (hover: hover) and (pointer: fine) {
    :root {
        --card-stage-height: min(900px, calc(100vh - 48px));
        --card-stage-width: min(720px, calc(80vh - 38.4px));
        --card-stage-top: calc((100vh - var(--card-stage-height)) / 2);
        --card-stage-left: calc((100vw - var(--card-stage-width)) / 2);
    }

    @supports (height: 100dvh) {
        :root {
            --card-stage-height: min(900px, calc(100dvh - 48px));
            --card-stage-width: min(720px, calc(80dvh - 38.4px));
            --card-stage-top: calc((100dvh - var(--card-stage-height)) / 2);
            --card-stage-left: calc((100dvw - var(--card-stage-width)) / 2);
        }
    }

    body,
    html {
        background: #111014;
    }

    #main-content {
        top: var(--card-stage-top);
        left: var(--card-stage-left);
        width: var(--card-stage-width);
        height: var(--card-stage-height);
    }

    #main-content {
        position: fixed;
        overflow: hidden;
        border-radius: 18px;
        box-shadow: 0 24px 72px rgba(0, 0, 0, 0.5);
    }

    .background,
    #blessing-modal,
    #confetti-canvas {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
    }

    .background {
        background-attachment: scroll;
    }

    #presents-container {
        pointer-events: none;
    }

    #presents-container .present,
    #presents-container #youtube-video-tile {
        pointer-events: auto;
    }

    #present-modal {
        width: min(800px, calc(var(--card-stage-width) - 24px));
        height: min(760px, calc(var(--card-stage-height) - 24px));
        max-height: calc(var(--card-stage-height) - 24px);
    }

    #close-blessing-modal {
        position: absolute;
        top: 20px;
        right: 20px;
    }

    .footer {
        left: var(--card-stage-left);
        right: auto;
        bottom: var(--card-stage-top);
        width: var(--card-stage-width);
        box-sizing: border-box;
        border-radius: 0 0 18px 18px;
    }

    .report-blessing {
        position: absolute;
    }

    #mute-btn,
    .loading-mute-btn {
        right: calc(var(--card-stage-left) + 6px);
        bottom: calc(var(--card-stage-top) + 8px);
    }
}

@keyframes flash {
    from {
        opacity: 1;
    }

    to {
        opacity: 0.5;
    }
}
