/* 1. Глобальные сбросы */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
}

/* 2. Основной контейнер (центровщик) */
#game-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
    /* Фоновая картинка игры */
    background-image: url("images/bg.png");
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* 3. Игровая зона (виртуальный экран) */
#game-area {
    width: 450px;
    height: 800px;
    position: relative;
    transform-origin: center center;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    z-index: 1; /* Базовый слой */
}

/* Мягкий свет сверху */
#game-area::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at top center, rgba(255, 255, 255, 0.4), transparent 60%);
    pointer-events: none !important; /* КРИТИЧНО: Клик должен проходить сквозь этот слой */
    z-index: 2;
}

/* 4. Шапка (Header) */
#header {
    flex-shrink: 0;
    padding: 30px 24px 10px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    z-index: 50;
}

.header-section {
    display: flex;
    flex-direction: column;
}

.label {
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 0.15em;
    color: #9D85E0;
    text-transform: uppercase;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.value {
    font-size: 38px;
    font-weight: 900;
    line-height: 1;
    color: #1e293b;
}

.header-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    margin: 0 10px;
}

.timer {
    font-size: 14px;
    font-weight: bold;
    color: #475569;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.timer-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #f43f5e;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.moves-badge {
    padding: 8px 25px;
    border-radius: 9999px;
    background-color: #9D85E0;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

#moves-text {
    font-size: 16px;
    font-weight: 900;
    color: white;
    text-transform: uppercase;
}

/* 5. Игровое поле и Сетка */
#game-field {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 10px;
}

#shelves-grid {
    width: 100%;
    max-width: 430px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 20px 10px;
    padding: 10px;
    justify-items: center;
}

/* 6. Полка (Shelf) */
.shelf {
    width: 95px;
    height: 260px;
    position: relative;
    background-color: #FFD19A;
    border: 4px solid #FFA54F;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    box-shadow: inset 0 -10px 20px rgba(0,0,0,0.1);
    pointer-events: auto !important; 
    z-index: 10;
    overflow: hidden; /* Чтобы разделители не вылезали за границы */
}

/* Линии-разделители */
.shelf-divider {
    position: absolute;
    width: 100%;
    height: 4px; /* Сделаем чуть толще для видимости */
    background: rgba(184, 115, 51, 0.3); /* Темно-золотистый цвет */
    left: 0;
    z-index: 5; /* Выше фона полки, но ниже предметов */
}

/* Расположение линий (ровно на 1/3 и 2/3 высоты) */
.shelf-divider:nth-of-type(1) { top: 33.33%; }
.shelf-divider:nth-of-type(2) { top: 66.66%; }

.shelf-items {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    position: relative;
    z-index: 10; /* Предметы поверх линий */
    background: transparent;
}






.shelf-slot {
    width: 100%;
    height: 33.33%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px;
}

.shelf-divider {
    position: absolute;
    width: 100%;
    height: 2px;
    background: rgba(255, 165, 79, 0.4);
    left: 0;
    z-index: 1;
}
/* Расположение линий */
.shelf-divider:nth-child(1) { top: 33.33%; }
.shelf-divider:nth-child(2) { top: 66.66%; }

/* 7. Предмет (Item) */
.item {
    width: 70px;
    height: 70px;
    border-radius: 12px;
    border: 3px solid rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: white;
    box-shadow: 0 4px 0 rgba(0,0,0,0.15);
    transition: transform 0.1s;
    touch-action: none; /* Запрещает браузеру "перехватывать" жест скролла */
	pointer-events: none; /* Если вы перетаскиваете ПОЛКУ, то предметы внутри не должны мешать */
}

.item-top {
    cursor: grab;
    border-color: rgba(0,0,0,0.5);
	pointer-events: auto; /* Если вы перетаскиваете именно ПРЕДМЕТ */
}

.item-icon {
    font-size: 40px;
}

/* 8. Оверлеи (Экраны) */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000; /* Только для активных окон */
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
}

/* 1. ГАРАНТИРУЕМ, ЧТО СКРЫТЫЕ ОКНА НЕ БЛОКИРУЮТ КЛИКИ */
.overlay.hidden {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden;
    z-index: -1 !important;
}

.overlay-content {
    background-color: #f7e6c8;
    padding: 40px 24px;
    border-radius: 32px;
    width: 85%;
    max-width: 380px;
    text-align: center;
    border: 6px solid #FFA54F;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
	pointer-events: auto !important;
}

/* Специфические фоны оверлеев */
#start-overlay { background-image: url("images/start_bg.png"); background-size: cover; }
#pause-overlay { background-color: rgba(30, 41, 59, 0.7); }
#win-overlay { background-color: rgba(93, 64, 55, 0.85); }
#lose-overlay { background-color: rgba(62, 39, 35, 0.85); }

/* Заголовки */
#start-title {
    font-size: 32px;
    font-weight: 900;
    color: #FFD19A;
    text-transform: uppercase;
    text-shadow: -2px -2px 0 #5D4037, 2px -2px 0 #5D4037, -2px 2px 0 #5D4037, 2px 2px 0 #5D4037, 0px 5px 0 #3E2723;
    transform: rotate(-2deg);
    margin-bottom: 30px;
}

.success-title { font-size: 42px; color: #10b981; margin-bottom: 10px; }
.error-title { font-size: 36px; color: #ef4444; margin-bottom: 10px; }

.emoji-large { font-size: 80px; margin-bottom: 20px; }

/* 9. Кнопки */
.btn {
    padding: 18px 32px;
    border-radius: 20px;
    font-size: 22px;
    font-weight: 800;
    width: 100%;
    max-width: 260px;
    cursor: pointer;
    border: none;
    transition: transform 0.1s, box-shadow 0.1s;
    text-transform: uppercase;
    touch-action: manipulation;
}

#play-button {
    background: linear-gradient(180deg, #FFB74D 0%, #F57C00 100%);
    color: white;
    border: 3px solid white;
    box-shadow: 0 6px 0 #E65100, 0 10px 20px rgba(0,0,0,0.3);
}

.btn-success { background: #10b981; color: white; box-shadow: 0 6px 0 #065f46; }
.btn-error { background: #ef4444; color: white; box-shadow: 0 6px 0 #991b1b; }

.btn:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 rgba(0,0,0,0.2);
}

/* Футер */
#footer {
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
}

#footer-title {
    font-size: 12px;
    font-weight: bold;
    letter-spacing: 0.2em;
    color: #1e293b;
}