/* =========================================
   1. VARIABLES & THEME SETUP
   ========================================= */
:root {
    /* Light Theme (Default) */
    --primary: #3498db;
    --primary-hover: #2980b9;
    --accent: #e74c3c;
    --bg: #f4f7f6;
    --card-bg: #ffffff;
    --text: #2c3e50;
    --text-muted: #7f8c8d;
    --border: #e0e0e0;
    --shadow: 0 4px 6px rgba(0,0,0,0.05), 0 10px 20px rgba(0,0,0,0.1);
    --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
    
    /* Ad Placeholders */
    --ad-bg: #e9ecef;
    --ad-border: #ced4da;
    
    /* Layout */
    --header-height: 60px;
    --container-width: 1200px;
}

body.dark-mode {
    /* Dark Theme Overrides */
    --primary: #5dade2;
    --primary-hover: #3498db;
    --accent: #ff6b6b;
    --bg: #121212;
    --card-bg: #1e1e1e;
    --text: #ecf0f1;
    --text-muted: #bdc3c7;
    --border: #333333;
    --shadow: 0 4px 15px rgba(0,0,0,0.5);
    
    --ad-bg: #2a2a2a;
    --ad-border: #444;
}

/* =========================================
   2. RESET & BASE STYLES
   ========================================= */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
}

/* Confetti Canvas - Fixed Overlay */
#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
}

/* =========================================
   3. HEADER
   ========================================= */
header {
    height: var(--header-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0,0,0,0.03);
}

.logo {
    font-weight: 800;
    font-size: 1.4rem;
    color: var(--primary);
    letter-spacing: -0.5px;
}

.header-right {
    display: flex;
    gap: 1px;
    align-items: center;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text);
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
}

.icon-btn:hover {
    background: rgba(128, 128, 128, 0.1);
}

.icon-btn:active {
    transform: scale(0.95);
}

/* =========================================
   4. ADVERTISEMENTS (CLS OPTIMIZED)
   ========================================= */
.ad-slot {
    background-color: var(--ad-bg);
    border: 1px solid var(--ad-bg);
    display: none;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    overflow: hidden;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    border-radius: 4px;
}

/* Mobile Top Ad (Hidden on Desktop) */
.mobile-top-ad {
    width: 100%;
    max-width: 320px;
    min-height: 50px; /* Reserve space */
    margin-top: 15px;
    margin-bottom: 15px;
    display: flex;
}

/* Sidebar Skyscraper Ad (Hidden on Mobile) */
.sidebar-ad {
    display: none; /* Default hidden */
    width: 300px;
    flex-shrink: 0;
}

.skyscraper-ad {
    width: 300px;
    min-height: 600px; /* Reserve space */
    position: sticky;
    top: calc(var(--header-height) + 20px);
}

/* In-Content Ads */
.content-ad {
    width: 100%;
    min-height: 100px; /* Reserve space */
    margin: 30px 0;
    max-width: 100%;
}

/* Footer Sticky Ad */
.footer-ad {
    width: 100%;
    min-height: 50px; /* Reserve space */
    background: transparent;
    border: none;
    margin-top: 10px;
}

/* =========================================
   5. MAIN LAYOUT
   ========================================= */
.main-layout {
    width: 100%;
    max-width: var(--container-width);
    margin: 0 auto;
    padding: 0 15px;
    flex: 1;
}

/* Game Row: Holds Wheel & Sidebar */
.game-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
    margin-bottom: 40px;
    position: relative;
}

.wheel-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

/* Responsive Breakpoint for Sidebar */
@media (min-width: 1024px) {
    .game-row {
        flex-direction: row;
        align-items: flex-start;
        padding-top: 30px;
    }
    .mobile-top-ad {
        display: none;
    }
    .sidebar-ad {
        display: block;
    }
}

/* =========================================
   6. WHEEL COMPONENT
   ========================================= */
.wheel-wrapper {
    position: relative;
    width: 90vmin;
    height: 90vmin;
    max-width: 500px;
    max-height: 500px;
    /* Aspect Ratio Hack ensuring square */
    aspect-ratio: 1 / 1; 
}

#wheel-canvas {
    width: 100%;
    height: 100%;
    display: block;
    /* Rotation handled by JS transform */
}

/* The red triangle pointer */
.indicator {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 45px;
    color: var(--accent);
    z-index: 10;
    filter: drop-shadow(0 3px 3px rgba(0,0,0,0.3));
    pointer-events: none;
}

/* Center Spin Button */
#spin-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: var(--card-bg);
    border: 4px solid var(--border);
    color: var(--primary);
    font-weight: 800;
    font-size: 0.9rem;
    cursor: pointer;
    z-index: 11;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    transition: transform 0.1s, box-shadow 0.3s;
    text-transform: uppercase;
    letter-spacing: 1px;
    
    /* Pulse Animation */
    animation: pulse-shadow 2s infinite;
}

#spin-btn:hover {
    color: var(--primary-hover);
    border-color: var(--primary-hover);
}

#spin-btn:active {
    transform: translate(-50%, -50%) scale(0.95);
}

#spin-btn:disabled {
    cursor: not-allowed;
    opacity: 0.8;
    animation: none;
    color: var(--text-muted);
}

@keyframes pulse-shadow {
    0% { box-shadow: 0 0 0 0 rgba(52, 152, 219, 0.4); }
    70% { box-shadow: 0 0 0 15px rgba(52, 152, 219, 0); }
    100% { box-shadow: 0 0 0 0 rgba(52, 152, 219, 0); }
}

/* =========================================
   7. CONTENT & SEO SECTION
   ========================================= */
.content-section {
    max-width: 800px;
    margin: 0 auto 50px auto;
    background: var(--card-bg);
    padding: 30px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.content-section h1 {
    font-size: 1.8rem;
    margin-bottom: 15px;
    color: var(--primary);
    line-height: 1.3;
}

.content-section h2 {
    font-size: 1.4rem;
    margin: 25px 0 15px 0;
    color: var(--text);
}

.content-section p, .content-section li {
    margin-bottom: 12px;
    color: var(--text);
    font-size: 1.05rem;
}

.steps-list, .content-section ul {
    padding-left: 20px;
    margin-bottom: 20px;
}

.steps-list li {
    margin-bottom: 8px;
}

/* FAQ Accordion */
.faq-item {
    border-bottom: 1px solid var(--border);
    padding: 15px 0;
}
.faq-item:last-child { border-bottom: none; }

details summary {
    cursor: pointer;
    font-weight: 700;
    list-style: none;
    position: relative;
    padding-right: 20px;
}

details summary::-webkit-details-marker {
    display: none;
}

details summary::after {
    content: "+";
    position: absolute;
    right: 0;
    top: 0;
    font-weight: 300;
    font-size: 1.2rem;
    color: var(--primary);
}

details[open] summary::after {
    content: "−"; /* Minus sign */
}

details p {
    margin-top: 10px;
    font-size: 0.95rem;
    color: var(--text-muted);
    padding-left: 10px;
    border-left: 2px solid var(--primary);
}

/* =========================================
   8. FOOTER
   ========================================= */
.site-footer {
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    padding: 30px 20px;
    text-align: center;
    margin-top: auto;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.footer-links a:hover {
    color: var(--primary);
}

/* =========================================
   9. MODALS (DIALOG)
   ========================================= */
dialog {
    border: none;
    border-radius: 12px;
    padding: 0;
    width: 90%;
    max-width: 450px;
    margin: auto;
    background: var(--card-bg);
    color: var(--text);
    box-shadow: 0 15px 40px rgba(0,0,0,0.2);
}

dialog::backdrop {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
}

/* Animation for Modal Entry */
dialog[open] {
    animation: slide-up 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}

@keyframes slide-up {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(0,0,0,0.02);
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-muted);
}

.modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-height: 70vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border);
    background: rgba(0,0,0,0.02);
    text-align: right;
}

/* Form Elements inside Modal */
label {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 5px;
    display: block;
}

textarea, input[type="text"] {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 1rem;
    transition: border 0.2s;
}

textarea:focus, input[type="text"]:focus {
    border-color: var(--primary);
}

/* Range Slider */
input[type=range] {
    width: 100%;
    accent-color: var(--primary);
    cursor: pointer;
}

.control-group {
    background: var(--bg);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

/* Buttons */
.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 5px;
}

.primary-btn {
    background: var(--primary);
    color: #ffffff;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s;
}

.primary-btn:hover {
    background: var(--primary-hover);
}

.secondary-btn {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    padding: 10px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    flex: 1;
    transition: background 0.2s;
}

.secondary-btn:hover {
    background: rgba(0,0,0,0.05);
}

.full-width {
    width: 100%;
}

.text-danger {
    color: #e74c3c;
    border-color: rgba(231, 76, 60, 0.3);
}

.text-danger:hover {
    background: rgba(231, 76, 60, 0.05);
}

/* Language Grid */
.lang-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.lang-option {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 8px;
    text-align: left;
    cursor: pointer;
    font-weight: 500;
    color: var(--text);
    transition: all 0.2s;
}

.lang-option:hover {
    border-color: var(--primary);
    background: var(--card-bg);
}

/* =========================================
   10. RESULT OVERLAY
   ========================================= */
#result-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    backdrop-filter: blur(4px);
}

#result-overlay:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

.result-box {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    width: 90%;
    max-width: 350px;
    transform: scale(0.8);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    border: 2px solid var(--primary);
}

#result-overlay:not(.hidden) .result-box {
    transform: scale(1);
}

.result-box h2 {
    color: var(--primary);
    margin-bottom: 10px;
    font-size: 1.5rem;
}

#winner-text {
    font-size: 2.5rem;
    font-weight: 800;
    margin: 20px 0 30px 0;
    color: var(--text);
    word-break: break-word;
    line-height: 1.1;
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* =========================================
   11. RTL SUPPORT (Arabic)
   ========================================= */
html[dir="rtl"] {
    text-align: right;
}

html[dir="rtl"] .header-right {
    flex-direction: row-reverse;
}

/* html[dir="rtl"] .indicator {
     Flip indicator logic not strictly needed if centered, 
       but if you used margins, flip them here 
}*/

html[dir="rtl"] details summary::after {
    right: auto;
    left: 0;
}

html[dir="rtl"] details p {
    border-left: none;
    border-right: 2px solid var(--primary);
    padding-left: 0;
    padding-right: 10px;
}

html[dir="rtl"] .lang-option {
    text-align: right;
}

/* =========================================
   12. UTILITY CLASSES
   ========================================= */
.hidden {
    display: none !important;
}

.input-group {
    display: flex;
    gap: 8px;
}

.social-btn {
    transition: opacity 0.2s;
}

.social-btn:hover {
    opacity: 0.9;
}

#history-list {
    list-style: none;
}

#history-list li {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
#history-list li:last-child { border-bottom: none; }