:root {
    --tile-size: 40px;
    --border-width: 5px;
}

body {
    font-family: sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #333;
    color: #fff;
    margin: 0;
    padding: 10px 0;
}

h1 {
    font-size: 2.5em;
}

#game-container {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
}

#game-board {
    display: grid;
    grid-template-columns: repeat(12, var(--tile-size));
    grid-template-rows: repeat(12, var(--tile-size));
    border: var(--border-width) solid #fff;
    overflow: hidden; /* This is important for the animation */
}

.tile {
    width: var(--tile-size);
    height: var(--tile-size);
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: calc(var(--tile-size) * 0.6);
    position: relative;
    transition: transform 0.3s ease-in-out;
}

.player {
    font-size: calc(var(--tile-size) * 0.7);
}

.player.selected::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 255, 0, 0.3);
}

.artifact {
    font-size: calc(var(--tile-size) * 0.7);
    cursor: pointer;
}

.sidebar {
    width: 200px;
    padding: 20px;
    background-color: #444;
    border: var(--border-width) solid #fff;
    text-align: center;
    box-sizing: border-box;
}

#player1-sidebar {
    margin-right: 20px;
}

#player2-sidebar {
    margin-left: 20px;
}

#player1-artifacts, #player2-artifacts {
    list-style-type: none;
    padding: 0;
}

#player1-artifacts li, #player2-artifacts li {
    font-size: 24px;
    margin-bottom: 10px;
}

#spare-tile-container {
    margin-top: 20px;
    text-align: center;
}

#spare-tile-controls {
    display: inline-flex;
    align-items: center;
}

#spare-tile {
    border: var(--border-width) solid #fff;
    cursor: pointer;
}

#spare-tile.selected::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 255, 0, 0.3);
}

#rotate-ccw, #rotate-cw, #skip-turn {
    font-size: 24px;
    margin: 0 10px;
    cursor: pointer;
    background: none;
    border: none;
    color: #fff;
}

.player.player-1 {
    background-color: rgba(255, 255, 0, 0.5);
}

.player.player-2 {
    background-color: rgba(128, 0, 128, 0.5);
}

#turn-indicator {
    position: fixed;
    bottom: 10px;
    right: 10px;
    padding: 10px;
    background-color: #444;
    border: var(--border-width) solid #fff;
}

#game-state-display {
    position: fixed;
    bottom: 10px;
    left: 10px;
    padding: 10px;
    background-color: #444;
    border: var(--border-width) solid #fff;
}

#skip-turn:disabled {
    color: #777;
    cursor: not-allowed;
}

#victory-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 20, 0, 0.85);
    padding: 40px;
    text-align: center;
    font-size: 48px;
    width: 80%;
}

#play-again {
    background: none;
    border: none;
    color: #fff;
    font-size: 36px;
    cursor: pointer;
    margin-top: 20px;
}

#rules-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

#rules-content {
    background-color: #222;
    padding: 30px;
    border-radius: 10px;
    max-width: 500px;
    width: 90%;
    text-align: left;
    box-sizing: border-box;
}

#rules-content h2 {
    text-align: center;
    margin-top: 0;
}

#rules-content ol {
    padding-left: 20px;
}

#close-rules {
    display: block;
    margin: 20px auto 0;
    padding: 10px 20px;
    background-color: #444;
    border: none;
    color: #fff;
    cursor: pointer;
}

#rules-link {
    position: fixed;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    text-decoration: none;
    font-size: 24px;
}

#skip-turn {
    margin-top: 20px;
}


/* Wall styles */
.wall-top { border-top: var(--border-width) solid #fff; }
.wall-right { border-right: var(--border-width) solid #fff; }
.wall-bottom { border-bottom: var(--border-width) solid #fff; }
.wall-left { border-left: var(--border-width) solid #fff; }

/* Animation for shifting tiles */
.tile.shifting-up { transform: translateY(calc(-1 * var(--tile-size))); }
.tile.shifting-down { transform: translateY(var(--tile-size)); }
.tile.shifting-left { transform: translateX(calc(-1 * var(--tile-size))); }
.tile.shifting-right { transform: translateX(var(--tile-size)); }

/* Animation for the new tile appearing */
.tile.new-tile {
    transform: scale(0);
    animation: new-tile-animation 0.3s ease-in-out forwards;
}

@keyframes new-tile-animation {
    from { transform: scale(0); }
    to { transform: scale(1); }
}

/* Animation for the old tile disappearing */
.tile.old-tile {
    transform: scale(1);
    animation: old-tile-animation 0.3s ease-in-out forwards;
}

@keyframes old-tile-animation {
    from { transform: scale(1); }
    to { transform: scale(0); }
}

/* Animation for player movement */
.player.moving {
    transition: top 0.5s, left 0.5s;
}

/* Responsive Design */
@media (max-width: 800px) {
    :root {
        --tile-size: min(7vw, 40px);
        --border-width: 3px;
    }

    h1 {
        font-size: 1.8em;
    }

    #game-container {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    #game-board {
        order: 1;
        margin-bottom: 10px;
    }

    #player1-sidebar {
        order: 2;
        width: 48%;
        margin: 0 1% 0 0;
    }

    #player2-sidebar {
        order: 3;
        width: 48%;
        margin: 0 0 0 1%;
    }

    #player1-artifacts, #player2-artifacts {
        display: flex;
        flex-wrap: wrap;
        gap: 5px;
        justify-content: center;
    }

    #player1-artifacts li, #player2-artifacts li {
        font-size: 20px;
        margin-bottom: 0;
    }

    #spare-tile-container {
        order: 4; /* Spare tile below everything */
        margin-top: 10px;
    }

    #skip-turn {
        order: 5;
    }

    #victory-message {
        font-size: 24px;
        padding: 20px;
    }

    #play-again {
        font-size: 20px;
    }

    #rules-link {
        position: fixed;
        top: 10px;
        right: 10px;
        bottom: auto;
        left: auto;
        transform: none;
        font-size: 14px;
        padding: 5px;
    }

    #turn-indicator, #game-state-display {
        font-size: 14px;
        padding: 5px;
    }

    #game-state-display {
        bottom: 10px;
        top: auto;
        left: 10px;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.2em;
    }

    .sidebar {
        flex-direction: column;
    }

    .sidebar h2 {
        margin-bottom: 10px;
        font-size: 1em;
    }

    #player1-artifacts li, #player2-artifacts li {
        font-size: 18px;
    }

    #rotate-ccw, #rotate-cw, #skip-turn {
        font-size: 20px;
    }

    #rules-link {
        font-size: 12px;
        padding: 3px;
        top: 5px;
        right: 5px;
    }

    #turn-indicator, #game-state-display {
        font-size: 12px;
    }
}
