/* ===== CSS Variables ===== */
:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --accent: #38bdf8;
    --accent-dark: #0284c7;
    --success: #22c55e;
    --warning: #eab308;
    --error: #ef4444;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.3), 0 2px 4px -2px rgba(0,0,0,0.3);
    --transition: 0.2s cubic-bezier(0.19, 1, 0.22, 1);
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ===== View Transitions ===== */
::view-transition-group(*),
::view-transition-old(*),
::view-transition-new(*) {
    animation-duration: 0.25s;
    animation-timing-function: cubic-bezier(0.19, 1, 0.22, 1);
}

/* ===== Navbar ===== */
.navbar {
    background: var(--surface);
    border-bottom: 1px solid var(--surface-light);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
}

.logo {
    font-size: 1.5rem;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-links a {
    color: var(--text-muted);
    font-weight: 500;
    transition: color var(--transition);
}

.nav-links a:hover {
    color: var(--text);
    text-decoration: none;
}

.progress-mini {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.progress-bar-mini {
    width: 80px;
    height: 6px;
    background: var(--surface-light);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-mini > div {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width var(--transition);
}

/* ===== Container ===== */
.container {
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem;
    flex: 1;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
    text-decoration: none;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
    text-decoration: none;
}

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

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

.btn-secondary {
    background: var(--surface-light);
    color: var(--text);
}

.btn-secondary:hover {
    background: #475569;
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--surface-light);
}

.btn-ghost:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

.btn-small {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-run {
    background: var(--success);
    color: #064e3b;
}

.btn-reset {
    background: var(--surface-light);
    color: var(--text-muted);
}

/* ===== Hero ===== */
.hero {
    text-align: center;
    padding: 3rem 1rem;
}

.hero h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    background: linear-gradient(90deg, var(--accent), #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.125rem;
    margin-bottom: 2rem;
}

.stats {
    display: flex;
    justify-content: center;
    gap: 2.5rem;
    flex-wrap: wrap;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-number {
    font-size: 2rem;
    font-weight: 800;
    color: var(--accent);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===== Chapter Cards ===== */
.chapters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
}

.chapter-card {
    background: var(--surface);
    border: 1px solid var(--surface-light);
    border-radius: var(--radius);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    transition: transform var(--transition), border-color var(--transition);
}

.chapter-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent-dark);
}

.chapter-number {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--accent);
}

.chapter-card h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.chapter-subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.chapter-progress {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: var(--surface-light);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #818cf8);
    border-radius: 4px;
    transition: width var(--transition);
}

.progress-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-passed {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
}

.badge-completed {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
}

.badge-pending {
    background: rgba(234, 179, 8, 0.15);
    color: var(--warning);
}

/* ===== Chapter Page ===== */
.chapter-hero {
    text-align: center;
    padding: 2rem 0;
}

.chapter-number-large {
    font-size: 0.875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--accent);
}

.chapter-hero h1 {
    font-size: 2rem;
    margin: 0.5rem 0;
}

.chapter-description {
    color: var(--text-muted);
    max-width: 600px;
    margin: 0 auto;
}

.lessons-list {
    margin: 2rem 0;
}

.lessons-list h2 {
    font-size: 1.125rem;
    margin-bottom: 1rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.lesson-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--surface-light);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 0.75rem;
    transition: border-color var(--transition);
}

.lesson-row:hover {
    border-color: var(--accent-dark);
}

.lesson-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.lesson-number {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-light);
    border-radius: 50%;
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--accent);
}

.lesson-info h3 {
    font-size: 1rem;
    font-weight: 600;
}

.lesson-duration {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.chapter-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 2rem;
}

/* ===== Lesson Page ===== */
.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.breadcrumbs a {
    color: var(--text-muted);
}

.breadcrumbs a:hover {
    color: var(--accent);
}

.lesson-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.lesson-header h1 {
    font-size: 1.75rem;
}

.objectives {
    background: var(--surface);
    border: 1px solid var(--surface-light);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 2rem;
}

.objectives h2 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--accent);
}

.objectives ul {
    list-style: none;
    padding-left: 0;
}

.objectives li {
    padding: 0.25rem 0;
    padding-left: 1.25rem;
    position: relative;
}

.objectives li::before {
    content: "✓";
    position: absolute;
    left: 0;
    color: var(--success);
    font-weight: 700;
}

.lesson-section {
    margin-bottom: 2rem;
}

.lesson-section h2 {
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
}

.lesson-section p {
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.note {
    background: rgba(234, 179, 8, 0.1);
    border-left: 3px solid var(--warning);
    padding: 0.75rem 1rem;
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 0.875rem;
    color: var(--warning);
    margin-bottom: 1rem;
}

.code-block {
    position: relative;
    background: #0b1220;
    border: 1px solid var(--surface-light);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 1rem;
}

.code-block pre {
    padding: 1rem;
    overflow-x: auto;
}

.code-block code {
    font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.875rem;
    color: #e2e8f0;
    line-height: 1.6;
}

.code-block .btn-run {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
}

/* ===== Code Editor ===== */
.exercise {
    background: var(--surface);
    border: 1px solid var(--surface-light);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin: 2rem 0;
}

.exercise h2 {
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
}

.exercise > p {
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.editor-wrap {
    border: 1px solid var(--surface-light);
    border-radius: var(--radius);
    overflow: hidden;
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #0b1220;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--surface-light);
}

.editor-title {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: monospace;
}

.editor-actions {
    display: flex;
    gap: 0.5rem;
}

.code-editor {
    width: 100%;
    min-height: 180px;
    background: #0b1220;
    color: #e2e8f0;
    font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    padding: 1rem;
    border: none;
    resize: vertical;
    outline: none;
}

.output-wrap {
    border-top: 1px solid var(--surface-light);
}

.output-header {
    background: #0b1220;
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.code-output {
    background: #0b1220;
    color: #e2e8f0;
    font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.875rem;
    padding: 1rem;
    min-height: 60px;
    max-height: 300px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.code-output.error {
    color: var(--error);
}

.code-output.success {
    color: var(--success);
}

.lesson-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--surface-light);
}

/* ===== Quiz ===== */
.quiz {
    max-width: 720px;
    margin: 0 auto;
}

.quiz-header {
    text-align: center;
    margin-bottom: 2rem;
}

.quiz-header h1 {
    font-size: 1.75rem;
}

.quiz-header p {
    color: var(--text-muted);
}

.quiz-question {
    background: var(--surface);
    border: 1px solid var(--surface-light);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.question-text {
    font-size: 1rem;
    margin-bottom: 1rem;
    line-height: 1.5;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--bg);
    border: 1px solid var(--surface-light);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
}

.option:hover {
    border-color: var(--accent-dark);
}

.option input {
    accent-color: var(--accent);
}

.option.correct {
    border-color: var(--success);
    background: rgba(34, 197, 94, 0.1);
}

.option.wrong {
    border-color: var(--error);
    background: rgba(239, 68, 68, 0.1);
}

.explanation {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: rgba(56, 189, 248, 0.1);
    border-radius: 8px;
    font-size: 0.875rem;
    color: var(--accent);
    display: none;
}

.explanation.visible {
    display: block;
}

.quiz-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1.5rem;
}

.quiz-result {
    text-align: center;
    padding: 2rem;
    background: var(--surface);
    border: 1px solid var(--surface-light);
    border-radius: var(--radius);
    margin-top: 1.5rem;
}

.quiz-result.hidden {
    display: none;
}

.quiz-result.passed {
    border-color: var(--success);
}

.quiz-result.failed {
    border-color: var(--error);
}

/* ===== Footer ===== */
.footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    border-top: 1px solid var(--surface-light);
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
    .navbar {
        padding: 1rem;
    }
    .container {
        padding: 1rem;
    }
    .hero h1 {
        font-size: 1.75rem;
    }
    .stats {
        gap: 1.5rem;
    }
    .chapter-actions,
    .quiz-actions,
    .lesson-nav {
        flex-direction: column;
    }
    .lesson-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
}
