/* VN Dialogue — Dialogue box, speaker name, typewriter, portrait */

/* === DIALOGUE BOX === */

.vn-dialogue-box {
    position: relative;
    /* Centered column wide enough to fit 4-6 lines of dialogue without
       clipping; gutters either side still leave room for character
       portraits but the text gets the breathing room it needs.
       overflow is intentionally `visible` so the speaker-portrait
       circle (positioned at top: -42px) and the speaker-name badge
       (top: -14px) can render outside the box. The inner text element
       carries its own scroll if dialogue is unusually long. */
    margin: 0 auto 2.5%;
    max-width: var(--vn-dialogue-max-width, 880px);
    width: min(var(--vn-dialogue-width, 94%), var(--vn-dialogue-max-width, 880px));
    padding: 1.1rem 1.3rem 0.9rem;
    background: linear-gradient(
        180deg,
        rgba(8, 8, 18, 0.9) 0%,
        rgba(12, 12, 25, 0.95) 100%
    );
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 6px;
    backdrop-filter: blur(16px);
    pointer-events: auto;
    cursor: pointer;
    min-height: 100px;
    overflow: visible;
    box-shadow:
        0 -4px 24px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.03);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.vn-dialogue-box.hidden {
    display: none;
}

/* === SPEAKER NAME === */

.vn-speaker-name {
    position: absolute;
    top: -14px;
    left: 20px;
    background: linear-gradient(135deg, #4a6fa5 0%, #3d5a8a 100%);
    color: #fff;
    padding: 4px 16px;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
}

.vn-speaker-name.narrator {
    background: linear-gradient(135deg, #555 0%, #444 100%);
    font-style: italic;
}

/* === DIALOGUE TEXT === */

.vn-dialogue-text {
    color: rgba(255, 255, 255, 0.92);
    font-size: clamp(1rem, 1.6vw, 1.2rem);
    line-height: 1.55;
    margin-top: 8px;
    min-height: 2.6em;
    max-height: 28vh;
    overflow-y: auto;
    font-family: 'Georgia', 'Times New Roman', serif;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    /* Thin scrollbar styling so it doesn't overpower the dialogue. */
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.18) transparent;
}
.vn-dialogue-text::-webkit-scrollbar { width: 6px; }
.vn-dialogue-text::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 3px; }

/* Typewriter cursor */
.vn-dialogue-text .vn-cursor {
    display: inline-block;
    width: 2px;
    height: 1.1em;
    background: rgba(255, 255, 255, 0.7);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: vn-blink 0.8s step-end infinite;
}

@keyframes vn-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Advance indicator — shows when text is fully revealed */
.vn-advance-indicator {
    position: absolute;
    bottom: 10px;
    right: 16px;
    color: rgba(255, 255, 255, 0.4);
    font-size: 0.85rem;
    animation: vn-bounce 1.5s ease-in-out infinite;
}

@keyframes vn-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

/* === SPEAKER PORTRAIT (small, in dialogue box) === */

.vn-speaker-portrait {
    position: absolute;
    top: -42px;
    width: 84px;
    height: 84px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.2);
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
    background: rgba(30, 30, 50, 0.8);
}

/* Default position: right of the dialogue box. .on-left flips it. The
   side is set by scene-director from the speaker's stage position so
   the inset matches where the actor stands on screen. */
.vn-speaker-portrait,
.vn-speaker-portrait.on-right { right: 24px; left: auto; }
.vn-speaker-portrait.on-left  { left: 24px; right: auto; }

.vn-speaker-portrait img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Lift the focal point so the face — typically generated in the
       upper third of the source image — stays visible in the circle. */
    object-position: 50% 18%;
}

.vn-speaker-portrait.hidden {
    display: none;
}

/* === CHOICE MENU === */

.vn-choices-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(640px, 92vw);
    width: min(90%, 640px);
}

.vn-choice-btn {
    background: linear-gradient(
        135deg,
        rgba(20, 20, 40, 0.9) 0%,
        rgba(30, 30, 55, 0.95) 100%
    );
    color: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(100, 140, 200, 0.25);
    border-radius: 6px;
    padding: 16px 22px;
    font-size: 1.15rem;
    font-family: 'Georgia', 'Times New Roman', serif;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    line-height: 1.4;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.vn-choice-btn:hover {
    background: linear-gradient(
        135deg,
        rgba(40, 50, 80, 0.95) 0%,
        rgba(50, 60, 100, 0.98) 100%
    );
    border-color: rgba(100, 150, 220, 0.5);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}

.vn-choice-btn:active {
    transform: translateY(0);
}

.vn-choice-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.vn-choice-btn .vn-choice-requirement {
    display: block;
    font-size: 0.75rem;
    color: rgba(255, 100, 100, 0.7);
    margin-top: 4px;
    font-style: italic;
}

/* === FREE-TEXT INPUT === */

.vn-freetext {
    display: flex;
    gap: 8px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    width: 100%;
}

.vn-freetext-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 5px;
    padding: 11px 14px;
    color: rgba(255, 255, 255, 0.9);
    font-family: 'Georgia', 'Times New Roman', serif;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.vn-freetext-input:focus {
    border-color: rgba(100, 150, 220, 0.5);
}

.vn-freetext-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
    font-style: italic;
}

.vn-freetext-send {
    background: linear-gradient(135deg, rgba(60, 80, 120, 0.8), rgba(40, 55, 90, 0.9));
    color: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(100, 140, 200, 0.3);
    border-radius: 5px;
    padding: 11px 18px;
    font-family: inherit;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.vn-freetext-send:hover {
    background: linear-gradient(135deg, rgba(70, 95, 140, 0.9), rgba(50, 65, 110, 0.95));
    color: #fff;
}

/* === INPUT PROMPT === */

.vn-input-prompt {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 500px;
}

.vn-input-label {
    color: rgba(255, 255, 255, 0.8);
    font-size: 1.15rem;
    font-family: 'Georgia', 'Times New Roman', serif;
    text-align: center;
}

.vn-input-field {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 5px;
    padding: 14px 16px;
    color: rgba(255, 255, 255, 0.95);
    font-family: 'Georgia', 'Times New Roman', serif;
    font-size: 1.2rem;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
}

.vn-input-field:focus {
    border-color: rgba(100, 150, 220, 0.6);
}

.vn-input-field::placeholder {
    color: rgba(255, 255, 255, 0.25);
}

.vn-input-submit {
    align-self: center;
    max-width: 200px;
}

.vn-choice-btn .vn-choice-tag {
    display: inline-block;
    background: rgba(100, 150, 255, 0.2);
    color: rgba(150, 180, 255, 0.9);
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 0.75rem;
    margin-right: 6px;
}

/* === HISTORY OVERLAY === */

.vn-history {
    position: absolute;
    inset: 0;
    background: rgba(5, 5, 15, 0.95);
    overflow-y: auto;
    padding: 2rem 3rem;
    display: none;
}

.vn-history.active {
    display: block;
}

.vn-history-entry {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.vn-history-speaker {
    color: rgba(100, 150, 220, 0.9);
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 4px;
}

.vn-history-text {
    color: rgba(255, 255, 255, 0.75);
    font-size: 1.1rem;
    line-height: 1.6;
}

.vn-history-close {
    position: sticky;
    top: 0;
    text-align: right;
    padding-bottom: 1rem;
}

/* === CHARACTER CREATION === */

.vn-char-creation {
    width: 100%;
    max-width: 520px;
    max-height: 85vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.vn-cc-title {
    text-align: center;
    color: #e0e0f0;
    font-size: 1.4rem;
    font-family: 'Georgia', serif;
    margin-bottom: 4px;
}

.vn-cc-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.vn-cc-label {
    color: rgba(255,255,255,0.6);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.vn-cc-input {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 5px;
    padding: 10px 14px;
    color: rgba(255,255,255,0.95);
    font-family: 'Georgia', serif;
    font-size: 1.1rem;
    text-align: center;
    outline: none;
}

.vn-cc-input:focus { border-color: rgba(100,150,220,0.5); }

.vn-cc-pills {
    display: flex;
    gap: 6px;
}

.vn-cc-pill {
    flex: 1;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 4px;
    padding: 8px;
    color: rgba(255,255,255,0.7);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.vn-cc-pill.active {
    background: rgba(74,111,165,0.3);
    border-color: rgba(74,111,165,0.6);
    color: #fff;
}

.vn-cc-row {
    display: flex;
    gap: 6px;
}

.vn-cc-select {
    flex: 1;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 4px;
    padding: 7px 8px;
    color: rgba(255,255,255,0.85);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
}

.vn-cc-archetypes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.vn-cc-archetype {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 6px;
    padding: 10px;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-family: inherit;
    font-size: 0.85rem;
}

.vn-cc-archetype strong { color: rgba(255,255,255,0.9); font-size: 0.95rem; }
.vn-cc-archetype .vn-cc-stats { color: rgba(100,180,255,0.6); font-size: 0.75rem; font-family: monospace; }

.vn-cc-archetype.active {
    background: rgba(74,111,165,0.2);
    border-color: rgba(74,111,165,0.5);
}

.vn-cc-stat-row {
    display: flex;
    align-items: center;
    gap: 8px;
    color: rgba(255,255,255,0.8);
    font-size: 0.9rem;
}

.vn-cc-stat-row span:first-child { width: 70px; }

.vn-cc-stat-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.15);
    background: rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.7);
    font-size: 1rem;
    cursor: pointer;
    font-family: inherit;
}

.vn-cc-points { color: rgba(100,180,255,0.7); font-size: 0.75rem; margin-left: 8px; }

.vn-cc-actions {
    display: flex;
    gap: 8px;
    margin-top: 6px;
}

.vn-cc-toggle {
    flex: 1;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 4px;
    padding: 10px;
    color: rgba(255,255,255,0.5);
    font-size: 0.8rem;
    cursor: pointer;
    font-family: inherit;
}

.vn-cc-start {
    flex: 1;
    background: linear-gradient(135deg, #4a6fa5, #5a3d8a);
    border: none;
    border-radius: 5px;
    padding: 12px 20px;
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: transform 0.15s;
}

.vn-cc-start:hover { transform: translateY(-1px); }

.vn-cc-portrait {
    text-align: center;
    min-height: 40px;
}

/* === MOBILE === */

@media (max-width: 768px) {
    .vn-dialogue-box {
        margin: 0 2% calc(1.5% + 36px); /* Extra space for controls below */
        padding: 0.8rem 1rem 0.6rem;
        min-height: 80px;
        max-height: 150px;
        border-radius: 4px;
    }

    .vn-dialogue-text {
        font-size: 0.9rem;
        line-height: 1.5;
    }

    .vn-speaker-name {
        font-size: 0.75rem;
        padding: 3px 10px;
        top: -12px;
    }

    .vn-speaker-portrait {
        width: 40px;
        height: 40px;
        top: -20px;
    }

    .vn-advance-indicator {
        font-size: 0.6rem;
        bottom: 6px;
        right: 10px;
    }

    .vn-choices-container {
        max-width: 95%;
        padding: 0 2%;
    }

    .vn-choice-btn {
        padding: 12px 14px;
        font-size: 0.85rem;
        min-height: 44px; /* Touch target */
    }

    .vn-history {
        padding: 1rem 1.5rem;
    }
}

@media (max-width: 480px) {
    .vn-dialogue-box {
        margin: 0 1% calc(1% + 34px); /* Clear controls on small phones */
        min-height: 70px;
    }

    .vn-dialogue-text {
        font-size: 0.85rem;
        line-height: 1.4;
    }

    .vn-choice-btn {
        padding: 10px 12px;
        font-size: 0.8rem;
    }
}
