/* Card Stack */
.card-stack {
  position: relative;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  max-height: calc(
    100vh - 120px
  ); /* Only reserve space for header since buttons float */
  margin: 0.25rem 0.5rem;
  overflow: hidden;
}

/* Book Card */
.book-card {
  position: absolute;
  width: 100%;
  max-width: min(420px, calc(100vw - 1rem)); /* Better use of screen space */
  height: calc(100vh - 140px); /* More height available since buttons float */
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  cursor: grab;
  user-select: none;
  transform-origin: center center;
  transition: transform 0.3s ease; /* Removed box-shadow transition to prevent hover effects */
  box-shadow: var(--shadow-lg) !important; /* Force static shadow */
  display: flex;
  flex-direction: column;
}

.book-card:active {
  cursor: grabbing;
}

.book-card.dragging {
  transition: none;
}

/* Explicitly disable any box-shadow transitions on cards */
.book-card,
.book-card *,
.book-card::before,
.book-card::after {
  transition:
    transform 0.3s ease,
    opacity 0.3s ease !important;
}

.book-card.swiping-left {
  transform: translateX(-100%) rotate(-30deg);
  opacity: 0;
}

.book-card.swiping-right {
  transform: translateX(100%) rotate(30deg);
  opacity: 0;
}

/* Card stacking effect */
.book-card:nth-child(1) {
  z-index: 10;
  transform: scale(1) translateY(0);
}

.book-card:nth-child(2) {
  z-index: 9;
  transform: scale(0.95) translateY(10px);
  opacity: 0.8;
}

.book-card:nth-child(3) {
  z-index: 8;
  transform: scale(0.9) translateY(20px);
  opacity: 0.6;
}

.book-card:nth-child(n + 4) {
  z-index: 7;
  transform: scale(0.85) translateY(30px);
  opacity: 0.4;
}

/* Book Header - Cover and Title Side by Side */
.book-header {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.book-cover {
  width: 80px;
  height: 120px;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--bg-tertiary), var(--border-color));
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  overflow: hidden;
}

.book-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 4px;
}

.book-cover.no-image {
  background: linear-gradient(
    135deg,
    var(--primary-color),
    var(--accent-purple)
  );
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
  padding: 0.5rem;
}

.book-header-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  min-width: 0; /* Allow text to truncate */
  gap: 0.5rem;
}

/* Card Content */
.card-content {
  padding: 0.75rem;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
  scroll-behavior: smooth;

  /* Always show scrollbar when content overflows */
  scrollbar-width: thin;
  scrollbar-color: var(--primary-color) var(--bg-tertiary);
}

/* Custom scrollbar for WebKit browsers */
.card-content::-webkit-scrollbar {
  width: 6px;
}

.card-content::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
  border-radius: 3px;
}

.card-content::-webkit-scrollbar-thumb {
  background: var(--primary-color);
  border-radius: 3px;
}

.card-content::-webkit-scrollbar-thumb:hover {
  background: var(--primary-hover);
}

/* Scroll indicator for when content overflows */
.card-content.has-overflow {
  position: relative;
}

.card-content.has-overflow::after {
  content: "⇅";
  position: absolute;
  top: 50%;
  right: -15px;
  transform: translateY(-50%);
  background: var(--primary-color);
  color: white;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  opacity: 0.8;
  pointer-events: none;
  z-index: 10;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.8;
  }
  50% {
    opacity: 0.4;
  }
}

.book-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  line-height: 1.3;
  color: var(--text-primary);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.book-author {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  font-weight: 500;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.book-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-light);
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.meta-separator {
  color: var(--border-color);
}

/* Genre Tags - Now in header */
.book-header-info .genre-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 0;
}

.book-header-info .genre-tag {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  background: var(--primary-color);
  color: white;
  border-radius: var(--radius-md);
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: lowercase;
}

.book-header-info .genre-tag:nth-child(2n) {
  background: var(--accent-purple);
}

.book-header-info .genre-tag:nth-child(3n) {
  background: var(--success-color);
}

.book-header-info .genre-tag:nth-child(4n) {
  background: var(--warning-color);
}

.book-header-info .genre-tag:nth-child(5n) {
  background: var(--danger-color);
}

/* Rating and Stats - Now in header */
.book-header-info .book-stats {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  margin: 0;
  padding: 0;
  border: none;
}

.book-header-info .rating {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--warning-color);
  font-weight: 600;
}

.book-header-info .rating-stars {
  color: var(--warning-color);
}

.book-header-info .vote-count {
  color: var(--text-light);
  font-size: 0.75rem;
}

/* Original Genre Tags - Keep for backward compatibility but hide */
.genre-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.genre-tag {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: var(--primary-color);
  color: white;
  border-radius: var(--radius-md);
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: lowercase;
}

.genre-tag:nth-child(2n) {
  background: var(--accent-purple);
}

.genre-tag:nth-child(3n) {
  background: var(--success-color);
}

.genre-tag:nth-child(4n) {
  background: var(--warning-color);
}

.genre-tag:nth-child(5n) {
  background: var(--danger-color);
}

/* Book Synopsis */
.book-synopsis {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

/* Rating and Stats */
.book-stats {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.875rem;
}

.rating {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--warning-color);
  font-weight: 600;
}

.rating-stars {
  color: var(--warning-color);
}

.vote-count {
  color: var(--text-light);
  font-size: 0.8rem;
}

/* Swipe Indicators */
.swipe-indicator {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  padding: 1rem 1.5rem;
  border-radius: var(--radius-lg);
  font-size: 1.5rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 15;
}

.swipe-indicator.like {
  right: 1rem;
  background: var(--success-color);
  color: white;
  border: 3px solid white;
}

.swipe-indicator.pass {
  left: 1rem;
  background: var(--danger-color);
  color: white;
  border: 3px solid white;
}

.swipe-indicator.show {
  opacity: 1;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
}

.empty-state .empty-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.empty-state h3 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.empty-state p {
  font-size: 1rem;
  line-height: 1.5;
}

/* Loading Card */
.loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 2rem;
  background: var(--bg-secondary);
  border-radius: var(--radius-xl);
  border: 2px dashed var(--border-color);
}

.loading-card .loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-color);
  border-top: 3px solid var(--primary-color);
  margin-bottom: 1rem;
}

/* Visual hint for scrollable content in card header */
.book-card.has-scrollable-content .book-header {
  border-bottom: 2px solid var(--primary-color);
  position: relative;
}

.book-card.has-scrollable-content .book-header::after {
  content: "Scroll down to read more";
  position: absolute;
  bottom: -1.5rem;
  left: 1rem;
  right: 1rem;
  font-size: 0.75rem;
  color: var(--primary-color);
  background: var(--bg-card);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  text-align: center;
  opacity: 0;
  animation: fadeInOut 6s ease-in-out;
  pointer-events: none;
  z-index: 5;
}

@keyframes fadeInOut {
  0%,
  100% {
    opacity: 0;
    transform: translateY(-5px);
  }
  15%,
  85% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Responsive Adjustments */
@media (max-width: 480px) {
  .card-stack {
    margin: 0.25rem 0.25rem;
    max-height: calc(
      100vh - 110px
    ); /* Only header space needed since buttons float */
  }

  .book-card {
    max-width: calc(100vw - 0.5rem);
    height: calc(
      100vh - 130px
    ); /* More height available with floating buttons */
    margin: 0 0.25rem;
  }

  .book-header {
    padding: 0.75rem;
    gap: 0.75rem;
  }

  .book-cover {
    width: 80px; /* Slightly larger on mobile */
    height: 120px;
  }

  .book-title {
    font-size: 1.1rem;
  }

  .book-author {
    font-size: 0.9rem;
  }

  .book-meta {
    font-size: 0.75rem;
  }

  /* Adjust header elements on mobile */
  .book-header-info .genre-tags {
    gap: 0.3rem;
  }

  .book-header-info .genre-tag {
    font-size: 0.65rem;
    padding: 0.15rem 0.5rem;
  }

  .book-header-info .book-stats {
    font-size: 0.75rem;
  }

  .book-header-info .vote-count {
    font-size: 0.7rem;
  }

  .card-content {
    padding: 0.75rem 1rem; /* More padding for readability */
    /* Make scrollbar more visible on mobile */
    scrollbar-width: auto;
  }

  .card-content::-webkit-scrollbar {
    width: 8px;
  }

  .card-content.has-overflow::after {
    right: -18px;
    width: 24px;
    height: 24px;
    font-size: 0.8rem;
  }

  /* Add subtle background to indicate scrollable area */
  .card-content.has-overflow {
    background: linear-gradient(
      to bottom,
      var(--bg-card) 0%,
      var(--bg-secondary) 50%,
      var(--bg-card) 100%
    );
    border-radius: var(--radius-md);
    margin: 0 -0.25rem;
    padding: 0.75rem 1.25rem;
  }
}

/* Tablet and larger screens */
@media (min-width: 481px) and (max-width: 768px) {
  .card-stack {
    margin: 0.5rem;
    max-height: calc(100vh - 110px); /* Only header space needed */
  }

  .book-card {
    max-width: min(500px, calc(100vw - 1rem));
    height: calc(100vh - 130px); /* More height with floating buttons */
  }

  .book-header {
    padding: 1rem;
    gap: 1rem;
  }

  .book-cover {
    width: 90px;
    height: 135px;
  }

  .book-title {
    font-size: 1.25rem;
  }

  .book-author {
    font-size: 1rem;
  }

  .card-content {
    padding: 1rem;
  }

  .book-synopsis {
    font-size: 1rem;
    line-height: 1.6;
  }

  /* Adjust header elements on tablet */
  .book-header-info .genre-tag {
    font-size: 0.75rem;
    padding: 0.25rem 0.7rem;
  }

  .book-header-info .book-stats {
    font-size: 0.85rem;
  }
}

/* Large screens */
@media (min-width: 769px) {
  .card-stack {
    margin: 0.75rem;
    max-height: calc(100vh - 100px); /* Only header space needed */
  }

  .book-card {
    max-width: min(520px, calc(100vw - 1.5rem));
    height: calc(100vh - 120px); /* More height with floating buttons */
  }

  .book-header {
    padding: 1.25rem;
    gap: 1.25rem;
  }

  .book-cover {
    width: 100px;
    height: 150px;
  }

  .book-title {
    font-size: 1.4rem;
  }

  .book-author {
    font-size: 1.1rem;
  }

  .card-content {
    padding: 1.25rem;
  }

  .book-synopsis {
    font-size: 1.05rem;
    line-height: 1.7;
  }

  /* Adjust header elements on desktop */
  .book-header-info .genre-tag {
    font-size: 0.8rem;
    padding: 0.3rem 0.8rem;
  }

  .book-header-info .book-stats {
    font-size: 0.9rem;
  }

  .book-header-info .vote-count {
    font-size: 0.8rem;
  }
}

@media (max-height: 600px) {
  .card-stack {
    max-height: 400px;
  }

  .book-card {
    height: 400px; /* Fixed height for small screen heights */
  }

  .book-cover {
    width: 65px;
    height: 95px;
  }

  .book-header {
    padding: 0.75rem;
  }

  .card-content {
    padding: 0.75rem;
  }

  .book-synopsis {
    font-size: 0.85rem;
  }
}
