/* ==========================================================================
   STORY SCREEN — Beelinguapp-style dual panel reader
   Dependencies: lesson/layout.css (shared l_header, l_footer, feedback_overlay)
   Naming: .target = изучаемый язык, .native = родной язык
   ========================================================================== */

/* --- 1. GLOBAL OVERRIDES FOR STORY MODE --- */

html.story_active,
.story_active body,
.lesson_layout.story_mode {
    overflow-x: hidden !important;
    width: 100%;
    position: relative;
}

.story_mode .l_main {
    padding: 0;
    justify-content: flex-start;
    align-items: center;
    width: 100%;
    overflow-x: hidden;
}


/* --- 2. SPLIT VIEW (Two-panel layout) --- */

.story_split_view {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -ms-flex-direction: column;
    flex-direction: column;
    width: 100%;
    max-width: var(--content-max-width);
    height: 100%;
    overflow: hidden;
}

.story_scroll_panel {
    -webkit-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    width: 100%;
    padding: 16px 16px 10px;
    position: relative;
}

/* Разделитель между панелями (мобильные — горизонтальная линия) */
.story_scroll_panel + .story_scroll_panel {
    border-top: 1px solid var(--c-border);
}

/* Кастомный скроллбар */
.story_scroll_panel::-webkit-scrollbar { width: 3px; }
.story_scroll_panel::-webkit-scrollbar-thumb { background: #333; border-radius: 10px; }


/* --- Desktop: Side-by-side panels --- */
@media (min-width: 701px) {
    .story_split_view {
        -webkit-box-orient: horizontal;
        -webkit-box-direction: normal;
        -ms-flex-direction: row;
        flex-direction: row;
    }

    .story_scroll_panel + .story_scroll_panel {
        border-top: none;
        border-left: 1px solid var(--c-border);
    }
}


/* --- 3. STORY CONTAINER (text flow) --- */

.story_container {
    display: block;
    width: 100%;
    line-height: 1.85;
    text-align: left;
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
    z-index: 300;
}

/* Tokens inside story must flow as inline text */
.story_container .c_token_container {
    display: inline !important;
    white-space: normal !important;
    pointer-events: auto;
}

.story_container .c_token {
    display: inline-block !important;
    font-size: 1.15rem;
    color: inherit;
    vertical-align: baseline;
    margin: 0 1px;
}


/* --- 4. TITLES --- */

.story_title {
    display: block;
    width: 100%;
    text-align: center;
    font-weight: 900;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.story_title.target {
    font-size: 1.4rem;
    color: #fff;
}

.story_title.native {
    font-size: 1.4rem;
    color: #777;
}


/* --- 5. SENTENCE UNITS --- */

.story_sentence_unit {
    display: inline;
    white-space: normal;
}

/* -- Target language (top panel) -- */
.story_sentence_unit.target {
    color: rgba(255,255,255,0.45);
}

.story_sentence_unit.target.is_current {
    color: var(--c-accent-orange) !important;
    font-weight: 600;
}

.story_sentence_unit.target.is_current .c_token {
    color: var(--c-accent-orange) !important;
}

/* -- Native language (bottom panel) -- */
.story_sentence_unit.native {
    font-size: 1.15rem;
    color: #777;
    -webkit-transition: filter 0.3s, opacity 0.3s;
    transition: filter 0.3s, opacity 0.3s;
}

.story_sentence_unit.native.is_current {
    color: var(--c-accent-orange);
}


/* --- 6. BLUR EFFECT (Beelinguapp: native text hidden by default) --- */

.story_sentence_unit.native.is_blurred {
    -webkit-filter: blur(8px);
    filter: blur(8px);
    opacity: 0.3;
    cursor: pointer;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 4px;
    padding: 0 2px;
}

.story_sentence_unit.native.is_blurred:hover {
    -webkit-filter: blur(4px);
    filter: blur(4px);
    opacity: 0.5;
}

.story_sentence_unit.native:not(.is_blurred) {
    -webkit-filter: blur(0);
    filter: blur(0);
    opacity: 1;
    background: transparent;
}


/* --- 7. BLUR TOGGLE BUTTON --- */

.story_blur_toggle {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 8px;
    color: var(--c-text-muted);
    font-size: 11px;
    font-weight: 700;
    padding: 5px 10px;
    cursor: pointer;
    z-index: 10;
    -webkit-transition: background 0.2s, color 0.2s;
    transition: background 0.2s, color 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.story_blur_toggle:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.story_blur_toggle.is_active {
    background: var(--c-accent-orange);
    color: #fff;
    border-color: var(--c-accent-orange);
}


/* --- 8. PANEL LABELS --- */

.story_panel_label {
    display: block;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.2);
    margin-bottom: 10px;
    padding-bottom: 6px;
}


/* --- 9. PROGRESS BAR (override for story mode) --- */

.story_mode .progress_track {
    -webkit-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    height: 10px;
    background: #333;
    border-radius: 5px;
    overflow: hidden;
}

.story_mode .progress_fill {
    height: 100%;
    background-color: var(--c-accent-green);
    -webkit-transition: width 0.3s ease;
    transition: width 0.3s ease;
}


/* --- 10. TEXT APPEAR ANIMATION --- */

.animated_text {
    -webkit-animation: storyFadeIn 0.4s ease-out forwards;
    animation: storyFadeIn 0.4s ease-out forwards;
}

@-webkit-keyframes storyFadeIn {
    from { opacity: 0; -webkit-transform: translateY(8px); transform: translateY(8px); }
    to   { opacity: 1; -webkit-transform: translateY(0); transform: translateY(0); }
}
@keyframes storyFadeIn {
    from { opacity: 0; -webkit-transform: translateY(8px); transform: translateY(8px); }
    to   { opacity: 1; -webkit-transform: translateY(0); transform: translateY(0); }
}


/* --- 11. QUIZ POPUP (slide-up comprehension check) --- */

.story_quiz_popup {
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 100%;
    max-width: var(--content-max-width);
    -webkit-transform: translateX(-50%) translateY(100%);
    transform: translateX(-50%) translateY(100%);
    background: #1a1a1a;
    border-radius: 24px 24px 0 0;
    z-index: 10;
    -webkit-transition: -webkit-transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.4s ease;
    transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.4s ease;
    -webkit-box-shadow: 0 -10px 50px rgba(0,0,0,0.9);
    box-shadow: 0 -10px 50px rgba(0,0,0,0.9);
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -ms-flex-direction: column;
    flex-direction: column;
    overflow: hidden; /* Clips body+footer when height shrinks on collapse */
}

.story_quiz_popup.is_active {
    -webkit-transform: translateX(-50%) translateY(0);
    transform: translateX(-50%) translateY(0);
}

.story_quiz_popup.is_expanded {
    height: 70vh;
}

/* Collapsed: only the 56px header tab is visible, body+footer clipped */
.story_quiz_popup.is_collapsed {
    height: 56px;
    overflow: hidden;
    -webkit-transform: translateX(-50%) translateY(0);
    transform: translateX(-50%) translateY(0);
}

.quiz_popup_inner {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -ms-flex-direction: column;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

/* Header */
.quiz_popup_header {
    height: 56px;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid #333;
    -ms-flex-negative: 0;
    flex-shrink: 0;
}

.quiz_toggle_btn {
    background: var(--c-accent-blue);
    border: none;
    color: #fff;
    padding: 6px 14px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
    -webkit-box-shadow: 0 3px 0 rgba(0,0,0,0.2);
    box-shadow: 0 3px 0 rgba(0,0,0,0.2);
}

.quiz_toggle_btn.is_collapsed {
    background: var(--c-accent-orange);
}

.quiz_popup_title {
    margin-left: 14px;
    font-weight: 800;
    font-size: 14px;
    color: var(--c-accent-orange);
}

/* Body */
.quiz_popup_body {
    -webkit-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.quiz_popup_body .options_list {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -ms-flex-direction: column;
    flex-direction: column;
}

.quiz_popup_body .options_list > * {
    margin-bottom: 10px;
}
.quiz_popup_body .options_list > *:last-child {
    margin-bottom: 0;
}

/* Footer */
.quiz_popup_footer {
    -ms-flex-negative: 0;
    flex-shrink: 0;
    background: #1a1a1a;
    border-top: 1px solid #333;
}


/* --- 12. INLINE AUDIO BUTTON (compact, inside sentence) --- */

.c_story_audio_btn {
    display: -webkit-inline-box;
    display: -ms-inline-flexbox;
    display: inline-flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    vertical-align: middle;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #2a2a2a;
    border: 1px solid #444;
    color: var(--c-accent-green);
    margin-right: 5px;
    margin-left: 2px;
    cursor: pointer;
    padding: 0;
    position: relative;
    top: -1px;
    -webkit-transition: -webkit-transform 0.1s, background 0.1s;
    transition: transform 0.1s, background 0.1s;
}

.c_story_audio_btn .g_icon {
    width: 13px;
    height: 13px;
    fill: currentColor;
    -webkit-transform: translateX(0.5px);
    transform: translateX(0.5px);
}

.c_story_audio_btn:hover {
    background: #333;
    -webkit-transform: scale(1.1);
    transform: scale(1.1);
}

.c_story_audio_btn:active {
    background: #222;
    -webkit-transform: scale(0.95);
    transform: scale(0.95);
}
