body {
    margin: 0;
    padding: 0;
    font-family: Arial, sans-serif;
    background: #f5f5f5;
    color: #333;
}

.container {
    width: 100%;
    height: 100vh;
    overflow: auto;
    padding: 20px;
    box-sizing: border-box;
}

.bookshelf {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: max-content;  /* Allow horizontal scrolling */
    min-width: 1400px;   /* Minimum width for proper layout */
    margin: 0 auto;
}

.shelf {
    position: relative;
    display: flex;
    gap: 0px;
    align-items: stretch;  /* Stacks stretch to fill height */
    padding: 10px 10px 0px 10px;
    background: rgba(0,0,0,0.02);
    border: 1px solid #ddd;
    border-radius: 8px;
    min-height: 300px;  /* Minimum height, but can grow */
}

.shelf::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 8px;
    background: #aaa;
    border-radius: 0 0 8px 8px;
    z-index: 1;  /* Keep shelf bar above background but below books */
}

.stack {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;  /* Books still stack from bottom */
    gap: 1px;
    min-height: 180px;  /* Good drop target height without being too tall */
    min-width: 80px;
    padding: 8px;
    padding-bottom: 9px;  /* Extra bottom padding to clear the shelf bar */
    border-radius: 4px;
    position: relative;
    z-index: 2;  /* Ensure stacks and books are above shelf bar */
}

.stack:hover {
    background: rgba(0,0,0,0.05);
}

.book {
    width: 70px;
    min-height: auto;
    border: 1px solid #666;
    border-radius: 2px;
    padding: 4px 6px;
    cursor: move;
    display: flex;
    flex-direction: column;
    justify-content: center;
    font-size: 10px;  /* Slightly larger for better readability */
    line-height: 1;
    text-align: left;
    margin: 0;
    user-select: none;
}

.book:hover {
    transform: translateX(2px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    z-index: 10;
}

.book-domain {
    font-weight: bold;
    font-size: 9px;
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1;
    margin-bottom: 2px;
}

.book-title {
    font-size: 8px;
    opacity: 0.9;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1;
}

/* Sortable states */
.sortable-ghost {
    opacity: 0.4;
}

.sortable-chosen {
    /* Subtle lift when picked up */
    transform: translateY(-2px);
}

.sortable-drag {
    opacity: 0.8;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    cursor: move !important;
}

/* Fix for forceFallback mode */
.sortable-fallback {
    opacity: 0.8 !important;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3) !important;
    cursor: move !important;
    z-index: 1000 !important;
}

/* Ensure smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Optional: Style scrollbars for better visibility */
.container::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

.container::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.1);
    border-radius: 6px;
}

.container::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.3);
    border-radius: 6px;
}

.container::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.5);
}

/* Ensure touch targets are adequate on mobile */
@media (max-width: 768px) {
    .book {
        min-height: 44px;  /* Apple's touch target recommendation */
        font-size: 12px;
    }
    
    .book-domain {
        font-size: 11px;
    }
    
    .book-title {
        font-size: 10px;
    }
}

/* Performance optimizations during drag */
body.dragging .book {
    transition: none !important;
    user-select: none;
}

body.dragging .book:not(.sortable-drag):not(.sortable-ghost) {
    box-shadow: none !important;
}

body.dragging .stack {
    transition: none !important;
}

/* Optimize rendering performance */
.bookshelf {
    contain: layout style;
}

.shelf {
    contain: layout;
}

.stack {
    contain: layout style;
    will-change: auto;
}
