/* ============================================
   ONE SHOT HERO - Cinematic Dialogue System
   The Chronicler Tutorial Overlay
   Matches premium leather-bound book aesthetic
   ============================================ */

/* === Main Overlay Container === */
.dialogue-overlay {
    position: fixed;
    inset: 0;
    z-index: 50000;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.6s ease, visibility 0.6s ease;
}

.dialogue-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* === Dark Cinematic Vignette === */
.dialogue-vignette {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 50% 40%,
            rgba(255, 180, 80, 0.05) 0%,
            rgba(0, 0, 0, 0.4) 50%,
            rgba(0, 0, 0, 0.85) 100%),
        /* Floating dust particles */
        radial-gradient(circle at 20% 30%, rgba(255, 200, 150, 0.03) 0%, transparent 20%),
        radial-gradient(circle at 80% 70%, rgba(200, 150, 100, 0.02) 0%, transparent 30%);
    pointer-events: none;
    animation: lanternFlicker 4s ease-in-out infinite;
}

@keyframes lanternFlicker {

    0%,
    100% {
        opacity: 0.9;
    }

    33% {
        opacity: 0.95;
    }

    66% {
        opacity: 0.85;
    }
}

/* === Narrator Container (Right Side) === */
.narrator-container {
    position: absolute;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0;
    padding: 20px;
    padding-bottom: 0;
    transform: translateX(50px);
    opacity: 0;
    transition: transform 0.7s cubic-bezier(0.16, 1, 0.3, 1),
        opacity 0.5s ease;
}

.dialogue-overlay.active .narrator-container {
    transform: translateX(0);
    opacity: 1;
}

/* === Narrator Portrait === */
.narrator-portrait {
    width: 300px;
    height: 400px;
    position: relative;
    filter: drop-shadow(-10px 0 30px rgba(0, 0, 0, 0.8));
}

.narrator-portrait-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: bottom right;
}

/* Placeholder styling when no image (transparent) */
.narrator-portrait-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: transparent;
}

/* === Dialogue Bubble - Parchment Style === */
.dialogue-bubble {
    position: absolute;
    right: 320px;
    bottom: 100px;
    max-width: 500px;
    /* Increased from 420px for smoother line breaks */
    min-width: 320px;

    /* Parchment background matching notebook pages */
    background:
        url('../img/parchment_bg.png') center/cover,
        linear-gradient(165deg, #f5ebe0 0%, #e8dcc8 50%, #d6cab0 100%);
    background-blend-mode: multiply, normal;

    /* Ornate double border like the game UI */
    border: 3px double var(--gold-ornament, #d4a84b);
    border-radius: var(--radius-md, 8px);
    padding: 32px 42px 24px;
    /* More generous side padding */

    /* Deep shadows matching notebook aesthetic */
    box-shadow:
        0 15px 40px rgba(0, 0, 0, 0.6),
        0 6px 15px rgba(0, 0, 0, 0.4),
        inset 0 1px 1px rgba(255, 255, 255, 0.5),
        inset 0 -2px 8px rgba(0, 0, 0, 0.1);

    transform: translateX(20px) scale(0.95);
    opacity: 0;
    transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1) 0.2s,
        opacity 0.4s ease 0.2s;
}

/* Aged paper texture overlay */
.dialogue-bubble::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        /* Coffee stain effect */
        radial-gradient(ellipse at 85% 85%, rgba(139, 90, 43, 0.06) 0%, transparent 40%),
        /* Paper fiber texture */
        url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
    border-radius: inherit;
    pointer-events: none;
    z-index: 0;
}

.dialogue-overlay.active .dialogue-bubble {
    transform: translateX(0) scale(1);
    opacity: 1;
}

/* Bubble tail pointing to narrator */
.dialogue-bubble::after {
    content: '';
    position: absolute;
    right: -18px;
    bottom: 40px;
    width: 0;
    height: 0;
    border-left: 20px solid var(--gold-ornament, #d4a84b);
    border-top: 12px solid transparent;
    border-bottom: 12px solid transparent;
    filter: drop-shadow(2px 2px 3px rgba(0, 0, 0, 0.3));
}

/* === Dialogue Text - Ink Style === */
.dialogue-text {
    position: relative;
    z-index: 1;
    color: #251810;
    /* Solid dark leather-ink for maximum legibility */
    font-family: var(--font-body, 'Lora', serif);
    font-size: 1.15rem;
    line-height: 1.6;
    /* Slightly tighter for cleaner 2-line blocks */
    margin: 0 0 24px 0;
    min-height: 2.8em;
    font-style: italic;
    text-align: center;
    /* Centered for better balance in a bubble */
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
}

/* Typewriter cursor */
.dialogue-text::after {
    content: '|';
    animation: blink-cursor 0.8s infinite;
    color: var(--ink-brown, #3d2914);
    margin-left: 2px;
    opacity: 0;
}

.dialogue-text.typing::after {
    opacity: 1;
}

@keyframes blink-cursor {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* === Controls Row === */
.dialogue-controls {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 12px;
    padding-top: 16px;
    border-top: 2px solid var(--gold-ornament, #d4a84b);
}

/* Decorative border ornament */
.dialogue-controls::before {
    content: '✵ ✵ ✵';
    position: absolute;
    top: -12px;
    /* Slightly higher to center on the line */
    left: 50%;
    transform: translateX(-50%);
    background: transparent;
    /* Removed solid color that looked like a white box */
    padding: 0 12px;
    color: var(--gold-ornament, #d4a84b);
    font-size: 0.8rem;
    letter-spacing: 0.4em;
    text-shadow:
        0 1px 0 rgba(255, 255, 255, 0.5),
        -1px -1px 0 #f5ebe0,
        1px -1px 0 #f5ebe0,
        -1px 1px 0 #f5ebe0,
        1px 1px 0 #f5ebe0;
    /* Subtle text-shadow outline to break the line without a box */
}

/* Continue indicator - styled like page prompt */
.dialogue-continue {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--ink-brown, #3d2914);
    font-family: 'IM Fell English', var(--font-body, 'Lora', serif);
    font-size: 1.1rem;
    /* Slightly larger for better readability */
    font-style: italic;
    opacity: 0.8;
    cursor: pointer;
    transition: all 0.3s ease;
    letter-spacing: 0.05em;
    line-height: 1;
    /* Reset line height for centering */
}

.dialogue-continue:hover {
    opacity: 1;
    color: var(--gold-dark, #9a7520);
}

.dialogue-continue-arrow {
    display: inline-block;
    animation: pulse-arrow 1.5s ease-in-out infinite;
    color: var(--gold-ornament, #d4a84b);
    font-weight: bold;
}

@keyframes pulse-arrow {

    0%,
    100% {
        transform: translateX(0);
        opacity: 0.7;
    }

    50% {
        transform: translateX(4px);
        opacity: 1;
    }
}

/* Skip button - styled like Begin Adventure button but smaller/muted */
.dialogue-skip-btn {
    font-family: 'Cinzel', var(--font-display, serif);
    font-size: 0.75rem;
    /* Balanced size */
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--parchment-light, #e8ddd0);
    background: linear-gradient(165deg,
            var(--leather-accent, #7a4f2a) 0%,
            var(--leather, #3d2815) 60%,
            var(--leather-dark, #251810) 100%);
    border: none;
    border-radius: 4px;
    padding: 10px 20px;
    /* More robust padding */
    cursor: pointer;
    position: relative;
    overflow: hidden;
    box-shadow:
        0 3px 0 var(--leather-dark, #251810),
        0 4px 12px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.1),
        inset 0 -1px 0 rgba(0, 0, 0, 0.2);
    transition: all 0.15s ease;
}

.dialogue-skip-btn::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.4s ease;
}

.dialogue-skip-btn:hover {
    transform: translateY(-1px);
    box-shadow:
        0 4px 0 var(--leather-dark, #251810),
        0 6px 16px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
    background: linear-gradient(165deg,
            #8b5a30 0%,
            #4a3016 60%,
            #2a1a0a 100%);
}

.dialogue-skip-btn:hover::after {
    left: 100%;
}

.dialogue-skip-btn:active {
    transform: translateY(1px);
    box-shadow:
        0 1px 0 var(--leather-dark, #251810),
        0 2px 6px rgba(0, 0, 0, 0.3),
        inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* === Don't Show Again Checkbox === */
.dialogue-dont-show {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid rgba(139, 90, 43, 0.2);
}

.dialogue-dont-show-checkbox {
    appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--ink-brown, #3d2914);
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.3);
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.dialogue-dont-show-checkbox:hover {
    border-color: var(--gold-ornament, #d4a84b);
    background: rgba(212, 168, 75, 0.1);
}

.dialogue-dont-show-checkbox:checked {
    background: var(--gold-ornament, #d4a84b);
    border-color: var(--gold-dark, #9a7520);
}

.dialogue-dont-show-checkbox:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--leather-dark, #251810);
    font-size: 0.75rem;
    font-weight: bold;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
}

.dialogue-dont-show-label {
    color: var(--ink-faded, #6b5a4a);
    font-family: 'IM Fell English', var(--font-body, 'Lora', serif);
    font-size: 0.85rem;
    font-style: italic;
    cursor: pointer;
    user-select: none;
    letter-spacing: 0.02em;
}

.dialogue-dont-show-label:hover {
    color: var(--ink-brown, #3d2914);
}

/* === Voice Over Indicator === */
.dialogue-voice-indicator {
    position: absolute;
    top: -10px;
    left: 24px;
    display: flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(165deg,
            var(--leather-accent, #7a4f2a) 0%,
            var(--leather, #3d2815) 100%);
    border: 2px solid var(--gold-ornament, #d4a84b);
    border-radius: 20px;
    padding: 5px 14px;
    font-family: var(--font-display, 'Cinzel', serif);
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--gold-highlight, #e8c060);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
    z-index: 2;
}

.voice-wave {
    display: flex;
    align-items: center;
    gap: 2px;
    height: 10px;
}

.voice-wave-bar {
    width: 2px;
    background: var(--gold-highlight, #e8c060);
    border-radius: 1px;
    animation: voice-wave 0.5s ease-in-out infinite;
}

.voice-wave-bar:nth-child(1) {
    animation-delay: 0s;
    height: 4px;
}

.voice-wave-bar:nth-child(2) {
    animation-delay: 0.1s;
    height: 7px;
}

.voice-wave-bar:nth-child(3) {
    animation-delay: 0.2s;
    height: 10px;
}

.voice-wave-bar:nth-child(4) {
    animation-delay: 0.3s;
    height: 6px;
}

@keyframes voice-wave {

    0%,
    100% {
        transform: scaleY(0.5);
    }

    50% {
        transform: scaleY(1);
    }
}

/* Hide voice indicator by default */
.dialogue-voice-indicator.hidden {
    display: none;
}

/* === Responsive Adjustments === */
@media (max-width: 900px) {
    .narrator-portrait {
        width: 220px;
        height: 300px;
    }

    .dialogue-bubble {
        right: 240px;
        max-width: 340px;
        min-width: 260px;
        padding: 22px 26px 20px;
    }

    .dialogue-text {
        font-size: 1.05rem;
    }
}

@media (max-width: 600px) {
    .narrator-container {
        right: 0;
        bottom: 0;
        padding: 10px;
    }

    .narrator-portrait {
        width: 150px;
        height: 220px;
    }

    .dialogue-bubble {
        right: 160px;
        bottom: 60px;
        max-width: 220px;
        min-width: 180px;
        padding: 16px 18px 14px;
    }

    .dialogue-text {
        font-size: 0.95rem;
        line-height: 1.6;
    }

    .dialogue-controls {
        flex-direction: column;
        gap: 10px;
    }

    .dialogue-controls::before {
        display: none;
    }
}