:root {
    --bg: #0f1117;
    --panel: #1a1d25;
    --editor-bg: #11131a;
    --border: rgba(255, 255, 255, 0.06);
    --primary: #7C5CFF;
    --secondary: #00D4FF;
    --text: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.65);
    --success: #22c55e;
    --warning: #f59e0b;
    --gradient: linear-gradient(135deg, #7C5CFF, #00D4FF);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    --header-height: 72px;
    --sidebar-width: 320px;
    --radius-panel: 18px;
    --radius-btn: 12px;
    --radius-editor: 16px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; }
html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', sans-serif;
    color: var(--text);
    background:
        radial-gradient(900px 450px at 12% -15%, rgba(124, 92, 255, 0.2), transparent 65%),
        radial-gradient(900px 500px at 100% -18%, rgba(0, 212, 255, 0.12), transparent 60%),
        var(--bg);
    line-height: 1.6;
    overflow-x: hidden;
}

a,
a:visited,
a:hover,
a:active {
    color: inherit;
    text-decoration: none;
}

::selection { background: rgba(124, 92, 255, 0.35); color: #fff; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.03); }
::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: linear-gradient(180deg, rgba(124, 92, 255, 0.9), rgba(0, 212, 255, 0.9));
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

h1, .lesson-title {
    font-size: clamp(2rem, 4vw, 3rem);
    font-weight: 700;
    letter-spacing: -1px;
    line-height: 1.1;
}

h2, .section-title, .completion-title {
    font-size: clamp(1.5rem, 2.6vw, 1.75rem);
    font-weight: 600;
}

p, .theory-text, .lesson-subtitle, li {
    font-size: clamp(1rem, 1.05vw, 1.07rem);
    color: var(--text-secondary);
}

code, pre, .code-editor, .line-numbers, .code-inline {
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
}

header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    height: var(--header-height);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    background: rgba(15, 17, 23, 0.7);
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 18px;
}

.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 100%;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-size: 1.1rem;
    font-weight: 700;
    text-decoration: none;
}

.logo-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: var(--gradient);
    box-shadow: 0 10px 30px rgba(124, 92, 255, 0.4);
}

.mobile-menu-toggle {
    display: none;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
}

.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.progress-container { display: flex; flex-direction: column; gap: 6px; }
.progress-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-secondary);
}
.progress-bar {
    height: 8px;
    width: 180px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.05);
    overflow: hidden;
}
.progress-fill {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #7C5CFF, #00D4FF);
    box-shadow: 0 0 20px rgba(124, 92, 255, 0.6);
    transition: width 0.35s ease;
}
.progress-value { font-weight: 600; color: #fff; }

.sidebar {
    position: fixed;
    left: 0;
    top: var(--header-height);
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    padding: 14px;
    border-right: 1px solid var(--border);
    background: rgba(26, 29, 37, 0.88);
    backdrop-filter: blur(14px);
    overflow-y: auto;
    transition: var(--transition);
    z-index: 950;
}

.sidebar-header,
.module {
    background: var(--panel);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-panel);
    box-shadow: 0 20px 60px rgba(0,0,0,.4);
}

.sidebar-header { padding: 18px; margin-bottom: 14px; }
.sidebar-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-secondary);
}
.sidebar-subtitle { margin-top: 6px; color: #fff; font-weight: 600; }

.module { padding: 12px 0; margin-bottom: 14px; }
.module-header { padding: 0 16px 8px; }
.module-title {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-secondary);
}
.module-progress {
    border-radius: 999px;
    padding: 2px 8px;
    background: rgba(124, 92, 255, 0.16);
    border: 1px solid rgba(124, 92, 255, 0.35);
    color: #c8bcff;
}

.lesson-list { list-style: none; padding: 8px; }
.lesson-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    padding: 14px;
    border-radius: 18px;
    background: #1a1d25;
    border: 1px solid rgba(255,255,255,.05);
    box-shadow: 0 20px 60px rgba(0,0,0,.4);
    cursor: pointer;
    transition: var(--transition);
}
.lesson-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 30px 80px rgba(124,92,255,.25);
}
.lesson-item.active {
    border-color: rgba(124, 92, 255, 0.9);
    box-shadow: 0 0 0 1px rgba(124,92,255,.55), 0 30px 80px rgba(124,92,255,.25);
}

.lesson-number {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: rgba(255,255,255,.08);
    display: grid;
    place-items: center;
    font-weight: 700;
    flex-shrink: 0;
}
.lesson-item.active .lesson-number,
.lesson-item.completed .lesson-number { background: var(--gradient); }

.lesson-info { flex: 1; min-width: 0; }
.lesson-name {
    font-weight: 600;
    color: #fff;
    font-size: 1rem;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.lesson-meta { display: flex; align-items: center; gap: 8px; }
.lesson-duration { font-size: 12px; color: var(--text-secondary); display: inline-flex; gap: 4px; align-items: center; }
.lesson-difficulty {
    border-radius: 999px;
    padding: 2px 8px;
    border: 1px solid rgba(124, 92, 255, 0.32);
    background: rgba(124, 92, 255, 0.14);
    color: #c7baff;
    font-size: 11px;
}
.lesson-status { margin-left: auto; color: rgba(255, 255, 255, 0.18); }
.lesson-item.completed .lesson-status { color: var(--success); }

/* исправление артефактов из неидеальной HTML-структуры */
.lesson-list > .lesson-status {
    display: none;
}

.main-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--header-height);
    min-height: calc(100vh - var(--header-height));
    padding: 80px 18px;
}

.lesson-header,
.lesson-content,
.meta-card,
.theory-panel,
.editor-container,
.preview-container,
.completion-card,
.toast {
    animation: fadeUp .5s ease both;
}

.lesson-header,
.lesson-content {
    max-width: 1200px;
    margin: 0 auto;
}

.lesson-header { margin-bottom: 22px; }
.lesson-title {
    margin-bottom: 12px;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.lesson-subtitle { margin-bottom: 16px; max-width: 900px; }

.lesson-meta-grid { display: grid; grid-template-columns: minmax(220px, 320px); gap: 14px; }
.meta-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-panel);
    box-shadow: 0 20px 60px rgba(0,0,0,.4);
    padding: 24px;
}
.meta-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: rgba(124, 92, 255, .16);
    color: #c4b7ff;
    display: grid;
    place-items: center;
    margin-bottom: 10px;
}
.meta-title { font-size: 12px; color: var(--text-secondary); }
.meta-value { color: #fff; font-weight: 700; font-size: 1.15rem; }

.lesson-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    min-height: 640px;
    align-items: start;
}

.theory-panel,
.editor-container,
.preview-container {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-panel);
    box-shadow: 0 20px 60px rgba(0,0,0,.4);
    overflow: hidden;
}

.theory-panel { overflow-y: auto; }
.theory-content { padding: 28px; }
.theory-section { padding-bottom: 26px; margin-bottom: 26px; border-bottom: 1px solid var(--border); }
.theory-section:last-child { border-bottom: none; margin-bottom: 0; }
.section-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.section-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    color: #fff;
    background: var(--gradient);
}
.theory-text code, .code-inline {
    border-radius: 10px;
    padding: 2px 8px;
    background: rgba(124, 92, 255, .14);
    border: 1px solid rgba(124, 92, 255, .35);
    color: #ddd6ff;
}

.theory-list,
ol.exercise-steps { padding-left: 18px; }
.theory-list li,
ol.exercise-steps li { margin-bottom: 8px; }

.note-box,
.tip-box,
.exercise-box,
.code-block,
.step,
.compare-item,
.result-preview {
    background: rgba(255, 255, 255, .02);
    border: 1px solid var(--border);
    border-radius: var(--radius-panel);
    padding: 18px;
    margin: 14px 0;
}

.note-header,
.exercise-header,
.code-block-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.practice-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
    position: sticky;
    top: calc(var(--header-height) + 16px);
    align-self: start;
    height: calc(100vh - var(--header-height) - 28px);
    overflow-y: auto;
    padding-right: 4px;
}

.editor-container {
    background: #11131a;
    border-radius: var(--radius-editor);
    border: 1px solid rgba(255,255,255,.05);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.02), 0 20px 60px rgba(0,0,0,.5);
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 280px;
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    border-bottom: 1px solid var(--border);
    padding: 14px 16px;
    background:
      radial-gradient(circle at 18px 50%, #ff5f57 0 5px, transparent 6px),
      radial-gradient(circle at 38px 50%, #febc2e 0 5px, transparent 6px),
      radial-gradient(circle at 58px 50%, #28c840 0 5px, transparent 6px),
      rgba(255,255,255,.01);
}

.file-tabs { display: flex; gap: 8px; margin-left: 74px; }
.file-tab {
    border-radius: 10px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 12px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}
.file-tab:hover { border-color: rgba(255,255,255,.1); color: #fff; }
.file-tab.active {
    color: #fff;
    border-color: rgba(124,92,255,.5);
    background: rgba(124,92,255,.14);
}

.editor-options { display: flex; gap: 14px; align-items: center; }
.option-group { display: flex; align-items: center; gap: 8px; }
.option-label { font-size: 12px; color: var(--text-secondary); }

.toggle-switch { position: relative; width: 38px; height: 22px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: rgba(255,255,255,.14);
    transition: var(--transition);
}
.slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    top: 3px;
    border-radius: 50%;
    background: #fff;
    transition: var(--transition);
}
.toggle-switch input:checked + .slider { background: rgba(124, 92, 255, .85); }
.toggle-switch input:checked + .slider::before { transform: translateX(16px); }

.editor-wrapper {
    flex: 1;
    display: flex;
    background: #11131a;
    min-height: 300px;
}

.line-numbers {
    width: 54px;
    border-right: 1px solid var(--border);
    background: rgba(255,255,255,.01);
    color: rgba(255,255,255,.35);
    padding: 16px 8px;
    line-height: 1.7;
    text-align: right;
    user-select: none;
}

.code-editor {
    flex: 1;
    background: #11131a;
    color: #f3f4ff;
    border: none;
    resize: none;
    outline: none;
    padding: 16px;
    line-height: 1.7;
    caret-color: #7C5CFF;
    tab-size: 4;
    transition: var(--transition);
}

.code-editor:focus {
    box-shadow: inset 0 0 0 1px rgba(124,92,255,.45), 0 0 30px rgba(124,92,255,.35);
    background: linear-gradient(0deg, rgba(124,92,255,.08), rgba(124,92,255,.08)), #11131a;
}

.editor-footer,
.preview-header {
    border-top: 1px solid var(--border);
    padding: 14px 16px;
    background: rgba(255,255,255,.01);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.action-buttons { display: flex; gap: 10px; flex-wrap: wrap; }

.btn {
    border: none;
    border-radius: var(--radius-btn);
    padding: 12px 24px;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition);
}

.btn-primary,
.btn-success {
    background: var(--gradient);
    box-shadow: 0 10px 30px rgba(124,92,255,.4);
}
.btn-primary:hover,
.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 20px 40px rgba(124,92,255,.6);
}

.btn-secondary,
.btn-outline {
    background: transparent;
    border: 1px solid rgba(255,255,255,.1);
}
.btn-secondary:hover,
.btn-outline:hover { background: rgba(255,255,255,.05); }

.hint-btn {
    border-radius: 12px;
    border: 1px solid rgba(245, 158, 11, .35);
    background: rgba(245, 158, 11, .12);
    color: #f5b434;
    padding: 10px 14px;
    font-weight: 600;
    transition: var(--transition);
}
.hint-btn:hover { transform: translateY(-1px); }

.preview-container {
    min-height: 220px;
    max-height: 45vh;
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    resize: vertical;
    overflow: auto;
}
.preview-title { color: #fff; font-weight: 600; display: inline-flex; gap: 8px; align-items: center; }
.preview-frame { width: 100%; flex: 1; border: 0; background: #fff; }

.completion-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 17, 23, .84);
    backdrop-filter: blur(8px);
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
    z-index: 2000;
}
.completion-overlay.active { opacity: 1; visibility: visible; }
.completion-card {
    width: min(520px, 92vw);
    padding: 32px;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: var(--panel);
    box-shadow: 0 20px 60px rgba(0,0,0,.5);
    text-align: center;
}
.completion-icon {
    width: 74px;
    height: 74px;
    border-radius: 50%;
    margin: 0 auto 14px;
    display: grid;
    place-items: center;
    background: var(--gradient);
    box-shadow: 0 12px 28px rgba(124,92,255,.45);
}
.completion-text { margin: 12px 0 22px; }
.completion-actions { display: flex; justify-content: center; gap: 12px; }

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 3000;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 420px;
    padding: 14px 16px;
    border-radius: 14px;
    border-left: 4px solid var(--primary);
    border: 1px solid var(--border);
    background: rgba(26, 29, 37, .95);
    box-shadow: 0 20px 50px rgba(0,0,0,.45);
    opacity: 0;
    transform: translateY(20px);
    transition: var(--transition);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-icon { color: var(--success); }
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: #ef4444; }
.toast-error .toast-icon { color: #ef4444; }

.login-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    background: rgba(15, 17, 23, .9);
    backdrop-filter: blur(10px);
}
.login-card {
    width: min(520px, 92vw);
    padding: 30px;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: var(--panel);
    box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.login-card h2 {
    margin-bottom: 10px;
    text-align: center;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.login-card > p { text-align: center; margin-bottom: 16px; }
.saved-users {
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,.02);
    padding: 12px;
    margin-bottom: 14px;
}
.saved-users h4 { margin-bottom: 8px; }
.saved-users ul { list-style: none; max-height: 180px; overflow: auto; }
.saved-users li {
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--panel);
    padding: 10px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: var(--transition);
}
.saved-users li:hover { border-color: rgba(124,92,255,.5); transform: translateX(3px); }
#login-form { display: flex; flex-direction: column; gap: 10px; }
#username-input {
    border-radius: 12px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,.03);
    color: #fff;
    padding: 12px;
}
#username-input:focus {
    outline: none;
    border-color: rgba(124,92,255,.7);
    box-shadow: 0 0 0 3px rgba(124,92,255,.25);
}

.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: .5rem; }
.gap-4 { gap: 1rem; }
.w-full { width: 100%; }
.h-full { height: 100%; }
.text-center { text-align: center; }

@media (max-width: 1180px) {
    .lesson-content { grid-template-columns: 1fr; }
    .practice-panel {
        position: static;
        top: auto;
        height: auto;
        overflow: visible;
        padding-right: 0;
    }
}

@media (max-width: 992px) {
    .mobile-menu-toggle { display: inline-grid; place-items: center; }

    .sidebar { transform: translateX(-100%); }
    .sidebar:not(.collapsed) { transform: translateX(0); }

    .main-content {
        margin-left: 0;
        padding: 36px 14px;
    }

    .progress-container { display: none; }
}

@media (max-width: 760px) {
    .editor-header,
    .editor-footer,
    .preview-header {
        flex-direction: column;
        align-items: stretch;
    }

    .file-tabs { margin-left: 0; overflow-x: auto; }
    .action-buttons { width: 100%; }
    .btn { flex: 1; }
    .completion-actions { flex-direction: column; }
}