:root {
  --active-bg: rgba(0, 0, 0, 0.05);
}

@supports (color-scheme: light dark) {
  @media (prefers-color-scheme: dark) {
    :root {
      --active-bg: rgba(255, 255, 255, 0.1);
    }
  }
}

html {
  height: 100%;
}

body {
  margin: 0 auto;
  height: 100%;
  font: menu;
  font-family: system-ui, sans-serif;
}

#drop-target {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  visibility: hidden;
}

#drop-target h1 {
  font-weight: 900;
}

#file-button {
  font: inherit;
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline;
  cursor: pointer;
}

.icon {
  display: block;
  fill: none;
  stroke: currentcolor;
  stroke-width: 2px;
}

.empty-state-icon {
  margin: auto;
}

.toolbar {
  box-sizing: border-box;
  position: absolute;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 48px;
  padding: 6px;
  transition: opacity 250ms ease;
  visibility: hidden;
}

.toolbar button {
  padding: 3px;
  border-radius: 6px;
  background: none;
  border: 0;
  color: GrayText;
}

.toolbar button:hover {
  background: rgba(0, 0, 0, 0.1);
  color: currentcolor;
}

#header-bar {
  top: 0;
}

#nav-bar {
  bottom: 0;
}

#progress-slider {
  flex-grow: 1;
  margin: 0 12px;
  visibility: hidden;
}

#side-bar {
  visibility: hidden;
  box-sizing: border-box;
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  height: 100%;
  width: 320px;
  transform: translateX(-320px);
  display: flex;
  flex-direction: column;
  background: Canvas;
  color: CanvasText;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2), 0 0 40px rgba(0, 0, 0, 0.2);
  transition: visibility 0s linear 300ms, transform 300ms ease;
}

#side-bar.show {
  visibility: visible;
  transform: translateX(0);
  transition-delay: 0s;
}

#dimming-overlay {
  visibility: hidden;
  position: fixed;
  z-index: 2;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: visibility 0s linear 300ms, opacity 300ms ease;
}

#dimming-overlay.show {
  visibility: visible;
  opacity: 1;
  transition-delay: 0s;
}

#side-bar-header {
  padding: 1rem;
  display: flex;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  align-items: center;
}

#side-bar-cover {
  height: 10vh;
  min-height: 60px;
  max-height: 180px;
  border-radius: 3px;
  border: 0;
  background: lightgray;
  box-shadow: 0 0 1px rgba(0, 0, 0, 0.1), 0 0 16px rgba(0, 0, 0, 0.1);
  margin-inline-end: 1rem;
}

#side-bar-cover:not([src]) {
  display: none;
}

#side-bar-title {
  margin: 0.5rem 0;
  font-size: inherit;
}

#side-bar-author {
  margin: 0.5rem 0;
  font-size: small;
  color: GrayText;
}

#toc-view {
  padding: 0.5rem;
  overflow-y: scroll;
}

#toc-view li,
#toc-view ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

#toc-view a,
#toc-view span {
  display: block;
  border-radius: 6px;
  padding: 8px;
  margin: 2px 0;
}

#toc-view a {
  color: CanvasText;
  text-decoration: none;
}

#toc-view a:hover {
  background: var(--active-bg);
}

#toc-view span {
  color: GrayText;
}

#toc-view svg {
  margin-inline-start: -24px;
  padding-inline-start: 5px;
  padding-inline-end: 6px;
  fill: CanvasText;
  cursor: default;
  transition: transform 0.2s ease;
  opacity: 0.5;
}

#toc-view svg:hover {
  opacity: 1;
}

#toc-view [aria-current] {
  font-weight: bold;
  background: var(--active-bg);
}

#toc-view [aria-expanded="false"] svg {
  transform: rotate(-90deg);
}

#toc-view [aria-expanded="false"] + [role="group"] {
  display: none;
}

.menu-container {
  position: relative;
}

.menu,
.menu ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.menu {
  visibility: hidden;
  position: absolute;
  right: 0;
  background: Canvas;
  color: CanvasText;
  border-radius: 6px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2), 0 0 16px rgba(0, 0, 0, 0.1);
  padding: 6px;
  cursor: default;
}

.menu.show {
  visibility: visible;
}

.menu li {
  padding: 6px 12px;
  padding-left: 24px;
  border-radius: 6px;
}

.menu li:hover {
  background: var(--active-bg);
}

.menu li[aria-checked="true"] {
  background-position: center left;
  background-repeat: no-repeat;
  background-image: url("data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%3E%3Ccircle%20cx%3D%2212%22%20cy%3D%2212%22%20r%3D%223%22%2F%3E%3C%2Fsvg%3E");
}

.popover {
  background: Canvas;
  color: CanvasText;
  border-radius: 6px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2), 0 0 16px rgba(0, 0, 0, 0.1),
    0 0 32px rgba(0, 0, 0, 0.1);
}

.popover-arrow-down {
  fill: Canvas;
  filter: drop-shadow(0 -1px 0 rgba(0, 0, 0, 0.2));
}

.popover-arrow-up {
  fill: Canvas;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.2));
}

#back-to-index {
  margin: 20px 24px 0;
  text-align: center;
}

#back-to-index-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-color, #9c8d8d);
  text-decoration: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 500;
  transition: all 0.25s ease;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

#back-to-index-link:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

#back-to-index-link svg {
  transition: transform 0.2s ease;
}

#back-to-index-link:hover svg {
  transform: translateX(-4px);
}

/* Dark mode support (if your reader already uses dark theme) */
@media (prefers-color-scheme: dark) {
  #back-to-index-link {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #cfcfcf;
  }
  #back-to-index-link:hover {
    background: rgba(0, 0, 0, 0.5);
  }
}

/* Add this to your reader.css or inside a <style> tag */
#epub-error-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  align-items: center;
  justify-content: center;
  z-index: 99999;
  display: none;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  backdrop-filter: blur(5px);
}

#epub-error-overlay.visible {
  display: flex;
}

.epub-error-modal {
  background: var(--bg-color, #fff);
  color: var(--text-color, #222);
  max-width: 420px;
  width: 90%;
  border-radius: 16px;
  padding: 32px 24px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
  position: relative;
}

.epub-error-icon {
  margin-bottom: 16px;
  color: #e74c3c;
}

.epub-error-modal h2 {
  margin: 0 0 12px;
  font-size: 1.4rem;
  font-weight: 600;
}

.epub-error-modal p {
  margin: 0 0 24px;
  opacity: 0.85;
  line-height: 1.5;
}

.epub-error-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.epub-btn-primary,
.epub-btn-secondary {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.epub-btn-primary {
  background: #3498db;
  color: white;
}

.epub-btn-primary:hover {
  background: #2980b9;
}

.epub-btn-secondary {
  background: transparent;
  color: #3498db;
  border: 1.5px solid #3498db;
}

.epub-btn-secondary:hover {
  background: rgba(52, 152, 219, 0.1);
}

.epub-error-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: #999;
  cursor: pointer;
  padding: 4px;
}

@media (prefers-color-scheme: dark) {
  .epub-error-modal {
    background: #1a1a1a;
    color: #eee;
  }
  .epub-error-close {
    color: #aaa;
  }
}

#spinner {
  position: fixed;
  z-index: 99999;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

#spinner::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  background: currentColor;
  animation: pulse 1.4s ease-in-out infinite both;
  box-shadow: 16px 0 currentColor, -16px 0 currentColor;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  50% {
    opacity: 1;
    transform: scale(1.2);
  }
}

/* Light mode */
@media (prefers-color-scheme: light) {
  #spinner::before {
    color: #222;
  }
}

/* --- OFFLINE CONTROLS STYLES (NEW) --- */

/* Container for all controls (Badge, Buttons, Progress, Size) */
#offline-controls {
  display: flex;
  flex-direction: column;
  gap: 8px !important;
  padding: 12px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.05);
  align-items: center;
}

/* Dark mode support for the container */
@media (prefers-color-scheme: dark) {
  #offline-controls {
    background: rgba(26, 26, 26, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.05);
  }
}

/* Ensure all buttons inside have a minimum width for consistency */
#offline-controls button {
  min-width: 180px;
  text-align: center;
}

/* Offline Ready Badge */
#offlineBadge {
  /* Override inline styles for cleaner presentation */
  display: none;
  background-color: #28a745 !important;
  color: white !important;
  padding: 6px 12px !important;
  border-radius: 6px !important;
  font-size: 14px !important;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  margin-bottom: 2px; /* Space above the top button */
}

/* Download Progress Bar */
#downloadProgress {
  width: 100%;
  height: 8px !important;
  border: none;
  border-radius: 4px;
  overflow: hidden;
}

/* Customizing progress bar for cross-browser consistency */
#downloadProgress::-webkit-progress-bar {
  background-color: #ecf0f1; /* Light grey track */
}
#downloadProgress::-webkit-progress-value {
  background-color: #3498db; /* Blue progress fill */
}
#downloadProgress::-moz-progress-bar {
  background-color: #3498db;
}

/* PWA Install Button Visibility Fix (It should be part of the offline controls group) */
#installBtn {
  display: block;
  margin-top: 5px; /* Separate it visually from the other controls */
}

/* Hiding utility class for the download components */
.hidden {
  display: none !important;
}

/* Hide remove button until downloaded (Controlled by JS: checkOfflineStatus) */
#removeOfflineBtn {
  display: none;
}

.epub-btn-danger {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  background: #e74c3c; /* Red color for removal action */
  color: white;
}

.epub-btn-danger:hover {
  background: #c0392b; /* Darker red on hover */
}
