        /* CSS Variables for theming */
        :root {
            --color-primary: #4a9eff;
            --color-primary-hover: #3a8eef;
            --color-secondary: #6366f1;
            --color-icon: #4a9eff;
            --color-icon-active: #6bb5ff;
            --color-primary-rgb: 74, 158, 255;
            --color-secondary-rgb: 99, 102, 241;
            /* Dark theme */
            --bg-page: #0a0a12;
            --bg-toolbar: rgba(40, 40, 50, 0.95);
            --bg-popup: #252532;
            --bg-sidebar: #1a1a24;
            --text-color: #ffffff;
            --border-color: rgba(255, 255, 255, 0.1);
            /* Light theme */
            --bg-page-light: #e8e8f0;
            --bg-toolbar-light: rgba(255, 255, 255, 0.95);
            --bg-popup-light: #ffffff;
            --bg-sidebar-light: #f5f5f7;
            --text-color-light: #333333;
            --border-color-light: rgba(0, 0, 0, 0.1);
        }

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

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: var(--bg-page);
            min-height: 100vh;
            overflow: hidden;
            color: var(--text-color);
            -webkit-tap-highlight-color: transparent;
            -webkit-touch-callout: none;
            -webkit-user-select: none;
            user-select: none;
        }

        #canvas-container {
            touch-action: none;
        }

        /* Main container */
        #app {
            width: 100vw;
            height: 100vh;
            display: flex;
            flex-direction: column;
            position: relative;
        }

        /* Three.js canvas container */
        #canvas-container {
            flex: 1;
            position: relative;
            display: flex;
            align-items: center;
            justify-content: center;
            transform: translateY(-30px);
        }

        /* Page Peel Container - positioned over the book */
        .page-container {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            pointer-events: none;
            z-index: 60;
            overflow: hidden;
        }

        /* Corner hover zones - now hit-tested by JS against projected page corners.
           DOM elements remain only for visual peel rendering (peel-fold/peel-shadow). */
        .corner-peel {
            position: absolute;
            width: 120px;
            height: 120px;
            pointer-events: none;
            z-index: 61;
        }

        .corner-peel .peel-fold,
        .corner-peel .peel-shadow {
            display: none;
        }

        .corner-peel.bottom-right {
            bottom: 0;
            right: 0;
        }

        .corner-peel.top-right {
            top: 0;
            right: 0;
        }

        .corner-peel.bottom-left {
            bottom: 0;
            left: 0;
        }

        .corner-peel.top-left {
            top: 0;
            left: 0;
        }

        /* RTL mode - swap side nav positions */
        body.rtl-mode .side-nav.left {
            left: auto;
            right: 20px;
        }
        body.rtl-mode .side-nav.right {
            right: auto;
            left: 20px;
        }
        body.rtl-mode .side-nav.left .nav-btn svg {
            transform: scaleX(-1);
        }
        body.rtl-mode .side-nav.right .nav-btn svg {
            transform: scaleX(-1);
        }

        /* Side Navigation */
        .side-nav {
            position: fixed;
            top: 50%;
            transform: translateY(-50%);
            display: flex;
            flex-direction: column;
            gap: 15px;
            z-index: 100;
        }

        .side-nav.left {
            left: 20px;
        }

        .side-nav.right {
            right: 20px;
        }

        .nav-btn {
            width: 44px;
            height: 44px;
            border: none;
            background: transparent !important;
            outline: none;
            color: rgba(255, 255, 255, 0.7);
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.2s ease;
        }

        .nav-btn:hover {
            color: rgba(255, 255, 255, 1);
        }

        .nav-btn:disabled {
            opacity: 0.3;
            cursor: not-allowed;
        }

        .nav-btn svg {
            width: 24px;
            height: 24px;
        }

        /* Top Right Controls */
        .top-right-controls {
            position: fixed;
            top: 20px;
            right: 20px;
            display: flex;
            flex-direction: column;
            gap: 10px;
            z-index: 100;
            pointer-events: none;
        }

        .top-right-controls > * {
            pointer-events: auto;
        }

        .control-btn {
            width: 40px;
            height: 40px;
            background: rgba(255, 255, 255, 0.1);
            border: none;
            border-radius: 8px;
            color: rgba(255, 255, 255, 0.7);
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.2s ease;
        }

        .control-btn:hover {
            background: rgba(255, 255, 255, 0.2);
            color: var(--text-color);
        }

        .control-btn svg {
            width: 20px;
            height: 20px;
        }

        .control-btn.theme-toggle-ctrl .tooltip {
            bottom: auto;
            top: 50%;
            left: auto;
            right: 100%;
            transform: translateY(-50%);
            margin-bottom: 0;
            margin-right: 8px;
        }

        /* Bottom Toolbar */
        .bottom-toolbar {
            position: fixed;
            bottom: 30px;
            left: 50%;
            transform: translateX(-50%);
            display: flex;
            align-items: center;
            gap: 4px;
            background: var(--bg-toolbar);
            padding: 8px 12px;
            border-radius: 5px;
            backdrop-filter: blur(20px);
            z-index: 100;
            box-shadow: 1px 0 5px rgba(0, 0, 0, 0.5);
        }

        .toolbar-btn {
            width: 36px;
            height: 36px;
            background: transparent;
            border: none;
            border-radius: 6px;
            color: rgba(255, 255, 255, 0.7);
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.2s ease;
            position: relative;
        }

        .toolbar-btn:hover {
            background: rgba(255, 255, 255, 0.1);
            color: var(--text-color);
        }

        .toolbar-btn svg {
            width: 18px;
            height: 18px;
        }

        .toolbar-btn.active {
            color: var(--color-icon-active);
            background: color-mix(in srgb, var(--color-primary) 22%, transparent);
            box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--color-primary) 45%, transparent);
        }
        .toolbar-btn.active:hover {
            background: color-mix(in srgb, var(--color-primary) 30%, transparent);
        }
        body.light-theme .toolbar-btn.active {
            background: color-mix(in srgb, var(--color-primary) 16%, transparent);
            box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--color-primary) 40%, transparent);
        }

        .toolbar-btn.disabled {
            opacity: 0.35;
            cursor: not-allowed;
            pointer-events: none;
        }

        .page-indicator {
            background: rgba(0, 0, 0, 0.4);
            padding: 6px 12px;
            border-radius: 6px;
            font-size: 13px;
            color: rgba(255, 255, 255, 0.9);
            min-width: 50px;
            text-align: center;
            font-weight: 500;
            white-space: nowrap;
        }

        /* Loading indicator removed — page indicator shows final state immediately */

        /* Zoom Dropdown */
        .zoom-dropdown {
            position: relative;
        }

        .zoom-select {
            background: rgba(0, 0, 0, 0.4);
            border: none;
            border-radius: 6px;
            padding: 6px 28px 6px 10px;
            font-size: 13px;
            color: rgba(255, 255, 255, 0.9);
            cursor: pointer;
            appearance: none;
            -webkit-appearance: none;
            min-width: 100px;
            font-family: inherit;
        }

        .zoom-dropdown::after {
            content: '';
            position: absolute;
            right: 10px;
            top: 50%;
            transform: translateY(-50%);
            border-left: 4px solid transparent;
            border-right: 4px solid transparent;
            border-top: 5px solid rgba(255, 255, 255, 0.7);
            pointer-events: none;
        }

        .zoom-select:hover {
            background: rgba(0, 0, 0, 0.5);
        }

        .zoom-select:focus {
            outline: none;
            box-shadow: 0 0 0 2px rgba(var(--color-primary-rgb), 0.5);
        }

        .zoom-select option {
            background: var(--bg-popup);
            color: var(--text-color);
            padding: 8px;
        }
        body.light-theme .zoom-select option {
            background: var(--bg-popup-light);
            color: var(--text-color-light);
        }

        body.light-theme .zoom-select {
            background: rgba(0, 0, 0, 0.08);
            color: rgba(0, 0, 0, 0.8);
        }

        body.light-theme .zoom-dropdown::after {
            border-top-color: rgba(0, 0, 0, 0.6);
        }

        body.light-theme .zoom-select:hover {
            background: rgba(0, 0, 0, 0.12);
        }

        body.light-theme .zoom-select option {
            background: white;
            color: var(--text-color-light);
        }

        .toolbar-divider {
            width: 1px;
            height: 24px;
            background: rgba(255, 255, 255, 0.15);
            margin: 0 4px;
        }

        .divider-center-only {
            display: none;
        }

        /* Theme toggle button in toolbar - hidden by default, shown in fullwidth */
        .theme-toggle-btn {
            display: none;
        }

        .theme-toggle-btn .moon-icon,
        .theme-toggle-ctrl .moon-icon {
            display: none;
        }

        .theme-toggle-btn .sun-icon,
        .theme-toggle-ctrl .sun-icon {
            display: block;
        }

        body.light-theme .theme-toggle-btn .moon-icon,
        body.light-theme .theme-toggle-ctrl .moon-icon {
            display: block;
        }

        body.light-theme .theme-toggle-btn .sun-icon,
        body.light-theme .theme-toggle-ctrl .sun-icon {
            display: none;
        }

        /* Toolbar sections - default (bottom-center) */
        .toolbar-left,
        .toolbar-center,
        .toolbar-right {
            display: flex;
            align-items: center;
            gap: 4px;
        }

        .toolbar-logo {
            width: 36px;
            height: 36px;
            border-radius: 6px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-left: 4px;
            overflow: hidden;
        }

        .toolbar-logo img {
            width: 100%;
            height: 100%;
            object-fit: contain;
        }

        .toolbar-logo .logo-light {
            display: none;
        }

        .toolbar-logo .logo-dark {
            display: block;
        }

        body.light-theme .toolbar-logo .logo-light {
            display: block;
        }

        body.light-theme .toolbar-logo .logo-dark {
            display: none;
        }

        /* Tooltip */
        .tooltip {
            position: absolute;
            bottom: 100%;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0, 0, 0, 0.9);
            color: #fff;
            padding: 6px 10px;
            border-radius: 6px;
            font-size: 12px;
            white-space: nowrap;
            opacity: 0;
            visibility: hidden;
            transition: all 0.2s ease;
            margin-bottom: 8px;
            pointer-events: none;
        }

        .toolbar-btn:hover .tooltip,
        .control-btn:hover .tooltip {
            opacity: 1;
            visibility: visible;
        }

        /* Theme toggle active states */
        .theme-btn.active {
            background: rgba(255, 255, 255, 0.2);
            color: var(--text-color);
        }

        /* Sound button muted state */
        .toolbar-btn.muted {
            color: rgba(255, 255, 255, 0.4);
        }

        body.light-theme .toolbar-btn.muted {
            color: rgba(0, 0, 0, 0.3);
        }

        /* Loading */
        #loading {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            color: var(--text-color);
            font-size: 14px;
            z-index: 1000;
            text-align: center;
            width: 280px;
        }

        .loading-logo {
            display: block;
            max-width: 150px;
            max-height: 80px;
            margin: 0 auto 24px auto;
            object-fit: contain;
        }

        .loading-title {
            font-size: 18px;
            font-weight: 500;
            margin-bottom: 20px;
            opacity: 0.9;
        }

        .progress-container {
            width: 100%;
            height: 6px;
            background: rgba(255, 255, 255, 0.15);
            border-radius: 3px;
            overflow: hidden;
            margin-bottom: 12px;
        }

        .progress-bar {
            height: 100%;
            width: 0%;
            background: linear-gradient(90deg, var(--color-secondary), var(--color-primary));
            border-radius: 3px;
            transition: width 0.3s ease-out;
        }

        .progress-text {
            font-size: 13px;
            opacity: 0.7;
        }

        body.light-theme #loading {
            color: var(--text-color-light);
        }

        body.light-theme .progress-container {
            background: rgba(0, 0, 0, 0.1);
        }

        /* Light theme */
        body.light-theme {
            background: var(--bg-page-light);
        }
        html.tncfb-transparent,
        html.tncfb-transparent body,
        html.tncfb-transparent body.light-theme,
        body.tncfb-transparent,
        body.tncfb-transparent.light-theme {
            background: transparent !important;
            background-color: transparent !important;
        }
        html.tncfb-transparent #app,
        html.tncfb-transparent #canvas-container,
        html.tncfb-transparent .tncfb-2d-container {
            background: transparent !important;
            background-color: transparent !important;
        }
        body.tncfb-transparent #loading {
            color: rgba(255, 255, 255, 0.9);
        }
        body.tncfb-transparent .progress-container {
            background: rgba(255, 255, 255, 0.15) !important;
        }
        body.tncfb-transparent .progress-bar {
            background: rgba(255, 255, 255, 0.6) !important;
        }
        body.tncfb-transparent.light-theme #loading {
            color: rgba(0, 0, 0, 0.8);
        }
        body.tncfb-transparent.light-theme .progress-container {
            background: rgba(0, 0, 0, 0.1) !important;
        }
        body.tncfb-transparent.light-theme .progress-bar {
            background: rgba(0, 0, 0, 0.4) !important;
        }

        /* Transparent popups: loading screen sits over the popup overlay,
           whose polarity is set by popuptheme — drive contrast off that,
           not off page polarity, so text and progress stay readable
           regardless of which way the page chrome was biased. */
        body.tncfb-transparent.tncfb-popup-theme-dark #loading {
            color: rgba(255, 255, 255, 0.9) !important;
        }
        body.tncfb-transparent.tncfb-popup-theme-dark .progress-container {
            background: rgba(255, 255, 255, 0.15) !important;
        }
        body.tncfb-transparent.tncfb-popup-theme-dark .progress-bar {
            background: rgba(255, 255, 255, 0.6) !important;
        }
        body.tncfb-transparent.tncfb-popup-theme-light #loading {
            color: rgba(0, 0, 0, 0.8) !important;
        }
        body.tncfb-transparent.tncfb-popup-theme-light .progress-container {
            background: rgba(0, 0, 0, 0.1) !important;
        }
        body.tncfb-transparent.tncfb-popup-theme-light .progress-bar {
            background: rgba(0, 0, 0, 0.4) !important;
        }

        body.light-theme .bottom-toolbar {
            background: var(--bg-toolbar-light);
            box-shadow: 0 4px 30px rgba(0, 0, 0, 0.15);
        }

        body.light-theme .toolbar-btn {
            color: rgba(0, 0, 0, 0.6);
        }

        body.light-theme .toolbar-btn:hover {
            background: rgba(0, 0, 0, 0.08);
            color: rgba(0, 0, 0, 0.9);
        }

        body.light-theme .page-indicator {
            background: rgba(0, 0, 0, 0.08);
            color: rgba(0, 0, 0, 0.8);
        }

        body.light-theme .zoom-indicator {
            color: rgba(0, 0, 0, 0.6);
        }

        body.light-theme .nav-btn {
            color: rgba(0, 0, 0, 0.4);
        }

        body.light-theme .nav-btn:hover {
            color: rgba(0, 0, 0, 0.8);
        }

        body.light-theme .control-btn {
            background: rgba(0, 0, 0, 0.05);
            color: rgba(0, 0, 0, 0.6);
        }

        body.light-theme .control-btn:hover {
            background: rgba(0, 0, 0, 0.1);
            color: rgba(0, 0, 0, 0.9);
        }

        body.light-theme .toolbar-divider {
            background: rgba(0, 0, 0, 0.15);
        }

        /* Top Center Layout */
        body.layout-top-center .bottom-toolbar {
            bottom: auto;
            top: 20px;
        }

        body.layout-top-center .top-right-controls {
            top: 20px;
            right: 20px;
        }

        body.layout-top-center .thumbnails-sidebar {
            /* Sidebar position stays the same for all layouts */
        }

        body.layout-top-center .minimap {
            top: 80px;
        }

        /* Bottom Fullwidth Layout */
        body.layout-bottom-fullwidth .bottom-toolbar {
            left: 0;
            right: 0;
            bottom: 0;
            transform: none;
            border-radius: 0;
            padding: 10px 20px;
            justify-content: space-between;
        }

        body.layout-bottom-fullwidth .bottom-toolbar .toolbar-left {
            display: flex;
            align-items: center;
            z-index: 1;
        }

        body.layout-bottom-fullwidth .bottom-toolbar .toolbar-center {
            display: flex;
            align-items: center;
            gap: 4px;
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
        }

        body.layout-bottom-fullwidth .bottom-toolbar .toolbar-right {
            display: flex;
            align-items: center;
            z-index: 1;
        }

        body.layout-bottom-fullwidth .divider-center-only {
            display: none;
        }

        body.layout-bottom-fullwidth .thumbnails-sidebar {
            /* Sidebar position stays the same for all layouts */
        }

        body.layout-bottom-fullwidth .top-right-controls {
            top: 20px;
        }
        body.layout-bottom-fullwidth .theme-toggle-ctrl {
            display: none;
        }

        body.layout-bottom-fullwidth .page-indicator {
            background: transparent;
            padding: 6px 0;
        }

        body.layout-bottom-fullwidth .theme-toggle-btn {
            display: flex;
        }

        /* Top Fullwidth Layout */
        body.layout-top-fullwidth .bottom-toolbar {
            left: 0;
            right: 0;
            bottom: auto;
            top: 0;
            transform: none;
            border-radius: 0;
            padding: 10px 20px;
            justify-content: space-between;
        }

        body.layout-top-fullwidth .bottom-toolbar .toolbar-left {
            display: flex;
            align-items: center;
            z-index: 1;
        }

        body.layout-top-fullwidth .bottom-toolbar .toolbar-center {
            display: flex;
            align-items: center;
            gap: 4px;
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
        }

        body.layout-top-fullwidth .bottom-toolbar .toolbar-right {
            display: flex;
            align-items: center;
            z-index: 1;
        }

        body.layout-top-fullwidth .divider-center-only {
            display: none;
        }

        body.layout-top-fullwidth .thumbnails-sidebar {
            /* Sidebar position stays the same for all layouts */
        }

        body.layout-top-fullwidth .top-right-controls {
            display: none;
        }

        body.layout-top-fullwidth .minimap {
            top: 80px;
        }

        body.layout-top-fullwidth .theme-toggle-btn {
            display: flex;
        }

        body.layout-top-fullwidth .page-indicator {
            background: transparent;
            padding: 6px 0;
        }

        /* Search Sidebar */
        /* Hide off-screen sidebars from tab order and assistive tech */
        .search-sidebar:not(.active),
        .thumbnails-sidebar:not(.active),
        .bookmarks-sidebar:not(.active),
        .notes-sidebar:not(.active) {
            visibility: hidden;
        }
        .search-sidebar.active,
        .thumbnails-sidebar.active,
        .bookmarks-sidebar.active,
        .notes-sidebar.active {
            visibility: visible;
        }

        /* Hide off-screen modals from tab order */
        .share-modal:not(.active),
        .keyboard-help-modal:not(.active),
        .print-modal:not(.active) {
            visibility: hidden;
        }
        .share-modal.active,
        .keyboard-help-modal.active,
        .print-modal.active {
            visibility: visible;
        }

        .search-sidebar {
            position: fixed;
            top: 0;
            left: 0;
            width: 280px;
            height: 100vh;
            background: var(--bg-sidebar);
            z-index: 200;
            transform: translateX(-100%);
            transition: transform 0.3s ease;
            display: flex;
            flex-direction: column;
        }

        .search-sidebar.active {
            transform: translateX(0);
        }

        body.light-theme .search-sidebar {
            background: var(--bg-sidebar-light);
        }

        .search-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 16px 20px;
            border-bottom: 1px solid var(--border-color);
        }

        body.light-theme .search-header {
            border-bottom-color: var(--border-color-light);
        }

        .search-title {
            font-size: 16px;
            font-weight: 600;
            color: var(--text-color);
        }

        body.light-theme .search-title {
            color: var(--text-color-light);
        }

        .search-close {
            background: none;
            border: none;
            color: rgba(255, 255, 255, 0.7);
            cursor: pointer;
            padding: 4px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .search-close:hover {
            color: var(--text-color);
        }

        body.light-theme .search-close {
            color: rgba(0, 0, 0, 0.5);
        }

        body.light-theme .search-close:hover {
            color: var(--text-color-light);
        }

        .search-input-wrapper {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 16px 20px;
            border-bottom: 1px solid var(--border-color);
        }

        body.light-theme .search-input-wrapper {
            border-bottom-color: var(--border-color-light);
        }

        .search-input-container {
            flex: 1;
            display: flex;
            align-items: center;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 6px;
            padding: 0 12px;
        }

        body.light-theme .search-input-container {
            background: rgba(0, 0, 0, 0.08);
        }

        .search-input-container svg {
            width: 16px;
            height: 16px;
            color: rgba(255, 255, 255, 0.5);
            flex-shrink: 0;
        }

        body.light-theme .search-input-container svg {
            color: rgba(0, 0, 0, 0.4);
        }

        .search-input {
            flex: 1;
            background: none;
            border: none;
            padding: 10px 8px;
            color: var(--text-color);
            font-size: 13px;
            outline: none;
        }

        .search-input::placeholder {
            color: rgba(255, 255, 255, 0.4);
        }

        body.light-theme .search-input {
            color: var(--text-color-light);
        }

        body.light-theme .search-input::placeholder {
            color: rgba(0, 0, 0, 0.4);
        }

        .search-clear-btn {
            background: color-mix(in srgb, var(--color-primary) 70%, #000);
            border: none;
            color: #fff;
            padding: 8px 14px;
            border-radius: 6px;
            font-size: 12px;
            font-weight: 600;
            cursor: pointer;
            transition: background 0.2s;
            flex-shrink: 0;
            white-space: nowrap;
        }

        .search-clear-btn:hover {
            background: color-mix(in srgb, var(--color-primary) 60%, #000);
        }

        .search-status {
            padding: 12px 20px;
            font-size: 13px;
            color: rgba(255, 255, 255, 0.9);
            border-bottom: 1px solid var(--border-color);
        }

        body.light-theme .search-status {
            color: rgba(0, 0, 0, 0.8);
            border-bottom-color: var(--border-color-light);
        }

        .search-results {
            flex: 1;
            overflow-y: auto;
            padding: 0 0 20px 0;
        }

        .search-result-group {
            border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        }

        body.light-theme .search-result-group {
            border-bottom-color: rgba(0, 0, 0, 0.05);
        }

        .search-result-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 14px 20px;
            cursor: pointer;
            transition: background 0.2s;
        }

        .search-result-header:hover {
            background: rgba(255, 255, 255, 0.05);
        }

        .search-result-header.active {
            background: rgba(var(--color-primary-rgb), 0.15);
        }

        body.light-theme .search-result-header:hover {
            background: rgba(0, 0, 0, 0.05);
        }

        body.light-theme .search-result-header.active {
            background: rgba(var(--color-primary-rgb), 0.15);
        }

        .search-result-page-label {
            font-size: 14px;
            font-weight: 500;
            color: rgba(255, 255, 255, 0.9);
        }

        body.light-theme .search-result-page-label {
            color: rgba(0, 0, 0, 0.8);
        }

        .search-result-count {
            font-size: 13px;
            color: rgba(255, 255, 255, 0.5);
        }

        body.light-theme .search-result-count {
            color: rgba(0, 0, 0, 0.5);
        }

        /* ===== Reading Mode ===== */

        /* Softer background for reduced eye strain */
        body.reading-mode {
            --bg-page: #141420;
        }
        body.reading-mode.light-theme {
            --bg-page-light: #f0f0f5;
        }

        /* Auto-hide toolbar */
        body.reading-mode .bottom-toolbar {
            transform: translateX(-50%) translateY(calc(100% + 40px));
            opacity: 0;
            transition: transform 0.35s ease, opacity 0.35s ease;
        }
        body.reading-mode .bottom-toolbar.reading-toolbar-visible {
            transform: translateX(-50%) translateY(0);
            opacity: 1;
        }
        /* Fullwidth toolbar variants */
        body.reading-mode.layout-bottom-fullwidth .bottom-toolbar {
            transform: translateY(calc(100% + 40px));
        }
        body.reading-mode.layout-bottom-fullwidth .bottom-toolbar.reading-toolbar-visible {
            transform: translateY(0);
        }
        body.reading-mode.layout-top-center .bottom-toolbar {
            transform: translateX(-50%) translateY(calc(-100% - 40px));
        }
        body.reading-mode.layout-top-center .bottom-toolbar.reading-toolbar-visible {
            transform: translateX(-50%) translateY(0);
        }
        body.reading-mode.layout-top-fullwidth .bottom-toolbar {
            transform: translateY(calc(-100% - 40px));
        }
        body.reading-mode.layout-top-fullwidth .bottom-toolbar.reading-toolbar-visible {
            transform: translateY(0);
        }

        /* Hide side navigation arrows */
        body.reading-mode .side-nav {
            opacity: 1;
            transition: opacity 0.3s ease;
        }

        /* Hide minimap */
        body.reading-mode .minimap {
            opacity: 0 !important;
            pointer-events: none !important;
            transition: opacity 0.3s ease;
        }

        /* Hide top-right controls */
        body.reading-mode .top-right-controls {
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.3s ease;
        }

        /* ===== Vertical PDF Viewer ===== */
        body.vertical-viewer #canvas-container {
            display: none;
        }
        body.vertical-viewer .side-nav {
            opacity: 1;
            pointer-events: auto;
        }
        body.vertical-viewer .minimap {
            opacity: 0 !important;
            pointer-events: none !important;
        }
        body.vertical-viewer .page-container {
            display: none;
        }
        #verticalViewerContainer {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            overflow-y: auto;
            overflow-x: hidden;
            z-index: 5;
            background: var(--bg-page);
            padding: 30px 0 120px;
        }
        body.vertical-viewer #verticalViewerContainer {
            display: block;
        }
        body.light-theme #verticalViewerContainer {
            background: var(--bg-page-light);
        }
        .vertical-viewer-page {
            display: flex;
            flex-direction: column;
            align-items: center;
            margin: 16px auto;
            max-width: 900px;
            padding: 0 20px;
        }
        .vertical-viewer-page img {
            width: 100%;
            max-width: 800px;
            height: auto;
            display: block;
            box-shadow: 0 2px 16px rgba(0, 0, 0, 0.35);
            border-radius: 3px;
        }
        .vertical-viewer-page-number {
            margin-top: 8px;
            font-size: 12px;
            color: rgba(255, 255, 255, 0.4);
            user-select: none;
        }
        body.light-theme .vertical-viewer-page-number {
            color: rgba(0, 0, 0, 0.35);
        }
        body.light-theme .vertical-viewer-page img {
            box-shadow: 0 2px 16px rgba(0, 0, 0, 0.12);
        }

        /* Vertical Viewer Spread Mode (2-page view) */
        #verticalViewerContainer.spread-mode .vertical-viewer-spread {
            max-width: 1400px;
        }
        .spread-pages {
            display: flex;
            justify-content: center;
            gap: 4px;
            width: 100%;
        }
        .spread-page {
            flex: 0 1 auto;
            max-width: 50%;
            position: relative;
        }
        .spread-page img {
            width: 100%;
            max-width: 600px;
            height: auto;
            display: block;
            box-shadow: 0 2px 16px rgba(0, 0, 0, 0.35);
            border-radius: 3px;
        }
        .spread-page-left img {
            border-radius: 3px 0 0 3px;
        }
        .spread-page-right img {
            border-radius: 0 3px 3px 0;
        }
        .spread-page-single {
            display: flex;
            justify-content: center;
            position: relative;
        }
        .spread-page-single img {
            max-width: 600px;
            width: 100%;
            height: auto;
            display: block;
            box-shadow: 0 2px 16px rgba(0, 0, 0, 0.35);
            border-radius: 3px;
        }
        body.light-theme .spread-page img,
        body.light-theme .spread-page-single img {
            box-shadow: 0 2px 16px rgba(0, 0, 0, 0.12);
        }

        /* ===== Horizontal PDF Viewer ===== */
        body.horizontal-viewer #canvas-container {
            display: none;
        }
        body.horizontal-viewer .side-nav {
            opacity: 1;
            pointer-events: auto;
        }
        body.horizontal-viewer .minimap {
            opacity: 0 !important;
            pointer-events: none !important;
        }
        body.horizontal-viewer .page-container {
            display: none;
        }
        #horizontalViewerContainer {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            overflow-x: auto;
            overflow-y: hidden;
            z-index: 5;
            background: var(--bg-page);
            padding: 0 60px;
        }
        body.horizontal-viewer #horizontalViewerContainer {
            display: flex;
            align-items: center;
        }
        body.light-theme #horizontalViewerContainer {
            background: var(--bg-page-light);
        }
        .horizontal-viewer-inner {
            display: flex;
            flex-direction: row;
            align-items: center;
            gap: 30px;
            padding: 20px 40px;
            min-width: min-content;
        }
        .horizontal-viewer-page {
            display: flex;
            flex-direction: column;
            align-items: center;
            flex-shrink: 0;
        }
        .horizontal-viewer-page img {
            height: calc(100vh - 180px);
            width: auto;
            max-height: 800px;
            display: block;
            box-shadow: 0 2px 16px rgba(0, 0, 0, 0.35);
            border-radius: 3px;
        }
        .horizontal-viewer-page-number {
            margin-top: 10px;
            font-size: 12px;
            color: rgba(255, 255, 255, 0.4);
            user-select: none;
        }
        body.light-theme .horizontal-viewer-page-number {
            color: rgba(0, 0, 0, 0.35);
        }
        body.light-theme .horizontal-viewer-page img {
            box-shadow: 0 2px 16px rgba(0, 0, 0, 0.12);
        }

        /* Horizontal Viewer Spread Mode (2-page view) */
        #horizontalViewerInner.spread-mode .horizontal-viewer-spread {
            min-width: auto;
        }
        .horizontal-spread-pages {
            display: flex;
            align-items: flex-start;
            gap: 4px;
            height: 100%;
        }
        .horizontal-spread-page {
            flex: 0 0 auto;
            height: 100%;
            position: relative;
        }
        .horizontal-spread-page img {
            height: calc(100vh - 180px);
            max-height: 800px;
            width: auto;
            display: block;
            box-shadow: 0 2px 16px rgba(0, 0, 0, 0.35);
            border-radius: 3px;
        }
        .horizontal-spread-left img {
            border-radius: 3px 0 0 3px;
        }
        .horizontal-spread-right img {
            border-radius: 0 3px 3px 0;
        }
        .horizontal-spread-single {
            display: flex;
            justify-content: center;
            align-items: flex-start;
            height: 100%;
            position: relative;
        }
        .horizontal-spread-single img {
            height: calc(100vh - 180px);
            max-height: 800px;
            width: auto;
            display: block;
            box-shadow: 0 2px 16px rgba(0, 0, 0, 0.35);
            border-radius: 3px;
        }
        body.light-theme .horizontal-spread-page img,
        body.light-theme .horizontal-spread-single img {
            box-shadow: 0 2px 16px rgba(0, 0, 0, 0.12);
        }


        /* Share Modal - Premium Side-by-Side Layout */
        .share-modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.7);
            backdrop-filter: blur(8px);
            -webkit-backdrop-filter: blur(8px);
            z-index: 300;
            align-items: center;
            justify-content: center;
        }
        .share-modal.active {
            display: flex;
        }
        .share-modal-content {
            position: relative;
            background: var(--bg-popup, #1e1e2e);
            border-radius: 20px;
            padding: 0;
            max-width: 640px;
            width: 94%;
            box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.06);
            overflow: hidden;
        }
        body.light-theme .share-modal {
            background: rgba(0, 0, 0, 0.3);
        }
        body.light-theme .share-modal-content {
            background: var(--bg-popup-light, #ffffff);
            box-shadow: 0 24px 64px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.06);
        }
        .share-modal-header {
            padding: 20px 24px;
            border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        body.light-theme .share-modal-header {
            border-bottom-color: var(--border-color-light, rgba(0, 0, 0, 0.06));
        }
        .share-modal-title {
            color: var(--text-color, rgba(255, 255, 255, 0.95));
            font-size: 17px;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 10px;
            margin: 0;
        }
        body.light-theme .share-modal-title {
            color: var(--text-color-light, #333333);
        }
        body.light-theme .share-modal-close {
            color: var(--text-color-light, #333);
        }
        body.light-theme .share-qr-hint,
        body.light-theme .share-section-label,
        body.light-theme .share-page-option-label,
        body.light-theme .share-custom-page-hint {
            color: var(--text-color-light, #333);
        }
        body.light-theme .share-link-input {
            color: var(--text-color-light, #333);
        }
        body.light-theme .share-social-btn {
            color: var(--text-color-light, #333);
        }
        .share-modal-title svg {
            width: 22px;
            height: 22px;
            opacity: 0.8;
        }
        .share-modal-close {
            background: rgba(128, 128, 128, 0.1);
            border: none;
            color: var(--text-color, #fff);
            opacity: 0.5;
            cursor: pointer;
            padding: 8px;
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.2s;
        }
        .share-modal-close:hover {
            background: rgba(128, 128, 128, 0.2);
            opacity: 1;
        }
        .share-modal-close svg {
            width: 18px;
            height: 18px;
        }
        .share-modal-body {
            display: flex;
            padding: 24px;
            gap: 28px;
        }
        .share-qr-section {
            flex-shrink: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        .share-qr-container {
            background: white;
            border-radius: 16px;
            padding: 16px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
        }
        .share-qr-container canvas {
            display: block;
            border-radius: 4px;
        }
        .share-qr-hint {
            text-align: center;
            color: var(--text-color, #fff);
            opacity: 0.45;
            font-size: 11px;
            margin-top: 12px;
            line-height: 1.4;
        }
        body.light-theme .share-qr-container {
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            border: 1px solid rgba(0, 0, 0, 0.06);
        }
        .share-options-section {
            flex: 1;
            display: flex;
            flex-direction: column;
            min-width: 0;
        }
        .share-section-label {
            color: var(--text-color, #fff);
            opacity: 0.5;
            font-size: 11px;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            margin-bottom: 10px;
        }
        .share-page-options {
            margin-bottom: 18px;
        }
        .share-page-option {
            display: flex;
            align-items: center;
            padding: 8px 10px;
            margin-bottom: 4px;
            border-radius: 8px;
            cursor: pointer;
            transition: background 0.15s;
        }
        .share-page-option:hover {
            background: rgba(128, 128, 128, 0.1);
        }
        .share-page-option input[type="radio"] {
            width: 18px;
            height: 18px;
            margin-right: 10px;
            accent-color: var(--color-primary, #4a9eff);
            cursor: pointer;
        }
        body.light-theme .share-page-option input[type="radio"] {
            accent-color: var(--color-primary, #4a9eff);
            outline: none;
            box-shadow: none;
            border-color: #c3c4c7;
        }
        .share-page-option input[type="radio"]:focus-visible {
            outline: 2px solid var(--color-primary, #4a9eff);
            outline-offset: 2px;
            border-radius: 50%;
        }
        .share-page-option-label {
            color: var(--text-color, #fff);
            font-size: 13px;
        }
        .share-custom-page {
            display: none;
            margin-left: 26px;
            margin-top: 6px;
            margin-bottom: 4px;
        }
        .share-custom-page.visible {
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .share-custom-page input {
            width: 70px;
            padding: 6px 10px;
            border: 1px solid var(--border-color, rgba(255, 255, 255, 0.15));
            border-radius: 6px;
            background: rgba(128, 128, 128, 0.08);
            color: var(--text-color);
            font-size: 13px;
            text-align: center;
        }
        .share-custom-page input:focus {
            outline: none;
            border-color: var(--color-primary, #4a9eff);
            background: rgba(255, 255, 255, 0.12);
        }
        /* share-custom-page uses var(--border-color) + neutral bg — auto-adapts */
        .share-custom-page-hint {
            color: var(--text-color, #fff);
            opacity: 0.4;
            font-size: 12px;
        }
        .share-link-section {
            margin-bottom: 18px;
        }
        .share-link-row {
            display: flex;
            gap: 8px;
        }
        .share-link-input {
            flex: 1;
            padding: 10px 12px;
            border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
            border-radius: 8px;
            background: rgba(128, 128, 128, 0.08);
            color: var(--text-color, #fff);
            font-size: 12px;
            font-family: 'SF Mono', 'Consolas', monospace;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            min-width: 0;
        }
        body.light-theme .share-link-input {
            background: rgba(0, 0, 0, 0.03);
            border-color: var(--border-color, rgba(0, 0, 0, 0.1));
        }
        body.light-theme .share-custom-page input {
            background: rgba(0, 0, 0, 0.03);
            border-color: var(--border-color-light, rgba(0, 0, 0, 0.1));
            color: var(--text-color-light, #333);
        }
        body.light-theme .share-custom-page input:focus {
            background: #fff;
            color: var(--text-color-light, #333);
        }
        body.light-theme .share-custom-page-hint {
            color: var(--text-color-light, #333);
        }
        .share-copy-btn {
            padding: 10px 14px;
            border: none;
            border-radius: 8px;
            background: color-mix(in srgb, var(--color-primary, #4a9eff) 70%, #000);
            color: white;
            font-size: 12px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s;
            display: flex;
            align-items: center;
            gap: 6px;
            white-space: nowrap;
        }
        .share-copy-btn:hover {
            background: color-mix(in srgb, var(--color-primary, #4a9eff) 60%, #000);
            transform: translateY(-1px);
        }
        .share-copy-btn:active {
            transform: translateY(0);
        }
        .share-copy-btn svg {
            width: 14px;
            height: 14px;
        }
        .share-social-section {
            margin-top: auto;
        }
        .share-social-buttons {
            display: flex;
            gap: 8px;
        }
        .share-social-btn {
            flex: 1;
            height: 42px;
            border: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
            border-radius: 10px;
            background: rgba(128, 128, 128, 0.08);
            color: var(--text-color, #fff);
            opacity: 0.7;
            cursor: pointer;
            transition: all 0.2s;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .share-social-btn:hover {
            background: rgba(128, 128, 128, 0.15);
            opacity: 1;
            transform: translateY(-1px);
        }
        .share-social-btn:active {
            transform: translateY(0);
        }
        .share-social-btn svg {
            width: 20px;
            height: 20px;
        }
        body.light-theme .share-social-btn {
            background: rgba(0, 0, 0, 0.04);
            border-color: var(--border-color, rgba(0, 0, 0, 0.08));
        }
        body.light-theme .share-social-btn:hover {
            background: rgba(0, 0, 0, 0.08);
        }
        /* Specific social button colors on hover */
        .share-social-btn[data-platform="facebook"]:hover {
            background: rgba(24, 119, 242, 0.2);
            color: #1877f2;
        }
        .share-social-btn[data-platform="twitter"]:hover {
            background: rgba(0, 0, 0, 0.15);
            color: var(--text-color);
        }
        body.light-theme .share-social-btn[data-platform="twitter"]:hover {
            background: rgba(0, 0, 0, 0.1);
            color: #000;
        }
        .share-social-btn[data-platform="linkedin"]:hover {
            background: rgba(10, 102, 194, 0.2);
            color: #0a66c2;
        }
        .share-social-btn[data-platform="whatsapp"]:hover {
            background: rgba(37, 211, 102, 0.2);
            color: #25d366;
        }
        .share-social-btn[data-platform="pinterest"]:hover {
            background: rgba(230, 0, 35, 0.2);
            color: #e60023;
        }
        .share-social-btn[data-platform="email"]:hover {
            background: rgba(234, 67, 53, 0.2);
            color: #ea4335;
        }
        /* Responsive: stack on mobile */
        @media (max-width: 560px) {
            .share-modal-content {
                max-width: 95%;
            }
            .share-modal-body {
                flex-direction: column;
                align-items: center;
                gap: 20px;
                padding: 20px;
            }
            .share-qr-section {
                width: 100%;
            }
            .share-options-section {
                width: 100%;
            }
            .share-qr-container canvas {
                width: 140px;
                height: 140px;
            }
            .share-social-buttons {
                flex-wrap: wrap;
            }
            .share-social-btn {
                flex: 0 0 calc(33.33% - 6px);
            }
        }

        /* Reading indicator - minimal page counter */
        .reading-indicator {
            position: fixed;
            bottom: 14px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0, 0, 0, 0.75);
            color: rgba(255, 255, 255, 0.95);
            padding: 5px 16px;
            border-radius: 14px;
            font-size: 12px;
            font-weight: 500;
            z-index: 90;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.3s ease;
            backdrop-filter: blur(8px);
        }
        body.reading-mode .reading-indicator {
            opacity: 1;
        }
        /* Hide indicator when toolbar is visible */
        body.reading-mode .bottom-toolbar.reading-toolbar-visible ~ .reading-indicator {
            opacity: 0;
        }
        body.light-theme .reading-indicator {
            background: rgba(255, 255, 255, 0.95);
            color: rgba(0, 0, 0, 0.85);
        }

        /* Edge click zones for page turning */
        .reading-click-zone {
            position: fixed;
            top: 0;
            width: 20%;
            height: 100%;
            z-index: 55;
            cursor: pointer;
            display: none;
        }
        body.reading-mode .reading-click-zone {
            display: block;
        }
        .reading-click-zone.left {
            left: 0;
            cursor: w-resize;
        }
        .reading-click-zone.right {
            right: 0;
            cursor: e-resize;
        }
        .reading-click-zone:hover {
            background: rgba(255, 255, 255, 0.015);
        }
        body.light-theme .reading-click-zone:hover {
            background: rgba(0, 0, 0, 0.015);
        }

        /* ===== Scroll-Native Reading Mode (focused single-page-at-a-time) ===== */

        /* Vertical viewer — snap pages to viewport center */
        body.scroll-reading-mode #verticalViewerContainer {
            scroll-snap-type: y mandatory;
            padding-top: 0;
            padding-bottom: 0;
        }
        body.scroll-reading-mode .vertical-viewer-page,
        body.scroll-reading-mode .vertical-viewer-spread {
            scroll-snap-align: center;
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            margin: 0 auto;
            padding: 20px;
        }
        body.scroll-reading-mode .vertical-viewer-page img {
            max-height: calc(100vh - 80px);
            width: auto;
            max-width: 100%;
        }
        body.scroll-reading-mode .vertical-viewer-spread .spread-pages img {
            max-height: calc(100vh - 80px);
        }
        body.scroll-reading-mode .vertical-viewer-page-number {
            display: none;
        }

        /* Horizontal viewer — snap pages to viewport center */
        body.scroll-reading-mode #horizontalViewerContainer {
            scroll-snap-type: x mandatory;
        }
        body.scroll-reading-mode .horizontal-viewer-page,
        body.scroll-reading-mode .horizontal-viewer-spread {
            scroll-snap-align: center;
            min-width: 100vw;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        body.scroll-reading-mode .horizontal-viewer-page img {
            max-height: calc(100vh - 80px);
            height: auto;
            max-width: calc(100vw - 80px);
        }
        body.scroll-reading-mode .horizontal-viewer-spread .horizontal-spread-pages img {
            max-height: calc(100vh - 80px);
        }
        body.scroll-reading-mode .horizontal-viewer-page-number {
            display: none;
        }

        /* Minimap */
        .minimap {
            position: fixed;
            top: 20px;
            left: 20px;
            width: 160px;
            background: rgba(30, 30, 40, 0.95);
            border-radius: 8px;
            padding: 8px;
            z-index: 180;
            opacity: 0;
            transform: translateY(-10px);
            transition: opacity 0.3s ease, transform 0.3s ease;
            pointer-events: none;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
            border: 1px solid var(--border-color);
        }

        .minimap.active {
            opacity: 1;
            transform: translateY(0);
            pointer-events: auto;
        }

        body.light-theme .minimap {
            background: rgba(255, 255, 255, 0.95);
            border-color: var(--border-color-light);
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
        }

        .minimap-canvas-container {
            position: relative;
            width: 100%;
            border-radius: 4px;
            overflow: hidden;
            cursor: pointer;
        }

        .minimap-canvas {
            width: 100%;
            display: block;
            border-radius: 4px;
        }

        .minimap-viewport {
            position: absolute;
            border: 2px solid var(--color-primary);
            background: rgba(var(--color-primary-rgb), 0.15);
            pointer-events: none;
            box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3);
        }

        /* Share Popup */
        .share-popup {
            position: fixed;
            bottom: 70px;
            left: 0;
            background: var(--bg-popup);
            border-radius: 8px;
            padding: 10px 12px;
            display: flex;
            gap: 8px;
            z-index: 300;
            opacity: 0;
            visibility: hidden;
            transition: opacity 0.2s ease, visibility 0.2s ease;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
        }

        .share-popup.active {
            opacity: 1;
            visibility: visible;
        }

        .share-option {
            display: flex;
            align-items: center;
            justify-content: center;
            background: transparent;
            border: none;
            border-radius: 6px;
            padding: 8px;
            cursor: pointer;
            transition: all 0.2s ease;
            color: rgba(255, 255, 255, 0.8);
        }

        .share-option:hover {
            background: rgba(255, 255, 255, 0.1);
            color: var(--text-color);
        }

        .share-option svg {
            width: 22px;
            height: 22px;
        }

        body.light-theme .share-popup {
            background: var(--bg-popup-light);
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
        }

        body.light-theme .share-option {
            color: rgba(0, 0, 0, 0.6);
        }

        body.light-theme .share-option:hover {
            background: rgba(0, 0, 0, 0.08);
            color: rgba(0, 0, 0, 0.9);
        }

        /* Share popup positioning handled by JavaScript */

        /* More Options Popup */
        .more-popup {
            position: fixed;
            bottom: 80px;
            left: 0;
            background: var(--bg-popup);
            border-radius: 5px;
            padding: 8px 0;
            min-width: 200px;
            z-index: 300;
            opacity: 0;
            visibility: hidden;
            transition: opacity 0.2s ease, visibility 0.2s ease;
            box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
        }

        .more-popup.active {
            opacity: 1;
            visibility: visible;
        }

        .more-popup-arrow {
            position: absolute;
            bottom: -8px;
            left: 50%;
            width: 0;
            height: 0;
            border-left: 10px solid transparent;
            border-right: 10px solid transparent;
            border-top: 10px solid var(--bg-popup);
        }

        .more-option {
            display: flex;
            align-items: center;
            gap: 14px;
            width: 100%;
            padding: 12px 20px;
            background: transparent;
            border: none;
            color: rgba(255, 255, 255, 0.85);
            font-size: 14px;
            cursor: pointer;
            transition: all 0.15s ease;
            text-align: left;
        }

        .more-option:hover {
            background: rgba(255, 255, 255, 0.08);
            color: var(--text-color);
        }

        .more-option.active {
            background: rgba(255, 255, 255, 0.15);
            color: #ffffff;
        }

        .more-option svg {
            width: 22px;
            height: 22px;
            flex-shrink: 0;
            opacity: 0.8;
        }

        .more-option:hover svg {
            opacity: 1;
        }

        .more-option.active svg {
            opacity: 1;
        }

        .more-option.disabled {
            opacity: 0.35;
            cursor: not-allowed;
            pointer-events: none;
        }

        .more-popup-divider {
            height: 1px;
            background: var(--border-color);
            margin: 8px 0;
        }

        .more-popup-section-title {
            padding: 8px 20px 4px;
            font-size: 11px;
            font-weight: 600;
            color: rgba(255, 255, 255, 0.45);
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        /* PDF Link Overlay */
        .pdf-link-overlay {
            position: fixed;
            top: 0; left: 0;
            width: 100%; height: 100%;
            pointer-events: none;
            z-index: 59;
            transition: opacity 0.15s;
        }
        .pdf-link-overlay .pdf-link {
            position: absolute;
            pointer-events: auto;
            cursor: pointer;
            border-radius: 2px;
            transition: background 0.15s;
        }
        .pdf-link-overlay .pdf-link:hover {
            background: rgba(59, 130, 246, 0.15);
            outline: 1.5px solid rgba(59, 130, 246, 0.4);
        }
        .pdf-link-overlay .pdf-link:active {
            background: rgba(59, 130, 246, 0.25);
        }

        /* Links inside vertical/horizontal viewer pages */
        .viewer-page-links {
            position: absolute;
            top: 0; left: 0;
            width: 100%; height: 100%;
            pointer-events: none;
        }
        .viewer-page-links .pdf-link {
            position: absolute;
            pointer-events: auto;
            cursor: pointer;
            border-radius: 2px;
            transition: background 0.15s;
        }
        .viewer-page-links .pdf-link:hover {
            background: rgba(59, 130, 246, 0.15);
            outline: 1.5px solid rgba(59, 130, 246, 0.4);
        }
        .viewer-page-links .pdf-link:active {
            background: rgba(59, 130, 246, 0.25);
        }

        /* ========== PDF Media Overlay (video, audio, 3D, rich media) ========== */
        .pdf-media-overlay {
            position: fixed;
            top: 0; left: 0;
            width: 100%; height: 100%;
            pointer-events: none;
            z-index: 58;
        }
        .pdf-media-overlay .media-element {
            position: absolute;
            pointer-events: auto;
        }
        .media-player-container {
            width: 100%; height: 100%;
            background: #000;
            border-radius: 4px;
            overflow: hidden;
            box-shadow: 0 2px 12px rgba(0,0,0,0.5);
            display: flex;
            flex-direction: column;
            position: relative;
        }
        .media-player-container video {
            width: 100%; height: 100%;
            object-fit: contain;
            display: block;
        }
        .media-player-controls {
            position: absolute;
            bottom: 0; left: 0; right: 0;
            background: linear-gradient(transparent, rgba(0,0,0,0.8));
            padding: 8px 10px 6px;
            display: flex;
            align-items: center;
            gap: 8px;
            opacity: 0;
            transition: opacity 0.2s;
        }
        .media-player-container:hover .media-player-controls {
            opacity: 1;
        }
        .media-player-controls button {
            background: none; border: none;
            color: var(--text-color); cursor: pointer;
            padding: 2px; display: flex;
            align-items: center; justify-content: center;
        }
        .media-player-controls button svg {
            width: 18px; height: 18px;
        }
        .media-player-controls .media-progress {
            flex: 1; height: 4px;
            background: rgba(255,255,255,0.25);
            border-radius: 2px; cursor: pointer;
            position: relative;
        }
        .media-player-controls .media-progress-fill {
            height: 100%; background: #3b82f6;
            border-radius: 2px; width: 0%;
            transition: width 0.1s linear;
        }
        .media-player-controls .media-time {
            color: rgba(255,255,255,0.7);
            font-size: 11px; white-space: nowrap;
            font-family: monospace;
        }
        /* Audio player */
        .media-audio-container {
            width: 100%; height: 100%;
            background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
            border-radius: 4px;
            box-shadow: 0 2px 12px rgba(0,0,0,0.5);
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            position: relative;
        }
        .media-audio-icon {
            width: 32px; height: 32px;
            color: rgba(255,255,255,0.6);
            margin-bottom: 8px;
        }
        .media-audio-container .media-player-controls {
            opacity: 1;
            position: relative;
            background: rgba(0,0,0,0.3);
            border-radius: 0 0 4px 4px;
        }
        /* 3D Viewer */
        .viewer-3d-container {
            width: 100%; height: 100%;
            background: linear-gradient(135deg, #1a1a24 0%, #0d1117 100%);
            border-radius: 4px;
            overflow: hidden;
            box-shadow: 0 2px 12px rgba(0,0,0,0.5);
            position: relative;
        }
        .viewer-3d-container canvas {
            width: 100% !important;
            height: 100% !important;
            display: block;
        }
        .viewer-3d-toolbar {
            position: absolute;
            top: 6px; right: 6px;
            display: flex; gap: 4px;
            z-index: 2;
        }
        .viewer-3d-toolbar button {
            background: rgba(0,0,0,0.5);
            border: 1px solid rgba(255,255,255,0.15);
            color: #fff; border-radius: 4px;
            width: 28px; height: 28px;
            cursor: pointer; display: flex;
            align-items: center; justify-content: center;
            transition: background 0.15s;
        }
        .viewer-3d-toolbar button:hover {
            background: rgba(59,130,246,0.5);
        }
        .viewer-3d-toolbar button svg {
            width: 16px; height: 16px;
        }
        .viewer-3d-loading {
            position: absolute;
            top: 50%; left: 50%;
            transform: translate(-50%, -50%);
            color: rgba(255,255,255,0.5);
            font-size: 13px;
            text-align: center;
        }
        /* Placeholder for unsupported/unextractable media */
        .media-placeholder {
            width: 100%; height: 100%;
            border: 2px dashed rgba(255,255,255,0.2);
            border-radius: 4px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            background: rgba(0,0,0,0.3);
            cursor: pointer;
            transition: border-color 0.2s, background 0.2s;
        }
        .media-placeholder:hover {
            border-color: rgba(59,130,246,0.5);
            background: rgba(59,130,246,0.1);
        }
        .media-placeholder-icon {
            width: 36px; height: 36px;
            color: rgba(255,255,255,0.4);
            margin-bottom: 8px;
        }
        .media-placeholder-label {
            color: rgba(255,255,255,0.5);
            font-size: 12px;
            text-align: center;
            padding: 0 8px;
        }
        /* Small corner badge for unsupported 3D formats (lets PDF snapshot show through) */
        .media-3d-badge {
            position: absolute;
            top: 6px; left: 6px;
            background: rgba(0,0,0,0.65);
            backdrop-filter: blur(4px);
            -webkit-backdrop-filter: blur(4px);
            border: 1px solid rgba(255,255,255,0.15);
            border-radius: 6px;
            padding: 5px 10px;
            display: flex;
            align-items: center;
            gap: 6px;
            cursor: pointer;
            transition: background 0.2s, border-color 0.2s;
            z-index: 2;
            pointer-events: auto;
        }
        .media-3d-badge:hover {
            background: rgba(59,130,246,0.7);
            border-color: rgba(59,130,246,0.6);
        }
        .media-3d-badge svg {
            width: 16px; height: 16px;
            color: rgba(255,255,255,0.85);
            flex-shrink: 0;
        }
        .media-3d-badge span {
            color: rgba(255,255,255,0.9);
            font-size: 11px;
            font-weight: 500;
            white-space: nowrap;
        }
        /* Rich media iframe */
        .richmedia-container {
            width: 100%; height: 100%;
            border-radius: 4px;
            overflow: hidden;
            box-shadow: 0 2px 12px rgba(0,0,0,0.5);
        }
        .richmedia-container iframe {
            width: 100%; height: 100%;
            border: none;
        }
        /* Viewer mode media (percentage-based inside page wrappers) */
        .viewer-page-media {
            position: absolute;
            top: 0; left: 0;
            width: 100%; height: 100%;
            pointer-events: none;
        }
        .viewer-page-media .media-element {
            position: absolute;
            pointer-events: auto;
        }

        .vertical-viewer-page, .horizontal-viewer-page {
            position: relative;
        }

        /* Page Video Overlay */
        .page-video-overlay {
            position: fixed;
            top: 0; left: 0;
            width: 100%; height: 100%;
            pointer-events: none;
            z-index: 57;
        }
        .page-video-container {
            position: absolute;
            pointer-events: auto;
            background: #000;
            border-radius: 4px;
            overflow: hidden;
            box-shadow: 0 4px 20px rgba(0,0,0,0.5);
        }
        .page-video-container video {
            width: 100%;
            height: 100%;
            object-fit: cover;
            display: block;
        }
        .page-video-container.no-controls video::-webkit-media-controls {
            display: none !important;
        }
        .page-video-container.no-controls video::-webkit-media-controls-enclosure {
            display: none !important;
        }
        /* Custom play button for videos without controls */
        .page-video-play-btn {
            position: absolute;
            top: 50%; left: 50%;
            transform: translate(-50%, -50%);
            width: 60px; height: 60px;
            background: rgba(0,0,0,0.6);
            border: none;
            border-radius: 50%;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.2s ease;
            opacity: 0;
            pointer-events: none;
        }
        .page-video-container:hover .page-video-play-btn,
        .page-video-container.paused .page-video-play-btn {
            opacity: 1;
            pointer-events: auto;
        }
        .page-video-play-btn:hover {
            background: rgba(0,0,0,0.8);
            transform: translate(-50%, -50%) scale(1.1);
        }
        .page-video-play-btn svg {
            width: 28px; height: 28px;
            color: var(--text-color);
            margin-left: 4px;
        }
        .page-video-container.playing .page-video-play-btn svg.play-icon { display: none; }
        .page-video-container.playing .page-video-play-btn svg.pause-icon { display: block; }
        .page-video-container.paused .page-video-play-btn svg.play-icon { display: block; }
        .page-video-container.paused .page-video-play-btn svg.pause-icon { display: none; }
        .page-video-play-btn svg.pause-icon { display: none; margin-left: 0; }
        /* Mute toggle button */
        .page-video-mute-btn {
            position: absolute;
            bottom: 10px; right: 10px;
            width: 36px; height: 36px;
            background: rgba(0,0,0,0.6);
            border: none;
            border-radius: 50%;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            opacity: 0;
            transition: opacity 0.2s ease;
        }
        .page-video-container:hover .page-video-mute-btn {
            opacity: 1;
        }
        .page-video-mute-btn:hover {
            background: rgba(0,0,0,0.8);
        }
        .page-video-mute-btn svg {
            width: 18px; height: 18px;
            color: var(--text-color);
        }
        .page-video-mute-btn .muted-icon { display: none; }
        .page-video-container.muted .page-video-mute-btn .muted-icon { display: block; }
        .page-video-container.muted .page-video-mute-btn .unmuted-icon { display: none; }
        .page-video-container:not(.muted) .page-video-mute-btn .unmuted-icon { display: block; }
        /* Video in viewer modes */
        .viewer-page-video {
            position: absolute;
            pointer-events: auto;
            background: #000;
            border-radius: 4px;
            overflow: hidden;
        }
        .viewer-page-video video {
            width: 100%; height: 100%;
            object-fit: cover;
        }


        body.light-theme .more-popup-divider {
            background: var(--border-color-light);
        }

        body.light-theme .more-popup-section-title {
            color: rgba(0, 0, 0, 0.4);
        }

        body.light-theme .more-popup {
            background: var(--bg-popup-light);
            box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
        }

        body.light-theme .more-popup-arrow {
            border-top-color: var(--bg-popup-light);
        }

        body.light-theme .more-option {
            color: rgba(0, 0, 0, 0.75);
        }

        body.light-theme .more-option:hover {
            background: rgba(0, 0, 0, 0.06);
            color: rgba(0, 0, 0, 0.9);
        }

        body.light-theme .more-option.active {
            background: rgba(0, 0, 0, 0.08);
            color: rgba(0, 0, 0, 0.9);
        }

        /* More popup positioning handled by JavaScript */

        /* Audio Player - Floating Mini Player */
        .audio-player {
            position: fixed;
            bottom: 100px;
            left: 50%;
            transform: translateX(-50%) translateY(20px);
            background: var(--bg-toolbar);
            border-radius: 16px;
            padding: 12px 16px;
            min-width: 420px;
            max-width: 90vw;
            z-index: 300;
            opacity: 0;
            visibility: hidden;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            backdrop-filter: blur(20px);
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.1);
        }

        .audio-player.active {
            opacity: 1;
            visibility: visible;
            transform: translateX(-50%) translateY(0);
        }

        .audio-player-main {
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .audio-player-controls {
            display: flex;
            align-items: center;
            gap: 4px;
        }

        .audio-player-btn {
            width: 36px;
            height: 36px;
            border: none;
            border-radius: 50%;
            background: transparent;
            color: rgba(255, 255, 255, 0.7);
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.2s;
        }

        .audio-player-btn:hover {
            background: rgba(255, 255, 255, 0.1);
            color: var(--text-color);
        }

        .audio-player-btn svg {
            width: 18px;
            height: 18px;
        }

        .audio-player-btn.play-btn {
            width: 44px;
            height: 44px;
            background: var(--color-primary);
            color: white;
        }

        .audio-player-btn.play-btn:hover {
            background: var(--color-primary-hover);
            transform: scale(1.05);
        }

        .audio-player-btn.play-btn svg {
            width: 22px;
            height: 22px;
        }

        .audio-player-text {
            flex: 1;
            min-width: 0;
            display: flex;
            flex-direction: column;
            gap: 6px;
        }

        .audio-player-sentence {
            font-size: 14px;
            line-height: 1.4;
            color: rgba(255, 255, 255, 0.9);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            min-height: 20px;
        }

        .audio-player-sentence .highlight {
            background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-hover) 100%);
            color: white;
            padding: 1px 4px;
            border-radius: 3px;
            font-weight: 500;
        }

        .audio-player-progress-row {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .audio-player-progress {
            flex: 1;
            height: 4px;
            background: rgba(255, 255, 255, 0.15);
            border-radius: 2px;
            cursor: pointer;
            overflow: hidden;
        }

        .audio-player-progress:hover {
            height: 6px;
        }

        .audio-player-progress-fill {
            height: 100%;
            background: var(--color-primary);
            border-radius: 2px;
            transition: width 0.15s ease;
        }

        .audio-player-time {
            font-size: 11px;
            color: rgba(255, 255, 255, 0.5);
            min-width: 70px;
            text-align: right;
        }

        .audio-player-right {
            display: flex;
            align-items: center;
            gap: 4px;
            margin-left: 8px;
        }

        .audio-player-speed {
            padding: 4px 10px;
            background: rgba(255, 255, 255, 0.1);
            border: none;
            border-radius: 5px;
            color: rgba(255, 255, 255, 0.8);
            font-size: 12px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.2s;
            min-width: 42px;
        }

        .audio-player-speed:hover {
            background: rgba(255, 255, 255, 0.2);
            color: var(--text-color);
        }

        .audio-player-close {
            width: 28px;
            height: 28px;
            border: none;
            border-radius: 50%;
            background: transparent;
            color: rgba(255, 255, 255, 0.5);
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.2s;
        }

        .audio-player-close:hover {
            background: rgba(255, 99, 99, 0.2);
            color: #ff9999;
        }

        .audio-player-close svg {
            width: 14px;
            height: 14px;
        }

        /* Settings Panel */
        .audio-player-settings {
            display: none;
            padding-top: 12px;
            margin-top: 12px;
            border-top: 1px solid var(--border-color);
        }

        .audio-player-settings.active {
            display: block;
        }

        .audio-player-settings-row {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 10px;
        }

        .audio-player-settings-row:last-child {
            margin-bottom: 0;
        }

        .audio-player-settings-label {
            font-size: 12px;
            color: rgba(255, 255, 255, 0.6);
            min-width: 50px;
        }

        .audio-player-settings select {
            flex: 1;
            padding: 6px 10px;
            background: rgba(255, 255, 255, 0.1);
            border: 1px solid var(--border-color);
            border-radius: 6px;
            color: var(--text-color);
            font-size: 12px;
            cursor: pointer;
            outline: none;
        }

        .audio-player-settings select option {
            background: var(--bg-sidebar);
            color: var(--text-color);
        }

        .audio-player-toggle {
            display: flex;
            align-items: center;
            gap: 8px;
            cursor: pointer;
        }

        .audio-player-toggle input[type="checkbox"] {
            width: 16px;
            height: 16px;
            cursor: pointer;
            accent-color: var(--color-primary);
        }

        .audio-player-toggle .toggle-text {
            font-size: 12px;
            color: rgba(255, 255, 255, 0.7);
        }

        body.light-theme .audio-player-toggle .toggle-text {
            color: rgba(0, 0, 0, 0.6);
        }

        .tts-status-text {
            font-size: 11px;
            padding: 4px 8px;
            border-radius: 4px;
        }

        .tts-status-text.success {
            color: #4ade80;
            background: rgba(74, 222, 128, 0.1);
        }

        .tts-status-text.error {
            color: #f87171;
            background: rgba(248, 113, 113, 0.1);
        }

        .tts-status-text.warning {
            color: #fbbf24;
            background: rgba(251, 191, 36, 0.1);
        }

        .tts-status-text.loading {
            color: #60a5fa;
            background: rgba(96, 165, 250, 0.1);
        }

        body.light-theme .tts-status-text.success {
            background: rgba(74, 222, 128, 0.15);
        }

        body.light-theme .tts-status-text.error {
            background: rgba(248, 113, 113, 0.15);
        }

        body.light-theme .tts-status-text.warning {
            background: rgba(251, 191, 36, 0.15);
        }

        body.light-theme .tts-status-text.loading {
            background: rgba(96, 165, 250, 0.15);
        }

        /* Keyboard hint */
        .audio-player-hint {
            text-align: center;
            padding-top: 8px;
            margin-top: 8px;
            border-top: 1px solid rgba(255, 255, 255, 0.05);
            font-size: 10px;
            color: rgba(255, 255, 255, 0.3);
        }

        .audio-player-hint kbd {
            display: inline-block;
            padding: 2px 5px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 3px;
            font-family: inherit;
            margin: 0 2px;
        }

        /* Light theme */
        body.light-theme .audio-player {
            background: var(--bg-toolbar-light);
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.08);
        }

        body.light-theme .audio-player-btn {
            color: rgba(0, 0, 0, 0.6);
        }

        body.light-theme .audio-player-btn:hover {
            background: rgba(0, 0, 0, 0.08);
            color: rgba(0, 0, 0, 0.9);
        }

        body.light-theme .audio-player-btn.play-btn {
            background: var(--color-primary);
            color: white;
        }

        body.light-theme .audio-player-sentence {
            color: rgba(0, 0, 0, 0.85);
        }

        body.light-theme .audio-player-progress {
            background: rgba(0, 0, 0, 0.1);
        }

        body.light-theme .audio-player-time {
            color: rgba(0, 0, 0, 0.5);
        }

        body.light-theme .audio-player-speed {
            background: rgba(0, 0, 0, 0.08);
            color: rgba(0, 0, 0, 0.7);
        }

        body.light-theme .audio-player-speed:hover {
            background: rgba(0, 0, 0, 0.12);
            color: rgba(0, 0, 0, 0.9);
        }

        body.light-theme .audio-player-close {
            color: rgba(0, 0, 0, 0.4);
        }

        body.light-theme .audio-player-close:hover {
            background: rgba(220, 53, 53, 0.1);
            color: #dc3535;
        }

        body.light-theme .audio-player-settings {
            border-top-color: var(--border-color-light);
        }

        body.light-theme .audio-player-settings-label {
            color: rgba(0, 0, 0, 0.6);
        }

        body.light-theme .audio-player-settings select {
            background: rgba(0, 0, 0, 0.05);
            border-color: var(--border-color-light);
            color: var(--text-color-light);
        }

        body.light-theme .audio-player-settings select option {
            background: white;
            color: var(--text-color-light);
        }

        body.light-theme .audio-player-hint {
            border-top-color: rgba(0, 0, 0, 0.05);
            color: rgba(0, 0, 0, 0.35);
        }

        body.light-theme .audio-player-hint kbd {
            background: rgba(0, 0, 0, 0.08);
        }

        /* Responsive */
        @media (max-width: 500px) {
            .audio-player {
                min-width: auto;
                width: calc(100% - 32px);
                margin: 0 16px;
                left: 0;
                transform: translateX(0) translateY(20px);
            }

            .audio-player.active {
                transform: translateX(0) translateY(0);
            }

            .audio-player-sentence {
                font-size: 13px;
            }

            .audio-player-hint {
                display: none;
            }
        }

        /* Thumbnails Sidebar */
        .thumbnails-sidebar {
            position: fixed;
            top: 0;
            left: 0;
            width: 280px;
            height: 100vh;
            background: var(--bg-sidebar);
            z-index: 200;
            transform: translateX(-100%);
            transition: transform 0.3s ease;
            display: flex;
            flex-direction: column;
        }

        .thumbnails-sidebar.active {
            transform: translateX(0);
        }

        body.light-theme .thumbnails-sidebar {
            background: var(--bg-sidebar-light);
        }

        .thumbnails-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 16px 20px;
            border-bottom: 1px solid var(--border-color);
        }

        body.light-theme .thumbnails-header {
            border-bottom-color: var(--border-color-light);
        }

        .thumbnails-title {
            font-size: 16px;
            font-weight: 600;
            color: var(--text-color);
        }

        body.light-theme .thumbnails-title {
            color: var(--text-color-light);
        }

        .thumbnails-close {
            background: none;
            border: none;
            color: rgba(255, 255, 255, 0.7);
            cursor: pointer;
            padding: 4px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .thumbnails-close:hover {
            color: var(--text-color);
        }

        body.light-theme .thumbnails-close {
            color: rgba(0, 0, 0, 0.5);
        }

        body.light-theme .thumbnails-close:hover {
            color: rgba(0, 0, 0, 0.8);
        }

        .thumbnails-grid {
            flex: 1;
            overflow-y: auto;
            padding: 16px;
            display: flex;
            flex-wrap: wrap;
            gap: 16px 12px;
            align-content: start;
        }

        .thumbnail {
            width: calc(50% - 6px);
            aspect-ratio: 8.5 / 11;
            background: #2a2a35;
            border-radius: 4px;
            cursor: pointer;
            border: 2px solid transparent;
            transition: all 0.2s ease;
            overflow: hidden;
        }

        .thumbnail:hover {
            border-color: rgba(var(--color-primary-rgb), 0.5);
        }

        .thumbnail.active {
            border-color: var(--color-primary);
        }

        .thumbnail img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        body.light-theme .thumbnail {
            background: #e0e0e0;
        }

        /* Bookmarks Sidebar (shell + outline available in Free; user bookmarks Pro-only) */
        .bookmarks-sidebar {
            position: fixed;
            top: 0;
            right: 0;
            width: 300px;
            height: 100vh;
            background: var(--bg-sidebar);
            z-index: 200;
            transform: translateX(100%);
            transition: transform 0.3s ease;
            display: flex;
            flex-direction: column;
        }

        .bookmarks-sidebar.active {
            transform: translateX(0);
        }

        body.light-theme .bookmarks-sidebar {
            background: var(--bg-sidebar-light);
        }

        .bookmarks-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 16px 20px;
            border-bottom: 1px solid var(--border-color);
        }

        body.light-theme .bookmarks-header {
            border-bottom-color: var(--border-color-light);
        }

        .bookmarks-title {
            font-size: 16px;
            font-weight: 600;
            color: var(--text-color);
        }

        body.light-theme .bookmarks-title {
            color: var(--text-color-light);
        }

        .bookmarks-close {
            background: none;
            border: none;
            color: rgba(255, 255, 255, 0.7);
            cursor: pointer;
            padding: 4px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .bookmarks-close:hover {
            color: var(--text-color);
        }

        body.light-theme .bookmarks-close {
            color: rgba(0, 0, 0, 0.5);
        }

        body.light-theme .bookmarks-close:hover {
            color: var(--text-color-light);
        }


        .bookmarks-section-title {
            font-size: 11px;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            color: rgba(255, 255, 255, 0.4);
            padding: 10px 20px 6px;
        }

        body.light-theme .bookmarks-section-title {
            color: rgba(0, 0, 0, 0.4);
        }

        .outline-item {
            display: flex;
            align-items: center;
            padding: 10px 20px;
            cursor: pointer;
            transition: background 0.15s ease;
            gap: 12px;
        }

        .outline-item:hover {
            background: rgba(255, 255, 255, 0.05);
        }

        body.light-theme .outline-item:hover {
            background: rgba(0, 0, 0, 0.05);
        }

        .outline-item-icon {
            width: 30px;
            height: 30px;
            background: rgba(255, 255, 255, 0.08);
            border-radius: 6px;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
        }

        body.light-theme .outline-item-icon {
            background: rgba(0, 0, 0, 0.06);
        }

        .outline-item-icon svg {
            width: 15px;
            height: 15px;
            color: rgba(255, 255, 255, 0.5);
        }

        body.light-theme .outline-item-icon svg {
            color: rgba(0, 0, 0, 0.4);
        }

        .outline-item-info {
            flex: 1;
            min-width: 0;
        }

        .outline-item-title {
            font-size: 13px;
            font-weight: 500;
            color: var(--text-color);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        body.light-theme .outline-item-title {
            color: var(--text-color-light);
        }

        .outline-item-page {
            font-size: 11px;
            color: rgba(255, 255, 255, 0.4);
            flex-shrink: 0;
        }

        body.light-theme .outline-item-page {
            color: rgba(0, 0, 0, 0.4);
        }

        .outline-children {
            padding-left: 16px;
        }




        /* ==================== */
        /* RESPONSIVE STYLES    */
        /* ==================== */

        /* Tablet and below */
        @media (max-width: 1024px) {
            .minimap {
                width: 120px;
            }

            .search-sidebar,
            .thumbnails-sidebar,
            .bookmarks-sidebar,
            .notes-sidebar {
                width: 260px;
            }
        }

        /* Tablet */
        @media (max-width: 768px) {
            .bottom-toolbar {
                padding: 8px 12px;
                gap: 4px;
            }

            .toolbar-btn {
                width: 36px;
                height: 36px;
            }

            .toolbar-btn svg {
                width: 18px;
                height: 18px;
            }

            .toolbar-divider {
                height: 20px;
                margin: 0 6px;
            }

            .page-indicator {
                font-size: 12px;
                padding: 4px 8px;
                min-width: 60px;
            }

            .nav-btn {
                width: 40px;
                height: 40px;
            }

            .nav-btn svg {
                width: 20px;
                height: 20px;
            }

            .search-sidebar,
            .thumbnails-sidebar,
            .bookmarks-sidebar,
            .notes-sidebar {
                width: 100%;
                max-width: 320px;
            }

            .minimap {
                width: 100px;
                top: 10px;
                left: 10px;
            }

            .share-popup {
                bottom: 60px;
            }

            body.layout-top-center .share-popup,
            body.layout-top-fullwidth .share-popup {
                top: 60px;
            }

            .top-right-controls {
                top: 10px;
                right: 10px;
                gap: 6px;
            }

            .top-right-controls button {
                width: 36px;
                height: 36px;
            }

            /* Hide some toolbar buttons on tablet */
            .toolbar-logo {
                display: none;
            }
        }

        /* Mobile */
        @media (max-width: 480px) {
            .bottom-toolbar {
                padding: 6px 8px;
                gap: 2px;
                border-radius: 5px;
            }

            body.layout-bottom-fullwidth .bottom-toolbar,
            body.layout-top-fullwidth .bottom-toolbar {
                padding: 6px 12px;
                border-radius: 0;
            }

            .toolbar-btn {
                width: 32px;
                height: 32px;
            }

            .toolbar-btn svg {
                width: 16px;
                height: 16px;
            }

            .toolbar-divider {
                height: 16px;
                margin: 0 4px;
            }

            .toolbar-left {
                display: none;
            }

            body.layout-bottom-fullwidth .toolbar-left,
            body.layout-top-fullwidth .toolbar-left {
                display: flex;
            }

            .page-indicator {
                font-size: 11px;
                padding: 3px 6px;
                min-width: 50px;
            }

            .nav-btn {
                width: 36px;
                height: 36px;
            }

            .nav-btn svg {
                width: 18px;
                height: 18px;
            }

            .search-sidebar,
            .thumbnails-sidebar {
                width: 100%;
                max-width: 100%;
            }

            .search-header,
            .thumbnails-header {
                padding: 12px 16px;
            }

            .search-input-wrapper {
                padding: 12px 16px;
            }

            .thumbnails-grid {
                padding: 12px;
                gap: 12px 8px;
            }

            .thumbnail {
                width: calc(50% - 4px);
            }

            .minimap {
                width: 80px;
                top: 8px;
                left: 8px;
            }

            .share-popup {
                padding: 8px 10px;
                gap: 6px;
            }

            .share-option {
                padding: 6px;
            }

            .share-option svg {
                width: 20px;
                height: 20px;
            }

            .top-right-controls {
                top: 8px;
                right: 8px;
                gap: 4px;
            }

            .top-right-controls button {
                width: 32px;
                height: 32px;
            }

            #loading {
                width: 240px;
            }

            .loading-title {
                font-size: 16px;
            }

            /* Hide less important buttons on mobile */
            #rotateBtn,
            #downloadBtn,
            #printBtn {
                display: none;
            }

            body.layout-bottom-fullwidth #rotateBtn,
            body.layout-bottom-fullwidth #downloadBtn,
            body.layout-bottom-fullwidth #printBtn,
            body.layout-top-fullwidth #rotateBtn,
            body.layout-top-fullwidth #downloadBtn,
            body.layout-top-fullwidth #printBtn {
                display: flex;
            }

            /* Adjust zoom dropdown */
            .zoom-dropdown {
                font-size: 11px;
                padding: 4px 6px;
                min-width: 50px;
            }
        }

        /* Very small mobile */
        @media (max-width: 360px) {
            .bottom-toolbar {
                padding: 5px 6px;
            }

            .toolbar-btn {
                width: 28px;
                height: 28px;
            }

            .toolbar-btn svg {
                width: 14px;
                height: 14px;
            }

            .toolbar-divider {
                margin: 0 2px;
            }

            .nav-btn {
                width: 32px;
                height: 32px;
            }

            /* Hide more buttons on very small screens */
            #readAloudBtn,
            .divider-center-only {
                display: none;
            }

            .share-popup {
                padding: 6px 8px;
                gap: 4px;
            }

            .share-option svg {
                width: 18px;
                height: 18px;
            }
        }

        /* Touch device optimizations */
        @media (hover: none) and (pointer: coarse) {
            .toolbar-btn:hover {
                background: transparent;
            }

            .toolbar-btn:active {
                background: rgba(255, 255, 255, 0.1);
            }

            .nav-btn:hover {
                background: transparent !important;
                opacity: 0.8;
            }

            .nav-btn:active {
                background: transparent !important;
                opacity: 1;
            }

            /* Larger touch targets for corners */
            .corner-peel {
                width: 100px;
                height: 100px;
            }

            .tooltip {
                display: none !important;
            }
        }

        /* Landscape mobile */
        @media (max-height: 500px) and (orientation: landscape) {
            .bottom-toolbar {
                padding: 4px 8px;
            }

            .toolbar-btn {
                width: 30px;
                height: 30px;
            }

            .nav-btn {
                width: 34px;
                height: 34px;
            }

            .minimap {
                width: 70px;
            }

            .search-sidebar,
            .thumbnails-sidebar {
                width: 50%;
                max-width: 280px;
            }
        }

        /* =============================================
           COMPACT TOOLBAR — media-query responsive
           ============================================= */

        /* Overflow items hidden by default */
        .tncfb-overflow-item { display: none !important; }

        /* Toolbar items disabled in CONFIG.toolbar are hidden via this class.
           The compound selector keeps specificity above the mobile rule that
           force-shows overflow twins (.tncfb-overflow-item{display:flex !important}),
           so a disabled Download/Print/Share stays hidden in the more menu too. */
        .tncfb-config-hidden,
        .tncfb-overflow-item.tncfb-config-hidden { display: none !important; }

        /* ── Compact: < 600px ─────────────────────── */
        @media (max-width: 600px) {
            .bottom-toolbar {
                padding: 6px 8px;
                gap: 2px;
                max-width: calc(100% - 32px);
            }
            .toolbar-btn {
                width: 32px;
                height: 32px;
            }
            .toolbar-btn svg {
                width: 16px;
                height: 16px;
            }
            .toolbar-divider {
                display: none;
            }
            .toolbar-left {
                display: none;
            }
            #tiltBtn,
            #rotateBtn,
            #downloadBtn,
            #printBtn,
            #readAloudBtn,
            #themeToggleBtn,
            #zoomInBtn,
            #zoomOutBtn,
            #readingModeBtn {
                display: none !important;
            }
            /* Show overflow items in more menu */
            .tncfb-overflow-item {
                display: flex !important;
            }
            /* Scrollable more popup when it has overflow items */
            .more-popup {
                max-height: calc(100% - 100px);
                overflow-y: auto;
            }
        }

        /* ── Mini: < 380px ────────────────────────── */
        @media (max-width: 380px) {
            #shareBtn,
            #searchBtn,
            .zoom-dropdown {
                display: none !important;
            }
            .toolbar-btn {
                width: 28px;
                height: 28px;
            }
            .toolbar-btn svg {
                width: 14px;
                height: 14px;
            }
        }


        /* =============================================
           ACCESSIBILITY STYLES
           ============================================= */

        /* Skip link - visible only on focus */
        .skip-link {
            position: absolute;
            top: -100%;
            left: 50%;
            transform: translateX(-50%);
            z-index: 100000;
            padding: 12px 24px;
            background: var(--color-primary);
            color: #fff;
            font-size: 16px;
            font-weight: 600;
            border-radius: 0 0 8px 8px;
            text-decoration: none;
            transition: top 0.2s;
        }
        .skip-link:focus {
            top: 0;
        }

        /* Screen reader only - visually hidden but accessible */
        .sr-only {
            position: absolute !important;
            width: 1px !important;
            height: 1px !important;
            padding: 0 !important;
            margin: -1px !important;
            overflow: hidden !important;
            clip: rect(0, 0, 0, 0) !important;
            white-space: nowrap !important;
            border: 0 !important;
        }

        /* Enhanced focus indicators when accessibility is active */
        html.a11y-active *:focus-visible {
            outline: 3px solid var(--color-primary) !important;
            outline-offset: 2px !important;
            box-shadow: 0 0 0 5px rgba(74, 158, 255, 0.3) !important;
        }
        html.a11y-active *:focus:not(:focus-visible) {
            outline: none !important;
        }

        /* Reduced motion support */
        @media (prefers-reduced-motion: reduce) {
            *, *::before, *::after {
                animation-duration: 0.01ms !important;
                animation-iteration-count: 1 !important;
                transition-duration: 0.01ms !important;
                scroll-behavior: auto !important;
            }
        }

        /* Keyboard help modal */
        .keyboard-help-modal {
            display: none;
            position: fixed;
            top: 0; left: 0; right: 0; bottom: 0;
            z-index: 99999;
            background: rgba(0,0,0,0.7);
            backdrop-filter: blur(8px);
            -webkit-backdrop-filter: blur(8px);
            align-items: center;
            justify-content: center;
        }
        body.light-theme .keyboard-help-modal {
            background: rgba(0,0,0,0.3);
        }
        .keyboard-help-modal.active {
            display: flex;
        }
        .keyboard-help-content {
            background: var(--bg-popup, #1e1e2e);
            color: var(--text-color);
            border-radius: 20px;
            padding: 0;
            max-width: 480px;
            width: 94%;
            max-height: 80vh;
            overflow: hidden;
            box-shadow: 0 24px 64px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.06);
        }
        body.light-theme .keyboard-help-content {
            background: var(--bg-popup-light, #ffffff);
            box-shadow: 0 24px 64px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.06);
        }
        .keyboard-help-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 20px 24px;
            border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.08));
        }
        body.light-theme .keyboard-help-header {
            border-bottom-color: var(--border-color-light, rgba(0,0,0,0.06));
        }
        .keyboard-help-content h2 {
            margin: 0;
            font-size: 17px;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        body.light-theme .keyboard-help-content h2 {
            color: var(--text-color-light, #333);
        }
        .keyboard-help-content h2 svg {
            width: 22px;
            height: 22px;
            opacity: 0.8;
        }
        .keyboard-help-header-close {
            background: rgba(128,128,128,0.1);
            border: none;
            color: var(--text-color, #fff);
            opacity: 0.5;
            cursor: pointer;
            padding: 8px;
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.2s;
        }
        .keyboard-help-header-close:hover {
            background: rgba(128,128,128,0.2);
            opacity: 1;
        }
        body.light-theme .keyboard-help-header-close {
            color: var(--text-color-light, #333);
        }
        .keyboard-help-header-close svg {
            width: 18px;
            height: 18px;
        }
        .keyboard-help-body {
            padding: 20px 24px;
            overflow-y: auto;
            max-height: calc(80vh - 130px);
        }
        .keyboard-help-content dl {
            margin: 0;
            display: grid;
            grid-template-columns: auto 1fr;
            gap: 4px 16px;
            align-items: center;
        }
        .keyboard-help-content dt {
            font-weight: 500;
            padding: 8px 0;
            white-space: nowrap;
        }
        .keyboard-help-content dd {
            margin: 0;
            padding: 8px 0;
            opacity: 0.7;
            font-size: 13px;
        }
        body.light-theme .keyboard-help-content dt {
            color: var(--text-color-light, #333);
        }
        body.light-theme .keyboard-help-content dd {
            color: var(--text-color-light, #555);
        }
        .keyboard-help-content kbd {
            display: inline-block;
            padding: 3px 8px;
            font-size: 12px;
            font-family: -apple-system, BlinkMacSystemFont, 'SF Mono', 'Consolas', monospace;
            background: rgba(255,255,255,0.08);
            border: 1px solid rgba(255,255,255,0.15);
            border-radius: 6px;
            min-width: 28px;
            text-align: center;
            box-shadow: 0 1px 2px rgba(0,0,0,0.2);
        }
        body.light-theme .keyboard-help-content kbd {
            background: #f3f4f6;
            border-color: #d1d5db;
            color: #374151;
            box-shadow: 0 1px 2px rgba(0,0,0,0.06);
        }
        .keyboard-help-footer {
            padding: 16px 24px;
            border-top: 1px solid var(--border-color, rgba(255,255,255,0.08));
        }
        body.light-theme .keyboard-help-footer {
            border-top-color: var(--border-color-light, rgba(0,0,0,0.06));
        }
        .keyboard-help-close {
            width: 100%;
            padding: 10px;
            border: none;
            border-radius: 10px;
            background: var(--color-primary);
            color: #fff;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            transition: background 0.2s;
        }
        .keyboard-help-close:hover {
            opacity: 0.9;
        }

        /* ── PDF Password Prompt Modal ────────────────────── */
        .pdf-password-modal {
            display: none;
            position: fixed;
            top: 0; left: 0; right: 0; bottom: 0;
            z-index: 1001;
            background: rgba(0,0,0,0.8);
            backdrop-filter: blur(12px);
            -webkit-backdrop-filter: blur(12px);
            align-items: center;
            justify-content: center;
            visibility: hidden;
        }
        body.light-theme .pdf-password-modal {
            background: rgba(0,0,0,0.35);
        }
        .pdf-password-modal.active {
            display: flex;
            visibility: visible;
        }
        .pdf-password-content {
            background: var(--bg-popup, #1e1e2e);
            color: var(--text-color);
            border-radius: 20px;
            padding: 0;
            max-width: 380px;
            width: 90%;
            box-shadow: 0 24px 64px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.06);
            overflow: hidden;
        }
        body.light-theme .pdf-password-content {
            background: var(--bg-popup-light, #ffffff);
            box-shadow: 0 24px 64px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.06);
        }
        .pdf-password-header {
            padding: 24px 28px 0;
            text-align: center;
        }
        .pdf-password-header h2 {
            margin: 0;
            font-size: 17px;
            font-weight: 600;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }
        body.light-theme .pdf-password-header h2 {
            color: var(--text-color-light, #333);
        }
        .pdf-password-header h2 svg {
            width: 22px;
            height: 22px;
            opacity: 0.8;
        }
        .pdf-password-body {
            padding: 16px 28px 28px;
            text-align: center;
        }
        .pdf-password-message {
            font-size: 13px;
            opacity: 0.7;
            margin: 0 0 16px;
            line-height: 1.5;
        }
        body.light-theme .pdf-password-message {
            color: var(--text-color-light, #555);
        }
        .pdf-password-error {
            display: none;
            font-size: 13px;
            color: #f43f5e;
            margin: 0 0 12px;
            padding: 8px 12px;
            background: rgba(244,63,94,0.1);
            border-radius: 8px;
        }
        .pdf-password-error.visible {
            display: block;
        }
        .pdf-password-input-row {
            display: flex;
            gap: 8px;
        }
        .pdf-password-input-row input {
            flex: 1;
            padding: 10px 14px;
            border: 1px solid var(--border-color, rgba(255,255,255,0.15));
            border-radius: 10px;
            background: rgba(128,128,128,0.08);
            color: var(--text-color, #fff);
            font-size: 14px;
        }
        body.light-theme .pdf-password-input-row input {
            background: rgba(0,0,0,0.03);
            border-color: var(--border-color-light, rgba(0,0,0,0.12));
            color: var(--text-color-light, #333);
        }
        .pdf-password-input-row input:focus {
            outline: none;
            border-color: var(--color-primary, #4a9eff);
            box-shadow: 0 0 0 2px rgba(74,158,255,0.2);
        }
        .pdf-password-input-row input::placeholder {
            color: rgba(255,255,255,0.3);
        }
        body.light-theme .pdf-password-input-row input::placeholder {
            color: rgba(0,0,0,0.3);
        }
        #pdfPasswordSubmit {
            padding: 10px 20px;
            border: none;
            border-radius: 10px;
            background: var(--color-primary, #4a9eff);
            color: #fff;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            white-space: nowrap;
            transition: opacity 0.15s;
        }
        #pdfPasswordSubmit:hover {
            opacity: 0.9;
        }
        #pdfPasswordSubmit:disabled {
            opacity: 0.5;
            cursor: not-allowed;
        }

/* =============================================
   2D CSS FALLBACK MODE
   ============================================= */

.tncfb-book-2d {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    perspective: 2500px;
    transform-style: preserve-3d;
    transition: transform 0.4s ease, width 0.4s ease, height 0.4s ease;
}

.tncfb-sheet {
    position: absolute;
    top: 0;
    left: 50%;
    width: 50%;
    height: 100%;
    transform-origin: left center;
    transform-style: preserve-3d;
    transition: transform 0.8s cubic-bezier(0.645, 0.045, 0.355, 1);
    contain: layout paint;
}

/* In-flight flip: isolate the book from pointer events (kills mousemove/curl
   work mid-flip) and hint the compositor to keep it on its own layer. */
.tncfb-book-2d.tncfb-flipping {
    pointer-events: none;
    will-change: transform;
}
.tncfb-book-2d.tncfb-flipping .tncfb-sheet.flipping {
    will-change: transform;
}

.tncfb-sheet.flipped {
    transform: rotateY(-180deg);
}

/* Suppress sheet flip transition during slide/fade effects */
.tncfb-book-2d.tncfb-sliding .tncfb-sheet {
    transition: none;
}

.tncfb-sheet-front,
.tncfb-sheet-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    overflow: hidden;
    background: #ffffff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

body.light-theme .tncfb-sheet-front,
body.light-theme .tncfb-sheet-back {
    box-shadow: 0 0 1px rgba(0, 0, 0, 0.08);
}

.tncfb-sheet-back {
    transform: rotateY(180deg);
}

.tncfb-sheet-front canvas,
.tncfb-sheet-back canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Book layout states */
.tncfb-book-2d.at-start,
.tncfb-book-2d.at-end {
    /* Single page visible — book resized to single-page width by JS */
    transform: translate(-50%, -50%);
}
.tncfb-book-2d.at-start .tncfb-sheet,
.tncfb-book-2d.at-end .tncfb-sheet {
    left: 0;
    width: 100%;
    transform: none !important;
    transform-style: flat;
}
.tncfb-book-2d.at-end .tncfb-sheet .tncfb-sheet-front {
    display: none;
}
.tncfb-book-2d.at-end .tncfb-sheet .tncfb-sheet-back {
    transform: none;
    backface-visibility: visible;
    -webkit-backface-visibility: visible;
}
.tncfb-book-2d.at-start .tncfb-sheet .tncfb-sheet-back {
    display: none;
}
.tncfb-book-2d.at-start .tncfb-sheet .tncfb-sheet-front {
    transform: none;
    backface-visibility: visible;
    -webkit-backface-visibility: visible;
}

/* RTL: sheets and flip direction are mirrored */
body.rtl-mode .tncfb-sheet {
    left: auto;
    right: 50%;
    transform-origin: right center;
}
body.rtl-mode .tncfb-sheet.flipped {
    transform: rotateY(180deg);
}
body.rtl-mode .tncfb-book-2d.at-start .tncfb-sheet,
body.rtl-mode .tncfb-book-2d.at-end .tncfb-sheet {
    left: 0;
    right: auto;
    width: 100%;
    transform-origin: center center;
}

.tncfb-book-2d.spread-open {
    /* Both halves visible — center the whole book */
    transform: translate(-50%, -50%);
}

/* 2D single page flip animations — applied to the visible sheet */
@keyframes tncfb-page-turn-next {
    0%   { transform: rotateY(0deg) scale(1); opacity: 1; }
    40%  { transform: rotateY(-90deg) scale(0.92); opacity: 0.3; }
    60%  { transform: rotateY(90deg) scale(0.92); opacity: 0.3; }
    100% { transform: rotateY(0deg) scale(1); opacity: 1; }
}
@keyframes tncfb-page-turn-prev {
    0%   { transform: rotateY(0deg) scale(1); opacity: 1; }
    40%  { transform: rotateY(90deg) scale(0.92); opacity: 0.3; }
    60%  { transform: rotateY(-90deg) scale(0.92); opacity: 0.3; }
    100% { transform: rotateY(0deg) scale(1); opacity: 1; }
}

/* ── Slide effect ──────────────────────────────────────────── */
/* Slide uses a clone-based approach in JS — these are not used */

/* ── Fade effect ───────────────────────────────────────────── */
@keyframes tncfb-fade-out {
    from { opacity: 1; }
    to   { opacity: 0; }
}
@keyframes tncfb-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ── Hard cover effect (2D) — stiff rotation, no scale/fold ─ */
@keyframes tncfb-hard-turn-next {
    0%   { transform: rotateY(0deg); opacity: 1; }
    45%  { transform: rotateY(-90deg); opacity: 0.6; }
    55%  { transform: rotateY(90deg); opacity: 0.6; }
    100% { transform: rotateY(0deg); opacity: 1; }
}
@keyframes tncfb-hard-turn-prev {
    0%   { transform: rotateY(0deg); opacity: 1; }
    45%  { transform: rotateY(90deg); opacity: 0.6; }
    55%  { transform: rotateY(-90deg); opacity: 0.6; }
    100% { transform: rotateY(0deg); opacity: 1; }
}

/* ── Magazine fold effect (2D) ─────────────────────────────── */
@keyframes tncfb-fold-out {
    0%   { transform: perspective(1200px) rotateY(0deg) scaleX(1); opacity: 1; }
    50%  { transform: perspective(1200px) rotateY(-90deg) scaleX(0.5); opacity: 0.4; }
    100% { transform: perspective(1200px) rotateY(-180deg) scaleX(0); opacity: 0; }
}
@keyframes tncfb-fold-in {
    0%   { transform: perspective(1200px) rotateY(180deg) scaleX(0); opacity: 0; }
    50%  { transform: perspective(1200px) rotateY(90deg) scaleX(0.5); opacity: 0.4; }
    100% { transform: perspective(1200px) rotateY(0deg) scaleX(1); opacity: 1; }
}

/* Slide transition container (injected by JS) — will-change applied by JS only
   while a slide is active to avoid permanent GPU memory cost. */
.tncfb-slide-track {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
}
.tncfb-slide-track > * {
    flex: 0 0 100%;
    width: 100%;
    height: 100%;
}

/* Effect animation classes */
.tncfb-effect-fade-out { animation: tncfb-fade-out forwards; }
.tncfb-effect-fade-in { animation: tncfb-fade-in forwards; }
.tncfb-effect-hard-next { animation: tncfb-hard-turn-next forwards; transform-origin: center center; }
.tncfb-effect-hard-prev { animation: tncfb-hard-turn-prev forwards; transform-origin: center center; }
.tncfb-effect-fold-out { animation: tncfb-fold-out forwards; transform-origin: center center; }
.tncfb-effect-fold-in { animation: tncfb-fold-in forwards; transform-origin: center center; }
.tncfb-single-page .tncfb-sheet.tncfb-sheet-turning {
    animation-fill-mode: both;
    transform-origin: center center;
}
.tncfb-single-page .tncfb-sheet.tncfb-sheet-turning.tncfb-turn-next {
    animation-name: tncfb-page-turn-next;
    animation-timing-function: ease-in-out;
}
.tncfb-single-page .tncfb-sheet.tncfb-sheet-turning.tncfb-turn-prev {
    animation-name: tncfb-page-turn-prev;
    animation-timing-function: ease-in-out;
}

/* Mode transition: width/left are layout properties — animating them on every
   sheet causes layout thrashing (one full recalc per frame × N sheets). Snap
   the resize instantly and only crossfade opacity, which is composited. */
.tncfb-book-2d.tncfb-mode-transitioning .tncfb-sheet {
    transition: opacity 0.25s ease;
}

/* Single page mode — show one page centered */
.tncfb-book-2d.tncfb-single-page {
    transform: translate(-50%, -50%);
}
.tncfb-book-2d.tncfb-single-page::after,
.tncfb-book-2d.tncfb-single-page::before {
    display: none;
}
/* In single page mode: sheets fill container, no CSS 3D flip */
.tncfb-book-2d.tncfb-single-page .tncfb-sheet {
    left: 0;
    width: 100%;
    transform: none !important;
    transform-style: flat;
    transition: none;
}
/* Both faces are flat, JS toggles display to show the correct one */
.tncfb-book-2d.tncfb-single-page .tncfb-sheet-front,
.tncfb-book-2d.tncfb-single-page .tncfb-sheet-back {
    backface-visibility: visible;
    -webkit-backface-visibility: visible;
    transform: none;
}

/* Center spine crease line */
.tncfb-book-2d.spread-open::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 2px;
    height: 100%;
    background: linear-gradient(to right,
        rgba(0, 0, 0, 0.08),
        rgba(0, 0, 0, 0.15),
        rgba(0, 0, 0, 0.08)
    );
    transform: translateX(-50%);
    z-index: 10000;
    pointer-events: none;
}

/* Subtle page edge shadow on left side of right page */
.tncfb-book-2d.spread-open::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 12px;
    height: 100%;
    background: linear-gradient(to right,
        rgba(0, 0, 0, 0.06),
        transparent
    );
    z-index: 9999;
    pointer-events: none;
}

/* ── Turn.js-style fold & shadow effects ─────────────────────────── */

/* Corner curl element — absolutely positioned inside the sheet face */
.tncfb-curl {
    position: absolute;
    width: 0;
    height: 0;
    pointer-events: none;
    z-index: 5;
    transition: width 0.15s cubic-bezier(0.4, 0, 0.2, 1), height 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

/* Curl in each corner */
.tncfb-curl-br { bottom: 0; right: 0; }
.tncfb-curl-tr { top: 0; right: 0; }
.tncfb-curl-bl { bottom: 0; left: 0; }
.tncfb-curl-tl { top: 0; left: 0; }

/* The folded-back gradient inside the curl */
.tncfb-curl-inner {
    position: absolute;
    width: 100%;
    height: 100%;
}

/* Bottom-right corner: diagonal gradient */
.tncfb-curl-br .tncfb-curl-inner {
    bottom: 0;
    right: 0;
    background: linear-gradient(315deg,
        #b8b8b8 0%,
        #e8e8e8 25%,
        #f2f2f2 50%,
        #ddd 100%
    );
    box-shadow:
        -2px -2px 4px rgba(0, 0, 0, 0.12),
        -4px -4px 10px rgba(0, 0, 0, 0.08);
}

/* Top-right corner */
.tncfb-curl-tr .tncfb-curl-inner {
    top: 0;
    right: 0;
    background: linear-gradient(225deg,
        #b8b8b8 0%,
        #e8e8e8 25%,
        #f2f2f2 50%,
        #ddd 100%
    );
    box-shadow:
        -2px 2px 4px rgba(0, 0, 0, 0.12),
        -4px 4px 10px rgba(0, 0, 0, 0.08);
}

/* Bottom-left corner */
.tncfb-curl-bl .tncfb-curl-inner {
    bottom: 0;
    left: 0;
    background: linear-gradient(45deg,
        #b8b8b8 0%,
        #e8e8e8 25%,
        #f2f2f2 50%,
        #ddd 100%
    );
    box-shadow:
        2px -2px 4px rgba(0, 0, 0, 0.12),
        4px -4px 10px rgba(0, 0, 0, 0.08);
}

/* Top-left corner */
.tncfb-curl-tl .tncfb-curl-inner {
    top: 0;
    left: 0;
    background: linear-gradient(135deg,
        #b8b8b8 0%,
        #e8e8e8 25%,
        #f2f2f2 50%,
        #ddd 100%
    );
    box-shadow:
        2px 2px 4px rgba(0, 0, 0, 0.12),
        4px 4px 10px rgba(0, 0, 0, 0.08);
}

/* Shadow beneath the curl on the page */
.tncfb-curl-shadow {
    position: absolute;
    pointer-events: none;
    z-index: 4;
    opacity: 0;
    transition: opacity 0.15s ease, width 0.15s ease, height 0.15s ease;
    width: 0;
    height: 0;
}

.tncfb-curl-shadow-br {
    bottom: 0; right: 0;
    background: radial-gradient(ellipse at bottom right,
        rgba(0, 0, 0, 0.15) 0%,
        rgba(0, 0, 0, 0.08) 35%,
        transparent 65%
    );
}

.tncfb-curl-shadow-tr {
    top: 0; right: 0;
    background: radial-gradient(ellipse at top right,
        rgba(0, 0, 0, 0.15) 0%,
        rgba(0, 0, 0, 0.08) 35%,
        transparent 65%
    );
}

.tncfb-curl-shadow-bl {
    bottom: 0; left: 0;
    background: radial-gradient(ellipse at bottom left,
        rgba(0, 0, 0, 0.15) 0%,
        rgba(0, 0, 0, 0.08) 35%,
        transparent 65%
    );
}

.tncfb-curl-shadow-tl {
    top: 0; left: 0;
    background: radial-gradient(ellipse at top left,
        rgba(0, 0, 0, 0.15) 0%,
        rgba(0, 0, 0, 0.08) 35%,
        transparent 65%
    );
}

/* Flip animation: fold gradient on the front face */
.tncfb-sheet.flipping .tncfb-sheet-front .tncfb-fold-gradient {
    opacity: 1;
}

.tncfb-fold-gradient {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 3;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.tncfb-fold-right {
    background: linear-gradient(to left,
        rgba(0, 0, 0, 0.22) 0%,
        rgba(0, 0, 0, 0.10) 4%,
        rgba(0, 0, 0, 0.03) 12%,
        rgba(0, 0, 0, 0) 20%
    );
}

.tncfb-fold-left {
    background: linear-gradient(to right,
        rgba(0, 0, 0, 0.22) 0%,
        rgba(0, 0, 0, 0.10) 4%,
        rgba(0, 0, 0, 0.03) 12%,
        rgba(0, 0, 0, 0) 20%
    );
}

/* Cast shadow beneath the flipping sheet */
.tncfb-flip-shadow {
    position: absolute;
    top: 3%;
    left: -20%;
    width: 120%;
    bottom: 3%;
    background: rgba(0, 0, 0, 0.10);
    filter: blur(10px);
    border-radius: 4px;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.tncfb-sheet.flipping .tncfb-flip-shadow {
    opacity: 1;
}

/* Reduced motion: instant flips, no peel */
@media (prefers-reduced-motion: reduce) {
    .tncfb-sheet {
        transition: none;
    }
    .tncfb-curl,
    .tncfb-curl-shadow,
    .tncfb-flip-shadow {
        display: none;
    }
}

/* ── Transparent-mode UI override ───────────────────────────────────────────
   When the viewer is loaded with transparent=1 the host page is the
   background. Keep every chrome's identity (its colors, text, borders,
   brand accents) but make the surfaces slightly translucent so they sit
   nicely on top of the host page instead of looking like opaque slabs.

   We only touch the surfaces that already have a chrome bg — never paint a
   backdrop on positioning containers like .top-right-controls (each child
   button has its own bg). The book area still flips with the theme toggle. */
        body.tncfb-transparent .bottom-toolbar {
            background: color-mix(in srgb, var(--bg-toolbar) 75%, transparent);
        }
        body.light-theme.tncfb-transparent .bottom-toolbar {
            background: color-mix(in srgb, var(--bg-toolbar-light) 75%, transparent);
        }

        body.tncfb-transparent .search-sidebar,
        body.tncfb-transparent .thumbnails-sidebar,
        body.tncfb-transparent .bookmarks-sidebar,
        body.tncfb-transparent .notes-sidebar {
            background: color-mix(in srgb, var(--bg-sidebar) 80%, transparent);
            backdrop-filter: blur(16px);
            -webkit-backdrop-filter: blur(16px);
        }
        body.light-theme.tncfb-transparent .search-sidebar,
        body.light-theme.tncfb-transparent .thumbnails-sidebar,
        body.light-theme.tncfb-transparent .bookmarks-sidebar,
        body.light-theme.tncfb-transparent .notes-sidebar {
            background: color-mix(in srgb, var(--bg-sidebar-light) 80%, transparent);
        }

        body.tncfb-transparent .share-modal,
        body.tncfb-transparent .keyboard-help-modal,
        body.tncfb-transparent .more-popup,
        body.tncfb-transparent .share-popup {
            background: color-mix(in srgb, var(--bg-popup) 88%, transparent);
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
        }
        body.light-theme.tncfb-transparent .share-modal,
        body.light-theme.tncfb-transparent .keyboard-help-modal,
        body.light-theme.tncfb-transparent .more-popup,
        body.light-theme.tncfb-transparent .share-popup {
            background: color-mix(in srgb, var(--bg-popup-light) 88%, transparent);
        }
        body.tncfb-transparent .more-popup-arrow {
            background: color-mix(in srgb, var(--bg-popup) 88%, transparent);
        }
        body.light-theme.tncfb-transparent .more-popup-arrow {
            background: color-mix(in srgb, var(--bg-popup-light) 88%, transparent);
        }

        /* Polarity mismatch: light popup surround + user-toggled dark page.
           At 75–88% the dark chrome washes out over the light popup backdrop
           and the white icons disappear. Bump opacity so the dark surface
           dominates the surround instead of blending into it. */
        body.tncfb-popup-theme-light.tncfb-transparent:not(.light-theme) .bottom-toolbar {
            background: color-mix(in srgb, var(--bg-toolbar) 96%, transparent);
        }
        body.tncfb-popup-theme-light.tncfb-transparent:not(.light-theme) .search-sidebar,
        body.tncfb-popup-theme-light.tncfb-transparent:not(.light-theme) .thumbnails-sidebar,
        body.tncfb-popup-theme-light.tncfb-transparent:not(.light-theme) .bookmarks-sidebar,
        body.tncfb-popup-theme-light.tncfb-transparent:not(.light-theme) .notes-sidebar {
            background: color-mix(in srgb, var(--bg-sidebar) 96%, transparent);
        }
        body.tncfb-popup-theme-light.tncfb-transparent:not(.light-theme) .share-modal,
        body.tncfb-popup-theme-light.tncfb-transparent:not(.light-theme) .keyboard-help-modal,
        body.tncfb-popup-theme-light.tncfb-transparent:not(.light-theme) .more-popup,
        body.tncfb-popup-theme-light.tncfb-transparent:not(.light-theme) .share-popup,
        body.tncfb-popup-theme-light.tncfb-transparent:not(.light-theme) .more-popup-arrow {
            background: color-mix(in srgb, var(--bg-popup) 98%, transparent);
        }

        /* On polarity mismatch in transparent mode (light popup surround +
           dark page toggle), just bias the icon color of bare-icon controls
           so they stay readable against the light surround instead of
           painting a backdrop pill they don't normally have. */
        body.tncfb-popup-theme-light.tncfb-transparent:not(.light-theme) .nav-btn {
            color: rgba(0, 0, 0, 0.55);
        }
        body.tncfb-popup-theme-light.tncfb-transparent:not(.light-theme) .nav-btn:hover {
            color: rgba(0, 0, 0, 0.85);
        }
        body.tncfb-popup-theme-light.tncfb-transparent:not(.light-theme) .control-btn {
            background: rgba(0, 0, 0, 0.08);
            color: rgba(0, 0, 0, 0.7);
        }
        body.tncfb-popup-theme-light.tncfb-transparent:not(.light-theme) .control-btn:hover {
            background: rgba(0, 0, 0, 0.15);
            color: rgba(0, 0, 0, 0.95);
        }

        /* Symmetric case: dark popup surround + user-toggled light page.
           Default light-theme icon color is dark, which vanishes against
           the dark popup. Force light icons + faint light bg on the toggle
           so they read against the dark surround. */
        body.tncfb-popup-theme-dark.tncfb-transparent.light-theme .nav-btn {
            color: rgba(255, 255, 255, 0.7);
        }
        body.tncfb-popup-theme-dark.tncfb-transparent.light-theme .nav-btn:hover {
            color: rgba(255, 255, 255, 1);
        }
        body.tncfb-popup-theme-dark.tncfb-transparent.light-theme .control-btn {
            background: rgba(255, 255, 255, 0.1);
            color: rgba(255, 255, 255, 0.7);
        }
        body.tncfb-popup-theme-dark.tncfb-transparent.light-theme .control-btn:hover {
            background: rgba(255, 255, 255, 0.18);
            color: rgba(255, 255, 255, 1);
        }

        /* Jump spinner — shown while target page renders after a long-jump nav. */
        .tncfb-jump-spinner {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 56px;
            height: 56px;
            pointer-events: none;
            opacity: 0;
            transition: opacity .18s ease;
            z-index: 50;
        }
        .tncfb-jump-spinner.is-visible { opacity: 1; }
        .tncfb-jump-spinner::before {
            content: '';
            position: absolute;
            inset: 0;
            border-radius: 50%;
            background: rgba(0, 0, 0, 0.42);
            backdrop-filter: blur(6px);
            -webkit-backdrop-filter: blur(6px);
            box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
        }
        .tncfb-jump-spinner svg {
            position: absolute;
            inset: 0;
            width: 100%;
            height: 100%;
            animation: tncfb-jump-spin 0.9s linear infinite;
        }
        .tncfb-jump-spinner svg circle {
            fill: none;
            stroke: rgba(255, 255, 255, 0.95);
            stroke-width: 3;
            stroke-linecap: round;
            stroke-dasharray: 90 150;
            stroke-dashoffset: 0;
        }
        @keyframes tncfb-jump-spin {
            to { transform: rotate(360deg); }
        }


/* Attribution badge (moved from inline <style> for WordPress.org) */
#tncfb-branding {
            position: fixed;
            bottom: 8px;
            right: 8px;
            z-index: 999999;
            background: rgba(0,0,0,0.8);
            backdrop-filter: blur(8px);
            -webkit-backdrop-filter: blur(8px);
            padding: 5px 14px;
            border-radius: 6px;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            font-size: 11px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.3);
        }
        #tncfb-branding a { color: #a0aec0; text-decoration: none; }
        #tncfb-branding a:hover { color: #fff; }
        #tncfb-branding a strong { color: #e2e8f0; }
        body.layout-bottom-fullwidth #tncfb-branding,
        body.layout-bottom-center #tncfb-branding { bottom: 70px; }
