/* ========== Общие стили ========== */
:root {
    --primary-color: #0ea5e9;
    --secondary-color: #10b981;
    --accent-color: #f472b6;
    --bg-color: rgba(255, 255, 255, 0.05);
    --card-bg: rgba(0, 0, 0, 0.5);
    --text-color: #ffffff;
    --text-light: #cccccc;
    --font-main: 'Inter', sans-serif;
    --font-hand: 'Patrick Hand', cursive;
    --border-radius: 12px;
    --transition: 0.3s;
}

/* ========== Шрифты с оптимизацией для скорости (SEO) ========== */
@font-face {
    font-family: 'Inter';
    font-display: swap;
    src: local('Inter'), url('/fonts/Inter.woff2') format('woff2');
}
@font-face {
    font-family: 'Patrick Hand';
    font-display: swap;
    src: local('Patrick Hand'), url('/fonts/PatrickHand.woff2') format('woff2');
}

/* ========== BASE ========== */
body {
    margin: 0;
    font-family: var(--font-main);
    background: #0f172a;
    color: var(--text-color);
}
a {
    color: var(--primary-color);
    text-decoration: none;
    transition: var(--transition);
}
a:hover {
    color: var(--accent-color);
}

/* ========== Header ========== */
.site-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--card-bg);
    position: sticky;
    top: 0;
    z-index: 1000;
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.site-header .logo {
    font-family: var(--font-hand);
    font-size: 1.8rem;
    font-weight: bold;
}
.site-header .back-link {
    font-size: 0.9rem;
}

/* ========== Article wrapper ========== */
.article-wrapper {
    max-width: 900px;
    margin: 3rem auto;
    padding: 2rem;
    background: var(--bg-color);
    border-radius: var(--border-radius);
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}

/* Заголовки */
.news-article h1 { font-size: 2rem; margin-bottom: 1rem; font-weight: 700; }
.news-article h2 { font-size: 1.5rem; margin: 2rem 0 1rem 0; }


/* Контент с оптимизированной читаемостью (SEO) */
.content {
    font-size: 1.05rem;
    line-height: 1.75;
    max-width: 720px;
    margin: 0 auto 1.5rem;
    color: #e6e6e6;
}
/* Ссылки ТОЛЬКО внутри текста статьи */
.content a {
    text-decoration: underline;
    text-underline-offset: 4px;
}
.content a:hover {
    text-decoration: none;
}

/* Изображения без сдвигов макета (SEO - CLS) */
.article-image {
    width: 100%;
    height: auto;
    display: block;
    margin: 1.5rem 0;
    border-radius: var(--border-radius);
}
.article-video {
    width: 100%;
    aspect-ratio: 16/9;
    margin: 1.5rem 0;
    border-radius: var(--border-radius);
}

/* ========== Grid system ========== */
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 768px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* ========== Cards ========== */
.card {
    background: var(--card-bg);
    padding: 1rem;
    border-radius: var(--border-radius);
    transition: var(--transition);
}
.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.6);
}

/* ========== Buttons ========== */
.btn {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    border-radius: var(--border-radius);
    border: none;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 600;
}
.btn-like { background: var(--secondary-color); color: #000; margin-right:0.5rem; }
.btn-like:hover { background: var(--accent-color); color: #fff; }
.btn-dislike { background: #dc2626; color: #fff; }
.btn-dislike:hover { background: #f87171; }

/* Шаринг — сохранён оригинальный стиль */
.share-btn { display: flex; align-items: center; justify-content: center; gap: 0.5rem; text-align: center; }
.share-btn i { font-size: 1.2rem; }

/* Голосование */
.article-votes {
    text-align: center;
    margin: 2rem 0;
}
.article-votes .grid-2 {
    gap: 2rem;
}
.article-votes .vote {
    display: inline-block;
    width: auto;
    margin: 0 auto;
}
.vote { font-size: 1.2rem; text-align: center; }
.vote-buttons { margin-top: 1rem; }
.voted-msg { font-style: italic; color: var(--text-light); }

/* ========== Комментарии ========== */
.comments { margin: 1rem 0; }
.comment { margin-bottom: 1rem; background: rgba(255,255,255,0.1); padding: 1rem; border-radius: var(--border-radius); }
.comment-form input,
.comment-form textarea {
    width: 100%; padding: 0.7rem; margin-bottom: 0.8rem;
    border-radius: var(--border-radius);
    border: 1px solid rgba(255,255,255,0.2);
    background: rgba(255,255,255,0.05);
    color: var(--text-color);
    font-size: 0.9rem;
}
.comment-form button { background: var(--primary-color); color: #fff; }
.comment-form button:hover { background: var(--accent-color); }

/* ========== Divider ========== */
.divider { height: 2px; width: 50px; background: var(--primary-color); margin: 3rem auto; border-radius: var(--border-radius); }

/* ========== Related articles ========== */
.related-article h3 { font-size: 1rem; }
.related-article small { color: var(--text-light); }

/* ========== Final block ========== */
.final-block {
    margin-top: 3rem; padding: 1.5rem;
    background: rgba(255,255,255,0.1);
    border-radius: var(--border-radius);
    font-weight: 500;
}

/* ========== Back to top ========== */
#backToTop {
    position: fixed; bottom: 2rem; right: 2rem;
    background: var(--primary-color); color: #000;
    padding: 0.7rem 1rem; border-radius: var(--border-radius);
    font-size: 1.2rem; cursor: pointer; display: none;
    transition: var(--transition); z-index: 999;
}
#backToTop.show { display: block; }
#backToTop:hover { background: var(--accent-color); }

/* ========== Particles layer ========== */
#particles-js {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: -1;
}

/* ========== Responsive typography ========== */
@media (max-width: 768px){
    .news-article h1 { font-size: 1.6rem; }
    .news-article h2 { font-size: 1.3rem; }
    .article-meta { flex-direction: column; gap: 0.5rem; }
    .content {
        font-size: 1rem;
        line-height: 1.7;
        max-width: 100%;
    }
}

/* ========== NEW: Beautiful numbered steps with animation (ИСПРАВЛЕНО) ======== */
.content ol {
    counter-reset: step;
    list-style: none;
    padding-left: 0;
    margin: 2rem 0;
}
.content ol li {
    counter-increment: step;
    margin: 1rem 0;
    padding: 1rem 1rem 1rem 5.5rem; /* Исправлено: достаточно места для номера */
    background: rgba(255,255,255,0.05);
    border-radius: var(--border-radius);
    position: relative;
    opacity:0; transform: translateX(-20px);
    animation: fadeInStep 0.6s forwards;
}
.content ol li:nth-child(1) { animation-delay: 0.1s; }
.content ol li:nth-child(2) { animation-delay: 0.3s; }
.content ol li:nth-child(3) { animation-delay: 0.5s; }
.content ol li:nth-child(4) { animation-delay: 0.7s; }
.content ol li:nth-child(5) { animation-delay: 0.9s; }
.content ol li::before {
    content: counter(step);
    position: absolute; left: 1.5rem; top:50%; transform:translateY(-50%);
    width:32px; height:32px;
    background: linear-gradient(135deg,var(--primary-color),var(--secondary-color));
    color:#020617; font-weight:700; border-radius:50%;
    display:flex; align-items:center; justify-content:center;
    box-shadow:0 2px 8px rgba(0,0,0,0.4);
    font-family: var(--font-hand);
    z-index: 2;
}
@keyframes fadeInStep { to { opacity:1; transform:translateX(0); } }

/* ========== NEW: Tables with hover (SEO - CLS) ======== */
table {
    width: 100%;
    border-collapse: collapse;
    margin:2rem 0;
    border-radius: var(--border-radius);
    overflow:hidden;
    transition: var(--transition);
    table-layout: fixed;
}
thead {
    background: linear-gradient(135deg,var(--primary-color),var(--secondary-color));
    color:#020617;
    font-weight:600;
}
th, td {
    padding:0.9rem;
    text-align:left;
    border: 1px solid rgba(255,255,255,0.1);
    word-wrap: break-word;
}
tbody tr {
    background: rgba(255,255,255,0.05);
    transition: var(--transition);
}
tbody tr:nth-child(even) {
    background: rgba(255,255,255,0.08);
}
tbody tr:hover {
    background: rgba(255,255,255,0.15);
}

/* ========== NEW: Alerts / Tips / Warnings with glassmorphism ======== */
.alert {
    margin:2rem 0; padding:1.2rem 1.4rem;
    border-radius: var(--border-radius);
    backdrop-filter: blur(8px);
    border-left:4px solid;
}
.alert.warn { background: rgba(239,68,68,.15); border-color:#ef4444; }
.alert.tip { background: rgba(16,185,129,.15); border-color:#10b981; }

/* ========== NEW: Glass cards for tips / info ======== */
.glass-card {
    padding:1rem 1.2rem;
    background: rgba(255,255,255,0.05);
    border-radius: var(--border-radius);
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.4);
    transition: var(--transition);
    margin:1.5rem 0;
}
.glass-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
}

/* ========== NEW: Code blocks ======== */
pre {
    margin: 2rem 0;
    border-radius: var(--border-radius);
    overflow: auto;
}
code {
    display: block;
    padding: 1.2rem;
    background: rgba(0, 0, 0, 0.6);
    color: #e6e6e6;
    font-family: 'Fira Code', 'Consolas', monospace;
    line-height: 1.5;
    border-left: 4px solid var(--primary-color);
}

/* ========== NEW: Blockquotes ======== */
blockquote {
    margin: 2rem 0;
    padding: 1.2rem 1.5rem;
    background: rgba(255,255,255,0.03);
    border-left: 4px solid var(--accent-color);
    border-radius: 0 var(--border-radius) var(--border-radius) 0;
    font-style: italic;
    color: var(--text-light);
}

/* ========== NEW: Breadcrumbs (SEO) ========== */
.breadcrumbs {
    margin-bottom: 1.5rem;
    padding: 0.8rem 0;
    font-size: 0.9rem;
    color: var(--text-light);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.breadcrumbs a {
    color: var(--primary-color);
    text-decoration: none;
    transition: var(--transition);
    display: flex;
    align-items: center;
}

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

.breadcrumbs-separator {
    color: var(--text-light);
    margin: 0 0.3rem;
    font-size: 1.1rem;
}

.breadcrumbs-current {
    color: var(--text-color);
    font-weight: 500;
}

/* ========== NEW: Оглавление (Table of Contents) - Улучшенная версия ========== */
.toc-container {
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.1), rgba(16, 185, 129, 0.1));
    backdrop-filter: blur(12px);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin: 2rem 0;
    border: 2px solid rgba(14, 165, 233, 0.3);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    /* Убираем sticky чтобы не перекрывало другие элементы */
    position: relative;
    max-height: none;
    overflow-y: visible;
    transition: all 0.3s ease;
    z-index: 10; /* Низкий z-index чтобы не перекрывать другие элементы */
}

.toc-container:hover {
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
    transform: translateY(-2px);
}

/* Заголовок оглавления */
.toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.2rem;
    padding-bottom: 0.8rem;
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
}

.toc-title {
    margin: 0;
    font-size: 1.4rem;
    color: var(--text-color);
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.toc-title::before {
    content: '📖';
    font-size: 1.6rem;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

/* Кнопка сворачивания */
.toc-toggle-btn {
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-size: 1rem;
    padding: 0;
}

.toc-toggle-btn:hover {
    background: var(--primary-color);
    color: #020617;
    transform: rotate(180deg) scale(1.1);
    box-shadow: 0 4px 15px rgba(14, 165, 233, 0.4);
}

.toc-toggle-btn i {
    transition: transform 0.3s ease;
}

/* Список оглавления */
.toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
    counter-reset: toc-counter;
}

.toc-list li {
    margin-bottom: 0.9rem;
    position: relative;
    counter-increment: toc-counter;
}

/* Стиль ссылок в оглавлении */
.toc-link {
    color: var(--text-color);
    text-decoration: none;
    transition: all 0.3s ease;
    display: block;
    padding: 0.8rem 1rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    position: relative;
    overflow: hidden;
    border: 2px solid transparent;
    font-weight: 500;
}

.toc-link::before {
    content: counter(toc-counter);
    position: absolute;
    left: -32px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: #020617;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    opacity: 0.8;
    transition: all 0.3s ease;
}

.toc-link:hover::before {
    left: -28px;
    transform: translateY(-50%) scale(1.2);
    opacity: 1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.toc-link::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 100%;
    background: linear-gradient(90deg, rgba(14, 165, 233, 0.2), rgba(16, 185, 129, 0.2));
    transition: width 0.3s ease;
    z-index: -1;
}

.toc-link:hover::after {
    width: 100%;
}

.toc-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--primary-color);
    transform: translateX(5px);
    border-color: rgba(14, 165, 233, 0.5);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Активный раздел */
.toc-link.active {
    background: rgba(14, 165, 233, 0.2);
    color: var(--primary-color);
    font-weight: 600;
    border-color: var(--primary-color);
    box-shadow: 0 4px 15px rgba(14, 165, 233, 0.3);
    transform: translateX(3px);
}

.toc-link.active::before {
    left: -28px;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    opacity: 1;
    box-shadow: 0 0 12px rgba(14, 165, 233, 0.6);
}

.toc-link.active::after {
    width: 100%;
    background: linear-gradient(90deg, rgba(14, 165, 233, 0.3), rgba(244, 114, 182, 0.2));
}

/* Ссылка на заголовок */
.header-link {
    color: var(--text-light);
    text-decoration: none;
    margin-right: 0.6rem;
    font-size: 0.95rem;
    transition: all 0.3s ease;
    opacity: 0;
    display: inline-block;
    width: 20px;
    text-align: center;
}

h2:hover .header-link {
    opacity: 1;
    animation: fadeInLink 0.3s ease;
}

.header-link:hover {
    color: var(--primary-color);
    transform: scale(1.3) rotate(10deg);
    text-shadow: 0 0 10px rgba(14, 165, 233, 0.5);
}

@keyframes fadeInLink {
    from {
        opacity: 0;
        transform: scale(0.5);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Кнопка "Вернуться к оглавлению" */
.back-to-toc {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin: 1.5rem 0;
    padding: 0.7rem 1.2rem;
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.15), rgba(16, 185, 129, 0.15));
    color: var(--primary-color);
    text-decoration: none;
    border-radius: var(--border-radius);
    font-size: 0.95rem;
    font-weight: 600;
    transition: all 0.3s ease;
    border: 2px solid rgba(14, 165, 233, 0.3);
    width: fit-content;
    z-index: 5; /* Низкий z-index */
    position: relative;
}

.back-to-toc i {
    font-size: 1rem;
}

.back-to-toc:hover {
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.25), rgba(16, 185, 129, 0.25));
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(14, 165, 233, 0.4);
    border-color: var(--primary-color);
}

.back-to-toc:active {
    transform: translateY(-1px);
}

/* Анимация появления оглавления */
@keyframes slideInToc {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Адаптивность оглавления */
@media (max-width: 1024px) {
    .toc-container {
        position: relative;
        max-height: none;
        margin: 1.5rem 0;
    }
    
    .toc-title {
        font-size: 1.2rem;
    }
}

@media (max-width: 768px) {
    .toc-container {
        padding: 1rem;
    }
    
    .toc-header {
        flex-direction: column;
        gap: 0.8rem;
    }
    
    .toc-toggle-btn {
        width: 32px;
        height: 32px;
    }
    
    .toc-link {
        padding: 0.7rem 0.9rem;
        font-size: 0.9rem;
    }
    
    .toc-link::before {
        width: 22px;
        height: 22px;
        font-size: 0.8rem;
    }
    
    .back-to-toc {
        font-size: 0.9rem;
        padding: 0.6rem 1rem;
    }
}

/* ========== NEW: Progress bar ========== */
.reading-progress-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    z-index: 9999;
}

.reading-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
    width: 0%;
    transition: width 0.3s ease;
}

/* ========== NEW: Copy buttons for code blocks ========== */
.code-block-wrapper {
    position: relative;
    margin: 2rem 0;
}

.copy-btn {
    position: absolute;
    top: 0.8rem;
    right: 0.8rem;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    border: none;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: var(--transition);
    z-index: 10;
    font-family: var(--font-main);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.copy-btn:hover {
    background: var(--primary-color);
    transform: scale(1.05);
}

.copy-btn.copied {
    background: var(--secondary-color);
}

/* ========== Animations ========== */
@keyframes pulseHighlight {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(14, 165, 233, 0);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(14, 165, 233, 0.2);
    }
}