/* General Setup */
body {
    font-family: Arial, sans-serif;
    background-color: #f0f0f0;
    color: #333;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
}

h1 {
    color: #c0392b;
    text-shadow: 2px 2px #aaa;
}

.hidden {
    display: none !important;
}

/* Lobby */
#lobby-screen {
    background: #fff;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    text-align: center;
    width: 90%;
    max-width: 400px;
}

#lobby-screen h2 {
    margin-top: 0;
}

.lobby-join {
    display: flex;
    margin: 15px 0;
}

#player-name, #lobby-code-input {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

button {
    padding: 10px 15px;
    background-color: #eb5f00;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.2s;
}

button:hover {
    background-color: #183c8b;
}

button:disabled {
    background-color: #95a5a6;
    cursor: not-allowed;
}

.lobby-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.lobby-actions span {
    font-weight: bold;
    color: #7f8c8d;
}

#lobby-message {
    margin-top: 15px;
    color: #eb5f00;
    font-weight: bold;
}

/* Game Screen */
#game-screen {
    width: 100%;
    max-width: 1220px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#game-info {
    width: 100%;
    display: flex;
    justify-content: space-between;
    background: #ecf0f1;
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 20px;
}

#turn-message {
    font-weight: bold;
    color: #2c3e50;
}

/* --- NEW 3D DICE STYLES --- */
#dice-container {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    /* Add perspective to the container */
    perspective: 800px;
    height: 70px; /* Give it space */
    padding-top: 5px;
}

.die-scene {
    width: 60px;
    height: 60px;
    position: relative;
    cursor: pointer;
    transition: all 0.2s ease;
}

/* The 'held' effect is now on the scene wrapper */
.die-scene.held {
    box-shadow: 0 0 10px #1abc9c;
    transform: translateY(-5px);
    border-radius: 6px;
}

.die {
    width: 100%;
    height: 100%;
    position: absolute;
    transform-style: preserve-3d;
    /* Base transform to center it (half of width) */
    transform: translateZ(-30px);
    /* This is the animation for *showing* the face */
    transition: transform 0.6s cubic-bezier(.2, .8, .4, 1.1);
}

.die .face {
    position: absolute;
    width: 60px;
    height: 60px;
    border: 2px solid #333;
    border-radius: 6px;
    background-color: #fff;
    box-sizing: border-box;
    
    /* Pip layout grid (copied from old .die) */
    display: grid;
    grid-template-areas: 
        "top-left . top-right"
        "center-left center center-right"
        "bottom-left . bottom-right";
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
}

/* Held dice faces have a different style */
.die-scene.held .face {
     background-color: #e8f6f3;
     border-color: #1abc9c;
}

.face .pip {
    width: 12px;
    height: 12px;
    background-color: #333;
    border-radius: 50%;
    align-self: center;
    justify-self: center;
    display: none; /* Hide all pips by default */
}

/* --- Position the 6 faces in 3D space --- */
/* (30px is half the width/height) */

/* 1 = Front */
.face-1 { transform: rotateY(0deg) translateZ(30px); }
/* 6 = Back (opposite 1) */
.face-6 { transform: rotateY(180deg) translateZ(30px); }
/* 3 = Right */
.face-3 { transform: rotateY(90deg) translateZ(30px); }
/* 4 = Left (opposite 3) */
.face-4 { transform: rotateY(-90deg) translateZ(30px); }
/* 5 = Top */
.face-5 { transform: rotateX(90deg) translateZ(30px); }
/* 2 = Bottom (opposite 5) */
.face-2 { transform: rotateX(-90deg) translateZ(30px); }


/* --- Pip display rules for each face --- */
/* (This replaces the old .die[data-value] rules) */
.face-1 .pip:nth-child(1) { display: block; grid-area: center; }

.face-2 .pip:nth-child(1) { display: block; grid-area: top-left; }
.face-2 .pip:nth-child(2) { display: block; grid-area: bottom-right; }

.face-3 .pip:nth-child(1) { display: block; grid-area: top-left; }
.face-3 .pip:nth-child(2) { display: block; grid-area: center; }
.face-3 .pip:nth-child(3) { display: block; grid-area: bottom-right; }

.face-4 .pip:nth-child(1) { display: block; grid-area: top-left; }
.face-4 .pip:nth-child(2) { display: block; grid-area: top-right; }
.face-4 .pip:nth-child(3) { display: block; grid-area: bottom-left; }
.face-4 .pip:nth-child(4) { display: block; grid-area: bottom-right; }

.face-5 .pip:nth-child(1) { display: block; grid-area: top-left; }
.face-5 .pip:nth-child(2) { display: block; grid-area: top-right; }
.face-5 .pip:nth-child(3) { display: block; grid-area: center; }
.face-5 .pip:nth-child(4) { display: block; grid-area: bottom-left; }
.face-5 .pip:nth-child(5) { display: block; grid-area: bottom-right; }

.face-6 .pip:nth-child(1) { display: block; grid-area: top-left; }
.face-6 .pip:nth-child(2) { display: block; grid-area: top-right; }
.face-6 .pip:nth-child(3) { display: block; grid-area: center-left; }
.face-6 .pip:nth-child(4) { display: block; grid-area: center-right; }
.face-6 .pip:nth-child(5) { display: block; grid-area: bottom-left; }
.face-6 .pip:nth-child(6) { display: block; grid-area: bottom-right; }

/* --- Show correct face by rotating the cube --- */
/* We add the base translateZ(-30px) to all of them */
.die.show-face-1 { transform: translateZ(-30px) rotateY(0deg); }
.die.show-face-6 { transform: translateZ(-30px) rotateY(180deg); }
.die.show-face-3 { transform: translateZ(-30px) rotateY(-90deg); }
.die.show-face-4 { transform: translateZ(-30px) rotateY(90deg); }
.die.show-face-5 { transform: translateZ(-30px) rotateX(-90deg); }
.die.show-face-2 { transform: translateZ(-30px) rotateX(90deg); }

/* --- THE ROLL ANIMATION --- */
.die.rolling {
    /* Override the smooth transition with a fast animation */
    transition: none;
    animation: roll-animation 0.7s ease-out;
}

@keyframes roll-animation {
    from {
        /* Start from wherever it was and spin fast */
        transform: translateZ(-30px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);
    }
    to {
        /* Do a random-looking tumble */
        /* The final 'show-face' transform will snap in after this animation */
        transform: translateZ(-30px) rotateX(720deg) rotateY(720deg) rotateZ(360deg);
    }
}
/* --- END NEW 3D DICE STYLES --- */


#roll-btn {
    padding: 12px 25px;
    font-size: 18px;
    background-color: #eb5f00;
    min-width: 150px;
}
#roll-btn:hover {
    background-color: #183c8b;
}

/* Scoreboard */
#scoreboard-container {
    width: 100%;
    margin-top: 20px;
    overflow-x: auto; /* For small screens */
}

#scoreboard {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

#scoreboard th, #scoreboard td {
    border: 1px solid #bdc3c7;
    padding: 10px;
    text-align: left;
    min-width: 70px;
}

#scoreboard th {
    background-color: #34495e;
    color: white;
    font-size: 12px;
    text-align: center;
    white-space: nowrap;
}

#scoreboard tr:nth-child(even) {
    background-color: #f9f9f9;
}

#scoreboard tr.header-row th:first-child {
    text-align: left;
    background-color: #2c3e50;
    font-size: 14px;
}

#scoreboard .score-category {
    font-weight: bold;
    font-size: 14px;
}

#scoreboard .total-row {
    font-weight: bold;
    background-color: #ecf0f1;
}
#scoreboard .grand-total {
    background-color: #bdc3c7;
    font-size: 16px;
    font-weight: bold;
}

.score-cell {
    text-align: center;
    font-size: 16px;
}

.score-cell.selectable {
    cursor: pointer;
    color: #eb5f00;
    font-weight: bold;
}
.score-cell.selectable:hover {
    background-color: #f39c12;
}
.score-cell.filled {
    color: #333;
}
.score-cell.potential {
    color: #7f8c8d;
    font-style: italic;
    font-size: 14px;
}

/* Winner Modal */
#winner-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
}
#winner-content {
    background: #fff;
    padding: 40px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}
#play-again-btn {
    margin-top: 20px;
    background-color: #27ae60;
}
#play-again-btn:hover {
    background-color: #2ecc71;
}

/* --- NEW WAITING ROOM STYLES --- */
#waiting-room {
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    text-align: center;
    width: 100%;
    margin-bottom: 20px;
}

#waiting-room h3 {
    margin-top: 0;
}

#player-list {
    list-style-type: none;
    padding: 0;
    margin: 15px 0;
}

#player-list li {
    font-size: 18px;
    padding: 5px;
    background-color: #f9f9f9;
    border-bottom: 1px solid #eee;
}

#player-list li:first-child {
    font-weight: bold;
    color: #eb5f00;
}

#waiting-message {
    font-style: italic;
    color: #7f8c8d;
}

#play-again-btn:hover {
    background-color: #2ecc71;
}

/* --- NEW WAITING ROOM STYLES --- */
/* ... (waiting-room styles) ... */

#waiting-message {
    font-style: italic;
    color: #7f8c8d;
}

/* --- NEW YAHTZEE ANIMATION --- */
#yahtzee-animation {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    /* Clicks go through it */
    pointer-events: none; 
}

#yahtzee-text {
    font-size: 15vw; /* Scales with screen */
    font-weight: bold;
    color: #eb5f00;
    text-shadow: 5px 5px 0px #183c8b, 10px 10px 0px #bdc3c7;
    text-align: center;
    
    /* Animation */
    opacity: 0;
    transform: scale(0.1);
    animation: yahtzee-zoom 2.5s ease-out;
}

#yahtzee-text span {
    display: block;
    font-size: 2vw;
    color: #333;
    text-shadow: none;
    margin-top: 10px;
    font-weight: normal;
    font-style: italic;
}

@keyframes yahtzee-zoom {
    0% {
        opacity: 0;
        transform: scale(0.1) rotate(-30deg);
    }
    20% {
        opacity: 1;
        transform: scale(1.2) rotate(10deg);
    }
    40% {
        transform: scale(1) rotate(0deg);
    }
    80% {
        opacity: 1;
        transform: scale(1);
    }
    100% {
        opacity: 0;
        transform: scale(1.5);
    }
}