/**
 * 归并排序可视化样式
 * @author changyadai
 * 
 * 算法特有样式 - 递归树、分治和合并动画
 */

/* ==================== 阶段指示器 ==================== */
.phase-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
    padding: 12px 30px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 30px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.phase {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 20px;
    transition: all 0.3s ease;
    opacity: 0.5;
}

.phase.active {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

.phase-icon {
    font-size: 1.2rem;
}

.phase-text {
    font-size: 0.95rem;
    color: rgba(255, 255, 255, 0.8);
}

.divide-phase.active {
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.5);
}

.merge-phase.active {
    box-shadow: 0 0 15px rgba(34, 197, 94, 0.5);
}

.phase-arrow {
    color: rgba(255, 255, 255, 0.4);
    font-size: 1.2rem;
}

/* ==================== 递归树可视化 ==================== */
.tree-visualization {
    min-height: 120px;
    margin-bottom: 15px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 15px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    overflow-x: auto;
}

.tree-level {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.tree-node {
    display: flex;
    gap: 3px;
    padding: 6px 10px;
    background: rgba(139, 92, 246, 0.2);
    border: 1px solid rgba(139, 92, 246, 0.4);
    border-radius: 8px;
    transition: all 0.3s ease;
}

.tree-node.active {
    background: rgba(139, 92, 246, 0.4);
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.6);
    transform: scale(1.05);
}

.tree-node.merging {
    background: rgba(34, 197, 94, 0.3);
    border-color: rgba(34, 197, 94, 0.6);
    box-shadow: 0 0 15px rgba(34, 197, 94, 0.5);
}

.tree-node.completed {
    background: rgba(34, 197, 94, 0.2);
    border-color: rgba(34, 197, 94, 0.4);
}

.tree-item {
    min-width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    font-size: 11px;
    font-weight: bold;
    color: #fff;
}

/* ==================== 操作区域 ==================== */
.operation-area {
    margin-bottom: 15px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 15px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.operation-label {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.merge-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 15px;
}

.merge-section {
    flex: 1;
    max-width: 250px;
}

.section-title {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 8px;
}

.section-items, .result-items {
    display: flex;
    justify-content: center;
    gap: 5px;
    min-height: 45px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 10px;
    flex-wrap: wrap;
}

.left-section .section-items {
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.right-section .section-items {
    border: 1px solid rgba(236, 72, 153, 0.3);
}

.result-section {
    margin-top: 10px;
}

.result-items {
    border: 1px solid rgba(34, 197, 94, 0.3);
    background: rgba(34, 197, 94, 0.05);
}

.merge-arrow {
    font-size: 1.5rem;
    opacity: 0.6;
    animation: pulseArrow 1s ease-in-out infinite;
}

@keyframes pulseArrow {
    0%, 100% { transform: scale(1); opacity: 0.6; }
    50% { transform: scale(1.1); opacity: 1; }
}

/* ==================== 合并项目样式 ==================== */
.merge-item {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 13px;
    font-weight: bold;
    color: #fff;
    transition: all 0.3s ease;
}

.merge-item.left {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    box-shadow: 0 2px 10px rgba(59, 130, 246, 0.3);
}

.merge-item.right {
    background: linear-gradient(135deg, #ec4899 0%, #db2777 100%);
    box-shadow: 0 2px 10px rgba(236, 72, 153, 0.3);
}

.merge-item.result {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    box-shadow: 0 2px 10px rgba(34, 197, 94, 0.3);
    animation: popIn 0.3s ease-out;
}

.merge-item.active {
    transform: scale(1.15);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

.merge-item.used {
    opacity: 0.3;
    transform: scale(0.9);
}

@keyframes popIn {
    0% { transform: scale(0); opacity: 0; }
    70% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

/* ==================== 主数组 ==================== */
.main-array-section {
    margin-bottom: 15px;
}

.section-label {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.array-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 8px;
    flex-wrap: wrap;
    padding-top: 20px; /* 为索引标签留出空间 */
    min-height: 62px; /* 42px (item height) + 20px (padding-top) */
    max-height: 80px; /* 限制最大高度 */
    overflow: visible;
}

.array-item {
    width: 42px;
    height: 42px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    font-size: 13px;
    font-weight: bold;
    color: #fff;
    transition: all 0.3s ease;
    position: relative;
}

.array-item .index {
    position: absolute;
    top: -16px;
    font-size: 9px;
    color: rgba(255, 255, 255, 0.4);
    font-weight: normal;
    white-space: nowrap;
}

.array-item.in-range {
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.6);
    transform: scale(1.05);
}

.array-item.left-part {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
}

.array-item.right-part {
    background: linear-gradient(135deg, #ec4899 0%, #db2777 100%);
}

.array-item.merging {
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    box-shadow: 0 0 15px rgba(251, 191, 36, 0.6);
}

.array-item.sorted {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.4);
}

/* ==================== 粒子效果 ==================== */
.merge-particle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: radial-gradient(circle, rgba(34, 197, 94, 0.8) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
    animation: mergeParticleFade 0.6s ease-out forwards;
}

@keyframes mergeParticleFade {
    0% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(2) translateY(-20px); }
}

/* ==================== 完成动画 ==================== */
.array-item.celebrate {
    animation: mergeCelebrate 0.5s ease-in-out;
}

@keyframes mergeCelebrate {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15) translateY(-5px); }
}

/* ==================== 响应式 ==================== */
@media (max-width: 768px) {
    .merge-container {
        flex-direction: column;
        gap: 10px;
    }
    
    .merge-section {
        max-width: 100%;
    }
    
    .merge-arrow {
        transform: rotate(90deg);
    }
    
    .array-item, .merge-item {
        width: 35px;
        height: 35px;
        font-size: 11px;
    }
}
