/* --- Responsive Design --- */

/* 全局 / 默认样式 (适用于所有屏幕尺寸，除非被媒体查询覆盖) */
h1 .desktop-text {
    display: inline; /* 默认情况下：在桌面大屏幕上显示 "English Dictionary" */
}
h1 .mobile-text {
    display: none;   /* 默认情况下：在桌面大屏幕上隐藏 "Words" */
}

/* Tablet size (e.g., between 768px - 1024px) */
@media (max-width: 1024px) {
    .container {
        padding: 25px 35px;
    }

    h1 {
        font-size: 2.5em;
    }
    /* 在 Tablet 尺寸范围内明确定义显示规则，与全局样式相同，确保一致性 */
    h1 .desktop-text {
        display: inline;
    }
    h1 .mobile-text {
        display: none;
    }

    #wordInput {
        font-size: 1.3em;
    }

    .search-button {
        font-size: 1.2em;
        padding: 12px 20px;
    }

    /* Age Level Selector Adjustments for Tablet */
    .age-level-selector {
        gap: 10px;
        margin-top: 15px;
    }
    .age-level-selector label {
        font-size: 1.1em;
    }
    #ageLevelSelect {
        padding: 10px 18px;
        font-size: 1.1em;
        background-size: 14px;
        padding-right: 35px;
    }

    /* Result section changes */
    .result-section #wordResult {
        font-size: 2.5em;
    }
    .word-pronounce-button {
        width: 45px;
        height: 45px;
        font-size: 1.3em;
    }
    .text-pronounce-button {
        width: 25px;
        height: 25px;
        font-size: 0.65em;
    }
    .cefr-badge {
        font-size: 0.65em;
        padding: 4px 9px;
        min-width: 40px;
    }

    #explanation, #exampleSentence {
        font-size: 1.3em;
    }

    #exampleSentence {
        font-size: 1.1em;
    }

    .history-section h2 {
        font-size: 1.6em;
    }

    /* History item adjustments for tablets */
    .history-item-word-container {
        font-size: 1em;
    }
    .history-cefr-badge {
        font-size: 0.55em;
        padding: 2px 7px;
        min-width: 32px;
    }
    .history-word-pronounce-button {
        width: 32px;
        height: 32px;
        font-size: 0.9em;
    }
    .history-text-pronounce-button {
        width: 22px;
        height: 22px;
        font-size: 0.65em;
    }
    .history-item-explanation, .history-item-example {
        font-size: 0.85em;
    }
    .history-item-image {
        max-height: 120px;
    }

    /* Sidebar and menu-toggle on tablet should still be active */
    .sidebar {
        width: 250px; /* Slightly smaller sidebar on tablets */
    }
    body.sidebar-open .main-content-wrapper {
        margin-left: 250px;
    }
    .menu-toggle {
        top: 15px;
        left: 15px;
        width: 45px;
        height: 45px;
        font-size: 1.3em;
    }
}

/* Mobile size (less than 768px) */
@media (max-width: 768px) {
    body {
        padding: 15px; /* Adjust top/side padding as needed */
        padding-bottom: 60px; /* Crucial: Make space for the fixed footer (50px footer height + 10px buffer) */
    }

    /* Reset main content wrapper margin in case sidebar-open class persists */
    body.sidebar-open .main-content-wrapper {
        margin-left: 0 !important; /* Ensure no left margin on mobile */
    }

    /* Hide desktop UI elements on mobile */
    .menu-toggle {
        display: none;
    }

    .sidebar {
        display: none;
        transform: translateX(-100%) !important; /* Ensure sidebar is fully hidden */
    }

    /* Ensure main content is not pushed by a hidden sidebar */
    .main-content-wrapper {
        margin-left: 0;
        padding-left: 15px; /* Adjusted from 20px for mobile */
        padding-right: 15px; /* Ensure consistent padding */
        min-height: calc(100vh - 60px); /* Adjust min-height to account for footer */
    }

    /* General mobile content adjustments continued */
    .container {
        padding: 20px 25px; /* Adjusted container padding */
        border-radius: 15px;
    }

    h1 {
        font-size: 1.8em; /* Adjusted: Smaller for typical mobile */
        margin-bottom: 20px;
    }
    /* 手机端特定可见性 */
    h1 .desktop-text {
        display: none; /* 在手机上隐藏 "English Dictionary" */
    }
    h1 .mobile-text {
        display: inline; /* 在手机上显示 "Words" */
    }

    .search-section {
        padding: 15px; /* Reduced padding for search section on mobile */
        margin-bottom: 25px;
    }

    .search-section label {
        font-size: 1.2em;
        margin-bottom: 10px;
    }

    .search-input-group {
        flex-direction: column;
        gap: 10px;
    }

    #wordInput {
        width: 100%;
        max-width: none;
        margin-bottom: 0;
        padding: 10px 12px; /* Slightly reduced padding */
        font-size: 1.1em; /* Slightly smaller font */
    }

    .search-button {
        width: 90%; /* Make search button wider */
        font-size: 1em; /* Slightly smaller font */
        padding: 10px 15px; /* Slightly reduced padding */
    }

    /* Age Level Selector Adjustments for Mobile (within responsive.css) */
    .age-level-selector {
        flex-direction: column; /* Stack label and select vertically */
        gap: 5px; /* Reduced gap between label and select */
        margin-top: 15px;
        width: 100%; /* Ensure it takes full available width in its container */
        align-items: center; /* Center items horizontally within the flex container */
    }
    .age-level-selector label {
        font-size: 1em; /* Slightly smaller font for label */
        text-align: center; /* Center the label text */
        white-space: normal; /* Allow label text to wrap if necessary */
        padding: 0 5px; /* Add slight horizontal padding to prevent text touching edges */
    }
    #ageLevelSelect {
        width: 95%; /* Give it even more width for better fit */
        max-width: 250px; /* Re-evaluate this max-width, keeping it reasonable for dropdown width */
        font-size: 1em; /* Slightly smaller font for select */
        padding: 8px 10px; /* Reduced padding */
        background-size: 10px; /* Smaller arrow icon */
        padding-right: 25px; /* Ensure space for dropdown arrow */
        box-sizing: border-box; /* Include padding in the width calculation */
    }

    .result-section {
        padding: 15px; /* Reduced padding for result section */
        margin-bottom: 25px;
        min-height: 160px; /* Adjusted min-height */
    }

    /* Result section changes for mobile */
    .result-section #wordResult {
        font-size: 2em; /* Slightly smaller */
        flex-direction: column;
        gap: 8px; /* Reduced gap */
    }
    .word-pronounce-button {
        width: 35px; /* Smaller button */
        height: 35px;
        font-size: 1em;
    }
    .text-pronounce-button {
        width: 20px;
        height: 20px;
        font-size: 0.5em;
    }
    .cefr-badge {
        margin-left: 0;
        font-size: 0.55em; /* Slightly smaller */
        padding: 3px 6px;
        min-width: 35px;
    }

    #explanation, #exampleSentence {
        font-size: 1em; /* Slightly smaller */
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
    #explanationText, #exampleSentenceText {
        width: 100%;
    }

    #wordImage {
        max-width: 80%; /* Slightly smaller image */
    }

    #exampleSentence {
        font-size: 0.9em; /* Slightly smaller */
    }

    #encouragement {
        font-size: 1em; /* Slightly smaller */
        margin-top: 15px;
    }

    .no-result {
        font-size: 1.1em; /* Slightly smaller */
    }

    .history-section {
        padding: 15px; /* Reduced padding */
    }

    .history-section h2 {
        font-size: 1.4em; /* Slightly smaller */
    }

    /* History item adjustments for mobile */
    .history-item-header {
        flex-wrap: wrap;
        justify-content: flex-start;
        gap: 5px;
    }
    .history-item-word-container {
        flex-grow: 0;
        font-size: 0.95em; /* Slightly smaller */
        width: auto;
        justify-content: flex-start;
    }
    .history-item-word {
        font-size: 0.95em;
    }
    .history-cefr-badge {
        font-size: 0.45em;
        padding: 1px 4px;
        min-width: 25px;
    }
    .history-word-pronounce-button {
        width: 25px;
        height: 25px;
        font-size: 0.7em;
    }
    .toggle-icon {
        order: 1;
        margin-left: auto;
        margin-right: 5px;
    }
    .history-item-time {
        order: 2;
        margin-left: 0;
        text-align: right;
        width: 100%;
        font-size: 0.7em; /* Slightly smaller */
    }
    .history-item-explanation, .history-item-example {
        font-size: 0.8em;
        flex-direction: column;
        align-items: flex-start;
    }
    .history-text-pronounce-button {
        width: 18px;
        height: 18px;
        font-size: 0.45em;
        margin-top: 5px;
    }
    .history-item-image {
        max-height: 80px;
    }
}

/* Extra small screen devices (e.g., 320px width) */
@media (max-width: 400px) {
    h1 {
        font-size: 1.6em; /* Even smaller heading */
    }
    /* mobile-text and desktop-text visibility inherited from 768px breakpoint */

    .search-button {
        width: 98%; /* Almost full width for search button */
    }
    /* Age Level Selector adjustments for very small screens */
    #ageLevelSelect {
        width: 98%; /* Even more width for very small screens */
        max-width: none; /* Remove max-width on very small screens to let it fill more */
        font-size: 0.9em; /* Even smaller font for very small screens */
        padding: 6px 8px; /* Reduced padding */
        padding-right: 20px; /* Adjust padding for smaller size */
    }
    .age-level-selector label {
        font-size: 0.9em; /* Even smaller label font */
    }
    /* Reduce padding for .container and .search-section */
    .container {
        padding: 15px;
    }
    .search-section {
        padding: 10px;
    }

    .result-section #wordResult {
        font-size: 1.8em;
    }
    .word-pronounce-button {
        width: 30px;
        height: 30px;
        font-size: 0.9em;
    }
    .text-pronounce-button {
        width: 16px;
        height: 16px;
        font-size: 0.4em;
    }
    .cefr-badge {
        font-size: 0.5em;
        padding: 2px 5px;
        min-width: 30px;
    }
    #explanation, #exampleSentence {
        font-size: 0.9em;
    }
    #exampleSentence {
        font-size: 0.8em;
    }
    .history-item-word-container {
        font-size: 0.85em;
    }
    .history-cefr-badge {
        font-size: 0.4em;
        padding: 1px 3px;
        min-width: 22px;
    }
    .history-word-pronounce-button {
        width: 22px;
        height: 22px;
        font-size: 0.6em;
    }
    .history-item-explanation, .history-item-example {
        font-size: 0.75em;
    }
    .history-text-pronounce-button {
        width: 16px;
        height: 16px;
        font-size: 0.4em;
    }
    .history-item-image {
        max-height: 70px;
    }
}