/* ==========================================================================
   RepoShelf — styles
   Books are pure CSS: a flex row of .book divs sitting on a wooden .plank.
   Visual data-mapping itself lives in app.js (inline width/height/color);
   this file owns the bookshelf realism: lighting, wear, gold, shelves.
   ========================================================================== */

:root {
  --wood-1: #8a5a33;
  --wood-2: #6b4423;
  --gold: #f5c542;
}

html { scrollbar-color: #8a5a33 #1c1410; }

body {
  background:
    radial-gradient(1200px 400px at 50% -80px, rgba(245, 197, 66, 0.08), transparent),
    repeating-linear-gradient(0deg, #241a13 0 3px, #201712 3px 6px),
    #201712;
  color: #f5ead6;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---------- generic cards / fields / buttons (on top of Tailwind) ---------- */
.card {
  background: rgba(38, 28, 20, 0.92);
  border: 1px solid rgba(245, 197, 66, 0.18);
  border-radius: 1rem;
  padding: 1.25rem 1.25rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.field {
  background: #17100b;
  border: 1px solid rgba(245, 197, 66, 0.25);
  color: #f5ead6;
  border-radius: 0.6rem;
  padding: 0.6rem 0.8rem;
  font-size: 0.9rem;
  width: 100%;
  outline: none;
}
.field:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(245, 197, 66, 0.15); }
.field::placeholder { color: rgba(245, 234, 214, 0.35); }

.btn-primary {
  background: linear-gradient(180deg, #f5c542, #d99a22);
  color: #241a10;
  font-weight: 800;
  border-radius: 0.6rem;
  padding: 0.6rem 1.1rem;
  font-size: 0.9rem;
  white-space: nowrap;
  box-shadow: 0 4px 0 #8a5f14, 0 8px 18px rgba(0,0,0,.4);
  transition: transform .08s ease, box-shadow .08s ease, filter .15s;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { transform: translateY(3px); box-shadow: 0 1px 0 #8a5f14; }

.btn-ghost {
  background: rgba(245, 197, 66, 0.08);
  border: 1px solid rgba(245, 197, 66, 0.3);
  color: #f5ead6;
  border-radius: 0.6rem;
  padding: 0.55rem 0.8rem;
  font-size: 0.8rem;
  white-space: nowrap;
  transition: background .15s;
}
.btn-ghost:hover { background: rgba(245, 197, 66, 0.18); }

.tab {
  font-size: 0.8rem; font-weight: 700;
  padding: 0.4rem 0.9rem; border-radius: 999px;
  border: 1px solid rgba(245,197,66,.25); color: rgba(245,234,214,.7);
}
.tab-active { background: rgba(245,197,66,.9); color: #241a10; border-color: transparent; }

.demo-btn {
  border: 1px solid rgba(245,197,66,.25); border-radius: 999px;
  padding: 0.1rem 0.6rem; color: #f5c542;
}
.demo-btn:hover { background: rgba(245,197,66,.15); }

.ctl { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.72rem; color: rgba(245,234,214,.6); }

.rate-badge {
  background: rgba(245,197,66,.12); border: 1px solid rgba(245,197,66,.3);
  border-radius: 999px; padding: 0.2rem 0.7rem; color: #f5c542; font-variant-numeric: tabular-nums;
}

.loader {
  width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid rgba(245,197,66,.2); border-top-color: var(--gold);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================ Bookshelf ============================ */
.shelf { user-select: none; }

/* Row of books: bottom-aligned like real books on a plank */
.books {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
  padding: 0 18px;
  min-height: 200px;
  flex-wrap: nowrap;
  overflow-x: auto;              /* very thick collections can scroll sideways */
  scrollbar-width: thin;
}

/* ---- individual book ---- */
.book {
  position: relative;
  border-radius: 4px 7px 7px 4px;
  cursor: pointer;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  /* spine highlight (light from the left) + cloth texture */
  box-shadow:
    inset 4px 0 6px rgba(255, 255, 255, 0.28),
    inset -3px 0 5px rgba(0, 0, 0, 0.45),
    2px 2px 0 rgba(0,0,0,.35);
  transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease;
}
.book::before { /* cloth grain */
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background-image: repeating-linear-gradient(0deg, rgba(255,255,255,.045) 0 1px, transparent 1px 3px);
}
.book:hover, .book:focus-visible {
  transform: translateY(-14px) scale(1.03);
  box-shadow:
    inset 4px 0 6px rgba(255,255,255,.3),
    inset -3px 0 5px rgba(0,0,0,.4),
    0 14px 24px rgba(0,0,0,.55),
    0 0 0 2px rgba(245,197,66,.7);
  z-index: 5;
  outline: none;
}
.book.dragging { opacity: .4; }
.book.drop-target { outline: 2px dashed var(--gold); outline-offset: 2px; }

/* spine text: stars + footer are fixed-size; the title flexes to fill leftovers
   (previously the title used max-height:62% and got flex-shrunk to ~4 chars) */
.book-stars { flex: 0 0 auto; text-align: center; color: var(--gold); line-height: 1.25; padding-top: 6px; min-height: 26px; }
.book-stars .star { text-shadow: 0 0 6px rgba(245,197,66,.9), 0 1px 0 #5c3f05; }
.book-band { height: 4px; margin: 3px 6px; border-radius: 2px;
  background: linear-gradient(90deg, #8a6a1c, #ffe9a3 50%, #8a6a1c); box-shadow: 0 1px 1px rgba(0,0,0,.5); }

.book-title {
  writing-mode: vertical-rl;
  font-weight: 800;
  color: rgba(255,255,255,.94);
  text-shadow: 0 1px 2px rgba(0,0,0,.7);
  letter-spacing: .02em;
  padding: 6px 0;
  margin: 0 auto;
  flex: 1 1 auto;              /* take all vertical space not used by stars/footer */
  min-height: 0;               /* allow shrinking inside the fixed-height book */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.78rem;
}
.book-foot { flex: 0 0 auto; overflow: hidden; } /* author + lang dot never shrink; title absorbs the squeeze */
.book-author {
  writing-mode: vertical-rl;
  font-size: 0.5rem;
  color: rgba(255,255,255,.65);
  margin: 0 auto;
  padding-bottom: 2px;
  max-height: 24%;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.book-langdot {
  width: 8px; height: 8px; border-radius: 999px; margin: 4px auto;
  background: rgba(255,255,255,.85); box-shadow: 0 0 0 2px rgba(0,0,0,.25);
}

/* Gold embossing tiers get progressively fancier borders */
.tier-2 { box-shadow: inset 4px 0 6px rgba(255,255,255,.28), inset -3px 0 5px rgba(0,0,0,.45),
  inset 0 0 0 1px rgba(245,197,66,.55), 2px 2px 0 rgba(0,0,0,.35); }
.tier-3, .tier-4 { box-shadow: inset 4px 0 6px rgba(255,255,255,.28), inset -3px 0 5px rgba(0,0,0,.45),
  inset 0 0 0 2px rgba(245,197,66,.85), 2px 2px 0 rgba(0,0,0,.35); }
.tier-4 .book-title { color: #ffe9a3; text-shadow: 0 0 8px rgba(245,197,66,.8), 0 1px 2px rgba(0,0,0,.8); }

/* ---- wear levels: older push date = more worn ----
   wear-0 crisp (<30d) · wear-1 light (<180d) · wear-2 worn (<365d) · wear-3 ancient */
.wear-1 { filter: saturate(.88) brightness(.97); }
.wear-2 { filter: saturate(.72) sepia(.28) brightness(.94); }
.wear-3 { filter: saturate(.55) sepia(.45) brightness(.86) contrast(.96); }

/* dog-ear fold on the top-right for stale books */
.wear-2::after, .wear-3::after {
  content: ""; position: absolute; top: 0; right: 0; width: 0; height: 0;
  border-style: solid;
  border-width: 0 18px 18px 0;
  border-color: transparent rgba(0,0,0,.45) transparent transparent;
}
.wear-2::before, .wear-3::before { /* keep grain above fold shading */ z-index: 0; }
.wear-3 { border-top: 3px dashed rgba(0,0,0,.35); } /* frayed top edge */

/* ---- wooden plank under each row ---- */
.plank {
  height: 22px; border-radius: 4px; margin: 0 4px;
  background: linear-gradient(180deg, var(--wood-1), var(--wood-2) 60%, #4a2d15);
  box-shadow: 0 10px 24px rgba(0,0,0,.6), inset 0 2px 2px rgba(255,255,255,.25);
  position: relative;
}
.plank::after { /* wood grain */
  content: ""; position: absolute; inset: 0; border-radius: 4px; opacity: .35;
  background-image: repeating-linear-gradient(90deg, rgba(0,0,0,.18) 0 2px, transparent 2px 14px);
}
.shelf-label {
  text-align: center; font-size: 0.68rem; letter-spacing: .2em;
  color: rgba(245,234,214,.35); text-transform: uppercase; margin-top: 6px;
}

/* ============================ Modal ============================ */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10,6,3,.75); backdrop-filter: blur(3px); }
.modal-panel {
  position: relative; width: 100%; max-width: 720px; max-height: 88vh; overflow: auto;
  background: #faf6ee; color: #292524; border-radius: 1rem; padding: 1.75rem;
  box-shadow: 0 30px 80px rgba(0,0,0,.7);
  animation: pop .18s ease-out;
}
@keyframes pop { from { transform: translateY(12px) scale(.98); opacity: 0; } }
.modal-close {
  position: absolute; top: .7rem; right: .7rem; width: 2rem; height: 2rem; border-radius: 999px;
  background: rgba(0,0,0,.06); font-weight: 800;
}
.modal-close:hover { background: rgba(0,0,0,.14); }
.modal-cover {
  width: 120px; min-height: 220px; border-radius: 6px 10px 10px 6px; flex: none;
  display: flex; align-items: center; justify-content: center;
  box-shadow: inset 6px 0 8px rgba(255,255,255,.3), inset -4px 0 6px rgba(0,0,0,.4), 6px 8px 20px rgba(0,0,0,.35);
}
.badge {
  font-size: .72rem; font-weight: 700; border-radius: 999px; padding: .15rem .65rem;
  background: #f5f5f4; border: 1px solid #e7e5e4; color: #44403c;
}
.badge-gold { background: #fef3c7; border-color: #f5c542; color: #92400e; }
.readme-box {
  margin-top: .5rem; background: #1c1917; color: #e7e5e4; border-radius: .6rem;
  padding: .8rem; font-size: .72rem; line-height: 1.5; max-height: 220px; overflow: auto;
  white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, monospace;
}

/* ============================ Responsive ============================ */
@media (max-width: 640px) {
  .books { justify-content: flex-start; padding: 0 8px; }
  .book-title { font-size: .68rem; }
  .card { padding: 1rem; }
}
