/* --- Variables --- */
:root {
    --background-color: #f8f9fa; /* Light grey */
    --card-background: #ffffff;
    --text-color: #343a40;      /* Dark grey */
    --primary-color: #007bff;   /* Blue */
    --primary-hover: #0056b3;
    --secondary-color: #6c757d; /* Medium grey */
    --secondary-hover: #5a6268;
    --label-color: #6c757d;     /* Medium grey */
    --border-color: #e9ecef;    /* Light border */
    --shadow-color: rgba(0, 0, 0, 0.08);
    --font-family: 'Nunito', 'Arial', sans-serif;
    --base-font-size: 16px;
    --card-padding: 25px;
    --card-radius: 12px;
    --button-radius: 8px;
}

/* --- Reset & Base --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 20px;
    font-size: var(--base-font-size);
    line-height: 1.6;
}

/* --- App Layout --- */
.flashcard-app {
    width: 100%;   
    max-width: 700px; /* Thêm max-width */
    display: flex;
    flex-direction: column;
    align-items: center;
}

h1 {
    font-size: 1.8rem;
    color: var(--primary-color);
    margin-bottom: 25px;
    font-weight: 700;
}

/* --- Flashcard Styling --- */
.flashcard {
    background-color: var(--card-background);
    border-radius: var(--card-radius);
    box-shadow: 0 4px 15px var(--shadow-color);
    padding: var(--card-padding);
    width: 100%;
    text-align: left;
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
    transition: box-shadow 0.3s ease;
}

.flashcard:hover {
     box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

.flashcard__term {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.flashcard__term h2 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-color);
    margin: 0;
}

.flashcard__term button {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

.flashcard__term button:hover {
    background-color: rgba(0, 123, 255, 0.1);
}

.flashcard__term button svg {
     display: block;
}


/* --- Visual Aid (Image) --- */
.flashcard__visual {
    margin-bottom: 20px;
    text-align: center;
    position: relative;
    min-height: 100px;
}

#wordImage {
    max-width: 100%;
    max-height: 250px;
    height: auto;
    border-radius: var(--button-radius);
    display: block;
    margin: 0 auto 10px auto;
    border: 1px solid var(--border-color);
    object-fit: contain;
}

#wordImage.default-image {
    max-height: 90px;
    width: auto;
    object-fit: contain;
}

/* --- Definitions List --- */
.flashcard__definitions {
    margin-top: 20px;
}

.definition-group {
    margin-bottom: 15px;
}

.definition-group dt {
    font-weight: 600;
    color: var(--label-color);
    margin-bottom: 4px;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.definition-group dd {
    margin-left: 0;
    font-size: 1rem;
    line-height: 1.8;
}

.word-item-container {
    display: inline-block;
    margin-right: 5px;
    white-space: nowrap;
}

.word-text {
    vertical-align: middle;
}

.read-item-button {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    padding: 0 3px;
    border-radius: 50%;
    transition: background-color 0.2s ease;
    display: inline-block;
    vertical-align: middle;
    opacity: 0.7;
}

.read-item-button:hover {
    background-color: rgba(0, 123, 255, 0.1);
    opacity: 1;
}

.read-item-button svg {
     display: inline-block;
     width: 16px;
     height: 16px;
     vertical-align: middle;
}

.definition-group dd .separator {
     color: var(--label-color);
     margin-right: 5px;
     vertical-align: middle;
}

.definition-group dd ul.example-list {
    list-style-position: inside;
    padding-left: 0;
}
.definition-group dd ul.example-list li {
    font-style: italic;
    color: #555;
    font-size: 0.95rem;
    border-left: 3px solid var(--primary-color);
    padding-left: 10px;
    margin-bottom: 5px;
}

/* --- Explanation Container --- */
.explanation-container {
    margin-top: 25px;
    padding: 20px;
    border: 1px solid var(--border-color);
    border-radius: var(--button-radius);
    background-color: #fdfdff; /* Slightly different background */
}
.explanation-container h3 {
    color: var(--primary-color);
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 8px;
    margin-bottom: 15px;
}
.explanation-container .explanation-intro {
    font-style: italic;
    color: var(--secondary-color);
    margin-bottom: 20px;
}
.explanation-container .explanation-section {
    margin-bottom: 15px;
}
.explanation-container .explanation-section h4 {
    margin-bottom: 5px;
    font-weight: 600;
}
.explanation-container .explanation-section p,
.explanation-container .explanation-section ul {
    margin-left: 0;
    padding-left: 0;
}
.explanation-container .explanation-section ul li {
    list-style-type: '– '; /* Dấu gạch ngang đầu dòng */
    padding-left: 8px;
    margin-bottom: 5px;
}
.explanation-container .explanation-footer {
    text-align: right;
    font-size: 0.8rem;
    color: #aaa;
    margin-top: 20px;
}


/* --- Navigation Buttons --- */
.navigation {
    display: flex;
    justify-content: space-between;
    width: 100%;
    gap: 15px; /* Thêm khoảng cách */
}

.navigation button {
    flex-grow: 1; /* Cho các nút tự động chia sẻ không gian */
    color: white;
    padding: 12px 20px;
    border: none;
    border-radius: var(--button-radius);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: background-color 0.3s ease, transform 0.1s ease;
}
#prevButton, #nextButton {
    background-color: var(--primary-color);
}
#prevButton:hover, #nextButton:hover {
    background-color: var(--primary-hover);
}
#explainButton {
    background-color: var(--secondary-color);
}
#explainButton:hover {
    background-color: var(--secondary-hover);
}
.navigation button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}
.navigation button:active:not(:disabled) {
     transform: scale(0.98);
}


/* --- Status & Loading --- */
.status-message {
    margin-top: 15px;
    font-style: italic;
    color: var(--label-color);
}

.error-message {
    color: #dc3545;
    font-weight: 600;
}

.loading-spinner {
    border: 4px solid rgba(0, 123, 255, 0.2);
    border-left-color: var(--primary-color);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
    display: none;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}


/* --- Responsiveness --- */
@media (max-width: 768px) {
    .flashcard__term h2 {
        font-size: 2rem;
    }
     .navigation button {
        padding: 10px 20px;
        font-size: 0.95rem;
     }
     h1 {
         font-size: 1.5rem;
     }
}

@media (max-width: 480px) {
     body {
         padding: 15px;
     }
    .flashcard {
        padding: 20px;
    }
    .flashcard__term h2 {
        font-size: 1.8rem;
    }
     .navigation {
        flex-direction: column;
        gap: 10px;
     }
     .navigation button {
         width: 100%;
     }
     h1 {
         font-size: 1.3rem;
         margin-bottom: 20px;
     }
     .definition-group dt {
         font-size: 0.85rem;
     }
     .definition-group dd {
         font-size: 0.95rem;
     }
}