/* Chess Common Styles */
:root {
    --board-border: #5d4037;
    --white-square: #f0d9b5;
    --black-square: #b58863;
    --highlight-move: rgba(106, 255, 106, 0.6);
    --highlight-capture: rgba(255, 87, 87, 0.6);
    --highlight-selected: rgba(255, 255, 0, 0.5);
    --primary-color: #2c3e50;
    --accent-color: #f1c40f;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--primary-color);
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0;
    padding: 10px;
    /* Small padding */
    min-height: 100vh;
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-y: auto;
}

/* Header Elements */
h1 {
    margin: 50px 0 10px 0;
    /* Huge margin for Back Button */
    font-size: clamp(1.5rem, 5vw, 2.5rem);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    text-align: center;
    line-height: 1.2;
}

.level-instruction {
    font-size: clamp(0.9rem, 4vw, 1.2rem);
    color: #ecf0f1;
    margin-bottom: 15px;
    text-align: center;
    max-width: 600px;
    padding: 0 10px;
    line-height: 1.4;
}

.game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 100%;
    margin-bottom: 20px;
}

/* Board Container */
.board-container {
    position: relative;
    padding: 8px;
    /* Slightly smaller padding for mobile */
    background: var(--board-border);
    border-radius: 4px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

#board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);

    /* VITAL: Responsive sizing logic */
    width: min(90vw, 450px);
    height: min(90vw, 450px);

    background-color: var(--white-square);
}

/* Squares */
.square {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    cursor: pointer;
    font-size: clamp(20px, 8vw, 40px);
    /* Adjust piece size */
    user-select: none;
}

.white-square {
    background-color: var(--white-square);
}

.black-square {
    background-color: var(--black-square);
}

/* Pieces */
.piece {
    z-index: 2;
    transition: transform 0.2s ease-out;
}

.white-piece {
    color: #fff;
    text-shadow: 0 0 2px #000, 0 2px 4px rgba(0, 0, 0, 0.4);
}

.black-piece {
    color: #000;
    text-shadow: 0 0 1px #fff;
}

/* Collectibles / Obstacles */
.star {
    font-size: 0.6em;
    color: #f1c40f;
    text-shadow: 0 0 5px orange;
    animation: pulse 1.5s infinite;
}

.rock {
    font-size: 0.7em;
    color: #7f8c8d;
    filter: drop-shadow(2px 2px 0px #34495e);
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

/* Highlights */
.highlight::after {
    content: '';
    position: absolute;
    width: 30%;
    height: 30%;
    background-color: rgba(0, 128, 0, 0.5);
    border-radius: 50%;
}

.capture {
    background-color: var(--highlight-capture) !important;
    box-shadow: inset 0 0 10px red;
}

.selected {
    background-color: var(--highlight-selected) !important;
}

.danger {
    background-color: rgba(231, 76, 60, 0.4) !important;
    box-shadow: inset 0 0 10px rgba(192, 57, 43, 0.5);
}

/* Controls */
.controls {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
}

.btn {
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: bold;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    background-color: var(--accent-color);
    color: #2c3e50;
    transition: transform 0.1s;
    box-shadow: 0 4px 0 #d35400;
    touch-action: manipulation;
    /* Touch optimization */
}

.btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #d35400;
}

.btn-home {
    background-color: #95a5a6;
    color: white;
    box-shadow: 0 4px 0 #7f8c8d;
}

/* BACK BUTTON - SUPER VISIBLE */
.back-btn {
    position: fixed;
    top: 15px;
    left: 15px;
    text-decoration: none;
    color: #2c3e50;
    font-weight: bold;
    font-size: 1.8rem;

    /* High Visibility Colors */
    background: #f1c40f;
    /* Bright Yellow */
    border: 2px solid #2c3e50;
    /* Dark Border */

    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;

    /* Ensure it overlays everything */
    z-index: 10000 !important;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);

    transition: transform 0.2s;
}

.back-btn:active {
    transform: scale(0.9);
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 20px;
    box-sizing: border-box;
}

.modal {
    background: white;
    color: #2c3e50;
    padding: 25px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.5);
    border: 5px solid var(--accent-color);
    width: 100%;
    max-width: 350px;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from {
        transform: scale(0.5);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Media Queries for Desktop */
@media (min-width: 768px) {
    #board {
        width: min(65vh, 500px);
        height: min(65vh, 500px);
    }
}