/* screen-library.css — the bookshelf. Owned by S9.
   Every colour here is either a token from tokens.css or is derived from the
   per-book hue custom property --cov-h that js/library.js sets on each cover.
   No images, no fonts, no network. */

/* ---- header ------------------------------------------------------------ */

/* clears the fixed #hud chips, matching the convention in screen-home.css */
#screen-library { padding-top: 72px; }
@media (max-width: 419px) {
  #screen-library { padding-top: 84px; }
}

#screen-library .lib-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  max-width: 1200px;
  margin: 0 auto;
}
#screen-library .lib-head__h1 { margin: 0; flex: 1 1 auto; }

#screen-library .lib-sub {
  max-width: 1200px;
  margin: var(--sp-2) auto var(--sp-4);
  font-size: var(--fs-body);
  color: var(--c-ink-soft);
}

/* ---- speak buttons ------------------------------------------------------
   Sized to the hard tap floor, not to the 48px shared .speak component. */

#screen-library .lib-speak {
  width: var(--tap);
  height: var(--tap);
  min-width: var(--tap);
  min-height: var(--tap);
  flex: 0 0 auto;
  border: none;
  border-radius: 50%;
  background: var(--c-bg-2);
  color: var(--c-ink);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-pop);
}
#screen-library .lib-speak:active { transform: scale(.9); }
#screen-library .lib-speak--head { background: var(--c-surface); box-shadow: var(--shadow); }

/* ---- section headers ----------------------------------------------------
   The only "grouping" on the shelf: new books above, loved books below.
   Visual and obvious — there is nothing to read, choose or filter. */

#screen-library .lib-sechead {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  max-width: 1200px;
  margin: var(--sp-5) auto var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-pill);
  background: var(--c-bg-2);
}
#screen-library .lib-sechead__title {
  margin: 0;
  flex: 1 1 auto;
  font-size: var(--fs-big);
  font-weight: 700;
}
#screen-library .lib-sechead--new {
  background: linear-gradient(90deg, #FFE9F1, #FFF3D8);
  box-shadow: inset 0 0 0 3px rgba(255, 93, 143, .28);
}
#screen-library .lib-sechead--loved {
  background: linear-gradient(90deg, #FFF3D8, #FFF6E9);
  box-shadow: inset 0 0 0 3px rgba(245, 179, 60, .28);
}

/* ---- grid ---------------------------------------------------------------
   Two columns at 320px, filling out to a comfortable 180px minimum above. */

#screen-library .lib-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-3);
  max-width: 1200px;
  margin: 0 auto var(--sp-5);
  align-items: start;
}
@media (min-width: 420px) {
  #screen-library .lib-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: var(--sp-4);
  }
}

/* ---- the card -----------------------------------------------------------
   The WHOLE card is the tap target. Nothing here is ever greyed out: a book
   she has read keeps every bit of its colour and gains a gold star strip. */

#screen-library .lib-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: var(--tap);
  padding: 0;
  border: none;
  border-radius: var(--r-lg);
  background: var(--c-surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  transition: transform var(--dur-fast) var(--ease-pop), box-shadow var(--dur-fast);
  animation: lib-card-in var(--dur) var(--ease-pop) both;
  animation-delay: var(--lib-delay, 0ms);
}
#screen-library .lib-card:active { transform: scale(.96); }
#screen-library .lib-card:focus-visible {
  outline: 4px solid var(--c-accent);
  outline-offset: 3px;
}
@keyframes lib-card-in {
  from { opacity: 0; transform: translateY(10px) scale(.96); }
}

/* New books are unmistakable: soft breathing glow + ribbon + first in order. */
#screen-library .lib-card.is-new {
  box-shadow: 0 0 0 3px var(--c-heart), 0 6px 18px rgba(255, 93, 143, .35);
  animation: lib-card-in var(--dur) var(--ease-pop) var(--lib-delay, 0ms) both,
             lib-glow 2.4s ease-in-out var(--lib-delay, 0ms) infinite;
}
@keyframes lib-glow {
  0%, 100% { box-shadow: 0 0 0 3px var(--c-heart), 0 6px 16px rgba(255, 93, 143, .28); }
  50%      { box-shadow: 0 0 0 5px var(--c-heart), 0 10px 30px rgba(255, 93, 143, .55); }
}

/* ---- the generated cover ------------------------------------------------
   Colour comes from --cov-h, which js/library.js derives deterministically
   from the book id's rank in the catalogue: the same book is always the same
   colour, and no two books in the catalogue share a hue. */

#screen-library .lib-cover {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: var(--sp-2);
  aspect-ratio: 3 / 4;
  padding: var(--sp-3) var(--sp-3) var(--sp-3) 26px;
  background-color: hsl(var(--cov-h), 66%, 66%);
  /* deliberately NOT overflow:hidden — a long title must be allowed to grow the
     cover past its 3:4 ideal rather than being clipped. The card clips instead. */
}

/* the spine — a darker band down the binding edge */
#screen-library .lib-cover__spine {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 16px;
  background:
    linear-gradient(90deg,
      hsl(var(--cov-h), 55%, 40%) 0 10px,
      hsl(var(--cov-h), 70%, 82%) 10px 12px,
      hsl(var(--cov-h), 55%, 46%) 12px 16px);
}

/* cover patterns — a second axis of difference, so two books with neighbouring
   hues still never read as "the same book" at a glance */
#screen-library .lib-cover--dots {
  background-image: radial-gradient(circle at 7px 7px, rgba(255, 255, 255, .45) 3px, transparent 3.5px);
  background-size: 22px 22px;
}
#screen-library .lib-cover--stripes {
  background-image: repeating-linear-gradient(135deg,
    rgba(255, 255, 255, .26) 0 10px, rgba(255, 255, 255, 0) 10px 24px);
}
#screen-library .lib-cover--waves {
  background-image: radial-gradient(circle at 50% 120%, rgba(255, 255, 255, .38) 14px, transparent 15px);
  background-size: 34px 18px;
}
#screen-library .lib-cover--rows {
  background-image: repeating-linear-gradient(0deg,
    rgba(255, 255, 255, .22) 0 6px, rgba(255, 255, 255, 0) 6px 26px);
}
#screen-library .lib-cover--confetti {
  background-image:
    radial-gradient(circle at 20% 25%, rgba(255, 255, 255, .5) 3px, transparent 3.5px),
    radial-gradient(circle at 70% 60%, rgba(255, 255, 255, .35) 5px, transparent 5.5px);
  background-size: 40px 40px, 56px 56px;
}

/* the emoji lifted from the book's own pages */
#screen-library .lib-cover__art {
  font-size: clamp(30px, 12vw, 46px);
  line-height: 1.1;
  letter-spacing: 2px;
  text-shadow: 0 2px 0 rgba(255, 255, 255, .5);
}

/* the title is the biggest thing on the card — she should be able to read
   her own shelf */
#screen-library .lib-cover__title {
  margin: 0 0 34px;                /* clears the reward + level chips below */
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, .92);
  color: var(--c-ink);
  font-size: clamp(20px, 5.6vw, var(--fs-big));
  font-weight: 700;
  line-height: 1.12;
  overflow-wrap: break-word;
  hyphens: none;
}

/* The reward badge — the number ALWAYS comes from G.state.bookReward(), so a
   re-read shows its real (smaller) value in exactly the same warm chip as a
   first read. Sits bottom-left, beside the level pip, so it can never collide
   with the NEW ribbon in the narrow two-column layout. */
#screen-library .lib-cover__reward {
  position: absolute;
  bottom: var(--sp-2);
  left: 22px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 4px var(--sp-2);
  border-radius: var(--r-pill);
  background: var(--c-surface);
  color: var(--c-heart);
  font-size: var(--fs-small);
  font-weight: 700;
  box-shadow: var(--shadow);
  white-space: nowrap;
}

#screen-library .lib-cover__ribbon {
  position: absolute;
  top: var(--sp-2);
  left: 22px;
  padding: 3px var(--sp-2);
  border-radius: var(--r-pill);
  background: var(--c-heart);
  color: #fff;
  font-size: var(--fs-small);
  font-weight: 700;
  letter-spacing: .5px;
  box-shadow: var(--shadow);
  animation: lib-ribbon 1.8s ease-in-out infinite;
}
@keyframes lib-ribbon {
  0%, 100% { transform: rotate(-4deg) scale(1); }
  50%      { transform: rotate(-4deg) scale(1.08); }
}

/* level: pips + numeral, plus a colour. Readable by her (how many dots) and
   by the adult next to her (the number). */
#screen-library .lib-cover__level {
  position: absolute;
  bottom: var(--sp-2);
  right: var(--sp-2);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px var(--sp-2);
  border-radius: var(--r-pill);
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  box-shadow: var(--shadow);
}
#screen-library .lib-card[data-level="1"] .lib-cover__level { background: var(--c-accent); }
#screen-library .lib-card[data-level="2"] .lib-cover__level { background: var(--c-stars); }
#screen-library .lib-cover__pips { letter-spacing: 1px; font-size: 11px; }
#screen-library .lib-cover__lvlnum { font-size: 14px; }

/* ---- the "loved" strip --------------------------------------------------
   A re-read is a win, not leftovers. Warm gold, gold stars, no grey anywhere.
   Re-reading an easy book is the point of the whole game. */

#screen-library .lib-card__loved {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-small);
  font-weight: 700;
  background: linear-gradient(90deg, #FFF0CE, #FFF8E7);
  color: #8A5F14;
  border-top: 2px solid rgba(245, 179, 60, .45);
}
#screen-library .lib-card.is-new .lib-card__loved {
  background: linear-gradient(90deg, #FFE4EE, #FFF1F5);
  color: #B5325F;
  border-top-color: rgba(255, 93, 143, .45);
}
#screen-library .lib-card__stars {
  font-size: 13px;
  letter-spacing: -1px;
  white-space: nowrap;
}
#screen-library .lib-card__lovedicon { font-size: 15px; }

/* ---- the footer: who gave it to her, and the 🔊 ------------------------- */

#screen-library .lib-card__foot {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  padding: var(--sp-2);
}
#screen-library .lib-card__from {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  min-width: 0;
  flex: 1 1 auto;
  color: var(--c-ink-soft);
  font-size: var(--fs-small);
}
#screen-library .lib-card__avatar {
  display: inline-flex;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
}
#screen-library .lib-card__avatar svg { width: 100%; height: 100%; display: block; }
#screen-library .lib-card__petemoji { font-size: 26px; flex: 0 0 auto; }
#screen-library .lib-card__fromtext {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* At the narrowest widths the "from" line drops under the avatar row rather
   than squeezing the 64px speak button below the tap floor. */
@media (max-width: 359px) {
  #screen-library .lib-card__fromtext { display: none; }
  #screen-library .lib-head { padding-right: 0; }
  #screen-library .lib-head__h1 { font-size: var(--fs-big); }
}

/* ---- empty state --------------------------------------------------------
   Should never happen (she starts with Pip's book) but it is warm, not blank,
   and it points straight at the shop. */

#screen-library .lib-empty {
  max-width: 520px;
  margin: var(--sp-6) auto;
  padding: var(--sp-6) var(--sp-4);
  border-radius: var(--r-lg);
  background: var(--c-surface);
  box-shadow: var(--shadow-lg);
  text-align: center;
}
#screen-library .lib-empty__icon {
  font-size: 76px;
  line-height: 1;
  animation: lib-empty-bob 2.6s ease-in-out infinite;
}
@keyframes lib-empty-bob {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50%      { transform: translateY(-8px) rotate(3deg); }
}
#screen-library .lib-empty__big {
  margin: var(--sp-4) 0 var(--sp-2);
  font-size: var(--fs-big);
  font-weight: 700;
}
#screen-library .lib-empty__small {
  margin: 0 0 var(--sp-5);
  color: var(--c-ink-soft);
  font-size: var(--fs-body);
}
