@import url('variables.css');

/* --- MODAL STRUCTURE --- */
.builder-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--bg-paper); z-index: 9999;
    display: flex; flex-direction: column;
    opacity: 0; pointer-events: none; transition: 0.3s;
}
.builder-overlay.active { opacity: 1; pointer-events: all; }

.builder-header {
    padding: 1.5rem 2rem; display: flex; justify-content: space-between; align-items: center;
    background: white; border-bottom: 2px solid #f1f5f9;
}
.step-progress { display: flex; gap: 8px; }
.dot { width: 12px; height: 12px; background: #e2e8f0; border-radius: 50%; transition: 0.3s; }
.dot.active { background: var(--primary); transform: scale(1.2); }
.btn-close { background: none; border: none; font-size: 2rem; cursor: pointer; color: #94a3b8; line-height: 1; }

.builder-container {
    flex: 1; 
    display: flex; 
    justify-content: center; 
    /* CHANGED: Changed from 'center' to 'flex-start' to prevent top cutoff */
    align-items: flex-start; 
    padding: 2rem; 
    overflow-y: auto; 
    perspective: 1200px;
    /* ADDED: Smooth scrolling behavior */
    -webkit-overflow-scrolling: touch; 
}

.step-view { 
    max-width: 600px; 
    width: 100%; 
    text-align: center; 
    display: none; 
    animation: slideUp 0.4s ease;
    /* ADDED: Margin auto handles horizontal centering, 
       margin-top/bottom ensures space on small screens */
    margin: auto; 
}

/* ADDED: Specific mobile fix */
@media (max-width: 768px) {
    .builder-container {
        padding: 1rem;
        /* Ensure content starts below header even if keyboard opens */
        align-items: flex-start; 
    }
    
    .step-view {
        /* Add breathing room at top/bottom so it doesn't touch edges */
        /* margin-top: 10px; */
        padding-bottom: 50px; 
    }
}
.step-view.active { display: block; }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* --- INPUTS --- */
.big-input {
    width: 100%; padding: 18px; font-size: 1.2rem; text-align: center;
    border: 2px solid #e2e8f0; border-radius: var(--radius-sm); margin-bottom: 20px; outline: none; 
    font-family: var(--font-body); transition: 0.2s;
}
.big-input:focus { border-color: var(--primary); background: white; }

.option-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin: 30px 0; }
.option-card {
    background: white; padding: 20px; border-radius: var(--radius-lg);
    border: 3px solid transparent; cursor: pointer; transition: 0.2s;
    box-shadow: var(--shadow-card);
}
.option-card:hover { transform: translateY(-3px); border-color: #cbd5e1; }
.option-card.selected { border-color: var(--primary); background: #fffcf5; box-shadow: 0 0 0 3px rgba(255, 183, 3, 0.2); }
.option-icon { font-size: 2.5rem; display: block; margin-bottom: 10px; }

/* --- UPLOAD --- */
.upload-box {
    border: 3px dashed #cbd5e1; border-radius: var(--radius-lg);
    padding: 3rem 1rem; cursor: pointer; background: #f8fafc;
    transition: 0.2s; position: relative; overflow: hidden;
}
.upload-box:hover { border-color: var(--primary); background: #fffcf5; }
.preview-thumb { 
    width: 100%; height: 100%; object-fit: cover; 
    position: absolute; top: 0; left: 0; opacity: 1; z-index: 5;
}

/* ========================================= */
/*          NEW 3D BOOK PREVIEW STYLES       */
/* ========================================= */
.book-stage-3d {
    width: 100%; height: 400px;
    display: flex; justify-content: center; align-items: center;
    position: relative; margin-bottom: 0rem;
    perspective: 1500px;
}

/* Common Book properties */
.book-3d-model {
    position: relative; transition: all 0.8s cubic-bezier(0.25, 0.8, 0.25, 1);
    transform-style: preserve-3d;
}

/* STATE 1: CLOSED COVER */
.book-3d-model.closed {
    width: 280px; height: 280px;
    transform: rotateY(-35deg) rotateX(20deg); /* Adjusted angle for better 3D view */
    box-shadow: -20px 25px 40px rgba(0,0,0,0.4);
    border-radius: 2px 6px 6px 2px;
    cursor: pointer;
    background: #000; /* Dark backing for the cover board */
}
.book-3d-model.closed:hover { transform: rotateY(-30deg) rotateX(15deg) translateY(-10px); }

/* Thickness of closed book */
/* RIGHT PAGES (Thickness) */
.book-3d-model.closed::before {
    content: ''; 
    position: absolute; 
    /* Insets: This creates the "Lip" so the board hangs over the pages */
    top: 10px;
    bottom: -5px;
    right: -12px; /* Starts 2px inside the right edge */
    width: 23px; /* Thickness */
    
    /* Texture: Vertical lines (Pages) */
    background: repeating-linear-gradient(
        90deg, 
        #fdfdfd 0px, 
        #d1d1d1 1px, 
        #fdfdfd 2px
    );
    
    /* 3D Logic: Rotate it, but also push it BACK (-1px) so it sits behind the cover edge */
    transform: rotateY(90deg) translateZ(-1px);
    transform-origin: right;
    
    /* Shadow: Makes it look recessed */
    box-shadow: inset 4px 0 6px rgba(0,0,0,0.1);
}

/* BOTTOM PAGES (Thickness) */
.book-3d-model.closed::after {
    content: ''; 
    position: absolute;
    /* Insets: Keep it inside the cover boundaries */
    left: -6px;
    right: 9px;
    bottom: 3px; /* Starts 2px inside the bottom edge */
    height: 36px; /* Thickness */
    
    /* Texture: Horizontal lines (Pages) */
    background: repeating-linear-gradient(
        0deg, 
        #fdfdfd 0px, 
        #d1d1d1 1px, 
        #fdfdfd 2px
    );
    
    /* 3D Logic: Rotate, push back (-1px) to align with side pages */
    transform: rotateX(90deg) translateZ(-1px);
    transform-origin: bottom;
    
    /* Shadow */
    box-shadow: inset 0 4px 6px rgba(0,0,0,0.1);
}

/* STATE 2: OPEN SPREAD (Tilted) */
.book-3d-model.open {
    width: 600px; height: 300px;
    transform: rotateX(20deg); /* Slight tilt towards viewer */
    box-shadow: 0 30px 50px rgba(0,0,0,0.2);
    display: flex;
}
/* Center Spine Shadow */
.book-3d-model.open::after {
    content: ''; position: absolute; left: 50%; top: 0; bottom: 0; width: 40px;
    transform: translateX(-50%); z-index: 10;
    background: linear-gradient(to right, rgba(0,0,0,0.05), rgba(0,0,0,0.2), rgba(0,0,0,0.05));
    pointer-events: none;
}

/* Pages */
.page-3d { width: 100%; height: 100%; object-fit: cover; display: none; }
.book-3d-model.closed .cover-img { display: block; border-radius: 2px 5px 5px 2px; }

.page-container { flex: 1; height: 100%; position: relative; overflow: hidden; background: white; }
.book-3d-model.open .page-container { display: block; }
.book-3d-model.closed .page-container { display: none; }

.page-left { border-radius: 5px 0 0 5px; border-right: 1px solid #ddd; }
.page-right { border-radius: 0 5px 5px 0; }

/* Controls */
.preview-controls { display: flex; gap: 15px; justify-content: center; margin-top: 10px; }
.btn-round {
    width: 45px; height: 45px; border-radius: 50%; border: 1px solid #cbd5e1;
    background: white; cursor: pointer; color: var(--secondary-dark); transition: 0.2s;
}
.btn-round:hover { background: var(--primary); color: white; border-color: var(--primary); }
.btn-open-book {
    padding: 10px 25px; background: var(--secondary-dark); color: white;
    border-radius: 30px; border: none; cursor: pointer; font-weight: bold;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2); transition: 0.2s;
}
.btn-open-book:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,0.3); }

/* --- STEP 5: CONFIG & UPSELL --- */
.size-selector { display: flex; gap: 10px; margin: 20px 0; justify-content: center; }
.size-btn {
    padding: 10px 20px; border: 2px solid #e2e8f0; 
    border-radius: var(--radius-sm); cursor: pointer; background: white; font-weight: 600;
}
.size-btn.selected { background: var(--secondary-dark); color: white; border-color: var(--secondary-dark); }
.size-btn:disabled { opacity: 0.5; cursor: not-allowed; text-decoration: line-through; }

.config-container { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; text-align: left; }
.config-card {
    background: white; border: 2px solid #e2e8f0; border-radius: var(--radius-lg); 
    overflow: hidden; cursor: pointer; transition: 0.2s; position: relative;
}
.config-card:hover { transform: translateY(-3px); }
.config-card.selected { border-color: var(--primary); background: #fffcf5; box-shadow: 0 0 0 3px rgba(255, 183, 3, 0.2); }
.config-img-box { height: 140px; background: #f1f5f9; }
.config-img-box img { width: 100%; height: 100%; object-fit: cover; }
.config-details { padding: 15px; }
.config-title { font-weight: bold; display: block; margin-bottom: 5px; color: var(--secondary-dark); }
.config-desc { font-size: 0.85rem; color: var(--text-muted); line-height: 1.4; }
.config-badge { 
    position: absolute; top: 10px; right: 10px; background: var(--primary); 
    color: var(--secondary-dark); padding: 4px 10px; border-radius: 20px; font-weight: bold; font-size: 0.75rem;
}

/* --- STEP 6: UPSELL UI --- */
.upsell-modal-content {
    text-align: center; padding: 2rem 1rem;
}
.upsell-big-card {
    background: white; border: 2px solid #38bdf8; border-radius: var(--radius-lg);
    padding: 20px; margin: 30px auto; max-width: 450px;
    display: flex; gap: 20px; align-items: center; text-align: left;
    box-shadow: 0 10px 30px rgba(56, 189, 248, 0.15);
}
.upsell-img img { width: 80px; height: auto; border: 1px solid #ddd; border-radius: 5px; }
.upsell-text h3 { margin: 0 0 10px 0; color: var(--secondary-dark); }
.upsell-text ul { list-style: none; padding: 0; margin: 0; color: var(--text-muted); font-size: 0.9rem; }
.upsell-text i { color: #10b981; margin-right: 5px; }
.price-tag { 
    background: #0ea5e9; color: white; display: inline-block; 
    padding: 4px 10px; border-radius: 15px; font-weight: bold; font-size: 0.85rem; margin-top: 10px;
}
.upsell-actions { max-width: 300px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.btn-cta.full-width { width: 100%; justify-content: center; }
.btn-link { background: none; border: none; color: #94a3b8; text-decoration: underline; cursor: pointer; }

/* --- STEP 7: PAYMENT UI --- */
.checkout-grid {
    display: grid; 
    grid-template-columns: 1fr; /* CHANGED: Stacked instead of 1fr 1fr */
    gap: 30px; 
    text-align: left; 
    max-width: 500px; /* CHANGED: Narrower since it's stacked */
    margin: 0 auto;
}
.form-section h3 { border-bottom: 2px solid #f1f5f9; padding-bottom: 10px; margin-bottom: 15px; font-size: 1.1rem; }
.input-row { margin-bottom: 15px; }
.input-row.split { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.std-input {
    width: 100%; padding: 12px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 1rem;
}
.order-summary-box {
    background: #f8fafc; padding: 15px; border-radius: 8px; margin-bottom: 20px;
}
.summary-row { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 0.95rem; }
.summary-divider { height: 1px; background: #cbd5e1; margin: 10px 0; }
.summary-row.total { font-weight: bold; font-size: 1.2rem; color: var(--secondary-dark); }
#payment-element { min-height: 200px; margin-bottom: 15px; }
.error-msg { color: #ef4444; font-size: 0.9rem; background: #fee2e2; padding: 10px; border-radius: 5px; }
.hidden { display: none; }

@media (max-width: 768px) {
    .checkout-grid { grid-template-columns: 1fr; }
    .upsell-big-card { flex-direction: column; text-align: center; }
}
/* Footer */
.total-bar {
    background: var(--secondary-dark); color: white;
    padding: 20px; border-radius: var(--radius-lg); margin-top: 20px;
    display: flex; justify-content: space-between; align-items: center;
}
.total-price { font-size: 1.5rem; font-weight: bold; color: var(--primary); }
.builder-footer { padding: 1.5rem; background: white; border-top: 1px solid #f1f5f9; display: flex; justify-content: space-between; align-items: center; }

/* MEDIA */
@media (max-width: 768px) {
    .book-3d-model.open { width: 100%; height: auto; aspect-ratio: 2/1; }
    /* .book-stage-3d { height: 250px; } */
    .config-container { grid-template-columns: 1fr; }
}



/* Loading Screen Styles */
.loading-container { padding: 20px; max-width: 400px; margin: 0 auto; }
.loading-icons-wrapper { height: 60px; margin-bottom: 20px; animation: bounce 2s infinite; }

.progress-track {
    width: 100%; height: 10px; background: #e2e8f0; border-radius: 10px;
    margin: 20px 0 10px 0; overflow: hidden; position: relative;
}
.progress-fill {
    height: 100%; width: 0%; background: var(--primary);
    border-radius: 10px; transition: width 0.5s ease;
}
.progress-text { font-size: 0.85rem; color: #94a3b8; font-style: italic; }

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}



/* --- UPLOAD LAYOUT --- */
.upload-layout {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 30px;
    margin-top: 20px;
}

/* Make Upload Box Square */
.upload-box.square {
    width: 260px;
    height: 260px;
    padding: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    aspect-ratio: 1/1;
}

/* Instructions Panel */
.photo-instructions {
    flex: 1;
    min-width: 250px;
    max-width: 300px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-lg);
    padding: 20px;
    text-align: left;
}

.photo-instructions h3 { margin-top: 0; font-size: 1rem; color: var(--secondary-dark); }
.photo-instructions ul { list-style: none; padding: 0; margin: 15px 0; font-size: 0.9rem; color: var(--text-muted); }
.photo-instructions li { margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }

.circle-icon { width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.7rem; color: white; }
.circle-icon.success { background: #10b981; }
.circle-icon.danger { background: #ef4444; }

/* Example Thumbnails */
.example-grid { display: flex; gap: 10px; margin-top: 15px; }
.ex-item { text-align: center; font-size: 0.75rem; color: #64748b; }
.ex-item img { width: 60px; height: 60px; border-radius: 8px; object-fit: cover; margin-bottom: 4px; display: block; }