html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    height: 100dvh;
    min-height: 100%;
    overflow: hidden;
}

body {
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(to bottom, #87CEEB, #FFFFFF);
}

.game-container {
    width: 100%;
    max-width: 600px;
    height: 100%;
    max-height: 800px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    background: transparent;
}

@media (max-width: 768px) {
    .game-container {
        width: 100vw;
        height: 100%;
        max-height: none;
        border-radius: 0;
        min-height: 100%;
    }
}

.chat-window {
    flex-grow: 1;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    padding: 15px;
    box-sizing: border-box;
    min-height: 0;
    justify-content: flex-start;
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding-right: 10px;
    scroll-behavior: smooth;
    min-height: 0;
    display: flex;
    flex-direction: column;
    /* Важливо: Додаємо, щоб вміст повідомлень завжди виштовхувався вгору */
    justify-content: flex-end; /* Починаємо повідомлення з низу, щоб завжди бачити останні */
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}
.chat-messages::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}
.chat-messages::-webkit-scrollbar-track {
    background-color: rgba(0, 0, 0, 0.1);
}

.message {
    margin-bottom: 10px;
    line-height: 1.4;
    max-width: 85%;
    display: flex;
}

.message.bot {
    align-self: flex-start;
    flex-direction: row;
}

.message.user {
    align-self: flex-start;
    flex-direction: row;
}

.message-sender {
    font-weight: bold;
    color: #F8F8A7;
    margin-right: 5px;
    flex-shrink: 0;
}

.message-text {
    color: #FFFFFF;
    word-wrap: break-word;
}

.chat-link {
    color: #87CEEB;
    text-decoration: underline;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    font-size: inherit;
    font-family: inherit;
}
.chat-link:hover {
    color: #5bbad5;
}

.chat-input-area {
    background-color: rgba(0, 0, 0, 0.85);
    padding: 10px 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    height: auto;
    min-height: 50px; /* Зменшено min-height */
    box-sizing: border-box;
    display: flex;
    flex-direction: column-reverse;
    flex-shrink: 0;
    /* Спроба компенсації білої смуги на Android */
    /* ЦЕ ЕКСПЕРИМЕНТАЛЬНО. Можливо, доведеться підбирати значення */
    @supports (-webkit-touch-callout: none) and (not (min-resolution: 0.001dpcm)) { /* Тільки для iOS Safari */
        padding-bottom: 10px; /* Повертаємо стандартний padding для iOS */
    }
    @media (max-width: 768px) { /* Застосовуємо на мобільних */
        padding-bottom: calc(10px + env(safe-area-inset-bottom)); /* Для Android та iOS */
        /* Або якщо це не спрацює, спробуйте негативний маргін: */
        margin-bottom: 50px; /* Експериментально: щоб input-area була "під" системною панеллю */
    }
}

.pseudo-input-field {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 35px; /* Зменшено min-height */
    box-sizing: border-box;
}

.input-placeholder {
    color: rgba(255, 255, 255, 0.5);
    font-style: italic;
    flex-grow: 1;
    cursor: pointer;
}

.send-icon {
    width: 20px;
    height: 20px;
    background-color: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    margin-left: 10px;
    flex-shrink: 0;
}

.user-options {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 5px; /* Зменшено margin-bottom */
    width: 100%;
    padding: 0 5px;
    box-sizing: border-box;
}

.user-options.active {
    max-height: 200px;
}

.user-option-button {
    background-color: #28a745;
    color: white;
    padding: 8px 15px; /* Зменшено padding */
    border-radius: 5px;
    cursor: pointer;
    text-align: center;
    border: none;
    font-size: 0.95em; /* Трохи зменшено розмір шрифту */
    transition: background-color 0.2s ease;
    flex-grow: 1;
}
.user-option-button:hover {
    background-color: #218838;
}

.user-options.active + .pseudo-input-field .input-placeholder {
    display: none;
}

/* Стилі для спливаючих вікон (overlay) */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    height: 100dvh;
    box-sizing: border-box;
    padding: 20px;
}

.overlay.active {
    opacity: 1;
    visibility: visible;
}

.popup {
    background-color: #fff;
    padding: 30px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.4);
    max-width: 80%;
    max-height: 90vh;
    overflow-y: auto;
}

.popup p {
    font-size: 1.2em;
    color: #333;
    margin-bottom: 20px;
}

#popupActionBtn {
    background-color: #007bff;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease;
}
#popupActionBtn:hover {
    background-color: #0056b3;
}
