* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
}

#gameContainer, #gameCanvas {
    touch-action: none;
}

body {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
}

#gameContainer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

#header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 400px;
    padding: 0 10px;
    color: white;
}

#score, #timer {
    font-size: 18px;
    font-weight: bold;
}

#pauseBtn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 5px;
}

#eventDisplay {
    color: #ffd700;
    font-size: 16px;
    font-weight: bold;
    text-align: center;
    min-height: 24px;
    text-shadow: 0 0 10px #ffd700;
    animation: pulse 0.5s ease-in-out;
}

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

#gameCanvas {
    border: 3px solid #4a69bd;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(74, 105, 189, 0.5);
    background: #0a0a15;
}

#swipeHint {
    color: rgba(255,255,255,0.5);
    font-size: 12px;
    margin-top: 10px;
    text-align: center;
}

#welcomeScreen, #howToPlayScreen, #settingsScreen, #achievementsScreen,
#shopScreen, #leaderboardScreen, #startScreen, #gameOverScreen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    z-index: 10;
    padding: 20px;
    overflow-y: auto;
}

#welcomeScreen .logo {
    font-size: 80px;
    animation: bounce 2s infinite;
}

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

#welcomeScreen h1 {
    font-size: 42px;
    margin: 10px 0;
    background: linear-gradient(90deg, #4a69bd, #6c5ce7, #e74c3c);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    color: rgba(255,255,255,0.7);
    font-size: 14px;
    margin-bottom: 20px;
}

#playerInfo {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
    width: 100%;
    max-width: 320px;
}

#levelDisplay {
    font-size: 14px;
    font-weight: bold;
    color: #ffd700;
    white-space: nowrap;
    min-width: 45px;
}

#xpBar {
    flex: 1;
    height: 10px;
    background: rgba(255,255,255,0.1);
    border-radius: 5px;
    overflow: hidden;
}

#xpFill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4a69bd, #6c5ce7);
    border-radius: 5px;
    transition: width 0.5s ease;
}

#streakDisplay {
    font-size: 13px;
    color: #ff6b6b;
    white-space: nowrap;
}

#dailyChallengeDisplay {
    background: rgba(255, 215, 0, 0.1);
    border: 1px solid #ffd700;
    border-radius: 10px;
    padding: 10px 20px;
    margin-bottom: 20px;
    font-size: 14px;
    color: #ffd700;
}

.menu-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
    justify-content: center;
}

.menu-buttons .secondaryBtn {
    font-size: 13px;
    padding: 8px 16px;
}

#howToPlayScreen h2, #settingsScreen h2, #achievementsScreen h2,
#shopScreen h2, #leaderboardScreen h2 {
    font-size: 28px;
    color: #4a69bd;
    margin-bottom: 20px;
}

#howToPlayScreen h3, #settingsScreen h3 {
    font-size: 18px;
    color: #ffd700;
    margin: 20px 0 10px;
}

.instructions {
    text-align: left;
    padding: 0 20px;
    max-height: 200px;
    overflow-y: auto;
}

.instruction-item {
    font-size: 14px;
    margin: 10px 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.events-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    padding: 0 20px;
    max-width: 300px;
}

.events-preview span {
    background: rgba(255,255,255,0.1);
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 12px;
}

.settings-group {
    width: 100%;
    max-width: 300px;
}

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

.toggleBtn {
    padding: 8px 20px;
    border: none;
    border-radius: 20px;
    background: #4a69bd;
    color: white;
    cursor: pointer;
    font-weight: bold;
}

.difficulty-buttons {
    display: flex;
    gap: 10px;
    margin: 10px 0 20px;
}

.diff-btn {
    padding: 10px 20px;
    border: 2px solid #4a69bd;
    border-radius: 20px;
    background: transparent;
    color: #4a69bd;
    cursor: pointer;
    transition: all 0.3s;
}

.diff-btn.active {
    background: #4a69bd;
    color: white;
}

#achievementsList {
    width: 100%;
    max-width: 350px;
    max-height: 320px;
    overflow-y: auto;
    touch-action: pan-y;
}

.achievement-item {
    display: flex;
    flex-direction: column;
    padding: 12px;
    margin: 8px 0;
    background: rgba(255,255,255,0.05);
    border-radius: 10px;
    opacity: 0.5;
}

.achievement-item.unlocked {
    opacity: 1;
    background: rgba(255, 215, 0, 0.1);
    border: 1px solid rgba(255, 215, 0, 0.3);
}

.achievement-item small {
    color: rgba(255,255,255,0.6);
    font-size: 12px;
    margin-top: 4px;
}

.achievement-popup {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(145deg, #ffd700, #ffaa00);
    color: #000;
    padding: 15px 30px;
    border-radius: 30px;
    font-weight: bold;
    z-index: 100;
    animation: popIn 0.5s ease, popOut 0.5s ease 2.5s forwards;
    box-shadow: 0 5px 20px rgba(255, 215, 0, 0.5);
}

@keyframes popIn {
    0% { transform: translateX(-50%) translateY(-100px); opacity: 0; }
    100% { transform: translateX(-50%) translateY(0); opacity: 1; }
}

@keyframes popOut {
    0% { transform: translateX(-50%) translateY(0); opacity: 1; }
    100% { transform: translateX(-50%) translateY(-100px); opacity: 0; }
}

/* Shop */
#shopCoins {
    font-size: 20px;
    color: #ffd700;
    margin-bottom: 15px;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

#shopTabs {
    display: flex;
    gap: 5px;
    margin-bottom: 15px;
}

.shop-tab {
    padding: 8px 20px;
    border: 2px solid #4a69bd;
    border-radius: 20px;
    background: transparent;
    color: #4a69bd;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.3s;
}

.shop-tab.active {
    background: #4a69bd;
    color: white;
}

#shopItems {
    width: 100%;
    max-width: 350px;
    max-height: 320px;
    overflow-y: auto;
    touch-action: pan-y;
}

.shop-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    margin: 8px 0;
    background: rgba(255,255,255,0.05);
    border-radius: 10px;
    border: 1px solid transparent;
    transition: all 0.3s;
}

.shop-item.owned {
    border-color: rgba(46, 204, 113, 0.3);
    background: rgba(46, 204, 113, 0.05);
}

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

.shop-item-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.shop-item-name {
    font-size: 14px;
    font-weight: bold;
}

.shop-item-desc {
    font-size: 11px;
    color: rgba(255,255,255,0.5);
}

.shop-btn {
    padding: 6px 16px;
    border: none;
    border-radius: 15px;
    font-size: 12px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
}

.shop-btn.buy {
    background: #4a69bd;
    color: white;
}

.shop-btn.equip {
    background: #2ecc71;
    color: white;
}

.shop-btn.equipped {
    background: #ffd700;
    color: #000;
}

.shop-btn.owned {
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.5);
    cursor: default;
}

/* Leaderboard */
#leaderboardList {
    width: 100%;
    max-width: 350px;
    max-height: 350px;
    overflow-y: auto;
    touch-action: pan-y;
}

.lb-entry {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    margin: 5px 0;
    background: rgba(255,255,255,0.05);
    border-radius: 8px;
    gap: 10px;
}

.lb-rank {
    font-size: 16px;
    font-weight: bold;
    color: #4a69bd;
    min-width: 30px;
}

.lb-rank.gold { color: #ffd700; }
.lb-rank.silver { color: #c0c0c0; }
.lb-rank.bronze { color: #cd7f32; }

.lb-score {
    font-size: 18px;
    font-weight: bold;
    color: white;
    margin-left: auto;
}

.lb-detail {
    font-size: 11px;
    color: rgba(255,255,255,0.4);
    margin-left: 10px;
}

.lb-clear {
    margin-top: 15px;
    padding: 8px 20px;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 15px;
    background: transparent;
    color: rgba(255,255,255,0.4);
    cursor: pointer;
    font-size: 12px;
}

/* Game Over */
#highScoreDisplay {
    color: rgba(255,255,255,0.7);
    font-size: 16px;
    margin-bottom: 10px;
}

#statsBreakdown {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin: 10px 0;
    max-width: 320px;
}

.stat-chip {
    background: rgba(255,255,255,0.08);
    padding: 6px 14px;
    border-radius: 15px;
    font-size: 12px;
    color: rgba(255,255,255,0.8);
}

.stat-chip strong {
    color: #ffd700;
}

#xpGained {
    font-size: 14px;
    color: #6c5ce7;
    margin-bottom: 10px;
    font-weight: bold;
}

.gameover-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

/* Pause overlay */
#pauseOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 20;
}

#pauseOverlay h2 {
    font-size: 36px;
    color: #4a69bd;
    margin-bottom: 30px;
}

.secondaryBtn {
    padding: 12px 30px;
    font-size: 16px;
    border: 2px solid #4a69bd;
    border-radius: 25px;
    background: transparent;
    color: #4a69bd;
    cursor: pointer;
    margin-top: 10px;
    transition: all 0.3s;
}

.secondaryBtn:hover {
    background: rgba(74, 105, 189, 0.2);
}

#startScreen h1, #gameOverScreen h1 {
    font-size: 36px;
    margin-bottom: 20px;
    color: #4a69bd;
    text-shadow: 0 0 20px #4a69bd;
}

#startScreen p, #gameOverScreen p {
    font-size: 16px;
    margin-bottom: 10px;
    text-align: center;
    padding: 0 20px;
}

#finalScore {
    font-size: 32px;
    color: #ffd700;
    margin: 10px 0;
}

.startBtn {
    padding: 15px 40px;
    font-size: 20px;
    border: none;
    border-radius: 25px;
    background: linear-gradient(145deg, #4a69bd, #3c55a5);
    color: white;
    cursor: pointer;
    margin-top: 20px;
    box-shadow: 0 4px 15px rgba(74, 105, 189, 0.5);
    transition: transform 0.2s;
}

.startBtn:active {
    transform: scale(0.95);
}

.hidden {
    display: none !important;
}

/* Level up popup */
.levelup-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(145deg, #6c5ce7, #4a69bd);
    color: white;
    padding: 25px 40px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 24px;
    z-index: 100;
    animation: levelUpIn 0.5s ease, levelUpOut 0.5s ease 2s forwards;
    box-shadow: 0 5px 30px rgba(108, 92, 231, 0.6);
    text-align: center;
}

.levelup-popup small {
    display: block;
    font-size: 14px;
    margin-top: 8px;
    opacity: 0.8;
    font-weight: normal;
}

.toast-popup {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(145deg, #4a69bd, #3c55a5);
    color: white;
    padding: 12px 28px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: bold;
    z-index: 100;
    animation: popIn 0.3s ease, popOut 0.3s ease 2.2s forwards;
    box-shadow: 0 4px 15px rgba(74, 105, 189, 0.4);
}

@keyframes levelUpIn {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
    50% { transform: translate(-50%, -50%) scale(1.2); }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

@keyframes levelUpOut {
    0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background: #4a69bd;
    border-radius: 3px;
}
