/*
 * Dual-theme Shiki output. Tokens carry both light and dark colours as CSS
 * variables; this file picks which one shows.
 *
 * Light is the default. Dark wins under prefers-color-scheme: dark, when the
 * document carries data-code-tokens="dark" (themes whose code panel stays dark
 * in light mode), or when html.dark is set (class-based dark mode).
 *
 * The panel itself is the theme's job — Shiki only colours tokens. Optional
 * copy control, line numbers and word wrap sit on the block without changing
 * the theme's pre chrome.
 */

/*
 * Panel chrome (background, padding, radius) is the theme's. Shiki only puts
 * colour variables on the tokens — it does not paint a background of its own
 * when defaultColor is false — so nothing here fights the theme's pre rule.
 */
pre.shiki code {
    background: none;
    padding: 0;
    font-size: inherit;
    color: inherit;
}

/* defaultColor: false — light vars are the base paint. */
pre.shiki,
pre.shiki span {
    color: var(--shiki-light);
    font-style: var(--shiki-light-font-style, inherit);
    font-weight: var(--shiki-light-font-weight, inherit);
    text-decoration: var(--shiki-light-text-decoration, inherit);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-code-tokens="light"]) pre.shiki,
    :root:not([data-code-tokens="light"]) pre.shiki span {
        color: var(--shiki-dark) !important;
        font-style: var(--shiki-dark-font-style, inherit) !important;
        font-weight: var(--shiki-dark-font-weight, inherit) !important;
        text-decoration: var(--shiki-dark-text-decoration, inherit) !important;
    }
}

:is(html, body)[data-code-tokens="dark"] pre.shiki,
:is(html, body)[data-code-tokens="dark"] pre.shiki span,
html.dark pre.shiki,
html.dark pre.shiki span {
    color: var(--shiki-dark) !important;
    font-style: var(--shiki-dark-font-style, inherit) !important;
    font-weight: var(--shiki-dark-font-weight, inherit) !important;
    text-decoration: var(--shiki-dark-text-decoration, inherit) !important;
}

/* ── Block shell ───────────────────────────────────────────────────── */

.syntax-block {
    position: relative;
}

.syntax-block:has(.syntax-copy) > pre {
    /* Room for the button so the first line is not covered on narrow panels. */
    padding-right: 2.75rem;
}

/* ── Line numbers (Shiki already wraps each line in .line) ─────────── */

.syntax-block--lines pre.shiki code {
    counter-reset: syntax-line;
}

.syntax-block--lines pre.shiki .line {
    display: inline-block;
    width: 100%;
    counter-increment: syntax-line;
}

.syntax-block--lines pre.shiki .line::before {
    content: counter(syntax-line);
    display: inline-block;
    min-width: 2ch;
    margin-right: 1.1em;
    padding-right: 0.75em;
    text-align: right;
    color: #64748b;
    -webkit-user-select: none;
    user-select: none;
    pointer-events: none;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-code-tokens="light"]) .syntax-block--lines pre.shiki .line::before {
        color: #94a3b8;
    }
}

:is(html, body)[data-code-tokens="dark"] .syntax-block--lines pre.shiki .line::before,
html.dark .syntax-block--lines pre.shiki .line::before {
    color: #94a3b8;
}

/* ── Word wrap ─────────────────────────────────────────────────────── */

.syntax-block--wrap pre.shiki,
.syntax-block--wrap pre.shiki code {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* ── Copy control ──────────────────────────────────────────────────── */

.syntax-copy {
    position: absolute;
    top: 0.55rem;
    right: 0.55rem;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    margin: 0;
    padding: 0;
    border: 1px solid rgba(15, 23, 42, 0.14);
    border-radius: 0.4rem;
    background: rgba(255, 255, 255, 0.86);
    color: #334155;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.syntax-copy:hover {
    background: #ffffff;
    color: #0f172a;
    border-color: rgba(15, 23, 42, 0.28);
}

.syntax-copy:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.syntax-copy.is-copied {
    color: #15803d;
    border-color: rgba(21, 128, 61, 0.35);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-code-tokens="light"]) .syntax-copy {
        border-color: rgba(255, 255, 255, 0.14);
        background: rgba(15, 23, 42, 0.72);
        color: #e2e8f0;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    }

    :root:not([data-code-tokens="light"]) .syntax-copy:hover {
        background: rgba(30, 41, 59, 0.95);
        color: #f8fafc;
        border-color: rgba(255, 255, 255, 0.28);
    }

    :root:not([data-code-tokens="light"]) .syntax-copy.is-copied {
        color: #86efac;
        border-color: rgba(134, 239, 172, 0.4);
    }
}

:is(html, body)[data-code-tokens="dark"] .syntax-copy,
html.dark .syntax-copy {
    border-color: rgba(255, 255, 255, 0.14);
    background: rgba(15, 23, 42, 0.72);
    color: #e2e8f0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

:is(html, body)[data-code-tokens="dark"] .syntax-copy:hover,
html.dark .syntax-copy:hover {
    background: rgba(30, 41, 59, 0.95);
    color: #f8fafc;
    border-color: rgba(255, 255, 255, 0.28);
}

:is(html, body)[data-code-tokens="dark"] .syntax-copy.is-copied,
html.dark .syntax-copy.is-copied {
    color: #86efac;
    border-color: rgba(134, 239, 172, 0.4);
}

@media (prefers-reduced-motion: reduce) {
    .syntax-copy {
        transition: none;
    }
}
