/* ==========================================================================
   Shelf — zoomed-out, editorial year-by-year reading view.

   Aesthetic: Sunday-supplement library spread. Big Fraunces year numerals
   set the rhythm. Cover art is the only color. Months are columns; books
   stack on subtle hairline shelves. Hover reveals a hand-written tooltip.
   ========================================================================== */

.shelf {
  --shelf-bg: var(--bg);
  --shelf-rule: rgba(28, 22, 15, 0.18);
  --shelf-rule-soft: rgba(28, 22, 15, 0.08);
  --shelf-ink: var(--text);
  --cover-w: 30px;
  --cover-h: 44px;
  --cover-overlap: 8px;

  position: relative;
  padding: var(--space-2xl) 0;
  background:
    radial-gradient(1200px 600px at 0% 0%, rgba(184, 76, 42, 0.04), transparent 60%),
    radial-gradient(900px 500px at 100% 100%, rgba(46, 125, 155, 0.03), transparent 60%),
    var(--shelf-bg);
}

/* Faint vertical guide running the length of the shelf — looks like the
   gutter of an open book. */
.shelf::before {
  content: "";
  position: absolute;
  inset: var(--space-xl) 0;
  left: clamp(80px, 14%, 180px);
  border-left: 1px solid var(--shelf-rule-soft);
  pointer-events: none;
}

/* ---- Masthead ---------------------------------------------------------- */

.shelf-masthead {
  display: grid;
  grid-template-columns: clamp(80px, 14%, 180px) 1fr;
  gap: var(--space-lg);
  align-items: baseline;
  margin: 0 0 var(--space-2xl) 0;
  padding: 0 var(--space-xl);
}

.shelf-masthead__eyebrow {
  grid-column: 1;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: right;
  padding-right: var(--space-md);
}

.shelf-masthead__headline {
  grid-column: 2;
  display: flex;
  align-items: baseline;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.shelf-masthead__num {
  font-family: var(--font-display);
  font-size: clamp(3rem, 7vw, 5.5rem);
  font-weight: 300;
  letter-spacing: -0.04em;
  line-height: 0.9;
  color: var(--shelf-ink);
  font-variation-settings: 'opsz' 96, 'SOFT' 50;
}

.shelf-masthead__label {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 300;
  font-size: clamp(1rem, 1.8vw, 1.25rem);
  color: var(--text-secondary);
  letter-spacing: -0.01em;
}

.shelf-masthead__sub {
  grid-column: 2;
  font-family: var(--font-body);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-top: var(--space-xs);
}

.shelf-masthead__sub em {
  font-family: var(--font-mono);
  font-style: normal;
  font-weight: 600;
  color: var(--rated);
  letter-spacing: 0;
}

/* ---- Year row ---------------------------------------------------------- */

.shelf-year {
  display: grid;
  grid-template-columns: clamp(80px, 14%, 180px) 1fr;
  gap: var(--space-lg);
  align-items: stretch;
  padding: var(--space-xl) var(--space-xl);
  border-top: 1px solid var(--shelf-rule-soft);
  animation: shelfYearIn 0.6s ease both;
  animation-delay: var(--stagger, 0s);
}

@keyframes shelfYearIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.shelf-year__masthead {
  grid-column: 1;
  position: sticky;
  top: 72px;          /* under the app topbar */
  align-self: start;
  text-align: right;
  padding-right: var(--space-md);
}

.shelf-year__num {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(2.5rem, 6vw, 4.75rem);
  line-height: 0.95;
  letter-spacing: -0.05em;
  color: var(--shelf-ink);
  font-variation-settings: 'opsz' 144, 'SOFT' 100;
  /* Tiny watermark of the digit behind itself, hand-set */
  text-shadow: 1px 1px 0 rgba(184, 76, 42, 0.06);
}

.shelf-year__meta {
  margin-top: var(--space-sm);
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-end;
}

.shelf-year__meta-row {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

.shelf-year__count {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--shelf-ink);
}

.shelf-year__count-label {
  font-family: var(--font-body);
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-muted);
}

.shelf-year__avg {
  font-family: var(--font-body);
  font-size: 0.6875rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.shelf-year__avg em {
  font-family: var(--font-mono);
  font-style: normal;
  font-weight: 600;
  color: var(--rated);
}

.shelf-year__avg-scale {
  color: var(--text-faint);
}

.shelf-year__peak {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.75rem;
  color: var(--accent);
  letter-spacing: 0.01em;
}

/* ---- The strip of months ---------------------------------------------- */

.shelf-year__strip {
  grid-column: 2;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 4px;
  align-items: end;
  min-height: calc(var(--cover-h) + 32px);
}

.shelf-month {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 18px;     /* leave room for shelf line + label */
  min-height: 100%;
}

.shelf-month--empty {
  opacity: 0.55;
}

/* The vertical stack of covers, growing UP from the shelf line */
.shelf-month__column {
  display: flex;
  flex-direction: column-reverse;   /* newest finish on top */
  align-items: center;
  gap: calc(-1 * var(--cover-overlap)); /* overlap a little */
  width: var(--cover-w);
  margin-bottom: 4px;
}

/* The hairline "shelf" that books rest on */
.shelf-month__shelf-line {
  position: absolute;
  bottom: 16px;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--shelf-rule);
}

.shelf-month__shelf-line::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(28, 22, 15, 0.06), transparent);
  height: 3px;
}

.shelf-month__foot {
  position: absolute;
  bottom: 0;
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.shelf-month__label {
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.shelf-month__count {
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  color: var(--text-faint);
}

.shelf-month--peak .shelf-month__label,
.shelf-month--peak .shelf-month__count {
  color: var(--accent);
}

.shelf-month--peak .shelf-month__shelf-line {
  background: linear-gradient(90deg, var(--shelf-rule) 0%, var(--accent) 50%, var(--shelf-rule) 100%);
  height: 2px;
  bottom: 15px;
}

/* ---- A single cover --------------------------------------------------- */

.shelf-cover {
  position: relative;
  width: var(--cover-w);
  height: var(--cover-h);
  border: 0;
  padding: 0;
  background: var(--bg-warm);
  border-radius: 1.5px;
  box-shadow:
    1px 1px 0 rgba(28, 22, 15, 0.04),
    var(--shadow-book);
  transform: rotate(var(--rot, 0deg));
  transform-origin: bottom center;
  transition:
    transform 0.25s cubic-bezier(0.2, 0.7, 0.2, 1),
    box-shadow 0.25s ease,
    z-index 0s linear 0.25s;
  cursor: pointer;
  overflow: visible;  /* tooltip escapes */
  z-index: 1;
}

.shelf-cover__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
  display: block;
}

.shelf-cover__placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  color: var(--text-faint);
  background: var(--bg-warm);
}

.shelf-cover__rating {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  font-family: var(--font-mono);
  font-size: 0.5rem;
  font-weight: 700;
  color: var(--bg);
  background: var(--rated);
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  pointer-events: none;
}

.shelf-cover:hover,
.shelf-cover:focus-visible {
  transform: rotate(0deg) scale(2.6) translateY(-12%);
  box-shadow:
    0 12px 28px rgba(28, 22, 15, 0.25),
    0 2px 6px rgba(28, 22, 15, 0.15);
  z-index: 50;
  outline: none;
  transition:
    transform 0.25s cubic-bezier(0.2, 0.7, 0.2, 1),
    box-shadow 0.25s ease,
    z-index 0s linear 0s;
}

/* When a cover lifts, the tooltip floats above it */
.shelf-cover__tooltip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  width: 200px;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-surface);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 60;
  text-align: left;
}

.shelf-cover:hover .shelf-cover__tooltip,
.shelf-cover:focus-visible .shelf-cover__tooltip {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(0.4); /* counter parent scale */
  transform-origin: bottom center;
}

.shelf-cover__tooltip-title {
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin-bottom: 2px;
}

.shelf-cover__tooltip-author {
  font-family: var(--font-body);
  font-size: 0.6875rem;
  color: var(--text-secondary);
  line-height: 1.3;
  margin-bottom: 4px;
}

.shelf-cover__tooltip-date {
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-muted);
}

/* ---- View-mode toggle (Timeline / Shelf) ------------------------------ */

.timeline-mode-switch {
  display: inline-flex;
  align-items: center;
  gap: 0;
  background: var(--bg-warm);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 2px;
  margin: 0 0 var(--space-md) 0;
}

.timeline-mode-switch__btn {
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: transparent;
  border: 0;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.timeline-mode-switch__btn:hover {
  color: var(--text);
}

.timeline-mode-switch__btn--active {
  background: var(--bg-surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.timeline-mode-switch__glyph {
  font-size: 0.625rem;
  opacity: 0.7;
}

/* ---- Responsive ------------------------------------------------------- */

@media (max-width: 760px) {
  .shelf {
    --cover-w: 24px;
    --cover-h: 36px;
    --cover-overlap: 6px;
    padding: var(--space-lg) 0;
  }
  .shelf::before { display: none; }
  .shelf-year,
  .shelf-masthead {
    grid-template-columns: 1fr;
    padding: var(--space-md) var(--space-md);
  }
  .shelf-year__masthead {
    text-align: left;
    padding-right: 0;
    position: static;
  }
  .shelf-year__meta {
    align-items: flex-start;
    flex-direction: row;
    flex-wrap: wrap;
    gap: var(--space-sm);
  }
  .shelf-cover:hover,
  .shelf-cover:focus-visible {
    transform: rotate(0deg) scale(2.2) translateY(-10%);
  }
  .shelf-cover:hover .shelf-cover__tooltip {
    transform: translateX(-50%) translateY(0) scale(0.5);
  }
}
