/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --accent-color: #e74c3c;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --danger-color: #e74c3c;
    --dark-bg: #1a252f;
    --light-bg: #ecf0f1;
    --text-primary: #2c3e50;
    --text-light: #ffffff;
    --text-muted: #7f8c8d;
    --border-color: #bdc3c7;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.15);
    --border-radius: 8px;
    --transition: all 0.3s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.rtl {
    direction: rtl;
    font-family: 'Cairo', -apple-system, BlinkMacSystemFont, sans-serif;
}

.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    z-index: 1000;
}

.screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
    margin: 0 auto;
}

/* MOBILE VIEWPORT FIXES */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    min-height: 100vh;
    min-height: -webkit-fill-available; /* iOS fix */
    width: 100vw;
    overflow-x: hidden;
    position: relative;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: -webkit-fill-available; /* iOS fix */
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    z-index: 1000;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Loading Screen */
.loading-content {
    text-align: center;
    color: var(--text-light);
}

.logo {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.loading-title {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 2rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid var(--text-light);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Header Styles */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
    color: var(--text-light);
}

.header .logo {
    font-size: 2.5rem;
    margin: 0;
}

.header h1, .header h2 {
    flex: 1;
    text-align: center;
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}

.lang-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--text-light);
    padding: 8px 12px;
    border-radius: var(--border-radius);
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
}

.lang-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.back-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--text-light);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateX(-2px);
}

/* Form Styles */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-light);
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--border-radius);
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-light);
    font-size: 1rem;
    transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--text-light);
    background: rgba(255, 255, 255, 0.2);
}

.form-group input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

/* Button Styles */
.btn-primary,
.btn-secondary,
.btn-outline {
    width: 100%;
    padding: 14px 20px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    box-shadow: var(--shadow);
}

.btn-primary {
    background: var(--text-light);
    color: var(--primary-color);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: var(--secondary-color);
    color: var(--text-light);
}

.btn-secondary:hover {
    background: #2980b9;
    transform: translateY(-2px);
}

.btn-outline {
    background: transparent;
    color: var(--text-light);
    border: 2px solid rgba(255, 255, 255, 0.5);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--text-light);
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Menu Options */
.menu-options {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 2rem;
}

/* Rules Screen */
.rules-content {
    color: var(--text-light);
    max-height: 70vh;
    overflow-y: auto;
    padding-right: 10px;
}

.rule-section {
    margin-bottom: 2rem;
}

.rule-section h3 {
    font-size: 1.3rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid rgba(255, 255, 255, 0.3);
    padding-bottom: 0.5rem;
}

.role-card {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
    backdrop-filter: blur(10px);
}

.role-icon {
    font-size: 2rem;
    margin-right: 1rem;
}

body.rtl .role-icon {
    margin-right: 0;
    margin-left: 1rem;
}

.role-card h4 {
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
}

.role-card p {
    font-size: 0.9rem;
    opacity: 0.8;
    margin: 0;
}

/* Lobby Screen */
.lobby-header {
    text-align: center;
    margin-bottom: 2rem;
    color: var(--text-light);
}

.room-code {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    backdrop-filter: blur(10px);
}

.code {
    font-family: 'Courier New', monospace;
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 2px;
}

.copy-btn {
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 4px;
    border-radius: 4px;
    transition: var(--transition);
}

.copy-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.players-section {
    margin-bottom: 2rem;
}

.players-section h3 {
    color: var(--text-light);
    margin-bottom: 1rem;
    text-align: center;
}

.players-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.player-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.1);
    padding: 1rem;
    border-radius: var(--border-radius);
    color: var(--text-light);
    backdrop-filter: blur(10px);
}

.player-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.player-status {
    font-size: 0.8rem;
    opacity: 0.7;
}

.host-badge {
    background: var(--warning-color);
    color: var(--text-light);
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 12px;
    font-weight: 600;
}

/* Game Screen */
.game-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
    color: var(--text-light);
    backdrop-filter: blur(10px);
}

.phase-indicator {
    font-size: 1.1rem;
    font-weight: 600;
}

.timer {
    font-family: 'Courier New', monospace;
    font-size: 1.2rem;
    font-weight: 700;
}

.role-display {
    background: rgba(255, 255, 255, 0.1);
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
    color: var(--text-light);
    text-align: center;
    backdrop-filter: blur(10px);
}

.role-display .role-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.role-info h3 {
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.role-desc {
    font-size: 0.9rem;
    opacity: 0.8;
    margin-top: 0.5rem;
}

.game-content {
    margin-bottom: 1rem;
}

.phase-content {
    background: rgba(255, 255, 255, 0.1);
    padding: 1rem;
    border-radius: var(--border-radius);
    color: var(--text-light);
    backdrop-filter: blur(10px);
}

.phase-content h3 {
    margin-bottom: 1rem;
    text-align: center;
}

.voting-section h4 {
    margin-bottom: 1rem;
    font-size: 1rem;
}

.voting-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.vote-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.75rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
}

.vote-option:hover {
    background: rgba(255, 255, 255, 0.2);
}

.vote-option.selected {
    background: var(--accent-color);
}

.vote-option.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.vote-count {
    background: rgba(255, 255, 255, 0.3);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}

.night-actions {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.action-section h4 {
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.action-targets {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.target-option {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.75rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
}

.target-option:hover {
    background: rgba(255, 255, 255, 0.2);
}

.target-option.selected {
    background: var(--secondary-color);
}

.game-players h4 {
    color: var(--text-light);
    margin-bottom: 1rem;
    text-align: center;
}

.players-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.5rem;
}

.game-player-card {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.75rem;
    border-radius: var(--border-radius);
    text-align: center;
    color: var(--text-light);
    backdrop-filter: blur(10px);
    transition: var(--transition);
}

.game-player-card.dead {
   opacity: 0.5;
   background: rgba(231, 76, 60, 0.2);
}

.game-player-card.eliminated::after {
   content: "💀";
   position: absolute;
   top: 50%;
   left: 50%;
   transform: translate(-50%, -50%);
   font-size: 1.5rem;
}

.game-player-card {
   position: relative;
}

.player-name {
   font-size: 0.9rem;
   font-weight: 600;
   margin-bottom: 0.25rem;
}

.player-vote-status {
   font-size: 0.7rem;
   opacity: 0.7;
}

/* Results Display */
.results-display {
   background: rgba(255, 255, 255, 0.1);
   padding: 1rem;
   border-radius: var(--border-radius);
   margin-bottom: 1rem;
   color: var(--text-light);
   backdrop-filter: blur(10px);
   text-align: center;
}

.elimination-result {
   font-size: 1.1rem;
   margin-bottom: 1rem;
}

.elimination-result.no-elimination {
   color: var(--warning-color);
}

.elimination-result.elimination {
   color: var(--accent-color);
}

/* Game Over Screen */
.game-over-content {
   text-align: center;
   color: var(--text-light);
}

.game-over-content .logo {
   font-size: 5rem;
   margin-bottom: 1rem;
}

.winner-display {
   background: rgba(255, 255, 255, 0.1);
   padding: 1.5rem;
   border-radius: var(--border-radius);
   margin: 2rem 0;
   backdrop-filter: blur(10px);
}

.winner-display h2 {
   font-size: 1.5rem;
   margin-bottom: 0.5rem;
}

.winner-team {
   font-size: 1.2rem;
   font-weight: 600;
   margin-bottom: 1rem;
}

.winner-team.mafia {
   color: var(--accent-color);
}

.winner-team.village {
   color: var(--success-color);
}

.final-roles {
   background: rgba(255, 255, 255, 0.1);
   padding: 1rem;
   border-radius: var(--border-radius);
   margin-bottom: 2rem;
   backdrop-filter: blur(10px);
}

.final-roles h3 {
   margin-bottom: 1rem;
}

.final-role-list {
   display: flex;
   flex-direction: column;
   gap: 0.5rem;
}

.final-role-item {
   display: flex;
   justify-content: space-between;
   align-items: center;
   padding: 0.5rem;
   background: rgba(255, 255, 255, 0.1);
   border-radius: var(--border-radius);
}

/* Toast Messages */
.toast {
   position: fixed;
   top: 20px;
   left: 50%;
   transform: translateX(-50%);
   background: var(--dark-bg);
   color: var(--text-light);
   padding: 1rem 1.5rem;
   border-radius: var(--border-radius);
   box-shadow: var(--shadow-lg);
   z-index: 2000;
   max-width: 90%;
   transition: var(--transition);
}

.toast.hidden {
   opacity: 0;
   transform: translateX(-50%) translateY(-100%);
   pointer-events: none;
}

.toast-content {
   display: flex;
   align-items: center;
   justify-content: space-between;
   gap: 1rem;
}

.toast-close {
   background: none;
   border: none;
   color: var(--text-light);
   font-size: 1.2rem;
   cursor: pointer;
   padding: 0;
   opacity: 0.7;
}

.toast-close:hover {
   opacity: 1;
}

.toast.success {
   background: var(--success-color);
}

.toast.error {
   background: var(--danger-color);
}

.toast.warning {
   background: var(--warning-color);
}

/* Modal */
.modal {
   position: fixed;
   top: 0;
   left: 0;
   width: 100%;
   height: 100vh;
   background: rgba(0, 0, 0, 0.8);
   display: flex;
   align-items: center;
   justify-content: center;
   z-index: 3000;
   transition: var(--transition);
}

.modal.hidden {
   opacity: 0;
   visibility: hidden;
   pointer-events: none;
}

.modal-content {
   background: var(--text-light);
   padding: 2rem;
   border-radius: var(--border-radius);
   max-width: 90%;
   width: 300px;
   text-align: center;
   box-shadow: var(--shadow-lg);
}

.modal-content h3 {
   margin-bottom: 1rem;
   color: var(--text-primary);
}

.modal-content p {
   margin-bottom: 2rem;
   color: var(--text-muted);
}

.modal-buttons {
   display: flex;
   gap: 1rem;
   justify-content: center;
}

.modal-buttons .btn-primary,
.modal-buttons .btn-outline {
   width: auto;
   margin: 0;
   flex: 1;
}

/* Responsive Design */
@media (max-width: 480px) {
   .container {
       padding: 15px;
   }
   
   .header h1,
   .header h2 {
       font-size: 1.3rem;
   }
   
   .loading-title {
       font-size: 1.8rem;
   }
   
   .logo {
       font-size: 3rem;
   }
   
   .players-grid {
       grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
   }
   
   .game-player-card {
       padding: 0.5rem;
   }
   
   .player-name {
       font-size: 0.8rem;
   }
   
   .modal-content {
       padding: 1.5rem;
   }
   
   .room-code {
       flex-direction: column;
       gap: 0.75rem;
   }
}

/* Landscape orientation adjustments */
@media (max-height: 600px) and (orientation: landscape) {
   .container {
       max-width: 600px;
   }
   
   .game-content {
       max-height: 30vh;
       overflow-y: auto;
   }
   
   .rules-content {
       max-height: 50vh;
   }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
   .modal-content {
       background: var(--dark-bg);
       color: var(--text-light);
   }
   
   .modal-content h3 {
       color: var(--text-light);
   }
   
   .modal-content p {
       color: rgba(255, 255, 255, 0.7);
   }
}

/* Accessibility */
.btn-primary:focus,
.btn-secondary:focus,
.btn-outline:focus,
.vote-option:focus,
.target-option:focus {
   outline: 2px solid rgba(255, 255, 255, 0.8);
   outline-offset: 2px;
}

/* Animation for phase transitions */
.phase-content {
   animation: fadeInUp 0.5s ease;
}

@keyframes fadeInUp {
   from {
       opacity: 0;
       transform: translateY(20px);
   }
   to {
       opacity: 1;
       transform: translateY(0);
   }
}

/* Connection status indicator */
.connection-status {
   position: fixed;
   top: 10px;
   right: 10px;
   width: 12px;
   height: 12px;
   border-radius: 50%;
   z-index: 1001;
   transition: var(--transition);
}

.connection-status.connected {
   background: var(--success-color);
}

.connection-status.connecting {
   background: var(--warning-color);
   animation: pulse 1s infinite;
}

.connection-status.disconnected {
   background: var(--danger-color);
}

/* Install prompt */
.install-prompt {
   position: fixed;
   bottom: 20px;
   left: 20px;
   right: 20px;
   background: var(--text-light);
   color: var(--text-primary);
   padding: 1rem;
   border-radius: var(--border-radius);
   box-shadow: var(--shadow-lg);
   display: flex;
   align-items: center;
   justify-content: space-between;
   z-index: 1001;
   transform: translateY(100px);
   transition: var(--transition);
}

.install-prompt.show {
   transform: translateY(0);
}

.install-prompt button {
   background: var(--primary-color);
   color: var(--text-light);
   border: none;
   padding: 8px 16px;
   border-radius: var(--border-radius);
   cursor: pointer;
   font-weight: 600;
}

/* RTL Adjustments */
body.rtl .header {
   direction: rtl;
}

body.rtl .back-btn:hover {
   transform: translateX(2px);
}

body.rtl .players-grid {
   direction: rtl;
}

body.rtl .vote-option {
   direction: rtl;
}

body.rtl .player-card {
   direction: rtl;
}

body.rtl .final-role-item {
   direction: rtl;
}

/* Custom scrollbar */
.rules-content::-webkit-scrollbar,
.game-content::-webkit-scrollbar {
   width: 6px;
}

.rules-content::-webkit-scrollbar-track,
.game-content::-webkit-scrollbar-track {
   background: rgba(255, 255, 255, 0.1);
   border-radius: 3px;
}

.rules-content::-webkit-scrollbar-thumb,
.game-content::-webkit-scrollbar-thumb {
   background: rgba(255, 255, 255, 0.3);
   border-radius: 3px;
}

.rules-content::-webkit-scrollbar-thumb:hover,
.game-content::-webkit-scrollbar-thumb:hover {
   background: rgba(255, 255, 255, 0.5);
}

/* iOS SPECIFIC FIXES */
@supports (-webkit-touch-callout: none) {
    body {
        min-height: -webkit-fill-available;
    }
    
    .screen {
        height: -webkit-fill-available;
    }
}

/* Prevent zoom on input focus */
input, select, textarea {
    font-size: 16px !important; /* Prevents zoom on iOS */
}

/* Hide scrollbars but keep functionality */
body::-webkit-scrollbar,
.screen::-webkit-scrollbar {
    display: none;
}

body, .screen {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* ENHANCED VISUAL EFFECTS */
.container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
    margin: 0 auto;
    backdrop-filter: blur(20px);
    background: rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.btn-primary, .btn-secondary, .btn-outline {
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
    border-radius: 15px;
    font-size: 1.1rem;
    padding: 16px 24px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

.btn-primary:hover::before {
    left: 100%;
}

.logo {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: float 3s ease-in-out infinite;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
}

/* Add particle effect background */
.screen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: radial-gradient(2px 2px at 20px 30px, rgba(255,255,255,0.1), transparent),
                      radial-gradient(2px 2px at 40px 70px, rgba(255,255,255,0.05), transparent),
                      radial-gradient(1px 1px at 90px 40px, rgba(255,255,255,0.08), transparent);
    background-repeat: repeat;
    background-size: 200px 100px;
    animation: sparkle 8s linear infinite;
    pointer-events: none;
}

@keyframes sparkle {
    0% { transform: translateY(0px); }
    100% { transform: translateY(-100px); }
}