:root {
    --primary-color: #3a7bd5;
    --primary-dark: #2c5fb3;
    --secondary-color: #00d2ff;
    --success-color: #4CAF50;
    --error-color: #f44336;
    --warning-color: #FFC107;
    --light-color: #f8f9fa;
    --dark-color: #212529;
    --text-color: #333;
    --text-light: #f8f9fa;
    --border-radius: 12px;
    --box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s ease;
    --font-main: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-mono: 'Courier New', monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    height: 100%;
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    font-family: var(--font-main);
    line-height: 1.5;
    color: var(--text-color);
    background-color: var(--light-color);
    height: 100%;
    overflow: hidden;
    touch-action: manipulation;
    overscroll-behavior: none;
        -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    touch-action: pan-y;
}

/* Основной контейнер викторины */
.quiz-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    background: white;
    position: relative;
}

/* Фиксированная шапка */
.quiz-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: var(--text-light);
    padding: 0.75rem 1rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    box-shadow: var(--box-shadow);
}

.quiz-header h1 {
    font-size: clamp(1.1rem, 4vw, 1.5rem);
    margin: 0;
    font-weight: 600;
    white-space: nowrap;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.timer-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.timer-display {
    font-family: var(--font-mono);
    font-size: clamp(0.9rem, 3vw, 1.2rem);
    font-weight: bold;
    background: rgba(255, 255, 255, 0.15);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    min-width: 6.5rem;
    text-align: center;
}

.best-score {
    font-weight: 600;
    color: var(--warning-color);
    background: rgba(255, 255, 255, 0.15);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    font-family: var(--font-mono);
    font-size: clamp(0.9rem, 3vw, 1rem);
}

.best-score span {
    color: var(--text-light);
}

.header-btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: var(--border-radius);
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    backdrop-filter: blur(5px);
    white-space: nowrap;
}

.header-btn:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

/* Основное содержимое */
.quiz-content {
    display: flex;
    flex: 1;
    height: calc(100vh - 70px);
    overflow: hidden;
    position: relative;
}

/* Боковые секции с прокруткой */
.scrollable-section {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.countries-section {
    width: 18rem;
    min-width: 18rem;
    border-right: 1px solid #e2e8f0;
    background: white;
}

.games-section {
    width: 16rem;
    min-width: 16rem;
    border-left: 1px solid #e2e8f0;
    background: #f1f5f9;
}

/* Контейнер списка стран */
.countries-table-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background-color: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 10;
}

.table-header h2 {
    font-size: 1.2rem;
    margin: 0;
    color: var(--dark-color);
    font-weight: 600;
}

.counter {
    font-weight: 700;
    color: var(--success-color);
    font-size: 1rem;
}

.table-controls {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 60px;
    z-index: 10;
    background: white;
}

.control-btn {
    padding: 0.75rem;
    width: 100%;
    border: none;
    border-radius: var(--border-radius);
    background-color: var(--warning-color);
    color: var(--dark-color);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.control-btn:hover {
    background-color: #ffb300;
}

.table-scroll-container {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

#countries-table {
    width: 100%;
    border-collapse: collapse;
}

#countries-list tr {
    transition: background-color 0.2s;
}

#countries-list td {
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    border-bottom: 1px solid #f1f5f9;
    text-align: center;
}

#countries-list td.guessed {
    background-color: #e6f7e9;
    color: var(--success-color);
    font-weight: 600;
}

/* Контейнер других игр */
.other-games-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 1rem;
}

.other-games-container h2 {
    font-size: 1.2rem;
    color: var(--dark-color);
    text-align: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--primary-color);
    position: sticky;
    top: 0;
    background: #f1f5f9;
    z-index: 10;
}

#other-games-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding-bottom: 1rem;
}

.game-btn {
    background: white;
    color: var(--dark-color);
    border: none;
    border-radius: var(--border-radius);
    padding: 0.75rem;
    cursor: pointer;
    text-align: center;
    transition: var(--transition);
    box-shadow: var(--box-shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.game-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
}

.game-btn img {
    width: 3.5rem;
    height: 3.5rem;
    border-radius: var(--border-radius);
    margin-bottom: 0.5rem;
    object-fit: cover;
}

.game-btn span {
    font-size: 0.9rem;
    font-weight: 500;
}

/* Основная область с картой */
.map-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    min-width: 0;
    overflow: hidden;
}

.input-container {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    width: 100%;
}

#country-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 2px solid #e2e8f0;
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: var(--transition);
    min-width: 0;
}

#country-input:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(0, 210, 255, 0.2);
}

#guess-button {
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

#guess-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

#result {
    min-height: 1.75rem;
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
    text-align: center;
    color: var(--error-color);
    font-weight: 500;
}

#map {
    flex: 1;
    border-radius: var(--border-radius);
    border: 1px solid #e2e8f0;
    background: white;
    min-height: 15rem;
    width: 100%;
    transition: transform 0.2s ease;
}

.disclaimer {
    font-size: 0.8em;
    color: #666;
    margin-top: 20px;
    font-style: italic;
}

.modal-body h3 {
    margin-top: 15px;
    color: #2c3e50;
}

/* Адаптация для Яндекс Игр с рекламным блоком */
@media (max-width: 1200px) {
    .quiz-content {
        flex-wrap: wrap;
    }
    
    .countries-section {
        width: 16rem;
        min-width: 16rem;
    }
    
    .games-section {
        width: 14rem;
        min-width: 14rem;
    }
}

@media (max-width: 1024px) {
    .quiz-content {
        flex-direction: column;
        height: auto;
    }

    .scrollable-section {
        width: 100%;
        min-width: 100%;
        height: auto;
        max-height: 15rem;
        border-right: none;
        border-left: none;
    }

    .countries-section {
        border-bottom: 1px solid #e2e8f0;
    }

    .games-section {
        border-top: 1px solid #e2e8f0;
        order: 3;
    }

    .map-section {
        order: 2;
        min-height: 20rem;
    }
}

@media (max-width: 900px) {
    .quiz-header {
        padding: 0.5rem;
    }
    
    .header-controls {
        gap: 0.5rem;
    }
    
    .header-btn {
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
    }
    
    .timer-display,
    .best-score {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }
    
    .countries-section {
        width: 14rem;
        min-width: 14rem;
    }
    
    .games-section {
        width: 12rem;
        min-width: 12rem;
    }
}

@media (max-width: 768px) {
    .quiz-container {
        min-height: calc(100vh - 60px);
    }

    .other-games-container {
        padding: 0.75rem;
    }

    .game-btn {
        padding: 0.5rem;
    }

    .game-btn img {
        width: 2.5rem;
        height: 2.5rem;
    }

    #countries-list td {
        padding: 0.5rem 0.75rem;
    }
}

@media (max-width: 640px) {
    .quiz-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    
    .header-controls {
        justify-content: space-between;
    }
    
    .input-container {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    #guess-button {
        width: 100%;
    }
    
    #map {
        min-height: 15rem;
    }
    
    .countries-section,
    .games-section {
        width: 100%;
        min-width: 100%;
    }
}

@media (max-width: 480px) {
    .quiz-container {
        min-height: calc(100vh - 120px);
    }
    
    html {
        font-size: 14px;
    }
    
    .modal-content {
        margin: 5% auto;
        padding: 15px;
    }
}

@media (max-width: 360px) {
    html {
        font-size: 12px;
    }

    #map {
        min-height: 12rem;
    }
}

/* Для устройств с высоким DPI и масштабированием */
@media (min-resolution: 192dpi) {
    :root {
        --border-radius: 16px;
    }

    .quiz-header {
        padding: 0.5rem;
    }

    .header-btn,
    .control-btn,
    #guess-button {
        padding: 1rem 2rem;
        font-size: 1.1rem;
    }

    #country-input {
        padding: 1rem;
        font-size: 1.1rem;
    }

    .timer-display,
    .best-score {
        font-size: 1.2rem;
        padding: 0.75rem 1.5rem;
    }

    .game-btn img {
        width: 5rem;
        height: 5rem;
    }

    #countries-list td {
        padding: 1rem;
        font-size: 1.1rem;
    }
    
    .modal-content {
        padding: 25px;
    }
}

/* Вертикальная ориентация на мобильных */
@media (max-height: 600px) and (orientation: portrait) {
    .quiz-header {
        padding: 0.5rem;
    }
    
    .quiz-content {
        height: calc(100vh - 60px);
    }
    
    .map-section {
        min-height: 15rem;
    }
    
    .scrollable-section {
        max-height: 12rem;
    }
}

/* Горизонтальная ориентация на мобильных */
@media (max-height: 450px) and (orientation: landscape) {
    .quiz-header {
        position: static;
    }
    
    .quiz-content {
        flex-direction: row;
        height: calc(100vh - 50px);
    }
    
    .map-section {
        min-height: auto;
    }
    
    .scrollable-section {
        max-height: none;
        height: 100%;
    }
}

/* Специальные адаптации для узких экранов */
@media (max-width: 320px) {
    .header-btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.7rem;
    }
    
    .timer-display,
    .best-score {
        padding: 0.3rem 0.6rem;
        font-size: 0.7rem;
    }
    
    #country-input {
        padding: 0.6rem;
    }
    
    #guess-button {
        padding: 0.6rem 1rem;
    }
}

.map-disclaimer {
    margin: 0.5rem 0;
    font-size: 0.75rem;
    color: #666;
    text-align: center;
    line-height: 1.3;
    padding: 0 1rem;
    font-style: italic;
}

@media (max-width: 640px) {
    .map-disclaimer {
        font-size: 0.7rem;
        margin: 0.3rem 0;
    }
}