:root {
    --gold: #ffd700;
    --gold-bright: #fff370;
    --gold-dark: #8c6c0a;
    --cyan: #00f0ff;
    --emerald: #00ff88;
    --ruby: #ff3366;
    --purple: #cc33ff;
    --dark-bg: #040c14;
    --radius-md: 16px;
    --radius-lg: 24px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--dark-bg);
    color: white;
    overflow: hidden;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.bonus-container {
    position: relative;
    width: 100%;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* ───────────────────────────────────────── */
/*  CLEAN PIRATE CAVE BACKGROUND             */
/* ───────────────────────────────────────── */
.background-layer {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse 90% 70% at 50% 50%, rgba(4, 12, 20, 0.2) 0%, rgba(4, 12, 20, 0.65) 100%),
        url('assets/bg_cave.webp') center/cover no-repeat fixed var(--dark-bg);
    z-index: 1;
}

.background-layer::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 50% at 50% 10%, rgba(0, 240, 255, 0.12) 0%, transparent 60%),
        radial-gradient(ellipse 60% 40% at 50% 90%, rgba(255, 215, 0, 0.12) 0%, transparent 60%);
    pointer-events: none;
    animation: ambientTorch 7s ease-in-out infinite alternate;
}

@keyframes ambientTorch {
    0% { opacity: 0.75; transform: scale(1); }
    100% { opacity: 1; transform: scale(1.02); }
}

/* UI Overlay Grid Container */
.ui-overlay {
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 1200px;
    height: 100dvh;
    padding: clamp(12px, 2.5vh, 24px) 16px;
    box-sizing: border-box;
}

/* ───────────────────────────────────────── */
/*  HEADER BANNER                            */
/* ───────────────────────────────────────── */
.header-banner {
    text-align: center;
    background: linear-gradient(180deg, rgba(8, 26, 44, 0.92) 0%, rgba(4, 14, 24, 0.95) 100%);
    border: 2px solid var(--cyan);
    border-radius: var(--radius-md);
    padding: clamp(8px, 1.5vh, 12px) clamp(20px, 4vw, 40px);
    box-shadow:
        0 0 30px rgba(0, 240, 255, 0.4),
        0 8px 24px rgba(0, 0, 0, 0.7),
        inset 0 0 15px rgba(0, 240, 255, 0.2);
    position: relative;
    max-width: 680px;
    width: 100%;
    flex-shrink: 0;
}

.header-banner::before,
.header-banner::after {
    content: '✦';
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.2rem;
    color: var(--cyan);
    text-shadow: 0 0 10px var(--cyan);
}

.header-banner::before { left: 16px; }
.header-banner::after { right: 16px; }

.marquee-title {
    font-family: 'Cinzel', serif;
    font-size: clamp(1.4rem, 5vw, 2.6rem);
    font-weight: 900;
    text-transform: uppercase;
    background: linear-gradient(180deg, #ffffff 0%, #fff0a0 30%, var(--gold) 70%, var(--gold-dark) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 0.08em;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.9)) drop-shadow(0 0 14px rgba(255, 215, 0, 0.5));
    line-height: 1.1;
}

.marquee-subtitle {
    font-size: clamp(0.7rem, 2.5vw, 1.1rem);
    font-weight: 700;
    color: var(--cyan);
    letter-spacing: 0.1em;
    text-shadow: 0 0 8px rgba(0, 240, 255, 0.8);
    margin-top: 2px;
}

/* ───────────────────────────────────────── */
/*  FLUID 3D CHEST SELECTION GRID            */
/* ───────────────────────────────────────── */
.chest-selection-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 0;
    position: relative;
    padding: 10px 0;
}

.chests-grid {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: clamp(10px, 2.5vw, 28px);
    width: 100%;
    max-width: 1100px;
}

/* Individual 3D Chest Card */
.chest-card {
    flex: 1;
    max-width: 190px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    position: relative;
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.4s;
}

.chest-card:hover:not(.opened):not(.disabled) {
    transform: translateY(-12px) scale(1.08);
}

.chest-card:active:not(.opened):not(.disabled) {
    transform: translateY(-2px) scale(0.97);
}

/* Number Badge */
.chest-badge {
    font-family: 'Cinzel', serif;
    font-size: clamp(1.2rem, 3.5vw, 2.2rem);
    font-weight: 900;
    color: var(--gold-bright);
    text-shadow: 0 0 12px var(--gold), 0 2px 6px rgba(0, 0, 0, 0.9);
    margin-bottom: 4px;
    z-index: 5;
}

/* 3D Chest Image & Aura Glow */
.chest-img-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chest-aura {
    position: absolute;
    inset: 10%;
    border-radius: 50%;
    opacity: 0.45;
    filter: blur(18px);
    transition: opacity 0.35s, filter 0.35s;
    pointer-events: none;
}

.chest-card:hover .chest-aura {
    opacity: 0.9;
    filter: blur(24px);
}

.chest-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    position: relative;
    z-index: 2;
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.8));
    transition: transform 0.35s, filter 0.35s;
}

.chest-card:hover .chest-img {
    filter: drop-shadow(0 15px 30px rgba(0, 0, 0, 0.9)) brightness(1.1);
}

/* Title Tag Badge */
.chest-title-tag {
    font-size: clamp(0.55rem, 1.5vw, 0.78rem);
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #ffffff;
    background: rgba(8, 24, 40, 0.85);
    border: 1.5px solid rgba(255, 255, 255, 0.25);
    border-radius: 12px;
    padding: 4px 10px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    margin-top: 6px;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
    transition: border-color 0.3s, color 0.3s;
}

/* ───────────────────────────────────────── */
/*  CHEST THEME COLOR GLOWS                  */
/* ───────────────────────────────────────── */
/* 1. Skull (Cyan) */
.chest-skull .chest-aura { background: var(--cyan); }
.chest-skull:hover .chest-title-tag { border-color: var(--cyan); color: var(--cyan); }

/* 2. Anchor (Gold) */
.chest-anchor .chest-aura { background: var(--gold); }
.chest-anchor:hover .chest-title-tag { border-color: var(--gold); color: var(--gold-bright); }

/* 3. Emerald (Green) */
.chest-emerald .chest-aura { background: var(--emerald); }
.chest-emerald:hover .chest-title-tag { border-color: var(--emerald); color: var(--emerald); }

/* 4. Compass (Ruby Red) */
.chest-compass .chest-aura { background: var(--ruby); }
.chest-compass:hover .chest-title-tag { border-color: var(--ruby); color: #ff88a8; }

/* 5. Crown (Royal Purple) */
.chest-crown .chest-aura { background: var(--purple); }
.chest-crown:hover .chest-title-tag { border-color: var(--purple); color: #e699ff; }

/* Disabled / Opened State */
.chest-card.disabled {
    opacity: 0.35;
    cursor: default;
    filter: grayscale(0.5);
    transform: scale(0.94);
}

.chest-card.opened {
    transform: scale(1.12) !important;
}

.chest-card.opened .chest-aura {
    opacity: 1;
    filter: blur(30px);
}

/* ───────────────────────────────────────── */
/*  FOOTER MARQUEE                           */
/* ───────────────────────────────────────── */
.footer-banner {
    text-align: center;
    background: linear-gradient(180deg, rgba(6, 18, 30, 0.95) 0%, rgba(2, 8, 15, 0.98) 100%);
    border: 2px solid var(--gold);
    border-radius: var(--radius-md);
    padding: clamp(8px, 1.5vh, 12px) clamp(16px, 3vw, 32px);
    box-shadow: 0 0 25px rgba(255, 215, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.8);
    max-width: 760px;
    width: 100%;
    flex-shrink: 0;
}

.footer-instructions {
    font-size: clamp(0.65rem, 2.2vw, 0.95rem);
    font-weight: 700;
    color: var(--cyan);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    text-shadow: 0 0 8px rgba(0, 240, 255, 0.6);
    margin-bottom: 2px;
}

.footer-title {
    font-family: 'Cinzel', serif;
    font-size: clamp(1.1rem, 3.8vw, 1.9rem);
    font-weight: 900;
    color: var(--gold-bright);
    letter-spacing: 0.1em;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.7);
    text-transform: uppercase;
}

/* ───────────────────────────────────────── */
/*  WIN REVEAL MODAL                         */
/* ───────────────────────────────────────── */
.win-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(4, 12, 20, 0.82);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: none;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.win-modal-overlay.show {
    display: flex;
    animation: modalFadeIn 0.35s ease-out forwards;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.win-modal-card {
    background: linear-gradient(145deg, rgba(14, 34, 54, 0.96) 0%, rgba(6, 16, 28, 0.98) 100%);
    border: 2px solid var(--gold);
    border-radius: var(--radius-lg);
    padding: clamp(24px, 5vw, 40px) clamp(20px, 6vw, 48px);
    text-align: center;
    max-width: 440px;
    width: 100%;
    box-shadow: 0 0 70px rgba(255, 215, 0, 0.4), 0 20px 50px rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: cardPopIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes cardPopIn {
    from { opacity: 0; transform: scale(0.8) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-badge-icon {
    width: clamp(110px, 25vw, 150px);
    height: clamp(110px, 25vw, 150px);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 4px;
    filter: drop-shadow(0 0 25px rgba(255, 215, 0, 0.7));
    animation: chestFloat 3s ease-in-out infinite alternate;
}

.modal-chest-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

@keyframes chestFloat {
    0% { transform: translateY(0) scale(1); }
    100% { transform: translateY(-8px) scale(1.06); }
}

.modal-title {
    font-family: 'Cinzel', serif;
    font-size: clamp(1.4rem, 4.5vw, 2.2rem);
    font-weight: 900;
    color: var(--gold-bright);
    letter-spacing: 0.08em;
    text-shadow: 0 0 12px rgba(255, 215, 0, 0.6);
    margin-bottom: 4px;
}

.modal-prize-name {
    font-size: clamp(0.9rem, 3vw, 1.25rem);
    font-weight: 900;
    color: var(--cyan);
    letter-spacing: 0.06em;
    text-shadow: 0 0 10px rgba(0, 240, 255, 0.7);
    margin-bottom: 12px;
}

.modal-prize-amount {
    font-size: clamp(2.2rem, 8vw, 3.6rem);
    font-weight: 900;
    color: #ffffff;
    text-shadow: 0 0 25px rgba(255, 215, 0, 0.7), 0 4px 8px rgba(0,0,0,0.9);
    line-height: 1.1;
    margin-bottom: 24px;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.btn-action {
    font-family: 'Outfit', sans-serif;
    font-size: clamp(0.95rem, 3.2vw, 1.2rem);
    font-weight: 900;
    letter-spacing: 0.08em;
    padding: clamp(10px, 2vh, 14px) 24px;
    border-radius: 35px;
    border: none;
    cursor: pointer;
    text-transform: uppercase;
    transition: transform 0.2s, box-shadow 0.2s;
    width: 100%;
}

.btn-collect {
    background: linear-gradient(135deg, var(--gold-bright) 0%, var(--gold) 100%);
    color: var(--dark-bg);
    box-shadow: 0 6px 20px rgba(255, 215, 0, 0.5);
}

.btn-collect:hover {
    transform: scale(1.04);
    box-shadow: 0 8px 30px rgba(255, 215, 0, 0.7);
}

.btn-replay {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #ffffff;
}

.btn-replay:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.02);
}

/* ───────────────────────────────────────── */
/*  RESPONSIVE MOBILE BREAKPOINTS             */
/* ───────────────────────────────────────── */
@media (max-width: 767px) {
    .chests-grid {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
        gap: 14px 18px;
        max-width: 480px;
        padding: 0 12px;
    }

    .chest-card {
        flex: 0 1 calc(33.33% - 14px);
        max-width: 135px;
    }

    /* Center the 4th and 5th chests on row 2 */
    .chest-card:nth-child(4),
    .chest-card:nth-child(5) {
        flex: 0 1 calc(40% - 14px);
        max-width: 140px;
    }

    .chest-badge {
        font-size: 1.4rem;
        margin-bottom: 2px;
    }

    .chest-title-tag {
        font-size: 0.58rem;
        padding: 3px 8px;
    }

    .header-banner::before,
    .header-banner::after {
        display: none;
    }
}

@media (max-width: 420px) {
    .chests-grid {
        gap: 10px 12px;
        max-width: 360px;
    }

    .chest-card {
        flex: 0 1 calc(33.33% - 10px);
        max-width: 105px;
    }

    .chest-card:nth-child(4),
    .chest-card:nth-child(5) {
        flex: 0 1 calc(42% - 10px);
        max-width: 115px;
    }

    .chest-badge {
        font-size: 1.2rem;
    }

    .chest-title-tag {
        font-size: 0.5rem;
        padding: 2px 6px;
    }
}
