/* App shell layout */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: #1e1e1e;
    color: #d4d4d4;
    font-family: 'Inter', 'Segoe UI', sans-serif;
}

/* Top bar */
.topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0 6px;
    min-height: 42px;
    background: #252526;
    border-bottom: 1px solid #3c3c3c;
    flex-shrink: 0;
    gap: 8px;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
}

.topbar-center {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
}

.topbar-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    min-width: 0;
}

@media (max-width: 600px) {
    .topbar {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        padding: 6px 9px;
        gap: 6px;
    }
    .topbar-left,
    .topbar-center,
    .topbar-right {
        justify-content: flex-start;
    }
}

.logo {
    font-size: 15px;
    font-weight: 600;
    color: #cccccc;
    letter-spacing: 0.3px;
    text-decoration: none;
}

.logo:hover {
    color: #ffffff;
}

.warp-control {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 30px;
}

.warp-label {
    font-size: 12px;
    color: #888;
    letter-spacing: 0.3px;
}

.warp-input {
    width: 42px;
    height: 30px;
    padding: 0 6px;
    background: #3c3c3c;
    border: 1px solid #555;
    border-radius: 3px;
    color: #d4d4d4;
    font-size: 13px;
    text-align: center;
    -moz-appearance: textfield;
    box-sizing: border-box;
}

.warp-input::-webkit-outer-spin-button,
.warp-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

.warp-input:focus {
    outline: none;
    border-color: #007acc;
}

.warp-input:disabled {
    opacity: 0.5;
}

.warp-sep {
    font-size: 13px;
    color: #666;
}

.btn-run {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 30px;
    width: 30px;
    padding: 0;
    background: #1a7a3a;
    color: white;
    border: none;
    border-radius: 3px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s;
    box-sizing: border-box;
}

.btn-run:hover:not(:disabled) {
    background: #22964a;
}

.btn-run:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Spinner */
.spinner {
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Main split */
.main-split {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.editor-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.resize-h-handle {
    width: 4px;
    flex-shrink: 0;
    background: #3c3c3c;
    cursor: col-resize;
    transition: background 0.15s;
    user-select: none;
}

.resize-h-handle:hover,
.resize-h-handle:active {
    background: #007acc;
}

.output-panel {
    display: flex;
    flex-direction: column;
    width: 42vw;
    min-width: 160px;
    min-height: 0;
    flex-shrink: 0;
    background: #252526;
    overflow-y: auto;
}

/* In wide mode, ignore any leftover inline height from a prior narrow-mode drag. */
@media (min-width: 769px) {
    .output-panel {
        height: auto !important;
    }
}

/* Narrow viewports: stack editor on top and output panel on the bottom. */
@media (max-width: 768px) {
    .main-split {
        flex-direction: column;
    }
    .editor-panel {
        flex: 1 1 auto;
        min-height: 120px;
        width: 100%;
    }
    .resize-h-handle {
        width: auto;
        height: 4px;
        cursor: row-resize;
    }
    .output-panel {
        width: auto !important;
        min-width: 0;
        height: 40vh;
        flex-shrink: 0;
    }
}

/* VS Code-style thin scrollbars throughout the output panel. */
.output-panel,
.output-panel *,
.output-body {
    scrollbar-width: thin;
    scrollbar-color: #4f4f4f transparent;
}
.output-panel::-webkit-scrollbar,
.output-panel *::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
.output-panel::-webkit-scrollbar-track,
.output-panel *::-webkit-scrollbar-track {
    background: transparent;
}
.output-panel::-webkit-scrollbar-thumb,
.output-panel *::-webkit-scrollbar-thumb {
    background: #4f4f4f;
    border: 2px solid transparent;
    background-clip: padding-box;
    border-radius: 6px;
}
.output-panel::-webkit-scrollbar-thumb:hover,
.output-panel *::-webkit-scrollbar-thumb:hover {
    background: #6f6f6f;
    background-clip: padding-box;
}
.output-panel::-webkit-scrollbar-corner,
.output-panel *::-webkit-scrollbar-corner {
    background: transparent;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    height: 28px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: #bbbbbb;
    background: #2d2d2d;
    border-bottom: 1px solid #3c3c3c;
    flex-shrink: 0;
}

.panel-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex-shrink: 1;
}

.panel-header-actions > select.settings-text-input {
    flex: 0 1 auto;
    min-width: 60px;
}

.footer-select {
    height: 18px;
    padding: 0 4px;
    background: #3c3c3c;
    border: 1px solid #555;
    border-radius: 3px;
    color: #d4d4d4;
    font-family: 'Inter', 'Segoe UI', sans-serif;
    font-size: 11px;
    cursor: pointer;
}

.footer-select:focus {
    outline: none;
    border-color: #007acc;
}


/* Tab bar */
.editor-tabs {
    display: flex;
    flex-direction: row;
    background: #2d2d2d;
    border-bottom: 1px solid #1e1e1e;
    overflow-x: auto;
    flex-shrink: 0;
    scrollbar-width: none;
}
.editor-tabs::-webkit-scrollbar { display: none; }
.editor-tab {
    padding: 0 12px;
    height: 28px;
    display: flex;
    align-items: center;
    font-size: 12px;
    color: #969696;
    cursor: pointer;
    white-space: nowrap;
    border-right: 1px solid #1e1e1e;
    user-select: none;
    flex-shrink: 0;
}
.editor-tab:hover { color: #d4d4d4; background: #2a2d2e; }
.editor-tab.active {
    color: #d4d4d4;
    background: #1e1e1e;
    border-top: 1px solid #007acc;
}
.editor-tab-close {
    margin-left: 8px;
    font-size: 11px;
    opacity: 0;
    border-radius: 3px;
    padding: 1px 3px;
    line-height: 1;
}
.editor-tab:hover .editor-tab-close,
.editor-tab.active .editor-tab-close { opacity: 0.6; }

.panel-header-tabs {
    border-bottom: 1px solid #3c3c3c;
}

.editor-tabs-rest {
    flex: 1 1 auto;
    align-self: stretch;
}

/* Bonzomatic mode: rendered output sits behind a transparent code editor. */
.app-shell.bonzomatic .main-split {
    position: relative;
}
.app-shell.bonzomatic .resize-h-handle {
    display: none;
}
.app-shell.bonzomatic .editor-panel {
    width: 100%;
    background: rgba(0, 0, 0, 0.75);
    z-index: 2;
}
.app-shell.bonzomatic .editor-panel .panel-header,
.app-shell.bonzomatic .editor-panel .editor-tabs,
.app-shell.bonzomatic .editor-panel .editor-tab.active {
    background: transparent;
}
.app-shell.bonzomatic .editor-container {
    background: transparent !important;
}
.app-shell.bonzomatic .output-panel {
    position: absolute !important;
    inset: 0;
    width: auto !important;
    height: auto !important;
    z-index: 1;
    background: transparent;
    overflow: hidden;
    pointer-events: none;
}
.app-shell.bonzomatic .output-panel > *:not(.debug-section-image),
.app-shell.bonzomatic .output-panel .panel-header,
.app-shell.bonzomatic .output-panel .resize-v-handle {
    display: none !important;
}
.app-shell.bonzomatic .output-panel .debug-section-image {
    height: 100%;
    width: 100%;
    margin: 0;
}
.app-shell.bonzomatic .image-container {
    height: 100% !important;
    width: 100% !important;
}
.app-shell.bonzomatic.editor-hidden .editor-panel {
    display: none;
}
.app-shell.bonzomatic.editor-hidden .output-panel {
    pointer-events: auto;
}
.app-shell.bonzomatic:not(.editor-hidden) .image-overlay {
    display: none;
}
.editor-tab-close:hover { opacity: 1 !important; background: rgba(255,255,255,0.1); }

.editor-toolbar-group {
    display: flex;
    align-items: stretch;
    height: 100%;
    margin-left: -12px; /* bleed to panel-header left padding */
}
.btn-editor-toolbar {
    padding: 0 12px;
    height: 100%;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: #bbbbbb;
    background: transparent;
    border: none;
    border-right: 1px solid #3c3c3c;
    cursor: pointer;
}
.btn-editor-toolbar:hover { background: rgba(255,255,255,0.07); color: #e8e8e8; }

/* Monaco editor container */
.editor-container {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Debug gutter decorations */
.dbg-breakpoint-glyph {
    cursor: pointer;
}
.dbg-breakpoint-glyph::before {
    content: '';
    display: block;
    background: #e51400;
    border-radius: 50%;
    width: 10px;
    height: 10px;
    position: absolute;
    right: 3px;
    top: 50%;
    transform: translateY(-50%);
}

.dbg-current-line {
    background: rgba(255, 204, 0, 0.12) !important;
}

.dbg-current-glyph::before {
    content: '';
    display: block;
    width: 0;
    height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-left: 9px solid #ffcc00;
    position: absolute;
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
}

/* Output body */
.output-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.hint {
    color: #666;
    font-size: 13px;
    padding: 16px 0;
    text-align: center;
}

.hint strong {
    color: #888;
}

.running-hint {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    color: #999;
}

.spinner-output {
    border-color: rgba(255,255,255,0.15);
    border-top-color: #999;
    width: 14px;
    height: 14px;
}

.output-text {
    font-size: 15px;
    color: #9cdcfe;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
    margin: 0 0 8px 0;
}

.error-text {
    font-size: 15px;
    color: #f48771;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
    margin: 0;
}

/* Image section */
.image-section {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: var(--section-h, 45vh);
    min-height: 60px;
    overflow: hidden;
}

.resize-v-handle {
    height: 4px;
    flex-shrink: 0;
    background: #3c3c3c;
    cursor: row-resize;
    transition: background 0.15s;
    user-select: none;
}

.resize-v-handle:hover,
.resize-v-handle:active {
    background: #007acc;
}

.image-slot {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.image-container {
    flex: 1;
    min-height: 0;
    padding: 0;
    background: #141414;
    position: relative;
    overflow: hidden;
}
/* The overlay's red rect stands in for the cursor over the painted image, so
   we hide the system cursor on the canvas only. The letterboxed padding keeps
   the default cursor since it sits on the container. */
.image-container .image-canvas { cursor: none; }
.image-container.pick-vertex .image-canvas { cursor: default; }
.exec-state-body .image-container .image-canvas { cursor: default; }
.image-container.panning,
.image-container.panning .image-canvas { cursor: grabbing; }

.image-canvas {
    position: absolute;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    transform-origin: 0 0;
}
.image-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: block;
}

#color-canvas-gpu { display: none; }
.image-container.gpu-mode #color-canvas { display: none; }
.image-container.gpu-mode #color-canvas-gpu { display: block; }

.metric-legend-wrap {
    position: relative;
    display: flex;
    flex-shrink: 0;
}
.metric-legend {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    width: 220px;
    background: rgba(30, 30, 30, 0.95);
    border: 1px solid #3c3c3c;
    border-radius: 4px;
    padding: 10px;
    color: #ddd;
    font-size: 12px;
    text-transform: none;
    letter-spacing: normal;
    z-index: 10;
}
.metric-legend-title {
    font-weight: 600;
    margin-bottom: 4px;
    color: #fff;
}
.metric-legend-blurb {
    line-height: 1.4;
    margin-bottom: 8px;
    color: #bbb;
}
.metric-legend-bar {
    height: 12px;
    border-radius: 2px;
}
.metric-legend-scale {
    display: flex;
    justify-content: space-between;
    margin-top: 3px;
    color: #999;
}
.metric-legend-swatches {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.metric-legend-swatch {
    display: flex;
    align-items: center;
    gap: 6px;
}
.metric-legend-swatch span {
    width: 14px;
    height: 14px;
    border-radius: 2px;
    border: 1px solid #555;
    display: inline-block;
}

/* Debug controls in topbar */
.debug-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn-dbg {
    height: 30px;
    width: 30px;
    padding: 0;
    background: #3c3c3c;
    color: #d4d4d4;
    border: 1px solid #555;
    border-radius: 3px;
    font-size: 20px;
    cursor: pointer;
    transition: background 0.15s;
    box-sizing: border-box;
    line-height: 1;
}

.btn-dbg:hover:not(:disabled) {
    background: #4e4e4e;
}

.btn-dbg:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-dbg-continue {
    background: #1a7a3a;
    border-color: #1a7a3a;
    color: white;
}

.btn-dbg-continue:hover:not(:disabled) {
    background: #22964a;
}

.btn-dbg-continue-back {
    background: #0e639c;
    border-color: #0e639c;
    color: white;
}

.btn-dbg-continue-back:hover:not(:disabled) {
    background: #1177bb;
}

.dbg-controls-sep {
    width: 1px;
    height: 20px;
    background: #555;
    margin: 0 2px;
    flex-shrink: 0;
}

.btn-icon-mirror {
    display: inline-block;
    transform: scaleX(-1);
}

.icon-step-into      { display: inline-block; transform: rotate(-45deg); }
.icon-step-out       { display: inline-block; transform: rotate(45deg); }
.icon-step-into-back { display: inline-block; transform: scaleX(-1) rotate(-45deg); }
.icon-step-out-back  { display: inline-block; transform: scaleX(-1) rotate(45deg); }

.btn-stop {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 30px;
    width: 30px;
    padding: 0;
    background: #6b1414;
    color: #f48771;
    border: 1px solid #8b2020;
    border-radius: 3px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s;
    box-sizing: border-box;
}

.btn-stop:hover {
    background: #8b1a1a;
}

.debug-step-info {
    font-size: 12px;
    color: #888;
    padding: 0 6px;
    white-space: nowrap;
    min-width: 150px;
    font-variant-numeric: tabular-nums;
}

.thread-selector .warp-sep {
    min-width: 62px;
    font-variant-numeric: tabular-nums;
}

.btn-menu {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 30px;
    width: 30px;
    padding: 0;
    background: #3c3c3c;
    color: #d4d4d4;
    border: 1px solid #555;
    border-radius: 3px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s;
    box-sizing: border-box;
}

.btn-menu:hover {
    background: #4e4e4e;
}

.menu-button-wrap {
    position: relative;
    display: flex;
}

.topbar-title {
    font-size: 15px;
    color: #d4d4d4;
    letter-spacing: 0.3px;
    user-select: none;
    white-space: nowrap;
    padding: 0 2px;
}

a.topbar-title {
    text-decoration: none;
    transition: color 0.15s ease;
}

a.topbar-title:hover,
a.topbar-title:focus-visible {
    color: #ffffff;
    text-shadow: 0 0 6px rgba(255, 255, 255, 0.4);
    outline: none;
}

.menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: transparent;
}

.menu-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    background: #2d2d2d;
    border: 1px solid #555;
    border-radius: 3px;
    min-width: 180px;
    padding: 4px 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    z-index: 101;
    display: flex;
    flex-direction: column;
}

.menu-item {
    display: block;
    padding: 6px 14px;
    background: transparent;
    color: #d4d4d4;
    border: none;
    text-align: left;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}

.menu-item:hover:not(:disabled) {
    background: #094771;
    color: #ffffff;
}

.menu-item:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.menu-divider {
    height: 1px;
    background: #3c3c3c;
    margin: 4px 0;
}

.menu-item-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    width: 100%;
}

.menu-item-check {
    color: #d4d4d4;
    min-width: 10px;
    text-align: right;
}

.modal-body.example-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    max-height: 60vh;
    overflow-y: auto;
}

.modal-body.example-list > .example-loading {
    grid-column: 1 / -1;
}

.modal-body.example-list.single-column {
    grid-template-columns: 1fr;
}

.example-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 8px 12px;
    background: #2d2d2d;
    color: #d4d4d4;
    border: 1px solid #3c3c3c;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
    transition: background 0.15s, border-color 0.15s;
}

.example-item:hover {
    background: #094771;
    border-color: #0e639c;
}

.example-name {
    font-size: 13px;
    font-weight: 500;
}

.example-mode {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 2px;
}

.btn-share {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 30px;
    width: 30px;
    padding: 0;
    background: #3c3c3c;
    color: #d4d4d4;
    border: 1px solid #555;
    border-radius: 3px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s;
    box-sizing: border-box;
}

.btn-share:hover {
    background: #4e4e4e;
}

.share-button-wrap {
    position: relative;
    display: flex;
}

.permalink-toast {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: #1a7a3a;
    color: white;
    padding: 4px 10px;
    border-radius: 3px;
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 10;
    animation: permalink-toast-fade 1.5s ease-out forwards;
}

@keyframes permalink-toast-fade {
    0%   { opacity: 0; transform: translateY(-4px); }
    15%  { opacity: 1; transform: translateY(0); }
    80%  { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(0); }
}

.btn-settings:hover {
    background: #4e4e4e;
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
.modal-dialog {
    background: #252526;
    border: 1px solid #454545;
    border-radius: 6px;
    width: 300px;
    max-width: 90vw;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
    display: flex;
    flex-direction: column;
}
.modal-dialog.settings-dialog {
    width: 380px;
}
.modal-header {
    padding: 12px 16px;
    font-weight: 600;
    font-size: 0.95rem;
    border-bottom: 1px solid #3c3c3c;
    color: #e8e8e8;
}
.modal-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 13px;
}
.modal-footer {
    padding: 12px 16px;
    border-top: 1px solid #3c3c3c;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}
.btn-modal-save {
    background: #0e639c;
    border: 1px solid #0e639c;
    color: white;
    border-radius: 4px;
    padding: 5px 14px;
    cursor: pointer;
    font-size: 0.85rem;
}
.btn-modal-save:hover { background: #1177bb; }

.modal-body::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
.modal-body::-webkit-scrollbar-track {
    background: transparent;
}
.modal-body::-webkit-scrollbar-thumb {
    background: #4f4f4f;
    border: 2px solid transparent;
    background-clip: padding-box;
    border-radius: 6px;
}
.modal-body::-webkit-scrollbar-thumb:hover {
    background: #6f6f6f;
    background-clip: padding-box;
}
.modal-body::-webkit-scrollbar-corner {
    background: transparent;
}

.modal-section-title {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #7d8492;
    margin: 14px 0 6px;
    padding-bottom: 2px;
    border-bottom: 1px solid #2f3338;
}

.modal-section-title:first-child {
    margin-top: 0;
}

.hotkeys-table {
    width: 100%;
    border-collapse: collapse;
}

.hotkeys-table td {
    padding: 4px 8px;
    vertical-align: middle;
}

.hotkeys-keys {
    width: 130px;
    white-space: nowrap;
    text-align: right;
    color: #cdd6e2;
}

.hotkeys-desc {
    color: #aab2bd;
}

.hotkeys-table kbd {
    display: inline-block;
    padding: 1px 6px;
    background: #2a2a2a;
    border: 1px solid #555;
    border-bottom-width: 2px;
    border-radius: 3px;
    color: #e6e6e6;
    font-size: 11px;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
    line-height: 16px;
}

.hotkeys-plus {
    color: #888;
    margin: 0 4px;
}

.tex-empty {
    color: #6c727b;
    font-size: 12px;
    padding: 4px 0 6px;
    font-style: italic;
}

.tex-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.tex-row-stack {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.tex-pick-row {
    display: flex;
    gap: 4px;
}

.tex-pick-row .tex-pick {
    flex: 1 1 auto;
}

.lib-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 8px;
    margin-bottom: 6px;
}

.lib-tile {
    background: #2d2d2d;
    border: 1px solid #3c3c3c;
    border-radius: 3px;
    padding: 4px;
    cursor: pointer;
    display: block;
    overflow: hidden;
    aspect-ratio: 1 / 1;
    position: relative;
}

.lib-tile:hover {
    background: #3c3c3c;
    border-color: #555;
}

.lib-tile img {
    width: 100%;
    height: 100%;
    object-fit: fill;
    display: block;
    background: #1a1a1a;
}

.lib-tile[disabled] {
    cursor: default;
    opacity: 0.7;
}

.tex-thumb {
    width: 64px;
    height: 64px;
    border: 1px solid #3c3c3c;
    background: #1a1a1a;
    flex: 0 0 auto;
    overflow: hidden;
    border-radius: 3px;
}

.tex-thumb img {
    width: 100%;
    height: 100%;
    object-fit: fill;
    display: block;
}

.tex-thumb-empty {
    background: repeating-linear-gradient(45deg, #1a1a1a, #1a1a1a 4px, #222 4px, #222 8px);
}

.tex-name {
    flex: 1 1 auto;
    min-width: 0;
    background: #2d2d2d;
    color: #f0f0f0;
    border: 1px solid #3c3c3c;
    border-radius: 3px;
    padding: 4px 8px;
    font-size: 13px;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
}

.tex-pick, .btn-tex-add {
    background: #2d2d2d;
    color: #f0f0f0;
    border: 1px solid #3c3c3c;
    border-radius: 3px;
    padding: 4px 10px;
    font-size: 13px;
    cursor: pointer;
}

.tex-pick:hover, .btn-tex-add:hover {
    background: #3c3c3c;
}

.btn-tex-add {
    margin-top: 4px;
    margin-bottom: 4px;
}

.tex-select {
    background: #2d2d2d;
    color: #f0f0f0;
    border: 1px solid #3c3c3c;
    border-radius: 3px;
    padding: 3px 6px;
    font-size: 13px;
}

.btn-tex-remove {
    background: transparent;
    color: #aaa;
    border: none;
    padding: 4px 6px;
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
}

.btn-tex-remove:hover {
    color: #ff7a7a;
}

.tex-error {
    color: #ff7a7a;
    font-size: 12px;
    margin-top: 8px;
}

.settings-label {
    font-size: 13px;
    color: #cccccc;
    width: 90px;
    flex-shrink: 0;
}

.settings-toggle {
    position: relative;
    display: inline-block;
    cursor: pointer;
}
.settings-toggle input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.settings-toggle-track {
    display: inline-block;
    width: 36px;
    height: 20px;
    background: #3c3c3c;
    border: 1px solid #555;
    border-radius: 10px;
    position: relative;
    transition: background 0.15s, border-color 0.15s;
}
.settings-toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background: #d4d4d4;
    border-radius: 50%;
    transition: left 0.15s, background 0.15s;
}
.settings-toggle input:checked + .settings-toggle-track {
    background: #007acc;
    border-color: #007acc;
}
.settings-toggle input:checked + .settings-toggle-track .settings-toggle-thumb {
    left: 18px;
    background: #ffffff;
}
.settings-toggle input:disabled + .settings-toggle-track {
    opacity: 0.5;
    cursor: not-allowed;
}

.panel-header-toggle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 100%;
}
.panel-header-toggle .settings-toggle-track {
    width: 26px;
    height: 14px;
    border-radius: 8px;
}
.panel-header-toggle .settings-toggle-thumb {
    width: 10px;
    height: 10px;
    top: 1px;
    left: 1px;
}
.panel-header-toggle input:checked + .settings-toggle-track .settings-toggle-thumb {
    left: 14px;
}
.panel-header-toggle-label {
    font-size: 11px;
    color: #cccccc;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.segmented-toggle {
    display: inline-flex;
    align-items: stretch;
    height: 16px;
    padding: 1px;
    background: #3c3c3c;
    border: 1px solid #555;
    border-radius: 9999px;
    box-sizing: border-box;
}
.segmented-toggle-option {
    appearance: none;
    border: 0;
    background: transparent;
    color: #cccccc;
    font: inherit;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0 8px;
    border-radius: 9999px;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.segmented-toggle-option:hover:not(.active) { color: #ffffff; }
.segmented-toggle-option.active {
    background: #d4d4d4;
    color: #1c1c1c;
}

.btn-time-ctrl {
    display: inline-flex;
    align-items: stretch;
    justify-content: stretch;
    box-sizing: border-box;
    height: 18px;
    width: 22px;
    padding: 0;
    background: #3c3c3c;
    color: #d4d4d4;
    border: 1px solid #555;
    border-radius: 3px;
    font-size: 13px;
    cursor: pointer;
}
.btn-time-ctrl:hover { background: #4e4e4e; }
.btn-time-ctrl > .mdi {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    line-height: 1;
    transform: translateY(1px);
}

.settings-text-input {
    height: 30px;
    padding: 0 8px;
    background: #3c3c3c;
    color: #d4d4d4;
    border: 1px solid #555;
    border-radius: 3px;
    font-size: 13px;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
    box-sizing: border-box;
    flex: 1;
    min-width: 0;
}

.settings-row > .warp-control {
    flex: 1;
}

.settings-row > .warp-control .warp-input {
    flex: 1;
    min-width: 0;
    width: 0;
}

.settings-text-input:focus {
    outline: none;
    border-color: #007acc;
}

.settings-text-input:disabled {
    opacity: 0.5;
}

textarea.settings-text-input {
    height: auto;
    padding: 8px;
    resize: none;
    line-height: 1.4;
    scrollbar-width: thin;
    scrollbar-color: #4f4f4f transparent;
}
textarea.settings-text-input::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
textarea.settings-text-input::-webkit-scrollbar-track {
    background: transparent;
}
textarea.settings-text-input::-webkit-scrollbar-thumb {
    background: #4f4f4f;
    border: 2px solid transparent;
    background-clip: padding-box;
    border-radius: 6px;
}
textarea.settings-text-input::-webkit-scrollbar-thumb:hover {
    background: #6f6f6f;
    background-clip: padding-box;
}
textarea.settings-text-input::-webkit-scrollbar-corner {
    background: transparent;
}

.btn-debug-start {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 30px;
    width: 30px;
    padding: 0;
    background: #0e639c;
    color: #ffffff;
    border: 1px solid #0e639c;
    border-radius: 3px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s;
    box-sizing: border-box;
}

.btn-debug-start:hover:not(:disabled) {
    background: #1177bd;
    border-color: #1177bd;
}

.btn-debug-start:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Thread selector in debug mode */
.thread-selector {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    font-size: 12px;
    color: #888;
}

/* Breakpoint hint in panel header */
.breakpoint-hint {
    font-size: 10px;
    color: #666;
    letter-spacing: 0;
    text-transform: none;
    font-weight: 400;
}

/* Variable inspector */
.debug-vars-body {
    padding: 0;
    overflow-y: auto;
    flex: 1;
}

/* Hierarchical variable list */
.var-list {
    width: 100%;
    font-size: 12px;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
}

.var-subsection-header {
    display: flex;
    align-items: center;
    gap: 2px;
    background: #252526;
    position: sticky;
    top: 0;
    z-index: 1;
    border-bottom: 1px solid #3c3c3c;
    padding: 4px 10px 4px 6px;
    font-family: 'Inter', 'Segoe UI', sans-serif;
    font-size: 10px;
    font-weight: 600;
    color: #999;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    cursor: pointer;
    user-select: none;
}

.var-subsection-header:hover {
    background: #2d2d2d;
}

.var-row {
    display: flex;
    align-items: baseline;
    border-bottom: 1px solid #2d2d2d;
    padding: 3px 10px 3px 0;
    min-height: 22px;
}

.var-row:hover {
    background: #2a2a2a;
}

.var-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    cursor: pointer;
    color: #888;
    font-size: 9px;
    transition: transform 0.12s ease;
    user-select: none;
    margin-right: 4px;
}

.var-toggle.expanded {
    transform: rotate(90deg);
}

.var-toggle-spacer {
    display: inline-block;
    width: 14px;
    flex-shrink: 0;
    margin-right: 4px;
}

.var-row-name {
    color: #9cdcfe;
    flex: 0 0 35%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 8px;
    /* subtract toggle width from the 35% so name+toggle = 35% of container */
    max-width: calc(35% - 18px);
}

.var-row-value {
    color: #ce9178;
    flex: 1;
    word-break: break-all;
}


/* Call stack table (reuses var-table) */
.var-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
    table-layout: fixed;
}

.var-table col.col-name { width: 35%; }
.var-table col.col-value { width: 65%; }

.var-table thead tr {
    background: #2a2a2a;
    position: sticky;
    top: 0;
    z-index: 1;
}

.var-table th {
    padding: 5px 10px;
    text-align: left;
    font-weight: 600;
    color: #999;
    border-bottom: 1px solid #3c3c3c;
    font-size: 11px;
    letter-spacing: 0.3px;
}

.var-table tr:hover {
    background: #2a2a2a;
}

.callstack-selected {
    background: #094771 !important;
}

.var-table td {
    padding: 4px 10px;
    border-bottom: 1px solid #2d2d2d;
    vertical-align: top;
}

.var-name {
    color: #9cdcfe;
    white-space: nowrap;
    min-width: 80px;
}

.var-value {
    color: #ce9178;
    word-break: break-all;
}

/* Collapsible debug sections */
.debug-section {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}

.debug-section-vars {
    height: var(--section-h, 260px);
    min-height: 0;
    flex-shrink: 0;
}

.debug-section-vars.section-collapsed {
    height: auto;
}

.debug-section-console {
    height: var(--section-h, 260px);
    min-height: 0;
    flex-shrink: 0;
}

.debug-section-console.section-collapsed {
    height: auto;
}

.debug-console-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 8px 12px;
}

.debug-section-exec {
    height: var(--section-h, 260px);
    min-height: 0;
    flex-shrink: 0;
}

.callstack-exec-body {
    display: flex;
    flex-direction: row;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.callstack-pane {
    flex: 0 0 var(--callstack-w, 70%);
    min-width: 40px;
    overflow-y: auto;
    overflow-x: hidden;
}

.resize-inner-h-handle {
    width: 4px;
    flex-shrink: 0;
    background: #3c3c3c;
    cursor: col-resize;
    transition: background 0.1s;
}

.resize-inner-h-handle:hover,
.resize-inner-h-handle.dragging {
    background: #007acc;
}

/* Immediate window */
.debug-section-immediate {
    height: var(--section-h, 260px);
    min-height: 0;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.debug-section-immediate.section-collapsed {
    height: auto;
}

.imm-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    min-height: 0;
}

.imm-history {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.imm-entry {
    padding: 4px 10px;
    border-bottom: 1px solid #2d2d2d;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
    font-size: 12px;
}

.imm-expr {
    color: #9cdcfe;
}

.imm-prompt {
    color: #569cd6;
    user-select: none;
}

.imm-result {
    color: #ce9178;
    padding-left: 14px;
}

.imm-image {
    display: block;
    margin: 4px 0 4px 14px;
    image-rendering: pixelated;
}

.imm-error {
    color: #f44747;
}

.imm-input-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
    border-top: 1px solid #3c3c3c;
    background: #1e1e1e;
    flex-shrink: 0;
}

.imm-prompt-inline {
    color: #569cd6;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
    font-size: 12px;
    user-select: none;
}

.imm-input {
    flex: 1;
    background: #2d2d2d;
    border: 1px solid #3c3c3c;
    border-radius: 3px;
    color: #d4d4d4;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
    font-size: 12px;
    padding: 3px 6px;
    outline: none;
}

.imm-input:focus {
    border-color: #569cd6;
}

.imm-eval-btn {
    background: #0e639c;
    border: none;
    border-radius: 3px;
    color: #fff;
    font-size: 11px;
    padding: 3px 8px;
    cursor: pointer;
    white-space: nowrap;
}

.imm-eval-btn:hover {
    background: #1177bb;
}

.imm-eval-btn:disabled {
    background: #3c3c3c;
    color: #666;
    cursor: default;
}

.debug-section-exec.section-collapsed {
    height: auto;
}

.debug-section-callstack {
    height: var(--section-h, 260px);
    min-height: 0;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.debug-section-callstack.section-collapsed {
    height: auto;
}

.debug-section-image {
    height: var(--section-h, 480px);
    min-height: 0;
    flex-shrink: 0;
}

.debug-section-image.section-collapsed {
    height: auto;
}

.debug-panel-spacer {
    flex: 1;
}

.collapsible-header {
    cursor: pointer;
    user-select: none;
}

.collapsible-header:hover {
    background: #333;
}

.panel-header-left {
    display: flex;
    align-items: center;
    gap: 2px;
}

.collapse-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    font-size: 18px;
    color: #777;
    flex-shrink: 0;
    transition: transform 0.12s ease;
    transform: rotate(0deg);
    line-height: 1;
}

.collapse-icon.expanded {
    transform: rotate(90deg);
}

/* Execution state section (kept for non-debug image-section) */

.exec-state-pane {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.exec-state-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
}
/* When the pane hosts the image-container, let it fill the content box and
   drop the padding so the panel background doesn't frame the image. */
.exec-state-body:has(.image-container) {
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
}

.bottom-mode-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 12px;
    border-top: 1px solid #3c3c3c;
    background: #1e1e1e;
    flex-shrink: 0;
}
.bottom-mode-row label {
    font-size: 11px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.bottom-mode-row select {
    height: 18px;
    padding: 0 4px;
    background: #3c3c3c;
    color: #d4d4d4;
    border: 1px solid #555;
    border-radius: 3px;
    font-family: 'Inter', 'Segoe UI', sans-serif;
    font-size: 11px;
    cursor: pointer;
}
.bottom-mode-row select:focus {
    outline: none;
    border-color: #007acc;
}

/* Execution state grid */
.thread-legend {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    color: #777;
}

.tl-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    flex-shrink: 0;
}

.thread-grid {
    display: grid;
    gap: 2px;
}

.thread-cell {
    border-radius: 2px;
    cursor: pointer;
    transition: opacity 0.1s;
}

.thread-cell:hover { opacity: 0.75; }

.tc-active    { background: #4caf50; }
.tc-diverged  { background: #e88f1a; }
.tc-suspended { background: #e88f1a; }
.tc-exited    { background: #555; }

.tc-selected {
    box-shadow: 0 0 0 2px #ffffff, 0 0 0 3px rgba(0, 0, 0, 0.6);
    filter: brightness(1.6);
    position: relative;
    z-index: 2;
}

.debug-section-sep {
    height: 1px;
    background: #3c3c3c;
    margin: 4px 0;
}

.debug-output-section {
    border-top: 1px solid #3c3c3c;
    padding: 8px 12px;
}

.debug-output-label {
    font-size: 10px;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 4px;
}

/* Scrollbar */
.output-body::-webkit-scrollbar {
    width: 6px;
}
.output-body::-webkit-scrollbar-track {
    background: #1e1e1e;
}
.output-body::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 3px;
}

#blazor-error-ui {
    background: #c00;
    bottom: 0;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    color: white;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}
