.edit-mode-warning {
    position: fixed;
    top: 10px;
    left: 10px;
    background-color: #c0392b;
    color: white;
    padding: 8px 15px;
    border-radius: 5px;
    z-index: 10000;
    font-size: 1em;
    font-weight: bold;
    display: none; /* Hidden by default */
}

body.edit-mode-enabled .edit-mode-warning {
    display: block; /* Show only in edit mode */
}

.edit-mode-warning p {
    margin: 0;
}

.edit-mode-warning a {
    color: white;
    text-decoration: underline;
}

/* --- EDITING MODE --- */

#loading-spinner-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: none; /* Hidden by default */
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.spinner {
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 5px solid var(--primary-color);
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.status-icon {
    margin-left: 10px;
    font-size: 1.2em;
    opacity: 1;
    transition: opacity 0.3s ease-out;
}

.status-icon.success {
    color: #2ecc71;
}

.status-icon.error {
    color: #e74c3c;
}

.save-toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translate(-50%, 24px);
    opacity: 0;
    pointer-events: none;
    z-index: 10020;
    padding: 10px 18px;
    border-radius: 999px;
    background: linear-gradient(135deg, #1ea85d, #29c46b);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    box-shadow: 0 14px 32px rgba(18, 122, 65, 0.3);
    transition:
        opacity 0.28s ease,
        transform 0.34s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.save-toast.visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

.editable-list li {
    position: relative;
}

body.edit-mode-enabled #warmup .editable-list li,
body.edit-mode-enabled #discussion .editable-list li {
    padding-left: 68px;
    padding-right: 96px;
    cursor: grab;
}

body.edit-mode-enabled #warmup .editable-list li.editing,
body.edit-mode-enabled #discussion .editable-list li.editing,
body.edit-mode-enabled #warmup .editable-list li.drag-disabled,
body.edit-mode-enabled #discussion .editable-list li.drag-disabled {
    cursor: default;
}

body.edit-mode-enabled #warmup .editable-list li.dragging,
body.edit-mode-enabled #discussion .editable-list li.dragging {
    cursor: grabbing;
}

.question-text {
    display: block;
    user-select: none;
}

.question-text[contenteditable="true"] {
    outline: none;
    min-height: 1.5em;
    user-select: text;
    cursor: text;
}

.drag-handle {
    position: absolute;
    top: 50%;
    left: 12px;
    transform: translateY(-50%);
    width: 40px;
    min-height: 36px;
    border: none;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.7);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
    z-index: 4;
    padding: 4px;
}

body.light-mode .drag-handle {
    background: rgba(0, 0, 0, 0.06);
    color: rgba(0, 0, 0, 0.55);
}

.drag-handle:hover:not(:disabled) {
    background: rgba(229, 9, 20, 0.18);
    color: white;
}

.drag-order {
    font-size: 0.8rem;
    font-weight: 700;
    line-height: 1;
    min-width: 1.5em;
    text-align: center;
}

.drag-handle:active:not(:disabled) {
    cursor: grabbing;
}

.drag-handle:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.editable-list li.saving {
    filter: blur(1.8px) saturate(0.8);
    opacity: 0.52;
    transform: scale(0.992);
    box-shadow: 0 0 0 2px rgba(229, 9, 20, 0.28), 0 14px 28px rgba(0, 0, 0, 0.18);
    background-color: rgba(229, 9, 20, 0.08);
    pointer-events: none;
}

body.light-mode .editable-list li.saving {
    background-color: rgba(229, 9, 20, 0.12);
}

#reading .title-container.saving,
#reading .article-part.saving {
    filter: blur(1.8px) saturate(0.8);
    opacity: 0.52;
    transform: scale(0.992);
    box-shadow: 0 0 0 2px rgba(229, 9, 20, 0.28), 0 14px 28px rgba(0, 0, 0, 0.18);
    background-color: rgba(229, 9, 20, 0.08);
    pointer-events: none;
}

body.light-mode #reading .title-container.saving,
body.light-mode #reading .article-part.saving {
    background-color: rgba(229, 9, 20, 0.12);
}

.custom-question-drag-ghost {
    position: fixed;
    top: 0;
    left: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    box-sizing: border-box;
    padding: 14px 18px 14px 12px;
    border-radius: 14px;
    background: rgba(24, 24, 24, 0.82);
    border-left: 4px solid var(--primary-color);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.32);
    pointer-events: none;
    z-index: 10001;
    opacity: 0.88;
}

body.light-mode .custom-question-drag-ghost {
    background: rgba(255, 255, 255, 0.88);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.14);
}

.custom-question-drag-ghost .drag-handle {
    position: static;
    transform: none;
    flex: 0 0 auto;
}

.custom-question-drag-ghost .question-text {
    display: block;
    user-select: none;
    color: inherit;
    line-height: 1.4;
}

.edit-controls {
    position: absolute;
    bottom: 15px;
    right: 15px;
    display: flex;
    gap: 8px;
    opacity: 0; /* Hidden by default */
    pointer-events: none; /* Not interactive by default */
    transition: opacity 0.2s ease-in-out;
    z-index: 4;
}

.flashcard .edit-controls {
    position: relative;
    top: auto;
    right: auto;
    transform: none;
    justify-content: center;
    padding-bottom: 10px;
    margin-top: auto;
}

.article-part .edit-controls {
    position: relative;
    top: auto;
    right: auto;
    transform: none;
    justify-content: flex-end;
    padding-top: 10px;
}

/* Only show controls when edit mode is enabled AND the user hovers over the item */
body.edit-mode-enabled li:hover > .edit-controls,
body.edit-mode-enabled .article-part:hover > .edit-controls,
body.edit-mode-enabled .question:hover > .edit-controls {
    opacity: 1;
    pointer-events: auto;
}

body.edit-mode-enabled .flashcard:hover > .edit-controls {
    opacity: 1;
    pointer-events: auto;
}

.add-item-container {
    display: none; /* Hide the add button container by default */
}

/* Only show the add button container when edit mode is enabled */
body.edit-mode-enabled .add-item-container {
    display: block;
}

.edit-btn, .delete-btn {
    background: rgba(0,0,0,0.3);
    border: none;
    color: white;
    cursor: pointer;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, transform 0.2s;
    z-index: 5;
}

.edit-btn:hover {
    background-color: #27ae60;
    transform: scale(1.1);
}

.delete-btn:hover {
    background-color: #c0392b;
    transform: scale(1.1);
}

li.editing {
    background-color: rgba(255, 255, 255, 0.05);
    border-left-color: #f1c40f;
    box-shadow: 0 0 15px rgba(241, 196, 15, 0.2);
}

.editable-list.is-sorting li {
    transition: background-color 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

.editable-list li.dragging {
    opacity: 0.72;
    box-shadow: 0 18px 34px rgba(0, 0, 0, 0.32);
    transform: none !important;
}

body.edit-mode-enabled #warmup .editable-list.is-sorting li:not(.dragging),
body.edit-mode-enabled #discussion .editable-list.is-sorting li:not(.dragging) {
    will-change: transform;
}

.editable-list li.drag-disabled .drag-handle {
    opacity: 0.35;
}

.editable-list.order-saving {
    pointer-events: none;
}

.editable-list.order-saving li {
    filter: blur(1.8px) saturate(0.8);
    opacity: 0.52;
    transform: scale(0.992);
    box-shadow: 0 0 0 2px rgba(229, 9, 20, 0.28), 0 14px 28px rgba(0, 0, 0, 0.18);
    background-color: rgba(229, 9, 20, 0.08);
}

body.light-mode .editable-list.order-saving li {
    background-color: rgba(229, 9, 20, 0.12);
}

.tf-question.editing .tf-btn {
    cursor: pointer !important;
    opacity: 0.6;
    pointer-events: auto !important;
}

.tf-question.editing .tf-btn.selected {
    opacity: 1;
    transform: scale(1.1);
    box-shadow: 0 0 15px var(--primary-color);
}

.add-item-container {
    text-align: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 2px solid #333;
}

body.light-mode .add-item-container {
    border-top-color: #eee;
}

.add-btn {
    background-color: var(--primary-color); /* Changed from green to red */
}

.add-btn:hover {
    background-color: var(--primary-hover);
}

.item-counter {
    display: block;
    margin-top: 15px;
    font-size: 1em;
    font-weight: bold;
    color: #888;
}

/* --- VOCAB EDIT MODAL --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background-color: var(--container-bg-dark);
    padding: 30px;
    border-radius: 15px;
    box-shadow: var(--shadow-dark);
    width: 90%;
    max-width: 500px;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal-overlay.visible .modal-content {
    transform: scale(1);
}

body.light-mode .modal-content {
    background-color: var(--container-bg-light);
    box-shadow: var(--shadow-light);
}

.modal-content h3 {
    color: var(--primary-color);
    margin-top: 0;
    margin-bottom: 25px;
    text-align: center;
}

.modal-form-group {
    margin-bottom: 20px;
}

.modal-form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #aaa;
}

body.light-mode .modal-form-group label {
    color: #555;
}

.modal-form-group input,
.modal-form-group textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid #444;
    background-color: #111;
    color: #fff;
    border-radius: 8px;
    font-size: 1em;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

body.light-mode .modal-form-group input,
body.light-mode .modal-form-group textarea {
    background-color: #f0f0f0;
    border-color: #ccc;
    color: #111;
}

.modal-form-group input:focus,
.modal-form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 10px rgba(229, 9, 20, 0.5);
}

.modal-form-group textarea {
    resize: vertical;
    min-height: 100px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 15px;
    margin-top: 30px;
}

.modal-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 25px;
    border: none;
    border-radius: 50px;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
}

.modal-btn:hover {
    transform: translateY(-2px);
}

.modal-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.modal-btn:disabled:hover {
    transform: none;
}

.modal-btn.is-saving {
    min-width: 96px;
}

.modal-btn-spinner {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    animation: modalButtonSpin 0.75s linear infinite;
}

@keyframes modalButtonSpin {
    to {
        transform: rotate(360deg);
    }
}

.modal-btn.save {
    background-color: var(--primary-color);
    color: white;
}
.modal-btn.save:hover {
    background-color: var(--primary-hover);
}

.modal-btn.cancel {
    background-color: #555;
    color: white;
}
.modal-btn.cancel:hover {
    background-color: #666;
}

.modal-btn.remove {
    background-color: #c0392b;
    color: white;
    margin-right: auto;
}

.modal-btn.remove:hover {
    background-color: #e74c3c;
}
.mcq-option {
    display: flex;
    align-items: center;
    gap: 15px;
}

.mcq-option input[type="text"] {
    flex-grow: 1;
}

.mcq-option input[type="radio"] {
    display: none;
}

.mcq-option label {
    position: relative;
    cursor: pointer;
    padding-left: 30px;
    font-weight: normal !important;
    color: #888 !important;
    transition: color 0.2s;
}

.mcq-option label:before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    border: 2px solid #555;
    border-radius: 50%;
    background-color: #222;
    transition: all 0.2s;
}

.mcq-option label:after {
    content: '';
    position: absolute;
    left: 5px;
    top: 50%;
    transform: translateY(-50%) scale(0);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--primary-color);
    transition: transform 0.2s var(--bounce);
}

.mcq-option input[type="radio"]:checked + label {
    color: var(--primary-color) !important;
    font-weight: bold !important;
}

.mcq-option input[type="radio"]:checked + label:before {
    border-color: var(--primary-color);
}

.mcq-option input[type="radio"]:checked + label:after {
    transform: translateY(-50%) scale(1);
}

body.light-mode .mcq-option label:before {
    background-color: #fff;
    border-color: #6f6f6f;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

body.light-mode .mcq-option label {
    color: #444 !important;
}

body.light-mode .mcq-option label:hover:before {
    border-color: #3f3f46;
}

body.light-mode .mcq-option input[type="radio"]:checked + label:before {
    box-shadow: 0 0 0 3px rgba(229, 9, 20, 0.14);
}

/* --- TF EDIT MODAL --- */
.tf-options-modal {
    display: flex;
    gap: 20px;
    align-items: center;
}

.tf-options-modal input[type="radio"] {
    display: none;
}

.tf-options-modal label {
    position: relative;
    cursor: pointer;
    padding-left: 30px;
    font-weight: normal !important;
    color: #888 !important;
    transition: color 0.2s;
}

.tf-options-modal label:before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    border: 2px solid #555;
    border-radius: 50%;
    background-color: #222;
    transition: all 0.2s;
}

.tf-options-modal label:after {
    content: '';
    position: absolute;
    left: 5px;
    top: 50%;
    transform: translateY(-50%) scale(0);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--primary-color);
    transition: transform 0.2s var(--bounce);
}

.tf-options-modal input[type="radio"]:checked + label {
    color: var(--primary-color) !important;
    font-weight: bold !important;
}

.tf-options-modal input[type="radio"]:checked + label:before {
    border-color: var(--primary-color);
}

.tf-options-modal input[type="radio"]:checked + label:after {
    transform: translateY(-50%) scale(1);
}

body.light-mode .tf-options-modal label {
    color: #444 !important;
}

body.light-mode .tf-options-modal label:before {
    background-color: #fff;
    border-color: #6f6f6f;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

body.light-mode .tf-options-modal label:hover:before {
    border-color: #3f3f46;
}

body.light-mode .tf-options-modal input[type="radio"]:checked + label:before {
    box-shadow: 0 0 0 3px rgba(229, 9, 20, 0.14);
}

body.edit-mode-enabled .options li {
    pointer-events: none;
}

li.correct-answer {
    background-color: rgba(46, 204, 113, 0.18);
    color: #f4fff8;
    border-color: #2f9246;
    border-width: 3px;
    box-shadow: 0 0 0 2px rgba(47, 146, 70, 0.16);
}

.tf-btn.correct-answer {
    background-color: rgba(46, 204, 113, 0.18);
    color: #f4fff8;
    border-color: #2f9246;
    border-width: 3px;
    box-shadow: 0 0 0 2px rgba(47, 146, 70, 0.16);
    opacity: 1;
}

body.light-mode li.correct-answer {
    background-color: #eef9f1;
    color: #185b2a;
    border-color: #2f9246;
}

body.light-mode .tf-btn.correct-answer {
    background-color: #eef9f1;
    color: #185b2a;
    border-color: #2f9246;
}

.edit-banner-btn {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background-color: rgba(0, 0, 0, 0.5);
    color: white;
    border: 1px solid white;
    padding: 8px 12px;
    border-radius: 20px;
    cursor: pointer;
    transition: background-color 0.3s;
    z-index: 10;
}

.change-image-btn {
    background-color: rgba(0, 0, 0, 0.5);
    color: white;
    border: 1px solid white;
    padding: 8px 12px;
    border-radius: 20px;
    cursor: pointer;
    transition: background-color 0.3s;
    z-index: 10;
}

.tab-image-container .change-image-btn {
    position: absolute;
    bottom: 20px;
    right: 20px;
}

.tab-header .change-image-btn {
    position: relative;
    font-size: 0.5em;
    padding: 4px 8px;
}

.edit-banner-btn:hover, .change-image-btn:hover {
    background-color: rgba(0, 0, 0, 0.8);
}

/* --- IMAGE BANNER MODAL --- */
#banner-image-modal .modal-content {
    max-width: 800px;
}

#flashcard-image-modal .modal-content {
    width: min(92vw, 960px);
    max-width: 960px;
    max-height: 76vh;
    padding: 24px 28px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#flashcard-image-modal .flashcard-modal-header {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(0, 3fr);
    gap: 20px;
    margin-bottom: 16px;
    padding-bottom: 16px;
    position: sticky;
    top: 0;
    z-index: 2;
    flex-shrink: 0;
    background: var(--container-bg-dark);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

#flashcard-image-modal .current-image-section {
    margin: 0;
    padding: 0;
}

#flashcard-image-modal .current-image-section h4 {
    margin-bottom: 10px;
}

#flashcard-image-modal .current-image-preview {
    min-height: 64px;
    padding: 12px;
}

#flashcard-image-modal #flashcard-current-image {
    max-width: 120px;
    max-height: 120px;
}

body.light-mode #flashcard-image-modal .flashcard-modal-header {
    background: var(--container-bg-light);
    border-bottom-color: rgba(0, 0, 0, 0.08);
}

#flashcard-image-modal .flashcard-modal-controls {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 14px;
    min-width: 0;
}

#flashcard-image-modal .flashcard-header-search {
    margin-bottom: 0;
}

#flashcard-image-modal .image-modal-tabs {
    margin-bottom: 0;
}

.image-modal-tabs {
    display: flex;
    border-bottom: 2px solid #333;
    margin-bottom: 20px;
}

body.light-mode .image-modal-tabs {
    border-bottom-color: #ddd;
}

.image-modal-tabs .tab-link {
    background: none;
    border: none;
    color: #888;
    padding: 10px 20px;
    cursor: pointer;
    font-size: 1em;
    font-weight: bold;
    transition: color 0.2s, border-bottom 0.2s;
    border-bottom: 3px solid transparent;
}

body.light-mode .image-modal-tabs .tab-link {
    color: #666;
}

.image-modal-tabs .tab-link.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.image-tab-content {
    display: none;
}

.image-tab-content.active {
    display: block;
}

#flashcard-image-modal .image-modal-tabs,
#flashcard-image-modal .modal-actions {
    flex-shrink: 0;
}

#flashcard-image-modal .modal-actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    margin-top: 16px;
    padding-top: 16px;
    background: var(--container-bg-dark);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

#flashcard-image-modal .image-tab-content.active {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#flashcard-image-modal[data-active-tab="flashcard-upload"] .flashcard-header-search {
    display: none;
}

#flashcard-image-modal #flashcard-search-tab {
    flex: 1 1 auto;
    min-height: 0;
}

#flashcard-image-modal #flashcard-upload-tab {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

#flashcard-image-modal .search-container {
    flex-shrink: 0;
}

.search-container {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.search-container input {
    flex-grow: 1;
    padding: 12px;
    border: 2px solid #444;
    background-color: #111;
    color: #fff;
    border-radius: 8px;
    font-size: 1em;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

body.light-mode .search-container input {
    background-color: #f0f0f0;
    border-color: #ccc;
    color: #111;
}

body.light-mode #flashcard-image-modal .modal-actions {
    background: var(--container-bg-light);
    border-top-color: rgba(0, 0, 0, 0.08);
}

.search-container input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 10px rgba(229, 9, 20, 0.5);
}

.search-container .modal-btn {
    background-color: var(--primary-color);
    color: white;
}

.search-container .modal-btn:hover {
    background-color: var(--primary-hover);
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    height: 320px;
    overflow-y: auto;
    padding-right: 10px; /* for scrollbar */
    align-content: start;
}

#flashcard-image-modal .image-grid {
    flex: 1 1 auto;
    gap: 12px;
    height: 260px;
    padding-right: 4px;
}

#flashcard-image-modal .flashcard-search-result {
    width: 100%;
    margin: 0;
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1 / 1;
    box-sizing: border-box;
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 10px;
    transition:
        box-shadow 0.22s ease,
        border-color 0.22s ease;
}

body.light-mode #flashcard-image-modal .flashcard-search-result {
    background: #f9f9f9;
    border-color: #d6d6d6;
}

#flashcard-image-modal .flashcard-search-result.is-placeholder {
    pointer-events: none;
}

#flashcard-image-modal .flashcard-search-result.is-selected {
    border-color: var(--primary-color);
    border-width: 2px;
    box-shadow:
        0 0 0 3px rgba(var(--primary-rgb), 0.32),
        inset 0 0 0 1px rgba(var(--primary-rgb), 0.2);
}

body.light-mode #flashcard-image-modal .flashcard-search-result.is-selected {
    border-color: #b2070f;
    box-shadow:
        0 0 0 4px rgba(178, 7, 15, 0.28),
        inset 0 0 0 1px rgba(178, 7, 15, 0.18);
}

#flashcard-image-modal .flashcard-search-result.is-error {
    opacity: 0.7;
}

#flashcard-image-modal .flashcard-search-media {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    overflow: hidden;
    background: transparent;
}

#flashcard-image-modal .flashcard-search-result.is-loading .flashcard-search-media {
    background: linear-gradient(135deg, rgba(219, 226, 234, 0.92), rgba(241, 245, 249, 0.98));
    box-shadow: inset 0 0 0 1px rgba(133, 146, 160, 0.14);
}

body.light-mode #flashcard-image-modal .flashcard-search-result.is-loading .flashcard-search-media {
    background: linear-gradient(135deg, rgba(222, 229, 236, 0.94), rgba(244, 247, 250, 0.99));
    box-shadow: inset 0 0 0 1px rgba(136, 149, 162, 0.12);
}

#flashcard-image-modal .flashcard-search-media::before {
    content: "";
    position: absolute;
    inset: 0;
    opacity: 0;
    transform: translateX(-100%);
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.12) 32%,
        rgba(255, 255, 255, 0.5) 50%,
        rgba(255, 255, 255, 0.12) 68%,
        transparent 100%
    );
    transition: opacity 0.24s ease;
}

body.light-mode #flashcard-image-modal .flashcard-search-media::before {
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.22) 32%,
        rgba(255, 255, 255, 0.68) 50%,
        rgba(255, 255, 255, 0.22) 68%,
        transparent 100%
    );
}

#flashcard-image-modal .flashcard-search-result.is-loading .flashcard-search-media::before {
    opacity: 1;
    animation: flashcardImageShimmer 1.1s ease-in-out infinite;
}

#flashcard-image-modal .flashcard-search-result.is-loaded .flashcard-search-media::before,
#flashcard-image-modal .flashcard-search-result.is-error .flashcard-search-media::before {
    opacity: 0;
}

#flashcard-image-modal .flashcard-search-result img {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    max-width: 72px;
    max-height: 72px;
    object-fit: contain;
    opacity: 0;
    transform: scale(0.96);
    transition:
        opacity 0.26s ease,
        transform 0.32s ease;
}

#flashcard-image-modal .flashcard-search-result.is-loaded img {
    opacity: 1;
    transform: scale(1);
}

@keyframes flashcardImageShimmer {
    100% {
        transform: translateX(100%);
    }
}

.image-grid img {
    width: 100%;
    height: 100px;
    object-fit: cover;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.image-grid img:hover {
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.3);
}

.upload-container {
    text-align: center;
    padding: 40px 20px;
    border: 2px dashed #444;
    border-radius: 10px;
}

body.light-mode .upload-container {
    border-color: #ccc;
}

.upload-container input[type="file"] {
    display: none;
}

.upload-container label {
    display: inline-block;
    margin-bottom: 20px;
}

.upload-container p {
    font-size: 0.9em;
    color: #888;
}

#flashcard-image-modal .flashcard-upload-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    width: 100%;
    min-height: 0;
    padding: 24px 20px;
    box-sizing: border-box;
}

@media (min-width: 768px) {
    #warmup .tab-image-container,
    #discussion .tab-image-container {
        height: 320px;
        background-position: center;
    }
}

@media (max-width: 900px) {
    #flashcard-image-modal .modal-content {
        width: min(94vw, 820px);
    }

    #flashcard-image-modal .flashcard-modal-header {
        grid-template-columns: 1fr;
    }

    #flashcard-image-modal .image-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    #flashcard-image-modal .modal-content {
        width: 94vw;
        max-height: 84vh;
        padding: 20px;
    }

    #flashcard-image-modal .image-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        height: 240px;
    }
}

#warmup .tab-image-container,
#discussion .tab-image-container {
    height: 320px;
    background-position: center;
    background-size: cover;
    margin-bottom: 20px;
    border-radius: 15px;
}

.tab-image-container .change-image-btn {
    position: relative;
}

.view-exercise-container {
    text-align: center;
    margin: 20px 0;
}

.view-exercise-container .action-btn {
    background-color: var(--primary-color);
    color: white;
    text-decoration: none;
}

#edit-expired-modal .modal-content {
    text-align: center;
}

#edit-expired-modal .modal-actions {
    justify-content: center;
}

#edit-expired-modal .modal-btn {
    text-decoration: none;
}
