/* ==========================================================================
   A PERSONALIZED BIRTHDAY FRIENDSHIP VISUAL NOVEL - 16-BIT PIXEL ART STYLES
   ========================================================================== */

:root {
    --bg-dark: #0f111a;
    --dialogue-bg: rgba(15, 20, 35, 0.92);
    --dialogue-border: #f4b251;
    --dialogue-border-glow: rgba(244, 178, 81, 0.4);
    --accent-gold: #ffcf68;
    --accent-blue: #60a5fa;
    --accent-pink: #f472b6;
    --text-main: #f8fafc;
    --text-muted: #cbd5e1;
    --btn-bg: #1e293b;
    --btn-hover: #334155;
    --btn-border: #475569;
    --font-pixel: 'Courier New', Courier, monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
    font-family: var(--font-pixel);
    color: var(--text-main);
    touch-action: manipulation;
    overscroll-behavior: none;
}

/* ==========================================================================
   APP CONTAINER & RESPONSIVE 16:9 VIEWPORT
   ========================================================================== */

#game-wrapper {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #08090e;
}

#game-viewport {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 177.78vh; /* 16:9 ratio */
    max-height: 56.25vw;
    background: #000;
    overflow: hidden;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.9);
}

/* Fallback for portrait mobile: allow filling viewport nicely */
@media (max-aspect-ratio: 16/10) {
    #game-viewport {
        max-width: 100vw;
        max-height: 100vh;
    }
}

/* Background Scene Layer */
#scene-bg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    transition: opacity 0.5s ease-in-out, transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1;
}

/* Camera Zoom / Pan Shots */
#scene-bg.shot-establishing {
    transform: scale(1);
}
#scene-bg.shot-medium {
    transform: scale(1.08) translateY(-2%);
}
#scene-bg.shot-closeup {
    transform: scale(1.2) translateY(-4%);
}
#scene-bg.shot-reaction {
    transform: scale(1.15) translateY(-2%);
}
#scene-bg.shot-emotional-wide {
    transform: scale(1.02);
}

/* Ambient Lighting & CRT Overlay */
#lighting-layer {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 40%, rgba(255, 230, 180, 0.08) 0%, rgba(10, 12, 20, 0.35) 100%);
    pointer-events: none;
    z-index: 2;
}

#crt-scanlines {
    position: absolute;
    inset: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%);
    background-size: 100% 4px;
    pointer-events: none;
    z-index: 99;
    opacity: 0.35;
}

/* ==========================================================================
   CHARACTER PORTRAIT STAGE
   ========================================================================== */

#character-stage {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 3;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 4%;
    padding-bottom: 220px;
}

.stage-character {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    opacity: 0;
    transform: translateY(25px);
}

.stage-character.active {
    opacity: 1;
    transform: translateY(0);
}

.stage-character.speaking {
    filter: drop-shadow(0 0 12px rgba(255, 207, 104, 0.6));
    transform: translateY(-6px) scale(1.03);
}

.stage-character.dimmed {
    opacity: 0.6;
    filter: brightness(0.65) grayscale(20%);
    transform: translateY(10px) scale(0.97);
}

.portrait-frame {
    width: 220px;
    height: 220px;
    background: rgba(15, 23, 42, 0.7);
    border: 3px solid var(--dialogue-border);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.8), inset 0 0 15px rgba(244, 178, 81, 0.2);
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.portrait-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    image-rendering: pixelated;
    transition: transform 0.2s ease;
}

/* Full body stand stage (Elevator, Diabari, Residential scenes) */
#fullbody-stage {
    position: absolute;
    bottom: 190px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 40px;
    align-items: flex-end;
    pointer-events: none;
    z-index: 4;
}

.fullbody-char {
    image-rendering: pixelated;
    filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.85));
    transition: transform 0.3s ease, opacity 0.4s ease;
}

/* Height difference: Boy taller (scale 1.15), Girl smaller (scale 0.95) */
.fullbody-boy {
    height: 310px;
}
.fullbody-girl {
    height: 260px;
}

/* ==========================================================================
   INTERACTIVE MINIGAME & INSPECTION OVERLAY
   ========================================================================== */

#interactive-overlay {
    position: absolute;
    inset: 0;
    z-index: 25;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    padding-bottom: 180px; /* Leave comfortable room for dialogue box */
}

#interactive-overlay.active {
    pointer-events: auto;
}

.inspect-card-container {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    max-width: 90%;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.inspect-btn {
    background: rgba(15, 23, 42, 0.92);
    border: 2px solid var(--accent-gold);
    color: #fff;
    padding: 14px 22px;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s ease;
    touch-action: manipulation;
}

.inspect-btn:hover, .inspect-btn:active {
    background: var(--accent-gold);
    color: #000;
    transform: translateY(-3px) scale(1.04);
    box-shadow: 0 6px 20px rgba(255, 207, 104, 0.6);
}

.inspect-btn.examined {
    border-color: #64748b;
    opacity: 0.65;
}

/* Study Timer Widget (Level 2) */
.study-timer-box {
    background: rgba(15, 23, 42, 0.96);
    border: 3px solid #38bdf8;
    border-radius: 12px;
    padding: 24px 32px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.85);
    animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.study-clock-display {
    font-size: 36px;
    color: #38bdf8;
    margin: 12px 0;
    letter-spacing: 2px;
    font-weight: bold;
    text-shadow: 0 0 12px rgba(56, 189, 248, 0.6);
}

/* Empathy Decision Cards (Level 3) */
.empathy-card {
    background: rgba(15, 23, 42, 0.95);
    border: 2px solid #a855f7;
    border-radius: 12px;
    padding: 22px;
    max-width: 580px;
    width: 90%;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.8);
    animation: fadeIn 0.4s ease;
}

.empathy-question {
    font-size: 16px;
    line-height: 1.5;
    margin-bottom: 16px;
    color: #e9d5ff;
}

.empathy-option {
    display: block;
    width: 100%;
    margin-bottom: 10px;
    padding: 12px 16px;
    background: #1e1b4b;
    border: 1px solid #c084fc;
    color: #f3e8ff;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
}

.empathy-option:hover, .empathy-option:active {
    background: #c084fc;
    color: #0f172a;
    font-weight: bold;
}

/* ==========================================================================
   DIALOGUE BOX & TEXT PRESENTATION
   ========================================================================== */

#dialogue-container {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    width: 92%;
    max-width: 1080px;
    z-index: 10;
    transition: all 0.3s ease;
}

.dialogue-box {
    position: relative;
    background: var(--dialogue-bg);
    border: 3px solid var(--dialogue-border);
    border-radius: 12px;
    padding: 18px 24px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.85), inset 0 0 20px rgba(244, 178, 81, 0.15);
    min-height: 135px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    backdrop-filter: blur(8px);
    cursor: pointer;
}

.speaker-tag {
    position: absolute;
    top: -16px;
    left: 20px;
    background: #1e293b;
    border: 2px solid var(--dialogue-border);
    color: var(--accent-gold);
    font-weight: bold;
    font-size: 14px;
    padding: 4px 16px;
    border-radius: 6px;
    letter-spacing: 1px;
    text-transform: uppercase;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
}

.speaker-tag.Girl {
    border-color: #60a5fa;
    color: #93c5fd;
    background: #172554;
}

.speaker-tag.Boy {
    border-color: #f59e0b;
    color: #fcd34d;
    background: #451a03;
}

.speaker-tag.Narration {
    border-color: #a855f7;
    color: #e9d5ff;
    background: #2e1065;
}

.dialogue-text {
    font-size: 18px;
    line-height: 1.6;
    letter-spacing: 0.5px;
    margin-top: 8px;
    min-height: 58px;
    word-break: break-word;
}

/* Glowing flashing advance indicator */
.advance-indicator {
    align-self: flex-end;
    color: var(--accent-gold);
    font-size: 18px;
    animation: bounceDown 0.8s infinite alternate ease-in-out;
}

/* Fast controls bar (top right of dialogue) */
.vn-controls-bar {
    position: absolute;
    top: -34px;
    right: 12px;
    display: flex;
    gap: 8px;
}

.vn-btn {
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid var(--btn-border);
    color: var(--text-muted);
    font-size: 12px;
    font-family: inherit;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
}

.vn-btn:hover, .vn-btn:active {
    background: var(--dialogue-border);
    color: #000;
    font-weight: bold;
}

/* ==========================================================================
   CHOICES CONTAINER
   ========================================================================== */

#choices-container {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 85%;
    max-width: 580px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 12;
    pointer-events: none;
}

#choices-container.active {
    pointer-events: auto;
}

.choice-btn {
    background: rgba(15, 23, 42, 0.95);
    border: 2px solid var(--accent-gold);
    color: #fff;
    padding: 16px 20px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.7);
    transition: all 0.2s ease;
    touch-action: manipulation;
    text-align: center;
}

.choice-btn:hover, .choice-btn:active {
    background: var(--accent-gold);
    color: #000;
    transform: scale(1.03);
    box-shadow: 0 8px 25px rgba(255, 207, 104, 0.6);
}

/* ==========================================================================
   START SCREEN & TITLE UI
   ========================================================================== */

#title-screen {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 6vh 4vw;
    background: linear-gradient(rgba(10, 12, 22, 0.42), rgba(8, 10, 18, 0.86)), url('assets/ui/title_screen_wallpaper_hd.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    image-rendering: pixelated;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

#title-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.title-header {
    text-align: center;
    animation: fadeInDown 0.8s ease;
}

.title-banner-main {
    font-size: clamp(24px, 5vw, 42px);
    font-weight: bold;
    color: #fff;
    text-shadow: 0 0 15px rgba(244, 178, 81, 0.8), 0 4px 10px #000;
    letter-spacing: 2px;
    margin-bottom: 8px;
}

.title-sub-banner {
    font-size: clamp(13px, 2.5vw, 17px);
    color: var(--accent-gold);
    letter-spacing: 1px;
}

.title-action-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 90%;
    max-width: 380px;
    animation: fadeInUp 0.8s ease;
}

.title-btn {
    background: #1e293b;
    border: 2px solid var(--dialogue-border);
    color: #fff;
    padding: 16px 24px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.6);
    transition: all 0.2s ease;
    touch-action: manipulation;
    text-align: center;
    letter-spacing: 1px;
}

.title-btn:hover, .title-btn:active {
    background: var(--dialogue-border);
    color: #000;
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 8px 24px rgba(244, 178, 81, 0.5);
}

.title-btn.start {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #000;
    border-color: #fef3c7;
}

/* Chapter Select Modal */
#chapter-modal {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 40;
    display: flex;
    justify-content: center;
    align-items: center;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

#chapter-modal.active {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}

.chapter-box {
    background: #111827;
    border: 2px solid var(--accent-gold);
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 480px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.9);
}

.chapter-item {
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 8px;
    padding: 14px 18px;
    margin: 12px 0;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chapter-item:hover, .chapter-item:active {
    background: #374151;
    border-color: var(--accent-gold);
    transform: translateX(6px);
}

/* ==========================================================================
   CINEMATIC FULLSCREEN BANNERS (Quote, Friendship Started, Birthday)
   ========================================================================== */

#cinematic-banner-overlay {
    position: absolute;
    inset: 0;
    z-index: 35;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(10, 12, 20, 0.92);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    padding: 24px;
    text-align: center;
}

#cinematic-banner-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.cinematic-main-title {
    font-size: clamp(24px, 4vw, 38px);
    font-weight: bold;
    color: var(--accent-gold);
    text-shadow: 0 0 20px rgba(244, 178, 81, 0.8);
    margin-bottom: 20px;
    letter-spacing: 2px;
    animation: popIn 0.6s ease;
}

.cinematic-sub-text {
    font-size: clamp(15px, 2.4vw, 20px);
    line-height: 1.8;
    max-width: 720px;
    color: #f1f5f9;
    letter-spacing: 0.5px;
    margin-bottom: 28px;
}

/* Confetti particles for Birthday Reveal */
.confetti-canvas {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 16;
}

/* Screen Transitions (Black Fade) */
#transition-fader {
    position: absolute;
    inset: 0;
    background: #000;
    z-index: 30;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease-in-out;
}

#transition-fader.fade-in {
    opacity: 1;
    pointer-events: auto;
}

/* ==========================================================================
   MOBILE CONTROLS BAR (THUMB-FRIENDLY)
   ========================================================================== */

#mobile-touch-bar {
    position: absolute;
    top: 14px;
    left: 14px;
    z-index: 18;
    display: flex;
    gap: 8px;
}

.mobile-icon-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.9);
    border: 2px solid var(--dialogue-border);
    color: #fff;
    font-size: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
    touch-action: manipulation;
    transition: transform 0.15s ease, background 0.15s ease;
}

.mobile-icon-btn:hover, .mobile-icon-btn:active {
    background: var(--dialogue-border);
    color: #000;
    transform: scale(1.1);
}

/* ==========================================================================
   KEYFRAME ANIMATIONS
   ========================================================================== */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes popIn {
    0% { transform: scale(0.8); opacity: 0; }
    70% { transform: scale(1.05); opacity: 1; }
    100% { transform: scale(1); }
}

@keyframes bounceDown {
    from { transform: translateY(0); }
    to { transform: translateY(5px); }
}

/* ==========================================================================
   MOBILE OPTIMIZATIONS & BREAKPOINTS
   ========================================================================== */

@media (max-width: 768px) {
    #character-stage {
        padding-bottom: 185px;
        padding-left: 2%;
        padding-right: 2%;
    }

    .portrait-frame {
        width: 140px;
        height: 140px;
        border-width: 2px;
    }

    .fullbody-boy {
        height: 230px;
    }
    .fullbody-girl {
        height: 195px;
    }

    #dialogue-container {
        width: 95%;
        bottom: max(12px, env(safe-area-inset-bottom, 12px));
    }

    .dialogue-box {
        padding: 14px 18px;
        min-height: 125px;
    }

    .dialogue-text {
        font-size: 15px;
        line-height: 1.5;
        min-height: 48px;
    }

    .speaker-tag {
        font-size: 12px;
        padding: 3px 12px;
    }

    .vn-controls-bar {
        top: -32px;
    }

    .vn-btn {
        padding: 6px 12px;
        font-size: 11px;
        min-height: 32px;
    }

    #interactive-overlay {
        padding: 12px;
        padding-bottom: 175px;
    }

    .inspect-btn {
        padding: 14px 20px;
        font-size: 14px;
        min-height: 48px;
    }

    .empathy-option {
        padding: 14px 16px;
        font-size: 13px;
        min-height: 48px;
    }

    .title-btn {
        padding: 16px 20px;
        font-size: 15px;
        min-height: 52px;
    }
}

/* Landscape mobile optimization */
@media (max-height: 550px) and (orientation: landscape) {
    #character-stage {
        padding-bottom: 130px;
    }

    .portrait-frame {
        width: 100px;
        height: 100px;
    }

    #dialogue-container {
        bottom: 8px;
        width: 96%;
    }

    .dialogue-box {
        padding: 10px 16px;
        min-height: 95px;
    }

    .dialogue-text {
        font-size: 13px;
        line-height: 1.4;
        min-height: 36px;
    }

    #interactive-overlay {
        padding-bottom: 120px;
    }

    .inspect-btn {
        padding: 10px 16px;
        font-size: 13px;
    }
}
