/* ═══════════════════════════════════════════════════════════════
   GEM CRUSH SAGA - Premium Game Styles v2.0
   Inspired by Candy Crush, Bejeweled, Royal Match
   ═══════════════════════════════════════════════════════════════ */

/* ── Design Tokens ── */
:root {
    --bg-deep: #08031a;
    --bg-mid: #120830;
    --bg-panel: linear-gradient(180deg, #1e0f4d 0%, #0e0628 100%);
    --glass: rgba(255, 255, 255, 0.06);
    --glass-border: rgba(255, 255, 255, 0.12);
    --gold: #ffd700;
    --gold-light: #ffe660;
    --gold-dark: #cc8800;
    --orange: #ff8c00;
    --green: #3ddc84;
    --green-dark: #289d5f;
    --red: #ff4757;
    --purple: #a855f7;
    --purple-dark: #7c3aed;
    --blue: #4f8cff;
    --cyan: #22d3ee;
    --text: #ffffff;
    --text-dim: rgba(255, 255, 255, 0.55);
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-xl: 32px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Reset ── */
*, *::before, *::after {
    margin: 0; padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none; -webkit-user-select: none;
}

html, body {
    width: 100%; height: 100%;
    overflow: hidden;
    font-family: 'Outfit', sans-serif;
    background: var(--bg-deep);
    color: var(--text);
    touch-action: manipulation;
}

/* ═══════════════════════════════════════════════════════════
   ANIMATED BACKGROUND SYSTEM
   ═══════════════════════════════════════════════════════════ */
#bgLayers {
    position: fixed; inset: 0; z-index: 0; pointer-events: none;
}

.bg-gradient {
    position: absolute; inset: 0;
    background:
        radial-gradient(ellipse at 20% 20%, rgba(120, 50, 255, 0.25) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(255, 100, 50, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(30, 15, 77, 0.8) 0%, transparent 80%),
        linear-gradient(180deg, #120840 0%, #08031a 50%, #0a0520 100%);
}

#sparkleCanvas {
    position: absolute; inset: 0; width: 100%; height: 100%;
}

.bg-rays {
    position: absolute; inset: 0;
    background: conic-gradient(
        from 0deg at 50% 40%,
        transparent 0deg, rgba(255, 215, 0, 0.03) 10deg, transparent 20deg,
        transparent 40deg, rgba(168, 85, 247, 0.03) 50deg, transparent 60deg,
        transparent 80deg, rgba(255, 140, 0, 0.02) 90deg, transparent 100deg
    );
    animation: raysSpin 60s linear infinite;
}

@keyframes raysSpin { to { transform: rotate(360deg); } }

.bg-vignette {
    position: absolute; inset: 0;
    background: radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,0.6) 100%);
}

/* ═══════════════════════════════════════════════════════════
   SCREEN SYSTEM
   ═══════════════════════════════════════════════════════════ */
.screen {
    position: fixed; inset: 0;
    display: none; flex-direction: column;
    z-index: 1;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
}

.screen.active {
    display: flex;
    animation: screenIn 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes screenIn {
    from { opacity: 0; transform: scale(0.94); }
    to { opacity: 1; transform: scale(1); }
}

/* ═══════════════════════════════════════════════════════════
   MAIN MENU
   ═══════════════════════════════════════════════════════════ */
.deco-gems {
    position: absolute; inset: 0;
    pointer-events: none; z-index: 0; overflow: hidden;
}

.deco-gem {
    position: absolute;
    width: 70px; height: 70px;
    object-fit: cover;
    border-radius: 50%;
    filter: drop-shadow(0 0 12px rgba(168, 85, 247, 0.5));
    animation: decoFloat 5s ease-in-out infinite;
}

.deco-tl { top: 5%; left: 3%; animation-delay: 0s; width: 65px; height: 65px; }
.deco-tr { top: 4%; right: 4%; animation-delay: 0.8s; width: 55px; height: 55px; }
.deco-bl { bottom: 8%; left: 5%; animation-delay: 1.6s; width: 60px; height: 60px; }
.deco-br { bottom: 6%; right: 3%; animation-delay: 2.4s; width: 50px; height: 50px; }
.deco-ml { top: 45%; left: -10px; animation-delay: 0.4s; width: 45px; height: 45px; opacity: 0.6; }
.deco-mr { top: 38%; right: -5px; animation-delay: 1.2s; width: 50px; height: 50px; opacity: 0.6; }
.deco-tc { top: -5px; left: 50%; transform: translateX(-50%); animation-delay: 2s; width: 40px; height: 40px; opacity: 0.5; }

@keyframes decoFloat {
    0%, 100% { transform: translateY(0) rotate(0deg) scale(1); }
    33% { transform: translateY(-15px) rotate(8deg) scale(1.05); }
    66% { transform: translateY(8px) rotate(-5deg) scale(0.97); }
}

.menu-container {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    height: 100%; padding: 1.5rem;
    position: relative; z-index: 2; gap: 2.2rem;
}

/* ── Title Banner ── */
.title-banner {
    position: relative; width: 100%; max-width: 380px; padding: 1.2rem 0;
    margin-bottom: 0.5rem;
}

.title-bg {
    position: absolute; inset: 0;
    background: radial-gradient(ellipse at center, rgba(168, 85, 247, 0.25) 0%, transparent 70%);
    filter: blur(30px);
}

.title-content {
    position: relative;
    display: flex; flex-direction: column; align-items: center;
}

.title-gem-row {
    display: flex; align-items: flex-end; justify-content: center;
    gap: 0; margin-bottom: -10px; z-index: 2;
}

.title-crown-gem {
    width: 80px; height: 80px; object-fit: cover;
    border-radius: 50%;
    box-shadow: 0 0 25px rgba(100, 200, 255, 0.7), 0 5px 15px rgba(0,0,0,0.5), inset 0 0 8px rgba(255,255,255,0.2);
    animation: crownBounce 3s ease-in-out infinite; z-index: 2;
}

.title-side-gem {
    width: 50px; height: 50px; object-fit: cover;
    border-radius: 50%;
    box-shadow: 0 0 15px rgba(255, 100, 100, 0.5), 0 3px 10px rgba(0,0,0,0.4);
}

.title-side-gem.left {
    transform: rotate(-15deg) translateX(10px);
    animation: sideGemLeft 4s ease-in-out infinite;
}

.title-side-gem.right {
    transform: rotate(15deg) translateX(-10px);
    animation: sideGemRight 4s ease-in-out infinite;
    box-shadow: 0 0 15px rgba(68, 136, 255, 0.5), 0 3px 10px rgba(0,0,0,0.4);
}

@keyframes crownBounce {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-8px) scale(1.05); }
}

@keyframes sideGemLeft {
    0%, 100% { transform: rotate(-15deg) translateX(10px) translateY(0); }
    50% { transform: rotate(-10deg) translateX(10px) translateY(-5px); }
}

@keyframes sideGemRight {
    0%, 100% { transform: rotate(15deg) translateX(-10px) translateY(0); }
    50% { transform: rotate(10deg) translateX(-10px) translateY(-5px); }
}

.game-title {
    display: flex; flex-direction: column; align-items: center; line-height: 1;
}

.title-line-1 {
    font-family: 'Lilita One', cursive;
    font-size: 3.8rem; letter-spacing: 3px;
    background: linear-gradient(180deg, #fff 0%, #ffd700 40%, #ff8c00 100%);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 3px 0 rgba(0,0,0,0.4)) drop-shadow(0 6px 20px rgba(255, 140, 0, 0.3));
    paint-order: stroke fill;
    -webkit-text-stroke: 1px rgba(180, 80, 0, 0.3);
}

.title-line-2 {
    font-family: 'Lilita One', cursive;
    font-size: 2.2rem; letter-spacing: 16px; margin-left: 16px;
    background: linear-gradient(180deg, #e0c3fc 0%, #a855f7 50%, #7c3aed 100%);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 2px 0 rgba(0,0,0,0.3)) drop-shadow(0 4px 15px rgba(168, 85, 247, 0.4));
}

.title-sparkle-line {
    width: 60%; height: 2px; margin-top: 12px;
    background: linear-gradient(90deg, transparent, rgba(255, 215, 0, 0.6), var(--gold), rgba(255, 215, 0, 0.6), transparent);
    border-radius: 2px; position: relative;
}

.title-sparkle-line::after {
    content: '✦'; position: absolute; top: -8px; font-size: 14px;
    color: var(--gold); animation: sparkleSlide 3s ease-in-out infinite;
}

@keyframes sparkleSlide {
    0% { left: 0%; opacity: 0; } 10% { opacity: 1; } 90% { opacity: 1; }
    100% { left: 100%; opacity: 0; }
}

/* ── Gem Showcase Strip ── */
.gem-showcase {
    width: 100%; max-width: 380px; overflow: hidden; padding: 8px 0;
    position: relative;
    mask-image: linear-gradient(90deg, transparent, black 15%, black 85%, transparent);
    -webkit-mask-image: linear-gradient(90deg, transparent, black 15%, black 85%, transparent);
}

.showcase-track {
    display: flex; gap: 10px;
    animation: showcaseScroll 12s linear infinite;
    width: max-content;
}

.showcase-track img {
    width: 44px; height: 44px; object-fit: cover;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4), 0 0 12px rgba(168, 85, 247, 0.2);
    animation: gemShimmer 3s ease-in-out infinite;
}

.showcase-track img:nth-child(1) { animation-delay: 0s; }
.showcase-track img:nth-child(2) { animation-delay: 0.4s; }
.showcase-track img:nth-child(3) { animation-delay: 0.8s; }
.showcase-track img:nth-child(4) { animation-delay: 1.2s; }
.showcase-track img:nth-child(5) { animation-delay: 1.6s; }
.showcase-track img:nth-child(6) { animation-delay: 2.0s; }
.showcase-track img:nth-child(7) { animation-delay: 2.4s; }

@keyframes showcaseScroll {
    0% { transform: translateX(0); }
    100% { transform: translateX(-50%); }
}

@keyframes gemShimmer {
    0%, 100% { filter: drop-shadow(0 2px 8px rgba(0,0,0,0.4)) brightness(1); }
    50% { filter: drop-shadow(0 2px 16px rgba(255,215,0,0.4)) brightness(1.2); }
}

/* ── Play Button ── */
.btn-play {
    position: relative; width: 100%; max-width: 320px; height: 64px;
    border: none; border-radius: var(--radius-lg);
    cursor: pointer; overflow: hidden; transition: transform 0.15s;
}

.btn-play:active { transform: scale(0.96) translateY(2px); }

.btn-play-bg {
    position: absolute; inset: 0;
    background: linear-gradient(180deg, #5cd85c 0%, #3dba3d 40%, #2d9e2d 100%);
    border-radius: var(--radius-lg);
    box-shadow:
        0 6px 0 #1a7a1a, 0 8px 20px rgba(61, 186, 61, 0.4),
        inset 0 2px 0 rgba(255,255,255,0.25), inset 0 -2px 0 rgba(0,0,0,0.15);
}

.btn-play:active .btn-play-bg {
    box-shadow:
        0 2px 0 #1a7a1a, 0 3px 10px rgba(61, 186, 61, 0.3),
        inset 0 2px 0 rgba(255,255,255,0.15);
}

.btn-play-shine {
    position: absolute; top: 0; left: -100%; width: 60%; height: 100%;
    background: linear-gradient(100deg, transparent, rgba(255,255,255,0.3), transparent);
    animation: playShine 3s ease-in-out infinite;
}

@keyframes playShine {
    0%, 60%, 100% { left: -100%; }
    30% { left: 150%; }
}

.btn-play-content {
    position: relative; z-index: 2;
    display: flex; align-items: center; justify-content: center; gap: 10px;
    font-family: 'Lilita One', cursive; font-size: 1.8rem;
    color: #fff; text-shadow: 0 2px 4px rgba(0,0,0,0.3); letter-spacing: 4px;
}

.play-icon {
    width: 28px; height: 28px;
    filter: drop-shadow(0 2px 2px rgba(0,0,0,0.3));
}

/* ── Menu Buttons Row ── */
.btn-row {
    display: flex; gap: 12px; width: 100%; max-width: 320px;
}

.btn-menu {
    flex: 1; display: flex; align-items: center; justify-content: center;
    gap: 6px; padding: 14px 0;
    border: 2px solid var(--glass-border); border-radius: var(--radius-md);
    background: linear-gradient(180deg, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0.02) 100%);
    backdrop-filter: blur(10px);
    color: var(--text); font-family: 'Outfit', sans-serif;
    font-size: 0.85rem; font-weight: 700;
    cursor: pointer; letter-spacing: 1px; transition: all 0.2s;
    box-shadow: 0 4px 0 rgba(0,0,0,0.3), 0 6px 15px rgba(0,0,0,0.2),
        inset 0 1px 0 rgba(255,255,255,0.1);
}

.btn-menu:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.1);
}

.btn-menu-icon { font-size: 1.2rem; }

/* ── Stats Bar ── */
.stats-bar {
    display: flex; align-items: center; gap: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0.03) 100%);
    border: 1px solid var(--glass-border);
    border-radius: 50px; padding: 8px 20px;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.stat-pill {
    display: flex; flex-direction: column; align-items: center;
    padding: 0 16px; min-width: 70px;
}

.stat-pill-icon { font-size: 1.4rem; margin-bottom: 2px; }

.stat-pill-val {
    font-family: 'Lilita One', cursive; font-size: 1.3rem;
    color: var(--gold);
    text-shadow: 0 1px 4px rgba(255, 215, 0, 0.3);
}

.stat-pill-label {
    font-size: 0.6rem; font-weight: 600;
    color: var(--text-dim); letter-spacing: 1px; text-transform: uppercase;
}

.stat-divider {
    width: 1px; height: 30px; background: var(--glass-border);
}

/* ═══════════════════════════════════════════════════════════
   LEVEL SELECT SCREEN
   ═══════════════════════════════════════════════════════════ */
.screen-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(180deg, rgba(18, 8, 64, 0.95) 0%, rgba(18, 8, 64, 0.7) 100%);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--glass-border); z-index: 5;
}

.header-title {
    font-family: 'Lilita One', cursive; font-size: 1.2rem;
    letter-spacing: 3px; color: var(--gold);
    text-shadow: 0 2px 8px rgba(255, 215, 0, 0.3);
}

.btn-back {
    width: 44px; height: 44px; border-radius: var(--radius-sm);
    background: var(--glass); border: 1px solid var(--glass-border);
    color: var(--text); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.15s; box-shadow: 0 3px 0 rgba(0,0,0,0.3);
}

.btn-back:active {
    transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,0.3);
}

.header-stars-badge {
    font-weight: 700; font-size: 1rem;
    padding: 6px 14px; background: var(--glass);
    border-radius: 50px; border: 1px solid var(--glass-border);
}

.level-scroll-area {
    flex: 1; overflow-y: auto; padding: 16px;
    -webkit-overflow-scrolling: touch;
}

.level-grid {
    display: grid; grid-template-columns: repeat(5, 1fr);
    gap: 10px; max-width: 400px; margin: 0 auto;
}

.level-btn {
    aspect-ratio: 1; border-radius: var(--radius-md);
    border: 2px solid transparent;
    background: linear-gradient(180deg, rgba(255,255,255,0.06) 0%, rgba(255,255,255,0.02) 100%);
    color: var(--text); font-family: 'Lilita One', cursive; font-size: 1.4rem;
    cursor: pointer; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 3px;
    transition: all 0.2s; position: relative;
    box-shadow: 0 3px 0 rgba(0,0,0,0.3);
}

.level-btn.unlocked {
    border-color: rgba(168, 85, 247, 0.4);
    background: linear-gradient(180deg, rgba(100, 80, 200, 0.3) 0%, rgba(60, 40, 140, 0.3) 100%);
}

.level-btn.unlocked:active {
    transform: translateY(2px) scale(0.95);
    box-shadow: 0 1px 0 rgba(0,0,0,0.3);
}

.level-btn.current {
    border-color: var(--gold);
    background: linear-gradient(180deg, rgba(255, 215, 0, 0.25) 0%, rgba(255, 140, 0, 0.2) 100%);
    box-shadow: 0 3px 0 var(--gold-dark), 0 0 25px rgba(255, 215, 0, 0.3);
    animation: lvlPulse 2.5s ease-in-out infinite;
}

@keyframes lvlPulse {
    0%, 100% { box-shadow: 0 3px 0 var(--gold-dark), 0 0 15px rgba(255, 215, 0, 0.2); }
    50% { box-shadow: 0 3px 0 var(--gold-dark), 0 0 35px rgba(255, 215, 0, 0.5); }
}

.level-btn.locked {
    opacity: 0.3; cursor: default; filter: grayscale(0.5);
}

.level-btn .level-stars { font-size: 0.5rem; letter-spacing: 0.5px; }

/* ═══════════════════════════════════════════════════════════
   GAME SCREEN
   ═══════════════════════════════════════════════════════════ */
.game-topbar {
    display: flex; align-items: center; gap: 8px; padding: 8px 10px;
    background: linear-gradient(180deg, rgba(8, 3, 26, 0.95) 0%, rgba(8, 3, 26, 0.75) 100%);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255,255,255,0.06); z-index: 10;
}

.btn-game-back {
    width: 40px; height: 40px; border-radius: var(--radius-sm);
    background: var(--glass); border: 1px solid var(--glass-border);
    color: var(--text); cursor: pointer;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    transition: transform 0.1s;
}

.btn-game-back:active { transform: scale(0.9); }

.game-info-strip { display: flex; flex: 1; gap: 6px; }

.gi-block {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    padding: 4px 6px; border-radius: var(--radius-sm);
    background: var(--glass); border: 1px solid rgba(255,255,255,0.06);
}

.gi-label {
    font-size: 0.55rem; font-weight: 700;
    color: var(--text-dim); letter-spacing: 2px;
}

.gi-value { font-family: 'Lilita One', cursive; font-size: 1.3rem; }

.gi-score .gi-value {
    background: linear-gradient(180deg, #fff, var(--gold));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}

.gi-moves .gi-value { color: var(--green); transition: color 0.3s; }

.gi-moves.warning .gi-value {
    color: var(--red);
    animation: movePulse 0.6s ease-in-out infinite;
}

@keyframes movePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.3); }
}

/* Target Bar */
.target-bar {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.35);
    border-bottom: 1px solid rgba(255,255,255,0.04);
}

.target-label {
    font-size: 0.65rem; font-weight: 800;
    letter-spacing: 2px; color: var(--text-dim);
}

.target-items { display: flex; gap: 8px; flex: 1; }

.target-item {
    display: flex; align-items: center; gap: 5px;
    padding: 4px 8px;
    background: rgba(255,255,255,0.05);
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.08);
    transition: all 0.3s;
}

.target-item img { width: 22px; height: 22px; object-fit: cover; border-radius: 50%; }

.target-item .target-count {
    font-family: 'Lilita One', cursive; font-size: 0.95rem;
    transition: color 0.3s;
}

.target-item.completed {
    border-color: var(--green);
    background: rgba(61, 220, 132, 0.15);
}

.target-item.completed .target-count {
    color: var(--green);
}

/* Progress Strip */
.progress-strip { padding: 6px 12px; }

.progress-track {
    height: 10px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 5px; position: relative; overflow: visible;
    border: 1px solid rgba(255,255,255,0.06);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--orange), var(--gold), var(--gold-light));
    border-radius: 5px; width: 0%;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.4);
}

.progress-fill::after {
    content: ''; position: absolute;
    right: -2px; top: -3px; width: 14px; height: 14px;
    background: radial-gradient(circle, var(--gold-light), var(--gold));
    border-radius: 50%; border: 2px solid #fff;
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.7);
}

.star-markers {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
}

.star-marker {
    position: absolute; top: -12px; transform: translateX(-50%);
    font-size: 1rem;
    filter: grayscale(1) brightness(0.4);
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.star-marker.earned {
    filter: none;
    transform: translateX(-50%) scale(1.3);
    animation: starPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes starPop {
    0% { transform: translateX(-50%) scale(0.5); }
    60% { transform: translateX(-50%) scale(1.5); }
    100% { transform: translateX(-50%) scale(1.3); }
}

/* Board Container */
.board-container {
    flex: 1; display: flex; align-items: center; justify-content: center;
    padding: 6px; position: relative; overflow: hidden;
}

.board-frame {
    position: relative; border-radius: var(--radius-lg); padding: 4px;
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.3), rgba(79, 140, 255, 0.2), rgba(168, 85, 247, 0.3));
    box-shadow:
        0 0 30px rgba(168, 85, 247, 0.15),
        0 0 60px rgba(79, 140, 255, 0.1),
        inset 0 0 1px rgba(255,255,255,0.2);
}

#gameCanvas {
    display: block; border-radius: 20px;
    background: linear-gradient(180deg, rgba(15, 8, 40, 0.9) 0%, rgba(8, 3, 26, 0.95) 100%);
    touch-action: none;
}

/* Combo Display */
.combo-display {
    position: fixed; top: 45%; left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Lilita One', cursive; font-size: 3.2rem;
    z-index: 100; pointer-events: none;
    animation: comboAnim 1.2s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

#comboText {
    background: linear-gradient(180deg, #fff, var(--gold));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 3px 0 rgba(0,0,0,0.4)) drop-shadow(0 0 30px rgba(255, 215, 0, 0.6));
}

@keyframes comboAnim {
    0% { transform: translate(-50%, -50%) scale(0.3) rotate(-10deg); opacity: 0; }
    30% { transform: translate(-50%, -50%) scale(1.4) rotate(3deg); opacity: 1; }
    70% { transform: translate(-50%, -50%) scale(1) rotate(0deg); opacity: 1; }
    100% { transform: translate(-50%, -60%) scale(0.8); opacity: 0; }
}

/* ── Booster Bar ── */
.booster-bar {
    display: flex; justify-content: center; gap: 8px;
    padding: 6px 10px;
    background: linear-gradient(180deg, rgba(8, 3, 26, 0.7) 0%, rgba(8, 3, 26, 0.9) 100%);
    border-top: 1px solid rgba(255,255,255,0.05);
}

.booster-btn {
    display: flex; flex-direction: column; align-items: center;
    gap: 2px; padding: 6px 10px;
    background: linear-gradient(180deg, rgba(100, 80, 200, 0.3), rgba(60, 40, 140, 0.3));
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: 12px;
    color: var(--text); cursor: pointer;
    transition: all 0.2s; position: relative;
    min-width: 60px;
}

.booster-btn:active {
    transform: scale(0.92);
    background: linear-gradient(180deg, rgba(168, 85, 247, 0.4), rgba(100, 60, 200, 0.4));
}

.booster-icon { font-size: 1.3rem; }

.booster-count {
    position: absolute; top: -4px; right: -4px;
    background: var(--green); color: #000;
    font-weight: 800; font-size: 0.6rem;
    width: 18px; height: 18px;
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.booster-price {
    font-size: 0.55rem; color: var(--gold); font-weight: 700;
}

/* ── Coins Display ── */
.gi-coins .gi-value {
    color: var(--gold);
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.3);
}

/* ── Post-Level Stats ── */
.post-stats {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 6px; padding: 8px 0; width: 100%;
}

.post-stat {
    display: flex; flex-direction: column; align-items: center;
    padding: 6px 4px;
    background: rgba(255,255,255,0.04);
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.06);
}

.post-stat-icon { font-size: 1.1rem; }

.post-stat-val {
    font-family: 'Lilita One', cursive; font-size: 1rem;
    color: var(--gold);
}

.post-stat-label {
    font-size: 0.5rem; font-weight: 700; color: var(--text-dim);
    text-transform: uppercase; letter-spacing: 0.5px;
}

/* ═══════════════════════════════════════════════════════════
   OVERLAY SYSTEM
   ═══════════════════════════════════════════════════════════ */
.overlay {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(12px);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
    animation: overlayFadeIn 0.3s ease-out;
}

.overlay.hidden { display: none; }

@keyframes overlayFadeIn { from { opacity: 0; } to { opacity: 1; } }

.overlay-panel {
    width: 90%; max-width: 340px;
    padding: 2rem 1.5rem 1.5rem;
    border-radius: var(--radius-xl);
    display: flex; flex-direction: column; align-items: center;
    gap: 1.2rem; position: relative; overflow: hidden;
    animation: panelPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    background: var(--bg-panel);
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow:
        0 20px 60px rgba(0,0,0,0.6),
        0 0 0 1px rgba(255,255,255,0.05),
        inset 0 1px 0 rgba(255,255,255,0.08);
}

.panel-header-deco {
    position: absolute; top: 0; left: 0; right: 0; height: 4px;
    background: linear-gradient(90deg, var(--purple), var(--blue), var(--purple));
}

.win-deco {
    background: linear-gradient(90deg, var(--gold-dark), var(--gold), var(--gold-light), var(--gold), var(--gold-dark));
}

.lose-deco {
    background: linear-gradient(90deg, #831010, var(--red), #831010);
}

@keyframes panelPop {
    from { transform: scale(0.7) translateY(30px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
}

.panel-title {
    font-family: 'Lilita One', cursive; font-size: 2rem;
    letter-spacing: 2px; text-align: center; line-height: 1.1;
    background: linear-gradient(180deg, #fff, var(--gold));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.win-title { font-size: 2.2rem; }

.lose-title {
    background: linear-gradient(180deg, #ffaaaa, var(--red));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Stars Display */
.stars-display {
    font-size: 3rem; display: flex; gap: 8px;
    animation: starsReveal 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.stars-display .star {
    display: inline-block;
    animation: starDrop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    filter: drop-shadow(0 2px 8px rgba(255, 215, 0, 0.5));
}

.stars-display .star:nth-child(1) { animation-delay: 0.1s; }
.stars-display .star:nth-child(2) { animation-delay: 0.3s; }
.stars-display .star:nth-child(3) { animation-delay: 0.5s; }

.stars-display .star-empty {
    filter: grayscale(1) brightness(0.4);
}

@keyframes starsReveal { from { transform: scale(0); } to { transform: scale(1); } }

@keyframes starDrop {
    from { transform: scale(0) rotate(-45deg) translateY(-20px); opacity: 0; }
    to { transform: scale(1) rotate(0) translateY(0); opacity: 1; }
}

/* Score Block */
.score-block {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
}

.score-label {
    font-size: 0.7rem; font-weight: 700;
    color: var(--text-dim); letter-spacing: 3px;
}

.score-number {
    font-family: 'Lilita One', cursive; font-size: 2.8rem;
    background: linear-gradient(180deg, #fff, var(--gold));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

/* Panel Buttons */
.panel-buttons {
    display: flex; flex-direction: column; gap: 10px; width: 100%;
}

.btn-panel {
    display: flex; align-items: center; justify-content: center;
    gap: 10px; width: 100%; padding: 14px 20px;
    border: 2px solid var(--glass-border); border-radius: var(--radius-md);
    background: linear-gradient(180deg, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0.02) 100%);
    color: var(--text); font-family: 'Outfit', sans-serif;
    font-size: 1rem; font-weight: 700;
    cursor: pointer; letter-spacing: 1px;
    transition: all 0.15s;
    box-shadow: 0 4px 0 rgba(0,0,0,0.3);
}

.btn-panel:active {
    transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.3);
}

.btn-panel-primary {
    border-color: transparent;
    background: linear-gradient(180deg, #5cd85c 0%, #3dba3d 40%, #2d9e2d 100%);
    box-shadow: 0 5px 0 #1a7a1a, 0 6px 15px rgba(61, 186, 61, 0.3);
    font-family: 'Lilita One', cursive; font-size: 1.15rem; letter-spacing: 2px;
}

.btn-panel-primary:active { box-shadow: 0 2px 0 #1a7a1a; }

.btn-panel svg { flex-shrink: 0; }

/* ── Settings ── */
.settings-list { width: 100%; }

.setting-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.setting-row:last-child { border-bottom: none; }

.setting-info { display: flex; align-items: center; gap: 10px; }

.setting-icon { font-size: 1.3rem; }

.setting-name { font-weight: 600; font-size: 0.95rem; }

/* Toggle Switch */
.toggle-switch { position: relative; cursor: pointer; }

.toggle-switch input {
    position: absolute; opacity: 0; width: 0; height: 0;
}

.toggle-track {
    display: block; width: 52px; height: 30px; border-radius: 15px;
    background: rgba(255, 255, 255, 0.12);
    border: 2px solid rgba(255,255,255,0.1);
    position: relative; transition: all 0.3s;
}

.toggle-knob {
    position: absolute; top: 2px; left: 2px;
    width: 22px; height: 22px; border-radius: 50%;
    background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toggle-switch input:checked + .toggle-track {
    background: linear-gradient(180deg, #5cd85c, #3dba3d);
    border-color: #2d9e2d;
}

.toggle-switch input:checked + .toggle-track .toggle-knob {
    transform: translateX(22px);
}

/* ═══════════════════════════════════════════════════════════
   LEADERBOARD
   ═══════════════════════════════════════════════════════════ */
.leaderboard-list {
    width: 100%;
    max-height: 340px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.lb-empty {
    color: var(--text-dim);
    text-align: center;
    padding: 24px 10px;
    font-size: 0.95rem;
}

.lb-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    transition: background 0.2s;
}

.lb-row:last-child { border-bottom: none; }

.lb-row.lb-top {
    background: rgba(255, 215, 0, 0.05);
}

.lb-rank {
    color: var(--gold);
    display: inline-block;
    width: 36px;
    font-weight: 900;
    font-size: 1.1rem;
    text-align: center;
    flex-shrink: 0;
}

.lb-info {
    flex: 1;
    font-size: 0.95rem;
    padding: 0 8px;
}

.lb-date {
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-left: 6px;
}

.lb-score {
    font-weight: 900;
    color: var(--green);
    font-size: 1.1rem;
    font-family: 'Lilita One', cursive;
    flex-shrink: 0;
}

/* Level Badge */
.level-badge {
    font-family: 'Lilita One', cursive;
    font-size: 1rem;
    letter-spacing: 3px;
    padding: 6px 20px;
    background: linear-gradient(180deg, rgba(255, 215, 0, 0.2) 0%, rgba(255, 140, 0, 0.15) 100%);
    border: 1px solid rgba(255, 215, 0, 0.3);
    border-radius: 50px;
    color: var(--gold);
    text-shadow: 0 1px 4px rgba(255, 215, 0, 0.3);
}

.level-badge-lose {
    background: linear-gradient(180deg, rgba(255, 71, 87, 0.15) 0%, rgba(255, 71, 87, 0.08) 100%);
    border-color: rgba(255, 71, 87, 0.3);
    color: var(--red);
    text-shadow: 0 1px 4px rgba(255, 71, 87, 0.3);
}

/* Score Block Small */
.score-block-small {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 6px 16px;
    background: rgba(255,255,255,0.04);
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.06);
}

.score-number-sm {
    font-family: 'Lilita One', cursive;
    font-size: 1.4rem;
    color: var(--text-dim);
}

/* ═══════════════════════════════════════════════════════════
   UTILITIES
   ═══════════════════════════════════════════════════════════ */
.hidden { display: none !important; }

.score-popup {
    position: absolute;
    font-family: 'Lilita One', cursive; font-size: 1.2rem;
    color: var(--gold);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
    pointer-events: none;
    animation: scoreFloat 1s ease-out forwards;
    z-index: 50;
}

@keyframes scoreFloat {
    0% { transform: translateY(0) scale(1); opacity: 1; }
    100% { transform: translateY(-50px) scale(1.4); opacity: 0; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

/* ── Responsive ── */

/* Small phones (iPhone SE, etc) */
@media (max-width: 360px) {
    .title-line-1 { font-size: 2.6rem; }
    .title-line-2 { font-size: 1.4rem; letter-spacing: 10px; }
    .title-crown-gem { width: 55px; height: 55px; }
    .title-side-gem { width: 36px; height: 36px; }
    .gi-value { font-size: 1rem; }
    .gi-label { font-size: 0.5rem; }
    .stat-pill { padding: 0 8px; min-width: 50px; }
    .stat-pill-val { font-size: 1.1rem; }
    .btn-menu { font-size: 0.75rem; padding: 12px 0; }
    .btn-play { padding: 16px 0; font-size: 1.4rem; }
    .level-grid { gap: 6px; }
    .level-btn { font-size: 1.1rem; }
    .menu-container { gap: 1.5rem; }
    .showcase-track img { width: 34px; height: 34px; }
    .deco-gem { display: none; }
}

/* Regular phones */
@media (min-width: 361px) and (max-width: 480px) {
    .showcase-track img { width: 38px; height: 38px; }
}

/* Tablets portrait */
@media (min-width: 768px) {
    .menu-container { max-width: 480px; margin: 0 auto; }
    .game-topbar { max-width: 700px; margin: 0 auto; width: 100%; }
    .target-bar { max-width: 700px; margin: 0 auto; }
    .progress-strip { max-width: 700px; margin: 0 auto; }
    .board-container { max-width: 640px; margin: 0 auto; }
    .level-grid { grid-template-columns: repeat(5, 1fr); gap: 12px; max-width: 450px; }
    .title-line-1 { font-size: 4.2rem; }
    .title-line-2 { font-size: 2.6rem; }
    .title-crown-gem { width: 90px; height: 90px; }
    .title-side-gem { width: 60px; height: 60px; }
    .showcase-track img { width: 52px; height: 52px; }
    .btn-play { max-width: 400px; }
    .menu-btns { max-width: 400px; }
}

/* Desktop & Laptop */
@media (min-width: 1024px) {
    .menu-container { max-width: 520px; }
    .board-container { max-width: 640px; }
    .game-topbar { max-width: 640px; }
    .target-bar { max-width: 640px; }
    .progress-strip { max-width: 640px; }
    .deco-gem { opacity: 0.7; }
    .deco-tl { width: 80px; height: 80px; }
    .deco-tr { width: 70px; height: 70px; }
    .deco-bl { width: 75px; height: 75px; }
    .deco-br { width: 65px; height: 65px; }
}

/* Landscape phones */
@media (max-height: 500px) and (orientation: landscape) {
    .menu-container { gap: 1rem; flex-direction: row; flex-wrap: wrap; justify-content: center; }
    .title-banner { max-width: 280px; padding: 0.5rem 0; margin-bottom: 0; }
    .title-line-1 { font-size: 2.4rem; }
    .title-line-2 { font-size: 1.4rem; }
    .gem-showcase { display: none; }
    .stat-bar { margin-top: 0; }
    .title-crown-gem { width: 50px; height: 50px; }
    .title-side-gem { width: 35px; height: 35px; }
    .game-topbar { padding: 4px 10px; }
    .gi-value { font-size: 1rem; }
    .target-bar { padding: 3px 12px; }
    .progress-strip { padding: 3px 12px; }
    .deco-gem { display: none; }
}
