:root {
    --bg-color: #1a1a1a;
    --panel-bg: #252525;
    --text-color: #eee;
    --accent: #4CAF50;
    --board-color: #deb887;
    --board-border: #8b4513;
}

* { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.hidden { display: none !important; }

/* --- LOGIN SCREEN --- */
#login-screen {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--bg-color); z-index: 1000;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
}

.login-box {
    background: var(--panel-bg); 
    padding: 2rem; 
    border-radius: 8px;
    width: 320px; /* Slightly wider for better spacing */
    display: flex; flex-direction: column; 
    gap: 15px; /* Increased gap for cleaner look */
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}

/* GLOBAL INPUT & BUTTON RESET */
input, button {
    margin: 0; /* Fixes the alignment bug */
    box-sizing: border-box; /* Ensures padding doesn't break width */
}

input { 
    padding: 12px; 
    border-radius: 4px; 
    border: 1px solid #444; 
    background: #333; 
    color: white; 
    width: 100%; /* Forces inputs to fill container */
}

button { 
    padding: 12px; 
    cursor: pointer; 
    border-radius: 4px; 
    border: 1px solid transparent; /* Match input border size to align perfectly */
    font-weight: bold; 
    background: var(--accent); 
    color: white; 
    transition: 0.2s; 
    width: 100%; /* Default full width */
}

button:hover { filter: brightness(1.1); }
button:disabled { background: #555; cursor: not-allowed; }

/* ROW FOR JOIN ID & BUTTON */
.join-row { 
    display: flex; 
    gap: 10px; 
    width: 100%; 
}

#room-input { 
    flex: 1; /* Takes up remaining space */
}

#join-btn {
    width: auto; /* Let this button be sized by its text "Join" */
    min-width: 80px; /* Minimum width for clickability */
}

/* LAYOUT */
#game-screen { display: flex; width: 100%; height: 100%; }

.left-panel {
    width: 260px; background: var(--panel-bg); padding: 15px;
    display: flex; flex-direction: column; gap: 10px; border-right: 1px solid #333;
    overflow-y: auto;
}
/* CENTER: Board Area */
.center-panel {
    flex: 1; 
    display: flex; 
    justify-content: center; 
    align-items: center;
    background: #121212; 
    position: relative; 
    
    /* ENABLE SCROLLING/DRAGGING */
    overflow: auto; 
    -webkit-overflow-scrolling: touch; /* Smooth scroll on iPhone */
}

/* CARDS */
.game-title { font-size: 1.5rem; font-weight: bold; color: var(--board-color); text-align: center; }
.player-card {
    background: #333; padding: 10px; border-radius: 8px; border-left: 4px solid transparent;
}
.player-card.active { border-left-color: var(--accent); background: #3a3a3a; box-shadow: 0 0 10px rgba(76, 175, 80, 0.1); }
.p-role { font-size: 0.7rem; color: #888; text-transform: uppercase; }
.p-name { font-size: 1rem; font-weight: bold; margin: 3px 0; }
.p-status { font-size: 0.8rem; display: flex; justify-content: space-between; }
.timer-count { color: #ffeb3b; font-weight: bold; }

.game-result { padding: 10px; border-radius: 8px; text-align: center; font-weight: bold; margin-top: auto; }
.res-win { background: rgba(76, 175, 80, 0.2); color: #4CAF50; border: 1px solid #4CAF50; }
.res-lose { background: rgba(244, 67, 54, 0.2); color: #F44336; border: 1px solid #F44336; }
.res-draw { background: rgba(255, 255, 255, 0.1); border: 1px solid #999; }

/* BOARD */
#board {
    display: grid;
    grid-template-columns: repeat(19, 1fr);
    grid-template-rows: repeat(19, 1fr);
    
    /* DEFAULT SIZE (Controlled by Slider JS later) */
    width: 600px; 
    height: 600px;
    
    /* Remove Max constraints so Zoom works */
    max-width: none; 
    max-height: none;
    
    background-color: var(--board-color);
    border: 8px solid var(--board-border);
    box-shadow: 0 0 50px rgba(0,0,0,0.5);
    
    /* Keep it centered when zoomed out */
    margin: auto;
}
.cell { border: 1px solid rgba(0,0,0,0.1); position: relative; display: flex; justify-content: center; align-items: center; }
.stone { width: 90%; height: 90%; border-radius: 50%; box-shadow: 1px 1px 2px rgba(0,0,0,0.4); }
.stone.black { background: radial-gradient(circle at 30% 30%, #555, #000); }
.stone.white { background: radial-gradient(circle at 30% 30%, #fff, #ccc); border: 1px solid #999; }
.win-highlight { background-color: rgba(0, 255, 0, 0.5) !important; }

/* CONTROLS */
.controls { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.controls button { padding: 8px; width: 100%; border-radius: 4px; border:none; cursor: pointer; background: var(--accent); color: white; font-weight: bold; }
.btn-secondary { background: #555 !important; }

/* CHAT */
.spectator-list { height: 100px; padding: 10px; border-bottom: 1px solid #333; overflow-y: auto; }
.spec-item { font-size: 0.8rem; color: #aaa; }
.chat-container { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#chat-box { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 5px; font-size: 0.8rem; }
.chat-msg { word-wrap: break-word; }
.chat-name { font-weight: bold; margin-right: 5px; }
.chat-input-area { display: flex; padding: 5px; background: #222; }
#chat-input { flex: 1; padding: 8px; background: #333; color: white; border:none; }
#send-chat { width: 40px; background: var(--accent); border:none; color:white; }
.timer-warning { color: #ff5252; animation: pulse 0.5s infinite; }

@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; } }

/* MOBILE RESPONSIVE */
@media (max-width: 900px) {
    body { overflow-y: auto; height: auto; }
    #game-screen { flex-direction: column; }
    
    /* Order: Board first, then Info, then Chat */
    .center-panel { order: 1; height: 100vw; width: 100vw; background: #000; padding: 0; }
    #board { width: 98vw; height: 98vw; border-width: 2px; }
    
    .left-panel { order: 2; width: 100%; height: auto; flex-direction: row; flex-wrap: wrap; justify-content: space-between; padding: 10px; border-bottom: 1px solid #333; }
    .game-title { display: none; }
    .player-card { width: 48%; }
    .controls { width: 100%; flex-direction: row; }
    .controls button { font-size: 0.8rem; }
    
    .right-panel { order: 3; width: 100%; height: 300px; }
}

/* --- BLAZINGLY OBVIOUS UPGRADES --- */

/* 1. The Big Turn Status Box */
.turn-status {
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 8px;
    text-align: center;
    font-weight: 900;
    font-size: 1.4rem;
    text-transform: uppercase;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    transition: 0.3s;
    border: 2px solid transparent;
}

.turn-status.your-turn {
    background-color: #4CAF50; /* Green */
    color: #fff;
    border-color: #81c784;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
    animation: popIn 0.3s ease-out;
}

.turn-status.opp-turn {
    background-color: #D32F2F; /* Red */
    color: #fff;
    border-color: #e57373;
}

.turn-status.waiting {
    background-color: #FF9800; /* Orange */
    color: #fff;
    font-size: 1.1rem;
}

/* 2. The "YOU" Identifier */
.player-card.is-me {
    border: 2px solid #2196F3; /* Bright Blue Border */
    background: #2c3e50; /* Slightly blue-tinted bg */
    position: relative;
}

.player-card.is-me::after {
    content: "YOU";
    position: absolute;
    top: -12px;
    right: 15px;
    background: #2196F3;
    color: white;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    letter-spacing: 1px;
}

/* 3. Intense Turn Highlighting */
.player-card.active {
    border-left: 8px solid #4CAF50; /* Thicker indicator */
    background: #383838;
    box-shadow: 0 0 15px rgba(76, 175, 80, 0.4); /* Glow */
    transform: scale(1.02); /* Slight pop */
}

/* 4. Spectator Badge Fix */
.turn-status.spec-turn {
    background-color: #555;
    color: #ccc;
    font-size: 1rem;
}

@keyframes popIn {
    0% { transform: scale(0.9); opacity: 0.5; }
    100% { transform: scale(1); opacity: 1; }
}

/* --- MUTE BUTTON FIX --- */
#mute-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 2000;
    width: 50px !important;  /* Force small width */
    height: 50px !important; /* Force small height */
    border-radius: 50%;      /* Make it circular */
    background: rgba(30, 30, 30, 0.8);
    border: 2px solid #555;
    font-size: 1.5rem;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    transition: transform 0.2s;
}

#mute-btn:hover {
    background: #333;
    transform: scale(1.1);
    border-color: #fff;
}

/* --- RULES BOX --- */
.rules-box {
    margin-top: 20px;
    background: rgba(0, 0, 0, 0.6); /* Dark see-through background */
    border: 1px solid #444;
    border-radius: 8px;
    padding: 15px 25px;
    max-width: 350px;
    color: #ccc;
    font-size: 0.9rem;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    backdrop-filter: blur(5px); /* Blurs the background behind it */
}

.rules-box h3 {
    margin: 0 0 10px 0;
    color: var(--board-color);
    text-align: center;
    border-bottom: 1px solid #555;
    padding-bottom: 5px;
    font-size: 1.1rem;
}

.rules-box ul {
    padding-left: 20px;
    margin: 0;
    line-height: 1.6;
}

.rules-box li {
    margin-bottom: 5px;
}

.rules-box strong {
    color: var(--accent); /* Green text for emphasis */
}

/* Mobile Adjustment for Rules */
@media (max-width: 900px) {
    .rules-box {
        width: 90%;
        font-size: 0.85rem;
        margin-bottom: 20px; /* Space at bottom for scrolling */
    }
}