/* Основные стили */
:root {
    --primary: #4361ee;
    --primary-dark: #3a56d4;
    --secondary: #7209b7;
    --success: #4cc9f0;
    --danger: #f72585;
    --light: #f8f9fa;
    --dark: #212529;
    --gray: #6c757d;
    --border-radius: 12px;
    --box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: var(--dark);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: var(--box-shadow);
    overflow: hidden;
    min-height: 90vh;
}

.screen {
    display: none;
}

.screen.active {
    display: block;
}

.header {
    background: linear-gradient(to right, var(--primary), var(--secondary));
    color: white;
    padding: 25px;
    text-align: center;
    -webkit-user-select: none;
    user-select: none;
}

.header h1 {
    font-size: 2.2rem;
    margin-bottom: 10px;
    font-weight: 700;
}

.header h1 i {
    margin-right: 10px;
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

.room-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.room-code-display {
    background: rgba(255, 255, 255, 0.2);
    padding: 10px 20px;
    border-radius: var(--border-radius);
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    gap: 15px;
    -webkit-user-select: none;
    user-select: none;
}

.code {
    font-family: 'Courier New', Courier, monospace;
    font-weight: bold;
    letter-spacing: 2px;
    font-size: 1.8rem;
}

.btn-icon {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
}

.room-status {
    font-size: 1.2rem;
    font-weight: 500;
}

.content {
    padding: 25px;
}

.card {
    background: var(--light);
    border-radius: var(--border-radius);
    padding: 25px;
    margin-bottom: 25px;
    box-shadow: var(--box-shadow);
}

.card h2 {
    color: var(--primary);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

input[type="text"] {
    width: 100%;
    padding: 15px;
    border: 2px solid #ddd;
    border-radius: var(--border-radius);
    font-size: 1.1rem;
    margin-bottom: 20px;
    transition: all 0.3s;
    -webkit-appearance: none;
    appearance: none;
    font-family: inherit;
}

input[type="text"]:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2);
}

.actions {
    margin-top: 25px;
}

.btn {
    padding: 15px 30px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    font-family: inherit;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(67, 97, 238, 0.3);
}

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

.btn-secondary:hover {
    background: #5a6268;
    transform: translateY(-2px);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.btn-large {
    padding: 18px 30px;
    font-size: 1.2rem;
}

.btn-small {
    padding: 10px 20px;
    font-size: 0.9rem;
}

.divider {
    text-align: center;
    margin: 20px 0;
    position: relative;
}

.divider span {
    background: var(--light);
    padding: 0 15px;
    color: var(--gray);
    font-style: italic;
}

.divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: #dee2e6;
    z-index: -1;
}

.join-section {
    display: flex;
    gap: 10px;
}

.join-section input {
    flex: 1;
    font-size: 1.2rem;
    text-align: center;
    letter-spacing: 3px;
    font-family: 'Courier New', Courier, monospace;
}

.instructions {
    background: white;
    border-radius: var(--border-radius);
    padding: 20px;
    border-left: 5px solid var(--primary);
    margin-top: 25px;
    -webkit-user-select: none;
    user-select: none;
}

.instructions h3 {
    color: var(--primary);
    margin-bottom: 15px;
}

.instructions ol {
    padding-left: 20px;
}

.instructions li {
    margin-bottom: 10px;
    line-height: 1.6;
}

.tech-info {
    margin-top: 15px;
    padding: 10px;
    background: #e3f2fd;
    border-radius: 8px;
    border-left: 4px solid #2196f3;
    font-size: 0.9rem;
    color: #1565c0;
}

.tech-info i {
    margin-right: 8px;
}

.players-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 25px;
}

.player-item {
    background: white;
    padding: 20px;
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    gap: 15px;
    border: 2px solid #e9ecef;
    transition: all 0.3s;
    -webkit-user-select: none;
    user-select: none;
}

.player-item.host {
    border-color: #ff9f43;
    background: #fff9f0;
}

.player-item.you {
    border-color: var(--primary);
    background: #f0f4ff;
}

.player-avatar {
    width: 50px;
    height: 50px;
    background: linear-gradient(45deg, var(--primary), var(--secondary));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    font-weight: bold;
    flex-shrink: 0;
}

.player-info h4 {
    margin-bottom: 5px;
    word-break: break-word;
}

.player-badge {
    font-size: 0.8rem;
    padding: 3px 10px;
    border-radius: 12px;
    display: inline-block;
    margin-top: 5px;
}

.badge-host {
    background: #ff9f43;
    color: white;
}

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

.lobby-controls {
    display: flex;
    gap: 15px;
    margin-top: 25px;
    flex-wrap: wrap;
    justify-content: center;
}

.chat-messages {
    height: 200px;
    overflow-y: auto;
    background: white;
    border-radius: var(--border-radius);
    padding: 15px;
    margin-bottom: 15px;
    border: 1px solid #dee2e6;
    -webkit-overflow-scrolling: touch;
}

.message {
    margin-bottom: 10px;
    padding: 10px 15px;
    background: #f8f9fa;
    border-radius: 10px;
    border-left: 4px solid var(--primary);
    word-break: break-word;
    -webkit-user-select: none;
    user-select: none;
}

.message.system {
    background: #e3f2fd;
    border-left-color: #2196f3;
    font-style: italic;
}

.message .time {
    font-size: 0.8rem;
    color: var(--gray);
    margin-right: 10px;
}

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

.chat-input input {
    flex: 1;
    margin: 0;
}

.progress-container {
    margin: 25px 0;
}

.progress-bar {
    height: 10px;
    background: #e9ecef;
    border-radius: 5px;
    margin-bottom: 10px;
    overflow: hidden;
}

.progress {
    height: 100%;
    background: linear-gradient(to right, #4cd964, #5ac8fa);
    width: 0%;
    transition: width 0.5s ease;
}

.progress-text {
    text-align: center;
    color: var(--gray);
    font-weight: 500;
}

.writing-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin: 30px 0;
}

.info-box {
    background: white;
    padding: 20px;
    border-radius: var(--border-radius);
    text-align: center;
    -webkit-user-select: none;
    user-select: none;
}

.info-box h3 {
    color: var(--gray);
    margin-bottom: 10px;
    font-size: 1rem;
}

.player-name {
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--dark);
    word-break: break-word;
}

.highlight {
    color: var(--primary);
}

.word-input-section {
    margin: 30px 0;
}

#inputArea, #waitingArea {
    text-align: center;
}

#inputArea input {
    max-width: 400px;
    margin: 0 auto 20px;
    display: block;
    font-size: 1.3rem;
    text-align: center;
}

.hidden {
    display: none !important;
}

.waiting-message {
    padding: 30px;
    color: var(--gray);
    -webkit-user-select: none;
    user-select: none;
}

.waiting-message i {
    font-size: 2rem;
    margin-bottom: 15px;
    display: block;
}

.examples {
    text-align: center;
    color: var(--gray);
    margin-top: 25px;
    -webkit-user-select: none;
    user-select: none;
}

.example {
    display: inline-block;
    background: #e9ecef;
    padding: 5px 15px;
    border-radius: 20px;
    margin: 0 5px;
    font-style: italic;
}

.players-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.other-player {
    background: white;
    padding: 25px;
    border-radius: var(--border-radius);
    text-align: center;
    border: 2px solid #e9ecef;
    transition: all 0.3s;
    -webkit-user-select: none;
    user-select: none;
}

.other-player:hover {
    transform: translateY(-5px);
    box-shadow: var(--box-shadow);
}

.other-player h4 {
    color: var(--primary);
    margin-bottom: 15px;
    word-break: break-word;
}

.other-player .word {
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--dark);
    margin: 20px 0;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    word-break: break-word;
}

.game-controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 40px;
}

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

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    max-width: 500px;
    width: 90%;
    text-align: center;
}

.modal-content h2 {
    color: var(--primary);
    margin-bottom: 20px;
}

.modal-actions {
    margin-top: 30px;
}

.notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--primary);
    color: white;
    padding: 15px 25px;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    display: none;
    z-index: 1001;
    animation: slideIn 0.3s ease;
    max-width: 90%;
    word-break: break-word;
}

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

/* Стили для секретного слова */
.my-info {
    text-align: center;
    padding: 30px 0;
    -webkit-user-select: none;
    user-select: none;
}

.secret-word {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
}

.secret-word i {
    font-size: 3rem;
    color: #4361ee;
    opacity: 0.7;
}

.hint {
    color: var(--gray);
    font-style: italic;
    margin-top: 10px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: var(--border-radius);
    border-left: 4px solid var(--primary);
    word-break: break-word;
}

.hint-small {
    font-size: 0.9rem;
    color: #666;
    margin-top: 10px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 8px;
    text-align: center;
    word-break: break-word;
}

.connection-status {
    text-align: center;
    margin-top: 20px;
    padding: 10px;
    color: #28a745;
    background: #f0fff4;
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    -webkit-user-select: none;
    user-select: none;
}

.connection-status i {
    font-size: 1.2rem;
}

/* iOS специфичные стили */
@supports (-webkit-touch-callout: none) {
    body {
        padding: 10px;
        min-height: -webkit-fill-available;
    }
    
    .container {
        min-height: -webkit-fill-available;
        border-radius: 16px;
    }
    
    .btn {
        min-height: 44px; /* Минимальная высота для касания на iOS */
    }
    
    input[type="text"] {
        min-height: 44px; /* Минимальная высота для касания на iOS */
        font-size: 16px; /* Предотвращает увеличение в iOS */
    }
    
    .chat-input input {
        min-height: 44px;
    }
    
    #wordInput {
        font-size: 16px;
    }
}

/* Адаптивность */
@media (max-width: 768px) {
    .container {
        margin: 10px;
        border-radius: 15px;
    }
    
    .header {
        padding: 20px;
    }
    
    .header h1 {
        font-size: 1.8rem;
    }
    
    .room-header {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
    
    .content {
        padding: 15px;
    }
    
    .card {
        padding: 20px;
    }
    
    .writing-info {
        grid-template-columns: 1fr;
    }
    
    .players-list, .players-grid {
        grid-template-columns: 1fr;
    }
    
    .join-section {
        flex-direction: column;
    }
    
    .lobby-controls, .game-controls {
        flex-direction: column;
    }
    
    .lobby-controls .btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .room-code-display {
        font-size: 1.1rem;
        padding: 8px 15px;
    }
    
    .code {
        font-size: 1.4rem;
    }
    
    .writing-info {
        gap: 10px;
    }
    
    .info-box {
        padding: 15px;
    }
    
    .player-name {
        font-size: 1.4rem;
    }
    
    .examples {
        font-size: 0.9rem;
    }
    
    .example {
        padding: 3px 10px;
        margin: 0 3px;
    }
    
    .notification {
        left: 20px;
        right: 20px;
        width: auto;
    }
}

/* Предотвращение выделения на мобильных */
@media (hover: none) and (pointer: coarse) {
    .btn:hover {
        transform: none;
        box-shadow: none;
    }
    
    .player-item:hover, .other-player:hover {
        transform: none;
        box-shadow: none;
    }
}
/* Стили для предупреждений Safari */
.safari-warning {
    background: linear-gradient(135deg, #ff6b6b, #ff8e8e);
    color: white;
    padding: 15px;
    border-radius: var(--border-radius);
    margin: 15px 0;
    text-align: center;
    border-left: 5px solid #ff4757;
}

.safari-warning h4 {
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.safari-tips {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    color: #856404;
    padding: 12px;
    border-radius: 8px;
    margin-top: 10px;
    font-size: 0.9rem;
}

.safari-tips ul {
    margin: 5px 0 0 20px;
}

/* Анимация подключения для Safari */
.connecting-animation {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 20px;
}

.connecting-animation .dot {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    animation: pulse 1.5s infinite ease-in-out;
}

.connecting-animation .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.connecting-animation .dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes pulse {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.2); }
}

/* Мобильная оптимизация для Safari */
@supports (-webkit-touch-callout: none) {
    input, textarea, select {
        font-size: 16px !important; /* Предотвращает масштабирование в iOS */
    }
    
    .btn {
        -webkit-appearance: none; /* Убирает стили Safari по умолчанию */
    }
    
    .modal {
        padding: env(safe-area-inset-top) env(safe-area-inset-right) 
                env(safe-area-inset-bottom) env(safe-area-inset-left);
    }
}