:root {
    --primary: #10b981;
    --primary-dark: #059669;
    --primary-light: #d1fae5;
    --accent: #6366f1;
    --accent-light: #e0e7ff;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text-main: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
    --shadow-hover: 0 20px 25px -5px rgb(0 0 0 / 0.08), 0 8px 10px -6px rgb(0 0 0 / 0.04);
    --shadow-lg: 0 25px 50px -12px rgb(0 0 0 / 0.15);
    --nav-bg: rgba(255, 255, 255, 0.85);
    --radius: 16px;
    --radius-sm: 10px;
}

[data-theme="dark"] {
    --primary: #34d399;
    --primary-dark: #10b981;
    --primary-light: #064e3b;
    --accent: #818cf8;
    --accent-light: #312e81;
    --bg: #0f172a;
    --surface: #1e293b;
    --text-main: #f1f5f9;
    --text-secondary: #94a3b8;
    --border: #334155;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-hover: 0 20px 25px -5px rgb(0 0 0 / 0.35), 0 8px 10px -6px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 25px 50px -12px rgb(0 0 0 / 0.5);
    --nav-bg: rgba(15, 23, 42, 0.85);
}

/* ───── Base ───── */

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg);
    color: var(--text-main);
    margin: 0;
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
}

.container {
    max-width: 1060px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* ───── Navbar ───── */

.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background-color: var(--nav-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 0.85rem 0;
}

.nav-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-weight: 800;
    font-size: 1.3rem;
    color: var(--primary);
    text-decoration: none;
    letter-spacing: -0.02em;
}

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

.nav-links a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: color 0.2s;
    padding: 0.25rem 0;
}

.nav-links a:hover {
    color: var(--primary);
}

.nav-highlight {
    font-weight: 600 !important;
    color: var(--primary) !important;
    background: var(--primary-light);
    padding: 0.3rem 0.75rem !important;
    border-radius: 999px;
    font-size: 0.8rem !important;
}

#theme-toggle {
    background: none;
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.4rem 0.5rem;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    color: var(--text-main);
    line-height: 1;
}

#theme-toggle:hover {
    background-color: var(--surface);
    border-color: var(--primary);
}

/* ───── Header ───── */

header {
    position: relative;
    background: linear-gradient(135deg, #10b981 0%, #059669 50%, #047857 100%);
    color: white;
    padding: 5rem 0 4rem;
    margin-bottom: 3rem;
    text-align: center;
    overflow: hidden;
}

.header-bg {
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(circle at 20% 50%, rgba(255,255,255,0.08) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255,255,255,0.06) 0%, transparent 40%),
        radial-gradient(circle at 60% 80%, rgba(0,0,0,0.05) 0%, transparent 40%);
    pointer-events: none;
}

.header-content {
    position: relative;
}

header h1 {
    font-size: 3.25rem;
    font-weight: 800;
    margin: 0 0 0.5rem 0;
    letter-spacing: -0.03em;
    text-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.header-subtitle {
    font-size: 1.15rem;
    opacity: 0.9;
    margin: 0 0 1.25rem 0;
    font-weight: 300;
}

.header-email {
    display: inline-block;
    color: white;
    text-decoration: none;
    font-size: 0.85rem;
    opacity: 0.75;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 0.35rem 1rem;
    border-radius: 999px;
    transition: all 0.2s;
}

.header-email:hover {
    opacity: 1;
    background: rgba(255,255,255,0.15);
}

/* ───── Macro Sections ───── */

.macro-section {
    margin-bottom: 4rem;
}

.macro-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 3rem 0 1.5rem;
    padding-bottom: 1.25rem;
    border-bottom: 2px solid var(--border);
}

.macro-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.macro-icon--lang {
    background: linear-gradient(135deg, var(--accent), #4f46e5);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.macro-title {
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0;
    letter-spacing: -0.02em;
}

.macro-description {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin: 0.2rem 0 0;
}

/* ───── Tabs ───── */

.tabs {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 1.5rem;
    background: var(--surface);
    padding: 0.3rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    width: fit-content;
}

.tab {
    padding: 0.55rem 1.25rem;
    border: none;
    background: none;
    border-radius: 8px;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.tab:hover {
    color: var(--text-main);
    background: var(--bg);
}

.tab.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.tab-panel {
    display: none;
    animation: panelFadeIn 0.3s ease-out;
}

.tab-panel.active {
    display: block;
}

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

/* ───── Grid & Cards ───── */

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
}

.lesson-card {
    background-color: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    animation: fadeIn 0.4s ease-out forwards;
    opacity: 0;
}

.lesson-card:nth-child(1) { animation-delay: 0.05s; }
.lesson-card:nth-child(2) { animation-delay: 0.1s; }
.lesson-card:nth-child(3) { animation-delay: 0.15s; }

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

.lesson-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
    border-color: var(--primary);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.lesson-card h3 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-main);
}

.badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge.new {
    background-color: var(--primary-light);
    color: var(--primary);
    border: 1px solid currentColor;
}

.lesson-card p {
    margin: 0 0 1.25rem 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.btn {
    display: inline-block;
    background-color: var(--bg);
    color: var(--primary);
    text-decoration: none;
    padding: 0.65rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    text-align: center;
    transition: all 0.2s;
    border: 1px solid var(--border);
}

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

/* ───── Empty state ───── */

.empty-state {
    padding: 4rem 2rem;
    text-align: center;
    background-color: var(--surface);
    border-radius: var(--radius);
    border: 2px dashed var(--border);
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.empty-state p {
    margin: 0;
    font-size: 1rem;
    font-weight: 500;
}

/* ───── Footer ───── */

footer {
    text-align: center;
    padding: 3rem 0;
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 2rem;
    border-top: 1px solid var(--border);
}

/* ───── Lesson Page Styles ───── */

.lesson-container {
    max-width: 1400px;
    padding-top: 2rem;
    padding-bottom: 4rem;
}

.lesson-header, .description {
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

.lesson-header {
    margin-bottom: 3rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 2rem;
}

.back-link {
    display: inline-block;
    margin-bottom: 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.back-link:hover {
    color: var(--primary);
}

.lesson-header h1 {
    font-size: 2.5rem;
    margin: 0 0 0.5rem 0;
    color: var(--text-main);
}

.lesson-subtitle {
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin: 0 0 1.5rem 0;
}

.lesson-actions {
    display: flex;
    gap: 1rem;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    border: none;
}

.btn-primary:hover {
    background-color: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.btn-disabled {
    opacity: 0.65;
    cursor: not-allowed;
    pointer-events: none;
}

.description {
    margin-bottom: 3rem;
    line-height: 1.7;
}

.description h2, .exercises h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text-main);
}

.exercises h2, .exercises p {
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

/* ───── Section title (used in lesson pages) ───── */

.section-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-main);
    margin: 4rem 0 1.5rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border);
    display: flex;
    align-items: center;
}

.section-title::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 24px;
    background-color: var(--primary);
    margin-right: 12px;
    border-radius: 3px;
}

/* ───── Code Browser ───── */

.code-browser {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 0;
    margin-top: 1.5rem;
    height: 75vh;
    min-height: 600px;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    background-color: var(--surface);
    box-shadow: var(--shadow);
}

.file-list {
    background-color: var(--bg);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.file-btn {
    text-align: left;
    background: none;
    border: none;
    padding: 1rem 1.5rem;
    border-radius: 0;
    cursor: pointer;
    color: var(--text-secondary);
    font-family: 'Fira Code', monospace;
    font-size: 0.9rem;
    transition: all 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-left: 3px solid transparent;
}

.file-btn:hover {
    background-color: rgba(99, 102, 241, 0.05);
    color: var(--primary);
}

.file-btn.active {
    background-color: var(--surface);
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 600;
}

.code-viewer {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: #2d2d2d;
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background-color: #1e1e1e;
    border-bottom: 1px solid #333;
    color: #e0e0e0;
}

#current-filename {
    font-family: monospace;
    font-weight: 600;
}

.copy-btn {
    background-color: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #e0e0e0;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}

.copy-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.code-viewer pre {
    margin: 0 !important;
    height: 100%;
    overflow: auto !important;
    border-radius: 0 !important;
    padding: 1.5rem !important;
}

/* ───── Responsive ───── */

@media (max-width: 640px) {
    header {
        padding: 3.5rem 0 2.5rem;
    }

    header h1 {
        font-size: 2rem;
    }

    .header-subtitle {
        font-size: 1rem;
    }

    .nav-links {
        display: none;
    }

    .nav-content {
        position: relative;
    }

    #theme-toggle {
        display: block;
        position: absolute;
        right: 0;
    }

    .macro-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .tabs {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .tab {
        font-size: 0.8rem;
        padding: 0.5rem 0.9rem;
    }
}

@media (max-width: 768px) {
    .code-browser {
        grid-template-columns: 1fr;
        height: auto;
        max-height: 800px;
    }

    .file-list {
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .code-viewer {
        height: 400px;
    }

    .grid {
        grid-template-columns: 1fr;
    }
}
