/* ============ Variables and Base Settings ============ */
:root {
    --primary: #27ae60;
    --secondary: #3498db;
    --accent: #e67e22;
    --text: #2c3e50;
    --error: #e74c3c;
    --light-gray: #f4f7f6;
}

body {
    font-family: 'Segoe UI', Arial, sans-serif;
    line-height: 1.6;
    background-color: var(--light-gray);
    color: var(--text);
    margin: 0;
    padding: 20px;
    padding-top: 80px; 
    transition: opacity 0.3s ease;
}

body.lang-transition {
    opacity: 0.3;
}

.container {
    max-width: 900px;
    margin: auto;
    background: white;
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
}

.sentence-breakdown {
    background: #fdfbff;
    padding: 12px 20px;
    margin-bottom: 10px;
    border-right: 4px solid #dcd0ff; /* Purple side bar for visual separation */
    border-radius: 4px;
    font-size: 1.1rem;
    line-height: 1.5;
}

/* English adjustment - move bar to the left */
html[dir="ltr"] .sentence-breakdown {
    border-right: none;
    border-left: 4px solid #dcd0ff;
}

.analysis-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}


.text-analysis .analysis-row {
    margin-bottom: 15px; 
    display: flex;       
    align-items: flex-start;
}

.text-analysis .sentence-breakdown {
    background: transparent; 
    box-shadow: none;        
    border: none;           
    padding: 0 15px;         
    margin: 0;
}

/* התאמה למובייל - שלא יקפוץ שורה */
@media (max-width: 768px) {
    .text-analysis .analysis-row {
        flex-direction: row !important; 
    }
}

/* Styling for the playing state */
.play-sentence-btn.playing {
    background: #ff4d4d !important; /* Red background for stop */
    color: white;
    border-color: #cc0000;
}

/* Ensure the audio container looks good above the text */
.audio-container {
    background: #f9f9f9;
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 20px;
    border: 1px solid #eee;
}

.play-sentence-btn {
    background: #f4efff;
    border: 1px solid #dcd0ff;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    flex-shrink: 0; /* Prevents the button from shrinking */
}

.play-sentence-btn:hover {
    background: var(--secondary);
    color: white;
}

.sentence-breakdown {
    flex-grow: 1;
    margin-bottom: 0; /* Removing previous margin because the row handles it */
}

.sentence-breakdown {
    background: #ffffff;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    border-right: 4px solid #dcd0ff;
    line-height: 1.6;
}

.sentence-breakdown strong {
    display: block;
    color: #2c3e50; /* Dark color for the Esperanto source */
    font-size: 1.1rem;
    margin-bottom: 4px; 
}

.sentence-breakdown small {
    display: block;
    color: #666; /* Grayer color for the translation */
    font-size: 1.1rem; 
    font-style: italic; /* Slight italicize for translation */
}

/* English mode adjustment */
html[dir="ltr"] .sentence-breakdown {
    border-right: none;
    border-left: 4px solid #dcd0ff;
}

/* Navigation buttons styling in top menu */
.nav-lesson-btn {
    text-decoration: none !important; /* Removes standard underline */
    border-bottom: none !important;  /* Removes dashed border if exists */
    cursor: pointer;
}

/* Ensure global tooltips do not affect these buttons */
.nav-lesson-btn:hover {
    border-bottom: none;
    background-color: rgba(255, 255, 255, 0.1); /* Example of a clean hover effect */
}

/* ============ Titles and Visual Elements ============ */
h1 { text-align: center; color: var(--primary); border-bottom: 3px solid var(--primary); padding-bottom: 10px; }
h2 { color: var(--primary); border-right: 5px solid var(--primary); padding-right: 15px; margin-top: 40px; }

.comic-section { text-align: center; margin: 30px 0; }
.comic-img { max-width: 100%; border-radius: 10px; border: 3px solid #ddd; }

/*.audio-container {
    display: flex;
    justify-content: center;
    width: 100%;
    margin: 30px 0;
}*/

/* ============ REVISED AUDIO PLAYER SECTION - FULLY RESPONSIVE ============ */
.audio-player-wide {
    direction: ltr;
    background: #f4efff;
    border: 1px solid #dcd0ff;
    border-radius: 50px;
    padding: 8px 15px;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 600px;
    box-shadow: 0 4px 15px rgba(108, 92, 231, 0.1);
    box-sizing: border-box; /* Ensures padding doesn't break width */
    flex-wrap: nowrap; /* Keep items in line unless on very small screens */
}

.main-play-btn {
    background: var(--secondary);
    color: white;
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    flex-shrink: 0;
}

.progress-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-grow: 1;
    font-family: monospace;
    color: var(--secondary);
    min-width: 0; /* Allows the wrapper to shrink correctly */
}

#progress-bar {
    flex-grow: 1;
    cursor: pointer;
    accent-color: var(--secondary);
    min-width: 50px;
    width: 100%;
}

#speed-select {
    border: 1px solid #dcd0ff;
    background: white;
    border-radius: 5px;
    padding: 3px;
    cursor: pointer;
    color: var(--secondary);
    font-weight: bold;
    flex-shrink: 0;
}

/* VOLUME SLIDER STYLING */
#volume-slider {
    width: 80px;
    accent-color: var(--secondary);
    cursor: pointer;
    flex-shrink: 0;
}

/* MOBILE OPTIMIZATION - TARGETING THE ISSUES IN THE SCREENSHOT */
@media screen and (max-width: 600px) {
    .audio-player-wide {
        gap: 8px;
        padding: 6px 10px;
        border-radius: 20px;
    }

    .main-play-btn {
        width: 35px;
        height: 35px;
        font-size: 16px;
    }

    #volume-slider {
        width: 50px; /* Smaller volume bar on mobile */
    }

    .progress-wrapper span {
        font-size: 12px; /* Smaller time stamps */
    }
}

@media screen and (max-width: 400px) {
    .audio-player-wide {
        flex-wrap: wrap; /* Allow wrapping only on extremely narrow screens */
        justify-content: center;
    }
    .progress-wrapper {
        width: 100%;
        order: 3; /* Move progress bar to its own row if screen is too small */
    }
}
/* ============ End of Audio Player Section ============ */

/* ============ Text Analysis and Tooltips ============ */
.text-analysis {
    background: #fff9db;
    padding: 25px;
    border-radius: 15px;
    font-size: 1.2em;
    border: 2px solid #f1c40f;
    margin-bottom: 30px;
    direction: ltr;
    text-align: left;
}

.word {
    border-bottom: 2px dotted var(--accent);
    cursor: help;
    position: relative;
}

.word:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 0.7em;
    white-space: nowrap;
    z-index: 100;
}


/* === Exercise System (Updated for Multi-line Synchronization) === */
.input-wrapper {
    position: relative;
    width: 100%;
    max-width: 600px;
    margin-top: 10px;
    direction: ltr !important; 
    text-align: left !important;
}

/* Common styles for all text layers to ensure perfect character alignment */
.input-wrapper input,
.input-wrapper textarea,
.input-wrapper .colored-text {
    font-size: 22px;
    font-family: 'Courier New', Courier, monospace;
    width: 100%;
    box-sizing: border-box;
    direction: ltr !important;
    text-align: left !important;
    letter-spacing: 1px;
    
    /* Identical line height is critical for vertical synchronization */
    line-height: 1.4;
    
    /* Padding must be exactly the same on all sides for all layers */
    /* Removed large right padding to prevent premature line breaking */
    padding: 12px 15px;

    /* Ensure line wrapping behavior is identical */
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Interactive element styles (input or textarea) */
.input-wrapper input,
.input-wrapper textarea {
    position: relative;
    background: transparent;
    color: transparent;
    caret-color: black; /* Keep the typing cursor visible */
    z-index: 2;
    border: 2px solid #ddd;
    border-radius: 8px;
    outline: none;
    display: block;
    /* Prevents spellcheck decorations from shifting text height */
    unicode-bidi: plaintext; 
}

/* Specific styling for textarea to support multi-line growth */
.input-wrapper textarea {
    resize: none; 
    min-height: 54px; 
    overflow: hidden; /* Height is managed by the validate() JS function */
}

/* The colored background feedback layer */
.input-wrapper .colored-text {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;    
    bottom: 0;   /* Stretches to match the height of the parent wrapper */
    z-index: 1;
    pointer-events: none;
    /* Transparent border to match the input's border width */
    border: 2px solid transparent; 
    color: #ccc;
    overflow: hidden;
}

/* Correct/Wrong character styles */
.char-correct { color: var(--primary) !important; font-weight: bold; }
.char-wrong { 
    color: var(--error) !important; 
    font-weight: bold; 
    text-decoration: underline;
    background-color: rgba(231, 76, 60, 0.1); 
}

/* Checkmark (V) positioning */
.checkmark {
    position: absolute;
    /* Moved slightly outside the input box to prevent interfering with text wrap */
    inset-inline-end: 10px; 
    top: 28px; 
    transform: translateY(-50%);
    font-size: 30px;
    color: var(--primary);
    opacity: 0;
    z-index: 3;
    pointer-events: none;
    transition: all 0.3s ease;
}

/* Visual state when answer is correct */
.input-wrapper.correct .checkmark { 
    opacity: 1; 
    transform: translateY(-50%) scale(1.1); 
}

.input-wrapper.correct input,
.input-wrapper.correct textarea { 
    border-color: var(--primary); 
}
/* ============ Memory Game (Fixed) ============ */
.memory-game { 
    display: grid; 
    grid-template-columns: repeat(4, 1fr); 
    gap: 15px; 
    margin: 20px 0;
}

.card {
    height: 100px; 
    background: var(--secondary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1.1em;
    font-weight: bold;
    text-align: center;
    padding: 10px;
    transition: transform 0.3s, background 0.3s;
    user-select: none;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.card:hover {
    transform: scale(1.05);
}

.card.flipped { 
    background: #ecf0f1; 
    color: var(--text); 
    cursor: default;
}

.card.matched { 
    visibility: hidden; 
    opacity: 0;
    transition: opacity 0.5s ease;
}

/* ============ Comics Section ============ */



/* ======== */
.comic-wrapper {
    max-width: 1200px;
    margin: 40px auto;
    padding: 0 20px;
    box-sizing: border-box;
    direction: ltr !important; 
}

.comic-strip { 
    display: flex; 
    gap: 12px; 
    margin: 20px 0;
    direction: ltr !important;
}

.comic-strip img {
    flex: 1; 
    width: 0; 
    height: auto; 
    border-radius: 12px;
    object-fit: cover; 
    /* Smooth transition for both desktop zoom and mobile layout */
    transition: transform 0.3s ease, box-shadow 0.3s ease; 
    cursor: pointer;
    position: relative;
}

/* DESKTOP ONLY: Enable hover zoom 
   (min-width: 769px) ensures it's a wide screen.
   (hover: hover) ensures the device actually has a cursor (prevents touch-triggering).
*/

/*
@media (min-width: 769px) and (hover: hover) {
    .comic-strip img:hover {
        transform: scale(1.05);
        z-index: 10;
        box-shadow: 0 10px 20px rgba(0,0,0,0.2);
    }
}
*/
@media (min-width: 769px) {
  .tooltip {
    opacity: 1;
    pointer-events: auto;
  }
}


/* MOBILE ONLY: Stack images vertically 
   This makes images readable on narrow phone screens.
*/
@media (max-width: 768px) {
    .comic-strip {
        flex-direction: column; 
        gap: 20px;
    }
    .comic-strip img {
        width: 100% !important; 
        flex: none;
    }
}


.next-lesson-btn {
    display: inline-block;
    padding: 15px 30px;
    background-color: #27ae60;
    color: white;
    text-decoration: none;
    font-size: 1.2em;
    font-weight: bold;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* =============Feedback ========== */
.feedback-footer {
    margin-top: 50px;
    padding: 20px;
    text-align: center;
}

.separator {
    border: 0;
    height: 1px;
    background-image: linear-gradient(to right, rgba(0, 0, 0, 0), rgba(108, 92, 231, 0.2), rgba(0, 0, 0, 0));
    margin-bottom: 30px;
}

.feedback-action p {
    font-size: 1.1rem;
    color: #636e72;
    margin-bottom: 15px;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background-color: #ffffff;
    color: var(--secondary);
    border: 2px solid var(--secondary);
    padding: 10px 20px;
    border-radius: 50px;
    text-decoration: none;
    font-weight: bold;
    transition: all 0.3s ease;
}

.btn-secondary:hover {
    background-color: var(--secondary);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(108, 92, 231, 0.2);
}


/* ============ Mobile ============ */
@media (max-width: 768px) {
    .container { padding: 20px; }
    .comic-strip { flex-direction: column; }
    .comic-strip img { width: 100%; }
    .memory-game { grid-template-columns: repeat(2, 1fr); } 
}

/* מבטיח שהאזורים הלחיצים יהיו תמיד ביחס לתמונה */
.comic-strip a, .comic-strip div {
    position: relative;
    display: inline-block;
    vertical-align: top;
}

.comic-hitbox {
    pointer-events: all;
    /* מונע מהדפדפן לסמן את התיבה בכחול בלחיצה ארוכה */
    -webkit-tap-highlight-color: transparent;
}

/* important */
.comic-panel img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
    border-radius: 15px;
    border: 1px solid #eee;
   
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    transition: all 0.3s ease;
}

.btn-toggle {
    background-color: #2c3e50;
    color: #ecf0f1;
    border: none;
    padding: 10px 25px;
    border-radius: 20px;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.3s, transform 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-toggle:hover {
    background-color: #34495e;
    transform: scale(1.05);
}

#textAnalysisSection {
   
    animation: slideDown 0.4s ease-out;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}
/*.btn-toggle span {
    font-size: 1.2em;
    line-height: 1;
}*/

.btn-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px; 
    min-width: 200px; 
}
.btn-toggle span {
    font-size: 1.5rem; 
    line-height: 1;
    vertical-align: middle; 
    display: inline-block;
    transition: transform 0.2s; 
}


.btn-toggle:hover span {
    transform: scale(1.2);
}


.actions-container {
    display: flex;
    gap: 15px;
    justify-content: center;
    align-items: center;
    margin-top: 10px;
}


.btn-copyright {
    display: flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    color: #7f8c8d; /* צבע אפור מקצועי */
    font-size: 0.85rem;
    padding: 6px 12px;
    border: 1px solid #dcdde1;
    border-radius: 20px;
    transition: all 0.3s ease;
    background-color: transparent;
}

.btn-copyright:hover {
    background-color: #f5f6fa;
    color: #2f3640;
    border-color: #7f8c8d;
    transform: translateY(-1px);
}

.btn-copyright .icon {
    font-size: 0.9rem;
    opacity: 0.8;
}

/* התאמה למובייל */
@media (max-width: 480px) {
    .actions-container {
        flex-direction: column;
        gap: 10px;
    }
}

.matching-container {
    display: flex;
    justify-content: space-around;
    gap: 20px;
    max-width: 600px;
    margin: 20px auto;
    background: #f9f9f9;
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}

.matching-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
}

.match-btn {
    padding: 12px;
    border: 2px solid var(--primary, #4CAF50);
    background: white;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.2s ease;
    min-height: 50px;
    color: #333;
    font-weight: bold;
}

.match-btn:hover {
    background: #f0fdf4;
    transform: translateY(-2px);
}

.match-btn.selected {
    background: var(--primary, #4CAF50);
    color: white;
    box-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
}

.match-btn.fade-out {
    opacity: 0;
    transform: scale(0.8);
    pointer-events: none;
}

/*  =====================  */
/* Custom Tooltip Styling */
.custom-tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    z-index: 1000;
    pointer-events: none; /* Allows clicks to pass through */
    display: none; /* Hidden by default */
    white-space: nowrap;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

/* For mobile devices, make it slightly larger for readability */
@media (max-width: 768px) {
    .custom-tooltip {
        font-size: 16px;
        padding: 10px 15px;
    }
}

/* Standardized button style for the course */
.course-btn {
    background-color: var(--primary, #4A90E2); /* Falls back to blue if var is missing */
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 25px; /* Rounded pill shape */
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 0px rgba(0,0,0,0.1);
    display: inline-block;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.course-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
    box-shadow: 0 6px 0px rgba(0,0,0,0.1);
}

.course-btn:active {
    transform: translateY(2px);
    box-shadow: none;
}

.match-btn.correct {
    background-color: #28a745 !important; /* ירוק */
    color: white !important;
    border-color: #1e7e34 !important;
}

.match-btn.wrong {
    background-color: #dc3545 !important; /* אדום */
    color: white !important;
    border-color: #bd2130 !important;
}