* {
    box-sizing: border-box;
}

body {
    background-color: #1a202c;
    color: #e2e8f0;
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.container {
    display: flex;
    background-color: #2d3748;
    border-radius: 8px;
    overflow: hidden;
    width: 800px;
    max-width: 95%;
    height: 600px;
    flex-wrap: wrap;
    position: relative;
    justify-content: center;
}

.sidebar {
    padding: 20px;
    width: 200px;
    background-color: #2d3748;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.mode-toggle {
    display: flex;
    background-color: #4a5568;
    border-radius: 4px;
    overflow: hidden;
}

.mode-toggle button {
    flex: 1;
    padding: 10px;
    border: none;
    background: none;
    color: #e2e8f0;
    cursor: pointer;
}

.mode-toggle button.active {
    background-color: #2d3748;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

label {
    font-size: 14px;
}

input, select, .display {
    background-color: #4a5568;
    border: none;
    padding: 10px;
    color: #e2e8f0;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.display span {
    background-color: #d69e2e;
    border-radius: 50%;
    padding: 2px 6px;
    color: #1a202c;
    font-size: 12px;
}

.buttons {
    display: flex;
    gap: 5px;
}

.buttons button {
    flex: 1;
    background-color: #4a5568;
    border: none;
    padding: 5px;
    color: #e2e8f0;
    cursor: pointer;
    border-radius: 4px;
}

.play-button {
    background-color: #48bb78;
    color: #1a202c;
    padding: 15px;
    border: none;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
}

.random-pick {
    background-color: #4a5568;
    padding: 10px;
    border-radius: 4px;
    text-align: center;
    cursor: pointer;
}

.net-gain {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.gain-display {
    background-color: #4a5568;
    padding: 10px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.gain-display span {
    background-color: #d69e2e;
    border-radius: 50%;
    padding: 2px 6px;
    color: #1a202c;
    font-size: 12px;
}

.grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-gap: 8px;
    padding: 15px;
    background-color: #2d3748;
    min-width: 0;
    max-width: 100%;
    justify-items: center;
}

.grid div {
    background-color: #4a5568;
    border-radius: 8px;
    aspect-ratio: 1;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    width: 100%;
    max-width: 80px;
}

.grid div img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

.grid .selected {
    border: 2px solid #d69e2e;
}

.grid .revealed-gem,
.grid .revealed-mine {
    background-color: transparent;
}

.home-button {
    position: absolute;
    top: 10px;
    left: 10px;
    padding: 8px 12px;
    background-color: #48bb78;
    color: #1a202c;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    z-index: 1000;
}

/* Mobile responsiveness with grid-on-top layout */
@media (max-width: 768px) {
    body {
        align-items: flex-start;
        padding: 0;
        flex-direction: column;
        justify-content: flex-start;
    }

    .container {
        flex-direction: column;
        width: 100%;
        max-width: 100%;
        height: auto;
        overflow: visible;
        border-radius: 0;
        padding: 0;
    }

    .grid {
        order: 0; /* tiles come first */
        grid-template-columns: repeat(auto-fit, minmax(50px, 1fr));
        grid-gap: 4px;
        padding: 10px;
        width: 100%;
    }

    .sidebar {
        order: 1; /* controls scroll underneath */
        width: 100%;
        padding: 10px;
    }

    header {
        order: 1;
        display: flex;
        justify-content: center;
        padding: 10px 0;
        width: 100%;
    }

    .home-button {
        position: relative;
        top: auto;
        left: auto;
        margin: 10px 0;
        display: inline-block;
    }

    footer {
        position: relative;
        bottom: auto;
        width: 100%;
        padding: 5px;
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .grid {
        grid-template-columns: repeat(auto-fit, minmax(40px, 1fr));
        grid-gap: 3px;
        padding: 5px;
    }

    .sidebar {
        padding: 5px;
    }

    input, select, .display, label {
        font-size: 10px;
        padding: 4px;
    }

    .play-button, .random-pick, .gain-display {
        font-size: 12px;
        padding: 6px;
    }
}