/*
 * Coupon Wheel Lead — frontend styles.
 * Every rule is scoped under #hulw-root so nothing leaks into the theme.
 * CSS custom properties are overridden per-store by an inline <style> block
 * emitted alongside this file (see Frontend::build_custom_props()).
 */

/* ── Design tokens (fallbacks; inline vars override these) ──────────── */
#hulw-root {
    --hulw-popup-bg:      #F5EFE0;
    --hulw-title-color:   #1A1A1A;
    --hulw-title-font:    Georgia, 'Times New Roman', serif;
    --hulw-gold:          #BFA15A;
    --hulw-teal:          #1F6F6B;
    --hulw-cream:         #EFE6CE;
    --hulw-input-bg:      #FFFFFF;
    --hulw-input-border:  #D0C9BB;
    --hulw-radius:        10px;
    --hulw-transition:    0.25s ease;

    /* Overridden by inline vars from hulw_appearance */
    --hulw-btn-bg:        #111111;
    --hulw-btn-color:     #FFFFFF;
    --hulw-desc-color:    #333333;
    --hulw-font:          inherit;
}

/* ── Modal overlay ────────────────────────────────────────────────────── */
#hulw-root {
    display: none;
    position: fixed;
    inset: 0;
    /* Above WoodMart's .wd-skip-links (999999) and any other theme fixed elements */
    z-index: 1000001;
    align-items: center;
    justify-content: center;
    padding: 16px;
    font-family: var(--hulw-font);
    box-sizing: border-box;
}

#hulw-root.hulw-open {
    display: flex;
}

.hulw-modal__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    cursor: pointer;
}

/* ── Dialog panel ─────────────────────────────────────────────────────── */
.hulw-modal__panel {
    position: relative;
    z-index: 1;
    background: var(--hulw-popup-bg);
    border-radius: 16px;
    width: 100%;
    max-width: 440px;
    max-height: 92vh;
    overflow-y: auto;
    padding: 36px 32px 28px;
    box-sizing: border-box;
    text-align: center;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
}

/* ── Close button ─────────────────────────────────────────────────────── */
#hulw-root .hulw-modal__close {
    position: absolute !important;
    top: 10px !important;
    right: 12px !important;
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    font-size: 26px !important;
    line-height: 1 !important;
    color: #888 !important;
    cursor: pointer !important;
    padding: 6px 10px !important;
    border-radius: 4px !important;
    transition: color var(--hulw-transition) !important;
    outline: none !important;
    /* Ensure it stays above the wheel SVG on mobile */
    z-index: 2 !important;
    /* Generous tap target for mobile */
    min-width: 44px !important;
    min-height: 44px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

#hulw-root .hulw-modal__close:hover,
#hulw-root .hulw-modal__close:focus-visible {
    color: #1A1A1A !important;
    outline: 2px solid var(--hulw-gold) !important;
    outline-offset: 2px !important;
}

/* ── Title & subtitle ────────────────────────────────────────────────── */
#hulw-root .hulw-modal__title {
    font-family: var(--hulw-title-font) !important;
    font-size: 32px !important;
    font-weight: 700 !important;
    color: var(--hulw-title-color) !important;
    margin: 0 0 8px !important;
    line-height: 1.15 !important;
}

.hulw-modal__subtitle {
    font-size: 15px;
    color: var(--hulw-desc-color);
    margin: 0 0 20px;
    line-height: 1.5;
}

/* ── Wheel container ─────────────────────────────────────────────────── */
.hulw-wheel {
    width: 280px;
    height: 280px;
    margin: 0 auto 20px;
    position: relative;
}

.hulw-wheel-svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
}

/* ── Form ────────────────────────────────────────────────────────────── */
.hulw-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Honeypot — off-screen, invisible, not display:none (detectable by bots) */
.hulw-hp-wrap {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}

.hulw-field {
    width: 100%;
}

.hulw-input {
    width: 100%;
    padding: 12px 14px;
    font-size: 15px;
    border: 1px solid var(--hulw-input-border);
    border-radius: var(--hulw-radius);
    background: var(--hulw-input-bg);
    color: var(--hulw-title-color);
    box-sizing: border-box;
    outline: none;
    transition: border-color var(--hulw-transition), box-shadow var(--hulw-transition);
}

.hulw-input:focus-visible {
    border-color: var(--hulw-gold);
    box-shadow: 0 0 0 3px rgba(191, 161, 90, 0.25);
}

/* ── Primary button ──────────────────────────────────────────────────── */
/* !important overrides WoodMart / WooCommerce generic button resets */
#hulw-root .hulw-btn {
    display: block !important;
    width: 100% !important;
    padding: 14px !important;
    font-size: 15px !important;
    font-weight: 700 !important;
    letter-spacing: 0.04em !important;
    text-transform: uppercase !important;
    color: var(--hulw-btn-color) !important;
    background: var(--hulw-btn-bg) !important;
    border: none !important;
    border-radius: var(--hulw-radius) !important;
    box-shadow: none !important;
    cursor: pointer !important;
    text-align: center !important;
    text-decoration: none !important;
    transition: opacity var(--hulw-transition) !important;
    line-height: 1.4 !important;
    box-sizing: border-box !important;
}

#hulw-root .hulw-btn:disabled {
    opacity: 0.4 !important;
    cursor: not-allowed !important;
}

#hulw-root .hulw-btn:not(:disabled):hover,
#hulw-root .hulw-btn:not(:disabled):focus-visible {
    opacity: 0.85 !important;
    outline: 2px solid var(--hulw-gold) !important;
    outline-offset: 2px !important;
}

/* Secondary / outline variant for copy + shop-now in result */
#hulw-root .hulw-btn--copy {
    background: transparent !important;
    color: var(--hulw-btn-bg) !important;
    border: 2px solid var(--hulw-btn-bg) !important;
}

#hulw-root .hulw-btn--shop {
    display: block !important;
    text-decoration: none !important;
    text-align: center !important;
}

/* ── Consent checkboxes ──────────────────────────────────────────────── */
.hulw-consent {
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
}

.hulw-consent__row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    cursor: pointer;
}

.hulw-consent__row input[type="checkbox"] {
    margin-top: 3px;
    flex-shrink: 0;
    accent-color: var(--hulw-teal);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.hulw-consent__text {
    font-size: 12px;
    color: #666;
    line-height: 1.5;
}

/* Links inside consent labels (terms / privacy policy) */
.hulw-consent__text a {
    color: var(--hulw-teal);
    text-decoration: underline;
}

.hulw-consent__text a:hover,
.hulw-consent__text a:focus-visible {
    text-decoration: none;
}

/* ── Result area ─────────────────────────────────────────────────────── */
.hulw-result {
    padding: 8px 0;
}

.hulw-result__message {
    font-size: 16px;
    font-weight: 600;
    color: var(--hulw-title-color);
    margin: 0 0 16px;
}

.hulw-result__code {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: 4px;
    color: var(--hulw-title-color);
    background: var(--hulw-cream);
    border-radius: 8px;
    padding: 12px 24px;
    margin: 0 0 8px;
    display: inline-block;
}

.hulw-result__email-note {
    font-size: 12px;
    color: #777;
    margin: 0 0 16px;
}

.hulw-result__actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 16px;
}

.hulw-result__error {
    font-size: 14px;
    color: #c0392b;
    margin: 0;
}

/* ── Decline link ────────────────────────────────────────────────────── */
/* Styled as a small muted text link; !important guards against theme resets */
#hulw-root .hulw-decline {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    font-size: 12px !important;
    font-weight: normal !important;
    text-transform: none !important;
    letter-spacing: normal !important;
    color: #999 !important;
    text-decoration: underline !important;
    cursor: pointer !important;
    margin-top: 10px !important;
    padding: 4px 0 !important;
    display: block !important;
    width: auto !important;
    text-align: center !important;
    transition: color var(--hulw-transition) !important;
    line-height: 1.5 !important;
}

#hulw-root .hulw-decline:hover,
#hulw-root .hulw-decline:focus-visible {
    color: #555 !important;
    outline: none !important;
}

/* ── Minimised launcher (floating wheel icon) ────────────────────────── */
/* Sibling of #hulw-root, so it carries its own reset-proof rules instead of
   relying on the #hulw-root scope. Sits at the bottom-LEFT, inset from the
   very corner, because WoodMart's .scrollToTop ("Goto Top") button occupies
   the bottom-right on this theme. */
#hulw-launcher {
    /* Distance from the chosen edge; lowered on mobile in the media query. */
    --hulw-gap: 28px;
    position: fixed !important;
    /* Just below the open modal (#hulw-root = 1000001); above theme chrome. */
    z-index: 1000000 !important;
    width: 58px !important;
    height: 58px !important;
    padding: 5px !important;
    margin: 0 !important;
    border: none !important;
    border-radius: 50% !important;
    background: var(--hulw-popup-bg) !important;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28) !important;
    cursor: pointer !important;
    line-height: 0 !important;
    box-sizing: border-box !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease !important;
}

#hulw-launcher[hidden] {
    display: none !important;
}

/* Placement modifiers (admin-configurable). The middle positions use a
   negative margin instead of translateY so the hover scale transform below
   doesn't fight the vertical centring.
   --hulw-sticky-offset is set by JS to the total bottom distance needed to
   clear a visible sticky add-to-cart bar (WoodMart .wd-sticky-btn on desktop,
   #hf-mobile-sticky-atc on mobile) — bar height plus a small gap. max() means
   it only ever raises the icon, never lowers it below the normal corner inset;
   it defaults to 0 (no bar). */
.hulw-launcher--bottom-left  { left:  var(--hulw-gap) !important; bottom: max(var(--hulw-gap), var(--hulw-sticky-offset, 0px)) !important; }
.hulw-launcher--bottom-right { right: var(--hulw-gap) !important; bottom: max(var(--hulw-gap), var(--hulw-sticky-offset, 0px)) !important; }
.hulw-launcher--top-left     { left:  var(--hulw-gap) !important; top:    var(--hulw-gap) !important; }
.hulw-launcher--top-right    { right: var(--hulw-gap) !important; top:    var(--hulw-gap) !important; }
.hulw-launcher--center-left  { left:  var(--hulw-gap) !important; top: 50% !important; margin-top: -29px !important; }
.hulw-launcher--center-right { right: var(--hulw-gap) !important; top: 50% !important; margin-top: -29px !important; }

#hulw-launcher:hover,
#hulw-launcher:focus-visible {
    transform: scale(1.06) rotate(-8deg) !important;
    box-shadow: 0 8px 26px rgba(0, 0, 0, 0.35) !important;
    outline: none !important;
}

.hulw-launcher__wheel,
.hulw-launcher__wheel svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
}

/* Entrance + attention animations are applied as classes (added/removed by
   JS) rather than on the base rule, so removing the shake never re-triggers
   the entrance. ID-level specificity ensures they win over the base rule. */
#hulw-launcher.hulw-launcher--intro {
    animation: hulw-launcher-in 0.3s ease both;
}

#hulw-launcher.hulw-launcher--shake {
    animation: hulw-launcher-shake 0.8s ease-in-out;
}

@keyframes hulw-launcher-in {
    from { transform: translateY(12px) scale(0.6); opacity: 0; }
    to   { transform: translateY(0)    scale(1);   opacity: 1; }
}

/* Side-to-side shake to draw the eye (a vibration, not a rotation). */
@keyframes hulw-launcher-shake {
    0%, 100% { transform: translateX(0); }
    10%      { transform: translateX(-6px); }
    20%      { transform: translateX(6px); }
    30%      { transform: translateX(-5px); }
    40%      { transform: translateX(5px); }
    50%      { transform: translateX(-4px); }
    60%      { transform: translateX(4px); }
    70%      { transform: translateX(-2px); }
    80%      { transform: translateX(2px); }
    90%      { transform: translateX(-1px); }
}

/* ── Screen-reader only ──────────────────────────────────────────────── */
.hulw-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── Prevent body scroll when modal is open ──────────────────────────── */
body.hulw-body-open {
    overflow: hidden;
}

/* ── Fix: CSS display value overrides [hidden] UA stylesheet rule ─────── */
/* .hulw-form{display:flex}, .hulw-decline{display:block}, .hulw-wheel has
   no explicit display but guard it too. Without !important the UA's
   [hidden]{display:none} loses to any authored display rule. */
#hulw-root .hulw-form[hidden],
#hulw-root .hulw-decline[hidden],
#hulw-root .hulw-wheel[hidden] {
    display: none !important;
}

/* ── Reduced motion ──────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    #hulw-root,
    #hulw-root *,
    #hulw-launcher {
        transition: none !important;
        animation: none !important;
    }
}

/* ── Responsive layout ───────────────────────────────────────────────── */

/* Use dynamic viewport height where supported so the panel accounts for
   the on-screen keyboard and browser chrome on mobile. */
.hulw-modal__panel {
    /* dvh / svh fall back to vh in browsers that don't support them */
    max-height: min(92vh, 92dvh);
}

/* ── Mobile width (≤ 480 px) ─────────────────────────────────────────── */
@media (max-width: 480px) {
    #hulw-root {
        padding: 12px;
        /* Keep popup centred so it reads as an overlay, not a page */
        align-items: center;
        /* Honour iOS notch / dynamic island safe area at the top */
        padding-top: max(12px, env(safe-area-inset-top, 12px));
        padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
    }

    .hulw-modal__panel {
        padding: 28px 20px 20px;
        border-radius: 14px;
        max-height: min(90vh, 90dvh);
    }

    #hulw-root .hulw-modal__title {
        font-size: 26px !important;
        margin-bottom: 4px !important;
    }

    .hulw-modal__subtitle {
        font-size: 14px;
        margin-bottom: 12px;
    }

    .hulw-wheel {
        width: 220px;
        height: 220px;
        margin-bottom: 12px;
    }

    .hulw-form {
        gap: 10px;
    }

    #hulw-root .hulw-btn {
        padding: 12px !important;
        font-size: 14px !important;
    }

    /* 16px minimum prevents iOS Safari from auto-zooming on input focus */
    .hulw-input {
        font-size: 16px;
    }

    .hulw-consent__text {
        font-size: 11px;
    }

    /* Slightly smaller launcher with a tighter inset on phones; still clear
       of the bottom-right Goto Top button. */
    #hulw-launcher {
        --hulw-gap: 18px;
        width: 50px !important;
        height: 50px !important;
    }
    /* Re-centre the middle positions for the smaller icon (half of 50px). */
    .hulw-launcher--center-left,
    .hulw-launcher--center-right {
        margin-top: -25px !important;
    }
}

/* ── Short viewport — keyboard open or small device (≤ 640 px tall) ─── */
@media (max-height: 640px) {
    .hulw-modal__panel {
        padding: 16px 18px 12px;
        max-height: min(98vh, 98dvh);
    }

    #hulw-root .hulw-modal__title {
        font-size: 22px !important;
        margin-bottom: 2px !important;
    }

    .hulw-modal__subtitle {
        font-size: 13px;
        margin-bottom: 8px;
    }

    .hulw-wheel {
        width: 190px;
        height: 190px;
        margin-bottom: 8px;
    }

    .hulw-form {
        gap: 8px;
    }

    .hulw-consent {
        gap: 6px;
    }

    #hulw-root .hulw-decline {
        margin-top: 6px !important;
    }
}

/* ── Very short — keyboard fully open on small phone (≤ 480 px tall) ── */
@media (max-height: 480px) {
    .hulw-wheel {
        width: 150px;
        height: 150px;
        margin-bottom: 6px;
    }

    .hulw-modal__subtitle {
        display: none; /* hide subtitle to save space */
    }
}

/* ── Narrow phone (≤ 360 px wide) ───────────────────────────────────── */
@media (max-width: 360px) {
    .hulw-modal__panel {
        padding: 18px 14px 12px;
    }

    .hulw-wheel {
        width: 190px;
        height: 190px;
    }
}
