* { box-sizing: border-box; }

:root {
    --bg: #09080d;
    --gold: #f3c56d;
    --gold-deep: #b8833a;
    --ink: #f8f1e4;
    --muted: #cbbda8;
    --line: rgba(243, 197, 109, 0.28);
    --card: rgba(18, 16, 22, 0.78);
    --danger: #ffb4b4;
    --ok: #b7f7c8;
}

html { scroll-behavior: smooth; }

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    color: var(--ink);
    font-family: "Segoe UI", sans-serif;
    background: var(--bg);
    overflow-x: hidden;
}

.bg {
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(ellipse 70% 45% at 15% -10%, rgba(226, 59, 74, 0.38), transparent 60%),
        radial-gradient(ellipse 50% 40% at 90% 0%, rgba(243, 197, 109, 0.22), transparent 55%),
        radial-gradient(ellipse 40% 30% at 50% 100%, rgba(120, 40, 160, 0.18), transparent 60%),
        var(--bg);
}

.bg::after {
    content: "";
    position: absolute;
    width: 42vw;
    height: 42vw;
    left: -8vw;
    bottom: -10vw;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(243, 197, 109, 0.16), transparent 68%);
    animation: drift 16s ease-in-out infinite alternate;
}

.wrap {
    width: min(980px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 108px;
}

.hero, .topbar, .panel, .history {
    animation: rise 0.55s ease both;
}

.panel { animation-delay: 0.08s; }
.history { animation-delay: 0.12s; }

.topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.logo {
    display: block;
    width: 100%;
    max-width: 168px;
    height: auto;
    justify-self: start;
    object-fit: contain;
}

.brand-name {
    margin: 0;
    justify-self: end;
    font-weight: 800;
    font-size: clamp(0.72rem, 3.1vw, 1.2rem);
    line-height: 1;
    white-space: nowrap;
    background: linear-gradient(120deg, #fff4d4, var(--gold) 45%, #fff 80%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.eyebrow {
    margin: 0 0 8px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    font-size: 0.75rem;
    color: var(--gold);
}

.hero h1,
.topbar h1 {
    margin: 0;
    font-size: clamp(2.2rem, 6vw, 4rem);
    line-height: 0.95;
    background: linear-gradient(120deg, #fff4d4, var(--gold) 45%, #fff 80%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.lede, .hint, .muted { color: var(--muted); line-height: 1.55; }
.lede { max-width: 38rem; margin: 12px 0 0; }

.userbar, .panel, .history {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 18px;
    margin-top: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(10px);
}

.userbar { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat {
    padding: 12px 14px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.03);
}
.stat span { display: block; color: var(--muted); font-size: 0.82rem; margin-bottom: 4px; }
.stat strong { font-size: 1.15rem; word-break: break-word; }

h2 { margin: 0 0 8px; font-size: 1.35rem; }

.claim {
    width: 100%;
    max-width: 280px;
    border: 0;
    border-radius: 999px;
    padding: 14px 22px;
    font: inherit;
    font-weight: 800;
    color: #1b140b;
    cursor: pointer;
    background: linear-gradient(180deg, #ffe0a0, var(--gold) 40%, var(--gold-deep));
    box-shadow: 0 10px 24px rgba(184, 131, 58, 0.35);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.claim:hover:not(:disabled) { transform: translateY(-2px); }
.claim:active:not(:disabled) { transform: translateY(1px) scale(0.98); }
.claim:disabled { opacity: 0.6; cursor: default; box-shadow: none; }
.claim.is-loading { animation: loadpulse 1s ease-in-out infinite; }

.claim-mini {
    justify-self: center;
    width: auto;
    max-width: none;
    margin: 0;
    padding: 8px 14px;
    font-size: 0.8rem;
    box-shadow: 0 6px 14px rgba(184, 131, 58, 0.28);
}

.tabs {
    position: fixed;
    z-index: 12;
    left: 50%;
    bottom: 12px;
    transform: translateX(-50%);
    width: min(980px, calc(100% - 24px));
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    padding: 6px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: rgba(14, 12, 18, 0.94);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(12px);
}

.tab {
    border: 0;
    border-radius: 12px;
    padding: 10px 4px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 0.74rem;
    font-weight: 700;
    cursor: pointer;
}

.tab.is-active {
    color: #1b140b;
    background: linear-gradient(180deg, #ffe0a0, var(--gold) 45%, var(--gold-deep));
}

.tab-panel[hidden] { display: none; }

.claim-card { text-align: center; }
.claim-copy {
    margin: 8px 0 16px;
    color: var(--muted);
    line-height: 1.55;
}
.claim-card .message { text-align: left; }
.text-btn {
    display: block;
    width: 100%;
    margin-top: 10px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font: inherit;
    cursor: pointer;
}

.toast {
    position: fixed;
    z-index: 16;
    left: 50%;
    bottom: 84px;
    transform: translateX(-50%);
    width: min(980px, calc(100% - 24px));
    margin: 0;
}

.stage-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin-bottom: 8px;
}

.badge {
    border: 1px solid var(--line);
    color: var(--gold);
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 0.82rem;
    white-space: nowrap;
}

.chests {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 14px;
}

.chest {
    position: relative;
    border: 0;
    padding: 4px;
    border-radius: 18px;
    background: radial-gradient(circle at 50% 80%, rgba(243, 197, 109, 0.16), transparent 58%);
    cursor: pointer;
    animation: rise 0.5s ease both;
    animation-delay: calc(var(--i) * 60ms);
    transition: opacity 0.3s ease, filter 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

.chest img {
    width: 100%;
    height: auto;
    display: block;
    filter: drop-shadow(0 12px 16px rgba(0, 0, 0, 0.45));
    animation: float 3.8s ease-in-out infinite;
    animation-delay: calc(var(--i) * 0.18s);
}

.chest:hover img,
.chest:focus-visible img {
    animation-play-state: paused;
    filter: drop-shadow(0 16px 18px rgba(243, 197, 109, 0.45));
}
.chest:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

.chests.is-locked .chest:not(.is-shaking) {
    opacity: 0.38;
    filter: saturate(0.6);
}

.chest.is-shaking { z-index: 2; }
.chest.is-shaking img { animation: none; }
.chest.is-shaking { animation: chest-shake 0.9s cubic-bezier(.36, .07, .19, .97); }

.message {
    padding: 12px 14px;
    border-radius: 14px;
    margin-top: 16px;
}
.message[hidden] { display: none; }
.message.ok { background: rgba(34, 197, 94, 0.14); color: var(--ok); }
.message.alert { background: rgba(239, 68, 68, 0.14); color: var(--danger); }

.history ul { list-style: none; padding: 0; margin: 12px 0 0; }
.history li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    animation: rise 0.4s ease both;
}
.history li:nth-child(2) { animation-delay: 0.05s; }
.history li:nth-child(3) { animation-delay: 0.1s; }

code {
    color: var(--gold);
    background: rgba(243, 197, 109, 0.1);
    padding: 2px 6px;
    border-radius: 6px;
}

.reward-modal {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    background: rgba(5, 4, 8, 0.72);
    backdrop-filter: blur(8px);
}

.reward-modal[hidden] { display: none; }

.reward-card {
    width: min(480px, 100%);
    text-align: center;
    position: relative;
}

.reward-card img {
    width: min(420px, 86vw);
    max-height: min(52dvh, 460px);
    object-fit: contain;
    filter: drop-shadow(0 24px 40px rgba(226, 59, 74, 0.45));
    animation: pop 0.7s cubic-bezier(.16, 1.2, .3, 1);
}

.glow {
    position: absolute;
    left: 50%;
    top: 38%;
    width: min(340px, 70vw);
    height: min(340px, 70vw);
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: radial-gradient(circle, rgba(243, 197, 109, 0.45), transparent 68%);
    animation: pulse 1.6s ease-in-out infinite;
    z-index: -1;
}

.reward-kicker {
    margin: 0;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--gold);
    font-size: 0.78rem;
}

#rewardText {
    margin: 8px 0 16px;
    font-size: clamp(1.5rem, 5vw, 2.3rem);
    font-weight: 800;
    color: #fff6df;
    animation: rise 0.45s 0.15s ease both;
}

.reward-card .claim { max-width: none; }

@keyframes rise {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: none; }
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-7px); }
}

@keyframes drift {
    from { transform: translate3d(0, 0, 0); }
    to { transform: translate3d(12vw, -6vh, 0); }
}

@keyframes chest-shake {
    0%, 100% { transform: rotate(0) scale(1); }
    15% { transform: rotate(-9deg) translateY(-6px) scale(1.05); }
    30% { transform: rotate(8deg) scale(1.05); }
    45% { transform: rotate(-6deg) translateY(-3px); }
    60% { transform: rotate(5deg); }
    75% { transform: rotate(-3deg) scale(1.08); }
}

@keyframes pop {
    from { opacity: 0; transform: scale(0.55) rotate(-6deg); }
    to { opacity: 1; transform: none; }
}

@keyframes pulse {
    0%, 100% { opacity: 0.65; transform: translate(-50%, -50%) scale(0.92); }
    50% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
}

@keyframes loadpulse {
    50% { filter: brightness(1.12); }
}

@media (max-width: 720px) {
    .wrap {
        width: min(100% - 20px, 980px);
        padding-top: calc(14px + env(safe-area-inset-top));
        padding-bottom: calc(92px + env(safe-area-inset-bottom));
    }
    .logo { max-width: 100%; }
    .brand-name { font-size: 0.72rem; }
    .claim-mini { padding: 7px 10px; font-size: 0.72rem; }
    .claim { max-width: none; }
    .stage-head { align-items: flex-start; }
    .history li { flex-direction: column; gap: 4px; }
    .chests { gap: 4px; }
    .chest { padding: 0; border-radius: 12px; }
    .panel, .history { border-radius: 18px; padding: 14px; }
    .tabs {
        left: 0;
        bottom: 0;
        transform: none;
        width: 100%;
        border-radius: 18px 18px 0 0;
        border-bottom: 0;
        padding-bottom: calc(6px + env(safe-area-inset-bottom));
    }
    .toast { bottom: calc(78px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }
}
