/* ===========================================
   BOOK PAGE FLIP SYSTEM
   Clean, simple implementation
   =========================================== */

/* Book dimensions - letter paper ratio (8.5x11 = 1:1.294) */
/* Height based on viewport, width calculated from ratio */
:root {
    --page-height: 75vh;
    --page-width: calc(var(--page-height) / 1.294);
}

/* The book container - centered, uses viewport height */
.book {
    position: relative;
    width: calc(var(--page-width) * 2);
    height: var(--page-height);
    min-height: 500px;
    max-height: calc(100vh - 180px);
    perspective: 2000px;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateX(0);
}

/* When cover is showing, book is single-page width and shifted right to stay centered */
.book.show-cover {
    width: var(--page-width);
    transform: translateX(calc(var(--page-width) / 2));
}

/* Initial state - no transition on first load */
.book.show-cover:not(.has-opened) {
    transition: none;
}

/* Transitioning state - smooth shift during open/close */
.book.transitioning {
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Container for all pages */
.pages-container {
    position: absolute;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
}

/* ===========================================
   COVER - Two-sided page that flips open
   =========================================== */
.page-cover {
    position: absolute;
    width: var(--page-width);
    height: 100%;
    left: 0;
    transform-origin: left center;
    transform-style: preserve-3d;
    transition: transform 0.8s ease-in-out;
    z-index: 100;
    cursor: pointer;
}

/* When book is open, cover sits at spine (center) */
.book:not(.show-cover) .page-cover {
    left: var(--page-width);
}

/* Cover opened - flipped to left side */
.page-cover.opened {
    transform: rotateY(-180deg);
    z-index: 1;
}

/* Cover faces */
.cover-front,
.cover-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    background: white;
    overflow: hidden;
}

/* Front of cover */
.cover-front {
    border-radius: 0 8px 8px 0;
    box-shadow: 2px 0 10px rgba(0,0,0,0.15);
}

/* Back of cover (Page 2) - rotated to show when flipped */
.cover-back {
    transform: rotateY(180deg);
    border-radius: 8px 0 0 8px;
    box-shadow: -2px 0 10px rgba(0,0,0,0.1);
}

/* ===========================================
   LEFT PAGE - Static base page (visible when open)
   =========================================== */
.page-left {
    position: absolute;
    left: 0;
    width: var(--page-width);
    height: 100%;
    background: white;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 8px 0 0 8px;
    box-shadow: -2px 0 10px rgba(0,0,0,0.1);
}

/* page-left is hidden via the combined rule above when cover is closed */

/* ===========================================
   BOOK SHEETS - Flippable pages after cover
   =========================================== */
.book-sheet {
    position: absolute;
    width: var(--page-width);
    height: 100%;
    left: var(--page-width);
    transform-origin: left center;
    transform-style: preserve-3d;
    transition: transform 0.8s ease-in-out;
}

/* Hide sheets and left page when cover is closed */
.book.show-cover .book-sheet,
.book.show-cover .page-left {
    display: none !important;
    visibility: hidden !important;
}

/* Stack sheets with z-index */
.book-sheet:nth-child(3) { z-index: 5; }
.book-sheet:nth-child(4) { z-index: 4; }
.book-sheet:nth-child(5) { z-index: 3; }
.book-sheet:nth-child(6) { z-index: 2; }
.book-sheet:nth-child(7) { z-index: 1; }

/* Flipped state */
.book-sheet.flipped {
    transform: rotateY(-180deg);
    z-index: 1;
}

/* Sheet faces */
.sheet-front,
.sheet-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    background: white;
    overflow: hidden;
}

.sheet-front {
    border-radius: 0 8px 8px 0;
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
}

.sheet-back {
    transform: rotateY(180deg);
    border-radius: 8px 0 0 8px;
    box-shadow: -2px 0 10px rgba(0,0,0,0.1);
}

/* ===========================================
   PAGE HEADERS
   =========================================== */
.page-header {
    height: 32px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.page-header span {
    font-size: 10px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===========================================
   PAGE CONTENT
   =========================================== */
.page-content {
    flex: 1;
    overflow: hidden;
    background: white;
    position: relative;
}

.newsletter-content {
    min-height: 100%;
    padding: 0.75rem;
}

/* ===========================================
   EMPTY PAGE STATE
   =========================================== */
.empty-canvas {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    text-align: center;
    color: #64748b;
}

.empty-canvas.hidden {
    display: none;
}

.empty-canvas .empty-icon {
    width: 48px;
    height: 48px;
    margin-bottom: 0.75rem;
    color: #94a3b8;
}

.empty-canvas h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #334155;
    margin-bottom: 0.25rem;
}

.empty-canvas p {
    font-size: 0.75rem;
    margin-bottom: 0.75rem;
}

.quick-start-buttons {
    display: flex;
    gap: 0.5rem;
}

.quick-start-btn {
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    background: #6366F1;
    color: white;
}

.quick-start-btn:hover {
    background: #4F46E5;
}

.quick-start-btn.secondary {
    background: white;
    color: #334155;
    border: 1px solid #e2e8f0;
}

.quick-start-btn.secondary:hover {
    background: #f8fafc;
}

/* ===========================================
   EDITING STATE
   =========================================== */
.cover-front.editing,
.cover-back.editing,
.sheet-front.editing,
.sheet-back.editing,
.page-left.editing {
    outline: 3px solid #6366F1;
    outline-offset: -3px;
}

/* ===========================================
   BOOK SPINE
   =========================================== */
.book-spine {
    position: absolute;
    left: var(--page-width);
    transform: translateX(-50%);
    width: 4px;
    height: 100%;
    background: linear-gradient(90deg,
        rgba(0,0,0,0.1) 0%,
        rgba(0,0,0,0.02) 50%,
        rgba(0,0,0,0.1) 100%);
    z-index: 200;
}

.book.show-cover .book-spine {
    display: none;
}

/* ===========================================
   BOOK SHADOW
   =========================================== */
.book::after {
    content: '';
    position: absolute;
    bottom: -15px;
    left: 5%;
    right: 5%;
    height: 15px;
    background: radial-gradient(ellipse at center, rgba(0,0,0,0.2) 0%, transparent 70%);
    z-index: -1;
}
