/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ===== VARIABLES ===== */
:root {
    --bg: #F6F6F6;
    --bg-elevated: #FFFFFF;
    --bg-quote: #FFFFFF;
    --bg-card: #FFFFFF;
    --bg-card-hover: #FAFAFA;
    --border: #EAEAEA;
    --border-light: #818181;
    --text: #1E1E1E;
    --text-secondary: #303030;
    --text-dim: #353535;
    --accent: #A8A8A8;
    --accent-hover: #8A8A8A;
    --sidebar-w: 280px;
    --header-h: 56px;
    --content-max: 720px;
    --font-display: 'Unbounded', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-mono: 'Inter', sans-serif;
}

/* ===== BASE ===== */
html { /* scroll-behavior managed by JS to avoid race conditions */ }
body {
    background: var(--bg); color: var(--text);
    font-family: var(--font-body); font-size: 18px; line-height: 1.75;
    -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #2a2a2a; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
::selection { background: var(--accent); color: var(--text); }
a { color: inherit; }

/* ===== SIDEBAR ===== */
.sidebar {
    position: fixed; top: 0; left: 0;
    width: var(--sidebar-w); height: 100vh;
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    z-index: 100; display: flex; flex-direction: column;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar-brand {
    padding: 20px 20px 12px;
    font-family: var(--font-display); font-weight: 900; font-size: 22px;
    color: var(--text); line-height: 1.2;
    border-bottom: 1px solid var(--border);
}
.sidebar-brand a { text-decoration: none; color: inherit; }
.sidebar-brand small {
    display: block; font-family: var(--font-mono); font-weight: 400;
    font-size: 10px; letter-spacing: 2.5px; text-transform: uppercase;
    color: var(--text-dim); margin-top: 6px;
}

/* Sidebar top nav (Главная / О проекте / Словарь) — hidden on desktop */
.sidebar-top-nav { display: none; }

/* Hidden in niksheh layout — desktop uses header-nav */
.sidebar-intro-link { display: none; }
.sidebar-label { display: none; }
.sidebar-nav {
    list-style: none; overflow-y: auto; flex: 1; padding-bottom: 24px;
}
.sidebar-nav li a {
    display: flex; align-items: baseline; gap: 10px;
    padding: 5px 20px;
    font-family: var(--font-mono); font-size: 13px; font-weight: 400;
    color: var(--text-dim); text-decoration: none;
    transition: all 0.15s ease; border-left: 2px solid transparent;
}
.sidebar-nav li a .nav-index {
    font-size: 10px; color: #333; min-width: 18px; transition: color 0.15s;
}
.sidebar-nav li a:hover { color: var(--text-secondary); }
.sidebar-nav li a:hover .nav-index { color: var(--text-dim); }
.sidebar-nav li a.active {
    color: var(--text); border-left-color: var(--accent);
    background: rgba(139, 37, 0, 0.06);
}
.sidebar-nav li a.active .nav-index { color: var(--accent); }

.sidebar-nav li {
    opacity: 0; transform: translateX(-8px);
    animation: navReveal 0.4s ease forwards;
}
@keyframes navReveal { to { opacity: 1; transform: translateX(0); } }

/* ===== MOBILE MENU ===== */
.menu-toggle {
    display: none; position: fixed; top: 14px; left: 16px; z-index: 200;
    width: 40px; height: 40px;
    background: var(--bg-elevated); border: 1px solid var(--border);
    border-radius: 4px; cursor: pointer;
    flex-direction: column; align-items: center; justify-content: center; gap: 5px;
}
.menu-toggle span {
    display: block; width: 20px; height: 1.5px;
    background: var(--text-dim); transition: all 0.3s;
}
.menu-toggle.open span:nth-child(1) { transform: rotate(45deg) translate(4.5px, 4.5px); }
.menu-toggle.open span:nth-child(2) { opacity: 0; }
.menu-toggle.open span:nth-child(3) { transform: rotate(-45deg) translate(4.5px, -4.5px); }
.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.6); z-index: 90;
}
.sidebar-overlay.open { display: block; }

/* ===== MAIN ===== */
.main { margin-left: var(--sidebar-w); min-height: 100vh; }

/* ===== HEADER ===== */
.header {
    position: sticky; top: 0; z-index: 50;
    background: rgba(255, 255, 255, 0.93);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    padding: 0 48px; height: var(--header-h);
    display: flex; align-items: center;
}
.header-inner {
    display: flex; align-items: center; justify-content: flex-start;
    max-width: calc(var(--content-max) + 96px); width: 100%;
}
.header-brand { display: none; }
.header-brand-title {
    font-family: var(--font-display); font-weight: 900; font-size: 24px;
    color: var(--text); text-decoration: none; line-height: 1.2;
}
.header-brand-sub {
    display: block; font-family: var(--font-mono); font-weight: 400;
    font-size: 10px; letter-spacing: 2px; text-transform: uppercase;
    color: var(--text-dim); margin-top: 2px;
}
.header-nav {
    display: flex; gap: 24px;
}
.header-nav a {
    font-family: var(--font-body); font-size: 15px;
    color: var(--text-secondary); text-decoration: none;
    transition: color 0.2s;
}
.header-nav a.active,
.sidebar-top-nav a.active { color: var(--text); }
.header-nav a:hover { color: var(--text); }

.header-title { display: none; }
.header-current { display: none; }

/* ===== PROJECT INTRO (index page) ===== */
.project-intro {
    padding: 40px 48px 32px;
    max-width: calc(var(--content-max) + 96px);
}
.project-intro p {
    font-size: 18px; line-height: 1.75;
    color: var(--text);
}
.project-intro strong {
    font-weight: 700;
}

/* ===== HERO ===== */
.hero {
    padding: 100px 48px 60px;
    max-width: calc(var(--content-max) + 96px);
}
.hero.hero-no-title {
    padding-top: 44px;
    padding-bottom: 44px;
}
.hero.hero-no-title .hero-line { margin-bottom: 16px; }
.hero-title {
    font-family: var(--font-display); font-weight: 900;
    font-size: clamp(52px, 7vw, 88px); line-height: 1.0;
    color: var(--text); margin-bottom: 32px;
    opacity: 0; transform: translateY(16px);
    animation: contentReveal 0.6s ease 0.15s forwards;
}
.hero-title em { font-style: italic; color: var(--accent); }
.hero-line {
    width: 80px; height: 2px; background: var(--accent); margin-bottom: 24px;
    opacity: 0; animation: contentReveal 0.6s ease 0.3s forwards;
}
.hero-meta {
    font-family: var(--font-mono); font-size: 13px;
    color: var(--text-dim); letter-spacing: 2px; text-transform: uppercase;
    opacity: 0; animation: contentReveal 0.6s ease 0.4s forwards;
}
@keyframes contentReveal { to { opacity: 1; transform: translateY(0); } }

/* ===== EPIGRAPH ===== */
.epigraph {
    padding: 48px 48px 64px;
    max-width: calc(var(--content-max) + 96px);
}
.epigraph blockquote {
    font-family: var(--font-body); font-style: italic;
    font-size: 19px; line-height: 1.8; color: var(--text-secondary);
    padding: 32px 32px 32px 36px;
    background: var(--bg-quote); border-left: 3px solid var(--accent);
    position: relative;
}
/* ===== INTRODUCTION ===== */
.introduction {
    padding: 0 48px 60px;
    max-width: calc(var(--content-max) + 96px);
}
.introduction p { margin-bottom: 20px; color: var(--text-secondary); }
.introduction .note {
    font-family: var(--font-mono); font-size: 14px; color: var(--text-dim);
    margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--border);
}

/* ===== TERM DIRECTORY (index page) ===== */
.term-directory { padding: 0 48px 80px; max-width: 1100px; }
.directory-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1px; background: var(--border); border: 1px solid var(--border);
}
.term-card {
    display: block; padding: 24px; background: var(--bg-card);
    text-decoration: none; transition: background 0.2s;
}
.term-card:hover { background: var(--bg-card-hover); }
.term-card-index {
    font-family: var(--font-mono); font-size: 11px;
    color: var(--accent); letter-spacing: 2px; display: block; margin-bottom: 8px;
}
.term-card h2 {
    font-family: var(--font-display); font-weight: 700;
    font-size: 22px; line-height: 1.2; color: var(--text); margin-bottom: 4px;
}
.term-card-sub {
    font-family: var(--font-mono); font-size: 12px;
    color: var(--text-dim); display: block; margin-bottom: 8px;
}
.term-card p {
    font-family: var(--font-body); font-size: 14px; line-height: 1.6;
    color: var(--text-dim);
    display: -webkit-box; -webkit-line-clamp: 3;
    -webkit-box-orient: vertical; overflow: hidden;
}

/* ===== LONGREAD TERMS ===== */
.terms-longread {
    max-width: calc(var(--content-max) + 96px);
}
.term-section {
    padding: 72px 48px 48px;
    position: relative;
    opacity: 0; transform: translateY(20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}
.term-section.visible { opacity: 1; transform: translateY(0); }
.term-section::before {
    content: ''; position: absolute; top: 0;
    left: 48px; right: 48px; height: 1px;
    background: var(--border);
}

/* ===== TERM PAGE (individual) ===== */
.term-page {
    padding: 72px 48px 48px;
    max-width: calc(var(--content-max) + 96px);
}

/* ===== SHARED TERM STYLES ===== */
.term-index {
    font-family: var(--font-mono); font-size: 11px; font-weight: 500;
    color: var(--accent); letter-spacing: 3px; margin-bottom: 12px;
}
.term-title {
    font-family: var(--font-display); font-weight: 900;
    font-size: clamp(36px, 5vw, 56px); line-height: 1.1;
    margin-bottom: 12px; color: var(--text);
}
.term-subtitle {
    font-family: var(--font-mono); font-size: 14px;
    color: var(--text-dim); margin-bottom: 32px;
}
.term-body { margin-top: 24px; }
.term-body p { margin-bottom: 20px; }
.term-body figure.term-figure {
    margin: 32px 0 36px;
}
.term-body figure.term-figure img {
    display: block;
    width: 100%;
    max-width: min(100%, 960px);
    height: auto;
    margin: 0 auto;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
}
.term-body figure.term-figure figcaption {
    max-width: 820px;
    margin: 12px auto 0;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-dim);
    text-align: center;
}
.term-body blockquote {
    margin: 28px 0; padding: 20px 24px 20px 28px;
    background: var(--bg-quote); border-left: 3px solid var(--accent);
    font-family: var(--font-mono); font-size: 14.5px;
    line-height: 1.75; color: var(--text-secondary);
}
.term-body blockquote p { margin-bottom: 0; }
.term-body .see-also {
    margin-top: 36px; font-family: var(--font-body);
    font-size: inherit; line-height: inherit; color: var(--text-secondary);
}
.cross-ref, .term-body .see-also a {
    color: var(--accent); text-decoration: none;
    border-bottom: 1px solid rgba(139,37,0,0.4); transition: all 0.2s;
}
.cross-ref:hover, .term-body .see-also a:hover {
    color: var(--accent-hover); border-bottom-color: var(--accent-hover);
}

/* ===== LAZY-LOAD PLACEHOLDER ===== */
.term-placeholder {
    min-height: 120px;
    display: flex; align-items: center; justify-content: center;
}
.term-loader {
    width: 24px; height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== TERM NAVIGATION (individual pages) ===== */
.term-nav {
    display: flex; align-items: stretch; justify-content: space-between;
    border-top: 1px solid var(--border);
    margin: 0 48px; max-width: var(--content-max);
}
.term-nav-link {
    display: flex; flex-direction: column; padding: 24px 0;
    text-decoration: none; transition: color 0.2s; max-width: 45%;
}
.term-nav-next { align-items: flex-end; text-align: right; }
.term-nav-dir {
    font-family: var(--font-mono); font-size: 11px;
    letter-spacing: 2px; text-transform: uppercase;
    color: var(--text-dim); margin-bottom: 4px;
}
.term-nav-name {
    font-family: var(--font-display); font-size: 20px;
    font-weight: 700; color: var(--text-secondary); transition: color 0.2s;
}
.term-nav-link:hover .term-nav-name { color: var(--text); }
.term-nav-home {
    font-family: var(--font-mono); font-size: 12px;
    color: var(--text-dim); text-decoration: none;
    align-self: center; padding: 8px 16px;
    border: 1px solid var(--border); border-radius: 4px; transition: all 0.2s;
}
.term-nav-home:hover { color: var(--text-secondary); border-color: var(--border-light); }

/* ===== FOOTER ===== */
.footer {
    padding: 60px 48px;
    max-width: calc(var(--content-max) + 96px);
    border-top: 1px solid var(--border);
    font-family: var(--font-mono); font-size: 12px;
    color: var(--text-dim); line-height: 1.8;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
    .menu-toggle { display: flex; }
    .sidebar { transform: translateX(-100%); width: 100%; }
    .sidebar.open { transform: translateX(0); box-shadow: none; }
    .sidebar-top-nav {
        display: flex; gap: 20px;
        padding: 12px 20px;
        border-bottom: 1px solid var(--border);
    }
    .sidebar-top-nav a {
        font-family: var(--font-body); font-size: 14px;
        color: var(--text-secondary); text-decoration: none;
    }
    .sidebar-top-nav a:hover { color: var(--text); }
    .main { margin-left: 0; }
    /* sidebar brand: отступ чтобы крестик не налезал, одна строка */
    .sidebar-brand {
        padding-left: 68px;
        font-size: 20px;
    }
    .sidebar-brand a br { display: none; }
    .header {
        height: auto; padding: 14px 16px;
        flex-direction: column; align-items: flex-start;
        backdrop-filter: none; -webkit-backdrop-filter: none;
        background: var(--bg-elevated);
    }
    .header-inner {
        flex-direction: column; align-items: flex-start;
        justify-content: flex-start;
    }
    .header-brand {
        display: block; margin-bottom: 0;
        padding-left: 52px;
    }
    /* nav — только в бургере, со страницы убрать */
    .header-nav { display: none; }
    /* sidebar-top-nav: горизонталь, без переноса слов */
    .sidebar-top-nav {
        display: flex; gap: 20px;
        padding: 12px 20px;
        border-bottom: 1px solid var(--border);
    }
    .sidebar-top-nav a {
        font-family: var(--font-body); font-size: 14px;
        color: var(--text-secondary); text-decoration: none;
        white-space: nowrap;
    }
    .sidebar-top-nav a:hover { color: var(--text); }
    .sidebar-top-nav a.active { color: var(--text); }
    .project-intro { padding: 32px 24px 24px; }
    .hero { padding: 96px 24px 48px; }
    .hero.hero-no-title { padding-top: 40px; padding-bottom: 36px; }
    .hero-title { font-size: clamp(40px, 10vw, 64px); }
    .epigraph { padding: 32px 24px 48px; }
    .introduction { padding: 0 24px 48px; }
    .term-directory { padding: 0 24px 60px; }
    .directory-grid { grid-template-columns: 1fr; }
    .term-page { padding: 72px 24px 48px; }
    .term-section { padding: 72px 24px 48px; }
    .term-section::before { left: 24px; right: 24px; }
    .term-nav { margin: 0 24px; flex-wrap: wrap; gap: 16px; }
    .term-nav-home { order: -1; width: 100%; text-align: center; }
    .footer { padding: 40px 24px; }
}
@media (max-width: 480px) {
    body { font-size: 16px; }
    .hero-title { font-size: clamp(32px, 12vw, 48px); }
    .term-title { font-size: clamp(28px, 8vw, 40px); }
    .term-body figure.term-figure { margin: 24px 0 28px; }
    .term-body figure.term-figure figcaption {
        margin-top: 10px;
        font-size: 11px;
        line-height: 1.55;
        text-align: left;
    }
    .term-body blockquote { padding: 16px 16px 16px 20px; font-size: 13.5px; }
    .epigraph blockquote { padding: 24px 20px 24px 24px; font-size: 17px; }
    .term-card h2 { font-size: 18px; }
}

/* ===== ACCESSIBILITY ===== */
.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;}
