body {
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
    background-color: #f5f5f5;
}

.container {
    text-align: center;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 0 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transform: translateY(-10vh); /* Move up by 10% of viewport height */
}

h1 {
    font-size: 3rem;
    margin-top: 0;
    margin-bottom: 2rem;
}

.wheel-container {
    position: relative;
    width: 400px;
    height: 400px;
    max-width: 80vmin; /* 80% of the smaller viewport dimension */
    max-height: 80vmin;
    margin: 0 auto 2rem;
    aspect-ratio: 1 / 1; /* Maintain square aspect ratio */
    display: flex;
    justify-content: center;
    align-items: center;
}

.pointer {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 15px solid transparent;
    border-right: 15px solid transparent;
    border-top: 30px solid #333;
    z-index: 2;
}

#spin-btn {
    padding: 12px 24px;
    font-size: 1.2rem;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    margin: 0 auto;
    display: block;
}

#spin-btn:hover {
    background-color: #45a049;
}

.share-button {
    position: fixed;
    bottom: 25px;
    right: 25px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: #4CAF50;
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    z-index: 20; /* Higher z-index to ensure it's above other elements */
}

.share-button:hover {
    background-color: #45a049;
}

.toast {
    position: fixed;
    bottom: 80px;
    right: 20px;
    background-color: #333;
    color: white;
    padding: 10px 20px;
    border-radius: 5px;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 16;
}

.toast.show {
    opacity: 1;
}

.ad-container {
    position: fixed;
    bottom: 20px; /* Adjusted for symmetry with buttons */
    left: 50%;
    transform: translateX(-50%);
    z-index: 15; /* Between buttons and background */
    background-color: rgba(255, 255, 255, 0.8);
    padding: 8px;
    border-radius: 8px;
    box-shadow: 0 3px 6px rgba(0,0,0,0.15);
    max-width: calc(100% - 140px); /* Ensure space for buttons on both sides */
    overflow: hidden;
}

/* Pop-up Ad Styles */
.popup-ad {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.6);
    animation: fadeIn 0.3s;
}

.popup-ad-content {
    position: relative;
    background-color: #fefefe;
    margin: 10% auto;
    padding: 25px;
    border: 1px solid #888;
    width: 400px;
    max-width: 80vmin; /* Cap at 80% of the smaller viewport dimension */
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    animation: slideIn 0.4s;
}

.popup-ad-header {
    padding: 8px 0;
    background-color: #f1f1f1;
    color: #555;
    text-align: center;
    font-size: 16px;
    font-weight: 500;
    border-radius: 5px;
    margin-bottom: 15px;
    letter-spacing: 0.5px;
}

.popup-ad-body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 300px;
    margin: 10px 0;
    max-width: 100%;
    overflow: hidden;
}

.popup-ad-unit {
    max-width: 100%;
    height: auto !important;
    max-height: 60vmin !important;
}

.close-ad {
    color: #ddd; /* Initially lighter color to indicate disabled state */
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: not-allowed; /* Initially not allowed cursor */
    position: absolute;
    right: 15px;
    top: 5px;
    transition: color 0.3s, cursor 0.3s;
}

/* Only apply hover effect when cursor is pointer (enabled state) */
.close-ad[style*="cursor: pointer"]:hover,
.close-ad[style*="cursor: pointer"]:focus {
    color: black;
    text-decoration: none;
}

.popup-ad-timer {
    position: absolute;
    bottom: 15px;
    right: 15px;
    background-color: rgba(0,0,0,0.8);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    border: 2px solid rgba(255,255,255,0.2);
}

@keyframes fadeIn {
    from {opacity: 0}
    to {opacity: 1}
}

@keyframes slideIn {
    from {transform: translateY(-30%); opacity: 0}
    to {transform: translateY(0); opacity: 1}
}

/* Buy Me a Coffee Button Container */
.bmc-container {
    position: fixed;
    bottom: 25px;
    left: 25px;
    z-index: 20; /* Match share button z-index */
}

/* Style the button */
.bmc-button {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    transition: transform 0.3s ease;
    box-shadow: 0 3px 6px rgba(0,0,0,0.16);
    border-radius: 5px;
    overflow: hidden;
}

.bmc-button img {
    height: 40px;
    width: auto;
    transition: transform 0.3s ease;
}

.bmc-button:hover {
    transform: scale(1.05);
}

/* Canvas styling */
#wheel {
    width: 100%;
    height: 100%;
    display: block;
}

/* Responsive adjustments for mobile */
@media (max-width: 768px) {
    body {
        padding: 0;
    }

    .container {
        transform: translateY(-8vh); /* Slightly less shift on mobile */
    }

    h1 {
        font-size: 2.5rem;
        margin-bottom: 1.5rem;
    }

    .wheel-container {
        margin-bottom: 1.5rem;
    }

    #spin-btn {
        padding: 10px 20px;
        font-size: 1.1rem;
    }

    .bmc-container {
        bottom: 120px; /* Move up to avoid overlap with other elements */
        left: 15px;
    }

    .bmc-button img {
        height: 35px;
    }

    .share-button {
        bottom: 120px;
        right: 15px;
        width: 45px;
        height: 45px;
    }

    .ad-container {
        bottom: 25px; /* Adjusted for symmetry: (90px - 45px = 45px) from bottom */
        max-width: calc(100% - 100px); /* Ensure space for buttons on both sides */
    }

    /* Adjust popup for mobile */
    .popup-ad-content {
        margin: 20% auto;
        padding: 20px;
    }
}

/* Extra small devices */
@media (max-width: 480px) {
    .container {
        transform: translateY(-6vh); /* Even less shift on very small screens */
    }

    h1 {
        font-size: 2rem;
    }

    .wheel-container {
        max-width: 90vmin;
        max-height: 90vmin;
    }

    .ad-container {
        bottom: 25px; /* Adjusted for symmetry: (95px - 50px = 45px) from bottom */
        max-width: calc(100% - 80px); /* Even more space for buttons */
        padding: 5px;
    }

    /* Further separate buttons from ad */
    .bmc-container {
        bottom: 120px;
        left: 10px;
    }

    .share-button {
        bottom: 120px;
        right: 10px;
    }
}
