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

    body {
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
      background: #1a1a1a;
      overflow: hidden;
      height: 100vh;
      width: 100vw;
    }

    #reader-container {
      width: 100vw;
      height: 100vh;
      display: flex;
      justify-content: center;
      align-items: center;
      overflow: hidden;
      position: relative;
    }

    #flipbook-container {
      width: 100%;
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      overflow: hidden;
      position: relative;
      z-index: 1;
      cursor: grab;
      touch-action: pan-x pan-y pinch-zoom;
    }

    /* Fixed frame container for stable page positioning during streaming */
    #stpageflip-fixed-frame {
      width: 100%;
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;
      overflow: hidden;
      /* Prevent size changes during streaming */
      box-sizing: border-box;
      flex-shrink: 0;
    }

    #flipbook-container:active {
      cursor: grabbing;
    }

    .flipbook-page {
      background: white;
      position: relative;
      overflow: hidden;
    }

    .flipbook-page canvas {
      display: block;
      position: absolute;
      top: 0;
      left: 0;
      z-index: 1;
    }

    .flipbook-page .pdf-text-layer {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      overflow: hidden;
      opacity: 1;
      z-index: 2;
      pointer-events: auto;
      line-height: 1.0;
    }

    .flipbook-page .pdf-text-layer > span {
      color: transparent;
      position: absolute;
      white-space: pre;
      cursor: text;
      transform-origin: 0% 0%;
    }

    .flipbook-page .pdf-text-layer ::selection {
      background: rgba(0, 0, 255, 0.3);
    }

    /* Page placeholder: skeleton shimmer when PDF page is not yet rendered */
    .flipbook-page[data-placeholder="true"] {
      background: linear-gradient(
        110deg,
        #f2f2f2 0%,
        #f2f2f2 35%,
        #e5e5e5 50%,
        #f2f2f2 65%,
        #f2f2f2 100%
      );
      background-size: 200% 100%;
      animation: pagePlaceholderShimmer 2.2s ease-in-out infinite;
    }

    @keyframes pagePlaceholderShimmer {
      0%, 100% { background-position: 200% 0; }
      50% { background-position: -200% 0; }
    }

    .page-placeholder-loader {
      position: absolute;
      inset: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 1;
      pointer-events: none;
    }

    /* Zen gradient spinner (skeleton-style, clearly visible) */
    .page-placeholder-spinner {
      width: 52px;
      height: 52px;
      border-radius: 50%;
      background: conic-gradient(
        from 0deg,
        #d4d4d4 0deg,
        #e8e8e8 90deg,
        #cacaca 180deg,
        #e2e2e2 270deg,
        #d4d4d4 360deg
      );
      animation: pagePlaceholderSpin 1.6s linear infinite;
      position: relative;
      box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.9);
    }

    .page-placeholder-spinner::after {
      content: '';
      position: absolute;
      inset: 4px;
      border-radius: 50%;
      background: linear-gradient(145deg, #f5f5f5 0%, #eeeeee 100%);
    }

    @keyframes pagePlaceholderSpin {
      to { transform: rotate(360deg); }
    }

    #loading {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      background: #1a1a1a;
      z-index: 1000;
      transition: opacity 0.3s ease;
    }

    #loading.hidden {
      opacity: 0;
      pointer-events: none;
    }

    .loading-content {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 2rem;
    }

    .loading-cover-preview {
      width: 200px;
      height: 280px;
      background: #2a2a2a;
      border-radius: 8px;
      overflow: hidden;
      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
      position: relative;
    }

    .loading-cover-media {
      position: absolute;
      inset: 0;
      z-index: 0;
    }

    .loading-cover-media img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block;
    }

    /* Animated cover reveal while the reader loads */
    .loading-cover-image {
      opacity: 0;
      transform: scale(1.03);
      filter: blur(8px) grayscale(30%);
      animation: coverReveal 1.4s ease-out forwards;
    }

    @keyframes coverReveal {
      0% {
        opacity: 0;
        transform: scale(1.03);
        filter: blur(8px) grayscale(30%);
      }
      55% {
        opacity: 0.65;
        transform: scale(1.01);
        filter: blur(3px) grayscale(10%);
      }
      100% {
        opacity: 1;
        transform: scale(1);
        filter: blur(0) grayscale(0);
      }
    }

    .loading-cover-preview::after {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: linear-gradient(180deg, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0.3) 100%);
      z-index: 1;
    }

    .loading-spinner {
      width: 40px;
      height: 40px;
      border: 3px solid rgba(255, 255, 255, 0.1);
      border-top-color: #fff;
      border-radius: 50%;
      animation: spin 1s linear infinite;
    }

    .loading-spinner-layer {
      position: absolute;
      inset: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 2;
      pointer-events: none;
    }

    @keyframes spin {
      to { transform: rotate(360deg); }
    }

    .loading-text {
      color: #ccc;
      font-size: 0.9rem;
      text-align: center;
      margin-top: 1rem;
    }

    /* Bottom navigation controls (glassmorphism style) */
    #nav-controls {
      position: absolute;
      left: 50%;
      right: auto;
      bottom: 24px;
      display: flex;
      justify-content: center;
      gap: 24px;
      padding: 0 24px;
      pointer-events: none;
      z-index: 12;
      opacity: 1;
      transform: translateX(-50%);
      transition: opacity 0.2s ease;
    }

    #nav-controls[data-position="page-edge"] {
      justify-content: space-between;
      padding: 0;
      width: auto;
      transform: translateY(-50%);
    }

    #nav-controls.hidden {
      opacity: 0;
      pointer-events: none;
    }

    .nav-button {
      pointer-events: auto;
      width: 56px;
      height: 56px;
      border-radius: 16px;
      border: 1px solid rgba(255, 255, 255, 0.18);
      background: rgba(20, 20, 20, 0.35);
      backdrop-filter: blur(16px) saturate(140%);
      -webkit-backdrop-filter: blur(16px) saturate(140%);
      box-shadow:
        inset 0 1px 1px rgba(255, 255, 255, 0.18),
        inset 0 -1px 2px rgba(0, 0, 0, 0.5),
        0 10px 30px rgba(0, 0, 0, 0.35);
      display: inline-flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      --nav-offset: 0px;
      transform: translateX(var(--nav-offset));
      transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s ease;
      color: #fff;
    }

    #nav-controls[data-position="page-edge"] .nav-button:first-child {
      --nav-offset: -50%;
    }

    #nav-controls[data-position="page-edge"] .nav-button:last-child {
      --nav-offset: 50%;
    }

    .nav-button svg {
      width: 22px;
      height: 22px;
      fill: none;
      stroke: rgba(255, 255, 255, 0.92);
      stroke-width: 2.25;
      stroke-linecap: round;
      stroke-linejoin: round;
    }

    .nav-button:active:not(:disabled) {
      transform: translateX(var(--nav-offset)) translateY(1px);
      box-shadow:
        inset 0 1px 1px rgba(255, 255, 255, 0.12),
        inset 0 -1px 3px rgba(0, 0, 0, 0.6),
        0 6px 18px rgba(0, 0, 0, 0.4);
    }

    .nav-button:disabled {
      opacity: 0.35;
      cursor: not-allowed;
    }

    .zoom-reset-floating {
      position: absolute;
      left: 50%;
      bottom: 24px;
      transform: translateX(-50%);
      z-index: 12;
      pointer-events: none;
      opacity: 0;
      transition: opacity 0.2s ease;
    }

    .zoom-reset-floating.visible {
      opacity: 1;
      pointer-events: auto;
    }

    .zoom-reset-button {
      width: 60px;
      height: 56px;
      border-radius: 16px;
      border: 1px solid rgba(255, 255, 255, 0.18);
      background: rgba(20, 20, 20, 0.35);
      backdrop-filter: blur(16px) saturate(140%);
      -webkit-backdrop-filter: blur(16px) saturate(140%);
      box-shadow:
        inset 0 1px 1px rgba(255, 255, 255, 0.18),
        inset 0 -1px 2px rgba(0, 0, 0, 0.5),
        0 10px 30px rgba(0, 0, 0, 0.35);
      display: inline-flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      transition: transform 0.15s ease, box-shadow 0.2s ease;
    }

    .zoom-reset-button svg {
      width: 22px;
      height: 22px;
      fill: none;
      stroke: rgba(255, 255, 255, 0.92);
      stroke-width: 2.25;
      stroke-linecap: round;
      stroke-linejoin: round;
    }

    /* Cover page container (first and last page) - Overlay above flipbook */
    #cover-page-container {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      overflow: hidden;
      cursor: pointer;
      background: rgba(26, 26, 26, 0.95); /* Semi-transparent background overlay */
      z-index: 10; /* Above flipbook container */
      backdrop-filter: blur(2px); /* Optional: blur effect */
    }

    #cover-page-container.hidden {
      display: none;
    }

    #cover-page-image {
      width: 100%;
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      padding: 2%;
    }

    #cover-page-image > div {
      background: white;
      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8);
      display: flex;
      justify-content: center;
      align-items: center;
      margin: 0 auto; /* Center horizontally */
      /* Size will be set by renderCoverPage function */
    }

    .stf__parent {
      width: 100% !important;
      height: 100% !important;
      display: flex !important;
      justify-content: center !important;
      align-items: center !important;
      overflow: hidden !important;
      max-width: 100vw !important;
      max-height: 100vh !important;
      position: relative !important;
    }

    .stf__wrapper {
      display: flex !important;
      justify-content: center !important;
      align-items: center !important;
      width: 100% !important;
      height: 100% !important;
      position: relative !important;
    }

    .stf__block {
      margin: 0 auto !important;
      position: relative !important;
    }

    .stf__canvas {
      margin: 0 auto !important;
      position: relative !important;
    }

    @media (max-width: 768px) {
      #loading {
        justify-content: flex-start;
        align-items: center;
        padding-top: 12px;
      }

      .loading-content {
        margin-top: 12px;
      }

      #reader-container {
        align-items: flex-start;
        padding-top: 12px;
      }

      #flipbook-container {
        align-items: flex-start;
        padding-top: 12px;
      }

      #stpageflip-fixed-frame {
        align-items: flex-start;
        padding-top: 12px;
      }

      #cover-page-container {
        align-items: flex-start;
        padding-top: 12px;
      }

      #cover-page-image {
        align-items: flex-start;
        padding-top: 12px;
      }

      .stf__parent {
        align-items: flex-start !important;
      }

      .stf__wrapper {
        align-items: flex-start !important;
      }

      #nav-controls {
        bottom: 16px;
        padding: 0 16px;
      }

      #nav-controls[data-position="fixed-bottom"] {
        top: auto !important;
        left: 50% !important;
        right: auto !important;
        bottom: 16px !important;
        width: auto !important;
        transform: translateX(-50%) !important;
      }

      #nav-controls[data-position="below-page"] {
        bottom: auto !important;
        left: 50% !important;
        right: auto !important;
        width: auto !important;
        transform: translateX(-50%) !important;
      }

      .nav-button {
        width: 48px;
        height: 48px;
        border-radius: 14px;
      }

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

      .zoom-reset-floating {
        bottom: 16px;
      }

      .zoom-reset-button {
        width: 56px;
        height: 48px;
        border-radius: 14px;
      }

      .zoom-reset-button svg {
        width: 20px;
        height: 20px;
      }
    }
