/* NPC conversation: an RPG dialogue box at the bottom centre (name plate,
   portrait, recent lines, choices, free input). Clear of the Kiki icon
   (bottom right) and the room chat (bottom left) on wide screens. */

.npc-dialogue {
    position: fixed;
    left: 50%;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    z-index: 13;
    width: min(560px, calc(100vw - 24px));
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 14px 12px;
    color: #f4f7ff;
    background: linear-gradient(180deg, rgba(20, 28, 52, 0.96), rgba(12, 18, 34, 0.96));
    border: 2px solid rgba(255, 212, 90, 0.7);
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(255, 255, 255, 0.06);
    font-size: 14px;
    pointer-events: auto;
    touch-action: manipulation;
}

/* The door panel and the dialogue share the bottom centre. */
body.npc-dialogue-open .portal-panel { display: none !important; }

@media (max-width: 1100px) {
    body.npc-dialogue-open .ccw-chat { display: none; }
}

@media (max-width: 640px) {
    body.npc-dialogue-open .kiki-world { display: none; }
    body.npc-dialogue-open .recenter-button { display: none; }
}

.npc-head {
    display: flex;
    align-items: center;
    gap: 10px;
}

.npc-portrait {
    flex: none;
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    overflow: hidden;
    background: radial-gradient(circle at 50% 35%, #33507e, #1a2744);
    border: 2px solid rgba(255, 212, 90, 0.8);
    border-radius: 12px;
}

.npc-portrait img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 50% 8%;
    transform: scale(1.7);
    transform-origin: 50% 12%;
    image-rendering: auto;
}

.npc-initial {
    font-size: 22px;
    font-weight: 800;
    color: #ffd45a;
}

.npc-plate {
    flex: 1;
    min-width: 0;
}

.npc-name {
    margin: 0;
    font-size: 16px;
    font-weight: 800;
    color: #ffd45a;
    letter-spacing: 0.01em;
}

.npc-role {
    margin: 2px 0 0;
    font-size: 12px;
    color: #b9c6e4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.npc-close {
    flex: none;
    width: 34px;
    height: 34px;
    font-size: 22px;
    line-height: 1;
    color: #dbe4ff;
    background: rgba(255, 255, 255, 0.08);
    border: 0;
    border-radius: 10px;
    cursor: pointer;
}

.npc-close:hover { background: rgba(255, 255, 255, 0.16); }

.npc-log {
    list-style: none;
    margin: 0;
    padding: 2px 2px 2px 0;
    max-height: min(210px, 32vh);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-wrap: anywhere;
    overscroll-behavior: contain;
}

.npc-line {
    max-width: 92%;
    padding: 7px 10px;
    border-radius: 10px;
    line-height: 1.5;
}

.npc-line p { margin: 0; }
.npc-line p + p { margin-top: 6px; }

.npc-line.is-npc {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.npc-line.is-user {
    align-self: flex-end;
    color: #1c2333;
    background: #8fd3ff;
}

.npc-line.is-note {
    align-self: center;
    max-width: 100%;
    padding: 3px 10px;
    font-size: 12px;
    color: #c8d3ee;
    background: none;
}

.npc-line.is-warn { color: #ffd45a; }
.npc-line.is-error { color: #ff9a9a; }

.npc-line.is-typing p:last-child::after,
.npc-line.is-typing p:empty::after {
    content: "▍";
    margin-left: 1px;
    color: #ffd45a;
    opacity: 0.8;
}

.npc-dots {
    display: inline-flex;
    gap: 4px;
    padding: 2px 0;
}

.npc-dots i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #c8d3ee;
    animation: npc-dot 1s ease-in-out infinite;
}

.npc-dots i:nth-child(2) { animation-delay: 0.15s; }
.npc-dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes npc-dot {
    0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-2px); }
}

@media (prefers-reduced-motion: reduce) {
    .npc-dots i { animation: none; opacity: 0.7; }
}

.npc-status {
    margin: 0;
    font-size: 12px;
    color: #5ee7ff;
}

.npc-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.npc-choice {
    min-height: 34px;
    padding: 6px 12px;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    color: #ffe9a8;
    background: rgba(255, 212, 90, 0.1);
    border: 1px solid rgba(255, 212, 90, 0.55);
    border-radius: 999px;
    cursor: pointer;
}

.npc-choice::before {
    content: "▸ ";
    color: #ffd45a;
}

.npc-choice:hover:not(:disabled) { background: rgba(255, 212, 90, 0.22); }
.npc-choice:disabled { opacity: 0.5; cursor: default; }

.npc-form {
    display: flex;
    gap: 6px;
}

.npc-input {
    flex: 1;
    min-width: 0;
    padding: 9px 11px;
    font: inherit;
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 10px;
}

.npc-input::placeholder { color: rgba(255, 255, 255, 0.55); }
.npc-input:focus { outline: 2px solid rgba(255, 212, 90, 0.7); outline-offset: 0; }

.npc-send {
    padding: 0 16px;
    font: inherit;
    font-weight: 700;
    color: #1b1300;
    background: #ffd45a;
    border: 0;
    border-radius: 10px;
    cursor: pointer;
}

.npc-send:disabled { opacity: 0.6; cursor: default; }

@media (max-width: 640px) {
    .npc-dialogue {
        bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        padding: 10px;
    }

    .npc-log { max-height: 26vh; }
    .npc-portrait { width: 44px; height: 44px; }
}
