* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
    padding: 10px 10px 30px 10px;
    color: #333;
    box-sizing: border-box;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    margin-left: 200px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    padding: 15px;
    /* Fill viewport under padding; do not grow with long code (code scrolls inside .code-container) */
    height: calc(100vh - 40px);
    max-height: calc(100vh - 40px);
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.controls {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.algorithm-name {
    color: #2ecc71;
    font-size: 1.2em;
    margin: 0;
    margin-right: auto;
    font-weight: 600;
}

.controls select {
    padding: 6px 10px;
    font-size: 13px;
    border: 2px solid #2ecc71;
    border-radius: 4px;
    background: white;
    color: #333;
    cursor: pointer;
    transition: all 0.3s;
}

.controls select:hover {
    background: #f0f0f0;
}

.btn {
    padding: 6px 12px;
    font-size: 13px;
    background: #2ecc71;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 500;
}

.btn:hover:not(:disabled) {
    background: #27ae60;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

.btn-mistake {
    padding: 6px 12px;
    font-size: 13px;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 500;
    margin-left: 8px;
}

.btn-mistake:hover {
    background: #c0392b;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.btn-mistake.showing-mistake {
    background: #27ae60;
}

.btn-mistake.showing-mistake:hover {
    background: #229954;
}

.mistake-icon {
    font-size: 16px;
    font-weight: bold;
    margin-right: 4px;
}

/* Red theme for mistake mode */
body.mistake-mode {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
}

body.mistake-mode .container {
    border: 2px solid #c0392b;
}

body.mistake-mode .algorithm-name {
    color: #e74c3c;
}

body.mistake-mode .code-panel h2,
body.mistake-mode .visualization-panel h2 {
    color: #e74c3c;
}

body.mistake-mode h3 {
    color: #e74c3c;
}

body.mistake-mode .array-index {
    color: #e74c3c;
}

body.mistake-mode .line-explanation {
    border-left-color: #e74c3c;
}

body.mistake-mode .explanation-content {
    color: #e74c3c;
}

body.mistake-mode .btn {
    background: #e74c3c;
}

body.mistake-mode .btn:hover:not(:disabled) {
    background: #c0392b;
}

body.mistake-mode .code-line.active {
    background: rgba(231, 76, 60, 0.2);
    border-left: 3px solid #e74c3c;
}

body.mistake-mode .array-cell {
    border: 2px solid #e74c3c;
}

body.mistake-mode .array-cell.array-updated {
    background: #ffd700;
    animation: arrayUpdateRed 0.6s ease;
}

@keyframes arrayUpdateRed {
    0% { background: #fff; }
    50% { background: #ffd700; }
    100% { background: #fff; }
}

body.mistake-mode .variable-block.updated {
    background: #ffd700;
    animation: variableUpdateRed 0.6s ease;
}

@keyframes variableUpdateRed {
    0% { background: #f0f0f0; }
    50% { background: #ffd700; }
    100% { background: #f0f0f0; }
}

.step-counter {
    margin-left: 10px;
    font-size: 12px;
    color: #666;
    font-weight: 500;
}

.btn-add-element {
    width: 28px;
    height: 28px;
    padding: 0;
    font-size: 20px;
    line-height: 1;
    background: #2ecc71;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(46, 204, 113, 0.3);
    flex-shrink: 0;
}

.btn-add-element:hover:not(:disabled) {
    background: #27ae60;
    transform: scale(1.1);
    box-shadow: 0 4px 10px rgba(46, 204, 113, 0.5);
}

.btn-add-element:active {
    transform: scale(0.95);
}

.array-cell-delete {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    padding: 0;
    font-size: 14px;
    line-height: 1;
    background: #ff6b6b;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(255, 107, 107, 0.4);
    z-index: 10;
    opacity: 0;
    pointer-events: none;
}

.array-cell:hover .array-cell-delete {
    opacity: 1;
    pointer-events: all;
}

.array-cell-delete:hover {
    background: #ff5252;
    transform: scale(1.15);
    box-shadow: 0 3px 6px rgba(255, 107, 107, 0.6);
}

.array-cell-delete:active {
    transform: scale(0.9);
}

.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: minmax(0, 1fr);
    gap: 10px;
    margin-bottom: 10px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    align-items: stretch;
}

@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
    }
}

.code-panel, .visualization-panel {
    background: #f8f9fa;
    border-radius: 6px;
    padding: 10px;
    border: 2px solid #e0e0e0;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.code-panel h2, .visualization-panel h2 {
    color: #2ecc71;
    margin-bottom: 8px;
    font-size: 1.1em;
    flex-shrink: 0;
}

.code-container {
    background: #1e1e1e;
    border-radius: 4px;
    padding: 10px;
    overflow-x: auto;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
    /* Dark track for code panel scrollbars (shared/scrollbars.css) */
    --sb-track: rgba(255, 255, 255, 0.07);
    --sb-thumb: #2ecc71;
    --sb-thumb-hover: #3ddf8a;
    --sb-thumb-active: #27ae60;
}

.visualization-panel .visualization-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

#codeDisplay {
    color: #d4d4d4;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    margin: 0;
}

#codeDisplay.find-mode-code {
    font-size: 11px;
}

.code-line {
    padding: 2px 6px;
    margin: 1px 0;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s;
    display: block;
}

.code-line:hover {
    background: rgba(255, 255, 255, 0.1);
}

.code-line.active {
    background: rgba(46, 204, 113, 0.4);
    border-left: 5px solid #2ecc71;
    padding-left: 12px;
    font-weight: 600;
    box-shadow: 0 0 8px rgba(46, 204, 113, 0.3);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        background: rgba(46, 204, 113, 0.4);
    }
    50% {
        background: rgba(46, 204, 113, 0.6);
    }
}

.code-line.executed {
    opacity: 0.7;
}

.visualization-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 8px 0;
    position: relative;
    min-height: 0;
}

/* Row 1: Input */
.input-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 12px;
}

.input-section h3 {
    font-size: 0.9em;
    color: #2ecc71;
    margin: 0 0 8px 0;
    font-weight: 600;
}

.input-content {
    display: flex;
    gap: 15px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.input-array-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.array-section-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.input-label {
    font-size: 0.85em;
    color: #666;
    font-weight: 500;
}

.input-numbers-container {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.input-number-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    background: #f8f9fa;
    border: 2px solid #2ecc71;
    border-radius: 6px;
}

.input-number-label {
    font-size: 11px;
    color: #666;
    font-weight: 500;
}

.input-number-value {
    font-size: 16px;
    font-weight: bold;
    color: #333;
}

/* Row 2: Variables and Condition */
.middle-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 12px;
}

.variables-section, .condition-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
}

.variables-section h3, .condition-section h3 {
    font-size: 0.9em;
    color: #2ecc71;
    margin: 0;
    font-weight: 600;
}

.condition-container {
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 6px;
    border: 2px dashed #e0e0e0;
    flex: 1;
}

.condition-container.empty {
    color: #999;
    font-style: italic;
    font-size: 13px;
}

/* Row 3: Result */
.result-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.result-section h3 {
    font-size: 0.9em;
    color: #2ecc71;
    margin: 0 0 8px 0;
    font-weight: 600;
}

.return-value-container {
    margin-top: 8px;
    padding: 10px;
    background: #e8f5e9;
    border: 2px solid #2ecc71;
    border-radius: 6px;
    min-height: 30px;
    display: none;
}

.return-value-container.has-value {
    display: block;
}

.return-value-label {
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
    font-weight: 500;
}

.return-value-content {
    font-size: 18px;
    font-weight: bold;
    color: #2ecc71;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

.array-container {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
    min-height: 80px;
    align-items: center;
    position: relative;
}

.array-container.matrix-container {
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 10px;
}

.matrix-row {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
    align-items: center;
}

.matrix-cell .array-index {
    font-size: 9px;
    line-height: 1.1;
    text-align: center;
    max-width: 52px;
    word-break: break-all;
}

.matrix-aux-label {
    font-size: 12px;
    font-weight: 600;
    color: #555;
    margin-top: 4px;
}

.matrix-aux-row {
    padding-top: 4px;
    border-top: 2px dashed #ccc;
}

.matrix-aux-cell {
    border-color: #3498db;
}

.copy-arrow {
    position: absolute;
    z-index: 1000;
    pointer-events: none;
    height: 3px;
    overflow: visible;
}

.arrow-line {
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, #2ecc71 0%, #27ae60 100%);
    position: relative;
    box-shadow: 0 2px 6px rgba(46, 204, 113, 0.4);
    border-radius: 2px;
}

.arrow-head {
    position: absolute;
    right: -12px;
    top: -8px;
    width: 0;
    height: 0;
    border-left: 12px solid #2ecc71;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    filter: drop-shadow(2px 2px 4px rgba(46, 204, 113, 0.4));
}

.copy-arrow.arrow-animate .arrow-line {
    animation: arrowFlow 1.5s ease-in-out;
}

@keyframes arrowFlow {
    0% {
        opacity: 0.6;
        box-shadow: 0 2px 6px rgba(46, 204, 113, 0.3);
    }
    50% {
        opacity: 1;
        box-shadow: 0 2px 12px rgba(46, 204, 113, 0.7);
    }
    100% {
        opacity: 0.7;
        box-shadow: 0 2px 6px rgba(46, 204, 113, 0.4);
    }
}

.variables-container {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    min-height: 60px;
    align-items: center;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 6px;
    border: 2px dashed #e0e0e0;
    flex: 1;
}

.array-cell {
    width: 50px;
    height: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    background: white;
    border: 2px solid #2ecc71;
    border-radius: 6px;
    transition: all 0.3s;
    position: relative;
    cursor: pointer;
    padding: 4px 0;
    overflow: visible;
}

.array-index {
    font-size: 11px;
    color: #2ecc71;
    font-weight: 600;
    margin-bottom: 4px;
    width: 100%;
    text-align: center;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 2px;
}

.array-value {
    font-size: 16px;
    font-weight: bold;
    color: #000;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.array-value-input {
    font-size: 16px;
    font-weight: bold;
    color: #000;
    background: white;
    text-align: center;
    outline: none;
}

.variable-block {
    min-width: 70px;
    height: 70px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
    border-radius: 12px;
    color: white;
    font-weight: bold;
    box-shadow: 0 4px 12px rgba(46, 204, 113, 0.3);
    transition: all 0.3s;
    position: relative;
    padding: 8px 12px;
}

.variable-block.new {
    animation: variableAppear 0.5s ease-out;
}

@keyframes variableAppear {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.variable-block.updated {
    animation: variableUpdate 0.6s ease-out;
}

@keyframes variableUpdate {
    0% {
        transform: scale(1);
        background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
        box-shadow: 0 4px 12px rgba(46, 204, 113, 0.3);
    }
    15% {
        transform: scale(1.1);
        background: linear-gradient(135deg, #ffd700 0%, #ffb347 100%);
        color: #333;
        box-shadow: 0 6px 20px rgba(255, 215, 0, 0.6);
    }
    30% {
        transform: scale(1.15);
        background: linear-gradient(135deg, #ffed4e 0%, #ffc947 100%);
        box-shadow: 0 8px 24px rgba(255, 215, 0, 0.8);
    }
    50% {
        transform: scale(0.95);
        background: linear-gradient(135deg, #ffd700 0%, #ffb347 100%);
        box-shadow: 0 6px 20px rgba(255, 215, 0, 0.6);
    }
    70% {
        transform: scale(1);
        background: linear-gradient(135deg, #ffd700 0%, #ffb347 100%);
        box-shadow: 0 4px 12px rgba(255, 215, 0, 0.4);
    }
    100% {
        transform: scale(1);
        background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
        color: white;
        box-shadow: 0 4px 12px rgba(46, 204, 113, 0.3);
    }
}


.variable-block-name {
    font-size: 11px;
    opacity: 0.9;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.variable-block-value {
    font-size: 20px;
    font-weight: 700;
}

.variable-block.highlighted {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(255, 215, 0, 0.6);
    background: linear-gradient(135deg, #ffd700 0%, #ffb347 100%);
    color: #333;
}

.array-cell.highlighted {
    background: #ffd700;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(255, 215, 0, 0.4);
}

.array-cell.comparing {
    background: #ff6b6b;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.4);
}

.array-cell.swapped {
    background: #51cf66;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(81, 207, 102, 0.4);
}

.array-cell.array-updated {
    animation: arrayUpdate 0.6s ease-out;
}

@keyframes arrayUpdate {
    0% {
        transform: scale(1);
        background: white;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }
    15% {
        transform: scale(1.1);
        background: #ffd700;
        box-shadow: 0 6px 20px rgba(255, 215, 0, 0.6);
    }
    30% {
        transform: scale(1.15);
        background: #ffed4e;
        box-shadow: 0 8px 24px rgba(255, 215, 0, 0.8);
    }
    50% {
        transform: scale(0.95);
        background: #ffd700;
        box-shadow: 0 6px 20px rgba(255, 215, 0, 0.6);
    }
    70% {
        transform: scale(1);
        background: #ffd700;
        box-shadow: 0 4px 12px rgba(255, 215, 0, 0.4);
    }
    100% {
        transform: scale(1);
        background: white;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }
}


.array-length-display {
    font-size: 12px;
    color: #666;
    font-weight: 500;
    margin-left: 8px;
}

.line-explanation {
    background: #f8f9fa;
    padding: 16px;
    border-radius: 6px;
    border-left: 4px solid #2ecc71;
    min-height: 40px;
}

.explanation-content {
    color: #333;
    font-size: 16px;
    line-height: 1.8;
}

.condition-block {
    background: rgba(46, 204, 113, 0.1);
    border: 2px solid #2ecc71;
    border-radius: 8px;
    padding: 16px;
    margin: 8px 0;
    text-align: center;
}

.condition-expression {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    margin-bottom: 12px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

.condition-result {
    font-size: 24px;
    font-weight: 700;
}

.explanation-content code {
    background: #e9ecef;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    color: #2ecc71;
    font-weight: 600;
}

.explanation-content strong {
    font-weight: 700;
}

.info-panel {
    background: #e8f4f8;
    border-radius: 6px;
    padding: 10px;
    border-left: 4px solid #2ecc71;
}

.info-panel h3 {
    color: #2ecc71;
    margin-bottom: 6px;
    font-size: 0.95em;
}

.step-description {
    color: #555;
    font-size: 12px;
    line-height: 1.4;
}

/* Sidebar Styles */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: 200px;
    background: white;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar-section {
    border-bottom: 1px solid #e0e0e0;
}

.sidebar-section:last-of-type {
    border-bottom: none;
}

.sidebar-practice-top {
    flex-shrink: 0;
    padding: 12px 10px 14px;
    background: linear-gradient(180deg, #e8f7ef 0%, #f6fbf8 55%, #ffffff 100%);
    border-bottom: 1px solid #c5e6d4;
}

.practice-link {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 11px 10px;
    margin: 0;
    background: #ffffff;
    color: #1a7f4c;
    text-align: center;
    text-decoration: none;
    font-weight: 600;
    font-size: 12px;
    line-height: 1.15;
    letter-spacing: 0.025em;
    white-space: nowrap;
    border-radius: 8px;
    border: 1.5px solid #2ecc71;
    box-shadow: 0 1px 0 rgba(46, 204, 113, 0.35), 0 4px 12px rgba(46, 204, 113, 0.12);
    transition:
        background 0.18s ease,
        border-color 0.18s ease,
        box-shadow 0.18s ease,
        color 0.18s ease,
        transform 0.15s ease;
}

.practice-link__title {
    font-size: inherit;
    font-weight: 600;
}

.sidebar-practice-top .practice-link + .practice-link {
    margin-top: 10px;
}

/* Same chrome as primary link; slightly deeper green to match sidebar accents */
.practice-link--frq {
    color: #168a53;
    border-color: #27ae60;
    box-shadow: 0 1px 0 rgba(39, 174, 96, 0.35), 0 4px 12px rgba(39, 174, 96, 0.1);
}

.practice-link:hover {
    background: #f0fdf6;
    border-color: #2ecc71;
    color: #0d5c36;
    box-shadow: 0 2px 0 rgba(46, 204, 113, 0.28), 0 6px 16px rgba(46, 204, 113, 0.16);
    transform: translateY(-1px);
}

.practice-link--frq:hover {
    background: #e8f8f0;
    border-color: #2ecc71;
    color: #0d5c36;
    box-shadow: 0 2px 0 rgba(46, 204, 113, 0.25), 0 6px 16px rgba(46, 204, 113, 0.18);
}

.practice-link:active {
    transform: translateY(0);
    box-shadow: 0 1px 6px rgba(46, 204, 113, 0.2);
}

.practice-link:focus-visible {
    outline: 2px solid #2ecc71;
    outline-offset: 3px;
}

.sidebar-header {
    padding: 12px;
    border-bottom: 2px solid #2ecc71;
    background: #f8f9fa;
}

.sidebar-header h2 {
    color: #2ecc71;
    font-size: 1.1em;
    margin: 0;
}

.algorithm-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.algorithm-list li {
    border-bottom: 1px solid #e0e0e0;
}

.algorithm-link {
    display: block;
    padding: 8px 12px;
    color: #333;
    text-decoration: none;
    transition: all 0.2s;
    font-size: 13px;
    line-height: 1.4;
}

.algorithm-link:hover {
    background: #e8f8f0;
    color: #2ecc71;
}

.algorithm-link.active {
    background: #2ecc71;
    color: white;
    font-weight: 500;
}

.page-footer {
    margin-top: auto;
    padding-top: 15px;
    text-align: center;
    border-top: 1px solid #e0e0e0;
}

.page-footer p {
    font-size: 11px;
    color: #999;
    margin: 0;
    font-style: italic;
}

