@font-face {
    font-family: 'TTSportsDisplay';
    src: url('assets/TTSportsDisplay-DemiBold.woff2') format('woff2');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

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

:root {
    --primary-blue: #0066cc;
    --primary-dark: #004499;
    --bg-dark: #0a0e1a;
    --bg-light: #141b2d;
    --accent-green: #00d4aa;
    --accent-red: #ff4757;
    --text-primary: #ffffff;
    --text-secondary: #a8b2d1;
    --border-color: #1e2d4f;
    --shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    
}

button {
  font-family: inherit;
}

body {
    font-family: 'TTSportsDisplay', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #1650B1;
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    position: relative;
    overflow: hidden;
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
}

body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(circle at 20% 50%, rgba(0, 102, 204, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 50%, rgba(0, 212, 170, 0.05) 0%, transparent 50%);
    pointer-events: none;
}

/* Stars positioned relative to game container */
.star-top {
    position: absolute;
    top: 20px;
    right: 0;
    width: 100px;
    height: 100px;
    background: url('assets/star_top.webp') right/contain no-repeat;
    pointer-events: none;
}

.star-bottom {
    position: absolute;
    bottom: 20px;
    left: 0;
    width: 100px;
    height: 100px;
    background: url('assets/star_bottom.webp') left/contain no-repeat;
    pointer-events: none;
}

.game-container {
    text-align: center;
    backdrop-filter: blur(20px);
    padding: 48px 40px;
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    width: 100%;
}

/* Фиксируем game-container при показе финального экрана */
.game-container.game-ended {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
}

h1 {
    margin: 0;
    font-size: 28px;
    font-weight: 600;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--text-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
    line-height: 1.3;
}

#gameCanvas {
    border: 3px solid #2563eb;
    background: #ffffff;
    box-shadow: 
        0 8px 32px rgba(37, 99, 235, 0.15),
        0 2px 8px rgba(0, 0, 0, 0.05);
    transition: transform 0.3s ease;
    border-radius: 16px;
    display: block;
    z-index: 3;
}

.score {
    margin: 0;
    font-size: 26px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 35px;
}

.star {
    width: 23px;
    height: 19px;
    flex-shrink: 0;
}

.counter-text {
    display: flex;
    align-items: center;
    gap: 8px;
}

.counter-text span {
    font-weight: 700;
    font-size: 42px;
}

.control-hint {
    font-size: 12px;
    opacity: 0.5;
    color: var(--text-primary);
    margin-top: 8px;
    text-align: center;
    margin: -8px 0;
}

.controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    position: relative;
}

/* Мобильные игровые контролы */
.mobile-game-controls {
    display: none;
    margin-top: 16px;
}

.control-grid {
    display: grid;
    grid-template-columns: 84px 134px 84px;
    grid-template-rows: 88px 88px;
    align-items: center;
    justify-content: center;
    gap: 0px;
}

.control-vertical {
    grid-column: 2;
    grid-row: 1 / 3;
    display: grid;
    grid-template-rows: 88px 88px;
    align-items: center;
    justify-items: center;
    gap: 2px;
}

.control-btn {
    width: 100%;
    height: 100%;
    border: none;
    background: url('assets/control.webp') center/cover no-repeat;
    color: transparent;
    font-size: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    text-indent: -9999px;
    overflow: hidden;
    transform-origin: center center;
    will-change: transform;
    border-radius: 8px;
    touch-action: manipulation;
}

.control-btn#leftBtn {
    transform: rotate(0deg);
    grid-column: 1;
    grid-row: 1 / 3;
    align-self: center;
}

.control-btn#leftBtn:active {
    transform: rotate(0deg);
    opacity: 0.7;
}

.control-btn#rightBtn {
    transform: rotate(180deg);
    grid-column: 3;
    grid-row: 1 / 3;
    align-self: center;
}

.control-btn#rightBtn:active {
    transform: rotate(180deg);
    opacity: 0.7;
}

.control-btn#upBtn {
    transform: rotate(90deg);
    width: 63%;
    height: 140%;
    border-radius: 8px;
}

.control-btn#upBtn:active {
    transform: rotate(90deg);
    opacity: 0.7;
}

.control-btn#downBtn {
    transform: rotate(-90deg);
    width: 63%;
    height: 140%;
}

.control-btn#downBtn:active {
    transform: rotate(-90deg);
    opacity: 0.7;
}


/* Показываем мобильные контролы на маленьких экранах */
@media (max-width: 650px) {
    .mobile-game-controls {
        display: block;
    }
    
    .control-hint {
        font-size: 12px;
        opacity: 0.5;
        color: var(--text-primary);
        margin-top: 0;
        text-align: center;
    }
    
    .desktop-hint {
        display: none;
    }
    
    .control-hint::before {
        content: "Управляй стрелками или\00a0свайпами по\00a0полю";
    }
}

#startBtn {
    background: #BFA069;
    color: white;
    border: none;
    width: 330px;
    height: 75px;
    font-size: 18px;
    font-weight: 600;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    z-index: 10;
}

@media (max-width: 650px) {
    #startBtn {
        transition: box-shadow 0.3s ease, background 0.3s ease; /* Don't transition transform on mobile */
    }
}

/* Start overlay */
.start-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 190px;
    left: 0;
    right: 0;
    height: 75%;
    z-index: 10;
    transition: opacity 0.3s ease;
    gap: 24px;
    padding-bottom: 20px;
}

@media (max-width: 650px) {
    .start-overlay {
        top: 120px;
        height: 86%;
    }
}

.start-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

.start-gradient {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg, rgba(22, 80, 177, 0.00) 0%, #1650B1 53.85%);
    pointer-events: none;
    z-index: 2;
}

.rpl-cup {
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    width: 144px;
    height: 324px;
    background: url('assets/rpl-cup.webp') center/contain no-repeat;
    pointer-events: none;
    z-index: 1;
}

@media (max-width: 650px) {
    .rpl-cup {
        top: -30px;
    }
}

.start-stars {
    display: flex;
    gap: 20px;
    position: relative;
    z-index: 3;
}

.start-star {
    width: 23px;
    height: 19px;
}

.start-text {
    text-align: center;
    color: white;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.4;
    width: 300px;
    position: relative;
    z-index: 3;
}

.start-text__title {
    font-size: 42px;
}

.start-text__subtitle {
    font-size: 18px;
    opacity: 0.7;
}


#startBtn {
    position: relative;
    z-index: 3;
}

#startBtn:hover {
    background: #C8A970;
    transform: translateY(-2px);
}

#startBtn:active {
    transform: translateY(0);
}

.popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 14, 26, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.popup:not(.hidden) {
    opacity: 1;
    visibility: visible;
}

.popup-content {
    background: linear-gradient(135deg, var(--bg-light) 0%, rgba(20, 27, 45, 0.95) 100%);
    backdrop-filter: blur(20px);
    padding: 48px;
    border-radius: 24px;
    text-align: center;
    max-width: 500px;
    position: relative;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    transform: translateY(20px);
    opacity: 0;
    transition: all 0.3s ease 0.1s;
}

.popup:not(.hidden) .popup-content {
    transform: translateY(0);
    opacity: 1;
}

.popup-content h2 {
    margin-bottom: 24px;
    font-size: 32px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent-green) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.popup-content p {
    margin-bottom: 32px;
    font-size: 18px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.popup-content button {
    background: #BFA069;
    color: white;
    border: none;
    width: 330px;
    height: 75px;
    font-size: 18px;
    font-weight: 600;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1.2px;
}

.popup-content button:hover {
    background: #C8A970;
    transform: translateY(-2px);
}

.karpin-image {
    width: 300px;
    height: auto;
    margin: 24px 0;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    border: 2px solid var(--border-color);
}

/* Game end overlay - unified for victory and game over */
.game-end-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    position: relative;
    z-index: 100;
    transition: opacity 0.3s ease;
    gap: 10px;
    padding-bottom: 50px;
    padding-top: 120px;
    width: 100%;
}

@media (max-width: 650px) {
    .game-end-overlay {
        padding-top: 80px;
    }
}

.game-end-overlay.hidden {
    display: none;
}

.game-end-gradient {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg, rgba(22, 80, 177, 0.00) 0%, #1650B1 53.85%);
    pointer-events: none;
    z-index: 2;
}

.karpin-bg {
       width: 300px;
    height: auto;
    pointer-events: none;
    z-index: 3;
}

.game-end-stars {
    display: flex;
    gap: 20px;
    position: relative;
    z-index: 3;
}

.game-end-star {
    width: 23px;
    height: 19px;
}

.game-end-text {
    text-align: center;
    color: white;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.4;
    width: 400px;
    position: relative;
    z-index: 3;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

.game-end-text__title {
    font-size: 46px;
    font-weight: 700;
}

.game-end-text__subtitle {
    font-size: 18px;
    opacity: 0.8;
}

.game-end-overlay button {
    background: transparent;
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    width: 330px;
    height: 75px;
    font-size: 18px;
    font-weight: 600;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    position: relative;
    z-index: 3;
}

.game-end-overlay button:hover {
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.game-end-overlay button:active {
    transform: translateY(0);
}

/* Share container styles */
.share-container {
    position: relative;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    margin: 20px 0;
    background: #BFA069;
    border-radius: 12px;
    padding: 18px;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.share-text {
    color: white;
    font-size: 18px;
    opacity: 0.8;
}

.share-buttons {
    display: flex;
    gap: 16px;
    justify-content: center;
}

.share-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 40px !important;
    height: 40px !important;
    padding: 0 !important;
    background: rgba(255, 255, 255, 0.1) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    border-radius: 50% !important;
    color: transparent !important;
    font-size: 0 !important;
    cursor: pointer;
    transition: all 0.3s ease !important;
    backdrop-filter: blur(10px);
    text-transform: none !important;
    letter-spacing: normal !important;
}

.share-btn:hover {
    background: rgba(255, 255, 255, 0.2) !important;
    transform: scale(1.1) !important;
}

.share-btn:active {
    transform: scale(0.95) !important;
}

.share-icon {
    width: 24px;
    height: 24px;
    filter: brightness(0) invert(1);
}

.copy-success {
    position: absolute;
    bottom: -40px;
    background: #BFA069;
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    box-shadow: 0 4px 12px rgba(191, 160, 105, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.copy-success.show {
    opacity: 1;
}

/* Victory animations */
.victory {
    overflow: visible;
}

.fireworks {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    pointer-events: none;
    transform: translate(-50%, -50%);
}

@keyframes firework-particle {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0;
    }
}

.fireworks::before,
.fireworks::after {
    content: '';
    position: absolute;
    width: 300px;
    height: 300px;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

.fireworks::before {
    background: radial-gradient(circle, transparent 30%, var(--accent-green) 30%, var(--accent-green) 34%, transparent 34%);
    animation: firework-particle 1.5s ease-out infinite;
}

.fireworks::after {
    background: radial-gradient(circle, transparent 40%, var(--primary-blue) 40%, var(--primary-blue) 44%, transparent 44%);
    animation: firework-particle 1.5s ease-out 0.3s infinite;
}

/* Confetti effect */
.victory::before,
.victory::after {
    font-size: 60px;
    position: absolute;
    animation: confetti 3s ease-out infinite;
    z-index: 10;
}

.victory::before {
    content: '⚽';
    left: 10%;
    top: -60px;
    animation-delay: 0s;
}

.victory::after {
    content: '🏆';
    right: 10%;
    top: -60px;
    animation-delay: 1.5s;
}

@keyframes confetti {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    100% {
        transform: translateY(400px) rotate(720deg);
        opacity: 0;
    }
}

/* Game over popup variants */
#gameOverPopup .popup-content h2 {
    background: linear-gradient(135deg, var(--accent-red) 0%, #ff6b7a 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Responsive */
@media (max-width: 650px) {    
    .game-container {
        padding: 32px 24px;
        width: 100%;
        max-width: 100vw;
        border-radius: 20px;
        gap: 20px;
    }
    
    h1 {
        font-size: 22px;
    }
    
    #gameCanvas {
        max-width: 400px;
        max-height: 400px;
        width: auto !important;
        height: auto !important;
    }
    
    .score {
        font-size: 20px;
    }
    
    .score span {
        font-size: 28px;
    }
    
    
    #startBtn {
        padding: 14px 36px;
        font-size: 15px;
    }
}

@media (max-width: 480px) {
    .game-container {
        padding: 24px 16px;
        border-radius: 16px;
        gap: 16px;
    }
    
    h1 {
        font-size: 18px;
    }
    
    #gameCanvas {
        max-width: 320px;
        max-height: 320px;
        border-radius: 12px;
        border-width: 2px;
    }
    
    .score {
        font-size: 18px;
    }
    
    .score span {
        font-size: 24px;
    }
    
    #startBtn {
        padding: 12px 32px;
        font-size: 14px;
    }
    
    .control-row {
        gap: 20px;
    }
    
    .popup-content {
        padding: 32px 24px;
        margin: 16px;
        border-radius: 16px;
    }
    
    .popup-content h2 {
        font-size: 24px;
        margin-bottom: 16px;
    }
    
    .popup-content p {
        font-size: 16px;
        margin-bottom: 20px;
    }
    
    .popup-content button {
        padding: 12px 28px;
        font-size: 14px;
    }
    
    .karpin-image {
        width: 200px;
        margin: 16px 0;
    }
    
    /* Уменьшаем размер эмодзи на мобильных */
    .victory::before,
    .victory::after {
        font-size: 40px;
    }
    
    .game-end-text {
        width: 100%
    }
    
    .game-end-text__title {
        font-size: 28px;
        width: 300px
    }
    
    .game-end-text__subtitle {
        font-size: 16px;
        width: 300px
    }
    
    .karpin-bg {
        width: 68%;
    }
    
    .share-container {
        margin: 16px 0;
    }
    
    .share-text {
        font-size: 16px;
    }
}

/* Сверхмаленькие экраны */
@media (max-width: 360px) {
    h1 {
        font-size: 16px;
    }
    
    .game-container {
        padding: 12px;
    }
    
    #gameCanvas {
        max-width: calc(100vw - 32px);
        max-height: calc(100vw - 32px);
    }
    
    .controls p {
        display: none; /* Скрываем текст управления на очень маленьких экранах */
    }
}

/* dat.GUI override */
.dg.ac {
    z-index: 99999 !important;
    display: none !important;
}

/* Iframe-specific overrides for Safari media query bug fix */
/* Only apply when in iframe AND not actually on mobile */
@media (min-width: 651px) {
    body.in-iframe #gameCanvas {
        width: 480px !important;
        height: 480px !important;
        max-width: none !important;
        max-height: none !important;
    }
}