/* 神迹 Wiki — AI 问答面板 */

.ai-chat-toggle {
    position: fixed;
    right: max(14px, env(safe-area-inset-right));
    bottom: max(14px, env(safe-area-inset-bottom));
    z-index: 170;
    width: 48px;
    height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid rgba(212, 180, 131, 0.42);
    background:
        linear-gradient(145deg, rgba(212, 180, 131, 0.2), rgba(18, 14, 12, 0.82)),
        rgba(12, 10, 10, 0.84);
    color: rgba(255, 236, 210, 0.94);
    backdrop-filter: blur(12px);
    box-shadow:
        0 10px 26px rgba(0, 0, 0, 0.42),
        inset 0 1px 0 rgba(255, 236, 210, 0.1);
    cursor: pointer;
    transition:
        border-color 0.2s ease,
        color 0.2s ease,
        transform 0.2s ease,
        box-shadow 0.2s ease;
}

.ai-chat-toggle:hover,
.ai-chat-toggle:focus-visible {
    outline: none;
    border-color: rgba(232, 201, 154, 0.7);
    color: #fff6e4;
    transform: translateY(-1px);
    box-shadow:
        0 12px 28px rgba(0, 0, 0, 0.48),
        0 0 18px rgba(212, 180, 131, 0.14);
}

.ai-chat-toggle[aria-expanded="true"] {
    border-color: rgba(232, 201, 154, 0.75);
    color: #ffe8b8;
}

.ai-chat-toggle-icon {
    display: grid;
    place-items: center;
    line-height: 0;
}

body.battlemap-mode .ai-chat-toggle,
body.book-toc-drawer-open .ai-chat-toggle {
    opacity: 0.35;
}

.ai-chat-panel {
    position: fixed;
    right: max(14px, env(safe-area-inset-right));
    bottom: calc(14px + 56px + env(safe-area-inset-bottom));
    z-index: 171;
    width: min(392px, calc(100vw - 28px));
    height: min(560px, calc(100vh - 110px));
    display: flex;
    flex-direction: column;
    border-radius: 18px;
    border: 1px solid rgba(212, 180, 131, 0.28);
    background:
        radial-gradient(ellipse 80% 50% at 50% 0%, rgba(90, 62, 28, 0.22), transparent 70%),
        linear-gradient(165deg, rgba(28, 22, 18, 0.96), rgba(10, 9, 8, 0.98));
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(16px);
    overflow: hidden;
    color: rgba(255, 244, 228, 0.92);
}

.ai-chat-panel.hidden {
    display: none;
}

.ai-chat-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 14px 12px;
    border-bottom: 1px solid rgba(232, 201, 154, 0.12);
}

.ai-chat-header-copy {
    min-width: 0;
}

.ai-chat-kicker {
    margin: 0 0 4px;
    font-size: 0.68rem;
    letter-spacing: 0.22em;
    text-indent: 0.22em;
    text-transform: uppercase;
    color: rgba(212, 180, 131, 0.78);
}

.ai-chat-title {
    margin: 0;
    font-family: "Cormorant Garamond", "Noto Serif SC", Georgia, serif;
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: #fff4e4;
}

.ai-chat-sub {
    margin: 4px 0 0;
    font-size: 0.78rem;
    line-height: 1.45;
    color: rgba(230, 214, 190, 0.62);
}

.ai-chat-close {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid rgba(232, 201, 154, 0.18);
    background: rgba(255, 255, 255, 0.03);
    color: rgba(255, 236, 210, 0.78);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
}

.ai-chat-close:hover {
    border-color: rgba(232, 201, 154, 0.4);
    color: #fff6e4;
}

.ai-chat-messages {
    flex: 1;
    overflow: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}

.ai-chat-bubble {
    max-width: 92%;
    padding: 10px 12px;
    border-radius: 14px;
    font-size: 0.9rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-chat-bubble--bot {
    align-self: flex-start;
    background: rgba(255, 236, 210, 0.06);
    border: 1px solid rgba(232, 201, 154, 0.14);
    color: rgba(255, 244, 228, 0.92);
}

.ai-chat-bubble--user {
    align-self: flex-end;
    background: rgba(212, 180, 131, 0.18);
    border: 1px solid rgba(232, 201, 154, 0.28);
    color: #fff8ec;
}

.ai-chat-bubble--error {
    align-self: stretch;
    background: rgba(140, 48, 40, 0.22);
    border: 1px solid rgba(220, 120, 100, 0.35);
    color: #ffd4c8;
}

.ai-chat-sources {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.ai-chat-source-btn {
    appearance: none;
    border: 1px solid rgba(232, 201, 154, 0.28);
    background: rgba(0, 0, 0, 0.22);
    color: rgba(255, 228, 190, 0.9);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.72rem;
    line-height: 1.3;
    cursor: pointer;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-chat-source-btn:hover:not(:disabled) {
    border-color: rgba(232, 201, 154, 0.55);
    color: #fff4e0;
}

.ai-chat-source-btn:disabled {
    cursor: default;
    opacity: 0.72;
}

.ai-chat-form {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid rgba(232, 201, 154, 0.12);
    background: rgba(0, 0, 0, 0.18);
}

.ai-chat-input {
    flex: 1;
    min-width: 0;
    resize: none;
    height: 42px;
    max-height: 96px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(232, 201, 154, 0.22);
    background: rgba(255, 255, 255, 0.04);
    color: #fff6e8;
    font: inherit;
    line-height: 1.4;
}

.ai-chat-input::placeholder {
    color: rgba(230, 214, 190, 0.42);
}

.ai-chat-input:focus {
    outline: none;
    border-color: rgba(232, 201, 154, 0.5);
}

.ai-chat-send {
    flex-shrink: 0;
    min-width: 72px;
    border-radius: 12px;
    border: 1px solid rgba(232, 201, 154, 0.4);
    background: linear-gradient(145deg, rgba(212, 180, 131, 0.28), rgba(90, 62, 28, 0.35));
    color: #fff4e4;
    font: inherit;
    font-size: 0.88rem;
    cursor: pointer;
    padding: 0 12px;
}

.ai-chat-send:hover:not(:disabled) {
    border-color: rgba(232, 201, 154, 0.7);
}

.ai-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-chat-status {
    padding: 0 14px 10px;
    font-size: 0.72rem;
    color: rgba(230, 214, 190, 0.45);
}

@media (max-width: 520px) {
    .ai-chat-panel {
        right: max(8px, env(safe-area-inset-right));
        left: max(8px, env(safe-area-inset-left));
        width: auto;
        height: min(68vh, calc(100vh - 100px));
        bottom: calc(12px + 54px + env(safe-area-inset-bottom));
    }

    .ai-chat-toggle {
        right: max(12px, env(safe-area-inset-right));
        bottom: max(12px, env(safe-area-inset-bottom));
    }
}
