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

/* Performance optimizations for 60fps animations */
.big-btn,
.grade-btn,
.topic-btn,
.option-btn,
.screen {
    will-change: transform;
    transform: translateZ(0); /* Hardware acceleration */
    backface-visibility: hidden;
}

/* Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .big-btn,
    .grade-btn,
    .topic-btn,
    .option-btn,
    .screen {
        transition: none;
        transform: none;
        animation: none;
    }
    
    .screen {
        opacity: 1;
        visibility: visible;
    }
    
    .screen.active {
        opacity: 1;
        visibility: visible;
    }
}

body {
    font-family: 
        'Comic Sans MS',           /* Windows */
        'Chalkboard SE',           /* macOS/iOS */
        'Chalkboard',              /* older macOS/iOS */
        'Marker Felt',             /* iOS fallback */
        'Bradley Hand ITC',        /* macOS */
        'Trebuchet MS',            /* Cross-platform readable */
        'Helvetica Neue',          /* iOS/macOS clean fallback */
        'Arial',                   /* Universal fallback */
        sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    
    /* CRITICAL FIX: Prevent content from being positioned below viewport */
    margin: 0;
    padding: 20px 0 0 0;
    overflow-x: hidden;
    box-sizing: border-box;
}

/* ⚡ SKIP LINK - Accessible but Hidden */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: #ff6b6b;
    color: white;
    padding: 8px;
    border-radius: 0 0 6px 6px;
    text-decoration: none;
    font-weight: bold;
    font-size: 14px;
    z-index: 1000;
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 0;
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* 🎮 FUN GAME-STYLE BREADCRUMBS */
.breadcrumb-nav {
    background: linear-gradient(45deg, #4ecdc4 0%, #44a08d 100%);
    border-radius: 25px;
    padding: 8px 15px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    font-size: 0.9em;
    min-height: 40px;
}

.breadcrumb-item {
    color: white;
    text-decoration: none;
    font-weight: bold;
    padding: 4px 8px;
    border-radius: 12px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 4px;
}

.breadcrumb-item:hover:not(.current) {
    background: rgba(255,255,255,0.2);
    transform: translateY(-1px);
}

.breadcrumb-item.current {
    background: rgba(255,255,255,0.3);
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

.breadcrumb-separator {
    color: rgba(255,255,255,0.8);
    font-weight: bold;
    font-size: 1.1em;
}

#app {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

.screen {
    background: white;
    border-radius: 20px;
    padding: 20px 25px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    text-align: center;

    /* CRITICAL FIX: Hide inactive screens completely to prevent layout space occupation */
    display: none;
    opacity: 0;
    visibility: hidden;
    transform: translate3d(0, 20px, 0);
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0s 0.3s;
    
    /* CRITICAL: Override grid system height conflicts for 1M+ children */
    height: auto !important;
    min-height: auto !important;
    max-height: none !important;
    position: relative !important;
}

.screen.active {
    /* CRITICAL FIX: Show active screen in layout */
    display: block;
    opacity: 1;
    visibility: visible;
    transform: translate3d(0, 0, 0);
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Viewport-safe screens use flexbox for proper positioning */
.screen.active.viewport-safe-nav-screen,
.screen.active.viewport-safe-game-content,
.screen.active.viewport-safe-menu {
    display: flex;
}

h1 {
    font-size: 2.5em;
    color: #ff6b6b;
    margin-bottom: 15px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

h2 {
    font-size: 2em;
    color: #ff6b6b;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

/* Special styling for welcome header h2 */
.welcome-header h2 {
    font-size: 2.2em;
    color: #ff6b6b;
    margin-bottom: 20px;
}

h3 {
    font-size: 1.5em;
    color: #333;
    margin-bottom: 20px;
}

.big-btn {
    background: linear-gradient(45deg, #ff6b6b, #ffa500);
    color: white;
    border: none;
    padding: 15px 30px;
    font-size: 1.2em;
    border-radius: 25px;
    cursor: pointer;
    margin: 10px;
    transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1), 
                box-shadow 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    font-weight: bold;
    /* Hardware acceleration for smooth animations */
    transform: translate3d(0, 0, 0);
}

.big-btn:hover {
    transform: translate3d(0, -2px, 0);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.big-btn:active {
    transform: translate3d(0, 0, 0);
    transition: transform 0.1s;
}

.grade-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin: 20px 0;
}

.grade-btn {
    background: linear-gradient(45deg, #4ecdc4, #45b7b8);
    color: white;
    border: none;
    padding: 20px;
    font-size: 1.1em;
    border-radius: 15px;
    cursor: pointer;
    transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    font-weight: bold;
    /* Hardware acceleration for smooth scaling */
    transform: translate3d(0, 0, 0) scale(1);
}

.grade-btn:hover {
    transform: translate3d(0, 0, 0) scale(1.05);
}

.grade-btn:active {
    transform: translate3d(0, 0, 0) scale(0.98);
    transition: transform 0.1s;
}

#topics-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin: 20px 0;
}

.topic-btn {
    background: linear-gradient(45deg, #a8e6cf, #88d8a3);
    color: #333;
    border: none;
    padding: 20px;
    font-size: 1em;
    border-radius: 15px;
    cursor: pointer;
    transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    font-weight: bold;
    /* Hardware acceleration for smooth scaling */
    transform: translate3d(0, 0, 0) scale(1);
}

.topic-btn:hover {
    transform: translate3d(0, 0, 0) scale(1.05);
}

.topic-btn:active {
    transform: translate3d(0, 0, 0) scale(0.98);
    transition: transform 0.1s;
}

.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 10px;
}

.stars-display {
    font-size: 1.5em;
    font-weight: bold;
    color: #ffa500;
}

.question-counter {
    font-size: 1.2em;
    color: #333;
}

#question-container {
    margin: 30px 0;
}

#answer-input {
    padding: 15px;
    font-size: 1.2em;
    border: 3px solid #ddd;
    border-radius: 10px;
    text-align: center;
    margin: 20px;
    width: 200px;
    font-family: inherit;
}

#answer-input:focus {
    outline: none;
    border-color: #4ecdc4;
}

.answer-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin: 20px 0;
}

.option-btn {
    background: #f8f9fa;
    border: 3px solid #ddd;
    padding: 15px;
    font-size: 1.1em;
    border-radius: 10px;
    cursor: pointer;
    transition: background-color 0.15s cubic-bezier(0.4, 0, 0.2, 1),
                border-color 0.15s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.1s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    /* Hardware acceleration */
    transform: translate3d(0, 0, 0);
}

.option-btn:hover {
    background: #e9ecef;
    border-color: #4ecdc4;
    transform: translate3d(0, -1px, 0);
}

.option-btn:active {
    transform: translate3d(0, 0, 0);
    transition: transform 0.05s;
}

.option-btn.selected {
    background: #4ecdc4;
    border-color: #4ecdc4;
    color: white;
}

.feedback {
    margin: 20px 0;
    padding: 15px;
    border-radius: 10px;
    font-size: 1.2em;
    font-weight: bold;
}

.feedback.correct {
    background: #d4edda;
    color: #155724;
    border: 2px solid #c3e6cb;
}

.feedback.incorrect {
    background: #f8d7da;
    color: #721c24;
    border: 2px solid #f5c6cb;
}

.results-summary {
    margin: 30px 0;
    font-size: 1.3em;
}

.results-summary span {
    color: #ff6b6b;
    font-weight: bold;
}

.results-buttons {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

.shop-header {
    margin-bottom: 30px;
    padding: 15px;
    background: #fff3cd;
    border-radius: 10px;
    font-size: 1.3em;
    font-weight: bold;
}

#shop-items {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin: 30px 0;
}

.shop-item {
    background: #f8f9fa;
    border: 2px solid #ddd;
    border-radius: 15px;
    padding: 20px;
    text-align: center;
    transition: transform 0.2s;
}

.shop-item:hover {
    transform: translateY(-2px);
}

.shop-item.owned {
    background: #d4edda;
    border-color: #c3e6cb;
}

.shop-item.affordable {
    border-color: #4ecdc4;
}

.trophy-icon {
    font-size: 3em;
    margin-bottom: 10px;
}

.trophy-name {
    font-size: 1.2em;
    font-weight: bold;
    margin-bottom: 10px;
}

.trophy-cost {
    color: #ffa500;
    font-weight: bold;
    margin-bottom: 15px;
}

.buy-btn {
    background: #4ecdc4;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit;
    font-weight: bold;
}

.buy-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.back-btn {
    background: #6c757d;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 10px;
    cursor: pointer;
    margin-top: 20px;
    font-family: inherit;
}

.back-btn:hover {
    background: #5a6268;
}

.setting-btn {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 1em;
    border-radius: 20px;
    cursor: pointer;
    margin: 10px;
    transition: all 0.3s ease;
    font-family: inherit;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.setting-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    background: linear-gradient(45deg, #764ba2, #667eea);
}

.setting-btn:focus {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* Progress Bar Styles */
.progress-container {
    margin: 20px 0;
    text-align: center;
}

.progress-bar {
    width: 100%;
    height: 20px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 8px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4ecdc4, #45b7b8, #26de81);
    border-radius: 10px;
    transition: width 0.5s ease, background 0.3s ease;
    position: relative;
    overflow: hidden;
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.3) 50%, transparent 70%);
    animation: progress-shine 2s infinite;
}

@keyframes progress-shine {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.progress-text {
    color: #fff;
    font-weight: bold;
    font-size: 0.9em;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

/* Enhanced quiz header layout */
.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    margin-bottom: 10px;
    flex-wrap: wrap;
    gap: 10px;
}

.stars-display {
    font-size: 1.2em;
    font-weight: bold;
    color: #ffd700;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.question-counter {
    font-weight: bold;
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.quiz-header-buttons {
    display: flex;
    gap: 10px;
}

/* Profile Screen Styles */
.new-profile-section {
    margin-top: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 15px;
}

#new-profile-name {
    padding: 15px;
    font-size: 1.2em;
    border: 3px solid #ddd;
    border-radius: 10px;
    text-align: center;
    margin: 15px;
    width: 350px;
    max-width: 90%;
    font-family: inherit;
}

#new-profile-name:focus {
    outline: none;
    border-color: #4ecdc4;
}

.avatar-selection {
    margin: 20px 0;
}

.avatar-options {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 15px 0;
}

.avatar-btn {
    background: #f8f9fa;
    border: 3px solid #ddd;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    font-size: 2em;
    cursor: pointer;
    transition: all 0.2s;
}

.avatar-btn:hover {
    transform: scale(1.1);
    border-color: #4ecdc4;
}

.avatar-btn.selected {
    border-color: #ff6b6b;
    background: #fff5f5;
    transform: scale(1.1);
}

.profile-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin: 20px 0;
}

.profile-item {
    background: #f8f9fa;
    border: 3px solid #ddd;
    border-radius: 15px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.profile-item:hover {
    border-color: #4ecdc4;
    transform: translateY(-2px);
}

.profile-avatar {
    font-size: 3em;
    margin-bottom: 10px;
}

.profile-name {
    font-size: 1.2em;
    font-weight: bold;
    margin-bottom: 5px;
}

.profile-stats {
    font-size: 0.9em;
    color: #666;
}

/* Main Menu Styles */
.welcome-header {
    margin-bottom: 30px;
}

.player-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin: 20px 0;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 15px;
}

#player-avatar {
    font-size: 3em;
}

.player-stats {
    text-align: left;
    font-size: 1.1em;
    font-weight: bold;
}

.menu-buttons {
    display: grid;
    gap: 15px;
    max-width: 400px;
    margin: 0 auto;
}

/* Leaderboard Styles */
#leaderboard-list {
    max-width: 500px;
    margin: 0 auto;
}

.leaderboard-item {
    background: #f8f9fa;
    border: 2px solid #ddd;
    border-radius: 10px;
    padding: 15px;
    margin: 10px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: transform 0.2s;
}

.leaderboard-item:hover {
    transform: translateY(-2px);
}

.leaderboard-item.current-player {
    border-color: #ff6b6b;
    background: #fff5f5;
}

.leaderboard-rank {
    font-size: 1.5em;
    font-weight: bold;
    color: #ffa500;
    min-width: 50px;
}

.leaderboard-player {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
}

.leaderboard-avatar {
    font-size: 2em;
}

.leaderboard-name {
    font-size: 1.2em;
    font-weight: bold;
}

.leaderboard-stats {
    text-align: right;
    font-size: 1.1em;
}

/* Navigation Button Styles */
.quit-btn {
    background: #dc3545;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9em;
    transition: background 0.2s;
}

.quit-btn:hover {
    background: #c82333;
}

.topic-nav-buttons, .shop-nav-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
}

@media (max-width: 600px) {
    .quiz-header {
        flex-direction: column;
        gap: 10px;
    }
    
    .results-buttons {
        flex-direction: column;
        align-items: center;
    }
    
    .grade-buttons {
        grid-template-columns: 1fr;
    }
    
    #topics-container {
        grid-template-columns: 1fr;
    }
    
    .player-info {
        flex-direction: column;
        gap: 10px;
    }
    
    .avatar-options {
        justify-content: center;
    }
    
    .topic-nav-buttons, .shop-nav-buttons {
        flex-direction: column;
        align-items: center;
    }
}

/* 🌟 MAGICAL DIFFICULTY SETTINGS & BACKGROUND THEMES 🌟 */

/* Difficulty Settings Screen */
.difficulty-description, .theme-description {
    text-align: center;
    font-size: 1.1em;
    color: #666;
    margin-bottom: 25px;
    line-height: 1.4;
}

.difficulty-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
}

.difficulty-card {
    background: linear-gradient(145deg, #ffffff 0%, #f8f9fa 100%);
    border: 3px solid #e3f2fd;
    border-radius: 20px;
    padding: 25px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    position: relative;
    overflow: hidden;
}

.difficulty-card::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(255,255,255,0.3), transparent);
    transform: rotate(45deg);
    transition: all 0.6s ease;
    opacity: 0;
}

.difficulty-card:hover::before {
    opacity: 1;
    animation: shimmer 1.5s ease-in-out infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%) rotate(45deg); }
    100% { transform: translateX(100%) rotate(45deg); }
}

.difficulty-card:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 15px 30px rgba(0,0,0,0.15);
    border-color: #2196f3;
}

.difficulty-card.selected {
    background: linear-gradient(145deg, #e3f2fd 0%, #bbdefb 100%);
    border-color: #2196f3;
    transform: scale(1.05);
    box-shadow: 0 10px 25px rgba(33, 150, 243, 0.3);
}

.difficulty-icon {
    font-size: 3em;
    margin-bottom: 15px;
    animation: float 3s ease-in-out infinite;
}

.difficulty-card[data-difficulty="easy"] .difficulty-icon {
    animation-delay: 0s;
}

.difficulty-card[data-difficulty="normal"] .difficulty-icon {
    animation-delay: 0.5s;
}

.difficulty-card[data-difficulty="hard"] .difficulty-icon {
    animation-delay: 1s;
}

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

.difficulty-card h3 {
    color: #1976d2;
    margin-bottom: 10px;
    font-size: 1.3em;
}

.difficulty-card p {
    color: #666;
    margin-bottom: 15px;
    line-height: 1.4;
}

.difficulty-examples {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.difficulty-examples span {
    background: rgba(33, 150, 243, 0.1);
    padding: 8px 12px;
    border-radius: 12px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    color: #1976d2;
    border: 1px solid rgba(33, 150, 243, 0.2);
}

.current-difficulty {
    text-align: center;
    background: linear-gradient(145deg, #f8f9fa 0%, #e3f2fd 100%);
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 25px;
    border: 2px solid #bbdefb;
}

.current-difficulty h3 {
    color: #1976d2;
    margin-bottom: 15px;
}

.adaptive-setting {
    display: flex;
    justify-content: center;
    align-items: center;
}

.adaptive-setting label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 1.1em;
    color: #555;
    gap: 10px;
}

.adaptive-setting input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: #2196f3;
}

/* Background Themes Section */
.background-themes-section {
    margin-top: 40px;
    padding-top: 30px;
    border-top: 3px solid #e3f2fd;
}

.theme-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
    margin-bottom: 25px;
    max-width: 1000px;
    margin-left: auto;
    margin-right: auto;
}

.theme-card {
    background: #ffffff;
    border: 3px solid #e3f2fd;
    border-radius: 15px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 3px 10px rgba(0,0,0,0.1);
}

.theme-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.15);
    border-color: #2196f3;
}

.theme-card.selected {
    border-color: #2196f3;
    transform: scale(1.05);
    box-shadow: 0 8px 20px rgba(33, 150, 243, 0.3);
}

.theme-preview {
    width: 100%;
    height: 60px;
    border-radius: 10px;
    margin-bottom: 10px;
    background-size: cover;
    background-position: center;
    position: relative;
    overflow: hidden;
}

.theme-card h4 {
    color: #1976d2;
    margin-bottom: 5px;
    font-size: 1em;
}

.theme-card p {
    color: #666;
    font-size: 0.9em;
    line-height: 1.3;
}

/* Theme Preview Styles */
.stars-theme {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    position: relative;
}

.stars-theme::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(2px 2px at 20px 30px, #fff, transparent),
        radial-gradient(2px 2px at 40px 70px, rgba(255,255,255,0.8), transparent),
        radial-gradient(1px 1px at 90px 40px, #fff, transparent),
        radial-gradient(1px 1px at 130px 80px, rgba(255,255,255,0.6), transparent);
    background-repeat: repeat;
    background-size: 150px 100px;
    animation: twinkle 3s ease-in-out infinite alternate;
}

@keyframes twinkle {
    0% { opacity: 0.5; }
    100% { opacity: 1; }
}

.rainbow-theme {
    background: linear-gradient(45deg, 
        #ff6b6b 0%, #4ecdc4 16.66%, #45b7d1 33.33%, 
        #96ceb4 50%, #ffeaa7 66.66%, #dda0dd 83.33%, #ff6b6b 100%);
    animation: rainbow-shift 4s ease-in-out infinite;
}

@keyframes rainbow-shift {
    0%, 100% { filter: hue-rotate(0deg) brightness(1); }
    50% { filter: hue-rotate(30deg) brightness(1.1); }
}

.forest-theme {
    background: linear-gradient(135deg, #2d5016 0%, #3e7b27 30%, #4d7c0f 60%, #65a30d 100%);
    position: relative;
}

.forest-theme::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(ellipse at bottom, rgba(125,211,252,0.3) 0%, transparent 50%);
    animation: forest-breeze 5s ease-in-out infinite;
}

@keyframes forest-breeze {
    0%, 100% { transform: translateX(0px); opacity: 0.3; }
    50% { transform: translateX(5px); opacity: 0.5; }
}

.ocean-theme {
    background: linear-gradient(135deg, #0369a1 0%, #0284c7 25%, #0ea5e9 50%, #38bdf8 75%, #7dd3fc 100%);
    position: relative;
}

.ocean-theme::after {
    content: '';
    position: absolute;
    width: 200%;
    height: 100%;
    background: linear-gradient(90deg, 
        transparent 0%, rgba(255,255,255,0.2) 25%, 
        rgba(255,255,255,0.4) 50%, rgba(255,255,255,0.2) 75%, transparent 100%);
    animation: ocean-wave 3s linear infinite;
}

@keyframes ocean-wave {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(0%); }
}

.sunset-theme {
    background: linear-gradient(135deg, #fed7aa 0%, #fdba74 25%, #fb923c 50%, #f97316 75%, #ea580c 100%);
    position: relative;
}

.sunset-theme::after {
    content: '';
    position: absolute;
    width: 40px;
    height: 40px;
    background: radial-gradient(circle, #fbbf24 0%, #f59e0b 70%, transparent 70%);
    border-radius: 50%;
    top: 10px;
    right: 15px;
    animation: sunset-glow 4s ease-in-out infinite;
}

@keyframes sunset-glow {
    0%, 100% { box-shadow: 0 0 10px rgba(251, 191, 36, 0.5); }
    50% { box-shadow: 0 0 20px rgba(251, 191, 36, 0.8); }
}

.galaxy-theme {
    background: linear-gradient(135deg, #1e1b4b 0%, #581c87 25%, #7c3aed 50%, #a855f7 75%, #c084fc 100%);
    position: relative;
}

.galaxy-theme::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(1px 1px at 25px 25px, rgba(255,255,255,0.8), transparent),
        radial-gradient(1px 1px at 75px 15px, rgba(196, 181, 253, 0.6), transparent),
        radial-gradient(2px 2px at 125px 45px, rgba(167, 139, 250, 0.4), transparent);
    background-repeat: repeat;
    background-size: 150px 80px;
    animation: galaxy-spiral 6s linear infinite;
}

@keyframes galaxy-spiral {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.current-theme {
    text-align: center;
    background: linear-gradient(145deg, #f0f9ff 0%, #e0f2fe 100%);
    padding: 15px;
    border-radius: 12px;
    border: 2px solid #bae6fd;
    color: #0c4a6e;
    font-weight: bold;
    font-size: 1.1em;
}

/* Dynamic Background Themes for Main App */
body.theme-stars {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    color: #ffffff;
}

body.theme-stars::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(2px 2px at 20px 30px, #fff, transparent),
        radial-gradient(2px 2px at 40px 70px, rgba(255,255,255,0.8), transparent),
        radial-gradient(1px 1px at 90px 40px, #fff, transparent),
        radial-gradient(1px 1px at 130px 80px, rgba(255,255,255,0.6), transparent),
        radial-gradient(2px 2px at 200px 100px, #fff, transparent),
        radial-gradient(1px 1px at 250px 50px, rgba(255,255,255,0.8), transparent);
    background-repeat: repeat;
    background-size: 300px 200px;
    animation: twinkle 3s ease-in-out infinite alternate;
    pointer-events: none;
    z-index: -1;
}

body.theme-rainbow {
    background: linear-gradient(45deg, 
        #ff6b6b 0%, #4ecdc4 16.66%, #45b7d1 33.33%, 
        #96ceb4 50%, #ffeaa7 66.66%, #dda0dd 83.33%, #ff6b6b 100%);
    background-size: 400% 400%;
    animation: rainbow-background 8s ease infinite;
    color: #333;
}

@keyframes rainbow-background {
    0%, 100% { background-position: 0% 50%; }
    25% { background-position: 100% 50%; }
    50% { background-position: 100% 100%; }
    75% { background-position: 0% 100%; }
}

body.theme-forest {
    background: linear-gradient(135deg, #2d5016 0%, #3e7b27 30%, #4d7c0f 60%, #65a30d 100%);
    color: #ffffff;
}

body.theme-forest::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(ellipse at 20% 80%, rgba(125,211,252,0.3) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(125,211,252,0.2) 0%, transparent 50%);
    animation: forest-atmosphere 8s ease-in-out infinite;
    pointer-events: none;
    z-index: -1;
}

@keyframes forest-atmosphere {
    0%, 100% { opacity: 0.3; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.1); }
}

body.theme-ocean {
    background: linear-gradient(135deg, #0369a1 0%, #0284c7 25%, #0ea5e9 50%, #38bdf8 75%, #7dd3fc 100%);
    color: #ffffff;
}

body.theme-ocean::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 200%;
    height: 100%;
    background: linear-gradient(90deg, 
        transparent 0%, rgba(255,255,255,0.1) 25%, 
        rgba(255,255,255,0.2) 50%, rgba(255,255,255,0.1) 75%, transparent 100%);
    animation: ocean-flow 6s linear infinite;
    pointer-events: none;
    z-index: -1;
}

@keyframes ocean-flow {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(0%); }
}

body.theme-sunset {
    background: linear-gradient(135deg, #fed7aa 0%, #fdba74 25%, #fb923c 50%, #f97316 75%, #ea580c 100%);
    color: #333;
}

body.theme-sunset::before {
    content: '';
    position: fixed;
    top: 20px;
    right: 20px;
    width: 80px;
    height: 80px;
    background: radial-gradient(circle, #fbbf24 0%, #f59e0b 70%, transparent 70%);
    border-radius: 50%;
    animation: sunset-sun 6s ease-in-out infinite;
    pointer-events: none;
    z-index: -1;
}

@keyframes sunset-sun {
    0%, 100% { 
        box-shadow: 0 0 20px rgba(251, 191, 36, 0.5);
        transform: scale(1);
    }
    50% { 
        box-shadow: 0 0 40px rgba(251, 191, 36, 0.8);
        transform: scale(1.1);
    }
}

body.theme-galaxy {
    background: linear-gradient(135deg, #1e1b4b 0%, #581c87 25%, #7c3aed 50%, #a855f7 75%, #c084fc 100%);
    color: #ffffff;
}

body.theme-galaxy::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(2px 2px at 50px 50px, rgba(255,255,255,0.8), transparent),
        radial-gradient(1px 1px at 150px 75px, rgba(196, 181, 253, 0.6), transparent),
        radial-gradient(2px 2px at 250px 125px, rgba(167, 139, 250, 0.4), transparent),
        radial-gradient(3px 3px at 100px 200px, rgba(139, 92, 246, 0.3), transparent);
    background-repeat: repeat;
    background-size: 300px 250px;
    animation: galaxy-drift 12s linear infinite;
    pointer-events: none;
    z-index: -1;
}

@keyframes galaxy-drift {
    0% { transform: rotate(0deg) translateX(-20px); }
    100% { transform: rotate(360deg) translateX(-20px); }
}

/* Theme-specific text adjustments */
body.theme-stars .screen,
body.theme-forest .screen,
body.theme-ocean .screen,
body.theme-galaxy .screen {
    background: rgba(255, 255, 255, 0.95);
    color: #333;
    border-radius: 20px;
    margin: 20px;
    padding: 20px;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

body.theme-rainbow .screen,
body.theme-sunset .screen {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 20px;
    margin: 20px;
    padding: 20px;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

/* Mobile Responsiveness for New Features */
@media (max-width: 768px) {
    .difficulty-options {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .difficulty-card {
        padding: 20px;
    }
    
    .theme-options {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .theme-card {
        padding: 12px;
    }
    
    .theme-preview {
        height: 50px;
    }
    
    /* 📱 Mobile-Optimized Breadcrumbs */
    .breadcrumb-nav {
        flex-wrap: wrap;
        padding: 6px 12px;
        font-size: 0.8em;
        min-height: 35px;
        margin-bottom: 10px;
    }
    
    .breadcrumb-item {
        padding: 3px 6px;
        font-size: 0.9em;
    }
    
    .breadcrumb-separator {
        font-size: 1em;
    }
    
    /* Reduce screen padding on mobile */
    .screen {
        padding: 15px 20px;
    }
    
    /* Make adventure name input more mobile-friendly */
    #new-profile-name {
        width: 300px;
        font-size: 1.1em;
    }
    
    .adaptive-setting label {
        font-size: 1em;
        text-align: center;
    }
}

/* 🌟 MAGICAL MESSAGE ANIMATIONS 🌟 */
@keyframes messageSlideIn {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8) rotateY(-90deg);
    }
    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1) rotateY(0deg);
    }
}

@keyframes messageSlideOut {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1) rotateY(0deg);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8) rotateY(90deg);
    }
}

/* 🔧 CRITICAL VIEWPORT POSITIONING FIXES */
/* Prevent content from appearing below viewport - FOR ARIA'S FEEDBACK */

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

html, body {
    margin: 0 !important;
    padding-top: 20px !important;
    padding-bottom: 0 !important;
}

/* Force main content container to start at viewport top */
body > * {
    margin-top: 0 !important;
}

/* Override any vertical centering that pushes content down */
* {
    transform: none !important;
}

.screen.active {
    /* Ensure active screens are always at viewport top */
    position: relative !important;
    top: 0 !important;
    margin-top: 0 !important;
    
    /* Override any grid system positioning that might push content down */
    align-self: flex-start !important;
    justify-self: center !important;
}

/* Emergency override for any centering layouts */
body, html {
    display: block !important;
    align-items: flex-start !important;
    justify-content: center !important;
}
