:root {
    color-scheme: dark;
    --bg: #060a12;
    --surface: rgba(10, 15, 24, 0.95);
    --surface-soft: rgba(255, 255, 255, 0.04);
    --surface-strong: rgba(15, 22, 33, 0.98);
    --text: #e9edf4;
    --muted: #8f9db0;
    --accent: #86b9e8;
    --accent-strong: #63a8e0;
    --success: #6fe8a0;
    --warning: #f5b86c;
    --danger: #ef7e7e;
    --border: rgba(134, 187, 236, 0.14);
    --shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
    --radius: 16px;
    --transition: 0.18s ease;
    font-family: 'Manrope', 'Inter', system-ui, sans-serif;
    --heading-font: 'Montserrat', 'Manrope', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
    margin: 0;
    min-height: 100%;
    background: linear-gradient(180deg, #060a12 0%, #05070d 100%);
    color: var(--text);
    line-height: 1.6;
    overflow-x: hidden;
}
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: linear-gradient(90deg, rgba(134, 185, 232, 0.03), transparent 40%, rgba(134, 185, 232, 0.025));
    pointer-events: none;
    z-index: -2;
}

img { max-width: 100%; display: block; }
button, a { font: inherit; }

.page-shell {
    position: relative;
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 1.5rem 3.5rem;
}

/* ===== Topbar ===== */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 2rem 0 1.2rem;
    flex-wrap: wrap;
}
.brand {
    font-family: var(--heading-font);
    font-size: 0.92rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3em;
    color: var(--accent-strong);
    text-decoration: none;
}
.topbar-actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.lang-switch {
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    padding: 0.5rem 0.8rem;
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.86rem;
    font-family: var(--heading-font);
    letter-spacing: 0.08em;
    transition: background-color var(--transition), border-color var(--transition);
}
.lang-switch:hover { background: rgba(255, 255, 255, 0.08); border-color: rgba(130, 199, 255, 0.24); }

.topnav { display: flex; gap: 1.2rem; flex-wrap: wrap; align-items: center; }
.topnav > a { color: var(--muted); text-decoration: none; transition: color var(--transition); font-size: 0.95rem; }
.topnav > a:hover { color: var(--text); }

/* ===== Dropdown статей ===== */
.articles-dropdown { position: relative; }
.articles-trigger {
    display: inline-flex; align-items: center; gap: 0.45rem;
    background: none; border: none; color: var(--muted);
    cursor: pointer; padding: 0.3rem 0.1rem; font-size: 0.95rem;
    transition: color var(--transition);
}
.articles-trigger:hover,
.articles-dropdown.open .articles-trigger { color: var(--text); }
.articles-chevron { transition: transform var(--transition); }
.articles-dropdown.open .articles-chevron { transform: rotate(180deg); }
.articles-menu {
    position: absolute; top: calc(100% + 0.6rem); right: 0;
    min-width: 340px;
    background: var(--surface-strong);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 0.5rem;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
    opacity: 0; visibility: hidden; transform: translateY(-6px);
    transition: opacity var(--transition), transform var(--transition), visibility var(--transition);
    z-index: 100;
}
.articles-menu.open { opacity: 1; visibility: visible; transform: translateY(0); }
.articles-menu-item {
    display: flex; align-items: center; gap: 0.8rem;
    padding: 0.8rem 1rem; border-radius: 10px;
    color: var(--text); text-decoration: none;
    transition: background-color var(--transition);
}
.articles-menu-item:hover { background: var(--surface-soft); }
.articles-menu-item-label { font-size: 1.15rem; line-height: 1; }
.articles-menu-item-text { font-size: 0.92rem; line-height: 1.4; }

/* ===== Hero статьи ===== */
.article-hero { padding: 3.5rem 0 2.5rem; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.article-meta { display: flex; gap: 1rem; align-items: center; color: var(--muted); font-size: 0.85rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.article-meta-pill { padding: 0.3rem 0.8rem; border-radius: 999px; background: rgba(130, 199, 255, 0.12); color: var(--accent); font-size: 0.78rem; letter-spacing: 0.06em; }
.article-hero h1 {
    margin: 0 0 1rem;
    font-family: var(--heading-font);
    font-size: clamp(1.9rem, 4vw, 3.4rem);
    line-height: 1.08;
    font-weight: 700;
    letter-spacing: -0.02em;
    max-width: 18ch;
}
.article-hero p { margin: 0; color: var(--muted); font-size: 1.08rem; max-width: 62ch; }

/* ===== Контент ===== */
.article-content { display: grid; gap: 3rem; padding: 3rem 0; }
.article-section { display: grid; gap: 1rem; }
.article-section-label { color: var(--accent); text-transform: uppercase; font-family: var(--heading-font); letter-spacing: 0.18em; font-size: 0.78rem; font-weight: 600; }
.article-section h2 { margin: 0; font-family: var(--heading-font); font-size: clamp(1.4rem, 2.2vw, 2rem); line-height: 1.15; font-weight: 600; letter-spacing: -0.01em; }
.article-section p { color: var(--muted); font-size: 1rem; max-width: 72ch; margin: 0; }

/* ===== Симуляции ===== */
.simulation {
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.6rem;
    box-shadow: var(--shadow);
}
.simulation-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.simulation-title { font-family: var(--heading-font); font-size: 1.05rem; font-weight: 600; margin: 0; }
.simulation-controls { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.btn {
    padding: 0.55rem 1rem;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 500;
    transition: all var(--transition);
}
.btn:hover { background: rgba(255, 255, 255, 0.08); border-color: rgba(130, 199, 255, 0.24); }
.btn.active { background: rgba(130, 199, 255, 0.18); border-color: rgba(130, 199, 255, 0.4); color: var(--accent); }
.btn-bot.active { background: rgba(239, 126, 126, 0.18); border-color: rgba(239, 126, 126, 0.4); color: var(--danger); }
.btn-human.active { background: rgba(111, 232, 160, 0.18); border-color: rgba(111, 232, 160, 0.4); color: var(--success); }

.btn-play {
    padding: 0.6rem 1.2rem;
    border-radius: 999px;
    background: rgba(130, 199, 255, 0.16);
    border: 1px solid rgba(130, 199, 255, 0.3);
    color: var(--accent);
    cursor: pointer;
    font-weight: 600;
    transition: all var(--transition);
}
.btn-play:hover { background: rgba(130, 199, 255, 0.24); transform: translateY(-1px); }
.btn-play:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.canvas-wrap {
    position: relative;
    width: 100%;
    background: #03060c;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.05);
}
.canvas-wrap canvas { display: block; }

.simulation-legend { display: flex; gap: 1.2rem; flex-wrap: wrap; margin-top: 1rem; font-size: 0.85rem; color: var(--muted); }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 0.5rem; vertical-align: middle; }

.simulation-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0.8rem; margin-top: 1rem; }
.stat-box { background: rgba(255, 255, 255, 0.03); border: 1px solid rgba(255, 255, 255, 0.06); border-radius: 10px; padding: 0.8rem 1rem; min-width: 0; }
.stat-label { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em; display: block; margin-bottom: 0.3rem; }
.stat-value { font-size: 1.1rem; font-weight: 600; color: var(--text); word-break: break-word; }

/* ===== Калькулятор + кастомные select ===== */
.calculator-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; align-items: start; }
.calc-form { display: grid; gap: 1rem; }
.calc-field { display: grid; gap: 0.4rem; }
.calc-label { font-size: 0.82rem; color: var(--muted); letter-spacing: 0.06em; }

.cselect { position: relative; }
.cselect-btn {
    width: 100%;
    display: flex; align-items: center; justify-content: space-between; gap: 0.8rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text);
    padding: 0.7rem 0.95rem;
    border-radius: 10px;
    font-size: 0.95rem;
    cursor: pointer;
    text-align: left;
    transition: border-color var(--transition), background-color var(--transition);
}
.cselect-btn:hover { background: rgba(255, 255, 255, 0.07); }
.cselect.open .cselect-btn { border-color: var(--accent); background: rgba(130, 199, 255, 0.08); }
.cselect-chevron { transition: transform var(--transition); flex: 0 0 auto; color: var(--muted); }
.cselect.open .cselect-chevron { transform: rotate(180deg); }
.cselect-list {
    position: absolute; top: calc(100% + 0.4rem); left: 0; right: 0;
    background: var(--surface-strong);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.35rem;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
    opacity: 0; visibility: hidden; transform: translateY(-4px);
    transition: opacity var(--transition), transform var(--transition), visibility var(--transition);
    z-index: 60;
    max-height: 240px;
    overflow: auto;
}
.cselect.open .cselect-list { opacity: 1; visibility: visible; transform: translateY(0); }
.cselect-option {
    display: flex; width: 100%; text-align: left;
    background: none; border: none;
    color: var(--muted);
    padding: 0.6rem 0.8rem;
    border-radius: 8px;
    font-size: 0.92rem;
    cursor: pointer;
    transition: background-color var(--transition), color var(--transition);
}
.cselect-option:hover { background: var(--surface-soft); color: var(--text); }
.cselect-option.selected { color: var(--accent); background: rgba(130, 199, 255, 0.1); }
.cselect-option.selected::after { content: '✓'; margin-left: auto; }

.calc-result {
    background: linear-gradient(135deg, rgba(130, 199, 255, 0.08), rgba(130, 199, 255, 0.02));
    border: 1px solid rgba(130, 199, 255, 0.2);
    border-radius: 12px;
    padding: 1.3rem;
}
.calc-result h4 { margin: 0 0 0.6rem; font-size: 0.78rem; color: var(--accent); text-transform: uppercase; letter-spacing: 0.14em; }
.calc-strategy { font-family: var(--heading-font); font-size: 1.3rem; font-weight: 700; margin-bottom: 0.8rem; line-height: 1.25; }
.calc-reason { color: var(--muted); font-size: 0.95rem; line-height: 1.65; margin: 0; }
.calc-stack { margin-top: 1rem; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.calc-stack-item {
    padding: 0.25rem 0.7rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    font-size: 0.78rem;
    color: var(--text);
    font-family: ui-monospace, 'JetBrains Mono', monospace;
}

/* ===== Таблица стека ===== */
.table-scroll { overflow-x: auto; }
.stack-table { width: 100%; min-width: 520px; border-collapse: collapse; background: rgba(255, 255, 255, 0.02); border-radius: 12px; overflow: hidden; }
.stack-table th, .stack-table td { padding: 0.9rem 1rem; text-align: left; border-bottom: 1px solid rgba(255, 255, 255, 0.05); }
.stack-table th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.12em; font-weight: 600; background: rgba(255, 255, 255, 0.03); }
.stack-table td { color: var(--text); font-size: 0.95rem; }
.stack-table td:first-child { font-family: ui-monospace, monospace; color: var(--accent); white-space: nowrap; }
.stack-table td:last-child { color: var(--muted); font-size: 0.9rem; }

/* ===== Подходы ===== */
.approaches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.approach-card { background: rgba(255, 255, 255, 0.03); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 12px; padding: 1.2rem; transition: all var(--transition); }
.approach-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.approach-card h4 { margin: 0 0 0.4rem; font-size: 1rem; }
.approach-card p { margin: 0 0 0.8rem; font-size: 0.88rem; color: var(--muted); }
.approach-pros, .approach-cons { font-size: 0.85rem; margin: 0.3rem 0; padding-left: 1.2rem; color: var(--muted); }
.approach-pros li::marker { color: var(--success); }
.approach-cons li::marker { color: var(--danger); }

/* ===== Контакты ===== */
.contact-panel { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; align-items: start; }
.contact-card {
    background: rgba(255, 255, 255, 0.035);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 16px;
    padding: 1.45rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    transition: transform var(--transition), border-color var(--transition), background-color var(--transition);
}
.contact-card:hover { transform: translateY(-2px); border-color: rgba(130, 199, 255, 0.2); }
.contact-card span { display: block; margin-bottom: 0.9rem; color: var(--accent); text-transform: uppercase; letter-spacing: 0.16em; font-size: 0.78rem; }
.contact-card a { text-decoration: none; color: var(--text); }
.contact-card a:hover { color: var(--accent-strong); }

.footer { text-align: center; padding: 2rem 0 0; color: var(--muted); }
.footer a { color: var(--accent); text-decoration: none; }
.footer a:hover { color: var(--accent-strong); }

/* ===== Адаптив ===== */
@media (max-width: 980px) {
    .calculator-grid { grid-template-columns: 1fr; }
    .approaches { grid-template-columns: 1fr; }
    .contact-panel { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
    .page-shell { padding: 0 1rem 2.5rem; }
    .simulation { padding: 1.2rem; }
    .article-hero { padding: 2rem 0 1.5rem; }
    .stack-table th, .stack-table td { padding: 0.7rem 0.7rem; }
}

@media (max-width: 560px) {
    .topnav { gap: 0.9rem; }
    .article-hero h1 { font-size: 1.8rem; max-width: none; }
    .simulation-header { flex-direction: column; align-items: stretch; }
    .simulation-controls { width: 100%; }
    .simulation-controls .btn,
    .simulation-controls .btn-play { flex: 1 1 auto; text-align: center; justify-content: center; }
    .simulation-stats { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    * { transition: none !important; animation: none !important; }
}


/* ===== Выравнивание кнопки «Статьи» по линии меню ===== */
.topnav {
    align-items: center;
}

.articles-dropdown {
    display: flex;
    align-items: center;
}

.articles-trigger {
    padding: 0 0.1rem;
    line-height: 1.6;
}

/* ===== FIX: мобильный overflow ===== */
.article-content > *,
.article-section > *,
.simulation,
.simulation-header,
.simulation-controls,
.canvas-wrap,
.calc-form,
.calc-result,
.table-scroll {
    min-width: 0;
}

.canvas-wrap canvas {
    max-width: 100%;
}

.table-scroll {
    max-width: 100%;
}

@media (max-width: 680px) {
    .topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.9rem;
        padding-top: 1.5rem;
    }
    .topbar-actions {
        width: 100%;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.9rem;
    }
    .topnav {
        width: 100%;
        gap: 0.8rem 1.1rem;
    }
}

@media (max-width: 560px) {
    .article-meta { gap: 0.6rem; }
    .simulation-controls .btn,
    .simulation-controls .btn-play {
        flex: 1 1 30%;
        min-width: 96px;
        text-align: center;
        justify-content: center;
    }
}

/* ===== FIX: мобильное меню — панель под навигацией, а не внизу экрана ===== */
@media (max-width: 680px) {
    .topnav {
        position: relative;
        align-items: flex-start;
    }
    .articles-dropdown {
        position: static;
        display: block;
    }
    .articles-menu {
        position: absolute;
        top: calc(100% + 0.6rem);
        left: 0;
        right: 0;
        min-width: 0;
        width: auto;
        border-radius: 12px;
        transform: translateY(-6px);
    }
    .articles-menu.open {
        transform: translateY(0);
    }
    .articles-menu-item {
        align-items: flex-start;
        padding: 0.75rem 0.9rem;
    }
    .articles-menu-item-text {
        white-space: normal;
        line-height: 1.45;
    }
}