:root {
    --primary: #2c3e50;
    --accent: #e74c3c;
    --accent-hover: #c0392b;
    --secondary: #3498db;
    --secondary-hover: #2980b9;
    --success: #27ae60;
    --success-hover: #219e50;
    --gray: #95a5a6;
    --light-gray: #ecf0f1;
    --text: #2c3e50;
    --bg-gradient: linear-gradient(135deg, #74ebd5, #9face6);
    --container-bg: white;
    --wheel-bg: radial-gradient(circle, #f8f9fa 60%, #dcdcdc 100%);
    --shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
    --shadow-inner: inset 0 0 30px rgba(0, 0, 0, 0.2);
    --ball-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    --result-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
    --border-radius: 18px;
    --transition: all 0.3s ease;
}

body.dark-mode {
    --primary: #ecf0f1;
    --text: #ecf0f1;
    --success: #27ae60;
    --container-bg: #1E123C;
    --wheel-bg: radial-gradient(circle, #2c2c3e 60%, #1e1e2e 100%);
    --shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
    --shadow-inner: inset 0 0 30px rgba(0, 0, 0, 0.5);
    --ball-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
    --result-shadow: 0 3px 8px rgba(0, 0, 0, 0.5);
    --bg-gradient: linear-gradient(135deg, #16213e, #0f3460);
}

/* 🔥 CLS FIX #1: Reserve space for result tray */
.result-tray {
    min-height: 80px; /* Reserve space BEFORE JS loads */
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 20px;
    opacity: 1;
}

/* 🔥 CLS FIX #2: Reserve space for SPIN button */
.spin-button {
    position: absolute;
    box-sizing: content-box;
    inset: 0px;
    width: 80px;
    height: 80px;
    min-height: 80px; /* Fixed height to prevent shift */
    min-width: 80px; /* Fixed width to prevent shift */
    line-height: 80px;
    border-radius: 50%;
    box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 5px;
    color: rgb(255, 255, 255);
    text-align: center;
    font-size: 16px;
    font-weight: bold;
    margin: auto;
    cursor: pointer;
    z-index: 2;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    outline: none;
    border: none;
    padding: 0;
}

.container {
    max-width: 100%;
    margin: auto;
    background: var(--container-bg);
    border-radius: 0;
    padding: 30px;
    overflow: hidden;
    position: relative;
    transition: background 0.5s;
}

.theme-toggle {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
    z-index: 10;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(5px);
    padding: 8px 12px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

body.dark-mode .theme-toggle {
    background: rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.theme-toggle span {
    transition: opacity 0.3s;
}

.theme-toggle .sun,
.theme-toggle .moon {
    font-size: 18px;
    transition: opacity 0.3s;
}

.theme-toggle .sun {
    opacity: 1;
}

.theme-toggle .moon {
    opacity: 0.25;
}

body.dark-mode .theme-toggle .sun {
    opacity: 0.25;
}

body.dark-mode .theme-toggle .moon {
    opacity: 1;
}

h1 {
    font-size: 32px;
    margin-bottom: 10px;
    font-weight: 600;
}

.spin-container p {
    color: var(--text);
    opacity: 0.8;
    margin-bottom: 30px;
    font-size: 16px;
}

.controls {
    display: grid;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-end;
    margin-bottom: 60px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    margin: 10px 0;
}

.input-group label{
     min-height: 28px;
    display: block;
}

.input-group input[type="number"] {
    min-height: 70px; 
    height: 70px;  
}

.draw-counter {
    font-size: 18px;
    font-weight: bold;
    color: var(--primary);
    margin: 10px 0;
}

/* 🔥 CLS FIX #3: Fixed label height */
label {
    font-size: 15px;
    font-weight: 600;
    color: var(--primary);
    min-height: 22px; /* Prevent text reflow */
    display: block;
}

/* 🔥 CLS FIX #4: Fixed input dimensions */
input[type="number"] {
    padding: 10px !important;
    width: 50% !important;
    border: 2px solid #bdc3c7;
    border-radius: 12px;
    text-align: center;
    font-size: 40px !important;
    font-weight: bold;
    color: var(--primary);
    background: white;
    transition: all 0.3s;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.05);
    height: 70px !important;
    min-height: 70px; /* Prevent height shift */
    box-sizing: border-box;
}

body.dark-mode input[type="number"] {
    background: #2c2c3e;
    border-color: #555;
    color: #fff;
}

input[type="number"]:focus {
    outline: none;
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(231, 76, 60, 0.2);
    overflow: hidden;
}

input[type="number"]:hover {
    overflow: hidden;
}

body.dark-mode input[type="number"]:focus {
    box-shadow: 0 5px 15px rgba(231, 76, 60, 0.4);
}

/* 🔥 CLS FIX #5: Fixed button dimensions */
button {
    padding: 18px 40px;
    border: none;
    border-radius: 12px;
    font-size: 17px;
    font-weight: bold;
    cursor: pointer;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 54px; /* Prevent button height shift */
    box-sizing: border-box;
}

button:hover:not(:disabled) {
    box-shadow: 0 12px 25px rgba(0, 0, 0, 0.2);
}

button:active:not(:disabled) {
    transform: translateY(0);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

#setup {
    background: var(--success);
    color: white;
    padding: 18px 60px;
    min-width: 160px; /* Prevent width shift */
}

#setup:hover:not(:disabled) {
    opacity: 0.5;
}

body.dark-mode #setup {
    background: var(--success);
}

/* 🔥 CLS FIX #6: Fixed wheel container dimensions */
#wheelContainer {
    position: relative;
    width: 90vw;
    max-width: 700px;
    aspect-ratio: 1 / 1;
    margin: 0;
    border-radius: 50%;
    background: var(--wheel-bg);
    box-shadow: var(--shadow-inner), 0 15px 30px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    transition: background 0.5s;
    contain: layout style paint; /* Prevent layout recalculation */
}

.input-group-setup {
    margin: 0 auto;
    text-align: center;
}

@media (max-width: 640px) {
    .container {
        padding: 0;
    }

    #wheelContainer {
        width: 83vw;
        margin: 0 auto;
    }

    .controls {
        margin-top: 90px;
        min-height: 300px;
    }

    input[type="number"] {
        font-size: 20px;
        padding: 25px 40px;
    }

    #setup {
        padding: 18px 35px;
    }

    .spin-info-container {
        display: grid !important;
        gap: 20px !important;
        padding-bottom: 10px;
    }

    .controls button,
    .spin-extra-cta button {
        width: 200px;
    }

    #muteBtn {
        font-size: 18px !important;
        line-height: 13px !important;
        padding: 6px !important;
    }

    button {
        padding: 18px 25px;
    }

    .tool-wrapper {
        display: block !important; 
        min-height: 480px; /* Reserve minimum space */
        padding-top: 20px;
        padding-bottom: 20px;
    }

    .tool-wrapper {
        gap: 0;
    }

    .input-group-wrapper {
        display: flex !important;
        gap: 10px !important;
        min-height: 135px;
    }

    .input-group-setup {
        margin: 0 auto;
    }
    .input-group{
        min-height: 115px;
    }
}

@media (max-width: 769px) {
    button#spin {
        width: 145px !important;
    }

    .input-group-wrapper {
        display: flex !important;
        gap: 10px !important;
    }

    button {
        padding: 18px 25px;
        font-size: 12px;
    }

    .controls button,
    .spin-extra-cta button {
        width: 145px !important;
    }
}

/* 🔥 CLS FIX #7: Ball containment */
.ball {
    position: absolute;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    font-size: 13px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    background: hsl(var(--hue), 80%, 50%);
    box-shadow: inset -3px -3px 6px rgba(0, 0, 0, 0.3),
        inset 3px 3px 6px rgba(255, 255, 255, 0.2),
        var(--ball-shadow);
    transition: opacity 0.5s, transform 0.5s;
    transform: translate(-50%, -50%);
    background-image: radial-gradient(circle at top left, rgba(255, 255, 255, 0.2), transparent 40%),
        radial-gradient(circle at bottom right, rgba(0, 0, 0, 0.2), transparent 40%);
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
    contain: layout style; /* Prevent parent reflow */
}

.ball::before {
    content: '';
    position: absolute;
    width: 60%;
    height: 60%;
    border-radius: 50%;
    background: #fff;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.1);
    z-index: 1;
    top: 5px;
    left: 6px;
}

.ball::after {
    content: attr(data-value);
    position: absolute;
    font-size: 11px;
    font-weight: bold;
    color: #000;
    text-align: center;
    z-index: 2;
    pointer-events: none;
}

.ball.removed {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.1);
    pointer-events: none;
}

.ball.extra {
    background: #0068aa;
}

.input-group-wrapper {
    display: grid;
    gap: 0;
}

/* 🔥 CLS FIX #8: Fixed result ball dimensions */
.result-ball {
    width: 45px;
    height: 45px;
    min-width: 45px; /* Prevent width shift */
    min-height: 45px; /* Prevent height shift */
    border-radius: 50%;
    background: none;
    color: #000;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--result-shadow);
    transform: scale(0);
    opacity: 0;
    transition: transform 0.6s ease, opacity 0.6s ease;
    position: relative;
    overflow: hidden;
    flex-shrink: 0; /* Prevent shrinking in flex container */
}

.result-ball.show {
    transform: scale(1);
    opacity: 1;
}

.result-ball.extra.show {
    background-color: #0068aa;
    color: white;
    width: 50px;
    height: 50px;
    min-width: 50px;
    min-height: 50px;
    font-size: 25px;
    position: relative;
    top: -2px;
}

.result-ball.match-wheel {
    position: relative;
    width: 35px;
    height: 35px;
    min-width: 35px;
    min-height: 35px;
    border-radius: 50%;
    font-size: 13px;
    font-weight: bold;
    cursor: default;
    user-select: none;
    pointer-events: none;
    background: hsl(var(--hue), 80%, 50%);
    box-shadow: 
        inset -3px -3px 6px rgba(0,0,0,0.3),
        inset 3px 3px 6px rgba(255,255,255,0.2),
        0 2px 4px rgba(0,0,0,0.3);
    background-image: 
        radial-gradient(circle at top left, rgba(255, 255, 255, 0.2), transparent 40%),
        radial-gradient(circle at bottom right, rgba(0, 0, 0, 0.2), transparent 40%);
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
    flex-shrink: 0;
}

.result-ball.match-wheel::before {
    content: '';
    position: absolute;
    width: 60%;
    height: 60%;
    border-radius: 50%;
    background: #fff;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.1);
    z-index: 1;
    top: 6px;
    left: 7px;
}

.result-ball.match-wheel::after {
    content: attr(data-value);
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #000;
    text-shadow: 0 1px 1px rgba(255,255,255,0.4);
    z-index: 2;
    pointer-events: none;
}

.confetti {
    position: absolute;
    pointer-events: none;
    width: 100%;
    height: 100%;
    top: 40px;
    left: 0;
    overflow: visible;
}

/* 🔥 CLS FIX #9: Copy button with visibility instead of display */
.copy-container {
    margin: 20px 0;
    text-align: center;
    min-height: 50px; /* Reserve space for button */
}

#copyBtn {
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s, visibility 0.3s;
    min-width: 100px;
    min-height: 44px;
}

#copyBtn.visible {
    visibility: visible;
    opacity: 1;
}

.spin-stop-ctas {
    display: grid;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 25px;
}

.spin-extra-cta {
    text-align: center;
}

.spin-info-container {
    display: flex;
    align-items: center;
    justify-content: center;
}

button#spin {
    width: 200px;
}

.volume-control {
    position: absolute;
    bottom: -10px;
    left: 10px;
    transform: translateY(-50%);
    border-radius: 10px;
    padding: 10px;
    z-index: 10;
    width: 60px;
    height: 60px;
    display: inline-block;
}

.spin-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: scale(0.95);
    box-shadow: none;
}

#volumeSlider {
    width: 60px;
    height: 8px;
    border-radius: 4px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    display: none;
}

#volumeSlider::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

#muteBtn {
    background: transparent;
    color: #333;
    font-size: 40px;
    line-height: 40px;
    cursor: pointer;
    margin-top: 5px;
}

.picker-popup {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(2px);
}

.picker-popup-content {
    background: var(--container-bg);
    padding: 30px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    max-width: 500px;
    width: 90%;
    text-align: center;
    color: var(--text);
    position: relative;
    overflow: hidden;
}

.picker-popup-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 24px;
    font-weight: bold;
    color: var(--text);
    cursor: pointer;
    line-height: 1;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease, transform 0.2s;
}

.picker-popup-close:hover {
    transform: scale(1.1);
}

.picker-popup h3 {
    color: var(--primary) !important;
    margin: 0 0 20px 0;
    font-size: 25px;
    padding-bottom: 25px;
}

.picker-popup .result-tray {
    justify-content: center;
    margin: 10px auto;
}

.picker-popup .result-tray#popupBonus {
    display: none;
}

.picker-popup-copy {
    margin: 30px auto;
    padding: 12px 25px;
    background: var(--success);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: bold;
    font-size: 16px;
    width: auto;
    min-width: 120px;
    min-height: 48px;
    transition: all 0.3s ease;
}

.picker-popup-copy:hover:not(:disabled) {
    background: var(--success-hover);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.picker-popup-copy:active:not(:disabled) {
    transform: translateY(0);
}

.picker-popup-copy:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.picker-popup-wrapper {
    width: 100%;
    justify-content: center;
    display: flex;
}

.spin-button::before {
    content: "";
    position: absolute;
    inset: 0px;
    width: 80px;
    height: 80px;
    border-radius: 50% 0px 50% 50%;
    transform: rotate(-45deg);
    background: #D70932;
    z-index: 2;
}

.spin-button::after {
    content: "SPIN";
    position: absolute;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    inset: 0px;
    z-index: 3;
    -webkit-tap-highlight-color: transparent;
    font-size: 16px;
    font-weight: bold;
    display: block;
    color: rgb(255, 255, 255);
    user-select: none;
    -webkit-text-stroke: 0.5px rgb(248, 248, 248);
    text-shadow: rgb(0, 0, 0) 0px 1px 4px;
    letter-spacing: 0.7px;
}

.spin-button:hover:not(:disabled) {
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
    background: #960019;
}

.spin-button:active:not(:disabled) {
    transform: scale(0.98);
}

.picker-instructions-wrapper {
    text-align: center;
    margin: 0 auto 5px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    padding: 0 15px;
    width: 100%;
}

.picker-instructions-wrapper h2 {
    font-size: 26px;
    margin-bottom: 12px;
    font-weight: 600;
}

.picker-instructions-wrapper p {
    opacity: 0.9;
    font-size: 16px;
    line-height: 1.7;
    margin-bottom: 0;
}

.picker-instructions-wrapper em {
    font-style: italic;
    opacity: 0.8;
    display: block;
    margin-top: 8px;
    font-size: 15px;
}

.steps-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 50px;
    margin: 30px auto;
}

.step {
    display: flex;
    align-items: flex-start;
    gap: 5px;
    padding: 5px;
    border-radius: 14px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.06);
    transition: all 0.3s ease;
    text-align: left;
}

.step:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.12);
}

.step-number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    background: #d70932;
    color: white;
    font-weight: bold;
    border-radius: 50%;
    flex-shrink: 0;
    font-size: 15px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.step p {
    margin: 0;
    font-size: 13px;
    opacity: 1;
}

.steps-grid-mobile {
    display: none;
}
    
.text-primary-red {
    color: #e74c3ce6;
}

body.dark-mode .picker-numbers-title,
body.dark-mode .picker-numbers-texte {
    color: #fff;
}

.picker-numbers-title {
    padding-top: 50px;
    font-size: 2.5rem;
}

.picker-numbers-texte {
    padding-bottom: 50px;
}

@media (max-width: 768px) {
    .steps-grid {
        grid-template-columns: 1fr;
        margin-left: auto;
        margin-right: auto;
    }

    .picker-instructions-wrapper h2 {
        font-size: 24px;
    }

    .picker-instructions-wrapper p {
        font-size: 15px;
    }

    .step {
        padding: 14px 18px;
    }

    .step p {
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .picker-instructions-wrapper {
        padding: 0 10px;
    }
    
    .step {
        gap: 10px;
        padding: 12px 16px;
    }
    
    .step-number {
        width: 30px;
        height: 30px;
        min-width: 30px;
        min-height: 30px;
        font-size: 14px;
    }
    
    .steps-grid {
        width: 100%;
        margin-top: 30px;
        display: none;
    }
    
    .steps-grid-mobile {
        display: block !important;
        padding-bottom: 50px;
    }
    
    .picker-numbers-title {
        font-size: 1.5rem;
        margin-top: 30px;
    }
    
    .picker-numbers-texte {
        padding-bottom: 20px;
    }
    
    .controls {
        margin-top: 0;
        border: none !important;
        box-shadow: none !important;
    }
    
    input[type="number"] {
        width: 100% !important;
    }
    
    .tool-wrapper {
        width: 95%;
        gap: 0 !important;
    }
}

.tool-wrapper {
    width: 100%;
    max-width: 82rem;
    margin-left: auto;
    margin-right: auto;
    display: flex;
    gap: 2rem;
    align-items: center;
    justify-content: center;

    min-height: 600px;   /* réserve la place → plus de CLS */
    opacity: 1;          /* IMPORTANT */
    visibility: visible;

    overflow: hidden;
    contain: layout style paint;
}


.tool-wrapper.loaded {
    opacity: 1;
}

@media (min-width: 1024px) {
    .tool-wrapper {
        grid-template-columns: repeat(12, minmax(0, 1fr));
        display: flex;
    }
}

/* 🔥 CLS FIX #11: Controls with fixed dimensions */
.controls {
    color: var(--card-foreground, #111);
    border-radius: 1rem;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1),
                0 10px 10px -5px rgba(0,0,0,0.04);
    padding: 1.5rem;
    border: 1px solid #e5e7eb;
    min-height: 300px; /* Reserve minimum space */
}

.controls > * + * {
    margin-top: 1.5rem;
}

@media (min-width: 1024px) {
    .controls {
        grid-column: span 5 / span 5;
    }
}

.spin-info-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

@media (min-width: 1024px) {
    .spin-info-container {
        grid-column: span 7 / span 7;
    }
}

/* 🔥 CLS FIX #12