:root {
    --bg-color: #f8fafc;
    --acc-color: #0ea5e9;
    --text-color: #1e293b;
    --panel-bg: rgba(255, 255, 255, 0.8);
    --border-radius: 16px;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    --glass-border: 1px solid rgba(0, 0, 0, 0.05);
}

body {
    margin: 0;
    padding: 20px 0;
    font-family: 'Outfit', 'Inter', system-ui, -apple-system, sans-serif;
    background: radial-gradient(circle at top left, #e2e8f0, #cbd5e1);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    /* ИСПРАВЛЕНО: убрали overflow: hidden и изменили align-items */
}

#game-wrapper {
    width: 95vw;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    backdrop-filter: blur(10px);
    /* ИСПРАВЛЕНО: добавили отступы снизу для скролла */
    margin-bottom: 40px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--panel-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    border: var(--glass-border);
    flex-wrap: wrap;
    gap: 15px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.back-link {
    text-decoration: none;
    color: var(--text-color);
    font-weight: 600;
    font-size: 0.95rem;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    border: var(--glass-border);
    transition: all 0.3s ease;
}

.back-link:hover {
    background: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

header h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: linear-gradient(to right, #38bdf8, #818cf8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

#controls {
    display: flex;
    gap: 16px;
}

select,
button {
    padding: 10px 20px;
    border-radius: 12px;
    border: var(--glass-border);
    font-size: 1rem;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-color);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

select option {
    background: #ffffff;
    color: #1e293b;
}

button {
    background: linear-gradient(135deg, #38bdf8, #2563eb);
    color: white;
    border: none;
    font-weight: 700;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px -5px rgba(56, 189, 248, 0.5);
}

main {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 24px;
    /* ИСПРАВЛЕНО: увеличили минимальную высоту под большие лабиринты */
    min-height: 600px;
}

#game-container {
    position: relative;
    background: #ffffff;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    display: flex;
    justify-content: center;
    align-items: center;
    border: var(--glass-border);
    /* Адаптивная высота под размер лабиринта */
    min-height: 400px;
    max-height: 80vh;
    overflow: auto; /* Добавляем скролл если нужно */
}

#game-canvas {
    max-width: 100%;
    max-height: 70vh; /* Ограничиваем высоту 70% от высоты экрана */
    width: auto;
    height: auto;
    transition: transform 0.8s ease-in-out;
    image-rendering: pixelated;
    /* Keeps pixel art sharp */
}

#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    justify-content: center;
    align-items: center;
}

#message-display {
    padding: 24px 48px;
    background: rgba(255, 255, 255, 0.95);
    color: #0ea5e9;
    border-radius: 100px;
    font-size: 2rem;
    font-weight: 900;
    opacity: 0;
    transition: all 0.4s;
    border: 2px solid #0ea5e9;
    box-shadow: 0 10px 30px rgba(14, 165, 233, 0.2);
}

#game-sidebar {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.hud-item {
    background: var(--panel-bg);
    padding: 16px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    text-align: center;
    border: var(--glass-border);
}

.hud-item h3 {
    margin-top: 0;
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #94a3b8;
    margin-bottom: 20px;
}

#compass-container {
    padding: 10px;
    display: flex;
    justify-content: center;
}

#compass-arrow {
    width: 120px;
    height: 120px;
    object-fit: contain;
    transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    filter: drop-shadow(0 0 10px rgba(56, 189, 248, 0.3));
}

#rotation-timer {
    font-size: 2.5rem;
    font-weight: 800;
    font-family: 'JetBrains Mono', 'Roboto Mono', monospace;
    transition: color 0.3s, transform 0.3s;
}

#rotation-timer.warning {
    color: #f87171;
    transform: scale(1.1);
    text-shadow: 0 0 15px rgba(248, 113, 113, 0.5);
    animation: pulse 1s infinite alternate;
}

@keyframes pulse {
    from {
        transform: scale(1.1);
    }

    to {
        transform: scale(1.2);
    }
}

#leaderboard-list {
    list-style: none;
    padding: 0;
    margin: 0;
    text-align: left;
}

#leaderboard-list li {
    padding: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.95rem;
    transition: background 0.3s;
}

#leaderboard-list li:hover {
    background: rgba(255, 255, 255, 0.05);
}

#leaderboard-list li strong {
    color: var(--acc-color);
}

/* Modal Styling */
#modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#modal-content {
    background: var(--panel-bg);
    padding: 40px;
    border-radius: 24px;
    border: var(--glass-border);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    text-align: center;
    max-width: 400px;
    width: 90%;
}

#modal-title {
    margin-top: 0;
    font-size: 2rem;
    background: linear-gradient(to right, #38bdf8, #818cf8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

#modal-message {
    font-size: 1.1rem;
    color: #94a3b8;
    margin: 20px 0 30px;
}

#modal-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#player-name-input {
    padding: 12px 16px;
    border-radius: 12px;
    background: rgba(30, 41, 59, 0.9);
    border: 1px solid rgba(148, 163, 184, 0.3);
    color: #f1f5f9;
    font-size: 1rem;
    outline: none;
    transition: all 0.3s ease;
    margin-bottom: 8px;
}

#player-name-input:focus {
    border-color: var(--acc-color);
    background: rgba(30, 41, 59, 1);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2);
}

.hidden {
    display: none !important;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Responsiveness */
@media (max-width: 1024px) {
    main {
        grid-template-columns: 1fr;
        /* ИСПРАВЛЕНО: увеличили минимальную высоту для больших лабиринтов на мобильных */
        min-height: 500px;
    }

    #game-sidebar {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    .hud-item {
        flex: 1;
        min-width: 250px;
    }
}

@media (max-width: 640px) {
    header {
        flex-direction: column;
        gap: 16px;
        text-align: center;
    }

    #controls {
        width: 100%;
        justify-content: center;
    }
    
    /* ИСПРАВЛЕНО: добавили больше отступов на мобильных */
    body {
        padding: 10px 0 60px 0;
    }
}