/* Remove external import to prevent blocking */
/* @import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;700;900&display=swap'); */

:root {
    --primary: #6c5ce7;
    --secondary: #a29bfe;
    --dark: #2d3436;
    --light: #dfe6e9;
    --glass: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

* {
    /* Fallback to system fonts for better compatibility */
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    box-sizing: border-box;
    user-select: none;
}

/* Allow text selection in inputs so users can type/edit */
input {
    user-select: text;
}

body {
    margin: 0;
    overflow: hidden;
    background: radial-gradient(circle at center, #2d3436 0%, #000000 100%);
    color: white;
    height: 100vh;
    width: 100vw;
}

#mainDiv {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative; /* Ensure stacking context */
}

/* --- GLASS PANELS --- */
.glass-panel {
    background: var(--glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 90%; /* Prevent overflow on small screens */
}

.modal-container {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    pointer-events: auto; /* Ensure clicks are registered */
}

/* --- BUTTONS & INPUTS --- */
.modern-btn {
    border: none;
    border-radius: 12px;
    padding: 12px 24px;
    font-weight: 900;
    font-size: 1.2rem;
    cursor: pointer;
    transition: transform 0.1s, filter 0.2s;
    color: white;
    box-shadow: 0 4px 0 rgba(0,0,0,0.2);
    margin: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.modern-btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

.green-btn { background: linear-gradient(to bottom, #00b894, #00ca9d); }
.red-btn { background: linear-gradient(to bottom, #d63031, #e17055); }
.blue-btn { background: linear-gradient(to bottom, #0984e3, #74b9ff); }
.orange-btn { background: linear-gradient(to bottom, #e17055, #fab1a0); }
.gray-btn { background: linear-gradient(to bottom, #636e72, #b2bec3); } /* For Exit Button */

.modern-input {
    background: rgba(0,0,0,0.3);
    border: 2px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    padding: 12px;
    color: white;
    font-size: 1.2rem;
    text-align: center;
    width: 100%;
    margin-bottom: 20px;
    outline: none;
}
.modern-input:focus { border-color: #0984e3; }

/* --- MAIN MENU --- */
.main-menu-bg {
    position: absolute; 
    width: 100%; 
    height: 100%;
    /* Replaced external image with CSS gradient to prevent loading errors */
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    display: flex; 
    justify-content: center; 
    align-items: center;
    z-index: 10; /* Ensure it sits on top */
}

.game-title {
    font-size: 4rem;
    background: linear-gradient(to right, #ffeaa7, #fab1a0);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 30px;
    filter: drop-shadow(0 4px 0 rgba(0,0,0,0.5));
    text-align: center;
}

.menu-panel { min-width: 400px; }

/* --- LOBBY --- */
.room-list-panel {
    width: 80%; height: 80%;
    padding: 0;
    align-items: stretch;
}

.panel-header {
    background: rgba(0,0,0,0.2);
    padding: 15px;
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid var(--glass-border);
}

.close-btn {
    background: none; border: none; color: white; font-size: 2rem; cursor: pointer;
}

.room-content {
    display: flex; flex: 1; overflow: hidden;
}

.room-scroll {
    flex: 3;
    overflow-y: auto;
    padding: 20px;
}

.room-sidebar {
    flex: 1;
    background: rgba(0,0,0,0.2);
    padding: 20px;
    display: flex; flex-direction: column;
}

.room-item {
    background: rgba(255,255,255,0.05);
    margin-bottom: 10px;
    padding: 15px;
    border-radius: 10px;
    display: flex; justify-content: space-between; align-items: center;
}

.join-room-btn {
    background: #0984e3; border: none; padding: 5px 15px; color: white; border-radius: 5px; cursor: pointer;
}

/* --- GAME SCREEN --- */

#playersDiv {
    display: flex; justify-content: space-between;
    width: 90%; max-width: 800px;
    margin-bottom: 10px;
}

.playerDiv {
    display: flex; flex-direction: column; align-items: center;
    opacity: 0.5;
    transition: all 0.3s;
    position: relative;
}

.playerDiv.active-turn { opacity: 1; transform: scale(1.1); }

.avatar {
    width: 60px; height: 60px;
    border-radius: 50%;
    background: #ccc;
    border: 3px solid white;
    margin-bottom: 5px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.red .avatar { background: #d63031; }
.blue .avatar { background: #0984e3; }
.green .avatar { background: #00b894; }
.yellow .avatar { background: #fdcb6e; }

.player-name { font-weight: bold; font-size: 0.9rem; text-shadow: 0 2px 4px rgba(0,0,0,0.5); }

.ready-glow .avatar { box-shadow: 0 0 15px #00b894; border-color: #00b894; }

.timer-ring {
    position: absolute;
    top: -5px; right: -5px;
    background: #2d3436;
    width: 24px; height: 24px;
    border-radius: 50%;
    display: flex; justify-content: center; align-items: center;
    font-size: 0.8rem;
    border: 2px solid white;
}

#gameBoard {
    position: relative;
    border-radius: 10px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    background: #fff;
    padding: 5px; /* Border rim */
}

#board {
    border-radius: 5px;
}

/* DICE */
#diceContainer {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 80px; height: 80px;
    z-index: 50;
    pointer-events: none; /* Let clicks pass to button */
    display: flex; justify-content: center; align-items: center;
}

#diceImg {
    width: 60px; height: 60px;
    background-size: cover;
    filter: drop-shadow(0 4px 4px rgba(0,0,0,0.3));
}

.shake {
    animation: shake 0.5s infinite;
}

@keyframes shake {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    10% { transform: translate(-1px, -2px) rotate(-1deg); }
    20% { transform: translate(-3px, 0px) rotate(1deg); }
    30% { transform: translate(3px, 2px) rotate(0deg); }
    40% { transform: translate(1px, -1px) rotate(1deg); }
    50% { transform: translate(-1px, 2px) rotate(-1deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    70% { transform: translate(3px, 1px) rotate(-1deg); }
    80% { transform: translate(-1px, -1px) rotate(1deg); }
    90% { transform: translate(1px, 2px) rotate(0deg); }
    100% { transform: translate(1px, -2px) rotate(-1deg); }
}

#throwDiceButton {
    position: absolute;
    pointer-events: auto;
    width: 100%; height: 100%;
    border-radius: 50%;
    background: rgba(255, 215, 0, 0.2);
    border: 2px solid gold;
    color: transparent;
    cursor: pointer;
    animation: pulse 1s infinite;
}
@keyframes pulse { 0% { transform: scale(1); opacity: 1; } 100% { transform: scale(1.5); opacity: 0; } }

/* MOVES */
.move-hint {
    position: absolute;
    width: 40px; height: 40px;
    border-radius: 50%;
    border: 3px dashed #00b894;
    background: rgba(0, 184, 148, 0.3);
    cursor: pointer;
    z-index: 60;
    animation: spin 3s linear infinite;
}

@keyframes spin { 100% { transform: rotate(360deg); } }

/* EXIT BUTTON STYLING */
#exitBtn {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 2000;
}

/* Responsive */
@media (max-width: 600px) {
    #gameBoard { transform: scale(0.6); }
    .game-title { font-size: 3rem; }
    .room-list-panel { width: 95%; height: 90%; }
    .menu-panel { min-width: 90%; }
}