* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    touch-action: manipulation;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
    padding: 20px;
    color: white;
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

.game-container {
    max-width: 800px;
    width: 100%;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    padding: 20px;
}

header {
    text-align: center;
    padding: 15px 0;
    border-bottom: 2px solid #ffd700;
    margin-bottom: 20px;
}

h1 {
    font-size: 2.5rem;
    color: #ffd700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
    margin-bottom: 10px;
}

.stats {
    display: flex;
    justify-content: space-around;
    background: rgba(0, 0, 0, 0.5);
    padding: 12px;
    border-radius: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.stat-box {
    text-align: center;
    min-width: 120px;
    margin: 5px;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: bold;
    color: #ffd700;
}

.game-area {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 20px;
}

.maze-container {
    position: relative;
    background: #0a1929;
    border: 3px solid #1e3a5f;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
    aspect-ratio: 1/1;
    touch-action: none;
}

#maze {
    display: grid;
    width: 100%;
    height: 100%;
}

.cell {
    border: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: center;
    align-items: center;
}

.player {
    background: #4dff4d;
    border-radius: 50%;
    width: 70%;
    height: 70%;
    box-shadow: 0 0 10px #4dff4d;
    animation: pulse 1.5s infinite;
}

.treasure {
    background: #ffd700;
    border-radius: 50%;
    width: 60%;
    height: 60%;
    box-shadow: 0 0 10px #ffd700;
    animation: spin 3s infinite linear;
}

.exit {
    background: #ff4d4d;
    border-radius: 50%;
    width: 80%;
    height: 80%;
    box-shadow: 0 0 15px #ff4d4d;
    animation: pulse-red 2s infinite;
}

.wall {
    background: #1e3a5f;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}

.instructions {
    background: rgba(30, 58, 95, 0.8);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

h2 {
    color: #ffd700;
    margin-bottom: 15px;
    text-align: center;
    border-bottom: 1px solid #ffd700;
    padding-bottom: 10px;
}

ul {
    padding-left: 20px;
    margin-bottom: 20px;
}

li {
    margin-bottom: 10px;
    line-height: 1.5;
}

.controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 60px);
    gap: 10px;
    margin-top: 20px;
}

.control-btn {
    background: linear-gradient(to bottom, #3a7bd5, #1e3a5f);
    border: none;
    border-radius: 10px;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    -webkit-tap-highlight-color: transparent;
}

.control-btn:hover {
    background: linear-gradient(to bottom, #4d9aff, #2a4a7a);
    transform: translateY(-2px);
}

.control-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.up {
    grid-column: 2;
    grid-row: 1;
}

.down {
    grid-column: 2;
    grid-row: 3;
}

.left {
    grid-column: 1;
    grid-row: 2;
}

.right {
    grid-column: 3;
    grid-row: 2;
}

.restart {
    grid-column: 1 / span 3;
    grid-row: 4;
    background: linear-gradient(to bottom, #ffd700, #b8860b);
    color: #1a2a6c;
    font-weight: bold;
}

.message {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s;
    padding: 20px;
    text-align: center;
}

.message.show {
    opacity: 1;
    pointer-events: all;
}

.message h2 {
    font-size: 3rem;
    color: #ffd700;
    margin-bottom: 20px;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.8);
    border: none;
}

.message p {
    font-size: 1.5rem;
    margin-bottom: 15px;
    text-align: center;
}

#levelStats {
    font-size: 1.2rem;
    margin-bottom: 25px;
    line-height: 1.6;
    background: rgba(255, 255, 255, 0.1);
    padding: 15px;
    border-radius: 10px;
    width: 100%;
    max-width: 400px;
}

#restartBtn {
    padding: 15px 40px;
    font-size: 1.2rem;
    background: linear-gradient(to bottom, #4dff4d, #00b300);
    border: none;
    border-radius: 50px;
    color: white;
    cursor: pointer;
    font-weight: bold;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    transition: all 0.3s;
}

#restartBtn:hover {
    transform: scale(1.05);
    box-shadow: 0 7px 20px rgba(0, 0, 0, 0.4);
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes pulse-red {
    0% { box-shadow: 0 0 10px #ff4d4d; }
    50% { box-shadow: 0 0 20px #ff4d4d; }
    100% { box-shadow: 0 0 10px #ff4d4d; }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Адаптивные стили */
@media (max-width: 768px) {
    body {
        padding: 10px;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .game-area {
        grid-template-columns: 1fr;
    }
    
    .stats {
        flex-direction: column;
        gap: 10px;
    }
    
    .stat-box {
        min-width: auto;
        width: 100%;
    }
    
    .maze-container {
        height: 60vh;
        max-height: 500px;
    }
    
    h1 {
        font-size: 1.8rem;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
    
    .instructions h2 {
        font-size: 1.5rem;
    }
    
    .control-btn {
        font-size: 1.2rem;
        height: 50px;
    }
    
    .controls {
        grid-template-rows: repeat(3, 50px);
    }
    
    .message h2 {
        font-size: 2rem;
    }
    
    .message p {
        font-size: 1.2rem;
        padding: 0 15px;
    }
    
    #levelStats {
        font-size: 1rem;
        padding: 10px;
    }
    
    #restartBtn {
        padding: 12px 30px;
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .game-container {
        padding: 10px;
    }
    
    .maze-container {
        height: 50vh;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    .stat-value {
        font-size: 1.3rem;
    }
    
    .controls {
        gap: 8px;
    }
    
    .control-btn {
        font-size: 1rem;
        height: 45px;
    }
    
    .instructions ul li {
        font-size: 0.9rem;
    }
    
    .message h2 {
        font-size: 1.8rem;
    }
    
    .message p {
        font-size: 1rem;
    }
    
    #levelStats {
        font-size: 0.9rem;
    }
}

/* Индикатор свайпа */
.swipe-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.5rem;
    color: rgba(255, 255, 255, 0.7);
    text-align: center;
    z-index: 5;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px 20px;
    border-radius: 20px;
}

.swipe-indicator.show {
    opacity: 1;
    animation: pulse 2s infinite;
}