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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #eff6ff 0%, #e0e7ff 100%);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden; /* Prevent horizontal scroll from animations */
}

/* Navigation */
.nav-bar {
    background: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid #e5e7eb;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-container {
    max-width: 1152px;
    margin: 0 auto;
    padding: 12px 16px;
}

.nav-menu {
    display: flex;
    gap: 24px;
}

.nav-button {
    background: none;
    border: none;
    color: #374151;
    font-weight: 500;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 6px;
    transition: color 0.2s ease;
}

.nav-button:hover {
    color: #2563eb;
}

/* Floating Action Buttons */
.floating-controls {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 1000;
}

.fab {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.2s ease; /* Reduced transition time */
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.fab:hover {
    transform: scale(1.05); /* Reduced scale to minimize movement */
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.fab:active {
    transform: scale(0.98); /* Minimal scale change */
}

.fab-primary {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: white;
}

.fab-primary:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.fab-primary:disabled:hover {
    transform: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.fab-secondary {
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
    color: white;
}

/* Tooltip for FAB */
.fab::before {
    content: attr(title);
    position: absolute;
    right: 100%;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    margin-right: 12px;
}

.fab:hover::before {
    opacity: 1;
}

/* Main Container - FIXED LAYOUT */
.main-container {
    padding: 16px;
    padding-bottom: 120px; /* Extra space for floating buttons */
}

.content-wrapper {
    max-width: 1152px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Bottom Spacer */
.bottom-spacer {
    height: 100px;
}

/* Card Styles - FIXED HEIGHTS */
.card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.card-header {
    padding: 24px;
    border-bottom: 1px solid #e5e7eb;
}

.card-header.text-center {
    text-align: center;
}

.card-content {
    padding: 24px;
}

.card-title {
    font-size: 18px;
    font-weight: 600;
    color: #4338ca;
    margin-bottom: 0;
}

.title {
    font-size: 24px;
    font-weight: 700;
    color: #1e40af;
    margin-bottom: 8px;
}

.subtitle {
    color: #6b7280;
    margin-bottom: 8px;
}

.tip {
    font-size: 14px;
    color: #4338ca;
}

/* Radio Group */
.radio-group {
    display: flex;
    justify-content: center;
    gap: 32px;
    margin-bottom: 8px;
}

.radio-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.radio-item input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: #4338ca;
}

.radio-label {
    font-size: 18px;
    cursor: pointer;
    font-weight: 500;
}

.radio-description {
    text-align: center;
    font-size: 14px;
    color: #6b7280;
}

/* Grid Layout */
.grid-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    min-height: 600px; /* Fixed minimum height */
}

@media (max-width: 1024px) {
    .grid-container {
        grid-template-columns: 1fr;
        min-height: 1200px; /* Adjusted for single column */
    }
}

/* Code Block - FIXED HEIGHT WITH BOLD WHITE TEXT */
.code-block {
    background: #111827;
    color: #ffffff !important; /* Changed from #10b981 to white */
    padding: 16px;
    border-radius: 8px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
    font-weight: bold !important; /* Added bold */
    margin-bottom: 16px;
    min-height: 200px; /* Fixed height for code block */
}

.code-line {
    padding: 4px 8px;
    border-radius: 4px;
    margin-bottom: 2px;
    transition: all 0.1s ease; /* Faster transitions */
    min-height: 22px; /* Fixed line height */
    color: #ffffff !important; /* Ensure all code lines are white */
    font-weight: bold !important; /* Ensure all code lines are bold */
}

.code-line.highlighted {
    background: #eab308;
    color: #000000; /* Black text on yellow background for contrast */
    font-weight: bold;
}

/* Variables Box - FIXED HEIGHT */
.variables-box {
    background: #eff6ff;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    min-height: 80px; /* Fixed height */
}

.variables-title {
    font-weight: 600;
    color: #1e40af;
    margin-bottom: 8px;
    font-size: 14px;
}

.variables-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    font-size: 14px;
}

/* Comparison Info - FIXED HEIGHT */
.comparison-info {
    background: #fefce8;
    border: 1px solid #fbbf24;
    padding: 8px;
    border-radius: 8px;
    margin-top: 8px;
    min-height: 40px; /* Fixed height */
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.1s ease;
}

.comparison-info.hidden {
    opacity: 0;
    visibility: hidden;
}

.comparison-text {
    font-size: 14px;
    color: #92400e;
}

/* Array Visualization - FIXED LAYOUT */
.array-indices {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 8px;
    height: 20px; /* Fixed height */
}

.array-index {
    width: 64px;
    text-align: center;
    font-size: 14px;
    color: #6b7280;
}

.array-elements {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 16px;
    height: 80px; /* Fixed height including animation space */
    align-items: center;
}

.array-element {
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #d1d5db;
    border-radius: 8px;
    font-size: 18px;
    font-weight: bold;
    background: white;
    color: #374151;
    transition: all 0.1s ease; /* Faster transition */
}

.array-element.sorted {
    background: #dcfce7;
    border-color: #10b981;
    color: #065f46;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.array-element.comparing {
    background: #fef3c7;
    border-color: #f59e0b;
    color: #92400e;
    transform: translateY(-5px) scale(1.05); /* Reduced scale */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.array-element.comparing .element-value {
    transform: scale(1.1); /* Reduced scale */
}

/* Legend - FIXED HEIGHT */
.legend {
    display: flex;
    justify-content: center;
    gap: 16px;
    font-size: 14px;
    margin-bottom: 16px;
    height: 24px; /* Fixed height */
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    border: 1px solid;
}

.legend-color.sorted {
    background: #dcfce7;
    border-color: #10b981;
}

.legend-color.comparing {
    background: #fef3c7;
    border-color: #f59e0b;
}

.legend-color.unsorted {
    background: white;
    border-color: #d1d5db;
}

/* Memory Triangle - FIXED HEIGHT AND POSITION */
.memory-triangle {
    background: #faf5ff;
    border: 1px solid #c4b5fd;
    padding: 16px;
    border-radius: 8px;
    margin: 16px 0;
    height: 220px; /* Fixed height */
    opacity: 0;
    transition: opacity 0.1s ease; /* Faster transition */
    display: flex;
    flex-direction: column;
}

.memory-triangle.active {
    opacity: 1;
}

.memory-title {
    font-weight: 600;
    color: #6b21a8;
    margin-bottom: 12px;
    text-align: center;
    font-size: 14px;
    height: 20px; /* Fixed height */
}

.triangle-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    flex: 1;
    justify-content: center;
}

.memory-box {
    width: 64px;
    height: 64px;
    border-radius: 8px;
    border: 2px solid #a855f7;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #6b21a8;
    background: #e5e7eb;
    transition: all 0.1s ease; /* Faster transition */
}

.memory-box.active {
    background: #fbbf24;
    transform: scale(1.1); /* Reduced scale */
}

.memory-label {
    font-size: 10px;
}

.memory-value {
    font-size: 18px;
}

.arrows-container {
    display: flex;
    align-items: center;
    gap: 32px;
    height: 20px; /* Fixed height */
}

.arrow {
    color: #a855f7;
    font-size: 16px;
    opacity: 0.3;
    transition: opacity 0.1s ease;
}

.arrow.active {
    opacity: 1;
}

.bottom-boxes {
    display: flex;
    gap: 32px;
}

.swap-arrow {
    position: absolute;
    top: 80px;
    font-size: 24px;
    color: #a855f7;
    opacity: 0.3;
    transform: scale(1);
    transition: all 0.1s ease;
}

.swap-arrow.active {
    opacity: 1;
    transform: scale(1.1); /* Reduced scale */
}

/* Pairs Info - FIXED HEIGHT */
.pairs-info {
    background: #eff6ff;
    padding: 12px;
    border-radius: 8px;
    min-height: 60px; /* Fixed height */
}

.pairs-title {
    font-weight: 600;
    color: #1e40af;
    margin-bottom: 8px;
    font-size: 14px;
}

.pairs-text {
    font-size: 14px;
    color: #1d4ed8;
}

/* Status Section - FIXED HEIGHT */
.status-section {
    text-align: center;
    min-height: 120px; /* Fixed height */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.status-message {
    background: white;
    border: 1px solid #d1d5db;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 18px;
    margin-bottom: 16px;
    display: inline-block;
    min-height: 50px; /* Fixed height */
    display: flex;
    align-items: center;
    justify-content: center;
}

.completion-message {
    color: #059669;
    font-weight: 600;
    font-size: 18px;
    opacity: 0;
    transition: opacity 0.1s ease; /* Faster transition */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.completion-message.show {
    opacity: 1;
}

.completion-tip {
    font-size: 14px;
    color: #6b7280;
    font-weight: normal;
}

/* Educational Content - FIXED HEIGHT */
.education-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    font-size: 14px;
}

.education-item {
    line-height: 1.5;
}

.pairs-list {
    margin: 4px 0 0 16px;
    font-size: 12px;
}

.pairs-list li {
    margin-bottom: 2px;
}

.tip-box {
    background: #fefce8;
    border-left: 4px solid #eab308;
    padding: 8px;
    border-radius: 4px;
    margin-top: 12px;
}

.array-values {
    margin-left: 8px;
    font-size: 14px;
    color: #6b7280;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .floating-controls {
        bottom: 16px;
        right: 16px;
    }
    
    .fab {
        width: 56px;
        height: 56px;
        font-size: 20px;
    }
    
    .fab::before {
        font-size: 12px;
        padding: 6px 8px;
    }
    
    .main-container {
        padding: 8px;
        padding-bottom: 100px;
    }
    
    .array-elements {
        gap: 4px;
        height: 70px; /* Adjusted for mobile */
    }
    
    .array-element {
        width: 48px;
        height: 48px;
        font-size: 16px;
    }
    
    .array-index {
        width: 48px;
        font-size: 12px;
    }
    
    .memory-triangle {
        height: 200px; /* Slightly smaller on mobile */
    }
    
    .grid-container {
        min-height: auto; /* Remove fixed height on mobile */
    }
}

/* PREVENT LAYOUT SHIFTS */
.no-layout-shift {
    contain: layout; /* CSS containment to prevent shifts */
}

/* Smooth scrolling but prevent jumps */
html {
    scroll-behavior: smooth;
}

/* Animations - MINIMAL AND FAST */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7; /* Reduced pulse effect */
    }
}

.pulsing {
    animation: pulse 0.5s ease; /* Faster pulse */
}

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

.slide-in {
    animation: slideIn 0.1s ease; /* Much faster */
}

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

.fade-in {
    animation: fadeIn 0.1s ease; /* Much faster */
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .fab {
        border: 2px solid #000;
    }
    
    .fab-primary {
        background: #0000ff;
    }
    
    .fab-secondary {
        background: #ff6600;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .fab:hover {
        transform: none;
    }
    
    .array-element.comparing {
        transform: none;
    }
    
    .memory-box.active {
        transform: none;
    }
}

/* STABLE LAYOUT - PREVENT ANY UNEXPECTED SHIFTS */
.content-wrapper > .card {
    will-change: auto; /* Prevent unnecessary compositor layers */
}

/* Optimize for smooth interactions */
.fab {
    will-change: transform;
}

.array-element {
    will-change: transform;
}

/* Ensure fixed positioning */
.floating-controls {
    contain: layout;
}