/* ================================
   ADD THESE CSS VARIABLES AT THE TOP
   ================================ */


:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --secondary: #10b981;
    --accent: #f59e0b;
    --danger: #ef4444;
    --warning: #f59e0b;
    --warning-light: rgba(245, 158, 11, 0.1);
    --success: #10b981;
    --text: #1f2937;
    --text-light: #6b7280;
    --text-lighter: #9ca3af;
    --bg: #ffffff;
    --bg-secondary: #f9fafb;
    --border: #e5e7eb;
    --border-light: #f3f4f6;
    --hover: #f9fafb;
    --code-bg: #f7f7f7;
    --input-bg: #ffffff;
    --card-bg: #ffffff;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --radius: 12px;
    --radius-sm: 8px;

}

.dark-mode {
    --accent: #f59e0b;
    --danger: #dc2626;
    --warning: #d97706;
    --warning-light: rgba(217, 119, 6, 0.1);
    --success: #10b981;
    --text: #f9fafb;
    --text-light: #d1d5db;
    --text-lighter: #9ca3af;
    --bg: #111827;
    --bg-secondary: #1f2937;
    --border: #374151;
    --border-light: #4b5563;
    --hover: #1f2937;
    --code-bg: #2d2d2d;
    --input-bg: #1f2937;
    --card-bg: #1f2937;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
}

.settings-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--text);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-btn:hover {
    background-color: #69696991;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}


/* صفحة الإعدادات */
.settings-page {
    position: absolute;
    position: fixed;
    /* keep it above content */
    top: 0;
    right: -400px;
    width: 400px;
    height: 100vh;
    background: white;
    box-shadow: -5px 0 25px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    transition: right 0.4s ease;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.settings-page.open {
    right: 0;
}

.settings-page.active {
    right: 0;
}

.settings-header {
    padding: 20px;
    background: var(--primary);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.settings-header h2 {
    margin: 0;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.close-settings {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s;
}

.close-settings:hover {
    background: rgba(255, 255, 255, 0.3);
}

.settings-content {
    padding: 20px;
    flex: 1;
}

.settings-section {
    margin-bottom: 30px;
}

.settings-section h3 {
    color: var(--primary);
    font-size: 1.1rem;
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-light);
}

.setting-info {
    flex: 1;
}

.setting-label {
    display: block;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 4px;
}

.setting-desc {
    display: block;
    font-size: 0.85rem;
    color: var(--text-light);
}

/* عناصر التحكم */
.toggle-switch {
    width: 50px;
    height: 26px;
    background: #ccc;
    border-radius: 13px;
    position: relative;
    border: none;
    cursor: pointer;
    transition: background 0.3s;
}

.toggle-switch.active {
    background: var(--primary);
}

.toggle-slider {
    position: absolute;
    width: 22px;
    height: 22px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
}

.toggle-switch.active .toggle-slider {
    transform: translateX(24px);
}

.font-size-controls {
    display: flex;
    gap: 5px;
}

.font-btn {
    padding: 6px 12px;
    border: 2px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-color);
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.font-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.toggle-btn,
.action-btn,
.danger-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.toggle-btn {
    background: var(--bg);
    border: 2px solid var(--border);
    padding: 10px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    color: var(--text);
    transition: all 0.3s ease;
    min-width: 50px;
    justify-content: center;
}

.action-btn {
    background: green;
    color: white;
}

.danger-btn {
    background: var(--danger);
    color: white;
}

.toggle-btn:hover,
.action-btn:hover,
.danger-btn:hover {
    opacity: 0.9;
    transform: translateY(-2px);
}

/* طبقة التعتيم خلف الإعدادات */
.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.808);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.settings-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Dark Mode للاعدادات */
.dark-mode .settings-page {
    background: #1f2937;
}

.dark-mode .settings-section h3 {
    color: #60a5fa;
    border-bottom-color: #374151;
}

.dark-mode .setting-item {
    border-bottom-color: #374151;
}

.dark-mode .font-btn {
    background: #374151;
    border-color: #4b5563;
    color: #f9fafb;
}

.tts-open {
    display: none;
    visibility: hidden;
    position: absolute
}

.control-btn {
    background: var(--bg);
    border: 2px solid var(--border);
    padding: 10px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    color: var(--text);
    transition: all 0.3s ease;
    min-width: 50px;
    justify-content: center;
}

select {
    background: var(--bg);
    border: 2px solid var(--border);
    padding: 10px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 500;
    color: var(--text);
    transition: all 0.3s ease;
    min-width: 20px;
    justify-content: center;
}

.tts-btn {
    background: var(--primary);
    border: 2px solid var(--border);
    padding: 10px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    color: var(--text);
    transition: all 0.3s ease;
    min-width: 50px;
    justify-content: center;
}

.tts-active {
    background: var(--bg);
}













/* ================================
   BUTTON STYLES - ADD THIS SECTION
   ================================ */

/* Base button class */
.btn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    padding: 12px 20px !important;
    border: none !important;
    border-radius: 8px !important;
    font-weight: 600 !important;
    font-size: 14px !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    text-decoration: none !important;
    min-width: 100px !important;
}

/* Button variants */
.btn-primary {
    background: #4f46e5 !important;
    color: white !important;
}

.btn-secondary {
    background: #6b7280 !important;
    color: white !important;
}

.btn-danger {
    background: #ef4444 !important;
    color: white !important;
}

.btn-success {
    background: #10b981 !important;
    color: white !important;
}

/* Hover effects */
.btn:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15) !important;
    opacity: 0.9 !important;
}

/* Active state */
.btn:active {
    transform: translateY(0) !important;
}

/* ================================
   FIX CSS-ACTIONS BUTTONS
   ================================ */

/* Remove the green background from .css-actions */
.css-actions {
    width: fit-content;
    display: flex !important;
    gap: 10px !important;
    margin-bottom: 15px !important;
    background-color: transparent !important;
    /* REMOVE THE GREEN */
    z-index: 90000 !important;
}



/* Custom CSS Modal Styles */
.custom-css-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    background: var(--background);
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    z-index: 1100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow-y: scroll;
}

.custom-css-modal.active {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

.custom-css-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card-bg);
    border-radius: 12px 12px 0 0;
}

.custom-css-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 10px;
}

.custom-css-header h3 i {
    color: var(--primary);
}

.close-modal {
    background: transparent;
    border: none;
    color: var(--text-light);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    transition: all 0.2s;
}

.close-modal:hover {
    background: var(--hover);
    color: var(--text);
}

.custom-css-body {
    padding: 20px;
    background-color: rgb(165, 165, 165);
    flex: 1;
    overflow-y: scroll;
    display: flex;
    flex-direction: column;
}

.dark-mode .custom-css-body {
    background-color: #111827;
}

.css-editor-header {
    margin-bottom: 15px;
}

.css-examples {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}

.css-examples small {
    color: var(--text-light);
    font-weight: 600;
}

.css-examples code {
    background: var(--code-bg);
    padding: 4px 8px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    color: var(--primary);
    border: 1px solid var(--border);
}

#customCSSInput {
    width: 100%;
    min-height: 220px;
    flex: 1;
    padding: 15px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text);
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    overflow-y: scroll;
    margin-bottom: 15px;
    transition: border-color 0.3s;
}

#customCSSInput:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(74, 108, 247, 0.1);
}

.css-actions {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
    background-color: green;
    z-index: 90000;
}

.css-actions .btn {
    padding: 10px 20px;
    font-size: 0.9rem;
}

.css-info {
    padding: 10px;
    background: var(--hover);
    border-radius: 6px;
    border-left: 3px solid var(--warning);
}

.css-info small {
    color: var(--text-light);
    font-size: 0.8rem;
}

.css-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1099;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.css-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Reset confirmation modal */
.reset-confirm-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 90%;
    max-width: 500px;
    background: rgba(0, 0, 0, 0.801);
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    z-index: 1100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}



.reset-confirm-modal.active {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

.reset-modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    background: var(--warning-light);
    border-radius: 12px 12px 0 0;
}

.reset-modal-header h3 {
    margin: 0;
    color: var(--warning);
    display: flex;
    align-items: center;
    gap: 10px;
}

.reset-modal-body {
    padding: 20px;

}

.reset-modal-body p {
    margin: 0 0 15px 0;
    color: var(--text);
    line-height: 1.5;
}

.reset-warning {
    background: var(--warning-light);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 20px;
    border-left: 3px solid var(--warning);
}

.reset-warning i {
    color: var(--warning);
    margin-right: 8px;
}

.reset-warning span {
    color: var(--text);
    font-weight: 600;
}

.reset-modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;

}

/* Button danger style */
.btn-danger {
    background: var(--danger) !important;
    color: white !important;
    border: none !important;
}

.btn-danger:hover {
    background: #dc2626 !important;
    transform: translateY(-2px);
}

/* gogggle translation popup */

/* Translation Popup Styles */
.word-translation-persistent {
    margin-top: 12px;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: 8px;
    border-left: 4px solid var(--primary);
    animation: fadeIn 0.3s ease;
}

.translation-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.translation-popup-language-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.translation-popup-icon {
    color: var(--primary);
}

.translation-popup-label {
    color: var(--text-light);
    font-weight: 600;
}

.translation-popup-actions {
    display: flex;
    gap: 5px;
}

.translation-popup-btn {
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.translation-popup-btn:hover {
    transform: translateY(-1px);
}

.translation-popup-btn:active {
    transform: translateY(0);
}

.retranslate {
    background: var(--primary);
    color: white;
}

.retranslate:hover {
    background: var(--primary-dark, #2a75ff);
    box-shadow: 0 2px 5px rgba(58, 134, 255, 0.3);
}

.close-translation-popup-btn {
    background: none;
    color: var(--text-light);
    font-size: 12px;
}

.close-translation-popup-btn:hover {
    color: var(--danger);
    background-color: rgba(230, 57, 70, 0.05);
}

.translation-popup-content {
    color: var(--primary);
    font-weight: 600;
    font-size: 18px;
    text-align: center;
    padding: 5px 0;
    line-height: 1.4;
}

.translation-popup-footer {
    font-size: 11px;
    color: var(--text-light);
    text-align: center;
    margin-top: 5px;
    opacity: 0.8;
}

/* Animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

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

.language-select {
    width: 150px;
}

/* Spinner animation for re-translate button */
.fa-spinner.fa-spin {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* google tss */
/* Add these styles to your CSS */
.word-tts-btn {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
}

.word-tts-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.1);
}

.word-tts-btn:active {
    transform: scale(0.95);
}

.word-tts-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}




/* Spinner animation */
@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.fa-spinner.fa-spin {
    animation: spin 1s linear infinite;
}

/* Responsive Design */
@media (max-width: 768px) {
    .settings-page {
        width: 100%;
        height: 100vh;
        right: -100%;
    }

    .css-actions {
        flex-wrap: wrap;
    }

    .settings-header {
        padding: 15px;
    }

    .settings-content {
        padding: 15px;
    }
}

@media print {

    /* ===== HIDE EVERYTHING FIRST ===== */
    body * {
        visibility: hidden !important;

    }

    /* ===== SHOW ONLY WHAT'S NEEDED ===== */
    header,
    header *,
    #storyPage,
    #storyPage *,
    .story-header,
    .story-header *,
    .reading-progress * {
        visibility: visible !important;
    }

    .reading-progress-bar {
        width: 100% !important;
    }
nav {
        display: none !important;
    }

    /* ===== RESET BODY ===== */
    body {
        min-height: 0 !important;
        top: 0 !important;
        background-color: white !important;
        margin: 0 !important;
        padding: 10px !important;

    }

    /* ===== LAYOUT FIXES ===== */
    header {
        position: sticky !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        background-color: white !important;
        box-shadow: none !important;
        border-bottom: 2px solid #ccc !important;
        z-index: 1000 !important;

    }

    .logo span {
        color: black !important;
    }

    #storyPage {
        position: absolute !important;
        top: 60px !important;
        left: 0 !important;
        width: 100% !important;
        background-color: white !important;

        margin: 0 !important;
        padding: 20px !important;

    }

    .main-content {
        min-height: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* ===== HIDE WITHIN VISIBLE ELEMENTS ===== */
    .settings-btn,
    .header-actions,
    .reading-controls,
    .story-header .back-button,
    .story-header [class*="btn"],
    .story-header button,
    .paragraph-buttons {
        visibility: hidden !important;
        display: none !important;
    }




    /* ===== STORY HEADER ===== */
    .story-header {
        display: flex !important;
        flex-wrap: wrap !important;
        align-items: center !important;
        gap: 8px !important;
        margin: 0 !important;
        margin-top: 15px !important;
        page-break-inside: avoid !important;
        break-after: avoid !important;
        justify-content: flex-start !important;
    }

    .pro {
        display: none;
    }

    #storyTitle {
        font-size: 1.6rem !important;
        margin: 0 !important;
        padding: 0 !important;
        line-height: 1.3 !important;
        break-after: avoid !important;
        flex: 1 1 auto !important;
        min-width: 0 !important;
      
        overflow: hidden !important;
        text-overflow: ellipsis !important;

    }

    #lvl,
    #lvlcefr {
        display: inline-flex !important;
        align-items: center !important;
        flex-shrink: 0 !important;


        margin: 0 !important;
    }

    /* ===== STORY TEXT ===== */
    .story-text-container {
        background-color: white !important;
        margin-bottom: 0px;

    }

    .no-translation {
        background-color: transparent !important;
        border: none !important;
    }

    .paragraph {
        margin-bottom: 0 !important;
        color: black !important;
    }



    .translation-prg {
        color: black !important;
        font-size: 1em !important;
    }

 

  


}



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

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.dark-mode .modal-content {
    background: #1f2937;
    color: #f3f4f6;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #e5e7eb;
}

.dark-mode .modal-header {
    border-bottom-color: #374151;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.2rem;
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #6b7280;
}

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

.modal-body {
    padding: 20px;
}

.page-info {
    background: #f3f4f6;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 0.95rem;
}

.dark-mode .page-info {
    background: #374151;
}

.page-info i {
    color: var(--primary);
    margin-right: 8px;
}

.select-all {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 15px;
}

.dark-mode .select-all {
    border-bottom-color: #374151;
}

.select-all input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.page-checkboxes {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    max-height: 300px;
    overflow-y: auto;
    padding: 5px;
}

.page-checkbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: #f9fafb;
    border-radius: 6px;
}

.dark-mode .page-checkbox-item {
    background: #374151;
}

.page-checkbox-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.page-checkbox-item label {
    cursor: pointer;
    font-size: 0.9rem;
}

.more-pages-msg {
    grid-column: 1 / -1;
    padding: 10px;
    background: #fff3cd;
    color: #856404;
    border-radius: 6px;
    font-size: 0.9rem;
    margin-top: 10px;
}

.dark-mode .more-pages-msg {
    background: #4b3d1c;
    color: #ffd966;
}

.selection-summary {
    margin-top: 20px;
    padding: 12px;
    background: #e0f2fe;
    border-radius: 8px;
    font-size: 0.95rem;
}

.dark-mode .selection-summary {
    background: #1e3a5f;
    color: #bfdbfe;
}

.selection-summary i {
    color: var(--primary);
    margin-right: 8px;
}

.selection-summary span {
    font-weight: 600;
    color: var(--primary);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 20px;
    border-top: 1px solid #e5e7eb;
}

.dark-mode .modal-footer {
    border-top-color: #374151;
}

.modal-footer button {
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}






/* ======== JS Story Picker Modal ======== */
#jsPickerBox {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(780px, 94vw);
    max-height: 88vh;
    background: var(--bg, #fff);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
    z-index: 9001;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#jsPickerHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border, #e5e7eb);
    flex-shrink: 0;
}

#jsPickerHeader h3 {
    margin: 0;
    font-size: 1.05rem;
    color: var(--text, #1f2937);
    display: flex;
    align-items: center;
    gap: 8px;
}

#jsPickerCloseBtn {
    background: none;
    border: none;
    font-size: 1.15rem;
    cursor: pointer;
    color: var(--text-light, #6b7280);
    padding: 5px 8px;
    border-radius: 6px;
    flex-shrink: 0;
}

#jsPickerCloseBtn:hover {
    background: var(--bg-secondary, #f3f4f6);
}

#jsPickerSearchWrap {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border, #e5e7eb);
    flex-shrink: 0;
}

#jsPickerSearchInner {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-secondary, #f9fafb);
    border: 1.5px solid var(--border, #e5e7eb);
    border-radius: 9px;
    padding: 8px 12px;
    transition: border-color .2s;
}

#jsPickerSearchInner:focus-within {
    border-color: var(--primary, #4a6cf7);
}

#jsPickerSearchInner i {
    color: var(--text-light, #9ca3af);
    font-size: .9rem;
}

#jsPickerSearch {
    border: none;
    background: transparent;
    outline: none;
    color: var(--text, #1f2937);
    font-size: .9rem;
    width: 100%;
}

/* Flex row that wraps cards */
#jsPickerGrid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
    align-content: flex-start;
    -webkit-overflow-scrolling: touch;
}

#jsPickerGrid::-webkit-scrollbar {
    width: 5px;
}

#jsPickerGrid::-webkit-scrollbar-thumb {
    background: var(--border, #e5e7eb);
    border-radius: 3px;
}

/* Each card takes ~25% minus gap — 4 per row on desktop */
.js-picker-card {
    flex: 1 1 160px;
    max-width: calc(25% - 9px);
    border: 1.5px solid var(--border, #e5e7eb);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    background: var(--bg, #fff);
    display: flex;
    flex-direction: column;
    transition: border-color .2s, box-shadow .2s, transform .15s;
    -webkit-tap-highlight-color: transparent;
}

.js-picker-card:hover {
    border-color: var(--primary, #4a6cf7);
    box-shadow: 0 6px 20px rgba(74, 108, 247, .13);
    transform: translateY(-2px);
}

.js-picker-card:active {
    transform: scale(.97);
}

.js-picker-cover {
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary, #4a6cf7), var(--secondary, #10b981));
    font-size: 2.3rem;
    overflow: hidden;
    flex-shrink: 0;
}

.js-picker-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.js-picker-body {
    padding: 10px 12px 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
}

.js-picker-title {
    font-size: .88rem;
    font-weight: 700;
    color: var(--text, #1f2937);
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}

.js-picker-meta {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-top: 3px;
}

.js-picker-badge {
    padding: 2px 7px;
    border-radius: 20px;
    font-size: .66rem;
    font-weight: 700;
    white-space: nowrap;
}

.js-picker-author {
    font-size: .7rem;
    color: var(--text-light, #9ca3af);
    margin-top: auto;
    padding-top: 4px;
    display: flex;
    align-items: center;
    gap: 3px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.js-picker-empty {
    width: 100%;
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light, #9ca3af);
}

.js-picker-empty i {
    font-size: 2.4rem;
    display: block;
    margin-bottom: 10px;
    opacity: .4;
}

/* ── Tablet: 3 per row ── */
@media (max-width: 640px) {
    #jsPickerGrid {
        gap: 10px;
        padding: 12px 16px 20px;
    }

    .js-picker-card {
        flex: 1 1 130px;
        max-width: calc(33.33% - 7px);
    }
}

/* ── Mobile: bottom sheet, 2 per row ── */
@media (max-width: 520px) {
    #jsPickerBox {
        top: 0px;
        bottom: 0;
        left: 0;
        transform: none;
        width: 100%;
        max-height: 92vh;
        border-radius: 18px 18px 0 0;
    }

    #jsPickerHeader {
        padding: 12px 16px;
    }

    #jsPickerSearchWrap {
        padding: 10px 14px;
    }

    #jsPickerGrid {
        gap: 10px;
        padding: 12px 14px 32px;
    }

    .js-picker-card {
        flex: 1 1 130px;
        max-width: calc(50% - 5px);
    }

    .js-picker-cover {
        height: 65px;
        font-size: 1.8rem;
    }

    .js-picker-body {
        padding: 8px 10px 10px;
        gap: 3px;
    }

    .js-picker-title {
        font-size: .78rem;
    }

    .js-picker-badge {
        font-size: .6rem;
        padding: 1px 6px;
    }
}

/* ── Very small phones: 1 per row ── */
@media (max-width: 360px) {
    .js-picker-card {
        flex: 1 1 100%;
        max-width: 100%;
    }

    .js-picker-cover {
        height: 55px;
    }
}
