body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    margin: 0;
    padding: 0;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
}
/* Palette variables */
:root{
    --p1: #3C467B;
    --p2: #50589C;
    --p3: #636CCB;
    --p4: #6E8CFB;
    --bg: #f4f4f9;
    --muted: #fafbff;
    --accent: var(--p3);
    --accent-strong: var(--p1);
    --success: #50c878;
    --danger: #e94e77;
    --shadow: rgba(60,68,123,0.18);
}
header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px 20px;
    width: 100%;
    text-align: center;
    font-size: 2.2em;
    font-weight: 700;
    letter-spacing: -0.5px;
    box-shadow: 0 8px 32px rgba(102, 126, 234, 0.15);
}
#tabs {
    display: flex;
    margin: 28px auto;
    width: calc(100% - 40px);
    max-width: 920px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
    gap: 4px;
    padding: 6px;
}
.tab-btn {
    flex: 1;
    padding: 12px 16px;
    background: transparent;
    border: none;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 8px;
    font-weight: 500;
    color: #666;
}
.tab-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.25);
}
.tab-btn:hover {
    background: rgba(102, 126, 234, 0.08);
}
.tab-content {
    display: none;
    padding: 28px;
    width: calc(100% - 56px);
    max-width: 860px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
    margin: 0 auto 40px;
}
.tab-content.active {
    display: block;
}
label {
    display: block;
    margin-top: 12px;
    margin-bottom: 6px;
    font-weight: 500;
    color: #333;
    font-size: 0.95em;
}
input[type="text"], select {
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 12px;
    border-radius: 8px;
    border: 1px solid #ddd;
    box-sizing: border-box;
    font-size: 0.95em;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}
input[type="text"]:focus, select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
button {
    margin-top: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 0.95em;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 500;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.2);
}
button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
}
button:active {
    transform: translateY(0);
}
.visualization {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    height: 320px;
    border: 1px solid #e5e5e5;
    border-radius: 10px;
    background: linear-gradient(to bottom, #fafbff, #f5f7fa);
    overflow-x: auto;
    padding: 16px;
    position: relative;
}
.bar {
    height: 100%;
    margin: 0 4px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    width: 22px;
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    color: white;
    font-weight: 600;
    font-size: 0.75em;
    user-select: none;
    transition: all 0.28s ease;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}
.bar:hover {
    transform: scaleY(1.05);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.25);
}
.bar.active, .node.active, .stack-node.active, .queue-node.active, .tree-node.active {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    box-shadow: 0 6px 20px rgba(245, 87, 108, 0.25);
}
.bar.found, .node.found, .stack-node.found, .queue-node.found, .tree-node.found {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}
.bar.comparing, .node.comparing {
    background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
}
.bar.min, .node.min {
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
}
.bar.sorted, .node.sorted {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
}
.bar.dividing, .node.dividing {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* Data Structures Styles */
#ds-section .visualization {
    height: auto; /* Allow content to dictate height, but set a min */
    min-height: 200px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-start;
    overflow: auto;
    max-width: 900px; /* Match tab/content width */
    display: flex; /* Ensure it uses flex */
    flex-direction: row; /* Default for linked lists/queues */
}

/* Linked List */
.list-container {
    display: flex;
    align-items: center;
    margin-right: 15px;
    position: relative;
}
.node {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: 2px solid #e5e5e5;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-weight: 600;
    font-size: 0.85em;
    transition: all 0.28s ease;
    z-index: 10;
    position: relative;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}
.node:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 18px rgba(102, 126, 234, 0.25);
}
.list-arrow {
    font-size: 20px;
    font-weight: bold;
    color: #333;
    margin: 0;
    line-height: 1;
    display: block;
}

.list-back-arrow {
    font-size: 14px;
    color: #9c27b0;
    line-height: 1;
}

.arrow-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.stack-node {
    width: 56px;
    height: 38px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-weight: 600;
    margin: 2px 4px;
    transition: all 0.28s ease;
    position: relative;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

/* Queue */
.queue-node {
    width: 56px;
    height: 38px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-weight: 600;
    margin: 4px;
    transition: all 0.28s ease;
    position: relative;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

/* Binary Tree */
.tree-node {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-weight: 600;
    font-size: 0.8em;
    position: absolute;
    transition: all 0.28s ease;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}
.tree-connector {
    position: absolute;
    height: 2px;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    transform-origin: 0 0;
    z-index: 5;
}

#message, #sortMessage, #dsMessage {
    margin-top: 12px;
    font-size: 1em;
    font-weight: 500;
    text-align: center;
    color: #666;
}
.operation-group {
    display: none;
    margin-top: 20px;
}
.operation-group.active {
    display: block;
}