:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #0f1624;
    --bg-card: rgba(255, 255, 255, 0.05);
    --bg-card-hover: rgba(255, 255, 255, 0.08);
    --accent-primary: #7b61ff;
    --accent-secondary: #00d4ff;
    --accent-success: #00ff88;
    --accent-danger: #ff3366;
    --text-primary: #ffffff;
    --text-secondary: #b4bcd0;
    --text-muted: #6b7280;
    --border-color: rgba(255, 255, 255, 0.1);
    --border-hover: rgba(123, 97, 255, 0.4);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(123, 97, 255, 0.3);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: 
        radial-gradient(ellipse at top left, rgba(123, 97, 255, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at bottom right, rgba(0, 212, 255, 0.15) 0%, transparent 50%),
        linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

header {
    background: rgba(15, 22, 36, 0.8);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    padding: 24px 0;
    text-align: center;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.container {
    max-width: 1400px;
    margin: 32px auto;
    padding: 0 24px;
}

/* --- Navigation --- */
.main-nav {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin: 24px auto 0;
    max-width: 1400px;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-color);
}

.nav-button {
    background: transparent;
    border: none;
    padding: 14px 28px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-secondary);
    border-bottom: 3px solid transparent;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    letter-spacing: 0.01em;
    display: inline-block;
    text-decoration: none;
}

.nav-button::before {
    content: '';
    position: absolute;
    bottom: -3px;
    left: 0;
    width: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-button:hover {
    color: var(--text-primary);
    transform: translateY(-2px);
}

.nav-button.active {
    color: var(--text-primary);
}

.nav-button.active::before {
    width: 100%;
}

/* --- View Sections --- */
.view-section {
    display: flex;
    margin-top: 32px;
    gap: 24px;
}

.view-section.hidden {
    display: none;
}

/* --- Challenge List Sidebar --- */
.challenge-list {
    flex: 0 0 280px;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    padding: 24px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    max-height: 85vh;
    overflow-y: auto;
    position: sticky;
    top: 120px;
}

.challenge-list::-webkit-scrollbar {
    width: 6px;
}

.challenge-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.challenge-list::-webkit-scrollbar-thumb {
    background: var(--accent-primary);
    border-radius: 10px;
}

.challenge-list h2 {
    color: var(--text-primary);
    margin-bottom: 20px;
    font-size: 1.25rem;
    font-weight: 700;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--border-color);
}

#challenge-buttons {
    list-style: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#challenge-buttons button {
    width: 100%;
    padding: 12px 16px;
    background: rgba(123, 97, 255, 0.1);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 500;
    text-align: left;
    font-size: 0.9rem;
}

#challenge-buttons button:hover {
    background: rgba(123, 97, 255, 0.2);
    border-color: var(--accent-primary);
    color: var(--text-primary);
    transform: translateX(4px);
    box-shadow: var(--shadow-sm);
}

#challenge-buttons button.active {
    background: linear-gradient(135deg, rgba(123, 97, 255, 0.3), rgba(0, 212, 255, 0.2));
    border-color: var(--accent-primary);
    color: var(--text-primary);
    box-shadow: var(--shadow-glow);
}

/* --- Challenge Area --- */
.challenge-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.challenge-description-box {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    padding: 32px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    transition: all 0.3s ease;
}

.challenge-description-box:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
}

#challenge-title {
    color: var(--text-primary);
    margin-bottom: 16px;
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#challenge-description {
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 1.05rem;
    line-height: 1.7;
    padding-left: 16px;
    border-left: 3px solid var(--accent-primary);
}

.answer-key-box {
    padding-top: 24px;
    border-top: 1px dashed var(--border-color);
}

#show-answer-btn {
    background: linear-gradient(135deg, var(--accent-danger), #ff5588);
    color: var(--text-primary);
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
}

#show-answer-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

#answer-key {
    background: rgba(255, 193, 7, 0.15);
    backdrop-filter: blur(10px);
    color: #ffd700;
    padding: 20px;
    margin-top: 16px;
    border-radius: 12px;
    white-space: pre-wrap;
    overflow-x: auto;
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 14px;
    border: 1px solid rgba(255, 193, 7, 0.3);
    line-height: 1.6;
}

.hidden {
    display: none;
}

/* --- Code Editor & Console --- */
.code-editor-console {
    display: flex;
    gap: 24px;
    flex-grow: 1;
}

.code-editor-box, .console-output-box {
    flex: 1;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    padding: 24px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}

.code-editor-box:hover, .console-output-box:hover {
    border-color: var(--border-hover);
}

.code-editor-box h3, .console-output-box h3 {
    color: var(--text-primary);
    margin-bottom: 16px;
    font-size: 1.1rem;
    font-weight: 600;
}

#code-editor {
    flex-grow: 1;
    background: #1a1f2e;
    color: #e0e6ed;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 15px;
    resize: none;
    min-height: 300px;
    transition: all 0.3s ease;
    line-height: 1.6;
}

#code-editor:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(123, 97, 255, 0.2);
}

.editor-actions {
    margin-top: 16px;
    display: flex;
    gap: 12px;
}

#run-code-btn {
    background: linear-gradient(135deg, var(--accent-success), #00cc77);
    color: var(--text-primary);
    flex: 1;
}

#reset-code-btn {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

#run-code-btn, #reset-code-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
}

#run-code-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

#reset-code-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-primary);
    transform: translateY(-2px);
}

.console-output {
    background: #0f1624;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 14px;
    white-space: pre-wrap;
    overflow-y: auto;
    flex-grow: 1;
    color: var(--accent-success);
    line-height: 1.6;
}

.console-output::-webkit-scrollbar {
    width: 6px;
}

.console-output::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.console-output::-webkit-scrollbar-thumb {
    background: var(--accent-success);
    border-radius: 10px;
}

/* --- Explanation Content --- */
.explanation-content {
    flex-grow: 1;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    padding: 40px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
}

.explanation-content h2 {
    color: var(--text-primary);
    margin-bottom: 24px;
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.explanation-content h3 {
    color: var(--text-primary);
    margin-top: 32px;
    margin-bottom: 16px;
    font-size: 1.4rem;
    font-weight: 600;
    border-left: 4px solid var(--accent-primary);
    padding-left: 16px;
}

.explanation-content h4 {
    color: var(--text-secondary);
    margin-top: 20px;
    margin-bottom: 12px;
    font-size: 1.1rem;
    font-weight: 600;
}

.explanation-content p {
    color: var(--text-secondary);
    margin-bottom: 16px;
    line-height: 1.7;
}

.explanation-content ul {
    margin-left: 24px;
    margin-bottom: 20px;
    color: var(--text-secondary);
    line-height: 1.8;
}

.explanation-content li {
    margin-bottom: 8px;
}

.explanation-content code {
    background: rgba(123, 97, 255, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
    font-size: 0.9em;
    color: var(--accent-secondary);
}

.explanation-code {
    background: #1a1f2e;
    color: #e0e6ed;
    padding: 20px;
    border-radius: 12px;
    overflow-x: auto;
    font-family: 'Fira Code', 'Courier New', monospace;
    margin: 16px 0 24px;
    border: 1px solid var(--border-color);
    line-height: 1.6;
}

.explanation-content hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 32px 0;
}

/* --- Responsive --- */
@media (max-width: 1024px) {
    .view-section {
        flex-direction: column;
    }
    
    .challenge-list {
        flex: 1;
        position: static;
        max-height: none;
    }
    
    .code-editor-console {
        flex-direction: column;
    }
}

@media (max-width: 768px) {
    header h1 {
        font-size: 1.5rem;
    }
    
    .container {
        padding: 0 16px;
    }
    
    .challenge-description-box,
    .explanation-content {
        padding: 24px;
    }
}
