/* VN Layout — Full-viewport visual novel layer system */

/* Reset for VN mode */
.vn-viewport {
    position: fixed;
    inset: 0;
    overflow: hidden;
    background: #000;
    font-family: 'Georgia', 'Times New Roman', serif;
    user-select: none;
    cursor: default;
    -webkit-tap-highlight-color: transparent;
}

/* Stage fills viewport — no aspect ratio letterboxing */
.vn-stage {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

/* === LAYER STACK === */

.vn-layer-background {
    position: absolute;
    inset: 0;
    z-index: 0;
    overflow: hidden;
}

.vn-layer-background img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Dual background slots for crossfade transitions */
.vn-bg-current,
.vn-bg-next {
    position: absolute;
    inset: 0;
}

.vn-bg-current img,
.vn-bg-next img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.vn-layer-characters {
    position: absolute;
    inset: 0;
    z-index: 10;
    pointer-events: none;
    overflow: hidden;
}

.vn-layer-effects {
    position: absolute;
    inset: 0;
    z-index: 20;
    pointer-events: none;
}

.vn-layer-dialogue {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    pointer-events: none;
}

.vn-layer-choices {
    position: absolute;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.vn-layer-choices.active {
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
}

.vn-layer-ui {
    position: absolute;
    inset: 0;
    z-index: 50;
    pointer-events: none;
}

.vn-layer-modal {
    position: absolute;
    inset: 0;
    z-index: 100;
    display: none;
}

.vn-layer-modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
}

/* === CHARACTER POSITIONS === */

.vn-character {
    position: absolute;
    bottom: 14%;
    transform: translateX(-50%);
    pointer-events: none;
    overflow: hidden !important;
    width: 180px;
    height: 280px;
    border-radius: 10px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255,255,255,0.08);
}

.vn-character img {
    display: block;
    width: 180px !important;
    height: 280px !important;
    object-fit: cover;
    object-position: top center;
}

.vn-character[data-position="left"] { left: 18%; }
.vn-character[data-position="center-left"] { left: 33%; }
.vn-character[data-position="center"] { left: 50%; }
.vn-character[data-position="center-right"] { left: 67%; }
.vn-character[data-position="right"] { left: 82%; }

/* === IMAGE LOADING STATES === */

.vn-character.loading img {
    opacity: 0;
}

.vn-character.loading::after {
    content: '';
    position: absolute;
    inset: 10% 15%;
    background: linear-gradient(
        110deg,
        rgba(255,255,255,0.03) 30%,
        rgba(255,255,255,0.08) 50%,
        rgba(255,255,255,0.03) 70%
    );
    background-size: 200% 100%;
    animation: vn-shimmer 1.5s ease-in-out infinite;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.05);
}

.vn-bg-loading {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(8px);
}

.vn-bg-loading-content {
    text-align: center;
    color: rgba(255,255,255,0.6);
    font-size: 0.85rem;
}

.vn-bg-loading-bar {
    width: 120px;
    height: 3px;
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
    margin: 12px auto 0;
    overflow: hidden;
}

.vn-bg-loading-bar::after {
    content: '';
    display: block;
    width: 40%;
    height: 100%;
    background: rgba(255,255,255,0.4);
    border-radius: 2px;
    animation: vn-loading-slide 1.2s ease-in-out infinite;
}

@keyframes vn-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@keyframes vn-loading-slide {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(350%); }
}

/* === MAIN LOADING OVERLAY === */

.vn-loading {
    position: absolute;
    inset: 0;
    z-index: 90;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
    color: #ccc;
    font-size: 1.15rem;
    gap: 1rem;
}

.vn-loading-spinner {
    width: 36px;
    height: 36px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top-color: rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    animation: vn-spin 0.7s linear infinite;
}

@keyframes vn-spin {
    to { transform: rotate(360deg); }
}

.vn-loading-text {
    opacity: 0.6;
    font-style: italic;
    font-size: 0.9rem;
}

.vn-loading-subtext {
    opacity: 0.35;
    font-size: 0.75rem;
    margin-top: -0.5rem;
}

/* === UI CONTROLS === */

.vn-controls {
    position: absolute;
    bottom: 8px;
    right: 8px;
    display: flex;
    gap: 4px;
    pointer-events: auto;
}

.vn-control-btn {
    background: rgba(0, 0, 0, 0.55);
    color: rgba(255, 255, 255, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s ease;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.vn-control-btn:hover,
.vn-control-btn:active {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.vn-control-btn.active {
    background: rgba(100, 150, 255, 0.3);
    border-color: rgba(100, 150, 255, 0.5);
    color: #fff;
}

/* === SIDEBAR OVERLAY === */

.vn-sidebar {
    position: absolute;
    top: 0;
    right: 0;
    width: 300px;
    height: 100%;
    background: rgba(10, 10, 20, 0.94);
    border-left: 1px solid rgba(255, 255, 255, 0.06);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
    pointer-events: auto;
    z-index: 55;
    padding: 1rem;
    color: #ddd;
    backdrop-filter: blur(10px);
}

.vn-sidebar.open {
    transform: translateX(0);
}

.vn-sidebar-toggle {
    position: absolute;
    top: 8px;
    right: 8px;
    pointer-events: auto;
    z-index: 56;
}

/* === MOBILE OPTIMIZATION === */

@media (max-width: 768px) {
    .vn-character {
        width: 140px;
        height: 220px;
        bottom: 16%;
        border-radius: 8px;
    }

    .vn-character img {
        width: 140px !important;
        height: 220px !important;
    }

    .vn-character[data-position="left"] { left: 25%; }
    .vn-character[data-position="center-left"] { left: 35%; }
    .vn-character[data-position="center"] { left: 50%; }
    .vn-character[data-position="center-right"] { left: 65%; }
    .vn-character[data-position="right"] { left: 75%; }

    .vn-sidebar {
        width: 100%;
    }

    .vn-controls {
        bottom: 4px;
        right: 4px;
        gap: 3px;
    }

    .vn-control-btn {
        padding: 6px 8px;
        font-size: 0.65rem;
        min-height: 32px;
        min-width: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .vn-sidebar-toggle {
        top: 6px;
        right: 6px;
        min-height: 32px;
    }
}

/* Very small screens (phones) */
@media (max-width: 480px) {
    .vn-character {
        width: 110px;
        height: 170px;
        bottom: 20%;
    }

    .vn-character img {
        width: 110px !important;
        height: 170px !important;
    }

    .vn-controls {
        bottom: 2px;
        right: 2px;
        gap: 2px;
    }

    .vn-control-btn {
        padding: 5px 6px;
        font-size: 0.6rem;
    }
}

/* Landscape phones */
@media (max-height: 500px) and (orientation: landscape) {
    .vn-character {
        width: 120px;
        height: 180px;
        bottom: 20%;
    }

    .vn-character img {
        width: 120px !important;
        height: 180px !important;
    }
}
