/* CSS Reset & Variable Definitions */
:root {
    --red: #f44336;
    --green: #4caf50;
    --yellow: #ffeb3b;
    --blue: #2196f3;
    --dark-bg: #1a1a1a;
    --panel-bg: #2d2d2d;
    --text: #ffffff;

    /* Responsive sizing variables */
    --board-max-size: 600px;
    --board-size: min(95vw, var(--board-max-size), 85vh);
    --cell-size: calc(var(--board-size) / 15);
    --home-size: calc(var(--cell-size) * 6);
    --center-size: calc(var(--cell-size) * 3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: #000;
    color: var(--text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    padding: 20px;
}

#space-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.4)), url('space_bg.png');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    overflow: hidden;
}

.nebula {
    position: absolute;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(138, 43, 226, 0.15) 0%, rgba(138, 43, 226, 0) 70%);
    filter: blur(80px);
    border-radius: 50%;
    pointer-events: none;
    z-index: 1;
}

.star {
    position: absolute;
    background: #fff;
    border-radius: 50%;
    opacity: 0.5;
    pointer-events: none;
    z-index: 2;
}

.star.twinkle {
    animation: twinkling var(--duration) infinite ease-in-out;
}

@keyframes twinkling {

    0%,
    100% {
        opacity: 0.3;
        transform: scale(1);
    }

    50% {
        opacity: 1;
        transform: scale(1.2);
    }
}

.shooting-star {
    position: absolute;
    left: 50%;
    top: 50%;
    height: 2px;
    background: linear-gradient(-45deg, rgba(95, 145, 255, 1), rgba(0, 0, 255, 0));
    border-radius: 999px;
    filter: drop-shadow(0 0 6px rgba(105, 155, 255, 1));
    animation: tail 3000ms ease-in-out infinite, shooting 3000ms ease-in-out infinite;
    pointer-events: none;
    z-index: 3;
}

@keyframes tail {
    0% {
        width: 0;
    }

    30% {
        width: 100px;
    }

    100% {
        width: 0;
    }
}

@keyframes shooting {
    0% {
        transform: translateX(0) translateY(0) rotate(215deg);
    }

    100% {
        transform: translateX(-500px) translateY(500px) rotate(215deg);
    }
}

.game-wrapper {
    display: flex;
    gap: 40px;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
}

/* SIDE PANELS */
.side-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    z-index: 100;
}

.player-zone {
    background: rgba(45, 45, 45, 0.4);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    padding: 15px;
    border-radius: 20px;
    width: 200px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-align: center;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.player-zone.active {
    border-color: rgba(255, 255, 255, 0.6);
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.3);
    transform: scale(1.05) translateY(-5px);
    background: rgba(45, 45, 45, 0.6);
    animation: pulseActive 2s infinite alternate;
}

@keyframes pulseActive {
    0% {
        box-shadow: 0 0 15px rgba(255, 255, 255, 0.2);
    }

    100% {
        box-shadow: 0 0 35px rgba(255, 255, 255, 0.5);
    }
}

.player-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.avatar {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: #444;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.9rem;
}

.zone-red .avatar {
    background: var(--red);
}

.zone-green .avatar {
    background: var(--green);
}

.zone-yellow .avatar {
    background: var(--yellow);
}

.zone-blue .avatar {
    background: var(--blue);
}

.ludo-board {
    width: var(--board-size);
    height: var(--board-size);
    background: #fff;
    border: calc(var(--board-size) / 60) solid #fff;
    border-radius: 10px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    display: grid;
    grid-template-columns: var(--home-size) var(--center-size) var(--home-size);
    grid-template-rows: var(--home-size) var(--center-size) var(--home-size);
    flex-shrink: 0;
}

.home-zone {
    width: 100%;
    height: 100%;
    padding: calc(var(--home-size) / 8);
}

.zone-red {
    background: var(--red);
}

.zone-green {
    background: var(--green);
}

.zone-yellow {
    background: var(--yellow);
}

.zone-blue {
    background: var(--blue);
}

/* FIX: Pieces in nest arranged in a square, not a line */
.piece-nest {
    background: #fff;
    width: 100%;
    height: 100%;
    border-radius: 15px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
    place-items: center;
    padding: 20px;
}

/* PATH ARMS */
.path-area {
    display: grid;
}

/* PATH ARMS */
.path-area.vertical {
    grid-template-columns: repeat(3, var(--cell-size));
    grid-template-rows: repeat(6, var(--cell-size));
}

.path-area.horizontal {
    grid-template-columns: repeat(6, var(--cell-size));
    grid-template-rows: repeat(3, var(--cell-size));
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    border: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    flex-wrap: wrap;
    align-content: center;
    justify-content: center;
    position: relative;
    box-sizing: border-box;
    gap: 1px;
}

/* Home Tracks */
.red-track {
    background: #ffcccc;
}

.green-track {
    background: #ccffcc;
}

.yellow-track {
    background: #ffffcc;
}

.blue-track {
    background: #ccccff;
}

/* Safe Points */
.cell.safe::after {
    content: "★";
    position: absolute;
    font-size: calc(var(--cell-size) * 0.45);
    color: rgba(0, 0, 0, 0.2);
    pointer-events: none;
}

/* CENTER TRIANGLES */
.center-square {
    position: relative;
    background: #fff;
    width: var(--center-size);
    height: var(--center-size);
}

.triangle {
    position: absolute;
    width: var(--center-size);
    height: var(--center-size);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: filter 0.3s ease;
}

.triangle:hover {
    filter: brightness(1.1);
}

.triangle.red {
    clip-path: polygon(0% 0%, 50% 50%, 0% 100%);
    background: var(--red);
    justify-content: flex-start;
    padding-left: 15px;
}

.triangle.green {
    clip-path: polygon(0% 0%, 100% 0%, 50% 50%);
    background: var(--green);
    align-items: flex-start;
    padding-top: 15px;
}

.triangle.yellow {
    clip-path: polygon(100% 0%, 100% 100%, 50% 50%);
    background: var(--yellow);
    justify-content: flex-end;
    padding-right: 15px;
}

.triangle.blue {
    clip-path: polygon(0% 100%, 100% 100%, 50% 50%);
    background: var(--blue);
    align-items: flex-end;
    padding-bottom: 15px;
}

/* PIECES */
.piece {
    width: calc(var(--cell-size) * 0.7);
    height: calc(var(--cell-size) * 0.7);
    border-radius: 50%;
    border: calc(var(--cell-size) * 0.07) solid rgba(255, 255, 255, 0.7);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    z-index: 10;
    position: relative;
}

.cell:has(.piece + .piece) .piece {
    width: calc(var(--cell-size) * 0.45);
    height: calc(var(--cell-size) * 0.45);
}

.cell:has(.piece + .piece + .piece) .piece {
    width: calc(var(--cell-size) * 0.35);
    height: calc(var(--cell-size) * 0.35);
}

.piece.red {
    background: var(--red);
}

.piece.green {
    background: var(--green);
}

.piece.yellow {
    background: var(--yellow);
}

.piece.blue {
    background: var(--blue);
}

.piece.movable {
    animation: bounce 0.6s infinite alternate;
    box-shadow: 0 0 15px #fff;
    z-index: 20;
}

@keyframes bounce {
    from {
        transform: scale(1);
    }

    to {
        transform: scale(1.3);
    }
}

/* DICE 3D - FIXING FACES WITH GRID */
.dice-container {
    --dice-size: 50px;
    width: var(--dice-size);
    height: var(--dice-size);
    perspective: 1000px;
    margin: 0 auto;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.player-zone.active .dice-container:hover {
    transform: scale(1.15);
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.5));
}

.dice {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
}

.face {
    position: absolute;
    width: var(--dice-size);
    height: var(--dice-size);
    background: #fff;
    border: 2px solid #ddd;
    border-radius: 8px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    padding: 3px;
    place-items: center;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.1);
}

.pip {
    width: calc(var(--dice-size) * 0.16);
    height: calc(var(--dice-size) * 0.16);
    background: #333;
    border-radius: 50%;
}

/* Pip Positioning Logic */
.face[data-value="1"] .pip:nth-child(1) {
    grid-area: 2 / 2;
}

.face[data-value="2"] .pip:nth-child(1) {
    grid-area: 1 / 1;
}

.face[data-value="2"] .pip:nth-child(2) {
    grid-area: 3 / 3;
}

.face[data-value="3"] .pip:nth-child(1) {
    grid-area: 1 / 1;
}

.face[data-value="3"] .pip:nth-child(2) {
    grid-area: 2 / 2;
}

.face[data-value="3"] .pip:nth-child(3) {
    grid-area: 3 / 3;
}

.face[data-value="4"] .pip:nth-child(1) {
    grid-area: 1 / 1;
}

.face[data-value="4"] .pip:nth-child(2) {
    grid-area: 1 / 3;
}

.face[data-value="4"] .pip:nth-child(3) {
    grid-area: 3 / 1;
}

.face[data-value="4"] .pip:nth-child(4) {
    grid-area: 3 / 3;
}

.face[data-value="5"] .pip:nth-child(1) {
    grid-area: 1 / 1;
}

.face[data-value="5"] .pip:nth-child(2) {
    grid-area: 1 / 3;
}

.face[data-value="5"] .pip:nth-child(3) {
    grid-area: 2 / 2;
}

.face[data-value="5"] .pip:nth-child(4) {
    grid-area: 3 / 1;
}

.face[data-value="5"] .pip:nth-child(5) {
    grid-area: 3 / 3;
}

.face[data-value="6"] .pip:nth-child(1) {
    grid-area: 1 / 1;
}

.face[data-value="6"] .pip:nth-child(2) {
    grid-area: 1 / 3;
}

.face[data-value="6"] .pip:nth-child(3) {
    grid-area: 2 / 1;
}

.face[data-value="6"] .pip:nth-child(4) {
    grid-area: 2 / 3;
}

.face[data-value="6"] .pip:nth-child(5) {
    grid-area: 3 / 1;
}

.face[data-value="6"] .pip:nth-child(6) {
    grid-area: 3 / 3;
}

.dice-front {
    transform: translateZ(calc(var(--dice-size) / 2));
}

.dice-back {
    transform: rotateY(180deg) translateZ(calc(var(--dice-size) / 2));
}

.dice-top {
    transform: rotateX(90deg) translateZ(calc(var(--dice-size) / 2));
}

.dice-bottom {
    transform: rotateX(-90deg) translateZ(calc(var(--dice-size) / 2));
}

.dice-left {
    transform: rotateY(-90deg) translateZ(calc(var(--dice-size) / 2));
}

.dice-right {
    transform: rotateY(90deg) translateZ(calc(var(--dice-size) / 2));
}

/* MEDIA QUERIES FOR RESPONSIVENESS */
@media (max-width: 1100px) {
    .game-wrapper {
        flex-direction: column;
        gap: 20px;
        padding-top: 10px;
        padding-bottom: 20px;
    }

    .side-panel {
        flex-direction: row;
        width: 100%;
        justify-content: space-around;
        gap: 15px;
    }

    .player-zone {
        width: calc(var(--board-size) / 2 - 10px);
        max-width: 250px;
    }

    /* Red/Blue on top (first panel), Board middle, Green/Yellow on bottom (last panel) */
    .side-panel:first-child {
        order: 1;
    }

    .ludo-board {
        order: 2;
    }

    .side-panel:last-child {
        order: 3;
    }
}

@media (max-width: 500px) {
    .game-wrapper {
        gap: 15px;
    }

    .player-zone {
        padding: 10px;
    }

    .player-header {
        margin-bottom: 8px;
    }

    .avatar {
        width: 30px;
        height: 30px;
        font-size: 0.8rem;
    }

    .dice-container {
        --dice-size: 40px;
    }
}

@media (max-height: 700px) and (min-width: 1101px) {
    :root {
        --board-max-size: 500px;
    }
}