:root {
    --primary-color: #4a6bff;
    --secondary-color: #ff6b6b;
    --accent-color: #4ecdc4;
    --dark-color: #2d3436;
    --light-color: #f5f6fa;
    --success-color: #2ecc71;
    --warning-color: #f39c12;
    --danger-color: #e74c3c;
}

* {
    box-sizing: border-box;
}

html, body {
    overflow: hidden;
    width: 100%;
    height: 100svh;
    min-height: 100svh;
    margin: 0;
    padding: 0;
    position: fixed;
    overscroll-behavior: contain;
    font-family: 'Roboto', sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  }

.app-container {
    position: fixed;
    width: 100%;
    height: 100%;
    inset: 0;
    overflow: hidden;
    max-width: 800px;
    margin: 0 auto;
    padding: 
    calc(12px + env(safe-area-inset-top))
    calc(12px + env(safe-area-inset-right))
    calc(12px + env(safe-area-inset-bottom))
    calc(12px + env(safe-area-inset-left));
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.screen {
    display: none;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    animation: fadeIn 0.5s ease;
    position: absolute;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    overflow: hidden;
    top: 0;
    left: 0;
    transform: none;
    transform-origin: top center;
    will-change: transform;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.screen.active {
    display: block;
}

input, textarea {
    user-select: text;
    -webkit-user-select: text;
}

#game-title {
    display: flex;
    flex-direction: row;
    justify-content: center;
    margin: 0;
    font-size: clamp(1rem, 2.5vw, 1.5rem);;
}

img {
    -webkit-user-drag: none;
    pointer-events: none;
}

.title {
    display: flex;
    flex-direction: row;
    justify-content: center;
    margin-top: 20px;
    font-size: 1.3rem;
}

.countries-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    gap: 15px;
    margin: 30px 0;
    max-height: calc(100vh - 200px);
    padding-right: 5px;
}

.countries-grid::-webkit-scrollbar {
    width: 6px;
}

.countries-grid::-webkit-scrollbar-thumb {
    background-color: #4a6bff;
    border-radius: 3px;
}

.country-card {
    background: white;
    border-radius: 10px;
    box-sizing: border-box;
    padding: 15px;
    padding: 12px;
    flex: 1 1 150px;
    max-width: 200px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    font-size: 0.9rem;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
}

.country-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    border-color: var(--primary-color);
}

.country-card img {
    width: 60px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 8px;
}

#country-flag {
    width: 50px;
    height: 30px;
}

.language-selector {
    display: flex;
    flex-direction: row;
    justify-content: center;
    flex-wrap: wrap;
}

.lang-btn {
    margin: 5px;
    padding: 8px 12px;
    font-size: 0.9rem;
}

.game-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.game-header {
    display: flex;
    flex: 0 0 auto;
    justify-content: space-between;
    justify-items: center;
    align-items: center;
    flex-wrap: wrap;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
    color: white;
    padding: 10px 15px;
    border-radius: 10px;
    margin-bottom: 0;
    gap: 10px;
}

.game-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.9rem;
    min-width: 60px;
}

.game-content {
    height: auto;
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    margin: 0;
    overflow: hidden;
    flex-direction: column;
    justify-content: flex-start;
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

.keyboard-open .screen {
    transform: none !important;
  }

.hearts {
    display: flex;
    gap: 3px;
}

.heart {
    color: var(--danger-color);
    font-size: 1.2rem;
}

.country-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0;
    font-size: 0.9rem;
}

.last-city {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 15px 0;
    text-align: center;
    font-size: 1.2rem;
}

.current-letter-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 15px 0;
    font-size: 1.1rem;
    text-align: center;
}

.current-letter {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--secondary-color);
    color: white;
    font-size: 2rem;
    font-weight: 700;
    box-shadow: 0 3px 10px rgba(255, 107, 107, 0.4);
    line-height: 1;
    padding: 0;
    margin: 5px 0 0;
}

.input-group {
    display: flex;
    gap: 8px;
    margin-top: 15px;
    width: 100%;
}

input[type="text"] {
    flex: 1;
    padding: 10px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 0.9rem;
    min-width: 0;
}

button {
    padding: 10px 18px;
    border: none;
    border-radius: 25px;
    font-size: clamp(0.8rem, 2vw, 0.9rem);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    background-color: var(--primary-color);
    color: white;
    white-space: nowrap;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(74, 107, 255, 0.4);
}

.notification {
    position: fixed;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--dark-color);
    color: white;
    padding: 8px 16px;
    border-radius: 5px;
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 0.9rem;
    max-width: 90%;
    text-align: center;
    z-index: 1000;
}

.notification.show {
    opacity: 1;
}

.back-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px;
    margin-right: 5px;
    transition: opacity 0.3s;
}

.back-btn:hover {
    opacity: 0.8;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 15px;
}

.modal-content {
    background-color: #2c3e50;
    padding: 15px;
    border-radius: 8px;
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    width: 400px;
    text-align: center;
}

.modal-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
}

.modal-buttons button {
    margin: 0;
    padding: 8px 16px;
    font-size: 0.9rem;
}

#confirm-leave {
    background-color: #e74c3c;
}

#cancel-leave {
    background-color: #3498db;
}

.timer-paused {
    opacity: 0.7;
    position: relative;
}

.timer-paused::after {
    content: "⏸";
    position: absolute;
    right: -20px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1rem;
}

.progress-bar {
    display: flex;
    justify-content: flex-start;
    flex: 0 0 auto;
    width: 100%;
    height: 8px;
    background-color: #f0f0f0;
    border-radius: 4px;
    margin-top: 0;
    overflow: hidden;
}

.progress {
    height: 100%;
    margin: 0;
    display: flex;
    justify-content: flex-start;
    background-color: #4CAF50;
    width: 100%;
    transition: width 0.3s;
}

.reward-btn {
    background: linear-gradient(90deg, #ff9a44, #fc6076);
    border: none;
    color: white;
    padding: 8px 12px;
    border-radius: 20px;
    cursor: pointer;
    margin: 8px 0;
    transition: transform 0.2s;
    font-size: 0.9rem;
    width: 100%;
    max-width: 300px;
}

.reward-btn:hover {
    transform: scale(1.02);
}

.reward-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
}

.action-buttons button {
    width: 100%;
    max-width: 250px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Медиа-запросы для адаптации */
@media (max-width: 600px) {
    .app-container {
        padding: 10px;
    }
    
    .screen {
        padding: 15px;
    }
    
    #game-title {
        font-size: 1.3rem;
    }
    
    .title {
        font-size: 1.1rem;
        margin-top: 15px;
    }
    
    .countries-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
    
    .country-card {
        padding: 8px;
        font-size: 0.8rem;
    }
    
    .game-header {
        padding: 8px 10px;
        justify-content: center;
        gap: 15px;
    }
    
    .game-stat {
        min-width: 50px;
        font-size: 0.8rem;
    }
    
    .current-letter {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }
    
    .input-group {
        flex-direction: column;
    }
    
    button {
        width: 100%;
    }
    
    .back-btn {
        font-size: 1.1rem;
    }
}

.player-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
}

.player-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    display: none;
}

.leaderboard-container {
    margin-top: 20px;
    width: 100%;
    max-width: 400px;
}

.leaderboard {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    padding: 10px;
    max-height: 300px;
    overflow-y: auto;
}

.leaderboard-entry {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    margin: 4px 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
}

.leaderboard-position {
    font-weight: bold;
    min-width: 30px;
}

.leaderboard-name {
    flex-grow: 1;
    padding: 0 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.leaderboard-score {
    font-weight: bold;
    color: var(--accent-color);
}

@media (max-width: 400px) {
    .countries-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 10px;
    }
    .country-card {
        min-width: 120px;
    }
    
    .country-card img {
        width: 40px;
        height: 25px;
    }
    
    .game-header {
        gap: 10px;
    }

    .player-info {
        font-size: 0.8rem;
    }
    
    .player-avatar {
        width: 25px;
        height: 25px;
    }
    
    .leaderboard {
        max-height: 200px;
    }
}