:root {
    --primary-color: #6366f1; /* Indigo */
    --secondary-color: #ec4899; /* Pink */
    --success-color: #10b981; /* Emerald */
    --error-color: #ef4444; /* Red */
    --bg-gradient-start: #0f172a; /* Slate 900 */
    --bg-gradient-end: #1e1b4b; /* Indigo 950 */
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-main: #f8fafc; /* Slate 50 */
    --text-muted: #cbd5e1; /* Slate 300 */
    
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
}

/* Themes */
body.theme-forest {
    --primary-color: #10b981;
    --secondary-color: #f59e0b;
    --bg-gradient-start: #064e3b;
    --bg-gradient-end: #022c22;
}

body.theme-ocean {
    --primary-color: #0ea5e9;
    --secondary-color: #14b8a6;
    --bg-gradient-start: #082f49;
    --bg-gradient-end: #0c4a6e;
}

body.theme-sunset {
    --primary-color: #f43f5e;
    --secondary-color: #f59e0b;
    --bg-gradient-start: #4c0519;
    --bg-gradient-end: #7c2d12;
}

body.theme-neon {
    --primary-color: #ec4899;
    --secondary-color: #8b5cf6;
    --bg-gradient-start: #2e1065;
    --bg-gradient-end: #000000;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
    color: var(--text-main);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
}

/* Base Styles & Utils */
.app-container {
    width: 100%;
    max-width: 800px;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    position: relative;
}

.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.top-bar h1 {
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(to right, #a855f7, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.badges-container {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.badge-icon {
    font-size: 1.2rem;
    color: #fbbf24; /* Amber */
    filter: drop-shadow(0 0 5px rgba(251, 191, 36, 0.5));
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.badge-icon.locked {
    color: var(--glass-border);
    filter: none;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes popIn {
    0% { transform: scale(0); }
    80% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

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

@keyframes float {
    0% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
    100% { transform: translateY(0px); }
}

.fade-in {
    animation: fadeIn var(--transition-normal) forwards;
}

.bounce {
    animation: popIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

/* Buttons */
button {
    font-family: 'Outfit', sans-serif;
    cursor: pointer;
    border: none;
    outline: none;
    transition: var(--transition-fast);
}

.btn-primary, .btn-secondary, .btn-option {
    padding: 1rem 1.5rem;
    border-radius: 0.75rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: white;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.btn-secondary {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Selector View */
.view-selector {
    text-align: center;
}

.view-selector h2 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.view-selector p {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.tables-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
}

.table-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    padding: 1.5rem;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.table-btn:hover {
    transform: translateY(-5px) scale(1.05);
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary-color);
    box-shadow: 0 10px 25px rgba(99, 102, 241, 0.2);
}

.table-btn.completed {
    border-color: var(--success-color);
    background: rgba(16, 185, 129, 0.1);
}

.table-btn i.fa-star {
    font-size: 1rem;
    color: #fbbf24;
}

/* Practice View */
.view-practice, .view-problem {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.progress-bar-container {
    height: 10px;
    border-radius: 5px;
    overflow: hidden;
    padding: 0;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--success-color), #34d399);
    width: 0%;
    transition: width 0.3s ease;
}

.question-container {
    padding: 3rem 2rem;
    margin: 1rem 0;
}

.question-text {
    font-size: 4rem;
    font-weight: 800;
    letter-spacing: 2px;
    text-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.btn-option {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    font-size: 1.5rem;
    padding: 1.5rem;
}

.btn-option:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.02);
}

.btn-option.correct {
    background: var(--success-color);
    border-color: var(--success-color);
}

.btn-option.wrong {
    background: var(--error-color);
    border-color: var(--error-color);
}

/* Problem View */
.problem-card {
    padding: 2rem;
    margin-bottom: 1rem;
}

.problem-icon {
    font-size: 3rem;
    color: var(--secondary-color);
    margin-bottom: 1rem;
}

.problem-text {
    font-size: 1.25rem;
    line-height: 1.6;
}

.problem-options {
    grid-template-columns: 1fr;
}

/* Badge Won View */
.view-badge-won {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
}

.badge-showcase {
    padding: 3rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.badge-large {
    font-size: 6rem;
    color: #fbbf24;
    filter: drop-shadow(0 0 20px rgba(251, 191, 36, 0.6));
}

/* Minigame Views */
.view-minigame {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.minigame-area {
    position: relative;
    width: 100%;
    max-width: 600px;
    height: 400px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 1rem;
    border: 1px solid var(--glass-border);
    overflow: hidden;
    margin-bottom: 1rem;
}

.score-display {
    padding: 0.5rem 2rem;
    font-size: 1.5rem;
    font-weight: 800;
    border-radius: 2rem;
    color: var(--secondary-color);
}

/* Balloons Game */
.balloon {
    position: absolute;
    bottom: -100px;
    font-size: 4rem;
    cursor: pointer;
    user-select: none;
    transition: transform 0.1s;
    animation: floatUp linear forwards;
}

.balloon:active {
    transform: scale(0.9);
}

.balloon.popped {
    animation: popBalloon 0.3s forwards !important;
    pointer-events: none;
}

@keyframes floatUp {
    to { bottom: 100%; }
}

@keyframes popBalloon {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.5); opacity: 0.5; }
    100% { transform: scale(0); opacity: 0; }
}

/* Treasure Game */
.treasure-area {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    padding: 2rem;
    align-content: center;
}

.chest {
    font-size: 4rem;
    cursor: pointer;
    transition: transform 0.2s;
    user-select: none;
}

.chest:hover {
    transform: scale(1.1);
}

.chest.opened {
    pointer-events: none;
    animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Whack-a-Mole Game */
.mole-area {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    padding: 2rem;
}

.hole {
    background: rgba(0,0,0,0.5);
    border-radius: 50%;
    height: 100px;
    position: relative;
    overflow: hidden;
    border: 4px solid var(--glass-border);
    box-shadow: inset 0 10px 20px rgba(0,0,0,0.5);
}

.mole {
    font-size: 4rem;
    position: absolute;
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
    cursor: pointer;
    transition: bottom 0.2s ease-out;
    user-select: none;
}

.mole.up {
    bottom: 0px;
}

.mole.whacked {
    pointer-events: none;
    animation: shake 0.2s;
}

/* Toast */
.toast-container {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 1000;
}

.toast {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    padding: 1rem 2rem;
    border-radius: 2rem;
    color: white;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: fadeIn 0.3s forwards, fadeOut 0.3s 2s forwards;
}

.toast.success { border-left: 4px solid var(--success-color); }
.toast.error { border-left: 4px solid var(--error-color); }

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

/* Nuevos Estilos para Niveles y Teclado */
.level-indicator {
    display: inline-block;
    padding: 0.5rem 1.5rem;
    border-radius: 2rem;
    font-weight: 800;
    font-size: 1.2rem;
    color: #fbbf24;
    margin: 0 auto;
    border-color: #fbbf24;
}

.keypad-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 300px;
    margin: 0 auto;
    width: 100%;
}

.keypad-input {
    font-size: 3rem;
    font-weight: 800;
    text-align: center;
    padding: 1rem;
    min-height: 80px;
    letter-spacing: 5px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 1rem;
}

.keypad-input.wrong-input {
    animation: shake 0.4s ease-in-out;
    color: var(--error-color);
}

.keypad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.key-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    font-size: 1.5rem;
    font-weight: 800;
    color: white;
    padding: 1rem 0;
    cursor: pointer;
    transition: transform 0.1s, background 0.2s;
}

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

.key-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.key-action {
    background: rgba(255, 255, 255, 0.1);
}

.key-action.correct {
    background: var(--success-color);
    border-color: var(--success-color);
}

.practice-timer {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--primary-color);
    background: rgba(255, 255, 255, 0.1);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    min-width: 110px;
    justify-content: center;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

.user-profile-display {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--text-main);
    max-width: 100%;
    min-width: 0;
}

#header-username {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
    display: inline-block;
    vertical-align: middle;
    min-width: 0;
}

.header-avatar {
    width: 32px;
    height: 32px;
    display: inline-block;
    flex-shrink: 0;
}

.view-profile,
.view-level-complete {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.profile-form {
    padding: 2rem;
    max-width: 500px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.input-text {
    width: 100%;
    padding: 1rem;
    font-size: 1.2rem;
    border-radius: 0.75rem;
    border: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.2);
    color: white;
    font-family: 'Outfit', sans-serif;
    outline: none;
    transition: border-color 0.3s;
}

.input-text:focus {
    border-color: var(--primary-color);
}

.avatars-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.avatar-option {
    font-size: 3rem;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 1rem;
    padding: 0.5rem;
    border: 2px solid transparent;
    transition: transform 0.2s, border-color 0.2s;
}

.avatar-option:hover {
    transform: scale(1.1);
}

.avatar-option.selected {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.2);
    transform: scale(1.1);
}

.theme-options-grid {
    display: flex;
    gap: 1rem;
    justify-content: space-around;
}

.theme-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--glass-border);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.theme-btn:hover {
    transform: scale(1.1);
}

.theme-btn.selected {
    border-color: white;
    transform: scale(1.1);
    box-shadow: 0 0 10px rgba(255,255,255,0.5);
}

/* Responsive fixes */
@media (max-width: 480px) {
    .app-container { padding: 1rem; }
    .question-text { font-size: clamp(2rem, 8vw, 4rem); }
    .btn-option { font-size: clamp(1rem, 4vw, 1.5rem); padding: 1rem; }
    .ws-cell { font-size: 1rem; }
    .key-btn { padding: 0.8rem 0; font-size: 1.3rem; }
    .keypad-input { font-size: 2.5rem; min-height: 60px; padding: 0.5rem; }
    .keypad-grid { gap: 0.5rem; }
    .top-bar { 
        flex-direction: column; 
        text-align: center; 
        justify-content: center; 
        gap: 1rem; 
        padding: 1rem; 
    }
    .operations-grid {
        grid-template-columns: 1fr !important;
    }
    .header-right { 
        display: flex;
        flex-direction: row; 
        flex-wrap: wrap; 
        justify-content: center; 
        gap: 0.5rem; 
        width: 100%;
    }
    .user-profile-display { 
        font-size: clamp(1rem, 4vw, 1.2rem); 
        max-width: 100%; 
        width: 100%;
        justify-content: center;
        margin-bottom: 0.5rem;
    }
    #header-username {
        max-width: 150px;
    }
    .badges-container { justify-content: center; width: 100%; }
}

/* --- Memory Game --- */
.memory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    max-width: 400px;
    margin: 20px auto;
}
.memory-card {
    background-color: transparent;
    width: 100%;
    aspect-ratio: 1;
    perspective: 1000px;
    cursor: pointer;
}
.memory-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s;
    transform-style: preserve-3d;
}
.memory-card.flipped .memory-card-inner {
    transform: rotateY(180deg);
}
.memory-card-front, .memory-card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}
.memory-card-front {
    background: var(--primary-color);
    color: white;
}
.memory-card-back {
    background: white;
    transform: rotateY(180deg);
}
