/* =========================================================
   SmartEmbed PDF Viewer - Frontend Styles
   ========================================================= */

/* --- Main Container --- */
.smartembed-pdf-app-container {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    /* background comes from inline style now */
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    /* Width/height come from shortcode inline style */
}

/* --- Fullscreen Mode --- */
.smartembed-pdf-app-container:fullscreen,
.smartembed-pdf-app-container:-webkit-full-screen,
.smartembed-pdf-app-container:-moz-full-screen,
.smartembed-pdf-app-container:-ms-fullscreen {
    width:  100vw !important;
    height: 100vh !important;
    max-width:  100vw !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    top: 0 !important;
    left: 0 !important;
}
.smartembed-pdf-app-container:fullscreen .smartembed-pdf-viewer-ui,
.smartembed-pdf-app-container:-webkit-full-screen .smartembed-pdf-viewer-ui,
.smartembed-pdf-app-container:-moz-full-screen .smartembed-pdf-viewer-ui {
    width:  100% !important;
    height: 100% !important;
}
.smartembed-pdf-app-container:fullscreen .flipbook-mode,
.smartembed-pdf-app-container:-webkit-full-screen .flipbook-mode,
.smartembed-pdf-app-container:-moz-full-screen .flipbook-mode {
    height: calc(100vh - 70px) !important;  /* leave room for toolbar */
}
.smartembed-pdf-app-container:fullscreen .smartembed-pdf-scroll-area:not(.flipbook-mode),
.smartembed-pdf-app-container:-webkit-full-screen .smartembed-pdf-scroll-area:not(.flipbook-mode),
.smartembed-pdf-app-container:-moz-full-screen .smartembed-pdf-scroll-area:not(.flipbook-mode) {
    height: calc(100vh - 70px) !important;
}

/* --- Inner Layout Wrapper - fills the grey container 100% --- */
.custom-premium-layout {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    background: transparent !important; /* let container background show through */
    position: relative;
    overflow: hidden;
}

/* --- Dark Mode --- */
.smartembed-dark-mode .custom-premium-layout {
    background: transparent !important;
}
/* Enable canvas inversion for smart dark mode */
.smartembed-dark-mode canvas,
.smartembed-dark-mode .st-page {
    filter: invert(1) hue-rotate(180deg) brightness(95%) contrast(95%);
}

/* =========================================================
   Scroll Area (Normal / Continuous modes)
   ========================================================= */
.smartembed-pdf-scroll-area {
    flex-grow: 1;
    overflow: auto;
    display: block;
    text-align: center;
    padding: 30px 80px 90px 80px;
    box-sizing: border-box;
}

/* Single canvas page */
.smartembed-pdf-page-canvas {
    max-width: none;
    height: auto !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    margin: 0 auto 20px auto;
    background: #fff;
    display: block;
    will-change: transform;
}

/* Page wrapper for continuous mode */
.smartembed-page-wrapper {
    margin-bottom: 20px;
    display: block;
}

/* =========================================================
   Flipbook Mode
   ========================================================= */
.flipbook-mode {
    padding: 0;
    overflow: visible;
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: calc(100% - 0px);  /* fill the grey area */
    box-sizing: border-box;
    background: #5a5a5a;  /* keep grey behind the flipbook book */
}

.flipbook-mode .smartembed-pdf-pages-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* The PageFlip container */
.smartembed-flipbook-container {
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    transform-origin: center center;
    max-width: 95%;
    overflow: visible;
}

/* Grab cursor when zoomed in — indicates draggable */
.smartembed-flipbook-container.se-flipbook-zoomed {
    cursor: grab;
}
.smartembed-flipbook-container.se-flipbook-dragging,
.smartembed-flipbook-container.se-flipbook-dragging * {
    cursor: grabbing !important;
    user-select: none !important;
}

/* Individual flipbook page divs */
.my-page {
    background-color: #ffffff !important;
    overflow: hidden;
    width: 100%;
    height: 100%;
}
.my-page canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    object-fit: contain;
    will-change: transform;
}

/* Watermark */
.smartembed-watermark-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-45deg);
    font-size: 6rem;
    font-weight: bold;
    color: rgba(0,0,0,0.05);
    pointer-events: none;
    white-space: nowrap;
    z-index: 10;
}

/* =========================================================
   Navigation Arrows
   ========================================================= */
.smartembed-nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.8);
    color: #ffffff;
    width: 44px;
    height: 80px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, border-color 0.2s, transform 0.2s;
    z-index: 50;
    border-radius: 6px;
    padding: 0;
    outline: none;
}
.smartembed-nav-arrow:hover {
    background: rgba(0, 0, 0, 0.75);
    border-color: #ffffff;
    transform: translateY(-50%) scale(1.05);
}
.smartembed-nav-arrow svg {
    width: 28px !important;
    height: 28px !important;
    stroke: #ffffff !important;
    fill: none !important;
    stroke-width: 2.5px !important;
    display: block !important;
    flex-shrink: 0;
}
.smartembed-prev-page {
    left: 12px;
}
.smartembed-next-page {
    right: 12px;
}

/* =========================================================
   Bottom Toolbar
   ========================================================= */
.smartembed-toolbar-wrapper {
    position: absolute;
    bottom: 32px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    pointer-events: none;
    z-index: 50;
}

.smartembed-bottom-toolbar {
    pointer-events: auto;
    width: max-content;
    background: rgba(45, 45, 45, 0.95);
    backdrop-filter: blur(8px);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    padding: 4px 6px;
    gap: 2px;
    white-space: nowrap;
    border: 1px solid rgba(255,255,255,0.2);
    transition: background 0.2s, border-color 0.2s;
}

.smartembed-tpl-name {
    font-size: 12px;
    font-weight: 700;
    color: #2e3a59;
    margin-bottom: 4px;
}
.smartembed-tpl-desc {
    font-size: 10px;
    color: #8f9bb3;
}

/* Tilt Effect */
.smartembed-tilt-enabled {
    perspective: 1500px;
}
.smartembed-tilt-enabled .st-page {
    transition: transform 0.3s ease-out;
}
.smartembed-tilt-enabled:hover {
    transform: rotateY(5deg) rotateX(2deg) !important;
}

/* Binder Style */
.smartembed-tpl-binder::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 15px,
        #333 15px,
        #333 20px
    );
    z-index: 999;
    pointer-events: none;
    border-radius: 4px;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.5);
}

/* 3D Book Cover Backing Case */



/* Center crease/spine line on the cover backing */






/* 3D Flipbook Style */
.smartembed-tpl-3d {
    box-shadow: 
        inset 4px 0 10px rgba(0, 0, 0, 0.1),
        inset -1px 0 2px rgba(255, 255, 255, 0.3),
        5px 5px 15px rgba(0, 0, 0, 0.3),
        15px 15px 35px rgba(0,0,0,0.45) !important;
    border-radius: 4px 12px 12px 4px;
    background: #fdfdfd;
}
.smartembed-tpl-3d .my-page {
    border-radius: 2px 8px 8px 2px;
    background: linear-gradient(to right, #e8e8e8 0%, #ffffff 5%, #ffffff 98%, #f0f0f0 100%) !important;
    box-shadow: inset 1px 0 5px rgba(0,0,0,0.1);
}
.smartembed-tpl-3d .st-page {
    border-left: 1px solid rgba(0,0,0,0.05);
}
.smartembed-tpl-3d .my-page::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.1);
    pointer-events: none;
}

/* Page Stack & 3D Depth effect on outer sides of pages */
.smartembed-tpl-3d .my-page[data-side="left"],
.smartembed-tpl-hardcover .my-page[data-side="left"],
.smartembed-tpl-binder .my-page[data-side="left"] {
    border-radius: 4px 0 0 4px;
    box-shadow: 
        -1px 1px 0px #ffffff,
        -2px 2px 0px #e2e8f0,
        -3px 3px 0px #ffffff,
        -4px 4px 0px #e2e8f0,
        -5px 5px 0px #ffffff,
        -6px 6px 0px #e2e8f0,
        -1px 1px 2px rgba(0,0,0,0.1),
        -3px 3px 3px rgba(0,0,0,0.15),
        -6px 6px 15px rgba(0,0,0,0.3) !important;
    border-right: none;
}

.smartembed-tpl-3d .my-page[data-side="right"],
.smartembed-tpl-hardcover .my-page[data-side="right"],
.smartembed-tpl-binder .my-page[data-side="right"] {
    border-radius: 0 4px 4px 0;
    box-shadow: 
        1px 1px 0px #ffffff,
        2px 2px 0px #e2e8f0,
        3px 3px 0px #ffffff,
        4px 4px 0px #e2e8f0,
        5px 5px 0px #ffffff,
        6px 6px 0px #e2e8f0,
        1px 1px 2px rgba(0,0,0,0.1),
        3px 3px 3px rgba(0,0,0,0.15),
        6px 6px 15px rgba(0,0,0,0.3) !important;
    border-left: none;
}

/* 2D Flipbook Style */
.smartembed-tpl-2d {
    box-shadow: 0 4px 20px rgba(0,0,0,0.15) !important;
    border-radius: 2px;
}
.smartembed-tpl-2d .my-page {
    border-radius: 2px;
}
/* Spine fold / inner crease effect to look realistic but flat */
.smartembed-tpl-2d .my-page[data-side="left"]::after {
    content: '';
    position: absolute;
    top: 0; right: 0; bottom: 0; width: 40px;
    background: linear-gradient(to left, rgba(0,0,0,0.12) 0%, rgba(0,0,0,0.02) 40%, rgba(0,0,0,0) 100%);
    pointer-events: none;
    z-index: 10;
}
.smartembed-tpl-2d .my-page[data-side="right"]::after {
    content: '';
    position: absolute;
    top: 0; left: 0; bottom: 0; width: 40px;
    background: linear-gradient(to right, rgba(0,0,0,0.12) 0%, rgba(0,0,0,0.02) 40%, rgba(0,0,0,0) 100%);
    pointer-events: none;
    z-index: 10;
}
/* Flatter page edges (no 3D stack) */
.smartembed-tpl-2d .my-page[data-side="left"] {
    box-shadow: inset -1px 0 3px rgba(0,0,0,0.05) !important;
    border-right: 1px solid rgba(0,0,0,0.08) !important;
}
.smartembed-tpl-2d .my-page[data-side="right"] {
    box-shadow: inset 1px 0 3px rgba(0,0,0,0.05) !important;
    border-left: 1px solid rgba(0,0,0,0.08) !important;
}

/* Overrides for Hard Cover density elements (pages 1 and last cover) */
.smartembed-tpl-hardcover .my-page[data-density="hard"] {
    background-color: #fcfcfc !important;
    border: 1px solid #dcdcdc;
    box-shadow: 
        3px 3px 15px rgba(0,0,0,0.4),
        inset 0 0 10px rgba(0,0,0,0.15) !important;
    border-radius: 6px !important;
}
.smartembed-tpl-hardcover .my-page[data-density="hard"]::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    box-shadow: inset 8px 0 15px -5px rgba(0,0,0,0.2);
    pointer-events: none;
}

/* Grab cursors when zoomed in */
.smartembed-book-cover-3d.se-flipbook-zoomed,
.smartembed-flipbook-container.se-flipbook-zoomed {
    cursor: grab;
}
.smartembed-book-cover-3d.se-flipbook-dragging,
.smartembed-book-cover-3d.se-flipbook-dragging *,
.smartembed-flipbook-container.se-flipbook-dragging,
.smartembed-flipbook-container.se-flipbook-dragging * {
    cursor: grabbing !important;
    user-select: none !important;
}

.smartembed-tpl-hardcover .st-page,
.smartembed-tpl-binder .st-page {
    overflow: visible !important;
}

.smartembed-page-info {
    padding: 0 12px;
    font-size: 14px;
    color: #e0e0e0;
    font-weight: 600;
    border-right: 1px solid #555;
    margin-right: 4px;
    display: flex;
    align-items: center;
    gap: 2px;
    height: 36px;
}
.smartembed-current-page {
    color: #fff !important;
    width: 44px !important;
    text-align: center !important;
    border: 1px solid #555 !important;
    border-radius: 4px !important;
    height: 24px !important;
    font-size: 13px !important;
    font-weight: bold !important;
    margin-right: 2px !important;
    padding: 0 !important;
    background: #444 !important;
    outline: none !important;
    box-shadow: none !important;
    display: inline-block !important;
}

.smartembed-tool-btn {
    background: transparent;
    border: none;
    color: #e0e0e0;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    padding: 0;
    outline: none;
}
.smartembed-tool-btn:hover {
    background: rgba(255,255,255,0.15);
    color: #fff;
}
.smartembed-tool-btn svg {
    width: 18px !important;
    height: 18px !important;
    stroke: currentColor !important;
    fill: none !important;
    stroke-width: 2px !important;
    display: block !important;
    flex-shrink: 0;
}

/* =========================================================
   Options Dropdown
   ========================================================= */
.smartembed-options-menu-container {
    position: relative;
}
.smartembed-options-dropdown {
    position: absolute;
    bottom: calc(100% + 8px);
    right: 0;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.15);
    display: none;
    flex-direction: column;
    min-width: 220px;
    padding: 8px 0;
    z-index: 100;
    border: 1px solid #eee;
}
.smartembed-options-dropdown.show {
    display: flex;
}
.smartembed-dropdown-item {
    background: transparent;
    border: none;
    padding: 10px 18px;
    text-align: left;
    width: 100%;
    cursor: pointer;
    font-size: 13px;
    color: #444;
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    transition: background 0.15s;
    box-sizing: border-box;
}
.smartembed-dropdown-item:hover {
    background: #f5f5f5;
    color: #111;
}
.smartembed-dropdown-item svg {
    width: 16px !important;
    height: 16px !important;
    stroke: #888 !important;
    fill: none !important;
    stroke-width: 2px !important;
    display: block !important;
    flex-shrink: 0;
}
.smartembed-options-dropdown::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 14px;
    border-width: 8px 7px 0 7px;
    border-style: solid;
    border-color: #fff transparent transparent transparent;
}

/* =========================================================
   Thumbnails Sidebar
   ========================================================= */
.smartembed-thumbnails-sidebar {
    position: absolute;
    top: 0;
    left: -320px;
    width: 280px;
    height: 100%;
    background: rgba(255,255,255,0.97);
    box-shadow: 4px 0 20px rgba(0,0,0,0.2);
    z-index: 60;
    transition: left 0.3s cubic-bezier(0.4,0,0.2,1);
    display: flex;
    flex-direction: column;
}
.smartembed-thumbnails-sidebar.open {
    left: 0;
}
.smartembed-thumbnails-header {
    padding: 14px 18px;
    font-weight: 700;
    color: #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #eee;
    font-size: 13px;
    letter-spacing: 1px;
    text-transform: uppercase;
}
.smartembed-thumbnails-close {
    background: transparent;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #999;
    padding: 4px;
    line-height: 1;
}
.smartembed-thumbnails-close:hover { color: #333; }

.smartembed-thumbnails-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.smartembed-thumbnail {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform 0.2s;
}
.smartembed-thumbnail:hover { transform: scale(1.04); }
.smartembed-thumbnail canvas {
    max-width: 100%;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    border-radius: 3px;
    background: #fff;
}
.smartembed-thumbnail-label {
    margin-top: 6px;
    font-size: 11px;
    color: #666;
    font-weight: 700;
    background: #f0f0f0;
    padding: 2px 10px;
    border-radius: 12px;
}

/* =========================================================
   Responsive Styles (Mobile & Tablet)
   ========================================================= */
@media (max-width: 850px) {
    .smartembed-pdf-app-container {
        height: 480px !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 auto !important;
    }
    .smartembed-pdf-scroll-area {
        padding: 10px 10px 90px 10px !important;
        overflow-x: hidden !important;
    }
    .smartembed-pdf-page-canvas {
        width: 100% !important;
        height: auto !important;
        max-width: 100% !important;
    }
    .smartembed-flipbook-container {
        overflow: hidden !important;
        display: flex !important;
        justify-content: center !important;
        align-items: flex-start !important;
    }
    .stf__parent {
        max-width: 100% !important;
        overflow: hidden !important;
    }
    .smartembed-bottom-toolbar {
        bottom: 8px !important;
        width: auto;
        max-width: 96%;
        padding: 2px 4px !important;
        gap: 1px !important;
        white-space: nowrap;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        justify-content: center;
        border-radius: 6px !important;
    }
    .smartembed-nav-arrow {
        width: 36px !important;
        height: 60px !important;
        background: rgba(0,0,0,0.5) !important;
        border: 2px solid rgba(255,255,255,0.8) !important;
    }
    .smartembed-prev-page {
        left: 4px !important;
    }
    .smartembed-next-page {
        right: 4px !important;
    }
    .smartembed-thumbnails-sidebar {
        width: 240px;
        left: -260px;
    }
    .smartembed-tool-btn {
        width: 30px !important;
        height: 30px !important;
    }
    .smartembed-tool-btn svg {
        width: 16px !important;
        height: 16px !important;
    }
    .smartembed-page-info {
        padding: 0 6px !important;
        font-size: 12px !important;
        height: 30px !important;
    }
    .smartembed-current-page {
        width: 32px !important;
        height: 20px !important;
        font-size: 11px !important;
    }
}

@media (max-width: 480px) {
    .smartembed-pdf-app-container {
        height: 400px !important;
    }
    .smartembed-pdf-scroll-area {
        padding: 10px 10px 90px 10px;
    }
    .smartembed-bottom-toolbar {
        bottom: 8px;
        padding: 2px 4px;
        gap: 0px;
        border-radius: 6px;
    }
    .smartembed-page-info {
        padding: 0 6px;
        font-size: 13px;
        margin-right: 4px;
        height: 32px;
    }
    .smartembed-current-page {
        width: 32px !important;
        height: 22px !important;
        font-size: 12px !important;
    }
    .smartembed-tool-btn {
        width: 30px;
        height: 30px;
    }
    .smartembed-tool-btn svg {
        width: 16px !important;
        height: 16px !important;
    }
    .smartembed-options-dropdown {
        min-width: 180px;
        right: 0;
        bottom: calc(100% + 4px);
    }
    .smartembed-options-dropdown::after {
        right: 8px; /* align arrow with the smaller button */
    }
    .smartembed-nav-arrow {
        width: 30px !important;
        height: 50px !important;
        background: rgba(0,0,0,0.6) !important;
        border: 2px solid rgba(255,255,255,0.9) !important;
    }
    .smartembed-nav-arrow svg {
        width: 20px !important;
        height: 20px !important;
    }
    .smartembed-prev-page {
        left: 4px !important;
    }
    .smartembed-next-page {
        right: 4px !important;
    }
    /* Hide fullscreen button on iOS/mobile since it often doesn't work well */
    .smartembed-fullscreen-btn {
        display: none !important;
    }
}

/* =========================================================
   Template Selector UI
   ========================================================= */
.smartembed-template-selector {
    background: linear-gradient(135deg, #f8fbfa 0%, #eef2f5 100%);
    padding: 20px 15px;
    border-radius: 8px 8px 0 0;
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, sans-serif;
    position: relative;
    z-index: 10;
    border-bottom: 2px solid #e1e8ed;
    box-shadow: inset 0 -4px 10px rgba(0,0,0,0.02);
    width: 100%;
    box-sizing: border-box;
}
.smartembed-template-title {
    text-align: center;
    font-size: 15px;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 16px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.smartembed-template-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    align-items: stretch;
}
.smartembed-tpl-card {
    background: #ffffff;
    border: 2px solid #e1e8ed;
    border-radius: 8px;
    padding: 14px 8px;
    width: 130px;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}
.smartembed-tpl-card:hover {
    border-color: #4caf50;
    background: #fdfdfd;
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(76, 175, 80, 0.15);
}
.smartembed-tpl-card.active {
    border-color: #4caf50;
    background: #f4fbf5;
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.1);
}
.smartembed-tpl-card.active::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid #4caf50;
    background: #fff;
    box-sizing: border-box;
}
.smartembed-tpl-card.active::after {
    content: '';
    position: absolute;
    top: 9px;
    left: 50%;
    transform: translateX(-50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4caf50;
}
.smartembed-tpl-icon {
    margin-top: 14px;
    margin-bottom: 6px;
    color: #64748b;
    transition: color 0.2s ease;
}
.smartembed-tpl-card:hover .smartembed-tpl-icon,
.smartembed-tpl-card.active .smartembed-tpl-icon {
    color: #4caf50;
}
.smartembed-tpl-icon svg {
    width: 32px;
    height: 32px;
}
.smartembed-tpl-name {
    font-size: 13px;
    font-weight: 700;
    color: #334155;
    margin-bottom: 3px;
    line-height: 1.2;
}
.smartembed-tpl-desc {
    font-size: 11px;
    color: #94a3b8;
    line-height: 1.2;
}

/* Real image icons */
.smartembed-tpl-img {
    width: 60px;
    height: 60px;
    object-fit: contain;
    display: block;
    margin: 0 auto;
    transition: transform 0.2s ease;
    border-radius: 4px;
}
.smartembed-tpl-card:hover .smartembed-tpl-img {
    transform: scale(1.08);
}
.smartembed-tpl-card.active .smartembed-tpl-img {
    transform: scale(1.05);
    filter: drop-shadow(0 2px 6px rgba(76, 175, 80, 0.4));
}


/* =========================================================
   Custom Hardcover Intro Animation (3D Closed Book)
   ========================================================= */

/* Scene wrapper — provides the 3D perspective */
.smartembed-custom-hardcover-intro {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    background: radial-gradient(ellipse at center, #6b6b6b 0%, #3d3d3d 100%);
    perspective: 1800px;
    perspective-origin: 50% 40%;
    overflow: hidden;
    transition: opacity 0.7s ease;
}
.smartembed-custom-hardcover-intro.hidden {
    opacity: 0;
    pointer-events: none;
}

/* The entire 3D book assembly */
.smartembed-hc-book {
    position: relative;
    transform-style: preserve-3d;
    /* Closed angled view: tilted forward + rotated slightly right */
    transform: rotateX(18deg) rotateY(-30deg) translateY(-20px);
    transition: transform 1.6s cubic-bezier(0.22, 0.61, 0.36, 1);
    cursor: pointer;
    /* will-change for GPU compositing */
    will-change: transform;
}
.smartembed-custom-hardcover-intro.is-opening .smartembed-hc-book {
    /* Flatten out as if setting the book on a table to open */
    transform: rotateX(2deg) rotateY(-2deg) translateY(0px) scale(1.04);
}

/* ---- SPINE THICKNESS (CSS variable passed inline) ---- */
/* All face thicknesses use --hc-depth set from JS */

/* Shared face style */
.smartembed-hc-face {
    position: absolute;
    backface-visibility: hidden;
    transform-style: preserve-3d;
}

/* FRONT COVER */
.smartembed-hc-front {
    top: 0; left: 0;
    width: 100%; height: 100%;
    transform-origin: left center;
    /* Start: flat closed, pushed forward by half depth */
    transform: rotateY(0deg) translateZ(var(--hc-half-depth, 15px));
    transition: transform 1.55s cubic-bezier(0.25, 0.85, 0.15, 1.06);
    border-radius: 2px 6px 6px 2px;
    overflow: hidden;
    /* Leather base colour — warm dark brown */
    background: linear-gradient(160deg, #2c1a0e 0%, #3d2410 40%, #2a1a0d 70%, #1e1208 100%);
    box-shadow:
        inset 0 0 60px rgba(0,0,0,0.5),
        inset 3px 0 10px rgba(0,0,0,0.6),
        4px 0 25px rgba(0,0,0,0.7);
    z-index: 10;
}
/* Leather grain texture overlay */
.smartembed-hc-front::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.08'/%3E%3C/svg%3E");
    background-size: 200px 200px;
    mix-blend-mode: overlay;
    pointer-events: none;
    z-index: 2;
}
/* Spine-edge inner shadow + highlight sheen on cover */
.smartembed-hc-front::after {
    content: '';
    position: absolute;
    inset: 0;
    background:
        linear-gradient(to right,
            rgba(0,0,0,0.55) 0%,
            rgba(0,0,0,0.1) 8%,
            rgba(255,255,255,0.04) 30%,
            rgba(255,255,255,0.07) 50%,
            rgba(0,0,0,0.15) 85%,
            rgba(0,0,0,0.3) 100%),
        linear-gradient(to bottom,
            rgba(255,255,255,0.07) 0%,
            transparent 20%,
            transparent 80%,
            rgba(0,0,0,0.2) 100%);
    pointer-events: none;
    z-index: 3;
    border-radius: inherit;
}
/* Canvas sits inside front cover */
.smartembed-hc-front-canvas-wrap {
    position: absolute;
    inset: 0;
    z-index: 1;
    overflow: hidden;
    border-radius: inherit;
}
.smartembed-hc-front-canvas-wrap canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* Opening state — rotate cover open ~175 deg */
.smartembed-custom-hardcover-intro.is-opening .smartembed-hc-front {
    transform: rotateY(-175deg) translateZ(var(--hc-half-depth, 15px));
}

/* BACK COVER */
.smartembed-hc-back {
    top: 0; left: 0;
    width: 100%; height: 100%;
    /* Push back by half depth */
    transform: translateZ(calc(-1 * var(--hc-half-depth, 15px)));
    background: linear-gradient(160deg, #1e1208 0%, #2a1a0d 50%, #1e1208 100%);
    border-radius: 2px 6px 6px 2px;
    box-shadow: inset 0 0 40px rgba(0,0,0,0.6);
    z-index: 1;
    overflow: hidden;
}
.smartembed-hc-back::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to right,
        rgba(0,0,0,0.4) 0%, rgba(0,0,0,0.05) 10%,
        transparent 50%, rgba(0,0,0,0.1) 100%);
    pointer-events: none;
}

/* SPINE (left face) */
.smartembed-hc-spine {
    top: 0;
    left: 0;
    /* Width = full spine depth, Height = book height */
    width: var(--hc-depth, 30px);
    height: 100%;
    /* Rotate -90deg around the left edge of front face, then shift left by full depth */
    transform-origin: right center;
    transform: rotateY(-90deg) translateZ(0);
    background: linear-gradient(to right,
        #0d0806 0%, #1e1208 15%, #2c1a0e 40%,
        #3d2410 50%, #2c1a0e 60%, #1a100a 85%, #0d0806 100%);
    box-shadow:
        inset -3px 0 8px rgba(0,0,0,0.8),
        inset 2px 0 6px rgba(255,255,255,0.04);
    z-index: 5;
    border-radius: 4px 0 0 4px;
}
/* Gold foil spine stripe */
.smartembed-hc-spine::before {
    content: '';
    position: absolute;
    top: 12%; bottom: 12%;
    left: 20%; width: 60%;
    background: linear-gradient(to right,
        transparent, rgba(180,140,60,0.18), rgba(220,180,90,0.25),
        rgba(180,140,60,0.18), transparent);
    border-radius: 2px;
}

/* TOP EDGE (pages stack top) */
.smartembed-hc-top {
    top: 0; left: 0;
    width: 100%;
    height: var(--hc-depth, 30px);
    transform-origin: top center;
    transform: rotateX(90deg) translateZ(0);
    background:
        repeating-linear-gradient(to right,
            #f8f6f0 0px, #f8f6f0 1px,
            #e8e4dc 2px, #e8e4dc 3px,
            #f4f1ea 4px, #f4f1ea 5px),
        linear-gradient(to bottom, #f0ede6 0%, #d8d4cc 100%);
    box-shadow: inset 0 -2px 4px rgba(0,0,0,0.1);
    z-index: 3;
}
/* Subtle top-edge highlight */
.smartembed-hc-top::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom,
        rgba(255,255,255,0.4) 0%, rgba(255,255,255,0) 50%);
    pointer-events: none;
}

/* BOTTOM EDGE */
.smartembed-hc-bottom {
    bottom: 0; left: 0;
    width: 100%;
    height: var(--hc-depth, 30px);
    transform-origin: bottom center;
    transform: rotateX(-90deg) translateZ(0);
    background:
        repeating-linear-gradient(to right,
            #f8f6f0 0px, #f8f6f0 1px,
            #e2ddd5 2px, #e2ddd5 3px,
            #f4f1ea 4px, #f4f1ea 5px),
        linear-gradient(to top, #e8e4dc 0%, #f0ede6 100%);
    z-index: 3;
}

/* RIGHT EDGE (fore-edge) */
.smartembed-hc-right {
    top: 0; right: 0;
    width: var(--hc-depth, 30px);
    height: 100%;
    transform-origin: right center;
    transform: rotateY(90deg) translateZ(0);
    background:
        repeating-linear-gradient(to bottom,
            #faf8f3 0px, #faf8f3 1px,
            #e5e0d8 2px, #e5e0d8 3px,
            #f5f2ec 4px, #f5f2ec 5px);
    box-shadow:
        inset -2px 0 6px rgba(0,0,0,0.08),
        inset 0 0 20px rgba(0,0,0,0.05);
    z-index: 3;
    border-radius: 0 2px 2px 0;
}
/* Right edge gilded highlight */
.smartembed-hc-right::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to right,
        rgba(255,255,255,0.0) 0%, rgba(255,255,255,0.35) 60%, rgba(255,255,255,0.0) 100%);
    pointer-events: none;
}

/* Ambient floor shadow (not 3D transformed — stays flat) */
.smartembed-hc-shadow {
    position: absolute;
    /* Positioned below and to the right to simulate angled light from top-left */
    bottom: -12%;
    left: 5%;
    width: 90%;
    height: 40%;
    background: radial-gradient(ellipse at 40% 50%,
        rgba(0,0,0,0.75) 0%, rgba(0,0,0,0.3) 50%, transparent 80%);
    filter: blur(18px);
    transform: translateZ(-100px) scaleY(0.4) rotateX(80deg);
    pointer-events: none;
    transition: all 1.6s cubic-bezier(0.22, 0.61, 0.36, 1);
    z-index: 0;
    border-radius: 50%;
}
.smartembed-custom-hardcover-intro.is-opening .smartembed-hc-shadow {
    filter: blur(28px);
    opacity: 0.45;
    transform: translateZ(-100px) scaleY(0.3) rotateX(80deg);
}

/* Ambient glow rim behind book */
.smartembed-hc-glow {
    position: absolute;
    inset: -15%;
    background: radial-gradient(ellipse at 40% 45%,
        rgba(120,80,40,0.12) 0%, transparent 65%);
    pointer-events: none;
    z-index: 0;
}

/* "Click to Open" hint label */
.smartembed-open-hint {
    position: absolute;
    bottom: 22px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,0.92);
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(6px);
    padding: 10px 24px;
    border-radius: 30px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    pointer-events: none;
    border: 1px solid rgba(255,255,255,0.15);
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    animation: se-hint-float 2.4s ease-in-out infinite;
    white-space: nowrap;
    transition: opacity 0.5s;
}
@keyframes se-hint-float {
    0%, 100% { transform: translateX(-50%) translateY(0px); opacity: 0.8; }
    50%        { transform: translateX(-50%) translateY(-6px); opacity: 1; }
}
.smartembed-custom-hardcover-intro.is-opening .smartembed-open-hint {
    opacity: 0;
    animation: none;
}

/* =========================================================
   Hardcover PageFlip inner pages (after opening)
   ========================================================= */
/* Inner gutter shadow when page is open */
.smartembed-tpl-hardcover .stf__block::after {
    content: '';
    position: absolute;
    top: 0; bottom: 0;
    left: 50%; width: 40px;
    margin-left: -20px;
    background: linear-gradient(to right,
        rgba(0,0,0,0.18) 0%, rgba(0,0,0,0.06) 40%, transparent 100%);
    pointer-events: none;
    z-index: 100;
}
/* Page edge highlight (fore-edge pages) */
.smartembed-tpl-hardcover .my-page[data-side="right"] canvas {
    box-shadow: inset -3px 0 8px rgba(0,0,0,0.06);
}
.smartembed-tpl-hardcover .my-page[data-side="left"] canvas {
    box-shadow: inset 3px 0 8px rgba(0,0,0,0.06);
}

/* Mobile: simplify 3D for performance */
@media (max-width: 768px) {
    .smartembed-custom-hardcover-intro {
        perspective: 1200px;
    }
    .smartembed-hc-book {
        transform: rotateX(10deg) rotateY(-20deg) translateY(-10px);
    }
    .smartembed-custom-hardcover-intro.is-opening .smartembed-hc-book {
        transform: rotateX(1deg) rotateY(-1deg) translateY(0) scale(1.02);
    }
    .smartembed-hc-shadow { filter: blur(12px); }
}

/* --- TOC Sidebar --- */
.smartembed-toc-sidebar {
    position: absolute;
    top: 0; left: 0;
    width: 280px; height: 100%;
    background: rgba(40,40,40,0.95);
    color: #fff;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 100;
    display: flex; flex-direction: column;
    border-right: 1px solid rgba(255,255,255,0.1);
    backdrop-filter: blur(8px);
}
.smartembed-toc-sidebar.open {
    transform: translateX(0);
}
.smartembed-toc-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 15px; border-bottom: 1px solid rgba(255,255,255,0.1);
    font-size: 14px; font-weight: 600; letter-spacing: 1px;
}
.smartembed-toc-close {
    background: none; border: none; color: #fff;
    font-size: 18px; cursor: pointer; padding: 5px;
    opacity: 0.6; transition: opacity 0.2s;
}
.smartembed-toc-close:hover { opacity: 1; }
.smartembed-toc-content {
    flex: 1; overflow-y: auto; padding: 15px 15px 15px 0;
}
.smartembed-toc-item > a:hover {
    color: #4dabf7 !important;
}
