:root {
    --primary: #6C63FF;
    --primary-dark: #5A52D5;
    --secondary: #FF6584;
    --success: #4ECDC4;
    --warning: #FFD93D;
    --danger: #FF4757;
    --dark: #2C3E50;
    --light: #F7F9FC;
    --gradient-1: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-2: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --gradient-3: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --gradient-4: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
    --bubble-1: #FF6B9D;
    --bubble-2: #C44569;
    --bubble-3: #4ECDC4;
    --bubble-4: #45B7D1;
    --bubble-5: #96CEB4;
    --bubble-6: #FFEAA7;
    --bubble-7: #DDA0DD;
    --bubble-8: #98D8C8;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 15px rgba(0,0,0,0.15);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.2);
    --shadow-xl: 0 15px 50px rgba(0,0,0,0.3);
    --radius-sm: 8px;
    --radius-md: 15px;
    --radius-lg: 25px;
    --radius-xl: 50px;
}

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

html, body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    font-family: 'Nunito', sans-serif;
    background: var(--gradient-1);
}

#app {
    width: 100%;
    height: 100%;
    height: 100dvh;
    position: relative;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
}
.screen.active { display: flex; }

.screen.overlay {
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.loading-screen { transition: opacity 0.5s ease; }

#start-screen {
    background: var(--gradient-1);
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.floating-bubbles {
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.floating-bubble {
    position: absolute;
    border-radius: 50%;
    animation: float linear infinite;
    opacity: 0;
}

@keyframes float {
    0% { transform: translateY(120vh) rotate(0deg) scale(0); opacity: 0; }
    10% { opacity: 0.6; }
    90% { opacity: 0.6; }
    100% { transform: translateY(-20vh) rotate(720deg) scale(1); opacity: 0; }
}

.content {
    text-align: center;
    z-index: 1;
    padding: 2rem;
    width: 100%;
    max-width: 500px;
}

.logo-container { margin-bottom: 1rem; }
.logo-bubble { font-size: 4rem; animation: bounce 2s infinite; display: block; }

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

.title {
    font-size: 2.5rem;
    font-weight: 900;
    color: white;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    margin: 0.5rem 0;
    background: linear-gradient(to right, #fff, #f0f0f0);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle { font-size: 1.1rem; color: rgba(255,255,255,0.9); margin-bottom: 1rem; font-weight: 400; }

.user-card {
    display: flex; align-items: center; justify-content: center; gap: 0.8rem;
    margin-bottom: 1.5rem; background: rgba(255,255,255,0.2); backdrop-filter: blur(10px);
    padding: 0.8rem 1.5rem; border-radius: var(--radius-xl); border: 1px solid rgba(255,255,255,0.3);
}
.user-avatar {
    width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,0.3);
    display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1.2rem; color: white; overflow: hidden;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-name { color: white; font-weight: 700; font-size: 1rem; }

.menu-buttons { display: flex; flex-direction: column; gap: 0.8rem; margin-bottom: 2rem; }

.btn-primary, .btn-secondary {
    border: none; cursor: pointer; font-family: 'Nunito', sans-serif; font-weight: 700;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); display: flex; align-items: center;
    justify-content: center; gap: 0.5rem; position: relative; overflow: hidden; text-decoration: none;
    text-align: center;
}

.btn-primary {
    background: white; color: var(--primary); padding: 1rem 2rem; border-radius: var(--radius-xl);
    font-size: 1.1rem; box-shadow: var(--shadow-lg);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow-xl); }
.btn-primary:active { transform: translateY(0) scale(0.98); }
.btn-primary::after {
    content: ''; position: absolute; top: 50%; left: 50%; width: 0; height: 0; border-radius: 50%;
    background: rgba(255,255,255,0.3); transform: translate(-50%, -50%); transition: width 0.6s, height 0.6s;
}
.btn-primary:active::after { width: 300px; height: 300px; }

.btn-large { padding: 1.2rem 2.5rem; font-size: 1.3rem; }

.btn-secondary {
    background: rgba(255,255,255,0.2); color: white; padding: 0.8rem 1.5rem;
    border-radius: var(--radius-xl); font-size: 1rem; backdrop-filter: blur(10px);
    border: 2px solid rgba(255,255,255,0.3);
}
.btn-secondary:hover { background: rgba(255,255,255,0.3); transform: translateY(-1px); }

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

.stats-container { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }
.stat-card {
    background: rgba(255,255,255,0.15); backdrop-filter: blur(10px); padding: 1rem;
    border-radius: var(--radius-md); min-width: 100px; flex: 1; max-width: 150px;
    border: 1px solid rgba(255,255,255,0.2);
}
.stat-label { display: block; color: rgba(255,255,255,0.8); font-size: 0.7rem; margin-bottom: 0.3rem; white-space: nowrap; }
.stat-card .stat-value { color: white; }
.stat-value { display: block; font-size: 1.5rem; font-weight: 800; }

.modal {
    background: white; padding: 2rem; border-radius: var(--radius-lg); box-shadow: var(--shadow-xl);
    width: 90%; max-width: 450px; max-height: 80vh; overflow-y: auto; animation: slideUp 0.3s ease; position: relative;
}
@keyframes slideUp {
    from { transform: translateY(50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.instructions-modal h2, .language-modal h2 { text-align: center; color: var(--dark); margin-bottom: 1.5rem; }
.instructions-content { margin-bottom: 1.5rem; }
.instruction-item { display: flex; align-items: center; gap: 1rem; padding: 0.8rem; background: var(--light); border-radius: var(--radius-sm); margin-bottom: 0.5rem; }
.instruction-icon { font-size: 2rem; min-width: 50px; text-align: center; }
.instruction-item p { color: var(--dark); font-weight: 600; font-size: 0.95rem; }

.language-modal { max-height: 70vh; }
.language-modal .btn-secondary { margin-top: 1rem; width: 100%; background: #f0f0f0; color: var(--dark); border: 2px solid #e0e0e0; }
.language-modal .btn-secondary:hover { background: #e0e0e0; }
.language-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 0.5rem; margin-bottom: 0.5rem; }
.language-btn {
    padding: 0.7rem 0.5rem; border: 2px solid #e0e0e0; border-radius: var(--radius-sm); background: white;
    cursor: pointer; font-family: 'Nunito', sans-serif; font-weight: 600; transition: all 0.2s ease;
    font-size: 0.85rem; text-align: center; animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.language-btn:hover { border-color: var(--primary); background: #f0f0ff; transform: scale(1.05); }
.language-btn.active { background: var(--primary); color: white; border-color: var(--primary); box-shadow: 0 2px 8px rgba(108,99,255,0.3); transform: scale(1.05); }

#game-screen { background: linear-gradient(180deg, #E8F5E9 0%, #B2DFDB 100%); }

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-sm);
    z-index: 10;
    color: var(--dark);
}

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

.stat-group { display: flex; align-items: center; gap: 0.3rem; }

.stat {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-weight: 700;
    color: var(--dark);
}
.stat-icon { font-size: 1.2rem; }

.header-left .stat-value,
.header-right .stat-value {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--dark);
}

.miss-stat {
    color: var(--danger);
    font-weight: 700;
}
.miss-stat .stat-value {
    font-size: 0.95rem;
    color: var(--danger);
    background: rgba(255,71,87,0.1);
    padding: 0.15rem 0.5rem;
    border-radius: 20px;
}

.btn-icon, .btn-icon-small {
    background: none; border: none; cursor: pointer; font-size: 1.5rem; padding: 0.3rem; transition: transform 0.2s;
}
.btn-icon-small {
    font-size: 1rem; background: var(--success); color: white; width: 28px; height: 28px;
    border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 800;
}
.btn-icon:hover, .btn-icon-small:hover { transform: scale(1.2); }

.timer-container { display: flex; align-items: center; gap: 0.5rem; width: 100%; max-width: 150px; }
.timer-bar { flex: 1; height: 6px; background: rgba(0,0,0,0.1); border-radius: 10px; overflow: hidden; }
.timer-fill { height: 100%; background: var(--gradient-3); transition: width 1s linear; border-radius: 10px; }
.timer-fill.warning { background: var(--gradient-2); animation: pulse 0.5s infinite; }
.timer-text { font-weight: 800; color: var(--dark); min-width: 30px; text-align: center; font-size: 0.9rem; }

.level-info {
    padding: 0.5rem 1rem;
    background: rgba(255,255,255,0.7);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--dark);
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.level-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.progress-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    max-width: 200px;
}

.mode-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

#mode-indicator {
    font-weight: 700;
    padding: 0.2rem 0.8rem;
    border-radius: 15px;
    font-size: 0.8rem;
    display: inline-block;
    flex-shrink: 0;
}
.mode-zen { background: rgba(76, 175, 80, 0.2); color: #2E7D32; }
.mode-challenge { background: rgba(255, 71, 87, 0.2); color: #C62828; animation: pulse 1s infinite; }
.mode-danger { background: rgba(136, 14, 79, 0.3); color: #FFD700; animation: pulse 0.7s infinite; }

.challenge-intensity-bar {
    width: 60px;
    height: 6px;
    background: rgba(0,0,0,0.2);
    border-radius: 10px;
    overflow: hidden;
    flex-shrink: 0;
}
.challenge-intensity-fill {
    height: 100%;
    background: linear-gradient(90deg, #FF4757, #FF6B6B);
    width: 0%;
    transition: width 0.3s ease;
}

#game-canvas { flex: 1; width: 100%; cursor: pointer; touch-action: none; }

#notification-area {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    z-index: 20;
    pointer-events: none;
    width: 90%;
    max-width: 300px;
}

.notification-item {
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 0.8rem 1.5rem;
    border-radius: 25px;
    font-weight: 700;
    font-size: 1rem;
    text-align: center;
    animation: slideInDown 0.3s ease, fadeOut 0.5s ease 1.5s forwards;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    width: fit-content;
    max-width: 100%;
}

.notification-item.combo { background: rgba(0,0,0,0.85); color: #FFD93D; }
.notification-item.powerup { background: rgba(76,175,80,0.9); color: white; }
.notification-item.levelup {
    background: linear-gradient(135deg, #FFD93D, #FF6B6B);
    color: #2C3E50;
    font-size: 1.5rem;
    font-weight: 900;
    padding: 1rem 2rem;
}

@keyframes slideInDown {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeOut {
    to { opacity: 0; transform: translateY(-10px); }
}

.pause-stats { display: flex; justify-content: center; gap: 2rem; margin: 1rem 0 1.5rem; }
.pause-stat { text-align: center; background: var(--light); padding: 1rem; border-radius: var(--radius-md); min-width: 100px; }
.pause-stat span:first-child { display: block; font-size: 0.8rem; color: #666; margin-bottom: 0.3rem; }
.pause-stat-value { font-size: 1.5rem; font-weight: 800; color: var(--primary); }

#pause-screen .modal {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}
#pause-screen .btn-primary,
#pause-screen .btn-secondary {
    width: 80%;
    max-width: 250px;
    margin: 0.4rem 0;
}

.celebration { text-align: center; }
.gameover-animation { font-size: 4rem; animation: celebrateBounce 0.6s ease; }
@keyframes celebrateBounce {
    0% { transform: scale(0); } 50% { transform: scale(1.2); } 100% { transform: scale(1); }
}
.final-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; margin: 1.5rem 0; }
.final-stat { background: var(--light); padding: 0.8rem; border-radius: var(--radius-sm); }
.final-stat-label { display: block; font-size: 0.7rem; color: #666; margin-bottom: 0.3rem; }
.final-stat-value { display: block; font-size: 1.2rem; font-weight: 800; color: var(--primary); }
#new-record { color: var(--warning); font-weight: 800; font-size: 1.2rem; animation: pulse 1s infinite; }
.gameover-buttons { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 1rem; align-items: center; }
.gameover-buttons .btn-secondary { background: #f0f0f0; color: var(--dark); border: 2px solid #e0e0e0; width: 80%; max-width: 280px; }
.gameover-buttons .btn-secondary:hover { background: #e0e0e0; }

.hidden { display: none !important; }

.modal::-webkit-scrollbar { width: 5px; }
.modal::-webkit-scrollbar-track { background: transparent; }
.modal::-webkit-scrollbar-thumb { background: #ccc; border-radius: 10px; }

@media (max-width: 768px) {
    .title { font-size: 2rem; }
    .final-stats { grid-template-columns: repeat(3, 1fr); }
    .stats-container { gap: 0.5rem; }
    .stat-card { min-width: 80px; padding: 0.8rem; }
    .stat-value { font-size: 1.2rem; }
}
@media (max-width: 480px) {
    .title { font-size: 1.6rem; }
    .subtitle { font-size: 0.9rem; }
    .menu-buttons { gap: 0.5rem; }
    .btn-large { padding: 1rem 2rem; font-size: 1.1rem; }
    .btn-secondary { padding: 0.7rem 1.2rem; font-size: 0.9rem; }
    .modal { padding: 1.5rem; width: 95%; }
    .final-stats { grid-template-columns: 1fr; gap: 0.3rem; }
    .final-stat { padding: 0.6rem; }
    .game-header { padding: 0.4rem 0.5rem; flex-wrap: wrap; }
    .header-left, .header-right { gap: 0.3rem; }
    .stat { font-size: 0.8rem; }
    .btn-icon { font-size: 1.2rem; }
    .language-grid { grid-template-columns: repeat(2, 1fr); gap: 0.4rem; }
    .language-btn { padding: 0.6rem 0.4rem; font-size: 0.8rem; }
    .miss-stat .stat-value { font-size: 0.8rem; }
}

@supports (padding-top: env(safe-area-inset-top)) {
    .game-header { padding-top: calc(env(safe-area-inset-top) + 0.5rem); }
    #start-screen { padding-top: env(safe-area-inset-top); }
}

#continue-btn {
    background: rgba(255,255,255,0.3);
    border: 2px solid rgba(255,255,255,0.5);
    font-weight: 600;
}
#continue-btn:hover { background: rgba(255,255,255,0.4); }

.bonus-panel {
    position: absolute;
    top: 70px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    z-index: 25;
    pointer-events: none;
}
.bonus-item {
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: fadeIn 0.3s ease;
    white-space: nowrap;
}
.bonus-timer-bar {
    width: 40px;
    height: 4px;
    background: rgba(255,255,255,0.3);
    border-radius: 2px;
    overflow: hidden;
}
.bonus-timer-fill {
    height: 100%;
    background: var(--success);
    transition: width 1s linear;
}

/* Barra de poder especial */
.power-bar-container {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-left: 0.5rem;
    cursor: pointer;
    position: relative;
}
.power-bar {
    width: 50px;
    height: 8px;
    background: rgba(0,0,0,0.2);
    border-radius: 10px;
    overflow: hidden;
    transition: all 0.2s;
}
.power-bar.full { box-shadow: 0 0 12px rgba(255,215,0,0.7); background: rgba(255,215,0,0.2); }
.power-fill {
    height: 100%;
    background: linear-gradient(90deg, #FFD700, #FFA500);
    width: 0%;
    transition: width 0.3s ease;
    box-shadow: 0 0 8px rgba(255,215,0,0.5);
}
.btn-power-icon {
    background: none;
    border: 2px solid #FFD700;
    color: #FFD700;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-power-icon:disabled { opacity: 0.4; border-color: #aaa; color: #aaa; cursor: not-allowed; animation: none; }
.btn-power-icon:not(:disabled) { animation: pulse 1.5s infinite; box-shadow: 0 0 15px rgba(255,215,0,0.6); }
.btn-power-icon:not(:disabled):hover { background: #FFD700; color: #333; transform: scale(1.2); }

/* Modal de guardado */
#save-modal .modal-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    text-align: center;
}
#save-modal .modal-content h2 { color: var(--dark); }
#save-modal .modal-content p { font-weight: 600; color: var(--dark); margin-bottom: 0.5rem; }
#save-modal .btn-primary,
#save-modal .btn-secondary {
    width: 200px;
    margin: 0.3rem 0;
}
#save-modal .btn-secondary {
    color: var(--dark);
    background: #f0f0f0;
    border: 2px solid #e0e0e0;
}
#save-modal .btn-secondary:hover {
    background: #e0e0e0;
}

/* Animación de explosión con temblor */
@keyframes supernova {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(10); opacity: 0; }
}
.supernova-circle {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255,255,255,0.9), rgba(255,200,0,0.5), transparent);
    animation: supernova 0.8s ease-out forwards;
    pointer-events: none;
    z-index: 15;
}

#game-screen.shake {
    animation: screenShake 0.6s ease;
}
@keyframes screenShake {
    0%, 100% { transform: translate(0); }
    10% { transform: translate(-5px, 2px); }
    20% { transform: translate(5px, -3px); }
    30% { transform: translate(-4px, -2px); }
    40% { transform: translate(4px, 3px); }
    50% { transform: translate(-3px, -1px); }
    60% { transform: translate(3px, -2px); }
    70% { transform: translate(-2px, 1px); }
    80% { transform: translate(2px, -3px); }
    90% { transform: translate(-1px, 2px); }
}