/* CSS Reset и базовые стили */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary-color: #0a3d62;
    --secondary-color: #FFD700;
    --accent-color: #FF6B33;
    --background-start: #87CEEB;
    --background-end: #1E90FF;
    --text-light: #ffffff;
    --text-dark: #000000;
    --success-color: #4CAF50;
    --error-color: #f44336;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.2);
    --border-radius: 12px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Базовые стили */
html {
    font-size: 16px;
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, var(--background-start), var(--background-end));
    height: 100vh;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    touch-action: manipulation;
    color: var(--text-light);
    line-height: 1.6;
}

/* Контейнер приложения */
#app {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

/* Игровой контейнер */
#game-container {
    position: relative;
    width: min(100vw, 400px);
    height: min(100vh, 600px);
    max-width: 100%;
    max-height: 100%;
    overflow: hidden;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    background: var(--background-start);
    aspect-ratio: 2/3;
}

/* Canvas */
#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
    background: var(--background-start);
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
}

/* Экранные элементы */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    color: var(--text-light);
    text-align: center;
    z-index: 100;
    padding: 2rem;
    opacity: 0;
    animation: fadeIn 0.5s ease forwards;
}

.screen-content {
    max-width: 90%;
    animation: slideUp 0.5s ease forwards;
}

#game-over {
    display: none;
}

#game-over[hidden] {
    display: none !important;
}

/* Анимации */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { 
        opacity: 0;
        transform: translateY(30px);
    }
    to { 
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes bounce {
    0%, 20%, 53%, 80%, 100% {
        transform: translate3d(0, 0, 0);
    }
    40%, 43% {
        transform: translate3d(0, -8px, 0);
    }
    70% {
        transform: translate3d(0, -4px, 0);
    }
    90% {
        transform: translate3d(0, -2px, 0);
    }
}

/* Заголовки */
h1 {
    font-size: clamp(2rem, 8vw, 3rem);
    margin-bottom: 1rem;
    color: var(--secondary-color);
    text-shadow: 3px 3px 0 var(--text-dark);
    font-weight: 900;
    letter-spacing: -0.5px;
}

h2 {
    font-size: clamp(1.75rem, 7vw, 2.5rem);
    margin-bottom: 1.5rem;
    color: var(--secondary-color);
    text-shadow: 2px 2px 0 var(--text-dark);
    font-weight: 800;
}

/* Текст */
p {
    font-size: clamp(1rem, 4vw, 1.125rem);
    margin-bottom: 1rem;
    line-height: 1.5;
    opacity: 0.9;
}

/* Кнопки */
.btn-primary {
    background: linear-gradient(135deg, var(--secondary-color), #FF8C00);
    color: var(--text-dark);
    border: none;
    border-radius: 50px;
    padding: 1rem 2rem;
    font-size: clamp(1rem, 4vw, 1.125rem);
    font-weight: 700;
    cursor: pointer;
    margin-top: 1.5rem;
    box-shadow: 0 6px 0 #CC7000, var(--shadow);
    transition: var(--transition);
    min-width: 160px;
    position: relative;
    overflow: hidden;
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: left 0.5s;
}

.btn-primary:hover::before {
    left: 100%;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 0 #CC7000, var(--shadow-lg);
}

.btn-primary:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 #CC7000, var(--shadow);
}

.btn-primary:focus {
    outline: 3px solid rgba(255, 215, 0, 0.5);
    outline-offset: 2px;
}

/* Отображение счета */
#score-display {
    position: absolute;
    top: 1.5rem;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: clamp(2.5rem, 10vw, 3.5rem);
    font-weight: 900;
    color: var(--text-light);
    text-shadow: 3px 3px 0 var(--text-dark);
    z-index: 50;
    display: none;
    animation: bounce 2s infinite;
}

/* Инструкции */
#instructions {
    position: absolute;
    bottom: 1.5rem;
    left: 0;
    width: 100%;
    text-align: center;
    color: var(--text-light);
    font-size: clamp(0.875rem, 3.5vw, 1rem);
    text-shadow: 1px 1px 0 var(--text-dark);
    opacity: 0.8;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.5rem;
    backdrop-filter: blur(5px);
}

/* Кнопка установки */
.install-btn {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--success-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    font-size: 1.5rem;
    display: none;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    z-index: 1000;
    transition: var(--transition);
    animation: pulse 2s infinite;
}

.install-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 25px rgba(76, 175, 80, 0.4);
}

.install-btn:active {
    transform: scale(0.95);
}

.install-btn:focus {
    outline: 3px solid rgba(76, 175, 80, 0.5);
    outline-offset: 2px;
}

/* Индикатор загрузки */
.loading-indicator {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--background-start), var(--background-end));
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s ease;
}

.loading-indicator.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid var(--secondary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-indicator p {
    color: var(--text-light);
    font-size: 1.125rem;
    opacity: 0.9;
}

/* Адаптивность */
@media (max-width: 480px) {
    #game-container {
        border-radius: 0;
        width: 100vw;
        height: 100vh;
        max-width: none;
        max-height: none;
    }
    
    .screen {
        padding: 1rem;
    }
    
    .install-btn {
        bottom: 1rem;
        right: 1rem;
        width: 50px;
        height: 50px;
        font-size: 1.25rem;
    }
}

@media (max-height: 600px) {
    h1 {
        font-size: clamp(1.5rem, 6vw, 2rem);
        margin-bottom: 0.5rem;
    }
    
    h2 {
        font-size: clamp(1.25rem, 5vw, 1.75rem);
        margin-bottom: 1rem;
    }
    
    .btn-primary {
        padding: 0.75rem 1.5rem;
        margin-top: 1rem;
    }
}

/* Поддержка reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .btn-primary:hover {
        transform: none;
    }
}

/* Темная тема */
@media (prefers-color-scheme: dark) {
    :root {
        --background-start: #0a3d62;
        --background-end: #1e3a8a;
    }
}

/* Портретная ориентация */
@media (orientation: portrait) {
    #game-container {
        width: min(100vw, 400px);
        height: min(100vh, 600px);
    }
}

/* Ландшафтная ориентация */
@media (orientation: landscape) and (max-height: 500px) {
    #game-container {
        width: min(80vh, 600px);
        height: min(80vh, 400px);
    }
    
    h1 {
        font-size: clamp(1.5rem, 5vw, 2rem);
    }
    
    .screen-content {
        transform: scale(0.9);
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    #game-canvas {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Print styles */
@media print {
    #game-container {
        box-shadow: none;
        border: 2px solid #000;
    }
    
    .install-btn,
    #instructions,
    .loading-indicator {
        display: none !important;
    }
}

/* Focus styles for accessibility */
button:focus-visible {
    outline: 3px solid var(--secondary-color);
    outline-offset: 2px;
}

/* Skip to content for screen readers */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--secondary-color);
    color: var(--text-dark);
    padding: 8px;
    text-decoration: none;
    border-radius: 4px;
    z-index: 10000;
    font-weight: bold;
}

.skip-link:focus {
    top: 6px;
}