/* ========================================
   Visualizer Section
   ======================================== */

#section-visualizer {
    display: none;
    position: relative;
    background: var(--bg-primary);
}

.toolbar {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    transition: all var(--transition);
}

.stats {
    display: flex;
    gap: 1.5rem;
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.stats span {
    color: var(--text-primary);
    font-weight: 500;
}

.select-wrapper select {
    min-width: 180px;
}

/* Advanced Options */
.advanced-options {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.advanced-toggle {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 2rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    cursor: pointer;
    transition: all var(--transition);
}

.advanced-toggle:hover {
    color: var(--text-secondary);
    background: var(--bg-tertiary);
}

.toggle-icon {
    transition: transform 0.2s ease;
}

.advanced-options.open .toggle-icon {
    transform: rotate(180deg);
}

.advanced-content {
    display: none;
    padding: 1rem 2rem 1.25rem;
    gap: 2rem;
    flex-wrap: wrap;
    border-top: 1px solid var(--border-color);
}

.advanced-options.open .advanced-content {
    display: flex;
}

.option-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.option-group label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.option-group select {
    min-width: 140px;
}

.option-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--bar-sorted);
}

.save-load-group {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
}

.save-load-buttons {
    display: flex;
    gap: 0.5rem;
}

.save-load-buttons .btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.75rem;
}

/* Custom Array Upload */
.custom-array-group {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 0.5rem !important;
}

.custom-array-group>label {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.custom-array-group>label small {
    font-size: 0.65rem;
    color: var(--text-muted);
    opacity: 0.8;
}

.custom-array-wrapper {
    display: flex;
    gap: 0.5rem;
}

.custom-array-wrapper input[type="text"] {
    flex: 1;
    min-width: 180px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.8rem;
    outline: none;
    transition: all var(--transition);
}

.custom-array-wrapper input[type="text"]:focus {
    border-color: var(--text-muted);
}

.custom-array-wrapper input[type="text"]::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

.custom-array-upload {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.custom-array-upload .btn {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.upload-hint {
    font-size: 0.65rem;
    color: var(--text-muted);
    opacity: 0.7;
}

/* Custom array mini controls for Compare and Benchmark */
.custom-array-mini {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.custom-array-config label,
.custom-array-bench label {
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
}

.custom-array-config label small,
.custom-array-bench label small {
    font-size: 0.65rem;
    color: var(--text-muted);
    opacity: 0.8;
}

.custom-status {
    font-size: 0.7rem;
    color: var(--bar-sorted);
    font-family: 'SF Mono', 'Consolas', monospace;
}

.custom-status.error {
    color: var(--bar-swap);
}

.custom-status.loaded {
    color: var(--bar-sorted);
}

.compare-custom-indicator {
    background: var(--bg-tertiary);
    border: 1px solid var(--bar-sorted);
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    color: var(--bar-sorted);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

/* Stats Panel */
.stats-panel {
    position: absolute;
    top: 1.5rem;
    left: 1.5rem;
    background: var(--bg-secondary);
    padding: 0.75rem 1.25rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    display: flex;
    gap: 2rem;
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
    z-index: 10;
    transition: all var(--transition);
}

.stats-panel span {
    color: var(--text-primary);
    font-weight: 600;
}

/* Visualizer Container */
#visualizer-container {
    flex: 1;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 2.5rem 4rem 0;
    min-height: 300px;
    overflow: visible;
    /* Fix #3: smooth crossfade when switching visualization modes */
    transition: opacity 0.25s ease-in-out;
}

#visualizer-container.mode-switching {
    opacity: 0;
}

/* Bars */
.bar {
    flex: 1;
    min-width: 1px;
    background: var(--bar-default);
    margin: 0;
    border-radius: 1px 1px 0 0;
    transition: height 0.08s ease-out, background-color 0.1s;
    opacity: 0.85;
    position: relative;
}

.bar.compare {
    background: var(--bar-compare) !important;
    opacity: 1;
}

.bar.swap {
    background: var(--bar-swap) !important;
    opacity: 1;
}

.bar.sorted {
    background: var(--bar-sorted) !important;
    opacity: 1;
}

.bar.show-value::before {
    content: attr(data-value);
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(-50%) rotate(-90deg);
    transform-origin: center center;
    font-size: 0.6rem;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.7);
    white-space: nowrap;
    pointer-events: none;
}

/* Progress */
.progress-container {
    width: 100%;
    max-width: calc(100% - 8rem);
    margin: 0.5rem 4rem;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    position: relative;
    display: none;
}

.progress-container.active {
    display: block;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--text-primary);
    border-radius: 2px;
    /* Fix #17: smooth progress bar animation */
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-text {
    position: absolute;
    right: 0;
    top: -18px;
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: 'SF Mono', 'Consolas', monospace;
}

/* Confetti */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 9999;
    overflow: hidden;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    opacity: 0;
    animation: confetti-fall 3s ease-out forwards;
}

@keyframes confetti-fall {
    0% {
        opacity: 1;
        transform: translateY(-100px) rotate(0deg);
    }

    100% {
        opacity: 0;
        transform: translateY(100vh) rotate(720deg);
    }
}

/* Keyboard Hints */
.keyboard-hints {
    position: fixed;
    bottom: 6rem;
    /* Keeps it above the time travel scrubber at the bottom */
    right: 1.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    font-size: 0.7rem;
    color: var(--text-muted);
    z-index: 100;
    opacity: 0.7;
    transform: translateX(0);
    transition: opacity var(--transition), transform 0.3s ease-in-out;
}

.keyboard-hints.hidden {
    transform: translateX(calc(100% + 2rem));
    opacity: 0;
    pointer-events: none;
}

.keyboard-hints:hover {
    opacity: 1;
}

.keyboard-hints kbd {
    display: inline-block;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    padding: 0.15rem 0.4rem;
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 0.65rem;
    margin-right: 0.25rem;
}

.keyboard-shortcuts-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.keyboard-shortcuts-card {
    position: relative;
    width: min(96vw, 940px);
    max-height: 86vh;
    overflow: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 1.4rem 1.2rem 1.25rem;
}

.keyboard-shortcuts-card h2 {
    margin: 0 0 0.45rem;
    color: var(--text-primary);
    font-size: 1.08rem;
}

.keyboard-shortcuts-note {
    margin: 0 0 1rem;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.keyboard-shortcuts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem 1.1rem;
}

.keyboard-shortcuts-grid section {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.8rem 0.75rem;
    background: var(--bg-tertiary);
}

.keyboard-shortcuts-grid h3 {
    margin: 0 0 0.55rem;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 650;
}

.keyboard-shortcuts-close {
    position: absolute;
    top: 0.55rem;
    right: 0.75rem;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}

.keyboard-shortcuts-close:hover {
    color: var(--text-primary);
}

.keyboard-shortcuts-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0.35rem;
}

.keyboard-shortcuts-list li {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-secondary);
    font-size: 0.8rem;
    flex-wrap: wrap;
}

.keyboard-shortcuts-list kbd {
    min-width: 2.2rem;
    text-align: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.12rem 0.36rem;
    font-family: 'SF Mono', 'Consolas', monospace;
    color: var(--text-primary);
    font-size: 0.7rem;
}