/* 💬 RPG DIALOGUE WINDOWS, ACTIONS, CHAT, AND INTERJECTIONS STYLES */

#rpg-dialogue-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 40010; /* Above editor UI */
    padding: 20px;
    box-sizing: border-box;
    pointer-events: none; /* Allow clicks through overlay unless on a child */
}

#rpg-dialogue-character-image {
    position: absolute;
    left: 20px;
    bottom: 0;
    height: 80vh;
    max-height: 600px;
    animation: fadeInCharacter 0.5s ease-out;
    pointer-events: none;
}

#rpg-dialogue-character-image-right {
    position: absolute;
    right: 20px;
    bottom: 0;
    height: 80vh;
    max-height: 600px;
    transform: scaleX(-1); /* Flip horizontally for a mirrored look */
    animation: fadeInCharacterRight 0.5s ease-out;
    pointer-events: none;
    display: none; /* Hidden by default */
}

@keyframes fadeInCharacterRight {
    from { opacity: 0; transform: translateX(50px) scaleX(-1); }
    to { opacity: 1; transform: translateX(0) scaleX(-1); }
}

@keyframes fadeInCharacter {
    from { opacity: 0; transform: translateX(-50px); }
    to { opacity: 1; transform: translateX(0); }
}

#rpg-dialogue-box {
    position: absolute; /* Positioned within the overlay */
    bottom: 20px; /* Respect overlay padding */
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 40px); /* Respect overlay padding */
    max-width: 900px;
    height: 35%;
    max-height: 300px;
    background-color: rgba(90, 75, 62, 0.9);
    border: 3px solid #3B322C;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: row; /* Changed */
    overflow: visible; /* Allows absolutely positioned nametag to float over top border */
    pointer-events: auto; /* Re-enable pointer events for the box */
    z-index: 40030; /* Ensure dialog box and child name tags stack above slideup windows */
}

#rpg-dialogue-main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    min-width: 0; /* Prevents flexbox overflow issues */
    height: 100%;
    overflow: hidden; /* Fully locks height, restricting any shifting or scrolling layout issues */
    border-top-left-radius: 10px;
    border-bottom-left-radius: 10px;
}

#rpg-dialogue-name-tag {
    position: absolute;
    top: -15px;
    left: 20px;
    background-color: #4a3c30;
    border: 3px solid #3B322C;
    border-radius: 8px;
    padding: 5px 15px;
    font-size: 1.2em;
    color: #EFEBE0;
    font-weight: bold;
    margin-top: 0px; /* Adjust this value as needed */
    transition: background-color 0.3s ease;
    z-index: 1000;
}

#rpg-dialogue-box.private-chat #rpg-dialogue-name-tag {
    background-color: #582f6e;
}

#rpg-dialogue-close {
    position: absolute;
    top: 5px;
    right: 5px;
    background: none;
    border: none;
    color: #EFEBE0;
    font-size: 1.5em;
    cursor: pointer;
    text-shadow: 0 0 5px black;
    pointer-events: auto; /* Re-enable pointer events for the close button */
    z-index: 10;
}
#rpg-dialogue-close:hover {
    color: #D4C8A0;
}

#rpg-dialogue-messages {
    flex-grow: 1;
    padding: 25px;
    padding-top: 15px; /* Extra space for name tag */
    margin-top: 15px; /* Shift scrolling window below the floating name tag */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    color: #EFEBE0;
    line-height: 1.5;
}

.rpg-dialogue-entry strong {
    color: #D4C8A0;
    font-weight: bold;
}

.rpg-dialogue-entry.user-entry strong {
    color: #8cb1f3;
}

.rpg-dialogue-entry.system-entry {
    color: #d4c8a0;
    font-style: italic;
    text-align: center;
    font-size: 0.9em;
}

#rpg-dialogue-input-area {
    display: flex;
    padding: 10px;
    border-top: 2px solid #3B322C;
    background-color: #4a3c30;
    color: #EFEBE0;
    font-size: 1em;
    min-height: 40px;
    height: auto;
}

#rpg-dialogue-input {
    flex-grow: 1;
    resize: none;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #8C6D56;
    background-color: #3B322C;
    color: #EFEBE0;
    font-family: inherit;
    font-size: 1em;
    min-height: 40px;
    height: auto;
}
#rpg-dialogue-input:focus {
    outline: none;
    border-color: #A07D65;
}

#rpg-dialogue-send {
    margin-left: 10px;
    padding: 0 20px;
    border: none;
    border-radius: 8px;
    background-color: #8C6D56;
    color: white;
    font-weight: bold;
    cursor: pointer;
}
#rpg-dialogue-send:hover {
    background-color: #A07D65;
}
#rpg-dialogue-send:disabled {
    background-color: #5A4B3E;
    cursor: not-allowed;
}

#rpg-dialogue-controls {
    width: 180px;
    flex-shrink: 0;
    background-color: rgba(59, 50, 44, 0.7);
    border-left: 2px solid #3B322C;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-sizing: border-box;
    align-items: center;
    border-top-right-radius: 10px;
    border-bottom-right-radius: 10px;
    overflow: hidden;
}

#rpg-dialogue-controls h4 {
    margin: 0;
    width: 100%;
    padding-bottom: 5px;
    border-bottom: 1px solid #8C6D56;
    color: #EFEBE0;
    text-align: center;
    font-size: 1.1em;
}

#rpg-dialogue-controls button {
    background-color: #8C6D56;
    color: white;
    width: 100%;
    border: 1px solid #5A4B3E;
    border-radius: 5px;
    padding: 6px 10px;
    cursor: pointer;
    font-weight: normal;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

#rpg-dialogue-controls button:hover {
    background-color: #A07D65;
}

#rpg-dialogue-toggle-mode.active {
    border-color: #d4c8a0;
}

#rpg-dialogue-box.private-chat #rpg-dialogue-toggle-mode {
    background-color: #6a4a7e;
}

/* Interjecting NPC Styles */
#rpg-dialogue-interjections-container {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 300px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 40011; /* Above dialogue box */
    pointer-events: none; /* Pass clicks through */
}

.rpg-dialogue-interjection {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    opacity: 0;
    transform: translateX(100%);
    transition: opacity 0.5s ease-out, transform 0.5s ease-out, background-color 0.2s;
    cursor: pointer;
    padding: 5px;
    border-radius: 8px;
}

.rpg-dialogue-interjection:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.rpg-dialogue-interjection.show {
    opacity: 1;
    transform: translateX(0);
}

.rpg-dialogue-interjection img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 2px solid #3B322C;
    object-fit: cover;
    flex-shrink: 0;
}

.rpg-dialogue-interjection-bubble {
    background-color: rgba(90, 75, 62, 0.9);
    border: 2px solid #3B322C;
    border-radius: 8px;
    padding: 10px;
    color: #EFEBE0;
    flex-grow: 1;
    pointer-events: auto; /* Allow interaction with bubble content if needed */
    box-shadow: 0 3px 8px rgba(0,0,0,0.4);
}

.rpg-dialogue-interjection-bubble strong {
    display: block;
    font-weight: bold;
    color: #D4C8A0;
    margin-bottom: 5px;
}
