/* Rich public Books calendar refinements. */

.books-calendar-metrics {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}

.books-calendar-summary {
  margin: -1px 0 13px;
  color: var(--books-calendar-muted, #626a78);
  font-size: 0.72rem;
  line-height: 1.4;
  text-align: center;
}

.books-calendar-activity-row {
  display: flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: -2px 0 9px;
}

.books-calendar-activity-toggle {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--books-calendar-border, #e2e6ee);
  border-radius: 999px;
  background: #fff;
  color: var(--books-calendar-muted, #626a78);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 780;
  cursor: pointer;
}

.books-calendar-activity-toggle strong {
  min-width: 24px;
  color: var(--books-calendar-accent-dark, #263ebd);
  font-size: 0.67rem;
}

.books-calendar-activity-toggle:hover,
.books-calendar-activity-toggle[aria-pressed="true"] {
  border-color: rgba(64, 92, 245, 0.4);
  background: var(--books-calendar-accent-soft, #eef1ff);
  color: var(--books-calendar-accent-dark, #263ebd);
}

.books-calendar-activity-status {
  margin: 0;
  color: var(--books-calendar-muted, #626a78);
  font-size: 0.68rem;
  line-height: 1.35;
}

.books-calendar-activity-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: -1px 0 11px;
  color: var(--books-calendar-muted, #626a78);
  font-size: 0.64rem;
  font-weight: 700;
}

.books-calendar-activity-legend[hidden],
.books-calendar-mobile-activity[hidden],
.books-calendar-preview[hidden] {
  display: none !important;
}

.books-calendar-activity-legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.books-calendar-activity-legend i {
  display: inline-block;
  width: 17px;
  height: 5px;
  border-radius: 999px;
  background: #e3e7ef;
}

.books-calendar-activity-legend i[data-level="low"] { background: #cbd5ff; }
.books-calendar-activity-legend i[data-level="medium"] { background: #9dadff; }
.books-calendar-activity-legend i[data-level="high"] { background: #667df7; }
.books-calendar-activity-legend i[data-level="very-high"] { background: #2947d8; }
.books-calendar-activity-legend i[data-level="missing"] {
  border: 1px solid #cbd0da;
  background: repeating-linear-gradient(135deg, #d8dce4 0 2px, #fff 2px 4px);
}

.books-calendar-day[data-outside-month="true"] {
  background: #f5f6f9 !important;
}

.books-calendar-day[data-outside-month="true"][data-has-books="true"] {
  background: linear-gradient(180deg, #eff1f6 0, #f7f8fa 46%) !important;
}

button.books-calendar-day-number--outside {
  background: transparent !important;
  color: #a4aab6 !important;
}

button.books-calendar-day-number--outside:hover {
  background: #e7eaf2 !important;
  color: #5f6673 !important;
}

.books-calendar-day[data-outside-month="true"] .books-calendar-cover {
  opacity: 0.42;
  filter: grayscale(0.6) saturate(0.45);
  transition: opacity 150ms ease, filter 150ms ease, transform 150ms ease;
}

.books-calendar-day[data-outside-month="true"] .books-calendar-cover:hover,
.books-calendar-day[data-outside-month="true"] .books-calendar-cover:focus-visible {
  opacity: 1;
  filter: none;
}

.books-calendar-day-covers.is-stack .books-calendar-cover[hidden] {
  display: none !important;
}

.books-calendar-stack-overflow {
  position: absolute;
  left: 50%;
  bottom: 4px;
  z-index: 70;
  min-width: 28px;
  padding: 3px 6px;
  border: 1px solid rgba(64, 92, 245, 0.22);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--books-calendar-accent-dark, #263ebd);
  font-size: 0.62rem;
  font-weight: 850;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
}

.books-calendar-day-covers.is-stack:hover .books-calendar-stack-overflow,
.books-calendar-day-covers.is-stack:focus-within .books-calendar-stack-overflow,
.books-calendar-day-covers.is-stack.is-expanded .books-calendar-stack-overflow {
  opacity: 0;
}

.books-calendar-activity-strip {
  position: absolute;
  right: 5px;
  bottom: 3px;
  left: 5px;
  z-index: 44;
  display: none;
  height: 5px;
  border-radius: 999px;
  background: #e3e7ef;
}

.books-calendar.show-listening-activity .books-calendar-activity-strip {
  display: block;
}

.books-calendar-activity-strip[data-level="low"] { background: #cbd5ff; }
.books-calendar-activity-strip[data-level="medium"] { background: #9dadff; }
.books-calendar-activity-strip[data-level="high"] { background: #667df7; }
.books-calendar-activity-strip[data-level="very-high"] { background: #2947d8; }
.books-calendar-activity-strip[data-level="missing"],
.books-calendar-activity-strip[data-level="error"] {
  border: 1px solid #cbd0da;
  background: repeating-linear-gradient(135deg, #d8dce4 0 2px, #fff 2px 4px);
}
.books-calendar-activity-strip[data-level="loading"] {
  overflow: hidden;
  background: #e6e9f1;
}
.books-calendar-activity-strip[data-level="loading"]::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(64, 92, 245, 0.34), transparent);
  animation: booksCalendarActivityLoading 1.1s linear infinite;
}

@keyframes booksCalendarActivityLoading {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}

.books-calendar-most-active {
  position: absolute;
  top: 7px;
  right: 7px;
  z-index: 43;
  display: none;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid rgba(41, 71, 216, 0.22);
  border-radius: 999px;
  background: #fff;
  font-size: 0.68rem;
  box-shadow: 0 3px 9px rgba(15, 23, 42, 0.08);
}

.books-calendar.show-listening-activity .books-calendar-most-active {
  display: grid;
}

/* Anchored desktop book preview. */
.books-calendar-preview {
  position: fixed;
  z-index: 1200;
  width: min(430px, calc(100vw - 28px));
  opacity: 0;
  transform: translateY(4px) scale(0.985);
  pointer-events: auto;
  color-scheme: light;
  transition: opacity 120ms ease, transform 120ms ease;
}

.books-calendar-preview.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.books-calendar-preview-shell {
  position: relative;
  display: grid;
  grid-template-columns: 142px minmax(0, 1fr);
  gap: 16px;
  padding: 15px;
  border: 1px solid rgba(214, 219, 230, 0.98);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 24px 65px rgba(15, 23, 42, 0.22);
  backdrop-filter: blur(14px);
}

.books-calendar-preview-shell::before {
  content: "";
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  border: solid rgba(214, 219, 230, 0.98);
  background: #fff;
  transform: translateY(-50%) rotate(45deg);
}

.books-calendar-preview[data-side="right"] .books-calendar-preview-shell::before {
  left: -7px;
  border-width: 0 0 1px 1px;
}

.books-calendar-preview[data-side="left"] .books-calendar-preview-shell::before {
  right: -7px;
  border-width: 1px 1px 0 0;
}

.books-calendar-preview img {
  display: block;
  width: 142px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border: 1px solid #d9dde6;
  border-radius: 10px;
  background: #eef0f5;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.17);
}

.books-calendar-preview-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.books-calendar-preview-eyebrow {
  margin: 0 0 4px;
  color: var(--books-calendar-accent-dark, #263ebd);
  font-size: 0.7rem;
  font-weight: 850;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.books-calendar-preview h3 {
  margin: 0;
  color: #0e121b;
  font-size: 1.15rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.books-calendar-preview-author {
  margin: 5px 0 9px;
  color: #626a78;
  font-size: 0.82rem;
  font-weight: 700;
}

.books-calendar-preview dl,
.books-calendar-book-sheet dl {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 4px 9px;
  margin: 0;
  padding-top: 9px;
  border-top: 1px solid #e2e6ee;
  font-size: 0.72rem;
  line-height: 1.35;
}

.books-calendar-preview dt,
.books-calendar-book-sheet dt {
  color: #858c9a;
  font-weight: 700;
}

.books-calendar-preview dd,
.books-calendar-book-sheet dd {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: #0e121b;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.books-calendar-preview a {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 5px;
  margin-top: auto;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--books-calendar-accent, #405cf5);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
  text-decoration: none;
}

.books-calendar-preview a:hover {
  background: var(--books-calendar-accent-dark, #263ebd);
}

/* Mobile/coarse-pointer detail sheet. */
.books-calendar-book-sheet {
  width: min(560px, calc(100vw - 20px));
  max-height: calc(100dvh - 20px);
  overflow: hidden;
  padding: 0;
  border: 1px solid #e2e6ee;
  border-radius: 22px;
  background: #fff;
  color: #0e121b;
  color-scheme: light;
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.28);
}

.books-calendar-book-sheet::backdrop {
  background: rgba(13, 18, 31, 0.42);
  backdrop-filter: blur(3px);
}

.books-calendar-book-sheet-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(120px, 0.78fr) minmax(0, 1.22fr);
  gap: 18px;
  max-height: calc(100dvh - 20px);
  overflow-y: auto;
  padding: 20px;
}

.books-calendar-book-sheet-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 38px;
  height: 38px;
  border: 1px solid #e2e6ee;
  border-radius: 999px;
  background: #fff;
  color: #626a78;
  font: inherit;
  font-size: 1.05rem;
  cursor: pointer;
}

.books-calendar-book-sheet img {
  display: block;
  width: 100%;
  max-height: 430px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border: 1px solid #d9dde6;
  border-radius: 11px;
  background: #eef0f5;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.18);
}

.books-calendar-book-sheet-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding-top: 28px;
}

.books-calendar-book-sheet h2 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.17;
  letter-spacing: -0.025em;
}

.books-calendar-book-sheet-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-top: 16px;
  padding: 11px 13px;
  border-radius: 11px;
  background: var(--books-calendar-accent, #405cf5);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 850;
  text-decoration: none;
}

.books-calendar-book-sheet-link:hover {
  background: var(--books-calendar-accent-dark, #263ebd);
}

.books-calendar-mobile-activity {
  display: none;
}

@media (max-width: 1100px) and (min-width: 761px) {
  .books-calendar-preview {
    width: min(390px, calc(100vw - 28px));
  }
  .books-calendar-preview-shell {
    grid-template-columns: 124px minmax(0, 1fr);
  }
  .books-calendar-preview img {
    width: 124px;
  }
}

@media (max-width: 760px) {
  .books-calendar-activity-row {
    flex-direction: column;
    gap: 5px;
    margin-bottom: 8px;
  }

  .books-calendar-activity-status {
    min-height: 1.2em;
    text-align: center;
  }

  .books-calendar-activity-legend {
    flex-wrap: wrap;
    gap: 6px 9px;
    margin-bottom: 9px;
  }

  .books-calendar-summary {
    margin-bottom: 10px;
    font-size: 0.65rem;
  }

  .books-calendar-preview {
    display: none !important;
  }

  .books-calendar-mobile-activity {
    display: block;
    margin-bottom: 10px;
    padding: 9px;
    border: 1px solid var(--books-calendar-border, #e2e6ee);
    border-radius: 13px;
    background: #fafbfe;
  }

  .books-calendar-mobile-weekdays,
  .books-calendar-mobile-activity-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 4px;
  }

  .books-calendar-mobile-weekdays {
    margin-bottom: 4px;
  }

  .books-calendar-mobile-weekdays span {
    color: #8a919f;
    font-size: 0.56rem;
    font-weight: 850;
    text-align: center;
  }

  .books-calendar-mobile-activity-day {
    position: relative;
    display: grid;
    min-width: 0;
    aspect-ratio: 1;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 7px;
    background: #e3e7ef;
    color: #4b5260;
    font: inherit;
    font-size: 0.61rem;
    font-weight: 800;
  }

  button.books-calendar-mobile-activity-day { cursor: pointer; }
  .books-calendar-mobile-activity-day[data-level="low"] { background: #cbd5ff; }
  .books-calendar-mobile-activity-day[data-level="medium"] { background: #9dadff; }
  .books-calendar-mobile-activity-day[data-level="high"] { background: #667df7; color: #fff; }
  .books-calendar-mobile-activity-day[data-level="very-high"] { background: #2947d8; color: #fff; }
  .books-calendar-mobile-activity-day[data-level="missing"],
  .books-calendar-mobile-activity-day[data-level="error"] {
    border: 1px solid #cbd0da;
    background: repeating-linear-gradient(135deg, #d8dce4 0 3px, #fff 3px 6px);
  }
  .books-calendar-mobile-activity-day[data-level="loading"] { background: #eceef4; }
  .books-calendar-mobile-activity-day[data-outside-month="true"] { opacity: 0.4; }
  .books-calendar-mobile-activity-day[data-most-active="true"]::after {
    content: "🎧";
    position: absolute;
    top: -4px;
    right: -4px;
    font-size: 0.48rem;
  }

  .books-calendar-book-sheet {
    width: calc(100vw - 12px);
    max-height: calc(100dvh - 12px);
    margin-top: auto;
    margin-bottom: 6px;
    border-radius: 22px 22px 14px 14px;
  }

  .books-calendar-book-sheet-shell {
    display: flex;
    max-height: calc(100dvh - 12px);
    flex-direction: column;
    gap: 13px;
    padding: 17px;
  }

  .books-calendar-book-sheet img {
    width: min(220px, 64vw);
    max-height: 46vh;
    align-self: center;
  }

  .books-calendar-book-sheet-copy {
    padding-top: 0;
  }

  .books-calendar-book-sheet h2 {
    padding-right: 34px;
    font-size: 1.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .books-calendar-preview,
  .books-calendar-activity-strip::after {
    animation: none !important;
    transition: none !important;
  }
}
