/* 1. Global Reset and Body Styling */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 24px;
    color: white;
    overflow-x: hidden;
    padding: 20px;
}

.main-title {
    font-size: 6rem;
    font-weight: 900;
    letter-spacing: 5px;
    background: linear-gradient(to right, #240b36, #3a1c71);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0px 5px 5px rgba(0, 0, 0, 0.5));
}

/* 2. Main Game Container */
.container {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 40px;
    border-radius: 25px;
    box-shadow: 0 25px 45px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
    transition: filter 0.5s ease, transform 0.5s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 450px;
}

/* 3. The Grid */
.grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(70px, 100px));
    justify-content: center;
    align-content: center;
    gap: 15px;
    margin: 0 auto 24px auto;
}

.row {
    display: contents;
}

/* 4. The Cells (.col) */
.col {
    width: 100%;
    aspect-ratio: 1 / 1;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: inset 0 0 0px rgba(255, 255, 255, 0.1);
    padding: 12px;
}

.col:empty:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.col:not(:empty) {
    animation: popIn 0.3s forwards;
}

.mark-svg { width: 100%; height: 100%; overflow: visible; }
.heart-doodle { filter: drop-shadow(0 0 8px rgba(255, 45, 85, 0.6)); transform: rotate(-5deg); }
.circle-doodle { filter: drop-shadow(0 0 8px rgba(45, 125, 255, 0.6)); transform: rotate(3deg); }

/* 5. Buttons */
.controls {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
    width: 100%;
}

button {
    padding: 12px 25px;
    border: none;
    border-radius: 50px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    color: white;
    background-size: 200% auto;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

button:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
    background-position: right center;
}

button:active { transform: translateY(-1px); }

.btn { background-image: linear-gradient(to right, #00d2ff 0%, #3a7bd5 51%, #00d2ff 100%); }
.btn-leave { background-image: linear-gradient(to right, #ff5858 0%, #f857a6 51%, #ff5858 100%); }

@keyframes popIn {
    from { transform: scale(0.5); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

/* ============ LOBBY / NAME / WAITING ============ */
#lobby, #namePrompt, #waitingRoom {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 40px;
    border-radius: 25px;
    box-shadow: 0 25px 45px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
    max-width: 95%;
}

#lobby h2, #namePrompt h2, #waitingRoom h2 { font-size: 2rem; margin-bottom: 10px; }
#lobby p { margin-bottom: 20px; opacity: 0.9; }

#lobby input, #namePrompt input {
    padding: 12px; border-radius: 50px; border: none; font-size: 16px;
    margin: 8px; width: 180px; text-align: center; outline: none;
}

.edit-name-btn {
    background: none; border: none; color: #ffe9a8; cursor: pointer;
    font-size: 0.9rem; margin-left: 10px; font-weight: bold; text-decoration: underline;
    transition: color 0.2s, transform 0.2s; box-shadow: none; padding: 0;
}
.edit-name-btn:hover { color: #ffffff; transform: translateY(-1px); box-shadow: none; background-image: none; }

#roomCodeDisplay, #waitRoomCode {
    font-size: 1.1rem; margin-bottom: 10px; padding: 8px 18px;
    background: rgba(255, 255, 255, 0.1); border-radius: 50px; display: inline-block;
    text-transform: lowercase; 
}

#status { font-size: 1.3rem; font-weight: 600; margin: 12px 0 16px; }

/* ============ PLAYER STATUS BAR ============ */
.players-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: nowrap;
    margin: 10px auto 6px;
    background: rgba(255, 255, 255, 0.08);
    padding: 12px 10px;
    border-radius: 20px;
    max-width: 100%;
}

.player-card {
    display: flex; align-items: center; gap: 10px; padding: 6px 10px;
    border-radius: 16px; transition: opacity 0.3s ease;
}

.player-card.is-offline { opacity: 0.55; }
.avatar-wrap { position: relative; width: 54px; height: 54px; flex-shrink: 0; }
.avatar-svg { width: 100%; height: 100%; }

.status-dot {
    position: absolute; bottom: 2px; right: 2px; width: 14px; height: 14px;
    border-radius: 50%; border: 2px solid #2b1b4d;
}
.dot-online  { background: #22c55e; box-shadow: 0 0 8px #22c55e; }
.dot-offline { background: #9ca3af; }

.player-meta { text-align: left; }
.player-name { 
    font-weight: 700; 
    font-size: 1rem; 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
    max-width: 120px;
}

.player-score { font-size: 0.85rem; color: #ffe9a8; font-weight: 600; margin-top: 2px; }
.draws-text { font-size: 0.8rem; font-weight: normal; color: #e5e7eb; }

.player-mark { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; opacity: 0.85; }
.player-mark .mark-svg { width: 18px; height: 18px; }

.vs-label { font-weight: 900; font-size: 1.1rem; opacity: 0.8; }

.rematch-info { width: 100%; min-height: 22px; margin-bottom: 12px; font-size: 0.95rem; font-weight: 600; color: #ffe9a8; }
.hidden { display: none !important; }

/* ============ CUSTOM MODAL OVERLAY ============ */
#modalOverlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
    display: flex; justify-content: center; align-items: center; z-index: 1000; opacity: 1; transition: opacity 0.3s ease;
}
#modalOverlay.hidden { opacity: 0; pointer-events: none; }

#modalBox {
    background: rgba(255, 255, 255, 0.15); border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 30px; border-radius: 25px; box-shadow: 0 25px 45px rgba(0, 0, 0, 0.3);
    text-align: center; max-width: 400px; width: 90%; transform: scale(1);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
#modalOverlay.hidden #modalBox { transform: scale(0.8); }
#modalMessage { font-size: 1.2rem; margin-bottom: 25px; font-weight: 600; line-height: 1.5; }
.modal-controls { margin-top: 10px; }


/* ============ FLOATING CHAT BUTTON (FAB) ============ */
.chat-fab {
    position: fixed;
    bottom: 25px;
    right: 25px;
    width: 65px;
    height: 65px;
    border-radius: 50%;
    background-image: linear-gradient(to right, #00d2ff 0%, #3a7bd5 100%);
    border: none;
    color: white;
    font-size: 1.8rem;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    z-index: 900;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.chat-fab .chat-badge {
    position: absolute;
    top: 12px;
    right: 12px;
}


/* ============ CHAT PANEL & AUDIO ============ */
#chatPanel {
    position: fixed;
    bottom: 105px; 
    right: 25px;
    width: 350px;
    height: 480px;
    background: rgba(20, 10, 40, 0.85);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    z-index: 500;
    box-shadow: 0 15px 35px rgba(0,0,0,0.5);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
    overflow: hidden; 
}

#chatPanel.closed {
    opacity: 0;
    pointer-events: none;
    transform: translateY(50px) scale(0.95);
}

.chat-header {
    display: flex; justify-content: space-between; align-items: center; padding: 15px 20px;
    background: rgba(255, 255, 255, 0.1); border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-header h3 { font-size: 1.1rem; margin: 0; }
.close-chat { background: none; border: none; color: white; font-size: 1.2rem; cursor: pointer; padding: 0 !important; box-shadow: none; width: auto !important; margin: 0; }
.close-chat:hover { background: none; box-shadow: none; transform: scale(1.1); }
.chat-messages { flex: 1; padding: 15px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { max-width: 85%; padding: 10px 15px; border-radius: 18px; font-size: 0.9rem; word-wrap: break-word; animation: popIn 0.2s forwards; }
.msg-me { align-self: flex-end; background: linear-gradient(to right, #00d2ff, #3a7bd5); border-bottom-right-radius: 4px; }
.msg-them { align-self: flex-start; background: rgba(255, 255, 255, 0.15); border-bottom-left-radius: 4px; }

/* STRICT AUDIO HIDING CSS (Webkit/Blink Browsers) */
.chat-audio {
    height: 40px;
    width: 220px;
    outline: none;
    border-radius: 20px;
}
.chat-audio::-webkit-media-controls-mute-button,
.chat-audio::-webkit-media-controls-volume-slider {
    display: none !important;
}
.chat-audio::-webkit-media-controls-panel {
    background-color: rgba(255, 255, 255, 0.9);
}

.chat-input-area { 
    display: flex; padding: 12px 15px; gap: 10px; 
    background: rgba(255, 255, 255, 0.05); 
    border-top: 1px solid rgba(255, 255, 255, 0.1); 
    align-items: center; 
}

#chatInput { 
    flex: 1; padding: 12px 18px; border-radius: 50px; border: none; 
    outline: none; font-size: 0.95rem; text-align: left; width: 100%; 
    margin: 0; background: rgba(255, 255, 255, 0.9); color: #333; 
}

/* WhatsApp-Style Action Button Wrapper */
.chat-action-wrapper {
    position: relative;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
}

.chat-action-btn {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: white;
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease, background 0.3s ease;
    padding: 0 !important;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2) !important;
}

.chat-action-btn:hover {
    transform: scale(1.05);
}

.chat-action-btn.hidden {
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}

/* Mic Recording Pulse State */
.chat-action-btn.recording {
    background: #ff2d55;
    animation: pulseMic 1s infinite;
}
.chat-action-btn.recording svg {
    fill: white !important;
}

@keyframes pulseMic {
    0% { box-shadow: 0 0 0 0 rgba(255, 45, 85, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(255, 45, 85, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 45, 85, 0); }
}


/* ============ RESPONSIVENESS ============ */

@media (max-width: 600px) {
    .main-title { font-size: 4rem; letter-spacing: 2px; margin-top: 10px; }
    .container, #lobby, #namePrompt, #waitingRoom { padding: 25px 15px; width: 95%; }
    
    .grid { grid-template-columns: repeat(3, minmax(60px, 80px)); justify-content: center; gap: 10px; margin: 0 auto 20px auto; }
    .col { border-radius: 10px; padding: 8px; }
    .controls { flex-direction: column; width: 100%; }

    /* Override mobile button styles for chat components to protect layout */
    button:not(.close-chat):not(.chat-action-btn):not(.chat-fab) { width: 100%; padding: 15px; }

    #lobby input, #namePrompt input { width: 100%; margin: 8px 0; }

    .players-status { gap: 5px; padding: 10px 5px; }
    .avatar-wrap { width: 46px; height: 46px; }
    .player-name { font-size: 0.85rem; max-width: 80px; }
    .vs-label { font-size: 0.9rem; }
    
    .chat-fab { bottom: 15px; right: 15px; width: 55px; height: 55px; font-size: 1.5rem; z-index: 1100; }
    
    #chatPanel {
        bottom: 0; right: 0; width: 100%; height: 70vh;
        border-radius: 20px 20px 0 0;
        z-index: 1200; 
    }
    
    .chat-audio { width: 180px; } 
}

@media (max-width: 480px) {
    .main-title { font-size: 3.4rem; }
    .vs-label { font-size: 0.95rem; }
}

@media (max-width: 350px) {
    .main-title { font-size: 2.8rem; }
    .grid { grid-template-columns: repeat(3, minmax(50px, 70px)); }
    .col { padding: 6px; }
    .avatar-wrap { width: 40px; height: 40px; }
    .player-meta { font-size: 0.85rem; }
}