:root {
    --primary-color: #4a90d9;
    --secondary-color: #6c757d;
    --danger-color: #dc3545;
    --success-color: #28a745;
    --warning-color: #ffc107;
    --bg-color: #1a1a2e;
    --panel-bg: #16213e;
    --text-color: #e4e4e4;
    --border-color: #0f3460;
    --highlight-color: #e94560;
    --node-color: #4a90d9;
    --node-highlight: #e94560;
    --node-found: #28a745;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    padding: 20px 0;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 20px;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    background: linear-gradient(135deg, var(--primary-color), var(--highlight-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

header p {
    color: #888;
    font-size: 1.1rem;
}

.algo-nav {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
}

.nav-btn {
    padding: 10px 24px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: transparent;
    color: var(--text-color);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.nav-btn:hover {
    background: var(--border-color);
}

.nav-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.algo-section {
    display: none;
}

.algo-section.active {
    display: block;
}

.controls {
    background: var(--panel-bg);
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    align-items: center;
    justify-content: space-between;
}

.input-group, .action-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

input[type="number"], input[type="text"] {
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 1rem;
    width: 120px;
}

input[type="number"]:focus, input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
}

select {
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 1rem;
    cursor: pointer;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: #3a7bc8;
    transform: translateY(-2px);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--border-color);
    color: var(--text-color);
}

.btn-outline:hover {
    background: var(--border-color);
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.9rem;
}

.speed-control-global {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--panel-bg);
    padding: 15px 20px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    z-index: 100;
}

.speed-control-global label {
    color: #888;
    font-size: 0.9rem;
}

.speed-control-global input[type="range"] {
    width: 100px;
    accent-color: var(--primary-color);
}

.visualization {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.panel {
    background: var(--panel-bg);
    border-radius: 12px;
    padding: 20px;
}

.panel h2 {
    font-size: 1.2rem;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    color: var(--primary-color);
}

.canvas-container {
    width: 100%;
    height: 400px;
    background: var(--bg-color);
    border-radius: 8px;
    overflow: hidden;
}

#treeCanvas, #heapCanvas {
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    border-radius: 8px;
}

.memory-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.memory-section h3 {
    font-size: 1rem;
    color: #888;
    margin-bottom: 10px;
}

.memory-view {
    background: var(--bg-color);
    border-radius: 8px;
    padding: 10px;
    min-height: 300px;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    overflow-y: auto;
    max-height: 350px;
}

.stack-frame {
    background: rgba(74, 144, 217, 0.2);
    border-left: 3px solid var(--primary-color);
    padding: 8px;
    margin-bottom: 8px;
    border-radius: 4px;
}

.stack-frame.active {
    background: rgba(233, 69, 96, 0.2);
    border-left-color: var(--highlight-color);
}

.stack-frame-name {
    font-weight: bold;
    color: var(--primary-color);
}

.stack-var {
    margin-left: 10px;
    color: #aaa;
}

.heap-object {
    background: rgba(40, 167, 69, 0.2);
    border: 1px solid var(--success-color);
    padding: 8px;
    margin-bottom: 8px;
    border-radius: 4px;
}

.heap-object.highlight {
    border-color: var(--highlight-color);
    background: rgba(233, 69, 96, 0.2);
}

.heap-address {
    font-weight: bold;
    color: var(--success-color);
}

.heap-field {
    margin-left: 10px;
    color: #aaa;
}

.info-panel {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
}

.log-container {
    background: var(--bg-color);
    border-radius: 8px;
    padding: 15px;
    height: 200px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}

.log-entry {
    padding: 5px 0;
    border-bottom: 1px solid var(--border-color);
}

.log-entry.highlight, .log-entry.log-warning {
    color: var(--highlight-color);
}

.log-entry.success, .log-entry.log-success, .log-entry.log-found {
    color: var(--success-color);
}

.log-entry.info, .log-entry.log-info, .log-entry.log-hash, .log-entry.log-compare {
    color: var(--primary-color);
}

.log-entry.log-collision {
    color: var(--warning-color);
}

.log-entry.log-swap, .log-entry.log-delete, .log-entry.log-insert {
    color: var(--highlight-color);
}

.log-entry.log-not_found, .log-entry.log-error {
    color: var(--danger-color);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-bottom: 20px;
}

.stat-item {
    background: var(--bg-color);
    padding: 15px;
    border-radius: 8px;
    text-align: center;
}

.stat-label {
    display: block;
    color: #888;
    font-size: 0.85rem;
    margin-bottom: 5px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
}

.traversal-section h3 {
    font-size: 1rem;
    color: #888;
    margin-bottom: 10px;
}

.traversal-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.traversal-result {
    background: var(--bg-color);
    padding: 10px;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    min-height: 40px;
}

.ht-table {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    padding: 20px;
}

.ht-cell {
    width: 60px;
    height: 70px;
    background: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.ht-cell.ht-hash, .ht-cell.ht-highlight {
    border-color: var(--primary-color);
    background: rgba(74, 144, 217, 0.2);
}

.ht-cell.ht-collision, .ht-cell.ht-compare {
    border-color: var(--warning-color);
    background: rgba(255, 193, 7, 0.2);
}

.ht-cell.ht-insert, .ht-cell.ht-found {
    border-color: var(--success-color);
    background: rgba(40, 167, 69, 0.2);
}

.ht-cell.ht-delete {
    border-color: var(--danger-color);
    background: rgba(220, 53, 69, 0.2);
}

.ht-index {
    font-size: 0.75rem;
    color: #888;
}

.ht-value {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--text-color);
    min-height: 24px;
}

.ht-stats, .sort-stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    padding: 15px;
    background: var(--bg-color);
    border-radius: 8px;
    margin-top: 15px;
}

.ht-stats span, .sort-stats span {
    color: #888;
}

.ht-stats span span, .sort-stats span span {
    color: var(--primary-color);
    font-weight: bold;
}

.hashtable-container {
    min-height: 150px;
}

.sort-container {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 4px;
    padding: 20px;
    min-height: 300px;
    background: var(--bg-color);
    border-radius: 8px;
}

.sort-bar {
    width: 40px;
    background: var(--primary-color);
    border-radius: 4px 4px 0 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    transition: all 0.3s ease;
    position: relative;
}

.sort-bar.comparing {
    background: var(--warning-color);
}

.sort-bar.swapping {
    background: var(--highlight-color);
}

.sort-bar.pivot {
    background: #9b59b6;
}

.sort-bar.sorted {
    background: var(--success-color);
}

.sort-bar.merging {
    background: #3498db;
}

.sort-bar-label {
    position: absolute;
    bottom: -25px;
    font-size: 0.8rem;
    color: var(--text-color);
}

.heap-array {
    display: flex;
    justify-content: center;
    gap: 5px;
    padding: 15px;
    flex-wrap: wrap;
}

.heap-array-cell {
    width: 50px;
    height: 60px;
    background: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.heap-array-cell.highlight {
    border-color: var(--success-color);
    background: rgba(40, 167, 69, 0.2);
}

.heap-array-cell.comparing {
    border-color: var(--warning-color);
    background: rgba(255, 193, 7, 0.2);
}

.heap-array-cell.swapping {
    border-color: var(--highlight-color);
    background: rgba(233, 69, 96, 0.2);
}

.heap-cell-index {
    font-size: 0.7rem;
    color: #888;
}

.heap-cell-value {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--text-color);
}

footer {
    text-align: center;
    padding: 20px;
    color: #666;
    border-top: 1px solid var(--border-color);
    margin-top: 20px;
}

@media (max-width: 1200px) {
    .visualization {
        grid-template-columns: 1fr;
    }
    
    .info-panel {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .input-group, .action-group {
        justify-content: center;
    }
    
    .memory-container {
        grid-template-columns: 1fr;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .algo-nav {
        flex-wrap: wrap;
    }
    
    .sort-bar {
        width: 25px;
    }
}
