/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body, html {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #333;
  overflow-x: hidden;
}

/* Loading Screen */
.loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  color: white;
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top: 4px solid white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Header */
.reader-header {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 0;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}

.menu-btn, .search-btn {
  background: none;
  border: none;
  font-size: 20px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s;
  color: #667eea;
}

.menu-btn:hover, .search-btn:hover {
  background-color: rgba(102, 126, 234, 0.1);
}

#bookTitle {
  font-size: 18px;
  font-weight: 600;
  color: #333;
  margin: 0;
  flex: 1;
  text-align: center;
}

/* Search Bar */
.search-bar {
  display: flex;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.98);
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

#searchInput {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

#searchInput:focus {
  border-color: #667eea;
}

#closeSearch {
  background: none;
  border: none;
  font-size: 18px;
  padding: 8px 12px;
  margin-left: 8px;
  cursor: pointer;
  color: #666;
}

/* Main Content */
.reader {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 120px);
}

/* Library View */
.book-library {
  padding: 20px 16px;
  flex: 1;
}

.library-header {
  text-align: center;
  margin-bottom: 30px;
  color: white;
}

.library-header h2 {
  font-size: 28px;
  margin-bottom: 8px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.library-header p {
  font-size: 16px;
  opacity: 0.9;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

/* Book Cards */
.book-card {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: all 0.3s ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.book-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #667eea, #764ba2);
}

.book-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.book-card h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  color: #333;
  line-height: 1.4;
}

.book-card .book-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  font-size: 14px;
  color: #666;
}

.book-card .book-actions {
  display: flex;
  gap: 8px;
}

.book-card .btn {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  flex: 1;
}

.book-card .btn-primary {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
}

.book-card .btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.book-card .btn-secondary {
  background: rgba(102, 126, 234, 0.1);
  color: #667eea;
  border: 1px solid rgba(102, 126, 234, 0.3);
}

.book-card .btn-secondary:hover {
  background: rgba(102, 126, 234, 0.2);
}

/* Class Headers */
.class-header {
  grid-column: 1 / -1;
  text-align: center;
  margin: 30px 0 20px;
  color: white;
  font-size: 24px;
  font-weight: 600;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Reader View */
.reader-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #f8f9fa;
}

.reader-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: white;
  border-bottom: 1px solid #e9ecef;
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar-left, .toolbar-center, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-info {
  font-size: 14px;
  color: #666;
  font-weight: 500;
}

.zoom-btn, .fullscreen-btn {
  background: none;
  border: 1px solid #ddd;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.zoom-btn:hover, .fullscreen-btn:hover {
  background: #f8f9fa;
  border-color: #667eea;
}

.flipbook-container {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  background: #f8f9fa;
}

/* Footer */
.reader-footer {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  padding: 16px;
  position: sticky;
  bottom: 0;
}

.footer-buttons {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 600px;
  margin: 0 auto;
  gap: 16px;
}

.nav-btn {
  background: linear-gradient(135deg, #667eea, #764ba2);
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  color: white;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 80px;
}

.nav-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.nav-btn:active {
  transform: translateY(0);
}

.btn-icon {
  font-size: 18px;
}

.btn-text {
  font-size: 12px;
}

.page-controls {
  display: flex;
  gap: 12px;
}

.back-btn {
  background: linear-gradient(135deg, #6c757d, #495057);
}

.back-btn:hover {
  box-shadow: 0 6px 20px rgba(108, 117, 125, 0.4);
}

.play-btn {
  background: linear-gradient(135deg, #28a745, #20c997);
}

.play-btn:hover {
  box-shadow: 0 6px 20px rgba(40, 167, 69, 0.4);
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 20px;
}

.modal-content {
  background: white;
  border-radius: 16px;
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid #e9ecef;
}

.modal-header h3 {
  margin: 0;
  color: #333;
  font-size: 20px;
}

.close-btn {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #666;
  padding: 4px;
}

.modal-body {
  padding: 24px;
}

.book-info {
  margin-bottom: 24px;
}

.book-info p {
  margin-bottom: 8px;
  color: #666;
}

.book-info strong {
  color: #333;
}

.modal-actions {
  display: flex;
  gap: 12px;
}

.primary-btn, .secondary-btn {
  flex: 1;
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.primary-btn {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
}

.primary-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.secondary-btn {
  background: rgba(102, 126, 234, 0.1);
  color: #667eea;
  border: 1px solid rgba(102, 126, 234, 0.3);
}

.secondary-btn:hover {
  background: rgba(102, 126, 234, 0.2);
}

/* Responsive Design */
@media (max-width: 768px) {
  .book-grid {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 0 8px;
  }
  
  .book-card {
    padding: 16px;
  }
  
  .book-card h3 {
    font-size: 16px;
  }
  
  .footer-buttons {
    flex-direction: column;
    gap: 12px;
  }
  
  .page-controls {
    order: -1;
    width: 100%;
    justify-content: center;
  }
  
  .back-btn {
    order: 1;
    width: 100%;
  }
  
  .nav-btn {
    min-width: 60px;
    padding: 10px 12px;
  }
  
  .btn-text {
    font-size: 11px;
  }
  
  .reader-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  
  .toolbar-left, .toolbar-center, .toolbar-right {
    justify-content: center;
  }
  
  .modal-content {
    margin: 20px;
    max-height: calc(100vh - 40px);
  }
  
  .modal-actions {
    flex-direction: column;
  }
}

@media (max-width: 480px) {
  .header-content {
    padding: 10px 12px;
  }
  
  #bookTitle {
    font-size: 16px;
  }
  
  .library-header h2 {
    font-size: 24px;
  }
  
  .book-card {
    padding: 14px;
  }
  
  .nav-btn {
    padding: 8px 10px;
    min-width: 50px;
  }
  
  .btn-icon {
    font-size: 16px;
  }
  
  .btn-text {
    font-size: 10px;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  body {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  }
  
  .book-card {
    background: rgba(30, 30, 50, 0.95);
    color: #e0e0e0;
  }
  
  .book-card h3 {
    color: #e0e0e0;
  }
  
  .reader-header, .reader-footer {
    background: rgba(30, 30, 50, 0.95);
    color: #e0e0e0;
  }
  
  .reader-view {
    background: #1a1a2e;
  }
  
  .reader-toolbar {
    background: rgba(30, 30, 50, 0.95);
    color: #e0e0e0;
  }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus styles for keyboard navigation */
button:focus, input:focus {
  outline: 2px solid #667eea;
  outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .book-card {
    border: 2px solid #000;
  }
  
  .nav-btn {
    border: 2px solid #000;
  }
}
