.code-wrapper {
    margin-block: 1.75rem;
}

.code-wrapper + .code-wrapper {
    margin-top: 2rem;
}

@media (min-width: 1280px) {
    .code-wrapper {
        margin-block: 2.5rem;
    }
}

.code-disclosure__summary {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    padding: 0.9rem 1rem;
    font-weight: 600;
    background: var(--color-surface-secondary, #eef2f7);
    color: var(--color-text, #1f2937);
    transition: background-color 0.2s ease;
}

.code-disclosure__summary::before {
    content: "▸";
    display: inline-block;
    flex: 0 0 auto;
    line-height: 1;
    transition: transform 0.2s ease;
}

.code-disclosure__summary:hover {
    background: #e6ebf2;
}

.code-disclosure[open] > .code-disclosure__summary::before {
    transform: rotate(90deg);
}

[data-theme="dark"] .code-disclosure__summary:hover {
    background: #273449;
}

.code-disclosure {
    border: 1px solid var(--color-border, #d7dee8);
    border-radius: 0.75rem;
    overflow: hidden;
    background: var(--color-surface, #ffffff);
}

.code-disclosure__summary {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    padding: 0.9rem 1rem;
    font-weight: 600;
    background: var(--color-surface-secondary, #eef2f7);
    color: var(--color-text, #1f2937);
    transition: background-color 0.2s ease;
}

.code-disclosure__summary::-webkit-details-marker {
    display: none;
}

.code-disclosure__panel {
    border-top: 1px solid var(--color-border, #d7dee8);
}

.code-toolbar {
    display: flex;
    justify-content: flex-end;
    padding: 0.75rem 1rem 0;
    background: var(--color-surface, #ffffff);
}

.code-copy-button {
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--color-border, #c8d1dc);
    border-radius: 0.5rem;
    background: var(--color-surface, #ffffff);
    color: var(--color-text, #1f2937);
    cursor: pointer;
    font: inherit;
    line-height: 1.2;
    transition:
        background-color 0.2s ease,
        border-color 0.2s ease,
        color 0.2s ease;
}

.code-copy-button:hover {
    background: #eef2f7;
    border-color: #b8c4d3;
}

.code-copy-button:focus-visible,
.code-disclosure__summary:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.code-scroll {
    overflow: auto;
    background: var(--color-code-bg, #f8fafc);
    margin-top: 0.75rem;
}

.code-scroll--limited {
    max-height: calc(var(--max-visible-lines, 30) * 1.5em + 2rem);
}

.code-frame {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: start;
    min-width: max-content;
}

.code-frame--no-gutter {
    grid-template-columns: 1fr;
}

.code-gutter {
    position: sticky;
    left: 0;
    z-index: 1;
    padding: 1rem 0 1rem 1rem;
    background: var(--color-code-gutter, #f1f5f9);
    border-right: 1px solid var(--color-border, #d7dee8);
    text-align: right;
    user-select: none;
}

.code-gutter-line {
    display: block;
    min-width: calc(var(--line-number-digits) * 1ch);
    padding-right: 0.75rem;
    color: var(--color-text-muted, #64748b);
    font-family: "Fira Code", "Cascadia Code", "Consolas", "Courier New", monospace;
    font-size: 0.95rem;
    line-height: 1.5;
}

.runtime-code-block {
    margin: 0;
    padding: 1rem;
    background: var(--color-code-bg, #f8fafc);
    color: var(--color-text, #1f2937);
    font-family: "Fira Code", "Cascadia Code", "Consolas", "Courier New", monospace;
    font-size: 0.95rem;
    line-height: 1.5;
    tab-size: 4;
    white-space: pre;
}

.code-lines {
    display: block;
}

.code-lines .c1  { color: #6a9955; }
.code-lines .s1  { color: #ce9178; }
.code-lines .s2  { color: #d7ba7d; }
.code-lines .p   { color: #374151; }
.code-lines .o   { color: #a855f7; }
.code-lines .k   { color: #2563eb; font-weight: 600; }
.code-lines .kc  { color: #0f766e; }
.code-lines .nv  { color: #0ea5e9; }
.code-lines .nc  { color: #0f766e; }
.code-lines .nf  { color: #ca8a04; }

[data-theme="dark"] .code-disclosure {
    border-color: #334155;
    background: #111827;
}

[data-theme="dark"] .code-disclosure__summary {
    background: #1e293b;
    color: #e5e7eb;
}

[data-theme="dark"] .code-disclosure__panel {
    border-top-color: #334155;
}

[data-theme="dark"] .code-toolbar {
    background: #111827;
}

[data-theme="dark"] .code-copy-button {
    border-color: #475569;
    background: #0f172a;
    color: #e5e7eb;
}

[data-theme="dark"] .code-copy-button:hover {
    background: #1e293b;
    border-color: #64748b;
}

[data-theme="dark"] .code-scroll,
[data-theme="dark"] .runtime-code-block {
    background: #0f172a;
    color: #e5e7eb;
}

[data-theme="dark"] .code-gutter {
    background: #111827;
    border-right-color: #334155;
}

[data-theme="dark"] .code-gutter-line {
    color: #94a3b8;
}

[data-theme="dark"] .code-lines .c1  { color: #6a9955; }
[data-theme="dark"] .code-lines .s1  { color: #fca5a5; }
[data-theme="dark"] .code-lines .s2  { color: #fde68a; }
[data-theme="dark"] .code-lines .p   { color: #cbd5e1; }
[data-theme="dark"] .code-lines .o   { color: #c084fc; }
[data-theme="dark"] .code-lines .k   { color: #60a5fa; }
[data-theme="dark"] .code-lines .kc  { color: #5eead4; }
[data-theme="dark"] .code-lines .nv  { color: #7dd3fc; }
[data-theme="dark"] .code-lines .nc  { color: #5eead4; }
[data-theme="dark"] .code-lines .nf  { color: #fde68a; }

@media (max-width: 768px) {
    .code-frame {
        grid-template-columns: 1fr;
        min-width: 0;
    }

    .code-gutter {
        display: none;
    }

    .runtime-code-block {
        font-size: 0.875rem;
    }
}