/* ===== CSS Variables & Reset ===== */
:root {
    /* Light Mode - Vibrant Professional Colors */
    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);
    --quicksort-gradient: linear-gradient(135deg, #3b82f6 0%, #06b6d4 100%);
    --rbtree-gradient: linear-gradient(135deg, #ec4899 0%, #f43f5e 100%);
    --knapsack-gradient: linear-gradient(135deg, #10b981 0%, #14b8a6 100%);
    
    --color-bg: linear-gradient(135deg, #f0f4ff 0%, #e0e7ff 50%, #f5f3ff 100%);
    --color-card: #ffffff;
    --color-text: #1e293b;
    --color-text-light: #64748b;
    --color-border: #e2e8f0;
    --color-muted: #f1f5f9;
    
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.08);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.12);
    --shadow-xl: 0 20px 40px rgba(0,0,0,0.15);
    --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.15);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-xl: 30px;
    
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Mode Variables */
[data-theme="dark"] {
    --primary-gradient: linear-gradient(135deg, #818cf8 0%, #a78bfa 50%, #c084fc 100%);
    --quicksort-gradient: linear-gradient(135deg, #60a5fa 0%, #22d3ee 100%);
    --rbtree-gradient: linear-gradient(135deg, #f472b6 0%, #fb7185 100%);
    --knapsack-gradient: linear-gradient(135deg, #34d399 0%, #2dd4bf 100%);
    
    --color-bg: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #312e81 100%);
    --color-card: #1e293b;
    --color-text: #f1f5f9;
    --color-text-light: #94a3b8;
    --color-border: #334155;
    --color-muted: #334155;
    
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.5);
    --shadow-xl: 0 20px 40px rgba(0,0,0,0.6);
    --shadow-glow: 0 0 40px rgba(129, 140, 248, 0.2);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', sans-serif;
    background: var(--color-bg);
    background-attachment: fixed;
    min-height: 100vh;
    color: var(--color-text);
    line-height: 1.6;
    transition: var(--transition);
}

/* Dark Mode Toggle Button */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--primary-gradient);
    border: none;
    color: white;
    font-size: 1.3rem;
    cursor: pointer;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    transform: scale(1.1) rotate(15deg);
    box-shadow: var(--shadow-xl), 0 0 30px rgba(99, 102, 241, 0.4);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* ===== Hero Section ===== */
.hero {
    background: var(--primary-gradient);
    border-radius: var(--radius-lg);
    padding: 60px 40px;
    margin-bottom: 30px;
    text-align: center;
    box-shadow: var(--shadow-xl), var(--shadow-glow);
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.1);
}

.hero::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.1'%3E%3Ccircle cx='30' cy='30' r='4'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    opacity: 0.6;
}

.hero-content {
    position: relative;
    z-index: 1;
}

.assignment-badge {
    display: inline-block;
    background: rgba(255,255,255,0.2);
    color: white;
    padding: 8px 20px;
    border-radius: 50px;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 20px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.3);
}

.hero h1 {
    font-size: 3.5rem;
    color: white;
    margin-bottom: 15px;
    font-weight: 700;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
    font-family: 'Playfair Display', serif;
}

.hero h1 i {
    margin-right: 15px;
}

.subtitle {
    font-size: 1.2rem;
    color: rgba(255,255,255,0.9);
    max-width: 600px;
    margin: 0 auto 20px;
}

.creator-info {
    background: rgba(255,255,255,0.15);
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 12px 25px;
    border-radius: 50px;
    color: white;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.3);
    margin-top: 10px;
}

.creator-info i {
    font-size: 1.2rem;
}

.creator-info strong {
    font-weight: 600;
}

/* ===== Input Section ===== */
.input-section {
    margin-bottom: 40px;
}

.input-card {
    background: var(--color-card);
    border-radius: var(--radius-lg);
    padding: 30px;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    border: 1px solid var(--color-border);
    transition: var(--transition);
}

.input-card:hover {
    box-shadow: var(--shadow-xl);
}

.input-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.input-group-full {
    width: 100%;
}

.input-group-full label {
    display: block;
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 8px;
}

.input-group-full label i {
    margin-right: 8px;
    color: var(--color-primary);
}

.input-group-full input {
    width: 100%;
    padding: 15px 20px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-family: 'Poppins', sans-serif;
    background: var(--color-card);
    color: var(--color-text);
    transition: var(--transition);
}

.input-group-full input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.input-group-half label {
    display: block;
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 8px;
}

.input-group-half label i {
    margin-right: 8px;
    color: var(--color-primary);
}

.input-group-half input {
    width: 100%;
    padding: 15px 20px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-family: 'Poppins', sans-serif;
    background: var(--color-card);
    color: var(--color-text);
    transition: var(--transition);
}

.input-group-half input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.button-row {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: var(--transition);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: linear-gradient(135deg, #ed8936 0%, #dd6b20 100%);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: var(--transition);
    box-shadow: 0 4px 15px rgba(237, 137, 54, 0.4);
}

.btn-secondary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(237, 137, 54, 0.5);
}

.btn-secondary:disabled {
    background: #cbd5e0;
    cursor: not-allowed;
    box-shadow: none;
}

.hint {
    color: var(--color-text-light);
    font-size: 0.9rem;
    font-style: italic;
    display: flex;
    align-items: center;
    gap: 8px;
}

.hint i {
    color: #667eea;
}

/* ===== ID Display Section ===== */
.id-display {
    margin-bottom: 40px;
}

.id-card {
    background: var(--primary-gradient);
    border-radius: var(--radius-lg);
    padding: 30px;
    color: white;
    box-shadow: var(--shadow-lg), 0 0 30px rgba(99, 102, 241, 0.3);
    border: 1px solid rgba(255,255,255,0.1);
}

.id-card h3 {
    font-size: 1.3rem;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.id-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 15px;
}

.id-original, .id-doubled {
    padding: 15px;
    background: rgba(255,255,255,0.15);
    border-radius: var(--radius-md);
    backdrop-filter: blur(10px);
}

.id-original .label, .id-doubled .label, .numbers-array .label {
    font-weight: 600;
    display: block;
    margin-bottom: 8px;
    font-size: 0.9rem;
    opacity: 0.9;
}

.id-original .value, .id-doubled .value {
    font-family: 'Courier New', monospace;
    font-size: 1.2rem;
    letter-spacing: 2px;
    word-break: break-all;
}

.numbers-array {
    padding: 15px;
    background: rgba(255,255,255,0.15);
    border-radius: var(--radius-md);
    backdrop-filter: blur(10px);
}

.array-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.array-badge {
    background: rgba(255,255,255,0.9);
    color: #764ba2;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-family: 'Courier New', monospace;
    font-size: 1.1rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* ===== Tabs ===== */
.algorithms-tabs {
    margin-bottom: 40px;
}

.tabs-header {
    display: flex;
    gap: 10px;
    margin-bottom: 0;
    background: var(--color-muted);
    padding: 10px;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    border: 1px solid var(--color-border);
    border-bottom: none;
}

.tab-btn {
    flex: 1;
    padding: 15px 20px;
    border: none;
    background: transparent;
    color: #718096;
    font-family: 'Poppins', sans-serif;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.tab-btn:hover {
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
}

.tab-btn.active {
    background: white;
    color: #667eea;
    box-shadow: var(--shadow-sm);
}

.tab-btn i {
    font-size: 1.1rem;
}

.tab-content {
    display: none;
    background: var(--color-card);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    border: 1px solid var(--color-border);
    border-top: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

/* ===== Algorithm Sections ===== */
.algorithm-section {
    background: var(--color-card);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    overflow: hidden;
}

.section-header {
    padding: 25px 30px;
    display: flex;
    align-items: center;
    gap: 20px;
    border-bottom: 1px solid #e2e8f0;
}

.quicksort-header {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.15) 0%, rgba(6, 182, 212, 0.15) 100%);
    border-left: 5px solid #3b82f6;
}

.rbtree-header {
    background: linear-gradient(135deg, rgba(236, 72, 153, 0.15) 0%, rgba(244, 63, 94, 0.15) 100%);
    border-left: 5px solid #ec4899;
}

.knapsack-header {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.15) 0%, rgba(20, 184, 166, 0.15) 100%);
    border-left: 5px solid #10b981;
}

.icon-circle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    box-shadow: var(--shadow-md);
}

.bg-blue { background: var(--quicksort-gradient); }
.bg-red { background: var(--rbtree-gradient); }
.bg-green { background: var(--knapsack-gradient); }

.section-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

.section-content {
    padding: 30px;
}

.algorithm-description {
    background: var(--color-muted);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 25px;
    border-left: 4px solid var(--color-border);
}

.algorithm-description p {
    color: var(--color-text-light);
    font-size: 0.95rem;
}

.algorithm-output {
    min-height: 200px;
}

.placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--color-text-light);
    text-align: center;
}

.placeholder i {
    font-size: 3rem;
    margin-bottom: 20px;
    opacity: 0.5;
}

/* ===== Quick Sort Styles ===== */
.quicksort-container {
    font-family: 'Courier New', monospace;
    width: 100%;
    overflow-x: hidden;
}

.sort-step {
    background: var(--color-muted);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 20px;
    border: 2px solid var(--color-border);
    transition: var(--transition);
    overflow-x: auto;
}

.sort-step:hover {
    box-shadow: var(--shadow-md);
}

.step-header {
    font-weight: 600;
    color: #3b82f6;
    margin-bottom: 15px;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.array-visualization {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 15px;
    padding: 15px;
    background: var(--color-card);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
}

.array-element {
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 1.1rem;
    transition: var(--transition);
    position: relative;
}

.array-element.pivot {
    background: linear-gradient(135deg, #f6ad55 0%, #ed8936 100%);
    color: white;
    box-shadow: 0 4px 10px rgba(237, 137, 54, 0.4);
}

.array-element.pivot::after {
    content: 'P';
    position: absolute;
    top: -8px;
    right: -8px;
    background: #ed8936;
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 0.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.array-element.less {
    background: linear-gradient(135deg, #68d391 0%, #48bb78 100%);
    color: white;
}

.array-element.greater {
    background: linear-gradient(135deg, #fc8181 0%, #f56565 100%);
    color: white;
}

.array-element.unprocessed {
    background: #e2e8f0;
    color: #4a5568;
}

.array-element.sorted {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 10px rgba(102, 126, 234, 0.4);
}

.step-description {
    background: var(--color-card);
    padding: 15px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    color: var(--color-text-light);
    border-left: 3px solid #3b82f6;
}

.step-description strong {
    color: #3b82f6;
}

.final-result {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
    padding: 25px;
    border-radius: var(--radius-md);
    text-align: center;
    margin-top: 20px;
}

.final-result h3 {
    margin-bottom: 15px;
    font-size: 1.3rem;
}

/* ===== Partition Visualization ===== */
.partition-visual {
    background: var(--color-card);
    border-radius: var(--radius-sm);
    padding: 15px;
    margin: 15px 0;
    border: 1px solid var(--color-border);
}

.partition-row {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    flex-wrap: wrap;
    gap: 10px;
}

.partition-row:last-child {
    margin-bottom: 0;
}

.partition-label {
    font-weight: 600;
    color: var(--color-text-light);
    min-width: 110px;
    font-size: 0.9rem;
}

.partition-array {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 10px 0;
    padding: 10px;
    background: var(--color-muted);
    border-radius: var(--radius-sm);
}

.partition-detail {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 8px 0;
    font-size: 0.9rem;
    flex-wrap: wrap;
}

.detail-label {
    font-weight: 600;
    color: var(--color-text);
    min-width: 180px;
}

.p-swap-val {
    background: #8b5cf6;
    color: white;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-family: 'Courier New', monospace;
}

.p-elem {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.95rem;
    font-family: 'Courier New', monospace;
    transition: all 0.2s ease;
}

.p-pivot {
    background: linear-gradient(135deg, #f59e0b 0%, #f97316 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(249, 115, 22, 0.4);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.p-pivot-badge {
    background: linear-gradient(135deg, #f59e0b 0%, #f97316 100%);
    color: white;
    padding: 6px 14px;
    border-radius: 20px;
    font-weight: 700;
    font-family: 'Courier New', monospace;
}

.p-left {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

.p-right {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
}

.p-swap {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    color: white;
    animation: bounce 0.5s ease;
}

@keyframes bounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.p-scan {
    background: linear-gradient(135deg, #06b6d4 0%, #0891b2 100%);
    color: white;
    box-shadow: 0 0 8px rgba(6, 182, 212, 0.6);
}

.p-unprocessed {
    background: var(--color-border);
    color: var(--color-text-light);
}

.p-empty {
    color: var(--color-text-light);
    font-style: italic;
    font-size: 0.9rem;
}

/* ===== Red-Black Tree Styles ===== */
.rbtree-container {
    font-family: 'Courier New', monospace;
    width: 100%;
    overflow-x: hidden;
}

.tree-step {
    background: var(--color-muted);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 20px;
    border: 2px solid var(--color-border);
    overflow-x: auto;
}

.tree-step-header {
    font-weight: 600;
    color: #f5576c;
    margin-bottom: 15px;
    font-size: 1.1rem;
}

.tree-visualization {
    background: var(--color-card);
    border-radius: var(--radius-md);
    padding: 30px;
    overflow-x: auto;
    min-height: 200px;
    border: 1px solid var(--color-border);
}

.tree-svg {
    min-width: 600px;
}

.tree-legend {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    padding: 15px;
    background: var(--color-card);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid #333;
}

.legend-color.red { background: #e53e3e; }
.legend-color.black { background: #2d3748; }

.tree-node {
    cursor: pointer;
    transition: var(--transition);
}

.tree-node:hover {
    filter: brightness(1.1);
}

.node-circle {
    stroke-width: 2px;
    stroke: #1a202c;
}

.node-text {
    font-family: 'Courier New', monospace;
    font-weight: 700;
    font-size: 14px;
    fill: white;
    text-anchor: middle;
    dominant-baseline: middle;
}

.node-circle.red {
    fill: #e53e3e;
}

.node-circle.black {
    fill: #2d3748;
}

.tree-edge {
    stroke: #718096;
    stroke-width: 2px;
    fill: none;
}

.step-actions {
    margin-top: 15px;
    padding: 15px;
    background: var(--color-card);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    border: 1px solid var(--color-border);
}

.step-actions ul {
    margin-left: 20px;
    margin-top: 10px;
}

.step-actions li {
    margin-bottom: 5px;
    color: var(--color-text-light);
}

/* ===== Compact RB Tree Styles ===== */
.tree-insert-block {
    background: var(--color-muted);
    border-radius: var(--radius-md);
    margin-bottom: 15px;
    overflow: hidden;
    border: 1px solid var(--color-border);
}

.tree-insert-header {
    background: linear-gradient(135deg, rgba(236, 72, 153, 0.1) 0%, rgba(244, 63, 94, 0.1) 100%);
    padding: 12px 15px;
    font-weight: 600;
    color: #ec4899;
    border-bottom: 1px solid var(--color-border);
}

.tree-insert-header i {
    margin-right: 8px;
}

.tree-simple-view {
    padding: 20px;
    display: flex;
    justify-content: flex-start;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tree-fix-step {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    border-top: 1px solid var(--color-border);
}

.tree-fix-step:first-child {
    border-top: none;
}

.fix-label {
    min-width: 120px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===== Knapsack Styles ===== */
.knapsack-container {
    font-family: 'Poppins', sans-serif;
    width: 100%;
    overflow-x: hidden;
}

.ks-section-title {
    color: var(--color-text);
    margin-bottom: 15px;
    font-size: 1.1rem;
}

/* Items Table */
.knapsack-table-container {
    margin-bottom: 25px;
    overflow-x: auto;
}

.knapsack-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-card);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.knapsack-table th,
.knapsack-table td {
    padding: 15px;
    text-align: center;
    border: 1px solid var(--color-border);
}

.knapsack-table th {
    background: linear-gradient(135deg, #00f2fe 0%, #4facfe 100%);
    color: white;
    font-weight: 600;
}

.knapsack-table tr:nth-child(even) {
    background: var(--color-muted);
}

.value-cell {
    font-family: 'Courier New', monospace;
    font-weight: 700;
    color: var(--color-text);
}

.weight-cell {
    font-family: 'Courier New', monospace;
    font-weight: 600;
    color: var(--color-text-light);
}

.ratio-cell {
    font-family: 'Courier New', monospace;
    color: #10b981;
    font-weight: 600;
}

/* Explanation */
.ks-explanation {
    background: var(--color-muted);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 25px;
    border-left: 4px solid #3b82f6;
}

.ks-explanation h4 {
    color: var(--color-text);
    margin-bottom: 12px;
    font-size: 1rem;
}

.ks-explanation p {
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: var(--color-text-light);
}

/* Selection Table */
.knapsack-steps {
    margin-top: 25px;
}

.knapsack-selection-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-card);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.knapsack-selection-table th,
.knapsack-selection-table td {
    padding: 12px 15px;
    text-align: center;
    border: 1px solid var(--color-border);
}

.knapsack-selection-table th {
    background: var(--color-muted);
    font-weight: 600;
    color: var(--color-text);
}

.ks-selection-row.full {
    background: rgba(16, 185, 129, 0.05);
}

.ks-selection-row.partial {
    background: rgba(245, 158, 11, 0.05);
}

.ks-action-full {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.ks-action-partial {
    background: linear-gradient(135deg, #f59e0b 0%, #f97316 100%);
    color: white;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* Capacity Section */
.ks-capacity-section {
    margin: 25px 0;
    padding: 20px;
    background: var(--color-muted);
    border-radius: var(--radius-md);
}

.ks-capacity-bar {
    margin: 15px 0;
    background: var(--color-border);
}

.ks-capacity-fill {
    background: linear-gradient(90deg, #10b981 0%, #14b8a6 100%);
}

.ks-capacity-text {
    text-align: center;
    color: var(--color-text-light);
    font-size: 0.9rem;
    margin-top: 8px;
}

/* Final Summary Table */
.knapsack-summary {
    background: var(--knapsack-gradient);
    color: white;
    padding: 25px;
    border-radius: var(--radius-md);
    margin-top: 25px;
}

.knapsack-summary h3 {
    margin-bottom: 20px;
    font-size: 1.2rem;
}

.knapsack-final-table {
    width: 100%;
    border-collapse: collapse;
    background: rgba(255,255,255,0.1);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.knapsack-final-table th,
.knapsack-final-table td {
    padding: 15px 20px;
    text-align: left;
    border-bottom: 1px solid rgba(255,255,255,0.2);
}

.knapsack-final-table th {
    background: rgba(255,255,255,0.15);
    font-weight: 600;
}

.ks-highlight-value {
    font-size: 1.3rem;
    font-weight: 700;
    font-family: 'Courier New', monospace;
}

/* ===== Modal Styles ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: var(--color-card);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 1000px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: var(--shadow-xl);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    background: var(--primary-gradient);
    color: white;
    padding: 25px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    gap: 12px;
}

.modal-close {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: rgba(255,255,255,0.3);
    transform: rotate(90deg);
}

.modal-body {
    padding: 30px;
    overflow-y: auto;
    max-height: calc(90vh - 100px);
}

/* ===== Theme Grid ===== */
.theme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
}

.theme-card {
    background: var(--color-muted);
    border-radius: var(--radius-md);
    padding: 15px;
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid transparent;
    text-align: center;
}

.theme-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
    border-color: #667eea;
}

.theme-preview {
    height: 120px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    border: 1px solid #e2e8f0;
}

.theme-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text);
}

/* Theme Preview Styles */
.theme-1 { background: linear-gradient(135deg, #ffffff 0%, #f7fafc 100%); border: 2px solid #2d3748; }
.theme-2 { background: linear-gradient(135deg, #f5f5f5 0%, #ffffff 100%); }
.theme-3 { background: linear-gradient(135deg, #ebf8ff 0%, #bee3f8 100%); }
.theme-4 { background: linear-gradient(135deg, #1a202c 0%, #2d3748 100%); }
.theme-5 { background: linear-gradient(135deg, #fffaf0 0%, #feebc8 100%); }
.theme-6 { background: linear-gradient(135deg, #f0fff4 0%, #c6f6d5 100%); }
.theme-7 { background: linear-gradient(135deg, #faf5ff 0%, #e9d8fd 100%); }
.theme-8 { background: linear-gradient(135deg, #fff5f5 0%, #fed7d7 100%); }
.theme-9 { background: linear-gradient(135deg, #fffaf0 0%, #fdd9a9 100%); }
.theme-10 { background: linear-gradient(135deg, #e6fffa 0%, #b2f5ea 100%); }
.theme-11 { background: linear-gradient(135deg, #f7fafc 0%, #e2e8f0 100%); }
.theme-12 { background: linear-gradient(135deg, #fff5f7 0%, #fedde9 100%); }
.theme-13 { background: linear-gradient(135deg, #f7f2ed 0%, #e8ddd4 100%); }
.theme-14 { background: linear-gradient(135deg, #ecfeff 0%, #a5f3fc 100%); }
.theme-15 { background: linear-gradient(135deg, #fffbeb 0%, #fde68a 100%); }
.theme-16 { background: linear-gradient(135deg, #1e3a5f 0%, #2c5282 100%); }
.theme-17 { background: linear-gradient(135deg, #f0fdf4 0%, #86efac 100%); }
.theme-18 { background: linear-gradient(135deg, #eef2ff 0%, #c7d2fe 100%); }
.theme-19 { background: linear-gradient(135deg, #fff1f2 0%, #fda4af 100%); }
.theme-20 { background: linear-gradient(135deg, #f8fafc 0%, #94a3b8 100%); }

/* ===== Footer ===== */
footer {
    background: var(--color-card);
    border-radius: var(--radius-lg);
    padding: 30px;
    margin-top: 20px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--color-border);
}

.footer-content {
    text-align: center;
}

.footer-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 8px;
}

.footer-title i {
    color: #6366f1;
    margin-right: 8px;
}

.footer-creator {
    color: var(--color-text-light);
    font-size: 0.95rem;
    margin-bottom: 5px;
}

.footer-year {
    color: #a0aec0;
    font-size: 0.85rem;
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sort-step, .tree-step, .knapsack-step {
    animation: fadeIn 0.5s ease forwards;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.array-element.pivot {
    animation: pulse 1s ease infinite;
}

/* ===== Responsive Design ===== */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .hero {
        padding: 30px 15px;
        margin-bottom: 20px;
    }
    
    .hero h1 {
        font-size: 1.8rem;
    }
    
    .hero .subtitle {
        font-size: 0.9rem;
        padding: 0 10px;
    }
    
    .assignment-badge {
        font-size: 0.8rem;
        padding: 6px 15px;
    }
    
    .input-card {
        padding: 20px 15px;
    }
    
    .input-row {
        grid-template-columns: 1fr;
    }
    
    .input-group-full input {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 12px 15px;
    }
    
    .button-row {
        flex-direction: column;
        gap: 10px;
    }
    
    .btn-primary, .btn-secondary {
        width: 100%;
        justify-content: center;
        padding: 14px 20px;
        font-size: 1rem;
    }
    
    .hint {
        font-size: 0.8rem;
        padding: 0 5px;
    }
    
    .section-header {
        flex-direction: column;
        text-align: center;
        gap: 10px;
    }
    
    .section-title {
        font-size: 1.3rem;
    }
    
    .tabs-header {
        flex-direction: column;
        gap: 8px;
    }
    
    .tab-btn {
        width: 100%;
        padding: 12px 15px;
        font-size: 0.9rem;
    }
    
    .id-display {
        padding: 20px 15px;
    }
    
    .id-info-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .array-badge {
        width: 35px;
        height: 35px;
        font-size: 0.85rem;
    }
    
    .array-visualization {
        gap: 4px;
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 10px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        justify-content: flex-start;
    }
    
    .partition-array {
        gap: 3px;
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 8px;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
    }
    
    .array-element {
        width: 28px;
        height: 28px;
        font-size: 0.7rem;
        flex-shrink: 0;
    }
    
    .p-elem {
        width: 26px;
        height: 26px;
        font-size: 0.7rem;
        flex-shrink: 0;
    }
    
    .sort-step, .tree-step, .knapsack-step {
        padding: 12px;
        overflow-x: hidden;
    }
    
    .step-header {
        font-size: 0.85rem;
    }
    
    .partition-detail {
        font-size: 0.75rem;
    }
    
    /* Tree visualization mobile fixes */
    .tree-visualization {
        padding: 10px 5px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        display: flex;
        justify-content: flex-start;
    }
    
    .tree-svg {
        min-width: 350px;
        max-width: 600px;
        width: 100%;
        height: auto;
    }
    
    .tree-simple-view {
        padding: 10px 5px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        display: flex;
        justify-content: flex-start;
    }
    
    .tree-simple-view .tree-svg {
        min-width: 300px;
    }
    
    .tree-legend {
        flex-wrap: wrap;
        gap: 10px;
        padding: 10px;
    }
    
    .legend-item {
        font-size: 0.8rem;
    }
    
    .legend-color {
        width: 16px;
        height: 16px;
    }
    
    .tree-svg .node-text {
        font-size: 11px;
    }
    
    .tree-svg .node-circle {
        stroke-width: 1.5px;
    }
    
    .knapsack-item {
        padding: 12px;
    }
    
    .knapsack-item-header {
        flex-direction: column;
        gap: 8px;
    }
    
    .item-stats {
        width: 100%;
        justify-content: space-between;
    }
    
    .stat-badge {
        padding: 4px 8px;
        font-size: 0.75rem;
    }
    
    .knapsack-bar-container {
        height: 25px;
    }
    
    .knapsack-bar {
        font-size: 0.75rem;
    }
    
    .final-result h3 {
        font-size: 1.1rem;
    }
    
    /* Knapsack table mobile fixes */
    .knapsack-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .knapsack-table {
        min-width: 350px;
    }
    
    .knapsack-table th,
    .knapsack-table td {
        padding: 8px 10px;
        font-size: 0.8rem;
    }
    
    .knapsack-selection-table {
        min-width: 300px;
    }
    
    .knapsack-selection-table th,
    .knapsack-selection-table td {
        padding: 8px 10px;
        font-size: 0.8rem;
    }
    
    .theme-toggle {
        width: 45px;
        height: 45px;
        font-size: 1.1rem;
        top: 10px;
        right: 10px;
    }
    
    .footer-content {
        padding: 20px 15px;
    }
    
    .footer-title {
        font-size: 1rem;
    }
}

/* Smaller phones */
@media (max-width: 480px) {
    .hero h1 {
        font-size: 1.5rem;
    }
    
    .hero .subtitle {
        font-size: 0.8rem;
    }
    
    .section-title {
        font-size: 1.1rem;
    }
    
    /* Smaller arrays for tiny screens */
    .array-element {
        width: 24px;
        height: 24px;
        font-size: 0.65rem;
    }
    
    .p-elem {
        width: 22px;
        height: 22px;
        font-size: 0.65rem;
    }
    
    .array-badge {
        width: 26px;
        height: 26px;
        font-size: 0.7rem;
    }
    
    .array-visualization {
        gap: 3px;
    }
    
    .partition-array {
        gap: 2px;
    }
    
    /* Tree fixes for small screens */
    .tree-visualization {
        padding: 8px 3px;
    }
    
    .tree-svg {
        min-width: 280px;
        max-width: 100%;
    }
    
    .tree-simple-view {
        padding: 8px 3px;
    }
    
    .tree-simple-view .tree-svg {
        min-width: 250px;
    }
    
    .tree-svg .node-circle {
        r: 16;
    }
    
    .tree-svg .node-text {
        font-size: 9px;
    }
    
    .tree-node {
        width: 26px;
        height: 26px;
        font-size: 0.65rem;
    }
    
    .tab-content {
        padding: 10px 8px;
    }
    
    .sort-step, .tree-step, .knapsack-step {
        padding: 10px 8px;
        margin-bottom: 15px;
    }
    
    .step-header {
        font-size: 0.8rem;
    }
    
    .partition-row {
        flex-direction: column;
        gap: 6px;
    }
    
    .tree-canvas {
        min-height: 180px;
    }
    
    .quicksort-container, .rbtree-container, .knapsack-container {
        overflow-x: hidden;
    }
    
    /* Small screen knapsack fixes */
    .knapsack-table {
        min-width: 320px;
    }
    
    .knapsack-table th,
    .knapsack-table td {
        padding: 6px 8px;
        font-size: 0.75rem;
    }
    
    .knapsack-selection-table {
        min-width: 280px;
    }
    
    .knapsack-selection-table th,
    .knapsack-selection-table td {
        padding: 6px 8px;
        font-size: 0.75rem;
    }
    
    .ks-action-full, .ks-action-partial {
        padding: 3px 6px;
        font-size: 0.7rem;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn-primary, .btn-secondary, .tab-btn, .theme-toggle {
        min-height: 44px; /* Minimum touch target size */
    }
    
    .array-element, .p-elem, .tree-node, .array-badge {
        min-width: 32px;
        min-height: 32px;
    }
    
    input, button {
        font-size: 16px !important; /* Prevent zoom on focus */
    }
}

/* ===== Scrollbar Styling ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}
