/* Modern Legal Library Design */

:root {
  --shelf-bg: #2c1b18; /* Dark Wood */
  --shelf-shadow: #1a100e;
  --wall-bg: #f5f5f5;
  --book-spine-width: 90px;
  --book-height: 200px;
  --paper-color: #fdfbf7;
  --text-color: #2c3e50;
  --highlight-color: #ffd700;
  --bookmark-color: #c62828;
  --highlight-user: #ffeb3b;
  --highlight-search: #ff9800;
  --link-color: #1565c0;
}

/* --- Layout & Container --- */
#library-container {
  flex: 1;
  padding: 40px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100%;
  /* URL encoded filename to avoid issues with umlauts */
  background: url("../gesetze/Buecherregal.jpg") no-repeat center center fixed;
  background-size: cover;
  perspective: 1000px;
}

/* Mobile: fixed Background kann auf iOS/Android Probleme machen */
@media (max-width: 767px) {
  #library-container {
    padding: 16px;
    background-attachment: scroll;
  }

  .shelf-books-container {
    padding: 0 12px;
  }
}

.library-header {
  text-align: center;
  margin-bottom: 40px;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
  background: rgba(0, 0, 0, 0.75);
  padding: 20px 40px;
  border-radius: 15px;
  border: 2px solid #d4af37;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
  z-index: 10;
}

.library-header h1 {
  font-family: "Playfair Display", serif; /* Elegant font if available */
  font-size: 3rem;
  margin-bottom: 10px;
  color: #ffffff !important;
}

.library-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  margin-bottom: 40px;
  background: rgba(255, 255, 255, 0.95);
  padding: 25px 35px;
  border-radius: 20px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
  width: 90%;
  max-width: 1000px;
  border: 1px solid #e0e0e0;
}

.library-search-input {
  width: 100%;
  padding: 12px 20px;
  border: 2px solid #eee;
  border-radius: 10px;
  font-size: 1.2rem;
  outline: none;
  color: #333;
  background: #f9f9f9;
  transition: border-color 0.3s;
}
.library-search-input:focus {
  border-color: #d4af37;
  background: #fff;
}

.library-filter-btn {
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid #ddd;
  background: #f9f9f9;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.9rem;
}

.library-filter-btn.active,
.library-filter-btn:hover {
  background: #333;
  color: white;
  border-color: #333;
}

/* --- Shelves --- */
.shelf-unit {
  width: 100%;
  max-width: 1200px;
  margin-bottom: 60px;
  position: relative;
  transform-style: preserve-3d;
}

.shelf-row {
  width: 100%;
  height: 20px;
  background: #5d4037;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3),
    inset 0 2px 5px rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  position: relative;
  z-index: 1;
}

.shelf-books-container {
  display: flex;
  align-items: flex-end;
  justify-content: center; /* Center books */
  padding: 0 40px;
  height: 220px; /* Space for books */
  margin-bottom: -20px; /* Overlap with shelf */
  gap: 4px;
  perspective: 800px;
}

/* --- Books --- */
.book-spine {
  width: var(--book-spine-width);
  height: var(--book-height);
  /* background-color is set inline via JS */
  border-radius: 3px;
  position: relative;
  cursor: pointer;
  transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), box-shadow 0.3s;

  /* Realistic Spine Effect: Deep shadows for roundness */
  box-shadow: inset 12px 0 15px -5px rgba(0, 0, 0, 0.6),
    /* Left shadow (spine curve) */ inset -4px 0 8px -2px
      rgba(255, 255, 255, 0.3),
    /* Right highlight */ inset 0 0 0 1px rgba(0, 0, 0, 0.1),
    /* Subtle border */ 5px 5px 15px rgba(0, 0, 0, 0.4); /* Drop shadow */

  /* Gradient Overlay for Texture and Roundness */
  background-image: linear-gradient(
    90deg,
    rgba(0, 0, 0, 0.3) 0%,
    rgba(255, 255, 255, 0.1) 20%,
    rgba(255, 255, 255, 0.05) 40%,
    rgba(0, 0, 0, 0.1) 60%,
    rgba(0, 0, 0, 0.4) 100%
  );

  display: flex;
  align-items: center;
  justify-content: center;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  color: #f0e6d2; /* Parchment/Goldish text */
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
  font-family: "Cinzel", serif;
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: 2px;
  z-index: 2;
  transform-origin: bottom center;
  overflow: hidden;
}

/* Book Details (Ribbons, Gold leaf, Ridges) */
.book-spine::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: 
    /* Top Gold Band */ linear-gradient(
      to bottom,
      transparent 20px,
      rgba(0, 0, 0, 0.5) 20px,
      rgba(218, 165, 32, 0.9) 22px,
      rgba(255, 223, 0, 0.8) 24px,
      rgba(218, 165, 32, 0.9) 26px,
      rgba(0, 0, 0, 0.5) 28px,
      transparent 28px
    ),
    /* Bottom Gold Band */
      linear-gradient(
        to top,
        transparent 30px,
        rgba(0, 0, 0, 0.5) 30px,
        rgba(218, 165, 32, 0.9) 32px,
        rgba(255, 223, 0, 0.8) 34px,
        rgba(218, 165, 32, 0.9) 36px,
        rgba(0, 0, 0, 0.5) 38px,
        transparent 38px
      ),
    /* Subtle Ridges (Bünde) */
      linear-gradient(
        to bottom,
        transparent 70px,
        rgba(0, 0, 0, 0.3) 70px,
        rgba(255, 255, 255, 0.1) 72px,
        rgba(0, 0, 0, 0.3) 74px,
        transparent 74px
      ),
    linear-gradient(
      to bottom,
      transparent 120px,
      rgba(0, 0, 0, 0.3) 120px,
      rgba(255, 255, 255, 0.1) 122px,
      rgba(0, 0, 0, 0.3) 124px,
      transparent 124px
    );
}

/* Optional: Leather Texture Overlay */
.book-spine::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.08'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
  pointer-events: none;
  z-index: 1;
}

.book-spine:hover {
  transform: translateY(-10px) scale(1.03);
  box-shadow: inset 12px 0 15px -5px rgba(0, 0, 0, 0.6),
    0 20px 30px rgba(0, 0, 0, 0.5);
  z-index: 10;
}

/* --- Modal (Reading View) --- */
.book-modal-overlay {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  top: var(--header-height, 0px);
  height: calc(100vh - var(--header-height, 0px));
  background: rgba(0, 0, 0, 0.3); /* More transparent */
  display: flex;
  justify-content: center;
  align-items: flex-start;
  z-index: 180;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  animation: fadeIn 0.3s ease-out;
  padding: 14px 16px 16px;
  overscroll-behavior: contain;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.book-wrapper {
  width: min(1080px, 84vw);
  height: calc((100vh - var(--header-height, 0px) - 32px) * 0.9);
  max-height: calc((100vh - var(--header-height, 0px) - 32px) * 0.9);
  display: flex;
  flex-direction: column;
  background: transparent;
  box-shadow: none;
  transform: none;
  animation: scaleUp 0.3s ease-out forwards;
}

@keyframes scaleUp {
  to {
    transform: scale(1);
  }
}

.book-toolbar {
  background: #212121;
  color: #fff;
  padding: 10px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 8px 8px 0 0;
  border-bottom: 1px solid #424242;
  flex-shrink: 0;
}

.book-toolbar-btn {
  background: #455a64;
  color: white;
  border: 1px solid #546e7a;
  padding: 5px 12px;
  cursor: pointer;
  border-radius: 3px;
  font-size: 0.9rem;
  margin-left: 5px;
}
.book-toolbar-btn:hover {
  background: #546e7a;
}

.open-book {
  flex: 1;
  min-height: 0;
  background-color: var(--paper-color);
  display: flex;
  position: relative;
  overflow: visible;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.35);
  background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23d7ccc8' fill-opacity='0.1'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zM32 63c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm57-13c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z' /%3E%3C/g%3E%3C/svg%3E");
}

.book-spine-center {
  width: 40px;
  background: linear-gradient(90deg, #ccc, #fff 50%, #ccc);
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.1);
  z-index: 5;
}

.book-page {
  flex: 1;
  padding: 30px 40px; /* Reduced padding */
  overflow-y: auto;
  overscroll-behavior: contain;
  font-family: "Georgia", serif;
  font-size: 1rem; /* Reduced font size */
  line-height: 1.6; /* Slightly reduced line height */
  color: #212121;
}

@media (max-width: 767px), (max-height: 500px) and (pointer: coarse) {
  .book-modal-overlay {
    padding: 10px 10px 12px;
  }
  .book-wrapper {
    width: 96vw;
    height: calc((100vh - var(--header-height, 0px) - 24px) * 0.9);
    max-height: calc((100vh - var(--header-height, 0px) - 24px) * 0.9);
  }
  .book-page {
    padding: 18px 16px;
    font-size: 0.95rem;
    line-height: 1.55;
  }
}

.book-page.left {
  border-right: 1px solid #e0e0e0;
  background: linear-gradient(to right, #fff 95%, #f5f5f5 100%);
}

.book-page.right {
  background: linear-gradient(to left, #fff 95%, #f5f5f5 100%);
}

.book-footer {
  background: #f5f5f5;
  padding: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  border-top: 1px solid #e0e0e0;
  border-radius: 0 0 8px 8px;
  flex-shrink: 0;
}

/* --- Law Text Styling --- */
.law-section {
  margin-bottom: 30px;
}

.law-title {
  font-family: "Arial", sans-serif;
  font-weight: 700;
  color: #b71c1c;
  font-size: 1em; /* Reduced font size */
  margin-bottom: 6px;
  display: block;
}

.law-text {
  text-align: justify;
}

.highlighted-text {
  background-color: rgba(255, 235, 59, 0.5);
  border-bottom: 2px solid #fbc02d;
}

/* --- Sidebar Overrides --- */
.library-sidebar-group {
  border: none;
  background: transparent;
  margin-bottom: 15px;
}

.library-group-header {
  background: transparent;
  color: #555;
  font-weight: 600;
  border-bottom: 1px solid #eee;
  padding: 5px 0;
}

.library-saved-item {
  padding: 8px 0;
  border-bottom: 1px dashed #eee;
  font-size: 0.85rem;
  color: #666;
}

/* Das Verweis-Eingabefeld */
.ref-box {
  display: none;
  margin-top: 10px;
  padding: 10px;
  background: #fffde7;
  border: 1px solid #fbc02d;
  border-radius: 4px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.ref-box input {
  width: 70%;
  padding: 5px;
  border: 1px solid #ccc;
  color: #333;
}
.ref-box button {
  width: 25%;
  padding: 5px;
  background: #4caf50;
  color: white;
  border: none;
  cursor: pointer;
}

/* Sticky Notes am Rand */
.sticky-note {
  position: absolute;
  right: -15px;
  width: 35px;
  height: 35px;
  background-color: var(--bookmark-color);
  color: white;
  font-size: 0.65rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  z-index: 5;
  transition: transform 0.1s;
  border-radius: 2px;
  text-align: center;
  line-height: 1;
}
.sticky-note:hover {
  transform: scale(1.1);
}

/* Ketten-Symbol */
.chain-icon {
  color: #1565c0;
  font-size: 0.8em;
  margin-left: 5px;
  cursor: help;
}

/* Side Tabs for Bookmarks */
.side-tab {
  position: relative;
  z-index: 10;
  box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.side-tab:hover {
  transform: scale(1.1) translateX(2px);
  box-shadow: 3px 3px 8px rgba(0, 0, 0, 0.3);
}

/* --- Responsive Design (Tablet & Mobile) --- */

@media (max-width: 1024px) {
  :root {
    --book-spine-width: 60px;
    --book-height: 160px;
  }

  .library-header h1 {
    font-size: 2.5rem;
  }

  .shelf-books-container {
    height: 180px;
  }
}

@media (max-width: 768px) {
  :root {
    --book-spine-width: 45px;
    --book-height: 130px;
  }

  #library-container {
    padding: 15px;
  }

  .library-header {
    padding: 15px;
    margin-bottom: 20px;
  }

  .library-header h1 {
    font-size: 1.8rem;
  }

  .library-header p {
    font-size: 0.9rem;
  }

  .library-controls {
    padding: 15px;
    width: 100%;
    gap: 10px;
  }

  .library-search-input {
    font-size: 1rem;
    padding: 10px;
  }

  .shelf-unit {
    margin-bottom: 40px;
  }

  .shelf-books-container {
    padding: 0 10px;
    height: 150px;
    /* Allow horizontal scrolling for shelves on mobile */
    overflow-x: auto;
    justify-content: flex-start;
    /* Hide scrollbar but allow scrolling */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
  }

  .shelf-books-container::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
  }

  .book-spine {
    font-size: 0.8rem;
    letter-spacing: 1px;
    /* Ensure books don't shrink below their width */
    flex-shrink: 0;
  }
}

@media (max-width: 480px) {
  :root {
    --book-spine-width: 35px;
    --book-height: 110px;
  }

  .library-header h1 {
    font-size: 1.5rem;
  }

  .shelf-books-container {
    height: 130px;
  }

  .book-spine {
    font-size: 0.6rem;
    letter-spacing: 0.5px;
    box-shadow: inset 5px 0 5px -2px rgba(0, 0, 0, 0.6); /* Simplified shadow */
  }
}

/* --- Mobile Book View --- */
@media (max-width: 768px) {
  .book-wrapper {
    width: 96vw;
    height: calc((100vh - var(--header-height, 0px) - 24px) * 0.9);
    max-height: calc((100vh - var(--header-height, 0px) - 24px) * 0.9);
  }

  .open-book {
    flex-direction: column;
  }

  .book-page {
    width: 100%;
    padding: 15px 15px; /* Much smaller padding for mobile */
    border-right: none !important;
    border-bottom: 1px solid #e0e0e0;
  }

  .book-spine-center {
    display: none;
  }

  .book-toolbar {
    padding: 8px 10px;
  }

  .book-toolbar span.text-lg {
    font-size: 1rem;
    margin-left: 5px;
    margin-right: 5px;
  }

  #book-search-input {
    width: 100px;
  }

  /* Adjust font size for law text on mobile */
  .law-text {
    font-size: 0.95rem;
  }

  .law-title {
    font-size: 0.95rem;
  }
}
