/* AI Book Reader - Kindle-like Styles */

/* Base styles */
* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Book Viewer Container */
#book-viewer {
  width: 100%;
  height: 100%;
  background: #ffffff;
  position: relative;
}

/* EPUB.js iframe styling */
#book-viewer iframe {
  border: none;
  width: 100%;
  height: 100%;
}

/* Make EPUB content readable */
#book-viewer iframe body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.7;
  font-size: 18px;
  color: #1f2937;
  padding: 2rem 3rem !important;
  max-width: 800px;
  margin: 0 auto;
}

/* Text selection styling - Highlight yellow like Kindle */
::selection {
  background-color: #fef3c7;
  color: #92400e;
}

::-moz-selection {
  background-color: #fef3c7;
  color: #92400e;
}

/* Make text selectable and interactive */
#book-viewer {
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
  -moz-user-select: text;
}

/* TOC Styling */
#toc-container {
  max-height: calc(100vh - 140px);
  overflow-y: auto;
}

#toc-container a {
  display: block;
  padding: 0.75rem 1rem;
  color: #4b5563;
  text-decoration: none;
  border-radius: 0.5rem;
  transition: all 0.2s;
  font-size: 0.95rem;
  border-left: 3px solid transparent;
}

#toc-container a:hover {
  background-color: #f3f4f6;
  color: #1f2937;
  border-left-color: #3b82f6;
}

#toc-container a.active {
  background-color: #dbeafe;
  color: #1e40af;
  font-weight: 600;
  border-left-color: #2563eb;
}

#toc-container .toc-level-1 {
  font-weight: 600;
  margin-top: 0.75rem;
}

#toc-container .toc-level-2 {
  padding-left: 2rem;
  font-size: 0.9rem;
}

#toc-container .toc-level-3 {
  padding-left: 3rem;
  font-size: 0.85rem;
  color: #6b7280;
}

/* Sidebar animations */
#sidebar {
  transition: transform 0.3s ease-in-out;
}

#sidebar.open {
  transform: translateX(0);
}

/* Floating Explain Button */
#floating-explain-btn {
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 40;
  cursor: pointer;
  display: none;
}

#floating-explain-btn.show {
  opacity: 1;
  pointer-events: auto;
  animation: bounceIn 0.5s ease-out;
  z-index: 40;
  display: block;
}

#floating-explain-btn.hidden {
  display: none !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

@keyframes bounceIn {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(-30px) scale(0.8);
  }
  50% {
    transform: translateX(-50%) translateY(5px) scale(1.05);
  }
  100% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
}

#floating-explain-btn:hover {
  box-shadow: 0 20px 40px rgba(79, 70, 229, 0.4);
}

#floating-explain-btn:active {
  transform: translateX(-50%) scale(0.95);
}

/* AI Popup animations */
#ai-popup {
  animation: fadeInPopup 0.3s ease-out;
  backdrop-filter: blur(4px);
}

@keyframes fadeInPopup {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

#ai-popup > div {
  animation: slideUpPopup 0.3s ease-out;
}

@keyframes slideUpPopup {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Selected text highlighting */
#selected-text {
  max-height: 150px;
  overflow-y: auto;
}

/* Explanation content */
#explanation-content {
  min-height: 100px;
  line-height: 1.8;
}

/* Popup buttons */
#ai-popup button {
  transition: all 0.2s;
}

#ai-popup button:active {
  transform: scale(0.95);
}

/* Loading animation */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.animate-pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Navigation buttons */
#nav-controls button {
  font-weight: 500;
  box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
}

#nav-controls button:active:not(:disabled) {
  transform: scale(0.98);
}

/* Book info header */
#book-info {
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

/* Responsive design */
@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: 0;
    top: 57px;
    height: calc(100vh - 57px);
    z-index: 40;
    transform: translateX(-100%);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #book-viewer iframe body {
    padding: 1.5rem 1rem !important;
    font-size: 16px;
  }

  #nav-controls {
    padding: 0.5rem 1rem;
  }

  #nav-controls button {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
  }

  #nav-controls button span:not(.sr-only) {
    display: none;
  }

  #nav-controls button i {
    margin: 0;
  }
}

/* Kindle-like page transitions */
.epub-container {
  transition: opacity 0.3s ease-in-out;
}

/* Focus states for accessibility */
button:focus,
a:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* Loading overlay */
#loading-overlay {
  backdrop-filter: blur(4px);
}

/* Print styles */
@media print {
  header,
  #nav-controls,
  #sidebar,
  #ai-tooltip {
    display: none !important;
  }

  #book-viewer {
    height: auto;
  }
}

/* Improve text rendering */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Ensure proper stacking */
#ai-tooltip {
  z-index: 1000;
}

#loading-overlay {
  z-index: 9999;
}

/* Sidebar backdrop for mobile */
@media (max-width: 768px) {
  #sidebar.open::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: -1;
  }
}

/* Better iframe content styling */
#book-viewer iframe html {
  height: 100%;
}

#book-viewer iframe body {
  height: 100%;
  overflow-y: auto;
}

/* Ensure content is centered and readable */
#book-viewer iframe body p {
  margin-bottom: 1em;
  text-align: justify;
  hyphens: auto;
}

#book-viewer iframe body h1,
#book-viewer iframe body h2,
#book-viewer iframe body h3,
#book-viewer iframe body h4,
#book-viewer iframe body h5,
#book-viewer iframe body h6 {
  margin-top: 1.5em;
  margin-bottom: 0.75em;
  font-weight: 700;
  color: #111827;
  line-height: 1.3;
}

#book-viewer iframe body h1 {
  font-size: 2em;
}

#book-viewer iframe body h2 {
  font-size: 1.5em;
}

#book-viewer iframe body h3 {
  font-size: 1.25em;
}

/* Better image handling in books */
#book-viewer iframe body img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5em auto;
}

/* Blockquotes styling */
#book-viewer iframe body blockquote {
  margin: 1.5em 0;
  padding-left: 1.5em;
  border-left: 4px solid #e5e7eb;
  color: #6b7280;
  font-style: italic;
}

/* Better list styling */
#book-viewer iframe body ul,
#book-viewer iframe body ol {
  margin: 1em 0;
  padding-left: 2em;
}

#book-viewer iframe body li {
  margin-bottom: 0.5em;
}

/* Code blocks in books */
#book-viewer iframe body code {
  background-color: #f3f4f6;
  padding: 0.2em 0.4em;
  border-radius: 0.25em;
  font-size: 0.9em;
  font-family: 'Courier New', monospace;
}

#book-viewer iframe body pre {
  background-color: #f3f4f6;
  padding: 1em;
  border-radius: 0.5em;
  overflow-x: auto;
  margin: 1.5em 0;
}

#book-viewer iframe body pre code {
  background: none;
  padding: 0;
}
