/* ========================================
   Custom Algorithm Mode
   ======================================== */

#section-custom {
    display: none;
    padding: 0 2rem 2rem 2rem;
    width: 100%;
    margin: 0 auto;
    flex: 1;
    overflow: hidden;
}

#section-custom.active-section {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.custom-header {
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.custom-workspace {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    flex: 1;
    min-height: 0;
}

@media (max-width: 900px) {
    .custom-workspace {
        grid-template-columns: 1fr;
    }
}

.editor-pane {
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.editor-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.editor-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.editor-actions {
    display: flex;
    gap: 0.5rem;
}

.editor-wrapper {
    flex: 1;
    position: relative;
    background: #0d1117;
    overflow: hidden;
}

/* ── Syntax highlight backdrop (sits behind textarea) ── */
.code-highlight-pre {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    padding: 1rem;
    border: none;
    background: transparent;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    tab-size: 4;
    -moz-tab-size: 4;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    overflow: auto;
    color: #e6edf3;
    pointer-events: none;
    box-sizing: border-box;
    z-index: 0;
}

.code-highlight-pre code {
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    tab-size: inherit;
    -moz-tab-size: inherit;
    white-space: inherit;
    word-wrap: inherit;
    display: block;
}

/* Syntax token colors — GitHub dark theme */
.code-highlight-pre .hl-kw {
    color: #ff7b72;
}

.code-highlight-pre .hl-bi {
    color: #ffa657;
}

.code-highlight-pre .hl-fn {
    color: #d2a8ff;
}

.code-highlight-pre .hl-st {
    color: #a5d6ff;
}

.code-highlight-pre .hl-nu {
    color: #79c0ff;
}

.code-highlight-pre .hl-cm {
    color: #8b949e;
    font-style: italic;
}

.code-highlight-pre .hl-op {
    color: #ff7b72;
}

.code-highlight-pre .hl-ty {
    color: #ffa657;
}

.code-highlight-pre .hl-api {
    color: #7ee787;
    font-weight: 600;
}

/* ── Execution line highlighting (active during replay) ── */
.code-highlight-pre [data-ln] {
    display: block;
    border-left: 3px solid transparent;
    padding-left: 6px;
    margin-left: -9px;
    transition: background 0.12s ease, border-color 0.12s ease;
}

.code-highlight-pre .hl-exec-line {
    border-radius: 2px;
}

.code-highlight-pre .hl-exec-cmp {
    background: rgba(255, 213, 79, 0.12);
    border-left-color: #ffd54f;
}

.code-highlight-pre .hl-exec-swap {
    background: rgba(255, 107, 107, 0.14);
    border-left-color: #ff6b6b;
}

.code-highlight-pre .hl-exec-set {
    background: rgba(0, 229, 255, 0.10);
    border-left-color: #00e5ff;
}

/* ── Textarea (on top, text invisible when highlight active) ── */
#custom-code-editor {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 1rem;
    border: none;
    resize: none;
    background: transparent;
    color: #e6edf3;
    caret-color: #e6edf3;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    tab-size: 4;
    -moz-tab-size: 4;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    overflow: auto;
    outline: none;
    box-sizing: border-box;
    z-index: 1;
}

/* When highlight is active, hide textarea text — caret stays visible */
.editor-wrapper.hl-active #custom-code-editor {
    color: transparent;
}

.editor-help {
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.75rem;
}

.editor-help code {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    color: var(--text-primary);
}

.visualizer-pane {
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
    min-height: 0;
    overflow: hidden;
}

.custom-controls {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.custom-stats {
    display: flex;
    gap: 1.5rem;
    margin-left: auto;
    font-feature-settings: "tnum";
    font-variant-numeric: tabular-nums;
}

.custom-stats b {
    color: var(--text-primary);
}

.custom-vis-box {
    flex: 1;
    min-height: 200px;
    background: var(--bg-main);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0 10px;
}

.custom-console {
    margin-top: 0.5rem;
    background: #0d1117;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.custom-console-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.75rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}

.console-header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.btn.small.static {
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
}

.btn.small.static:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.custom-console-body {
    background: #0d1117;
    height: 120px;
    overflow-y: auto;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.85rem;
    transition: height 0.3s ease;
}

.custom-console-body.collapsed {
    height: 0;
    border-bottom: none;
}

.console-output {
    list-style: none;
    padding: 0;
    margin: 0;
}

.console-msg {
    padding: 0.2rem 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    word-break: break-word;
    white-space: pre-wrap;
    color: #e6edf3;
}

.console-error {
    color: #e74c3c;
    background: rgba(231, 76, 60, 0.1);
}

.console-warn {
    color: #f1c40f;
    background: rgba(241, 196, 15, 0.1);
}

.console-log {
    color: #e6edf3;
}