:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --accent: #f59e0b;
    --bg-color: #1d4ed8; 
    --text-main: #0f172a;
    --text-muted: #475569;
    
    /* Glassmorphism Variables */
    --glass-bg: rgba(255, 255, 255, 0.95);
    --glass-border: rgba(255, 255, 255, 0.6);
    --glass-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
    --glass-radius: 24px;
}

body {
    font-family: 'Segoe UI', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    margin: 0;
    background-color: var(--bg-color); 
    background-image: url('bg.png');
    background-repeat: repeat;
    background-attachment: fixed;
    background-position: center center;
    background-size: 250px;
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* =========================================
   ELEMENTS
   ========================================= */

.btn { 
    width: 100%; padding: 12px; border: none; border-radius: 12px; cursor: pointer; font-weight: 700; font-size: 1rem; color: white; transition: all 0.2s; display: inline-flex; justify-content: center; align-items: center; gap: 8px; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: linear-gradient(135deg, #4f46e5, #4338ca); }
.btn-primary:hover { filter: brightness(1.1); box-shadow: 0 8px 20px -4px rgba(79, 70, 229, 0.4); transform: translateY(-1px); }
.btn-secondary { background: #94a3b8; color: white; }
.btn-secondary:hover { background: #64748b; }
.btn-danger { background: #ef4444; }
.btn-danger:hover { background: #dc2626; box-shadow: 0 6px 15px -3px rgba(239, 68, 68, 0.4); }

.word-choice-btn {
    background: var(--primary);
    color: white !important;
    font-size: 1.1rem;
    padding: 15px;
    margin-bottom: 10px;
    border: 2px solid rgba(255,255,255,0.1);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    width: 100%;
}
.word-choice-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.02);
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}

input[type="text"], input[type="number"], select, textarea { 
    width: 100%; padding: 12px 15px; 
    /* NEW: More visible border, even when not focused */
    border: 2px solid #e5e7eb; 
    border-radius: 12px; 
    box-sizing: border-box; 
    font-family: inherit; 
    font-size: 1rem; 
    background: white; /* White background instead of f1f5f9 for more contrast */
    color: var(--text-main); 
    transition: all 0.2s;
}
/* NEW: Improved focus effect for better visibility */
input:focus, select:focus, textarea:focus { 
    outline: none; 
    background: white; 
    border-color: var(--primary); 
    /* Stronger shadow when focused */
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.2); 
}

/* =========================================
   STARTSEITE & LAYOUT
   ========================================= */

#lobby-browser { max-width: 1200px; margin: 0 auto; padding: 20px; height: 100vh; display: flex; flex-direction: column; box-sizing: border-box; }
.header { text-align: center; margin-bottom: -50px; flex-shrink: 0; z-index: 10; margin-top: -75px; }
.game-logo { max-width: 500px; width: 85%; height: auto; display: block; margin: 0 auto; filter: drop-shadow(0 4px 6px rgba(0,0,0,0.1)); }

.main-menu { display: grid; grid-template-columns: 400px 1fr; gap: 30px; flex: 1; overflow: hidden; padding-bottom: 20px; }

.action-box, .lobby-list-container, .lobby-panel, .word-select-box, .status-box, .result-box { 
    background: var(--glass-bg); 
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); 
    padding: 30px; 
    border-radius: var(--glass-radius); 
    box-shadow: var(--glass-shadow); 
    border: 1px solid var(--glass-border); 
    display: flex; flex-direction: column;
}

h3, .lobby-panel h2 { margin-top: 0; color: var(--text-main); font-size: 1.4rem; margin-bottom: 20px; font-weight: 800; letter-spacing: -0.5px; }

.control-panel { display: flex; flex-direction: column; gap: 25px; overflow-y: auto; }
.lobby-list-container { height: 100%; box-sizing: border-box; }
.list-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
#lobby-list { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 12px; padding-right: 5px; }

.lobby-card { 
    background: rgba(255,255,255,0.8); padding: 15px 20px; border-radius: 16px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 2px 5px rgba(0,0,0,0.05); border: 1px solid transparent; transition: all 0.2s; 
    /* NEW: Since Join button exists, card itself doesn't need a hover effect */
}

/* Deleted: .lobby-card:hover { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(0,0,0,0.08); border-color: var(--primary); background: white; } */

.lobby-info h4 { margin: 0; font-size: 1.1rem; font-weight: 700; color: var(--text-main); }
.lobby-meta { font-size: 0.85rem; color: var(--text-muted); margin-top: 4px; display: flex; gap: 12px; }
.btn-join { background: var(--primary); color: white; border: none; padding: 8px 20px; border-radius: 10px; cursor: pointer; font-weight: 700; transition: all 0.2s; }
.btn-join:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3); }
.btn-join.disabled { background: #e2e8f0; color: #94a3b8; cursor: not-allowed; transform: none; box-shadow: none; }

/* =========================================
   GAME PAGE
   ========================================= */

#game-container { 
    display: grid; grid-template-columns: 280px 1fr 320px; gap: 20px; width: 100%; height: 100vh; padding: 20px; box-sizing: border-box; overflow: hidden; 
}

#sidebar, #chat-container { 
    background: var(--glass-bg); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border-radius: var(--glass-radius); box-shadow: var(--glass-shadow); border: 1px solid var(--glass-border); display: flex; flex-direction: column; overflow: hidden; height: 100%;
}

.sidebar-header, #chat-input-area { padding: 20px; background: rgba(255,255,255,0.5); border-bottom: 1px solid rgba(0,0,0,0.05); }
#chat-input-area { border-top: 1px solid rgba(0,0,0,0.05); border-bottom: none; background: white; }
#room-title { margin: 0; font-size: 1.2rem; font-weight: 800; }
.room-id-display { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; background: rgba(0,0,0,0.05); display: inline-block; padding: 2px 8px; border-radius: 6px; margin-top: 5px; }
#player-list { flex: 1; overflow-y: auto; padding: 15px; }
#messages { 
    flex: 1; 
    overflow-y: auto; 
    padding: 15px; 
    /*display: flex;*/ 
    flex-direction: column; 
    gap: 8px; 
    /* NEW: Extra padding for last message visibility */
    padding-bottom: 20px; 
}
.sidebar-footer { padding: 20px; border-top: 1px solid rgba(0,0,0,0.05); background: rgba(255,255,255,0.3); display: flex; flex-direction: column; gap: 10px; }

#main { display: flex; flex-direction: column; gap: 20px; position: relative; overflow: hidden; border-radius: var(--glass-radius); }

#top-bar { 
    height: 70px; background: var(--glass-bg); backdrop-filter: blur(20px); border-radius: 16px; display: flex; justify-content: space-between; align-items: center; padding: 0 25px; box-shadow: var(--glass-shadow); flex-shrink: 0;
}
#timer { font-size: 1.8rem; font-weight: 800; color: var(--primary); font-variant-numeric: tabular-nums; }
#word-display { font-size: 1.4rem; letter-spacing: 1px; text-transform: uppercase; font-weight: 700; color: var(--text-main); }
#round-display { font-weight: 600; color: var(--text-muted); background: #e2e8f0; padding: 5px 12px; border-radius: 20px; font-size: 0.9rem;}

#canvas-wrapper { flex: 1; position: relative; display: flex; justify-content: center; align-items: center; overflow: hidden; }
canvas { background-color: white; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4); border-radius: 16px; cursor: crosshair; }

#tools-container { 
    background: white; 
    padding: 6px 15px; 
    border-radius: 12px; 
    display: flex; justify-content: center; align-items: center;
    gap: 15px; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.1); 
    margin: 0 auto; 
    width: fit-content; 
    max-width: 98vw;
    overflow: visible; 
    height: auto; 
    min-height: 44px;
    flex-wrap: wrap; 
    z-index: 100; 
    position: relative;
}

/* --- NEW: COMPACT COLOR PICKER STYLES (Keep existing good styles) --- */
/* The container inside the Toolbar */
.color-picker-container {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px; 
    padding-right: 15px;
    margin-right: 5px;
    border-right: 1px solid #e2e8f0;
}
/* ... rest of color picker styles remain ... */
.color-btn-fixed {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid rgba(0,0,0,0.05);
    transition: transform 0.1s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.color-btn-fixed:hover {
    transform: scale(1.1);
    z-index: 2;
}
.color-btn-fixed.active {
    border: 2px solid #0f172a; 
    transform: scale(1.1);
}
.picker-wrapper {
    position: relative;
}
.color-picker-trigger {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 2px solid rgba(0,0,0,0.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    margin-left: 4px; 
}
.color-picker-trigger:hover, .color-picker-trigger.active { 
    transform: scale(1.05);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}
.color-picker-trigger.active {
    border-color: #0f172a;
}
.color-popover {
    display: none; 
    position: absolute;
    bottom: 55px; 
    left: 50%;
    transform: translateX(-80%); 
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 10px;
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
    border: 1px solid rgba(255,255,255,0.5);
    grid-template-columns: repeat(4, 1fr); 
    gap: 8px;
    z-index: 5000; 
    width: max-content;
    animation: popUp 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.color-popover::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 80%; 
    margin-left: -6px;
    width: 12px;
    height: 12px;
    background: rgba(255, 255, 255, 0.95);
    transform: rotate(45deg);
    border-right: 1px solid rgba(0,0,0,0.05);
    border-bottom: 1px solid rgba(0,0,0,0.05);
}
@keyframes popUp {
    from { opacity: 0; transform: translateX(-80%) translateY(10px) scale(0.95); }
    to { opacity: 1; transform: translateX(-80%) translateY(0) scale(1); }
}
.color-swatch-compact {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid rgba(0,0,0,0.05);
    transition: transform 0.1s;
}
.color-swatch-compact:hover {
    transform: scale(1.2);
    z-index: 2;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.color-swatch-compact.active {
    border: 2px solid #0f172a;
    transform: scale(1.1);
}
/* ------------------------------------- */

.tools-section { display: flex; align-items: center; gap: 8px; }
/* Tool Buttons (clickable) */
.tool-btn { width: 30px; height: 30px; border-radius: 6px; display: flex; justify-content: center; align-items: center; cursor: pointer; color: #64748b; background: #f1f5f9; transition: all 0.2s; font-size: 0.9rem; flex-shrink: 0; }
.tool-btn:hover { background: #e2e8f0; color: var(--text-main); transform: translateY(-1px); }
.tool-btn.active { background: var(--primary); color: white; box-shadow: 0 2px 5px rgba(79, 70, 229, 0.3); transform: translateY(-1px); }

.separator { width: 1px; height: 20px; background: #e2e8f0; flex-shrink: 0; }

.player { 
    padding: 12px; margin-bottom: 8px; border-radius: 12px; display: flex; justify-content: space-between; align-items: center; background: rgba(255,255,255,0.6); border: 1px solid transparent; transition: all 0.2s; 
    /* Deleted: Hover effect for player list */
}

/* Deleted: .player:hover { background: white; transform: translateX(2px); } */

.player.drawer { background: #e0e7ff; border-color: var(--primary); }
.player.guessed { background: #dcfce7; color: #166534; }
.player.ready { border-left: 4px solid #10b981; }
.player.not-ready { border-left: 4px solid #ef4444; }

/* =========================================
   CHAT STYLING IMPROVEMENTS
   ========================================= */

/* Default Chat Bubble (Others) */
.msg-chat { 
    padding: 10px 15px; 
    background: #f1f5f9; /* Light gray background */
    border-radius: 16px; 
    border-top-left-radius: 4px; /* Slightly pointed corner at the top left */
    font-size: 0.95rem; 
    box-shadow: 0 1px 3px rgba(0,0,0,0.08); 
    border-left: 4px solid #94a3b8; /* Subtle gray bar */
    transition: all 0.2s ease-out; 
    margin-right: auto; 
    max-width: 85%;
    width: fit-content;
}
.msg-chat b { 
    color: var(--primary); 
    display: block; 
    font-size: 0.8rem; 
    margin-bottom: 2px; 
    font-weight: 700;
}

/* Chat Bubble for Self */
.msg-self {
    background: #e0e7ff; /* Lighter primary background */
    border-left: none; /* Remove left bar */
    border-right: 4px solid var(--primary-hover); /* Stronger color bar on the right */
    border-top-left-radius: 16px; /* Reset original corner */
    border-top-right-radius: 4px; /* Pointed corner at the top right */
    margin-left: auto; /* Float right */
    margin-right: 0;
}
.msg-self b {
    color: var(--primary-hover); 
    text-align: right;
}

/* System Messages (Events/Info) */
.msg-system { 
    text-align: center; 
    font-size: 0.75rem; 
    color: var(--text-muted); 
    opacity: 1; 
    margin: 10px auto; 
    position: relative;
    padding: 3px 10px;
    background: #eef2ff; 
    border-radius: 8px;
    width: fit-content;
    max-width: 90%;
    font-style: italic;
    font-weight: 500;
}

/* Correct Guess Messages */
.msg-correct { 
    background: #dcfce7; 
    color: #15803d; 
    padding: 10px; 
    border-radius: 16px; 
    text-align: center; 
    font-weight: 800; 
    font-size: 1rem; 
    border: 1px solid #bbf7d0; 
    box-shadow: 0 2px 5px rgba(21, 128, 61, 0.1);
}

/* =========================================
   OVERLAYS
   ========================================= */

#lobby-overlay, #word-select-overlay, #status-overlay, #turn-result-overlay, #game-over-overlay, #login-overlay, #notification-overlay, #audio-init-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    z-index: 1000; 
    background: rgba(15, 23, 42, 0.6); 
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    display: flex; justify-content: center; align-items: center; 
}

/* CHANGE: Lobby Overlay transparent and click-through */
#lobby-overlay { 
    backdrop-filter: none !important; 
    -webkit-backdrop-filter: none !important; 
    background: rgba(0, 0, 0, 0.1) !important; 
    pointer-events: none; 
}

/* BUT: The panel itself must remain interactive */
#lobby-overlay .lobby-panel {
    pointer-events: auto; 
    box-shadow: 0 25px 60px rgba(0,0,0,0.4); 
}

.lobby-panel, .word-select-box, .status-box, .result-box {
    width: 90%; max-width: 550px; 
    text-align: center; 
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    color: var(--text-main);
    padding: 30px; 
    overflow: hidden; 
}

@keyframes popIn { from { opacity: 0; transform: scale(0.95) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 25px; text-align: left; }
.setting-item { display: flex; flex-direction: column; gap: 6px; }
.lobby-panel label, .custom-words-area label { font-size: 0.9rem; font-weight: 700; color: var(--text-muted); display: block; }
.custom-words-area { margin-bottom: 25px; text-align: left; display: flex; flex-direction: column; gap: 8px; }
.checkbox-wrapper { display: flex; align-items: center; gap: 10px; margin-top: 5px; }

/* =========================================
   SCOREBOARD & RESULTS
   ========================================= */

.reveal-word { 
    font-size: 2.8rem; 
    color: var(--primary); 
    font-weight: 900; 
    margin: 15px 0 25px 0; 
    letter-spacing: 2px; 
    text-shadow: 0 2px 10px rgba(79, 70, 229, 0.2);
}

.result-list {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 350px;
    overflow-y: auto;
    padding-right: 8px; 
}

.result-list::-webkit-scrollbar { width: 6px; }
.result-list::-webkit-scrollbar-track { background: rgba(0,0,0,0.05); border-radius: 3px; }
.result-list::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

.result-row {
    background: white;
    border: 1px solid rgba(0,0,0,0.05);
    border-radius: 12px;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 5px rgba(0,0,0,0.03);
    /* NEW: Keep transition, but remove hover effect */
    transition: none; 
    font-size: 1.1rem;
}

/* Deleted: .result-row:hover { transform: translateX(3px); box-shadow: 0 4px 10px rgba(0,0,0,0.06); } */

.res-rank {
    font-weight: 800;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #f1f5f9;
    color: var(--text-muted);
    margin-right: 15px;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.rank-1 .res-rank { background: linear-gradient(135deg, #FFD700, #FDB931); color: #8a6d0b; text-shadow: 0 1px 0 rgba(255,255,255,0.4); box-shadow: 0 2px 5px rgba(253, 185, 49, 0.3); }
.rank-2 .res-rank { background: linear-gradient(135deg, #E0E0E0, #BDBDBD); color: #555; text-shadow: 0 1px 0 rgba(255,255,255,0.4); }
.rank-3 .res-rank { background: linear-gradient(135deg, #CD7F32, #A0522D); color: #3e1f0e; text-shadow: 0 1px 0 rgba(255,255,255,0.4); }

.res-name {
    flex: 1;
    text-align: left;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.res-gain {
    color: #10b981;
    font-weight: 800;
    font-size: 1rem;
    margin-right: 15px;
    background: #dcfce7;
    padding: 2px 8px;
    border-radius: 6px;
    animation: slideUpFade 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.res-score {
    font-weight: 700;
    color: var(--text-muted);
    min-width: 60px;
    text-align: right;
}

.row-winner {
    background: linear-gradient(to right, #fff, #fffbeb);
    border: 2px solid #fbbf24;
    transform: scale(1.02);
    margin-bottom: 5px;
}
.row-winner .res-name { color: #b45309; }

#winner-display {
    margin-bottom: 30px;
    padding: 20px;
    background: linear-gradient(135deg, rgba(255,255,255,0.8), rgba(255,255,255,0.4));
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.6);
}

@keyframes slideUpFade {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1000px) {
    .main-menu { grid-template-columns: 1fr; }
    #game-container { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; padding: 10px; gap: 10px; }
    #sidebar, #chat-container { display: none; }
    #top-bar { padding: 0 15px; height: 60px; }
    #lobby-browser { height: auto; padding: 10px; }
    .result-list { max-height: 250px; }
    .reveal-word { font-size: 2rem; }
}
