/* ================================================================
   1. ЗМІННІ ТА БАЗОВІ НАЛАШТУВАННЯ
   ================================================================ */
:root {
    --primary-color: #a960ee;
    --secondary-color: #ff7eb9;
    --text-color: #ffffff;
    --bg-color-1: #3d2c5a;
    --bg-color-2: #1e152e;
    
    --box-background: rgba(0, 0, 0, 0.2);
    --box-border: 1px solid rgba(255, 255, 255, 0.1);
    --box-shadow: 0 15px 30px rgba(0,0,0,0.3);

    --font-main: 'Montserrat', sans-serif;

    /* ДОДАНО: Змінні для Safe Areas (Notch на iPhone) */
    --sat: env(safe-area-inset-top);
    --sab: env(safe-area-inset-bottom);
    --sar: env(safe-area-inset-right);
    --sal: env(safe-area-inset-left);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* Кастомний скролбар */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.1); }
::-webkit-scrollbar-thumb { background: var(--primary-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--secondary-color); }

body, html {
    margin: 0; padding: 0; width: 100%;
    height: 100%; 
    overflow: hidden; 
    font-family: var(--font-main);
    color: var(--text-color);
    background: linear-gradient(135deg, var(--bg-color-1), var(--bg-color-2));
    background-attachment: fixed;
    position: relative;
    -webkit-font-smoothing: antialiased;
}

body::before, body::after {
    content: ''; position: absolute; border-radius: 50%;
    filter: blur(120px); z-index: 0; pointer-events: none;
}
body::before { width: 400px; height: 400px; background: var(--primary-color); top: -100px; left: -100px; }
body::after { width: 300px; height: 300px; background: var(--secondary-color); bottom: 0; right: -80px; }

/* ================================================================
   2. ЕКРАНИ (ЛОГІКА ПЕРЕМИКАННЯ)
   ================================================================ */
.screen {
    width: 100%; height: 100%; 
    overflow-y: auto; 
    display: none;
    position: relative; opacity: 0; transition: opacity 0.5s ease-in-out; z-index: 2;
    /* ДОДАНО: Врахування Safe Areas для скролу */
    padding-top: var(--sat);
    padding-bottom: var(--sab);
}

.screen.active {
    display: flex; flex-direction: column; padding: 20px; opacity: 1;
}

/* ================================================================
   3. ЕКРАНИ ВВОДУ (ЦЕНТРУВАННЯ)
   ================================================================ */
#gender-selection-screen .intro-box, 
#statistics-screen .intro-box { margin: auto; }

/* РЕКОМЕНДАЦІЯ: Обмеження ширини на планшетах */
@media screen and (min-width: 600px) and (orientation: portrait) {
    .intro-box { max-width: 500px; }
}

.intro-box {
    background: var(--box-background); backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px); border: var(--box-border);
    box-shadow: var(--box-shadow); border-radius: 20px;
    padding: 30px 40px; text-align: center; max-width: 600px; width: 100%;
}
.intro-box p { text-align: justify; line-height: 1.5; }
.intro-box h1 {
    color: var(--text-color); text-shadow: 0 0 8px var(--primary-color), 0 0 16px var(--secondary-color);
    margin-top: 0; font-size: 2rem;
}

.gender-buttons { display: flex; justify-content: center; gap: 20px; margin-top: 25px; flex-wrap: wrap; }
.gender-buttons button {
    background-color: transparent; border: 2px solid var(--primary-color);
    border-radius: 10px; cursor: pointer; padding: 15px; width: 100%; max-width: 220px;
    transition: transform 0.2s, background-color 0.3s;
}
.gender-buttons img { height: 150px; display: block; margin: 0 auto 10px; pointer-events: none; }
.gender-buttons span { font-size: 1.2em; font-weight: bold; color: var(--text-color); }
.disclaimer { font-size: 0.75em; opacity: 0.8; margin-top: 20px; }

/* ================================================================
   4. ФОРМА СТАТИСТИКИ ТА SLIDER
   ================================================================ */
#stats-form { display: flex; flex-direction: column; gap: 15px; margin-top: 20px; text-align: left; }
.form-group label { font-weight: bold; color: var(--primary-color); }
.form-group select, .form-group input[type="text"] {
    width: 100%; background-color: rgba(0,0,0,0.3); color: var(--text-color);
    border: 1px solid var(--primary-color); border-radius: 5px; padding: 12px;
    font-family: var(--font-main); font-size: 1em;
}
.radio-group { display: flex; gap: 20px; flex-wrap: wrap; }
.radio-group label { font-weight: normal; color: var(--text-color); display: flex; align-items: center; gap: 8px; cursor: pointer; }

input[type=range] { -webkit-appearance: none; width: 100%; background: transparent; padding: 10px 0; }
input[type=range]::-webkit-slider-runnable-track { width: 100%; height: 6px; background: var(--primary-color); border-radius: 3px; }
input[type=range]::-webkit-slider-thumb { height: 24px; width: 24px; border-radius: 50%; background: var(--secondary-color); cursor: pointer; -webkit-appearance: none; margin-top: -9px; }

.start-game-btn {
    margin-top: 15px; padding: 15px; font-size: 1.1em; font-weight: bold;
    background-color: var(--secondary-color); border: none; color: var(--text-color);
    border-radius: 8px; cursor: pointer;
}

/* ================================================================
   5. ОСНОВНИЙ ІГРОВИЙ ЕКРАН (СТАНДАРТНИЙ ПОРТРЕТНИЙ РЕЖИМ)
   ================================================================ */
#game-screen {
    background-image: none !important; padding: 0; position: relative;
    display: flex; flex-direction: column; height: 100%; overflow: hidden;
}

#scene-background { 
    display: block; position: absolute; top: 0; left: 0;
    width: 100%; height: 50dvh; background-size: cover; background-position: center;
    z-index: 1; opacity:1; transition: opacity 3s ease-in-out; 
}

/* ДОДАНО: Фон заходить під Notch на iPhone */
@media screen and (orientation: portrait) {
    #scene-background { height: calc(50dvh + var(--sat)); }
}

#hero-container {
    position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    height: 50dvh; width: 100vw; z-index: 5; pointer-events: none; 
	opacity: 1; transition: opacity 1s ease-in-out; 
}

#hero-image {
    width: 100%; height: 100%; object-fit: contain; object-position: bottom center;
    filter: drop-shadow(0 4px 15px rgba(0,0,0,0.5));
}

#story-container {
    position: absolute; bottom: 0; left: 0; right: 0; width: 100%; height: 50dvh;
    background: var(--box-background); border-top: 2px solid var(--secondary-color);
    padding: 20px; 
    /* ДОДАНО: Safe Area внизу та з боків */
    padding-left: calc(20px + var(--sal));
    padding-right: calc(20px + var(--sar));
    padding-bottom: calc(20px + var(--sab));
    box-shadow: 0 -4px 30px rgba(255, 126, 185, 0.4);
    backdrop-filter: blur(15px); -webkit-backdrop-filter: blur(15px); z-index: 10;
    display: flex; flex-direction: column; justify-content: flex-start;
}

#text-box { flex-grow: 1; overflow-y: auto; margin-bottom: 15px; padding-right: 5px; }
#scene-text { font-size: 1.25em; line-height: 1.5; margin: 0; transition: opacity 0.25s; }

#choices-container { display: flex; flex-direction: column; gap: 10px; flex-shrink: 0; }
#choices-container button {
    width: 100%; padding: 16px; font-size: 1.1em; font-weight: bold;
    background-color: var(--primary-color); border: 1px solid var(--primary-color);
    color: var(--bg-color-2); border-radius: 8px; opacity: 0.95; cursor: pointer; text-align: left;
}

/* РЕКОМЕНДАЦІЯ: Кнопки у дві колонки для планшетів */
@media screen and (min-width: 768px) and (orientation: portrait) {
    #story-container { padding-left: 15%; padding-right: 15%; }
    #choices-container { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
}

/* РЕКОМЕНДАЦІЯ: Дуже довгі екрани (Sony/Xperia) */
@media screen and (max-aspect-ratio: 1/2.1) and (orientation: portrait) {
    #scene-background, #hero-container { height: 43dvh; }
    #story-container { height: 57dvh; }
}

/* =======================================================================
   6. АДАПТАЦІЯ (SPLIT SCREEN) - ГОРИЗОНТАЛЬНИЙ РЕЖИМ
   ======================================================================= */
@media screen and (orientation: landscape) and (max-height: 700px) {
    #game-screen { flex-direction: row; align-items: stretch; }
    #scene-background {
        width: 50%; height: 100%; left: 0; top: 0;
        border-right: 2px solid var(--secondary-color); transform: none;
    }
    #hero-container {
        width: 50%; height: 100%; left: 0; top: 0; transform: none;
        display: flex; justify-content: center; align-items: flex-end;       
    }
    #hero-image { height: 100%; width: auto; max-width: 100%; object-fit: contain; }
    #story-container {
        width: 50%; height: 100%; left: 50%; bottom: 0;
        border-top: none; border-left: 2px solid var(--secondary-color);
        padding-bottom: 20px; border-radius: 0; transform: none;
    }
    #choices-container { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
}

/* РЕКОМЕНДАЦІЯ: Квадратні екрани (Fold) */
@media screen and (min-width: 600px) and (aspect-ratio: 1/1) {
    #game-screen { flex-direction: row; }
    #scene-background, #hero-container { width: 40%; height: 100%; }
    #story-container { width: 60%; height: 100%; left: 40%; }
}

/* =======================================================================
   7. DESKTOP (ВЕЛИКІ ЕКРАНИ)
   ======================================================================= */
@media (min-width: 768px) and (min-height: 701px) {
    .intro-box h1 { font-size: 2.5rem; }
    #scene-background, #hero-container { height: 60dvh; }
    #story-container { height: 40dvh; }
}

@media (min-width: 1024px) and (min-height: 701px) {
    #game-screen { flex-direction: row; justify-content: flex-start; align-items: flex-end; }
    #scene-background {
        top: 50%; left: 55%; transform: translate(-50%, -50%);
        width: 80vw; height: 85vh; max-width: 1400px; max-height: 800px;
        border-radius: 30px; box-shadow: 0 0 50px rgba(0, 0, 0, 0.5); border: none;
    }
    #hero-container {
        position: relative; transform: none; left: auto; top: auto; bottom: 0;
        flex: 0 0 35%; height: 100vh; width: auto; pointer-events: auto;
        display: flex; justify-content: center; align-items: flex-end;
    }
    #hero-image { height: 95%; width: auto; max-width: 140%; }
    #story-container {
        position: absolute; bottom: 5vh; left: 55%; transform: translateX(-50%);
        width: 85vw; height: auto; min-height: 200px;
        border-radius: 15px; border-left: none; border-top: 2px solid var(--secondary-color);
    }
    #game-screen.hero-visible:not(.final-scene-layout) #story-container {
        width: 55vw; bottom: 8vh; left: 35%; transform: none;
    }
    #choices-container { flex-direction: row; flex-wrap: wrap; }
    #choices-container button { flex: 1 1 45%; }
}

/* ================================================================
   8. СПЕЦІАЛЬНИЙ ФІКС ДЛЯ IPHONE SE ТА КОРОТКИХ ЕКРАНІВ
   ================================================================ */
@media screen and (orientation: portrait) and (max-height: 750px) {
    #scene-background, #hero-container { height: 38dvh; }
    #story-container { height: 62dvh; padding-top: 15px; }
    #scene-text { font-size: 1.15em; line-height: 1.45; }
    #choices-container button { padding: 12px; font-size: 1em; }
}

/* ================================================================
   9. УТИЛІТИ, АНІМАЦІЇ ТА ВЗАЄМОДІЯ
   ================================================================ */
@media (hover: hover) {
    #choices-container button:hover { background-color: #be82f5; opacity: 1; transform: scale(1.02); }
    .start-game-btn:hover { background-color: #e666a3; transform: scale(1.03); }
    .gender-buttons button:hover { background-color: rgba(169, 96, 238, 0.2); transform: scale(1.05); }
}

#choices-container button:active, .start-game-btn:active { transform: scale(0.98); }
.fading-out { opacity: 0; pointer-events: none; }
.final-message { margin-top: 25px; text-align: center; }
.test-link-btn { display: inline-block; padding: 12px 25px; font-weight: bold; text-decoration: none; background-color: var(--secondary-color); color: white; border-radius: 8px; margin-top: 10px; }

/* Orientation Warning */
#orientation-warning { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: var(--bg-color-2); z-index: 10000; justify-content: center; align-items: center; text-align: center; padding: 20px; }
@media screen and (orientation: landscape) and (max-height: 320px) { #orientation-warning { display: flex; } }

/* Debug Panel */
#debug-panel {
    position: fixed; top: calc(10px + var(--sat)); right: 10px; z-index: 9999;
    background: rgba(0,0,0,0.95); color: white; border: 1px solid var(--primary-color);
    border-radius: 8px; max-width: 300px; display: none;
}
.debug-content { padding: 15px; max-height: 80dvh; overflow-y: auto; }