/* Mobile-First Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background-attachment: fixed;
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height для iOS */
    height: 100vh;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #333;
    overflow: hidden;
    touch-action: manipulation;
    position: fixed;
    width: 100%;
    max-width: 100%;
    top: 0;
    left: 0;
}

.container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height */
    max-width: 100%;
    padding: clamp(12px, 3vw, 16px);
    padding-top: max(clamp(12px, 3vw, 16px), env(safe-area-inset-top));
    padding-right: max(clamp(12px, 3vw, 16px), env(safe-area-inset-right));
    padding-bottom: max(clamp(12px, 3vw, 16px), env(safe-area-inset-bottom));
    padding-left: max(clamp(12px, 3vw, 16px), env(safe-area-inset-left));
}

/* Хедер з назвою та рахунком */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: clamp(8px, 2vw, 12px) 0;
    flex-shrink: 0;
    min-height: clamp(50px, 10vh, 60px);
}

h1 {
    color: white;
    font-size: clamp(1.1rem, 4.5vw, 1.8rem);
    margin: 0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

/* Головний ігровий wrapper */
.game-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: clamp(12px, 3.5vw, 16px);
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.game-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(4px, 1.2vw, 6px);
    flex-shrink: 0;
    max-height: 100%;
}

#gameCanvas {
    border: clamp(2px, 0.5vw, 3px) solid #fff;
    border-radius: clamp(6px, 2vw, 10px);
    box-shadow: 0 clamp(3px, 1.2vw, 5px) clamp(15px, 4vw, 20px) rgba(0, 0, 0, 0.3);
    background-color: #1a1a2e;
    touch-action: none;
    max-height: 100%;
    max-width: 100%;
    object-fit: contain;
}

/* Рахунок в хедері */
.score-display {
    display: flex;
    align-items: center;
    gap: clamp(6px, 2vw, 10px);
    background: rgba(255, 255, 255, 0.2);
    padding: clamp(4px, 1.2vw, 6px) clamp(12px, 3.5vw, 18px);
    border-radius: clamp(16px, 4vw, 22px);
    backdrop-filter: blur(10px);
}

.score-label {
    color: white;
    font-size: clamp(0.9rem, 3vw, 1rem);
    font-weight: 500;
}

.score-display #score {
    color: white;
    font-size: clamp(1.2rem, 4vw, 1.5rem);
    font-weight: bold;
}

/* Кнопки Start/Restart */
.controls {
    width: 100%;
    display: flex;
    justify-content: center;
}

.btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 10px 25px;
    font-size: clamp(0.9rem, 3.5vw, 1rem);
    border-radius: 20px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    font-weight: bold;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
}

/* Desktop інструкції - приховані на мобільних */
.instructions {
    display: none;
}

/* Мобільні кнопки - ліва колонка */
.mobile-controls-left,
.mobile-controls-right {
    display: flex;
    flex-direction: column;
    gap: clamp(12px, 3vh, 16px);
    justify-content: center;
    flex-shrink: 0;
}

.mobile-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 0;
    font-size: clamp(1.3rem, 5vw, 1.8rem);
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
    font-weight: bold;
    width: clamp(50px, 13vw, 70px);
    height: clamp(50px, 13vw, 70px);
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-btn:active {
    transform: scale(0.9);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* Кнопка скидання внизу */
.mobile-controls-bottom {
    display: flex;
    justify-content: center;
    padding: clamp(12px, 3.5vw, 16px) 0;
    flex-shrink: 0;
    min-height: clamp(60px, 13vh, 70px);
    align-items: center;
}

.mobile-btn-drop {
    background: linear-gradient(135deg, #f0a000 0%, #f06000 100%);
    color: white;
    border: none;
    padding: 12px 40px;
    font-size: clamp(0.95rem, 3.8vw, 1.05rem);
    border-radius: 22px;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
    font-weight: bold;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
}

.mobile-btn-drop:active {
    transform: scale(0.95);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.game-over {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: clamp(20px, 5vw, 30px) clamp(25px, 6vw, 35px);
    border-radius: clamp(12px, 3vw, 18px);
    box-shadow: 0 clamp(10px, 3vw, 15px) clamp(40px, 10vw, 50px) rgba(0, 0, 0, 0.5);
    z-index: 1000;
    max-width: 90%;
    width: clamp(280px, 85%, 400px);
}

.game-over h2 {
    color: #764ba2;
    font-size: clamp(1.5rem, 6vw, 2.5rem);
    margin-bottom: 15px;
}

.game-over p {
    font-size: clamp(1rem, 4vw, 1.5rem);
    color: #555;
}

.game-over span {
    color: #667eea;
    font-weight: bold;
    font-size: clamp(1.3rem, 5vw, 1.8rem);
}

/* Tablet and Desktop - min-width 576px */
@media (min-width: 576px) {
    body {
        overflow: auto;
    }
    
    .container {
        padding: 20px;
        height: auto;
        min-height: 100vh;
    }
    
    .header {
        margin-bottom: 20px;
    }
    
    .game-wrapper {
        flex-direction: column;
        gap: 20px;
    }
    
    .mobile-controls-left,
    .mobile-controls-right,
    .mobile-controls-bottom {
        display: none;
    }
    
    .instructions {
        display: block;
        text-align: left;
        background: rgba(255, 255, 255, 0.9);
        padding: 15px;
        border-radius: 8px;
        margin: 20px auto 0;
        max-width: 300px;
    }
    
    .instructions h3 {
        color: #667eea;
        margin-bottom: 10px;
        font-size: 1.2rem;
    }
    
    .instructions ul {
        list-style: none;
    }
    
    .instructions li {
        padding: 5px 0;
        color: #555;
    }
    
    #gameCanvas {
        max-height: none;
    }
}

/* Desktop - min-width 768px */
@media (min-width: 768px) {
    .container {
        padding: 30px;
    }
    
    .header {
        margin-bottom: 30px;
    }
    
    .game-wrapper {
        gap: 30px;
    }
    
    #gameCanvas {
        max-width: 350px;
    }
    
    .btn {
        padding: 12px 30px;
    }
    
    .btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
    }
    
    .btn:active {
        transform: translateY(0);
    }
    
    .game-over {
        padding: 40px 60px;
    }
    
    .instructions {
        max-width: 350px;
        padding: 20px;
    }
}

/* Large Desktop - min-width 992px */
@media (min-width: 992px) {
    #gameCanvas {
        max-width: 400px;
    }
}

/* Medium Mobile Devices - max-width 575px (все мобильные до планшетов) */
@media (max-width: 575px) {
    .container {
        max-width: 100%;
        padding: clamp(12px, 3vw, 16px);
    }
    
    .game-wrapper {
        gap: clamp(12px, 3.5vw, 14px);
    }
    
    /* Минимальный размер touch targets согласно Apple HIG и Material Design */
    .mobile-btn {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Small Mobile Devices - max-width 414px */
@media (max-width: 414px) {
    .mobile-btn {
        width: clamp(48px, 12vw, 62px);
        height: clamp(48px, 12vw, 62px);
        font-size: clamp(1.2rem, 4.5vw, 1.6rem);
    }
    
    .mobile-controls-left,
    .mobile-controls-right {
        gap: clamp(8px, 2vh, 12px);
    }
}

/* Extra Small Mobile Devices - max-width 360px */
@media (max-width: 360px) {
    .mobile-btn {
        width: clamp(44px, 11vw, 55px);
        height: clamp(44px, 11vw, 55px);
        font-size: clamp(1.1rem, 4vw, 1.5rem);
    }
    
    .mobile-controls-left,
    .mobile-controls-right {
        gap: clamp(10px, 2.5vh, 14px);
    }
    
    .container {
        padding: clamp(10px, 2.5vw, 12px);
        padding-top: max(clamp(10px, 2.5vw, 12px), env(safe-area-inset-top));
        padding-right: max(clamp(10px, 2.5vw, 12px), env(safe-area-inset-right));
        padding-bottom: max(clamp(10px, 2.5vw, 12px), env(safe-area-inset-bottom));
        padding-left: max(clamp(10px, 2.5vw, 12px), env(safe-area-inset-left));
    }
    
    h1 {
        font-size: clamp(1rem, 4vw, 1.5rem);
    }
    
    .mobile-btn-drop {
        padding: 10px 30px;
        font-size: clamp(0.85rem, 3.5vw, 1rem);
    }
    
    .game-wrapper {
        gap: clamp(10px, 3vw, 12px);
    }
}

/* Touch Devices - увеличенные touch targets для удобства */
@media (pointer: coarse) {
    .mobile-btn {
        min-width: 48px;
        min-height: 48px;
    }
    
    .btn {
        padding: 12px 30px;
        min-height: 44px;
    }
    
    .mobile-btn-drop {
        min-height: 48px;
        padding: 12px 35px;
    }
}

/* Дополнительные стили для очень маленьких экранов и in-app браузеров */
@media (max-width: 575px) and (max-height: 750px) {
    .container {
        padding: clamp(10px, 2.5vw, 14px);
    }
    
    .header {
        min-height: clamp(45px, 8vh, 55px);
        padding: clamp(8px, 2vw, 10px) 0;
    }
    
    .mobile-btn {
        width: clamp(48px, 12vw, 62px);
        height: clamp(48px, 12vw, 62px);
        font-size: clamp(1.2rem, 4.5vw, 1.6rem);
    }
    
    .mobile-controls-left,
    .mobile-controls-right {
        gap: clamp(10px, 2.5vh, 14px);
    }
    
    .mobile-controls-bottom {
        min-height: clamp(55px, 11vh, 65px);
        padding: clamp(10px, 2.5vw, 12px) 0;
    }
    
    .game-wrapper {
        gap: clamp(10px, 3vw, 14px);
    }
}
