/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Nunito', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    overflow: hidden;
    position: relative;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loading-content {
    text-align: center;
    color: white;
}

.gem-spinner {
    font-size: 4rem;
    animation: spin 2s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-content h2 {
    font-family: 'Fredoka One', cursive;
    font-size: 2.5rem;
    margin-bottom: 1.5rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.loading-bar {
    width: 200px;
    height: 6px;
    background: rgba(255,255,255,0.3);
    border-radius: 10px;
    overflow: hidden;
    margin: 0 auto 1rem;
}

.loading-progress {
    height: 100%;
    background: linear-gradient(90deg, #ffd700, #ffed4a);
    width: 0%;
    border-radius: 10px;
    animation: loading 3s ease-in-out infinite;
}

@keyframes loading {
    0% { width: 0%; }
    50% { width: 80%; }
    100% { width: 100%; }
}

/* Game Container */
.game-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    max-width: 400px;
    margin: 0 auto;
    background: rgba(255,255,255,0.1);
    backdrop-filter: blur(10px);
    position: relative;
}

/* Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: rgba(255,255,255,0.2);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.header-left, .header-center, .header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.level-number {
    background: linear-gradient(45deg, #ffd700, #ffed4a);
    color: #333;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-weight: 800;
    font-size: 0.9rem;
    text-shadow: none;
}

.score-display, .lives-display, .coins-display {
    background: rgba(255,255,255,0.2);
    color: white;
    padding: 0.4rem 0.8rem;
    border-radius: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.score-display i { color: #ffd700; }
.lives-display i { color: #ff6b6b; }
.coins-display i { color: #ffd700; }

.icon-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.icon-btn:hover {
    background: rgba(255,255,255,0.3);
    transform: scale(1.1);
}

/* Progress Bar */
.progress-container {
    padding: 1rem;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: rgba(255,255,255,0.2);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4ecdc4, #44a08d);
    width: 0%;
    border-radius: 10px;
    transition: width 0.3s ease;
}

.target-info {
    display: flex;
    justify-content: space-between;
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
}

/* Power-ups Panel */
.powerups-panel {
    display: flex;
    justify-content: space-around;
    padding: 1rem;
    gap: 0.5rem;
}

.powerup {
    background: linear-gradient(145deg, #667eea, #764ba2);
    border: 2px solid rgba(255,255,255,0.2);
    border-radius: 15px;
    padding: 0.8rem 0.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    min-width: 70px;
}

.powerup:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.powerup i {
    color: white;
    font-size: 1.5rem;
    margin-bottom: 0.3rem;
}

.powerup-count {
    background: #ff6b6b;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 0.7rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: -5px;
    right: -5px;
}

.powerup-cost {
    color: #ffd700;
    font-size: 0.7rem;
    font-weight: 600;
    margin-top: 0.3rem;
}

/* Game Board */
.game-board-container {
    flex: 1;
    padding: 1rem;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: 2px;
    background: rgba(0,0,0,0.3);
    padding: 5px;
    border-radius: 10px;
    width: 320px;
    height: 320px;
}

.gem {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.gem:hover {
    transform: scale(1.05);
}

.gem.selected {
    animation: pulse 0.8s infinite;
    box-shadow: 0 0 15px rgba(255,255,255,0.8);
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.gem.red { background: linear-gradient(145deg, #ff6b6b, #ee5a52); }
.gem.blue { background: linear-gradient(145deg, #4ecdc4, #44a08d); }
.gem.green { background: linear-gradient(145deg, #95e1d3, #48cab2); }
.gem.yellow { background: linear-gradient(145deg, #fce38a, #f38181); }
.gem.purple { background: linear-gradient(145deg, #a8e6cf, #7fcdcd); }
.gem.orange { background: linear-gradient(145deg, #ffd3a5, #fd9853); }

.gem.matching {
    animation: matchGlow 0.5s ease-in-out;
}

@keyframes matchGlow {
    0% { box-shadow: 0 0 0 rgba(255,255,255,0.8); }
    50% { box-shadow: 0 0 20px rgba(255,255,255,0.8); }
    100% { box-shadow: 0 0 0 rgba(255,255,255,0.8); }
}

.gem.falling {
    animation: fall 0.3s ease-in;
}

@keyframes fall {
    0% { transform: translateY(-100%); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

/* Particle System */
.particle-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.particle {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ffd700;
    animation: particleExplode 1s ease-out forwards;
}

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

/* Bottom UI */
.bottom-ui {
    display: flex;
    justify-content: space-around;
    padding: 1rem;
    gap: 1rem;
}

.game-btn {
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 25px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'Nunito', sans-serif;
    font-size: 0.9rem;
}

.game-btn.primary {
    background: linear-gradient(45deg, #4ecdc4, #44a08d);
    color: white;
    box-shadow: 0 4px 15px rgba(78, 205, 196, 0.3);
}

.game-btn.secondary {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    box-shadow: 0 4px 15px rgba(118, 75, 162, 0.3);
}

.game-btn.tertiary {
    background: rgba(255,255,255,0.2);
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
}

.game-btn.danger {
    background: linear-gradient(45deg, #ff6b6b, #ee5a52);
    color: white;
}

.game-btn.premium {
    background: linear-gradient(45deg, #ffd700, #ffed4a);
    color: #333;
}

.game-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}

.game-btn:active {
    transform: translateY(0);
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal.show {
    display: flex;
}

.modal-content {
    background: linear-gradient(145deg, #667eea, #764ba2);
    padding: 2rem;
    border-radius: 20px;
    text-align: center;
    color: white;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    max-width: 350px;
    width: 90%;
    position: relative;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    background: rgba(255,255,255,0.2);
}

.modal-content h2 {
    font-family: 'Fredoka One', cursive;
    font-size: 1.8rem;
    margin-bottom: 1rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.stars-earned {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin: 1rem 0;
    font-size: 2rem;
}

.stars-earned i {
    color: #ffd700;
    animation: starTwinkle 0.5s ease-in-out;
}

@keyframes starTwinkle {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.reward-info {
    background: rgba(255,255,255,0.1);
    padding: 1rem;
    border-radius: 10px;
    margin: 1rem 0;
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    margin-top: 1.5rem;
}

/* Shop Modal */
.shop-modal {
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
}

.shop-items {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.shop-item {
    background: rgba(255,255,255,0.1);
    padding: 1rem;
    border-radius: 15px;
    display: flex;
    align-items: center;
    gap: 1rem;
    border: 2px solid transparent;
    transition: all 0.3s ease;
}

.shop-item.premium {
    border-color: #ffd700;
    background: rgba(255,215,0,0.1);
}

.shop-item:hover {
    background: rgba(255,255,255,0.2);
    transform: translateY(-2px);
}

.item-icon {
    background: rgba(255,255,255,0.2);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.item-info {
    flex: 1;
    text-align: left;
}

.item-info h3 {
    margin-bottom: 0.3rem;
    font-size: 1.1rem;
}

.item-info p {
    font-size: 0.9rem;
    opacity: 0.8;
}

.item-price {
    font-weight: bold;
    font-size: 1.2rem;
    color: #ffd700;
}

.buy-btn {
    background: linear-gradient(45deg, #4ecdc4, #44a08d);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.buy-btn:hover {
    background: linear-gradient(45deg, #44a08d, #4ecdc4);
    transform: scale(1.05);
}

/* Settings */
.settings-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
}

.toggle-switch {
    position: relative;
    width: 50px;
    height: 25px;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255,255,255,0.3);
    transition: 0.3s;
    border-radius: 25px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 19px;
    width: 19px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #4ecdc4;
}

input:checked + .slider:before {
    transform: translateX(25px);
}

/* Lives Timer */
.lives-timer {
    background: rgba(255,255,255,0.1);
    padding: 1rem;
    border-radius: 10px;
    margin: 1rem 0;
}

.lives-timer p {
    font-size: 1.1rem;
    font-weight: 600;
}

#lifeTimer {
    color: #ff6b6b;
    font-family: 'Courier New', monospace;
    font-size: 1.3rem;
}

/* Ad Banner */
.ad-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(45deg, #333, #555);
    color: white;
    padding: 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 999;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.3);
}

.ad-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.ad-close {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 25px;
    height: 25px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
}

/* Responsive Design */
@media (max-width: 480px) {
    .game-container {
        max-width: 100%;
        height: 100vh;
    }
    
    .game-board {
        width: min(90vw, 320px);
        height: min(90vw, 320px);
        max-width: 320px;
        max-height: 320px;
    }
    
    .gem {
        font-size: clamp(1rem, 3vw, 1.4rem);
    }
    
    .game-header {
        padding: 0.8rem 0.5rem;
        flex-wrap: wrap;
        gap: 0.3rem;
    }
    
    .header-left, .header-center, .header-right {
        gap: 0.3rem;
    }
    
    .level-number {
        padding: 0.3rem 0.8rem;
        font-size: 0.8rem;
    }
    
    .score-display, .lives-display, .coins-display {
        padding: 0.3rem 0.6rem;
        font-size: 0.8rem;
    }
    
    .powerups-panel {
        padding: 0.5rem;
        gap: 0.3rem;
    }
    
    .powerup {
        min-width: 55px;
        padding: 0.5rem 0.3rem;
        border-radius: 10px;
    }
    
    .powerup i {
        font-size: 1rem;
    }
    
    .powerup-cost {
        font-size: 0.6rem;
    }
    
    .modal-content {
        padding: 1.5rem 1rem;
        margin: 1rem 0.5rem;
        max-width: 90vw;
    }
    
    .modal-content h2 {
        font-size: 1.5rem;
    }
    
    .game-btn {
        padding: 0.6rem 1rem;
        font-size: 0.8rem;
    }
    
    .progress-container {
        padding: 0.8rem;
    }
    
    .target-info {
        font-size: 0.8rem;
    }
}

@media (max-width: 360px) {
    .game-board {
        width: min(85vw, 280px);
        height: min(85vw, 280px);
    }
    
    .powerup {
        min-width: 50px;
        padding: 0.4rem 0.2rem;
    }
    
    .powerup i {
        font-size: 0.9rem;
    }
    
    .game-header {
        padding: 0.6rem 0.3rem;
    }
    
    .level-number, .score-display, .lives-display, .coins-display {
        font-size: 0.7rem;
        padding: 0.2rem 0.5rem;
    }
}

@media (max-height: 700px) {
    .game-board {
        width: min(70vh, 280px);
        height: min(70vh, 280px);
    }
    
    .gem {
        font-size: clamp(0.9rem, 2.5vh, 1.2rem);
    }
    
    .powerups-panel {
        padding: 0.3rem;
    }
    
    .powerup {
        padding: 0.4rem 0.3rem;
    }
    
    .game-header {
        padding: 0.6rem;
    }
    
    .progress-container {
        padding: 0.6rem;
    }
}

@media (max-height: 600px) {
    .game-board {
        width: min(60vh, 250px);
        height: min(60vh, 250px);
    }
    
    .powerups-panel {
        padding: 0.2rem;
    }
    
    .powerup {
        min-width: 45px;
        padding: 0.3rem 0.2rem;
    }
    
    .powerup i {
        font-size: 0.8rem;
    }
    
    .modal-content {
        padding: 1rem;
        margin: 0.5rem;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .gem {
        cursor: pointer;
    }
    
    .gem:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
    
    .powerup:active, .game-btn:active, .icon-btn:active {
        transform: scale(0.95);
    }
    
    /* Increase tap targets for mobile */
    .powerup, .game-btn, .icon-btn {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Landscape orientation optimizations */
@media (orientation: landscape) and (max-height: 500px) {
    .game-container {
        flex-direction: row;
        max-width: 100vw;
    }
    
    .game-header {
        writing-mode: vertical-rl;
        width: auto;
        height: 100vh;
        flex-direction: column;
        padding: 1rem 0.5rem;
    }
    
    .powerups-panel {
        writing-mode: vertical-rl;
        flex-direction: column;
        width: auto;
        height: 100vh;
        padding: 1rem 0.3rem;
    }
    
    .game-board-container {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .progress-container {
        position: absolute;
        top: 10px;
        left: 50%;
        transform: translateX(-50%);
        width: 300px;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .gem {
        image-rendering: crisp-edges;
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .gem.selected {
        animation: none;
        box-shadow: 0 0 0 3px #fff;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    body {
        background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    }
    
    .game-container {
        background: rgba(0,0,0,0.3);
    }
    
    .modal-content {
        background: linear-gradient(145deg, #2c3e50, #34495e);
    }
}

/* Animations */
@keyframes bounce {
    0%, 20%, 60%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-10px);
    }
    80% {
        transform: translateY(-5px);
    }
}

.bounce {
    animation: bounce 0.6s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.5s ease-in-out;
}

/* Score popup */
.score-popup {
    position: absolute;
    color: #ffd700;
    font-weight: bold;
    font-size: 1.5rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    pointer-events: none;
    animation: scorePopup 1s ease-out forwards;
}

@keyframes scorePopup {
    0% {
        opacity: 1;
        transform: translateY(0) scale(0.8);
    }
    50% {
        transform: translateY(-30px) scale(1.2);
    }
    100% {
        opacity: 0;
        transform: translateY(-60px) scale(1);
    }
}