/* ===================================================
   RESET & BASE STYLES
=================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    overflow-x: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ===================================================
   CUSTOM SCROLLBAR
=================================================== */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 10px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #3b82f6, #1d4ed8);
    border-radius: 10px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #2563eb, #1e40af);
}

/* ===================================================
   WHEEL CONTAINER
=================================================== */
#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;
    image-rendering: auto;
    transform: translateZ(0);
}

/* ===================================================
   POINTER
=================================================== */
.pointer {
    position: absolute;
    left: 50%;
    transform: translateX(-50%); 
    z-index: 10;
    width: 0;
    height: 0;
    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.5)); 
    pointer-events: none;
}

@media (min-width: 768px) {
    .pointer {
        border-left: 20px solid transparent;
        border-right: 20px solid transparent;
        border-top: 50px solid #ef4444;
    }
}

@media (min-width: 1024px) {
    .pointer {
        border-left: 22px solid transparent;
        border-right: 22px solid transparent;
        border-top: 55px solid #ef4444;
    }
}

.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); }
}

/* ===================================================
   CENTER LOGO
=================================================== */
#wheelContainer > div {
    z-index: 50 !important;
}

#wheelContainer img {
    position: relative;
    z-index: 50;
}

/* ===================================================
   SPIN BUTTON
=================================================== */
.spin-btn {
    position: relative;
    z-index: 5000;
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
    color: #ffffff;
    font-size: clamp(1.25rem, 4vw, 1.75rem);
    font-weight: 700;
    padding: 1rem 3rem;
	margin-bottom: 2rem;
    border-radius: 9999px;
    border: none;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(22, 163, 74, 0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.spin-btn:hover {
    background: linear-gradient(135deg, #15803d 0%, #166534 100%);
    box-shadow: 0 15px 35px rgba(22, 163, 74, 0.5);
    transform: translateY(-2px);
}

.spin-btn:active {
    transform: translateY(0) scale(0.98);
}

.spin-btn:focus {
    outline: none;
    box-shadow: 0 0 0 4px rgba(134, 239, 172, 0.5), 0 15px 35px rgba(22, 163, 74, 0.5);
}

@media (min-width: 768px) {
    .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;
    }

    .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);
    }
}

/* ===================================================
   FULLSCREEN MODES
=================================================== */
.ios-fullscreen-active,
.fullscreen-mode {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 100000 !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;
	border-radius: 0px !important;
    touch-action: none;
}

.ios-fullscreen-active #wheelContainer,
.fullscreen-mode #wheelContainer {
    max-width: 90vmin !important;
    max-height: 90vmin !important;
    width: 90vmin !important;
    height: 90vmin !important;
    z-index: 100001 !important;
}

/* Hide header in fullscreen */
.ios-fullscreen-active ~ header,
.fullscreen-mode ~ header,
body:has(.ios-fullscreen-active) header,
body:has(.fullscreen-mode) header,
:fullscreen header,
:-webkit-full-screen header {
    display: none !important;
}

/* Mobile Fullscreen */
@media (max-width: 767px) {
    .ios-fullscreen-active #wheelContainer,
    .fullscreen-mode #wheelContainer {
        max-width: 95vmin !important;
        max-height: 95vmin !important;
        width: 95vmin !important;
        height: 95vmin !important;
    }

    .ios-fullscreen-active #spinBtn,
    .fullscreen-mode #spinBtn {
        position: fixed !important;
        bottom: 60px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        z-index: 100003 !important;
    }
}

/* Tablet Fullscreen */
@media (min-width: 768px) and (max-width: 1023px) {
    .ios-fullscreen-active #wheelContainer,
    .fullscreen-mode #wheelContainer {
        max-width: 92vmin !important;
        max-height: 92vmin !important;
        width: 92vmin !important;
        height: 92vmin !important;
    }

    .ios-fullscreen-active #spinBtn,
    .fullscreen-mode #spinBtn {
        position: fixed !important;
        bottom: 30px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        z-index: 100003 !important;
    }
}

/* Desktop Fullscreen */
@media (min-width: 1024px) {
    .ios-fullscreen-active #wheelContainer,
    .fullscreen-mode #wheelContainer {
        max-width: 90vmin !important;
        max-height: 90vmin !important;
        width: 90vmin !important;
        height: 90vmin !important;
    }

    .ios-fullscreen-active #spinBtn,
    .fullscreen-mode #spinBtn {
        position: fixed !important;
        right: 20px !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        font-size: 2.2rem !important;
        padding: 1.6rem 2rem !important;
        z-index: 100003 !important;
    }
}

/* ===================================================
   RESULT POPUP
=================================================== */
#resultPopup {
    position: fixed;
    inset: 0;
    display: none;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 200000 !important;
}

#resultPopup.show-popup {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

.popup-overlay {
    z-index: 199999 !important;
}

#resultContent {
    background: #fff;
    border-radius: 1.5rem;
    padding: 2rem;
    text-align: center;
    max-width: 90%;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.4);
    animation: scaleIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleIn {
    from { 
        opacity: 0; 
        transform: scale(0.8);
    }
    to { 
        opacity: 1; 
        transform: scale(1);
    }
}

/* ===================================================
   OPTIONS LIST ITEMS
=================================================== */
#optionsList li {
    padding: 0.75rem;
    transition: all 0.2s ease;
}

#optionsList li:hover {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
}

#optionsList li.opacity-50 {
    opacity: 0.5;
    background: #f9fafb;
}

#optionsList li.opacity-50:hover {
    background: #f3f4f6;
}

/* ===================================================
   SAVED LISTS CARDS
=================================================== */
#savedListsGrid > div {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#savedListsGrid > div:hover {
    
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
}

/* ===================================================
   HISTORY ITEMS
=================================================== */
#winnerHistoryList li {
    padding: 0.65rem;
    transition: all 0.2s ease;
    border-bottom: 1px solid #e0e7ff;
}

#winnerHistoryList li:last-child {
    border-bottom: none;
}

#winnerHistoryList li:hover {
    background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
}

/* ===================================================
   BUTTONS & INPUTS DISABLED STATE
=================================================== */
button:disabled, 
input:disabled {
    cursor: not-allowed !important;
    opacity: 0.5 !important;
}

/* ===================================================
   ANIMATIONS
=================================================== */
@keyframes slideInRight {
    from { transform: translateX(400px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOutRight {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(400px); opacity: 0; }
}

.show-popup {
    animation: fadeIn 0.3s ease-out;
}

.animate-fade-in {
    animation: fadeIn 0.3s ease-out forwards;
}

/* ===================================================
   PROBABILITY CONTROLS
=================================================== */
#probabilityControls > div {
    transition: all 0.2s ease;
}

#probabilityControls > div:hover {
background-color: #ddd;
    box-shadow: 0 4px 12px rgba(251, 191, 36, 0.2);
}

/* ===================================================
   TAB SYSTEM
=================================================== */
.tab-btn {
    color: #6b7280;
    position: relative;
}

.tab-btn.active {
    color: #2563eb;
    border-bottom-color: #2563eb !important;
    background: linear-gradient(to bottom, transparent 0%, #eff6ff 100%);
}

.tab-btn:hover {
    color: #3b82f6;
}

.tab-content {
    display: none;
    animation: tabFadeIn 0.3s ease-out;
}

.tab-content.active {
    display: block;
}

@keyframes tabFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Saved Lists Cards in Tab */
#savedListsGrid > div {
    background: #fff;
    border: 2px solid #e5e7eb;
    border-radius: 0.75rem;
    padding: 0.875rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

#savedListsGrid > div:hover {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border-color: #3b82f6;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

#savedListsGrid h3 {
    font-size: 0.875rem;
    line-height: 1.3;
    margin-bottom: 0.5rem;
    transition: color 0.3s ease;
}

#savedListsGrid > div:hover h3 {
    color: #2563eb;
}

#savedListsGrid p {
    font-size: 0.75rem;
    color: #6b7280;
}

#savedListsGrid button {
    font-size: 0.75rem;
    padding: 0.5rem 0.75rem;
}

/* Empty message styling */
#emptySavedMessage {
    display: block;
}

#savedListsGrid:not(:empty) ~ #emptySavedMessage {
    display: none;
}

#savedListsGrid:empty {
    display: none;
}

/* Options Count Badge */
#optionsCount {
    transition: all 0.2s ease;
}

/* ===================================================
   RESPONSIVE ADJUSTMENTS
=================================================== */
@media (max-width: 640px) {
    .spin-btn {
        padding: 0.875rem 2rem;
		margin-bottom: 2rem;
        font-size: 1.25rem;
    }
    
    .tab-btn span {
        font-size: 0.75rem;
    }
    
    .tab-btn svg {
        width: 1rem;
        height: 1rem;
    }
}

@media (max-width: 1024px) {
    header h1 {
        font-size: 1.5rem;
    }
}

/* ===================================================
   HEADER Z-INDEX
=================================================== */
header {
    z-index: 50;
}

/* ===================================================
   BUTTONS - NORMAL & FULLSCREEN POSITIONING
=================================================== */

/* Normal mode - buttons in header */
#soundToggleBtn,
#fullscreenBtn {
    position: relative;
    z-index: 100;
    pointer-events: auto !important;
    cursor: pointer !important;
}

/* CRITICAL FIX: Buttons visibility when moved to body by JavaScript */
body > #soundToggleBtn,
body > #fullscreenBtn {
    position: fixed !important;
    z-index: 2147483647 !important;
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

body > #soundToggleBtn {
    top: 1rem !important;
    left: 1rem !important;
}

body > #fullscreenBtn {
    top: 1rem !important;
    right: 1rem !important;
}

/* Mobile - hide button text when in body */
@media (max-width: 767px) {
    body > #soundToggleBtn span,
    body > #fullscreenBtn span {
        display: none !important;
    }
}

/* ===================================================
   RANGE SLIDER STYLING
=================================================== */
/* Webkit (Chrome, Safari, Edge) */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    background: #3b82f68c;
	height: 8px;
    cursor: pointer;
}

/* Track */
input[type="range"]::-webkit-slider-track {
    background: linear-gradient(to right, #3b82f6 0%, #2563eb 100%);
    
    border-radius: 10px;
    border: 1px solid #dbeafe;
}

input[type="range"]::-moz-range-track {
    background: linear-gradient(to right, #3b82f6 0%, #2563eb 100%);
    height: 8px;
    border-radius: 10px;
    border: 1px solid #dbeafe;
}

/* Thumb */
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ffffff;
    border: 3px solid #3b82f6;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(59, 130, 246, 0.3);
    transition: all 0.2s ease;
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ffffff;
    border: 3px solid #3b82f6;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(59, 130, 246, 0.3);
    transition: all 0.2s ease;
}

/* Hover effects */
input[type="range"]:hover::-webkit-slider-thumb {
    background: #eff6ff;
    border-color: #2563eb;
    box-shadow: 0 3px 10px rgba(37, 99, 235, 0.4);
    transform: scale(1.1);
}

input[type="range"]:hover::-moz-range-thumb {
    background: #eff6ff;
    border-color: #2563eb;
    box-shadow: 0 3px 10px rgba(37, 99, 235, 0.4);
    transform: scale(1.1);
}

/* Active/Focus states */
input[type="range"]:active::-webkit-slider-thumb {
    background: #dbeafe;
    border-color: #1d4ed8;
    box-shadow: 0 4px 12px rgba(29, 78, 216, 0.5);
    transform: scale(1.15);
}

input[type="range"]:active::-moz-range-thumb {
    background: #dbeafe;
    border-color: #1d4ed8;
    box-shadow: 0 4px 12px rgba(29, 78, 216, 0.5);
    transform: scale(1.15);
}

input[type="range"]:focus {
    outline: none;
}

input[type="range"]:focus::-webkit-slider-thumb {
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2), 0 2px 6px rgba(59, 130, 246, 0.3);
}

input[type="range"]:focus::-moz-range-thumb {
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2), 0 2px 6px rgba(59, 130, 246, 0.3);
}


/* Khi div vòng quay ở chế độ Fullscreen */
#wheelCard:fullscreen {
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8fafc; /* Màu nền trắng xám cho dễ nhìn */
}

/* Fix lỗi font bị phóng to khi fullscreen trên một số trình duyệt */
#wheelCard:fullscreen * {
    font-size: 14px; 
}

/* Đảm bảo vòng quay luôn ở giữa và to rõ */
#wheelCard:fullscreen #wheelContainer {
    transform: scale(1.2); /* Phóng to vòng quay một chút khi full */
}

/* Reset lại khi thoát để font không bị lưu lại kích thước lớn */
#soundToggleBtn, #fullscreenBtn {
    transition: all 0.3s ease;
}