/* Chế độ Fullscreen giả lập cho iPhone */
.ios-fullscreen-active {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 99999 !important;
    background: linear-gradient(135deg, #667eea, #764ba2) !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    overflow: hidden !important;
    touch-action: none;
}

.ios-fullscreen-active #wheelContainer {
    max-width: 95vmin !important;
    max-height: 95vmin !important;
    width: 95vmin !important;
    height: 95vmin !important;
}

.ios-fullscreen-active #spinBtn {
    position: fixed;
    bottom: 30px;
    z-index: 10000;
}

.ios-fullscreen-active #fullscreenBtn, 
.ios-fullscreen-active #soundToggleBtn {
    position: fixed;
    top: 15px;
    z-index: 10000;
}

.ios-fullscreen-active #soundToggleBtn { left: 15px; }
.ios-fullscreen-active #fullscreenBtn { right: 15px; }

@media (max-width: 767px) {
    .ios-fullscreen-active #soundToggleBtn span,
    .ios-fullscreen-active #fullscreenBtn span {
        display: none;
    }
}

/* ===================================================
   RESET
=================================================== */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    overflow-x: hidden;
}

/* ===================================================
   VÒNG QUAY – CHUNG
=================================================== */
#wheelContainer {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    aspect-ratio: 1 / 1;
}

#wheelCanvas {
    width: 100% !important;
    height: 100% !important;
    aspect-ratio: 1 / 1;
    display: block;
    transform-origin: center center;
    will-change: transform;
    backface-visibility: hidden;
    z-index: 1; /* Canvas ở dưới */
}

/* ===================================================
   POINTER – VỊ TRÍ TÍNH BẰNG JS
   🔥 FIX: Đảm bảo pointer KHÔNG CHE NÚT
=================================================== */
.pointer {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10; /* ⬆️ Tăng z-index nhưng vẫn thấp hơn nút */

    width: 0;
    height: 0;

    /* Kích thước responsive - Mobile nhỏ */
    border-left: 15px solid transparent;
    border-right: 15px solid transparent;
    border-top: 35px solid #ef4444;

    transform-origin: 50% 100%;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.45));
    pointer-events: none; /* 🔥 QUAN TRỌNG: Cho phép click xuyên qua */
}

/* Tablet - Kim vừa */
@media (min-width: 768px) {
    .pointer {
        border-left: 26px solid transparent;
        border-right: 26px solid transparent;
        border-top: 65px solid #ef4444;
    }
}

/* Desktop - Kim lớn */
@media (min-width: 1024px) {
    .pointer {
        border-left: 20px solid transparent;
        border-right: 20px solid transparent;
        border-top: 50px solid #ef4444;
    }
}

/* Lắc kim khi tick */
.pointer.shake {
    animation: pointerShake 0.25s ease-in-out;
}

@keyframes pointerShake {
    0%   { transform: translateX(-50%) rotate(0deg); }
    30%  { transform: translateX(-50%) rotate(-6deg); }
    60%  { transform: translateX(-50%) rotate(6deg); }
    100% { transform: translateX(-50%) rotate(0deg); }
}

/* ===================================================
   LOGO GIỮA - LUÔN Ở TRÊN POINTER
=================================================== */
#wheelContainer > div {
    z-index: 50 !important; /* 🔥 Logo ở giữa pointer và nút */
}

#wheelContainer img {
    position: relative;
    z-index: 50;
}

/* ===================================================
   NÚT QUAY - LUÔN Ở TRÊN CÙNG
=================================================== */
.spin-btn {
    position: relative; /* 🔥 Đảm bảo z-index hoạt động */
    z-index: 100; /* ⬆️ Z-index cao hơn pointer */
    
    background-color: #16a34a;
    color: #ffffff;
    font-size: 1.5rem;
    font-weight: 700;

    padding: 0.75rem;
    border-radius: 9999px;

    border: none;
    cursor: pointer;

    box-shadow: 0 10px 15px rgba(0, 0, 0, 0.15);

    transition:
        background-color 0.3s ease-in-out,
        transform 0.2s ease;
}

.spin-btn:hover {
    background-color: #15803d;
}

/* 🔥 TOOLTIP KHI HOVER */
.spin-btn:hover::after {
    content: 'Có thể bấm Space để quay';
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%);
    
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    
    animation: tooltipFadeIn 0.2s ease-out;
    pointer-events: none;
    z-index: 101;
}

/* Mũi tên tooltip */
.spin-btn:hover::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid rgba(0, 0, 0, 0.9);
    
    animation: tooltipFadeIn 0.2s ease-out;
    pointer-events: none;
    z-index: 101;
}

@keyframes tooltipFadeIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Ẩn tooltip trên mobile */
@media (max-width: 768px) {
    .spin-btn:hover::after,
    .spin-btn:hover::before {
        display: none;
    }
}

.spin-btn:focus {
    outline: none;
    box-shadow:
        0 0 0 4px rgba(134, 239, 172, 0.8),
        0 10px 15px rgba(0, 0, 0, 0.15);
}

.spin-btn:active {
    transform: scale(0.96);
}

@media (max-width: 768px) {
    .spin-btn {
        font-size: 1.25rem;
        padding: 0.6rem 1.2rem;
    }
}

/* ===================================================
   FULLSCREEN MODE – CHUNG
=================================================== */
.fullscreen-mode {
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    width: 100vw !important;
    height: 100vh !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
}

.fullscreen-mode #wheelContainer {
    aspect-ratio: 1 / 1 !important;
    max-width: min(90vmin, 90vh) !important;
    max-height: min(90vmin, 90vh) !important;
    width: min(90vmin, 90vh) !important;
    height: min(90vmin, 90vh) !important;
}

/* ===================================================
   FULLSCREEN – MOBILE
=================================================== */
@media (max-width: 767px) {
    .fullscreen-mode #wheelContainer {
        max-width: 98vmin !important;
        max-height: 98vmin !important;
        width: 98vmin !important;
        height: 98vmin !important;
    }

    .fullscreen-mode #spinBtn {
        position: fixed;
        bottom: 60px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 9999; /* 🔥 Luôn ở trên cùng */
    }

    .fullscreen-mode #soundToggleBtn {
        position: fixed;
        top: 0.75rem;
        left: 0.75rem;
        z-index: 9999;
    }

    .fullscreen-mode #fullscreenBtn {
        position: fixed;
        top: 0.75rem;
        right: 0.75rem;
        z-index: 9999;
    }

    .fullscreen-mode #soundToggleBtn span,
    .fullscreen-mode #fullscreenBtn span {
        display: none;
    }
}

/* ===================================================
   FULLSCREEN – IPAD / TABLET
=================================================== */
@media (min-width: 768px) and (max-width: 1023px) {
    .fullscreen-mode #wheelContainer {
        max-width: 94vmin !important;
        max-height: 94vmin !important;
        width: 94vmin !important;
        height: 94vmin !important;
    }

    .fullscreen-mode #spinBtn {
        position: fixed;
        bottom: 24px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 9999;
    }

    .fullscreen-mode #soundToggleBtn {
        position: fixed;
        top: 1rem;
        left: 1rem;
        z-index: 9999;
    }

    .fullscreen-mode #fullscreenBtn {
        position: fixed;
        top: 1rem;
        right: 1rem;
        z-index: 9999;
    }
}

/* ===================================================
   FULLSCREEN – MÁY TÍNH (VÒNG QUAY LỚN, VUÔNG)
=================================================== */
@media (min-width: 1024px) {
    .fullscreen-mode #wheelContainer {
        max-width: 95vmin !important;
        max-height: 95vmin !important;
        width: 95vmin !important;
        height: 95vmin !important;
    }

    .fullscreen-mode #spinBtn {
        position: fixed;
        right: 20px;
        top: 50%;
        transform: translateY(-50%);
        font-size: 2.2rem !important;
        padding: 1.6rem 2rem !important;
        z-index: 9999;
    }

    .fullscreen-mode #soundToggleBtn {
        position: fixed;
        top: 1rem;
        right: 14rem;
        z-index: 9999;
    }

    .fullscreen-mode #fullscreenBtn {
        position: fixed;
        top: 1rem;
        right: 1rem;
        z-index: 9999;
    }
}

/* ===================================================
   POPUP – NHẸ, KHÔNG GIẬT
=================================================== */
#resultPopup {
    position: fixed;
    inset: 0;
    display: none;
    justify-content: center;
    align-items: center;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(6px);
    z-index: 99999; /* 🔥 Popup luôn ở trên cùng */
}

#resultPopup.show-popup {
    display: flex;
}

#resultContent {
    background: #fff;
    border-radius: 1rem;
    padding: 2rem;
    text-align: center;
    max-width: 90%;
    z-index: 100000;
}

/* ===================================================
   CANVAS - CHẤT LƯỢNG CAO
=================================================== */
#wheelCanvas {
    image-rendering: auto;
    transform: translateZ(0);
}