/* ==========================================================================
   Ebook page — extends the SIBI design system (style.css) with fallbacks
   so this file still looks correct even if a token isn't defined there.
   ========================================================================== */

.ebook-hero {
  background: linear-gradient(180deg, var(--gold, #C1603E) 0%, transparent 140%);
}

/* ---- toolbar chip active state reuse from catalog is inherited ---- */

.ebook-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 22px;
}

.ebook-empty {
  padding: 40px 0;
  text-align: center;
  color: var(--text-soft, #83866E);
  font-size: .9rem;
}

.ebook-card {
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  overflow: hidden;
  background: var(--card, #fff);
  border: 1px solid var(--border, rgba(0,0,0,.08));
  box-shadow: 0 1px 2px rgba(20,16,8,.04);
  transition: transform .18s ease, box-shadow .18s ease;
  cursor: pointer;
}

.ebook-card:hover,
.ebook-card:focus-within {
  transform: translateY(-4px);
  box-shadow: 0 14px 28px rgba(20,16,8,.12);
}

.ebook-card:focus-visible {
  outline: 2px solid var(--gold, #C1603E);
  outline-offset: 2px;
}

/* the "spine" is this page's signature element: a thin coloured strip along
   the top edge of every cover, echoing a book shelved on its side — the
   colour encodes the ebook's category, same idea as a library call-number
   sticker. */
.ebook-cover {
  position: relative;
  aspect-ratio: 3 / 4;
  display: flex;
  align-items: flex-end;
  padding: 14px;
  color: #fff;
  font-family: 'Fraunces', serif;
}

.ebook-cover::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 8px;
  background: rgba(0,0,0,.18);
}

.ebook-cover-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

/* readability overlay so the title stays legible over any photo */
.ebook-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0) 40%, rgba(0,0,0,.55) 100%);
  z-index: 1;
}

.ebook-cover .ebook-cover-glyph {
  position: absolute;
  top: 22px;
  left: 14px;
  right: 14px;
  font-size: 2rem;
  opacity: .9;
  z-index: 2;
  display: none; /* shown only as fallback, see .no-photo below */
}

/* fallback state: applied by JS if a cover photo fails to load */
.ebook-cover.no-photo .ebook-cover-glyph,
.ebook-modal-cover.no-photo .ebook-cover-glyph {
  display: block;
}

.ebook-format-tag,
.ebook-cover-title {
  position: relative;
  z-index: 2;
}

.ebook-cover .ebook-cover-title {
  position: relative;
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.25;
  text-shadow: 0 1px 6px rgba(0,0,0,.25);
}

.ebook-format-tag {
  position: absolute;
  top: 14px;
  right: 12px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .04em;
  background: rgba(0,0,0,.35);
  padding: 3px 7px;
  border-radius: 6px;
}

.ebook-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.ebook-badge {
  align-self: flex-start;
  font-family: 'IBM Plex Mono', monospace;
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--gold, #C1603E);
  background: color-mix(in srgb, var(--gold, #C1603E) 14%, transparent);
  padding: 3px 8px;
  border-radius: 20px;
}

.ebook-title {
  font-family: 'Fraunces', serif;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
  margin: 0;
}

.ebook-author {
  font-size: .8rem;
  color: var(--text-soft, #83866E);
  margin: 0;
}

.ebook-meta-row {
  display: flex;
  gap: 10px;
  font-size: .72rem;
  color: var(--text-soft, #83866E);
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px dashed var(--border, rgba(0,0,0,.1));
}

.ebook-meta-row span {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ---- modal (reader / download sheet) ---- */

.ebook-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.ebook-modal[hidden] { display: none; }

.ebook-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20,16,8,.5);
  backdrop-filter: blur(2px);
}

.ebook-modal-card {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--card, #fff);
  border-radius: 18px;
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 0;
  box-shadow: 0 30px 60px rgba(0,0,0,.3);
}

.ebook-modal-cover {
  position: relative;
  min-height: 100%;
  overflow: hidden;
  color: #fff;
  display: flex;
  align-items: flex-end;
  padding: 14px;
  font-family: 'Fraunces', serif;
  font-weight: 600;
}

.ebook-modal-cover .ebook-cover-glyph {
  font-size: 2.4rem;
  display: none;
}

.ebook-modal-cover.no-photo .ebook-cover-glyph {
  display: block;
}

.ebook-modal-body {
  padding: 22px 22px 22px 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ebook-modal-body h3 {
  font-family: 'Fraunces', serif;
  margin: 2px 0 0;
  font-size: 1.3rem;
}

.ebook-modal-author {
  color: var(--text-soft, #83866E);
  font-size: .85rem;
  margin: 0;
}

.ebook-modal-body > p:not(.ebook-modal-author) {
  font-size: .88rem;
  line-height: 1.55;
  margin: 6px 0 0;
}

.ebook-modal-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: .7rem;
  color: var(--text-soft, #83866E);
  margin-top: 4px;
}

.ebook-modal-meta span {
  background: rgba(0,0,0,.05);
  padding: 3px 8px;
  border-radius: 20px;
}

.ebook-modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.ebook-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,.35);
  color: #fff;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

@media (max-width: 560px) {
  .ebook-modal-card { grid-template-columns: 1fr; }
  .ebook-modal-cover { min-height: 140px; align-items: center; justify-content: center; }
}

/* ---- lightweight toast (self-contained fallback) ---- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(10px);
  background: #2A2E1F;
  color: #fff;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: .85rem;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.main-nav a.active {
  color: var(--gold, #C1603E);
  font-weight: 700;
}