:root {
    --primary-color: #3498db;
    --secondary-color: #2c3e50;
    --success-color: #27ae60;
    --danger-color: #e74c3c;
    --bg-color: #ecf0f1;
    --message-bg: #ffffff;
    --admin-color: #9b59b6;
    --guest-color: #16a085;
    --border-radius: 8px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    width: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
    padding: 0;
}

.screen {
    width: 100%;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.hidden {
    display: none !important;
}

/* Login Screen - Minimal Design */
.login-container {
    background: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    max-width: 400px;
    width: 90%;
}

.login-container h1 {
    text-align: center;
    margin-bottom: 30px;
    color: var(--secondary-color);
    font-size: 28px;
}

.role-selection {
    margin-bottom: 20px;
}

.role-selection label {
    display: block;
    padding: 12px 16px;
    margin-bottom: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 500;
}

.role-selection label:hover {
    border-color: var(--primary-color);
    background: rgba(52, 152, 219, 0.05);
}

.role-selection input[type="radio"]:checked + span {
    color: var(--primary-color);
}

.role-selection label:has(input:checked) {
    border-color: var(--primary-color);
    background: rgba(52, 152, 219, 0.1);
}

.role-selection input[type="radio"] {
    margin-right: 10px;
}

.login-container input[type="password"] {
    width: 100%;
    padding: 14px;
    margin-bottom: 20px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s;
}

.login-container input[type="password"]:focus {
    outline: none;
    border-color: var(--primary-color);
}

.error-message {
    color: var(--danger-color);
    text-align: center;
    margin-top: 15px;
    font-size: 14px;
}

/* Chat Screen */
.chat-container {
    background: white;
    width: 100%;
    max-width: 800px;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

.chat-header {
    background: var(--secondary-color);
    color: white;
    padding: 15px 20px;
    padding-top: max(15px, env(safe-area-inset-top));
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
    position: relative;
    z-index: 100;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    z-index: 101;
}

.user-badge {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
}

.user-badge.admin {
    background: var(--admin-color);
}

.user-badge.guest {
    background: var(--guest-color);
}

.status-indicator {
    font-size: 12px;
    opacity: 0.85;
    font-weight: 500;
}

.status-indicator::before {
    content: '●';
    margin-right: 5px;
}

.status-indicator.online::before {
    color: var(--success-color);
}

.status-indicator.offline::before {
    color: #95a5a6;
}

/* Messages Area */
.messages-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    background: var(--bg-color);
    min-height: 0;
    overscroll-behavior: contain;
}

.message {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
}

.message.admin .message-bubble {
    background: var(--admin-color);
    align-self: flex-end;
    color: white;
}

.message.guest .message-bubble {
    background: var(--guest-color);
    align-self: flex-start;
    color: white;
}

.message-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 12px;
    background: var(--message-bg);
    color: var(--secondary-color);
    word-wrap: break-word;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.message-header {
    font-size: 12px;
    opacity: 0.9;
    margin-bottom: 4px;
    font-weight: 600;
}

.message-text {
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message-text a {
    color: inherit;
    text-decoration: underline;
    font-weight: 600;
    word-break: break-all;
}

.message-text a:hover {
    text-decoration: none;
    opacity: 0.8;
}

.message-footer {
    display: flex;
    align-items: center;
    margin-top: 5px;
    font-size: 11px;
    opacity: 0.8;
}

.message-time {
    font-size: 11px;
    opacity: 0.9;
}

.message-delete-info {
    font-size: 10px;
    opacity: 0.7;
    font-style: italic;
}

/* Call Controls - Minimal Modern Design */
.call-controls {
    background: linear-gradient(135deg, #1f1f2e 0%, #15172b 100%);
    padding: 20px;
    border-radius: var(--border-radius) var(--border-radius) 0 0;
}

.call-info {
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

#callStatus {
    font-weight: 500;
    font-size: 14px;
}

#callTimer {
    font-weight: 600;
    font-size: 16px;
    color: var(--success-color);
}

.call-videos {
    position: relative;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

#remoteVideo {
    width: 100%;
    height: 400px;
    object-fit: cover;
    background: linear-gradient(135deg, #1a1a2e 0%, #0f1419 100%);
}

#localVideo {
    position: absolute;
    bottom: 15px;
    right: 15px;
    width: 140px;
    height: 105px;
    object-fit: cover;
    border: 3px solid rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    transition: all 0.3s ease;
}

#localVideo:hover {
    transform: scale(1.05);
    border-color: var(--primary-color);
}

.call-buttons {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    padding: 10px;
}

/* Input Area */
.input-area {
    background: white;
    padding: 15px;
    border-top: 1px solid #e0e0e0;
    flex-shrink: 0;
    min-height: 0;
}

.message-input-container {
    display: flex;
    gap: 10px;
}

#messageInput {
    flex: 1;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 15px;
    resize: none;
    font-family: inherit;
    transition: border-color 0.3s;
}

#messageInput:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Buttons - Modern Minimal Design */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 600;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: #2980b9;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover {
    background: #229954;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(39, 174, 96, 0.3);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #c0392b;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3);
}

.btn-small {
    padding: 8px 16px;
    font-size: 14px;
}

.btn-round {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    font-size: 24px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.btn-round:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.btn-round:active {
    transform: translateY(-1px);
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    font-size: 20px;
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    color: white;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    z-index: 10;
    pointer-events: auto;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.6);
    transform: scale(1.08);
}

.btn-icon:active {
    transform: scale(0.97);
}

/* Offline state for call buttons - visual feedback instead of disabled */
.btn-icon.user-offline {
    opacity: 0.5;
    border-color: rgba(255, 255, 255, 0.15);
}

.btn-icon.user-offline:hover {
    background: rgba(231, 76, 60, 0.15);
    border-color: rgba(231, 76, 60, 0.5);
    opacity: 0.7;
}

.btn-icon svg {
    display: block;
    width: 20px;
    height: 20px;
    pointer-events: none;
}

.btn-icon#logoutBtn {
    border-color: rgba(231, 76, 60, 0.4);
}

.btn-icon#logoutBtn:hover {
    background: rgba(231, 76, 60, 0.2);
    border-color: rgba(231, 76, 60, 0.8);
}

.btn-secondary {
    background: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

/* Modal - Modern Design */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
}

.modal-content {
    background: white;
    padding: 32px;
    border-radius: 16px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-content h2 {
    margin-bottom: 16px;
    color: var(--secondary-color);
    font-size: 22px;
}

.modal-content p {
    margin-bottom: 12px;
    font-size: 16px;
    color: #555;
}

.modal-content p span {
    font-weight: 600;
    color: var(--primary-color);
}

.call-type {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 18px;
}

.modal-buttons {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.modal-buttons .btn {
    flex: 1;
}

/* Responsive - Enhanced Mobile Experience */
@media (max-width: 768px) {
    html {
        height: 100%;
        overflow: hidden;
    }
    
    body {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        top: 0;
        left: 0;
        display: block;
        justify-content: unset;
        align-items: unset;
    }
    
    .chat-container {
        max-width: 100%;
        border-radius: 0;
        height: 100vh;
        height: 100dvh;
        max-height: -webkit-fill-available;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
    
    .chat-header {
        padding: 12px 15px;
        flex-wrap: wrap;
    }
    
    .user-info {
        gap: 10px;
        flex: 1;
    }
    
    .user-badge {
        font-size: 12px;
        padding: 5px 12px;
    }
    
    .status-indicator {
        font-size: 11px;
    }
    
    .header-actions {
        display: flex;
        gap: 8px;
        flex-wrap: nowrap;
    }
    
    .btn-icon {
        width: 38px;
        height: 38px;
        border-width: 1.5px;
    }
    
    .btn-icon svg {
        width: 18px;
        height: 18px;
    }
    
    /* Call UI Mobile Optimizations */
    .call-controls {
        padding: 15px;
    }
    
    .call-info {
        font-size: 13px;
        padding: 10px 12px;
    }
    
    #callStatus {
        font-size: 12px;
    }
    
    #callTimer {
        font-size: 14px;
    }
    
    #remoteVideo {
        height: 300px;
        border-radius: 10px;
    }
    
    #localVideo {
        width: 100px;
        height: 75px;
        bottom: 10px;
        right: 10px;
        border-width: 2px;
        border-radius: 10px;
    }
    
    .call-buttons {
        gap: 15px;
        padding: 5px;
    }
    
    .btn-round {
        width: 55px;
        height: 55px;
        font-size: 22px;
    }
    
    /* Messages for mobile */
    .messages-area {
        padding: 15px 10px;
        flex: 1 1 auto;
        min-height: 0;
    }
    
    .message-bubble {
        max-width: 85%;
        font-size: 14px;
        padding: 10px 14px;
    }
    
    /* Input area mobile */
    .input-area {
        padding: 10px;
        padding-bottom: max(15px, env(safe-area-inset-bottom));
        flex-shrink: 0;
        flex-grow: 0;
        min-height: fit-content;
        position: relative;
    }
    
    .message-input-container {
        gap: 8px;
    }
    
    #messageInput {
        padding: 10px;
        font-size: 15px;
    }
    
    .btn-primary {
        padding: 10px 20px;
        font-size: 15px;
    }
    
    /* Login screen mobile */
    .login-container {
        padding: 32px 24px;
    }
    
    .login-container h1 {
        font-size: 24px;
        margin-bottom: 24px;
    }
    
    /* Modal mobile */
    .modal-content {
        padding: 28px 22px;
        width: 88%;
    }
    
    .modal-content h2 {
        font-size: 20px;
    }
}

/* Extra small mobile devices  */
@media (max-width: 400px) {
    .header-actions {
        width: 100%;
        justify-content: space-around;
        margin-top: 8px;
    }
    
    .btn-icon {
        width: 36px;
        height: 36px;
    }
    
    #remoteVideo {
        height: 250px;
    }
    
    #localVideo {
        width: 85px;
        height: 64px;
    }
    
    .btn-round {
        width: 52px;
        height: 52px;
        font-size: 20px;
    }
    
    .call-buttons {
        gap: 12px;
    }
    
    .tictactoe-board {
        width: 260px;
        height: 260px;
    }
    
    .tictactoe-cell {
        font-size: 32px;
    }
}

/* Game Panel Styles */
.game-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
    z-index: 999;
    animation: slideInRight 0.3s ease;
    overflow: hidden;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.game-panel-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, #2980b9 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.game-panel-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.btn-close {
    background: transparent;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s;
    line-height: 1;
    padding: 0;
}

.btn-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

.game-content {
    padding: 20px;
}

.game-status {
    text-align: center;
    font-size: 15px;
    font-weight: 600;
    color: var(--secondary-color);
    margin-bottom: 20px;
    padding: 12px;
    background: var(--bg-color);
    border-radius: 8px;
    min-height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tictactoe-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-gap: 8px;
    margin: 0 auto 20px;
    width: 300px;
    height: 300px;
    background: var(--bg-color);
    padding: 8px;
    border-radius: 12px;
}

.tictactoe-cell {
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    -webkit-user-select: none;
    user-select: none;
}

.tictactoe-cell:hover:not(.taken) {
    background: rgba(52, 152, 219, 0.1);
    border-color: var(--primary-color);
    transform: scale(1.05);
}

.tictactoe-cell.taken {
    cursor: not-allowed;
}

.tictactoe-cell.player-x {
    color: var(--primary-color);
}

.tictactoe-cell.player-o {
    color: var(--danger-color);
}

.tictactoe-cell.winning-cell {
    background: linear-gradient(135deg, var(--success-color) 0%, #27ae60 100%);
    color: white;
    animation: winningPulse 0.6s ease-in-out;
}

@keyframes winningPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

.game-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.game-actions .btn {
    flex: 1;
    max-width: 200px;
}

/* Game Panel Mobile Responsive */
@media (max-width: 768px) {
    .game-panel {
        bottom: 10px;
        right: 10px;
        left: 10px;
        width: auto;
        max-width: 400px;
        margin: 0 auto;
    }
    
    .tictactoe-board {
        width: 280px;
        height: 280px;
    }
    
    .tictactoe-cell {
        font-size: 42px;
    }
}

@media (max-width: 400px) {
    .game-panel {
        bottom: 5px;
        right: 5px;
        left: 5px;
    }
    
    .game-content {
        padding: 15px;
    }
    
    .tictactoe-board {
        width: 260px;
        height: 260px;
    }
    
    .tictactoe-cell {
        font-size: 36px;
    }
    
    .game-status {
        font-size: 13px;
        padding: 10px;
        min-height: 40px;
    }
}
