.thanks-letter-modal {
    position: fixed;
    inset: 0;
    z-index: 220;
    display: none;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: 16px 12px;
    padding-top: max(16px, env(safe-area-inset-top));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    padding-left: max(12px, env(safe-area-inset-left));
}

.thanks-letter-modal.is-open {
    display: flex;
}

.thanks-letter-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .5);
}

.thanks-letter-modal__panel {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 960px;
    max-height: min(860px, calc((var(--file-viewer-vh, 1vh) * 100) - 32px));
    overflow: hidden;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 12px 60px rgba(10, 36, 86, .2);
}

.thanks-letter-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    gap: 16px;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(52, 67, 71, .16);
}

.thanks-letter-modal__title {
    min-width: 0;
    margin: 0;
    color: #253437;
    font-size: 16px;
    font-weight: 500;
    line-height: 1.35;
}

.thanks-letter-modal__icon-button {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    color: #7f8a8d;
    background: transparent;
    cursor: pointer;
    transition: opacity .2s ease, background-color .2s ease;
}

.thanks-letter-modal__icon-button:hover {
    opacity: .7;
    background: rgba(52, 67, 71, .08);
}

.thanks-letter-modal__icon-button:focus-visible,
.thanks-letter-modal__secondary-button:focus-visible,
.thanks-letter-modal__primary-button:focus-visible {
    outline: 2px solid #02BBDF;
    outline-offset: 2px;
}

.thanks-letter-modal__secondary-button:hover {
    background: #f3f4f4;
}

.thanks-letter-modal__body {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1 1 auto;
    min-height: 0;
    height: min(72vh, 720px);
    height: min(72dvh, 720px);
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 8px;
    background: #F5F2EB;
}

.thanks-letter-frame,
.thanks-letter-image {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 8px;
    background: #fff;
}

.thanks-letter-image {
    display: none;
    object-fit: contain;
    object-position: center;
}

.thanks-letter-modal--image .thanks-letter-frame {
    display: none;
}

.thanks-letter-modal--image .thanks-letter-image {
    display: block;
}

.thanks-letter-modal__footer {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid rgba(52, 67, 71, .16);
    background: #fff;
}

.thanks-letter-modal__secondary-button,
.thanks-letter-modal__primary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 100%;
    min-height: 42px;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.25;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

.thanks-letter-modal__secondary-button {
    border: 0;
    color: #253437;
    background: #F5F2EB;
}

.thanks-letter-modal__primary-button {
    border: 0;
    color: #fff;
    background: #02BBDF;
}

@media (min-width: 768px) {
    .thanks-letter-modal {
        padding: 28px 24px;
    }

    .thanks-letter-modal__panel {
        max-height: calc(100vh - 56px);
        max-height: calc(100dvh - 56px);
    }

    .thanks-letter-modal__header,
    .thanks-letter-modal__footer {
        padding: 16px 24px;
    }

    .thanks-letter-modal__title {
        font-size: 20px;
    }

    .thanks-letter-modal__body {
        padding: 16px;
    }

    .thanks-letter-modal__footer {
        flex-direction: row;
        align-items: center;
        justify-content: flex-end;
    }

    .thanks-letter-modal__secondary-button,
    .thanks-letter-modal__primary-button {
        width: auto;
    }
}

@media (max-width: 767px) {
    .thanks-letter-modal {
        align-items: stretch;
        padding: 8px;
        padding-top: max(8px, env(safe-area-inset-top));
        padding-right: max(8px, env(safe-area-inset-right));
        padding-bottom: max(8px, env(safe-area-inset-bottom));
        padding-left: max(8px, env(safe-area-inset-left));
    }

    .thanks-letter-modal__panel {
        width: 100%;
        max-width: none;
        height: 100%;
        max-height: 100%;
        border-radius: 12px;
    }

    .thanks-letter-modal__header {
        gap: 10px;
        padding: 10px 12px;
    }

    .thanks-letter-modal__title {
        overflow: hidden;
        font-size: 14px;
        white-space: nowrap;
        text-overflow: ellipsis;
    }

    .thanks-letter-modal__icon-button {
        width: 44px;
        height: 44px;
    }

    .thanks-letter-modal__body {
        height: auto;
        padding: 6px;
    }

    .thanks-letter-frame,
    .thanks-letter-image {
        border-radius: 6px;
    }

    .thanks-letter-modal__footer {
        flex-direction: row;
        align-items: center;
        gap: 8px;
        padding: 10px 12px;
    }

    .thanks-letter-modal__secondary-button,
    .thanks-letter-modal__primary-button {
        min-height: 44px;
        padding: 10px 12px;
        font-size: 13px;
    }

    .thanks-letter-modal__secondary-button {
        flex: 0 0 auto;
        width: auto;
        min-width: 88px;
    }

    .thanks-letter-modal__primary-button {
        flex: 1 1 auto;
        min-width: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .thanks-letter-modal__icon-button {
        transition: none;
    }
}
