/* Wall background - default witchy theme */
.library {
  background:
    linear-gradient(rgba(0,0,0,0.3), rgba(0,0,0,0.3)),
    url('../../assets/bookshelf-bg-witchy.jpg');
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  background-repeat: no-repeat;
  transition: background-image 0.3s ease;
  min-height: 100vh;
}

/* Colorful theme */
.library.theme-colorful {
  background:
    linear-gradient(rgba(255,255,255,0.1), rgba(255,255,255,0.1)),
    url('../../assets/bookshelf-bg-colorful.jpg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

body.theme-colorful .hud {
  background: #d4739b;
}

body.theme-colorful .hud button {
  background: #c05a87;
  border: 1px solid rgba(255,255,255,0.15);
}

body.theme-colorful .hud button:hover {
  background: #a84773;
}

body.theme-colorful .hud select {
  background: #c05a87;
  border: 1px solid rgba(255,255,255,0.15);
}

body.theme-colorful .hud select:hover {
  background: #a84773;
}

body.theme-colorful .pagination-footer {
  background: #d4739b;
}

body.theme-colorful .page-btn {
  background: #c05a87;
  border: 1px solid rgba(255,255,255,0.15);
}

body.theme-colorful .page-btn:hover:not(:disabled) {
  background: #a84773;
}

/* Minimal theme */
.library.theme-minimal {
  background:
    linear-gradient(rgba(255,255,255,0.05), rgba(255,255,255,0.05)),
    url('../../assets/bookshelf-bg-minimal.jpg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

body.theme-minimal .hud {
  background: #f5f0e8;
  color: #333;
}

body.theme-minimal .hud h1 {
  color: #333;
}

body.theme-minimal .hud label {
  color: #666;
}

body.theme-minimal .hud button {
  background: #e8dcc8;
  color: #333;
  border: 1px solid rgba(0,0,0,0.1);
}

body.theme-minimal .hud button:hover {
  background: #d9cbb5;
}

body.theme-minimal .hud select {
  background: #e8dcc8;
  color: #333;
  border: 1px solid rgba(0,0,0,0.1);
}

body.theme-minimal .hud select:hover {
  background: #d9cbb5;
}

body.theme-minimal .pagination-footer {
  background: #f5f0e8;
  color: #333;
}

body.theme-minimal .page-info {
  color: #666;
}

body.theme-minimal .page-btn {
  background: #e8dcc8;
  color: #333;
  border: 1px solid rgba(0,0,0,0.1);
}

body.theme-minimal .page-btn:hover:not(:disabled) {
  background: #d9cbb5;
}

/* Shelves - stacked vertically */
.shelves {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 12px var(--space-6) 16px;
  overflow: hidden;
  height: 100%;
}

/* Shelf - transparent to show background image */
.shelf {
  background: transparent;
  backdrop-filter: none;
  border-radius: 0;
  box-shadow: none;
  height: 210px;
  flex-shrink: 0;
  position: relative;
  display: flex;
  align-items: flex-end;
  padding: 0 var(--space-4) 0;
  gap: var(--space-3);
  overflow-x: auto;
  overflow-y: hidden;
  margin: 0;
}

/* Book tile - looks like a book spine */
.book-tile {
  flex-shrink: 0;
  width: 65px;
  height: 210px;
  position: relative;
  cursor: pointer;
  transition: transform 0.2s ease;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: var(--space-3) var(--space-2);
  border-radius: 2px 2px 0 0;
  overflow: hidden;
  background: linear-gradient(
    to right,
    rgba(0,0,0,0.3) 0%,
    rgba(255,255,255,0.1) 5%,
    rgba(255,255,255,0.05) 50%,
    rgba(0,0,0,0.2) 95%,
    rgba(0,0,0,0.4) 100%
  );
  box-shadow:
    inset -1px 0 2px rgba(0,0,0,0.3),
    inset 1px 0 1px rgba(255,255,255,0.1),
    2px 0 4px rgba(0,0,0,0.2);
}

.book-tile:hover {
  transform: translateY(-8px);
}

.book-tile .spine {
  position: absolute;
  inset: 0;
  border-radius: 2px 2px 0 0;
  background-size: cover;
  background-position: center;
  opacity: 1;
  z-index: 0;
}

.book-tile .title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-100);
  white-space: normal;
  overflow: hidden;
  max-width: 190px;
  max-height: 140px;
  position: relative;
  z-index: 1;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  letter-spacing: 0.3px;
  padding: var(--space-2) 0;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 8;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.book-tile .author {
  font-size: 0.75rem;
  color: #e8dcc8;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 190px;
  position: relative;
  z-index: 1;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

/* Theme-specific text colors */

/* Minimal theme: use dark and light greys */
.theme-minimal .book-tile .title {
  color: #2a2a2a;
  text-shadow: 0 1px 2px rgba(255,255,255,0.3);
}

.theme-minimal .book-tile .author {
  color: #4a4a4a;
  text-shadow: 0 1px 2px rgba(255,255,255,0.3);
}

/* Colorful theme: use dark browns for better contrast */
.theme-colorful .book-tile .title {
  color: #3d2817;
  text-shadow: 0 1px 2px rgba(255,255,255,0.4);
}

.theme-colorful .book-tile .author {
  color: #5a3a22;
  text-shadow: 0 1px 2px rgba(255,255,255,0.4);
}

.book-tile.highlight {
  outline: 2px solid var(--accent-500);
  outline-offset: 2px;
  box-shadow:
    inset -1px 0 2px rgba(0,0,0,0.3),
    inset 1px 0 1px rgba(255,255,255,0.1),
    0 0 0 4px rgba(139,216,189,0.2),
    0 0 16px rgba(139,216,189,0.4);
  transform: translateY(-8px);
}

/* Series divider */
.series-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 210px;
  width: 30px;
  flex-shrink: 0;
  font-size: 1.5rem;
  color: rgba(200,164,82,0.7);
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

/* Series badge */
.book-tile .series-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(200,164,82,0.9);
  color: #000;
  font-size: 0.65rem;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 3px;
  z-index: 10;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* Visual connection for series books */
.book-tile[data-series] + .book-tile[data-series] {
  margin-left: 2px;
}

/* First book in a series gets a subtle left indicator */
.book-tile[data-series] {
  position: relative;
}

.book-tile[data-series-number="1"]::before {
  content: '';
  position: absolute;
  left: -4px;
  top: 10%;
  bottom: 10%;
  width: 2px;
  background: rgba(200,164,82,0.5);
  border-radius: 1px;
}

/* ============================================
   BOOKSHELF THEME - Dynamic CSS Shelves
   ============================================ */

/* Warm library wall background */
.library.theme-bookshelf {
  background: linear-gradient(135deg, #e8dcc8 0%, #d4c5a9 50%, #c7b299 100%);
  background-attachment: fixed;
  min-height: 100vh;
  overflow-y: auto; /* Allow scrolling */
  overflow-x: hidden; /* Prevent horizontal scroll */
}

/* Shelves container shouldn't clip */
.theme-bookshelf .shelves {
  overflow: visible !important;
  padding-top: 20px;
}

body.theme-bookshelf .hud {
  background: linear-gradient(135deg, #8b7355 0%, #6d5a45 100%);
  border-bottom: 3px solid #5a4735;
}

body.theme-bookshelf .hud button {
  background: linear-gradient(135deg, #a58968 0%, #8b7355 100%);
  border: 1px solid #6d5a45;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

body.theme-bookshelf .hud button:hover {
  background: linear-gradient(135deg, #8b7355 0%, #6d5a45 100%);
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(0,0,0,0.3);
}

body.theme-bookshelf .hud select {
  background: linear-gradient(135deg, #a58968 0%, #8b7355 100%);
  border: 1px solid #6d5a45;
}

body.theme-bookshelf .hud select:hover {
  background: linear-gradient(135deg, #8b7355 0%, #6d5a45 100%);
}

body.theme-bookshelf .pagination-footer {
  background: linear-gradient(135deg, #8b7355 0%, #6d5a45 100%);
  border-top: 3px solid #5a4735;
}

body.theme-bookshelf .page-btn {
  background: linear-gradient(135deg, #a58968 0%, #8b7355 100%);
  border: 1px solid #6d5a45;
}

body.theme-bookshelf .page-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #8b7355 0%, #6d5a45 100%);
}

/* Realistic wooden shelves with VISIBLE horizontal planks */
.theme-bookshelf .shelf {
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 4px;
  padding: 20px var(--space-6) 45px; /* Top padding prevents clipping! */
  min-height: 350px; /* Taller to fit books */
  margin-bottom: 20px; /* Gap between shelves */
  position: relative;
  flex-wrap: wrap; /* Books wrap to next line when needed */
  overflow: visible !important; /* CRITICAL - don't clip books! */
  /* Auto-adjust height based on content */
  height: auto;
}

/* Visible wooden shelf plank - books sit ON this */
.theme-bookshelf .shelf::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 35px;
  /* Wood grain texture using gradients */
  background:
    /* Subtle wood grain lines */
    repeating-linear-gradient(90deg,
      transparent 0px,
      transparent 80px,
      rgba(90,70,50,0.15) 80px,
      rgba(90,70,50,0.15) 82px
    ),
    /* Vertical gradient for depth */
    linear-gradient(180deg,
      #b89968 0%,
      #a58968 10%,
      #8b7355 40%,
      #7a6550 70%,
      #6d5a45 90%,
      #5a4735 100%
    );
  border-radius: 2px 2px 4px 4px;
  /* Realistic 3D depth and shadow */
  box-shadow:
    /* Top highlight */
    inset 0 2px 1px rgba(255,255,255,0.2),
    /* Inner shadow for depth */
    inset 0 -3px 5px rgba(0,0,0,0.3),
    /* Drop shadow below shelf */
    0 6px 12px rgba(0,0,0,0.4),
    0 2px 4px rgba(0,0,0,0.3);
  border-top: 1px solid rgba(255,255,255,0.15);
  border-bottom: 2px solid rgba(0,0,0,0.4);
  z-index: 1;
}

/* No brackets - they look like turds */

/* Books in bookshelf theme have varied heights and sit ON the shelf */
.theme-bookshelf .book-tile {
  /* Heights will be set dynamically via inline style or data attribute */
  height: var(--book-height, 220px);
  min-height: 180px;
  max-height: 260px;
  align-self: flex-end;
  margin-bottom: 0; /* Sit directly on shelf plank */
  position: relative;
  z-index: 5;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  /* Cast realistic shadow on shelf */
  box-shadow:
    /* Main shadow on shelf */
    0 6px 10px rgba(0,0,0,0.35),
    0 2px 4px rgba(0,0,0,0.25),
    /* Book spine depth */
    inset -3px 0 5px rgba(0,0,0,0.25),
    inset 3px 0 3px rgba(255,255,255,0.1);
}

/* Slightly tilt books for realism */
.theme-bookshelf .book-tile:nth-child(3n+1) {
  transform: rotate(-0.8deg);
}

.theme-bookshelf .book-tile:nth-child(3n+2) {
  transform: rotate(0.8deg);
}

.theme-bookshelf .book-tile:nth-child(3n) {
  transform: rotate(-0.3deg);
}

/* Enhanced hover effect - book lifts off shelf */
.theme-bookshelf .book-tile:hover {
  transform: translateY(-12px) scale(1.03) rotate(0deg) !important;
  box-shadow:
    /* Bigger shadow when lifted */
    0 12px 20px rgba(0,0,0,0.45),
    0 4px 8px rgba(0,0,0,0.35),
    inset -3px 0 5px rgba(0,0,0,0.25),
    inset 3px 0 3px rgba(255,255,255,0.15);
  z-index: 100;
}

/* Text colors for bookshelf theme */
.theme-bookshelf .book-tile .title {
  color: #2a2010;
  text-shadow: 0 1px 2px rgba(255,255,255,0.5);
  font-weight: 700;
}

.theme-bookshelf .book-tile .author {
  color: #4a3820;
  text-shadow: 0 1px 2px rgba(255,255,255,0.5);
  font-weight: 600;
}

/* Series badges for bookshelf theme */
.theme-bookshelf .series-badge {
  background: linear-gradient(135deg, #c8a452 0%, #b8944a 100%);
  color: #2a2010;
  border: 1px solid #a07f3a;
}

/* First page shelf has extra top margin for spacing */
.theme-bookshelf .shelves > .shelf:first-child {
  margin-top: var(--space-6);
}
