/* Блоки кода в статьях блога, уроках и книгах */
:root {
    --code-font: 'JetBrains Mono', ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'Courier New', monospace;
    --code-bg: #0f172a;
    --code-border: #1e293b;
    --code-text: #e2e8f0;
    --code-muted: #94a3b8;
    --code-inline-bg: #f1f5f9;
    --code-inline-text: #be185d;
    --code-inline-border: #e2e8f0;
    --code-accent: #E86B4E;
    --code-shadow: 0 8px 30px rgba(15, 23, 42, 0.14);
}

.dark-theme {
    --code-inline-bg: #2d333b;
    --code-inline-text: #f97583;
    --code-inline-border: #3d4450;
    --code-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

.post-content-html,
.book-chapter-body,
.book-chapter-content,
.lesson-description {
    --content-code-scope: 1;
}

/* ——— Блочный код: <pre> ——— */
.post-content-html pre,
.book-chapter-body pre,
.book-chapter-content pre,
.lesson-description pre,
.book-code-example pre {
    background: var(--code-bg);
    border: 1px solid var(--code-border);
    border-radius: 12px;
    margin: 1.35rem 0 1.6rem;
    padding: 0;
    overflow: hidden;
    box-shadow: var(--code-shadow);
    position: relative;
}

.post-content-html pre::before,
.book-chapter-body pre::before,
.book-chapter-content pre::before,
.lesson-description pre::before,
.book-code-example:not(:has(.book-code-label))::before {
    content: '';
    display: block;
    height: 3px;
    background: linear-gradient(90deg, var(--code-accent) 0%, #f59e0b 55%, #38bdf8 100%);
}

.post-content-html pre code,
.book-chapter-body pre code,
.book-chapter-content pre code,
.lesson-description pre code,
.book-code-example pre code {
    display: block;
    margin: 0;
    padding: 1.05rem 1.2rem 1.15rem;
    overflow-x: auto;
    color: var(--code-text);
    font-family: var(--code-font);
    font-size: 0.84rem;
    font-weight: 400;
    line-height: 1.65;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    white-space: pre;
    tab-size: 4;
    -webkit-font-smoothing: antialiased;
}

/* ——— Блочный код: <code class="code"> без <pre> (старые статьи) ——— */
.post-content-html code.code,
.book-chapter-body code.code,
.book-chapter-content code.code,
.lesson-description code.code {
    display: block;
    background: var(--code-bg);
    border: 1px solid var(--code-border);
    border-radius: 12px;
    margin: 1.35rem 0 1.6rem;
    padding: 1.05rem 1.2rem 1.15rem;
    overflow-x: auto;
    color: var(--code-text);
    font-family: var(--code-font);
    font-size: 0.84rem;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
    box-shadow: var(--code-shadow);
    position: relative;
}

.post-content-html code.code::before,
.book-chapter-body code.code::before,
.book-chapter-content code.code::before,
.lesson-description code.code::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: 12px 12px 0 0;
    background: linear-gradient(90deg, var(--code-accent) 0%, #f59e0b 55%, #38bdf8 100%);
}

.post-content-html pre code.code,
.book-chapter-body pre code.code,
.book-chapter-content pre code.code,
.lesson-description pre code.code {
    margin: 0;
    padding: 1.05rem 1.2rem 1.15rem;
    border: none;
    border-radius: 0;
    box-shadow: none;
    white-space: pre;
}

.post-content-html pre code.code::before,
.book-chapter-body pre code.code::before,
.book-chapter-content pre code.code::before,
.lesson-description pre code.code::before {
    display: none;
}

/* ——— Инлайн-код в тексте ——— */
.post-content-html :not(pre) > code,
.book-chapter-body :not(pre) > code,
.book-chapter-content :not(pre) > code,
.lesson-description :not(pre) > code {
    display: inline;
    padding: 0.14em 0.42em;
    margin: 0 0.05em;
    font-family: var(--code-font);
    font-size: 0.86em;
    font-weight: 500;
    line-height: 1.45;
    color: var(--code-inline-text);
    background: var(--code-inline-bg);
    border: 1px solid var(--code-inline-border);
    border-radius: 6px;
    white-space: nowrap;
    vertical-align: baseline;
    word-break: normal;
}

.post-content-html p > code,
.book-chapter-body p > code,
.book-chapter-content p > code,
.lesson-description p > code {
    white-space: normal;
    word-break: break-word;
}

/* ——— Обёртка с подписью (книги) ——— */
.book-code-example {
    background: var(--code-bg);
    border-radius: 12px;
    margin: 1.35rem 0 1.6rem;
    overflow: hidden;
    border: 1px solid var(--code-border);
    box-shadow: var(--code-shadow);
}

.book-code-label {
    background: #1e293b;
    color: var(--code-muted);
    font-family: var(--code-font);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    padding: 0.55rem 1rem;
    text-transform: uppercase;
    border-bottom: 1px solid var(--code-border);
}

.book-code-example pre {
    margin: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

.book-code-example pre::before {
    display: none;
}

/* ——— Скроллбар в блоках кода ——— */
.post-content-html pre code::-webkit-scrollbar,
.book-chapter-body pre code::-webkit-scrollbar,
.post-content-html code.code::-webkit-scrollbar,
.book-chapter-body code.code::-webkit-scrollbar {
    height: 8px;
}

.post-content-html pre code::-webkit-scrollbar-thumb,
.book-chapter-body pre code::-webkit-scrollbar-thumb,
.post-content-html code.code::-webkit-scrollbar-thumb,
.book-chapter-body code.code::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 4px;
}

/* ——— Тёмная тема: текст статьи рядом с кодом ——— */
.dark-theme .post-content-html,
.dark-theme .book-chapter-body,
.dark-theme .book-chapter-content {
    color: #d1d5db;
}

.dark-theme .post-content-html h2,
.dark-theme .post-content-html h3,
.dark-theme .post-content-html h4,
.dark-theme .book-chapter-body h2,
.dark-theme .book-chapter-body h3,
.dark-theme .book-chapter-body h4 {
    color: #f3f4f6;
}
