:root {
    --bg-color: #1a1a1a;
    --text-color: #e0e0e0;
    --accent: #d32f2f; /* Red for Coup */
    --card-bg: #2c2c2c;
    --highlight: #4caf50;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Roboto Mono', monospace; }

body { background-color: var(--bg-color); color: var(--text-color); height: 100vh; overflow-y: auto; }

.screen { display: none; min-height: 100%; flex-direction: column; }
.screen.active { display: flex; }

/* LOBBY */
#lobby-screen { justify-content: center; align-items: center; text-align: center; background-color: var(--bg-color); z-index: 50; overflow-y: auto; padding: 20px 0; }
#history-screen { justify-content: center; align-items: center; text-align: center; background-color: var(--bg-color); z-index: 60; overflow-y: auto; }
h1 { font-size: 4rem; color: var(--accent); letter-spacing: 5px; margin-bottom: 0.5rem; }
.subtitle { color: #888; margin-bottom: 2rem; }
.setup-box { background: var(--card-bg); padding: 2rem; border-radius: 10px; border: 1px solid #444; width: 90%; max-width: 400px; margin: auto; }
.control-group { margin-bottom: 1.5rem; text-align: left; }
select { width: 100%; padding: 10px; background: #333; color: white; border: 1px solid #555; margin-top: 5px; }

button { background: var(--accent); color: white; border: none; padding: 12px 20px; font-size: 1rem; cursor: pointer; width: 100%; margin-top: 10px; transition: 0.2s; }
button:hover { opacity: 0.9; }
button:disabled { background: #555; cursor: not-allowed; }
button.secondary { background: transparent; border: 1px solid #555; }
button.small-btn { width: auto; padding: 5px 10px; font-size: 0.8rem; }
button.red { background: #800; }
button.disabled-force { opacity: 0.3; pointer-events: none; }

/* GAME BOARD */
.game-header { display: flex; justify-content: space-between; padding: 10px; background: #000; align-items: center; flex-wrap: wrap; gap: 5px; }

#game-log { flex: 1; overflow-y: auto; padding: 10px; border-bottom: 1px solid #444; font-size: 0.9rem; background: #111; }
.log-entry { margin-bottom: 5px; }
.log-entry.system { color: #888; font-style: italic; }
.log-entry.important { color: var(--accent); font-weight: bold; }

#opponents-container { flex: 1; display: flex; justify-content: space-around; align-items: center; padding: 10px; flex-wrap: wrap; background: #222; }
.opponent-card { background: var(--card-bg); padding: 10px; border-radius: 5px; text-align: center; border: 1px solid #444; min-width: 100px; margin: 5px; }
.opponent-card.active-turn { border-color: var(--highlight); box-shadow: 0 0 10px var(--highlight); }
.card-back {
    display: inline-block;
    width: 30px; height: 40px;
    margin: 2px;
    border-radius: 3px;
    background: repeating-linear-gradient(45deg, #444, #444 5px, #333 5px, #333 10px);
    border: 1px solid #666;
    box-shadow: 1px 1px 3px rgba(0,0,0,0.5);
    vertical-align: middle;
}
.card-back.dead {
    background: #222;
    border-color: #333;
    opacity: 0.6;
    position: relative;
}
.card-back.dead::after {
    content: "✖";
    color: #c62828;
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.2rem;
    line-height: 0;
}
.card-back.replay-card {
    background: #ddd;
    color: #000;
}

/* PLAYER AREA */
#player-area { background: #151515; padding: 15px; border-top: 2px solid var(--accent); }
.cards-container { display: flex; justify-content: center; gap: 10px; margin: 10px 0; }

.player-card {
    width: 80px; height: 110px;
    display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
    border-radius: 8px;
    font-weight: bold;
    position: relative;
    cursor: pointer;
    background: #e0e0e0; /* Fallback */
    background-size: 80% 80%; /* Icon Size */
    background-position: center 20%;
    background-repeat: no-repeat;
    color: white;
    text-shadow: 1px 1px 2px black;
    box-shadow: 0 4px 6px rgba(0,0,0,0.5);
    border: 2px solid rgba(255,255,255,0.2);
    transition: transform 0.2s, box-shadow 0.2s;
    overflow: hidden;
    padding-bottom: 10px;
}

.player-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 12px rgba(0,0,0,0.7);
    z-index: 10;
}

.player-card.selectable { border: 3px solid var(--highlight); }

.player-card.dead {
    filter: grayscale(100%) brightness(50%);
    opacity: 0.8;
    border: 1px dashed #666;
    background-blend-mode: luminosity;
    text-decoration: none;
}

/* ROLE THEMES */
.role-duke {
    background-color: #512DA8;
    background-image: linear-gradient(135deg, #673AB7 0%, #311B92 100%), url("data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%27http%3A//www.w3.org/2000/svg%27%20viewBox%3D%270%200%2024%2024%27%20fill%3D%27black%27%20opacity%3D%270.7%27%3E%3C%21--%20Coin%20--%3E%3Ccircle%20cx%3D%2712%27%20cy%3D%2712%27%20r%3D%278%27/%3E%3Ctext%20x%3D%2712%27%20y%3D%2716%27%20font-size%3D%2710%27%20text-anchor%3D%27middle%27%20fill%3D%27white%27%20font-weight%3D%27bold%27%3E%24%3C/text%3E%3C/svg%3E");
    background-blend-mode: overlay, normal;
    border-color: #9575CD;
}
.role-assassin {
    background-color: #FFC107;
    background-image: linear-gradient(135deg, #FFEB3B 0%, #FFA000 100%), url("data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%27http%3A//www.w3.org/2000/svg%27%20viewBox%3D%270%200%2024%2024%27%20fill%3D%27black%27%20opacity%3D%270.7%27%3E%3C%21--%20Dagger%20--%3E%3Cpath%20d%3D%27M20.71%205.63l-2.34-2.34c-.39-.39-1.02-.39-1.41%200l-3.12%203.12-1.93-1.91-1.41%201.41%201.42%201.42L3%2016.25V21h4.75l8.92-8.92%201.42%201.42%201.41-1.41-1.92-1.92%203.12-3.12c.4-.4.4-1.03.01-1.42zM5.25%2020l-.63-.63%201.13-1.13.71.71L5.25%2020z%27/%3E%3C/svg%3E");
    background-blend-mode: overlay, normal;
    border-color: #FF6F00; /* Darker Gold/Orange */
    color: #000;
    text-shadow: none;
}
.role-captain {
    background-color: #1565C0;
    background-image: linear-gradient(135deg, #1976D2 0%, #0D47A1 100%), url("data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%27http%3A//www.w3.org/2000/svg%27%20viewBox%3D%270%200%2024%2024%27%20fill%3D%27black%27%20opacity%3D%270.7%27%3E%3C%21--%20Shield%20--%3E%3Cpath%20d%3D%27M12%201L3%205v6c0%205.55%203.84%2010.74%209%2012%205.16-1.26%209-6.45%209-12V5l-9-4z%27/%3E%3C/svg%3E");
    background-blend-mode: overlay, normal;
    border-color: #64B5F6;
}
.role-ambassador {
    background-color: #2E7D32;
    background-image: linear-gradient(135deg, #388E3C 0%, #1B5E20 100%), url("data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%27http%3A//www.w3.org/2000/svg%27%20viewBox%3D%270%200%2024%2024%27%20fill%3D%27black%27%20opacity%3D%270.7%27%3E%3C%21--%20Swap%20--%3E%3Cpath%20d%3D%27M6.99%2011L3%2015l3.99%204v-3H14v-2H6.99v-3zM21%209l-3.99-4v3H10v2h7.01v3L21%209z%27/%3E%3C/svg%3E");
    background-blend-mode: overlay, normal;
    border-color: #81C784;
}
.role-contessa {
    background-color: #d84315; /* Deep Orange / Rust */
    background-image: linear-gradient(135deg, #f4511e 0%, #bf360c 100%), url("data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%27http%3A//www.w3.org/2000/svg%27%20viewBox%3D%270%200%2024%2024%27%20fill%3D%27black%27%20opacity%3D%270.7%27%3E%3C%21--%20Crown%20--%3E%3Cpath%20d%3D%27M5%2018v3h14v-3H5zm.3-5l.7%203h12l.7-3L12%209%205.3%2013zM12%205L9%208h6l-3-3z%27/%3E%3C/svg%3E");
    background-blend-mode: overlay, normal;
    border-color: #ffab91;
}

.action-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 8px; padding-bottom: 20px; }
#action-panel h3, #reaction-panel h3 { margin-bottom: 10px; text-align: center; font-size: 0.9rem; color: #aaa; }

.hidden { display: none !important; }

/* MODAL */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.95); z-index: 100; display: flex; justify-content: center; align-items: center; }
.modal-content { background: var(--card-bg); padding: 20px; max-width: 500px; border: 1px solid var(--accent); max-height: 90vh; overflow-y: auto; }
.modal-content li { margin-bottom: 8px; margin-left: 20px; }

/* Responsive */
@media (max-width: 600px) {
    h1 { font-size: 2.5rem; }
    .player-card { width: 65px; height: 95px; font-size: 0.65rem; word-wrap: break-word; padding-bottom: 4px; } /* Adjusted size for visibility */
    .cards-container { gap: 8px; flex-wrap: wrap; } /* Allow wrapping if needed */
    button { font-size: 0.8rem; padding: 8px; white-space: normal; line-height: 1.2; }
    .action-grid { grid-template-columns: repeat(2, 1fr); }
    #opponents-container { flex: 0 0 auto; max-height: 150px; overflow-y: auto; } /* Prevent opponents taking too much space */
    #game-log { flex: 1; min-height: 100px; }
}

/* ADDED: Selection Style for Exchange */
.player-card.selected {
    border: 4px solid gold;
    transform: translateY(-10px);
    box-shadow: 0 0 15px gold;
}

/* ADDED: Game Footer */
.game-footer {
    color: #888;
    font-size: 0.8rem;
    margin-top: 20px;
    text-align: center;
    width: 100%;
}

/* ADDED: Mode Selector Styles */
.mode-selector {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.mode-btn {
    flex: 1;
    background: #333;
    border: 1px solid #555;
    opacity: 0.6;
}

.mode-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    opacity: 1;
    font-weight: bold;
}

/* --- NETWORK MODE ADJUSTMENTS FOR MOBILE --- */
@media (max-width: 600px) {
    #lobby-screen h1 { font-size: 2.5rem; margin-top: 10px; }
    .mode-selector { flex-direction: row; gap: 5px; margin-bottom: 15px; }
    .mode-btn { padding: 10px 5px; font-size: 0.9rem; }

    #online-controls input {
        font-size: 1.1rem; /* Better for mobile keyboard */
        padding: 12px;
    }

    #my-room-code {
        font-size: 1.0rem;
        word-break: break-all;
        padding: 8px;
    }

    /* Make opponent cards smaller to fit multiple on phone */
    .opponent-card {
        min-width: 80px;
        padding: 5px;
        margin: 2px;
        font-size: 0.8rem;
    }
    .card-back { width: 20px; height: 28px; }

    /* Action Grid - 2 columns for touch targets */
    .action-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    button {
        padding: 12px 5px; /* Taller tap target */
        font-size: 0.9rem;
    }

    /* Modal - Ensure full screen on small devices */
    .modal-content {
        width: 95%;
        max-height: 95vh;
        padding: 15px;
    }
}

/* --- CUSTOM PLAYER NAME --- */
#my-player-name {
    border: 1px solid #444;
    background: #222;
    color: white;
    font-family: 'Roboto Mono', monospace;
    transition: border-color 0.2s;
}

#my-player-name:focus {
    border-color: var(--highlight);
    outline: none;
}

/* --- TURN TIMER --- */
#turn-timer-bar {
    width: 0%;
    height: 4px;
    background: gold;
    position: absolute;
    bottom: 0;
    left: 0;
    transition: width 0.1s linear;
}

.game-header {
    position: relative; /* Context for absolute timer bar */
}


/* --- LARGE SCREEN FIXES --- */
/* REPLAY CONTROLS MOBILE */
@media (max-width: 600px) {
    #replay-controls {
        flex-wrap: wrap;
    }
    #replay-controls button {
        padding: 8px 15px;
        font-size: 0.8rem;
    }
}

/* Tablet & Desktop: Constrain grid to prevent overflow */
@media (min-width: 768px) {
    #action-panel {
        max-width: 800px;
        margin: 0 auto; /* Center the panel */
        overflow: visible; /* Allow buttons to show */
        flex-shrink: 0; /* Prevent squashing */
    }

    .action-grid {
        display: flex;
        flex-wrap: wrap; /* Allow wrapping if too many buttons */
        justify-content: center;
        gap: 10px;
        max-width: 100%; /* Ensure it fits in parent */
    }

    .action-grid button {
        flex: 1 1 120px; /* Flex grow, shrink, base width */
        max-width: 200px; /* Don't get too wide */
    }

    .setup-box {
        max-width: 500px;
        margin: 0 auto;
    }

    #online-controls {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
    }

    .control-group {
        width: 100%;
        max-width: 400px;
    }
}

/* --- DESKTOP DASHBOARD LAYOUT --- */
@media (min-width: 1024px) {
    #game-screen {
        display: grid;
        grid-template-columns: 1fr 350px; /* Main Area | Sidebar */
        grid-template-rows: auto 1fr; /* Top Row (Opponents+Header) | Bottom Row (Player+Log) */
        height: 100vh;
        overflow: hidden;
    }

    /* Sidebar: Header + Log */
    .game-header {
        grid-column: 2;
        grid-row: 1;
        flex-direction: column;
        align-items: stretch;
        justify-content: center;
        gap: 10px;
        padding: 20px;
        background: #111;
        border-left: 2px solid #333;
        border-bottom: 2px solid #333;
        height: 100%; /* Fill the grid cell */
    }

    #game-log {
        grid-column: 2;
        grid-row: 2;
        border-left: 2px solid #333;
        border-bottom: none;
        background: #0d0d0d;
        height: 100%; /* Fill remaining vertical space */
    }

    /* Main Area: Opponents + Player */
    #opponents-container {
        grid-column: 1;
        grid-row: 1;
        background: radial-gradient(circle at center, #222 0%, #1a1a1a 100%);
        align-items: center; /* Center vertically in the top row */
        padding: 20px;
        border-bottom: none; /* Remove legacy border */
        overflow-y: auto;
    }

    #player-area {
        grid-column: 1;
        grid-row: 2;
        border-top: none; /* Remove legacy border */
        display: flex;
        flex-direction: column;
        justify-content: flex-start; /* Prevent top-clipping */
        overflow-y: auto; /* Enable scrolling */
        min-height: 0; /* Allow flex/grid item to shrink below content size */
        padding: 30px;
    }

    /* Visual Polish for Desktop */
    .opponent-card {
        min-width: 140px; /* Larger opponent cards */
        font-size: 1rem;
        box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    }

    .card-back {
        width: 40px;
        height: 55px; /* Larger card backs */
    }

    .player-card {
        width: 120px; /* Significantly larger player cards */
        height: 165px;
        font-size: 1.1rem;
        box-shadow: 0 0 15px rgba(0,0,0,0.5);
    }

    #active-player-name {
        font-size: 2rem;
        margin-bottom: 20px;
    }

    .coins-display {
        font-size: 1.5rem;
        margin-bottom: 20px;
    }

    /* Action Buttons Scaling */
    .action-grid button {
        font-size: 1.1rem;
        padding: 15px;
        flex: 1 1 140px;
    }

    /* Lobby tweaks */
    .setup-box {
        max-width: 600px; /* Wider lobby box */
    }

    h1 {
        font-size: 5rem; /* Bigger Title */
    }
}

/* ADDED: Kick Button */
.kick-btn {
    background: #c62828;
    color: white;
    border: none;
    padding: 2px 6px;
    font-size: 0.8rem;
    border-radius: 4px;
    cursor: pointer;
    margin-left: 10px;
    vertical-align: middle;
    width: auto; /* Override default 100% width for buttons */
}
.kick-btn:hover {
    background: #d32f2f;
}

/* ADDED: Turn Timer Animation (Optional) */
@keyframes pulse-red {
    0% { color: #FF9800; }
    50% { color: #FF0000; }
    100% { color: #FF9800; }
}
.timer-low {
    animation: pulse-red 1s infinite;
}
