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

.comic-relief-regular {
  font-family: "Comic Relief", system-ui;
  font-weight: 400;
  font-style: normal;
}

.comic-relief-bold {
  font-family: "Comic Relief", system-ui;
  font-weight: 700;
  font-style: normal;
}

@font-face {
  font-family: 'Comic Relief';
  src: url('https://fonts.googleapis.com/css2?family=Comic+Relief:wght@400;700&display=swap') format('woff2');
  font-display: swap;
}

button:focus {
  outline: 2px solid #FF5733;
  outline-offset: 2px;
}



:root {
    /* Dark mode colors (existing) */
    --primary: #dc2626;
    --primary-dark: #991b1b;
    --secondary: #1f2937;
    --accent: #3b82f6;
    --success: #10b981;
    --warning: #f59e0b;
    --bg-dark: #0f172a;
    --bg-light: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border: #334155;
    --shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    
    /* Light mode colors */
    --light-bg-primary: #f8fafc;
    --light-bg-secondary: #ffffff;
    --light-bg-tertiary: #f1f5f9;
    --light-text-primary: #1e293b;
    --light-text-secondary: #475569;
    --light-border: #e2e8f0;
    --light-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.05), 0 10px 10px -5px rgba(0, 0, 0, 0.02);
    --light-primary: #ef4444;
    --light-primary-dark: #dc2626;
    --light-accent: #3b82f6;
    --light-success: #10b981;
    --light-warning: #f59e0b;
}

body {
    font-family: "Comic Relief", system-ui;
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-light) 100%);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

/* Light mode styles */
body.light-mode {
    background: linear-gradient(135deg, var(--light-bg-primary) 0%, var(--light-bg-secondary) 100%);
    color: var(--light-text-primary);
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 1.5rem;
}

header {
    text-align: center;
    margin-bottom: 2rem;
    animation: fadeInDown 0.8s ease;
    position: relative;
}

h1 {
    font-size: 2.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

body.light-mode h1 {
    background: linear-gradient(135deg, var(--light-primary) 0%, var(--light-accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-top: 1.5rem;
}

.tree-placeholder{
    margin-top: 1rem;
    font-size: small;
}

body.light-mode .subtitle {
    color: var(--light-text-secondary);
}

/* Theme toggle switch */
.theme-toggle {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.theme-toggle-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

body.light-mode .theme-toggle-label {
    color: var(--light-text-secondary);
}

.theme-switch {
    position: relative;
    width: 60px;
    height: 30px;
    background: var(--border);
    border-radius: 15px;
    cursor: pointer;
    transition: background 0.3s ease;
}

body.light-mode .theme-switch {
    background: var(--light-border);
}

.theme-switch-slider {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 24px;
    height: 24px;
    background: var(--text-primary);
    border-radius: 50%;
    transition: transform 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

body.light-mode .theme-switch-slider {
    background: var(--light-text-primary);
    transform: translateX(30px);
}

.theme-icon {
    font-size: 14px;
}

/* Update the main layout grid */
.main-layout {
    display: grid;
    grid-template-columns: 350px 1fr 350px;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

/* New algorithm panel styles */
.algorithm-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.visualization-panel {
    background: var(--bg-light);
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    animation: fadeIn 1s ease;
    display: flex;
    flex-direction: column;
    transition: background 0.3s ease, border 0.3s ease;
    min-height: 600px; /* Ensure panel has enough height */
}

body.light-mode .visualization-panel {
    background: var(--light-bg-secondary);
    border-color: var(--light-border);
    box-shadow: var(--light-shadow);
}

.right-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.panel {
    background: var(--bg-light);
    border-radius: 1rem;
    padding: 1.25rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    animation: fadeInRight 1s ease;
    transition: background 0.3s ease, border 0.3s ease;
}

body.light-mode .panel {
    background: var(--light-bg-secondary);
    border-color: var(--light-border);
    box-shadow: var(--light-shadow);
}

.panel-header {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: border-color 0.3s ease;
}

body.light-mode .panel-header {
    color: var(--light-accent);
    border-color: var(--light-border);
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.input-group {
    display: flex;
    gap: 0.5rem;
}

input[type="number"], input[type="range"] {
    flex: 1;
    padding: 0.6rem;
    background: var(--bg-dark);
    border: 2px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

body.light-mode input[type="number"], 
body.light-mode input[type="range"] {
    background: var(--light-bg-tertiary);
    border-color: var(--light-border);
    color: var(--light-text-primary);
}

input[type="number"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

body.light-mode input[type="number"]:focus {
    border-color: var(--light-accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

button {
    padding: 0.6rem 1.2rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

body.light-mode button {
    background: linear-gradient(135deg, var(--light-primary) 0%, var(--light-primary-dark) 100%);
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(220, 38, 38, 0.3);
}

body.light-mode button:hover {
    box-shadow: 0 10px 20px rgba(239, 68, 68, 0.3);
}

button:active {
    transform: translateY(0);
}

button.secondary {
    background: linear-gradient(135deg, var(--accent) 0%, #2563eb 100%);
}

body.light-mode button.secondary {
    background: linear-gradient(135deg, var(--light-accent) 0%, #2563eb 100%);
}

button.danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
}

button.success {
    background: linear-gradient(135deg, var(--success) 0%, #059669 100%);
}

body.light-mode button.success {
    background: linear-gradient(135deg, var(--light-success) 0%, #059669 100%);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.tree-container {
    position: relative;
    height: 500px; /* Increased from 350px to 500px */
    min-height: 500px; /* Ensure minimum height */
    overflow: hidden;
    background: radial-gradient(circle at center, rgba(59, 130, 246, 0.05) 0%, transparent 70%);
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    flex-grow: 1;
    cursor: grab;
    transition: background 0.3s ease;
}

/* Light mode adjustment */
body.light-mode .tree-container {
    background: radial-gradient(circle at center, rgba(59, 130, 246, 0.1) 0%, transparent 70%);
}
.tree-container.grabbing {
    cursor: grabbing;
}

svg {
    width: 100%;
    height: 100%;
    transition: transform 0.3s ease;
}

.node {
    cursor: pointer;
    transition: all 0.3s ease;
}

.node:hover {
    filter: brightness(1.2);
}

.node.highlighted {
    filter: brightness(1.5) drop-shadow(0 0 10px rgba(59, 130, 246, 0.8));
}

.node-circle {
    stroke-width: 3;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.3));
}

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

.edge {
    stroke: var(--text-secondary);
    stroke-width: 2;
    fill: none;
    opacity: 0.6;
    transition: stroke 0.3s ease;
}

body.light-mode .edge {
    stroke: var(--light-text-secondary);
}

.edge.highlighted {
    stroke: var(--accent);
    stroke-width: 3;
    opacity: 1;
}

body.light-mode .edge.highlighted {
    stroke: var(--light-accent);
}

.info-section {
    background: var(--bg-dark);
    border-radius: 0.5rem;
    padding: 0.8rem;
    margin-bottom: 0.75rem;
    border: 1px solid var(--border);
    transition: background 0.3s ease, border 0.3s ease;
}

body.light-mode .info-section {
    background: var(--light-bg-tertiary);
    border-color: var(--light-border);
}

.info-title {
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    transition: color 0.3s ease;
}

body.light-mode .info-title {
    color: var(--light-accent);
}

.info-content {
    color: var(--text-secondary);
    line-height: 1.5;
    font-size: 0.85rem;
    transition: color 0.3s ease;
}

body.light-mode .info-content {
    color: var(--light-text-secondary);
}

.metric {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
    transition: border-color 0.3s ease;
}

body.light-mode .metric {
    border-color: var(--light-border);
}

.metric:last-child {
    border-bottom: none;
}

.metric-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
    transition: color 0.3s ease;
}

body.light-mode .metric-label {
    color: var(--light-text-secondary);
}

.metric-value {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.85rem;
    transition: color 0.3s ease;
}

body.light-mode .metric-value {
    color: var(--light-text-primary);
}

.algorithm-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    flex-grow: 1;
}

.algorithm-display {
    background: var(--bg-dark);
    border-radius: 0.5rem;
    padding: 1.5rem;
    border: 1px solid var(--border);
    min-height: 200px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    transition: background 0.3s ease, border 0.3s ease;
}

body.light-mode .algorithm-display {
    background: var(--light-bg-tertiary);
    border-color: var(--light-border);
}

.algorithm-details {
    background: var(--bg-dark);
    border-radius: 0.5rem;
    padding: 1rem;
    border: 1px solid var(--border);
    transition: background 0.3s ease, border 0.3s ease;
}

body.light-mode .algorithm-details {
    background: var(--light-bg-tertiary);
    border-color: var(--light-border);
}

.details-title {
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    transition: color 0.3s ease;
}

body.light-mode .details-title {
    color: var(--light-accent);
}

.details-content {
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.6;
    transition: color 0.3s ease;
}

body.light-mode .details-content {
    color: var(--light-text-secondary);
}

.details-content p {
    margin-bottom: 0.5rem;
}

.details-content p:last-child {
    margin-bottom: 0;
}

.visual-cues {
    background: var(--bg-dark);
    border-radius: 0.5rem;
    padding: 1rem;
    border: 1px solid var(--border);
    transition: background 0.3s ease, border 0.3s ease;
}

body.light-mode .visual-cues {
    background: var(--light-bg-tertiary);
    border-color: var(--light-border);
}

.cues-title {
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    transition: color 0.3s ease;
}

body.light-mode .cues-title {
    color: var(--light-accent);
}

.cues-content {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.cue-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

body.light-mode .cue-item {
    color: var(--light-text-secondary);
}

.cue-color {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid var(--border);
    flex-shrink: 0;
}

body.light-mode .cue-color {
    border-color: var(--light-border);
}

.cue-color.red {
    background: var(--primary);
}

body.light-mode .cue-color.red {
    background: var(--light-primary);
}

.cue-color.black {
    background: var(--secondary);
}

.cue-color.highlight {
    background: var(--accent);
}

body.light-mode .cue-color.highlight {
    background: var(--light-accent);
}

/* Enhanced step display */
.step-explanation {
    background: rgba(59, 130, 246, 0.1);
    border-left: 3px solid var(--accent);
    padding: 0.75rem;
    margin-top: 0.75rem;
    border-radius: 0.25rem;
    font-size: 0.85rem;
    color: var(--text-primary);
    line-height: 1.5;
}

body.light-mode .step-explanation {
    background: rgba(59, 130, 246, 0.05);
    color: var(--light-text-primary);
}

.step-visual {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: var(--bg-light);
    border-radius: 0.25rem;
    font-size: 0.8rem;
}

body.light-mode .step-visual {
    background: var(--light-bg-secondary);
}

.step-visual-icon {
    font-size: 1.2rem;
}

.step-visual-text {
    color: var(--text-secondary);
}

body.light-mode .step-visual-text {
    color: var(--light-text-secondary);
}

.current-step {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    line-height: 1.4;
    transition: color 0.3s ease;
}

body.light-mode .current-step {
    color: var(--light-text-primary);
}

.step-type {
    display: inline-block;
    padding: 0.3rem 0.8rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    margin-left: auto;
}

.step-type.info {
    background: var(--accent);
    color: white;
}

body.light-mode .step-type.info {
    background: var(--light-accent);
}

.step-type.success {
    background: var(--success);
    color: white;
}

body.light-mode .step-type.success {
    background: var(--light-success);
}

.step-type.warning {
    background: var(--warning);
    color: white;
}

body.light-mode .step-type.warning {
    background: var(--light-warning);
}

.step-type.error {
    background: var(--primary);
    color: white;
}

body.light-mode .step-type.error {
    background: var(--light-primary);
}

.step-description {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
    margin-top: 0.5rem;
    transition: color 0.3s ease;
}

body.light-mode .step-description {
    color: var(--light-text-secondary);
}

.step-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    transition: border-color 0.3s ease;
}

body.light-mode .step-controls {
    border-color: var(--light-border);
}

.step-controls button {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

.step-progress {
    margin-left: auto;
    color: var(--text-secondary);
    font-size: 0.85rem;
    transition: color 0.3s ease;
}

body.light-mode .step-progress {
    color: var(--light-text-secondary);
}

.comparison-section {
    background: var(--bg-light);
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    animation: fadeInUp 1s ease;
    transition: background 0.3s ease, border 0.3s ease;
}

body.light-mode .comparison-section {
    background: var(--light-bg-secondary);
    border-color: var(--light-border);
    box-shadow: var(--light-shadow);
}

.comparison-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.comparison-card {
    background: var(--bg-dark);
    padding: 1.25rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    transition: all 0.3s ease;
}

body.light-mode .comparison-card {
    background: var(--light-bg-tertiary);
    border-color: var(--light-border);
}

.comparison-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
}

body.light-mode .comparison-card:hover {
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
}

.tree-type {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
}

.rb-tree { color: var(--primary); }
.avl-tree { color: var(--accent); }

body.light-mode .rb-tree { color: var(--light-primary); }
body.light-mode .avl-tree { color: var(--light-accent); }

.legend {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-dark);
    border-radius: 0.5rem;
    transition: background 0.3s ease;
    flex-wrap: wrap;
}

body.light-mode .legend {
    background: var(--light-bg-tertiary);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    transition: color 0.3s ease;
}

body.light-mode .legend-item {
    color: var(--light-text-primary);
}

.legend-color {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid var(--border);
    transition: border-color 0.3s ease;
}

body.light-mode .legend-color {
    border-color: var(--light-border);
}

.legend-color.red {
    background: var(--primary);
}

body.light-mode .legend-color.red {
    background: var(--light-primary);
}

.legend-color.black {
    background: var(--secondary);
}

.legend-color.nil {
    background: #64748b;
}

.legend-color.balance {
    background: var(--success);
}

body.light-mode .legend-color.balance {
    background: var(--light-success);
}

.history-section {
    background: var(--bg-light);
    border-radius: 1rem;
    padding: 1.25rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-top: 1.5rem;
    animation: fadeInUp 1s ease;
    transition: background 0.3s ease, border 0.3s ease;
}

body.light-mode .history-section {
    background: var(--light-bg-secondary);
    border-color: var(--light-border);
    box-shadow: var(--light-shadow);
}

.history-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: color 0.3s ease;
}

body.light-mode .history-title {
    color: var(--light-accent);
}

.history-list {
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg-dark);
    border-radius: 0.5rem;
    padding: 0.75rem;
    transition: background 0.3s ease;
}

body.light-mode .history-list {
    background: var(--light-bg-tertiary);
}

.history-item {
    padding: 0.6rem;
    margin-bottom: 0.4rem;
    background: var(--bg-light);
    border-radius: 0.5rem;
    border-left: 3px solid var(--accent);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
    font-size: 0.85rem;
}

body.light-mode .history-item {
    background: var(--light-bg-secondary);
    border-left-color: var(--light-accent);
}

.history-item:hover {
    transform: translateX(3px);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}

body.light-mode .history-item:hover {
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
}

.history-item.insert {
    border-left-color: var(--success);
}

body.light-mode .history-item.insert {
    border-left-color: var(--light-success);
}

.history-item.delete {
    border-left-color: var(--primary);
}

body.light-mode .history-item.delete {
    border-left-color: var(--light-primary);
}

.history-item.clear {
    border-left-color: var(--warning);
}

body.light-mode .history-item.clear {
    border-left-color: var(--light-warning);
}

.history-item.convert {
    border-left-color: var(--accent);
}

body.light-mode .history-item.convert {
    border-left-color: var(--light-accent);
}

.history-operation {
    font-weight: 600;
    transition: color 0.3s ease;
}

body.light-mode .history-operation {
    color: var(--light-text-primary);
}

.history-value {
    color: var(--text-secondary);
    font-size: 0.8rem;
    transition: color 0.3s ease;
}

body.light-mode .history-value {
    color: var(--light-text-secondary);
}

.history-time {
    color: var(--text-secondary);
    font-size: 0.75rem;
    transition: color 0.3s ease;
}

body.light-mode .history-time {
    color: var(--light-text-secondary);
}

.toggle-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.8rem;
    background: var(--bg-dark);
    border-radius: 0.5rem;
    margin-top: 0.75rem;
    transition: background 0.3s ease;
}

body.light-mode .toggle-container {
    background: var(--light-bg-tertiary);
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 22px;
    background: var(--border);
    border-radius: 11px;
    cursor: pointer;
    transition: background 0.3s ease;
}

body.light-mode .toggle-switch {
    background: var(--light-border);
}

.toggle-switch.active {
    background: var(--accent);
}

body.light-mode .toggle-switch.active {
    background: var(--light-accent);
}

.toggle-slider {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s ease;
}

.toggle-switch.active .toggle-slider {
    transform: translateX(22px);
}

.nil-node {
    fill: #64748b;
    stroke: #475569;
    stroke-width: 2;
    stroke-dasharray: 3, 3;
    opacity: 0.7;
}

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

.bottom-sections {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.small-panel {
    background: var(--bg-light);
    border-radius: 1rem;
    padding: 1.25rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    animation: fadeInUp 1s ease;
    transition: background 0.3s ease, border 0.3s ease;
}

body.light-mode .small-panel {
    background: var(--light-bg-secondary);
    border-color: var(--light-border);
    box-shadow: var(--light-shadow);
}

.properties-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.property-card {
    background: var(--bg-dark);
    border-radius: 0.5rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    transition: all 0.3s ease;
    text-align: center;
}

body.light-mode .property-card {
    background: var(--light-bg-tertiary);
    border-color: var(--light-border);
}

.property-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
    border-color: var(--accent);
}

body.light-mode .property-card:hover {
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
    border-color: var(--light-accent);
}

.property-number {
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.4rem;
    line-height: 1;
}

body.light-mode .property-number {
    background: linear-gradient(135deg, var(--light-primary) 0%, var(--light-accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.property-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.2rem;
    font-size: 0.8rem;
    transition: color 0.3s ease;
}

body.light-mode .property-title {
    color: var(--light-text-primary);
}

.property-description {
    color: var(--text-secondary);
    font-size: 0.7rem;
    line-height: 1.3;
    transition: color 0.3s ease;
}

body.light-mode .property-description {
    color: var(--light-text-secondary);
}

.rules-list {
    margin-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.rule-item {
    background: var(--bg-dark);
    border-radius: 0.5rem;
    padding: 0.5rem;
    border: 1px solid var(--border);
    transition: all 0.3s ease;
}

body.light-mode .rule-item {
    background: var(--light-bg-tertiary);
    border-color: var(--light-border);
}

.rule-item:hover {
    transform: translateX(5px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    border-color: var(--primary);
}

body.light-mode .rule-item:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border-color: var(--light-primary);
}

.rule-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.2rem;
}

.rule-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border-radius: 50%;
    font-weight: bold;
    font-size: 0.7rem;
    flex-shrink: 0;
}

body.light-mode .rule-number {
    background: linear-gradient(135deg, var(--light-primary) 0%, var(--light-primary-dark) 100%);
}

.rule-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.75rem;
    transition: color 0.3s ease;
}

body.light-mode .rule-title {
    color: var(--light-text-primary);
}

.rule-description {
    color: var(--text-secondary);
    font-size: 0.65rem;
    line-height: 1.2;
    margin-left: 25px;
    transition: color 0.3s ease;
}

body.light-mode .rule-description {
    color: var(--light-text-secondary);
}

.complexity-table {
    width: 100%;
    margin-top: 0.75rem;
    border-collapse: collapse;
}

.complexity-table th,
.complexity-table td {
    padding: 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
    transition: border-color 0.3s ease;
}

body.light-mode .complexity-table th,
body.light-mode .complexity-table td {
    border-color: var(--light-border);
}

.complexity-table th {
    background: var(--bg-dark);
    color: var(--accent);
    font-weight: 600;
    transition: background 0.3s ease, color 0.3s ease;
}

body.light-mode .complexity-table th {
    background: var(--light-bg-tertiary);
    color: var(--light-accent);
}

.complexity-table td {
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

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

.complexity-table tr:hover {
    background: rgba(59, 130, 246, 0.1);
}

body.light-mode .complexity-table tr:hover {
    background: rgba(59, 130, 246, 0.05);
}

.complexity-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    background: var(--accent);
    color: white;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    transition: background 0.3s ease;
}

body.light-mode .complexity-badge {
    background: var(--light-accent);
}

.key-points {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-top: 1rem;
}

.key-point {
    background: var(--bg-dark);
    border-radius: 0.5rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    text-align: center;
    transition: all 0.3s ease;
}

body.light-mode .key-point {
    background: var(--light-bg-tertiary);
    border-color: var(--light-border);
}

.key-point:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
    border-color: var(--success);
}

body.light-mode .key-point:hover {
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
    border-color: var(--light-success);
}

.key-point-icon {
    font-size: 1.5rem;
    margin-bottom: 0.3rem;
}

.key-point-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.3;
    transition: color 0.3s ease;
}

body.light-mode .key-point-text {
    color: var(--light-text-secondary);
}

.tutorial-section {
    background: var(--bg-dark);
    border-radius: 0.5rem;
    padding: 1rem;
    margin-top: 0.75rem;
    border: 1px solid var(--border);
    transition: background 0.3s ease, border 0.3s ease;
}

body.light-mode .tutorial-section {
    background: var(--light-bg-tertiary);
    border-color: var(--light-border);
}

.tutorial-step {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.tutorial-step:last-child {
    margin-bottom: 0;
}

.step-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--accent);
    color: white;
    border-radius: 50%;
    font-weight: bold;
    font-size: 0.75rem;
    flex-shrink: 0;
    margin-top: 0.1rem;
    transition: background 0.3s ease;
}

body.light-mode .step-number {
    background: var(--light-accent);
}

.step-content {
    flex-grow: 1;
}

.step-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
    transition: color 0.3s ease;
}

body.light-mode .step-title {
    color: var(--light-text-primary);
}

.step-description {
    color: var(--text-secondary);
    font-size: 0.75rem;
    line-height: 1.4;
    transition: color 0.3s ease;
}

body.light-mode .step-description {
    color: var(--light-text-secondary);
}

.tips-section {
    background: var(--bg-dark);
    border-radius: 0.5rem;
    padding: 1rem;
    border: 1px solid var(--border);
    transition: background 0.3s ease, border 0.3s ease;
}

body.light-mode .tips-section {
    background: var(--light-bg-tertiary);
    border-color: var(--light-border);
}

.tips-title {
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: color 0.3s ease;
}

body.light-mode .tips-title {
    color: var(--light-accent);
}

.tips-list {
    list-style-type: none;
}

.tips-item {
    padding: 0.4rem 0;
    color: var(--text-secondary);
    font-size: 0.8rem;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    transition: color 0.3s ease;
}

body.light-mode .tips-item {
    color: var(--light-text-secondary);
}

.tips-item:before {
    content: "•";
    color: var(--accent);
    font-weight: bold;
    transition: color 0.3s ease;
}

body.light-mode .tips-item:before {
    color: var(--light-accent);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInRight {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Toast styles */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 0.8rem 1.2rem;
    background: var(--bg-light);
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transform: translateX(400px);
    transition: transform 0.3s ease;
    z-index: 1000;
    font-size: 0.9rem;
}

body.light-mode .toast {
    background: var(--light-bg-secondary);
    border-color: var(--light-border);
    box-shadow: var(--light-shadow);
}

.toast.show {
    transform: translateX(0);
}

.toast.success {
    border-left: 3px solid var(--success);
}

body.light-mode .toast.success {
    border-left-color: var(--light-success);
}

.toast.error {
    border-left: 3px solid var(--primary);
}

body.light-mode .toast.error {
    border-left-color: var(--light-primary);
}

.toast.info {
    border-left: 3px solid var(--accent);
}

body.light-mode .toast.info {
    border-left-color: var(--light-accent);
}

.panel-section {
    margin-bottom: 1rem;
}

.panel-section:last-child {
    margin-bottom: 0;
}

.compact-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.stat-card {
    background: var(--bg-dark);
    border-radius: 0.5rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    text-align: center;
    transition: background 0.3s ease, border 0.3s ease;
}

body.light-mode .stat-card {
    background: var(--light-bg-tertiary);
    border-color: var(--light-border);
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--accent);
    margin-bottom: 0.2rem;
    transition: color 0.3s ease;
}

body.light-mode .stat-value {
    color: var(--light-accent);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

body.light-mode .stat-label {
    color: var(--light-text-secondary);
}

.tree-type-selector {
    display: flex;
    gap: 0.5rem;
    padding: 0.8rem;
    background: var(--bg-dark);
    border-radius: 0.5rem;
    margin-top: 0.75rem;
    transition: background 0.3s ease;
}

body.light-mode .tree-type-selector {
    background: var(--light-bg-tertiary);
}

.tree-type-btn {
    flex: 1;
    padding: 0.5rem;
    background: var(--border);
    color: var(--text-secondary);
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    font-size: 0.85rem;
}

body.light-mode .tree-type-btn {
    background: var(--light-border);
    color: var(--light-text-secondary);
}

.tree-type-btn.active {
    background: var(--accent);
    color: white;
}

body.light-mode .tree-type-btn.active {
    background: var(--light-accent);
}

.tree-type-btn:hover:not(.active) {
    background: rgba(59, 130, 246, 0.2);
    color: var(--text-primary);
}

body.light-mode .tree-type-btn:hover:not(.active) {
    background: rgba(59, 130, 246, 0.1);
    color: var(--light-text-primary);
}

.balance-factor {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--success);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
    transition: background 0.3s ease;
}

body.light-mode .balance-factor {
    background: var(--light-success);
}

.zoom-controls {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 10;
}

.zoom-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-dark);
    border: 2px solid var(--border);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1.2rem;
}

body.light-mode .zoom-btn {
    background: var(--light-bg-tertiary);
    border-color: var(--light-border);
    color: var(--light-text-primary);
}

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

body.light-mode .zoom-btn:hover {
    background: var(--light-accent);
    border-color: var(--light-accent);
}

.traversal-panel {
    background: var(--bg-light);
    border-radius: 1rem;
    padding: 1.25rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    animation: fadeInUp 1s ease;
    margin-top: 1.5rem;
    transition: background 0.3s ease, border 0.3s ease;
}

body.light-mode .traversal-panel {
    background: var(--light-bg-secondary);
    border-color: var(--light-border);
    box-shadow: var(--light-shadow);
}

.traversal-table {
    width: 100%;
    margin-top: 1rem;
    border-collapse: collapse;
}

.traversal-table th,
.traversal-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    transition: border-color 0.3s ease;
}

body.light-mode .traversal-table th,
body.light-mode .traversal-table td {
    border-color: var(--light-border);
}

.traversal-table th {
    background: var(--bg-dark);
    color: var(--accent);
    font-weight: 600;
    font-size: 0.9rem;
    transition: background 0.3s ease, color 0.3s ease;
}

body.light-mode .traversal-table th {
    background: var(--light-bg-tertiary);
    color: var(--light-accent);
}

.traversal-table td {
    color: var(--text-primary);
    font-size: 0.85rem;
    transition: color 0.3s ease;
}

body.light-mode .traversal-table td {
    color: var(--light-text-primary);
}

.traversal-btn {
    padding: 0.4rem 0.8rem;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.8rem;
    margin-right: 0.5rem;
}

body.light-mode .traversal-btn {
    background: var(--light-bg-tertiary);
    border-color: var(--light-border);
    color: var(--light-text-primary);
}

.traversal-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

body.light-mode .traversal-btn:hover {
    background: var(--light-accent);
    border-color: var(--light-accent);
}

.traversal-result {
    color: var(--text-secondary);
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    background: var(--bg-dark);
    padding: 0.5rem;
    border-radius: 0.25rem;
    margin-top: 0.5rem;
    transition: color 0.3s ease, background 0.3s ease;
    word-break: break-all;
}

body.light-mode .traversal-result {
    color: var(--light-text-secondary);
    background: var(--light-bg-tertiary);
}

.speed-control {
    display: flex;
    align-items: center;
    margin-left: -0.6rem;
    padding: 0.8rem;
    background: var(--bg-dark);
    border-radius: 0.5rem;
    margin-top: 0.75rem;
    transition: background 0.3s ease;
}

body.light-mode .speed-control {
    background: var(--light-bg-tertiary);
}

.speed-control label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    min-width: 100px;
    transition: color 0.3s ease;
}

body.light-mode .speed-control label {
    color: var(--light-text-secondary);
}

.speed-control input[type="range"] {
    flex: 1;
}

.speed-value {
    min-width: 60px;
    text-align: center;
    color: var(--text-primary);
    font-size: 0.85rem;
    transition: color 0.3s ease;
}

body.light-mode .speed-value {
    color: var(--light-text-primary);
}

.complexity-case {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.complexity-case-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: color 0.3s ease;
}

body.light-mode .complexity-case-label {
    color: var(--light-text-secondary);
}

.complexity-badges {
    display: flex;
    gap: 0.5rem;
}

.complexity-badge.best {
    background: var(--success);
}

body.light-mode .complexity-badge.best {
    background: var(--light-success);
}

.complexity-badge.average {
    background: var(--warning);
}

body.light-mode .complexity-badge.average {
    background: var(--light-warning);
}

.complexity-badge.worst {
    background: var(--primary);
}

body.light-mode .complexity-badge.worst {
    background: var(--light-primary);
}

/* New styles for node tooltip */
.node-tooltip {
    position: absolute;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.75rem;
    box-shadow: var(--shadow);
    z-index: 100;
    min-width: 180px;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

body.light-mode .node-tooltip {
    background: var(--light-bg-tertiary);
    border-color: var(--light-border);
    box-shadow: var(--light-shadow);
}

.node-tooltip.visible {
    opacity: 1;
}

.tooltip-title {
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.25rem;
    transition: color 0.3s ease, border-color 0.3s ease;
}

body.light-mode .tooltip-title {
    color: var(--light-accent);
    border-color: var(--light-border);
}

.tooltip-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
    font-size: 0.8rem;
}

.tooltip-label {
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

body.light-mode .tooltip-label {
    color: var(--light-text-secondary);
}

.tooltip-value {
    color: var(--text-primary);
    font-weight: 500;
    transition: color 0.3s ease;
}

body.light-mode .tooltip-value {
    color: var(--light-text-primary);
}

.color-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-left: 0.25rem;
    vertical-align: middle;
}

.color-indicator.red {
    background: var(--primary);
}

body.light-mode .color-indicator.red {
    background: var(--light-primary);
}

.color-indicator.black {
    background: var(--secondary);
}

.color-indicator.nil {
    background: #64748b;
}

/* New styles for tree placeholder */
.tree-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    text-align: center;
    z-index: 1;
}

.tree-placeholder.hidden {
    display: none;
}

.placeholder-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 1rem;
    transition: color 0.3s ease;
}

body.light-mode .placeholder-title {
    color: var(--light-accent);
}

.placeholder-content {
    max-width: 600px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 1.5rem;
    transition: color 0.3s ease;
}

body.light-mode .placeholder-content {
    color: var(--light-text-secondary);
}

.placeholder-section {
    margin-bottom: 1.5rem;
}

.placeholder-section-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    transition: color 0.3s ease;
}

body.light-mode .placeholder-section-title {
    color: var(--light-text-primary);
}

.placeholder-highlight {
    color: var(--accent);
    font-weight: 600;
    transition: color 0.3s ease;
}

body.light-mode .placeholder-highlight {
    color: var(--light-accent);
}

/* Complexity container responsive layout */
.complexity-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

@media (max-width: 992px) {
    .complexity-container {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .complexity-container > div {
        margin-bottom: 1rem;
    }
    
    .complexity-container > div:last-child {
        margin-bottom: 0;
    }
}

@media (max-width: 768px) {
    .complexity-container {
        gap: 0.75rem;
    }
    
    .complexity-container .info-title {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }
}

@media (max-width: 480px) {
    .complexity-container {
        gap: 0.5rem;
    }
    
    .complexity-container .info-title {
        font-size: 0.85rem;
        margin-bottom: 0.4rem;
    }
}

/* Enhanced table responsiveness */
@media (max-width: 768px) {
    .complexity-table {
        font-size: 0.75rem;
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        border-radius: 0.5rem;
        background: var(--bg-dark);
    }
    
    body.light-mode .complexity-table {
        background: var(--light-bg-tertiary);
    }
    
    .complexity-table thead {
        position: sticky;
        top: 0;
        z-index: 10;
    }
    
    .complexity-table th,
    .complexity-table td {
        padding: 0.4rem 0.3rem;
        min-width: 80px;
    }
    
    .complexity-badge {
        display: inline-block;
        white-space: nowrap;
        font-size: 0.65rem;
        padding: 0.15rem 0.4rem;
    }
}

@media (max-width: 480px) {
    .complexity-table {
        font-size: 0.7rem;
    }
    
    .complexity-table th,
    .complexity-table td {
        padding: 0.3rem 0.2rem;
        min-width: 70px;
    }
    
    .complexity-badge {
        font-size: 0.6rem;
        padding: 0.1rem 0.3rem;
    }
}

/* Mobile Menu Styles */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 1000;
}

body.light-mode .mobile-menu-btn {
    color: var(--light-text-primary);
}

.mobile-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    display: none;
}

.mobile-menu-overlay.active {
    display: block;
}

.mobile-menu {
    position: fixed;
    top: 0;
    left: -300px;
    width: 280px;
    height: 100%;
    background: var(--bg-light);
    z-index: 1000;
    transition: left 0.3s ease;
    overflow-y: auto;
    padding: 2rem 1rem;
}

body.light-mode .mobile-menu {
    background: var(--light-bg-secondary);
}

.mobile-menu.active {
    left: 0;
}

.mobile-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.mobile-menu-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent);
}

body.light-mode .mobile-menu-title {
    color: var(--light-accent);
}

.mobile-menu-close {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
}

body.light-mode .mobile-menu-close {
    color: var(--light-text-primary);
}

.mobile-menu-section {
    margin-bottom: 1.5rem;
}

.mobile-menu-section-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

body.light-mode .mobile-menu-section-title {
    color: var(--light-text-secondary);
}

.mobile-menu-item {
    display: block;
    padding: 0.75rem;
    background: var(--bg-dark);
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    text-decoration: none;
    transition: all 0.3s ease;
}

body.light-mode .mobile-menu-item {
    background: var(--light-bg-tertiary);
    color: var(--light-text-primary);
}

.mobile-menu-item:hover {
    background: var(--accent);
    color: white;
}

.mobile-menu-item.active {
    background: var(--accent);
    color: white;
}

.mobile-menu-button {
    width: 100%;
    padding: 0.75rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 0.5rem;
}

body.light-mode .mobile-menu-button {
    background: var(--light-primary);
}

.mobile-menu-button:hover {
    background: var(--primary-dark);
}

body.light-mode .mobile-menu-button:hover {
    background: var(--light-primary-dark);
}

.mobile-menu-button.secondary {
    background: var(--accent);
}

body.light-mode .mobile-menu-button.secondary {
    background: var(--light-accent);
}

.mobile-menu-button.danger {
    background: var(--danger);
}

.mobile-menu-button.success {
    background: var(--success);
}

body.light-mode .mobile-menu-button.success {
    background: var(--light-success);
}

.mobile-controls-button {
    display: none;
    width: 100%;
    padding: 0.75rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 1rem;
}

body.light-mode .mobile-controls-button {
    background: var(--light-accent);
}

.mobile-controls-button:hover {
    background: #2563eb;
}

.mobile-panel-header {
    display: none;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

body.light-mode .mobile-panel-header {
    border-color: var(--light-border);
}

.mobile-panel-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent);
}

body.light-mode .mobile-panel-title {
    color: var(--light-accent);
}

.mobile-panel-close {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
}

body.light-mode .mobile-panel-close {
    color: var(--light-text-primary);
}

/* Responsive Design */
@media (max-width: 1400px) {
    .main-layout {
        grid-template-columns: 280px 1fr 340px;
    }
}

@media (max-width: 1200px) {
    .main-layout {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .algorithm-panel {
        order: 2;
    }
    
    .visualization-panel {
        order: 1;
    }
    
    .right-panel {
        order: 3;
    }
}

@media (max-width: 992px) {
    .container {
        padding: 1rem;
    }
    
    header {
        padding: 1rem 0;
    }
    
    .theme-toggle {
        position: static;
        margin-top: 1rem;
        justify-content: center;
    }
    
    .main-layout {
        gap: 1rem;
    }
    
    .tree-container {
        height: 300px;
    }
    
    .legend {
        gap: 0.75rem;
        padding: 0.5rem;
    }
    
    .legend-item {
        font-size: 0.8rem;
    }
    
    .legend-color {
        width: 15px;
        height: 15px;
    }
    
    .panel {
        padding: 1rem;
    }
    
    .panel-header {
        font-size: 1rem;
    }
    
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }
    
    .stat-card {
        padding: 0.5rem;
    }
    
    .stat-value {
        font-size: 1.2rem;
    }
    
    .stat-label {
        font-size: 0.7rem;
    }
    
    .properties-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
    
    .property-card {
        padding: 0.5rem;
    }
    
    .property-number {
        font-size: 1.2rem;
    }
    
    .property-title {
        font-size: 0.75rem;
    }
    
    .property-description {
        font-size: 0.65rem;
    }
    
    .key-points {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
    
    .key-point {
        padding: 0.5rem;
    }
    
    .key-point-icon {
        font-size: 1.2rem;
    }
    
    .key-point-text {
        font-size: 0.7rem;
    }
    
    .rules-list {
        gap: 0.3rem;
    }
    
    .rule-item {
        padding: 0.4rem;
    }
    
    .rule-number {
        width: 18px;
        height: 18px;
        font-size: 0.65rem;
    }
    
    .rule-title {
        font-size: 0.7rem;
    }
    
    .rule-description {
        font-size: 0.6rem;
        margin-left: 20px;
    }
    
    .tutorial-step {
        gap: 0.5rem;
    }
    
    .step-number {
        width: 20px;
        height: 20px;
        font-size: 0.7rem;
    }
    
    .step-title {
        font-size: 0.8rem;
    }
    
    .step-description {
        font-size: 0.7rem;
    }
    
    .algorithm-display {
        padding: 1rem;
        min-height: 200px;
    }
    
    .current-step {
        font-size: 1rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .step-type {
        margin-left: 0;
        align-self: flex-end;
    }
    
    .step-description {
        font-size: 0.85rem;
    }
    
    .algorithm-code {
        font-size: 0.75rem;
        padding: 0.75rem;
    }
    
    .tips-section {
        padding: 0.75rem;
    }
    
    .tips-title {
        font-size: 0.85rem;
    }
    
    .tips-item {
        font-size: 0.75rem;
    }
    
    .traversal-panel {
        padding: 1rem;
    }
    
    .traversal-table {
        font-size: 0.8rem;
    }
    
    .traversal-table th,
    .traversal-table td {
        padding: 0.5rem;
    }
    
    .traversal-btn {
        padding: 0.3rem 0.6rem;
        font-size: 0.75rem;
    }
    
    .traversal-result {
        font-size: 0.7rem;
        padding: 0.4rem;
    }
    
    .history-section {
        padding: 1rem;
    }
    
    .history-title {
        font-size: 1.1rem;
    }
    
    .history-list {
        padding: 0.5rem;
    }
    
    .history-item {
        padding: 0.5rem;
        font-size: 0.8rem;
    }
    
    .history-operation {
        font-size: 0.85rem;
    }
    
    .history-value {
        font-size: 0.75rem;
    }
    
    .history-time {
        font-size: 0.7rem;
    }
    
    .toggle-container {
        padding: 0.6rem;
    }
    
    .speed-control {
        padding: 0.6rem;
    }
    
    .speed-control label {
        font-size: 0.8rem;
        min-width: 80px;
    }
    
    .speed-value {
        font-size: 0.8rem;
        min-width: 50px;
    }
    
    .zoom-controls {
        top: 0.5rem;
        right: 0.5rem;
    }
    
    .zoom-btn {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }
    
    .node-tooltip {
        min-width: 160px;
        padding: 0.5rem;
        font-size: 0.75rem;
    }
    
    .tooltip-title {
        font-size: 0.85rem;
    }
    
    .tooltip-row {
        font-size: 0.75rem;
    }
    
    .complexity-table {
        font-size: 0.8rem;
    }
    
    .complexity-table th,
    .complexity-table td {
        padding: 0.4rem;
    }
    
    .complexity-badge {
        padding: 0.15rem 0.5rem;
        font-size: 0.7rem;
    }
    
    .comparison-section {
        padding: 1rem;
    }
    
    .comparison-section h2 {
        font-size: 1.3rem;
    }
    
    .comparison-card {
        padding: 1rem;
    }
    
    .tree-type {
        font-size: 1.1rem;
    }
    
    .metric {
        padding: 0.3rem 0;
    }
    
    .metric-label {
        font-size: 0.8rem;
    }
    
    .metric-value {
        font-size: 0.8rem;
    }
    
    .placeholder-title {
        font-size: 1.3rem;
    }
    
    .placeholder-content {
        font-size: 0.9rem;
    }
    
    .placeholder-section-title {
        font-size: 1rem;
    }
    
    .toast {
        bottom: 1rem;
        right: 1rem;
        left: 1rem;
        transform: translateY(100px);
    }
    
    .toast.show {
        transform: translateY(0);
    }
}

@media (max-width: 768px) {
    .mobile-menu-btn {
        display: block;
    }
    
    .mobile-controls-button {
        display: block;
    }
    
    .mobile-panel-header {
        display: flex;
    }
    
    .algorithm-panel {
        display: none;
    }
    
    .algorithm-panel.mobile-visible {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: var(--bg-light);
        z-index: 998;
        overflow-y: auto;
        padding: 1rem;
    }
    
    body.light-mode .algorithm-panel.mobile-visible {
        background: var(--light-bg-secondary);
    }
    
    .container {
        padding: 0.75rem;
    }
    
    h1 {
        font-size: 1.8rem;
    }
    
    .subtitle {
        font-size: 1rem;
    }
    
    .tree-container {
        height: 250px;
        touch-action: pan-x pan-y pinch-zoom;
    }
    
    .legend {
        gap: 0.5rem;
        padding: 0.3rem;
    }
    
    .legend-item {
        font-size: 0.75rem;
    }
    
    .legend-color {
        width: 12px;
        height: 12px;
    }
    
    .panel {
        padding: 0.75rem;
    }
    
    .panel-header {
        font-size: 0.9rem;
    }
    
    .input-group {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .controls {
        gap: 0.4rem;
    }
    
    button {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }
    
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.3rem;
    }
    
    .stat-card {
        padding: 0.4rem;
    }
    
    .stat-value {
        font-size: 1rem;
    }
    
    .stat-label {
        font-size: 0.65rem;
    }
    
    .properties-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.4rem;
    }
    
    .property-card {
        padding: 0.4rem;
    }
    
    .property-number {
        font-size: 1rem;
    }
    
    .property-title {
        font-size: 0.7rem;
    }
    
    .property-description {
        font-size: 0.6rem;
    }
    
    .key-points {
        grid-template-columns: 1fr;
        gap: 0.4rem;
    }
    
    .key-point {
        padding: 0.4rem;
    }
    
    .key-point-icon {
        font-size: 1rem;
    }
    
    .key-point-text {
        font-size: 0.65rem;
    }
    
    .rules-list {
        gap: 0.2rem;
    }
    
    .rule-item {
        padding: 0.3rem;
    }
    
    .rule-number {
        width: 16px;
        height: 16px;
        font-size: 0.6rem;
    }
    
    .rule-title {
        font-size: 0.65rem;
    }
    
    .rule-description {
        font-size: 0.55rem;
        margin-left: 18px;
    }
    
    .tutorial-step {
        gap: 0.4rem;
    }
    
    .step-number {
        width: 18px;
        height: 18px;
        font-size: 0.65rem;
    }
    
    .step-title {
        font-size: 0.75rem;
    }
    
    .step-description {
        font-size: 0.65rem;
    }
    
    .algorithm-display {
        padding: 0.75rem;
        min-height: 180px;
    }
    
    .current-step {
        font-size: 0.9rem;
    }
    
    .step-description {
        font-size: 0.8rem;
    }
    
    .algorithm-code {
        font-size: 0.7rem;
        padding: 0.5rem;
    }
    
    .tips-section {
        padding: 0.5rem;
    }
    
    .tips-title {
        font-size: 0.8rem;
    }
    
    .tips-item {
        font-size: 0.7rem;
    }
    
    .traversal-panel {
        padding: 0.75rem;
    }
    
    .traversal-table {
        font-size: 0.75rem;
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    
    .traversal-table th,
    .traversal-table td {
        padding: 0.4rem;
    }
    
    .traversal-btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.7rem;
    }
    
    .traversal-result {
        font-size: 0.65rem;
        padding: 0.3rem;
    }
    
    .history-section {
        padding: 0.75rem;
    }
    
    .history-title {
        font-size: 1rem;
    }
    
    .history-list {
        padding: 0.4rem;
    }
    
    .history-item {
        padding: 0.4rem;
        font-size: 0.75rem;
    }
    
    .history-operation {
        font-size: 0.8rem;
    }
    
    .history-value {
        font-size: 0.7rem;
    }
    
    .history-time {
        font-size: 0.65rem;
    }
    
    .toggle-container {
        padding: 0.5rem;
    }
    
    .speed-control {
        padding: 0.5rem;
    }
    
    .speed-control label {
        font-size: 0.75rem;
        min-width: 70px;
    }
    
    .speed-value {
        font-size: 0.75rem;
        min-width: 45px;
    }
    
    .zoom-controls {
        flex-direction: row;
        top: auto;
        bottom: 1rem;
        right: 50%;
        transform: translateX(50%);
        gap: 0.25rem;
    }
    
    .zoom-btn {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }
    
    .node-tooltip {
        min-width: 150px;
        padding: 0.4rem;
        font-size: 0.7rem;
    }
    
    .tooltip-title {
        font-size: 0.8rem;
    }
    
    .tooltip-row {
        font-size: 0.7rem;
    }
    
    .complexity-table {
        font-size: 0.75rem;
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    
    .complexity-table th,
    .complexity-table td {
        padding: 0.3rem;
    }
    
    .complexity-badge {
        padding: 0.1rem 0.4rem;
        font-size: 0.65rem;
    }
    
    .comparison-section {
        padding: 0.75rem;
    }
    
    .comparison-section h2 {
        font-size: 1.2rem;
    }
    
    .comparison-card {
        padding: 0.75rem;
    }
    
    .tree-type {
        font-size: 1rem;
    }
    
    .metric {
        padding: 0.2rem 0;
    }
    
    .metric-label {
        font-size: 0.75rem;
    }
    
    .metric-value {
        font-size: 0.75rem;
    }
    
    .placeholder-title {
        font-size: 1.2rem;
    }
    
    .placeholder-content {
        font-size: 0.85rem;
    }
    
    .placeholder-section-title {
        font-size: 0.9rem;
    }
    
    .toast {
        font-size: 0.85rem;
        padding: 0.6rem 1rem;
    }
    
    .right-panel {
        display: none;
    }
    
    .right-panel.mobile-visible {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        right: 0;
        width: 100%;
        height: 100%;
        background: var(--bg-light);
        z-index: 998;
        overflow-y: auto;
        padding: 1rem;
    }
    
    body.light-mode .right-panel.mobile-visible {
        background: var(--light-bg-secondary);
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0.5rem;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    .subtitle {
        font-size: 0.9rem;
    }
    
    .tree-container {
        height: 200px;
    }
    
    .legend {
        gap: 0.3rem;
        padding: 0.2rem;
    }
    
    .legend-item {
        font-size: 0.7rem;
    }
    
    .legend-color {
        width: 10px;
        height: 10px;
    }
    
    .panel {
        padding: 0.5rem;
    }
    
    .panel-header {
        font-size: 0.85rem;
    }
    
    .controls {
        gap: 0.3rem;
    }
    
    button {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }
    
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.2rem;
    }
    
    .stat-card {
        padding: 0.3rem;
    }
    
    .stat-value {
        font-size: 0.9rem;
    }
    
    .stat-label {
        font-size: 0.6rem;
    }
    
    .properties-grid {
        grid-template-columns: 1fr;
        gap: 0.3rem;
    }
    
    .property-card {
        padding: 0.3rem;
    }
    
    .property-number {
        font-size: 0.9rem;
    }
    
    .property-title {
        font-size: 0.65rem;
    }
    
    .property-description {
        font-size: 0.55rem;
    }
    
    .key-points {
        grid-template-columns: 1fr;
        gap: 0.3rem;
    }
    
    .key-point {
        padding: 0.3rem;
    }
    
    .key-point-icon {
        font-size: 0.9rem;
    }
    
    .key-point-text {
        font-size: 0.6rem;
    }
    
    .rules-list {
        gap: 0.15rem;
    }
    
    .rule-item {
        padding: 0.25rem;
    }
    
    .rule-number {
        width: 14px;
        height: 14px;
        font-size: 0.55rem;
    }
    
    .rule-title {
        font-size: 0.6rem;
    }
    
    .rule-description {
        font-size: 0.5rem;
        margin-left: 16px;
    }
    
    .tutorial-step {
        gap: 0.3rem;
    }
    
    .step-number {
        width: 16px;
        height: 16px;
        font-size: 0.6rem;
    }
    
    .step-title {
        font-size: 0.7rem;
    }
    
    .step-description {
        font-size: 0.6rem;
    }
    
    .algorithm-display {
        padding: 0.5rem;
        min-height: 150px;
    }
    
    .current-step {
        font-size: 0.8rem;
    }
    
    .step-description {
        font-size: 0.7rem;
    }
    
    .algorithm-code {
        font-size: 0.65rem;
        padding: 0.4rem;
    }
    
    .tips-section {
        padding: 0.4rem;
    }
    
    .tips-title {
        font-size: 0.75rem;
    }
    
    .tips-item {
        font-size: 0.65rem;
    }
    
    .traversal-panel {
        padding: 0.5rem;
    }
    
    .traversal-table {
        font-size: 0.7rem;
    }
    
    .traversal-table th,
    .traversal-table td {
        padding: 0.3rem;
    }
    
    .traversal-btn {
        padding: 0.2rem 0.4rem;
        font-size: 0.65rem;
    }
    
    .traversal-result {
        font-size: 0.6rem;
        padding: 0.25rem;
    }
    
    .history-section {
        padding: 0.5rem;
    }
    
    .history-title {
        font-size: 0.9rem;
    }
    
    .history-list {
        padding: 0.3rem;
    }
    
    .history-item {
        padding: 0.3rem;
        font-size: 0.7rem;
    }
    
    .history-operation {
        font-size: 0.75rem;
    }
    
    .history-value {
        font-size: 0.65rem;
    }
    
    .history-time {
        font-size: 0.6rem;
    }
    
    .toggle-container {
        padding: 0.4rem;
    }
    
    .speed-control {
        padding: 0.4rem;
    }
    
    .speed-control label {
        font-size: 0.7rem;
        min-width: 60px;
    }
    
    .speed-value {
        font-size: 0.7rem;
        min-width: 40px;
    }
    
    .zoom-controls {
        top: 0.2rem;
        right: 0.2rem;
    }
    
    .zoom-btn {
        width: 28px;
        height: 28px;
        font-size: 0.9rem;
    }
    
    .node-tooltip {
        min-width: 140px;
        padding: 0.3rem;
        font-size: 0.65rem;
    }
    
    .tooltip-title {
        font-size: 0.75rem;
    }
    
    .tooltip-row {
        font-size: 0.65rem;
    }
    
    .complexity-table {
        font-size: 0.7rem;
    }
    
    .complexity-table th,
    .complexity-table td {
        padding: 0.2rem;
    }
    
    .complexity-badge {
        padding: 0.1rem 0.3rem;
        font-size: 0.6rem;
    }
    
    .comparison-section {
        padding: 0.5rem;
    }
    
    .comparison-section h2 {
        font-size: 1.1rem;
    }
    
    .comparison-card {
        padding: 0.5rem;
    }
    
    .tree-type {
        font-size: 0.9rem;
    }
    
    .metric {
        padding: 0.15rem 0;
    }
    
    .metric-label {
        font-size: 0.7rem;
    }
    
    .metric-value {
        font-size: 0.7rem;
    }
    
    .placeholder-title {
        font-size: 1.1rem;
    }
    
    .placeholder-content {
        font-size: 0.8rem;
    }
    
    .placeholder-section-title {
        font-size: 0.85rem;
    }
    
    .toast {
        font-size: 0.8rem;
        padding: 0.5rem 0.8rem;
    }
}

/* Enhanced mobile interactions */
@media (hover: none) and (pointer: coarse) {
    .node:hover {
        filter: none;
    }
    
    .node:active {
        filter: brightness(1.2);
    }
    
    .property-card:hover {
        transform: none;
        box-shadow: none;
    }
    
    .property-card:active {
        transform: translateY(-2px);
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
    }
    
    .key-point:hover {
        transform: none;
        box-shadow: none;
    }
    
    .key-point:active {
        transform: translateY(-2px);
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
    }
    
    .rule-item:hover {
        transform: none;
        box-shadow: none;
    }
    
    .rule-item:active {
        transform: translateX(5px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    }
    
    .comparison-card:hover {
        transform: none;
        box-shadow: none;
    }
    
    .comparison-card:active {
        transform: translateY(-3px);
        box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
    }
    
    .history-item:hover {
        transform: none;
        box-shadow: none;
    }
    
    .history-item:active {
        transform: translateX(3px);
        box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
    }
    
    .traversal-btn:hover {
        background: var(--bg-dark);
        border-color: var(--border);
        color: var(--text-primary);
    }
    
    .traversal-btn:active {
        background: var(--accent);
        border-color: var(--accent);
        color: white;
    }
    
    .tree-type-btn:hover:not(.active) {
        background: var(--border);
        color: var(--text-secondary);
    }
    
    .tree-type-btn:active:not(.active) {
        background: rgba(59, 130, 246, 0.2);
        color: var(--text-primary);
    }
    
    .zoom-btn:hover {
        background: var(--bg-dark);
        border-color: var(--border);
        color: var(--text-primary);
    }
    
    .zoom-btn:active {
        background: var(--accent);
        border-color: var(--accent);
    }
}

/* Improved touch targets */
@media (max-width: 768px) {
    button, .toggle-switch, .tree-type-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    input[type="number"] {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .legend-item {
        padding: 0.25rem;
    }
    
    .history-item {
        padding: 0.5rem;
    }
    
    .rule-item {
        padding: 0.5rem;
    }
    
    .property-card {
        padding: 0.5rem;
    }
    
    .key-point {
        padding: 0.5rem;
    }
}

/* =================================================================== */
/* NEW STYLES ADDED FOR PSEUDOCODE SECTION */
/* =================================================================== */

.pseudocode-title {
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.75rem;
    margin-top: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    transition: color 0.3s ease;
}

body.light-mode .pseudocode-title {
    color: var(--light-accent);
}

.algorithm-code {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 0.5rem;
    padding: 1rem;
    margin-top: 0.5rem;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    color: #e2e8f0;
    overflow-x: auto;
    white-space: pre;
    flex-grow: 1;
    transition: background 0.3s ease;
}

body.light-mode .algorithm-code {
    background: rgba(0, 0, 0, 0.1);
    color: #334155;
}

/* ... (all your existing CSS remains the same) ... */

/* =================================================================== */
/* MODIFIED STYLES FOR ALGORITHM SECTION */
/* =================================================================== */

.main-layout {
    display: grid;
    /* Increased the max-width of the left panel to give it more space */
    grid-template-columns: 400px 1fr 350px; 
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.algorithm-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    /* Make this panel grow to take up available space */
    flex-grow: 1; 
}

.algorithm-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    /* Make this section grow to fill the panel */
    flex-grow: 1; 
    /* Ensure it has a good minimum height */
    min-height: 600px; 
}

/* ... (rest of your CSS) ... */

.algorithm-code {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 0.5rem;
    padding: 1rem;
    margin-top: 0.5rem;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    color: #e2e8f0;
    /* MODIFIED: Wrap text instead of scrolling */
    white-space: pre-wrap; 
    /* MODIFIED: Removed horizontal scrollbar */
    /* overflow-x: auto; */
    flex-grow: 1;
    transition: background 0.3s ease;
}

body.light-mode .algorithm-code {
    background: rgba(0, 0, 0, 0.1);
    color: #334155;
}

/* ... (rest of your CSS) ... */

/* Responsive Design Adjustments */
@media (max-width: 1400px) {
    /* Adjusted for the new layout */
    .main-layout {
        grid-template-columns: 350px 1fr 340px;
    }
}

@media (max-width: 1200px) {
    .main-layout {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .algorithm-panel {
        order: 2;
        /* Reset flex-grow for mobile layout */
        flex-grow: 0; 
    }
    
    .visualization-panel {
        order: 1;
    }
    
    .right-panel {
        order: 3;
    }
}

/* ... (rest of your responsive CSS) ... */

/* Celestial Elements - Scrolling Theme Switcher */
.celestial-elements {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 100;
    pointer-events: auto;
}

.celestial-container {
    position: relative;
    width: 70px;
    height: 70px;
    cursor: pointer;
    transition: transform 0.3s ease;
    backdrop-filter: blur(2px);
    background: rgba(255, 255, 255, 0.05);
    border-radius: 50%;
    padding: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

/* Moon Styles - Smaller Size */
.moon {
    position: absolute;
    width: 55px;
    height: 55px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f4f4f4 0%, #e0e0e0 50%, #d0d0d0 100%);
    box-shadow: 
        0 0 15px rgba(255, 255, 255, 0.5),
        0 0 30px rgba(255, 255, 255, 0.3),
        0 0 45px rgba(255, 255, 255, 0.1),
        inset -7px -7px 15px rgba(0, 0, 0, 0.1);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: all 0.5s ease;
    animation: moonGlow 3s ease-in-out infinite alternate;
    pointer-events: none;
}

body:not(.light-mode) .moon {
    opacity: 1;
    pointer-events: auto;
}

body.light-mode .moon {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8) rotate(180deg);
    pointer-events: none;
}

/* Sun Styles - Smaller Size */
.sun {
    position: absolute;
    width: 55px;
    height: 55px;
    border-radius: 50%;
    background: radial-gradient(circle, #ffeb3b 0%, #ffc107 60%, #ff9800 100%);
    box-shadow: 
        0 0 15px rgba(255, 193, 7, 0.5),
        0 0 30px rgba(255, 193, 7, 0.3),
        0 0 45px rgba(255, 193, 7, 0.1);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: all 0.5s ease;
    animation: sunRotate 20s linear infinite;
    pointer-events: none;
}

body.light-mode .sun {
    opacity: 1;
    pointer-events: auto;
}

body:not(.light-mode) .sun {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8) rotate(-180deg);
    pointer-events: none;
}

/* Smaller moon craters */
.moon-crater:nth-child(1) {
    width: 10px;
    height: 10px;
    top: 15px;
    left: 18px;
}

.moon-crater:nth-child(2) {
    width: 7px;
    height: 7px;
    top: 28px;
    left: 32px;
}

.moon-crater:nth-child(3) {
    width: 5px;
    height: 5px;
    top: 35px;
    left: 15px;
}

/* Smaller sun rays */
.sun-ray {
    position: absolute;
    background: linear-gradient(to bottom, rgba(255, 193, 7, 0.8), transparent);
    transform-origin: center bottom;
}

.sun-ray:nth-child(1) {
    width: 3px;
    height: 15px;
    top: -18px;
    left: 26px;
    transform: rotate(0deg);
}

.sun-ray:nth-child(2) {
    width: 3px;
    height: 15px;
    top: -18px;
    left: 26px;
    transform: rotate(45deg);
}

.sun-ray:nth-child(3) {
    width: 3px;
    height: 15px;
    top: -18px;
    left: 26px;
    transform: rotate(90deg);
}

.sun-ray:nth-child(4) {
    width: 3px;
    height: 15px;
    top: -18px;
    left: 26px;
    transform: rotate(135deg);
}

.sun-ray:nth-child(5) {
    width: 3px;
    height: 15px;
    bottom: -18px;
    left: 26px;
    transform: rotate(180deg);
}

.sun-ray:nth-child(6) {
    width: 3px;
    height: 15px;
    bottom: -18px;
    left: 26px;
    transform: rotate(225deg);
}

.sun-ray:nth-child(7) {
    width: 3px;
    height: 15px;
    bottom: -18px;
    left: 26px;
    transform: rotate(270deg);
}

.sun-ray:nth-child(8) {
    width: 3px;
    height: 15px;
    bottom: -18px;
    left: 26px;
    transform: rotate(315deg);
}

/* Responsive adjustments for smaller celestial elements */
@media (max-width: 768px) {
    .celestial-elements {
        top: 10px;
        right: 10px;
    }
    
    .celestial-container {
        width: 60px;
        height: 60px;
        padding: 6px;
    }
    
    .moon, .sun {
        width: 45px;
        height: 45px;
    }
    
    .moon-crater:nth-child(1) {
        width: 8px;
        height: 8px;
        top: 12px;
        left: 15px;
    }
    
    .moon-crater:nth-child(2) {
        width: 6px;
        height: 6px;
        top: 23px;
        left: 27px;
    }
    
    .moon-crater:nth-child(3) {
        width: 4px;
        height: 4px;
        top: 29px;
        left: 12px;
    }
    
    .sun-ray {
        width: 2px;
        height: 12px;
    }
    
    .sun-ray:nth-child(1), .sun-ray:nth-child(2), .sun-ray:nth-child(3), .sun-ray:nth-child(4) {
        top: -15px;
        left: 21.5px;
    }
    
    .sun-ray:nth-child(5), .sun-ray:nth-child(6), .sun-ray:nth-child(7), .sun-ray:nth-child(8) {
        bottom: -15px;
        left: 21.5px;
    }
}

@media (max-width: 480px) {
    .celestial-elements {
        top: 5px;
        right: 5px;
    }
    
    .celestial-container {
        width: 50px;
        height: 50px;
        padding: 5px;
    }
    
    .moon, .sun {
        width: 40px;
        height: 40px;
    }
    
    .moon-crater:nth-child(1) {
        width: 7px;
        height: 7px;
        top: 10px;
        left: 13px;
    }
    
    .moon-crater:nth-child(2) {
        width: 5px;
        height: 5px;
        top: 20px;
        left: 24px;
    }
    
    .moon-crater:nth-child(3) {
        width: 4px;
        height: 4px;
        top: 26px;
        left: 11px;
    }
    
    .sun-ray {
        width: 2px;
        height: 10px;
    }
    
    .sun-ray:nth-child(1), .sun-ray:nth-child(2), .sun-ray:nth-child(3), .sun-ray:nth-child(4) {
        top: -12px;
        left: 19px;
    }
    
    .sun-ray:nth-child(5), .sun-ray:nth-child(6), .sun-ray:nth-child(7), .sun-ray:nth-child(8) {
        bottom: -12px;
        left: 19px;
    }
}


/* Enhanced algorithm details section */
.algorithm-details {
    background: var(--bg-dark);
    border-radius: 0.5rem;
    padding: 1rem;
    border: 1px solid var(--border);
    transition: background 0.3s ease, border 0.3s ease;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    min-height: 200px;
}

body.light-mode .algorithm-details {
    background: var(--light-bg-tertiary);
    border-color: var(--light-border);
}

.details-title {
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    transition: color 0.3s ease;
}

body.light-mode .details-title {
    color: var(--light-accent);
}

.details-content {
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.6;
    transition: color 0.3s ease;
    margin-bottom: 1rem;
    flex-grow: 1;
}

body.light-mode .details-content {
    color: var(--light-text-secondary);
}

.pseudocode-title {
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    transition: color 0.3s ease;
}

body.light-mode .pseudocode-title {
    color: var(--light-accent);
}

.algorithm-code {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 0.5rem;
    padding: 1rem;
    margin-top: 0.5rem;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    color: #e2e8f0;
    white-space: pre-wrap;
    flex-grow: 1;
    transition: background 0.3s ease;
    min-height: 100px;
    max-height: 300px;
    overflow-y: auto;
}

body.light-mode .algorithm-code {
    background: rgba(0, 0, 0, 0.1);
    color: #334155;
}

/* Aurora-like background effect */
.aurora-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    overflow: hidden;
}

.aurora {
    position: absolute;
    width: 100%;
    height: 100%;
    background: linear-gradient(0deg, 
        transparent, 
        rgba(59, 130, 246, 0.03), 
        rgba(147, 51, 234, 0.02), 
        transparent);
    animation: aurora-flow 30s ease-in-out infinite;
}

.aurora:nth-child(2) {
    background: linear-gradient(45deg, 
        transparent, 
        rgba(16, 185, 129, 0.02), 
        rgba(59, 130, 246, 0.03), 
        transparent);
    animation-delay: 10s;
    animation-duration: 35s;
}

.aurora:nth-child(3) {
    background: linear-gradient(90deg, 
        transparent, 
        rgba(147, 51, 234, 0.02), 
        rgba(16, 185, 129, 0.03), 
        transparent);
    animation-delay: 20s;
    animation-duration: 40s;
}

@keyframes aurora-flow {
    0%, 100% {
        transform: translateY(100%) skewX(-10deg);
        opacity: 0;
    }
    20% {
        opacity: 0.3;
    }
    50% {
        transform: translateY(-50%) skewX(10deg);
        opacity: 0.5;
    }
    80% {
        opacity: 0.3;
    }
}

/* Light mode aurora */
body.light-mode .aurora {
    opacity: 0.5;
}

/* Subtle geometric shapes in background */
.geometric-elements {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    overflow: hidden;
}

.geo-shape {
    position: absolute;
    border: 1px solid rgba(255, 255, 255, 0.05);
    animation: rotate-slow 60s linear infinite;
}

.geo-shape.circle {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    top: 10%;
    left: 10%;
}

.geo-shape.triangle {
    width: 0;
    height: 0;
    border-left: 100px solid transparent;
    border-right: 100px solid transparent;
    border-bottom: 173px solid rgba(255, 255, 255, 0.03);
    top: 60%;
    right: 15%;
    animation-duration: 80s;
}

.geo-shape.square {
    width: 150px;
    height: 150px;
    top: 30%;
    right: 30%;
    animation-duration: 70s;
    animation-direction: reverse;
}

@keyframes rotate-slow {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Light mode geometric elements */
body.light-mode .geo-shape {
    border-color: rgba(0, 0, 0, 0.03);
}

body.light-mode .geo-shape.triangle {
    border-bottom-color: rgba(0, 0, 0, 0.02);
}

/* Smooth transitions for background changes */
body {
    transition: filter 2s ease, background-position 0.5s ease;
}

/* Subtle vignette effect */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, transparent 0%, rgba(0, 0, 0, 0.1) 100%);
    z-index: -1;
    pointer-events: none;
}

/* Performance optimizations */
@media (max-width: 768px) {
    .ambient-particle {
        width: 1px;
        height: 1px;
    }
    
    .geo-shape {
        opacity: 0.5;
    }
    
    .aurora {
        opacity: 0.3;
    }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    .ambient-particle,
    .geo-shape,
    .aurora {
        animation: none !important;
    }
    
    body {
        animation: none !important;
    }
}

/* Tiny floating dots */
.micro-dots {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    overflow: hidden;
}

.micro-dot {
    position: absolute;
    width: 2px;
    height: 2px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    animation: micro-float 15s infinite ease-in-out;
}

.micro-dot:nth-child(1) { top: 10%; left: 5%; animation-delay: 0s; }
.micro-dot:nth-child(2) { top: 20%; left: 15%; animation-delay: 1s; }
.micro-dot:nth-child(3) { top: 30%; left: 25%; animation-delay: 2s; }
.micro-dot:nth-child(4) { top: 40%; left: 35%; animation-delay: 3s; }
.micro-dot:nth-child(5) { top: 50%; left: 45%; animation-delay: 4s; }
.micro-dot:nth-child(6) { top: 60%; left: 55%; animation-delay: 5s; }
.micro-dot:nth-child(7) { top: 70%; left: 65%; animation-delay: 6s; }
.micro-dot:nth-child(8) { top: 80%; left: 75%; animation-delay: 7s; }
.micro-dot:nth-child(9) { top: 90%; left: 85%; animation-delay: 8s; }
.micro-dot:nth-child(10) { top: 15%; left: 95%; animation-delay: 9s; }

@keyframes micro-float {
    0%, 100% {
        transform: translateY(0px) translateX(0px);
        opacity: 0.1;
    }
    25% {
        transform: translateY(-10px) translateX(5px);
        opacity: 0.2;
    }
    50% {
        transform: translateY(-5px) translateX(-3px);
        opacity: 0.15;
    }
    75% {
        transform: translateY(-15px) translateX(8px);
        opacity: 0.1;
    }
}

/* Light mode dots */
body.light-mode .micro-dot {
    background: rgba(0, 0, 0, 0.1);
}

/* Tiny sparkles */
.sparkles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    overflow: hidden;
}

.sparkle {
    position: absolute;
    width: 1px;
    height: 1px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    animation: sparkle-twinkle 4s infinite ease-in-out;
}

.sparkle::before {
    content: '';
    position: absolute;
    top: -1px;
    left: -1px;
    width: 3px;
    height: 3px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.3) 0%, transparent 70%);
    border-radius: 50%;
}

.sparkle:nth-child(1) { top: 5%; left: 10%; animation-delay: 0s; }
.sparkle:nth-child(2) { top: 15%; left: 20%; animation-delay: 0.5s; }
.sparkle:nth-child(3) { top: 25%; left: 30%; animation-delay: 1s; }
.sparkle:nth-child(4) { top: 35%; left: 40%; animation-delay: 1.5s; }
.sparkle:nth-child(5) { top: 45%; left: 50%; animation-delay: 2s; }
.sparkle:nth-child(6) { top: 55%; left: 60%; animation-delay: 2.5s; }
.sparkle:nth-child(7) { top: 65%; left: 70%; animation-delay: 3s; }
.sparkle:nth-child(8) { top: 75%; left: 80%; animation-delay: 3.5s; }
.sparkle:nth-child(9) { top: 85%; left: 90%; animation-delay: 4s; }
.sparkle:nth-child(10) { top: 95%; left: 5%; animation-delay: 4.5s; }

@keyframes sparkle-twinkle {
    0%, 100% {
        opacity: 0;
        transform: scale(0.5);
    }
    50% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Light mode sparkles */
body.light-mode .sparkle {
    background: rgba(0, 0, 0, 0.6);
}

/* Mini bubbles */
.bubbles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    overflow: hidden;
}

.bubble {
    position: absolute;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    animation: bubble-rise 12s infinite ease-in-out;
}

.bubble:nth-child(1) { width: 3px; height: 3px; bottom: 10%; left: 10%; animation-delay: 0s; }
.bubble:nth-child(2) { width: 2px; height: 2px; bottom: 20%; left: 20%; animation-delay: 1s; }
.bubble:nth-child(3) { width: 4px; height: 4px; bottom: 30%; left: 30%; animation-delay: 2s; }
.bubble:nth-child(4) { width: 2px; height: 2px; bottom: 40%; left: 40%; animation-delay: 3s; }
.bubble:nth-child(5) { width: 3px; height: 3px; bottom: 50%; left: 50%; animation-delay: 4s; }
.bubble:nth-child(6) { width: 2px; height: 2px; bottom: 60%; left: 60%; animation-delay: 5s; }
.bubble:nth-child(7) { width: 3px; height: 3px; bottom: 70%; left: 70%; animation-delay: 6s; }
.bubble:nth-child(8) { width: 2px; height: 2px; bottom: 80%; left: 80%; animation-delay: 7s; }

@keyframes bubble-rise {
    0% {
        transform: translateY(0) translateX(0);
        opacity: 0;
    }
    10% {
        opacity: 0.3;
    }
    50% {
        transform: translateY(-50px) translateX(10px);
        opacity: 0.2;
    }
    90% {
        opacity: 0.3;
    }
    100% {
        transform: translateY(-100px) translateX(-5px);
        opacity: 0;
    }
}

/* Light mode bubbles */
body.light-mode .bubble {
    border-color: rgba(0, 0, 0, 0.08);
}

/* Tiny stars */
.stars {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    overflow: hidden;
}

.star {
    position: absolute;
    width: 0;
    height: 0;
    border-right: 1px solid transparent;
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
    transform: rotate(45deg);
    animation: star-pulse 3s infinite ease-in-out;
}

.star::before {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border-left: 1px solid transparent;
    border-top: 1px solid rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.star:nth-child(1) { top: 8%; left: 12%; animation-delay: 0s; }
.star:nth-child(2) { top: 18%; left: 28%; animation-delay: 0.5s; }
.star:nth-child(3) { top: 28%; left: 42%; animation-delay: 1s; }
.star:nth-child(4) { top: 38%; left: 58%; animation-delay: 1.5s; }
.star:nth-child(5) { top: 48%; left: 72%; animation-delay: 2s; }
.star:nth-child(6) { top: 58%; left: 88%; animation-delay: 2.5s; }
.star:nth-child(7) { top: 68%; left: 15%; animation-delay: 3s; }
.star:nth-child(8) { top: 78%; left: 35%; animation-delay: 3.5s; }
.star:nth-child(9) { top: 88%; left: 55%; animation-delay: 4s; }
.star:nth-child(10) { top: 12%; left: 75%; animation-delay: 4.5s; }

@keyframes star-pulse {
    0%, 100% {
        opacity: 0.1;
        transform: rotate(45deg) scale(0.8);
    }
    50% {
        opacity: 0.3;
        transform: rotate(45deg) scale(1.2);
    }
}

/* Light mode stars */
body.light-mode .star {
    border-bottom-color: rgba(0, 0, 0, 0.2);
}

body.light-mode .star::before {
    border-top-color: rgba(0, 0, 0, 0.2);
}

/* Micro lines */
.micro-lines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    overflow: hidden;
}

.micro-line {
    position: absolute;
    width: 10px;
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
    animation: line-drift 20s infinite linear;
}

.micro-line:nth-child(1) { top: 15%; left: 5%; transform: rotate(15deg); animation-delay: 0s; }
.micro-line:nth-child(2) { top: 25%; left: 15%; transform: rotate(-20deg); animation-delay: 2s; }
.micro-line:nth-child(3) { top: 35%; left: 25%; transform: rotate(30deg); animation-delay: 4s; }
.micro-line:nth-child(4) { top: 45%; left: 35%; transform: rotate(-15deg); animation-delay: 6s; }
.micro-line:nth-child(5) { top: 55%; left: 45%; transform: rotate(25deg); animation-delay: 8s; }
.micro-line:nth-child(6) { top: 65%; left: 55%; transform: rotate(-30deg); animation-delay: 10s; }
.micro-line:nth-child(7) { top: 75%; left: 65%; transform: rotate(20deg); animation-delay: 12s; }
.micro-line:nth-child(8) { top: 85%; left: 75%; transform: rotate(-25deg); animation-delay: 14s; }

@keyframes line-drift {
    0% {
        transform: translateX(0) translateY(0) rotate(var(--rotation, 0deg));
        opacity: 0;
    }
    10% {
        opacity: 0.1;
    }
    50% {
        transform: translateX(20px) translateY(-10px) rotate(var(--rotation, 0deg));
        opacity: 0.05;
    }
    90% {
        opacity: 0.1;
    }
    100% {
        transform: translateX(40px) translateY(-20px) rotate(var(--rotation, 0deg));
        opacity: 0;
    }
}

/* Light mode lines */
body.light-mode .micro-line {
    background: rgba(0, 0, 0, 0.05);
}

/* Tiny plus symbols */
.plus-symbols {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    overflow: hidden;
}

.plus-symbol {
    position: absolute;
    width: 3px;
    height: 3px;
    background: transparent;
    animation: plus-rotate 25s infinite linear;
}

.plus-symbol::before,
.plus-symbol::after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.1);
}

.plus-symbol::before {
    width: 3px;
    height: 1px;
    top: 1px;
    left: 0;
}

.plus-symbol::after {
    width: 1px;
    height: 3px;
    top: 0;
    left: 1px;
}

.plus-symbol:nth-child(1) { top: 12%; left: 8%; animation-delay: 0s; }
.plus-symbol:nth-child(2) { top: 22%; left: 18%; animation-delay: 3s; }
.plus-symbol:nth-child(3) { top: 32%; left: 28%; animation-delay: 6s; }
.plus-symbol:nth-child(4) { top: 42%; left: 38%; animation-delay: 9s; }
.plus-symbol:nth-child(5) { top: 52%; left: 48%; animation-delay: 12s; }
.plus-symbol:nth-child(6) { top: 62%; left: 58%; animation-delay: 15s; }
.plus-symbol:nth-child(7) { top: 72%; left: 68%; animation-delay: 18s; }
.plus-symbol:nth-child(8) { top: 82%; left: 78%; animation-delay: 21s; }

@keyframes plus-rotate {
    0% {
        transform: rotate(0deg);
        opacity: 0.05;
    }
    50% {
        transform: rotate(180deg);
        opacity: 0.1;
    }
    100% {
        transform: rotate(360deg);
        opacity: 0.05;
    }
}

/* Light mode plus symbols */
body.light-mode .plus-symbol::before,
body.light-mode .plus-symbol::after {
    background: rgba(0, 0, 0, 0.08);
}

/* Performance optimizations */
.micro-dots, .sparkles, .bubbles, .stars, .micro-lines, .plus-symbols {
    will-change: transform, opacity;
}

/* Reduce animations on mobile */
@media (max-width: 768px) {
    .micro-dot, .sparkle, .bubble, .star, .micro-line, .plus-symbol {
        animation-duration: 20s !important;
    }
}

/* Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    .micro-dot, .sparkle, .bubble, .star, .micro-line, .plus-symbol {
        animation: none !important;
    }
}
/* Footer Styles */
.footer {
    position: relative;
    width: 100%;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin-top: 4rem;
    padding: 3rem 0 1.5rem;
    z-index: 10;
}

body.light-mode .footer {
    background: rgba(248, 250, 252, 0.95);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.footer-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.footer-content {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

.footer-section {
    display: flex;
    flex-direction: column;
}

.footer-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

body.light-mode .footer-title {
    background: linear-gradient(135deg, var(--light-primary) 0%, var(--light-accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.footer-subtitle {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

body.light-mode .footer-subtitle {
    color: var(--light-text-primary);
}

.footer-description {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 1.5rem;
    max-width: 300px;
}

body.light-mode .footer-description {
    color: var(--light-text-secondary);
}

.footer-social {
    display: flex;
    gap: 1rem;
}

.social-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    transition: all 0.3s ease;
}

.social-link:hover {
    background: var(--accent);
    color: white;
    transform: translateY(-3px);
}

body.light-mode .social-link {
    background: rgba(0, 0, 0, 0.05);
    color: var(--light-text-secondary);
}

body.light-mode .social-link:hover {
    background: var(--light-accent);
    color: white;
}

.footer-links {
    list-style: none;
    padding: 0;
    margin: 0;
}

.footer-links li {
    margin-bottom: 0.75rem;
}

.footer-link {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.3s ease;
    position: relative;
}

.footer-link::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 1px;
    background: var(--accent);
    transition: width 0.3s ease;
}

.footer-link:hover {
    color: var(--accent);
}

.footer-link:hover::after {
    width: 100%;
}

body.light-mode .footer-link {
    color: var(--light-text-secondary);
}

body.light-mode .footer-link:hover {
    color: var(--light-accent);
}

body.light-mode .footer-link::after {
    background: var(--light-accent);
}

.footer-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

body.light-mode .footer-bottom {
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.footer-copyright p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

body.light-mode .footer-copyright p {
    color: var(--light-text-secondary);
}

.footer-bottom-links {
    display: flex;
    gap: 1.5rem;
}

.footer-bottom-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.3s ease;
}

.footer-bottom-link:hover {
    color: var(--accent);
}

body.light-mode .footer-bottom-link {
    color: var(--light-text-secondary);
}

body.light-mode .footer-bottom-link:hover {
    color: var(--light-accent);
}

/* Footer particles */
.footer-particles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: -1;
}

.footer-particle {
    position: absolute;
    width: 2px;
    height: 2px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    animation: footer-float 15s infinite ease-in-out;
}

.footer-particle:nth-child(1) { top: 10%; left: 5%; animation-delay: 0s; }
.footer-particle:nth-child(2) { top: 20%; left: 15%; animation-delay: 2s; }
.footer-particle:nth-child(3) { top: 30%; left: 25%; animation-delay: 4s; }
.footer-particle:nth-child(4) { top: 40%; left: 35%; animation-delay: 6s; }
.footer-particle:nth-child(5) { top: 50%; left: 45%; animation-delay: 8s; }

@keyframes footer-float {
    0%, 100% {
        transform: translateY(0px) translateX(0px);
        opacity: 0.1;
    }
    25% {
        transform: translateY(-5px) translateX(3px);
        opacity: 0.2;
    }
    50% {
        transform: translateY(-3px) translateX(-2px);
        opacity: 0.15;
    }
    75% {
        transform: translateY(-7px) translateX(4px);
        opacity: 0.1;
    }
}

body.light-mode .footer-particle {
    background: rgba(0, 0, 0, 0.05);
}

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

@media (max-width: 768px) {
    .footer {
        padding: 2rem 0 1rem;
        margin-top: 3rem;
    }
    
    .footer-content {
        grid-template-columns: 1fr;
        gap: 1.5rem;
        text-align: center;
    }
    
    .footer-social {
        justify-content: center;
    }
    
    .footer-bottom {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .footer-bottom-links {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .footer {
        padding: 1.5rem 0 1rem;
    }
    
    .footer-title {
        font-size: 1.3rem;
    }
    
    .footer-subtitle {
        font-size: 1rem;
    }
    
    .footer-description {
        max-width: 100%;
    }
}

/* Enhanced footer link styles */
.footer-link {
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.3s ease;
    position: relative;
    display: inline-block;
    cursor: pointer;
}

.footer-link::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    transition: width 0.3s ease;
}

.footer-link:hover {
    color: var(--accent);
    transform: translateX(3px);
}

.footer-link:hover::after {
    width: 100%;
}

/* Action link indicator */
.footer-link[onclick]::before {
    content: '⚡';
    position: absolute;
    right: -15px;
    top: 0;
    font-size: 0.8em;
    opacity: 0.5;
    transition: opacity 0.3s ease;
}

.footer-link[onclick]:hover::before {
    opacity: 1;
}

/* Active section highlighting */
.section-highlight {
    animation: sectionGlow 2s ease;
}

@keyframes sectionGlow {
    0%, 100% {
        box-shadow: 0 0 0 rgba(59, 130, 246, 0);
    }
    50% {
        box-shadow: 0 0 20px rgba(59, 130, 246, 0.3);
    }
}

/* Modal styles */
.documentation-modal, .shortcuts-modal {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .footer-link[onclick]::before {
        display: none;
    }
    
    .footer-link:hover {
        transform: none;
    }
}

/* Keyboard styling */
kbd {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 6px;
    font-family: monospace;
    font-size: 0.9em;
}

body.light-mode kbd {
    background: var(--light-bg-tertiary);
    border: 1px solid var(--light-border);
}

/* Enhanced section highlighting */
.section-highlight {
    animation: sectionGlow 2s ease;
    position: relative;
}

.section-highlight::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, var(--primary), var(--accent), var(--primary));
    border-radius: inherit;
    z-index: -1;
    opacity: 0.3;
    animation: borderGlow 2s ease;
}

@keyframes sectionGlow {
    0%, 100% {
        box-shadow: 0 0 0 rgba(59, 130, 246, 0);
    }
    50% {
        box-shadow: 0 0 30px rgba(59, 130, 246, 0.4);
    }
}

@keyframes borderGlow {
    0%, 100% {
        opacity: 0;
    }
    50% {
        opacity: 0.6;
    }
}

/* Pulse animation for quick actions */
@keyframes sectionPulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.02);
    }
    100% {
        transform: scale(1);
    }
}

/* Enhanced footer link feedback */
.footer-link[onclick]:active {
    transform: translateX(3px) scale(0.95);
}

/* Loading state for quick actions */
.footer-link.loading {
    pointer-events: none;
    opacity: 0.6;
}

.footer-link.loading::after {
    content: '⏳';
    position: absolute;
    right: -20px;
    top: 0;
    font-size: 0.8em;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Enhanced particle system with connections */
.particle-network {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
}

.network-particle {
    position: absolute;
    width: 3px;
    height: 3px;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.8) 0%, transparent 70%);
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.5);
    animation: float-particle 20s infinite ease-in-out;
}

@keyframes float-particle {
    0%, 100% {
        transform: translateY(0) translateX(0) scale(1);
        opacity: 0.3;
    }
    25% {
        transform: translateY(-30px) translateX(20px) scale(1.2);
        opacity: 0.8;
    }
    50% {
        transform: translateY(-20px) translateX(-30px) scale(0.8);
        opacity: 0.5;
    }
    75% {
        transform: translateY(-40px) translateX(10px) scale(1.1);
        opacity: 0.7;
    }
}

.particle-connection {
    position: absolute;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.3), transparent);
    transform-origin: left center;
    animation: pulse-connection 3s infinite ease-in-out;
}

@keyframes pulse-connection {
    0%, 100% { opacity: 0.1; }
    50% { opacity: 0.4; }
}

/* Add floating gradient orbs for extra visual appeal */
.gradient-orbs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    overflow: hidden;
}

.gradient-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    animation: float-orb 25s infinite ease-in-out;
}

.gradient-orb:nth-child(1) {
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, #9c27b0 0%, transparent 70%);
    top: -200px;
    left: -200px;
    animation-delay: 0s;
}

.gradient-orb:nth-child(2) {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, #ba68c8 0%, transparent 70%);
    bottom: -150px;
    right: -150px;
    animation-delay: 5s;
}

.gradient-orb:nth-child(3) {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, #ce93d8 0%, transparent 70%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: 10s;
}

@keyframes float-orb {
    0%, 100% {
        transform: translate(0, 0) scale(1);
        opacity: 0.3;
    }
    25% {
        transform: translate(50px, -100px) scale(1.1);
        opacity: 0.5;
    }
    50% {
        transform: translate(-30px, 50px) scale(0.9);
        opacity: 0.4;
    }
    75% {
        transform: translate(80px, 30px) scale(1.05);
        opacity: 0.6;
    }
}

/* Light mode floating orbs */
body.light-mode .gradient-orb:nth-child(1) {
    background: radial-gradient(circle, #e1bee7 0%, transparent 70%);
}

body.light-mode .gradient-orb:nth-child(2) {
    background: radial-gradient(circle, #ce93d8 0%, transparent 70%);
}

body.light-mode .gradient-orb:nth-child(3) {
    background: radial-gradient(circle, #ba68c8 0%, transparent 70%);
}


/* Realistic space stars overlay */
header {
    position: relative;
    overflow: hidden;
}

/* Space overlay container */
.space-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    background: radial-gradient(ellipse at center, transparent 0%, rgba(0, 0, 0, 0.1) 100%);
}

/* Realistic star styles */
.star {
    position: absolute;
    background: white;
    border-radius: 50%;
    animation: twinkle ease-in-out infinite;
}

/* Different star sizes */
.star.small {
    width: 0.5px;
    height: 0.5px;
    box-shadow: 0 0 1px rgba(255, 255, 255, 0.8);
}

.star.medium {
    width: 1px;
    height: 1px;
    box-shadow: 0 0 2px rgba(255, 255, 255, 0.9);
}

.star.large {
    width: 1.5px;
    height: 1.5px;
    box-shadow: 0 0 3px rgba(255, 255, 255, 1);
}

/* Natural twinkling animation */
@keyframes twinkle {
    0%, 100% { opacity: 0.3; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.2); }
}

/* Subtle floating movement */
@keyframes float-random {
    0% { transform: translate(0, 0); }
    25% { transform: translate(1px, -1px); }
    50% { transform: translate(-1px, 1px); }
    75% { transform: translate(2px, 0px); }
    100% { transform: translate(0, 0); }
}

/* Slow drift animation for background stars */
@keyframes slow-drift {
    0% { transform: translate(0, 0); }
    100% { transform: translate(3px, 2px); }
}

/* Ensure header content stays above stars */
header h1, header h4, header p {
    position: relative;
    z-index: 2;
}

/* Light mode stars */
body.light-mode .star {
    background: rgba(156, 39, 176, 0.7);
}

body.light-mode .star.small {
    box-shadow: 0 0 1px rgba(156, 39, 176, 0.6);
}

body.light-mode .star.medium {
    box-shadow: 0 0 2px rgba(156, 39, 176, 0.7);
}

body.light-mode .star.large {
    box-shadow: 0 0 3px rgba(156, 39, 176, 0.8);
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .star {
        animation-duration: 4s; /* Slower on mobile */
    }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    .star {
        animation: none;
        opacity: 0.6;
    }
}


/* Add subtle glow to larger stars */
.star.large::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 4px;
    height: 4px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.8) 0%, transparent 70%);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { opacity: 0.3; transform: translate(-50%, -50%) scale(1); }
    50% { opacity: 0.8; transform: translate(-50%, -50%) scale(1.5); }
}

/* Add occasional shooting star */
.shooting-star {
    position: absolute;
    width: 2px;
    height: 2px;
    background: white;
    border-radius: 50%;
    opacity: 0;
    animation: shoot 3s linear infinite;
}

.shooting-star::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    width: 50px;
    height: 1px;
    background: linear-gradient(90deg, white, transparent);
    transform: translateY(-50%);
}

@keyframes shoot {
    0% {
        transform: translateX(-100px) translateY(0);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    90% {
        opacity: 1;
    }
    100% {
        transform: translateX(300px) translateY(100px);
        opacity: 0;
    }
}

/* Add shooting stars occasionally */
.space-overlay::after {
    content: '';
    position: absolute;
    width: 2px;
    height: 2px;
    background: white;
    border-radius: 50%;
    top: 20%;
    left: 10%;
    opacity: 0;
    animation: shoot 8s linear infinite;
    animation-delay: 5s;
}

.space-overlay::after::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    width: 50px;
    height: 1px;
    background: linear-gradient(90deg, white, transparent);
    transform: translateY(-50%);
}

/* Floating action indicators */
.floating-indicator {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(156, 39, 176, 0.4);
    transition: all 0.3s ease;
    z-index: 1000;
    animation: float-indicator 3s ease-in-out infinite;
}

@keyframes float-indicator {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.floating-indicator:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 35px rgba(156, 39, 176, 0.6);
}

.floating-indicator::before {
    content: '';
    position: absolute;
    top: -5px;
    left: -5px;
    right: -5px;
    bottom: -5px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 50%;
    z-index: -1;
    opacity: 0.5;
    animation: pulse-ring 2s ease-in-out infinite;
}

@keyframes pulse-ring {
    0%, 100% { transform: scale(1); opacity: 0.5; }
    50% { transform: scale(1.1); opacity: 0.3; }
}

/* Responsive Design */
@media (max-width: 1400px) {
    .main-layout {
        grid-template-columns: 300px 1fr 340px;
    }
    
    .tree-container {
        height: 450px;
        min-height: 450px;
    }
}

@media (max-width: 1200px) {
    .main-layout {
        grid-template-columns: 1fr;
        gap: 1rem;
        min-height: auto;
    }
    
    .visualization-panel {
        order: 1;
        min-height: 60vh;
    }
    
    .tree-container {
        height: calc(60vh - 150px);
        min-height: 400px;
    }
    
    .algorithm-panel {
        order: 2;
    }
    
    .right-panel {
        order: 3;
    }
}

@media (max-width: 992px) {
    .container {
        padding: 1rem;
    }
    
    .tree-container {
        height: 400px;
        min-height: 350px;
    }
}

@media (max-width: 768px) {
    .tree-container {
        height: 350px;
        min-height: 300px;
    }
    
    .visualization-panel {
        min-height: 50vh;
    }
}

@media (max-width: 480px) {
    .tree-container {
        height: 300px;
        min-height: 250px;
    }
    
    .visualization-panel {
        min-height: 45vh;
    }
}

@media (max-width: 768px) {
    .comparison-section {
        display: none !important;
    }
}

@media (max-width: 768px) {
    .tree-placeholder {
        display: none !important;
    }
}

