/* Skeuomorphic bookshelf – wood shelves and book spines */

:root {
  --wood-light: #d4b87a;
  --wood-mid: #9a7620;
  --wood-dark: #4a3a22;
  --wood-grain: rgba(0, 0, 0, 0.08);
  --shelf-height: 28px;
  --spine-width: 42px;
  --spine-min-height: 140px;
  --spine-max-height: 200px;
  --books-per-row: 10;
  --gap: 10px;
}

@media (max-width: 1200px) {
  :root {
    --books-per-row: 8;
    --spine-width: 40px;
  }
}

@media (max-width: 900px) {
  :root {
    --books-per-row: 6;
    --spine-width: 38px;
  }
}

@media (max-width: 768px) {
  :root {
    --books-per-row: 5;
    --spine-width: 36px;
    --spine-min-height: 120px;
    --spine-max-height: 160px;
  }
}

@media (max-width: 480px) {
  :root {
    --books-per-row: 4;
    --spine-width: 34px;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Source Sans 3', system-ui, sans-serif;
  background: linear-gradient(180deg, #1a120c 0%, #0f0a06 100%);
  color: #f0e8dc;
}

.shelf-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.shelf-header {
  padding: 1rem 1.5rem;
  text-align: center;
  border-bottom: 2px solid rgba(154, 118, 32, 0.6);
  background: rgba(0, 0, 0, 0.15);
}

.shelf-logo {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: #f5ecd8;
  text-decoration: none;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.shelf-logo:hover {
  color: #fff8ee;
}

.shelf-subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.875rem;
  color: rgba(245, 236, 216, 0.9);
}

/* Main – wood background (higher contrast vs body) */
.shelf-main {
  flex: 1;
  padding: 2rem 1rem 3rem;
  background-image:
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 2px,
      var(--wood-grain) 2px,
      var(--wood-grain) 3px
    ),
    linear-gradient(180deg, var(--wood-dark) 0%, var(--wood-mid) 18%, var(--wood-light) 40%, var(--wood-mid) 60%, var(--wood-dark) 100%);
  background-size: 8px 100%, 100% 100%;
  background-position: 0 0, 0 0;
  box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.2);
}

/* College / Faculty selector */
.shelf-selector {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem 1.25rem;
  padding: 1rem 1.5rem;
  margin-bottom: 0.5rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  max-width: 560px;
  margin-left: auto;
  margin-right: auto;
}

.shelf-selector label {
  font-size: 0.875rem;
  color: rgba(232, 224, 208, 0.85);
}

.shelf-selector select {
  font: inherit;
  font-size: 0.9375rem;
  padding: 0.4em 0.75em;
  border: 1px solid rgba(139, 105, 20, 0.5);
  border-radius: 6px;
  background: rgba(26, 16, 8, 0.9);
  color: #e8e0d0;
  min-width: 10ch;
}

.shelf-selector select#shelf-college {
  min-width: 14ch;
}

.shelf-selector select#shelf-faculty-select {
  min-width: 18ch;
}

.shelf-selector select:focus {
  outline: none;
  border-color: var(--wood-light);
  box-shadow: 0 0 0 2px rgba(196, 165, 116, 0.25);
}

.shelf-author-hint {
  margin: 0.75rem 0 0;
  font-size: 0.8125rem;
  color: rgba(232, 224, 208, 0.7);
}

.shelf-author-hint a {
  color: #c4a574;
  text-decoration: none;
}

.shelf-author-hint a:hover {
  text-decoration: underline;
}

.shelf-loading,
.shelf-error,
.shelf-empty {
  text-align: center;
  padding: 3rem 1rem;
  max-width: 420px;
  margin: 0 auto;
}

.shelf-loading-spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto 1rem;
  border: 3px solid rgba(232, 224, 208, 0.3);
  border-top-color: #e8e0d0;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.shelf-loading p,
.shelf-empty p {
  color: rgba(232, 224, 208, 0.9);
  margin: 0;
}

.shelf-error p {
  color: #e8b4a0;
  margin: 0 0 0.5rem;
}

.shelf-error-hint {
  font-size: 0.875rem;
  color: rgba(232, 224, 208, 0.7);
}

.shelf-error-hint a {
  color: #c4a574;
}

/* Shelf container */
.shelf-container {
  max-width: 1400px;
  margin: 0 auto;
}

.shelf-faculty-name {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 1.35rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 1.5rem;
  color: #f5ecd8;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* Wooden shelf row – stronger edge so shelves read clearly */
.shelf-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: var(--gap);
  padding: 0 0 var(--shelf-height);
  margin-bottom: 8px;
  min-height: var(--spine-max-height);
  background: linear-gradient(180deg, transparent 0%, var(--wood-mid) 80%, var(--wood-dark) 98%, #3d3020 100%);
  border-radius: 0 0 6px 6px;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.45), inset 0 2px 0 rgba(255, 255, 255, 0.12), 0 1px 0 rgba(0, 0, 0, 0.3);
  position: relative;
  border: 1px solid rgba(0, 0, 0, 0.25);
  border-top: none;
}

.shelf-row::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 6px;
  background: linear-gradient(180deg, var(--wood-dark) 0%, #2a2018 100%);
  border-radius: 0 0 6px 6px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* Book spine */
.book {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: var(--spine-width);
  min-height: var(--spine-min-height);
  max-height: var(--spine-max-height);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  flex-shrink: 0;
}

@media (hover: hover) {
  .book:hover {
    transform: translateY(-6px) rotateY(-8deg);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.35);
    z-index: 2;
  }
}

.book:active {
  transform: translateY(-2px);
}

.book-spine {
  width: 100%;
  height: 100%;
  min-height: var(--spine-min-height);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 10px 4px;
  background: var(--spine-bg, linear-gradient(135deg, #6b5344 0%, #4a3728 100%));
  border-radius: 2px 2px 0 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), inset -1px 0 0 rgba(0, 0, 0, 0.2), 0 2px 4px rgba(0, 0, 0, 0.25);
  position: relative;
  border: 1px solid rgba(0, 0, 0, 0.2);
}

/* Spine patterns (optional) */
.book-spine.pattern-stripes {
  background-image: repeating-linear-gradient(
    90deg,
    transparent,
    transparent 3px,
    rgba(0, 0, 0, 0.08) 3px,
    rgba(0, 0, 0, 0.08) 4px
  );
}

.book-spine.pattern-tartan {
  background-image:
    repeating-linear-gradient(0deg, transparent, transparent 4px, rgba(0,0,0,0.06) 4px, rgba(0,0,0,0.06) 5px),
    repeating-linear-gradient(90deg, transparent, transparent 4px, rgba(0,0,0,0.06) 4px, rgba(0,0,0,0.06) 5px);
}

/* Spine text – readable on both light and dark spines */
.book-title {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 0.7rem;
  line-height: 1.25;
  font-weight: 700;
  text-orientation: mixed;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  max-height: 100%;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 8;
  -webkit-box-orient: vertical;
  line-clamp: 8;
  color: #1a1a1a;
  text-shadow: 0 0 1px rgba(255, 255, 255, 0.9), 0 1px 2px rgba(255, 255, 255, 0.5), 0 1px 1px rgba(0, 0, 0, 0.15);
  filter: contrast(1.05);
}

.book-author {
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #2a2a2a;
  text-shadow: 0 0 1px rgba(255, 255, 255, 0.6), 0 1px 1px rgba(0, 0, 0, 0.1);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.book-dewey {
  font-size: 0.5rem;
  color: #333;
  text-shadow: 0 0 1px rgba(255, 255, 255, 0.5);
  margin-top: 2px;
}

/* Footer */
.shelf-footer {
  padding: 1rem;
  text-align: center;
  font-size: 0.8rem;
  color: rgba(232, 224, 208, 0.6);
  border-top: 1px solid rgba(139, 105, 20, 0.3);
}

.shelf-footer a {
  color: #c4a574;
  text-decoration: none;
}

.shelf-footer a:hover {
  text-decoration: underline;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .book {
    transition: none;
  }
  .book:hover {
    transform: none;
  }
}
