/* Responsive Outer Container */
.mfb-container {
    position: relative;
    width: 100%;
    max-width: 1200px;
    margin: 20px auto;
    padding: 20px 15px; /* Minimal side padding for full horizontal width */
    background-color: #515558;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-sizing: border-box;
    user-select: none;
}

/* Viewport Window */
.mfb-viewport {
    position: relative;
    width: 100%;
    perspective: 2000px;
    -webkit-perspective: 2000px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px 0;
    overflow: hidden;
}

.mfb-viewport.is-zoomed { cursor: grab; }
.mfb-viewport.is-dragging { cursor: grabbing !important; }

/* Responsive 2-Page Book Canvas Spread */
.mfb-book {
    position: relative;
    width: 100%;
    max-width: 1100px;
    height: clamp(280px, 55vw, 700px); /* Fully fluid dynamic height for all screen sizes */
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
}

/* 3D Page Half-Widths */
.mfb-page {
    position: absolute;
    top: 0;
    right: 0;
    width: 50%;
    height: 100%;
    transform-origin: left top;
    -webkit-transform-origin: left top;
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
    cursor: pointer;
}

.mfb-page-face {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    background-color: #ffffff;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
}

.mfb-page-front {
    background: linear-gradient(to right, #d9d9d9 0%, #f9f9f9 3%, #ffffff 8%, #ffffff 100%);
}

.mfb-page-back {
    transform: rotateY(-180deg);
    background: linear-gradient(to right, #ffffff 0%, #ffffff 92%, #f9f9f9 97%, #d9d9d9 100%);
}

/* --- FIX: NEVER CUT OFF IMAGE --- */
.mfb-page-face img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain; /* Prevents cropping, maintains original image aspect ratio */
    pointer-events: none;
}

/* --- BOTTOM CORNER FOLD EFFECTS --- */
.mfb-fold-right {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 0px;
    height: 0px;
    background: linear-gradient(135deg, #fefefe 0%, #e8e8e8 49%, #ffffff 50%, #ffffff 100%);
    border-top: 1px solid #CCCCCC;
    border-left: 1px solid #CCCCCC;
    box-shadow: -6px -6px 12px rgba(0, 0, 0, 0.25);
    transition: width 0.35s cubic-bezier(0.25, 1, 0.5, 1), height 0.35s cubic-bezier(0.25, 1, 0.5, 1);
    z-index: 30;
    pointer-events: none;
}

.mfb-page-front:hover .mfb-fold-right {
    width: 60px;
    height: 60px;
}

.mfb-fold-left {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0px;
    height: 0px;
    background: linear-gradient(45deg, #ffffff 0%, #ffffff 50%, #e8e8e8 51%, #fefefe 100%);
    border-top: 1px solid #CCCCCC;
    border-right: 1px solid #CCCCCC;
    box-shadow: 6px -6px 12px rgba(0, 0, 0, 0.25);
    transition: width 0.35s cubic-bezier(0.25, 1, 0.5, 1), height 0.35s cubic-bezier(0.25, 1, 0.5, 1);
    z-index: 30;
    pointer-events: none;
}

.mfb-page-back:hover .mfb-fold-left {
    width: 60px;
    height: 60px;
}

/* --- NO-BACKGROUND ARROWS OVERLAID DIRECTLY ON CANVAS --- */
.mfb-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 99999 !important; /* Placed directly over book spread */
    background: transparent !important;
    color: #ffffff !important;
    font-size: 36px; /* Large readable arrows */
    font-weight: bold;
    border: none;
    outline: none;
    cursor: pointer;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
    line-height: 1;
    text-shadow: 0px 2px 8px rgba(0, 0, 0, 0.85); /* Dark shadow behind arrow for contrast over light images */
}

.mfb-arrow:hover:not(:disabled) {
    color: #ffd700 !important;
    transform: translateY(-50%) scale(1.2);
}

.mfb-arrow:disabled {
    opacity: 0.15;
    cursor: not-allowed;
}

/* Overlay positions */
.mfb-arrow-prev { left: 5px; }
.mfb-arrow-next { right: 5px; }

/* Responsive Toolbar Controls */
.mfb-controls {
    margin-top: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    padding: 6px 16px;
    border-radius: 30px;
    z-index: 1000;
}

.mfb-btn-icon {
    padding: 5px 12px;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 14px;
    cursor: pointer;
}

.mfb-page-num { font-size: 13px; color: #e0e0e0; }

/* Mobile Optimizations */
@media screen and (max-width: 600px) {
    .mfb-container { padding: 10px 5px; }
    .mfb-arrow { font-size: 28px; width: 40px; height: 40px; }
    .mfb-controls { gap: 6px; padding: 4px 10px; }
    .mfb-btn-icon { padding: 4px 8px; font-size: 12px; }
}