/* CSS Custom Properties - Dark Mode Only */
:root {
    /* Dark Theme Colors */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-accent: #60a5fa;
    --border-color: #334155;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3);

    /* Algorithm Colors */
    --color-default: #94a3b8;
    --color-comparing: #f59e0b;
    --color-swapping: #ef4444;
    --color-sorted: #10b981;
    --color-found: #10b981;
    --color-current: #3b82f6;
    --color-pivot: #8b5cf6;

    /* Button Colors */
    --btn-primary: #3b82f6;
    --btn-primary-hover: #2563eb;
    --btn-secondary: #6b7280;
    --btn-secondary-hover: #4b5563;
    --btn-success: #10b981;
    --btn-success-hover: #059669;
    --btn-warning: #f59e0b;
    --btn-warning-hover: #d97706;
    --btn-danger: #ef4444;
    --btn-danger-hover: #dc2626;
    --btn-info: #06b6d4;
    --btn-info-hover: #0891b2;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 100vw;
    min-height: 100%;
}

/* Header Styles */
.header {
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-accent);
    margin-bottom: 0.25rem;
}

.tagline {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.nav {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.nav-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.875rem;
    font-weight: 500;
}

.nav-btn:hover {
    background-color: var(--bg-tertiary);
    transform: translateY(-1px);
}

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

.theme-controls {
    display: flex;
    gap: 0.5rem;
}

.theme-toggle,
.sound-toggle {
    width: 2.5rem;
    height: 2.5rem;
    border: 1px solid var(--border-color);
    background-color: var(--bg-primary);
    border-radius: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.theme-toggle:hover,
.sound-toggle:hover {
    background-color: var(--bg-tertiary);
    transform: translateY(-1px);
}

/* Main Content */
.main {
    min-height: calc(100vh - 140px);
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 2rem 0;
    padding-bottom: 0;
}

.visualizer-section {
    display: none;
}

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

.visualizer-header {
    text-align: center;
    margin-bottom: 2rem;
}

.visualizer-header h2 {
    font-size: 2rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.visualizer-header p {
    color: var(--text-secondary);
    font-size: 1.125rem;
}

.visualizer-content {
    display: grid;
    grid-template-columns: 1fr 3fr 1fr;
    gap: 2rem;
    align-items: start;
    padding-right: 20px;
    padding-left: 20px;
    height: 100%;
}

/* Controls Panel */
.controls-panel {
    background-color: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 0.75rem;
    height: 100%;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    flex-shrink: 0;
}

.control-group {
    margin-bottom: 1.5rem;
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.control-group input,
.control-group select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.875rem;
}

.control-group input[type="range"] {
    padding: 0;
    height: 0.5rem;
    background: var(--bg-tertiary);
    outline: none;
    border-radius: 0.25rem;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 1rem;
    height: 1rem;
    background: var(--text-accent);
    border-radius: 50%;
    cursor: pointer;
}

.control-group input[type="range"]::-moz-range-thumb {
    width: 1rem;
    height: 1rem;
    background: var(--text-accent);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.control-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.traversal-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* Button Styles */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    text-align: center;
    text-decoration: none;
    display: inline-block;
}

/* Button Styles */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.875rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.btn:hover::before {
    left: 100%;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
    background: #2563eb;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(59, 130, 246, 0.4);
}

.btn-secondary {
    background: var(--color-secondary);
    color: white;
    box-shadow: 0 2px 4px rgba(107, 114, 128, 0.3);
}

.btn-secondary:hover {
    background: #4b5563;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(107, 114, 128, 0.4);
}

.btn-success {
    background: var(--color-success);
    color: white;
    box-shadow: 0 2px 4px rgba(34, 197, 94, 0.3);
}

.btn-success:hover {
    background: #16a34a;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(34, 197, 94, 0.4);
}

.btn-danger {
    background: var(--color-danger);
    color: white;
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(239, 68, 68, 0.4);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.btn:disabled::before {
    display: none;
}

/* Header Enhancements */
.header h1 {
    background: linear-gradient(135deg, var(--text-accent), #60a5fa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes headerPulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.02);
    }
}

.btn-danger:hover:not(:disabled) {
    background-color: var(--btn-danger-hover);
    transform: translateY(-1px);
}

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

.btn-info:hover:not(:disabled) {
    background-color: var(--btn-info-hover);
    transform: translateY(-1px);
}

/* Visualization Area */
.visualization-area {
    background-color: var(--bg-secondary);
    padding: 1rem;
    border-radius: 0.75rem;
    height: 100%;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    min-height: 400px;
    display: flex;
    flex-shrink: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.array-container {
    display: flex;
    align-items: end;
    justify-content: center;
    gap: 1px;
    min-height: 300px;
    margin-bottom: 30px;
    width: 100%;
    overflow-x: auto;
    /* padding: 1rem; */
    box-sizing: border-box;
}

.array-bar {
    background-color: var(--color-default);
    border-radius: 2px 2px 0 0;
    transition: all 0.3s ease;
    position: relative;
    display: flex;
    align-items: end;
    justify-content: center;
    color: white;
    font-size: 0.75rem;
    font-weight: 500;
    min-width: 5px;
    max-width: 50px;
    flex: 1 1 auto;
    margin: 0 0.5px;
}

/* Responsive adjustments for sorting bars */
@media (max-width: 768px) {
    .array-container {
        gap: 0.5px;
        padding: 0.75rem;
    }

    .array-bar {
        min-width: 2px;
        max-width: 30px;
        font-size: 0.625rem;
        margin: 0 0.25px;
    }
}

@media (max-width: 480px) {
    .array-container {
        gap: 0.25px;
        padding: 0.5rem;
    }

    .array-bar {
        min-width: 1px;
        max-width: 20px;
        font-size: 0.5rem;
        margin: 0 0.125px;
    }
}

.array-bar.comparing {
    background-color: var(--color-comparing);
    transform: scale(1.1);
}

.array-bar.swapping {
    background-color: var(--color-swapping);
    transform: scale(1.2);
}

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

.array-bar.current {
    background-color: var(--color-current);
    transform: scale(1.1);
}

.array-bar.pivot {
    background-color: var(--color-pivot);
    transform: scale(1.1);
}

.array-element {
    background-color: var(--color-default);
    border: 2px solid var(--border-color);
    border-radius: 0.375rem;
    padding: 0.75rem;
    margin: 0.25rem;
    transition: all 0.3s ease;
    font-weight: 500;
    min-width: 60px;
    text-align: center;
    flex: 0 1 auto;
}

/* Responsive array elements for searching visualizer */
.searching-array-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.25rem;
    margin: 1rem 0;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
    overflow-x: auto;
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
}

.searching-array-container .array-element {
    flex: 1 1 auto;
    min-width: 40px;
    max-width: 80px;
    margin: 0.125rem;
    padding: 0.5rem 0.25rem;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Adjust for smaller screens */
@media (max-width: 768px) {
    .searching-array-container {
        gap: 0.125rem;
        padding: 0.75rem;
    }

    .searching-array-container .array-element {
        min-width: 30px;
        max-width: 60px;
        padding: 0.375rem 0.125rem;
        font-size: 0.75rem;
        margin: 0.0625rem;
    }
}

/* For very small screens */
@media (max-width: 480px) {
    .searching-array-container {
        gap: 0.0625rem;
        padding: 0.5rem;
    }

    .searching-array-container .array-element {
        min-width: 25px;
        max-width: 45px;
        padding: 0.25rem 0.0625rem;
        font-size: 0.625rem;
        margin: 0.03125rem;
    }
}

/* Index labels for searching array */
.array-index {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    text-align: center;
}

/* Responsive index labels */
@media (max-width: 768px) {
    .array-index {
        font-size: 0.625rem;
    }
}

@media (max-width: 480px) {
    .array-index {
        font-size: 0.5rem;
    }
}

.array-element.comparing {
    background-color: var(--color-comparing);
    color: white;
    transform: scale(1.1);
}

.array-element.found {
    background-color: var(--color-found);
    color: white;
    transform: scale(1.2);
}

.array-element.current {
    background-color: var(--color-current);
    color: white;
    transform: scale(1.1);
}

.array-element.checked {
    background-color: #868e96;
    color: white;
    opacity: 0.7;
}

.array-element.range {
    background-color: #74c0fc;
    color: white;
    border: 2px solid #339af0;
}

/* Variables Display */
.variables-display {
    margin: 20px 0;
    padding: 15px;
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    min-height: 60px;
}

.search-variable {
    display: inline-block;
    margin: 5px 10px;
    padding: 8px 12px;
    background: var(--accent-color);
    color: white;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    font-weight: bold;
}

.var-name {
    color: #ffd43b;
}

.var-value {
    color: #c3fae8;
}

.status-display {
    background-color: var(--bg-tertiary);
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
    text-align: center;
    margin-top: 1rem;
}

/* Tree Visualization */
.tree-container {
    width: 100%;
    height: 300px;
    position: relative;
    overflow: auto;
}

.tree-node {
    position: absolute;
    width: 40px;
    height: 40px;
    background-color: var(--color-default);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    color: white;
    transition: all 0.3s ease;
    cursor: pointer;
}

.tree-node.highlighted {
    background-color: var(--color-current);
    transform: scale(1.2);
}

.tree-edge {
    position: absolute;
    background-color: var(--text-secondary);
    transform-origin: left center;
}

/* Heap Visualization */
.heap-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.heap-tree {
    height: 200px;
    position: relative;
}

.heap-array {
    display: flex;
    justify-content: center;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.heap-element {
    width: 40px;
    height: 40px;
    background-color: var(--color-default);
    border: 2px solid var(--border-color);
    border-radius: 0.375rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    color: white;
    transition: all 0.3s ease;
}

.heap-element.highlighted {
    background-color: var(--color-current);
    transform: scale(1.1);
}

/* Stack & Queue Visualization */
.stack-queue-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    grid-column: 1 / -1;
}

.stack-section,
.queue-section {
    background-color: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

.stack-container {
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: 0.25rem;
    min-height: 200px;
    padding: 1rem;
    border: 2px dashed var(--border-color);
    border-radius: 0.5rem;
    margin: 1rem 0;
}

.queue-container {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    min-height: 80px;
    padding: 1rem;
    border: 2px dashed var(--border-color);
    border-radius: 0.5rem;
    margin: 1rem 0;
    overflow-x: auto;
}

.stack-element,
.queue-element {
    background-color: var(--color-default);
    border: 2px solid var(--border-color);
    border-radius: 0.375rem;
    padding: 0.5rem 1rem;
    font-weight: 500;
    color: white;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.stack-element.new,
.queue-element.new {
    background-color: var(--color-current);
    transform: scale(1.1);
}

/* Hash Table Visualization */
.hash-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.hash-bucket {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
}

.hash-index {
    font-weight: 600;
    color: var(--text-accent);
    min-width: 30px;
}

.hash-chain {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.hash-item {
    background-color: var(--color-default);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.hash-item.highlighted {
    background-color: var(--color-current);
    transform: scale(1.05);
}

/* Info Panel */
.info-panel {
    background-color: var(--bg-secondary);
    padding: 1.5rem;
    height: 100%;
    border-radius: 0.75rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

.info-panel h3 {
    margin-bottom: 1rem;
    color: var(--text-accent);
    font-size: 1.25rem;
    font-weight: 600;
}

.algorithm-description {
    margin-bottom: 1.5rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.complexity-table {
    overflow-x: auto;
}

.complexity-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.complexity-table th,
.complexity-table td {
    padding: 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.complexity-table th {
    background-color: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-primary);
}

.complexity-table td {
    color: var(--text-secondary);
}

/* Footer */
.footer {
    background-color: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 1rem 0;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .visualizer-content {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .stack-queue-container {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .header .container {
        flex-direction: column;
        text-align: center;
    }

    .nav {
        justify-content: center;
    }

    .nav-btn {
        font-size: 0.75rem;
        padding: 0.375rem 0.75rem;
    }

    .visualizer-header h2 {
        font-size: 1.5rem;
    }

    .array-container {
        padding: 0.5rem;
    }

    .array-bar {
        min-width: 15px;
        font-size: 0.625rem;
    }

    .controls-panel,
    .info-panel {
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 0.5rem;
    }

    .main {
        padding: 1rem 0;
    }

    .visualizer-content {
        gap: 1rem;
    }

    .array-bar {
        min-width: 12px;
        font-size: 0.5rem;
    }

    .array-element {
        min-width: 50px;
        padding: 0.5rem;
        font-size: 0.75rem;
    }
}

/* Footer Styles */
footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    margin-top: 4rem;
    padding: 3rem 0 1rem;
}

.footer-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
    padding: 0 1rem;
}

.footer-section h3 {
    color: var(--text-accent);
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

.footer-section h4 {
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    font-size: 1.1rem;
}

.footer-section p {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 0.5rem;
}

.footer-section ul {
    list-style: none;
    padding: 0;
}

.footer-section li {
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    padding-left: 1rem;
    position: relative;
}

.footer-section li::before {
    content: "▶";
    color: var(--text-accent);
    position: absolute;
    left: 0;
    font-size: 0.8rem;
}

.footer-bottom {
    border-top: 1px solid var(--border-color);
    padding-top: 1.5rem;
    text-align: center;
}

.footer-bottom p {
    color: var(--text-secondary);
    margin: 0;
}

/* Animation Classes */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

.slide-in {
    animation: slideIn 0.3s ease-out;
}

.pulse {
    animation: pulse 0.5s ease-in-out;
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus styles for keyboard navigation */
button:focus,
input:focus,
select:focus {
    outline: 2px solid var(--text-accent);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000000;
        --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    }

    [data-theme="dark"] {
        --border-color: #ffffff;
    }
}