
      :root {
        --bg: #222;
        --fg: #eee;
        --sidebar-bg: #333;
        --shadow: rgba(0, 0, 0, 0.3);
        --accent: #d4a373;
        --meta-label: #999;
        --spinner-color: #3498db;
      }
      body.light {
        --bg: #fff;
        --fg: #222;
        --sidebar-bg: #f5f5f5;
        --shadow: rgba(0, 0, 0, 0.1);
        --accent: #d4a373;
        --meta-label: #666;
        --spinner-color: #3498db;
      }

      /* Basic Resets & Layout */
      * {
        -webkit-tap-highlight-color: transparent;
        overscroll-behavior: none;
      }
      html {
        touch-action: manipulation;
        overscroll-behavior: none;
      }
      body {
        margin: 0;
        font: 16px/1.6 Georgia, serif;
        background: var(--bg);
        color: var(--fg);
        -webkit-text-size-adjust: none;
        touch-action: manipulation;
        overscroll-behavior: none;
      }
      button {
        touch-action: manipulation;
        -webkit-touch-callout: none;
      }

      /* Main container */
      #content {
        display: flex;
        min-height: 100vh;
        position: relative;
        overscroll-behavior: none;
      }

      /* Sidebar */
      #sidebar {
        width: 300px;
        background: var(--sidebar-bg);
        box-shadow: 2px 0 5px var(--shadow);
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        padding: 20px;
        overflow-y: auto;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s;
      }
      #sidebar.active {
        transform: translateX(0);
        box-shadow: 0 0 15px var(--shadow);
      }

      /* Reader */
      #reader {
        flex: 1;
        position: relative;
        display: flex;
        flex-direction: column;
        touch-action: pan-y pinch-zoom;
        -webkit-overflow-scrolling: touch;
      }
      #reader.book-mode {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 4em 2em;
        min-height: 100vh;
      }
      #reader:not(.book-mode) {
        padding: 1em;
        padding-bottom: 6em;
        max-width: 800px;
        margin: 0 auto;
        height: auto;
        min-height: auto;
        overflow: visible;
      }
      #reader-content {
        width: 100%;
        flex: 1;
        display: flex;
        flex-direction: column;
      }

      /* Chapters */
      #chapters {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 2em;
        padding-bottom: 4em;
      }
	#chapters.book-mode {
	  display: flex;
	  flex-direction: column;
	  max-width: min(1260px, 85vw);
	  width: 100%;
	  height: min(85vh, 95vh);
	  max-height: 1100px;
	  margin: 0 auto;
	  overflow: hidden;
	}

      .chapter {
        display: none;
        width: 100%;
        min-height: auto;
        height: min(80vh, 85vh);
        max-height: 1100px;
        padding: 0;
        margin: 0;
        background: var(--sidebar-bg);
        box-shadow: 0 0 10px var(--shadow);
        border-radius: 2px;
        font-family: Georgia, serif;
        line-height: 1.5;
        font-size: var(--font-size, 1em);
        box-sizing: border-box;
        flex-direction: column;
        margin-bottom: 2em;
      }
      .chapter.active {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        background: var(--sidebar-bg);
        padding: 0;
        width: 100%;
        height: 100%;
        gap: 0;
        overflow: hidden;
      }
      .chapter:first-child {
        justify-content: center;
        align-items: center;
        text-align: center;
      }
      .chapter:first-child .page {
        display: flex !important;
        justify-content: center;
        align-items: center;
        text-align: center;
      }
      .chapter:first-child .page > * {
        margin: 0;
      }
      .chapter:only-child h1 {
        margin: auto;
      }
      .chapter > :first-child {
        margin-top: 0;
      }
      .chapter > :last-child {
        margin-bottom: 0;
      }
      .chapter img {
        max-width: 100%;
        height: auto;
      }
      .chapter h1 {
        color: var(--accent);
        font-size: 1.8em;
        margin: 0 0 1em 0;
      }

      /* Pages in Book Mode */
      .page-spread {
        display: none;
        width: 100%;
        height: 100%;
      }
      .page-spread.active {
        display: flex;
        flex-direction: row;
        gap: 0;
      }
      .page {
		 flex: 1;
		  width: 50%;
		  min-width: 50%;
		  height: 100%;
		  max-height: 100%;
		  padding: 40px 60px;
		  background: var(--sidebar-bg);
		  box-shadow: 2px 0 5px var(--shadow);
		  box-sizing: border-box;
		  display: none;
		  margin: 0;
		  overflow-y: auto;
		  text-align: justify;
		  line-height: 1.5;
      }
      .page.active {
		  display: block;
			padding: 40px !important;
      }
      .page:nth-child(odd).active {
        border-right: 1px solid var(--shadow);
      }
      .page > * {
       max-width: 100%;
	   margin: 0.5em 0;
      }
      .page > :last-child {
        margin-bottom: 0;
      }
      .page p {
        margin: 0.2em 0;
        text-align: justify;
      }

      /* Metadata / TOC */
      .meta {
        margin: 0.5em 0 1em 0;
        font-size: 0.85em;
      }
      .meta div {
        margin: 0.5em 0;
        line-height: 1.4;
      }
      .meta-label {
        font-size: 0.75em;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: #666;
        margin-bottom: 0.2em;
        font-size: 0.8em;
        color: var(--fg);
        opacity: 0.7;
        margin-bottom: 2px;
      }
      .meta-value {
        font-size: 0.9em;
        color: var(--accent);
      }
      .toc-item {
        padding: 0.5em 0;
        cursor: pointer;
        border-bottom: 1px solid var(--shadow);
        font-size: 0.9em;
      }
      .toc-item:hover {
        color: var(--accent);
      }
      .toc-item.active {
        color: var(--accent);
        font-weight: 700;
      }

      /* Debug / Info */
      #debug {
        padding: 0.5em;
        font-size: 0.75em;
        color: #666;
        border-bottom: 1px solid var(--shadow);
      }

      /* Sidebar toggle & Menu Controls */
      .menu-controls {
        position: fixed;
        top: 20px;
        right: 20px;
        z-index: 10;
      }
      .menu-trigger {
        padding: 0;
        background: 0 0;
        border: none;
        color: var(--accent);
        cursor: pointer;
        font-size: 2em;
        opacity: 0.7;
        transition: opacity 0.2s;
        padding: 4px;
        border-radius: 4px;
		margin-right: 0.5em;
      }
      .menu-trigger.active,
      .menu-trigger:hover {
        opacity: 1;
      }
      .menu-dropdown {
        position: absolute;
        right: 5px;
        background: var(--sidebar-bg);
        box-shadow: 0 2px 8px var(--shadow);
        padding: 5px;
        display: none;
        min-width: 180px;

        top: calc(100% + 8px);
        right: 0;
        border-radius: 4px;
        box-shadow: 0 2px 8px var(--shadow);
        min-width: 200px;
        display: none;
      }
      .menu-dropdown.active {
        display: block;
      }
      .menu-group {
        padding: 12px;
        border-bottom: 1px solid var(--shadow);
      }
      .menu-group:last-child {
        border-bottom: none;
      }
      .menu-group-title {
        font-size: 0.8em;
        color: var(--fg);
        opacity: 0.7;
        margin-bottom: 8px;
      }
      .nav-button {
        display: block;
        width: 100%;
        text-align: left;
        padding: 8px;
        border: none;
        background: 0 0;
        color: var(--fg);
        cursor: pointer;
        border-radius: 4px;
        transition: 0.2s;
      }
      .nav-button:hover {
        background: var(--shadow);
      }
      .nav-button.active {
        background: var(--accent);
        color: var(--sidebar-bg);
      }

      /* Font controls (optional UI) */
      .font-controls {
        display: flex;
        gap: 8px;
      }
      .font-size-btn {
        padding: 4px 8px;
        border: 1px solid var(--shadow);
        border-radius: 4px;
        background: 0 0;
        color: var(--fg);
        cursor: pointer;
      }
      .font-size-btn:hover {
        background: var(--shadow);
      }

      /* Next/Prev side nav for flipping pages in book mode */
      .side-nav {
        position: fixed;
        top: 50%;
        transform: translateY(-50%);
        z-index: 4;
        opacity: 0.3;
        transition: opacity 0.2s;
      }
      .side-nav.prev {
        left: 20px;
      }
      .side-nav.next {
        right: 20px;
      }
      .side-nav .nav-button {
        font-size: 1.5em;
        padding: 15px;
        background: 0 0;
        border: none;
        color: var(--accent);
        cursor: pointer;
        transition: transform 0.2s;
      }
      .side-nav:hover {
        opacity: 0.8;
      }
      .side-nav .nav-button:hover {
        transform: scale(1.2);
        color: var(--accent);
      }

      /* Mobile Nav */
      #mobile-nav {
        display: none;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        background: var(--sidebar-bg);
        box-shadow: 0 -2px 5px var(--shadow);
        z-index: 10;
      }
      #mobile-nav.expanded {
        transform: translateY(0);
        height: auto;
        max-height: 70vh;
        overflow-y: auto;
      }
      .nav-content {
        display: none;
        padding: 15px;
        border-top: 1px solid var(--shadow);
        background: var(--sidebar-bg);
      }
      #mobile-nav.expanded .nav-content {
        display: block;
      }

      /* Book info / top bar */
      .book-info {
        position: fixed;
        top: 0;
        right: 0;
        transform: none;
        background: 0 0;
        padding: 0 10px;
        border-radius: 4px;
        font-size: 0.9em;
        display: flex;
        gap: 15px;
        align-items: center;
        z-index: 5;
      }
      .book-info .title {
        display: none;
      }
      .book-info .chapter {
        opacity: 0.8;
      }
      .book-info .pages {
        padding-left: 15px;
      }
      .book-info:hover {
        opacity: 1;
      }

      /* Additional meta layout */
      #meta {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 15px;
        margin-bottom: 15px;
      }
      #toc {
        max-height: 300px;
        overflow-y: auto;
        border-top: 1px solid var(--shadow);
        padding-top: 15px;
      }

      /* Non-book mode chapter styling */
      #reader:not(.book-mode) .chapter {
        padding: 1.5em;
        padding-bottom: 8em;
        margin-bottom: 2em;
        text-align: left;
        line-height: 1.6;
        background: 0 0;
        box-shadow: none;
        height: auto;
        min-height: auto;
        display: block;
        overflow: visible;
      }
      #reader:not(.book-mode) .chapter:last-child {
        margin-bottom: 12em;
      }
      #reader:not(.book-mode) .page {
        height: auto;
        min-height: auto;
        width: 100%;
        max-width: 100%;
        padding: 0;
        margin: 0;
        box-shadow: none;
        overflow: visible;
        display: block;
      }
      #reader:not(.book-mode) {
        padding-bottom: 4em;
      }

      /* Hide the side nav in continuous mode */
      body:has(#reader:not(.book-mode)) .book-info .pages,
      body:has(#reader:not(.book-mode)) .side-nav {
        display: none !important;
      }

      /* Responsive Adjustments */
@media (max-width:1200px) {
  .chapter.active {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 90vh; 
  max-height: 90vh; 
  background: var(--sidebar-bg); 
  box-shadow: 0 0 10px var(--shadow);
  margin: auto;
  align-items: center;
  justify-content: center;
  padding: 1em;
}


  .page {
    width: 100%;
    min-width: 100%;
    max-width: 100%;
    height: auto;
    min-height: calc(100vh - 80px);
    max-height: none;
    box-sizing: border-box;
    font-size: 1.2em;
	line-height: 1.6;
    padding: 20px !important;
    overflow-y: visible;
  }

  .page * {
    max-width: 100%;
    overflow-wrap: break-word;
    word-wrap: break-word;
  }

  .page p {
    margin: 0.3em 0;
    width: 100%;
    text-align: justify;
  }

  #chapters.book-mode {
    max-width: 100%;
    width: 100%;
    height: auto;
    min-height: calc(100vh - 2em);
    padding: 0;
    margin: 0;
    box-sizing: border-box;
  }

  #reader.book-mode {
    padding: 0;
    height: auto;
    min-height: 100vh;
    margin: 0;
    box-sizing: border-box;
  }

  .page.active + .page.active {
    display: none; 
  }

  .side-nav {
    transform: scale(0.7);
    opacity: 0.9;
  }
  .side-nav.prev { left: 0; }
  .side-nav.next { right: 0; }

  #reader:not(.book-mode) {
    padding: 1em;
    padding-bottom: 6em;
    overflow: visible;
  }
  #reader:not(.book-mode) .chapter {
    padding: 1.5em;
    padding-bottom: 8em;
    overflow: visible;
	font-size: 2.3em;
  }
  #reader:not(.book-mode) .chapter:last-child {
    margin-bottom: 8em;
  }

  #chapters {
    padding-bottom: 2em;
  }
  body {
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: none;
  }
  .page-spread.active {
    padding: 0;
  }
 
  .page.active > div {
  font-size: 1.9em;
  }
  

  .nav-button {
    font-size: 1.6em !important; 
    padding: 14px 20px !important; 
    min-width: 60px !important;
    min-height: 60px !important;
    border-radius: 8px !important; 
  }
  .menu-trigger {
    font-size: 3.7em !important; 
    padding: 14px !important;
    width: 65px !important;
    height: 65px !important;
    border-radius: 8px !important;
    position: absolute;
    top: -10px; 
    right: 15px; 
    z-index: 1000 !important; 
  }
   .menu-dropdown {
    width: 55% !important;
    max-width: 480px !important;
    font-size: 1.2em !important;
    padding: 25px !important;
    border-radius: 10px !important;
    box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.4) !important;
    position: absolute;
    top: 80px !important;
    right: 10px !important;
  }
.meta-label, .menu-group-title {
    font-size: 1.2em !important;
    font-weight: bold;
    color: #aaa !important;
  }

  .meta-value {
    font-size: 1.4em !important;
    color: var(--accent);
  }

  .meta-item {
    padding: 12px 0 !important;
  }
   #page-info {
    font-size: 2em !important;
    font-weight: bold;
    position: absolute;
    top: 18px;
    right: 90px;
    white-space: nowrap !important;
    text-align: right;
  }
   .side-nav .nav-button {
	font-size: 3em; !important;
  }
}


      /* Loading Spinner */
      #loading-spinner {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: var(--bg);
        display: flex;
        justify-content: center;
        align-items: center;
        z-index: 1000;
      }
      .spinner {
        width: 20px;
        height: 20px;
        border: 2px solid rgba(255, 255, 255, 0.1);
        border-top: 2px solid var(--accent);
        border-radius: 50%;
        animation: spin 0.8s linear infinite;
      }
      @keyframes spin {
        0% {
          transform: rotate(0);
        }
        100% {
          transform: rotate(360deg);
        }
      }
      body.light #loading-spinner {
        background: var(--bg);
      }
      body.light .spinner {
        border-color: rgba(0, 0, 0, 0.1);
        border-top-color: var(--accent);
      }

      /* Dragover effect for uploading */
      .upload-area.drag-over {
        border: 2px dashed var(--accent);
      }

/* Master page styles */
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
}

#collector-iframe,
#epub-iframe {
  width: 100%;
  height: 99vh;  
  border: none;
}
