:root {
  --bg-body: #f8f9fa;
  --bg-card: #ffffff;
  --text-primary: #2c3e50;
  --text-secondary: #6c757d;
  --accent: #e67e22;
  --accent-hover: #d35400;
  --border: #e9ecef;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)
}

body.dark-mode {
  --bg-body: #121212;
  --bg-card: #1e1e1e;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0a0;
  --border: #333;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5)
}

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

a {
  text-decoration: none;
}

body {
  font-display: swap;
  font-family: Segoe UI, Arial, serif;
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden
}

/* Screen reader only class for accessibility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0
}

.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  contain: layout style;
  height: 70px
}

.nav-brand a h1 {
  font-size: 1.5rem;
  color: var(--text-primary);
}

.nav-actions {
  display: flex;
  gap: 0.5rem
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: .5rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.2rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s
}

.icon-btn:hover {
  background: var(--border)
}

.main-container {
  max-width: 1200px;
  margin: 0 auto;
  min-height: 80vh
}

.page-header {
  text-align: center;
  padding: 2rem 1rem
}

.page-header h2 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  font-weight: 700
}

.page-header p {
  font-size: 1rem
}

.toolbar-sticky {
  position: sticky;
  top: 70px;
  z-index: 90;
  background: var(--bg-body);
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
  contain: layout style
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center
}

.search-box {
  flex: 1 1 300px;
  position: relative
}

.search-box input {
  width: 100%;
  padding: .8rem 1rem .8rem 2.8rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 1rem;
  transition: border-color 0.2s
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent)
}

.search-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  opacity: .5;
  pointer-events: none
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .8rem;
  flex: 1 1 auto;
  justify-content: flex-end
}

.filter-group {
  display: flex;
  gap: 0.5rem
}

.filter-chip {
  padding: .6rem 1.2rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  border-radius: 20px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
  white-space: nowrap
}

.filter-chip:hover {
  border-color: var(--accent)
}

.filter-chip.active {
  box-shadow: var(--shadow);
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--accent-hover);
  border-width: 2px
}

.sort-select {
  padding: .6rem 2rem .6rem 1rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.95rem
}

.sort-select:focus {
  outline: none;
  border-color: var(--accent)
}

.books-grid {
  display: grid;
  padding: 1.5rem;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  min-height: 250px;
  contain: layout
}

.book-card {
  text-rendering: optimizeSpeed;
  content-visibility: auto;
  contain-intrinsic-size: 0 400px;
  background: var(--bg-card);
  border-radius: 16px;
  padding: 1.5rem;
  position: relative;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  will-change: transform
}

.book-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / .1);
  border-color: var(--accent)
}

.card-link-overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: 16px
}

.favorite-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 2;
  background: var(--bg-card);
  border: 1px solid var(--border);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: transform 0.2s;
  will-change: transform
}

.favorite-btn:hover {
  transform: scale(1.1)
}

.favorite-btn.active {
  border-color: red;
  color: red
}

.book-emoji {
  font-size: 3rem;
  margin-bottom: 1rem;
  display: block;
  line-height: 1
}

.book-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: .25rem;
  color: var(--text-primary);
  line-height: 1.3
}

.book-author {
  font-size: .9rem;
  color: var(--text-secondary);
  margin-bottom: 1rem
}

.book-preview {
  font-size: .95rem;
  color: var(--text-primary);
  opacity: .8;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.5
}

.loading,
.no-results,
.error {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
  font-size: 1.1rem
}

.error {
  color: #dc3545
}

.load-more-container {
  display: flex;
  justify-content: center;
  text-align: center;
  margin: 2rem 0;
}

.load-more-btn {
  padding: .8rem 2rem;
  background: var(--text-primary);
  color: var(--bg-body);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: opacity 0.2s;
  font-size: 1rem
}

.load-more-btn:hover {
  opacity: 0.9
}

.load-more-btn:disabled {
  opacity: .5;
  cursor: not-allowed
}

.page-footer {
  contain: strict;
  content-visibility: auto;
  contain-intrinsic-size: auto 120px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 2rem 1.5rem;
  margin-top: 3rem;
  text-align: center;
}

.footer-content {
  margin: 0 auto;
  align-items: center;
  display: grid;
}

.footer-content p {
  margin-bottom: 1rem;
  color: var(--text-secondary)
}

.footer-content nav {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap
}

.footer-content a {
  color: var(--text-primary);
  text-decoration: none;
  transition: color 0.2s
}

.footer-content a:hover {
  color: var(--accent)
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / .5);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(2px)
}

.modal.active {
  display: flex
}

.modal-content {
  background: var(--bg-card);
  padding: 2rem;
  border-radius: 16px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 20px 25px -5px rgb(0 0 0 / .1)
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem
}

.modal-header h2 {
  font-size: 1.5rem
}

.modal-links {
  display: flex;
  flex-direction: column;
  gap: 0.5rem
}

.modal-links a {
  display: block;
  padding: 1rem;
  color: var(--text-primary);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  border-radius: 8px;
  transition: background 0.2s
}

.modal-links a:hover {
  background: var(--bg-body)
}

.modal-links a:last-child {
  border-bottom: none
}

.menu-item-title {
  font-weight: 600;
  margin-bottom: 0.25rem
}

.menu-item-desc {
  font-size: 0.9rem;
  color: var(--text-secondary)
}

.close-btn {
  background: none;
  border: none;
  font-size: 2rem;
  color: var(--text-primary);
  cursor: pointer;
  line-height: 1;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s
}

.close-btn:hover {
  background: var(--border)
}

@media (max-width: 768px) {
  .page-header h2 {
    font-size: 1.4rem;
  }
  
  .toolbar {
    gap: 0.8rem
  }
  
  .toolbar-actions {
    justify-content: flex-start;
    width: 100%
  }
  
  .filter-group {
    display: flex;
    gap: .5rem;
    width: 100%;
    overflow-x: auto;
    padding-bottom: .5rem;
    -webkit-overflow-scrolling: touch
  }
  
  .search-box {
    width: 100%;
    flex: 1 1 100%
  }
  
  .books-grid {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
    padding: 1rem
  }
  
  .book-card {
    padding: 1.25rem
  }
  
  .modal-content {
    width: 95%;
    padding: 1.5rem
  }
}

@media (max-width: 480px) {
  .books-grid {
    grid-template-columns: 1fr;
    padding: 0.75rem
  }
  
  .navbar {
    padding: 0.75rem 1rem
  }
  
  .nav-brand a h1 {
    font-size: 1.25rem;
  }
}