/* ==========================================================
   Books: /books, a shelf of the books Sam has read.
   Styled after Apple Books' library: covers in a grid, each opening a card.
   The HTML is generated by tools/build_books.py; books.js adds the filters and cards.
   Builds on styles.css (tokens, .page, .label, the shared .bk-glyph icon).
   ========================================================== */

.bk { font-family: var(--font); }

/* ---------- Header ---------- */
.bk-head { display: flex; flex-direction: column; gap: 12px; max-width: 640px; margin-bottom: 28px; }
.bk-app { display: flex; align-items: center; gap: 8px; font-family: var(--font-system); font-size: 13px; font-weight: 600; color: var(--muted); }
.bk-heading { font-size: clamp(28px, 4vw, 40px); font-weight: 600; line-height: 1.1; letter-spacing: -0.02em; }
.bk-lede { font-size: 17px; line-height: 1.55; color: var(--body-text); }
.bk-count { font-size: 13px; font-weight: 500; color: var(--muted); }

/* ---------- Topic filters (pills like Writing's topic chips) ---------- */
.bk-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 32px; }
.bk-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  font: 500 13px/1.2 var(--font);
  cursor: pointer;
  transition: background .2s, color .2s, border-color .2s;
}
.bk-chip span { color: var(--muted); }
.bk-chip:hover { border-color: var(--outline); }
.bk-chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--on-text); font-weight: 600; }
.bk-chip[aria-pressed="true"] span { color: inherit; opacity: .6; }
.bk-chip:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* ---------- The shelf ---------- */
.bk-shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 32px 24px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.bk-book[hidden] { display: none; }
.bk-link { display: flex; flex-direction: column; gap: 3px; min-width: 0; border-radius: 8px; }
.bk-link:focus-visible { outline: 2px solid var(--text); outline-offset: 4px; }

/* A cover: square spine on the left, a faint fold of light down it, and a soft shadow */
.bk-cover {
  position: relative;
  display: block;
  aspect-ratio: 2 / 3;
  margin-bottom: 9px;
  border-radius: 3px 7px 7px 3px;
  overflow: hidden;
  background: var(--line);
  box-shadow: 0 16px 28px -14px rgba(0, 0, 0, .5), 0 2px 4px rgba(0, 0, 0, .12);
  transition: transform .3s ease;
}
.bk-cover img { display: block; width: 100%; height: 100%; object-fit: cover; }
.bk-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(0, 0, 0, .22) 0, rgba(255, 255, 255, .16) 3%, transparent 8%);
}
.bk-link:hover .bk-cover { transform: translateY(-4px); }

/* No cover picture yet: a plain one with the title set big. Light in both themes, like paper. */
.bk-cover--drawn {
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  padding: 14% 10% 10% 16%;
  background: #f2f2f4;
  color: #111111;
}
.bk-drawn-title { font-size: 17cqw; font-weight: 700; line-height: 1; letter-spacing: -0.03em; }
.bk-drawn-sub { margin-top: 4cqw; font-size: 7.5cqw; font-weight: 500; line-height: 1.2; }
.bk-drawn-author { margin-top: auto; font-size: 6.2cqw; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; opacity: .75; }

.bk-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
}
.bk-author { overflow: hidden; font-size: 13px; color: var(--muted); white-space: nowrap; text-overflow: ellipsis; }

/* Sam's rating: five stars, filled up to the rating */
.bk-stars { display: flex; gap: 2px; margin-top: 4px; }
.bk-stars svg { width: 12px; height: 12px; }
.bk-stars path { fill: none; stroke: var(--outline); stroke-width: 2; stroke-linejoin: round; }
.bk-stars .is-on path { fill: var(--text); stroke: var(--text); }

/* ---------- A book's card ---------- */
.bk-card {
  margin: auto;   /* centres it: styles.css zeroes every margin, which undoes the browser's own centring */
  width: min(640px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 0;
  border-radius: 24px;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .45);
}
.bk-card::backdrop { background: rgba(17, 17, 17, .35); }
:root[data-theme="dark"] .bk-card { box-shadow: 0 0 0 1px var(--hover-ring), 0 30px 80px -20px rgba(0, 0, 0, .6); }
:root[data-theme="dark"] .bk-card::backdrop { background: rgba(0, 0, 0, .6); }
.bk-card[open] { animation: bk-in .25s ease; }
@keyframes bk-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }

.bk-card-inner { position: relative; display: flex; flex-wrap: wrap; gap: 28px; padding: 28px; }
.bk-card-cover { flex: 0 0 180px; }
.bk-card-cover .bk-cover { margin: 0; border-radius: 3px 9px 9px 3px; }
.bk-card-body { flex: 1 1 260px; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.bk-card-names { display: flex; flex-direction: column; gap: 6px; padding-right: 40px; }
.bk-card-title { font-size: 26px; font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; }
/* The card opens with focus on the title (screen readers start there), not on the close button */
.bk-card-title:focus { outline: none; }
.bk-card-sub { font-size: 15px; line-height: 1.4; color: var(--body-text); }
.bk-card-author { font-size: 14px; color: var(--muted); }
.bk-card-summary { font-size: 15px; line-height: 1.55; color: var(--body-text); }

.bk-card-ratings { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.bk-card-rating, .bk-readers-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}
.bk-card-rating { padding: 12px 0; }
.bk-card-rating .label, .bk-readers-row .label { margin-right: auto; }
.bk-stars--lg { gap: 3px; margin: 0; }
.bk-stars--lg svg { width: 20px; height: 20px; }
.bk-stars--lg path { stroke-width: 1.8; }
.bk-card-score { font-size: 13px; font-weight: 500; color: var(--muted); }

/* Readers' ratings: five stars to tap (44px tall, so easy to hit on a phone), then the average */
.bk-readers { padding: 2px 0 12px; border-top: 1px solid var(--line); }
.bk-rate { display: flex; margin-right: -8px; }
.bk-rate-star {
  width: 38px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}
.bk-rate-star svg { width: 26px; height: 26px; }
.bk-rate-star path { fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-linejoin: round; transition: fill .15s, stroke .15s; }
.bk-rate-star.is-on path { fill: var(--text); stroke: var(--text); }
.bk-rate-star:focus-visible { outline: 2px solid var(--text); outline-offset: -2px; }
/* With a mouse, hovering previews the rating: that star and the ones before it fill in */
@media (hover: hover) {
  .bk-rate:hover .bk-rate-star path { fill: none; stroke: var(--muted); }
  .bk-rate .bk-rate-star:hover path,
  .bk-rate .bk-rate-star:has(~ .bk-rate-star:hover) path { fill: var(--text); stroke: var(--text); }
}
.bk-readers-text { font-size: 13px; line-height: 1.45; color: var(--muted); }

.bk-card-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 2px; }
.bk-buy {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 20px;
  border-radius: 999px;
  font: 600 15px/1 var(--font);
  cursor: pointer;
}
.bk-buy { background: var(--text); color: var(--on-text); transition: opacity .2s; }
.bk-buy:hover { opacity: .85; }
.bk-buy svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.bk-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--tile);
  color: var(--text);
  cursor: pointer;
}
.bk-close svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.bk-buy:focus-visible, .bk-close:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* ---------- Phones: three covers a row, like the Books app ---------- */
@media (max-width: 640px) {
  .bk-shelf { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px 14px; }
  .bk-title { font-size: 13px; }
  .bk-author { font-size: 12px; }
  .bk-stars svg { width: 10px; height: 10px; }
  .bk-card-inner { gap: 20px; padding: 24px 20px; }
  .bk-card-cover { flex-basis: 120px; }
  .bk-card-title { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .bk-cover, .bk-card[open] { transition: none; animation: none; }
}
