/* Reset & Base */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #1a1a1a url('../images/background.png') no-repeat center center fixed;
    background-size: cover; /* Changed to cover for better mobile background */
    color: #eee;
    height: 100vh;
    overflow: hidden; /* Main desktop behavior */
}

#app {
    width: 100%;
    height: 100%;
    position: relative;
    overflow-y: auto; /* Allow scrolling if content overflows on mobile */
}

/* Screens */
.screen {
    display: none;
    width: 100%;
    min-height: 100%;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding-bottom: 100px; /* Space for logos */
}
.screen.active { display: flex; }

/* Logos */
#logos-container {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    z-index: 100;
    background: rgba(0, 0, 0, 0.5); /* Optional backdrop for visibility */
    padding: 10px 20px 0 20px;
    border-radius: 20px 20px 0 0;
    pointer-events: none; /* Let clicks pass through if needed, though buttons are usually higher */
}
#logos-container img {
    height: 90px;
    width: auto;
    object-fit: contain;
}

/* Menu */
#menu-screen h1 {
    font-size: 4rem;
    color: #ff8c00;
    text-shadow: 0 0 20px rgba(255, 140, 0, 0.8), 2px 2px 4px black;
    margin-bottom: 50px;
    font-weight: 900;
    text-align: center;
}
.menu-buttons button {
    display: block;
    width: 320px;
    padding: 18px;
    margin: 12px 0;
    font-size: 1.3rem;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.7);
    color: #ff8c00;
    border: 2px solid #ff8c00;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
    backdrop-filter: blur(5px);
}
.menu-buttons button:hover {
    background: #ff8c00;
    color: black;
    box-shadow: 0 0 20px #ff8c00;
    transform: scale(1.05);
}

/* Game Container */
#game-container {
    display: flex;
    width: 100%;
    height: 100%; /* Take full height */
    padding: 20px;
    gap: 20px;
    background: rgba(0, 0, 0, 0.4);
}

/* Info Panel */
#info-panel {
    flex: 1;
    background: rgba(0,0,0,0.8);
    border-radius: 15px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border: 1px solid #ff8c00;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    max-width: 300px;
}
.player-info {
    text-align: center;
    margin: 20px 0;
    padding: 15px;
    border-radius: 10px;
    width: 100%;
    transition: all 0.3s;
    opacity: 0.5;
    border: 2px solid transparent;
    background: rgba(255, 255, 255, 0.05);
}
.player-info.active-turn {
    opacity: 1;
    background: rgba(255, 140, 0, 0.2);
    border: 3px solid #ff8c00;
    box-shadow: 0 0 25px rgba(255, 140, 0, 0.7);
    transform: scale(1.05);
}
.player-info .name { font-size: 1.5rem; display: block; font-weight: bold; color: #fff; text-shadow: 1px 1px 2px black; }
.player-info .score { font-size: 1.2rem; color: #ccc; }

#match-score { font-size: 2.5rem; font-weight: 900; color: #ff8c00; margin: 10px 0; text-shadow: 0 0 10px rgba(255,140,0,0.5); }
#turn-indicator {
    margin-top: 30px;
    font-size: 1.5rem;
    color: #00ffcc;
    font-weight: bold;
    text-transform: uppercase;
    text-align: center;
    text-shadow: 0 0 10px rgba(0, 255, 204, 0.8);
}
@keyframes textPulse {
    0% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.1); opacity: 1; text-shadow: 0 0 20px #00ffcc; }
    100% { transform: scale(1); opacity: 0.8; }
}
.pulse-text { animation: textPulse 1s infinite; }

/* Board Area */
#board-container {
    flex: 3;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    /* Ensure board doesn't get too small or too big */
    min-width: 0; /* Flexbox fix */
}
#game-board {
    position: relative;
    width: 100%;
    max-width: 1200px;
    aspect-ratio: 2.4 / 1;
}

.board-visual {
    position: relative;
    width: 100%;
    height: 100%;
}
.board-visual img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 15px 30px rgba(0,0,0,0.6));
}

/* Pits */
.pit {
    position: absolute;
    width: 8.5%;
    height: 34%;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    z-index: 10;
}
.pit:hover {
    background: radial-gradient(circle, rgba(255,200,0,0.2) 0%, rgba(0,0,0,0) 70%);
}
.pit.active {
    cursor: pointer;
}
.pit::after {
    content: attr(data-count);
    position: absolute;
    bottom: -35px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 1rem;
    color: #fff;
    border: 1px solid #ff8c00;
    pointer-events: none;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
    white-space: nowrap;
}

/* Stores */
.store-area {
    position: absolute;
    width: 12%;
    height: 80%;
    top: 10%;
    z-index: 5;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap; /* Allow stones to wrap */
}
.store-count {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    font-weight: 900;
    color: rgba(255, 255, 255, 0.5); /* Increased transparency to show stones */
    text-shadow: 0 2px 10px rgba(0,0,0,1);
    z-index: 20;
    pointer-events: none;
}
/* Player Store Shift */
.store-area.player-store .store-count {
    transform: translate(-50%, -50%) translateX(-15px);
}

/* Stones */
.stone {
    width: 20px;
    height: 20px;
    position: absolute;
    background-size: contain;
    background-repeat: no-repeat;
    pointer-events: none;
    border-radius: 50%;
    filter: drop-shadow(1px 1px 2px rgba(0,0,0,0.5));
    z-index: 15;
}
.stone.type1 { background-image: url('../images/stone1.png'); }
.stone.type2 { background-image: url('../images/stone2.png'); }

/* Flying Stone */
#flying-stone {
    width: 30px;
    height: 30px;
    z-index: 1000;
    position: fixed;
    transition: all 0.3s ease-out;
    filter: drop-shadow(0 10px 15px rgba(0,0,0,0.6));
    pointer-events: none;
    display: none;
}

/* Chat */
#chat-container {
    flex: 1;
    background: rgba(0,0,0,0.8);
    border: 1px solid #ff8c00;
    display: flex;
    flex-direction: column;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    max-width: 300px;
}
#chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    font-size: 0.95rem;
    min-height: 150px;
}
.chat-msg { margin-bottom: 10px; padding: 8px; background: rgba(255,255,255,0.1); border-radius: 8px; }
.chat-msg.mine { background: rgba(0, 255, 204, 0.2); align-self: flex-end; border: 1px solid rgba(0, 255, 204, 0.3); }
.chat-msg .sender { font-weight: bold; color: #ff8c00; font-size: 0.85rem; margin-bottom: 2px; display: block;}
.chat-msg .text { display: block; color: #eee; word-break: break-word; }

#chat-input-area {
    padding: 15px;
    background: rgba(0,0,0,0.9);
    display: flex;
    gap: 10px;
    border-top: 1px solid #444;
}
#chat-input { 
    flex: 1; 
    padding: 10px; 
    border-radius: 8px; 
    border: 1px solid #555; 
    background: #222; 
    color: white; 
    font-size: 1rem;
    width: 100%;
}
#chat-input-area button { 
    padding: 0 20px; 
    background: #ff8c00; 
    border: none; 
    border-radius: 8px; 
    color: black; 
    font-weight: bold;
    cursor: pointer; 
    transition: background 0.3s;
}
#chat-input-area button:hover { background: #ffa500; }

/* Modals */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(5px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}
.modal.active { display: flex; }
.modal-content {
    background: #222;
    padding: 40px;
    border-radius: 20px;
    width: 90%;
    max-width: 450px;
    border: 2px solid #ff8c00;
    text-align: center;
    box-shadow: 0 0 30px rgba(255,140,0,0.3);
}
.modal-content h2 { color: #ff8c00; margin-bottom: 25px; font-size: 2rem; }
.modal-content input {
    width: 100%;
    padding: 15px;
    margin-bottom: 25px;
    background: #333;
    border: 1px solid #555;
    color: white;
    border-radius: 10px;
    font-size: 1.1rem;
    text-align: center;
}
.modal-buttons button {
    padding: 12px 30px;
    margin: 5px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    font-weight: bold;
    font-size: 1.1rem;
    transition: transform 0.2s;
}
.modal-buttons button:hover { transform: scale(1.05); }
.modal-buttons button:first-child { background: #ff8c00; color: black; }
.modal-buttons button:last-child { background: #444; color: white; }

#game-list {
    max-height: 250px;
    overflow-y: auto;
    margin-bottom: 25px;
    text-align: left;
    border: 1px solid #444;
    border-radius: 10px;
    padding: 5px;
}
.game-item {
    background: rgba(255,255,255,0.05);
    padding: 15px;
    margin-bottom: 5px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}
.game-item:hover { background: rgba(255,140,0,0.2); }
.game-item-info span { display: block; }
.game-status { font-size: 0.8rem; padding: 3px 8px; border-radius: 5px; font-weight: bold; }
.status-wait { background: #00aa00; color: white; }
.status-full { background: #aa0000; color: white; }

/* Buttons */
#new-set-btn, #exit-game-btn {
    margin-top: 10px;
    padding: 10px 20px;
    width: 100%;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: bold;
}
#new-set-btn { background: #2ecc71; color: white; }
#exit-game-btn { background: #e74c3c; color: white; }

/* RESPONSIVE DESIGN */
@media (max-width: 1024px) {
    #game-container {
        flex-direction: column;
        align-items: center;
        overflow-y: auto;
        padding-bottom: 120px; /* Space for logos + scroll */
    }

    #info-panel, #chat-container {
        width: 100%;
        max-width: none;
        flex: none;
    }

    #info-panel {
        flex-direction: row;
        justify-content: space-around;
        padding: 10px;
    }
    .player-info {
        margin: 0;
        width: 30%;
        font-size: 0.9rem;
        padding: 5px;
    }
    #turn-indicator {
        margin-top: 0;
        font-size: 1rem;
    }
    #match-score { font-size: 1.5rem; }

    #board-container {
        width: 100%;
        flex: none;
    }
    
    .pit::after {
        bottom: -25px;
        font-size: 0.8rem;
        padding: 2px 5px;
    }
    
    .store-count {
        font-size: 2rem;
    }

    #logos-container img {
        height: 60px; /* Smaller logos on mobile */
    }
    
    .menu-buttons button {
        width: 90%;
    }
    
    #menu-screen h1 {
        font-size: 3rem;
    }
    
    /* Make stones slightly smaller on mobile */
    .stone {
        width: 15px;
        height: 15px;
    }
}

/* Portrait Mobile Fixes */
@media (max-width: 600px) {
    #board-container {
        /* On very narrow screens, we might need to just let it fit width-wise */
        width: 100%;
    }
    
    .player-info .name {
        font-size: 1rem;
    }
    
    #info-panel {
        flex-wrap: wrap;
    }
}
