/* ============================================
   GIFT BOX RETENTION — CSS (Lively Edition)
   ============================================ */

/* Progress Section */
.gb-progress-section {
    margin: 24px 0;
    padding: 16px 20px;
    background: var(--bg2, #0f172a);
    border: 1px solid var(--brd, #334155);
    border-radius: 12px;
}
.gb-progress-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 14px; font-weight: 600; color: var(--t1, #f8fafc); }
.gb-emoji { font-size: 20px; }
.gb-progress-label { flex: 1; }
.gb-bar-track { height: 8px; border-radius: 4px; background: var(--bg3, #1e293b); overflow: hidden; margin-bottom: 10px; }
.gb-bar-fill { height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--ac, #22c55e), var(--gold, #fbbf24)); transition: width 0.6s ease; }
.gb-progress-dots { display: flex; align-items: center; gap: 8px; justify-content: center; }
.gb-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--bg3, #1e293b); border: 2px solid var(--brd, #334155); transition: all 0.3s; }
.gb-dot-done { background: var(--ac, #22c55e); border-color: var(--ac, #22c55e); }
.gb-dot-gift { font-size: 16px; }
.gb-nav-indicator { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 20px; background: var(--bg2, #0f172a); border: 1px solid var(--brd, #334155); font-size: 12px; font-weight: 600; color: var(--t2, #94a3b8); }

/* 9-Box Grid Overlay */
.gb-overlay {
    position: fixed; inset: 0; z-index: 9999;
    background: rgba(0,0,0,0.92);
    display: flex; align-items: center; justify-content: center;
    animation: gbFadeIn 0.3s ease;
    overflow: hidden;
}
@keyframes gbFadeIn { from { opacity: 0; } to { opacity: 1; } }

.gb-overlay-content { width: 90%; max-width: 420px; text-align: center; padding: 24px; position: relative; z-index: 2; }
.gb-overlay-header { margin-bottom: 20px; }
.gb-title { font-size: 26px; font-weight: 800; color: #fff; margin: 0 0 4px; }
.gb-subtitle { font-size: 14px; color: #94a3b8; margin: 0; }

/* V2.1: 4x3 Grid (falls back to 3x3 for V1 9-cell boxes) */
.gb-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 20px; }
.gb-grid.gb-grid-9 { grid-template-columns: repeat(3, 1fr); }

.gb-cell { aspect-ratio: 1; perspective: 800px; cursor: pointer; }
.gb-cell-inner {
    width: 100%; height: 100%; position: relative;
    transform-style: preserve-3d;
    transition: transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 14px;
}
.gb-cell.gb-flipped .gb-cell-inner { transform: rotateY(180deg); }

.gb-cell-front, .gb-cell-back {
    position: absolute; inset: 0; border-radius: 14px;
    backface-visibility: hidden;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.gb-cell-front {
    background: linear-gradient(145deg, #22c55e, #16a34a);
    font-size: 32px; color: #fff;
    box-shadow: 0 4px 15px rgba(34,197,94,0.3), inset 0 1px 0 rgba(255,255,255,0.2);
    animation: gbBoxPulse 2s ease-in-out infinite;
}
@keyframes gbBoxPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 4px 15px rgba(34,197,94,0.3); }
    50% { transform: scale(1.03); box-shadow: 0 6px 25px rgba(34,197,94,0.5); }
}
.gb-cell:hover .gb-cell-front {
    box-shadow: 0 8px 30px rgba(34,197,94,0.5);
    filter: brightness(1.1);
}

.gb-cell-back {
    background: var(--bg2, #0f172a);
    border: 2px solid var(--brd, #334155);
    transform: rotateY(180deg);
    gap: 2px; padding: 4px;
}
.gb-cell-back-emoji { font-size: 30px; }
.gb-cell-back-name { font-size: 10px; color: var(--t2, #94a3b8); font-weight: 600; }
.gb-cell-back-credits { font-size: 12px; color: var(--t1, #f8fafc); font-weight: 800; }

/* Actual reward highlight */
.gb-cell.gb-actual .gb-cell-back {
    border-color: var(--ac, #22c55e);
    box-shadow: 0 0 30px rgba(34,197,94,0.6), 0 0 60px rgba(34,197,94,0.2);
    background: linear-gradient(135deg, #0f2a1a, #1a3a2a);
}
.gb-cell.gb-actual .gb-cell-back-credits {
    color: var(--ac, #22c55e);
    font-size: 14px;
}

/* Reward Reveal */
.gb-reward-reveal { padding: 20px; }
@keyframes gbBounceIn {
    0% { opacity: 0; transform: scale(0.5) translateY(30px); }
    60% { transform: scale(1.1) translateY(-5px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

.gb-reward-emoji { font-size: 64px; margin-bottom: 8px; animation: gbEmojiPop 0.5s ease 0.2s both; }
@keyframes gbEmojiPop {
    0% { transform: scale(0); }
    60% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

.gb-reward-name {
    font-size: 20px; font-weight: 800; color: #fff; margin-bottom: 4px;
    text-shadow: 0 0 20px rgba(255,255,255,0.3);
}
.gb-reward-credits {
    font-size: 36px; font-weight: 900; margin-bottom: 16px;
    background: linear-gradient(135deg, var(--ac, #22c55e), var(--gold, #fbbf24));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: gbCreditsPulse 1s ease-in-out infinite;
}
@keyframes gbCreditsPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.gb-claim-btn {
    background: linear-gradient(135deg, var(--ac, #22c55e), #16a34a);
    color: #fff; border: none; border-radius: 14px;
    padding: 16px 48px; font-size: 17px; font-weight: 800;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(34,197,94,0.4);
    animation: gbClaimPulse 1.5s ease-in-out infinite;
    transition: transform 0.2s;
}
@keyframes gbClaimPulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(34,197,94,0.4); }
    50% { box-shadow: 0 4px 40px rgba(34,197,94,0.7); }
}
.gb-claim-btn:hover { transform: scale(1.05); }
.gb-claim-btn:disabled { opacity: 0.5; cursor: not-allowed; animation: none; }

/* Claimed state */
.gb-claimed { padding: 20px; }
.gb-claimed-check { font-size: 56px; margin-bottom: 8px; color: var(--ac, #22c55e); animation: gbEmojiPop 0.5s ease both; }
.gb-claimed-text { font-size: 18px; color: #fff; font-weight: 700; margin-bottom: 16px; }
.gb-play-again {
    display: inline-block; padding: 14px 36px;
    background: linear-gradient(135deg, var(--ac, #22c55e), var(--gold, #fbbf24));
    color: #fff; border-radius: 14px; font-weight: 800; font-size: 16px;
    text-decoration: none; box-shadow: 0 4px 20px rgba(34,197,94,0.3);
}

/* CONFETTI */
.gb-confetti {
    position: absolute;
    top: -10px;
    border-radius: 2px;
    animation: gbConfettiFall linear forwards;
    z-index: 10;
    pointer-events: none;
}
@keyframes gbConfettiFall {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* Wiggle for gift icon */
@keyframes gbWiggle {
    0%, 100% { transform: rotate(0deg); }
    15% { transform: rotate(-8deg); }
    30% { transform: rotate(8deg); }
    45% { transform: rotate(-5deg); }
    60% { transform: rotate(5deg); }
    75% { transform: rotate(-2deg); }
}

/* Responsive */
@media (max-width: 480px) {
    .gb-overlay-content { padding: 16px; }
    .gb-grid { gap: 6px; }
    .gb-cell-front { font-size: 24px; }
    .gb-cell-back-emoji { font-size: 22px; }
    .gb-reward-credits { font-size: 28px; }
    .gb-title { font-size: 20px; }
}

/* V2.1 §9.5: Very narrow viewport fallback (<340px) — 3 columns instead of 4 */
@media (max-width: 340px) {
    .gb-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 4px;
    }
    .gb-cell-front { font-size: 20px; }
    .gb-cell-back-emoji { font-size: 18px; }
    .gb-cell-back-name { font-size: 9px; }
    .gb-cell-back-credits { font-size: 10px; }
    .gb-overlay-content { padding: 10px; }
    .gb-title { font-size: 18px; }
}

/* V2.1: Reduce flip complexity on low-end devices */
@media (prefers-reduced-motion: reduce) {
    .gb-cell-inner { transition: opacity 0.3s ease !important; transform-style: flat !important; }
    .gb-cell.gb-flipped .gb-cell-front { opacity: 0; }
    .gb-cell.gb-flipped .gb-cell-back { opacity: 1; transform: none !important; }
    .gb-confetti { display: none !important; }
}
