* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #FFFFFF 0%, #eee 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

header {
    text-align: center;
    color: rgba(152, 211, 97, 0.9);
    margin-bottom: 30px;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
}

header p {
    font-size: 1.1em;
    opacity: 0.9;
}

.toolbar {
    background: white;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 30px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}
.toolbar2 {
    margin-bottom: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.upload-section {
    display: flex;
    gap: 10px;
    align-items: center;
}

.upload-btn {
    background: linear-gradient(135deg, rgba(152, 211, 97, 0.9) 0%, rgba(152, 211, 97, 0.9) 100%);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.2s, box-shadow 0.2s;
    display: inline-block;
}

.upload-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #f0f0f0;
    color: #333;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

.controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.btn-nav {
    background: #667eea;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-nav:hover:not(:disabled) {
    background: #5568d3;
}

.btn-nav:disabled {
    background: #ccc;
    cursor: not-allowed;
}

#pageInfo {
    font-weight: 600;
    min-width: 100px;
    text-align: center;
}

.main-content {
    display: flex;
    gap: 30px;
    align-items: flex-start;
}


.gallery {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    flex: 0 0 480px; /* Fixed width for 3 columns */
    max-width: 480px;
}

.book-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.book-container {
    perspective: 2000px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 600px;
    margin-bottom: 30px;
    width: 100%;
}

.book {
    position: relative;
    width: 800px;
    height: 600px;
    transform-style: preserve-3d;
    transition: transform 0.6s;
}

.page {
    position: absolute;
    width: 400px;
    height: 600px;
    background: #f9f9f9;
    border: 1px solid #ddd;
    box-shadow: 0 0 20px rgba(0,0,0,0.3);
    transform-style: preserve-3d;
    transition: transform 1s cubic-bezier(0.645, 0.045, 0.355, 1);
}

.left-page {
    left: 0;
    transform-origin: right center;
    border-radius: 8px 0 0 8px;
}

.right-page {
    right: 0;
    transform-origin: left center;
    border-radius: 0 8px 8px 0;
}

.page-content,
.page-back {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    padding: 20px;
    overflow: hidden;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.page-content {
    background: #f9f9f9;
}

.page-back {
    background: #f9f9f9;
    transform: rotateY(180deg);
}

/* Realistic page turn animation */
.page.turning-next {
    transform: rotateY(-180deg);
}

.page.turning-prev {
    transform: rotateY(180deg);
}

.image-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

.book-image-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-container:hover .book-remove-btn {
    opacity: 1;
}

.image-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.image-container.empty {
    border: 2px dashed #ccc;
    background: #fafafa;
}

.image-container.empty::before {
    content: '📷';
    font-size: 3em;
    opacity: 0.3;
}

.image-container.empty::after {
    content: attr(data-drop-text);
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: #999;
    font-size: 0.9em;
}

/* Enhanced page shadows during rotation */
.page.turning-next,
.page.turning-prev {
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

.gallery h3 {
    margin-bottom: 15px;
    color: #333;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* 3 columns */
    gap: 15px;
    min-height: 100px;
    max-height: calc(3 * 150px + 2 * 15px); /* 3 rows: 3 items (150px each) + 2 gaps between rows (15px each) */
    overflow-y: auto;
    overflow-x: hidden;
}

.gallery-placeholder {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px;
    color: #999;
}

.gallery-placeholder .hint {
    font-size: 0.9em;
    margin-top: 10px;
    opacity: 0.7;
}

.gallery-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 2px solid transparent;
}

.gallery-item:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.gallery-item.active {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.gallery-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.gallery-item.disabled img {
    filter: grayscale(100%);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-item .remove-btn,
.book-remove-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(255, 0, 0, 0.8);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 10;
}

.gallery-item:hover .remove-btn {
    opacity: 1;
}

/* Drag and Drop */
.book-container.drag-over {
    transform: scale(1.02);
}

.book-container.drag-over .page {
    border-color: #667eea;
    box-shadow: 0 0 20px rgba(102, 126, 234, 0.5);
}

/* Upload Overlay */
.upload-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    backdrop-filter: blur(4px);
}

.upload-overlay-content {
    background: white;
    border-radius: 16px;
    padding: 40px 60px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    min-width: 300px;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.upload-progress-text {
    font-size: 1.2em;
    font-weight: 600;
    color: #333;
    margin-bottom: 10px;
}

.upload-progress-count {
    font-size: 1em;
    color: #666;
}
