/* CSS Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-dark: #0f0f0f;
    --bg-card: #1a1a1a;
    --bg-code: #252525;
    --bg-hover: #2a2a2a;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-muted: #666666;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.2);
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --border: #2a2a2a;
    --border-hover: #3a3a3a;
    --grid-line: rgba(99, 102, 241, 0.3);
    --grid-item: #6366f1;
    --radius: 12px;
    --radius-sm: 8px;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --sidebar-width: 280px;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.6;
    display: flex;
    min-height: 100vh;
}

/* Sidebar Navigation */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    padding: 24px;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.logo-icon {
    font-size: 1.5rem;
    color: var(--accent);
}

.theme-toggle {
    position: absolute;
    top: 24px;
    right: 24px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s ease;
}

.theme-toggle:hover {
    background: var(--bg-hover);
    transform: rotate(15deg);
}

/* Light Theme */
[data-theme="light"] {
    --bg-dark: #f5f5f5;
    --bg-card: #ffffff;
    --bg-code: #f0f0f0;
    --bg-hover: #e5e5e5;
    --text-primary: #1a1a1a;
    --text-secondary: #555555;
    --text-muted: #888888;
    --border: #e0e0e0;
    --border-hover: #d0d0d0;
    --grid-line: rgba(99, 102, 241, 0.2);
}

.nav-section {
    margin-bottom: 24px;
}

.nav-section h3 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.nav-link {
    display: block;
    padding: 8px 12px;
    margin: 2px 0;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.nav-link.active {
    color: var(--accent);
    background: var(--accent-glow);
    font-weight: 500;
}

.nav-link.completed::after {
    content: '✓';
    float: right;
    color: var(--success);
}

/* Progress Section */
.progress-section {
    margin-top: 24px;
    padding: 16px;
    background: var(--bg-code);
    border-radius: var(--radius-sm);
}

.progress-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    margin-bottom: 8px;
}

.progress-percent {
    color: var(--accent);
    font-weight: 600;
}

.progress-bar {
    height: 6px;
    background: var(--bg-hover);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--success));
    border-radius: 3px;
    width: 0%;
    transition: width 0.5s ease;
}

.progress-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 8px;
    text-align: center;
}

.cert-btn {
    width: 100%;
    margin-top: 12px;
    padding: 8px;
    background: transparent;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.cert-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.cert-btn.unlocked {
    background: linear-gradient(135deg, rgba(234, 179, 8, 0.2), rgba(99, 102, 241, 0.2));
    border: 1px solid #eab308;
    color: #eab308;
    animation: glow 2s ease-in-out infinite;
}

@keyframes glow {
    0%, 100% { box-shadow: 0 0 5px rgba(234, 179, 8, 0.3); }
    50% { box-shadow: 0 0 15px rgba(234, 179, 8, 0.5); }
}

.nav-footer {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-muted);
}

.cheatsheet-link {
    display: block;
    padding: 10px 12px;
    background: var(--accent-glow);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    color: var(--accent);
    text-decoration: none;
    text-align: center;
    margin-bottom: 16px;
    transition: all 0.2s ease;
}

.cheatsheet-link:hover {
    background: var(--accent);
    color: white;
}

.nav-footer .credit {
    color: var(--accent);
    margin-top: 4px;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-width: 900px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 32px;
    position: relative;
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg-hover);
    color: var(--text-primary);
    font-size: 24px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--error);
}

.modal-content h2 {
    font-size: 1.75rem;
    margin-bottom: 24px;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.cheatsheet-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
}

.cheatsheet-section h3 {
    font-size: 1rem;
    color: var(--accent);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.cheatsheet-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px;
    background: var(--bg-code);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}

.cheatsheet-item code {
    font-family: var(--font-mono);
    color: var(--accent);
    font-size: 0.85rem;
}

.cheatsheet-item span {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Celebration */
.celebration {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-card);
    border: 2px solid var(--success);
    border-radius: var(--radius);
    padding: 40px 60px;
    text-align: center;
    z-index: 3000;
    animation: celebrateIn 0.5s ease;
}

@keyframes celebrateIn {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.celebration h2 {
    font-size: 2rem;
    margin-bottom: 12px;
}

.celebration p {
    color: var(--text-secondary);
}

.celebration .emoji {
    font-size: 4rem;
    margin-bottom: 16px;
}

/* Certificate */
.certificate {
    text-align: center;
    background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-code) 100%);
    border: 3px solid var(--accent);
    max-width: 600px;
}

.cert-header {
    font-size: 4rem;
    margin-bottom: 16px;
}

.certificate h2 {
    font-size: 2rem;
    margin-bottom: 24px;
}

.certificate h3 {
    font-size: 1.75rem;
    color: var(--accent);
    margin: 16px 0;
}

.cert-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 8px 0;
}

.cert-name {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 12px 0;
}

.cert-details {
    color: var(--text-secondary);
    margin: 16px 0;
}

.cert-date {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 24px;
}

.cert-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 32px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Main Content */
.content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 48px;
    max-width: 1200px;
}

/* Lesson Structure */
.lesson {
    animation: fadeIn 0.3s ease;
}

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

.lesson-header {
    margin-bottom: 40px;
}

.lesson-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 12px;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.lesson-header .subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
    max-width: 600px;
}

.lesson-content {
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.lesson-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
}

.lesson-section h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.lesson-section h2 .icon {
    font-size: 1.25rem;
}

.lesson-section p {
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.lesson-section ul, .lesson-section ol {
    color: var(--text-secondary);
    margin-left: 24px;
    margin-bottom: 16px;
}

.lesson-section li {
    margin-bottom: 8px;
}

.lesson-section code {
    font-family: var(--font-mono);
    background: var(--bg-code);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.9em;
    color: var(--accent);
}

/* Interactive Playground */
.playground {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.playground-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--bg-code);
    border-bottom: 1px solid var(--border);
}

.playground-title {
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.playground-title .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.playground-actions {
    display: flex;
    gap: 8px;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.playground-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: 400px;
}

.code-panel {
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.code-tabs {
    display: flex;
    background: var(--bg-code);
    border-bottom: 1px solid var(--border);
}

.code-tab {
    padding: 12px 20px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
}

.code-tab:hover {
    color: var(--text-primary);
}

.code-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.code-editor {
    flex: 1;
    padding: 20px;
    background: var(--bg-dark);
}

.code-editor textarea {
    width: 100%;
    height: 100%;
    min-height: 300px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    line-height: 1.6;
    resize: none;
    outline: none;
}

.preview-panel {
    padding: 24px;
    display: flex;
    flex-direction: column;
}

.preview-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.preview-container {
    flex: 1;
    background: var(--bg-dark);
    border-radius: var(--radius-sm);
    padding: 20px;
    overflow: auto;
}

/* Grid Preview Styling */
.grid-preview {
    display: grid;
    gap: 8px;
    min-height: 200px;
}

.grid-preview.show-lines {
    background-image: 
        linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
        linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
    background-size: 50px 50px;
}

.grid-item {
    background: var(--grid-item);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: white;
    min-height: 60px;
    transition: all 0.3s ease;
}

.grid-item:nth-child(2) { background: #8b5cf6; }
.grid-item:nth-child(3) { background: #ec4899; }
.grid-item:nth-child(4) { background: #f59e0b; }
.grid-item:nth-child(5) { background: #22c55e; }
.grid-item:nth-child(6) { background: #06b6d4; }
.grid-item:nth-child(7) { background: #f43f5e; }
.grid-item:nth-child(8) { background: #84cc16; }
.grid-item:nth-child(9) { background: #a855f7; }

/* Property Controls */
.controls {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-top: 24px;
}

.controls-header {
    font-weight: 600;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-group {
    margin-bottom: 20px;
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.control-label span {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.control-value {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    color: var(--accent);
    background: var(--bg-code);
    padding: 4px 8px;
    border-radius: 4px;
}

.control-slider {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-hover);
    border-radius: 3px;
    outline: none;
}

.control-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.control-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.control-select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s ease;
}

.control-select:hover, .control-select:focus {
    border-color: var(--accent);
}

.control-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.control-btn {
    padding: 8px 14px;
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.control-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.control-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Tip Cards */
.tip {
    background: var(--accent-glow);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 20px;
    margin: 16px 0;
}

.tip-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--accent);
}

.tip p {
    color: var(--text-secondary);
    margin: 0;
}

/* Challenge Cards */
.challenge {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.1) 0%, rgba(99, 102, 241, 0.1) 100%);
    border: 1px solid var(--success);
    border-radius: var(--radius);
    padding: 24px;
    margin-top: 32px;
}

.challenge-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.challenge-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.challenge-badge {
    background: var(--success);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.challenge-task {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.challenge-hints {
    background: var(--bg-code);
    border-radius: var(--radius-sm);
    padding: 16px;
}

.challenge-hints summary {
    cursor: pointer;
    font-weight: 500;
    color: var(--text-secondary);
}

.challenge-hints ul {
    margin-top: 12px;
    margin-left: 20px;
    color: var(--text-muted);
}

/* Navigation Buttons */
.lesson-nav {
    display: flex;
    justify-content: space-between;
    margin-top: 48px;
    padding-top: 32px;
    border-top: 1px solid var(--border);
}

.lesson-nav-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
}

.lesson-nav-btn:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
}

.lesson-nav-btn .direction {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.lesson-nav-btn .title {
    font-weight: 500;
}

.lesson-nav-btn.disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* Responsive */
@media (max-width: 1024px) {
    .playground-body {
        grid-template-columns: 1fr;
    }
    
    .code-panel {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
}

/* Mobile Menu Button */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 1001;
    width: 44px;
    height: 44px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mobile-menu-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.sidebar-overlay.active {
    display: block;
}

@media (max-width: 768px) {
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .sidebar {
        transform: translateX(-100%);
        z-index: 1000;
        transition: transform 0.3s ease;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .content {
        margin-left: 0;
        padding: 24px;
        padding-top: 80px;
    }
    
    .lesson-header h1 {
        font-size: 1.75rem;
    }
    
    .playground-body {
        grid-template-columns: 1fr;
    }
    
    .code-panel {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    
    .code-editor textarea {
        min-height: 200px;
    }
}

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

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============================================
   GAME SYSTEM STYLES
   ============================================ */

/* XP Toast Notification */
.xp-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 1.1rem;
    z-index: 9999;
    animation: slideInRight 0.3s ease;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
}

.xp-toast .xp-reason {
    font-size: 0.85rem;
    opacity: 0.9;
    margin-left: 8px;
    font-weight: 400;
}

.xp-toast.fade-out {
    animation: slideOutRight 0.3s ease forwards;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* Achievement Toast */
.achievement-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    border: 2px solid #f59e0b;
    color: white;
    padding: 16px 24px;
    border-radius: var(--radius);
    z-index: 9999;
    animation: achievementPop 0.5s ease;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 8px 32px rgba(245, 158, 11, 0.3);
}

.achievement-emoji {
    font-size: 2.5rem;
    animation: bounce 0.5s ease infinite alternate;
}

.achievement-info {
    display: flex;
    flex-direction: column;
}

.achievement-info strong {
    color: #f59e0b;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.achievement-info span {
    font-size: 1.1rem;
    font-weight: 600;
}

.achievement-toast.fade-out {
    animation: slideOutUp 0.3s ease forwards;
}

@keyframes achievementPop {
    0% {
        transform: translateX(-50%) scale(0);
        opacity: 0;
    }
    50% {
        transform: translateX(-50%) scale(1.1);
    }
    100% {
        transform: translateX(-50%) scale(1);
        opacity: 1;
    }
}

@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-5px); }
}

@keyframes slideOutUp {
    to {
        transform: translateX(-50%) translateY(-100%);
        opacity: 0;
    }
}

/* Level Up Modal */
.level-up-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.3s ease;
}

.level-up-content {
    background: var(--bg-card);
    border: 2px solid var(--accent);
    border-radius: var(--radius);
    padding: 48px;
    text-align: center;
    animation: scaleIn 0.5s ease;
}

.level-up-content .level-emoji {
    font-size: 5rem;
    margin-bottom: 16px;
    animation: bounce 0.5s ease infinite alternate;
}

.level-up-content h2 {
    font-size: 2rem;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.level-up-content p {
    font-size: 1.2rem;
    margin-bottom: 24px;
}

.level-up-content button {
    background: var(--accent);
    color: white;
    border: none;
    padding: 12px 32px;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.level-up-content button:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

@keyframes scaleIn {
    from {
        transform: scale(0.5);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Player Stats Bar */
.player-stats {
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 16px;
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    gap: 20px;
    align-items: center;
}

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

.stat-xp-bar {
    background: var(--bg-dark);
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
}

.stat-xp-bar .fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #8b5cf6);
    border-radius: 4px;
    transition: width 0.5s ease;
}

.stat-xp {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.stat-streak {
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 600;
    color: #f59e0b;
}

/* Games Section */
.games-nav {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.games-nav h3 {
    color: var(--accent);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
}

.game-mode-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    margin-bottom: 4px;
}

.game-mode-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border);
}

.game-mode-btn.active {
    background: var(--accent-glow);
    color: var(--accent);
    border-color: var(--accent);
}

.game-mode-btn .emoji {
    font-size: 1.2rem;
}

/* Game Container */
.game-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 24px;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.game-header h1 {
    font-size: 1.75rem;
    display: flex;
    align-items: center;
    gap: 12px;
}

.game-timer {
    font-size: 2rem;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--accent);
    background: var(--bg-code);
    padding: 8px 20px;
    border-radius: var(--radius);
    border: 2px solid var(--border);
}

.game-timer.warning {
    color: #f59e0b;
    border-color: #f59e0b;
    animation: pulse 1s ease infinite;
}

.game-timer.danger {
    color: #ef4444;
    border-color: #ef4444;
    animation: pulse 0.5s ease infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Challenge Card */
.challenge-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
}

.challenge-card h2 {
    font-size: 1.25rem;
    margin-bottom: 8px;
}

.challenge-card .description {
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.challenge-card .difficulty {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    background: var(--bg-code);
    border-radius: 20px;
    font-size: 0.85rem;
}

.difficulty-1 { color: #22c55e; }
.difficulty-2 { color: #3b82f6; }
.difficulty-3 { color: #f59e0b; }
.difficulty-4 { color: #ef4444; }

/* Target Preview */
.target-preview {
    background: var(--bg-dark);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
}

.target-preview h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.target-preview .grid-preview {
    min-height: 200px;
}

/* Game Editor */
.game-editor {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.game-editor .code-panel,
.game-editor .preview-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.game-editor .panel-header {
    background: var(--bg-code);
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.game-editor .panel-header h4 {
    font-size: 0.9rem;
    font-weight: 600;
}

.game-editor textarea {
    width: 100%;
    min-height: 250px;
    padding: 16px;
    background: var(--bg-dark);
    border: none;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    resize: vertical;
}

.game-editor textarea:focus {
    outline: none;
}

.game-editor .preview-content {
    padding: 24px;
    min-height: 280px;
}

/* Score Display */
.score-display {
    background: linear-gradient(135deg, var(--bg-card), var(--bg-code));
    border: 2px solid var(--accent);
    border-radius: var(--radius);
    padding: 32px;
    text-align: center;
    margin: 24px 0;
}

.score-display .score-value {
    font-size: 4rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.score-display .score-breakdown {
    display: flex;
    justify-content: center;
    gap: 32px;
    margin-top: 16px;
}

.score-display .score-item {
    text-align: center;
}

.score-display .score-item .label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.score-display .score-item .value {
    font-size: 1.5rem;
    font-weight: 600;
}

/* Debug Detective Styles */
.debug-code-container {
    background: var(--bg-dark);
    border-radius: var(--radius);
    overflow: hidden;
}

.debug-code-container .bug-indicator {
    background: rgba(239, 68, 68, 0.1);
    border-left: 3px solid #ef4444;
}

.hint-btn {
    background: #f59e0b;
    color: #000;
    border: none;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.hint-btn:hover {
    background: #fbbf24;
}

.hint-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.hint-display {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid #f59e0b;
    border-radius: var(--radius);
    padding: 16px;
    margin-top: 16px;
    display: flex;
    align-items: start;
    gap: 12px;
}

.hint-display .hint-icon {
    font-size: 1.5rem;
}

/* Clone Challenge Styles */
.clone-reference {
    background: var(--bg-dark);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
}

.clone-reference h3 {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 12px;
    text-transform: uppercase;
}

.clone-reference .ref-preview {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 20px;
    min-height: 150px;
}

/* Daily Challenge Calendar */
.daily-calendar {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 8px;
    margin: 24px 0;
}

.calendar-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-code);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.calendar-day.completed {
    background: var(--accent);
    color: white;
}

.calendar-day.today {
    border: 2px solid var(--accent);
}

.calendar-day.future {
    opacity: 0.3;
}

/* Streak Display */
.streak-display {
    display: flex;
    align-items: center;
    gap: 16px;
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    color: white;
    padding: 16px 24px;
    border-radius: var(--radius);
    margin-bottom: 24px;
}

.streak-display .streak-number {
    font-size: 2.5rem;
    font-weight: 700;
}

.streak-display .streak-label {
    font-size: 1rem;
}

.streak-display .fire-emoji {
    font-size: 2rem;
}

/* Share Button */
.share-btn {
    background: linear-gradient(135deg, #1da1f2, #0d8ecf);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: transform 0.2s ease;
}

.share-btn:hover {
    transform: scale(1.05);
}

/* Challenge List */
.challenge-list {
    display: grid;
    gap: 16px;
}

.challenge-list-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.challenge-list-item:hover {
    border-color: var(--accent);
    transform: translateX(4px);
}

.challenge-list-item.completed {
    border-color: var(--success);
}

.challenge-list-item.completed::after {
    content: '✓';
    color: var(--success);
    font-size: 1.5rem;
    font-weight: 700;
}

.challenge-list-item .info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.challenge-list-item .name {
    font-weight: 600;
    font-size: 1.1rem;
}

.challenge-list-item .meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Game Action Buttons */
.game-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.game-btn {
    flex: 1;
    padding: 14px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.game-btn.primary {
    background: var(--accent);
    color: white;
}

.game-btn.primary:hover {
    background: var(--accent-hover);
}

.game-btn.secondary {
    background: var(--bg-code);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.game-btn.secondary:hover {
    background: var(--bg-hover);
}

.game-btn.success {
    background: var(--success);
    color: white;
}

.game-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Achievements Grid */
.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.achievement-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    transition: all 0.3s ease;
}

.achievement-card.locked {
    opacity: 0.5;
    filter: grayscale(100%);
}

.achievement-card.unlocked {
    border-color: #f59e0b;
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.2);
}

.achievement-card .achievement-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
}

.achievement-card .achievement-name {
    font-weight: 600;
    margin-bottom: 4px;
}

.achievement-card .achievement-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Leaderboard */
.leaderboard {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.leaderboard-header {
    background: var(--bg-code);
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.leaderboard-row {
    display: grid;
    grid-template-columns: 50px 1fr auto;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    align-items: center;
}

.leaderboard-row:last-child {
    border-bottom: none;
}

.leaderboard-row .rank {
    font-weight: 700;
    color: var(--text-secondary);
}

.leaderboard-row .rank.gold { color: #fbbf24; }
.leaderboard-row .rank.silver { color: #9ca3af; }
.leaderboard-row .rank.bronze { color: #d97706; }

.leaderboard-row .score {
    font-weight: 600;
    color: var(--accent);
}

/* Responsive Game Styles */
@media (max-width: 768px) {
    .game-editor {
        grid-template-columns: 1fr;
    }
    
    .player-stats {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }
    
    .stat-xp-bar {
        grid-column: span 2;
    }
    
    .game-header {
        flex-direction: column;
        gap: 16px;
        text-align: center;
    }
    
    .score-display .score-breakdown {
        flex-direction: column;
        gap: 16px;
    }
    
    .daily-calendar {
        gap: 4px;
    }
    
    .calendar-day {
        font-size: 0.75rem;
    }
}

/* ============== Header Controls ============== */
.header-controls {
    position: absolute;
    top: 24px;
    right: 24px;
    display: flex;
    gap: 8px;
}

.header-controls .theme-toggle,
.header-controls .sound-toggle {
    position: static;
}

.sound-toggle {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s ease;
}

.sound-toggle:hover {
    background: var(--bg-hover);
    transform: scale(1.05);
}

/* ============== Puzzle Mode Styles ============== */
.puzzle-game {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.puzzle-blanks {
    background: var(--bg-code);
    border-radius: var(--radius);
    padding: 20px;
}

.puzzle-line {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.puzzle-line:last-child {
    border-bottom: none;
}

.puzzle-line code {
    font-family: var(--font-mono);
    font-size: 1.1rem;
}

.puzzle-blank {
    display: inline-block;
    min-width: 150px;
    padding: 4px 12px;
    background: var(--bg-hover);
    border: 2px dashed var(--accent);
    border-radius: 4px;
    text-align: center;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.puzzle-blank.filled {
    background: var(--accent);
    border-style: solid;
    color: white;
}

.puzzle-blank:hover {
    border-color: var(--accent-hover);
}

.puzzle-options {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 20px;
    background: var(--bg-card);
    border-radius: var(--radius);
}

.puzzle-option {
    padding: 10px 20px;
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    cursor: grab;
    transition: all 0.2s ease;
}

.puzzle-option:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
}

.puzzle-option.selected {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.puzzle-option:active {
    cursor: grabbing;
}

.puzzle-result {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-card);
    padding: 40px;
    border-radius: var(--radius);
    text-align: center;
    z-index: 1000;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.puzzle-result.success {
    border: 2px solid var(--success);
}

.puzzle-result.error {
    border: 2px solid var(--error);
}

.puzzle-result h3 {
    font-size: 1.5rem;
    margin-bottom: 10px;
}

.puzzle-result p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

/* ============== Survival Mode Styles ============== */
.survival-intro,
.speedrun-intro {
    text-align: center;
    padding: 40px;
}

.survival-stats,
.speedrun-stats {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin: 30px 0;
}

.survival-stat,
.speedrun-stat {
    text-align: center;
}

.survival-stat .label,
.speedrun-stat .label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.survival-stat .value,
.speedrun-stat .value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--accent);
}

.survival-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--bg-card);
    border-radius: var(--radius);
    margin-bottom: 20px;
}

.survival-lives {
    font-size: 1.5rem;
    letter-spacing: 4px;
}

.survival-score {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--accent);
}

.survival-streak {
    font-size: 1rem;
}

.survival-challenge,
.speedrun-challenge {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 30px;
}

.bug-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-top: 20px;
}

.bug-option {
    padding: 15px 20px;
    text-align: left;
    font-family: var(--font-mono);
    font-size: 0.9rem;
}

.bug-option.wrong {
    background: var(--error) !important;
    color: white !important;
    animation: shake 0.3s ease;
}

.game-over {
    text-align: center;
    padding: 60px;
}

.game-over h1 {
    font-size: 3rem;
    margin-bottom: 30px;
}

.final-score {
    margin: 30px 0;
}

.final-score .score-value {
    font-size: 4rem;
    font-weight: bold;
    color: var(--accent);
}

.final-score .score-label {
    color: var(--text-secondary);
    margin-top: 8px;
}

.game-over-stats {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin: 30px 0;
}

.game-over-stats .stat {
    text-align: center;
}

.game-over-stats .stat .label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.game-over-stats .stat .value {
    display: block;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-primary);
    margin-top: 4px;
}

.game-over-buttons {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 30px;
}

/* ============== Speed Run Styles ============== */
.speedrun-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--bg-card);
    border-radius: var(--radius);
    margin-bottom: 20px;
}

.speedrun-timer {
    font-size: 2rem;
    font-weight: bold;
    font-family: var(--font-mono);
    color: var(--accent);
}

.speedrun-progress {
    font-size: 1.2rem;
    color: var(--text-secondary);
}

.speedrun-buttons {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.speedrun-finish {
    text-align: center;
    padding: 60px;
}

.speedrun-finish h1 {
    font-size: 3rem;
    margin-bottom: 30px;
}

.finish-time {
    margin: 30px 0;
}

.finish-time .time-value {
    font-size: 4rem;
    font-weight: bold;
    font-family: var(--font-mono);
    color: var(--accent);
}

.finish-time .time-label {
    color: var(--text-secondary);
    margin-top: 8px;
}

.finish-stats {
    display: flex;
    justify-content: center;
    gap: 60px;
    margin: 30px 0;
}

.finish-stats .stat {
    text-align: center;
}

.finish-stats .stat .value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--text-primary);
}

.finish-stats .stat .label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.new-record {
    font-size: 1.5rem;
    color: var(--success);
    margin: 20px 0;
    animation: pulse 0.5s ease infinite;
}

.finish-buttons {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 30px;
}

/* Large game button */
.game-btn.large {
    font-size: 1.2rem;
    padding: 16px 40px;
}

/* ============== Mobile Adjustments ============== */
@media (max-width: 768px) {
    .header-controls {
        top: 12px;
        right: 12px;
    }
    
    .header-controls .theme-toggle,
    .header-controls .sound-toggle {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }
    
    .puzzle-options {
        justify-content: center;
    }
    
    .bug-options {
        grid-template-columns: 1fr;
    }
    
    .survival-stats,
    .speedrun-stats,
    .game-over-stats,
    .finish-stats {
        flex-direction: column;
        gap: 20px;
    }
    
    .survival-header,
    .speedrun-header {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }
    
    .speedrun-timer {
        font-size: 1.5rem;
    }
    
    .final-score .score-value,
    .finish-time .time-value {
        font-size: 2.5rem;
    }
    
    .game-over-buttons,
    .finish-buttons {
        flex-direction: column;
    }
}
