.playground-section {
    display: flex;
    flex: 1 0 auto;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding-bottom: 0;
}

.playground-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--type-space-content);
    padding-bottom: var(--type-space-content);
    border-bottom: 1px solid var(--theme-divider-standard);
}

.playground-page-header h1 {
    margin: 0;
    font-size: var(--type-size-content-title);
    line-height: var(--type-leading-heading);
}

.playground-page-header p {
    margin: var(--type-space-content) 0 0;
    font-size: var(--type-size-content-description);
    line-height: var(--type-leading-reading);
}

.playground-section .playground-page-header code {
    display: inline;
    padding: 0.08em 0.3em;
    border-radius: 3px;
    font-family: var(--body-font);
    font-size: var(--resources-code-display-font-size);
}

@media print {
    html[data-site-printing="true"] body {
        margin: 0 !important;
    }

    html[data-site-printing="true"] #playground-print-content {
        display: block !important;
    }

    html[data-site-printing="true"] #playground-print-content .playground-page-header {
        display: none !important;
    }

    html[data-site-printing="true"] #playground-print-content .playground-runner {
        margin-top: 0 !important;
    }

    html[data-site-printing="true"] #playground-print-content .resources-notebook-cell {
        border: 0 !important;
        border-radius: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
    }

    html[data-site-printing="true"] #playground-print-content :is(
        .playground-instructions,
        .resources-notebook-control-summary,
        .playground-notebook-file-bar,
        .resources-notebook-toolbar,
        .resources-notebook-local-file-controls,
        .resources-notebook-remove-local-file,
        .resources-notebook-cell-heading,
        .resources-code-header,
        .resources-notebook-variable-inspector
    ) {
        display: none !important;
    }

    html[data-site-printing="true"] #playground-print-content .resources-notebook-control-disclosure,
    html[data-site-printing="true"] #playground-print-content .resources-notebook-control-disclosure-body {
        display: block !important;
    }

    html[data-site-printing="true"] #playground-print-content .resources-notebook-local-files {
        display: block !important;
        margin: 0 0 4mm !important;
        padding: 0 0 3mm !important;
        border: 0 !important;
        border-bottom: 1px solid var(--theme-divider-standard) !important;
        background: transparent !important;
    }

    html[data-site-printing="true"] #playground-print-content .resources-notebook-local-files:has(
        .resources-notebook-local-file-list:empty
    ) {
        display: none !important;
    }

    html[data-site-printing="true"] #playground-print-content .resources-notebook-local-file-list {
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    html[data-site-printing="true"] #playground-print-content .resources-notebook-local-file-list::before {
        display: block;
        margin-bottom: 1.5mm;
        font-weight: 700;
        content: "Attached files";
    }

    html[data-site-printing="true"] #playground-print-content .resources-notebook-local-file-item {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 3mm;
        padding: 0.5mm 0 !important;
    }

    html[data-site-printing="true"] #playground-print-content :is(
        .resources-notebook-preview,
        .resources-notebook-embed,
        .resources-notebook-body,
        .resources-notebook-document,
        .resources-notebook-cell,
        .resources-notebook-cell-body,
        .resources-code-block,
        .resources-notebook-code-editor,
        .resources-notebook-outputs,
        .resources-rendered-markdown
    ) {
        width: 100% !important;
        max-width: none !important;
        max-height: none !important;
        overflow: visible !important;
    }

    html[data-site-printing="true"] #playground-print-content .resources-notebook-code-highlight {
        display: none !important;
    }
}

.playground-instructions {
    margin: 0;
}

/* Align the top Instructions state with the workspace's rightmost Save action. */
.playground-instructions-summary > .instruction-disclosure__state {
    margin-inline-end: var(--type-space-content);
}

.playground-instructions-body {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin: 0;
    background: var(--theme-surface);
    color: var(--theme-text);
}

.playground-instructions-section + .playground-instructions-section {
    margin-top: var(--type-space-content);
}

.playground-instructions-section h2 {
    margin: 0 0 var(--type-space-content);
    font-family: var(--body-font);
    font-size: inherit;
    font-weight: 600;
    line-height: inherit;
}

.playground-instructions-outline {
    grid-template-columns: minmax(0, 1fr);
    max-height: none;
    overflow: visible;
}

.playground-button-guide-groups {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.playground-button-guide-column {
    display: grid;
    align-content: start;
    gap: var(--type-space-content);
    min-width: 0;
}

.playground-button-guide-group {
    min-width: 0;
}

.playground-button-guide-group h3 {
    margin: 0 0 var(--type-space-content);
    font-family: var(--body-font);
    font-size: inherit;
    font-weight: 600;
    line-height: inherit;
}

.playground-instructions-body .resources-notebook-package-identity strong {
    font-weight: 600;
}

.playground-instructions-item > .resources-notebook-package-identity {
    flex: 0 0 auto;
    max-width: 45%;
    overflow-wrap: normal;
}

.playground-instructions-item > .resources-notebook-package-imports {
    flex: 1 1 auto;
}

.playground-reference-tools .resources-notebook-package-item > :is(
    .resources-notebook-package-identity,
    .resources-notebook-package-imports
) {
    flex: 1 1 0;
    min-width: 0;
    text-align: left;
}

.playground-instructions-outline :is(dt, dd) {
    min-width: 0;
    margin: 0;
    font-size: inherit;
    line-height: inherit;
}

.playground-instructions :is(code) {
    font-family: var(--resources-code-font-family);
    font-size: var(--resources-code-display-font-size);
}

.playground-instructions-body .resources-notebook-package-imports code {
    display: inline;
    padding: 0;
    border-radius: 0;
    background: transparent;
    color: inherit;
}

@media (max-width: 760px) {
    .playground-button-guide-groups {
        grid-template-columns: minmax(0, 1fr);
    }
}

.playground-runner {
    display: flex;
    flex: 1 0 auto;
    flex-direction: column;
    margin-top: var(--type-space-content);
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: 0;
}

.playground-runner .resources-notebook-embed {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    margin-top: 0;
    background: transparent;
}

/* Playground controls use the document surface rather than a gray band. */
.playground-section .playground-runner :is(
    .resources-notebook-control-summary,
    .playground-notebook-file-bar,
    .resources-notebook-local-files,
    .resources-notebook-toolbar
) {
    background: transparent;
}

/*
 * Shared Resources button colors must not reintroduce a filled control strip.
 * Resting and disabled Playground controls remain transparent in both themes;
 * interaction states retain the standard theme feedback.
 */
.playground-runner .resources-notebook-control-disclosure-body :is(
    .resources-notebook-toolbar-button,
    .resources-notebook-local-file-button,
    .notebook-reference-toggle
),
.playground-runner .resources-notebook-control-disclosure-body :is(
    .resources-notebook-toolbar-button,
    .resources-notebook-local-file-button
):disabled {
    background: transparent;
}

.playground-runner .resources-notebook-control-disclosure-body :is(
    .resources-notebook-toolbar-button,
    .resources-notebook-local-file-button,
    .notebook-reference-toggle
):not(:disabled):is(:hover, :focus-visible) {
    background: var(--theme-surface-hover);
}

.playground-runner .resources-notebook-control-disclosure-body
    .notebook-reference-toggle[aria-expanded="true"] {
    background: var(--theme-control-active);
}

/*
 * The workspace owns the remaining short-page height. Cells align to the menu
 * band edges; only the 12px transition above the cells is inset. Every cell
 * starts at its natural minimum instead of consuming free workspace height.
 */
.playground-runner .resources-notebook-body {
    display: flex;
    flex: 1 0 auto;
    padding: var(--type-space-content) 0 var(--type-space-page);
    background: transparent;
}

.playground-runner .resources-notebook-document {
    flex: 1 0 auto;
    background: transparent;
}

.playground-runner .resources-notebook-cell-heading {
    background: transparent;
}

.playground-runner .playground-cell {
    display: flex;
    flex-direction: column;
}

.playground-runner .playground-cell:last-child {
    flex: 0 0 auto;
}

.playground-runner .playground-cell:last-child :is(
    .resources-notebook-cell-body,
    .playground-code-editor:not([hidden]),
    .playground-editor-label
) {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
}

.playground-runner .playground-cell:last-child .playground-editor {
    flex: 0 0 auto;
    max-height: none;
}

.playground-notebook-file-bar {
    box-sizing: border-box;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px 12px;
    width: 100%;
    min-width: 0;
    padding: 8px var(--resources-preview-inline-padding);
    border-top: 1px solid var(--theme-divider-soft);
    border-bottom: 1px solid var(--theme-divider-soft);
    background: var(--theme-media-stage-bg);
    color: var(--theme-text-strong);
    font-size: var(--resources-content-code-font-size);
    line-height: var(--resources-content-line-height);
}

.playground-notebook-file-status {
    min-width: 0;
    overflow-wrap: anywhere;
    font-family: var(--body-font);
    font-size: inherit;
}

.playground-notebook-file-actions {
    display: grid;
    grid-template-columns: repeat(3, 84px);
    gap: 6px;
    width: 264px;
}

.playground-notebook-file-actions .resources-notebook-toolbar-button {
    width: 84px;
    min-width: 84px;
}

/* Match Add files and Clear all to the runtime action columns above. */
.playground-runner .playground-file-actions {
    grid-template-columns: repeat(2, 84px);
    width: 174px;
}

.playground-runner .playground-file-actions .resources-notebook-local-file-button {
    width: 84px;
    min-width: 84px;
}

.playground-runner .playground-toolbar-actions {
    /* Keep execution controls beside the runtime name, even at 320px. */
    display: grid;
    grid-column: 1 / -1;
    grid-row: 1 / span 2;
    grid-template-columns: minmax(0, 1fr) repeat(3, 84px);
    align-items: center;
    column-gap: 6px;
    row-gap: 4px;
    width: 100%;
    min-width: 0;
}

.playground-runner .resources-notebook-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) repeat(3, 84px);
    align-items: center;
    column-gap: 6px;
    row-gap: 4px;
}

.playground-runner .resources-notebook-runtime-info {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    overflow-wrap: normal;
}

.playground-toolbar-actions [data-playground-add-cell] {
    grid-column: 2;
    grid-row: 1;
}

.playground-toolbar-actions [data-playground-run-all] {
    grid-column: 3;
    grid-row: 1;
}

.playground-toolbar-actions [data-playground-reset-all] {
    grid-column: 4;
    grid-row: 1;
}

.playground-toolbar-actions .resources-notebook-toolbar-button {
    box-sizing: border-box;
    width: 84px;
    min-width: 84px;
    height: var(--type-notebook-control-height);
    min-height: var(--type-notebook-control-height);
    padding-block: var(--type-control-padding-block);
    padding-inline: var(--type-control-padding-inline);
    overflow-wrap: normal;
    white-space: nowrap;
}

.playground-reference-tools {
    grid-column: 1 / -1;
    grid-row: 3;
    min-width: 0;
    width: 100%;
    margin-inline-start: 0;
}

.playground-reference-toggles {
    display: grid;
    grid-template-columns: repeat(3, 84px);
    align-items: center;
    gap: 6px;
    width: 264px;
    margin-left: var(--resources-notebook-summary-text-offset);
}

.playground-reference-toggles .resources-notebook-package-summary {
    justify-content: center;
    width: 84px;
    min-width: 84px;
    height: var(--type-notebook-control-height);
    min-height: var(--type-notebook-control-height);
}

.playground-reference-tools > .resources-notebook-package-catalog {
    width: 100%;
}

.playground-reference-toggles .resources-notebook-package-summary[aria-expanded="true"]::before {
    transform: rotate(90deg);
}

/* On wider screens, keep the three execution actions beside the runtime name. */
@media (min-width: 651px) {
    .playground-runner .resources-notebook-toolbar {
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        justify-content: space-between;
        gap: 4px 12px;
    }

    .playground-runner .resources-notebook-runtime-info {
        flex: 1 1 220px;
    }

    .playground-runner .playground-toolbar-actions {
        flex: 0 0 264px;
        grid-column: auto;
        grid-row: auto;
        grid-template-columns: repeat(3, 84px);
        gap: 6px;
        width: 264px;
        min-width: 264px;
        margin-left: auto;
    }

    .playground-toolbar-actions :is(
        [data-playground-add-cell],
        [data-playground-run-all],
        [data-playground-reset-all]
    ) {
        grid-column: auto;
        grid-row: auto;
    }

    .playground-toolbar-actions [data-playground-add-cell] {
        justify-self: stretch;
        margin-inline-start: 0;
    }

    .playground-reference-tools {
        flex: 1 0 100%;
        width: 100%;
        margin-inline-start: 0;
    }
}

/* Preserve one stable execution row at the narrowest supported viewport. */
@media (max-width: 360px) {
    .playground-runner .resources-notebook-toolbar,
    .playground-runner .playground-toolbar-actions {
        grid-template-columns: minmax(0, 1fr) repeat(3, 66px);
        column-gap: 4px;
    }

    .playground-toolbar-actions .resources-notebook-toolbar-button {
        width: 66px;
        min-width: 66px;
        padding-inline: 4px;
    }
}

.playground-cell-list:empty {
    display: none;
}

.playground-cell:focus {
    outline: 0;
}

.playground-cell {
    content-visibility: auto;
    contain-intrinsic-size: auto 220px;
}

.playground-section[data-playground-mode="command"] .playground-cell.is-playground-selected {
    box-shadow: inset 3px 0 var(--theme-focus-ring);
}

.playground-cell-heading {
    flex-wrap: wrap;
}

.playground-cell-heading-spacer {
    flex: 1 1 auto;
}

.playground-cell-menu-actions {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-end;
    column-gap: 12px;
    min-width: 0;
    white-space: nowrap;
}

.playground-cell-menu-action {
    position: relative;
    display: inline-grid;
    flex: 0 0 auto;
    grid-template-areas: "label";
    justify-items: center;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--theme-text-secondary);
    cursor: pointer;
    font-family: inherit;
    font-size: var(--resources-content-small-font-size);
    font-weight: 400;
    line-height: var(--resources-content-line-height);
    text-underline-offset: 2px;
}

.playground-cell-menu-action > span {
    grid-area: label;
}

.playground-cell-menu-action + .playground-cell-menu-action {
    margin-left: 0;
}

.playground-cell-menu-action + .playground-cell-menu-action::before {
    position: absolute;
    top: 50%;
    left: -8px;
    content: "|";
    color: var(--theme-text-secondary);
    font-size: inherit;
    font-weight: 400;
    line-height: 1;
    pointer-events: none;
    transform: translateY(-50%);
}

.playground-cell-menu-action:not(:disabled):is(:hover, :focus-visible) > span {
    text-decoration: underline;
}

.playground-cell-menu-action:disabled {
    color: var(--theme-text-disabled);
    cursor: default;
    font-weight: 400;
    opacity: 0.5;
    text-decoration: none;
}

.playground-cell-delete {
    color: var(--theme-error-text);
}

.playground-editor-label {
    display: block;
    min-width: 0;
}

.playground-output .resources-notebook-text-output {
    border-radius: 0;
}

.playground-python-cell .playground-output:not([hidden]) {
    max-height: min(320px, 45vh);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    /*
     * A permanent gutter exposed the dark document background beside every
     * short result. Reserve scroll space only when it is needed, and keep a
     * long-result scrollbar on the same output surface in every theme.
     */
    background: var(--theme-surface);
    scrollbar-color: var(--theme-border-soft) var(--theme-surface);
    scrollbar-gutter: auto;
    scrollbar-width: thin;
}

.playground-python-cell .playground-output:has(.playground-live-frame):not([hidden]) {
    max-height: none;
    overflow: visible;
}

.playground-python-cell .playground-output:not([hidden])::-webkit-scrollbar {
    width: 10px;
}

.playground-python-cell .playground-output:not([hidden])::-webkit-scrollbar-track {
    background: var(--theme-surface);
}

.playground-python-cell .playground-output:not([hidden])::-webkit-scrollbar-thumb {
    border: 2px solid var(--theme-surface);
    border-radius: 999px;
    background: var(--theme-border-soft);
}

.playground-python-cell .playground-output .resources-notebook-text-output {
    overflow: visible;
}

.playground-output-history-note {
    margin: 0;
    padding: var(--type-space-compact) var(--resources-preview-inline-padding);
    color: var(--theme-text-secondary);
    font-family: var(--body-font);
    font-size: var(--resources-code-display-font-size);
    line-height: var(--resources-content-line-height);
}

.playground-live-frame {
    width: auto;
    max-height: none;
    object-fit: contain;
    cursor: crosshair;
    touch-action: none;
    user-select: none;
}

.playground-live-frame:focus-visible {
    outline: 2px solid var(--theme-focus-ring);
    outline-offset: 3px;
}

.playground-stop-cell:not(:disabled) {
    color: var(--theme-error-text);
}

.playground-cell-type-header {
    position: relative;
}

.playground-cell-type-control {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.playground-cell-type-toggle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    font-weight: 600;
}

.playground-cell-type-toggle::after {
    width: 0;
    height: 0;
    border-top: 4px solid currentColor;
    border-right: 4px solid transparent;
    border-left: 4px solid transparent;
    content: "";
}

.playground-cell-type-toggle:hover,
.playground-cell-type-toggle:focus-visible {
    color: var(--theme-code-text);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.playground-cell-type-toggle:disabled {
    cursor: default;
    opacity: 0.5;
    text-decoration: none;
}

.playground-cell-editable-label {
    font-weight: 400;
}

.playground-cell-type-menu {
    position: absolute;
    z-index: 20;
    top: calc(100% + 5px);
    right: 0;
    box-sizing: border-box;
    min-width: 132px;
    padding: var(--type-space-tight);
    border: 1px solid var(--theme-code-popup-border);
    border-radius: 5px;
    background: var(--theme-code-popup-bg);
    box-shadow: 0 6px 18px var(--theme-shadow);
}

.playground-cell-type-menu[hidden] {
    display: none;
}

.playground-cell-type-menu button {
    display: flex;
    align-items: center;
    gap: 7px;
    width: 100%;
    padding-block: var(--type-control-padding-block);
    padding-inline: var(--type-control-padding-inline);
    border: 0;
    border-radius: 3px;
    background: transparent;
    color: var(--theme-code-text);
    cursor: pointer;
    font-family: var(--body-font);
    font-size: var(--resources-content-small-font-size);
    line-height: var(--resources-content-line-height);
    text-align: left;
}

.playground-cell-type-menu button::before {
    display: inline-block;
    width: 1em;
    height: 1em;
    content: "";
    background-position: center;
    background-repeat: no-repeat;
    background-size: contain;
}

.playground-cell-type-menu button[aria-checked="true"]::before {
    content: "";
    background-image: url("../../app_design/images/check.svg");
}

html[data-theme="dark"] .playground-cell-type-menu button[aria-checked="true"]::before {
    filter: invert(1);
}

.playground-cell-type-menu button:hover,
.playground-cell-type-menu button:focus-visible {
    outline: 0;
    background: var(--theme-code-popup-hover);
}

.playground-markdown-cell .resources-notebook-markdown-output {
    max-height: none;
    margin: 0;
    padding: var(--type-space-content);
    overflow: visible;
}

.playground-markdown-cell .resources-notebook-markdown-output .katex-display {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding-block: var(--type-space-tight);
}

.playground-code-editor[hidden] {
    display: none;
}

.playground-markdown-cell.is-markdown-rendered .resources-notebook-markdown-output {
    min-height: calc(var(--resources-content-font-size) * var(--resources-content-line-height));
    border-top: 0;
    cursor: text;
}

.playground-markdown-cell.is-markdown-rendered .resources-notebook-markdown-output :is(a, button) {
    cursor: pointer;
}

.playground-markdown-cell .resources-notebook-markdown-output .resources-code-block {
    margin-bottom: calc(var(--main-font-size) * 0.65);
}

.playground-markdown-cell .resources-notebook-markdown-output > :last-child {
    margin-bottom: 0;
}

.playground-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 650px) {
    .playground-notebook-file-bar {
        grid-template-columns: minmax(0, 1fr);
    }

    .playground-notebook-file-actions {
        justify-self: end;
    }

    .playground-reference-toggles {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        align-items: center;
        gap: 6px;
        width: 100%;
        margin-left: 0;
    }

    .playground-reference-toggles .resources-notebook-package-summary {
        box-sizing: border-box;
        justify-content: center;
        width: 100%;
        min-width: 0;
        min-height: var(--type-notebook-control-height);
        overflow-wrap: normal;
        text-align: center;
        white-space: nowrap;
    }

    .playground-cell-heading-spacer {
        display: none;
    }

    .playground-cell-heading {
        row-gap: var(--type-space-tight);
        padding-block: var(--type-space-tight);
    }

    .playground-cell-menu-actions {
        flex: 1 0 100%;
        width: 100%;
        justify-content: flex-end;
    }

    .playground-cell-heading .resources-notebook-cell-label {
        margin-right: 0;
    }

}

@media (max-width: 420px) {
    .playground-cell-menu-action > span {
        display: none;
    }

    .playground-cell-menu-action::after {
        grid-area: label;
        content: attr(data-compact-label);
    }

    .playground-cell-menu-action:not(:disabled):is(:hover, :focus-visible)::after {
        text-decoration: underline;
    }
}
