@property --snake-angle {
    syntax: '<angle>';
    initial-value: 0deg;
    inherits: false;
}

:root {
    --primary-red: #8B0000;
    --light-red: #FF4444;
    --lighter-red: #FF6B6B;
    --dark-bg: #0d0000;
    --gold: #FFD700;
    --gold-dim: #B8960F;
    --orange: #FFA500;
    --card-width: 200px;
    --card-height: 300px;
    --radius: 700px;
    --spin-duration: 4s;
    --spin-ease: cubic-bezier(0.1, 0.7, 0.1, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Poppins', 'Segoe UI', sans-serif;
    background-color: var(--dark-bg);
    background-image: url('./images/bg1.webp'), url('./images/bg1.jpg');
    background-position: center center;
    background-size: cover;
    background-repeat: no-repeat;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow: hidden;
}

/* Ambient glow centered behind the wheel */
body::before {
    content: '';
    position: fixed;
    top: 50%;
    left: 35%;
    transform: translate(-50%, -50%);
    width: 800px;
    height: 800px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(139,0,0,0.15) 0%, rgba(139,0,0,0.05) 40%, transparent 70%);
    pointer-events: none;
    animation: ambientPulse 6s ease-in-out infinite;
}

@keyframes ambientPulse {
    0%, 100% { opacity: 0.6; transform: translate(-50%, -50%) scale(1); }
    50% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
}

/* Confetti canvas sits on top of everything */
#confettiCanvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2000;
}

/* Ember canvas — persistent background fire dust */
#emberCanvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

/* ── Floating Fruit Icons ── */
.floating-fruit {
    position: absolute;
    width: 200px;
    height: 200px;
    object-fit: contain;
    pointer-events: none;
    z-index: 10;
    filter: drop-shadow(0 8px 20px rgba(0,0,0,0.4));
}

.floating-fruit:nth-child(1) {
    left: 50px;
    top: 0%;
    animation: fruitPulse1 4.2s ease-in-out infinite;
}
.floating-fruit:nth-child(2) {
    left: 50px;
    top: 77%;
    animation: fruitPulse2 4.8s ease-in-out infinite;
}
.floating-fruit:nth-child(3) {
    left: 50px;
    top: 120%;
    animation: fruitPulse3 4.4s ease-in-out infinite;
}

@keyframes fruitPulse1 {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.12); }
}
@keyframes fruitPulse2 {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.15); }
}
@keyframes fruitPulse3 {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.1); }
}

/* ── Layout ── */
.main-container {
    display: flex;
    gap: 40px;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 1400px;
    position: relative;
    z-index: 1;
}

/* ── Wheel Container ── */
.wheel-container {
    perspective: 2200px;
    width: 100%;
    max-width: 800px;
    height: 700px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.wheel-container::before {
    content: '';
    position: absolute;
    width: 520px;
    height: 520px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255,0,0,0.06) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}

.controls {
    display: flex;
    align-items: center;
    gap: 15px;
    z-index: 100;
    pointer-events: auto;
    margin-top: 40px;
    text-align: center;
}

/* ── Arrow Indicator: square shaft, oversized head, stylized ── */
.arrow {
    width: 110px;
    height: 24px;
    border-radius: 0;
    background: linear-gradient(90deg, #ffd75a 0%, #ffb832 40%, #ff8f1f 100%);
    box-shadow:
        0 0 16px rgba(255, 215, 0, 0.7),
        0 0 32px rgba(255, 180, 50, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.4),
        inset 0 -1px 0 rgba(0, 0, 0, 0.2);
    position: relative;
}

.arrow::before {
    content: '';
    position: absolute;
    right: -72px;
    top: 50%;
    width: 0;
    height: 0;
    transform: translateY(-50%);
    border-top: 52px solid transparent;
    border-bottom: 52px solid transparent;
    border-left: 72px solid #ffb432;
    filter: drop-shadow(0 0 18px rgba(255, 180, 50, 0.9))
            drop-shadow(0 0 8px rgba(255, 140, 0, 0.5));
}

.arrow::after {
    content: '';
    position: absolute;
    inset: 3px 28px 3px 3px;
    border-radius: 0;
    background: linear-gradient(90deg, rgba(255,255,255,0.45) 0%, rgba(255,255,255,0.15) 50%, transparent 100%);
}

@keyframes arrowPulse {
    0%, 100% {
        transform: translateX(0) scale(1);
        filter: drop-shadow(0 0 15px rgba(255, 215, 0, 0.6));
    }
    50% {
        transform: translateX(10px) scale(1.1);
        filter: drop-shadow(0 0 25px rgba(255, 215, 0, 0.9));
    }
}

/* ── Wheel ── */
.wheel {
    width: 500px;
    height: 600px;
    position: relative;
    left: -50px;
    transform-style: preserve-3d;
    transition: transform var(--spin-duration) var(--spin-ease);
    will-change: transform;
}

.wheel.no-transition {
    transition: none !important;
}

/* ── Cards ── */
.card {
    position: absolute;
    width: var(--card-width);
    height: var(--card-height);
    left: 50%;
    top: 50%;
    margin-left: calc(var(--card-width) / -2);
    margin-top: calc(var(--card-height) / -2);
    background: var(--dark-bg);
    border-radius: 14px;
    box-shadow:
        0 10px 40px rgba(0,0,0,0.6),
        0 0 15px rgba(139, 0, 0, 0.3),
        inset 0 1px 0 rgba(255,255,255,0.05);
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px;
    border: 2px solid rgba(255, 68, 68, 0.25);
}

.card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 10px;
}

.card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        180deg,
        rgba(255,255,255,0.04) 0%,
        rgba(0,0,0,0) 40%,
        rgba(0,0,0,0.3) 100%
    );
    pointer-events: none;
    border-radius: 14px;
    z-index: 1;
}

.center-frame {
    position: absolute;
    width: calc(var(--card-width) + 110px);
    height: calc(var(--card-height) + 150px);
    border-radius: 18px;
    border: 3px solid rgba(255, 215, 0, 0.85);
    box-shadow: 0 0 18px rgba(255, 215, 0, 0.55), 0 0 40px rgba(255, 165, 0, 0.3);
    pointer-events: none;
    transform: translate(-50%, -50%);
    margin-left: 66px;
    z-index: 6;
    animation: centerFramePulse 1.8s ease-in-out infinite;
}

.center-frame::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 56px;
    height: 56px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    pointer-events: none;
    z-index: -1;
    background: radial-gradient(circle, rgba(255,245,180,0.95) 0%, rgba(255,180,40,0.7) 30%, rgba(255,80,0,0.3) 60%, rgba(255,60,0,0) 100%);
    animation: frameFireBurst 2.2s ease-out infinite;
}

.center-frame.is-hidden {
    opacity: 0;
    visibility: hidden;
}

@keyframes centerFramePulse {
    0%, 100% {
        border-color: rgba(255, 215, 0, 0.75);
        box-shadow: 0 0 12px rgba(255, 215, 0, 0.4), 0 0 28px rgba(255, 165, 0, 0.2);
    }
    50% {
        border-color: rgba(255, 235, 140, 1);
        box-shadow: 0 0 24px rgba(255, 215, 0, 0.75), 0 0 48px rgba(255, 165, 0, 0.45);
    }
}

@keyframes frameFireBurst {
    0% {
        transform: translate(-50%, -50%) scale(0.15);
        opacity: 0.95;
    }
    70% {
        transform: translate(-50%, -50%) scale(3.1);
        opacity: 0.32;
    }
    100% {
        transform: translate(-50%, -50%) scale(4.2);
        opacity: 0;
    }
}

.card-number {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(20, 0, 0, 0.9);
    color: var(--gold);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    z-index: 2;
    box-shadow: 0 2px 10px rgba(0,0,0,0.6);
    border: 2px solid var(--gold-dim);
    font-family: 'Russo One', sans-serif;
}

/* ── Start Button (with double parallel snake outline) ── */
.start-button-wrap {
    display: inline-block;
    position: relative;
}

/* Outer snake ring — 2 parallel snakes */
.start-button-wrap::before {
    content: '';
    position: absolute;
    inset: -10px;
    border-radius: 60px;
    padding: 4px;
    background: conic-gradient(
        from var(--snake-angle, 0deg),
        rgba(255, 215, 0, 0.05) 0deg,
        rgba(255, 215, 0, 0.12) 80deg,
        rgba(255, 200, 50, 0.45) 120deg,
        #FFE55C 150deg,
        #FFF8DC 165deg,
        #FFD700 175deg,
        rgba(255, 215, 0, 0.05) 180deg,
        rgba(255, 215, 0, 0.12) 260deg,
        rgba(255, 200, 50, 0.45) 300deg,
        #FFE55C 330deg,
        #FFF8DC 345deg,
        #FFD700 355deg,
        rgba(255, 215, 0, 0.05) 360deg
    );
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    animation: snakeBorder 2.2s linear infinite;
    z-index: 0;
    box-shadow: 0 0 18px rgba(255, 215, 0, 0.5);
}

/* Inner snake ring — 2 parallel snakes */
.start-button-wrap::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 54px;
    padding: 4px;
    background: conic-gradient(
        from var(--snake-angle, 0deg),
        rgba(255, 215, 0, 0.05) 0deg,
        rgba(255, 215, 0, 0.12) 80deg,
        rgba(255, 200, 50, 0.45) 120deg,
        #FFE55C 150deg,
        #FFF8DC 165deg,
        #FFD700 175deg,
        rgba(255, 215, 0, 0.05) 180deg,
        rgba(255, 215, 0, 0.12) 260deg,
        rgba(255, 200, 50, 0.45) 300deg,
        #FFE55C 330deg,
        #FFF8DC 345deg,
        #FFD700 355deg,
        rgba(255, 215, 0, 0.05) 360deg
    );
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    animation: snakeBorder 2.2s linear infinite;
    z-index: 0;
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.45);
}

.start-button {
    position: relative;
    background: linear-gradient(135deg, #D32F2F 0%, #B71C1C 50%, var(--primary-red) 100%);
    color: white;
    border: none;
    padding: 20px 60px;
    font-size: 1.8rem;
    font-weight: 700;
    font-family: 'Russo One', sans-serif;
    border-radius: 50px;
    cursor: pointer;
    box-shadow:
        0 8px 30px rgba(139, 0, 0, 0.6),
        0 0 20px rgba(255, 0, 0, 0.15),
        inset 0 1px 0 rgba(255,255,255,0.15);
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 4px;
    overflow: hidden;
}

.start-button::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 50%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 245, 220, 0.4) 40%,
        rgba(255, 255, 255, 0.25) 50%,
        rgba(255, 245, 220, 0.4) 60%,
        transparent 100%
    );
    transform: skewX(-16deg);
    animation: shimmer 2.8s ease-in-out infinite;
    pointer-events: none;
    z-index: 1;
}

@keyframes shimmer {
    0%   { transform: skewX(-16deg) translateX(-100%); }
    100% { transform: skewX(-16deg) translateX(250%); }
}

@keyframes snakeBorder {
    0%   { --snake-angle: 0deg; }
    100% { --snake-angle: 360deg; }
}

.start-button:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow:
        0 14px 40px rgba(139, 0, 0, 0.7),
        0 0 30px rgba(255, 0, 0, 0.25),
        inset 0 1px 0 rgba(255,255,255,0.2);
}

.start-button:active:not(:disabled) {
    transform: translateY(-1px);
}

.start-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.start-button:disabled::after {
    animation: none;
}

/* ── Modal ── */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.modal-content {
    background: linear-gradient(160deg, #1a0505 0%, #0d0000 100%);
    padding: 28px 32px;
    border-radius: 22px;
    text-align: center;
    max-width: 800px;
    width: 90%;
    box-shadow:
        0 25px 80px rgba(0,0,0,0.9),
        0 0 40px rgba(255, 215, 0, 0.1),
        inset 0 1px 0 rgba(255,255,255,0.05);
    animation: modalPopIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 2px solid rgba(255, 215, 0, 0.2);
}

@keyframes modalPopIn {
    from { transform: scale(0.8) translateY(30px); opacity: 0; }
    to   { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-content h2 {
    color: var(--gold);
    font-size: 3.7rem;
    margin-bottom: 14px;
    font-family: 'Russo One', sans-serif;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
}

.modal-content .winner-card {
    width: 700px;
    height: 1000px;
    margin: 12px auto;
    border-radius: 14px;
    box-shadow:
        0 12px 40px rgba(0, 0, 0, 0.6),
        0 0 25px rgba(255, 215, 0, 0.2);
    overflow: hidden;
    position: relative;
    border: 2px solid rgba(255, 215, 0, 0.4);
    animation: cardGlowPulse 2s ease-in-out infinite;
}

/* Pulsing golden border glow */
@keyframes cardGlowPulse {
    0%, 100% {
        box-shadow:
            0 12px 40px rgba(0,0,0,0.6),
            0 0 20px rgba(255, 215, 0, 0.2),
            0 0 0px rgba(255, 215, 0, 0);
    }
    50% {
        box-shadow:
            0 12px 50px rgba(0,0,0,0.7),
            0 0 35px rgba(255, 215, 0, 0.45),
            0 0 60px rgba(255, 165, 0, 0.2);
    }
}

/* Sweeping lightwave over the winner image */
.modal-content .winner-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        115deg,
        transparent 0%,
        transparent 30%,
        rgba(255, 255, 255, 0.18) 45%,
        rgba(255, 240, 180, 0.28) 50%,
        rgba(255, 255, 255, 0.18) 55%,
        transparent 70%,
        transparent 100%
    );
    animation: lightwave 2.4s ease-in-out infinite;
    pointer-events: none;
    z-index: 2;
}

@keyframes lightwave {
    0%   { transform: translateX(-120%); }
    60%  { transform: translateX(120%); }
    100% { transform: translateX(120%); }
}

.modal-content .winner-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.modal-content .winner-number {
    position: absolute;
    top: 12px;
    right: 12px;
    background: linear-gradient(135deg, var(--gold) 0%, var(--orange) 100%);
    color: #1a0000;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    font-family: 'Russo One', sans-serif;
    box-shadow: 0 4px 16px rgba(255, 215, 0, 0.55);
    z-index: 3;
}

.modal-content p {
    color: #ccc;
    font-size: 1rem;
    margin: 14px 0;
}

.spin-again-button {
    background: linear-gradient(135deg, var(--gold) 0%, var(--orange) 100%);
    color: #1a0000;
    border: none;
    padding: 12px 36px;
    font-size: 1.8rem;
    font-weight: 700;
    font-family: 'Russo One', sans-serif;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 6px 25px rgba(255, 215, 0, 0.4);
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.spin-again-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 35px rgba(255, 215, 0, 0.55);
}

/* ── History Section ── */
.history-section {
    background: rgba(10, 0, 0, 0.95);
    border-radius: 20px;
    padding: 24px;
    box-shadow:
        0 10px 50px rgba(0, 0, 0, 0.6),
        inset 0 1px 0 rgba(255,255,255,0.03);
    width: 600px;
    max-height: 1000px;
    overflow-y: auto;
    border: 2px solid rgba(255, 0, 0, 0.15);
    scrollbar-width: thin;
    scrollbar-color: rgba(139,0,0,0.5) transparent;
}

.history-section::-webkit-scrollbar { width: 6px; }
.history-section::-webkit-scrollbar-track { background: transparent; }
.history-section::-webkit-scrollbar-thumb {
    background: rgba(139,0,0,0.5);
    border-radius: 3px;
}

.history-header {
    text-align: center;
    margin-bottom: 20px;
}

.history-header h1 {
    font-family: 'Russo One', sans-serif;
    font-size: 3rem;
    color: var(--gold);
    text-shadow: 0 0 15px rgba(255, 215, 0, 0.2);
    margin-bottom: 8px;
}

.history-header h3 {
    color: var(--light-red);
    font-size: 2.4rem;
    margin-bottom: 5px;
    font-weight: 600;
}

.history-count {
    color: rgba(255, 107, 107, 0.7);
    font-size: 1.7rem;
}

.history-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-card-item {
    background: rgba(30, 0, 0, 0.8);
    border-radius: 10px;
    padding: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideInRight 0.4s ease;
    border: 1px solid rgba(255, 0, 0, 0.12);
    transition: border-color 0.2s, background 0.2s;
}

.history-card-item:hover {
    border-color: rgba(255, 215, 0, 0.25);
    background: rgba(40, 5, 5, 0.9);
}

@keyframes slideInRight {
    from { transform: translateX(50px); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}

.history-card-item img {
    width: 120px;
    height: 180px;
    object-fit: cover;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.history-card-info { flex: 1; }

.history-card-number {
    background: linear-gradient(135deg, #FF0000, #CC0000);
    color: white;
    padding: 4px 12px;
    border-radius: 15px;
    font-weight: 700;
    font-size: 1.7rem;
    display: inline-block;
    margin-bottom: 4px;
}

.history-card-order {
    color: rgba(255, 107, 107, 0.6);
    font-size: 0.8rem;
}

.empty-history {
    text-align: center;
    color: rgba(255, 107, 107, 0.5);
    padding: 40px 20px;
    font-style: italic;
    font-size: 0.9rem;
}

.reset-button {
    width: 100%;
    margin-top: 15px;
    background: linear-gradient(135deg, #CC0000 0%, var(--primary-red) 100%);
    color: white;
    border: none;
    padding: 12px;
    font-size: 1.9rem;
    font-weight: 700;
    font-family: 'Russo One', sans-serif;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 2px;
    box-shadow: 0 4px 15px rgba(139, 0, 0, 0.3);
}

.reset-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(255, 0, 0, 0.4);
}

.completion-message {
    background: linear-gradient(135deg, var(--gold) 0%, var(--orange) 100%);
    color: #1a0000;
    padding: 15px;
    border-radius: 10px;
    text-align: center;
    font-weight: 700;
    font-family: 'Russo One', sans-serif;
    margin-bottom: 15px;
    animation: completionPulse 2s ease-in-out infinite;
    display: none;
    box-shadow: 0 4px 20px rgba(255, 215, 0, 0.3);
}

@keyframes completionPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 4px 20px rgba(255, 215, 0, 0.3); }
    50%      { transform: scale(1.02); box-shadow: 0 4px 30px rgba(255, 215, 0, 0.5); }
}

/* ── Responsive ── */
@media (max-width: 768px) {
    :root {
        --card-width: 150px;
        --card-height: 225px;
    }

    .main-container { flex-direction: column; }

    .history-section {
        width: 100%;
        max-width: 400px;
        max-height: 400px;
    }

    .wheel-container {
        height: 500px;
        max-width: 450px;
    }

    .wheel {
        width: 300px;
        height: 400px;
    }

    .card-number {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    .arrow {
        width: 88px;
        height: 20px;
    }

    .arrow::before {
        right: -58px;
        border-top-width: 42px;
        border-bottom-width: 42px;
        border-left-width: 58px;
    }

    .arrow::after {
        inset: 2px 22px 2px 2px;
    }

    .modal-content .winner-card {
        width: 180px;
        height: 270px;
    }

    .start-button {
        padding: 15px 40px;
        font-size: 1.4rem;
    }
}
