/* Global Styles */
body,
html {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Noto Sans KR', sans-serif;
    background-color: #222222;
}

/* For Game Interface (Play Page) */
body.game-body {
    overflow: hidden;
    /* Prevent scrolling only on game page */
}

/* Visual Area */
.visual-area-wrapper {
    background-color: #222222;
    /* Common Background */
    position: relative;
    overflow: hidden;
}

/* The 4:3 Game Stage */
.background-img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    /* On PC, limit height to viewport minus padding to prevent overflow */
    max-height: 80vh;
    object-fit: contain;
    filter: brightness(0.7);
    margin: 0 auto;
}

/* Character Layer overlays the background */

.character-layer {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.character-sprite {
    height: 95%;
    width: auto;
    max-width: 100%;
    object-fit: contain;
    filter: drop-shadow(0 0 10px rgba(0, 0, 0, 0.5));
}

/* Chat Interface */
.chat-interface {
    min-height: 50vh;
    background-color: #f8f9fa;
    border-left: 1px solid #dee2e6;
}

.chat-log {
    overflow-y: auto;
    background-color: #fff;
    font-size: 1rem;
}

/* Mobile Specific Optimizations */
/* Mobile Specific Optimizations */
@media (max-width: 991.98px) {
    .visual-area-wrapper {
        height: 35vh;
        /* Fixed height for visual area */
        padding: 0;
        z-index: 10;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
        /* Shadow to separate from chat */
    }

    .game-stage {
        /* Maintain 4:3 ratio to ensure background and character align perfectly */
        aspect-ratio: 4/3;
        width: auto;
        height: auto;
        max-width: 100%;
        max-height: 100%;
        position: relative;
    }

    .background-img {
        max-height: 100%;
        width: 100%;
        object-fit: contain;
        /* Show full image */
    }

    .chat-interface {
        height: 65vh;
        /* Remaining height */
        flex: none;
        /* Disable flex growing in row context, force fixed height */
        border-left: none;
        border-top: 1px solid #444;
        /* Darker separator */
    }

    /* Ensure chat log scrolls properly */
    .chat-log {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        /* Smooth scroll on iOS */
    }
}

/* PC Specific Optimizations */
@media (min-width: 992px) {
    .visual-area-wrapper {
        height: 100vh;
        padding: 16px;
        /* Padding inside the dark area */
    }

    .game-stage {
        /* 
           Smart Sizing: 
           Width is 100% of container, BUT capped at the width that would result in (100vh - 32px) height.
           Formula: MaxWidth = (100vh - 32px padding) * (4/3 aspect ratio).
        */
        width: min(100%, calc((100vh - 32px) * 1.333333));
        aspect-ratio: 4/3;
        height: auto;

        position: relative;
        margin: auto;
    }

    .background-img {
        /* Fill the stage */
        width: 100%;
        height: 100%;
        max-height: none;
        /* Reset global mobile limit */
        object-fit: contain;
        /* Ensure full visibility */
        background-color: #000;
        /* Letterbox fill if any */
    }

    .chat-interface {
        height: 100vh;
    }

    .chat-log {
        font-size: 1.1rem;
    }
}

/* Message Styles - KakaoTalk Theme */

/* Chat Log Background */
.chat-log {
    background-color: #fce4ec;
    /* Soft Pink BG */
}

/* Common Message Container */
.message {
    padding: 0 5px;
    margin-bottom: 10px;
    clear: both;
    display: flex;
    flex-direction: column;
}

/* NPC (Left) */
.npc-container {
    align-items: flex-start;
}

.npc-name {
    margin-bottom: 5px;
    margin-left: 2px;
    font-size: 0.85rem;
    color: #880e4f;
    /* Dark Pink Text for name */
    font-weight: normal;
}

.message-bubble.npc {
    background-color: #ffffff;
    padding: 8px 12px;
    border-radius: 4px 12px 12px 12px;
    /* Square top-left */
    position: relative;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    max-width: 75%;
    word-wrap: break-word;
    font-size: 0.95rem;
    color: #4a4a4a;
}

/* Player (Right) */
.player-container {
    align-items: flex-end;
}

.message-bubble.player {
    background-color: #f8bbd0;
    /* Pink Bubble */
    padding: 8px 12px;
    border-radius: 12px 4px 12px 12px;
    /* Square top-right */
    position: relative;
    text-align: left;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    max-width: 75%;
    word-wrap: break-word;
    font-size: 0.95rem;
    color: #4a4a4a;
}

/* Remove old styles */
.player-name {
    display: none;
}

.message.system {
    color: #666;
    font-size: 0.85rem;
    text-align: center;
    border-radius: 20px;
    padding: 5px 15px;
    background-color: rgba(0, 0, 0, 0.1);
    width: fit-content;
    margin: 10px auto;
    border: none;
}

/* Typing Indicator Tweaks for Bubble */
.typing-indicator {
    background-color: transparent;
    padding: 0;
    margin: 0;
}

.typing-indicator span {
    display: inline-block;
    width: 6px;
    height: 6px;
    background-color: #666;
    border-radius: 50%;
    margin: 0 2px;
    animation: typing 1s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-3px);
    }
}

/* Affinity Hearts */
#affinityDisplay {
    pointer-events: none;
    /* Let clicks pass through if needed */
}

.heart-icon {
    font-size: 1.8rem;
    margin: 0 2px;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5));
}

/* Animations for Affinity Change */
@keyframes shake-earthquake {
    0% {
        transform: translate(0, 0) rotate(0deg);
    }

    10% {
        transform: translate(-8px, -8px) rotate(-8deg);
    }

    20% {
        transform: translate(8px, 8px) rotate(8deg);
    }

    30% {
        transform: translate(-8px, 8px) rotate(-8deg);
    }

    40% {
        transform: translate(8px, -8px) rotate(8deg);
    }

    50% {
        transform: translate(-4px, 4px) rotate(-4deg);
    }

    60% {
        transform: translate(4px, -4px) rotate(4deg);
    }

    70% {
        transform: translate(-2px, 2px) rotate(-2deg);
    }

    80% {
        transform: translate(2px, -2px) rotate(2deg);
    }

    90% {
        transform: translate(-1px, 1px) rotate(0deg);
    }

    100% {
        transform: translate(0, 0) rotate(0deg);
    }
}

@keyframes flash-burst {
    0% {
        transform: scale(1);
        filter: brightness(1);
    }

    10% {
        transform: scale(1.5);
        filter: brightness(3) drop-shadow(0 0 30px gold);
    }

    50% {
        transform: scale(1.2);
        filter: brightness(1.5);
    }

    100% {
        transform: scale(1);
        filter: brightness(1);
    }
}

.anim-shake {
    animation: shake-earthquake 0.6s cubic-bezier(.36, .07, .19, .97) both !important;
    transform-origin: center center;
    backface-visibility: hidden;
}

.anim-burst {
    animation: flash-burst 0.8s ease-out both !important;
    transform-origin: center center;
    backface-visibility: hidden;
}

/* =========================================
   Intro Screen & Scenario Selection Styles
   ========================================= */

.intro-title {
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
    letter-spacing: -2px;
}

.scenario-card {
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), box-shadow 0.3s ease;
    cursor: pointer;
    overflow: hidden;
    position: relative;
    border: 1px solid #444;
}

.scenario-card:hover {
    transform: translateY(-10px);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.5) !important;
    border-color: #888;
    z-index: 10;
}

.scenario-bg {
    transition: transform 0.5s ease, opacity 0.3s ease;
}

.scenario-char {
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-origin: bottom center;
}

/* Hover Effect: Zoom BG, Pop Character */
.scenario-card:hover .scenario-bg {
    transform: scale(1.1);
    opacity: 0.8 !important;
}

.scenario-card:hover .scenario-char {
    transform: translate(-50%, 0) scale(1.1);
}

/* Mobile specific for Intro */
@media (max-width: 768px) {
    .scenario-card {
        margin-bottom: 20px;
    }

    .intro-title {
        font-size: 2.5rem;
    }
}

/* Footer Link Hover */
.footer-link {
    transition: all 0.2s ease;
}

.footer-link:hover {
    text-decoration: underline !important;
    color: #ffffff !important;
}

/* Blink Warning Animation */
@keyframes blink-warning {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }

    100% {
        opacity: 1;
    }
}

.blink-warning {
    animation: blink-warning 1s infinite alternate;
}