/* Chests page - fit viewport, hero image left / text right, no scroll on desktop */
.chests-page {
    height: 100vh;
    min-height: 100vh;
    background-image: linear-gradient(rgba(10, 10, 15, 0.72), rgba(10, 10, 15, 0.72)), url('/images/casino-bg2.jpg');
    background-size: cover;
    background-position: center top;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chests-nav {
    flex-shrink: 0;
}

.chests-main {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 0;
    padding-top: 70px; /* clear fixed navbar */
    overflow: hidden;
    background-image: linear-gradient(rgba(10, 10, 15, 0.72), rgba(10, 10, 15, 0.72)), url('/images/casino-bg2.jpg');
    background-size: cover;
    background-position: center top;
}

/* Hero: whole block (image + text + logos) centered on page, scaled to fill space */
.chests-hero {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 32px 12px;
    width: 100%;
}

.chests-hero-inner {
    display: flex;
    align-items: center;
    gap: 40px;
}

.chests-hero-img-wrap {
    flex-shrink: 0;
    width: min(360px, 32vw);
}

.chests-hero-img {
    width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
}

.chests-hero-content {
    flex: 1;
    min-width: 0;
    text-align: left;
}

.chests-hero-title {
    font-size: clamp(32px, 5vw, 52px);
    font-weight: 800;
    margin: 0 0 10px;
    background: var(--gradient-1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.chests-hero-subtitle {
    font-size: clamp(17px, 2.2vw, 22px);
    color: var(--text-primary);
    margin: 0 0 8px;
    line-height: 1.4;
}

.chests-hero-partner-text {
    font-size: clamp(14px, 1.5vw, 17px);
    color: var(--text-secondary);
    margin: 0 0 16px;
}

.chests-partner-logos {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.partner-logo {
    display: block;
    width: 64px;
    height: 64px;
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    transition: transform 0.2s, box-shadow 0.2s;
}

.partner-logo:hover {
    transform: scale(1.08);
    box-shadow: 0 8px 24px rgba(139, 92, 246, 0.2);
}

.partner-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Mobile only: hero – row1 image+title centered + same vertical center, row2 subtitle, row3 partner text, row4 logos */
@media (max-width: 600px) {
    .chests-page,
    .chests-main {
        background-position: left top;
    }

    .chests-hero {
        padding: 12px 24px 10px;
    }

    .chests-hero-inner {
        display: grid;
        grid-template-columns: 1fr auto auto 1fr;
        grid-template-rows: auto auto auto auto;
        gap: 10px 14px;
        max-width: 100%;
        justify-items: center;
        align-items: center;
    }

    .chests-hero-content {
        display: contents;
    }

    .chests-hero-img-wrap {
        grid-row: 1;
        grid-column: 2;
        width: 106px;
        justify-self: end;
        align-self: center;
    }

    .chests-hero-title {
        grid-row: 1;
        grid-column: 3;
        justify-self: start;
        align-self: center;
        margin: 0;
        margin-top: 25px;
        font-size: 26px;
    }

    .chests-hero-subtitle {
        grid-row: 2;
        grid-column: 1 / -1;
        font-size: 14px;
        margin: 0 0 4px;
        line-height: 1.5;
        padding: 0 8px;
        text-align: center;
    }

    .chests-hero-partner-text {
        grid-row: 3;
        grid-column: 1 / -1;
        font-size: 12px;
        margin: 0 0 14px;
        padding: 0 8px;
        line-height: 1.4;
        text-align: center;
    }

    .chests-partner-logos {
        grid-row: 4;
        grid-column: 1 / -1;
        justify-content: center;
        gap: 12px;
    }

    .partner-logo {
        width: 44px;
        height: 44px;
        border-radius: 10px;
    }
}

/* Chests row: all three in view, content-sized height */
.chests-carousel-section {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 8px 24px 16px;
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
}

/* Hide carousel arrows on desktop (all three chests in view) */
@media (min-width: 901px) {
    .carousel-btn {
        display: none !important;
    }
}

.carousel-btn {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s, transform 0.2s;
}

.carousel-btn:hover:not(:disabled) {
    background: rgba(139, 92, 246, 0.2);
    color: var(--primary-light);
    transform: scale(1.05);
}

.carousel-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.chests-carousel-wrap {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.chests-carousel {
    display: flex;
    align-items: stretch;
    gap: 24px;
    transition: transform 0.35s ease-out;
    justify-content: center;
    padding: 4px 0;
}

.chests-carousel .chest-card {
    flex: 0 1 300px;
    min-width: 280px;
    max-width: 320px;
    scroll-snap-align: center;
}

/* Chest cards: distinct borders (bronze, silver, gold), slightly thicker */
.chest-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: 16px;
    padding: 14px 12px;
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}

.chest-card:not(.chest-card-disabled):hover {
    transform: translateY(-4px);
}

.chest-card-bronze {
    border-color: #b87333;
}

.chest-card-bronze:not(.chest-card-disabled):hover {
    box-shadow: 0 12px 40px rgba(205, 127, 50, 0.25);
}

.chest-card-silver {
    border-color: #c0c0c0;
}

.chest-card-gold {
    border-color: #d4af37;
}

.chest-card-disabled {
    opacity: 0.7;
}

.chest-visual {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 0;
}

.chest-img {
    width: 100%;
    max-width: 200px;
    height: auto;
    max-height: 160px;
    object-fit: contain;
    filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.4));
}

.chest-card-bronze .chest-img {
    filter: drop-shadow(0 8px 24px rgba(205, 127, 50, 0.3));
}

.chest-name {
    font-size: clamp(18px, 2.5vw, 22px);
    font-weight: 700;
    margin: 0 0 6px;
    color: var(--text-primary);
}

.chest-price {
    font-size: 15px;
    color: var(--primary-light);
    margin: 0 0 10px;
}

.chest-card-disabled .chest-price {
    color: var(--text-muted);
}

.price-amount {
    font-weight: 700;
}

.price-usd {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 400;
}

.coming-soon-price {
    color: var(--text-muted);
    font-style: italic;
}

/* 80% win chance badge: top-right of tile, transparent, gold */
.win-chance-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    border-radius: 10px;
    background: transparent;
    border: 1px solid #d4af37;
    text-align: center;
    line-height: 1.2;
}

.win-chance-badge .win-chance-value {
    font-size: 16px;
    font-weight: 800;
    color: #d4af37;
    display: block;
}

.win-chance-badge .win-chance-label {
    font-size: 9px;
    color: #d4af37;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.2;
}

/* Available prizes link */
.available-prizes-link {
    font-size: 12px;
    color: var(--primary-light);
    text-decoration: underline;
    margin-bottom: 8px;
    cursor: pointer;
}

.available-prizes-link:hover {
    color: var(--text-primary);
}

.chest-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
    padding: 14px 0 10px;
}

.chest-actions .btn {
    width: 100%;
    justify-content: center;
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 600;
}

.btn-chest {
    background: var(--gradient-1);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-chest:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.4);
}

.btn-chest:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-open {
    background: linear-gradient(135deg, #cd7f32 0%, #b8860b 100%);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
}

.btn-open:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(205, 127, 50, 0.4);
}

.chest-actions .btn-open:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-disabled {
    background: var(--bg-darker);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px 20px;
    font-size: 15px;
    cursor: not-allowed;
    width: 100%;
}

.chest-card .btn-disabled {
    margin-top: 14px;
    margin-bottom: 6px;
}

.chest-owned {
    font-size: 12px;
    color: var(--text-muted);
    margin: 8px 0 0;
}

/* Available prizes modal */
.available-prizes-modal .chest-modal-content {
    text-align: left;
    max-width: 420px;
}

.available-prizes-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.available-prizes-list .prize-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 14px;
}

.available-prizes-list .prize-item:last-child {
    border-bottom: none;
}

.available-prizes-list .prize-thumb {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.available-prizes-list .prize-label {
    flex: 1;
}

.available-prizes-list .prize-usd {
    color: var(--text-muted);
    font-size: 12px;
}

/* Nav links on chests page */
.chests-page .nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    font-size: 15px;
}

.chests-page .nav-link:hover {
    color: var(--text-primary);
}

.chests-page .nav-link-active {
    color: var(--primary-light);
}

.chests-page .wallet-connect-btn {
    padding: 8px 20px;
    background: var(--gradient-1);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.chests-page .wallet-connect-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.chests-page .wallet-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chests-page .wallet-info span {
    font-size: 12px;
    color: var(--text-secondary);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chests-page .wallet-disconnect-btn {
    padding: 6px 12px;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
}

.chests-page .wallet-disconnect-btn:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}

.chests-page .exit-home-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: color 0.2s, background 0.2s;
}

.chests-page .exit-home-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
}

/* Result modal */
.chest-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.chest-modal[aria-hidden="false"] {
    opacity: 1;
    visibility: visible;
}

.chest-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.82);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    cursor: pointer;
}

.fireworks-canvas-wrap {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
}

.fireworks-canvas-wrap[aria-hidden="true"] {
    visibility: hidden;
}

.fireworks-canvas-wrap canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.chest-modal-content {
    position: relative;
    z-index: 2;
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: 20px;
    padding: 32px;
    max-width: 400px;
    width: 100%;
    text-align: center;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
}

/* Result modal: square, video fills then fades; win/lose overlaid */
.result-modal-square {
    max-width: min(90vmin, 420px);
    width: min(90vmin, 420px);
    aspect-ratio: 1;
    padding: 0;
    overflow: hidden;
}

.result-video-wrap {
    position: absolute;
    inset: 0;
    z-index: 0;
    background: #000;
    transition: opacity 0.6s ease;
}

.result-video-wrap.result-video-faded {
    opacity: 0.15;
}

.result-video-wrap video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.result-modal-square .result-overlay {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.result-modal-square .result-overlay[aria-hidden="false"] {
    opacity: 1;
    pointer-events: auto;
}

.result-modal-square .result-overlay .result-panel {
    max-width: 100%;
}

.result-modal-square .chest-modal-close {
    z-index: 3;
}

.chest-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    border-radius: 8px;
}

.chest-modal-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
}

.result-panel {
    padding: 8px 0;
}

/* Lose: empty-chest icon with animation */
.result-lose-icon {
    margin: 0 auto 16px;
    width: 80px;
    height: 80px;
    color: var(--text-muted);
    animation: result-lose-wiggle 1.2s ease-in-out infinite;
}

.result-lose-svg {
    width: 100%;
    height: 100%;
    display: block;
}

@keyframes result-lose-wiggle {
    0%, 100% { transform: rotate(-2deg) scale(1); }
    25% { transform: rotate(2deg) scale(1.02); }
    50% { transform: rotate(-2deg) scale(0.98); }
    75% { transform: rotate(2deg) scale(1.02); }
}

.result-heading {
    font-size: 24px;
    font-weight: 800;
    margin: 0 0 12px;
    letter-spacing: 0.02em;
}

.result-heading-lose {
    color: var(--text-muted);
}

.result-heading-win {
    background: var(--gradient-1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.result-message {
    color: var(--text-secondary);
    font-size: 15px;
    line-height: 1.5;
    margin: 0 0 20px;
}

.result-prize-label {
    color: var(--primary-light);
    font-weight: 600;
}

.result-win-prize-visual {
    margin: 16px 0 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.result-prize-img {
    width: 100px;
    height: 100px;
    object-fit: cover;
    border-radius: 16px;
    border: 2px solid var(--border-color);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.result-prize-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.btn-collect {
    background: var(--gradient-1);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 12px 32px;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-collect:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.4);
}

.btn-collect:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Responsive: single card view on small screens */
/* Mobile: one tile in view; align carousel to start so JS translateX math is correct */
@media (max-width: 700px) {
    .chests-carousel-section {
        padding-left: 12px;
        padding-right: 12px;
        gap: 8px;
    }

    .chests-carousel-wrap {
        min-width: 0;
        justify-content: flex-start;
    }

    .chests-carousel {
        justify-content: flex-start;
        gap: 16px;
    }

    .chests-carousel .chest-card {
        flex: 0 0 260px;
        width: 260px;
        min-width: 260px;
        max-width: 260px;
    }

    .carousel-btn {
        width: 40px;
        height: 40px;
        font-size: 24px;
        flex-shrink: 0;
    }
}

/* Short viewport (e.g. Phantom wallet ~600px high): scale all elements to fit */
@media (max-height: 650px) {
    .chests-main {
        padding-top: 52px;
    }

    .chests-hero {
        padding: 8px 24px 6px;
    }

    .chests-hero-inner {
        gap: 16px;
    }

    .chests-hero-img-wrap {
        width: min(180px, 28vw);
    }

    .chests-hero-title {
        font-size: clamp(22px, 4vw, 32px);
        margin-bottom: 4px;
    }

    .chests-hero-subtitle {
        font-size: clamp(13px, 1.8vw, 16px);
        margin-bottom: 2px;
    }

    .chests-hero-partner-text {
        font-size: 12px;
        margin-bottom: 8px;
    }

    .chests-partner-logos {
        gap: 10px;
    }

    .partner-logo {
        width: 40px;
        height: 40px;
        border-radius: 10px;
    }

    .chests-carousel-section {
        padding: 4px 16px 8px;
    }

    .chests-carousel .chest-card {
        padding: 10px 10px;
    }

    .chest-visual {
        padding: 6px 0;
    }

    .chest-img {
        max-width: 140px;
        max-height: 112px;
    }

    .chest-name {
        font-size: 16px;
        margin-bottom: 2px;
    }

    .chest-price {
        font-size: 13px;
        margin-bottom: 4px;
    }

    .win-chance-badge {
        top: 6px;
        right: 6px;
        padding: 4px 8px;
    }

    .win-chance-badge .win-chance-value {
        font-size: 12px;
    }

    .win-chance-badge .win-chance-label {
        font-size: 8px;
    }

    .available-prizes-link {
        font-size: 11px;
        margin-bottom: 4px;
    }

    .chest-actions {
        padding: 8px 0 6px;
        margin-top: 6px;
        gap: 6px;
    }

    .chest-actions .btn {
        padding: 8px 14px;
        font-size: 13px;
    }

    /* Modals: centered on mobile; available-prizes can scroll */
    .chest-modal {
        padding: 12px;
        align-items: center;
    }

    .chest-modal-content {
        padding: 16px 20px;
        max-height: calc(100vh - 24px);
        overflow-y: auto;
    }

    #result-modal .chest-modal-content {
        margin: auto;
    }

    .available-prizes-modal .chest-modal-content h3 {
        font-size: 16px;
        margin-bottom: 8px;
    }

    .available-prizes-list .prize-item {
        padding: 6px 10px;
        font-size: 12px;
    }

    .available-prizes-list .prize-thumb {
        width: 32px;
        height: 32px;
        border-radius: 6px;
    }

    .chest-modal-close {
        top: 8px;
        right: 8px;
        width: 30px;
        height: 30px;
        font-size: 20px;
    }

    .result-heading {
        font-size: 20px;
    }

    .result-message {
        font-size: 13px;
        margin-bottom: 16px;
    }

    .btn-collect {
        padding: 10px 24px;
        font-size: 14px;
    }
}

/* Mobile + short (e.g. Phantom): extra compact hero */
@media (max-width: 600px) and (max-height: 650px) {
    .chests-hero {
        padding: 6px 16px 4px;
    }

    .chests-hero-img-wrap {
        width: 72px;
    }

    .chests-hero-title {
        font-size: 18px;
        margin-top: 10px;
    }

    .chests-hero-subtitle {
        font-size: 12px;
    }

    .chests-hero-partner-text {
        font-size: 11px;
        margin-bottom: 6px;
    }

    .chests-partner-logos {
        gap: 8px;
    }

    .partner-logo {
        width: 32px;
        height: 32px;
        border-radius: 8px;
    }

    .chests-carousel .chest-card {
        flex: 0 0 220px;
        width: 220px;
        min-width: 220px;
        max-width: 220px;
        padding: 8px 8px;
    }

    .chest-img {
        max-width: 120px;
        max-height: 96px;
    }
}

@media (max-width: 600px) {
    .chests-page,
    .chests-main {
        background-position: left top;
    }
}
