@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap');

/* --- 1. ROOT VARIABLES & BASE STYLES --- */

:root {
    --bg-color: #6A8E7F;
    --panel-blue: #A0D2EB;
    --panel-pink: #E4AEC5;
    --panel-dark-blue: #4A5899;
    --panel-dark: #444;
    --text-color: #333;
    --light-text-color: #fff;
    --border-radius: 20px;
}

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--bg-color);
    margin: 0;
    padding: 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    box-sizing: border-box;
}

/* --- 2. MAIN DICTIONARY PAGE LAYOUT --- */

#app-container {
    display: grid;
    grid-template-rows: 1fr auto;
    grid-template-columns: 1.2fr 2fr 1fr;
    grid-template-areas:
        "left main right"
        "actions actions actions";
    gap: 1.5rem;
    width: 100%;
    max-width: 1400px;
    height: 90vh;
}

/* Grid area assignments */
#left-panel { grid-area: left; }
#main-content { grid-area: main; }
#right-panel { grid-area: right; }
#actions-panel { grid-area: actions; }

#left-panel, #main-content, #right-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
    min-height: 0;
}

/* Generic panel styling */
.panel {
    background-color: white;
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}
.panel h3 { margin-top: 0; border-bottom: 2px solid rgba(0,0,0,0.1); padding-bottom: 0.5rem; margin-bottom: 1rem; }
.panel p { margin-bottom: 0; }

/* --- 3. DICTIONARY PAGE COMPONENTS --- */

/* Search Bar */
#search-container { background-color: var(--panel-dark); padding: 1rem; border-radius: var(--border-radius); }
#search-form { display: flex; align-items: center; background-color: #fff; border-radius: 25px; padding: 0.5rem 1rem; }
#word-input { border: none; outline: none; width: 100%; font-size: 1.1rem; padding-left: 0.75rem; }
#search-form i { color: #999; }

/* Image Panel */
#image-panel { flex-grow: 1; display: flex; justify-content: center; align-items: center; background-color: var(--panel-blue); overflow: hidden; min-height: 200px; }
#word-image { width: 100%; height: 100%; object-fit: cover; }

/* Colored Panels */
#definition-panel { background-color: var(--panel-blue); }
#vietnamese-panel, #example-panel, #ipa-panel, #synonym-panel { background-color: var(--panel-pink); }
#family-panel { background-color: var(--panel-dark-blue); color: var(--light-text-color); }
#family-panel h3 { border-bottom-color: rgba(255,255,255,0.2); }

/* Vietnamese Meaning Reveal Feature */
#vietnamese-panel { position: relative; cursor: pointer; }
#vietnamese-panel.hidden #vietnamese-meaning { filter: blur(5px); user-select: none; }
#vietnamese-panel.hidden::after {
    content: 'Click to reveal';
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.8);
    padding: 0.5rem 1rem; border-radius: 10px;
    font-weight: 500; color: #333;
}
#vietnamese-panel.revealed #vietnamese-meaning { filter: none; }
#vietnamese-panel.revealed::after { display: none; }

/* Tag Lists */
.tag-list { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.tag { padding: 0.3rem 0.8rem; border-radius: 15px; font-size: 0.9rem; }
#synonym-panel .tag { background-color: rgba(0,0,0,0.1); }
#family-panel .tag { background-color: rgba(255,255,255,0.2); }

/* Action Buttons */
#actions-panel { display: flex; gap: 1rem; justify-content: center; align-items: center; padding-top: 0.5rem; position: relative; z-index: 10; }
.action-btn, .exam-link, .data-link {
    padding: 0.8rem 1.5rem; border: none; border-radius: 12px;
    background-color: var(--panel-dark); color: var(--light-text-color);
    font-size: 1rem; font-weight: 500; cursor: pointer; text-decoration: none;
    transition: all 0.2s; display: flex; align-items: center; gap: 0.5rem;
}
.action-btn:hover, .exam-link:hover, .data-link:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.15); }
.action-btn:disabled { background-color: #28a745; color: white; cursor: not-allowed; opacity: 1; }
.data-link { background-color: var(--panel-blue) !important; color: var(--text-color) !important; }

/* --- 4. UNIVERSAL MODAL & TOAST STYLES --- */

/* Universal Modal Styling */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex; justify-content: center; align-items: center;
    z-index: 2000;
    opacity: 0; visibility: hidden; pointer-events: none;
    transition: opacity 0.3s ease, visibility 0s 0.3s;
}
.modal-overlay.visible {
    opacity: 1; visibility: visible; pointer-events: auto;
    transition: opacity 0.3s ease, visibility 0s;
}
.modal-content {
    background: white; padding: 2rem; border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.25);
    width: 90%; max-width: 450px;
    transform: scale(0.95); transition: transform 0.3s ease;
}
.modal-overlay.visible .modal-content { transform: scale(1); }
.modal-content h3 { margin-top: 0; text-align: center; }
.modal-content p { margin: 1rem 0; color: #555; text-align: center; }
.modal-actions { display: flex; justify-content: flex-end; gap: 1rem; margin-top: 1.5rem; }
.modal-actions button { padding: 10px 20px; border: none; border-radius: 8px; cursor: pointer; font-weight: bold; transition: background-color 0.2s; }

/* Save Word Modal Specifics */
.topic-list-container { max-height: 150px; overflow-y: auto; border: 1px solid #eee; padding: 0.5rem; border-radius: 8px; }
.topic-checkbox { display: flex; align-items: center; padding: 0.5rem; }
.topic-checkbox input { margin-right: 0.5rem; }
#add-topic-container { display: flex; gap: 0.5rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid #eee; }
#new-topic-input { flex-grow: 1; border: 1px solid #ccc; border-radius: 8px; padding: 0.5rem; }
#add-topic-btn { border: none; background-color: var(--panel-dark-blue); color: white; padding: 0.5rem 1rem; border-radius: 8px; cursor: pointer; }

/* Password Modal Specifics */
#password-input { width: 100%; box-sizing: border-box; padding: 12px; margin-bottom: 10px; border: 1px solid #ccc; border-radius: 8px; font-size: 1rem; }
.btn-primary { background-color: #007bff; color: white; }
.btn-secondary { background-color: #e9ecef; color: #495057; }
.error-message { color: #dc3545; font-size: 0.9rem; height: 1.2em; text-align: left; margin-top: -5px; }

/* Toast Notification */
#toast-notification {
    position: fixed; bottom: -100px; left: 50%;
    transform: translateX(-50%); padding: 1rem 2rem;
    border-radius: 10px; color: white; font-weight: 500;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2); z-index: 3000;
    transition: bottom 0.5s ease-in-out;
}
#toast-notification.show { bottom: 2rem; }
#toast-notification.success { background-color: #28a745; }
#toast-notification.error { background-color: #dc3545; }

/* --- 5. DATA & MANAGE TOPICS PAGE STYLES --- */

.data-body { align-items: flex-start; padding-top: 4rem; }
#data-container {
    width: 100%; max-width: 1000px; background-color: #ffffff;
    padding: 2.5rem; border-radius: var(--border-radius);
    box-shadow: 0 8px 30px rgba(0,0,0,0.12);
}
.data-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #eee; padding-bottom: 1rem; margin-bottom: 2rem; }
.data-title { margin: 0; color: var(--text-color); }
.btn-manage-topics {
    background-color: var(--panel-dark-blue); color: white;
    padding: 0.7rem 1.5rem; border-radius: 10px;
    text-decoration: none; font-weight: 500;
    transition: background-color 0.2s, transform 0.2s;
}
.btn-manage-topics:hover { background-color: #3b467a; transform: translateY(-2px); }
.table-container { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 1rem; border-bottom: 1px solid #e9ecef; text-align: left; vertical-align: middle; }
thead th { background-color: #f8f9fa; color: #495057; font-weight: 600; }
tbody tr:hover { background-color: #f1f3f5; }
td:first-child { font-weight: 600; color: var(--panel-dark-blue); }
.delete-btn {
    background-color: #ffe3e3; color: #dc3545;
    border: 1px solid #f5c6cb; padding: 0.4rem 0.8rem;
    border-radius: 8px; cursor: pointer; font-weight: 500;
    transition: all 0.2s;
}
.delete-btn:hover { background-color: #dc3545; color: white; }
.empty-table-cell { text-align: center; padding: 2rem 1rem !important; color: #888; font-style: italic; }

/* --- 6. EXAM PAGE STYLING [REFACTORED] --- */

/* Main container for the 2-column layout */
#exam-layout-container {
    display: flex;
    gap: 2rem;
    width: 100%;
    max-width: 1200px;
    align-items: flex-start;
    justify-content: center;
}

/* Left column for topic selection */
#topic-selection-container {
    flex: 1;
    background-color: #fff;
    padding: 2rem 2.5rem;
    border-radius: var(--border-radius);
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    position: sticky; /* Keeps it in view on scroll */
    top: 2rem;
}
#topic-selection-container h2 { margin-top: 0; }
#topic-selection-container p { color: #666; }

#topic-list-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin: 1.5rem 0;
}
.topic-checkbox {
    background-color: #f8f9fa; padding: 0.8rem 1rem;
    border-radius: 10px; border: 1px solid #dee2e6;
    display: flex; align-items: center; cursor: pointer;
    transition: background-color 0.2s;
}
.topic-checkbox:hover { background-color: #e9ecef; }
.topic-checkbox input { margin-right: 0.75rem; width: 18px; height: 18px; }
.topic-checkbox label { font-size: 1rem; cursor: pointer; }

#start-exam-btn {
    width: 100%; padding: 0.8rem; font-size: 1rem;
    font-weight: 600; border: none; border-radius: 10px;
    background-color: var(--panel-dark-blue); color: white;
    cursor: pointer; margin-top: 1rem;
}
.back-link { margin-top: 1.5rem; }

/* Right column for the main exam interface */
#exam-container {
    width: 100%;
    max-width: 550px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}
.exam-title { color: white; text-align: center; margin-bottom: 1rem; }
#question-card { text-align: center; }
#question-card h2 { font-size: 3rem; margin: 1rem 0; color: var(--panel-dark-blue); }
#hint-card { cursor: pointer; background-color: var(--panel-blue); text-align: center; }
#hint-image { max-width: 100%; max-height: 200px; border-radius: 10px; margin-top: 1rem; }
#answer-form { display: flex; gap: 1rem; }
#answer-input { flex-grow: 1; border: 2px solid #ccc; border-radius: 10px; padding: 0.8rem; font-size: 1.1rem; }
#answer-form button { padding: 0.8rem 1.5rem; border: none; background-color: var(--panel-dark-blue); color: white; border-radius: 10px; cursor: pointer; font-size: 1rem; }
#feedback-card { text-align: center; }
#feedback-card.correct { background-color: #d4edda; color: #155724; }
#feedback-card.incorrect { background-color: #f8d7da; color: #721c24; }
#next-word-btn, #change-topics-btn {
    padding: 0.7rem 1.5rem; border: 2px solid #ccc;
    background-color: white; border-radius: 10px;
    cursor: pointer; font-size: 1rem; font-weight: 500;
    margin-top: 1rem; margin-right: 0.5rem;
}

.hidden {
    display: none !important;
}
#vietnamese-panel.is-hidden #vietnamese-meaning {
    filter: blur(5px);
    user-select: none;
}

#vietnamese-panel.is-hidden::after {
    content: 'Click to reveal';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.8);
    padding: 0.5rem 1rem;
    border-radius: 10px;
    font-weight: 500;
    color: #333;
}

#vietnamese-panel.is-revealed #vietnamese-meaning {
    filter: none;
}

#vietnamese-panel.is-revealed::after {
    display: none;
}

/* --- GitHub Star Button Styling --- */
.github-star-button {
    background: linear-gradient(45deg, #333, #555);
    color: #ffffff !important;
    border: 2px solid #666;
    box-shadow: 0 0 5px rgba(255, 255, 255, 0.2);

    transition: all 0.3s ease-in-out !important;
}

.github-star-button:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
    background: linear-gradient(45deg, #444, #666);
}

.github-star-button .fa-github {
    font-size: 1.1rem;
}
