html {
    scrollbar-gutter: stable;
}

body.modal-open {
    overflow: hidden;
    touch-action: none;
}

.download-container {
    direction: rtl;
    --row-accent-color: #e40d75;
    --row-primary-gradient: linear-gradient(135deg, #e40d75 0%, #8e1ef7 52%, #2871e4 100%);
    --row-surface-bg: #ffffff;
    --row-border-color: #e5e7eb;
    --row-info-size: 34px;
    --row-radius-circle: 999px;
    --row-transition-speed: 0.25s;
}

.modal-overlay {
    --m-accent: #8e1ef7;
    --m-surface: #ffffff;
    --m-border: rgba(15, 23, 42, 0.08);
    --m-overlay-bg: rgba(15, 23, 42, 0.56);
    --m-white: #ffffff;
    --m-shadow: 0 20px 45px rgba(15, 23, 42, 0.16), 0 8px 24px rgba(15, 23, 42, 0.08);
    --m-shadow-soft: 0 6px 18px rgba(15, 23, 42, 0.06);
    --m-title-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
    --m-close-shadow: 0 10px 24px rgba(15, 23, 42, 0.16);
    --m-radius: 22px;
    --m-title-radius: 16px;
    --m-box-radius: 14px;
    --m-close-radius: 999px;
    --m-z: 2147483647;
    --m-overlay-padding: clamp(12px, 4vw, 28px);
    --m-content-width: min(94vw, 480px);
    --m-content-max-height: min(88vh, 88dvh);
    --m-content-padding-bottom: 24px;
    --m-hero-height: 92px;
    --m-title-padding: 14px 20px;
    --m-title-margin: -30px auto 20px;
    --m-title-max-width: calc(100% - 48px);
    --m-inner-padding: 0 22px;
    --m-box-padding: 14px 16px;
    --m-box-gap: 10px;
    --m-close-size: 38px;
    --m-close-offset: 14px;
    --m-close-line-width: 13px;
    --m-close-line-height: 2px;
    --juz-page-badge-size: 34px;
    --juz-page-radius-circle: 999px;
    --juz-page-badge-bg: #E5E7EB;
    --juz-page-badge-text: inherit;

    display: none;
    position: fixed;
    inset: 0;
    z-index: var(--m-z);
    align-items: center;
    justify-content: center;
    padding: var(--m-overlay-padding);
    background: var(--m-overlay-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    isolation: isolate;
}

.modal-overlay,
.modal-overlay * {
    box-sizing: border-box;
}

.modal-overlay.active {
    display: flex;
    animation: modalFadeIn 0.26s ease;
}

.modal-overlay .modal-content {
    position: relative;
    width: var(--m-content-width);
    max-width: 100%;
    max-height: var(--m-content-max-height);
    padding: 0 0 var(--m-content-padding-bottom);
    overflow-x: hidden;
    overflow-y: auto;
    direction: rtl;
    background: var(--m-surface);
    border: 1px solid var(--m-border);
    border-radius: var(--m-radius);
    box-shadow: var(--m-shadow);
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    animation: modalScaleIn 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.modal-overlay .modal-content::before {
    content: "";
    display: block;
    height: var(--m-hero-height);
    background: linear-gradient(135deg, #e40d75 0%, #8e1ef7 50%, #2871e4 100%);
}

.modal-overlay .modal-close {
    position: absolute;
    top: var(--m-close-offset);
    inset-inline-start: var(--m-close-offset);
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--m-close-size);
    height: var(--m-close-size);
    padding: 0;
    color: var(--m-white);
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: var(--m-close-radius);
    box-shadow: var(--m-close-shadow);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    cursor: pointer;
    transition:
        background-color 0.2s ease,
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        transform 0.2s ease;
}

.modal-overlay .modal-close::before,
.modal-overlay .modal-close::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: var(--m-close-line-width);
    height: var(--m-close-line-height);
    background: currentColor;
    border-radius: 999px;
}

.modal-overlay .modal-close::before {
    transform: translate(-50%, -50%) rotate(45deg);
}

.modal-overlay .modal-close::after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

.modal-overlay .modal-close:hover {
    background: rgba(255, 255, 255, 0.22);
    border-color: rgba(255, 255, 255, 0.42);
    box-shadow: 0 14px 28px rgba(15, 23, 42, 0.2);
    transform: translateY(-1px) scale(1.03);
}

.modal-overlay .modal-close:active,
.download-container .info-icon:active {
    transform: scale(0.96);
}

.modal-overlay .modal-close:focus-visible {
    outline: 2px solid var(--m-white);
    outline-offset: 2px;
}

.modal-overlay .modal-title {
    position: relative;
    display: block;
    width: fit-content;
    max-width: var(--m-title-max-width);
    margin: var(--m-title-margin);
    padding: var(--m-title-padding);
    color: var(--wp--preset--color--contrast, CanvasText);
    text-align: center;
    background: #E5E7EB;
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: var(--m-title-radius);
    box-shadow: var(--m-title-shadow);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.modal-overlay :is(.modal-text, .juz-modal-text, .modal-pages) {
    padding: var(--m-inner-padding);
}

.modal-overlay :is(.modal-text, .juz-modal-text) {
    text-align: justify;
    text-justify: inter-word;
}

.modal-overlay .modal-pages {
    text-align: center;
}

.modal-overlay :is(.modal-text, .juz-modal-text, .modal-pages) p {
    margin: 0 0 var(--m-box-gap);
    padding: var(--m-box-padding);
    background: var(--m-surface);
    border: 1px solid var(--m-border);
    border-radius: var(--m-box-radius);
    box-shadow: var(--m-shadow-soft);
}

.modal-overlay :is(.modal-text, .juz-modal-text, .modal-pages) p:empty {
    display: none;
}

.modal-overlay :is(.modal-text, .juz-modal-text, .modal-pages) p:last-child {
    margin-bottom: 0;
}

.modal-overlay .modal-text p {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--m-box-gap);
}

.modal-overlay .modal-text p span {
    color: var(--m-accent);
}

.modal-overlay .modal-pages p {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0;
    text-align: center;
}

.modal-overlay .circle-page {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: var(--juz-page-badge-size);
    aspect-ratio: 1;
    margin: 0 4px;
    padding: 0;
    color: var(--juz-page-badge-text);
    background: var(--juz-page-badge-bg);
    border-radius: var(--juz-page-radius-circle);
    box-shadow: none;
    user-select: none;
    vertical-align: middle;
}

.download-container .info-icon {
    appearance: none;
    -webkit-appearance: none;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: var(--row-info-size);
    height: var(--row-info-size);
    aspect-ratio: 1;
    margin: 0;
    padding: 0;
    color: inherit;
    font-size: calc(var(--row-info-size) * 0.52);
    line-height: 1;
    vertical-align: middle;
    background: var(--row-surface-bg);
    border: 1px solid var(--row-border-color);
    border-radius: var(--row-radius-circle);
    box-shadow: none;
    filter: none;
    overflow: visible;
    cursor: pointer;
    touch-action: manipulation;
    transition:
        color var(--row-transition-speed) ease,
        background var(--row-transition-speed) ease,
        border-color var(--row-transition-speed) ease,
        transform var(--row-transition-speed) ease;
}

.download-container .info-icon:is(:hover, :focus-visible) {
    color: #ffffff;
    background: var(--row-primary-gradient);
    border-color: transparent;
    box-shadow: none;
    filter: none;
    transform: none;
}

.download-container .info-icon:focus-visible {
    outline: 2px solid var(--row-accent-color);
    outline-offset: 2px;
}

.download-container .info-icon svg {
    display: block;
    width: 1em;
    height: 1em;
    fill: currentColor;
    stroke: currentColor;
    overflow: visible;
}

.download-container .info-icon :is(i, span) {
    display: block;
    color: currentColor;
    line-height: 1;
}

.modal-overlay :is(strong, b) {
    font-weight: inherit;
}

.modal-overlay .modal-content::-webkit-scrollbar {
    width: 7px;
}

.modal-overlay .modal-content::-webkit-scrollbar-track {
    background: transparent;
}

.modal-overlay .modal-content::-webkit-scrollbar-thumb {
    background: rgba(15, 23, 42, 0.16);
    border-radius: 999px;
}

@media (max-width: 768px) {
    .modal-overlay {
        --m-hero-height: 84px;
    }
}

@media (max-width: 520px) {
    .download-container {
        --row-info-size: 30px;
    }
}

@media (max-width: 480px) {
    .modal-overlay {
        --m-content-width: 96vw;
        --m-inner-padding: 0 16px;
        --m-title-margin: -28px auto 16px;
        --m-title-max-width: calc(100% - 32px);
        --juz-page-badge-size: 30px;
        --m-close-offset: 12px;
    }

    .modal-overlay :is(.modal-text, .juz-modal-text, .modal-pages) p {
        padding: 12px 14px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .modal-overlay,
    .modal-overlay *,
    .modal-overlay .modal-content::before {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }

    .download-container .info-icon {
        transition: none;
    }
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes modalScaleIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.985);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}
