/* Puzzle Search Popup v1.2.0 */

/* Core trigger behavior only. Visual appearance is inherited from the theme in Theme mode. */
.psp-trigger {
    cursor: pointer;
    font: inherit;
}

.psp-trigger-button {
    width: 100%;
}

.psp-trigger-icon-only {
    min-width: 44px;
    min-height: 44px;
}

/* Popup mechanics */
.psp-root {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: grid;
    place-items: center;
    padding: 24px;
    direction: rtl;
}
.psp-root[hidden] {
    display: none !important;
}

.psp-backdrop {
    position: absolute;
    inset: 0;
    background: var(--psp-overlay, rgba(0,0,0,.48));
    -webkit-backdrop-filter: blur(var(--psp-blur, 7px));
    backdrop-filter: blur(var(--psp-blur, 7px));
    opacity: 0;
    transition: opacity .2s ease;
}

.psp-dialog {
    position: relative;
    z-index: 2;
    width: min(var(--psp-width, 80vw), calc(100vw - 48px));
    max-width: var(--psp-max-width, 1200px);
    max-height: min(82vh, 900px);
    max-height: min(82dvh, 900px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(14px) scale(.985);
    transition: opacity .2s ease, transform .2s ease;
    outline: 0;
}

.psp-root.psp-open .psp-backdrop {
    opacity: 1;
}
.psp-root.psp-open .psp-dialog {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.psp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 58px;
    padding: 12px 16px 12px 12px;
    flex: 0 0 auto;
}

.psp-title {
    margin: 0;
    padding: 0;
    font: inherit;
    font-size: 1.05em;
    font-weight: inherit;
    line-height: 1.4;
}

.psp-close {
    min-width: 42px;
    min-height: 42px;
    display: grid;
    place-items: center;
    flex: 0 0 42px;
    cursor: pointer;
    font: inherit;
    font-size: 28px;
    line-height: 1;
}

.psp-body {
    padding: 18px;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.psp-status {
    padding: 12px 14px;
    margin-bottom: 12px;
    font: inherit;
}

body.psp-scroll-locked {
    overflow: hidden !important;
    touch-action: none;
}

/* Do not restyle the search shortcode itself. */
.psp-content,
.psp-content * {
    box-sizing: border-box;
}

.psp-content input,
.psp-content select,
.psp-content textarea,
.psp-content button {
    max-width: 100%;
}

/* Theme mode:
   Intentionally avoids forcing colors, borders, backgrounds, shadows,
   radii, typography, hover states, or button skinning. */
.psp-style-theme .psp-dialog {
    background: inherit;
    color: inherit;
}

.psp-style-theme .psp-header,
.psp-style-theme .psp-close,
.psp-style-theme .psp-title,
.psp-style-theme .psp-trigger {
    color: inherit;
}

.psp-style-theme .psp-close,
.psp-style-theme .psp-trigger {
    background: inherit;
    border-color: inherit;
    border-style: inherit;
    border-width: inherit;
    border-radius: inherit;
}

/* Give the modal a neutral container only if the theme does not provide one.
   The search shortcode's own CSS remains untouched. */
.psp-style-theme .psp-dialog {
    background-color: var(--mfn-background-color, var(--content-bg, #fff));
}

/* Custom mode keeps the previous self-contained appearance. */
.psp-style-custom .psp-trigger-button {
    min-height: 46px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border: 0;
    border-radius: 10px;
    background: #1f2937;
    color: #fff;
    transition: transform .16s ease, opacity .16s ease;
}
.psp-style-custom .psp-trigger-button:hover {
    opacity: .92;
}
.psp-style-custom .psp-trigger-button:active {
    transform: scale(.985);
}

.psp-style-custom .psp-trigger-icon-only {
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: #1f2937;
    color: #fff;
    display: inline-grid;
    place-items: center;
    font-size: 26px;
    line-height: 1;
}

.psp-style-custom .psp-dialog {
    background: #fff;
    color: #111827;
    border-radius: 18px;
    box-shadow: 0 24px 80px rgba(0,0,0,.28);
}

.psp-style-custom .psp-header {
    border-bottom: 1px solid #e5e7eb;
}

.psp-style-custom .psp-title {
    font-size: 18px;
    font-weight: 700;
}

.psp-style-custom .psp-close {
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 50%;
    background: #f3f4f6;
    color: #111827;
}
.psp-style-custom .psp-close:hover {
    background: #e5e7eb;
}

.psp-style-custom .psp-status {
    border-radius: 10px;
    background: #f3f4f6;
    font-size: 14px;
}
.psp-style-custom .psp-status.psp-error {
    background: #fff1f2;
    color: #991b1b;
}

/* Prevent iOS Safari from zooming into form fields. */
@supports (-webkit-touch-callout: none) {
    .psp-content input,
    .psp-content select,
    .psp-content textarea {
        font-size: 16px !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .psp-backdrop,
    .psp-dialog,
    .psp-trigger {
        transition: none !important;
    }
}

/* Safe default mobile fallback; selected breakpoint is also emitted dynamically by PHP. */
@media (max-width: 768px) {
    .psp-root {
        padding: 0;
        align-items: stretch;
    }

    .psp-dialog {
        width: 100%;
        max-width: none;
        max-height: none;
        border-radius: 0;
    }

    .psp-header {
        padding-top: max(12px, env(safe-area-inset-top));
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }

    .psp-body {
        padding-left: max(14px, env(safe-area-inset-left));
        padding-right: max(14px, env(safe-area-inset-right));
        padding-bottom: max(18px, env(safe-area-inset-bottom));
    }

    .psp-mobile-fullscreen .psp-dialog {
        height: 100vh;
        height: 100dvh;
    }

    .psp-mobile-sheet {
        align-items: end;
    }
    .psp-mobile-sheet .psp-dialog {
        height: auto;
        max-height: 88vh;
        max-height: 88dvh;
        border-radius: 22px 22px 0 0;
        transform: translateY(30px);
    }
    .psp-mobile-sheet.psp-open .psp-dialog {
        transform: translateY(0);
    }

    .psp-mobile-center {
        padding: 12px;
        align-items: center;
    }
    .psp-mobile-center .psp-dialog {
        width: calc(100vw - 24px);
        height: auto;
        max-height: 82vh;
        max-height: 82dvh;
        border-radius: 16px;
    }

    .psp-close {
        min-width: 46px;
        min-height: 46px;
        flex-basis: 46px;
    }
}
