/* Theme Variables */
:root {
    /* Light mode (default) */
    --bg-primary: #ffffff;
    --bg-secondary: #f6f8fa;
    --bg-tertiary: #f0f0f0;
    --bg-canvas: #f6f8fa;
    
    --text-primary: #24292f;
    --text-secondary: #57606a;
    --text-muted: #8b949e;
    
    --border-primary: #d0d7de;
    --border-secondary: #e1e4e8;
    
    --accent-primary: #0969da;
    --accent-secondary: #8250df;
    --accent-gradient: linear-gradient(135deg, #0969da 0%, #8250df 100%);
    
    --success: #1a7f37;
    --success-bg: #dafbe1;
    --warning: #9a6700;
    --warning-bg: #fff8c5;
    --info: #0550ae;
    --info-bg: #ddf4ff;
    
    --code-bg: #24292f;
    --code-text: #e6edf3;
    
    --shadow-sm: 0 1px 3px rgba(31, 35, 40, 0.08);
    --shadow-md: 0 3px 6px rgba(31, 35, 40, 0.12);
    --shadow-lg: 0 8px 24px rgba(31, 35, 40, 0.12);
}

/* Dark mode - GitHub style */
[data-theme="dark"] {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --bg-canvas: #010409;
    
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    
    --border-primary: #30363d;
    --border-secondary: #21262d;
    
    --accent-primary: #58a6ff;
    --accent-secondary: #a371f7;
    --accent-gradient: linear-gradient(135deg, #58a6ff 0%, #a371f7 100%);
    
    --success: #3fb950;
    --success-bg: #122117;
    --warning: #d29922;
    --warning-bg: #2d2300;
    --info: #58a6ff;
    --info-bg: #0c2d4a;
    
    --code-bg: #161b22;
    --code-text: #e6edf3;
    
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 3px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-canvas);
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 24px;
}

/* Header */
header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
    color: var(--text-primary);
    padding: 1.5rem 0;
}

header h1 {
    font-size: 1.75rem;
    margin-bottom: 0.375rem;
    font-weight: 600;
    color: var(--text-primary);
}

header h1 .accent {
    color: var(--accent-primary);
}

header p {
    color: var(--text-secondary);
    max-width: 800px;
    font-size: 0.9375rem;
}

/* Navigation */
nav {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-primary);
    position: sticky;
    top: 0;
    z-index: 100;
}

nav .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

nav ul {
    list-style: none;
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 0;
    overflow-x: auto;
}

nav a {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    transition: all 0.15s ease;
    white-space: nowrap;
    font-size: 0.875rem;
}

nav a:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

nav a.active {
    background: var(--accent-primary);
    color: white;
}

/* Theme Toggle */
.theme-toggle {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 6px;
    padding: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    transition: all 0.15s ease;
    color: var(--text-secondary);
}

.theme-toggle:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-primary);
}

.theme-toggle svg {
    width: 18px;
    height: 18px;
}

.theme-toggle .sun-icon {
    display: none;
}

.theme-toggle .moon-icon {
    display: block;
}

[data-theme="dark"] .theme-toggle .sun-icon {
    display: block;
}

[data-theme="dark"] .theme-toggle .moon-icon {
    display: none;
}

/* Main Layout */
main {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 1.5rem;
    padding: 1.5rem 0;
}

/* Sidebar */
aside {
    background: var(--bg-primary);
    padding: 1rem;
    border-radius: 6px;
    border: 1px solid var(--border-primary);
    height: fit-content;
    position: sticky;
    top: 70px;
}

aside h3 {
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-secondary);
}

aside ul {
    list-style: none;
}

aside li {
    margin: 0.25rem 0;
}

aside a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.15s ease;
    display: block;
    padding: 0.375rem 0.5rem;
    border-radius: 6px;
    font-size: 0.875rem;
}

aside a:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

aside a.active {
    background: var(--info-bg);
    color: var(--accent-primary);
    font-weight: 500;
}

/* Content Area */
.content {
    background: var(--bg-primary);
    padding: 2rem;
    border-radius: 6px;
    border: 1px solid var(--border-primary);
}

.content h2 {
    color: var(--text-primary);
    margin: 1.5rem 0 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-primary);
    font-weight: 600;
}

.content h2:first-child {
    margin-top: 0;
}

.content p {
    margin: 1rem 0;
    color: var(--text-secondary);
}

.content strong {
    color: var(--text-primary);
}

/* Code Examples */
.code-example {
    background: var(--code-bg);
    color: var(--code-text);
    padding: 1rem;
    border-radius: 6px;
    margin: 1rem 0;
    overflow-x: auto;
    border: 1px solid var(--border-primary);
}

.code-example code {
    font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
    white-space: pre;
    display: block;
    line-height: 1.5;
    font-size: 0.875rem;
}

/* Exercise Area */
.exercise {
    background: var(--bg-secondary);
    border-left: 3px solid var(--accent-primary);
    padding: 1.25rem;
    margin: 1.5rem 0;
    border-radius: 6px;
}

.exercise h3 {
    color: var(--accent-primary);
    margin-bottom: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
}

/* CodeMirror Override */
.CodeMirror {
    border: 1px solid var(--border-primary);
    border-radius: 6px;
    font-size: 14px;
    height: auto;
    margin: 1rem 0;
    font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
}

/* Controls */
.controls {
    display: flex;
    gap: 0.75rem;
    margin: 1rem 0;
}

button {
    padding: 0.625rem 1.25rem;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.15s ease;
    font-size: 0.875rem;
    font-family: inherit;
}

.run-btn {
    background: var(--success);
    color: white;
}

.run-btn:hover {
    background: #2ea043;
}

.clear-btn {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border-primary);
}

.clear-btn:hover {
    background: var(--bg-tertiary);
}

/* Output */
.output {
    background: var(--code-bg);
    color: var(--code-text);
    padding: 1rem;
    border-radius: 6px;
    font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
    white-space: pre-wrap;
    min-height: 100px;
    max-height: 300px;
    overflow-y: auto;
    margin-top: 1rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-primary);
}

.output:empty::before {
    content: 'Output will appear here...';
    color: var(--text-muted);
}

/* Instructions Panel */
.instructions {
    background: var(--info-bg);
    border: 1px solid var(--accent-primary);
    border-radius: 6px;
    padding: 1rem 1.25rem;
    margin: 1rem 0;
}

.instructions h4 {
    color: var(--info);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
}

.instructions ol, .instructions ul {
    margin: 0.5rem 0;
    padding-left: 1.25rem;
}

.instructions li {
    margin: 0.375rem 0;
    color: var(--info);
    font-size: 0.875rem;
}

.instructions code {
    background: rgba(88, 166, 255, 0.2);
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
}

/* Hints Panel */
.hints {
    background: var(--warning-bg);
    border: 1px solid var(--warning);
    border-radius: 6px;
    padding: 1rem 1.25rem;
    margin: 1rem 0;
}

.hints h4 {
    color: var(--warning);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
}

.hints ul {
    padding-left: 1.25rem;
    margin: 0.5rem 0;
}

.hints li {
    color: var(--warning);
    font-size: 0.875rem;
    margin: 0.375rem 0;
}

/* Solution Spoiler */
.solution-spoiler {
    margin: 1.5rem 0;
    border: 1px solid var(--border-primary);
    border-radius: 6px;
    overflow: hidden;
}

.solution-spoiler summary {
    background: var(--accent-gradient);
    color: white;
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    user-select: none;
    font-size: 0.875rem;
}

.solution-spoiler summary:hover {
    opacity: 0.9;
}

.solution-spoiler summary::marker {
    content: "";
}

.solution-spoiler summary::before {
    content: "▶";
    font-size: 0.75em;
    transition: transform 0.2s ease;
}

.solution-spoiler[open] summary::before {
    transform: rotate(90deg);
}

.solution-spoiler .solution-content {
    padding: 1rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-primary);
}

.solution-spoiler .solution-content .code-example {
    margin: 0.5rem 0;
}

.solution-spoiler .warning {
    background: var(--warning-bg);
    border-left: 3px solid var(--warning);
    padding: 0.5rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    color: var(--warning);
    border-radius: 0 4px 4px 0;
}

/* Footer */
footer {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    text-align: center;
    padding: 1.5rem;
    margin-top: 2rem;
    border-top: 1px solid var(--border-primary);
    font-size: 0.875rem;
}

/* Responsive */
@media (max-width: 768px) {
    main {
        grid-template-columns: 1fr;
    }

    aside {
        position: static;
    }

    nav ul {
        gap: 0.25rem;
    }
    
    nav .container {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .theme-toggle {
        align-self: flex-end;
    }
}
