* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    color: white;
    touch-action: none;
    padding: 10px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    text-align: center;
    padding: 15px;
    max-width: 400px;
    width: 100%;
    margin: 10px 0;
}

/* Упрощенный заголовок */
.header.compact {
    margin-bottom: 20px;
    background: rgba(255, 255, 255, 0.1);
    padding: 15px;
    border-radius: 15px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    position: relative;
}

.header.compact .police-badge {
    font-size: 35px;
    margin-bottom: 5px;
    animation: siren 2s ease-in-out infinite;
}

.header.compact h1 {
    font-size: 22px;
    margin-bottom: 5px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.device-info {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 5px;
}

@keyframes siren {
    0%, 100% { color: #ff0000; transform: scale(1); }
    50% { color: #0000ff; transform: scale(1.05); }
}

/* iOS инструкция */
.ios-instruction {
    background: rgba(255, 255, 255, 0.1);
    padding: 10px;
    border-radius: 10px;
    margin: 10px 0;
    font-size: 14px;
    border-left: 3px solid #007AFF;
}

/* Fallback режим */
.fallback-option {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.fallback-btn {
    padding: 12px 20px;
    font-size: 14px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
}

.fallback-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Touch controls */
.touch-controls {
    margin: 20px auto;
    width: 200px;
}

.touch-row {
    display: flex;
    justify-content: center;
    margin: 5px 0;
}

.touch-btn {
    width: 60px;
    height: 60px;
    font-size: 24px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 15px;
    cursor: pointer;
    margin: 0 5px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.touch-btn:active {
    background: rgba(255, 255, 255, 0.4);
    transform: scale(0.95);
}

.touch-center {
    width: 60px;
    height: 60px;
    margin: 0 5px;
}

.gyro-permission {
    background: rgba(255, 255, 255, 0.15);
    padding: 20px;
    border-radius: 15px;
    margin: 15px 0;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.permission-btn {
    padding: 15px 25px;
    font-size: 18px;
    background: linear-gradient(45deg, #007AFF, #5856D6);
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    margin: 10px 0;
    transition: all 0.3s ease;
    width: 100%;
    font-weight: bold;
    -webkit-appearance: none;
}

.permission-btn:hover {
    transform: scale(1.02);
}

.permission-btn:active {
    transform: scale(0.98);
}

.test-section {
    background: rgba(255, 255, 255, 0.15);
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 15px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    position: relative;
}

.test-section.active {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.4);
    transform: scale(1.01);
}

.hidden {
    display: none !important;
}

/* Заголовки тестов */
.test-title {
    margin-bottom: 25px !important;
    font-size: 20px;
    color: #ffd700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
    position: relative;
    z-index: 10;
}

/* Лабиринт - исправлено для масштабирования */
.maze-container {
    position: relative;
    width: 280px;
    height: 280px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    overflow: hidden;
}

.maze-wall {
    position: absolute;
    background: rgba(255, 0, 0, 0.7);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 3px;
    z-index: 1;
}

.maze-ball {
    position: absolute;
    background: radial-gradient(circle at 30% 30%, #007AFF, #0044CC);
    border-radius: 50%;
    border: 2px solid #007AFF;
    box-shadow: 0 0 15px rgba(0, 122, 255, 0.7);
    z-index: 2;
    transition: left 0.1s, top 0.1s;
}

.maze-target {
    position: absolute;
    background: radial-gradient(circle at 30% 30%, #00ff00, #006600);
    border-radius: 50%;
    border: 2px dashed #00ff00;
    box-shadow: 0 0 15px rgba(0, 255, 0, 0.7);
    z-index: 2;
    animation: pulse 1.5s infinite;
}

.maze-timer {
    margin-top: 10px;
    font-size: 16px;
    font-weight: bold;
    color: #ffd700;
}

@keyframes pulse {
    0%, 100% { 
        transform: scale(1); 
        box-shadow: 0 0 15px rgba(0, 255, 0, 0.7);
    }
    50% { 
        transform: scale(1.1); 
        box-shadow: 0 0 25px rgba(0, 255, 0, 0.9);
    }
}

/* Балансировка */
.balance-platform {
    position: relative;
    width: 220px;
    height: 220px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.3);
    overflow: hidden;
}

.balance-center {
    position: absolute;
    width: 30px;
    height: 30px;
    background: rgba(0, 255, 0, 0.3);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border: 2px dashed #00ff00;
}

.balance-dot {
    position: absolute;
    width: 15px;
    height: 15px;
    background: #ff6b6b;
    border-radius: 50%;
    transition: all 0.05s ease;
    border: 2px solid white;
    box-shadow: 0 0 10px rgba(255, 107, 107, 0.7);
    will-change: transform;
}

.balance-grid {
    position: absolute;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(circle at center, transparent 95%, rgba(255,255,255,0.1) 100%),
        linear-gradient(0deg, transparent 49%, rgba(255,255,255,0.1) 50%, transparent 51%),
        linear-gradient(90deg, transparent 49%, rgba(255,255,255,0.1) 50%, transparent 51%);
}

.balance-score {
    margin-top: 10px;
    font-size: 16px;
    font-weight: bold;
    color: #ffd700;
}

/* Дрожь */
.shake-container {
    position: relative;
    width: 280px;
    height: 200px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    overflow: hidden;
}

.shake-meter {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 0%;
    background: linear-gradient(to top, #ff0000, #ffff00, #00ff00);
    transition: height 0.2s;
}

.shake-indicator {
    position: absolute;
    left: 0;
    width: 100%;
    height: 3px;
    background: white;
    box-shadow: 0 0 10px white;
}

.shake-value {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 48px;
    font-weight: bold;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.7);
}

.shake-scale {
    position: absolute;
    right: 5px;
    top: 0;
    height: 100%;
    width: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
}

.scale-mark {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.7);
    position: absolute;
}

.shake-score {
    margin-top: 10px;
    font-size: 16px;
    font-weight: bold;
    color: #ffd700;
}

/* Улучшенные инструкции */
.instruction {
    margin-top: 15px;
    font-size: 14px;
    opacity: 0.9;
    min-height: 20px;
    line-height: 1.3;
}

.instruction.large {
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    background: rgba(0, 0, 0, 0.3);
    padding: 10px;
    border-radius: 10px;
    margin-top: 20px;
}

.instruction.small {
    font-size: 12px;
    margin-top: 10px;
    opacity: 0.8;
}

.controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-top: 15px;
}

.timer {
    font-size: 42px;
    font-weight: bold;
    color: #ffd700;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.7);
    margin-bottom: 5px;
}

.test-progress {
    width: 100%;
    margin-top: 10px;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 5px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007AFF, #00ff00);
    width: 33.33%;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 12px;
    opacity: 0.7;
}

.btn {
    padding: 16px 30px;
    font-size: 18px;
    font-weight: bold;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    width: 100%;
    -webkit-appearance: none;
}

.start-btn {
    background: linear-gradient(45deg, #007AFF, #5856D6);
    color: white;
    box-shadow: 0 4px 15px rgba(0, 122, 255, 0.5);
    border: 2px solid white;
}

.start-btn:hover:not(.disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 122, 255, 0.7);
}

.start-btn:active:not(.disabled) {
    transform: translateY(0);
}

/* Стиль для неактивной кнопки */
.start-btn.disabled {
    background: linear-gradient(45deg, #cccccc, #999999);
    color: #666666;
    border: 2px solid #cccccc;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.result {
    font-size: 20px;
    font-weight: bold;
    color: white;
    text-shadow: 2px 2px 6px rgba(0, 0, 0, 0.7);
    padding: 18px 25px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 15px;
    backdrop-filter: blur(10px);
    min-height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(255, 255, 255, 0.3);
    width: 100%;
    line-height: 1.3;
}

.gyro-data {
    background: rgba(255, 255, 255, 0.1);
    padding: 12px;
    border-radius: 8px;
    margin-top: 8px;
    font-size: 11px;
    font-family: monospace;
}

/* Анимации результатов */
.result.excellent {
    background: rgba(0, 255, 0, 0.3);
    border-color: rgba(0, 255, 0, 0.5);
    color: #90ff90;
}

.result.good {
    background: rgba(255, 255, 0, 0.3);
    border-color: rgba(255, 255, 0, 0.5);
    color: #ffff90;
}

.result.poor {
    background: rgba(255, 0, 0, 0.3);
    border-color: rgba(255, 0, 0, 0.5);
    color: #ff9090;
}

/* Стили для финального экрана результатов */
.final-results {
    text-align: center;
    padding: 20px;
    width: 100%;
}

.final-score {
    font-size: 48px;
    font-weight: bold;
    margin: 20px 0;
    color: #ffd700;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.7);
}

.recommendation {
    font-size: 20px;
    margin: 15px 0;
    line-height: 1.4;
    background: rgba(255, 255, 255, 0.15);
    padding: 15px;
    border-radius: 15px;
    backdrop-filter: blur(10px);
}

.test-results {
    background: rgba(255, 255, 255, 0.1);
    padding: 15px;
    border-radius: 15px;
    margin: 15px 0;
    backdrop-filter: blur(10px);
}

.test-result-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: 16px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.test-result-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

/* Стили для fallback режима */
.fallback-instructions {
    text-align: center;
    padding: 15px;
}

.fallback-instructions p {
    margin-bottom: 20px;
    font-size: 16px;
}

/* Адаптивность для iPhone */
@media (max-height: 700px) {
    .container {
        padding: 10px;
    }
    
    .header.compact {
        padding: 10px;
        margin-bottom: 15px;
    }
    
    .header.compact h1 {
        font-size: 20px;
    }
    
    .test-section {
        padding: 15px;
        margin-bottom: 12px;
    }
    
    .test-title {
        margin-bottom: 20px !important;
        font-size: 18px;
    }
    
    .maze-container {
        width: 240px;
        height: 240px;
    }
    
    .balance-platform {
        width: 200px;
        height: 200px;
    }
    
    .shake-container {
        width: 240px;
        height: 180px;
    }
    
    .touch-btn {
        width: 55px;
        height: 55px;
        font-size: 22px;
    }
    
    .final-score {
        font-size: 36px;
        margin: 15px 0;
    }
    
    .recommendation {
        font-size: 18px;
        padding: 12px;
    }
}

/* Адаптивность для маленьких iPhone (SE, 12 mini) */
@media (max-height: 600px) {
    .container {
        padding: 8px;
        max-width: 360px;
    }
    
    .header.compact {
        padding: 8px;
        margin-bottom: 10px;
    }
    
    .header.compact h1 {
        font-size: 18px;
    }
    
    .test-section {
        padding: 12px;
        margin-bottom: 10px;
    }
    
    .test-title {
        margin-bottom: 15px !important;
        font-size: 16px;
    }
    
    .maze-container {
        width: 200px;
        height: 200px;
    }
    
    .balance-platform {
        width: 180px;
        height: 180px;
    }
    
    .shake-container {
        width: 200px;
        height: 160px;
    }
    
    .instruction.large {
        font-size: 14px;
        padding: 8px;
        margin-top: 15px;
    }
    
    .permission-btn, .start-btn {
        padding: 14px 20px;
        font-size: 16px;
    }
    
    .touch-btn {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
    
    .final-score {
        font-size: 32px;
        margin: 10px 0;
    }
    
    .recommendation {
        font-size: 16px;
        padding: 10px;
    }
    
    .test-results {
        padding: 12px;
    }
    
    .test-result-item {
        font-size: 14px;
    }
}

/* Для очень узких экранов (iPhone в альбомной ориентации) */
@media (max-width: 350px) {
    .container {
        padding: 5px;
        max-width: 320px;
    }
    
    .header.compact .police-badge {
        font-size: 30px;
    }
    
    .header.compact h1 {
        font-size: 16px;
    }
    
    .maze-container {
        width: 180px;
        height: 180px;
    }
    
    .balance-platform {
        width: 160px;
        height: 160px;
    }
    
    .shake-container {
        width: 180px;
        height: 140px;
    }
    
    .touch-controls {
        width: 180px;
    }
    
    .touch-btn {
        width: 45px;
        height: 45px;
        font-size: 18px;
    }
    
    .permission-btn, .start-btn {
        padding: 12px 15px;
        font-size: 14px;
    }
    
    .result {
        padding: 15px 20px;
        font-size: 16px;
        min-height: 60px;
    }
}

/* Для iPhone в альбомной ориентации */
@media (orientation: landscape) and (max-height: 500px) {
    .container {
        transform: scale(0.9);
        transform-origin: top center;
        max-width: 320px;
    }
    
    .header.compact {
        padding: 6px;
    }
    
    .test-section {
        padding: 10px;
        margin-bottom: 8px;
    }
    
    .maze-container {
        width: 180px;
        height: 180px;
    }
    
    .balance-platform {
        width: 160px;
        height: 160px;
    }
    
    .shake-container {
        width: 180px;
        height: 140px;
    }
}

/* Поддержка notch и безопасных зон на iOS */
@supports (padding: max(0px)) {
    .container {
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
        padding-top: max(10px, env(safe-area-inset-top));
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
}

/* Анимации для лучшего UX */
.fade-in {
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}