/* ==========================================================================
   TIC-TAC-TOE PRO ULTIMATE - MAIN STYLESHEET (V6.4 Enterprise)
   Description: Global styles, layout, animations, and UI components.
   Features: Responsive design, glassmorphism, animations, and mobile fixes.
   Fixes: Symmetrical camera alignment, dynamic viewport heights, elastic buttons.
   Language: 100% English Enforcement.
   ========================================================================== */

/* --- 1. CSS VARIABLES & ROOT SETTINGS --- */
:root { 
    /* Core Color Palette */
    --bg-dark: #1a1a24; 
    --bg-light: #3a3a4f;
    --primary: #670185; 
    --secondary: #430053; 
    --success: #28a745; 
    --danger: #ff2c2c; 
    --warning: #ffc107;
    
    /* Glassmorphism base color */
    --glass: rgba(255, 255, 255, 0.1);
}

/* Global Reset and Base Typography */
* { 
    margin: 0; 
    padding: 0; 
    box-sizing: border-box; 
    user-select: none; /* Prevents text selection during fast gameplay */
    -webkit-tap-highlight-color: transparent; /* Removes blue tap highlight on mobile */
    text-shadow: 0 1px 3px rgba(0,0,0,0.7); /* Subtle global text shadow for depth */
}

body { 
    background-color: #000; 
    overflow: hidden; /* Prevents unwanted scrolling on the main view */
    font-family: 'Roboto', sans-serif; 
    color: white; 
}

/* Utility class to hide elements dynamically via JS */
.hidden { display: none !important; }


/* --- 2. GLOBAL ANIMATIONS --- */

/* Basic fade in for UI elements */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-15px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Smooth fade out for alerts and temporary elements */
@keyframes fadeOut { 
    to { opacity: 0; visibility: hidden; } 
}


/* --- 3. MAIN LAYOUT CONTAINERS --- */

/* The central app wrapper, constrained for mobile-first feel */
#app-container {
    width: 100%; 
    max-width: 500px; 
    height: 100vh; /* Fallback */
    height: 100dvh; /* Modern dynamic viewport height */
    margin: 0 auto;
    position: relative; 
    overflow-y: auto; 
    overflow-x: hidden;
    background: transparent; /* Allows background animations to show through */
    display: flex; 
    flex-direction: column; 
    align-items: center;
}


/* --- 4. RIPPLE EFFECT (MATERIAL DESIGN) --- */

/* Base button setup to contain the ripple */
button {
    position: relative;
    overflow: hidden; 
}

/* The ripple element itself (injected via JS) */
.ripple-span {
    position: absolute;
    border-radius: 50%;
    transform: scale(0);
    animation: ripple-anim 0.6s linear;
    background-color: rgba(255, 255, 255, 0.4);
    pointer-events: none; /* Prevents the ripple from blocking subsequent clicks */
}

@keyframes ripple-anim {
    to { transform: scale(4); opacity: 0; }
}


/* --- 5. BACKGROUND ANIMATION EFFECTS --- */

/* Sliding Diagonals (Used in Login, Register, and Lobby) */
.sliding-bg {
    animation: slide 3s ease-in-out infinite alternate;
    background-image: linear-gradient(-60deg, #430053 50%, #09f 50%); 
    bottom: 0; left: -50%; opacity: .5; position: fixed; right: -50%; top: 0; z-index: -1;
    display: none; /* Managed by JS based on current screen */
}
.sliding-bg.bg2 { animation-direction: alternate-reverse; animation-duration: 4s; }
.sliding-bg.bg3 { animation-duration: 5s; }

@keyframes slide {
    0% { transform: translateX(-25%); }
    100% { transform: translateX(25%); }
}

/* Floating X and O Canvas (Used in Match Screen) */
#matchCanvas {
    width: 100%; height: 100%; background: transparent; 
    position: fixed; top: 0; left: 0; z-index: -1;
    display: none; /* Managed by JS */
}


/* --- 6. TOP NAVIGATION BAR --- */
.top-bar { 
    width: 100%; 
    display: none; /* Hidden on auth screens */
    justify-content: space-between; 
    align-items: center; 
    padding: 10px 20px; 
    z-index: 10; 
    position: sticky; 
    top: 0; 
    background: rgba(26,26,36,0.8); 
    backdrop-filter: blur(10px); 
}

.btn-icon { 
    width: 40px; height: 40px; border-radius: 50%; 
    background: var(--glass); border: 1px solid rgba(255,255,255,0.2); 
    display: flex; align-items: center; justify-content: center; 
    color: white; font-size: 1.1rem; cursor: pointer; transition: 0.2s; 
    flex-shrink: 0;
}
.btn-icon:active { transform: scale(0.9); }

.online-tag { 
    background: rgba(40,167,69,0.2); color: #00ff00; padding: 6px 12px; 
    border-radius: 20px; font-size: 0.8rem; font-weight: bold; border: 1px solid #00ff00; 
}


/* --- 7. SCREEN CONTROLLERS --- */
.app-screen { 
    display: none; flex-direction: column; align-items: center; justify-content: center; 
    width: 100%; padding: 15px; flex: 1; z-index: 2; 
}
.app-screen.active { display: flex; }


/* --- 8. AUTHENTICATION & FORMS UI --- */
.logo-title { font-family: 'Oswald', sans-serif; font-size: 4.5rem; text-align: center; line-height: 1; margin: 10px 0; text-shadow: 0 5px 15px rgba(0,0,0,0.5); color: white;}
.subtitle { font-family: 'Oswald', sans-serif; font-size: 1.5rem; text-align: center; color: #00ff00; letter-spacing: 2px; margin-bottom: 20px; text-shadow: 0 2px 5px rgba(0,0,0,0.5); }

/* Glassmorphism Panel for Login/Register */
.auth-box, .lobby-box { 
    background: rgba(255, 255, 255, 0.05); width: 100%; padding: 25px 20px; border-radius: 20px; 
    border: 1px solid rgba(255,255,255,0.2); backdrop-filter: blur(15px); -webkit-backdrop-filter: blur(15px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5); animation: fadeIn 0.4s ease; 
}

.auth-title { font-family: 'Oswald', sans-serif; font-size: 1.8rem; text-align: center; margin-bottom: 15px; letter-spacing: 1px; color: #ffd700; text-shadow: 0 2px 5px rgba(0,0,0,0.5); }

.input-group { margin-bottom: 12px; width: 100%; }

/* High-contrast Input Fields */
.input-group input { 
    width: 100%; padding: 12px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.4); 
    background: rgba(0,0,0,0.6); color: white; font-size: 1rem; outline: none; transition: 0.3s; 
    font-weight: bold; letter-spacing: 1px; 
}
.input-group input::placeholder { color: rgba(255,255,255,0.7); font-weight: normal; }
.input-group input:focus { border-color: var(--success); background: rgba(0,0,0,0.8); }

/* Global Action Buttons */
.btn-primary, .btn-success, .btn-danger, .btn-warning { 
    border: none; padding: 12px 30px; font-size: 1.1rem; font-family: 'Oswald', sans-serif; 
    border-radius: 50px; cursor: pointer; box-shadow: 0 5px 15px rgba(0,0,0,0.3); transition: 0.2s; 
    width: 100%; margin-top: 10px; letter-spacing: 1px;
    flex-shrink: 0; /* Prevents buttons from being squished on small mobile screens */
}
.btn-primary { background: var(--primary); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: black; font-weight: bold;}
.btn-primary:active, .btn-success:active, .btn-danger:active, .btn-warning:active { transform: scale(0.95); }

/* Secondary (Outline) Buttons */
.btn-secondary { 
    background: rgba(0,0,0,0.3); color: white; border: 1px solid rgba(255,255,255,0.3); 
    padding: 12px; font-size: 1rem; font-family: 'Oswald', sans-serif; border-radius: 50px; 
    cursor: pointer; transition: 0.2s; width: 100%; margin-top: 15px; letter-spacing: 1px;
    flex-shrink: 0;
}
.btn-secondary:hover { border-color: white; background: rgba(255,255,255,0.2); }
.btn-secondary:active { transform: scale(0.95); }

/* Fixed Footer Text */
.footer-text { 
    position: fixed; bottom: 15px; left: 0; width: 100%; font-size: 0.85rem; 
    color: rgba(255,255,255,0.6); letter-spacing: 1px; font-family: 'Roboto', sans-serif; 
    text-align: center; z-index: 1000; pointer-events: none; 
}


/* --- 9. LOBBY SCREEN COMPONENTS --- */
#screen-lobby { justify-content: flex-start; }

/* Interactive Profile Picture Uploader */
.upload-avatar-wrapper { position: relative; margin-bottom: 20px; cursor: pointer; }
.upload-avatar-wrapper img { width: 100px; height: 100px; border-radius: 50%; border: 3px solid white; object-fit: cover; background: #333; }
.upload-avatar-wrapper .edit-icon { position: absolute; bottom: 0; right: 0; background: var(--primary); padding: 8px; border-radius: 50%; font-size: 0.8rem; }
#fileAvatar { display: none; }

/* Lobby Dashboard Panels */
.card-panel { 
    background: rgba(255, 255, 255, 0.05); width: 100%; padding: 15px; border-radius: 15px; margin-top: 15px; 
    border: 1px solid rgba(255,255,255,0.15); backdrop-filter: blur(10px); box-shadow: 0 8px 25px rgba(0,0,0,0.5); 
}
.card-panel h3 { font-family: 'Oswald'; margin-bottom: 5px; color: #ffd700; font-size: 1.1rem; }

/* Share Button */
.btn-share { 
    background: var(--primary); width: 100%; padding: 8px; border: none; border-radius: 10px; 
    color: white; font-weight: bold; cursor: pointer; display: flex; justify-content: center; gap: 10px; align-items: center; transition: 0.2s;
}
.btn-share:active { transform: scale(0.95); }

/* Favorites List Items */
.fav-item { display: flex; justify-content: space-between; align-items: center; background: rgba(0,0,0,0.3); padding: 10px; border-radius: 10px; margin-bottom: 5px; }
.fav-status { font-size: 0.7rem; font-weight: bold; padding: 3px 8px; border-radius: 10px; text-shadow: none; }

/* Dynamic Status Colors */
.status-online { background: rgba(40,167,69,0.2); color: #00ff00; }
.status-offline { background: rgba(255,255,255,0.1); color: #aaa; }
.status-playing { background: rgba(255,193,7,0.2); color: #ffc107; } 


/* --- 10. MATCH SCREEN COMPONENTS --- */
#screen-match { justify-content: flex-start; padding: 5px 10px 10px 10px; } 

/* Camera Layout */
.camera-grid { display: flex; justify-content: space-between; width: 100%; gap: 10px; margin-bottom: 5px; }
.player-box { width: 48%; display: flex; flex-direction: column; align-items: center; position: relative; }

/* FIX: Forces the names and trophies to bottom-align, ensuring cameras never mismatch in height */
.header-labels { 
    width: 100%; 
    display: flex; 
    justify-content: space-between; 
    align-items: flex-end; 
    min-height: 35px; 
    font-size: 0.7rem; 
    font-weight: bold; 
    margin-bottom: 5px; 
    text-shadow: 0 2px 4px rgba(0,0,0,0.8); 
}

/* WebRTC Video Containers */
.cam-container { 
    width: 100%; aspect-ratio: 1/1; max-height: 100px; background: #000; border-radius: 12px; 
    border: 3px solid rgba(255,255,255,0.2); overflow: hidden; position: relative; transition: 0.3s; box-shadow: 0 8px 20px rgba(0,0,0,0.7); 
}
.cam-container.active-turn { border-color: #00ff00; box-shadow: 0 0 15px rgba(0,255,0,0.5); }
.cam-container.winner-box { border-color: #ffd700 !important; box-shadow: 0 0 25px rgba(255, 215, 0, 0.8) !important; } 
.cam-container video, .cam-container img.avatar-view { width: 100%; height: 100%; object-fit: cover; position: absolute; top:0; left:0; }

/* Z-Index mapping to ensure fallback image hides behind active video */
.avatar-view { z-index: 1; }
video { z-index: 2; }

/* Camera Toggle Buttons */
.cam-controls { position: absolute; bottom: 5px; right: 5px; display: flex; gap: 5px; z-index: 5; }
.cam-btn { background: rgba(0,0,0,0.6); color: white; border: none; border-radius: 50%; width: 25px; height: 25px; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 0.7rem; }
.cam-btn.muted { background: var(--danger); }

/* Yellow Cards UI */
.cards-bar { display: flex; gap: 3px; position: absolute; bottom: 5px; left: 5px; z-index: 5;}
.card { width: 8px; height: 12px; background: rgba(255,255,255,0.3); border-radius: 3px; border: 1px solid rgba(0,0,0,0.5); }
.card.yellow { background: var(--warning); box-shadow: 0 0 5px var(--warning);}

.turn-text { color: #00ff00; font-family: 'Oswald', sans-serif; font-size: 1rem; margin-top: 3px; height: 20px; text-transform: uppercase; text-shadow: 0 2px 4px rgba(0,0,0,0.8); }

/* Emote Interaction Bar */
.emote-bar { display: flex; justify-content: center; gap: 10px; width: 100%; margin: 5px 0 10px 0; background: rgba(255,255,255,0.1); padding: 5px; border-radius: 15px; backdrop-filter: blur(5px); }
.emote-btn { background: transparent; border: none; font-size: 1.5rem; cursor: pointer; transition: 0.2s; filter: drop-shadow(0 2px 5px rgba(0,0,0,0.5));}
.emote-btn:active { transform: scale(1.3); }

/* Turn Timer Progress Bar */
.progress-wrapper { width: 100%; height: 6px; background: rgba(0,0,0,0.5); border-radius: 10px; margin-bottom: 8px; overflow: hidden; border: 1px solid rgba(255,255,255,0.1); }
.progress-fill { width: 100%; height: 100%; background: #00ff00; transition: width 0.5s linear; }


/* --- 11. TIC-TAC-TOE BOARD --- */
.board-wrapper { 
    position: relative; 
    width: 100%; 
    max-width: 320px; 
    margin-bottom: 5px; 
    min-height: 420px; /* Essential padding for endgame screens */
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; width: 100%; }

/* Individual Playable Cells */
.cell { 
    aspect-ratio: 1; 
    background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0.02) 100%); 
    border: 2px solid rgba(255,255,255,0.25); border-radius: 12px; 
    display: flex; align-items: center; justify-content: center; cursor: pointer; 
    box-shadow: 0 5px 15px rgba(0,0,0,0.4); backdrop-filter: blur(5px); 
    transition: transform 0.2s, box-shadow 0.2s;
}
.cell:active { transform: scale(0.92); box-shadow: 0 2px 5px rgba(0,0,0,0.6); }

/* Elastic Pop Animation for new pieces */
@keyframes elastic-pop {
    0% { transform: scale(0.2); opacity: 0; }
    60% { transform: scale(1.2); opacity: 1; }
    80% { transform: scale(0.9); }
    100% { transform: scale(1); }
}

/* Span injected by JS to hold the animated Piece (X or O) */
.cell span {
    font-size: 4.5rem; /* Huge pieces */
    font-family: 'Oswald', sans-serif;
    display: inline-block;
    animation: elastic-pop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* Piece Specific Styling */
.cell[data-value="X"] span { color: #ffeb3b; text-shadow: 0 0 15px rgba(255,235,59,0.8); }
.cell[data-value="O"] span { color: #00e5ff; text-shadow: 0 0 15px rgba(0,229,255,0.8); }

/* End Game Overlay Panel */
.board-overlay { 
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; 
    background: rgba(0,0,0,0.85); border-radius: 12px; display: none; 
    flex-direction: column; align-items: center; justify-content: flex-start; /* Changed to allow safe scrolling */
    gap: 10px; padding: 20px 15px; z-index: 20; backdrop-filter: blur(4px); 
    animation: fadeIn 0.3s; 
    overflow-y: auto; /* Allows scrolling if content exceeds height on mobile */
}
#matchResultTitle { 
    font-family: 'Oswald'; font-size: 2.2rem; margin-bottom: 5px; 
    margin-top: auto; /* Self-centering trick */
    text-shadow: 0 4px 10px rgba(0,0,0,0.8); text-align: center; 
    flex-shrink: 0;
}


/* --- 12. SIDE MENU & CUSTOM MODALS --- */

/* Modal Overlays */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.85); z-index: 3000; display: none; align-items: center; justify-content: center; backdrop-filter: blur(5px); opacity: 0; transition: opacity 0.3s; }
.modal-overlay.show { display: flex; opacity: 1; }

.modal-box { background: linear-gradient(135deg, var(--bg-light), var(--bg-dark)); padding: 25px; border-radius: 20px; width: 90%; max-width: 400px; text-align: center; border: 1px solid rgba(255,255,255,0.2); transform: translateY(50px); transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); box-shadow: 0 20px 40px rgba(0,0,0,0.5); }
.modal-overlay.show .modal-box { transform: translateY(0); }
.modal-box h2 { font-family: 'Oswald'; font-size: 1.8rem; margin-bottom: 10px; }
.modal-box p { font-size: 0.9rem; opacity: 0.8; margin-bottom: 20px; line-height: 1.4; }
.modal-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* Side Menu Sliding Panel */
.menu-backdrop { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); z-index: 1999; opacity: 0; pointer-events: none; transition: opacity 0.4s; backdrop-filter: blur(3px); }
.menu-backdrop.show { opacity: 1; pointer-events: auto; }

/* Mobile Menu Constraints */
#side-menu { 
    position: fixed; 
    top: 0; 
    left: -100%; 
    width: 100%; 
    max-width: 300px; 
    height: 100vh; /* Fallback */
    height: 100dvh; /* Dynamic Viewport Height prevents mobile address bar from hiding bottom elements */
    background: linear-gradient(to bottom, #670185, #430053); 
    z-index: 2000; 
    transition: left 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94); 
    padding: 25px 20px; 
    overflow-y: auto !important; /* Forces scrollability */
    padding-bottom: 80px !important; 
    border-right: 1px solid rgba(255,255,255,0.1); 
    box-shadow: 10px 0 30px rgba(0,0,0,0.5); 
    display: flex; 
    flex-direction: column; 
}
#side-menu.open { left: 0; }

.menu-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-shrink: 0; }

/* Menu Statistics Grid */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 20px; flex-shrink: 0;}
.stat-card { background: rgba(0,0,0,0.2); padding: 10px; border-radius: 12px; text-align: center; }
.stat-val { font-family: 'Oswald'; font-size: 1.5rem; display: block; }

/* CSS Toggle Switches */
.switch { position: relative; display: inline-block; width: 45px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(255,255,255,0.2); transition: .4s; border-radius: 34px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--success); }
input:checked + .slider:before { transform: translateX(21px); }
.setting-row { display: flex; justify-content: space-between; margin-bottom: 12px; font-size: 1rem; flex-shrink: 0; }

/* Floating Emote Animation */
.floating-emote { position: absolute; font-size: 3rem; z-index: 50; pointer-events: none; animation: floatUp 2s forwards ease-out; }
@keyframes floatUp { 
    0% { transform: translateY(0) scale(0.5); opacity: 0; } 
    20% { transform: translateY(-20px) scale(1.2); opacity: 1; } 
    100% { transform: translateY(-100px) scale(1); opacity: 0; } 
}

/* Utilities inside Menus & Modals */
#qrcode-canvas { background: white; padding: 10px; margin: 15px auto; display: inline-block; border-radius: 8px;}
.btn-logout-menu { margin-top: auto; margin-bottom: auto; padding: 12px; font-size: 1.1rem; background: var(--danger); flex-shrink: 0; }
.social-input { width: 100%; padding: 10px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.2); background: rgba(0,0,0,0.3); color: white; margin-bottom: 10px; outline: none; font-family: 'Roboto', sans-serif; flex-shrink: 0;}

/* ========================================================================
   V6: UI Animations (Rating System)
   ======================================================================== */

/* Bouncing animation for Like/Dislike buttons when clicked */
@keyframes bounceVote {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

.bouncing {
    animation: bounceVote 0.4s ease;
}