/* Modern CSS Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --text-primary: #1f2937;
    --text-secondary: #4b5563;
    --bg-primary: #f9fafb;
    --bg-secondary: #ffffff;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    min-height: 100vh;
}

/* Header Styles */
.header {
    text-align: center;
    padding: 4rem 1.5rem;
    background: var(--bg-secondary);
    box-shadow: var(--shadow-sm);
    margin-bottom: 3rem;
    position: relative;
    overflow: hidden;
}

.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(to right, var(--primary-color), #818cf8);
}

.header h1 {
    font-size: 3rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    letter-spacing: -0.025em;
}

.header .subtitle {
    font-size: 1.25rem;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto;
}

/* Categories Container */
.categories-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* Category Styles */
.category {
    margin-bottom: 4rem;
}

.category h2 {
    font-size: 2rem;
    color: var(--text-primary);
    margin-bottom: 2rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid #e5e7eb;
    font-weight: 700;
    letter-spacing: -0.025em;
}

/* Algorithm Grid */
.algorithm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
}

/* Algorithm Card */
.algorithm-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
    text-decoration: none;
    color: inherit;
    border: 1px solid #e5e7eb;
    position: relative;
    overflow: hidden;
}

.algorithm-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(to right, var(--primary-color), #818cf8);
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.algorithm-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.algorithm-card:hover::before {
    transform: scaleX(1);
}

.algorithm-card h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
    font-weight: 700;
    letter-spacing: -0.025em;
}

.algorithm-card p {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

/* Button Styles */
button {
    padding: 0.75rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

button:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

/* Input Styles */
input {
    padding: 0.75rem 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.2s ease;
    width: 100%;
}

input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Visualization Area Styles */
.visualization-container {
    max-width: 1400px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

.visualization-area {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    min-height: 500px;
}

/* Control Panel */
.control-panel {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: 1.5rem;
}

.controls-wrapper {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

/* Input Groups */
.input-group {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

/* Visualization Elements */
.array-container {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin: 20px 0;
    padding: 20px;
    background: #f5f5f5;
    border-radius: 8px;
    overflow-x: auto;
}

.array-element {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: 2px solid #ccc;
    border-radius: 4px;
    font-size: 16px;
    transition: all 0.3s ease;
}

.array-element.current {
    background: #2196F3;
    color: white;
    border-color: #1976D2;
    transform: scale(1.1);
}

.array-element.in-range {
    background: #E3F2FD;
    border-color: #2196F3;
}

.array-element.dividing {
    border-color: #FF9800;
}

.array-element.comparing {
    background: #FFF3E0;
    border-color: #FF9800;
}

.array-element.swapped {
    background: #E8F5E9;
    border-color: #4CAF50;
    animation: pulse 0.5s ease;
}

.array-element.merged {
    background: #F3E5F5;
    border-color: #9C27B0;
}

.array-element.pivot {
    background: #FF5722;
    color: white;
    border-color: #E64A19;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.search-result {
    text-align: center;
    margin-top: 20px;
    padding: 10px;
    background: #E8F5E9;
    border-radius: 4px;
    color: #2E7D32;
    font-weight: bold;
}

/* Graph Visualization */
.graph-container {
    width: 100%;
    height: 500px;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

.node {
    cursor: pointer;
}

.node circle {
    stroke: white;
    stroke-width: 2px;
}

.node text {
    font-size: 12px;
    fill: white;
    pointer-events: none;
}

.edge {
    stroke-linecap: round;
}

.weight-label {
    font-size: 12px;
    fill: #4a5568;
    pointer-events: none;
}

/* Popup Styles */
.popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.popup-content {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    max-width: 400px;
    width: 90%;
}

.popup h3 {
    margin-bottom: 1rem;
    color: #2d3748;
}

.popup .input-group {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.popup input {
    width: 100%;
}

.popup button {
    width: 100%;
}

.popup button:last-child {
    background: #e2e8f0;
    color: #2d3748;
}

.popup button:last-child:hover {
    background: #cbd5e0;
}

/* Back Button */
.back-button {
    position: absolute;
    top: 1.5rem;
    left: 1.5rem;
    text-decoration: none;
    color: #4a5568;
    display: flex;
    align-items: center;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.back-button:hover {
    color: #2d3748;
}

/* Responsive Design */
@media (max-width: 768px) {
    .header {
        padding: 3rem 1rem;
    }

    .header h1 {
        font-size: 2.25rem;
    }

    .header .subtitle {
        font-size: 1.1rem;
    }

    .categories-container {
        padding: 0 1rem;
    }

    .category h2 {
        font-size: 1.75rem;
    }

    .algorithm-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .algorithm-card {
        padding: 1.5rem;
    }

    .controls-wrapper {
        flex-direction: column;
    }

    .input-group {
        flex-wrap: wrap;
    }
}

/* Greedy Algorithm Styles */
.timeline {
    position: relative;
    width: 100%;
    height: 200px;
    background: #f5f5f5;
    border-radius: 8px;
    margin: 20px 0;
    padding: 20px;
}

.activity {
    position: absolute;
    height: 40px;
    background: #4CAF50;
    border-radius: 4px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.3s ease;
}

.activity.selected {
    background: #2196F3;
    box-shadow: 0 2px 4px rgba(33, 150, 243, 0.3);
}

.activity.current {
    border: 2px solid #FF5722;
    animation: pulse 1s infinite;
}

.items-container {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    height: 300px;
    background: #f5f5f5;
    border-radius: 8px;
    padding: 20px;
    margin: 20px 0;
}

.item {
    width: 60px;
    height: 100%;
    background: #4CAF50;
    border-radius: 4px 4px 0 0;
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding: 10px;
    font-size: 12px;
    white-space: pre-line;
    transition: all 0.3s ease;
}

.item.selected {
    background: #2196F3;
    box-shadow: 0 2px 4px rgba(33, 150, 243, 0.3);
}

.item.current {
    border: 2px solid #FF5722;
    animation: pulse 1s infinite;
}

.huffman-tree {
    width: 100%;
    height: 400px;
    background: #f5f5f5;
    border-radius: 8px;
    margin: 20px 0;
    padding: 20px;
    position: relative;
}

.huffman-node {
    position: absolute;
    width: 60px;
    height: 60px;
    background: #4CAF50;
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.3s ease;
}

.huffman-node.internal {
    background: #9C27B0;
}

.huffman-node.current {
    border: 2px solid #FF5722;
    animation: pulse 1s infinite;
}

.huffman-edge {
    position: absolute;
    background: #666;
    height: 2px;
    transform-origin: left center;
}

.coin-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 20px;
    background: #f5f5f5;
    border-radius: 8px;
    margin: 20px 0;
}

.coin {
    width: 60px;
    height: 60px;
    background: #4CAF50;
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.3s ease;
}

.coin.selected {
    background: #2196F3;
    transform: scale(1.1);
    box-shadow: 0 2px 4px rgba(33, 150, 243, 0.3);
}

.coin.current {
    border: 2px solid #FF5722;
    animation: pulse 1s infinite;
}

.schedule-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 10px;
    padding: 20px;
    background: #f5f5f5;
    border-radius: 8px;
    margin: 20px 0;
}

.job {
    background: #4CAF50;
    border-radius: 4px;
    color: white;
    padding: 10px;
    text-align: center;
    transition: all 0.3s ease;
}

.job.selected {
    background: #2196F3;
    box-shadow: 0 2px 4px rgba(33, 150, 243, 0.3);
}

.job.current {
    border: 2px solid #FF5722;
    animation: pulse 1s infinite;
}

.platforms-container {
    position: relative;
    width: 100%;
    height: 300px;
    background: #f5f5f5;
    border-radius: 8px;
    margin: 20px 0;
    padding: 20px;
}

.train {
    position: absolute;
    height: 30px;
    background: #4CAF50;
    border-radius: 4px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.3s ease;
}

.train.current {
    border: 2px solid #FF5722;
    animation: pulse 1s infinite;
}

.platform {
    position: absolute;
    width: 100%;
    height: 30px;
    background: rgba(158, 158, 158, 0.2);
    border-radius: 4px;
    display: flex;
    align-items: center;
    padding-left: 10px;
    color: #666;
    font-size: 12px;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 87, 34, 0.4);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(255, 87, 34, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(255, 87, 34, 0);
    }
}

/* Closest Pair Visualization */
canvas {
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 8px;
    margin: 20px auto;
    display: block;
}

/* Karatsuba Visualization */
.karatsuba-container {
    padding: 20px;
    background: #f5f5f5;
    border-radius: 8px;
    margin: 20px 0;
}

.split-numbers {
    margin-bottom: 20px;
    font-family: monospace;
    font-size: 16px;
}

.split-numbers div {
    margin: 10px 0;
    padding: 10px;
    background: #fff;
    border-radius: 4px;
    border-left: 4px solid #2196F3;
}

.karatsuba-result {
    background: #fff;
    padding: 20px;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.karatsuba-result div {
    margin: 10px 0;
    padding: 5px 0;
    border-bottom: 1px solid #eee;
}

.karatsuba-result .final-result {
    font-weight: bold;
    color: #2E7D32;
    border-bottom: none;
    margin-top: 20px;
}

/* Strassen Matrix Multiplication */
.matrix-container {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    justify-content: center;
    padding: 20px;
    background: #f5f5f5;
    border-radius: 8px;
    margin: 20px 0;
}

.matrix {
    background: #fff;
    padding: 20px;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.matrix-title {
    text-align: center;
    margin-bottom: 10px;
    font-weight: bold;
    color: #1976D2;
}

.matrix table {
    border-collapse: collapse;
}

.matrix td {
    width: 40px;
    height: 40px;
    text-align: center;
    border: 1px solid #ccc;
    padding: 8px;
}

.strassen-products {
    width: 100%;
    margin-top: 20px;
    padding: 20px;
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.strassen-products div {
    margin: 10px 0;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 4px;
    font-family: monospace;
}