:root {
    /* Warm library palette */
    --bg: #1b1713; /* page background */
    --panel: #2a221c; /* left pane bg */
    --border: rgba(255,217,168,0.12);
    --muted: #a88d74; /* muted text */
    --text: #efe6d9; /* main text on dark */
    --accent: #f1b866; /* buttons */
    --bubble: #2f2620; /* bot bubble */
    --bubble-me: #dfc9a4; /* user bubble */
    --bubble-me-border: #c7ae83;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
}

/* ================================================== */
/* --- LOGIN OVERLAY STYLES (KEPT) --- */
/* ================================================== */
#loginOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(27, 23, 19, 0.95); /* Dark background with opacity, matching --bg */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.login-card {
    background: var(--panel);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    width: 100%;
    max-width: 400px;
    text-align: center;
    border: 1px solid var(--border);
}

.login-card h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 5px;
}

.login-card h3 {
    font-size: 18px;
    color: var(--muted);
    margin-bottom: 25px;
}

.login-form {
    text-align: left;
}

.login-form label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: var(--text);
    margin-top: 15px;
}

.login-form input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    box-sizing: border-box;
    transition: border-color 0.2s;
    background: #3a2f28; /* Darker input background */
    color: var(--text);
}

.login-form input:focus {
    border-color: var(--accent);
    outline: none;
}

.login-form button {
    width: 100%;
    padding: 10px;
    margin-top: 30px;
    background-color: var(--accent);
    color: #3b2b18; /* Dark text on accent */
    border: none;
    border-radius: 6px;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.2s;
}

.login-form button:hover {
    background-color: #e5a954; /* Slightly darker accent */
}

.login-form button:disabled {
    background-color: #6d6153;
    cursor: not-allowed;
}

.credentials-info {
    background-color: #3a2f28; /* Dark background for info */
    border-left: 4px solid var(--accent);
    padding: 15px;
    border-radius: 6px;
    font-size: 14px;
    color: var(--text);
    margin-bottom: 20px;
}

.credentials-info code {
    font-weight: 600;
    background: #4a3a30;
    padding: 2px 4px;
    border-radius: 3px;
    color: var(--accent);
}

/* Status Messages */
.status-message {
    height: 20px;
    margin-bottom: 15px;
    font-size: 14px;
    text-align: center;
    color: var(--text);
}

.status-loading {
    color: var(--accent);
}

.status-success {
    color: #8ac926; /* Green for success */
    font-weight: 600;
}

.status-error {
    color: #f72585; /* Pink/Red for error */
    font-weight: 600;
}

/* ================================================== */
/* --- MAIN CHAT UI STYLES (REVERTED TO ORIGINAL) --- */
/* ================================================== */

/* Layout: 2/7 + 5/7 */
.app {
    display: grid;
    grid-template-columns: 2fr 5fr;
    height: 100vh;
}

/* LEFT PANE */
.left {
    background: var(--panel);
    color: var(--text);
    border-right: 2px solid var(--border);
    padding: 16px;
    display: grid;
    grid-template-rows: auto /* header */
    auto /* tools */
    auto /* shelf */
    auto /* info strip */
    1fr; /* art panel fills remainder */
    gap: 10px;
    overflow: hidden;
}

.left__header h3 {
    margin: 0;
}

/* Tools bar */
.tools {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

    .tools input[type="search"] {
        border: 1px solid var(--border);
        border-radius: 10px;
        padding: 8px 10px;
        color: var(--text);
        background: #3a2f28;
    }

.btn {
    background: var(--accent);
    color: #3b2b18;
    border: 1px solid var(--border);
    font-weight: 700;
    cursor: pointer;
}

    .btn.btn--small {
        padding: 6px 10px;
        border-radius: 10px;
    }

/* ===== Horizontal bookshelf ===== */
.shelfWrap {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #3a2f28;
    padding: 8px 6px;
}

.shelf {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 6px;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
}

    .shelf::-webkit-scrollbar {
        height: 8px;
    }

    .shelf::-webkit-scrollbar-thumb {
        background: rgba(241,184,102,0.35);
        border-radius: 8px;
    }

    .shelf::-webkit-scrollbar-track {
        background: rgba(0,0,0,0.15);
    }

/* Book spines */
.book {
    flex: 0 0 42px;
    height: 132px;
    border-radius: 6px;
    border: 1px solid rgba(0,0,0,0.35);
    position: relative;
    scroll-snap-align: start;
    cursor: pointer;
    box-shadow: inset 0 0 0 1px rgba(255,217,168,0.12);
    transition: transform .15s ease, box-shadow .15s ease, outline-color .15s;
    background: linear-gradient(180deg, rgba(0,0,0,.18), rgba(0,0,0,0)) 0 0/100% 40% no-repeat, linear-gradient(90deg, rgba(255,217,168,.55), rgba(255,217,168,.1)) 14px 0/2px 100% no-repeat, radial-gradient(120% 70% at 30% 10%, rgba(255,255,255,.08), transparent), #4a3a30;
}

    .book:hover {
        transform: translateY(-2px);
        box-shadow: inset 0 0 0 1px rgba(255,217,168,0.25), 0 6px 18px rgba(0,0,0,.25);
    }

    .book.active {
        outline: 2px solid rgba(241,184,102,0.55);
        outline-offset: 2px;
    }

.book__band {
    position: absolute;
    inset: 6px;
    border-radius: 4px;
    box-shadow: inset 0 0 0 1px rgba(255,217,168,0.14);
}

/* Tooltip on hover */
.book__tt {
    position: absolute;
    left: 50%;
    bottom: 100%;
    transform: translate(-50%, -8px);
    padding: 6px 8px;
    background: #2f2620;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .85rem;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity .12s ease, transform .12s ease;
    box-shadow: 0 8px 16px rgba(0,0,0,.25);
}

.book:hover .book__tt {
    opacity: 1;
    transform: translate(-50%, -10px);
}

/* New chat book */
.book--new {
    background: repeating-linear-gradient(90deg, rgba(241,184,102,.25) 0 2px, transparent 2px 6px), #3e2f26;
    border-style: dashed;
}

    .book--new::after {
        content: "+";
        position: absolute;
        inset: 0;
        display: grid;
        place-items: center;
        color: rgba(241,184,102,.9);
        font-weight: 700;
        font-size: 18px;
    }

/* Info strip */
.shelfInfo {
    font-size: .9rem;
    color: var(--muted);
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #3a2f28;
    min-height: 34px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

/* Title + meta + delete button layout */
.shelfInfo__main {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.shelfInfo__titleRow {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.shelfInfo__label {
    font-size: 0.8rem;
    color: var(--muted);
    white-space: nowrap;
}

.shelfInfo__titleInput {
    flex: 1;
    min-width: 0;
    border-radius: 8px;
    border: 1px solid var(--border);
    padding: 3px 6px;
    background: #2f2620;
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
}

    .shelfInfo__titleInput::placeholder {
        color: rgba(232, 210, 184, 0.6);
    }

.shelfInfo__meta {
    font-size: 0.8rem;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.iconBtn {
    border-radius: 999px;
    border: 1px solid var(--border);
    padding: 4px 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
}

    .iconBtn:hover {
        background: rgba(0,0,0,0.12);
        color: var(--accent);
    }

/* Background / character stage (big animated panel) */
.bgpanel {
    justify-self: center;
    width: 92%;
    min-height: 220px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #3a2f28;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 0 2px rgba(255,217,168,0.18), 0 8px 20px rgba(0,0,0,0.25);
}

    /* Inner frame */
    .bgpanel::before {
        content: "";
        position: absolute;
        inset: 10px;
        border-radius: 10px;
        box-shadow: inset 0 0 0 3px rgba(241,184,102,0.25);
        pointer-events: none;
    }

/* Full-panel sprite */
.bgpanel__sprite {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
}

/* Status pill in bottom-left of bgpanel */
.bgpanelStage {
    position: absolute;
    left: 14px;
    bottom: 14px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(15, 10, 6, 0.8);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.4);
}

.bgpanelStage__icon {
    width: 64px;
    height: 64px;
    border-radius: 10px;
    object-fit: cover;
    flex-shrink: 0;
}

.bgpanelStage__text {
    font-size: 0.85rem;
    color: var(--text);
}

/* Hide any legacy vertical list */
.convos {
    display: none !important;
}

/* RIGHT PANE */
.right {
    display: grid;
    grid-template-rows: auto 1fr auto;
    height: 100vh;
    padding: 16px 20px;
    gap: 12px;
}

.right__header h2 {
    margin: 0;
    color: var(--text);
}

.right__messages {
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    background: rgba(255,233,200,0.03);
    /* No flex centering here, reverting to block flow */
}

.msg {
    max-width: 72ch;
    margin: 0 0 10px 0; /* Bot messages default to left align */
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bubble);
    color: var(--text);
}

    .msg.me {
        margin-left: auto; /* Pushes user messages to the right */
        background: var(--bubble-me);
        color: #2a241f;
        border-color: var(--bubble-me-border);
    }

/* Composer */
.right__composer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
}

    .right__composer textarea {
        resize: none;
        min-height: 44px;
        max-height: 30vh;
        border: 1px solid var(--border);
        border-radius: 12px;
        padding: 10px 12px;
        background: rgba(255,233,200,0.06);
        color: var(--text);
        outline: none;
    }

    .right__composer button {
        border: 1px solid var(--border);
        background: var(--accent);
        color: #3b2b18;
        border-radius: 12px;
        padding: 0 18px;
        cursor: pointer;
        font-weight: 700;
    }

/* Responsive */
@media (max-width: 900px) {
    .app {
        grid-template-columns: 1fr;
    }

    .left {
        height: 46vh;
    }

    .right {
        height: 54vh;
    }
}