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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #dbeafe 0%, #e0e7ff 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

.header-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.header-card h1 {
    text-align: center;
    color: #1f2937;
    font-size: 2.5rem;
    font-weight: bold;
    margin-bottom: 24px;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: center;
    align-items: center;
}

.input {
    padding: 10px 16px;
    border: 2px solid #d1d5db;
    border-radius: 8px;
    font-size: 16px;
    width: 140px;
    transition: border-color 0.2s;
}

.input:focus {
    outline: none;
    border-color: #3b82f6;
}

.btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-primary {
    background: #3b82f6;
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #2563eb;
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

.btn-secondary {
    background: #6b7280;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #4b5563;
}

.btn-outline {
    background: transparent;
    color: #374151;
    border: 2px solid #d1d5db;
}

.btn-outline:hover:not(:disabled) {
    background: #f3f4f6;
}

.icon {
    font-size: 14px;
}

.steps-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.steps-card h2 {
    color: #1f2937;
    font-size: 1.5rem;
    margin-bottom: 16px;
}

.steps-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 250px; 
    overflow-y: auto;
    padding-right: 8px;
    border-top: 1px solid #e5e7eb;
    margin-top: 12px;
}

.step-item {
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

.step-badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
}

.step-badge.insert { background: #dbeafe; color: #1d4ed8; }
.step-badge.delete { background: #fee2e2; color: #dc2626; }
.step-badge.rotate-left, .step-badge.rotate-right { background: #f3e8ff; color: #7c3aed; }
.step-badge.balance-check { background: #f0f9ff; color: #0369a1; }


.tree-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.tree-header {
    margin-bottom: 20px;
}

.tree-header h2 {
    color: #1f2937;
    font-size: 1.5rem;
    margin-bottom: 16px;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    font-size: 14px;
    color: #6b7280;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid #1f2937;
}

.legend-color.normal {
    background: #3b82f6;
}

.legend-color.highlighted {
    background: #ef4444;
}

.balance-text {
    color: #059669;
    font-weight: 500;
}

.height-text {
    color: #6b7280;
}

.tree-container {
    width: 100%;
    overflow-x: auto;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: white;
}

#treeSvg {
    display: block;
    margin: 0 auto;
}

.node-circle {
    transition: all 0.5s ease;
}

.node-line {
    transition: all 0.5s ease;
}

.node-text {
    transition: all 0.5s ease;
}

.balance-factor {
    font-weight: bold;
    font-size: 12px;
}

.balance-factor.balanced {
    fill: #059669;
}

.balance-factor.unbalanced {
    fill: #ef4444;
}

.height-label {
    font-size: 10px;
    fill: #6b7280;
}

@media (max-width: 768px) {
    .controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .input {
        width: 100%;
    }
    
    .legend {
        justify-content: center;
    }
    
    .tree-container {
        overflow-x: scroll;
    }
}

.fade-in {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.pulse {
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}
