/* بلوک کد و رنگ‌آمیزی سینتکس — روشن / تاریک */

:root,
[data-theme="light"] {
    --font-mono: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
    --code-surface: #f4f4f5;
    --code-surface-header: #ececee;
    --code-border: var(--line);
    --code-text: #18181b;

    --syn-comment: #71717a;
    --syn-punctuation: #52525b;
    --syn-tag: #15803d;
    --syn-string: #1d4ed8;
    --syn-number: #0369a1;
    --syn-keyword: #be123c;
    --syn-function: #7c3aed;
    --syn-operator: #be123c;
    --syn-variable: #c2410c;
    --syn-important: #be123c;
    --syn-inserted: #15803d;
    --syn-deleted: #be123c;
    --syn-attr-value: #1d4ed8;
}

[data-theme="dark"] {
    --code-surface: #141414;
    --code-surface-header: #1c1c1c;
    --code-border: var(--line);
    --code-text: #f4f4f5;

    --syn-comment: #a1a1aa;
    --syn-punctuation: #d4d4d8;
    --syn-tag: #86efac;
    --syn-string: #93c5fd;
    --syn-number: #7dd3fc;
    --syn-keyword: #fda4af;
    --syn-function: #c4b5fd;
    --syn-operator: #7dd3fc;
    --syn-variable: #fdba74;
    --syn-important: #fda4af;
    --syn-inserted: #86efac;
    --syn-deleted: #fda4af;
    --syn-attr-value: #93c5fd;
}

/* کد همیشه LTR */
.code-block,
.gh-content pre,
.gh-content pre code,
.gh-content .kg-code-card,
.gh-content .kg-code-card pre,
.gh-content .kg-markdown-card pre,
.gh-content .kg-markdown-card pre code,
code[class*="language-"],
pre[class*="language-"] {
    direction: ltr !important;
    text-align: left !important;
    unicode-bidi: isolate;
}

.gh-content :not(pre) > code,
.gh-content p code,
.gh-content li code,
.gh-content td code {
    direction: ltr !important;
    unicode-bidi: isolate;
    display: inline-block;
}

/* کد درون‌خطی */
.gh-content :not(pre) > code,
.gh-content p code,
.gh-content li code,
.gh-content td code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    padding: 0.1em 0.35em;
    color: var(--code-text);
    background: var(--code-surface);
    border: 1px solid var(--code-border);
    border-radius: 3px;
    word-break: break-word;
}

/* بلوک کد */
.gh-content .kg-code-card {
    margin: 2em 0;
    padding: 0;
    background: none;
}

.code-block {
    margin: 2em 0;
    border: 1px solid var(--code-border);
    border-radius: 4px;
    background: var(--code-surface);
    overflow: hidden;
}

.code-block__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.45rem 0.85rem;
    background: var(--code-surface-header);
    border-block-end: 1px solid var(--code-border);
    direction: ltr;
}

.code-block__lang {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}

.code-block__copy {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.55rem;
    font-family: var(--font);
    font-size: 0.75rem;
    color: var(--muted);
    background: transparent;
    border: 1px solid var(--code-border);
    border-radius: 3px;
    cursor: pointer;
}

.code-block__copy:hover {
    color: var(--text);
    background: var(--code-surface);
}

.code-block__copy.is-copied {
    color: var(--accent);
    border-color: var(--accent);
}

.code-block__copy-icon {
    width: 0.875rem;
    height: 0.875rem;
    flex-shrink: 0;
}

.code-block pre,
.gh-content .kg-code-card pre {
    margin: 0;
    padding: 1rem 1.25rem;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    line-height: 1.65;
    tab-size: 4;
    color: var(--code-text);
    background: var(--code-surface);
    border: none;
    border-radius: 0;
}

.code-block pre code,
.gh-content .kg-code-card pre code {
    display: block;
    padding: 0;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    color: inherit;
    background: none;
    border: none;
    white-space: pre;
}

.gh-content > pre:not(.code-block pre) {
    margin: 2em 0;
    padding: 1rem 1.25rem;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    line-height: 1.65;
    color: var(--code-text);
    background: var(--code-surface);
    border: 1px solid var(--code-border);
    border-radius: 4px;
}

.gh-content > pre:not(.code-block pre) code {
    padding: 0;
    background: none;
    border: none;
}

/* توکن‌های Prism */
code[class*="language-"],
pre[class*="language-"] {
    text-shadow: none;
}

.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
    color: var(--syn-comment);
    font-style: italic;
}

.token.punctuation { color: var(--syn-punctuation); }

.token.namespace { opacity: 0.85; }

.token.property,
.token.constant,
.token.symbol,
.token.boolean,
.token.number {
    color: var(--syn-number);
}

.token.tag { color: var(--syn-tag); }

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin {
    color: var(--syn-string);
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
    color: var(--syn-operator);
}

.token.atrule,
.token.keyword {
    color: var(--syn-keyword);
    font-weight: 500;
}

.token.function,
.token.class-name {
    color: var(--syn-function);
}

.token.regex,
.token.variable {
    color: var(--syn-variable);
}

.token.important {
    color: var(--syn-important);
    font-weight: 600;
}

.token.deleted { color: var(--syn-deleted); }
.token.inserted { color: var(--syn-inserted); }
.token.attr-value { color: var(--syn-attr-value); }

@media (max-width: 767px) {
    .code-block pre,
    .gh-content .kg-code-card pre {
        font-size: 0.78rem;
        padding: 0.85rem 1rem;
    }

    .code-block__copy-label {
        display: none;
    }
}
