/* Load Quicksand Font */
@font-face {
    font-family: 'Quicksand';
    src: url('/res/quicksand.ttf') format('truetype');
    font-display: swap;
}

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
    display: block;
}

/* Set global font family */
* {
    font-family: 'Quicksand', sans-serif;
}

/* Improve touch interactions on mobile */
@media (hover: none) and (pointer: coarse) {
    /* Mobile-specific styles for touch devices */
    .folder:hover,
    .fav:hover {
        scale: 1; /* Remove hover effects on touch devices */
    }
    
    .folder:active,
    .fav:active {
        scale: 0.98; /* Add touch feedback instead */
    }
}

:root {
    --bg-color: #161618; /* #f4f4ff */
    --font-color: #efbf84;
}

body {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-content: center;
    justify-content: center;
    align-items: center;
    height: 100svh;
    padding: 0;
    margin: 0;
    font-family: 'Quicksand', sans-serif;

    /*background-size: 100% 100% !important;
    background: linear-gradient(15deg, #1dc9a3 0%, #1d516e 50%, #06071c 100%) center;*/
    background: url("https://api.dury.dev/wotd&lg=fr");
    background-size: cover;
    background-position: center;
}

#favs_ctn {
    max-width: 50%;

    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    align-content: center;
    padding: 2em;
    margin: 0;
    gap: 1em;

    /* Transparent background - let the beautiful background show through */
    background: transparent;
    backdrop-filter: none;
    border-radius: 0;
    box-shadow: none;

    max-height: 85%;
    overflow: auto;
}

.fav {
    cursor: pointer;
    text-decoration: none;
}

.fav_name {
    margin-bottom: 3px;
    text-decoration: none;
    color: black;
    font-family: 'Quicksand', sans-serif;
    font-weight: 600;
    word-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
    max-width: 100%;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.2;
}

.fav_icon {
    height:6em;
}

#addfav {
    position: fixed;
    height: 4em;
    width: 4em;
    right: 5px;
    bottom: 5px;
    cursor: pointer;
    fill: #000000;
    backdrop-filter: blur(0.5px);
    transition: all .2s ease-in-out;
}
#addfav:hover {
    scale:1.05;
}

modal {

}
modal.active {

}

#addfav_modal {

}

.folder {
    cursor: pointer;
    text-align: center;
    padding: 1em;
    margin: 0.5em;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 0.8em;
    backdrop-filter: blur(8px);
    transition: all 0.2s ease-in-out;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    aspect-ratio: 1;
    width: 140px;
    height: 140px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.folder:hover {
    background: rgba(255, 255, 255, 0.2);
    scale: 1.02;
    border-color: rgba(255, 255, 255, 0.4);
}

.folder-icon {
    font-size: 2.5em;
    margin-bottom: 0.3em;
}

.folder-name {
    color: black;
    font-size: 1em;
    margin: 0.3em 0;
    font-family: 'Quicksand', sans-serif;
    font-weight: 600;
    word-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
    max-width: 100%;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.2;
}

.folder-count {
    color: #666;
    font-size: 0.8em;
    font-family: 'Quicksand', sans-serif;
    font-weight: 500;
    background: rgba(255, 255, 255, 0.3);
    padding: 0.2em 0.5em;
    border-radius: 1em;
    display: inline-block;
    margin-top: 0.2em;
}

.back-folder {
    background: rgba(255, 165, 0, 0.2);
    border-color: rgba(255, 165, 0, 0.4);
}

.back-folder:hover {
    background: rgba(255, 165, 0, 0.3);
}

.folder-menu {
    position: absolute;
    top: 5px;
    right: 5px;
    cursor: pointer;
    font-size: 1.2em;
    color: #666;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.folder:hover .folder-menu {
    opacity: 1;
}

.folder-menu:hover {
    background: rgba(255, 255, 255, 0.9);
    color: #333;
}

.folder {
    position: relative;
}

.context-menu {
    position: absolute;
    background: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    z-index: 1000;
    min-width: 120px;
}

.context-item {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
}

.context-item:last-child {
    border-bottom: none;
}

.context-item:hover {
    background: #f0f0f0;
}

.fav-container {
    position: relative;
    display: inline-flex;
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(8px);
    border-radius: 0.8em;
    padding: 1rem;
    margin: 0.5em;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease-in-out;
    aspect-ratio: 1;
    width: 140px;
    height: 140px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.move-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    cursor: pointer;
    font-size: 1.2em;
    background: rgba(0, 150, 255, 0.7);
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.fav-container:hover .move-btn {
    opacity: 1;
}

.move-btn:hover {
    background: rgba(0, 150, 255, 0.9);
    transform: scale(1.1);
}

/* Modal System */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
    /* Prevent text selection on overlay */
    user-select: none;
}

.modal {
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    animation: modalSlideIn 0.3s ease-out;
    /* Allow text selection within modal */
    user-select: text;
    /* Remove focus outline since we handle it differently */
    outline: none;
}

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

.modal-header h3 {
    margin: 0;
    font-size: 1.2em;
    font-family: 'Quicksand', sans-serif;
    font-weight: 600;
    color: #333;
}

.modal-close {
    cursor: pointer;
    font-size: 24px;
    color: #666;
    line-height: 1;
    padding: 0 4px;
}

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

.modal-body {
    padding: 24px;
    max-height: 60vh;
    overflow-y: auto;
}

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

.modal-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-family: 'Quicksand', sans-serif;
    font-weight: 500;
    transition: all 0.2s;
}

.modal-btn-cancel {
    background: #f8f9fa;
    color: #666;
    border: 1px solid #dee2e6;
}

.modal-btn-cancel:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.modal-btn-confirm {
    background: #007bff;
    color: white;
}

.modal-btn-confirm:hover {
    background: #0056b3;
}

/* Form Styles */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-family: 'Quicksand', sans-serif;
    font-weight: 500;
    color: #333;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 14px;
    font-family: 'Quicksand', sans-serif;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.form-group input:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.warning-text {
    color: #dc3545;
    text-align: center;
    font-size: 16px;
    line-height: 1.5;
}

/* Folder Selection */
.folder-list {
    max-height: 200px;
    overflow-y: auto;
    border: 2px solid #e9ecef;
    border-radius: 8px;
}

.folder-option {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f8f9fa;
    transition: background-color 0.2s;
}

.folder-option:last-child {
    border-bottom: none;
}

.folder-option:hover {
    background: #f8f9fa;
}

/* Improved Context Menu */
.context-menu {
    position: fixed; /* Use fixed positioning for better viewport control */
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 1500;
    min-width: 160px;
    max-width: 200px;
    overflow: hidden;
    animation: contextMenuSlideIn 0.15s ease-out;
    /* Ensure menu stays within viewport bounds */
    max-height: calc(100vh - 20px);
    overflow-y: auto;
}

.context-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f8f9fa;
    font-size: 14px;
    font-family: 'Quicksand', sans-serif;
    font-weight: 500;
    display: flex;
    align-items: center;
    transition: background-color 0.2s;
}

.context-item:last-child {
    border-bottom: none;
}

.context-item:hover {
    background: #f8f9fa;
}

/* Bookmark Menu Button */
.bookmark-menu {
    position: absolute;
    top: 8px;
    right: 8px;
    cursor: pointer;
    font-size: 16px;
    color: #666;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.2s;
}

.fav-container:hover .bookmark-menu {
    opacity: 1;
}

.bookmark-menu:hover {
    background: rgba(255, 255, 255, 1);
    color: #333;
    transform: scale(1.1);
}

/* Remove old move button styles since we're using menu now */
.move-btn {
    display: none;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalSlideIn {
    from { 
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to { 
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes contextMenuSlideIn {
    from {
        opacity: 0;
        transform: translateY(-5px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Improved Mobile Responsiveness */
@media only screen and (max-width: 1400px) {
    #favs_ctn {
        max-width: 62%;
    }
}

@media only screen and (max-width: 1200px) {
    #favs_ctn {
        max-width: 70%;
    }
}

@media only screen and (max-width: 800px) {
    body {
        padding: 10px;
    }
    
    #favs_ctn {
        max-width: 95%;
        width: 95%;
        padding: 1.5em;
        gap: 1.2em;
        max-height: 90%;
        /* Make container transparent on mobile */
        background: transparent;
        backdrop-filter: none;
        border-radius: 0;
        box-shadow: none;
    }
    
    /* Enhanced individual element visibility on mobile */
    .folder, .fav {
        /*background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.3);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);*/
    }
    
    .folder:hover, .fav:hover {
        background: rgba(255, 255, 255, 0.98);
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
    }
    
    /* Larger folders for touch */
    .folder {
        min-width: 140px;
        padding: 1.2em;
    }
    
    .folder-icon {
        font-size: 3em;
    }
    
    .folder-name {
        font-size: 1.1em;
    }
    
    /* Better bookmark layout for mobile */
    .fav-container {
        width: calc(50% - 0.6em);
        min-width: 140px;
    }
    
    .fav {
        width: 100%;
        padding: 1em;
    }
    
    .fav_icon {
        height: 4em;
    }
    
    .fav_name {
        font-size: 0.9em;
        line-height: 1.2;
    }
    
    /* Touch-friendly menu buttons */
    .folder-menu {
        width: 32px;
        height: 32px;
        font-size: 18px;
        opacity: 1; /* Always visible on mobile */
        background: rgba(255, 255, 255, 0.95);
        top: 8px;
        right: 8px;
    }
    
    .bookmark-menu {
        width: 32px;
        height: 32px;
        font-size: 18px;
        opacity: 1; /* Always visible on mobile */
        background: rgba(255, 255, 255, 0.95);
        top: 8px;
        right: 8px;
    }
    
    /* Plus button positioning */
    #addfav {
        height: 3.5em;
        width: 3.5em;
        right: 15px;
        bottom: 15px;
    }
}

@media only screen and (max-width: 480px) {
    body {
        padding: 5px;
    }
    
    #favs_ctn {
        width: 100%;
        max-width: 100%;
        padding: 0.5rem;
        gap: 0.5rem;
        /* Keep transparent on small mobile too */
        background: transparent;
        backdrop-filter: none;
        border-radius: 0;
        box-shadow: none;
        height: auto;
        max-height: 100vh;
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-around;
        align-items: flex-start;
        overflow-y: auto;
    }
    
    /* Compact layout for 3 items per row with square aspect ratio */
    .folder, .fav-container {
        flex: 0 0 30%;
        max-width: 30%;
        min-width: 90px;
        margin: 0.25rem;
        padding: 0.5rem;
        background: rgba(255, 255, 255, 0.1);
        backdrop-filter: blur(15px);
        border: 1px solid rgba(255, 255, 255, 0.2);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
        aspect-ratio: 1;
        height: auto;
    }
    
    .folder:hover, .fav-container:hover {
        background: rgba(255, 255, 255, 0.98);
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
    }
    
    /* Compact folders for 3-per-row layout */
    .folder {
        min-width: 90px;
        padding: 0.5rem;
        height: auto;
    }
    
    .folder-icon {
        font-size: 2em;
        margin-bottom: 0.25rem;
    }
    
    .folder h3 {
        font-size: 0.9em;
        margin: 0;
        line-height: 1.2;
        text-align: center;
    }
    
    /* Make bookmarks match folder design */
    .fav {
        height: auto;
        min-height: 80px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-align: center;
        background: none !important;
        backdrop-filter: none !important;
        border: none !important;
        box-shadow: none !important;
    }
    
    .fav_icon {
        height: 2em;
        width: 2em;
        margin-bottom: 0.25rem;
    }
    
    .fav_name {
        font-size: 0.9em;
        line-height: 1.2;
        margin: 0;
        text-align: center;
        word-wrap: break-word;
        word-break: break-word;
        hyphens: auto;
        max-width: 100%;
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }
    
    /* Adjust modal for small screens */
    .modal {
        width: 95%;
        max-width: 95%;
    }
    
    .modal-header {
        padding: 15px 20px 12px;
    }
    
    .modal-body {
        padding: 20px;
    }
    
    .modal-footer {
        padding: 12px 20px;
    }
    
    /* Touch-friendly form elements */
    .form-group input {
        padding: 14px 16px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .modal-btn {
        padding: 12px 24px;
        font-size: 16px;
    }
    
    /* Context menu improvements */
    .context-menu {
        min-width: 180px;
    }
    
    .context-item {
        padding: 16px 20px;
        font-size: 16px;
    }
}