/* ============================================================
   Checkout Urgency Coupon — Modal Styles
   Mobile-first, tested on iOS Safari, Chrome Android, Samsung Browser
   ============================================================ */

:root {
    --cuc-primary:    #FF4F00;
    --cuc-primary-dk: #cc3e00;
    --cuc-success:    #22c55e;
    --cuc-dark:       #1a1a2e;
    --cuc-mid:        #16213e;
    --cuc-text:       #f8f9fa;
    --cuc-text-muted: #adb5bd;
    --cuc-radius:     16px;
    --cuc-shadow:     0 25px 80px rgba(0,0,0,.55);
    --cuc-code-bg:    #0f3460;
    --cuc-timer-bg:   #0d0d1a;
}

/* ---- Overlay ---- */
.cuc-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    /* Fallback for browsers that don't support inset */
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Extra padding-bottom on mobile accounts for browser chrome (address bar) */
    padding: 16px 16px 80px;
    opacity: 0;
    transition: opacity 0.3s ease;
    /* Prevent scroll-through on iOS */
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
    /* Use will-change to promote to own layer — fixes invisible overlay bug
       on some Android WebViews when combined with backdrop-filter */
    will-change: opacity;
}

/* Backdrop blur — keep as progressive enhancement only.
   Some older Android WebViews crash or show transparent overlays with
   backdrop-filter, so we apply it only when the browser actually supports it. */
@supports ((-webkit-backdrop-filter: blur(4px)) or (backdrop-filter: blur(4px))) {
    .cuc-overlay {
        -webkit-backdrop-filter: blur(4px);
        backdrop-filter: blur(4px);
    }
}

.cuc-overlay.cuc-visible {
    opacity: 1;
}

.cuc-overlay[hidden] {
    display: none !important;
}

/* ---- Modal box ---- */
.cuc-modal {
    background: var(--cuc-dark);
    border-radius: var(--cuc-radius);
    box-shadow: var(--cuc-shadow);
    max-width: 480px;
    width: 100%;
    /* Let the modal be taller than the visible viewport on small screens,
       with the overlay handling scroll — prevents content clipping. */
    max-height: none;
    position: relative;
    transform: translateY(30px) scale(0.96);
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
    opacity: 0;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.08);
    /* Prevents iOS bounce-scroll from propagating to the page */
    -webkit-overflow-scrolling: touch;
    /* Ensure it stacks correctly on Android */
    isolation: isolate;
}

.cuc-overlay.cuc-visible .cuc-modal {
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* Top accent stripe */
.cuc-modal::before {
    content: '';
    display: block;
    height: 4px;
    background: linear-gradient(90deg, var(--cuc-primary), #ff8c00, #ffd700);
}

/* ---- Close button ---- */
.cuc-close {
    position: absolute;
    top: 14px;
    right: 14px;
    background: rgba(255,255,255,0.1);
    border: none;
    color: var(--cuc-text);
    /* Minimum 44×44px tap target for iOS HIG compliance */
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    z-index: 2;
    /* Prevent text selection on double-tap */
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

.cuc-close:hover,
.cuc-close:active {
    background: rgba(255,255,255,0.2);
}

/* ---- Inner content ---- */
.cuc-modal-inner {
    padding: 32px 32px 28px;
    text-align: center;
    position: relative;
}

/* ---- Confetti ---- */
.cuc-confetti {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    pointer-events: none;
    overflow: hidden;
    height: 60px;
}

.cuc-confetti span {
    position: absolute;
    top: -10px;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    animation: cuc-fall 2.5s ease-out forwards;
    opacity: 0;
}

.cuc-confetti span:nth-child(1)  { left: 10%;  background: #ffd700; animation-delay: 0.10s; }
.cuc-confetti span:nth-child(2)  { left: 25%;  background: #ff4f00; animation-delay: 0.25s; transform: rotate(45deg); }
.cuc-confetti span:nth-child(3)  { left: 42%;  background: #22c55e; animation-delay: 0.05s; }
.cuc-confetti span:nth-child(4)  { left: 58%;  background: #60a5fa; animation-delay: 0.35s; transform: rotate(30deg); }
.cuc-confetti span:nth-child(5)  { left: 70%;  background: #ffd700; animation-delay: 0.15s; }
.cuc-confetti span:nth-child(6)  { left: 82%;  background: #ff4f00; animation-delay: 0.45s; }
.cuc-confetti span:nth-child(7)  { left: 5%;   background: #a78bfa; animation-delay: 0.55s; }
.cuc-confetti span:nth-child(8)  { left: 35%;  background: #ffd700; animation-delay: 0.30s; }
.cuc-confetti span:nth-child(9)  { left: 65%;  background: #22c55e; animation-delay: 0.60s; }
.cuc-confetti span:nth-child(10) { left: 90%;  background: #ff8c00; animation-delay: 0.20s; }

@keyframes cuc-fall {
    0%   { top: -10px; opacity: 1; }
    100% { top: 70px;  opacity: 0; transform: translateX(20px) rotate(360deg); }
}

/* ---- Title ---- */
.cuc-title {
    color: var(--cuc-text);
    font-size: 22px;
    font-weight: 700;
    margin: 8px 0 12px;
    line-height: 1.3;
}

/* ---- Body ---- */
.cuc-body {
    color: var(--cuc-text-muted);
    font-size: 14px;
    line-height: 1.6;
    margin: 0 0 20px;
}

/* tokens inside .cuc-body are bold for emphasis; colour inherits from .cuc-body */
.cuc-body strong { font-weight: 700; }

/* ---- Coupon code block ---- */
.cuc-coupon-block {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--cuc-code-bg);
    border: 2px dashed rgba(255,255,255,0.25);
    border-radius: 10px;
    padding: 14px 18px;
    margin: 0 0 20px;
    flex-wrap: wrap; /* Wrap on very narrow screens */
}

.cuc-code {
    font-family: 'Courier New', Courier, monospace;
    font-size: 20px;
    font-weight: 700;
    color: #ffd700;
    letter-spacing: 2px;
    /* Allow selection for manual copy on mobile */
    -webkit-user-select: text;
    user-select: text;
}

.cuc-copy-btn {
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.2);
    color: var(--cuc-text);
    font-size: 13px;
    /* Min tap target size */
    min-height: 44px;
    padding: 0 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.cuc-copy-btn:hover,
.cuc-copy-btn:active,
.cuc-copy-btn.copied {
    background: var(--cuc-success);
    border-color: var(--cuc-success);
}

/* ---- Countdown timer ---- */
.cuc-timer-block {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--cuc-timer-bg);
    border-radius: 12px;
    padding: 16px 24px;
    margin: 0 0 16px;
}

.cuc-timer-unit {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.cuc-timer-digit {
    font-size: 42px;
    font-weight: 800;
    color: var(--cuc-primary);
    line-height: 1;
    font-variant-numeric: tabular-nums;
    font-family: 'Courier New', Courier, monospace;
    min-width: 60px;
    text-align: center;
}

.cuc-timer-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--cuc-text-muted);
}

.cuc-timer-sep {
    font-size: 36px;
    font-weight: 700;
    color: var(--cuc-text-muted);
    margin-top: -8px;
}

/* ---- Expired message ---- */
.cuc-expired-msg {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.4);
    border-radius: 8px;
    color: #f87171;
    font-size: 14px;
    padding: 12px;
    margin: 0 0 16px;
    text-align: center;
}

.cuc-expired-msg[hidden] { display: none; }

/* ---- Progress bar ---- */
.cuc-progress-bar {
    height: 4px;
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
    overflow: hidden;
    margin: 0 0 20px;
}

.cuc-progress-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--cuc-primary), #ffd700);
    border-radius: 2px;
    transform-origin: left;
    transition: width 1s linear;
}

/* ---- CTA button ---- */
.cuc-cta-btn {
    display: block;
    background: linear-gradient(135deg, var(--cuc-primary), #ff8c00);
    color: #fff !important;
    text-decoration: none !important;
    font-size: 16px;
    font-weight: 700;
    /* Min tap height */
    min-height: 52px;
    line-height: 52px;
    padding: 0 20px;
    border-radius: 10px;
    margin: 0 0 12px;
    transition: filter 0.2s;
    box-shadow: 0 4px 20px rgba(255,79,0,0.4);
    text-align: center;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.cuc-cta-btn:hover  { filter: brightness(1.08); }
.cuc-cta-btn:active { filter: brightness(0.95); }

/* ---- Dismiss link ---- */
.cuc-dismiss-link {
    background: none;
    border: none;
    color: var(--cuc-text-muted);
    font-size: 13px;
    cursor: pointer;
    text-decoration: underline;
    /* Min tap target */
    min-height: 44px;
    padding: 10px 4px;
    width: 100%;
    display: block;
    transition: color 0.2s;
    touch-action: manipulation;
}

.cuc-dismiss-link:hover,
.cuc-dismiss-link:active { color: var(--cuc-text); }

/* ---- Expired state ---- */
.cuc-overlay.cuc-expired .cuc-cta-btn {
    opacity: 0.5;
    pointer-events: none;
    filter: grayscale(1);
}

.cuc-overlay.cuc-expired .cuc-timer-digit { color: #ef4444; }

/* ============================================================
   Mobile overrides
   ============================================================ */

/* Small screens: reduce padding, tighten timer */
@media (max-width: 480px) {
    .cuc-overlay {
        /* Align to bottom on small phones — easier to reach */
        align-items: flex-end;
        padding: 0 0 0;
    }

    .cuc-modal {
        /* Full-width bottom sheet on phones */
        max-width: 100%;
        border-radius: 20px 20px 0 0;
        /* Slide in from bottom instead of scaling */
        transform: translateY(100%);
    }

    .cuc-overlay.cuc-visible .cuc-modal {
        transform: translateY(0);
    }

    .cuc-modal-inner {
        padding: 24px 20px 32px; /* Extra bottom padding above home indicator */
    }

    .cuc-title {
        font-size: 18px;
    }

    .cuc-timer-digit {
        font-size: 34px;
        min-width: 48px;
    }

    .cuc-code {
        font-size: 16px;
        letter-spacing: 1px;
    }

    .cuc-coupon-block {
        flex-direction: column;
        gap: 12px;
    }

    .cuc-copy-btn {
        width: 100%;
        text-align: center;
    }
}

/* Handle safe areas (iPhone notch / Dynamic Island / home bar) */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 480px) {
        .cuc-modal-inner {
            padding-bottom: calc(32px + env(safe-area-inset-bottom));
        }
    }
}

/* Landscape mobile: keep modal visible, reduce height of timer block */
@media (max-height: 500px) and (orientation: landscape) {
    .cuc-overlay {
        align-items: flex-start;
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .cuc-confetti { display: none; }

    .cuc-timer-block {
        padding: 8px 16px;
        margin-bottom: 10px;
    }

    .cuc-timer-digit {
        font-size: 28px;
        min-width: 40px;
    }

    .cuc-modal-inner {
        padding: 16px 20px 16px;
    }
}
