/* Grokipedia-style hymnal spine shelf — click pulls out 3D cover */

.eh-spine-shelf {
  --eh-spine-ink: #e8ecf1;
  --eh-spine-muted: #9aa3ad;
  --eh-spine-border: rgba(255, 255, 255, 0.08);
  --eh-spine-plank: #2a303a;
  --eh-spine-accent: #6eb6ff;
  margin: 1.5rem 0 0.5rem;
  padding: 1.1rem 0.85rem 1rem;
  border: 1px solid var(--eh-spine-border);
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.03);
  color: var(--eh-spine-ink);
}

.ss-studio.ss-light .eh-spine-shelf,
.eh-spine-shelf.is-light {
  --eh-spine-ink: #1c1915;
  --eh-spine-muted: #5a554c;
  --eh-spine-border: #ddd6cb;
  --eh-spine-plank: #cfc5b6;
  --eh-spine-accent: #1f5f8a;
  background: #fffefb;
}

body:not(:has(.ss-studio)) .eh-spine-shelf {
  --eh-spine-ink: #1a1a2e;
  --eh-spine-muted: #64748b;
  --eh-spine-border: #e5e7eb;
  --eh-spine-plank: #d6d0c4;
  --eh-spine-accent: #1f5f8a;
  background: #fafbfc;
}

.eh-spine-shelf-head {
  margin: 0 0 0.85rem;
}

.eh-spine-shelf-head h3 {
  margin: 0 0 0.2rem;
  font-size: 1.05rem;
  font-weight: 750;
  color: var(--eh-spine-ink);
}

.eh-spine-shelf-head p {
  margin: 0;
  font-size: 0.84rem;
  color: var(--eh-spine-muted);
}

.eh-spine-rail {
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  padding: 1.35rem 0.5rem 1.25rem;
  perspective: 1200px;
}

.eh-spine-rail::-webkit-scrollbar {
  height: 6px;
}
.eh-spine-rail::-webkit-scrollbar-thumb {
  background: rgba(128, 128, 128, 0.35);
  border-radius: 999px;
}

.eh-spine-row {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  min-height: 210px;
  width: max-content;
  min-width: 100%;
  justify-content: flex-start;
  padding-bottom: 14px;
  position: relative;
}

.eh-spine-row::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 10px;
  border-radius: 2px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), transparent 40%),
    var(--eh-spine-plank);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.22);
}

/* ---- Slot: spine OR pulled 3D book ---- */

.eh-spine-slot {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  z-index: 1;
  transition: margin 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.eh-spine-slot.is-open {
  z-index: 6;
  margin-right: 0.35rem;
}

.eh-spine {
  appearance: none;
  border: 0;
  cursor: pointer;
  position: relative;
  flex: 0 0 auto;
  width: 34px;
  height: 150px;
  border-radius: 3px 3px 1px 1px;
  text-decoration: none;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.15rem 0.4rem;
  box-shadow:
    inset -2px 0 4px rgba(0, 0, 0, 0.28),
    inset 2px 0 3px rgba(255, 255, 255, 0.12),
    0 2px 6px rgba(0, 0, 0, 0.2);
  transform: translateY(0) scale(1);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.28s ease, opacity 0.3s ease, width 0.35s ease;
  z-index: 1;
  font: inherit;
}

.eh-spine:hover,
.eh-spine:focus-visible {
  transform: translateY(-12px) scale(1.03);
  box-shadow:
    inset -2px 0 4px rgba(0, 0, 0, 0.28),
    inset 2px 0 3px rgba(255, 255, 255, 0.14),
    0 14px 24px rgba(0, 0, 0, 0.35);
  z-index: 3;
  outline: none;
}

.eh-spine-slot.is-open .eh-spine {
  width: 0;
  height: 150px;
  padding: 0;
  margin: 0;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  transform: none;
  box-shadow: none;
}

.eh-spine-title {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.1;
  max-height: 112px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
}

.eh-spine-mark {
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-size: 0.72rem;
  font-weight: 700;
  opacity: 0.85;
  line-height: 1;
}

/* ---- Pulled-out 3D book ---- */

.eh-spine-pulled {
  width: 0;
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  transform-origin: left bottom;
  transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1), max-width 0.45s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.35s ease;
}

.eh-spine-slot.is-open .eh-spine-pulled {
  width: 128px;
  max-width: 128px;
  opacity: 1;
  overflow: visible;
  pointer-events: auto;
}

.eh-spine-book-3d {
  position: relative;
  width: 118px;
  height: 168px;
  margin: 0 auto 2px;
  transform-style: preserve-3d;
  transform: rotateY(-26deg) rotateX(5deg) translateY(-8px);
  filter: drop-shadow(14px 22px 26px rgba(0, 0, 0, 0.5));
  animation: eh-spine-pull-in 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes eh-spine-pull-in {
  from {
    opacity: 0;
    transform: rotateY(-78deg) rotateX(8deg) translateY(6px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: rotateY(-26deg) rotateX(5deg) translateY(-8px) scale(1);
  }
}

.eh-spine-book-cover {
  position: absolute;
  inset: 0;
  border-radius: 2px 5px 5px 2px;
  overflow: hidden;
  background: linear-gradient(160deg, #3a465c 0%, #1c2430 55%, #121820 100%);
  transform: translateZ(1px);
  box-shadow:
    inset -12px 0 18px rgba(0, 0, 0, 0.28),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.eh-spine-book-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
}

.eh-spine-book-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.75rem;
  text-align: center;
  color: #f3e9d8;
  background:
    radial-gradient(circle at 30% 20%, rgba(110, 182, 255, 0.2), transparent 50%),
    linear-gradient(160deg, #5a4634 0%, #2c2118 60%, #17120e 100%);
}

.eh-spine-book-fallback i {
  font-size: 1.5rem;
  opacity: 0.85;
}

.eh-spine-book-fallback strong {
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.25;
}

.eh-spine-book-brand {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 1.6rem 0.55rem 0.55rem;
  background: linear-gradient(180deg, transparent 0%, rgba(8, 12, 18, 0.82) 45%, rgba(8, 12, 18, 0.94) 100%);
  color: #f4f7fb;
  pointer-events: none;
}

.eh-spine-book-brand small {
  display: block;
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.75;
  margin-bottom: 0.15rem;
}

.eh-spine-book-brand strong {
  display: block;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.2;
}

.eh-spine-book-edge {
  position: absolute;
  top: 1px;
  bottom: 1px;
  left: 0;
  width: 16px;
  transform-origin: left center;
  transform: rotateY(-90deg) translateX(-16px);
  border-radius: 3px 0 0 3px;
  background: linear-gradient(90deg, #0e1218 0%, #2a3545 28%, #6eb6ff 52%, #2a3545 78%, #0e1218 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.ss-studio.ss-light .eh-spine-book-edge {
  background: linear-gradient(90deg, #1a2430 0%, #2f4a63 28%, #1f5f8a 52%, #2f4a63 78%, #1a2430 100%);
}

.eh-spine-book-pages {
  position: absolute;
  top: 4px;
  bottom: 4px;
  right: 0;
  width: 12px;
  transform-origin: right center;
  transform: rotateY(90deg) translateX(12px);
  background: repeating-linear-gradient(
    180deg,
    #f4efe4 0px,
    #f4efe4 2px,
    #e4dccb 2px,
    #e4dccb 3px
  );
  border-radius: 0 2px 2px 0;
  box-shadow: 2px 0 6px rgba(0, 0, 0, 0.2);
}

/* ---- Caption / actions bar ---- */

.eh-spine-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-top: 0.55rem;
  min-height: 1.6rem;
}

.eh-spine-caption {
  min-height: 1.35rem;
  font-size: 0.95rem;
  color: var(--eh-spine-ink);
  font-weight: 650;
  font-family: Georgia, "Times New Roman", serif;
}

.eh-spine-caption .eh-spine-cap-num {
  display: inline-block;
  margin-right: 0.45rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--eh-spine-muted);
  font-variant-numeric: tabular-nums;
  font-family: system-ui, sans-serif;
}

.eh-spine-caption:empty::before {
  content: "Click a spine to pull it out";
  color: var(--eh-spine-muted);
  font-weight: 500;
  font-size: 0.82rem;
  font-family: system-ui, sans-serif;
}

.eh-spine-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.85rem 1.15rem;
}

.eh-spine-actions[hidden] {
  display: none !important;
}

.eh-spine-action-open {
  color: var(--eh-spine-accent);
  font-size: 0.88rem;
  font-weight: 650;
  text-decoration: none;
}

.eh-spine-action-open:hover {
  text-decoration: underline;
}

.eh-spine-action-back {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  color: var(--eh-spine-muted);
  font-size: 0.88rem;
  font-weight: 550;
  font: inherit;
}

.eh-spine-action-back:hover {
  color: var(--eh-spine-ink);
  text-decoration: underline;
}

/* Spine color cycles */
.eh-spine[data-tone="0"] { background: linear-gradient(90deg, #1f2937, #374151 45%, #1f2937); }
.eh-spine[data-tone="1"] { background: linear-gradient(90deg, #1e3a5f, #2f5f8f 45%, #1e3a5f); }
.eh-spine[data-tone="2"] { background: linear-gradient(90deg, #3f2a1d, #6b4f35 45%, #3f2a1d); color: #f5efe6; }
.eh-spine[data-tone="3"] { background: linear-gradient(90deg, #1f3d32, #2f6b55 45%, #1f3d32); }
.eh-spine[data-tone="4"] { background: linear-gradient(90deg, #4a1f2e, #7a3a52 45%, #4a1f2e); }
.eh-spine[data-tone="5"] { background: linear-gradient(90deg, #2a2544, #4b4472 45%, #2a2544); }
.eh-spine[data-tone="6"] { background: linear-gradient(90deg, #6b3a1a, #b86a2e 45%, #6b3a1a); }
.eh-spine[data-tone="7"] { background: linear-gradient(90deg, #0f3d4a, #1f6d7d 45%, #0f3d4a); }
.eh-spine[data-tone="8"] { background: linear-gradient(90deg, #3d3d1f, #6d6d35 45%, #3d3d1f); }
.eh-spine[data-tone="9"] { background: linear-gradient(90deg, #4a2430, #8a4058 45%, #4a2430); }
.eh-spine[data-tone="10"] { background: linear-gradient(90deg, #243044, #3f5578 45%, #243044); }
.eh-spine[data-tone="11"] { background: linear-gradient(90deg, #2d2a28, #5a534c 45%, #2d2a28); }

@media (prefers-reduced-motion: reduce) {
  .eh-spine-book-3d {
    animation: none;
  }
  .eh-spine,
  .eh-spine-pulled,
  .eh-spine-slot {
    transition: none;
  }
}

@media (max-width: 560px) {
  .eh-spine {
    width: 30px;
    height: 132px;
  }
  .eh-spine-row {
    min-height: 188px;
  }
  .eh-spine-title {
    font-size: 0.62rem;
    max-height: 96px;
  }
  .eh-spine-slot.is-open .eh-spine-pulled {
    width: 108px;
  }
  .eh-spine-book-3d {
    width: 100px;
    height: 142px;
  }
  .eh-spine-bar {
    flex-direction: column;
    align-items: flex-start;
  }
}
