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

:root {
    --primary-color: #2196F3;
    --success-color: #4CAF50;
    --warning-color: #FFC107;
    --error-color: #F44336;
    --secondary-color: #9C27B0;
    --bg-light: #f8f9fa;
    --bg-white: #ffffff;
    --text-dark: #333333;
    --text-light: #666666;
    --shadow: 0 2px 10px rgba(0,0,0,0.1);
    --border-radius: 12px;
    --nav-height: 70px;
    --header-height: 80px;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-light) 0%, #e3f2fd 100%);
    color: var(--text-dark);
    padding-bottom: var(--nav-height);
    min-height: 100vh;
    background-image: 
        radial-gradient(circle at 25% 25%, rgba(33, 150, 243, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 75% 75%, rgba(76, 175, 80, 0.1) 0%, transparent 50%);
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        repeating-linear-gradient(45deg, transparent, transparent 2px, rgba(255,255,255,0.1) 2px, rgba(255,255,255,0.1) 4px),
        repeating-linear-gradient(-45deg, transparent, transparent 2px, rgba(255,255,255,0.05) 2px, rgba(255,255,255,0.05) 4px);
    pointer-events: none;
    z-index: -1;
}

.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    z-index: 1000;
    box-shadow: var(--shadow);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    height: 100%;
}

.header-content h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.user-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-size: 0.85rem;
}

.user-name {
    font-weight: 600;
}

.user-level {
    opacity: 0.9;
    font-size: 0.75rem;
}

.app-main {
    margin-top: var(--header-height);
    padding: 20px;
    min-height: calc(100vh - var(--header-height) - var(--nav-height));
}

.screen {
    display: none;
    animation: fadeIn 0.3s ease-in-out;
}

.screen.active {
    display: block;
}

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

/* Home Screen */
.welcome-section {
    max-width: 600px;
    margin: 0 auto;
}

.story-intro {
    background: var(--bg-white);
    padding: 25px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    text-align: center;
}

.story-intro h2 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.4rem;
}

.story-intro p {
    line-height: 1.6;
    color: var(--text-light);
}

.current-story {
    background: var(--bg-white);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    border-left: 4px solid var(--success-color);
}

.current-story h3 {
    color: var(--success-color);
    margin-bottom: 10px;
}

.difficulty-selector {
    background: var(--bg-white);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.difficulty-selector h4 {
    margin-bottom: 15px;
    color: var(--text-dark);
    text-align: center;
}

.difficulty-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.difficulty-btn {
    flex: 1;
    padding: 15px;
    border: 2px solid var(--primary-color);
    background: var(--bg-white);
    color: var(--primary-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    font-size: 0.9rem;
    font-weight: 600;
}

.difficulty-btn.active,
.difficulty-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.difficulty-btn i {
    font-size: 1.2rem;
}

.start-adventure-btn {
    width: 100%;
    padding: 18px;
    background: linear-gradient(135deg, var(--success-color), #66bb6a);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: var(--shadow);
}

.start-adventure-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
}

/* Game Screen */
.game-container {
    max-width: 600px;
    margin: 0 auto;
}

.game-header {
    background: var(--bg-white);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.progress-info {
    display: flex;
    justify-content: space-around;
    margin-bottom: 15px;
}

.progress-info > div {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.lives i { color: var(--error-color); }
.score i { color: var(--warning-color); }
.streak i { color: var(--secondary-color); }

.question-counter {
    text-align: center;
    font-weight: 600;
    color: var(--text-light);
}

.story-context {
    background: linear-gradient(135deg, var(--secondary-color), #ba68c8);
    color: white;
    padding: 15px;
    border-radius: var(--border-radius);
    margin-bottom: 20px;
    text-align: center;
    font-style: italic;
}

.question-container {
    background: var(--bg-white);
    padding: 30px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    text-align: center;
}

.math-problem {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 30px;
    padding: 20px;
    background: var(--bg-light);
    border-radius: var(--border-radius);
}

.answer-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.answer-btn {
    padding: 20px;
    font-size: 1.5rem;
    font-weight: 700;
    border: 3px solid var(--primary-color);
    background: var(--bg-white);
    color: var(--primary-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.3s ease;
}

.answer-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: scale(1.05);
}

.answer-btn.correct {
    background: var(--success-color);
    border-color: var(--success-color);
    color: white;
    animation: correctAnswer 0.6s ease;
}

.answer-btn.incorrect {
    background: var(--error-color);
    border-color: var(--error-color);
    color: white;
    animation: incorrectAnswer 0.6s ease;
}

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

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

.feedback-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-white);
    padding: 30px;
    border-radius: var(--border-radius);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    z-index: 2000;
    text-align: center;
    min-width: 300px;
    display: none;
}

.feedback-container.show {
    display: block;
    animation: popIn 0.4s ease;
}

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

.feedback-message {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

#feedback-text {
    font-size: 1.2rem;
    font-weight: 600;
}

#next-question-btn {
    padding: 12px 24px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

#next-question-btn:hover {
    background: #1976d2;
    transform: translateY(-2px);
}

/* Progress Screen */
.progress-container {
    max-width: 600px;
    margin: 0 auto;
}

.progress-container h2 {
    text-align: center;
    margin-bottom: 25px;
    color: var(--primary-color);
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--bg-white);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    text-align: center;
    display: flex;
    align-items: center;
    gap: 15px;
}

.stat-icon {
    font-size: 2rem;
}

.stat-info h3 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 5px;
}

.stat-info p {
    color: var(--text-light);
    font-size: 0.9rem;
}

.achievements-section {
    background: var(--bg-white);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.achievements-section h3 {
    margin-bottom: 15px;
    color: var(--primary-color);
}

.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 15px;
}

.achievement-item {
    text-align: center;
    padding: 15px;
    border-radius: var(--border-radius);
    transition: all 0.3s ease;
}

.achievement-item.unlocked {
    background: linear-gradient(135deg, var(--warning-color), #ffb74d);
    color: white;
    transform: scale(1.05);
}

.achievement-item.locked {
    background: var(--bg-light);
    color: var(--text-light);
    opacity: 0.6;
}

.achievement-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.achievement-name {
    font-weight: 600;
    font-size: 0.8rem;
}

.level-progress {
    background: var(--bg-white);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.level-progress h3 {
    margin-bottom: 15px;
    color: var(--primary-color);
    text-align: center;
}

.level-info {
    display: flex;
    align-items: center;
    gap: 15px;
    font-weight: 600;
}

.xp-bar {
    flex: 1;
    height: 12px;
    background: var(--bg-light);
    border-radius: 6px;
    overflow: hidden;
}

.xp-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success-color), var(--primary-color));
    width: 0%;
    transition: width 0.5s ease;
}

/* Settings Screen */
.settings-container {
    max-width: 600px;
    margin: 0 auto;
}

.settings-container h2 {
    text-align: center;
    margin-bottom: 25px;
    color: var(--primary-color);
}

.settings-group {
    background: var(--bg-white);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.settings-group h3 {
    margin-bottom: 15px;
    color: var(--text-dark);
    border-bottom: 2px solid var(--bg-light);
    padding-bottom: 8px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid var(--bg-light);
}

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

.setting-item label {
    font-weight: 600;
    color: var(--text-dark);
}

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

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}

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

input:checked + .slider {
    background-color: var(--primary-color);
}

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

.setting-item input[type="text"] {
    padding: 8px 12px;
    border: 2px solid var(--bg-light);
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.setting-item input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
}

.danger-zone {
    background: #ffebee;
    padding: 20px;
    border-radius: var(--border-radius);
    border: 2px solid var(--error-color);
}

.danger-zone h3 {
    color: var(--error-color);
    margin-bottom: 15px;
}

.reset-progress-btn {
    padding: 12px 20px;
    background: var(--error-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.reset-progress-btn:hover {
    background: #d32f2f;
    transform: translateY(-2px);
}

/* FAQ Section */
.faq-section {
    background: var(--bg-white);
    padding: 25px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-top: 30px;
}

.faq-section h2 {
    text-align: center;
    margin-bottom: 25px;
    color: var(--primary-color);
}

.faq-item {
    border-bottom: 1px solid var(--bg-light);
}

.faq-item:last-child {
    border-bottom: none;
}

.faq-question {
    width: 100%;
    padding: 20px;
    background: none;
    border: none;
    text-align: left;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-dark);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
}

.faq-question:hover {
    background: var(--bg-light);
}

.faq-icon {
    font-size: 1.2rem;
    color: var(--primary-color);
    transition: transform 0.3s ease;
}

.faq-question[aria-expanded="true"] .faq-icon {
    transform: rotate(45deg);
}

.faq-answer {
    padding: 0 20px 20px;
    color: var(--text-light);
    line-height: 1.6;
    overflow: hidden;
    transition: all 0.3s ease;
}

.faq-answer[hidden] {
    display: none;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--bg-white);
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--text-light);
    font-size: 0.75rem;
    font-weight: 600;
    transition: all 0.3s ease;
    padding: 8px;
    border-radius: 8px;
}

.nav-item i {
    font-size: 1.2rem;
    margin-bottom: 4px;
}

.nav-item.active {
    color: var(--primary-color);
    background: rgba(33, 150, 243, 0.1);
}

.nav-item:hover {
    color: var(--primary-color);
}

/* Footer */
footer {
    text-align: center;
    padding: 20px;
    color: var(--text-light);
    font-size: 0.85rem;
    background: var(--bg-white);
    margin-top: 40px;
}

/* Responsive Design */
@media (max-width: 480px) {
    .app-main {
        padding: 15px;
    }
    
    .header-content {
        padding: 0 15px;
    }
    
    .header-content h1 {
        font-size: 1.3rem;
    }
    
    .difficulty-buttons {
        flex-direction: column;
    }
    
    .math-problem {
        font-size: 2rem;
        padding: 15px;
    }
    
    .answer-options {
        grid-template-columns: 1fr;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .stat-card {
        flex-direction: column;
        text-align: center;
    }
    
    .level-info {
        flex-direction: column;
        gap: 10px;
    }
    
    .achievements-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
}

@media (min-width: 768px) {
    .app-main {
        padding: 40px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .achievements-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
}

/* Loading and Animation States */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

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

.pulse {
    animation: pulse 2s infinite;
}

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

.bounce {
    animation: bounce 0.6s ease;
}

@keyframes bounce {
    0%, 20%, 53%, 80%, 100% { transform: translateY(0); }
    40%, 43% { transform: translateY(-10px); }
    70% { transform: translateY(-5px); }
    90% { transform: translateY(-2px); }
}
