/* Modern Clean Theme Styles */

/* Base Transitions */
* {
    transition-property: background-color, border-color, color, fill, stroke, transform, box-shadow;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    transition-duration: 200ms;
}

/* Custom Scrollbar - Light Mode */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    /* Slate 300 */
    border-radius: 99px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
    /* Slate 400 */
}

/* Custom Scrollbar - Dark Mode Overrides */
/* The .dark class comes from the html tag */
.dark .custom-scrollbar::-webkit-scrollbar-thumb {
    background: #475569;
    /* Slate 600 */
}

.dark .custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: #64748b;
    /* Slate 500 */
}

/* Firefox Scrollbar */
.custom-scrollbar {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

.dark .custom-scrollbar {
    scrollbar-color: #475569 transparent;
}

/* Drag & Drop Visuals */
.ranked-item.dragging {
    opacity: 1.0;
    background-color: #e0e7ff;
    /* Indigo-100 */
    border: 2px solid #4f46e5;
    /* Indigo-600 */
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    transform: scale(1.05);
    z-index: 50;
    cursor: grabbing;
}

/* Dark mode drag state */
.dark .ranked-item.dragging {
    background-color: #1e293b;
    border-color: #818cf8;
}

.ranked-item.drag-over {
    border-top: 4px solid #0ea5e9;
    /* Sky-500 */
    margin-top: 4px;
}

.dark .ranked-item.drag-over {
    border-top-color: #38bdf8;
    /* Sky-400 */
}

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

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

.animate-fade-in {
    animation: fadeIn 0.3s ease-out forwards;
}

/* Mobile-specific adjustments */
@media (max-width: 640px) {

    /* Ensure no horizontal overflow */
    body {
        overflow-x: hidden;
    }

    /* Make sure buttons don't overflow */
    button {
        max-width: 100%;
        word-wrap: break-word;
    }

    /* Adjust container padding */
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* Adjust grid for very small screens */
    .grid {
        gap: 0.5rem;
    }
}

/* Prevent scrolling while dragging on touch */
.ranked-item.touch-dragging {
    touch-action: none;
}


/* Mobile Drag Avatar & Placeholder */
.drag-avatar {
    position: fixed;
    pointer-events: none;
    /* Critical: allows touch to pass through to the list below */
    z-index: 10000;
    opacity: 0.9;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
    transform: scale(1.05) rotate(2deg);
    /* Slight pop and tilt */
    transition: none;
    /* No lag when following finger */
}

.drag-placeholder {
    opacity: 0.3;
    border: 2px dashed #94a3b8 !important;
    filter: grayscale(100%);
}

/* ============================================ */
/* Layout Toggle Button Styling */
/* ============================================ */
.layout-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background-color: #f1f5f9;
    /* Slate 100 */
    color: #64748b;
    /* Slate 500 */
    border: 1px solid #e2e8f0;
    /* Slate 200 */
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.layout-toggle-btn:hover {
    background-color: #e2e8f0;
    /* Slate 200 */
    color: #475569;
    /* Slate 600 */
    border-color: #cbd5e1;
    /* Slate 300 */
    transform: scale(1.05);
}

.layout-toggle-btn:active {
    transform: scale(0.95);
}

.dark .layout-toggle-btn {
    background-color: #334155;
    /* Slate 700 */
    color: #94a3b8;
    /* Slate 400 */
    border-color: #475569;
    /* Slate 600 */
}

.dark .layout-toggle-btn:hover {
    background-color: #475569;
    /* Slate 600 */
    color: #cbd5e1;
    /* Slate 300 */
    border-color: #64748b;
    /* Slate 500 */
}

/* ============================================ */
/* Search & Import: List View Mode */
/* ============================================ */
.layout-list {
    display: grid !important;
    grid-template-columns: 1fr !important;
    /* Force single column */
    gap: 8px !important;
}

.layout-list>div {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    height: auto !important;
    padding: 10px !important;
    min-height: 80px;
}

/* Image styling in list view */
.layout-list>div>div:first-child {
    flex-shrink: 0;
    width: 60px !important;
    height: 60px !important;
    aspect-ratio: 1 / 1 !important;
    margin-right: 15px;
}

.layout-list>div>div:first-child img {
    width: 60px !important;
    height: 60px !important;
    object-fit: cover;
    border-radius: 6px;
}

/* Text/info section in list view */
.layout-list>div>div:nth-child(2) {
    flex-grow: 1;
    text-align: left;
    min-width: 0;
}

.layout-list>div>div:nth-child(2) h4 {
    line-clamp: initial !important;
    -webkit-line-clamp: initial !important;
    white-space: normal;
    overflow: visible;
}

/* Hover overlay adjustment for list view */
.layout-list>div>div:first-child>div {
    position: relative !important;
}

/* ============================================ */
/* Ranking Matrix: Grid View Mode */
/* ============================================ */
.layout-grid {
    display: grid !important;
    /* Better card size for readability */
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)) !important;
    gap: 12px !important;
    padding: 12px;
}

.layout-grid .ranked-item {
    /* The Card Item */
    display: flex !important;
    flex-direction: column !important;
    position: relative;
    /* Essential for overlays */
    aspect-ratio: 2 / 3;
    /* Standard Anime Poster Ratio */
    border-radius: 8px;
    overflow: hidden;
    /* Clips the image and overlays */
    padding: 0 !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    background: #000 !important;
    cursor: grab;
    height: auto !important;
}

/* The Image (Background) */
.layout-grid .ranked-item>img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Prevents squashing/stretching */
    display: block !important;
    border-radius: 0;
    /* Remove individual border-radius as parent handles it */
    box-shadow: none;
    /* Remove individual shadow */
    transition: transform 0.2s ease;
    z-index: 1;
}

.layout-grid .ranked-item:hover>img {
    transform: scale(1.05);
}

/* The Rank Number (Overlay Badge) - UNHIDE */
.layout-grid .ranked-item>div:first-child {
    display: flex !important;
    /* Force visible */
    position: absolute;
    top: 6px;
    left: 6px;

    /* Badge Styling */
    background-color: #6366f1;
    /* Primary color (Indigo) */
    color: #fff;
    font-weight: bold;
    font-size: 14px;
    width: 28px;
    height: 28px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    /* Circle badge */
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
    z-index: 2;
}

/* Dark mode badge adjustment */
.dark .layout-grid .ranked-item>div:first-child {
    background-color: #818cf8;
    /* Lighter indigo for dark mode */
}

/* The Title/Details Container (Bottom Overlay) - UNHIDE */
.layout-grid .ranked-item>div:nth-child(3) {
    display: flex !important;
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;

    /* Gradient Overlay background so text is readable */
    background: linear-gradient(to top, rgba(0, 0, 0, 0.95) 0%, rgba(0, 0, 0, 0.7) 50%, rgba(0, 0, 0, 0) 100%);
    padding: 30px 8px 8px 8px;
    /* Top padding for gradient fade */
    z-index: 2;
    flex-direction: column;
    justify-content: flex-end;
}

/* Style the Title text */
.layout-grid .ranked-item>div:nth-child(3)>div:first-child {
    color: #fff;
    font-size: 11px;
    line-height: 1.3;
    font-weight: 600;
    text-align: center;

    /* Truncate text to 2 lines */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
    margin-bottom: 2px;
}

/* Hide secondary info (Year, Format) in grid view to reduce clutter */
.layout-grid .ranked-item>div:nth-child(3)>div:last-child {
    display: none !important;
}

/* Hide the action buttons in grid view */
.layout-grid .ranked-item>div:nth-child(4) {
    display: none !important;
}

/* Dragging state in grid view */
.layout-grid .ranked-item.dragging {
    opacity: 0.5;
    transform: scale(1.05);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
}

/* Dark mode grid item border */
.dark .layout-grid .ranked-item {
    border-color: rgba(255, 255, 255, 0.15) !important;
}