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

/* Reset & Basic Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none; /* Prevent text selection for game feel */
}

body {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    font-family: 'Roboto', sans-serif;
    overflow: hidden; /* Prevent global scroll */
    width: 100vw;     /* Ensure full viewport width */
    height: 100vh;    /* Ensure full viewport height */
    position: relative; /* Contain absolute children like ::before */
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
}

/* Background Pattern */
body::before {
    content: "";
    position: absolute;
    width: 200%;
    height: 200%;
    background-image: 
        radial-gradient(#ffffff 2px, transparent 2px),
        radial-gradient(#ffffff 2px, transparent 2px);
    background-size: 50px 50px;
    background-position: 0 0, 25px 25px;
    opacity: 0.1;
    animation: moveBackground 60s linear infinite;
    z-index: -1;
}

@keyframes moveBackground {
    0% { transform: translate(0, 0); }
    100% { transform: translate(-50px, -50px); }
}



#screen-menu {
    flex-direction: column;
    justify-content: flex-start;
    padding-top: 0;
}

.menu-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: flex-start; /* Align to top */
    padding: 10px; /* Some padding for positioning */
    height: 0; /* Collapse height so content moves up */
    margin-bottom: 0;
    overflow: visible; /* Let buttons spill out */
    z-index: 100; /* Keep buttons on top */
    position: relative;
}

.header-item {
    display: flex;
    align-items: center;
}

/* Profile and Coin Bar Component Reuse */
.icon-wrapper {
    z-index: 2;
    width: 60px;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle, #ecf0f1 0%, #bdc3c7 100%);
    border-radius: 50%;
    border: 3px solid white;
    box-shadow: 0 3px 6px rgba(0,0,0,0.3);
}

.coin-wrapper {
    background: radial-gradient(circle, #f1c40f 0%, #f39c12 100%);
    border-color: #d35400;
}

.icon-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.text-bar-bg {
    background: rgba(44, 62, 80, 0.9);
    border: 2px solid #bdc3c7;
    border-radius: 0 20px 20px 0;
    border-left: none;
    padding: 5px 20px 5px 35px; /* Space for overlap */
    margin-left: -25px; /* Overlap */
    height: 40px;
    display: flex;
    align-items: center;
    z-index: 1;
    color: white;
    font-family: 'Fredoka One', cursive;
    font-size: 1.1rem;
    min-width: 120px;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.5);
}

.coin-display-static .text-bar-bg {
    border-color: #f39c12;
}

.icon-btn-static {
    width: 60px;
    height: 60px;
    cursor: pointer;
    transition: transform 0.2s;
    filter: drop-shadow(0 4px 4px rgba(0,0,0,0.5));
}

.icon-btn-static:hover {
    transform: scale(1.1);
}

/* Scrollable Content Area */
.menu-content-scrollable {
    flex: 1;
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    padding-bottom: 20px;
}

/* Placeholders */
.placeholder-box {
    background: rgba(255,255,255,0.2);
    border: 2px dashed rgba(255,255,255,0.5);
    border-radius: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-family: 'Fredoka One', cursive;
    font-size: 1.5rem;
    text-transform: uppercase;
}

.menu-logo-container {
    width: 100%;
    height: 140px;
    margin-bottom: 5px;
    margin-top: 10px; /* Small gap from absolute top */
}

.logo-box {
    width: 100%;
    height: 100%;
    background: transparent;
    display: flex;
    justify-content: center;
    align-items: center;
    border: none; /* Remove dashed border */
}

.logo-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.3));
}

.menu-shop-container {
    width: 100%;
    height: 110px;
    margin-bottom: 20px;
}

.shop-box {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #f1c40f 0%, #f39c12 100%);
    border-radius: 15px;
    border: 2px solid rgba(255,255,255,0.3);
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    padding: 0;
}

.shop-banner-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Grid System */
.menu-grid-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.menu-grid-row {
    display: flex;
    gap: 15px;
    width: 100%;
    /* height: 120px; */
}

.menu-grid-item {
    flex: 1;
    aspect-ratio: 1 / 1;
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    border-radius: 15px;
    border: 2px solid rgba(255,255,255,0.3);
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
    padding: 0;
}

.menu-card-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 75%;
    object-fit: cover;
    z-index: 1;
    margin: 0;
    border-bottom: none;
    display: block;
    background-color: #ffffff; /* Fix for transparent PNGs */
}

.menu-grid-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.4);
    filter: brightness(1.1);
}

.grid-content {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 25%;
    font-family: 'Fredoka One', cursive;
    font-size: 1.1rem;
    color: white;
    text-align: center;
    z-index: 2;
    text-shadow: 2px 2px 0 rgba(0,0,0,0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0,0,0,0.1);
}

/* Selection Screens */
.selection-row {
    display: flex;
    gap: 20px;
    margin: 30px 0;
    width: 100%;
    justify-content: center;
}

.big-selection-btn {
    flex: 1;
    height: 200px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 10px;
    background: linear-gradient(135deg, #9b59b6 0%, #8e44ad 100%);
    font-size: 1.5rem !important;
}

.big-selection-btn span {
    font-size: 1.8rem;
    white-space: nowrap;
}

.big-selection-btn small {
    font-size: 1rem;
    opacity: 0.8;
    font-family: 'Roboto', sans-serif;
    font-weight: normal;
}

.big-selection-btn:hover {
    transform: scale(1.05);
}

/* Scrollbar hidden for menu */
.menu-content-scrollable::-webkit-scrollbar {
    width: 0px;
    background: transparent;
}

/* Screen Container */
.screen {
    display: none;
    width: 100%;
    height: 100%;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 0;
    left: 0;
}

.screen.active {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

h1 {
    font-family: 'Fredoka One', cursive;
    font-size: 4rem;
    margin-bottom: 2rem;
    color: #ffcc00;
    text-shadow: 
        3px 3px 0px #e67e22,
        6px 6px 0px #c0392b,
        9px 9px 0px rgba(0,0,0,0.2);
    letter-spacing: 2px;
    transform: rotate(-2deg);
}

.menu-container {
    background: rgba(255, 255, 255, 0.1);
    padding: 3rem;
    border-radius: 20px;
    box-shadow: 
        0 10px 30px rgba(0,0,0,0.5),
        inset 0 0 0 2px rgba(255,255,255,0.2);
    text-align: center;
    min-width: 400px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.1);
}

/* Game Inputs */
input[type="text"] {
    width: 100%;
    padding: 15px;
    margin: 15px 0;
    border-radius: 50px;
    border: 3px solid #3498db;
    background: rgba(0, 0, 0, 0.3);
    color: white;
    font-size: 1.5rem;
    font-family: 'Fredoka One', cursive;
    text-align: center;
    outline: none;
    transition: all 0.3s;
}

input[type="text"]:focus {
    border-color: #2ecc71;
    background: rgba(0, 0, 0, 0.5);
    transform: scale(1.05);
}

input[type="text"]::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

/* Game Buttons */
button {
    width: 100%;
    padding: 15px;
    margin: 10px 0;
    background: linear-gradient(to bottom, #e74c3c, #c0392b);
    color: white;
    border: none;
    border-radius: 50px;
    font-size: 1.5rem;
    font-family: 'Fredoka One', cursive;
    cursor: pointer;
    transition: all 0.1s;
    box-shadow: 
        0 5px 0 #96281b,
        0 10px 10px rgba(0,0,0,0.3);
    text-transform: uppercase;
    position: relative;
    top: 0;
}

button:hover {
    background: linear-gradient(to bottom, #ff6b6b, #ee5253);
    transform: translateY(-2px);
    box-shadow: 
        0 7px 0 #96281b,
        0 15px 15px rgba(0,0,0,0.3);
}

button:active {
    transform: translateY(5px);
    box-shadow: 
        0 0 0 #96281b,
        0 0 0 rgba(0,0,0,0.3);
}

button:disabled {
    background: #7f8c8d;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
    opacity: 0.7;
}

button:disabled:hover {
    background: #7f8c8d;
    transform: none;
    box-shadow: none;
}

button.secondary {
    background: linear-gradient(to bottom, #3498db, #2980b9);
    box-shadow: 
        0 5px 0 #1a5276,
        0 10px 10px rgba(0,0,0,0.3);
}

button.secondary:hover {
    background: linear-gradient(to bottom, #5dade2, #3498db);
    box-shadow: 
        0 7px 0 #1a5276,
        0 15px 15px rgba(0,0,0,0.3);
}

button.secondary:active {
    box-shadow: 0 0 0 #1a5276;
}

/* Icon Buttons (Custom Images) */
.icon-button {
    position: absolute;
    width: 60px;
    height: 60px;
    background-color: transparent;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    border: none;
    border-radius: 0;
    box-shadow: none;
    cursor: pointer;
    z-index: 100;
    transition: transform 0.2s;
    padding: 0; /* Reset padding */
    margin: 0; /* Reset margin */
    top: auto; /* Reset top */
}

.icon-button:hover, .icon-button:active, .icon-button:focus {
    transform: none !important;
    filter: none !important;
    background-color: transparent !important;
    background-image: url('assets/buttons/botao_configuracao.png') !important;
    box-shadow: none !important;
    border: none !important;
    outline: none !important;
}

#btn-game-config {
    top: 15px;
    right: 15px; /* Positioned at the top-right corner */
    background-image: url('assets/buttons/botao_configuracao.png');
    /* Fallback if image missing */
    background-color: rgba(255,255,255,0.2); 
    border-radius: 50%;
}

/* Settings Controls */
.control-group {
    margin: 20px 0;
    text-align: left;
    background: rgba(0,0,0,0.2);
    padding: 15px;
    border-radius: 15px;
}

.control-group label {
    display: block;
    margin-bottom: 10px;
    font-family: 'Fredoka One', cursive;
    font-size: 1.2rem;
    color: #f1c40f;
}

input[type="range"] {
    width: 100%;
    height: 10px;
    border-radius: 5px;
    background: #2c3e50;
    outline: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 25px;
    height: 25px;
    border-radius: 50%;
    background: #f1c40f;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
}

/* Custom Dropdown (Select Replacement) */
.custom-select {
    position: relative;
    width: 100%;
    font-family: 'Fredoka One', cursive;
}

.select-selected {
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid #3498db;
    border-radius: 10px;
    padding: 10px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    user-select: none;
}

/* Arrow indicator */
.select-selected::after {
    content: "";
    position: absolute;
    right: 15px;
    border: 6px solid transparent;
    border-color: #fff transparent transparent transparent;
    top: 50%;
    transform: translateY(-25%);
}

.select-selected.select-arrow-active::after {
    border-color: transparent transparent #fff transparent;
    transform: translateY(-75%);
}

.select-items {
    position: absolute;
    background-color: #2c3e50;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 99;
    border-radius: 10px;
    margin-top: 5px;
    max-height: 300px;
    overflow-y: auto;
    border: 2px solid #3498db;
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);
}

.select-hide {
    display: none;
}

.select-items div {
    padding: 10px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    transition: background 0.2s;
}

.select-items div:last-child {
    border-bottom: none;
}

.select-items div:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

.select-selected img, .select-items img {
    width: 25px;
    height: auto;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* Scrollbar for dropdown */
.select-items::-webkit-scrollbar {
    width: 8px;
}
.select-items::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.2);
    border-radius: 0 10px 10px 0;
}
.select-items::-webkit-scrollbar-thumb {
    background: #3498db;
    border-radius: 4px;
}

/* Game Board Area */
#game-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: transparent;
}

#ludo-board {
    background: white;
    border-radius: 10px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    max-width: 95vh;
    max-height: 95vh;
}

/* Game UI Overlay */
#game-ui {
    background: rgba(0, 0, 0, 0.6) !important;
    border-radius: 15px;
    border: 2px solid rgba(255,255,255,0.1);
    backdrop-filter: blur(5px);
}

#turn-indicator {
    font-family: 'Fredoka One', cursive;
    font-size: 1.5rem;
    margin-bottom: 10px;
    text-align: center;
    color: #fff;
    text-shadow: 2px 2px 0 #000;
}

/* Player Avatars & Chat */
.player-avatar {
    position: absolute;
    width: 120px; /* Fixed width */
    height: 220px; /* Fixed height to prevent fluttering when dice appear */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start; /* Ensure content aligns to top */
    z-index: 20;
}

.avatar-wrapper {
    position: relative;
    width: 60px;
    height: 60px;
    margin-bottom: 5px;
}

.avatar-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    border: 3px solid white;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    background-color: #ddd;
}

/* Avatar Icons Container (Flag + Chat) */
.avatar-icons {
    display: flex;
    gap: 8px;
    margin-top: 5px;
    justify-content: center;
    align-items: center;
}

.avatar-flag {
    position: static; /* Removed absolute positioning */
    transform: none; /* Removed transform */
    width: 25px;
    height: 25px;
    border-radius: 50%;
    border: 2px solid white;
    object-fit: cover;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
    z-index: 25;
}

.avatar-name {
    background: rgba(0,0,0,0.6);
    padding: 3px 8px;
    border-radius: 10px;
    font-size: 0.9rem;
    text-shadow: 1px 1px 2px black;
    white-space: nowrap;
}

/* Winner Slots (Progress Bar) */
.winner-slots {
    display: flex;
    gap: 5px;
    margin-top: 5px;
    background: rgba(0,0,0,0.5);
    padding: 3px 6px;
    border-radius: 10px;
}

.winner-slots .slot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: rgba(255,255,255,0.3);
    border: 1px solid rgba(255,255,255,0.5);
    transition: all 0.3s ease;
}

/* Filled States (to be applied via JS) */
.winner-slots .slot.filled {
    box-shadow: 0 0 5px currentColor;
    border-color: white;
}
/* Specific player colors for filled slots will be handled by dynamic classes or inline styles */


/* Chat Button */
.player-chat-btn {
    position: static; /* Removed absolute positioning */
    transform: none;
    width: 25px;
    height: 25px;
    background-color: #2ecc71;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
    z-index: 30;
    font-size: 14px;
    border: 2px solid #fff;
    user-select: none;
}

.player-chat-btn:hover {
    transform: scale(1.1);
    background-color: #27ae60;
}

/* New Message Notification Styles */
@keyframes pulse-green {
    0% {
        box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.7);
        transform: scale(1);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(46, 204, 113, 0);
        transform: scale(1.1);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(46, 204, 113, 0);
        transform: scale(1);
    }
}

.player-chat-btn.has-new-message {
    animation: pulse-green 1.5s infinite;
    background-color: #2ecc71;
    position: relative; /* Ensure ::after is positioned relative to button */
}

.player-chat-btn.has-new-message::after {
    content: '!';
    position: absolute;
    top: -5px;
    right: -5px;
    width: 14px;
    height: 14px;
    background-color: #e74c3c;
    color: white;
    font-size: 10px;
    font-weight: bold;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 2px solid white;
    z-index: 35;
}

/* Hide chat button for self */
.player-avatar.is-me .player-chat-btn {
    display: none !important;
}

/* Coin Display UI */
#coin-display {
    position: absolute;
    top: 20px;
    right: 85px; /* Positioned to the left of the config button (which is at right: 15px + width 60px) */
    display: flex;
    align-items: center;
    z-index: 90;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.3));
}

.coin-icon-wrapper {
    z-index: 2;
    width: 50px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle, #f1c40f 0%, #f39c12 100%);
    border-radius: 50%;
    border: 2px solid #d35400;
}

.coin-icon-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 50%;
}

.coin-amount-bg {
    background: #2c3e50;
    border: 2px solid #f39c12;
    border-radius: 0 20px 20px 0; /* Rounded right side */
    border-left: none; /* Merge with coin */
    padding: 5px 15px 5px 25px; /* Extra left padding for overlap */
    margin-left: -20px; /* Overlap with coin */
    height: 36px;
    display: flex;
    align-items: center;
    z-index: 1;
    color: white;
    font-family: 'Fredoka One', cursive;
    font-size: 1.2rem;
    min-width: 100px;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.5);
}

/* Screen Results Modal */
#screen-results {
    background: rgba(0, 0, 0, 0.9);
    z-index: 3000; /* Ensure it is above everything, including trophies */
}

/* Results Modal Styles */
.results-container {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    border-radius: 20px;
    padding: 30px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    color: white;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    border: 3px solid #f1c40f;
    position: relative;
    overflow: hidden;
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 3001;
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

.results-container h1 {
    font-family: 'Fredoka One', cursive;
    color: #f1c40f;
    font-size: 2.5rem;
    margin-bottom: 20px;
    text-shadow: 2px 2px 0 #d35400;
}

.winner-profile {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 30px;
}

.winner-avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 4px solid #f1c40f;
    background-color: #ecf0f1;
    background-size: cover;
    background-position: center;
    margin-bottom: 10px;
    box-shadow: 0 0 20px rgba(241, 196, 15, 0.5);
}

.winner-profile h2 {
    font-size: 1.5rem;
    margin: 0;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 30px;
    background: rgba(0,0,0,0.2);
    padding: 15px;
    border-radius: 10px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.stat-label {
    font-size: 0.8rem;
    color: #bdc3c7;
    text-transform: uppercase;
}

.stat-value {
    font-size: 1.2rem;
    font-weight: bold;
    color: #ecf0f1;
}

.results-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.results-actions button {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    border: none;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s;
}

.results-actions button:hover {
    transform: translateY(-2px);
}

.results-actions .primary-btn {
    background: #2ecc71;
    color: white;
    box-shadow: 0 4px 0 #27ae60;
}

.results-actions .secondary-btn {
    background: #e74c3c;
    color: white;
    box-shadow: 0 4px 0 #c0392b;
}

/* Bottom Toolbar */
#bottom-toolbar {
    position: absolute;
    bottom: 5px; /* Moved lower as requested */
    left: 50%;
    transform: translateX(-50%) translateY(0);
    display: flex;
    gap: 15px;
    z-index: 100;
    transition: all 0.3s ease;
}

.toolbar-icon {
    width: 50px;
    height: 50px;
    background: rgba(44, 62, 80, 0.8);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    cursor: pointer;
    border: 2px solid rgba(255,255,255,0.3);
    color: white;
    opacity: 0.6;
    transform: translateY(15px); /* Start lower */
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    backdrop-filter: blur(5px);
    user-select: none;
}

.toolbar-icon:hover {
    opacity: 1;
    transform: translateY(-10px) scale(1.1); /* Move up on hover */
    background: rgba(44, 62, 80, 0.95);
    border-color: #3498db;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.toolbar-icon.active {
    background: #e74c3c;
    border-color: #c0392b;
    opacity: 1;
}

/* General Chat Sidebar */
.chat-sidebar {
    position: fixed;
    top: 0;
    left: -350px; /* Hidden by default */
    width: 320px;
    height: 100%;
    background: rgba(44, 62, 80, 0.85); /* Slightly more transparent */
    z-index: 1500;
    display: flex;
    flex-direction: column;
    border-right: 2px solid #3498db;
    box-shadow: 5px 0 15px rgba(0,0,0,0.5);
    backdrop-filter: blur(10px);
    transition: left 0.3s ease;
}

.chat-sidebar.open {
    left: 0;
}

/* Message Colors */
.msg-color-red { color: #e74c3c !important; }
.msg-color-green { color: #2ecc71 !important; }
.msg-color-yellow { color: #f1c40f !important; }
.msg-color-blue { color: #3498db !important; }

.chat-message-name {
    font-size: 0.8rem;
    color: #bdc3c7;
    margin-bottom: 2px;
    font-weight: bold;
}

.chat-message-text {
    font-size: 1rem;
    font-weight: normal;
    word-wrap: break-word;
    color: white; /* Default fallback */
}

/* Chat Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(3px);
}

.chat-window {
    width: 400px;
    max-width: 90%;
    height: 500px;
    max-height: 80vh;
    background: rgba(44, 62, 80, 0.95);
    border-radius: 15px;
    border: 2px solid #3498db;
    display: flex;
    flex-direction: column;
    box-shadow: 0 15px 30px rgba(0,0,0,0.5);
    overflow: hidden;
}

.chat-header {
    padding: 15px;
    background: #34495e;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: 'Fredoka One', cursive;
    border-bottom: 2px solid #2980b9;
}

.chat-header button {
    width: 30px;
    height: 30px;
    padding: 0;
    margin: 0;
    border-radius: 50%;
    background: #e74c3c;
    font-size: 14px;
    line-height: 30px;
    box-shadow: none;
    top: 0;
}

.chat-header button:hover {
    transform: scale(1.1);
}

.chat-history {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Scrollbar for chat */
.chat-history::-webkit-scrollbar {
    width: 8px;
}
.chat-history::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.1);
}
.chat-history::-webkit-scrollbar-thumb {
    background: #3498db;
    border-radius: 4px;
}

.chat-message {
    padding: 10px 15px;
    border-radius: 15px;
    max-width: 80%;
    word-wrap: break-word;
    font-size: 0.95rem;
    line-height: 1.4;
}

.chat-message.received {
    background: #ecf0f1;
    color: #2c3e50;
    align-self: flex-start;
    border-bottom-left-radius: 0;
}

.chat-message.sent {
    background: #3498db;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 0;
}

.chat-input-wrapper {
    padding: 15px;
    background: rgba(0,0,0,0.2);
    display: flex;
    gap: 10px;
    align-items: center;
}

.chat-input-wrapper input {
    flex: 1;
    margin: 0;
    text-align: left;
    padding: 12px 15px;
    font-size: 1rem;
    border-radius: 25px;
}

.chat-input-wrapper button {
    width: auto;
    padding: 0 20px;
    height: 48px;
    margin: 0;
    font-size: 1rem;
    border-radius: 25px;
}

/* Avatar Colors based on position/player */
#p1-avatar .avatar-img { border-color: #e74c3c; } /* Red */
#p2-avatar .avatar-img { border-color: #2ecc71; } /* Green */
#p3-avatar .avatar-img { border-color: #f1c40f; } /* Yellow */
#p4-avatar .avatar-img { border-color: #3498db; } /* Blue */

.player-avatar.disabled {
    opacity: 0.3;
    pointer-events: none;
    filter: grayscale(100%);
}

/* Room List Styles */
.room-list-scrollable {
    width: 100%;
    height: 300px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 10px;
    margin-bottom: 20px;
    overflow-y: auto;
    border: 2px solid rgba(255, 255, 255, 0.1);
    padding: 10px;
}

.room-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    margin-bottom: 10px;
    padding: 15px;
    border-radius: 8px;
    transition: all 0.2s;
}

.room-item:hover {
    background: rgba(255, 255, 255, 0.2);
}

.room-info {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.room-name {
    font-size: 1.2rem;
    font-weight: bold;
    color: #f1c40f;
}

.room-details {
    font-size: 0.9rem;
    color: #bdc3c7;
}

.room-status {
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 0.8rem;
    font-weight: bold;
    text-transform: uppercase;
}

.status-open {
    background: #2ecc71;
    color: #fff;
}

.status-playing {
    background: #e74c3c;
    color: #fff;
}

.btn-join-room {
    width: auto;
    padding: 8px 20px;
    font-size: 1rem;
    margin: 0;
    background: linear-gradient(to bottom, #3498db, #2980b9);
}

.btn-join-room:disabled {
    background: #7f8c8d;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.room-item-placeholder {
    text-align: center;
    padding: 20px;
    color: rgba(255, 255, 255, 0.5);
    font-style: italic;
}

/* Lobby Player Grid - Horizontal Slots */
.lobby-slots-container {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-top: 40px;
    flex-wrap: wrap;
    padding: 20px;
}

.lobby-slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 120px;
    transition: transform 0.2s;
    position: relative;
}

.lobby-slot.clickable {
    cursor: pointer;
}

.lobby-slot.clickable:hover {
    transform: scale(1.05);
}

.lobby-slot-circle {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 4px solid rgba(255, 255, 255, 0.1); /* Default fallback */
    background-color: rgba(0, 0, 0, 0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.3);
}

/* Color Themes for Slots */
.lobby-slot-circle.red { border-color: rgba(231, 76, 60, 0.3); }
.lobby-slot-circle.green { border-color: rgba(46, 204, 113, 0.3); }
.lobby-slot-circle.yellow { border-color: rgba(241, 196, 15, 0.3); }
.lobby-slot-circle.blue { border-color: rgba(52, 152, 219, 0.3); }

/* Occupied State */
.lobby-slot.occupied .lobby-slot-circle {
    background-color: transparent;
    border-width: 5px;
    box-shadow: 0 0 15px rgba(0,0,0,0.5);
}

.lobby-slot-circle.occupied.red { border-color: #e74c3c; box-shadow: 0 0 20px rgba(231, 76, 60, 0.4); }
.lobby-slot-circle.occupied.green { border-color: #2ecc71; box-shadow: 0 0 20px rgba(46, 204, 113, 0.4); }
.lobby-slot-circle.occupied.yellow { border-color: #f1c40f; box-shadow: 0 0 20px rgba(241, 196, 15, 0.4); }
.lobby-slot-circle.occupied.blue { border-color: #3498db; box-shadow: 0 0 20px rgba(52, 152, 219, 0.4); }

/* Avatar inside slot */
.lobby-slot-avatar {
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    border-radius: 50%;
}

/* Name and Label */
.lobby-slot-name {
    margin-top: 15px;
    font-weight: bold;
    color: #fff;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
    font-size: 1.1rem;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.lobby-slot-label {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 5px;
    text-transform: uppercase;
}


/* Turn Timer SVG Overlay */
.turn-timer-svg {
    position: absolute;
    top: -5px;
    left: -5px;
    width: 70px;
    height: 70px;
    z-index: 20;
    pointer-events: none;
    transform: rotate(-90deg); /* Start from top */
}

/* 3D Shaking Dice */
.dice-container-3d {
    position: absolute;
    width: 60px;
    height: 60px;
    perspective: 600px;
    z-index: 100;
    cursor: pointer;
    /* Default position, will be overridden by specific classes */
    top: 5px;
    left: 110px; /* Increased from 80px */
}

/* Positioning based on avatar location */
.dice-pos-left {
    left: auto;
    right: 110px; /* Increased from 80px */
}
.dice-pos-right {
    left: 110px; /* Increased from 80px */
}

.dice-3d {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transform: rotateX(-30deg) rotateY(-45deg);
}

.dice-3d.shaking {
    animation: shakeDice 0.5s infinite;
}

/* Rolling Animation to Center */
.dice-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7); /* Darker background */
    z-index: 2147483647; /* Max Z-Index */
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: all; /* Block clicks */
}

.dice-center-scaler {
    transform: scale(3.0); /* Even Bigger */
    transform-style: preserve-3d;
    width: 60px;
    height: 60px;
    position: relative;
    pointer-events: none;
}

/* Reuse standard dice classes inside the scaler */
.dice-center-scaler .dice-container-3d {
    position: relative; /* Changed from static to relative */
    top: auto;
    left: auto;
    margin: 0;
    perspective: 600px;
    transform-style: preserve-3d; /* Ensure 3D is preserved */
}

.dice-3d.rolling {
    animation: rollToResult 1s ease-out forwards; /* Slightly longer */
}

/* Ensure faces are solid and visible */
.dice-face {
    backface-visibility: hidden; /* Hide backfaces */
    -webkit-backface-visibility: hidden;
    background-color: #ffffff !important; /* Force white background */
}


@keyframes rollToResult {
    0% { transform: rotateX(0) rotateY(0) rotateZ(0); }
    100% { transform: rotateX(720deg) rotateY(720deg) rotateZ(360deg); }
}

@keyframes shakeDice {
    0% { transform: rotateX(-30deg) rotateY(-45deg) translate3d(0,0,0); }
    25% { transform: rotateX(-20deg) rotateY(-55deg) translate3d(2px, -2px, 0); }
    50% { transform: rotateX(-40deg) rotateY(-35deg) translate3d(-2px, 2px, 0); }
    75% { transform: rotateX(-25deg) rotateY(-50deg) translate3d(2px, 2px, 0); }
    100% { transform: rotateX(-30deg) rotateY(-45deg) translate3d(0,0,0); }
}

.dice-face {
    position: absolute;
    width: 60px;
    height: 60px;
    background: white;
    border: 2px solid #bdc3c7;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
    font-size: 24px;
    font-weight: bold;
    color: #2c3e50;
}

.small-result-dice {
    width: 30px;
    height: 30px;
    background: white;
    border: 2px solid #bdc3c7;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Fredoka One', cursive;
    font-size: 18px;
    color: #2c3e50;
    box-shadow: 0 3px 6px rgba(0,0,0,0.3);
    z-index: 50;
    margin-top: 5px;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from { transform: scale(0); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
.dice-face.one { 
    transform: rotateY(0deg) translateZ(30px); 
    background: radial-gradient(circle at center, #2c3e50 5px, transparent 6px) white;
}
.dice-face.six { 
    transform: rotateY(180deg) translateZ(30px); 
    background: 
        radial-gradient(circle at 13px 13px, #2c3e50 5px, transparent 6px),
        radial-gradient(circle at 13px 28px, #2c3e50 5px, transparent 6px),
        radial-gradient(circle at 13px 43px, #2c3e50 5px, transparent 6px),
        radial-gradient(circle at 43px 13px, #2c3e50 5px, transparent 6px),
        radial-gradient(circle at 43px 28px, #2c3e50 5px, transparent 6px),
        radial-gradient(circle at 43px 43px, #2c3e50 5px, transparent 6px) white;
}
.dice-face.three { 
    transform: rotateY(90deg) translateZ(30px); 
    background: 
        radial-gradient(circle at 13px 13px, #2c3e50 5px, transparent 6px),
        radial-gradient(circle at 28px 28px, #2c3e50 5px, transparent 6px),
        radial-gradient(circle at 43px 43px, #2c3e50 5px, transparent 6px) white;
}
.dice-face.four { 
    transform: rotateY(-90deg) translateZ(30px); 
    background: 
        radial-gradient(circle at 13px 13px, #2c3e50 5px, transparent 6px),
        radial-gradient(circle at 13px 43px, #2c3e50 5px, transparent 6px),
        radial-gradient(circle at 43px 13px, #2c3e50 5px, transparent 6px),
        radial-gradient(circle at 43px 43px, #2c3e50 5px, transparent 6px) white;
}
.dice-face.five { 
    transform: rotateX(90deg) translateZ(30px); 
    background: 
        radial-gradient(circle at 13px 13px, #2c3e50 5px, transparent 6px),
        radial-gradient(circle at 13px 43px, #2c3e50 5px, transparent 6px),
        radial-gradient(circle at 28px 28px, #2c3e50 5px, transparent 6px),
        radial-gradient(circle at 43px 13px, #2c3e50 5px, transparent 6px),
        radial-gradient(circle at 43px 43px, #2c3e50 5px, transparent 6px) white;
}
.dice-face.two { 
    transform: rotateX(-90deg) translateZ(30px); 
    background: 
        radial-gradient(circle at 13px 13px, #2c3e50 5px, transparent 6px),
        radial-gradient(circle at 43px 43px, #2c3e50 5px, transparent 6px) white;
}

/* Dice Result List (Horizontal Container) */
.dice-result-list {
    display: flex;
    flex-direction: row;
    gap: 6px; /* Increased gap for larger dice */
    margin-top: 5px;
    justify-content: center;
    /* background: rgba(0, 0, 0, 0.4); REMOVED background as requested */
    padding: 2px;
    border-radius: 6px;
    z-index: 50;
    pointer-events: none; /* Let clicks pass through if needed */
}

/* Small Result Dice Container */
.small-result-dice {
    width: 30px; /* Increased from 20px to fit dots (8, 15, 22px coords) */
    height: 30px; /* Increased from 20px */
    position: relative;
    box-shadow: 0 2px 4px rgba(0,0,0,0.5);
    border-radius: 6px; /* Slightly more rounded */
    /* Prevent shrinking in flex container */
    flex-shrink: 0;
    pointer-events: auto; /* Enable clicks specifically on dice */
    transition: transform 0.1s ease, filter 0.1s ease; /* Smooth interaction */
}

.small-result-dice.selected-dice {
    transform: scale(0.9) translateY(2px) !important;
    filter: brightness(0.8) !important;
    border: 2px solid #fff !important;
}

/* Small Result Dice Faces */
.small-result-dice .dice-face {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 4px;
    background-color: white;
    /* Reset 3D transforms */
    transform: none !important; 
    border: 1px solid #ccc;
}

/* Hide all faces by default in small dice, only show the active one */
.small-result-dice .dice-face {
    display: none;
}

/* We will manually append ONLY the correct face, or toggle display */
/* Actually, a better approach for 2D is to just have one div and apply the background class */
/* But the background classes (.one, .two) rely on radial-gradient which is fine */
/* They also have transform properties which we disabled above */

/* Specific face overrides for 2D */
.small-dice-face {
    width: 100%;
    height: 100%;
    background-color: white !important;
    border-radius: 4px;
    box-sizing: border-box;
    z-index: 60;
    position: relative; /* Ensure z-index works */
}

/* Ensure no other content leaks in */
.small-dice-face::before, .small-dice-face::after {
    content: none;
}

.small-dice-face.face-one {
    background-image: radial-gradient(circle at center, #2c3e50 3px, transparent 4px);
}

.small-dice-face.face-two {
    background-image: 
        radial-gradient(circle at 8px 8px, #2c3e50 3px, transparent 4px),
        radial-gradient(circle at 22px 22px, #2c3e50 3px, transparent 4px);
}

.small-dice-face.face-three {
    background-image: 
        radial-gradient(circle at 8px 8px, #2c3e50 3px, transparent 4px),
        radial-gradient(circle at 15px 15px, #2c3e50 3px, transparent 4px),
        radial-gradient(circle at 22px 22px, #2c3e50 3px, transparent 4px);
}

.small-dice-face.face-four {
    background-image: 
        radial-gradient(circle at 8px 8px, #2c3e50 3px, transparent 4px),
        radial-gradient(circle at 8px 22px, #2c3e50 3px, transparent 4px),
        radial-gradient(circle at 22px 8px, #2c3e50 3px, transparent 4px),
        radial-gradient(circle at 22px 22px, #2c3e50 3px, transparent 4px);
}

.small-dice-face.face-five {
    background-image: 
        radial-gradient(circle at 8px 8px, #2c3e50 3px, transparent 4px),
        radial-gradient(circle at 8px 22px, #2c3e50 3px, transparent 4px),
        radial-gradient(circle at 15px 15px, #2c3e50 3px, transparent 4px),
        radial-gradient(circle at 22px 8px, #2c3e50 3px, transparent 4px),
        radial-gradient(circle at 22px 22px, #2c3e50 3px, transparent 4px);
}

.small-dice-face.face-six {
    background-image: 
        radial-gradient(circle at 8px 8px, #2c3e50 3px, transparent 4px),
        radial-gradient(circle at 8px 15px, #2c3e50 3px, transparent 4px),
        radial-gradient(circle at 8px 22px, #2c3e50 3px, transparent 4px),
        radial-gradient(circle at 22px 8px, #2c3e50 3px, transparent 4px),
        radial-gradient(circle at 22px 15px, #2c3e50 3px, transparent 4px),
        radial-gradient(circle at 22px 22px, #2c3e50 3px, transparent 4px);
}

/* =========================================
   RESPONSIVE ADJUSTMENTS (LOGIN SCREEN ONLY)
   ========================================= */
/* 
   Strategy: We use the ID #screen-nickname to ensure these styles 
   ONLY affect the first screen. Other screens remain untouched.
*/
@media screen and (max-width: 768px) {
    
    /* Lock the screen container to prevent any scrolling */
    #screen-nickname {
        position: fixed;
        width: 100%;
        height: 100%;
        overflow: hidden;
        /* display: flex;  <-- REMOVED: Let the global .screen class handle display:none/flex toggling */
        justify-content: center;
        align-items: center;
    }
    
    /* Ensure it's visible only when active (fixing the 'stuck' issue) */
    #screen-nickname.active {
        display: flex;
    }

    /* Adjust the inner container width and spacing */
    #screen-nickname .menu-container {
        width: 90%;          /* Take 90% of screen width */
        max-width: 400px;    /* But never more than 400px */
        min-width: unset;    /* Override the global min-width */
        padding: 20px;       /* Smaller padding for mobile */
        margin: 0;           /* Center it */
        box-sizing: border-box; /* Include padding in width calculation */
    }

    /* Resize text for mobile */
    #screen-nickname h1 {
        font-size: 2.2rem;   /* Smaller title */
        margin-bottom: 20px;
        line-height: 1.1;
        word-wrap: break-word; /* Prevent text overflow */
        transform: none;       /* Remove rotation to save horizontal space */
        letter-spacing: 0;     /* Reduce spacing */
        width: 100%;           /* Ensure it stays within container */
    }

    /* Resize inputs and buttons */
    #screen-nickname input[type="text"],
    #screen-nickname button {
        font-size: 1.1rem;
        padding: 10px;
        width: 100%;
        margin: 10px 0;        /* Consistent vertical spacing */
        box-sizing: border-box; /* Prevent padding from causing overflow */
    }
}

/* =========================================
   RESPONSIVE ADJUSTMENTS (MAIN MENU SCREEN)
   ========================================= */
@media screen and (max-width: 768px) {
    #screen-menu {
        overflow-x: hidden;
        width: 100%;
        height: 100%;
        position: fixed; /* Lock screen */
    }

    /* Header adjustments */
    #screen-menu .menu-header {
        height: 50px;
        padding: 0 5px;
        margin-bottom: 0px;
    }

    /* Scale down profile/coin icons */
    #screen-menu .icon-wrapper {
        width: 40px;
        height: 40px;
        border-width: 2px;
    }

    #screen-menu .text-bar-bg {
        height: 28px;
        font-size: 0.8rem;
        padding: 5px 15px 5px 25px; /* Adjust overlap padding */
        margin-left: -18px;
        min-width: 70px;
    }

    #screen-menu .icon-btn-static {
        width: 40px;
        height: 40px;
    }

    /* Scrollable content container */
    #screen-menu .menu-content-scrollable {
        width: 95%;
        max-width: none;
        padding-bottom: 60px; /* Space for bottom scroll */
    }

    /* Logo Box */
    #screen-menu .menu-logo-container {
        width: 100%;
        height: 90px;
        margin-bottom: 0px;
    }
    
    #screen-menu .logo-box {
        height: 90px; /* Smaller logo area */
        font-size: 1.2rem;
    }

    /* Shop Box */
    #screen-menu .menu-shop-container {
        width: 100%;
        height: 80px;
        margin-bottom: 20px; /* Space between shop and grid */
    }

    #screen-menu .shop-box {
        height: 80px;
        font-size: 1.2rem;
    }

    /* Grid Container */
    #screen-menu .menu-grid-container {
        width: 100%;
        gap: 10px;
    }

    #screen-menu .menu-grid-row {
        gap: 10px;
    }

    /* REMOVED fixed height to maintain square aspect ratio from global styles */
    /* #screen-menu .menu-grid-item {
        height: 80px; 
    } */
    
    #screen-menu .grid-content {
        font-size: 1rem;
    }
}

/* =========================================
   RESPONSIVE ADJUSTMENTS (SELECT MODE SCREEN)
   ========================================= */
@media screen and (max-width: 768px) {
    /* Use specific ID to isolate changes */
    #screen-team-select .menu-container {
        width: 90%;
        max-width: 400px;
        min-width: unset;
        padding: 20px;
        box-sizing: border-box;
    }

    #screen-team-select h1 {
        font-size: 2.2rem;
        margin-bottom: 20px;
        transform: none;
        letter-spacing: 0;
    }

    #screen-team-select .selection-row {
        flex-direction: column; /* Stack buttons vertically */
        gap: 15px;
        margin: 20px 0;
    }

    #screen-team-select .big-selection-btn {
        height: 120px; /* Smaller height for stacked items */
        width: 100%;
        font-size: 1.2rem !important;
    }

    #screen-team-select .big-selection-btn span {
        font-size: 1.4rem;
    }

    #screen-team-select .big-selection-btn small {
        font-size: 0.9rem;
    }

    #screen-team-select .secondary {
        font-size: 1.1rem;
        padding: 10px;
    }
}

/* =========================================
   RESPONSIVE ADJUSTMENTS (GAME VARIANT SCREEN)
   ========================================= */
@media screen and (max-width: 768px) {
    /* Identical structure to Team Select, applied to Variant Select */
    #screen-variant-select .menu-container {
        width: 90%;
        max-width: 400px;
        min-width: unset;
        padding: 20px;
        box-sizing: border-box;
    }

    #screen-variant-select h1 {
        font-size: 2.2rem;
        margin-bottom: 20px;
        transform: none;
        letter-spacing: 0;
    }

    #screen-variant-select .selection-row {
        flex-direction: column; /* Stack buttons vertically */
        gap: 15px;
        margin: 20px 0;
    }

    #screen-variant-select .big-selection-btn {
        height: 120px; /* Smaller height for stacked items */
        width: 100%;
        font-size: 1.2rem !important;
    }

    #screen-variant-select .big-selection-btn span {
        font-size: 1.4rem;
    }

    #screen-variant-select .big-selection-btn small {
        font-size: 0.9rem;
    }

    #screen-variant-select .secondary {
        font-size: 1.1rem;
        padding: 10px;
    }
}

/* =========================================
   RESPONSIVE ADJUSTMENTS (AVAILABLE ROOMS SCREEN)
   ========================================= */
@media screen and (max-width: 768px) {
    #screen-room-list .menu-container {
        width: 95%;
        max-width: none;
        padding: 15px;
        min-width: unset;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        height: 90vh; /* Maximize height usage */
    }

    #screen-room-list h1 {
        font-size: 2rem;
        margin-bottom: 15px;
        transform: none;
        letter-spacing: 0;
    }

    /* Scrollable Room List */
    #screen-room-list .room-list-scrollable {
        flex: 1; /* Take remaining space */
        width: 100%;
        margin-bottom: 15px;
        height: auto; /* Let flex handle height */
        max-height: none; /* Remove fixed limit if any */
    }

    /* Join Buttons inside the list */
    #screen-room-list .room-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    #screen-room-list .room-info {
        width: 100%;
    }

    #screen-room-list .btn-join-room {
        width: 100%;
        padding: 12px;
        margin-top: 5px;
        font-size: 1.1rem;
    }

    /* Bottom Buttons (Create / Back) */
    #screen-room-list .selection-row {
        flex-direction: column;
        gap: 10px;
        margin: 0;
        width: 100%;
        height: auto; /* Allow auto height */
    }

    /* Target the specific buttons with high specificity */
    #screen-room-list button#btn-create-room,
    #screen-room-list button#btn-room-list-back {
        width: 100%;
        height: 60px !important; /* Override inline style */
        margin: 0 !important;
        font-size: 1.2rem !important;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    
    #screen-room-list .big-selection-btn span {
        font-size: 1.2rem;
    }
}

/* =========================================
   RESPONSIVE ADJUSTMENTS (LOBBY SCREEN - COLORS)
   ========================================= */
@media screen and (max-width: 768px) {
    /* Scoped strictly to #screen-lobby */
    #screen-lobby .menu-container {
        width: 95%;
        max-width: 600px;
        padding: 15px;
        min-width: unset;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    #screen-lobby h1 {
        font-size: 2rem;
        margin-bottom: 10px;
        transform: none;
        letter-spacing: 0;
    }

    /* Force 2 per line for player slots using GRID */
    #screen-lobby .lobby-slots-container {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important; /* Two equal columns */
        gap: 20px;
        width: 100%;
        margin-top: 20px;
        padding: 0;
        justify-content: center;
        justify-items: center;
    }

    #screen-lobby .lobby-slot {
        width: 100%;
        max-width: none;
        display: flex;
        flex-direction: column;
        align-items: center;
        margin: 0;
    }

    #screen-lobby .lobby-slot-circle {
        width: 90px;
        height: 90px;
    }

    /* Target ONLY buttons inside this screen to avoid side effects */
    #screen-lobby button {
        font-size: 1.2rem;
        padding: 12px;
        margin-top: 15px;
        width: 100%; 
    }
}

/* =========================================
   RESPONSIVE ADJUSTMENTS (GAME SCREEN)
   ========================================= */
@media screen and (max-width: 768px) {
    /* Increase board size on mobile */
    #ludo-board {
        width: 96vw;
        height: 96vw;
        max-width: 96vw;
        max-height: 96vw;
        /* Ensure it doesn't exceed height either, but allow it to be bigger than 95vh if possible? 
           Actually, on mobile portrait, width is the constraint. 96vw is good. */
    }

    /* Adjust Avatars to be in corners */
    /* Override inline styles with !important */
    
    /* Top Left - Player 1 */
    #p1-avatar {
        top: 80px !important;
        left: 5px !important;
        transform: scale(0.85); /* Slightly smaller to save space */
        transform-origin: top left;
    }

    /* Top Right - Player 2 */
    #p2-avatar {
        top: 80px !important;
        right: 5px !important;
        transform: scale(0.85);
        transform-origin: top right;
    }

    /* Bottom Right - Player 3 */
    #p3-avatar {
        bottom: 5px !important; /* Push further down */
        right: 5px !important;
        top: auto !important; /* Ensure top is unset */
        transform: scale(0.85);
        transform-origin: bottom right;
    }

    /* Bottom Left - Player 4 */
    #p4-avatar {
        bottom: 5px !important;
        left: 5px !important;
        top: auto !important;
        transform: scale(0.85);
        transform-origin: bottom left;
    }

    /* Adjust toolbar to not overlap with bottom avatars if they are close */
    #bottom-toolbar {
        bottom: 10px;
        gap: 10px;
    }
    
    .toolbar-icon {
        width: 45px;
        height: 45px;
        font-size: 20px;
    }

    /* Coin display adjustments */
    #coin-display {
        top: 10px;
        right: 60px; /* Move left of settings button */
        transform: scale(0.8);
        transform-origin: top right;
    }

    #btn-game-config {
        top: 10px;
        right: 10px;
        width: 40px;
        height: 40px;
    }
}

/* Victory Animations */
@keyframes explode {
    0% { transform: translate(0, 0) scale(1); opacity: 1; }
    100% { transform: translate(var(--tx), var(--ty)) scale(0); opacity: 0; }
}

@keyframes pulse-scale {
    0% { transform: scale(1); }
    50% { transform: scale(0.5); }
    75% { transform: scale(1.4); }
    100% { transform: scale(1); }
}

.explosion-particle {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    pointer-events: none;
    animation: explode 0.8s ease-out forwards;
    z-index: 1000;
}

.explosion-particle.large {
    width: 10px;
    height: 10px;
    box-shadow: 0 0 10px currentColor;
}

.flying-piece {
    position: absolute;
    width: 30px; /* Adjust based on board size */
    height: 30px;
    background-size: contain;
    background-repeat: no-repeat;
    z-index: 2000;
    pointer-events: none;
    transform-origin: center;
}

.flying-soul {
    position: absolute;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    z-index: 2001;
    pointer-events: none;
    box-shadow: 0 0 10px currentColor, 0 0 20px white;
}

/* Slot Fill Animation */
@keyframes slot-pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.5); }
    100% { transform: scale(1); }
}

.slot.filled.animate {
    animation: slot-pop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* =========================================
   PLAYER SELECTION IMAGES & LAYOUT
   ========================================= */
.selection-btn-img {
    width: 140px; /* Increased from 120px */
    height: auto;
    margin-bottom: 15px; /* Increased margin for better spacing */
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

#screen-player-count .menu-container {
    min-width: 900px; /* Specific width ONLY for Player Count screen on PC */
}

#screen-player-count .big-selection-btn {
    height: 300px; 
    padding: 20px 0;
    min-width: 200px; /* Ensure cards themselves are wider */
}

.btn-text-group {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* =========================================
   RESPONSIVE ADJUSTMENTS (PLAYER COUNT SELECTION)
   ========================================= */
@media screen and (max-width: 768px) {
    #screen-player-count .menu-container {
        width: 90%;
        max-width: 400px;
        min-width: unset;
        padding: 20px;
        box-sizing: border-box;
    }

    #screen-player-count h1 {
        font-size: 2.2rem;
        margin-bottom: 20px;
        transform: none;
        letter-spacing: 0;
    }

    #screen-player-count .selection-row {
        flex-direction: column;
        gap: 15px;
        margin: 20px 0;
    }

    #screen-player-count .big-selection-btn {
        height: 100px; /* Smaller height for stacked items */
        width: 100%;
        font-size: 1.2rem !important;
        flex-direction: row; /* Horizontal layout for stacked buttons */
        justify-content: flex-start;
        padding: 0 20px;
        gap: 20px;
    }

    #screen-player-count .big-selection-btn .selection-btn-img {
        width: 50px;
        margin-bottom: 0;
    }
    
    #screen-player-count .btn-text-group {
        align-items: flex-start; /* Left align text */
        margin-left: 0; /* Gap handles spacing */
    }

    #screen-player-count .big-selection-btn span {
        font-size: 1.4rem;
        text-align: left;
    }

    #screen-player-count .big-selection-btn small {
        font-size: 0.9rem;
        text-align: left;
    }

    #screen-player-count .secondary {
        font-size: 1.1rem;
        padding: 10px;
    }
}

/* Partner Badge */
.partner-badge {
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #27ae60;
    color: white;
    font-size: 10px;
    font-weight: bold;
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
    z-index: 40;
    border: 1px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    pointer-events: none;
}

/* =========================================
   VERTICAL ADS (GAME SCREEN)
   ========================================= */
.game-ad-side {
    position: absolute;
    top: 50%;
    width: 160px;
    height: 300px;
    z-index: 5; /* Behind avatars (z-index 10 usually) but visible */
    pointer-events: none; /* Let clicks pass through container */
    display: flex;
    justify-content: center;
    align-items: center;
}

.game-ad-side iframe {
    pointer-events: auto; /* Enable clicks on the ad itself */
}

.game-ad-left {
    left: 20px;
    transform: translateY(-50%);
}

.game-ad-right {
    right: 20px;
    transform: translateY(-50%);
}

/* Responsive Hiding for Vertical Ads */
@media screen and (max-width: 1100px) {
    .game-ad-side {
        display: none !important;
    }
}

@media screen and (max-height: 650px) {
    .game-ad-side {
        display: none !important;
    }
}
