/* --- History Section Styles (Adjusted for Card-like Layout for Long-Term Use) --- */
.history-section {
    background-color: #f7fcf7; /* 更柔和的淺綠，減少亮度刺激 */
    border-radius: 18px; /* 稍微增大圓角，更溫和 */
    padding: 30px; /* 增加內邊距，提供更多留白 */
    border: 1px solid #d4e7d4; /* 更柔和的綠色邊框，減少對比 */
    text-align: left;
    overflow-x: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04); /* 輕微的外部陰影，增加質感 */
}

.history-section h2 {
    color: #2e7d32; /* 更深的柔和綠色，保持標題清晰度 */
    font-size: 2em; /* 稍微增大標題字體 */
    margin-bottom: 20px; /* 增加標題底部間距 */
    text-align: center;
    font-weight: 600; /* 稍微調整字重，不至於過粗 */
}

#historyList {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    gap: 12px; /* 增加歷史記錄卡片間的間距 */

    background-color: #ffffff; /* 列表區域的純白背景，保持清晰 */
    border: 1px solid #ebebeb; /* 更柔和的邊框 */
    border-radius: 10px; /* 稍微增大圓角 */
    padding: 15px; /* 增加內邊距 */
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.03); /* 更輕微的內陰影，提供細微深度 */
    margin-bottom: 20px; /* 調整底部間距 */
    scroll-behavior: smooth;
}

/* Individual history item container (Card) */
.history-item-container {
    background-color: #e3f2e3; /* 更柔和的淺綠色，替代 #c8e6c9 (稍亮的綠) */
    padding: 12px 18px; /* 增加內邊距 */
    border-radius: 10px; /* 調整圓角 */
    border: 1px solid #b7e1b7; /* 更柔和的邊框 */
    cursor: pointer;
    transition: background-color 0.2s ease-in-out, transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06); /* 柔和的陰影 */
    flex-shrink: 0;
    min-width: 0;
}

.history-item-container:last-child {
    margin-bottom: 0;
}

.history-item-container:hover {
    background-color: #d4edd4; /* 更柔和的 hover 效果，替代 #a5d6a7 (稍深的綠) */
    transform: translateY(-3px); /* 輕微提升效果，增加互動感 */
    box-shadow: 0 5px 12px rgba(0, 0, 0, 0.1); /* 柔和但更明顯的 hover 陰影 */
}

/* Header block for word, arrow, and time */
.history-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 1.25em; /* 稍微增大字體，提升主單字的易讀性 */
    color: #216f27; /* 深綠色，與背景對比清晰 */
    font-weight: bold;
    flex-wrap: wrap;
    min-width: 0;
}

/* History item word container: word text, CEFR, and word pronounce button */
.history-item-word-container {
    display: flex;
    align-items: center;
    flex-grow: 1;
    text-align: left;
    margin-right: 12px; /* 增加與時間/箭頭的間距 */
    flex-wrap: wrap;
    gap: 8px; /* 增加內部元素間距 */
    min-width: 0;
    line-height: 1.3; /* 確保行高舒適 */
}

/* History item word text */
.history-item-word {
    color: #216f27; /* 深綠色，保持一致 */
    word-break: break-word;
}

/* History CEFR Level Badge styles */
.history-cefr-badge {
    display: inline-block;
    color: white;
    padding: 4px 10px; /* 增加內邊距，使徽章更易點擊和識別 */
    border-radius: 18px; /* 調整圓角，更圓潤 */
    font-size: 0.65em; /* 稍微增大字體 */
    font-weight: bold;
    vertical-align: middle;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); /* 柔和陰影 */
    min-width: 40px; /* 稍微增大最小寬度 */
    text-align: center;
    flex-shrink: 0;
    letter-spacing: 0.03em; /* 輕微字間距 */
}

/* History CEFR Colors (使用與主結果區保持一致的柔和色調) */
.history-cefr-badge.A1 { background-color: #66bb6a; } /* Green */
.history-cefr-badge.A2 { background-color: #aed581; } /* Light Green */
.history-cefr-badge.B1 { background-color: #ffca28; } /* Amber */
.history-cefr-badge.B2 { background-color: #ffa726; } /* Orange */
.history-cefr-badge.C1 { background-color: #ff7043; } /* Deep Orange */
.history-cefr-badge.C2 { background-color: #ef5350; } /* Red */

/* History word pronunciation button */
.history-word-pronounce-button {
    background-color: #7b1fa2; /* 柔和的深紫色 */
    width: 38px; /* 稍微增大 */
    height: 38px; /* 稍微增大 */
    font-size: 1.1em; /* 調整圖標大小 */
    flex-shrink: 0;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15); /* 柔和陰影 */
}
.history-word-pronounce-button:hover {
    background-color: #6a1b9a; /* 更深一點的紫色 */
    transform: scale(1.08); /* 輕微放大效果 */
}

/* Toggle icon for details */
.toggle-icon {
    font-size: 0.9em; /* 稍微增大 */
    color: #388e3c; /* 保持綠色主題 */
    margin-left: 12px; /* 增加間距 */
    width: 1.1em; /* 固定寬度，確保對齊一致性 */
    text-align: center;
    transition: transform 0.25s ease; /* 調整過渡效果，更流暢 */
    flex-shrink: 0;
}

/* Query time */
.history-item-time {
    font-size: 0.85em; /* 稍微增大字體 */
    color: #757575; /* 更柔和的灰色 */
    margin-left: 12px; /* 增加間距 */
    white-space: nowrap;
    flex-shrink: 0;
}

/* Word details content block (display controlled by JS) */
.history-item-details {
    padding: 12px 0 0 0; /* 調整內邊距 */
    text-align: left;
    border-top: 1px dashed #c5e1c5; /* 更柔和的虛線 */
    margin-top: 12px; /* 增加間距 */
    overflow-wrap: break-word;
    word-wrap: break-word;
    line-height: 1.6; /* 增加行高，提升閱讀舒適度 */
    color: #4a4a4a; /* 設置預設文字顏色 */
}

/* Explanation and example sentence paragraph containers in details: text and button side-by-side */
.history-item-explanation, .history-item-example {
    color: #4a4a4a; /* 柔和的深灰色 */
    margin-bottom: 10px; /* 增加底部間距 */
    line-height: 1.6; /* 增加行高 */
    font-size: 0.9em; /* 調整字體大小 */
    display: flex;
    align-items: flex-start;
    gap: 8px; /* 增加文本和按鈕間距 */
}

/* Ensure text content takes available space */
.history-item-explanation span, .history-item-example span {
    flex-grow: 1;
    min-width: 0;
    word-break: break-word;
}

/* History explanation/example pronunciation button (smallest) */
.history-text-pronounce-button {
    background-color: #00897b; /* 柔和的青色 */
    width: 28px; /* 稍微增大 */
    height: 28px; /* 稍微增大 */
    font-size: 0.7em; /* 調整圖標大小 */
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* 柔和陰影 */
}
.history-text-pronounce-button:hover {
    background-color: #00796b; /* 更深一點的青色 */
    transform: scale(1.08); /* 輕微放大效果 */
}

/* Image in details */
.history-item-image {
    max-width: 90%; /* 調整最大寬度 */
    height: auto;
    border-radius: 12px; /* 調整圓角 */
    margin-bottom: 10px; /* 調整底部間距 */
    display: block;
    margin-left: auto;
    margin-right: auto;
    max-height: 180px; /* 稍微增大最大高度 */
    object-fit: contain;
    border: 1px solid #e0e0e0; /* 柔和邊框 */
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.08); /* 柔和陰影 */
}

/* Example sentence in details */
.history-item-example {
    color: #616161; /* 更柔和的灰色 */
    font-style: italic;
    font-size: 0.85em; /* 稍微縮小字體，與解釋區分 */
    line-height: 1.5; /* 調整行高 */
}

/* Responsive adjustments for smaller screens */
@media (max-width: 768px) {
    .history-section {
        padding: 20px;
        border-radius: 15px;
    }
    .history-section h2 {
        font-size: 1.6em;
        margin-bottom: 15px;
    }
    #historyList {
        padding: 10px;
        gap: 8px;
        max-height: 350px; /* 手機端調整最大高度 */
    }
    .history-item-container {
        padding: 10px 15px;
        border-radius: 8px;
    }
    .history-item-header {
        font-size: 1.1em;
        flex-direction: column; /* 手機上標題區堆疊 */
        align-items: flex-start;
        gap: 5px;
    }
    .history-item-word-container {
        margin-right: 0;
        gap: 5px;
    }
    .history-cefr-badge {
        font-size: 0.55em;
        padding: 3px 7px;
        min-width: 30px;
    }
    .history-word-pronounce-button {
        width: 32px;
        height: 32px;
        font-size: 0.9em;
    }
    .toggle-icon, .history-item-time {
        margin-left: 0; /* 移除左邊距 */
        margin-top: 5px; /* 為時間和箭頭提供頂部間距 */
        align-self: flex-end; /* 將時間和箭頭推向右邊 */
    }
    .history-item-details {
        padding: 8px 0 0 0;
        margin-top: 8px;
        font-size: 0.9em;
    }
    .history-item-explanation, .history-item-example {
        font-size: 0.85em;
        margin-bottom: 6px;
        gap: 6px;
    }
    .history-text-pronounce-button {
        width: 22px;
        height: 22px;
        font-size: 0.6em;
    }
    .history-item-image {
        max-height: 120px; /* 手機端調整圖片高度 */
    }
}