﻿/* Cinematic Container */
.chat-container {
    display: flex;
    flex-direction: row;
    width: 100%;
    height: 100vh;
    background: linear-gradient(180deg, #2f2f2f 0%, #2a2a2a 100%);
    border-radius: 0;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
    transition: all 0.3s ease-in-out;
}

/* Custom Scrollbar Styles */
.chat-window::-webkit-scrollbar,
.stats-sidebar::-webkit-scrollbar {
    width: 12px;
}

.chat-window::-webkit-scrollbar-track,
.stats-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.chat-window::-webkit-scrollbar-thumb,
.stats-sidebar::-webkit-scrollbar-thumb {
    background-color: #000;
    border-radius: 6px;
    border: 3px solid transparent;
    background-clip: padding-box;
}

body.chat-shell .chat-window {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

body.chat-shell .chat-window::-webkit-scrollbar {
    display: none;
}

/* Chat Main */
.chat-main {
    display: grid;
    grid-template-columns: 4fr auto;
    grid-template-rows: 1fr auto;
    grid-template-areas:
        "chat-window stats-sidebar"
        "chat-input  stats-sidebar";
    flex: 1;
    padding: 0;
    margin: 0;
    height: 100vh;
    min-height: 0;
}

/* Chat Window */
.chat-window {
    grid-area: chat-window;
    flex: 1;
    padding: 20px 5% 110px;
    overflow-y: auto;
    background:
        linear-gradient(180deg, #202020 0%, #1b1b1b 100%);
    font-size: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;     /* center all message bubbles */
    max-width: 100%;
    position: relative;      /* allow absolute children like #turn-changes */
}

/* Stats Sidebar */
.stats-sidebar {
    grid-area: stats-sidebar;
    flex: 0.2;
    padding: 12px;
    background-color: #2c2c2c;
    border-left: 1px solid rgba(255, 255, 255, 0.06);
    overflow: visible;
    font-size: 25px;
    border-radius: 0 15px 15px 0;
    box-shadow: inset -2px 0 10px rgba(0,0,0,0.5);
    min-width: 120px;
    height: 100vh;
    position: sticky;
    top: 0;
    z-index: 3100;
}

.stats-sidebar h3 {
    margin-top: 0;
    margin-bottom: 10px;
    color: #2983dd;
    font-size: 1.6em;
    border-bottom: 2px solid #2983dd;
    padding-bottom: 5px;
}

.stats-summary {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 18px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    padding: 12px 14px;
}

.stats-portrait-wrap {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 4px;
}

.stats-portrait-image {
    width: 128px;
    height: 128px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    -ms-interpolation-mode: nearest-neighbor;
    background: rgba(0, 0, 0, 0.25);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: 0.9em;
    color: #f0f0f0;
}

.stat-label {
    font-weight: 600;
}

.stat-value {
    margin-left: auto;
    text-align: right;
    white-space: nowrap;
}

.inventory-list {
    list-style: none;
    margin: 0;
    padding: 0 0 0 6px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.inventory-section-label {
    margin: 12px 0 6px;
    font-weight: 700;
    color: #ffd166;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.inventory-section-label--count {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.inventory-count-badge {
    font-size: 0.8em;
    font-weight: 700;
    color: #ffd166;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 209, 102, 0.45);
    border-radius: 999px;
    padding: 2px 8px;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.inventory-section-label:first-child {
    margin-top: 0;
}

.inventory-section-gap {
    height: 10px;
}

.inventory-item {
    font-size: 0.85em;
    color: #f7f7f7;
    display: flex;
    flex-direction: column;
    gap: 4px;
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: normal;
    line-height: 1.2;
    position: relative;
    padding-left: 16px;
}

.inventory-item::before {
    content: "";
}

.inventory-item .item-qty {
    color: #a8b8ff;
    font-size: 0.9em;
    margin-left: 6px;
    white-space: nowrap;
    word-break: normal;
    overflow-wrap: normal;
    flex-shrink: 0;
}

.inventory-item .item-name {
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1;
}

.inventory-item .item-emoji {
    flex: 0 0 auto;
    color: initial !important;
    text-shadow: none !important;
    filter: none !important;
    font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}

.ui-emoji {
    color: initial !important;
    text-shadow: none !important;
    filter: none !important;
    font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}

.inventory-item .item-emoji.emoji-pixelated,
.ui-emoji.emoji-pixelated {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
}

.pixel-emoji-image {
    display: block;
    height: 1em;
    width: auto;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.inventory-item .item-creature-meta {
    color: #a8b8ff;
    font-size: 0.82em;
    line-height: 1.2;
    margin-left: 0;
}

.inventory-item .item-creature-abilities {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
    position: relative;
    overflow: visible;
}

.inventory-item .creature-ability {
    position: relative;
    display: inline-flex;
    align-items: center;
    font-size: 0.75em;
    color: #d8ecff;
    background: rgba(41, 131, 221, 0.24);
    border: 1px solid rgba(41, 131, 221, 0.75);
    border-radius: 999px;
    padding: 2px 8px;
    cursor: help;
}

.inventory-item .creature-ability .ability-info {
    display: none;
    font-size: 0.95em;
    line-height: 1.25;
    color: #d8ecff;
    background: #000000;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid #0088ff;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.55);
    position: absolute;
    left: auto;
    right: 0;
    transform: none;
    top: calc(100% + 4px);
    z-index: 4000;
    min-width: 180px;
    width: max-content;
    max-width: min(320px, calc(100vw - 40px));
    white-space: pre-line;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.inventory-item .creature-ability:hover .ability-info,
.inventory-item .creature-ability:focus-within .ability-info {
    display: block;
}

.inventory-item .item-info {
    display: none;
    font-size: 0.95em;
    line-height: 1.25;
    color: #d8ecff;
    background: #000000;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid #0088ff;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.55);
    position: absolute;
    left: auto;
    right: 0;
    top: calc(100% + 4px);
    z-index: 4000;
    min-width: 180px;
    width: max-content;
    max-width: min(320px, calc(100vw - 40px));
    white-space: pre-line;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.inventory-item[data-item-info]:hover .item-info,
.inventory-item[data-item-info]:focus-within .item-info {
    display: block;
}

.inventory-item .item-creature-abilities:hover ~ .item-info,
.inventory-item .item-creature-abilities:focus-within ~ .item-info {
    display: none !important;
}

.inventory-item.empty::before {
    content: "";
    margin-right: 0;
}

.stats-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

#stats-close {
    display: none;
    background: transparent;
    border: none;
    color: #e0e0e0;
    font-size: 1.6em;
    cursor: pointer;
}

.stats-sidebar hr {
    border: 0;
    height: 1px;
    background: #2983dd;
    margin: 20px 0;
}

/* Message Bubble Base */
.message-text {
    padding: 15px 20px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.38);
    transition: background-color 0.3s ease-in-out, transform 0.2s, box-shadow 0.2s ease-in-out;
    font-size: 38px;
    width: fit-content;       /* shrink-to-fit based on content */
    max-width: 80%;           /* never exceed 80% of the chat-window */
    word-wrap: break-word;     /* wrap long words if needed */
    white-space: pre-wrap;
    margin: 0 auto 50px;      /* center horizontally with bottom spacing */
}

/* User Messages (blue) */
.user-message .message-text {
    background: linear-gradient(180deg, #2f8de8 0%, #2578c9 100%);
    color: #ffffff;
    max-width: 100%;
}

.user-message .message-text::selection {
    background: var(--terminal-selection-bg, #ffe082);
    color: var(--terminal-selection-text, #1a1a1a);
}

.user-message .message-text::-moz-selection {
    background: var(--terminal-selection-bg, #ffe082);
    color: var(--terminal-selection-text, #1a1a1a);
}

.user-message .message-text:hover {
    background: linear-gradient(180deg, #2b85dc 0%, #216fb8 100%);
    transform: scale(1.02);
    box-shadow: 0 10px 24px rgba(20, 79, 133, 0.45);
}

/* Game Messages (grey) */
.game-message .message-text {
    background: linear-gradient(180deg, #343434 0%, #2f2f2f 100%);
    color: #e3e3e3;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.65), 0 2px 6px rgba(0, 0, 0, 0.55);
}

.game-message .message-text::selection {
    background: var(--terminal-selection-bg, #ffe082);
    color: var(--terminal-selection-text, #1a1a1a);
}

.game-message .message-text::-moz-selection {
    background: var(--terminal-selection-bg, #ffe082);
    color: var(--terminal-selection-text, #1a1a1a);
}

@media (min-width: 1024px) {
    .message-text {
        max-width: 72%;
    }

    .user-message .message-text {
        max-width: 100%;
    }
}

.game-message .message-text:hover {
    background: linear-gradient(180deg, #3b3b3b 0%, #363636 100%);
    transform: scale(1.02);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.48);
}

.generated-scene-image {
    width: 1536px;
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    image-rendering: auto;
    -ms-interpolation-mode: bicubic;
    filter: none;
}

.game-message.has-turn-deltas .message-text {
    cursor: help;
}

/* Chat Input Styling */
.chat-input {
    grid-area: chat-input;
    background: linear-gradient(180deg, #2f2f2f 0%, #292929 100%);
    padding: 10px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    height: 80px;
    position: sticky;
    bottom: 0;
    z-index: 10;
}

.chat-input form {
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 1000px;
}

.chat-input input[type="text"] {
    flex: 1;
    padding: 12px 18px;
    border: none;
    border-radius: 25px;
    margin-right: 10px;
    font-size: 18px;
    outline: none;
    background-color: #3f3f3f;
    color: #e0e0e0;
    text-align: center;
    caret-color: transparent;
    transition: background-color 0.3s ease-in-out, box-shadow 0.2s ease-in-out;
}

.chat-input input[type="text"].typing {
    animation: none;
}
.chat-input input[type="text"].keypress-effect {
    animation: pressFlash 0.2s ease-out;
}
.chat-input input[type="text"]:focus {
    background-color: #383838;
    box-shadow: none;
}
.chat-input input[type="text"]::placeholder {
    color: #b0b0b0;
    text-align: center;
}

.chat-input button {
    padding: 12px 24px;
    border: none;
    background-color: #2983dd;
    color: #fff;
    border-radius: 25px;
    cursor: pointer;
    font-size: 18px;
    transition: background-color 0.3s ease-in-out, transform 0.2s;
    margin-left: 5px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.chat-input button:hover {
    background-color: #1c6fb4;
    transform: translateY(-2px);
}

/* Undo Button */
.undo-button {
    background-color: #ff5722;
}

/* TTS Toggle */
#tts-toggle {
    background-color: #2196f3; /* blue when off */
}

#tts-volume {
    margin-left: 10px;
}

#sfx-volume {
    margin-left: 10px;
}

#tts-toggle.toggled {
    background-color: #4caf50; /* green when on */
}

#sfx-typing-toggle,
#sfx-cursor-toggle,
#sfx-notify-toggle,
#sfx-hum-toggle {
    background-color: #2196f3; /* blue when off */
}

#sfx-typing-toggle.toggled,
#sfx-cursor-toggle.toggled,
#sfx-notify-toggle.toggled,
#sfx-hum-toggle.toggled {
    background-color: #4caf50; /* green when on */
}

.settings-button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
}

.settings-button-row > button {
    flex: 1 1 0;
}

/* Settings Controls */
#settings-btn {
    background-color: #2983dd;
}


/* Modal overlay for settings controls */
#settings-modal,
#help-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 3000;
    align-items: center;
    justify-content: center;
}

#settings-panel,
#help-panel {
    background-color: #2c2c2c;
    border: 1px solid #99ccff;
    border-radius: 8px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 320px;
}

.settings-section {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 5px;
    flex-wrap: wrap;
}

#sfx-pack-select {
    min-width: min(420px, 100%);
    flex: 2 1 320px;
    text-align: left;
    text-align-last: left;
}

.modal-close,
#settings-close,
#help-close {
    background: none;
    border: none;
    color: #e0e0e0;
    font-size: 32px;
    align-self: flex-end;
    cursor: pointer;
    line-height: 1;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
}

#settings-panel select,
#settings-panel input[type="range"],
#settings-panel button {
    flex: 1;
}

#help-panel {
    max-width: min(760px, 92vw);
}

.help-section {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 14px 20px;
    align-items: start;
}

.help-heading {
    font-weight: 700;
}

.font-selector {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}

.font-selector select {
    width: 100%;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid #555;
    background-color: #1f1f1f;
    color: #fff;
    text-align: center;
    text-align-last: center;
}

#music-toggle {
    background-color: #2196f3;
}

#music-toggle.toggled {
    background-color: #4caf50;
}

#music-volume {
    margin-left: 10px;
}

/* Popup for inventory/currency changes */
#turn-changes {
    /* Position relative to the viewport so it always appears near the
       bottom of the chat area regardless of scroll position */
    position: fixed;
    left: 50%;
    top: 50%;
    bottom: auto;
    transform: translate(-50%, -50%);
    background: #000;
    color: #ffd48d;
    padding: 12px 18px;
    border: 1px solid rgba(245, 155, 47, 0.34);
    border-radius: 0;
    font-family: inherit;
    line-height: 1.25;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.5);
    text-shadow:
        0 0 2px rgba(245, 155, 47, 0.8),
        0 0 8px rgba(245, 155, 47, 0.18);
    opacity: 0;
    pointer-events: none;
    z-index: 2000;
    transition: opacity 0.5s ease-in-out;
    display: none;
}

#message-turn-changes {
    position: fixed;
    top: 0;
    left: 0;
    max-width: min(560px, 92vw);
    max-height: 50vh;
    overflow-y: auto;
    padding: 12px 16px;
    border: 1px solid var(--terminal-border);
    border-radius: 0;
    background:
        linear-gradient(180deg, rgba(24, 14, 8, 0.97) 0%, rgba(11, 7, 4, 0.99) 100%);
    color: color-mix(in srgb, var(--terminal-amber-soft) 72%, white);
    line-height: 1.3;
    font-size: 16px;
    box-shadow:
        0 0 0 1px color-mix(in srgb, var(--terminal-amber-soft) 8%, transparent),
        0 12px 30px rgba(0, 0, 0, 0.44);
    text-shadow: none;
    opacity: 0;
    pointer-events: none;
    z-index: 3000;
    transition: opacity 0.14s ease-in-out;
}

#message-turn-changes.visible {
    opacity: 1;
}

#message-turn-changes.forced-visible {
    opacity: 1;
}

.turn-change-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.turn-change-line {
    white-space: normal;
}

.turn-change-divider {
    width: 100%;
    height: 0;
    margin: 4px 0 6px;
    border-top: 1px solid color-mix(in srgb, var(--terminal-border) 78%, transparent);
    opacity: 0.75;
}

.undo-button:hover {
    background-color: #e64a19;
    transform: translateY(-2px);
}

/* Stats layout */
.stats-flex {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: calc(100vh - 32px);
    overflow-y: visible;
    overflow-x: visible;
    padding-right: 4px;
}

#inventory,
#currency {
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: normal;
}

#inventory {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 260px;
    width: 100%;
}

#stats-btn {
    display: none;
}

.stats-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 3200;
}

.stats-overlay.visible {
    display: block;
}

body.stats-modal-open {
    overflow: hidden;
}

@media (max-width: 768px) {
    #turn-changes {
        width: auto;
        bottom: 180px;
    }

    .stats-flex {
        flex-direction: row;
        justify-content: space-between;
        max-height: none;
        overflow: visible;
        padding-right: 0;
    }

    #inventory,
    #currency {
        width: 48%;
    }

    #inventory {
        max-height: none;
        overflow-y: visible;
        max-width: 100%;
    }

    .inventory-item {
        padding-left: 0;
    }

    .inventory-item::before {
        position: static;
        margin-right: 4px;
    }

    .inventory-item .item-name {
        flex-direction: row;
        align-items: baseline;
        flex-wrap: wrap;
        gap: 6px;
        min-width: 0;
    }

    .inventory-item .item-info {
        display: block !important;
        position: static;
        background: transparent;
        border: none;
        box-shadow: none;
        padding: 0;
        margin-left: 14px;
        color: #a8b8ff;
        font-size: 0.78em;
        width: auto;
        min-width: 0;
        max-width: 100%;
        white-space: normal;
        word-break: break-word;
        overflow-wrap: anywhere;
    }
}
