/*
 * Book detail page. Sits in the library layout (css/components/library.css),
 * which provides the rail, --tone/--tone-ink for the book's shelf and the --act-* colours.
 * Class names and ids are driven by users/js/book_detail.js — keep them stable.
 */

:root {
  --star-color: #f5b301;
  --danger-color: #d64545;
  /* Older names still used by the reviews, lightbox and modal rules below */
  --border-color: var(--border-light);
  --primary-color: var(--brand-primary);
  --primary-hover: var(--brand-primary-strong);
  --text-color: var(--text-primary);
  --bg-hover: var(--bg-secondary);
  --box-shadow: 0 18px 40px -18px rgba(14, 27, 44, 0.45);
}

/* ===== Layout ===== */
.book-detail-wrapper {
  min-width: 0;
}

.breadcrumb-container {
  margin: 0 0 1.25rem;
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.875rem;
}

.breadcrumb-item {
  display: flex;
  align-items: center;
  color: var(--text-muted);
}

.breadcrumb-item a {
  color: var(--text-secondary);
  text-decoration: none;
}

.breadcrumb-item a:hover {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.breadcrumb-item + .breadcrumb-item::before {
  content: "/";
  padding: 0 0.5rem;
  color: var(--text-muted);
}

.breadcrumb-item.active {
  min-width: 0;
  overflow: hidden;
  color: var(--text-primary);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-detail-container {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: clamp(1.75rem, 3.5vw, 3rem);
  align-items: start;
  margin-bottom: 2rem;
}

/* ===== Media column: the cover tucked into a pocket in the shelf's tone ===== */
.book-detail-media {
  position: sticky;
  top: calc(var(--header-height, 64px) + 1.25rem);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.book-detail-media {
  --tile-tone: var(--tone);
  --tile-ink: var(--tone-ink);
}

/* The 3D book itself is styled in library.css (.book-stage, .book3d) */
.library-page .book-primary-image {
  padding: 40px 46px 48px 34px;
  background: var(--jg-stage-surface);
  border: 1px solid color-mix(in srgb, var(--jg-accent) 12%, transparent);
  border-radius: var(--lib-radius, 22px);
  perspective: 1400px;
}

.library-page .book-primary-image .book3d {
  --t: 22px;
  transform: rotateY(-22deg) rotateX(3deg);
}

.library-page .book-primary-image:hover .book3d {
  transform: rotateY(-34deg) rotateX(4deg) translateY(-8px);
}

.library-page .book-primary-image .no-cover__title {
  font-size: 1.5rem;
}

/* ===== Flip-through viewer (built by initPreviews in book_detail.js) ===== */
.flipper {
  --sheet-w: min(100%, 440px);
  padding: 1.25rem 1.25rem 1rem;
  background: var(--jg-stage-surface);
  border: 1px solid color-mix(in srgb, var(--jg-accent) 12%, transparent);
  border-radius: var(--lib-radius, 22px);
}

.flipper__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  margin-bottom: 1rem;
}

.preview-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
}

.flipper__count {
  margin: 0;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  color: color-mix(in srgb, var(--tone-ink) 75%, var(--text-secondary));
}

.flipper__viewer {
  display: grid;
  grid-template-columns: auto minmax(0, var(--sheet-w)) auto;
  align-items: center;
  justify-content: center;
  gap: clamp(0.5rem, 2vw, 1.25rem);
}

/* One sheet of paper, with two more peeking out behind it like a stack */
.flipper__page {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  aspect-ratio: 612 / 792;
  cursor: zoom-in;
  background: #fff;
  border: 0;
  border-radius: 4px;
  box-shadow:
    4px 4px 0 -1px #fff,
    4px 4px 0 0 color-mix(in srgb, var(--tone-ink) 22%, transparent),
    8px 8px 0 -1px #fff,
    8px 8px 0 0 color-mix(in srgb, var(--tone-ink) 16%, transparent),
    0 24px 40px -22px rgba(14, 27, 44, 0.55);
  transform-origin: left center;
  touch-action: pan-y;
  user-select: none;
}

.flipper__page:focus-visible,
.flipper__thumb:focus-visible,
.flipper__nav:focus-visible {
  outline: 3px solid var(--brand-primary);
  outline-offset: 3px;
}

.flipper__img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.flipper__zoom {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: #fff;
  background: color-mix(in srgb, #0e1b2c 78%, transparent);
  border-radius: 999px;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.flipper__page:hover .flipper__zoom,
.flipper__page:focus-visible .flipper__zoom {
  opacity: 1;
  transform: none;
}

.flipper__page.is-turning-next { animation: flip-in-next 0.45s cubic-bezier(0.2, 0.7, 0.2, 1); }
.flipper__page.is-turning-prev { animation: flip-in-prev 0.45s cubic-bezier(0.2, 0.7, 0.2, 1); }

@keyframes flip-in-next {
  from { opacity: 0.4; transform: perspective(1400px) rotateY(-24deg) translateX(18px); }
}

@keyframes flip-in-prev {
  from { opacity: 0.4; transform: perspective(1400px) rotateY(18deg) translateX(-18px); }
}

.flipper__nav {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 1rem;
  color: var(--tone-ink);
  cursor: pointer;
  background: var(--bg-primary);
  border: 1px solid color-mix(in srgb, var(--tone-ink) 22%, transparent);
  border-radius: 50%;
  box-shadow: 0 6px 16px -10px rgba(14, 27, 44, 0.5);
  transition: transform 0.15s ease, background-color 0.15s ease, opacity 0.15s ease;
}

.flipper__nav:hover:not(:disabled) {
  color: #fff;
  background: var(--tone-ink);
  transform: scale(1.06);
}

.flipper__nav:disabled {
  opacity: 0.35;
  cursor: default;
  box-shadow: none;
}

.flipper__strip {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 1.25rem;
  padding: 4px 4px 6px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.flipper__thumb {
  flex: none;
  width: 54px;
  padding: 0;
  aspect-ratio: 612 / 792;
  overflow: hidden;
  cursor: pointer;
  background: #fff;
  border: 2px solid transparent;
  border-radius: 5px;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--tone-ink) 18%, transparent);
  opacity: 0.7;
  transition: opacity 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

.flipper__thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
}

.flipper__thumb:hover {
  opacity: 1;
  transform: translateY(-2px);
}

.flipper__thumb[aria-current="true"] {
  border-color: var(--tone-ink);
  opacity: 1;
}

.flipper__loading {
  display: flex;
  justify-content: center;
}

.flipper__sheet {
  display: block;
  width: var(--sheet-w);
  aspect-ratio: 612 / 792;
  background:
    linear-gradient(100deg, transparent 30%, color-mix(in srgb, var(--tone) 55%, transparent) 50%, transparent 70%) 0 0 / 250% 100%,
    #fff;
  border-radius: 4px;
  box-shadow: 0 24px 40px -22px rgba(14, 27, 44, 0.4);
  animation: lib-shimmer 1.6s linear infinite;
}

.flipper .no-previews {
  margin: 0;
  padding: 1.5rem 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-align: center;
}

@media (max-width: 640px) {
  .flipper {
    padding: 1rem 0.75rem 0.75rem;
  }

  .flipper__viewer {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Phones swipe; the arrows sit over the sheet edges */
  .flipper__nav {
    position: absolute;
    z-index: 1;
    top: 50%;
    width: 38px;
    height: 38px;
    transform: translateY(-50%);
  }

  .flipper__viewer { position: relative; }
  .flipper__nav--prev { left: -4px; }
  .flipper__nav--next { right: -4px; }
  .flipper__nav:hover:not(:disabled) { transform: translateY(-50%); }
  .flipper__nav:disabled { visibility: hidden; }
  .flipper__zoom { opacity: 1; transform: none; }
  .flipper__strip { justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  .flipper__page.is-turning-next,
  .flipper__page.is-turning-prev,
  .flipper__sheet {
    animation: none;
  }
}

/* ===== Info column ===== */
.book-detail-info {
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
  min-width: 0;
}

.header-main {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.book-detail-info .book-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2rem, 1.3rem + 2.2vw, 3rem);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.rating-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.25rem;
}

.star-rating {
  display: flex;
  align-items: center;
  gap: 3px;
  color: var(--star-color);
}

.star-rating .fa-star,
.stars .fa-star,
.rating-stars .fa-star {
  color: var(--star-color);
}

.rating-value {
  margin-left: 0.4rem;
  font-weight: 700;
  color: var(--text-primary);
}

.review-count {
  margin-left: 0.35rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  text-decoration: none;
}

.review-count:hover {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.download-count {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Tags */
.book-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.book-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border-radius: 999px;
}

.category-tag,
.main-category-tag {
  color: var(--tone-ink);
  background: var(--tone);
}

.age-tag { color: var(--lib-mint-ink); background: var(--lib-mint); }
.difficulty-tag { color: var(--lib-sun-ink); background: var(--lib-sun); }
.theme-tag { color: var(--lib-lilac-ink); background: var(--lib-lilac); }

/* Description and features */
.book-detail-description h2,
.book-detail-features h2,
.book-detail-reviews h2 {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text-primary);
}

.book-detail-description p {
  max-width: 68ch;
  margin: 0 0 0.75rem;
  font-size: 1.0625rem;
  line-height: 1.65;
  color: var(--text-secondary);
}

.no-description {
  color: var(--text-muted);
}

.features-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem 1.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.features-list li {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  font-size: 0.975rem;
  line-height: 1.45;
  color: var(--text-secondary);
}

.features-list li i {
  flex: none;
  margin-top: 0.15rem;
  color: var(--act-download, #0f8f7c);
}

/* ===== Actions ===== */
.book-detail-header {
  order: -2;
}

/* Actions come straight after the title, above the description */
.actions-container {
  order: -1;
  margin: -0.5rem 0 0;
}

.action-buttons-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  min-height: 52px;
  margin: 0;
  padding: 0 1.4rem;
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 999px;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.action-btn:hover {
  text-decoration: none;
  transform: translateY(-2px);
}

.action-btn:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 3px;
}

.action-btn small {
  font-size: 0.8rem;
  font-weight: 500;
  opacity: 0.85;
}

.download-book-btn {
  color: #fff;
  background: var(--act-download, #0f8f7c);
}

.download-book-btn:hover {
  color: #fff;
  background: color-mix(in srgb, var(--act-download, #0f8f7c) 85%, #000);
}

.toggle-favorite {
  color: var(--act-favorite, #e0457b);
  background: transparent;
  border-color: color-mix(in srgb, var(--act-favorite, #e0457b) 45%, transparent);
}

.toggle-favorite:hover {
  color: var(--act-favorite, #e0457b);
  background: color-mix(in srgb, var(--act-favorite, #e0457b) 10%, transparent);
  border-color: var(--act-favorite, #e0457b);
}

.toggle-favorite.favorited {
  color: #fff;
  background: var(--act-favorite, #e0457b);
  border-color: transparent;
}

.amazon-btn {
  color: #fff;
  background: var(--act-amazon, #d97706);
}

.amazon-btn:hover {
  color: #fff;
  background: color-mix(in srgb, var(--act-amazon, #d97706) 85%, #000);
}

[data-theme="dark"] .download-book-btn,
[data-theme="dark"] .download-book-btn:hover,
[data-theme="dark"] .amazon-btn,
[data-theme="dark"] .amazon-btn:hover,
[data-theme="dark"] .toggle-favorite.favorited {
  color: var(--bg-primary);
}

@media (max-width: 768px) {
  .action-buttons-row {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (prefers-reduced-motion: reduce) {
  .action-btn {
    transition: none;
  }

  .action-btn:hover {
    transform: none;
  }
}

/* Reviews section */
.book-detail-reviews {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: none !important;
}

.reviews-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.write-review-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;
    padding: 0 1.1rem;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--act-rate, #7c5cd6);
    cursor: pointer;
    background: color-mix(in srgb, var(--act-rate, #7c5cd6) 12%, transparent);
    border: 0;
    border-radius: 999px;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.write-review-btn:hover {
    color: #fff;
    background: var(--act-rate, #7c5cd6);
}

[data-theme="dark"] .write-review-btn:hover {
    color: var(--bg-primary);
}

.write-review-btn:focus-visible {
    outline: 2px solid var(--brand-primary);
    outline-offset: 2px;
}

.rating-overview {
  display: flex;
  gap: 24px;
  margin-bottom: 20px;
  padding: 20px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 18px;
}

.average-rating {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 100px;
  padding-right: 24px;
  border-right: 1px solid var(--border-color);
}

.average-rating .rating-value {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text-primary);
  line-height: 1;
}

.average-rating .rating-stars {
  margin-bottom: 4px;
  font-size: 1rem;
}

.average-rating .rating-count {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.rating-bars {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
}

.rating-bar-item {
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.rating-bar-item:hover {
  opacity: 0.8;
}

.bar-label {
  width: 50px;
  font-size: 0.9rem;
  text-align: right;
  color: var(--text-muted);
  font-weight: 500;
}

.bar-container {
  flex: 1;
  height: 8px;
  background: var(--bg-secondary);
  border-radius: 4px;
  overflow: hidden;
}

.bar {
  height: 100%;
  background: linear-gradient(90deg, #fbbf24 0%, #f59e0b 100%);
  width: 0;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 4px;
}

.bar-percent {
  width: 45px;
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: right;
}

/* Reviews container and items */
.reviews-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 16px;
}

.review-item {
    background: var(--bg-elevated, rgba(0, 0, 0, 0.02));
    border-radius: 12px;
    border: 1px solid var(--border-color);
    padding: 16px;
    position: relative;
    transition: all 0.2s ease;
}

.review-item:hover {
    background: var(--bg-hover, rgba(0, 0, 0, 0.03));
    border-color: var(--primary-color);
}

.review-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.reviewer-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.reviewer-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.review-date {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.review-content {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
    margin: 10px 0;
    padding: 0;
}

.review-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}

.helpful-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    padding: 6px 14px;
    border-radius: 50px;
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.helpful-btn:hover,
.helpful-btn.active {
    background: rgba(31, 111, 178, 0.1);
    color: var(--primary-color, #1f6fb2);
    border-color: rgba(31, 111, 178, 0.3);
}

/* Related books section */
.related-books {
  margin-top: 30px;
  border-top: none;
  padding-top: 20px;
}

.related-books h2 {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 20px;
}

.related-books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
}

.related-book {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  transition: all 0.3s ease;
}

.related-book:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

.related-book-link {
  text-decoration: none;
  color: inherit;
  display: block;
}

.related-book-image {
  height: 200px;
  position: relative;
  overflow: hidden;
}

.related-book-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.related-book-info {
  padding: 15px;
}

.related-book-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 10px 0;
  color: var(--text-color);
}

.related-book-meta {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
}

.related-book-rating {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--star-color);
}

/* Ensure all star groups are horizontal */
.rating-stars,
.star-rating,
.stars {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 4px;
  margin: 5px 0;
}

/* Lightbox styling */
.lightbox {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  display: none;
  z-index: 2000;
}

.lightbox-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.lightbox-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-content {
  max-width: 90%;
  max-height: 90%;
  position: relative;
}

.lightbox-image {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

.lightbox-caption {
  color: white;
  text-align: center;
  padding: 10px;
  font-size: 14px;
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  z-index: 2010;
}

.lightbox-navigation {
  position: absolute;
  bottom: 20px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 20px;
}

.lightbox-nav {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  padding: 10px 15px;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
}

.lightbox-nav:hover:not(.disabled) {
  background: rgba(255, 255, 255, 0.3);
}

.lightbox-nav.disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Rating Modal Styles */
.rating-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1050;
}

.rating-modal.show {
  display: flex;
  align-items: center;
  justify-content: center;
}

.rating-modal .modal-dialog {
  width: 100%;
  max-width: 500px;
  margin: 1.75rem auto;
}

.rating-modal .modal-content {
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: var(--box-shadow);
}

.rating-modal .modal-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.rating-modal .modal-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-color);
}

.rating-modal .modal-body {
  padding: 1.5rem;
}

.rating-modal .modal-footer {
  padding: 1rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Rating Form Styles */
.rating-section {
  margin-bottom: 1.5rem;
}

.rating-label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--text-color);
}

.rating-stars {
  display: flex !important;
  gap: 0.5rem;
  font-size: 1.5rem;
}

.rating-star {
  color: var(--star-color);
  cursor: pointer;
  transition: transform 0.2s ease;
}

.rating-star:hover {
  transform: scale(1.2);
}

.rating-text {
  margin-top: 0.25rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Review Form */
.review-section {
  margin-bottom: 1rem;
}

.review-textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text-color);
  min-height: 120px;
  resize: vertical;
}

.review-guidelines {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Error Message */
.rating-error {
  display: none;
  color: var(--danger-color);
  background: rgba(239, 68, 68, 0.1);
  padding: 0.75rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

/* Modal Buttons */
.btn-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.5rem;
}

/* Review Rating Alignment */
.review-rating {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 4px;
    margin-left: auto;
}

.stars {
    color: #ffd700;
    display: flex;
    gap: 2px;
}

/* Submit Review Button */
#submit-review {
    background: var(--primary-color);
    color: white;
    padding: 12px 28px;
    border-radius: 25px;
    border: none;
    font-size: 15px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(31, 111, 178, 0.2);
    margin-top: 16px;
}

#submit-review:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(31, 111, 178, 0.3);
}

#submit-review:active {
    transform: translateY(0);
}

#submit-review:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    transform: none;
    box-shadow: none; 
}

#submit-review i {
    font-size: 16px;
}

/* Review Form Container */
#review-form-container {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    margin: 20px 0;
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

#review-comment {
    width: 100%;
    min-height: 120px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin: 10px 0;
    font-size: 15px;
    line-height: 1.6;
    resize: vertical;
    background: var(--card-bg);
    color: var(--text-color);
}

#review-comment:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(31, 111, 178, 0.1);
}

.review-rating-stars {
    display: flex;
    gap: 8px;
    margin: 10px 0;
}

.rating-star {
    font-size: 24px;
    color: var(--star-color);
    cursor: pointer;
    transition: transform 0.2s ease;
}

.rating-star:hover {
    transform: scale(1.2);
}

/* Mobile responsiveness */
@media (max-width: 1100px) {
  .book-detail-container {
    grid-template-columns: minmax(0, 1fr);
  }

  .book-detail-media {
    position: static;
    width: min(100%, 320px);
  }

  .rating-overview {
    flex-direction: column;
    gap: 16px;
    padding: 16px;
  }

  .average-rating {
    align-items: flex-start;
    padding-right: 0;
    padding-bottom: 16px;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }
}

/* Tablets: cover beside the title and buttons, everything else full width below */
@media (min-width: 641px) and (max-width: 1100px) {
  .book-detail-container {
    grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
    gap: 1.75rem 2rem;
  }

  .book-detail-info {
    display: contents;
  }

  .book-detail-media {
    grid-column: 1;
    grid-row: 1 / span 2;
    width: auto;
  }

  .book-detail-header {
    grid-column: 2;
    grid-row: 1;
    align-self: end;
  }

  .actions-container {
    grid-column: 2;
    grid-row: 2;
    align-self: start;
  }

  .book-detail-info > section:not(.actions-container) {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .book-detail-media {
    margin: 0 auto;
  }

  .flipper__thumb {
    width: 44px;
  }

  .flipper__strip {
    gap: 8px;
  }

  .library-page .book-primary-image {
    padding: 30px 38px 40px 26px;
  }

  .reviews-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .features-list {
    grid-template-columns: minmax(0, 1fr);
  }

  .review-item {
    padding: 12px;
  }

  .rating-overview {
    padding: 12px;
  }

  .average-rating .rating-value {
    font-size: 2rem;
  }
}
