/* ==========================================================
   Spin Wheel Popup — Black Friday Edition (responsive)
   ========================================================== */

/* ---------- Modal (تمام‌صفحه، فقط برای وسط‌چین کردن کارت) ---------- */
#modalSpinWheel.modal-container,
.spin-wheel-popup {
    position: fixed !important;
    inset: 0 !important;
    z-index: 999999 !important;

    display: flex !important;
    align-items: center !important;
    justify-content: center !important;

    width: auto !important;
    height: auto !important;
    max-width: none !important;
    max-height: none !important;

    margin: 0 !important;
    padding: 12px !important;
    border: none !important;
    outline: none !important;

    overflow: hidden !important;
    box-sizing: border-box !important;

    background: transparent !important;
    box-shadow: none !important;
    transform: none !important;

    opacity: 0;
    visibility: hidden;
    /* کلیک از روی ناحیه‌ی خالی به underlayer می‌رسد و مودال بسته می‌شود */
    pointer-events: none;

    transition:
        opacity 0.3s ease,
        visibility 0.3s ease !important;
}

#modalSpinWheel.modal-container.active,
.spin-wheel-popup.active {
    opacity: 1 !important;
    visibility: visible !important;
}

/* Backdrop (اختصاصی و خودکفا؛ به هیچ CSS دیگری وابسته نیست) */
.spin-wheel-popup__backdrop {
    position: fixed;
    inset: 0;
    z-index: 999998;

    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);

    opacity: 0;
    visibility: hidden;
    pointer-events: none;

    transition:
        opacity 0.3s ease,
        visibility 0.3s ease;
}

.spin-wheel-popup__backdrop.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* ---------- Card ---------- */
.spin-wheel-popup__card {
    /* اندازه‌ی گردونه: بسته به ارتفاع صفحه کوچک می‌شود (حداقل ۱۹۰ و حداکثر ۳۳۰) */
    --wheel-size: max(190px, min(330px, calc(100dvh - 130px)));
    --wheel-pad: 16px;

    position: relative;
    pointer-events: auto;

    display: grid;
    grid-template-columns: minmax(0, 1fr) calc(var(--wheel-size) + var(--wheel-pad) * 2);
    align-items: center;
    column-gap: 32px;

    direction: rtl;

    width: min(100%, 850px);
    max-height: calc(100dvh - 24px);
    padding: 32px;
    box-sizing: border-box;

    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #3f3f46 transparent;

    border: 1px solid rgba(250, 204, 21, 0.2);
    border-radius: 28px;

    background: #121212;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);

    transform: scale(0.96);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.spin-wheel-popup.active .spin-wheel-popup__card {
    transform: scale(1);
}

/* ---------- Close ---------- */
.spin-wheel-popup__close {
    position: absolute;
    top: 1.25rem;
    left: 1.25rem;
    z-index: 15;

    display: flex;
    align-items: center;
    justify-content: center;

    width: 36px;
    height: 36px;
    padding: 0;

    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 50%;

    background: #1a1a1e;
    color: #9ca3af;

    cursor: pointer;
    transition:
        color 0.2s ease,
        background-color 0.2s ease,
        border-color 0.2s ease;
}

.spin-wheel-popup__close:hover {
    background: #27272a;
    color: #f3f4f6;
    border-color: rgba(212, 160, 23, 0.4);
}

.spin-wheel-popup__close:focus-visible {
    outline: 2px solid #facc15;
    outline-offset: 2px;
}

/* ---------- Info column ---------- */
.spin-wheel-popup__info {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 1.25rem;
    min-width: 0;
}

.spin-wheel-popup__title {
    margin: 0 0 0.375rem;
    color: #f3f4f6;
    font-size: 1.375rem;
    font-weight: 800;
    line-height: 1.5;
    letter-spacing: -0.02em;

    background: linear-gradient(135deg, #ffffff 0%, #d4a017 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.spin-wheel-popup__subtitle {
    margin: 0;
    color: #9ca3af;
    font-size: 0.875rem;
    line-height: 1.7;
}

/* Rules — Bootstrap accordion (override رنگ‌های پیش‌فرض بوت‌استرپ برای تم تیره) */
.spin-wheel-popup .spin-wheel-popup__rules {
    --bs-accordion-bg: transparent;
    --bs-accordion-border-width: 0;
    --bs-accordion-border-color: transparent;
    --bs-accordion-color: #9ca3af;
}

.spin-wheel-popup .spin-wheel-popup__rules .accordion-item {
    border: 0;
    background: transparent;
    color: inherit;
}

.spin-wheel-popup .spin-wheel-popup__rules .spin-wheel-popup__rules-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;

    width: 100%;
    padding: 0;
    border: 0;
    border-radius: 0;

    background: transparent;
    color: #f3f4f6;
    box-shadow: none;

    font-family: inherit;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.6;
    text-align: right;
}

.spin-wheel-popup .spin-wheel-popup__rules .spin-wheel-popup__rules-toggle:focus-visible {
    outline: 2px solid #facc15;
    outline-offset: 3px;
    box-shadow: none;
}

/* فلش آکاردیون */
.spin-wheel-popup .spin-wheel-popup__rules .spin-wheel-popup__rules-toggle::after {
    content: "";
    flex-shrink: 0;
    width: 1.1rem;
    height: 1.1rem;
    margin: 0;

    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23d4a017' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 5l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 100%;

    transition: transform 0.2s ease;
}

.spin-wheel-popup .spin-wheel-popup__rules .spin-wheel-popup__rules-toggle:not(.collapsed)::after {
    transform: rotate(-180deg);
}

.spin-wheel-popup .spin-wheel-popup__rules .accordion-body {
    padding: 0.625rem 0 0;
    background: transparent;
}

.spin-wheel-popup__rules ul {
    margin: 0;
    padding: 0 1.1rem 0 0;
    list-style-type: circle;
}

.spin-wheel-popup__rules li {
    margin-bottom: 0.35rem;
    color: #9ca3af;
    font-size: 0.875rem;
    line-height: 1.8;
}

.spin-wheel-popup__rules li::marker {
    color: #d4a017;
}

/* ---------- Wheel stage ---------- */
.spin-wheel-popup__stage {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
}

/*
 * علت لرزش اسکرول‌بار:
 * وقتی دیسک می‌چرخد، باکس مربعی آن (بعد از transform) از کارت بیرون می‌زند و
 * مرورگر آن را جزو overflow قابل اسکرول حساب می‌کند؛ نتیجه: اسکرول‌بار مدام ظاهر/مخفی می‌شود.
 * با overflow:hidden روی این والد، تاثیر چرخش دیسک روی کارت کاملاً حذف می‌شود.
 */
.spin-wheel {
    position: relative;
    isolation: isolate;

    width: calc(var(--wheel-size) + var(--wheel-pad) * 2);
    padding: var(--wheel-pad);
    box-sizing: border-box;

    overflow: hidden;
    contain: layout paint;
}

/* Pointer */
.spin-wheel__pointer {
    position: absolute;
    top: 0;
    left: 50%;
    z-index: 10;

    width: 28px;
    height: 34px;

    color: #d4a017;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.4));
    transform: translateX(-50%);
}

/* Disc */
.spin-wheel__disc {
    position: relative;

    width: 100%;
    aspect-ratio: 1 / 1;
    box-sizing: border-box;
    overflow: hidden;

    border: 6px solid #d4a017;
    border-radius: 50%;

    background: repeating-conic-gradient(
        #18181b 0deg var(--seg, 60deg),
        #222226 var(--seg, 60deg) calc(var(--seg, 60deg) * 2)
    );

    box-shadow:
        inset 0 0 20px rgba(0, 0, 0, 0.8),
        0 0 14px rgba(212, 160, 23, 0.25);

    /* واحد cqw برای لیبل‌ها = ۱٪ عرض دیسک → همه‌چیز با اندازه‌ی گردونه مقیاس می‌شود */
    container-type: inline-size;

    will-change: transform;
    transition: transform 4.2s cubic-bezier(0.15, 0.85, 0.15, 1);
}

/* Segment boundary lines */
.spin-wheel__disc::after {
    content: "";

    position: absolute;
    inset: 0;
    z-index: 2;

    border-radius: 50%;

    background: repeating-conic-gradient(
        from 0deg,
        rgba(212, 160, 23, 0.25) 0deg 1deg,
        transparent 1deg var(--seg, 60deg)
    );

    pointer-events: none;
}

/* Boundary dots */
.spin-wheel__dot {
    position: absolute;
    inset: 0;
    z-index: 4;

    pointer-events: none;
    transform: rotate(var(--angle, 0deg));
}

.spin-wheel__dot::after {
    content: "";

    position: absolute;
    top: -3px;
    left: 50%;

    width: 9px;
    height: 9px;
    margin-left: -4.5px;

    border-radius: 50%;
    background: #facc15;
}

/* Labels (کاملاً مبتنی بر cqw؛ دیگر نیازی به media query جدا نیست) */
.spin-wheel__label {
    --label-radius: 31cqw;

    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 3;

    display: flex;
    align-items: center;
    justify-content: center;

    width: 28cqw;
    height: 28cqw;

    text-align: center;
    pointer-events: none;

    transform:
        translate(-50%, -50%)
        rotate(calc(var(--angle) + var(--seg, 60deg) / 2))
        translateY(calc(var(--label-radius) * -1));
}

.spin-wheel__label.is-flipped {
    transform:
        translate(-50%, -50%)
        rotate(calc(var(--angle) + var(--seg, 60deg) / 2))
        translateY(calc(var(--label-radius) * -1))
        rotate(180deg);
}

.spin-wheel__label-text {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    max-width: 100%;

    color: #f3f4f6;
    font-weight: 700;
    line-height: 1.25;
    white-space: normal;
}

.spin-wheel__label-unit {
    margin-bottom: 1px;

    color: #facc15;
    font-size: clamp(0.6rem, 3.5cqw, 0.75rem);
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}

.spin-wheel__label-value {
    color: #ffffff;
    font-size: clamp(0.6875rem, 4.2cqw, 0.9rem);
    font-weight: 800;
    line-height: 1.25;
    text-align: center;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);

    overflow-wrap: anywhere;
    word-break: normal;
}

/* Hub */
.spin-wheel__hub {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 5;

    width: calc(var(--wheel-size) * 0.13);
    height: calc(var(--wheel-size) * 0.13);
    min-width: 30px;
    min-height: 30px;

    border: 3px solid #111113;
    border-radius: 50%;

    background: radial-gradient(circle, #facc15 0%, #b45309 100%);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);

    transform: translate(-50%, -50%);
}

/* ---------- Actions ---------- */
.spin-wheel-popup__actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
}

.spin-wheel__action {
    align-self: flex-start;
    min-height: 48px;
    margin: 0;
    padding: 0.6rem 2.25rem;

    border: none;
    border-radius: 12px;

    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: #000000;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 800;

    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;

    transition:
        background 0.2s ease,
        box-shadow 0.2s ease,
        transform 0.2s ease;
}

.spin-wheel__action:hover {
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    box-shadow: 0 10px 25px rgba(245, 158, 11, 0.4);
    transform: translateY(-1px);
}

.spin-wheel__action:active {
    transform: translateY(0);
}

.spin-wheel__action:disabled {
    cursor: wait;
    opacity: 0.7;
    box-shadow: none;
    transform: none;
}

.spin-wheel__action:focus-visible {
    outline: 2px solid #facc15;
    outline-offset: 3px;
}

.spin-wheel__action[hidden] {
    display: none !important;
}

/* ---------- Result & coupon ---------- */
.spin-wheel-popup__result {
    display: none;
    width: 100%;
    padding: 0.75rem;
    box-sizing: border-box;

    border: 1px solid rgba(212, 160, 23, 0.4);
    border-radius: 12px;
    background: rgba(212, 160, 23, 0.06);
    text-align: center;
}

.spin-wheel-popup__result.is-visible {
    display: block;
    animation: spinWheelResultIn 0.3s ease both;
}

.spin-wheel-popup__result-hint {
    display: none !important;
}

.spin-wheel-popup__result-content {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
    width: 100%;
}

.spin-wheel-popup__result-title {
    display: block;
    margin: 0;

    color: #9ca3af;
    font-size: 0.875rem;
    line-height: 1.6;
}

.spin-wheel-popup__result-title strong,
.spin-wheel-popup__result-prize {
    display: inline;
    color: #f3f4f6;
    font-size: inherit;
    font-weight: 800;
}

.spin-wheel-coupon-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;

    width: 100%;
    padding: 0.5rem 0.75rem;
    box-sizing: border-box;

    border: 1px dashed rgba(212, 160, 23, 0.5);
    border-radius: 10px;
    background: #121212;
}

.spin-wheel-coupon-code {
    direction: ltr;
    min-width: 0;

    color: #facc15;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-align: left;

    overflow-wrap: anywhere;
}

.spin-wheel-copy-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;

    flex-shrink: 0;
    min-height: 38px;
    padding: 0.4rem 0.9rem;

    border: none;
    border-radius: 8px;

    background: rgba(212, 160, 23, 0.15);
    color: #f3f4f6;

    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 700;

    cursor: pointer;
    touch-action: manipulation;
    transition:
        color 0.2s ease,
        background-color 0.2s ease;
}

.spin-wheel-copy-btn:hover {
    background: #facc15;
    color: #121212;
}

.spin-wheel-copy-btn:focus-visible {
    outline: 2px solid #facc15;
    outline-offset: 2px;
}

.spin-wheel-copy-btn.is-copied {
    background: #10b981;
    color: #ffffff;
}

@keyframes spinWheelResultIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

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

/* ==========================================================
   Mobile / narrow screens
   ترتیب: عنوان → گردونه → دکمه/نتیجه → شرایط
   ========================================================== */
@media (max-width: 720px) {
    #modalSpinWheel.modal-container,
    .spin-wheel-popup {
        padding: 8px !important;
    }

    .spin-wheel-popup__card {
        /* آکاردیون بسته جای کمتری می‌گیرد، پس گردونه می‌تواند بزرگ‌تر باشد */
        --wheel-size: max(200px, min(300px, calc(100vw - 90px), calc(100dvh - 320px)));

        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 0.875rem;

        width: 100%;
        max-height: calc(100dvh - 16px);
        padding: 18px 16px 16px;
        border-radius: 20px;
    }

    .spin-wheel-popup__close {
        top: 0.75rem;
        left: 0.75rem;
    }

    /* children مستقیماً آیتم flex کارت می‌شوند و با order جابه‌جا می‌شوند */
    .spin-wheel-popup__info {
        display: contents;
    }

    .spin-wheel-popup__intro {
        order: 1;
        padding: 0 44px; /* جا برای دکمه‌ی بستن */
        text-align: center;
    }

    .spin-wheel-popup__title {
        font-size: 1.2rem;
    }

    .spin-wheel-popup__subtitle {
        font-size: 0.8125rem;
    }

    .spin-wheel-popup__stage {
        order: 2;
    }

    .spin-wheel-popup__actions {
        order: 3;
    }

    .spin-wheel-popup__rules {
        order: 4;
        padding: 0.75rem 0.875rem;
        border: 1px solid rgba(255, 255, 255, 0.06);
        border-radius: 12px;
        background: rgba(255, 255, 255, 0.03);
    }

    .spin-wheel-popup .spin-wheel-popup__rules .spin-wheel-popup__rules-toggle {
        min-height: 28px;
        padding: 0;
        font-size: 0.9rem;
        cursor: pointer;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    .spin-wheel-popup__rules li {
        font-size: 0.8125rem;
        line-height: 1.75;
    }

    .spin-wheel__action {
        align-self: stretch;
        min-height: 50px;
        font-size: 1.0625rem;
    }
}

/* دسکتاپ: آکاردیون همیشه باز و فقط یک عنوان ساده است (غیرقابل کلیک) */
@media (min-width: 721px) {
    .spin-wheel-popup .spin-wheel-popup__rules .accordion-collapse.collapse:not(.show) {
        display: block !important;
        height: auto !important;
    }

    .spin-wheel-popup .spin-wheel-popup__rules .spin-wheel-popup__rules-toggle {
        pointer-events: none;
        cursor: default;
    }

    .spin-wheel-popup .spin-wheel-popup__rules .spin-wheel-popup__rules-toggle::after {
        display: none;
    }
}

/* Landscape کوتاه (مثلاً موبایل افقی): دو ستونه بماند ولی فشرده */
@media (max-height: 520px) and (min-width: 721px) {
    .spin-wheel-popup__card {
        padding: 18px 24px;
        column-gap: 20px;
    }

    .spin-wheel-popup__info {
        gap: 0.75rem;
    }

    .spin-wheel-popup__rules li {
        font-size: 0.8rem;
        line-height: 1.6;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .spin-wheel__disc {
        transition-duration: 0.01ms !important;
    }

    .spin-wheel-popup,
    .spin-wheel-popup__card,
    .spin-wheel-popup__result {
        transition: none !important;
        animation: none !important;
    }
}
