/* Code blocks: a Prism theme built on the neon tokens, so highlighted code reads the same as the
   rest of the site in both themes. prism-setup.js adds the header strip (language + Copy) to each
   <pre>; without it the block still renders, just without the strip. */

:root,
[data-theme="dark"] {
    --nx-code-bg: #060a14;
    --nx-code-bar: #0a1020;
    --nx-code-text: #dbe4f3;
    --nx-code-comment: #6b7a94;
    --nx-code-punct: #8e9bb3;
    --nx-code-keyword: #22d3ee;
    --nx-code-string: #4ade80;
    --nx-code-number: #fbbf24;
    --nx-code-function: #7dd3fc;
    --nx-code-type: #5eead4;
    --nx-code-attr: #fcd34d;
    --nx-code-variable: #fb923c;
    --nx-code-deleted: #f87171;
}

[data-theme="light"] {
    --nx-code-bg: #f7f9fc;
    --nx-code-bar: #edf1f8;
    --nx-code-text: #1b2436;
    --nx-code-comment: #6b778c;
    --nx-code-punct: #56627a;
    --nx-code-keyword: #0e7490;
    --nx-code-string: #15803d;
    --nx-code-number: #b45309;
    --nx-code-function: #1d4ed8;
    --nx-code-type: #0f766e;
    --nx-code-attr: #a16207;
    --nx-code-variable: #c2410c;
    --nx-code-deleted: #dc2626;
}

code[class*="language-"],
pre[class*="language-"] {
    color: var(--nx-code-text);
    background: none;
    text-shadow: none;
    font-family: var(--nx-font-mono);
    text-align: left;
    white-space: pre;
    word-spacing: normal;
    word-break: normal;
    overflow-wrap: normal;
    line-height: 1.6;
    tab-size: 4;
    hyphens: none;
}

pre[class*="language-"] {
    position: relative;
    margin: 1.4rem 0;
    padding: 1.1rem 1.2rem;
    overflow-x: auto;
    border: 1px solid var(--nx-border-strong);
    border-radius: var(--nx-radius-sm);
    background: var(--nx-code-bg);
    font-size: 0.86rem;
}

/* Once prism-setup.js has added the header, the body scrolls instead of the whole block, so the
   header stays put when a long line is scrolled sideways. */
pre.nx-code {
    padding: 0;
    overflow: hidden;
}

pre.nx-code > .nx-code-body {
    display: block;
    padding: 1rem 1.2rem 1.1rem;
    overflow-x: auto;
}

pre[class*="language-"],
pre.nx-code > .nx-code-body {
    scrollbar-width: thin;
    scrollbar-color: var(--nx-border-strong) transparent;
}

pre[class*="language-"] code {
    padding: 0;
    border-radius: 0;
    background: none;
    color: inherit;
    font-size: inherit;
}

/* Posts saved through the rich text editor sometimes come back with the code split into
   paragraphs or with a stray <br> at the end; keep those looking like one block. */
pre[class*="language-"] p {
    margin: 0;
}

pre[class*="language-"] > br:last-child,
pre.nx-code > .nx-code-body > br:last-child {
    display: none;
}

/* Inline code only: anything inside a <pre> (even nested in a stray <p>) is part of a block. */
code[class*="language-"]:not(pre code) {
    padding: 0.15rem 0.4rem;
    border-radius: 5px;
    white-space: normal;
}

.nx-code-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 8px 6px 14px;
    border-bottom: 1px solid var(--nx-border);
    background: var(--nx-code-bar);
    font-family: var(--nx-font-mono);
    font-size: 0.72rem;
    line-height: 1.4;
    white-space: normal;
    user-select: none;
}

.nx-code-lang {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--nx-text-dim);
    letter-spacing: 0.04em;
}

.nx-code-lang .bi {
    color: var(--nx-accent);
}

.nx-code-copy {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 9px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: none;
    color: var(--nx-text-dim);
    font: inherit;
    cursor: pointer;
}

.nx-code-copy:hover,
.nx-code-copy:focus-visible {
    border-color: var(--nx-border-strong);
    color: var(--nx-text);
}

.nx-code-copy:focus-visible {
    outline: 2px solid var(--nx-accent);
    outline-offset: 1px;
}

.nx-code-copy.is-copied {
    color: var(--nx-green);
}

@media (prefers-reduced-motion: no-preference) {
    .nx-code-copy {
        transition: color 0.15s ease, border-color 0.15s ease;
    }
}

/* Tokens */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
    color: var(--nx-code-comment);
    font-style: italic;
}

.token.punctuation,
.token.operator {
    color: var(--nx-code-punct);
    background: none;
}

.token.namespace {
    opacity: 0.8;
}

.token.keyword,
.token.atrule,
.token.tag,
.token.selector,
.token.important {
    color: var(--nx-code-keyword);
}

.token.string,
.token.char,
.token.attr-value,
.token.url,
.token.regex,
.token.inserted {
    color: var(--nx-code-string);
    background: none;
}

.token.number,
.token.boolean,
.token.constant,
.token.symbol,
.token.entity {
    color: var(--nx-code-number);
}

.token.function,
.token.method {
    color: var(--nx-code-function);
}

.token.class-name,
.token.builtin,
.token.property {
    color: var(--nx-code-type);
}

.token.attr-name {
    color: var(--nx-code-attr);
}

.token.variable {
    color: var(--nx-code-variable);
}

.token.deleted {
    color: var(--nx-code-deleted);
}

.token.important,
.token.bold {
    font-weight: 600;
}

.token.italic {
    font-style: italic;
}

.token.entity {
    cursor: help;
}
