/* Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

.container {
    background: #e7ca3c;
    padding: 25px;
    border-radius: 15px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 1000px;
    min-height: 470px;
}

.main-content {
    display: flex;
    gap: 2rem;
    position: relative;
}

/* Guide Character */
.guide-character {
    position: relative;
    width: 160px;
}

.man-image {
    width: 210px;
    height: auto;
    position: absolute;
    left: 15px;
    top: -150px;
}

.speech-bubble {
    position: absolute;
    left: -7px;
    top: 140px;
    background: rgba(255,255,255,0.95);
    padding: 1rem;
    border-radius: 1rem;
    width: 237px;
    box-shadow: 0 4px 15px #eb0606f3;
    font-size: 0.95rem;
    line-height: 1.4;
    z-index: 100;
    opacity: 0.7;
    text-align: center;
}

h1 {
    display: block;
    font-size: 4em;
    text-align: center;
    margin-block-start: 0.67em;
    margin-block-end: 0.67em;
    font-weight: bold;
    position: relative;
    top: -25px;
}

/* Array Visualization */
.simulation-area {
    flex-grow: 1;
    position: absolute;
    transform: translateX(238px);
}

.array-container {
    position: relative;
    min-height: 270px;
    padding: 1rem;
    background: rgba(231, 202, 60, 0.9);
    border-radius: 0.8rem;
    transform: translate(40px,-45px);
}

.array-boxes {
    display: flex;
    gap: 0.6rem;
    justify-content: center;
    position: relative;
    z-index: 2;
}

/* Center-align new elements dynamically */
.array-boxes .array-box {
    transition: all 0.4s ease;
}

/* Array Box */
.array-box {
    width: 60px;
    height: 60px;
    background: maroon;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    font-size: 1.4rem;
    font-weight: bold;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

/* Temp Array Visualization */
.temp-container {
    position: absolute;
    top: calc(100% + 20px); /* Positioned just below the main array */
    left: 50%;
    transform: translate(-50%,-173%);
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(5px);
    padding: 1rem;
    border-radius: 0.8rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    z-index: 3;
    border: 2px solid rgba(198, 40, 40, 0.2);
    opacity: 0.9;
    transition: all 0.1s ease;
    display: flex;
    gap: 0.6rem;
    flex-wrap: nowrap;
    justify-content: center; /* Ensures proper centering */
    min-width: fit-content;
}

.temp-box {
    width: 60px;
    height: 60px;
    background: #f0f4c3;
    color: #827717;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    font-size: 1.4rem;
    border: 2px solid #827717;
    transition: all 0.3s ease;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

/* Highlighted boxes during comparison */
.highlight {
    background: #ffcdd2 !important;
    border-color: #c62828 !important;
    color: #c62828 !important;
}

/* Flipping animation for swapping */
.flip {
    animation: flip 0.6s ease;
}

@keyframes flip {
    0% { transform: rotateX(0deg); }
    50% { transform: rotateX(180deg); }
    100% { transform: rotateX(360deg); }
}

/* Pop-in animation */
.pop-in {
    animation: smoothPop 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

@keyframes smoothPop {
    0% { transform: translateY(20px) scale(0.9); opacity: 0; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

/* Controls */
.controls {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
    justify-content: center;
}

input[type="number"] {
    padding: 0.8rem;
    border: 2px solid #ccc;
    border-radius: 0.6rem;
    font-size: 1.1rem;
    text-align: center;
    width: 203px;
    outline: none;
    transform: translate(140px,195px);
}

/* Removes Number Input Spinners */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

button {
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 0.6rem;
    background: #6b5d00;
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

button:hover {
    background: #8c7a00;
    transform: translateY(-2px);
}

button:disabled {
    background: #9e9e9e;
    cursor: not-allowed;
}

#add-number.add-number {
    transform: translate(130px,195px);
    width: 25%;
}

/* Run Merge Sort Button */
#run-algo {
    transform: translate(122px,195px);
    width: 27%;
}

/* Mobile Responsive Design */
@media (max-width: 768px) {
    .container {
        width: 130% !important;
        padding: 15px;
        border-radius: 0rem;
    }

    .array-container {
        min-height: 150px;
        padding: 0.5rem;
    }

    .array-box {
        width: 40px;
        height: 40px;
        font-size: 14px;
    }

    .temp-container {
        gap: 0.3rem;
        padding: 0.5rem;
        transform: scale(0.9);
        left: 50%;
        transform: translateY(-80px);
    }

    .temp-box {
        width: 35px;
        height: 35px;
        font-size: 0.9rem;
        padding: 0.3rem;
    }

    .controls {
        flex-direction: column;
        gap: 0.5rem;
        margin-top: 1rem;
    }

    input[type="number"],
    button {
        width: 100%;
        padding: 0.6rem;
        font-size: 1rem;
    }
}
