body {
    font-family: Arial, Helvetica, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: linear-gradient(110deg, #101051 10%, #482279 100%);
    margin: 0;
    padding: 2vw;
    color: #e0e0e0;
    min-height: 100vh;
}

h1, #status, .param label, .param span, .pause-label {
    color: rgb(100, 255, 218);
}

h1 {
    font-size: clamp(1.5rem, 4vw, 2rem);
    text-align: center;
    opacity: 0;
}

#status {
    margin: 1rem 0;
    font-weight: bold;
    font-size: clamp(0.9rem, 2.5vw, 1.2rem);
    text-align: center;
    opacity: 0;
}

.grid-container {
    display: grid;
    gap: 0.1rem;
    background-color: #fff;
    padding: 0.5rem;
    border: 2px solid rgb(100, 255, 218);
    border-radius: 50px;
    max-width: min(90vw, 30rem); /* Increased from 20rem to 30rem for larger grid */
    max-height: 70vh; /* Increased from 50vh to 70vh for taller grid */
    overflow-y: auto; /* Scroll if grid is too tall */
    box-sizing: border-box;
    justify-content: center;
    align-items: center;
    opacity: 0;
}

.state-healthy { color: green; font-weight: bold; }
.state-eclipse { color: yellow; font-weight: bold; }
.state-infected { color: red; font-weight: bold; }
.state-fused   { color: purple; font-weight: bold; }
.state-dead    { color: black; font-weight: bold; }

.controls {
    margin: 1rem 0;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
    opacity: 0;
}

.params {
    background-color: rgba(255, 255, 255, 0.1);
    padding: 1rem;
    border-radius: 25px;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    width: min(90%, 600px);
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-left: auto;
    margin-right: auto;
    opacity: 0;
}

.simulation-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 90vw;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.simulation-container h1.visible {
    opacity: 1;
    transition: opacity 0.5s ease 0s;
}

.simulation-container #status.visible {
    opacity: 1;
    transition: opacity 0.5s ease 0.2s;
}

.simulation-container .grid-container.visible {
    opacity: 1;
    transition: opacity 0.5s ease 0.4s;
}

.simulation-container .controls.visible {
    opacity: 1;
    transition: opacity 0.5s ease 0.6s;
}

.simulation-container .params.visible {
    opacity: 1;
    transition: opacity 0.5s ease 0.8s;
}

.cell {
    width: 100%;
    aspect-ratio: 1 / 1;
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
}

.cell.h { background-color: green; }
.cell.e { background-color: yellow; }
.cell.i { background-color: red; }
.cell.f { background-color: purple; }
.cell.d { background-color: black; }
.cell.o { background-color: white; }

.cell:hover {
    opacity: 0.7;
    cursor: pointer;
}

.control-button {
    padding: 0.5rem 1rem;
    background-color: #007bff;
    color: rgb(100, 255, 218);
    border: none;
    border-radius: 25px;
    cursor: pointer;
    transition: opacity 0.75ms, color 0.75s, box-shadow 300ms;
    font-size: clamp(0.8rem, 2vw, 1rem);
}

.control-button:hover {
    background-color:  rgb(100, 255, 218);
    color: #007bff;
    box-shadow: -3px 1px 3px rgba(98, 95, 95, 0.7);
}

.control-button:active {
    opacity: 0.9;
    color: #401479;
}

.param {
    margin: 0.5rem 0;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.9rem;
    justify-content: center;
    text-align: center;
}

.param label {
    width: min(120px, 30%);
    font-weight: bold;
    font-size: clamp(0.8rem, 2vw, 1rem);
}

.param input[type="range"] {
    flex: 1;
    min-width: 100px;
    max-width: 200px;
}

.param span {
    margin-left: 0.5rem;
    font-size: clamp(0.8rem, 2vw, 1rem);
}

.toggle-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
}

.toggle-container input[type="checkbox"] {
    display: none;
}

.toggle-container label {
    width: 3rem;
    height: 1.5rem;
    background-color: #ccc;
    border-radius: 0.75rem;
    position: relative;
    cursor: pointer;
    transition: background-color 0.3s;
}

.toggle-container label::before {
    content: '';
    position: absolute;
    width: 1.3rem;
    height: 1.3rem;
    background-color: white;
    border-radius: 50%;
    top: 0.1rem;
    left: 0.1rem;
    transition: transform 0.3s;
}

.toggle-container input:checked + label {
    background-color: #007bff;
}

.toggle-container input:checked + label::before {
    transform: translateX(1.5rem);
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 1.2rem;
    height: 1.2rem;
    border-radius: 50%;
    background: #007bff;
    border: 2px solid #fff;
    box-shadow: 0 0 2px #333;
    cursor: pointer;
    transition: background 0.3s;
}

input[type="range"]::-webkit-slider-thumb:active {
    opacity: 0.85;
}

.intro-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(110deg, #101051 10%, #401479 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.5s ease;
}

.intro-overlay.hidden {
    opacity: 0;
    pointer-events: none;
    display: none;
}

.hex-grid {
    display: grid;
    grid-template-columns: repeat(10, minmax(20px, 3vw));
    gap: 0.3rem;
}

.hex {
    width: 100%;
    aspect-ratio: 1 / 1;
    background-color: #e0e0e0;
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
    animation: scatter 2s ease-out forwards;
    animation-delay: calc(0.05s * var(--i));
}

@keyframes scatter {
    0% {
        transform: scale(1) translate(0, 0);
        opacity: 1;
    }
    100% {
        transform: scale(0.5) translate(calc(var(--dx) * 10vw), calc(var(--dy) * 10vw));
        opacity: 0;
    }
}

@media (max-width: 600px) {
    .grid-container {
        max-width: 90vw;
        max-height: 50vh; /* Adjusted for mobile to prevent excessive height */
    }
    .param {
        flex-direction: column;
        align-items: flex-start;
    }
    .param label {
        width: 100%;
    }
    .param input[type="range"] {
        width: 100%;
        max-width: none;
    }
    .controls {
        flex-direction: column;
        align-items: center;
    }
    .toggle-container {
        margin-left: 0;
    }
}