:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f7f7f7;
    --bg-tertiary: #ffffff;
    --text-primary: #000000;
    --text-secondary: #707579;
    --text-tertiary: #999999;
    --accent: #3390ec;
    --accent-hover: #2b7fd4;
    --border: #e5e5e5;
    --success: #4caf50;
    --warning: #ff9800;
    --error: #f44336;
    --progress-bg: #e5e5e5;
    --progress-fill: #3390ec;
    --shadow: rgba(0, 0, 0, 0.1);
    --modal-overlay: rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] {
    --bg-primary: #212121;
    --bg-secondary: #181818;
    --bg-tertiary: #2c2c2c;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-tertiary: #707070;
    --accent: #3390ec;
    --accent-hover: #4ba0ff;
    --border: #3a3a3a;
    --success: #66bb6a;
    --warning: #ffa726;
    --error: #ef5350;
    --progress-bg: #3a3a3a;
    --progress-fill: #3390ec;
    --shadow: rgba(0, 0, 0, 0.3);
    --modal-overlay: rgba(0, 0, 0, 0.7);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.app {
    min-height: 100vh;
    max-width: 600px;
    margin: 0 auto;
    background-color: var(--bg-primary);
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, #3390ec 0%, #2b7fd4 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
    gap: 8px;
    min-height: 56px;
    box-shadow: 0 2px 8px rgba(51, 144, 236, 0.3);
}

.header-left {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.header-title-wrapper {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.header h1 {
    font-size: 18px;
    font-weight: 600;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
    line-height: 1.2;
}

.demo-badge {
    font-size: 10px;
    font-weight: 500;
    color: #ffffff;
    opacity: 0.9;
    line-height: 1;
}

.header-right {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    background: rgba(255, 255, 255, 0.2);
    padding: 6px 12px;
    border-radius: 12px;
    backdrop-filter: blur(10px);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

.user-avatar:hover {
    transform: scale(1.05);
    border-color: rgba(255, 255, 255, 0.8);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.header-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    opacity: 0.9;
    min-width: 32px;
    min-height: 32px;
    backdrop-filter: blur(10px);
}

.header-btn:hover {
    background-color: rgba(255, 255, 255, 0.3);
    color: white;
    opacity: 1;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.header-btn:active {
    transform: translateY(0);
}

.header-btn svg {
    width: 18px;
    height: 18px;
}

.version-badge {
    font-size: 10px;
    font-weight: 500;
    color: white;
    background-color: rgba(255, 255, 255, 0.2);
    padding: 3px 8px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
    opacity: 0.9;
    transition: opacity 0.2s;
    white-space: nowrap;
    backdrop-filter: blur(10px);
}

.version-badge:hover {
    opacity: 1;
}

.theme-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    min-width: 32px;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    opacity: 0.9;
    backdrop-filter: blur(10px);
}

.theme-toggle:hover {
    background-color: rgba(255, 255, 255, 0.3);
    opacity: 1;
}

.theme-toggle:hover {
    background-color: var(--bg-tertiary);
}

/* Main Content */
.main {
    padding: 20px;
    padding-bottom: 40px;
}

.section {
    margin-bottom: 32px;
}

.section-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

/* Loading & Error States */
.loading, .error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    padding: 40px 20px;
    text-align: center;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--progress-bg);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.error svg {
    color: var(--error);
    margin-bottom: 16px;
}

.error h3 {
    margin-bottom: 8px;
    color: var(--text-primary);
}

.error p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

/* Progress Section */
.progress-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    width: 100%;
    max-width: 100%;
    padding: 0 16px;
    box-sizing: border-box;
}

.progress-ring {
    position: relative;
    width: 200px;
    height: 200px;
    max-width: 100%;
    max-height: 100%;
    flex-shrink: 0;
    margin: 0 auto;
}

.progress-ring-svg {
    transform: rotate(-90deg);
    width: 100%;
    height: 100%;
    display: block;
}

.progress-ring-bg {
    fill: none;
    stroke: var(--progress-bg);
    stroke-width: 12;
}

.progress-ring-progress {
    fill: none;
    stroke: var(--progress-fill);
    stroke-width: 12;
    stroke-linecap: round;
    stroke-dasharray: 534;
    stroke-dashoffset: 534;
    transition: stroke-dashoffset 0.8s ease;
}

.progress-ring-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.progress-percent {
    display: block;
    font-size: 36px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    margin: 0;
    padding: 0;
}

.progress-label {
    display: block;
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
    line-height: 1.2;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    width: 100%;
}

.stat-card {
    background-color: var(--bg-secondary);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    border: 1px solid var(--border);
}

.stat-icon {
    font-size: 24px;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.last-activity {
    margin-top: 16px;
    padding: 12px;
    background-color: var(--bg-secondary);
    border-radius: 8px;
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
    border: 1px solid var(--border);
}

/* Course Section */
.course-card {
    background-color: var(--bg-secondary);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid var(--border);
}

.course-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.course-icon {
    font-size: 48px;
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-tertiary);
    border-radius: 12px;
}

.course-info {
    flex: 1;
}

.course-name {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.course-meta {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.course-difficulty,
.course-schedule {
    font-size: 14px;
    color: var(--text-secondary);
    padding: 4px 8px;
    background-color: var(--bg-tertiary);
    border-radius: 6px;
}

.course-details {
    margin-bottom: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.course-detail-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 14px;
}

.detail-label {
    color: var(--text-secondary);
}

.detail-value {
    color: var(--text-primary);
    font-weight: 500;
}

.course-status {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    display: inline-block;
}

.course-status.in_progress {
    background-color: var(--accent);
    color: white;
}

.course-status.completed {
    background-color: var(--success);
    color: white;
}

.course-status.paused {
    background-color: var(--warning);
    color: white;
}

/* Buttons */
.btn {
    padding: 14px 24px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

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

.btn-primary:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--shadow);
}

.btn-secondary {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background-color: var(--bg-tertiary);
}

.btn-outline {
    background-color: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
}

.btn-outline:hover {
    background-color: var(--accent);
    color: white;
}

.btn-full {
    width: 100%;
}

/* Timeline */
.timeline {
    position: relative;
    padding-left: 24px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background-color: var(--border);
}

.timeline-item {
    position: relative;
    margin-bottom: 24px;
    padding-left: 32px;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -16px;
    top: 4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: var(--bg-primary);
    border: 3px solid var(--border);
    z-index: 1;
}

.timeline-item.completed::before {
    background-color: var(--success);
    border-color: var(--success);
}

.timeline-item.in_progress::before {
    background-color: var(--accent);
    border-color: var(--accent);
    animation: pulse 2s infinite;
}

.timeline-item.locked::before {
    background-color: var(--bg-tertiary);
    border-color: var(--border);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.timeline-content {
    background-color: var(--bg-secondary);
    border-radius: 12px;
    padding: 16px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
}

.timeline-content:hover {
    transform: translateX(4px);
    box-shadow: 0 4px 12px var(--shadow);
}

.timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.timeline-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.timeline-status {
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 6px;
    font-weight: 500;
}

.timeline-status.completed {
    background-color: var(--success);
    color: white;
}

.timeline-status.in_progress {
    background-color: var(--accent);
    color: white;
}

.timeline-status.locked {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
}

.timeline-details {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 8px;
}

.timeline-item.locked .timeline-content {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Profile Section */
.profile-card {
    background-color: var(--bg-secondary);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid var(--border);
}

.profile-item {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.profile-item:last-of-type {
    border-bottom: none;
    margin-bottom: 16px;
}

.profile-label {
    color: var(--text-secondary);
    font-size: 14px;
}

.profile-value {
    color: var(--text-primary);
    font-weight: 500;
    font-size: 14px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--modal-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background-color: var(--bg-primary);
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px var(--shadow);
    animation: slideUp 0.3s;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background-color 0.2s;
}

.modal-close:hover {
    background-color: var(--bg-secondary);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.course-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.course-option {
    padding: 16px;
    background-color: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.course-option:hover:not(.disabled) {
    background-color: var(--bg-tertiary);
    transform: translateX(4px);
}

.course-option.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.course-option-name {
    font-weight: 500;
    color: var(--text-primary);
}

.course-option-status {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Responsive */
/* Адаптивные стили для шапки */
@media (max-width: 600px) {
    .header {
        padding: 10px 12px;
        gap: 6px;
    }
    
    .header h1 {
        font-size: 16px;
    }
    
    .header-right {
        padding: 4px 8px;
        gap: 4px;
    }
    
    .header-btn {
        padding: 4px;
        min-width: 28px;
        min-height: 28px;
    }
    
    .header-btn svg {
        width: 16px;
        height: 16px;
    }
    
    .version-badge {
        font-size: 9px;
        padding: 2px 6px;
    }
    
    .user-avatar {
        width: 28px;
        height: 28px;
    }
}

@media (max-width: 480px) {
    .main {
        padding: 16px;
    }

    .progress-container {
        padding: 0 8px;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .progress-ring {
        width: min(160px, calc(100vw - 64px));
        height: min(160px, calc(100vw - 64px));
        max-width: 100%;
        max-height: 100%;
        aspect-ratio: 1;
    }

    .progress-ring-svg {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
    }

    .progress-percent {
        font-size: 28px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .stat-card {
        padding: 12px;
    }

    .course-icon {
        width: 56px;
        height: 56px;
        font-size: 40px;
    }
}

/* Telegram WebApp Integration */
body {
    padding-bottom: env(safe-area-inset-bottom);
}

