* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: black;
    color: white;
    font-family: sans-serif;
}

#formatting-toolbar {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(34, 34, 34, 0.9);
    padding: 8px 15px;
    border-radius: 30px;
    border: 1px solid #444;
    display: flex;
    align-items: center;
    gap: 5px;
    z-index: 600;
    transition: opacity 0.5s, transform 0.5s;
}

.toolbar-separator {
    width: 1px;
    height: 24px;
    background: #444;
    margin: 0 10px;
}

#formatting-toolbar.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(-20px);
    pointer-events: none;
}

#formatting-toolbar button {
    background: transparent;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.2s;
}

#formatting-toolbar button:hover {
    background: #444;
}

#dictation-btn.recording {
    background: rgba(255, 68, 68, 0.4);
    box-shadow: 0 0 15px rgba(255, 68, 68, 0.6);
    animation: pulse-red 1.5s infinite;
}

@keyframes pulse-red {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); background: rgba(255, 68, 68, 0.6); }
    100% { transform: scale(1); }
}

.color-picker-container {
    display: flex;
    align-items: center;
    position: relative;
}

#color-picker {
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    margin-left: -5px;
}

#color-picker::-webkit-color-swatch-wrapper {
    padding: 0;
}

#color-picker::-webkit-color-swatch {
    border: 1px solid #666;
    border-radius: 50%;
}

#editor-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    background-color: #000;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

#book-wrapper {
    position: relative;
    width: 1250px;
    height: 900px;
}

#book-image {
    width: 100%;
    height: 100%;
    display: block;
}

.nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 60px;
    height: 60px;
    background: rgba(34, 34, 34, 0.7);
    color: #f5deb3;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 40px;
    z-index: 100;
    transition: opacity 0.3s, background 0.2s, transform 0.2s;
    user-select: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.nav-arrow:hover {
    background: rgba(34, 34, 34, 0.9);
    transform: translateY(-50%) scale(1.1);
}

.nav-arrow.hidden {
    opacity: 0;
    pointer-events: none;
}

#nav-arrow-left {
    left: -80px;
}

#nav-arrow-right {
    right: -100px;
}

#book-cover {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 600px; /* One side of the book size approximately */
    height: 850px;
    background-color: #8b4513;
    border-radius: 5px 15px 15px 5px;
    box-shadow: 10px 10px 30px rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
    z-index: 10;
    border-left: 10px solid rgba(0,0,0,0.2);
    overflow: hidden;
}

#book-cover-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    z-index: 15;
}

#book-cover::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, 
        rgba(255,255,255,0.1) 0%, 
        rgba(255,255,255,0.05) 50%, 
        rgba(0,0,0,0.1) 100%);
    pointer-events: none;
}

#cover-title-display {
    font-family: 'Times New Roman', serif;
    font-size: 3rem;
    font-weight: bold;
    text-align: center;
    color: white;
    text-transform: uppercase;
    letter-spacing: 2px;
    word-wrap: break-word;
    max-width: 100%;
    position: relative;
    z-index: 20;
}

#cover-customizer {
    position: fixed;
    right: 50px;
    bottom: 50px;
    background: rgba(34, 34, 34, 0.9);
    padding: 25px;
    border-radius: 10px;
    border: 1px solid #444;
    z-index: 1000;
    width: 250px;
    color: white;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
}

#cover-customizer h3 {
    margin-bottom: 20px;
    text-align: center;
    color: #f5deb3;
}

#cover-customizer .menu-section {
    margin-bottom: 15px;
}

#cover-customizer button {
    width: 100%;
    padding: 10px;
    background: #4b2c20;
    color: #f5deb3;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    margin-top: 10px;
}

.page {
    position: absolute;
    top: 50px; /* Adjust based on book image design */
    width: 500px; /* Adjust based on book image design */
    height: 750px; /* Adjust based on book image design */
    display: flex;
    flex-direction: column;
}

.left-page {
    left: 80px; /* Adjust based on book image design */
}

.right-page {
    right: 80px; /* Adjust based on book image design */
}

.editable-page {
    flex-grow: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #333; /* Book pages are usually light, so dark text */
    font-size: 18px;
    line-height: 1.5;
    padding: 20px;
    font-family: 'Courier New', Courier, monospace;
    overflow-y: auto;
    white-space: normal;
    word-wrap: break-word;
}

.editable-page h1 {
    font-size: 2.2rem;
    margin-bottom: 1rem;
    color: #000;
}

.editable-page h2 {
    font-size: 1.6rem;
    margin-bottom: 0.8rem;
    color: #222;
}

.editable-page p {
    margin-bottom: 1rem;
    white-space: pre-wrap;
}

.editable-page iframe {
    max-width: 100%;
    height: auto;
    aspect-ratio: 16/9;
    border: 2px solid #8b4513;
    border-radius: 4px;
    margin: 10px 0;
}

.editable-page a {
    text-decoration: underline;
    cursor: pointer;
}

/* Side Index Styles */
#side-index {
    position: fixed;
    top: 50%;
    left: 20px;
    transform: translateY(-50%);
    width: 220px;
    max-height: 80%;
    background: rgba(34, 34, 34, 0.9);
    padding: 20px;
    border-radius: 10px;
    border: 1px solid #444;
    z-index: 1000;
    color: #f5deb3;
    overflow-y: auto;
    transition: opacity 0.5s, transform 0.5s;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
}

#side-index.hidden {
    opacity: 0;
    transform: translateY(-50%) translateX(-20px);
    pointer-events: none;
}

#side-index h3 {
    text-align: center;
    margin-bottom: 15px;
    border-bottom: 1px solid #555;
    padding-bottom: 10px;
    font-family: 'Times New Roman', serif;
}

.index-item {
    cursor: pointer;
    padding: 5px 0;
    font-size: 14px;
    transition: color 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.index-item:hover {
    color: white;
}

.index-h1 {
    font-weight: bold;
}

.index-h2 {
    padding-left: 15px;
    font-size: 13px;
    font-style: italic;
}

.page-number {
    text-align: center;
    color: #555;
    font-size: 14px;
    padding-bottom: 10px;
    pointer-events: none;
}

#zen-btn {
    font-size: 1.4rem;
    color: #f5deb3;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, opacity 0.2s;
}

#zen-btn:hover {
    transform: scale(1.1);
    opacity: 0.8;
}

/* Menu Styles */
#menu-overlay, .overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 5000; /* Higher than everything including library */
}

#library-customize-modal {
    background: transparent;
    pointer-events: none;
    align-items: flex-end;
    justify-content: flex-start;
    padding: 30px;
}

#library-customize-modal .modal-content {
    pointer-events: auto;
    margin-bottom: 20px;
    margin-left: 20px;
}

.modal-content {
    background: rgba(34, 34, 34, 0.95);
    padding: 30px;
    border-radius: 10px;
    border: 1px solid #444;
    min-width: 350px;
    max-width: 500px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    color: white;
}

.modal-content h2 {
    color: #f5deb3;
    text-align: center;
    margin-bottom: 25px;
    font-family: 'Times New Roman', serif;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.hidden {
    display: none !important;
}

.button-row {
    display: flex;
    gap: 10px;
}

.button-row button {
    flex: 1;
}

/* Library View Styles */
#library-view {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #2b1d0e; /* Fallback color */
    z-index: 3000; /* Above editor, below modals */
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.library-container {
    width: 1920px;
    height: 1080px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    flex-shrink: 0;
}

#library-music-ui {
    position: fixed;
    top: 24px;
    left: 24px;
    z-index: 4500; /* Higher than controls (4000) and library-view (3000) */
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

#library-music-btn {
    width: 56px;
    height: 56px;
    border: 1px solid #444;
    border-radius: 50%;
    background: rgba(34, 34, 34, 0.92);
    color: #f5deb3;
    font-size: 1.7rem;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.45);
    transition: transform 0.15s, background 0.2s, box-shadow 0.2s;
}

#library-music-btn:hover {
    background: rgba(60, 47, 36, 0.96);
    transform: scale(1.05);
}

#library-music-btn.playing {
    background: rgba(83, 193, 98, 0.2);
    border-color: rgba(83, 193, 98, 0.7);
    box-shadow: 0 0 16px rgba(83, 193, 98, 0.35);
}

#library-music-panel {
    width: 340px;
    background: rgba(34, 34, 34, 0.96);
    border: 1px solid #444;
    border-radius: 18px;
    padding: 18px;
    color: #f5deb3;
    box-shadow: 0 10px 30px rgba(0,0,0,0.45);
}

/* Global Timer Styles */
#global-timer-btn {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 4500;
    width: 56px;
    height: 56px;
    border: 1px solid #444;
    border-radius: 50%;
    background: rgba(34, 34, 34, 0.92);
    color: #f5deb3;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.45);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

#global-timer-btn:hover {
    background: rgba(60, 47, 36, 0.96);
    transform: scale(1.05);
}

#global-timer-btn.active {
    border-color: #f5deb3;
    box-shadow: 0 0 15px rgba(245, 222, 179, 0.3);
}

#timer-display {
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.2rem;
    font-weight: bold;
    color: #f5deb3;
}

#timer-display.hidden {
    display: none;
}

/* Book Tabs Styles */
#book-tabs-container {
    position: absolute;
    right: -40px; /* Positioned outside the book wrapper */
    top: 50px;
    height: 800px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    pointer-events: none; /* Allow clicks through to the book except on tabs */
    z-index: 5;
    opacity: 0;
    transition: opacity 0.3s;
}

#tabs-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    pointer-events: auto;
}

.book-tab {
    position: relative;
    width: 40px;
    height: 100px; /* Increased by 25% from 80px */
    background-color: #c79a63; /* Fallback and base color */
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    color: white;
    font-size: 12px;
    font-weight: bold;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.3);
    transition: transform 0.2s, width 0.2s;
    user-select: none;
    border: 1px solid black;
    border-left: none;
}

.book-tab.gradient {
    background-image: linear-gradient(to right, rgba(0,0,0,0.2), transparent 30%), 
                      linear-gradient(to bottom, rgba(255,255,255,0.2), transparent 50%, rgba(0,0,0,0.3));
}



.book-tab .delete-tab-x {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4444;
    color: white;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    opacity: 0;
    transition: opacity 0.2s;
}

.book-tab:hover .delete-tab-x {
    opacity: 1;
}

.book-tab.dragging {
    opacity: 0.5;
    transform: scale(1.05);
}

.book-tab.drag-over {
    border-top: 3px solid #f5deb3;
    transform: translateY(3px);
}

#add-tab-btn {
    width: 40px;
    height: 40px;
    background: rgba(34, 34, 34, 0.8);
    color: #f5deb3;
    border: 1px solid #444;
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    margin-top: 10px;
    transition: background 0.2s, width 0.2s;
}

#add-tab-btn:hover {
    background: rgba(60, 47, 36, 0.9);
    width: 50px;
}

#library-music-panel h3 {
    margin-bottom: 14px;
    font-family: 'Times New Roman', serif;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#library-music-panel label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.music-track-display {
    margin-bottom: 14px;
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
}

.music-track-label {
    margin-bottom: 8px;
    font-size: 0.76rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #c79a63;
}

#music-title-marquee {
    --music-title-start: 0px;
    --music-title-distance: 0px;
    --music-title-duration: 12s;
    overflow: hidden;
    white-space: nowrap;
}

#music-current-title {
    display: inline-block;
    max-width: 100%;
    color: white;
    font-size: 0.95rem;
    white-space: nowrap;
}

#music-title-marquee.scrolling #music-current-title {
    padding-left: var(--music-title-start);
    animation: music-title-scroll var(--music-title-duration) linear infinite;
}

@keyframes music-title-scroll {
    from {
        transform: translateX(0);
    }
    to {
        transform: translateX(calc(-1 * var(--music-title-distance)));
    }
}

#music-playlist-url {
    flex: 1;
    background: #2f2f2f;
    color: white;
    border: 1px solid #555;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 0.9rem;
}

.music-input-row {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
}

#favorite-music-btn {
    background: #2f2f2f;
    color: #888;
    border: 1px solid #555;
    border-radius: 8px;
    width: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: transform 0.15s, background 0.2s, color 0.2s, border-color 0.2s;
}

#favorite-music-btn.is-favorite {
    background: #4b2c20;
    color: #ffd700; /* Gold for favorite */
    border-color: #ffd700;
}

#favorite-music-btn:hover {
    background: #3f3f3f;
    transform: scale(1.05);
}

#favorite-music-btn.is-favorite:hover {
    background: #5a3d2b;
}

.music-favorites-list {
    margin-bottom: 14px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 8px;
    max-height: 150px;
    overflow-y: auto;
}

.favorites-header {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #c79a63;
    margin-bottom: 6px;
    letter-spacing: 0.5px;
    font-weight: bold;
}

.favorite-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    margin-bottom: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.favorite-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.favorite-title {
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    margin-right: 10px;
}

.delete-favorite-btn {
    background: transparent;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 2px 5px;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.edit-favorite-btn {
    background: transparent;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 2px 5px;
    font-size: 0.8rem;
    transition: color 0.2s;
}

.edit-favorite-btn:hover {
    color: #f5deb3;
}

.delete-favorite-btn:hover {
    color: #ff4444;
}

.favorite-actions {
    display: flex;
    gap: 4px;
}

.music-player-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
    align-items: center;
}

.music-player-buttons button {
    flex: 1 1 0;
    min-width: 0;
    padding: 10px 0;
    background: #4b2c20;
    color: #f5deb3;
    border: 1px solid #5a3d2b;
    border-radius: 20px;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
}

.music-player-buttons button:hover {
    background: #5a3d2b;
}

#music-toggle-btn {
    flex: 1.35 1 0;
    font-size: 1.25rem;
}

.music-volume-row {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 12px;
}

.music-volume-row label {
    margin: 0;
    min-width: 52px;
}

#music-volume {
    flex: 1;
    accent-color: #c79a63;
}

#music-status {
    color: #d7d7d7;
    font-size: 0.88rem;
    line-height: 1.4;
}

#youtube-player-host {
    position: fixed;
    top: -9999px;
    left: -9999px;
    width: 240px;
    height: 240px;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
}



.book-spine {
    width: 55px;
    height: 220px;
    border-radius: 4px 4px 0 0;
    cursor: pointer;
    position: absolute; /* Detached positioning */
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 3px -3px 8px rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    border-left: 2px solid rgba(255,255,255,0.1);
    border-right: 2px solid rgba(0,0,0,0.2);
    touch-action: none;
    z-index: 30;
}

#library-view.customize-mode .book-spine {
    cursor: grab;
}

#library-view.customize-mode .book-spine.dragging {
    cursor: grabbing;
    z-index: 100;
}

.rotate-book-btn {
    position: absolute;
    top: -12px;
    left: -12px;
    background: rgba(34, 34, 34, 0.9);
    color: #f5deb3;
    border: 1px solid #444;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 16px;
    cursor: pointer;
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 40;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    transition: background 0.2s, transform 0.2s;
}

#library-view.customize-mode .book-spine:hover .rotate-book-btn {
    display: flex;
}

.rotate-book-btn:hover {
    background: #4b2c20;
    transform: scale(1.1);
}

.book-spine::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, 
        rgba(0,0,0,0.3) 0%, 
        rgba(255,255,255,0.1) 20%, 
        rgba(255,255,255,0.1) 80%, 
        rgba(0,0,0,0.3) 100%);
    pointer-events: none;
    border-radius: inherit;
}

.book-spine.no-gradient::after {
    display: none;
}

.book-spine:hover {
    /* Handled dynamically in script.js to support scaling */
}



.book-title-side {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    font-family: 'Times New Roman', serif;
    font-size: 15px; /* Increased from 14px (approx 1pt bigger) */
    font-weight: bold;
    padding: 10px 0;
    text-align: center;
    pointer-events: none;
    max-height: 200px; /* Increased from 160px to match larger spine */
    overflow: hidden;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8); /* Added shadow for better readability */
    letter-spacing: 0.5px;
}

.delete-book-btn {
    position: absolute;
    top: 8px; 
    right: 8px; /* Adjusted for wider spine */
    background: rgba(85, 85, 85, 0.9);
    color: #ccc;
    border: none;
    border-radius: 50%;
    width: 24px; /* Slightly larger for easier clicking */
    height: 24px;
    font-size: 16px;
    cursor: pointer;
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    transition: background 0.2s, color 0.2s;
}

.delete-book-btn:hover {
    background: rgba(255, 68, 68, 0.9);
    color: white;
}

.book-spine:hover .delete-book-btn {
    display: flex;
}

.library-controls {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(34, 34, 34, 0.9);
    padding: 10px 25px;
    border-radius: 35px;
    border: 1px solid #444;
    display: flex;
    gap: 20px;
    z-index: 4000; /* Higher than library-view (3000) */
    transition: opacity 0.5s, transform 0.5s;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
}

.library-controls.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
    pointer-events: none;
}

.library-controls button {
    padding: 10px 20px;
    background: transparent;
    color: #f5deb3;
    border: none;
    border-radius: 20px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    white-space: nowrap;
}

.library-controls button:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.05);
}

#lib-fullscreen-btn {
    font-size: 1.2rem;
    padding: 10px 15px !important;
}

.small-btn {
    padding: 5px 10px !important;
    font-size: 0.8rem !important;
    width: auto !important;
    margin-left: 5px;
}

#library-customize-modal h2 {
    /* Already handled by .modal-content h2 */
}

.menu-section {
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.menu-section label {
    margin-right: 15px;
    color: #f5deb3;
    font-size: 0.95rem;
}

.divider {
    border-top: 1px solid #444;
    padding-top: 15px !important;
    margin-top: 15px !important;
}

.menu-section select, .menu-section input:not([type="checkbox"]), .menu-section input[type="number"] {
    background: #333;
    color: white;
    border: 1px solid #555;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 0.9rem;
}

.menu-section input[type="number"] {
    width: 70px;
}

.menu-section select {
    width: 170px;
}

.menu-section input[type="text"] {
    flex: 1;
    min-width: 0;
}

.menu-section button {
    padding: 8px 15px;
    background: #4b2c20;
    color: #f5deb3;
    border: 1px solid #5a3d2b;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s, transform 0.1s;
}

.menu-section button:hover {
    background: #5a3d2b;
    transform: scale(1.05);
}

.toggle-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    width: 52px;
    height: 30px;
    cursor: pointer;
}

.toggle-switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: relative;
    width: 100%;
    height: 100%;
    background: #555;
    border: 1px solid #777;
    border-radius: 999px;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
    transition: transform 0.2s ease;
}

.toggle-switch input:checked + .toggle-slider {
    background: #3fa34d;
    border-color: #53c162;
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(22px);
}

.toggle-switch input:focus-visible + .toggle-slider {
    box-shadow: 0 0 0 3px rgba(83, 193, 98, 0.25);
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
}

.menu-buttons button {
    padding: 10px;
    background: #4b2c20;
    color: #f5deb3;
    border: 1px solid #5a3d2b;
    cursor: pointer;
    border-radius: 5px;
    transition: background 0.2s, transform 0.1s;
}

.menu-buttons button:hover {
    background: #5a3d2b;
    transform: scale(1.05);
}

.secondary-btn {
    background: #333 !important;
    border: 1px solid #444 !important;
}

.secondary-btn:hover {
    background: #444 !important;
}

/* Image Picker Styles */
.picker-modal-large {
    width: 900px !important;
    height: 800px !important;
    max-width: 95vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.picker-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 1px solid #444;
    padding-bottom: 10px;
    justify-content: center;
    flex-shrink: 0;
}

.tab-btn {
    background: transparent;
    border: none;
    color: #888;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 0.95rem;
    transition: color 0.2s, border-bottom 0.2s;
    border-bottom: 2px solid transparent;
}

.tab-btn:hover {
    color: #f5deb3;
}

.tab-btn.active {
    color: #f5deb3;
    border-bottom: 2px solid #f5deb3;
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 15px;
    max-height: 400px;
    overflow-y: auto;
    padding: 10px;
    background: #111;
    border-radius: 5px;
    margin: 15px 0;
}

.grid-large {
    grid-template-columns: repeat(auto-fill, 160px) !important;
    justify-content: center;
    max-height: none !important;
    flex: 1;
    overflow-y: auto;
    border: 1px solid #333;
    gap: 20px !important;
}

.image-option {
    cursor: pointer;
    border: 2px solid #333;
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    width: 160px;
    height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #222;
    position: relative;
    box-sizing: border-box;
}

.image-option img,
.image-option video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 10px;
    box-sizing: border-box;
    pointer-events: none; /* Crucial: Prevent flickering */
}

.image-option:hover {
    transform: scale(1.05);
    border-color: #f5deb3;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
}

.image-option.selected {
    border-color: #3fa34d;
    box-shadow: 0 0 10px rgba(63, 163, 77, 0.5);
}

.delete-asset-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(255, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    z-index: 10;
}

.image-option:hover .delete-asset-btn {
    opacity: 1;
}

.delete-asset-btn:hover {
    background: rgba(255, 0, 0, 1);
}

/* Ornament Styles */
.ornament {
    position: absolute;
    cursor: default;
    user-select: none;
    touch-action: none;
    transition: transform 0.2s;
    z-index: 5;
}

.ornament img,
.ornament video {
    width: 100%; /* Fill container */
    height: 100%; /* Fill container */
    display: block;
    pointer-events: none;
    object-fit: contain; /* Keep aspect ratio */
}

/* Setup Modal Styles */
.setup-modal {
    max-width: 550px;
    padding: 35px 40px;
}

.setup-modal h2 {
    color: #f5deb3;
    margin-bottom: 10px;
    text-align: center;
    font-size: 2rem;
}

.setup-intro {
    text-align: center;
    color: #ccc;
    margin-bottom: 30px;
    font-size: 1.1rem;
}

.setup-step {
    display: flex;
    gap: 20px;
    margin-bottom: 30px;
    padding: 20px;
    background: rgba(51, 51, 51, 0.5);
    border-radius: 12px;
    border: 1px solid #444;
}

.setup-step-number {
    width: 45px;
    height: 45px;
    background: linear-gradient(135deg, #8b4513, #a0522d);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(139, 69, 19, 0.4);
}

.setup-step-content {
    flex-grow: 1;
}

.setup-step-content label {
    display: block;
    margin-bottom: 12px;
    color: #f5deb3;
    font-size: 1.1rem;
    font-weight: 500;
}

.setup-hint {
    color: #999;
    font-size: 0.95rem;
    margin-bottom: 15px;
    font-style: italic;
}

.autosave-file-display {
    margin-left: 15px;
    color: #90ee90;
    font-size: 0.95rem;
    display: none;
}

.setup-step-content button {
    padding: 8px 15px;
    background: #4b2c20;
    color: #f5deb3;
    border: 1px solid #5a3d2b;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s, transform 0.1s;
}

.setup-step-content button:hover {
    background: #5a3d2b;
    transform: scale(1.05);
}

#library-view.customize-mode .ornament {
    cursor: grab;
    border: 2px solid rgba(255, 255, 0, 0.6); /* Snug yellow outline */
    box-sizing: border-box;
}

#library-view.customize-mode .ornament.dragging {
    cursor: grabbing;
    z-index: 100;
    border-color: rgba(255, 255, 0, 1);
    box-shadow: 0 0 10px rgba(255, 255, 0, 0.5);
}

.resize-handle {
    position: absolute;
    bottom: -5px;
    right: -5px;
    width: 15px;
    height: 15px;
    background: #f5deb3;
    border-radius: 50%;
    cursor: nwse-resize;
    display: none;
    z-index: 20;
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
}

#library-view.customize-mode .ornament:hover .resize-handle {
    display: block;
}

.delete-ornament-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    background: rgba(85, 85, 85, 0.9);
    color: #ccc;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 14px;
    cursor: pointer;
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

#library-view.customize-mode .ornament:hover .delete-ornament-btn {
    display: flex;
}

.rotate-ornament-btn {
    position: absolute;
    top: -10px;
    left: -10px;
    background: rgba(34, 34, 34, 0.9);
    color: #f5deb3;
    border: 1px solid #444;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    cursor: pointer;
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    transition: background 0.2s, transform 0.2s;
}

#library-view.customize-mode .ornament:hover .rotate-ornament-btn {
    display: flex;
}

.rotate-ornament-btn:hover {
    background: #4b2c20;
    transform: scale(1.1);
}

.delete-ornament-btn:hover {
    background: rgba(255, 68, 68, 0.9);
    color: white;
}

/* Litter Basket Styles */
.litter-grid {
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 10px;
    margin-bottom: 20px;
}

.litter-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid #444;
    border-radius: 8px;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    transition: background 0.3s;
}

.litter-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.litter-info {
    flex: 1;
    min-width: 0;
}

.litter-info h4 {
    margin: 0 0 5px 0;
    color: #f5deb3;
}

.litter-info small {
    color: #888;
    display: block;
    margin-bottom: 8px;
}

.litter-preview {
    font-size: 14px;
    color: #ccc;
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
}

.litter-actions {
    display: flex;
    gap: 10px;
}

.litter-actions button {
    padding: 8px 12px;
    font-size: 13px;
}

.litter-actions .delete-btn {
    background: #ff5a5a;
    color: white;
}

.litter-actions .delete-btn:hover {
    background: #ff4444;
}

.empty-basket-msg {
    text-align: center;
    color: #888;
    padding: 40px;
    font-style: italic;
}

#excerpt-label {
    width: 100%;
    padding: 12px;
    background: #333;
    border: 1px solid #444;
    border-radius: 5px;
    color: white;
    margin-top: 10px;
    font-size: 16px; /* Slightly larger text */
}

.wide-input {
    min-width: 400px; /* Ensure field is wide enough */
}

#excerpt-label:focus {
    outline: none;
    border-color: #f5deb3;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}
