/* ======================================
   The chat of the game on a phone (src/ui/mobile-chat.js) and its keyboard (src/ui/virtual-keyboard.js,
   src/ui/word-suggestions.js). TabTibia r226: Minibia's mobile chat, in the dark and gold of the TabTibia hotbar
   ====================================== */

:root {
    --mchat-gold: #d8b55a;
    --mchat-gold-light: #f1d27a;
    --mchat-gold-dark: #8a6a1c;
    --mchat-text: #e8e2d4;
    --mchat-muted: #9b9486;
    --mchat-panel: rgba(18, 16, 13, 0.92);
    --mchat-glass: rgba(12, 11, 9, 0.62);
    --mchat-line: rgba(216, 181, 90, 0.35);
    --mchat-key: #2c2924;
    --mchat-key-top: #3a3630;
    --mchat-key-dark: #1d1b18;
    --mchat-key-pressed: #5a4a24;
    --vk-key-height: 42px;
}

/* ---------- The chat ---------- */

/* The buttons of the game (new.css: button, button:hover) have their margin, border and texture: not these */
#mobile-chat button,
.vk button {
    margin: 0;
    font-weight: normal;
    cursor: default;
}

#mobile-chat {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10050;
    flex-direction: column;
    justify-content: flex-end;
    padding: 0 var(--safe-area-right, 0px) var(--safe-area-bottom, 0px) var(--safe-area-left, 0px);
    pointer-events: none;
    font: 12px/1.35 Verdana, Arial, sans-serif;
    color: var(--mchat-text);
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

/* .mobile-only is display: flex !important in the mobile mode (mobile.css): the chat shows only while it is open */
body.force-mobile #mobile-chat:not(.mobile-chat-visible),
body.mobile-mode #mobile-chat:not(.mobile-chat-visible) {
    display: none !important;
}

#mobile-chat.mobile-chat-visible {
    display: flex !important;
}

/* Above the keyboard of the game, it has its own room at the bottom of the screen */
#mobile-chat.mobile-chat-typing {
    padding-bottom: 0;
}

#mobile-chat > * {
    pointer-events: auto;
}

/* ---------- The last messages, over the game ---------- */

.mobile-chat-preview {
    max-height: 66px;
    overflow-y: auto;
    overscroll-behavior: contain;
    margin: 0 8px;
    padding: 4px 8px;
    border-radius: 8px 8px 0 0;
    background: linear-gradient(to top, var(--mchat-glass), rgba(12, 11, 9, 0.25));
    text-shadow: 0 1px 1px #000, 0 0 2px #000;
    transition: max-height 0.18s ease;
}

.mobile-chat-preview:empty {
    display: none;
}

.mobile-chat-preview.mobile-chat-preview-expanded {
    max-height: 40vh;
    background: var(--mchat-panel);
}

#mobile-chat.mobile-chat-full .mobile-chat-preview {
    display: none;
}

/* The messages: the colors of the desktop chat (Message.createNode) */
#mobile-chat .chat-message {
    display: block;
    padding: 1px 0;
    white-space: pre-wrap;
    word-break: break-word;
    border-radius: 3px;
}

#mobile-chat .chat-message.chat-message-selected {
    background: rgba(216, 181, 90, 0.25);
    outline: 1px solid var(--mchat-line);
}

#mobile-chat .channel-empty {
    display: block;
    padding: 6px 0;
    color: var(--mchat-muted);
    font-style: italic;
}

/* New messages waiting while the list is scrolled up */
.mobile-chat-has-new {
    box-shadow: inset 0 -2px 0 var(--mchat-gold);
}

/* ---------- The whole channel ---------- */

.mobile-chat-log {
    display: none;
    flex-direction: column;
    height: 40vh;
    margin: 0 8px;
    border: 1px solid var(--mchat-line);
    border-bottom: 0;
    border-radius: 10px 10px 0 0;
    background: var(--mchat-panel);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.55);
    overflow: hidden;
}

#mobile-chat.mobile-chat-full .mobile-chat-log {
    display: flex;
}

.mobile-chat-log-header {
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 34px;
    padding: 0 4px 0 12px;
    border-bottom: 1px solid var(--mchat-line);
    background: linear-gradient(to bottom, rgba(216, 181, 90, 0.14), rgba(216, 181, 90, 0.03));
}

.mobile-chat-log-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: bold;
    letter-spacing: 0.3px;
}

.mobile-chat-log-messages {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 6px 12px;
    -webkit-overflow-scrolling: touch;
}

/* ---------- The channel tabs ---------- */

#mobile-chat .mobile-chat-tabs {
    display: flex;
    gap: 4px;
    margin: 0 8px;
    padding: 4px 6px 0;
    overflow-x: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
    background: var(--mchat-panel);
    border-top: 1px solid var(--mchat-line);
}

#mobile-chat .mobile-chat-tabs::-webkit-scrollbar {
    display: none;
}

#mobile-chat.mobile-chat-full .mobile-chat-tabs {
    border-top: 0;
}

#mobile-chat .mobile-chat-tab {
    position: relative;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 5px;
    max-width: 140px;
    height: 28px;
    padding: 0 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom: 2px solid transparent;
    border-radius: 6px 6px 0 0;
    background: rgba(255, 255, 255, 0.04);
    color: var(--mchat-muted);
    font: inherit;
    font-size: 11px;
    touch-action: pan-x;
}

#mobile-chat .mobile-chat-tab-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#mobile-chat .mobile-chat-tab.mobile-chat-tab-active {
    color: var(--tab-color, var(--mchat-gold-light));
    border-bottom-color: var(--tab-color, var(--mchat-gold));
    background: rgba(216, 181, 90, 0.1);
    font-weight: bold;
}

#mobile-chat .mobile-chat-tab-badge {
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    box-sizing: border-box;
    border-radius: 8px;
    background: #d93a2b;
    color: #fff;
    font: bold 9px/16px Verdana, sans-serif;
    text-align: center;
}

/* ---------- The bar to write ---------- */

.mobile-chat-bar {
    position: relative;
    display: flex;
    align-items: center;
    gap: 4px;
    margin: 0 8px;
    padding: 5px 4px 6px;
    background: var(--mchat-panel);
    border-bottom: 1px solid var(--mchat-line);
}

#mobile-chat:not(.mobile-chat-typing) .mobile-chat-bar {
    border-radius: 0 0 10px 10px;
    margin-bottom: 6px;
}

#mobile-chat .mobile-chat-icon {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--mchat-gold);
    touch-action: manipulation;
    outline: none;
}

#mobile-chat .mobile-chat-icon .material-icons {
    font-size: 20px;
    pointer-events: none;
}

#mobile-chat .mobile-chat-icon:active {
    background: var(--mchat-key-pressed);
    color: var(--mchat-gold-light);
}

#mobile-chat .mobile-chat-close-channel {
    color: #d98a7a;
}

#mobile-chat .mobile-chat-close-channel[hidden] {
    display: none;
}

/* The text being written, drawn by the keyboard of the game (the cursor and the selection are its own) */
.mobile-chat-msg {
    flex: 1;
    min-width: 0;
    height: 34px;
    padding: 0 10px;
    box-sizing: border-box;
    border: 1px solid rgba(216, 181, 90, 0.25);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.45);
    color: var(--mchat-text);
    font-size: 13px;
    line-height: 32px;
    white-space: pre;
    overflow: hidden;
    touch-action: manipulation;
}

#mobile-chat.mobile-chat-typing .mobile-chat-msg {
    border-color: var(--mchat-gold);
    box-shadow: 0 0 0 1px rgba(216, 181, 90, 0.25);
}

.mobile-chat-msg.vk-empty::after {
    content: attr(data-placeholder);
    color: var(--mchat-muted);
}

/* A short note above the bar (MobileChat.__hint): nothing copied yet, a channel only read... */
.mobile-chat-note {
    position: absolute;
    left: 50%;
    max-width: calc(100% - 24px);
    box-sizing: border-box;
    padding: 7px 14px;
    border: 1px solid var(--mchat-gold);
    border-radius: 16px;
    background: rgba(20, 15, 8, 0.94);
    color: var(--mchat-gold-light);
    font: 13px Verdana, Arial, sans-serif;
    text-align: center;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
    transform: translateX(-50%);
    visibility: hidden;
    pointer-events: none;
    z-index: 3;
}

.mobile-chat-note.mobile-chat-note-visible {
    visibility: visible;
}

.mobile-chat-msg .vk-selection {
    background: rgba(216, 181, 90, 0.45);
    color: #fff;
}

/* Where the next letter goes (user 2026-11-15: "una linea que marca donde estas escribiendo"): wide enough to see on a
   phone, and dimmed rather than gone when it blinks */
.mobile-chat-msg .vk-caret {
    display: inline-block;
    width: 3px;
    height: 20px;
    margin: 0 -1px 0 0;
    vertical-align: -4px;
    border-radius: 1px;
    background: var(--mchat-gold-light);
    box-shadow: 0 0 4px rgba(255, 211, 107, 0.7);
    animation: vk-caret-blink 1.05s steps(1) infinite;
}

/* The same cursor over the field of a window being typed into (VirtualKeyboard.__placeFieldCaret): above the windows,
   below the keyboard */
.vk-field-caret {
    position: fixed;
    z-index: 59990;
    display: block;
    width: 3px;
    border-radius: 1px;
    background: #ffd36b;
    box-shadow: 0 0 4px rgba(255, 211, 107, 0.7);
    pointer-events: none;
    animation: vk-caret-blink 1.05s steps(1) infinite;
}

.vk-field-caret[hidden] {
    display: none;
}

/* The empty text: the caret before the placeholder */
.mobile-chat-msg.vk-empty .vk-caret {
    margin: 0 4px 0 0;
}

@keyframes vk-caret-blink {
    50% { opacity: 0.25; }
}

.mobile-chat-read-only .mobile-chat-msg {
    opacity: 0.6;
}

.mobile-chat-read-only .mobile-chat-history,
.mobile-chat-read-only .mobile-chat-paste {
    opacity: 0.35;
}

/* The phone keyboard (Settings: Phone keyboard in the chat): a real text field in place of the drawn text */
.mobile-chat-native-input {
    display: none;
    flex: 1;
    min-width: 0;
    height: 34px;
    padding: 0 10px;
    box-sizing: border-box;
    border: 1px solid var(--mchat-gold);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.55);
    color: var(--mchat-text);
    font: 16px Verdana, Arial, sans-serif;
    -webkit-user-select: text;
    user-select: text;
}

.mobile-chat-bar.mobile-chat-native .mobile-chat-native-input {
    display: block;
}

.mobile-chat-bar.mobile-chat-native .mobile-chat-msg {
    display: none;
}

/* The bar asking for a player name (a private message): only the name across the whole bar, with Open and a way
   back (the id keeps it over "#mobile-chat .mobile-chat-icon", which shows the buttons) */
#mobile-chat .mobile-chat-bar.mobile-chat-asking > :not(.mobile-chat-private-prompt) {
    display: none;
}

.mobile-chat-private-prompt {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.mobile-chat-private-input {
    flex: 1;
    min-width: 0;
    height: 38px;
    padding: 0 12px;
    box-sizing: border-box;
    border: 1px solid var(--mchat-gold);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.55);
    color: var(--mchat-text);
    font: 17px Verdana, Arial, sans-serif;
    caret-color: var(--mchat-gold-light);
}

.mobile-chat-private-input::placeholder {
    color: var(--mchat-muted);
}

#mobile-chat .mobile-chat-private-open {
    flex: 0 0 auto;
    min-width: 72px;
    height: 38px;
    padding: 0 16px;
    border: 1px solid var(--mchat-gold-light);
    border-radius: 8px;
    background: linear-gradient(to bottom, var(--mchat-gold), var(--mchat-gold-dark));
    color: #1b1408;
    font: bold 14px Verdana, Arial, sans-serif;
}

/* ---------- The chat button: counters of what came while the chat was closed ---------- */

#mobile-chat-btn .mobile-chat-unread[hidden] {
    display: none;
}

#mobile-chat-btn .mobile-chat-unread.mobile-chat-unread-private {
    right: auto;
    left: -4px;
    background: #3d6fd9;
}

#mobile-chat-btn .mobile-chat-unread.mobile-chat-unread-guild {
    top: auto;
    bottom: -4px;
    background: #2f9a4a;
}

/* ---------- The keyboard of the game ---------- */

.vk {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    /* Over the windows of the phone (30000-50000: the NPC window, the market), whose fields it types into */
    z-index: 60000;
    flex-direction: column;
    gap: 6px;
    padding: 4px max(3px, var(--safe-area-right, 0px)) calc(6px + var(--safe-area-bottom, 0px)) max(3px, var(--safe-area-left, 0px));
    background: linear-gradient(to bottom, #1c1a16, #12110e);
    border-top: 1px solid var(--mchat-line);
    box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.5);
    font-family: Verdana, Arial, sans-serif;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    touch-action: none;
}

.vk.vk-visible {
    display: flex;
}

.vk .vk-keys {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.vk-row {
    display: flex;
    justify-content: center;
    gap: 5px;
}

.vk .vk-key {
    flex: 1 1 0;
    min-width: 0;
    max-width: 64px;
    height: calc(var(--vk-key-height) * var(--vk-scale, 1));
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: linear-gradient(to bottom, var(--mchat-key-top), var(--mchat-key));
    box-shadow: 0 1px 0 var(--mchat-key-dark), inset 0 1px 0 rgba(255, 255, 255, 0.06);
    color: var(--mchat-text);
    font: 18px Verdana, Arial, sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    outline: none;
}

.vk .vk-key span {
    pointer-events: none;
}

.vk .vk-key .material-icons {
    font-size: 21px;
}

.vk .vk-key.vk-pressed {
    background: var(--mchat-key-pressed);
    color: var(--mchat-gold-light);
}

/* A letter with accents: a small dot in its corner tells that holding it offers more */
.vk .vk-key.vk-key-has-accents {
    position: relative;
}

.vk .vk-key.vk-key-has-accents::after {
    content: "";
    position: absolute;
    top: 5px;
    right: 6px;
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: rgba(216, 181, 90, 0.5);
}

.vk .vk-key-wide,
.vk .vk-key-mode {
    flex-grow: 1.5;
    max-width: 96px;
    background: linear-gradient(to bottom, #2a2620, #201e1a);
    color: var(--mchat-gold);
    font-size: 13px;
}

.vk .vk-key-shift.vk-active,
.vk .vk-key-shift.vk-caps {
    background: linear-gradient(to bottom, #6b5626, #4b3c18);
    color: var(--mchat-gold-light);
}

.vk .vk-key-shift.vk-caps {
    box-shadow: inset 0 -3px 0 var(--mchat-gold-light);
}

.vk .vk-key-space {
    flex-grow: 5;
    max-width: none;
    color: var(--mchat-muted);
    font-size: 11px;
    letter-spacing: 0.5px;
}

.vk .vk-key-space.vk-key-sliding {
    color: var(--mchat-gold-light);
    background: linear-gradient(to bottom, #4b3c18, #2f2610);
}

.vk .vk-key-punct {
    max-width: 46px;
}

.vk .vk-key-send {
    flex-grow: 1.7;
    max-width: 110px;
    background: linear-gradient(to bottom, var(--mchat-gold), var(--mchat-gold-dark));
    color: #1b1408;
    font-size: 13px;
    font-weight: bold;
}

.vk .vk-key-send.vk-pressed {
    background: var(--mchat-gold-light);
    color: #1b1408;
}

/* The letter touched, big above the finger */
.vk-popup {
    position: fixed;
    z-index: 60010;
    min-width: 44px;
    height: 54px;
    padding: 0 6px;
    box-sizing: border-box;
    transform: translate(-50%, calc(-100% - 6px));
    border: 1px solid var(--mchat-gold);
    border-radius: 8px;
    background: #3a3428;
    color: var(--mchat-gold-light);
    font: 26px/52px Verdana, Arial, sans-serif;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
    pointer-events: none;
}

/* The accents of a held letter */
.vk-accents {
    position: fixed;
    z-index: 60011;
    display: flex;
    gap: 2px;
    padding: 4px;
    border: 1px solid var(--mchat-gold);
    border-radius: 10px;
    background: #2a2620;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.65);
    pointer-events: none;
}

.vk-accents span {
    min-width: 36px;
    height: 44px;
    border-radius: 7px;
    color: var(--mchat-text);
    font: 22px/44px Verdana, Arial, sans-serif;
    text-align: center;
}

.vk-accents span.vk-selected {
    background: linear-gradient(to bottom, var(--mchat-gold), var(--mchat-gold-dark));
    color: #1b1408;
}

/* The words offered above the keys */
.vk .vk-suggestions {
    display: flex;
    height: 30px;
    margin: 0 2px;
    border-bottom: 1px solid rgba(216, 181, 90, 0.15);
}

/* A field that gets no suggestions (a player name): no empty row above the keys */
.vk .vk-suggestions[hidden] {
    display: none;
}

.vk .vk-suggestion {
    flex: 1 1 0;
    min-width: 0;
    padding: 0 4px;
    border: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    background: transparent;
    color: var(--mchat-text);
    font: 14px Verdana, Arial, sans-serif;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    touch-action: none;
    outline: none;
}

.vk .vk-suggestion:last-child {
    border-right: 0;
}

.vk .vk-suggestion:first-child {
    color: var(--mchat-gold-light);
}

.vk .vk-suggestion:active {
    background: var(--mchat-key-pressed);
}

/* ---------- Landscape: a narrower chat and keyboard in the middle, the game in sight on both sides ---------- */

@media (orientation: landscape) and (max-height: 500px) {
    :root {
        --vk-key-height: 28px;
    }

    .mobile-chat-log {
        height: 25vh;
    }

    #mobile-chat.mobile-chat-full .mobile-chat-log {
        height: 50vh;
    }

    .mobile-chat-preview.mobile-chat-preview-expanded {
        max-height: 30vh;
    }

    #mobile-chat {
        left: 20%;
        right: 20%;
    }

    .vk {
        left: 20%;
        right: 20%;
        gap: 4px;
        padding-top: 2px;
        border: 1px solid var(--mchat-line);
        border-bottom: 0;
        border-radius: 10px 10px 0 0;
    }

    .vk .vk-keys {
        gap: 5px;
    }

    .vk .vk-suggestions {
        height: 22px;
    }

    .vk .vk-suggestion {
        font-size: 12px;
    }

    .vk .vk-key {
        font-size: 15px;
    }

    .vk {
        padding-bottom: calc(3px + var(--safe-area-bottom, 0px));
    }

    #mobile-chat .mobile-chat-tab {
        height: 24px;
    }

    .mobile-chat-bar {
        padding: 3px 4px 4px;
    }

    #mobile-chat .mobile-chat-icon,
    .mobile-chat-msg,
    .mobile-chat-native-input,
    .mobile-chat-private-input,
    #mobile-chat .mobile-chat-private-open {
        height: 30px;
    }

    .mobile-chat-msg {
        line-height: 28px;
    }
}

/* A phone upright: smaller buttons in the bar so the text keeps room */
@media (max-width: 440px) {
    .mobile-chat-bar {
        gap: 3px;
    }

    #mobile-chat .mobile-chat-icon {
        width: 30px;
    }

    #mobile-chat .mobile-chat-icon .material-icons {
        font-size: 19px;
    }
}

@media (max-width: 360px) {
    #mobile-chat .mobile-chat-icon {
        width: 27px;
    }

    .vk-row {
        gap: 4px;
    }
}
