/* General Styles */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f4f4f9;
    color: #333;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
}

/* --- Main Page (index.html) Specific Layout --- */
.main-container {
    justify-content: flex-start;
    align-items: stretch;
}

.left-panel {
    width: 350px;
    /* Initial width, will be adjustable */
    min-width: 250px;
    /* Minimum width */
    max-width: 800px;
    /* Maximum width */
    background-color: #fff;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
    /* Prevent from shrinking */
}

.resizer {
    flex-shrink: 0;
    width: 5px;
    background: #f4f4f9;
    cursor: col-resize;
    transition: background-color 0.2s;
}

.resizer:hover {
    background: #007bff;
}

#browser-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.controls {
    flex-shrink: 0;
    padding: 15px;
    border-bottom: 1px solid #ddd;
    overflow-y: auto;
}

.filter-group,
.sort-group {
    margin-bottom: 15px;
    display: flex;
    align-items: center;
}

.controls label {
    display: block;
    margin-right: 10px;
    margin-bottom: 0;
    font-weight: bold;
    font-size: 0.9em;
    color: #555;
    white-space: nowrap;
    min-width: 40px;
    /* Optional: align labels if desired */
}

.controls select,
.controls input[type="text"] {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
    background-color: #fdfdfd;
    transition: border-color 0.2s;
}

.controls select:focus,
.controls input[type="text"]:focus {
    border-color: #007bff;
    outline: none;
}


.poem-list {
    flex-grow: 1;
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-y: auto;
}

.poem-list li {
    padding: 12px 15px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
    transition: background-color 0.2s;
}

.poem-list li:hover {
    background-color: #e9f5ff;
}

.poem-list li.active {
    background-color: #007bff;
    color: white;
    font-weight: bold;
}

.exam-link-container {
    flex-shrink: 0;
    padding: 10px 15px;
    border-bottom: 1px solid #ddd;
    /* Changed from border-top */
    border-top: none;
    background: #f7f7f7;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.home-btn {
    font-size: 24px;
    text-decoration: none;
    width: 36px;
    height: 36px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    background: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, box-shadow 0.2s;
    margin-right: 10px;
}

.home-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
}

.mode-btn {
    display: block;
    padding: 8px 15px;
    /* Reduced padding for header style */
    font-size: 1em;
    cursor: pointer;
    border: 1px solid #007bff;
    background-color: #007bff;
    color: white;
    text-align: center;
    text-decoration: none;
    border-radius: 5px;
    transition: background-color 0.3s;
    flex-grow: 1;
    /* Take remaining space */
}

.mode-btn:hover {
    background-color: #0056b3;
}

.right-panel {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: #fff;
}

#poem-view {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    min-height: 0;
    /* Critical fix for nested flex containers */
}

.tabs {
    flex-shrink: 0;
    border-bottom: 2px solid #ddd;
    background-color: #f1f1f1;
    /* Changed to gray for better contrast */
    z-index: 1;
    position: sticky;
    top: 0;
    display: flex;
    /* Flexbox execution */
    align-items: center;
    /* Center vertically */
    padding-right: 15px;
    /* Spacing for right actions */
}

/* Right aligned actions container */
.tabs-right {
    margin-left: auto;
    /* Push to right */
    display: flex;
    align-items: center;
}

/* Common Tab Link (Left side) */
.tab-link {
    background-color: inherit;
    border: none;
    outline: none;
    cursor: pointer;
    padding: 14px 16px;
    transition: 0.3s;
    font-size: 17px;
    border-bottom: 2px solid transparent;
    color: #555;
    text-decoration: none;
}

.tab-link:hover {
    background-color: #e0e0e0;
}

.tab-link.active {
    border-bottom: 2px solid #007bff;
    color: #007bff;
    font-weight: bold;
    background-color: white;
    /* Active tab is white */
}

/* Favorite Button Styling (Matching Tabs) */
.fav-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px 12px;
    font-size: 16px;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
    color: #555;
}

.fav-btn:hover {
    background-color: #e0e0e0;
    color: #333;
}

.fav-btn.active {
    color: #e74c3c;
    background-color: rgba(231, 76, 60, 0.1);
}

.tab-content {
    display: none;
    flex-grow: 1;
    overflow-y: auto;
    padding: 5px;
    min-height: 0;
    /* Flexbox fix for scrolling */
}

.poem-images img {
    max-width: 100%;
    height: auto;
    display: block;
    margin-bottom: 15px;
    border-radius: 5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* --- Poem Navigation Bar (Header) --- */
#poem-navbar {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    background-color: #f8f5f2;
    border-bottom: 1px solid #e0d9d1;
    gap: 15px;
}

#poem-audio-container {
    flex-grow: 1;
    /* Audio takes remaining space */
    /* Remove padding/bg as parent handles it now */
    display: flex;
    /* To vertically center audio if needed */
    align-items: center;
    min-width: 0;
    /* Important for flex child truncation */
}

#poem-audio-container audio {
    width: 100%;
    height: 40px;
}

.nav-actions {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-btn-icon {
    font-size: 20px;
    text-decoration: none;
    width: 36px;
    height: 36px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    background: white;
    border: 1px solid #ddd;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
}

.nav-btn-icon:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
}

.nav-btn-text {
    padding: 6px 15px;
    font-size: 14px;
    background-color: #e67e22;
    /* Default Login Color */
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: background-color 0.2s;
    font-weight: bold;
    white-space: nowrap;
}

.nav-btn-text:hover {
    opacity: 0.9;
}

.poem-images {
    line-height: 1.8;
    font-size: 1.1em;
}

.poem-text {
    line-height: 1.8;
    font-size: 1.1em;
}

.poem-qa {
    line-height: 1.8;
    font-size: 1.1em;
}

/* --- Exam Page (exam.html) Specific Layout --- */
.exam-container {
    justify-content: center;
    align-items: center;
}

#exam-setup,
#exam-main,
#exam-results {
    width: 100%;
    max-width: 800px;
    padding: 40px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    text-align: center;
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

#wrong-questions-container {
    overflow-y: auto;
    text-align: left;
    padding-right: 15px;
    max-height: 1000px;
    /* Set max-height as requested */
}

#exam-setup h1,
#exam-results h1,
#exam-results h2 {
    margin-bottom: 20px;
    flex-shrink: 0;
}

.exam-filters {
    display: flex;
    justify-content: space-around;
    margin-bottom: 40px;
    text-align: left;
}

.exam-filters .filter-group {
    display: flex;
    flex-direction: column;
    min-width: 150px;
    /* Prevent groups from becoming too narrow */
}

.exam-filters .dynasty-group {
    width: 25%;
}

.exam-filters .author-group {
    width: 25%;
}

.exam-filters .semester-group {
    width: 40%;
}

.exam-filters .filter-group label {
    font-weight: bold;
    margin-bottom: 10px;
    font-size: 1.1em;
}

.checkbox-group {
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 10px;
    height: 200px;
    overflow-y: auto;
    background-color: #fdfdfd;
}

.checkbox-item {
    display: block;
    margin-bottom: 8px;
}

.checkbox-item label {
    margin-left: 8px;
    cursor: pointer;
    font-weight: normal;
    font-size: 1em;
}

#start-exam-btn,
#restart-exam-btn {
    padding: 15px 30px;
    font-size: 1.2em;
    background-color: #28a745;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    margin-top: 20px;
    flex-shrink: 0;
}

/* Other exam styles... */
#exam-countdown h1 {
    font-size: 6em;
    font-weight: bold;
    color: #007bff;
}

#exam-main .exam-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    font-size: 1.2em;
}

#question-timer {
    font-weight: bold;
    color: #dc3545;
}

#question-view {
    text-align: left;
    margin-bottom: 30px;
}

#results-summary {
    font-size: 1.5em;
    font-weight: bold;
    margin-bottom: 20px;
    color: #007bff;
    flex-shrink: 0;
}

.wrong-question {
    margin-bottom: 25px;
    padding: 15px;
    border-radius: 5px;
    background-color: #fce8e6;
    border-left: 5px solid #dc3545;
}

.wrong-question .options-result .correct {
    background-color: #e9f7ef;
    font-weight: bold;
}

.wrong-question .options-result .incorrect {
    text-decoration: line-through;
}

/* --- Exam Page (exam.html) Controls Styling --- */
.exam-controls {
    display: flex;
    justify-content: center;
    /* Center the control groups */
    gap: 40px;
    /* Add space between the groups */
    margin-bottom: 30px;
    width: 100%;
}

.control-group {
    display: flex;
    align-items: center;
    /* Vertically align label and select box */
    gap: 10px;
    /* Add space between them */
}

.control-group label {
    font-weight: bold;
    font-size: 1em;
    color: #555;
    flex-shrink: 0;
    /* Prevent label from shrinking */
}

.control-group select {
    /* Resetting default styles */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    /* Custom styles */
    background-color: #fdfdfd;
    border: 1px solid #ccc;
    border-radius: 5px;
    padding: 10px 40px 10px 15px;
    /* Right padding for arrow */
    font-size: 1em;
    color: #333;
    cursor: pointer;
    width: 200px;
    /* Or a specific width */
    background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20width%3D%2220%22%20height%3D%2220%22%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%3E%3Cpath%20d%3D%22M5%208l5%205%205-5z%22%20fill%3D%22%23555%22/%3E%3C/svg%3E');
    background-repeat: no-repeat;
    background-position: right 10px center;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.control-group select:hover {
    border-color: #888;
}

.control-group select:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

/* --- Mobile / Responsive Styles --- */
#menu-toggle-btn {
    display: none;
    /* Hidden by default on desktop */
    position: fixed;
    bottom: 15px;
    left: 15px;
    z-index: 1001;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

#overlay {
    display: none;
    /* Hidden by default */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

@media (max-width: 768px) {
    body {
        overflow: auto;
        /* Allow body to scroll on mobile */
    }

    .container {
        flex-direction: column;
        height: auto;
    }

    #menu-toggle-btn {
        display: block;
        /* Show the button on mobile */
    }

    .left-panel {
        position: fixed;
        left: 0;
        top: 0;
        height: 100%;
        width: 80%;
        max-width: 320px;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        box-shadow: 2px 0 15px rgba(0, 0, 0, 0.2);
    }

    .left-panel.open {
        transform: translateX(0);
    }

    #overlay.open {
        display: block;
    }

    .resizer {
        display: none;
    }

    .right-panel {
        width: 100%;
        height: auto;
        min-height: 100vh;
    }

    .main-container {
        padding-left: 0;
        /* Remove padding that might interfere */
    }

    /* Adjust right panel content for menu button */
    #poem-view {
        padding-top: 5px;
        /* Add padding to prevent content from hiding under the menu button area */
    }

    .tabs {
        top: 60px;
        /* Adjust sticky position for the new padding */
    }
}

/* --- Recitation View Styles --- */
.recitation-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 20px;
    box-sizing: border-box;
}

.recitation-header {
    margin-bottom: 20px;
    text-align: center;
}

.step-indicator {
    font-size: 1.2em;
    font-weight: bold;
    color: #555;
    margin-bottom: 10px;
}

.progress-bar-container {
    width: 100%;
    height: 10px;
    background-color: #e0e0e0;
    border-radius: 5px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background-color: #28a745;
    width: 0%;
    transition: width 0.3s ease;
}

.recitation-display {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 1.5em;
    /* Larger font for reading */
    line-height: 2;
    text-align: center;
    font-family: "楷体", "KaiTi", serif;
    /* Traditional font style */
    background-color: #fdfbf7;
    /* Paper-like background */
    border: 1px solid #e0d9d1;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    overflow-y: auto;
    position: relative;
    /* For absolute positioning of hints if needed */
}

.recitation-line {
    margin: 10px 0;
    transition: color 0.3s;
}

.recitation-line.active {
    color: #d32f2f;
    /* Highlight color */
    font-weight: bold;
    transform: scale(1.05);
    /* Slight zoom */
}

.masked-text {
    color: #999;
    /* Placeholder color */
    border-bottom: 1px dashed #999;
    cursor: pointer;
    transition: all 0.3s;
}

.masked-text.revealed {
    color: #333;
    text-shadow: none;
    border-bottom: none;
}

.recitation-controls {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
}

.control-btn {
    padding: 10px 20px;
    font-size: 1em;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    background-color: #007bff;
    color: white;
    transition: background-color 0.2s;
}

.control-btn:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

.control-btn:hover:not(:disabled) {
    background-color: #0056b3;
}

#hint-btn {
    background-color: #ffc107;
    color: #333;
}

#hint-btn:hover:not(:disabled) {
    background-color: #e0a800;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .recitation-display {
        font-size: 1.2em;
    }

    .control-btn {
        padding: 8px 15px;
        font-size: 0.9em;
    }
}

/* Modal Stylings */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    position: relative;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.success-icon {
    font-size: 60px;
    margin-bottom: 20px;
}

.success-content h2 {
    margin: 0 0 10px 0;
    color: #2c3e50;
    font-size: 24px;
}

.success-content p {
    color: #7f8c8d;
    margin-bottom: 25px;
    line-height: 1.5;
}

.primary-btn {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 10px 30px;
    border-radius: 25px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s;
}

.primary-btn:hover {
    background: #c0392b;
}

.close-modal {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 24px;
    color: #aaa;
    cursor: pointer;
}

.close-modal:hover {
    color: #333;
}