@import url("https://fonts.googleapis.com/css2?family=Fredoka+One&family=Nunito:wght@400;600;700;900&display=swap");

:root {
    --red: #e74c3c;
    --red-dark: #c0392b;
    --red-light: #f1948a;
    --blue: #2980b9;
    --blue-dark: #1a5276;
    --blue-light: #7fb3d3;
    --green: #27ae60;
    --green-dark: #1e8449;
    --green-light: #82e0aa;
    --yellow: #f39c12;
    --yellow-dark: #d68910;
    --yellow-light: #f8c471;
    --board-bg: #fdf6e3;
    --center: #ecf0f1;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body {
    height: 100vh;
    overflow: hidden;
    background: radial-gradient(
        ellipse at 20% 20%,
        #1a1a2e 0%,
        #16213e 40%,
        #0f3460 100%
    );
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    font-family: "Nunito", sans-serif;
    padding: 5px;
}
h1 {
    font-family: "Fredoka One", cursive;
    font-size: clamp(1.2rem, 4vw, 2.5rem);
    color: #fff;
    text-shadow:
        0 0 20px rgba(255, 200, 50, 0.6),
        2px 2px 0 #c0392b;
    letter-spacing: 1px;
    margin: 2px 0;
    text-align: center;
}
#game-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly;
    width: 100%;
    height: 100%;
    max-width: 1000px;
}
#board-scene {
    perspective: 1000px;
    perspective-origin: 50% 30%;
    width: min(95vw, 42vh, 600px);
}
.hub-btn {
    display: inline-block;
    margin-top: 18px;
    padding: 10px 24px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 30px;
    color: #fff;
    text-decoration: none;
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 1px;
    transition: all 0.2s;
    cursor: pointer;
}
#board-container {
    position: relative;
    transform: rotateX(15deg) rotateZ(0deg);
    transform-style: preserve-3d;
    transition: transform 0.5s ease;
    filter: drop-shadow(0 10px 15px rgba(0, 0, 0, 0.6));
}
#board-container:hover {
    transform: rotateX(10deg) rotateZ(0deg);
}
#board {
    width: min(95vw, 42vh, 600px);
    height: min(95vw, 42vh, 600px);
    display: grid;
    grid-template-columns: repeat(15, 1fr);
    grid-template-rows: repeat(15, 1fr);
    border: 3px solid #2c3e50;
    border-radius: 8px;
    position: relative;
    background: var(--board-bg);
    box-shadow:
        0 4px 0 #1a252f,
        0 6px 10px rgba(0, 0, 0, 0.5);
}
.cell {
    width: 100%;
    height: 100%;
    border: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: default;
}
.zone-red {
    background: var(--red) !important;
}
.zone-blue {
    background: var(--blue) !important;
}
.zone-green {
    background: var(--green) !important;
}
.zone-yellow {
    background: var(--yellow) !important;
}
.zone-white {
    background: #fff;
}
.zone-center {
    background: linear-gradient(
        135deg,
        var(--red),
        var(--blue),
        var(--green),
        var(--yellow)
    );
}
.safe::after {
    content: "★";
    font-size: clamp(8px, 2vw, 16px);
    color: rgba(0, 0, 0, 0.25);
    pointer-events: none;
}
.path-red {
    background: var(--red-light) !important;
}
.path-blue {
    background: var(--blue-light) !important;
}
.path-green {
    background: var(--green-light) !important;
}
.path-yellow {
    background: var(--yellow-light) !important;
}
.piece {
    border-radius: 50%;
    position: absolute;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    color: #fff;
    transition:
        transform 0.25s,
        box-shadow 0.25s,
        top 0.2s,
        left 0.2s;
    z-index: 10;
    user-select: none;
    border: 1px solid rgba(255, 255, 255, 0.6);
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);
}
.piece::after {
    content: "";
    position: absolute;
    bottom: -10%;
    left: 50%;
    transform: translateX(-50%);
    width: 70%;
    height: 20%;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 50%;
    filter: blur(1px);
}
.piece-red {
    background: radial-gradient(
        circle at 35% 30%,
        var(--red-light),
        var(--red-dark)
    );
    box-shadow:
        0 2px 0 #8b1a1a,
        0 3px 5px rgba(231, 76, 60, 0.5);
}
.piece-blue {
    background: radial-gradient(
        circle at 35% 30%,
        var(--blue-light),
        var(--blue-dark)
    );
    box-shadow:
        0 2px 0 #0e3460,
        0 3px 5px rgba(41, 128, 185, 0.5);
}
.piece-green {
    background: radial-gradient(
        circle at 35% 30%,
        var(--green-light),
        var(--green-dark)
    );
    box-shadow:
        0 2px 0 #0e5a2e,
        0 3px 5px rgba(39, 174, 96, 0.5);
}
.piece-yellow {
    background: radial-gradient(
        circle at 35% 30%,
        var(--yellow-light),
        var(--yellow-dark)
    );
    box-shadow:
        0 2px 0 #7d5000,
        0 3px 5px rgba(243, 156, 18, 0.5);
}

.piece.selectable {
    animation: bounce 0.5s infinite alternate;
    cursor: pointer !important;
}
.piece.selected {
    transform: scale(1.3) translateY(-4px) !important;
    z-index: 20;
}
@keyframes bounce {
    from {
        transform: translateY(0) scale(1);
    }
    to {
        transform: translateY(-3px) scale(1.08);
    }
}
#side-panel {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
    width: 100%;
    max-width: min(95vw, 500px);
    justify-content: center;
}
#dice-section {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-areas: "dice btn" "dice status";
    gap: 4px 10px;
    align-items: center;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 6px 10px;
    backdrop-filter: blur(6px);
    width: 100%;
    order: -1;
}
#dice-face {
    grid-area: dice;
    width: 45px;
    height: 45px;
    background: linear-gradient(135deg, #fff 0%, #e8e8e8 100%);
    border-radius: 8px;
    margin: 0;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    padding: 4px;
    gap: 2px;
    box-shadow:
        0 2px 0 #aaa,
        0 3px 5px rgba(0, 0, 0, 0.4);
    transition: transform 0.1s;
}
#dice-face.rolling {
    animation: diceRoll 0.5s ease;
}
@keyframes diceRoll {
    0% {
        transform: rotateX(0) rotateY(0) scale(1);
    }
    25% {
        transform: rotateX(180deg) rotateY(90deg) scale(0.8);
    }
    50% {
        transform: rotateX(360deg) rotateY(180deg) scale(1.1);
    }
    75% {
        transform: rotateX(180deg) rotateY(270deg) scale(0.9);
    }
    100% {
        transform: rotateX(0) rotateY(360deg) scale(1);
    }
}
.dot-pip {
    width: 8px;
    height: 8px;
    background: #2c3e50;
    border-radius: 50%;
    margin: auto;
    box-shadow:
        inset 0 1px 2px rgba(255, 255, 255, 0.3),
        0 1px 1px rgba(0, 0, 0, 0.3);
}
.dot-pip.hidden {
    visibility: hidden;
}
#roll-btn {
    grid-area: btn;
    width: 100%;
    padding: 6px;
    font-family: "Fredoka One", cursive;
    font-size: 0.9rem;
    background: linear-gradient(135deg, #f39c12, #e74c3c);
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    box-shadow:
        0 2px 0 #7d2e00,
        0 3px 5px rgba(0, 0, 0, 0.3);
}
#roll-btn:active {
    transform: translateY(2px);
    box-shadow: 0 0px 0 #7d2e00;
}
#roll-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
#status-msg {
    grid-area: status;
    color: gold;
    font-size: 0.7rem;
    font-weight: 700;
    margin: 0;
    text-align: center;
}
.player-card {
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 4px 6px;
    backdrop-filter: blur(6px);
    flex: 1 1 45%;
    transition:
        border-color 0.3s,
        background 0.3s;
}
.player-card.active {
    border-color: gold;
    background: rgba(255, 215, 0, 0.12);
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.3);
}
.player-card .player-name {
    font-family: "Fredoka One", cursive;
    font-size: 0.75rem;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 4px;
}
.player-card .player-name .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.dot-red {
    background: var(--red);
}
.dot-blue {
    background: var(--blue);
}
.dot-green {
    background: var(--green);
}
.dot-yellow {
    background: var(--yellow);
}
.player-status {
    font-size: 0.6rem;
    color: #aaa;
    margin-top: 1px;
}
.player-score {
    font-size: 0.65rem;
    color: gold;
    font-weight: 700;
}
#toggle-3d {
    position: absolute;
    top: 5px;
    right: 5px;
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    font-family: "Nunito", sans-serif;
    font-size: 0.65rem;
    backdrop-filter: blur(4px);
    z-index: 50;
}
#setup-overlay,
#win-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 100;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}
#setup-overlay.show,
#win-overlay.show {
    display: flex;
}
#setup-box,
#win-box {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    border: 3px solid gold;
    border-radius: 20px;
    padding: 30px 40px;
    text-align: center;
    box-shadow: 0 0 40px rgba(255, 215, 0, 0.4);
    width: 90%;
    max-width: 400px;
}
#setup-box h2,
#win-box h2 {
    font-family: "Fredoka One", cursive;
    font-size: 2rem;
    color: gold;
    margin-bottom: 20px;
}
#win-box h2 {
    margin-bottom: 8px;
}
#win-box p {
    color: #eee;
    font-size: 1rem;
    margin-bottom: 20px;
}
.player-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.player-options button {
    padding: 10px;
    font-family: "Fredoka One", cursive;
    font-size: 1.1rem;
    background: linear-gradient(135deg, #2980b9, #1a5276);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 0 #0e3460;
}
.player-options button:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #0e3460;
}

#new-game-btn {
    padding: 10px 25px;
    font-family: "Fredoka One", cursive;
    font-size: 1rem;
    background: linear-gradient(135deg, #f39c12, #e74c3c);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 0 #7d2e00;
}
@media (min-width: 769px) {
    #game-wrapper {
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
        gap: 30px;
    }
    #board-scene {
        width: 500px;
    }
    #board {
        width: 500px;
        height: 500px;
    }
    #side-panel {
        width: 250px;
        flex-direction: column;
    }
    .player-card {
        flex: 1 1 100%;
        padding: 12px;
    }
    .player-card .player-name {
        font-size: 1rem;
    }
    .player-status {
        font-size: 0.8rem;
    }
    .player-score {
        font-size: 0.85rem;
    }
    #dice-section {
        display: flex;
        flex-direction: column;
        padding: 20px;
    }
    #dice-face {
        width: 80px;
        height: 80px;
        padding: 10px;
        margin: 0 auto 15px;
    }
    .dot-pip {
        width: 14px;
        height: 14px;
    }
    #roll-btn {
        font-size: 1.2rem;
        padding: 12px;
    }
    #status-msg {
        font-size: 0.85rem;
        margin-top: 10px;
    }
}
