:root {
    --color-cream: #fbf7f2;
    --color-paper: #fffdf9;
    --color-sage: #bef2c5;
    --color-rose: #f8d2d4;
    --color-amber: #febc93;
    --color-lavender: #e8dff4;
    --color-butter: #fcf191;
    
    --wood-dark: #3d2314;
    --wood-mid: #613b24;
    --wood-shelf: #ab734e;
}

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

body {
    font-family: 'Quicksand', sans-serif;
    background-color: #d6dfeb;
    color: var(--wood-dark);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    overflow-x: auto;        /* CHANGED: Allows horizontal scrolling on smaller screens instead of clipping */
    min-width: 1020px;       /* ADDED: Ensures enough breathing room around the 980px book */
}

.hidden {
    display: none !important;
}

/* --- Header --- */
.header-container {
    width: 980px;
    min-width: 980px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    background: #edf2ee;
    padding: 12px 20px;
    border-radius: 14px;
    border: 2px solid var(--wood-dark);
    box-shadow: 0 4px 12px rgba(61, 35, 20, 0.08);
}

.scrapbook-title-area {
    font-weight: 700;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.scrapbook-title-area:hover {
    background-color: var(--color-butter);
    color: var(--wood-dark);
}

.header-tools {
    display: flex;
    gap: 8px;
}

.toolbox-btn {
    font-family: 'Quicksand', sans-serif;
    font-weight: 700;
    font-size: 0.85rem;
    background: #ffeee4;
    border: 1.5px solid var(--wood-dark);
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.toolbox-btn:hover { background-color: var(--color-amber); transform: translateY(-2px); }

.action-btns {
    display: flex;
    gap: 10px;
}

.btn {
    font-family: 'Quicksand', sans-serif;
    font-weight: 700;
    font-size: 0.9rem;
    padding: 6px 14px;
    border-radius: 8px;
    border: 2px solid var(--wood-dark);
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-primary { background-color: var(--color-amber); color: var(--wood-dark); }
.btn-primary:hover { background-color: #f7a876; transform: translateY(-2px); }

.btn-secondary { background-color: var(--color-lavender); color: var(--wood-dark); }
.btn-secondary:hover { background-color: #d6c3eb; transform: translateY(-2px); }

.btn-text-danger {
    background: none;
    border: none;
    color: #b33939;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    text-decoration: underline;
}

/* --- Book Container & Spread --- */
.scrapbook-container {
    position: relative;
    width: 980px;
    min-width: 980px;
    height: 520px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.book-spread {
    width: 980px;
    min-width: 980px;
    height: 100%;
    background: var(--color-paper);
    border: 4px solid var(--wood-dark);
    border-radius: 12px;
    display: flex;
    position: relative;
    box-shadow: 0 16px 40px rgba(61, 35, 20, 0.25);
    overflow: hidden;
}

.book-binding {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 24px;
    transform: translateX(-50%);
    background: linear-gradient(to right, rgba(0,0,0,0.05), rgba(61,35,20,0.12), rgba(0,0,0,0.05));
    z-index: 50;
    pointer-events: none;
    border-left: 1px solid rgba(61,35,20,0.15);
    border-right: 1px solid rgba(61,35,20,0.15);
}

.scrapbook-page {
    width: 490px;
    min-width: 490px;
    height: 100%;
    position: relative;
    padding: 30px;
    overflow: hidden;
    background: radial-gradient(circle at center, #fffdf9 0%, #f7f1e5 100%);
}

.left-page {
    border-right: 2px dashed #ebdcd0;
}

.page-date-stamp {
    font-family: 'Caveat', cursive;
    font-size: 1.15rem;
    color: #7a6252;
    opacity: 0.75;
    margin-bottom: 10px;
    cursor: pointer;
    pointer-events: auto;
    transition: opacity 0.15s, color 0.15s;
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
}

.page-date-stamp:hover {
    opacity: 1;
    color: var(--wood-dark);
    background-color: var(--color-butter);
}

/* Inline title edit input box */
.page-title-input {
    font-family: 'Caveat', cursive;
    font-size: 1.15rem;
    color: var(--wood-dark);
    background: #fff;
    border: 1.5px solid var(--wood-dark);
    border-radius: 4px;
    padding: 0 4px;
    margin-bottom: 10px;
    outline: none;
    width: 140px;
}

/* Flip Page Nav Buttons */
.flip-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: #ffffff;
    border: 3px solid var(--wood-dark);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(61,35,20,0.15);
    z-index: 100;
    transition: transform 0.15s ease, background-color 0.15s;
}

.flip-btn:hover { background-color: var(--color-butter); transform: translateY(-50%) scale(1.1); }
.flip-left { left: -22px; }
.flip-right { right: -22px; }

/* --- Item Bank / Holding Tray --- */
.item-bank-container {
    width: 980px;
    min-width: 980px;
    background: #edf2ee;
    border: 2px solid var(--wood-dark);
    border-radius: 12px;
    margin-top: 14px;
    padding: 10px 16px;
    box-shadow: 0 4px 12px rgba(61,35,20,0.06);
    position: relative;
    z-index: 100;
    transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

/* Visual highlight when dragging an item over it */
.item-bank-container.bank-highlight {
    background-color: #f9f3e8;
    border: 2px dashed var(--wood-dark);
    box-shadow: 0 0 16px rgba(254, 188, 147, 0.6);
}

.bank-header {
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 6px;
    opacity: 0.8;
}

.bank-tray {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    min-height: 70px;
    padding: 4px;
    align-items: center;
}

.bank-item {
    cursor: grab;
    background: #fff;
    border: 1.5px solid var(--wood-dark);
    border-radius: 6px;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    flex-shrink: 0;
}

.bank-item img { width: 48px; height: 48px; object-fit: cover; pointer-events: none; }
.bank-item .item-sticker { font-size: 2rem; pointer-events: none; }
.bank-item .item-note-preview { font-family: 'Caveat', cursive; font-size: 1rem; max-width: 80px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding: 4px; pointer-events: none; }

/* --- Placed Items on Page --- */
.scrapbook-item {
    position: absolute;
    cursor: grab;
    pointer-events: auto;
    transition: filter 0.15s ease;
    z-index: 10;
}

.scrapbook-item:hover {
    filter: drop-shadow(0 6px 12px rgba(61,35,20,0.25));
    z-index: 60;
}

.scrapbook-item.dragging {
    cursor: grabbing;
    opacity: 0.9;
    z-index: 200;
}

.item-photo-card {
    background: #ffffff;
    padding: 6px 6px 20px 6px;
    border: 1.5px solid #d4c5b9;
    border-radius: 4px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    max-width: 160px;
}

.item-photo-card img {
    width: 120px;
    height: 120px;
    object-fit: cover;
    display: block;
    pointer-events: none;
}

.item-sticker {
    font-size: 3rem;
    filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15));
}

.item-note-card {
    background: #fff9d6;
    padding: 10px 14px;
    border: 1.5px solid #e6dc9c;
    border-radius: 6px;
    font-family: 'Caveat', cursive;
    font-size: 1.3rem;
    line-height: 1.2;
    color: var(--wood-dark);
    max-width: 180px;
    box-shadow: 2px 4px 10px rgba(0,0,0,0.08);
}

/* --- Footer & Discrete Backup Links --- */
.page-footer-info {
    width: 980px;
    min-width: 980px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    font-weight: 700;
    font-size: 0.85rem;
    padding: 0 6px;
}

.footer-backup-area {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.backup-links {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
}

.text-link-btn {
    background: none;
    border: none;
    padding: 0;
    color: var(--wood-dark);
    text-decoration: underline;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.78rem;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.text-link-btn:hover { opacity: 1; }

/* --- Modals (Toned down blur to 1px) --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(61, 35, 20, 0.4);
    backdrop-filter: blur(1px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999; /* Make sure this is higher than everything else! */
    pointer-events: auto;
}

.modal-overlay.hidden {
    display: none;
}

.modal-card {
    background: #fff8f2;
    border: 2px solid var(--wood-dark);
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 10px 30px rgba(61, 35, 20, 0.2);
    position: relative;
    z-index: 10000;
    pointer-events: auto; /* Ensure interactive elements inside work */
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    border-bottom: 2px dashed #ebdcd0;
    padding-bottom: 8px;
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--wood-dark);
}

.form-group {
    margin-bottom: 14px;
}

.form-label {
    display: block;
    font-weight: 700;
    font-size: 0.85rem;
    margin-bottom: 6px;
}

.form-input, .form-textarea {
    width: 100%;
    font-family: 'Quicksand', sans-serif;
    padding: 10px;
    border-radius: 8px;
    border: 2px solid var(--wood-dark);
    background: #fff;
    font-size: 0.95rem;
}

.form-textarea { resize: vertical; min-height: 80px; }

.emoji-picker-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    max-height: 150px;
    overflow-y: auto;
    padding: 6px;
    border: 2px solid var(--wood-dark);
    border-radius: 8px;
    background: #fdfaf6;
    text-align: center;
    font-size: 1.8rem;
}

.emoji-option {
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: background 0.15s;
}

.emoji-option:hover { background-color: var(--color-butter); }

.archive-book-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #fdfaf6;
    border: 1.5px solid #d4c5b9;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.archive-book-row:hover {
    background-color: var(--color-butter);
}

.archive-book-row.active-book {
    background-color: var(--color-lavender);
    font-weight: 700;
    border-color: var(--wood-dark);
}


/* Back Link Navigation */
.nook-nav {
    width: 980px;
    min-width: 980px;
    display: flex;
    justify-content: flex-start; /* Ensures content stays aligned to the far left */
    margin-bottom: 12px;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    background-color: #FFFEE0;
    border: 1.5px solid rgba(74, 40, 0, 0.12);
    border-radius: 14px;
    color: #4A2800;
    font-size: 0.82rem;
    font-weight: 700;
    text-decoration: none;
    box-shadow: 0 2px 0 rgba(74, 40, 0, 0.08);
    transition: transform 0.15s ease, background-color 0.15s ease;
}

.back-link:hover {
    transform: translateY(-1px);
    background-color: #FFFFFF;
}