/* ============================================
   БАЗОВЫЕ СТИЛИ
   ============================================ */

:root {
    --screen-bottom: 16px;
}

   * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    color: #e8e0d4;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
}

/* ============================================
   ЭКРАНЫ
   ============================================ */

.screen {
    display: none;
    position: fixed;
    inset: 0;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
}

.screen.active {
    display: flex;
}

/* ============================================
   ЭКРАН 1: ПРИВЕТСТВИЕ
   ============================================ */

#screen-welcome {
    background: url('../assets/backgrounds/welcome.png') center/cover no-repeat;
    background-color: #0a0a14;
    justify-content: flex-end;
}

@media (orientation: landscape) {
    #screen-welcome {
        background-image: url('../assets/backgrounds/welcome-wide.png');
    }
}

.welcome-container {
    text-align: center;
    padding: 24px 24px var(--screen-bottom);
    max-width: 400px;
    width: 100%;
}

/* ============================================
   ЭКРАН 2: БАРМЕН
   ============================================ */

#screen-barman {
    background: #0a0a14;
    padding: 0;
    overflow: hidden;
}

.barman-portrait {
    font-size: 5em;
    margin-bottom: 20px;
}

.barman-turned {
    transform: scaleX(-1);
    opacity: 0.6;
}

/* Иллюстрация — абсолютно спозиционирована внутри #screen-barman и
   ограничена по ширине так же, как игровое поле (max-width: 440px).
   left: 50% + translateX(-50%) — горизонтальное центрирование внутри screen.
   top/bottom: 0 — тянется на всю высоту этой колонки.
   display: grid + grid-area 1/1 на обеих <img> кладёт их в одну ячейку:
   переключение активной меняет только opacity (crossfade) без скачков. */
.barman-illustration {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    display: grid;
    width: 100%;
    max-width: 440px;
    z-index: 0;
}

.barman-img {
    grid-area: 1 / 1;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    opacity: 0;
    transition: opacity 0.6s ease;
    pointer-events: none;
}

.barman-img--active {
    opacity: 1;
}

/* Оверлей с диалогом и кнопкой — накладывается поверх иллюстрации,
   ограничен той же max-width: 440px и прибит к низу колонки. */
.barman-overlay {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 440px;
    z-index: 1;
    padding: 80px 24px var(--screen-bottom);
    text-align: center;
    background: linear-gradient(to top,
        rgba(10, 10, 20, 0.92) 0%,
        rgba(10, 10, 20, 0.78) 45%,
        rgba(10, 10, 20, 0) 100%);
}

.barman-overlay .btn {
    margin: 0 auto;
}

.dialogue-box {
    background: rgba(20, 15, 25, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    padding: 20px;
    margin: 0 auto 24px;
    text-align: left;
    min-height: 150px;
}

.barman-name {
    font-size: 0.8em;
    color: #c4a87a;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 12px;
}

.barman-text {
    font-size: 0.95em;
    line-height: 1.7;
    color: #d4ccc0;
}

.barman-text.barman-text--fade-in {
    animation: barmanTextFadeIn 0.45s ease both;
}

@keyframes barmanTextFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.hint-legend {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.hint-legend-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 0.9em;
    line-height: 1.5;
}

.hint-legend-item .moon {
    font-size: 1.1em;
    flex-shrink: 0;
}

/* ============================================
   КНОПКИ
   ============================================ */

.btn {
    padding: 14px 32px;
    border: none;
    border-radius: 12px;
    font-size: 1.05em;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, opacity 0.15s;
    letter-spacing: 1px;
    width: 100%;
    height: 56px;
    max-width: 340px;
}

.btn:active {
    transform: scale(0.96);
}

.btn:disabled {
    opacity: 0.35;
    cursor: default;
    transform: none;
}

.btn-enter {
    background: linear-gradient(135deg, #c4a87a, #a08050);
    color: #1a1520;
}

.btn-accept,
.btn-confirm,
.btn-next,
.btn-retry {
    background: url('../assets/backgrounds/button.png') center/100% 100% no-repeat;
    color: #f0e6d3;
}

.btn-accept {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s;
}

.btn-accept.visible {
    opacity: 1;
    pointer-events: auto;
}

.btn-confirm {
    margin-top: auto;
    flex-shrink: 0;
    align-self: center;
}

/* ============================================
   ЭКРАН 3: ИГРА
   ============================================ */

#screen-game {
    background: linear-gradient(180deg, #141018 0%, #1c1624 50%, #141018 100%);
}

.game-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 400px;
    height: 100vh;
    height: 100dvh;
    padding: 12px 16px var(--screen-bottom);
    margin: 0 auto;
}

/* Счётчик */
.game-header {
    text-align: center;
    margin-bottom: 8px;
    flex-shrink: 0;
}

.attempt-counter {
    display: inline-block;
    background: rgba(255, 255, 255, 0.08);
    padding: 6px 20px;
    border-radius: 20px;
    font-size: 0.85em;
    color: #a09890;
    letter-spacing: 1px;
}

/* История */
.history-board {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding: 4px 0;
    margin-bottom: 8px;

    /* Скроллбар */
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.15) transparent;
}

.history-board::-webkit-scrollbar {
    width: 4px;
}

.history-board::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 2px;
}

.history-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 12px;
    padding: 8px 10px;
    margin-bottom: 5px;
}

.history-row--enter {
    animation: rowAppear 0.3s ease both;
}

@keyframes rowAppear {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.history-num {
    font-size: 0.75em;
    color: #5a5450;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

.history-ingredients {
    display: flex;
    gap: 4px;
    flex: 1;
}

.history-ingredient {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.07);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6em;
    text-align: center;
    line-height: 1.1;
    color: #b0a898;
    padding: 2px;
    overflow: hidden;
}

.history-ingredient .ingredient-emoji {
    font-size: 1.6em;
    line-height: 1;
    transform: scale(2);
    transform-origin: center center;
}

.history-ingredient .ingredient-icon {
    width: 90%;
    height: 90%;
    object-fit: contain;
}

.history-hints {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    min-width: 56px;
    justify-content: center;
}

.hint-group {
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: 0.85em;
}

.hint-group .moon {
    font-size: 1em;
}

.hint-group .count {
    font-size: 0.85em;
    font-weight: bold;
    min-width: 10px;
}

.hint-full .count { color: #f0d060; }
.hint-half .count { color: #8ab0d0; }

.history-row-current {
    animation: none;
}

.history-hints--pending {
    min-width: 56px;
    flex-shrink: 0;
}

.history-ingredients .slot {
    flex-shrink: 0;
}

.slot-placeholder-num {
    color: #3a3535;
    font-size: 0.8em;
}

.slot {
    width: 56px;
    height: 56px;
    border: 2px dashed rgba(196, 168, 122, 0.25);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7em;
    text-align: center;
    line-height: 1.1;
    color: #6a6060;
    background: rgba(255, 255, 255, 0.03);
    transition: all 0.2s;
    cursor: default;
    padding: 4px;
}

.slot.filled {
    border-color: #c4a87a;
    border-style: solid;
    background: rgba(196, 168, 122, 0.12);
    color: #e8dcc8;
    cursor: pointer;
    animation: slotPop 0.2s ease;
    overflow: hidden;
}

.slot.filled .ingredient-emoji {
    font-size: 1.8em;
    line-height: 1;
    transform: scale(2);
    transform-origin: center center;
}

.slot.filled .ingredient-icon {
    width: 90%;
    height: 90%;
    object-fit: contain;
}

@keyframes slotPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

.slot .slot-number {
    position: absolute;
    top: 2px;
    left: 6px;
    font-size: 0.55em;
    color: #5a5450;
}

/* Позиционирование для номеров */
.slot {
    position: relative;
}

/* Палитра */
.ingredient-palette {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    flex-shrink: 0;
    margin-bottom: 10px;
}

.palette-item {
    aspect-ratio: 1;
    border-radius: 10px;
    border: 1.5px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.06);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    cursor: pointer;
    transition: all 0.15s;
    padding: 6px 4px 8px;
    gap: 6px;
    overflow: hidden;
}

.palette-item:active:not(.disabled) {
    transform: scale(0.92);
    background: rgba(196, 168, 122, 0.2);
}

.palette-item.disabled {
    opacity: 0.2;
    cursor: default;
    border-color: transparent;
}

.palette-emoji {
    flex: 1;
    min-height: 0;
    width: 100%;
    font-size: 1.4em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.palette-emoji .ingredient-emoji {
    transform: scale(2);
    transform-origin: center center;
}

.palette-emoji .ingredient-icon {
    width: 1.4em;
    height: 1.4em;
    object-fit: contain;
    transform: scale(2);
    transform-origin: center center;
}

.palette-name {
    flex-shrink: 0;
    font-size: 0.55em;
    color: #a09890;
    text-align: center;
    line-height: 1.1;
    width: 100%;
    padding-top: 2px;
}

.palette-item.disabled .palette-name {
    color: #504840;
}

/* ============================================
   ЭКРАНЫ РЕЗУЛЬТАТА (4 и 5)
   ============================================ */

#screen-win {
    background: linear-gradient(180deg, #0A0E14 0%, #1A0A0E 100%);
    align-items: stretch;
}

#screen-lose {
    background: #0a0a14;
    padding: 0;
    overflow: hidden;
}

.result-container {
    text-align: center;
    padding: 14px 12px var(--screen-bottom);
    max-width: 440px;
    width: min(100%, 440px);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#screen-win .result-container {
    flex: 1;
    min-height: 0;
    align-self: center;
}

.win-block--top {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.win-block--main {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 12px;
    min-height: 0;
}

#screen-win .result-container .btn {
    margin-top: auto;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 0;
    flex-shrink: 0;
    align-self: center;
}

.win-dialogue {
    display: flex;
    align-items: center;
    gap: 10px;
}

.win-barman-thumb-frame {
    width: 72px;
    height: 72px;
    flex-shrink: 0;
    border-radius: 50%;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.win-barman-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
}

.barman-reaction {
    background: rgba(214, 210, 220, 0.2);
    border-radius: 16px 16px 16px 0;
    text-align: left;
    color: #e8e0d4;
    padding: 14px 16px;
    font-size: 1em;
    line-height: 1.35;
}

.cocktail-image-frame {
    width: min(100%, 320px);
    margin: 0 auto;
    aspect-ratio: 1 / 1;
    border: none;
    background: transparent;
    overflow: visible;
    border-radius: 0;
}

.cocktail-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    display: block;
}

.cocktail-name {
    font-size: clamp(2.2rem, 7vw, 3rem);
    font-weight: 300;
    color: #f3f1f5;
    letter-spacing: 0.5px;
    line-height: 1.05;
    margin-top: 8px;
}

.cocktail-ingredients {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.win-ingredient {
    width: 64px;
    height: 64px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.win-ingredient .ingredient-icon {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.win-ingredient .ingredient-emoji {
    font-size: 2.8em;
    line-height: 1;
}

.cocktail-legend {
    font-size: clamp(0.95rem, 3vw, 1.15rem);
    color: #efedf2;
    line-height: 1.35;
    margin-top: 2px;
}

.result-stats {
    font-size: clamp(0.9rem, 2.6vw, 1.05rem);
    color: #f3f1f5;
    line-height: 1.25;
    margin-top: 4px;
}

@media (max-height: 760px) {
    .result-container {
        gap: 10px;
    }

    .win-block--top,
    .win-block--main {
        gap: 10px;
    }

    .win-barman-thumb-frame {
        width: 64px;
        height: 64px;
    }

    .barman-reaction {
        padding: 12px 14px;
        font-size: 0.95em;
    }

    .cocktail-name {
        font-size: clamp(1.9rem, 6.2vw, 2.4rem);
    }

    .cocktail-legend {
        font-size: clamp(0.88rem, 2.8vw, 1.02rem);
    }

    .win-ingredient {
        width: 56px;
        height: 56px;
    }
}

/* ============================================
   АНИМАЦИЯ SHAKE
   ============================================ */

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

.shake {
    animation: shake 0.4s ease;
}

/* ============================================
   АДАПТИВНОСТЬ
   ============================================ */

@media (max-height: 680px) {
    :root {
        --screen-bottom: 12px;
    }

    .game-container {
        padding: 8px 12px var(--screen-bottom);
    }

    .slot {
        width: 48px;
        height: 48px;
    }

    .history-ingredient {
        width: 48px;
        height: 48px;
        font-size: 0.5em;
    }

    .palette-emoji {
        font-size: 1.1em;
    }

    .palette-name {
        font-size: 0.5em;
    }
}

@media (max-height: 600px) {
    .slot {
        width: 36px;
        height: 36px;
    }

    .history-ingredient {
        width: 36px;
        height: 36px;
        font-size: 0.5em;
    }

    .ingredient-palette {
        gap: 4px;
    }

    .btn-confirm {
        padding: 10px 24px;
        font-size: 0.95em;
    }
}

/* Широкие экраны (планшет) */
@media (min-width: 500px) {
    .slot {
        width: 56px;
        height: 56px;
        font-size: 0.8em;
    }

    .history-ingredient {
        width: 56px;
        height: 56px;
        font-size: 0.65em;
    }
}