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

body {
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 50%, #dee2e6 100%);
    min-height: 100vh;
    color: #495057;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 25% 25%, rgba(255,255,255,0.3) 0%, transparent 50%),
        radial-gradient(circle at 75% 75%, rgba(248,249,250,0.2) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    position: relative;
    z-index: 1;
}

h1 {
    text-align: center;
    color: #0e0e25;
    margin-bottom: 30px;
    font-size: 3em;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(108,117,125,0.3);
    background: linear-gradient(45deg, #495057, #0e0f47, #adb5bd);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 25px;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    margin-bottom: 20px;
    border: 1px solid rgba(255,255,255,0.2);
    flex-wrap: wrap;
    gap: 20px;
}

.input-section {
    display: flex;
    gap: 15px;
    align-items: center;
}

.button-section {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.info-section {
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
}

#nodeInput {
    padding: 12px 16px;
    border: 2px solid #e1e5e9;
    border-radius: 10px;
    font-size: 16px;
    width: 150px;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.8);
    color: #333;
}

#nodeInput:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    background: rgba(255, 255, 255, 1);
}

button {
    padding: 12px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
    position: relative;
    overflow: hidden;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
    background: linear-gradient(135deg, #5a67d8 0%, #667eea 100%);
}

#clearBtn {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
    padding: 8px 16px;
    font-size: 13px;
}

#clearBtn:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

#toggleLogBtn {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
    padding: 8px 16px;
    font-size: 13px;
}

#toggleLogBtn:hover {
    background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

.info-section p {
    margin: 0;
    color: #666;
    font-style: italic;
}

.traversal-btn {
    padding: 8px 12px;
    background: linear-gradient(135deg, #17a2b8 0%, #138496 100%);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(23, 162, 184, 0.3);
    min-width: 45px;
}

.traversal-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(23, 162, 184, 0.4);
    background: linear-gradient(135deg, #138496 0%, #117a8b 100%);
}

.traversal-btn:disabled {
    background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 1px 4px rgba(108, 117, 125, 0.2);
}

.animation-info {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 20px;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    margin-bottom: 20px;
    min-height: 60px;
    border: 1px solid rgba(255,255,255,0.2);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
}

.animation-info:hover {
    box-shadow: 0 12px 40px rgba(0,0,0,0.15);
    transform: translateY(-2px);
}

#operationInfo {
    font-weight: 700;
    background: linear-gradient(135deg, #1c2241 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 18px;
}

.tree-container {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(15px);
    border-radius: 20px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.1);
    padding: 30px;
    margin-bottom: 20px;
    border: 1px solid rgba(255,255,255,0.3);
    transition: all 0.3s ease;
    overflow: hidden;
    position: relative;
}

.tree-container:hover {
    box-shadow: 0 16px 50px rgba(0,0,0,0.15);
}

.main-content {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.tree-section {
    flex: 2;
    transition: all 0.3s ease;
}

.tree-section.full-width {
    flex: 1;
}

.log-section {
    flex: 1;
    min-width: 300px;
    transition: all 0.3s ease;
}

.log-section.hidden {
    display: none !important;
}

.log-container {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    height: 640px;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}

.log-container:hover {
    box-shadow: 0 12px 40px rgba(0,0,0,0.15);
}

.log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    border-bottom: 2px solid rgba(173, 181, 189, 0.3);
    background: linear-gradient(135deg, rgba(248, 249, 250, 0.8) 0%, rgba(233, 236, 239, 0.6) 100%);
}

.log-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#clearLogBtn {
    padding: 8px 16px;
    font-size: 14px;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(239, 68, 68, 0.3);
}

#clearLogBtn:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
}

.log-content {
    flex: 1;
    padding: 10px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.4;
}

.log-entry {
    padding: 8px 10px;
    margin-bottom: 5px;
    border-radius: 4px;
    border-left: 4px solid #cbd5e0;
    transition: all 0.3s ease;
}

.log-entry.recent {
    font-weight: bold;
    color: #000000 !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    border-left-width: 6px;
}

.log-entry.older {
    opacity: 0.7;
    color: #6b7280 !important;
    font-weight: normal;
}

.log-entry.welcome {
    background: #f0f9ff;
    border-left-color: #0ea5e9;
    color: #0c4a6e;
}

.log-entry.welcome.recent {
    color: #000000 !important;
    background: #dbeafe;
}

.log-entry.insert {
    background: #f0fdf4;
    border-left-color: #22c55e;
    color: #166534;
}

.log-entry.insert.recent {
    color: #000000 !important;
    background: #dcfce7;
}

.log-entry.delete {
    background: #fef2f2;
    border-left-color: #ef4444;
    color: #991b1b;
}

.log-entry.delete.recent {
    color: #000000 !important;
    background: #fee2e2;
}

.log-entry.rotation {
    background: #fef3c7;
    border-left-color: #f59e0b;
    color: #92400e;
}

.log-entry.rotation.recent {
    color: #000000 !important;
    background: #fef08a;
}

.log-entry.balance {
    background: #f3e8ff;
    border-left-color: #8b5cf6;
    color: #6b21a8;
}

.log-entry.balance.recent {
    color: #000000 !important;
    background: #e9d5ff;
}

.log-entry.info {
    background: #f8fafc;
    border-left-color: #64748b;
    color: #475569;
}

.log-entry.info.recent {
    color: #000000 !important;
    background: #f1f5f9;
}

.log-entry.timestamp {
    font-size: 11px;
    color: #64748b;
    font-weight: normal;
}

#treeSvg {
    width: 100%;
    height: 600px;
    border: 1px solid #dee2e6;
    border-radius: 5px;
    overflow: visible;
    background: linear-gradient(145deg, #ffffff, #f8f9fa);
}

.tree-info {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.05);
    padding: 25px;
    border: 1px solid rgba(173, 181, 189, 0.2);
}

.info-panel h3 {
    color: #667eea;
    margin-bottom: 15px;
    font-size: 1.5em;
}

.info-panel p {
    margin-bottom: 10px;
    font-size: 16px;
}

.info-panel span {
    font-weight: bold;
    color: #333;
}

/* SVG Node Styles */
.node-circle {
    fill: #4a5568;
    stroke: #2d3748;
    stroke-width: 2;
    cursor: pointer;
    transition: all 0.3s ease;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.2));
}

/* Balance factor -2: Dark Red */
.node-circle.balance-neg2 {
    fill: #7f1d1d;
    stroke: #991b1b;
}

.node-circle.balance-neg2:hover {
    fill: #991b1b;
    stroke: #b91c1c;
    filter: drop-shadow(0 0 15px rgba(185, 28, 28, 0.8));
}

/* Balance factor -1: Medium Red */
.node-circle.balance-neg1 {
    fill: #b91c1c;
    stroke: #dc2626;
}

.node-circle.balance-neg1:hover {
    fill: #dc2626;
    stroke: #ef4444;
    filter: drop-shadow(0 0 15px rgba(220, 38, 38, 0.8));
}

/* Balance factor 0: Dark Blue (balanced) */
.node-circle.balance-0 {
    fill: #1e3a8a;
    stroke: #1d4ed8;
}

.node-circle.balance-0:hover {
    fill: #1d4ed8;
    stroke: #2563eb;
    filter: drop-shadow(0 0 15px rgba(29, 78, 216, 0.8));
}

/* Balance factor 1: Medium Green */
.node-circle.balance-pos1 {
    fill: #166534;
    stroke: #16a34a;
}

.node-circle.balance-pos1:hover {
    fill: #16a34a;
    stroke: #22c55e;
    filter: drop-shadow(0 0 15px rgba(22, 163, 74, 0.8));
}

/* Balance factor 2: Dark Green */
.node-circle.balance-pos2 {
    fill: #14532d;
    stroke: #166534;
}

.node-circle.balance-pos2:hover {
    fill: #166534;
    stroke: #16a34a;
    filter: drop-shadow(0 0 15px rgba(22, 101, 52, 0.8));
}

.node-circle:hover {
    stroke-width: 3;
}

.node-circle.deleting {
    fill: #7f1d1d;
    stroke: #991b1b;
}

/* Traversal highlighting styles */
.node-circle.traversal-current {
    fill: #f59e0b !important;
    stroke: #d97706 !important;
    stroke-width: 4 !important;
    filter: drop-shadow(0 0 10px rgba(245, 158, 11, 0.6)) !important;
}

.node-circle.traversal-visited {
    fill: #10b981 !important;
    stroke: #059669 !important;
    stroke-width: 3 !important;
    filter: drop-shadow(2px 2px 8px rgba(16, 185, 129, 0.4)) !important;
}

.node-text {
    fill: white;
    font-family: Arial, sans-serif;
    font-size: 16px;
    font-weight: bold;
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
}

.node-balance {
    fill: #2d3748;
    font-family: Arial, sans-serif;
    font-size: 12px;
    text-anchor: middle;
    pointer-events: none;
}

.edge {
    stroke: #4a5568;
    stroke-width: 3;
    fill: none;
    transition: all 0.3s ease;
    opacity: 0.8;
}

.edge-left {
    stroke: #2b6cb0;
    stroke-dasharray: none;
}

.edge-right {
    stroke: #c53030;
    stroke-dasharray: none;
}

.edge:hover {
    stroke-width: 4;
    opacity: 1;
}

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

.rotating-node {
    animation: rotate 0.8s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.5); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes rotate {
    0% { transform: rotate(0deg); }
    50% { transform: rotate(180deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .controls {
        flex-direction: column;
        gap: 20px;
    }
    
    .input-section, .info-section {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        justify-content: center;
    }
    
    .main-content {
        flex-direction: column;
    }
    
    .log-container {
        height: 300px;
    }
    
    #treeSvg {
        height: 400px;
    }
    
    h1 {
        font-size: 2em;
    }
    
    .edge {
        stroke-width: 2;
    }
    
    .node-circle {
        r: 20;
    }
}

@media (max-width: 480px) {
    #treeSvg {
        height: 350px;
    }
    
    .log-container {
        height: 250px;
    }
    
    .edge {
        stroke-width: 1.5;
    }
}