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

/* Отключаем зум на мобильных устройствах */
html {
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

:root {
    --bg-gradient-start: #4A9FD4;
    --bg-gradient-end: #2E7AB8;
    --card-bg: #ffffff;
    --text-white: #ffffff;
    --text-dark: #2D3748;
    --btn-color: #3B8AC4;
    --shadow-soft: 0 8px 32px rgba(0, 0, 0, 0.12);
    --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.08);
}

body {
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
    min-height: 100vh;
    background: linear-gradient(180deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    color: var(--text-white);
    overflow-x: hidden;
}

.container {
    max-width: 420px;
    margin: 0 auto;
    padding: 32px 18px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 24px;
    animation: fadeInDown 0.6s ease-out;
}

.logo {
    width: 64px;
    height: 64px;
    background: var(--card-bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 14px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12), 0 2px 4px rgba(0, 0, 0, 0.08);
}

.logo svg {
    width: 36px;
    height: 36px;
    color: var(--btn-color);
}

.title {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.5px;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Subtitle */
.subtitle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border-radius: 30px;
    padding: 10px 20px;
    margin-bottom: 20px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    animation: fadeInUp 0.6s ease-out 0.2s both;
}

.trophy-icon {
    width: 18px;
    height: 18px;
    opacity: 0.9;
}

/* Games Grid */
.games-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    flex: 1;
    width: 100%;
}

/* Game Card */
.game-card {
    background: var(--card-bg);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 2px 4px rgba(0, 0, 0, 0.1);
    animation: fadeInUp 0.6s ease-out calc(var(--card-delay)) both;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    touch-action: manipulation;
}

.game-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2), 0 4px 8px rgba(0, 0, 0, 0.15);
}

.game-card:active {
    transform: scale(0.98);
}


.game-icon-wrapper {
    background: var(--card-color);
    padding: 28px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.game-icon {
    width: 48px;
    height: 48px;
    color: rgba(255, 255, 255, 0.95);
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

/* Стили для изображений игр */
.game-icon-wrapper.has-image {
    padding: 0;
    overflow: hidden;
    aspect-ratio: 16 / 9;
}

.game-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.game-card:hover .game-image {
    transform: scale(1.05);
}

.game-title {
    color: var(--text-dark);
    font-size: 14px;
    font-weight: 700;
    text-align: center;
    padding: 14px 8px 10px;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    min-height: auto;
}

.play-btn {
    display: block;
    width: calc(100% - 16px);
    margin: 0 8px 12px;
    padding: 10px 14px;
    background: var(--btn-color);
    color: white;
    border: none;
    border-radius: 10px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    /* Критично для работы на мобильных устройствах */
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.play-btn:hover {
    background: #2E7AB8;
    transform: scale(1.02);
}

.play-btn:active {
    transform: scale(0.96);
    background: #2567a0;
}

/* Для мобильных устройств */
@media (hover: none) {
    .play-btn:hover {
        transform: none;
    }
}

/* Footer */
.footer {
    text-align: center;
    margin-top: 24px;
    padding: 12px;
    font-size: 12px;
    opacity: 0.75;
    animation: fadeIn 0.6s ease-out 0.5s both;
}

/* Animations */
@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 0.8;
    }
}

/* Responsive */
@media (max-width: 380px) {
    .games-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .container {
        padding: 30px 14px;
    }
    
    .game-icon-wrapper {
        padding: 24px 18px;
    }
    
    .game-icon {
        width: 42px;
        height: 42px;
    }
}

@media (max-width: 360px) {
    .container {
        padding: 28px 12px;
    }
    
    .games-grid {
        gap: 8px;
    }
    
    .game-title {
        font-size: 13px;
        padding: 12px 6px 8px;
        line-height: 1.4;
    }
    
    .play-btn {
        font-size: 12px;
        padding: 9px 12px;
    }
}

@media (max-width: 340px) {
    .game-title {
        font-size: 12px;
        padding: 10px 4px 6px;
    }
    
    .play-btn {
        font-size: 11px;
        padding: 8px 10px;
        margin: 0 6px 10px;
        width: calc(100% - 12px);
    }
    
    .game-icon-wrapper {
        padding: 20px 14px;
    }
}

@media (min-width: 600px) {
    .container {
        max-width: 500px;
        padding: 60px 24px;
    }
    
    .title {
        font-size: 32px;
    }
    
    .game-icon-wrapper {
        padding: 40px 28px;
    }
    
    .game-icon {
        width: 64px;
        height: 64px;
    }
}

/* ========== MODAL STYLES ========== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    padding: 20px;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    border-radius: 28px;
    width: 100%;
    max-width: 340px;
    padding: 28px 24px;
    position: relative;
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 
        0 25px 50px -12px rgba(0, 0, 0, 0.25),
        0 0 0 1px rgba(255, 255, 255, 0.1);
}

.modal-overlay.active .modal-content {
    transform: scale(1) translateY(0);
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: rgba(0, 0, 0, 0.12);
    transform: scale(1.1);
}

.modal-close svg {
    width: 18px;
    height: 18px;
    color: #64748b;
}

.modal-icon-wrapper {
    width: 80px;
    height: 80px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    box-shadow: 
        0 8px 16px -4px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

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

.modal-icon svg {
    width: 44px;
    height: 44px;
    color: white;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

/* Стили для модального окна с изображением */
.modal-icon-wrapper.has-image {
    width: 100%;
    max-width: 320px;
    height: auto;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border-radius: 16px;
}

.modal-icon-wrapper.has-image img {
    border-radius: 16px;
}

.modal-title {
    font-size: 22px;
    font-weight: 800;
    color: #1e293b;
    text-align: center;
    margin-bottom: 10px;
}

.modal-description {
    font-size: 14px;
    color: #64748b;
    text-align: center;
    line-height: 1.6;
    margin-bottom: 16px;
}

.modal-tags {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.modal-tag {
    font-size: 12px;
    font-weight: 600;
    color: #475569;
    background: rgba(59, 138, 196, 0.1);
    padding: 6px 12px;
    border-radius: 20px;
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.modal-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 24px;
    border: none;
    border-radius: 14px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-btn svg {
    width: 20px;
    height: 20px;
}

.modal-btn-primary {
    background: linear-gradient(135deg, #3B8AC4 0%, #2563eb 100%);
    color: white;
    box-shadow: 0 4px 14px -3px rgba(59, 138, 196, 0.5);
}

.modal-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px -3px rgba(59, 138, 196, 0.6);
}

.modal-btn-primary:active {
    transform: translateY(0);
}

.modal-btn-secondary {
    background: rgba(59, 138, 196, 0.08);
    color: #3B8AC4;
    border: 2px solid rgba(59, 138, 196, 0.2);
}

.modal-btn-secondary:hover {
    background: rgba(59, 138, 196, 0.15);
    border-color: rgba(59, 138, 196, 0.3);
}

.modal-btn-secondary:active {
    transform: scale(0.98);
}

/* Modal responsive */
@media (max-width: 380px) {
    .modal-content {
        padding: 24px 20px;
    }
    
    .modal-icon-wrapper {
        width: 72px;
        height: 72px;
    }
    
    .modal-icon {
        width: 40px;
        height: 40px;
    }
    
    .modal-title {
        font-size: 20px;
    }
    
    .modal-btn {
        padding: 12px 20px;
        font-size: 14px;
    }
}

/* ========== GAME VIEWER (IFRAME) ========== */
.game-viewer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #1a1a2e;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.game-viewer.active {
    opacity: 1;
    visibility: visible;
}

.game-viewer-header {
    background: linear-gradient(135deg, #3B8AC4 0%, #2563eb 100%);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
    /* Безопасная зона для iPhone */
    padding-top: max(12px, env(safe-area-inset-top));
}

.game-viewer-back {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 8px;
    padding: 8px 14px;
    color: white;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.game-viewer-back:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateX(-2px);
}

.game-viewer-back svg {
    width: 20px;
    height: 20px;
}

.game-viewer-title {
    color: white;
    font-size: 16px;
    font-weight: 700;
    flex: 1;
}

.game-frame-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #1a1a2e;
}

/* Затемнение краёв для маскировки белого фона игр */
.game-frame-container::before,
.game-frame-container::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 100px;
    z-index: 10;
    pointer-events: none;
}

.game-frame-container::before {
    top: 0;
    background: linear-gradient(to bottom, #1a1a2e 0%, #1a1a2e 30%, transparent 100%);
}

.game-frame-container::after {
    bottom: 0;
    background: linear-gradient(to top, #1a1a2e 0%, #1a1a2e 30%, transparent 100%);
}

#gameFrame {
    width: 100%;
    height: 100%;
    border: none;
    background: #1a1a2e;
    display: block;
    margin: 0;
    padding: 0;
}

/* Адаптация под Telegram WebApp */
@media (max-width: 480px) {
    .game-viewer-header {
        padding: 10px 12px;
        padding-top: max(10px, env(safe-area-inset-top));
    }
    
    .game-viewer-back {
        padding: 6px 12px;
        font-size: 13px;
    }
    
    .game-viewer-title {
        font-size: 14px;
    }
}


