/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #09060a;
  --bg-card:     #130c10;
  --bg-modal:    #0f0a0c;
  --gold:        #c9986a;
  --gold-light:  #e8c49a;
  --gold-dim:    rgba(201,152,106,.18);
  --wine:        #6a1520;
  --wine-hover:  #8a1d28;
  --text:        #f0e8e2;
  --text-muted:  #7a6a62;
  --text-mid:    #a89888;
  --radius-card: 8px;
  --radius-chip: 20px;
  --cover-ratio: 2 / 3;
  --transition:  .3s cubic-bezier(.23,1,.32,1);
}

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Particles ────────────────────────────────────────────── */
.particles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.particle {
  position: absolute;
  border-radius: 50%;
  background: var(--gold);
  opacity: 0;
  animation: float-up linear infinite;
}

@keyframes float-up {
  0%   { transform: translateY(110vh) translateX(0);   opacity: 0; }
  8%   { opacity: .55; }
  92%  { opacity: .12; }
  100% { transform: translateY(-40px) translateX(20px); opacity: 0; }
}

/* ── Header ───────────────────────────────────────────────── */
.header {
  position: relative;
  z-index: 10;
  padding: 1.5rem 1rem 1rem;
  border-bottom: .5px solid var(--gold-dim);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.brand-icon { font-size: 1.5rem; line-height: 1; flex-shrink: 0; }

.brand-name {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: clamp(1.1rem, 4vw, 1.4rem);
  font-weight: 600;
  font-style: italic;
  color: var(--gold-light);
  letter-spacing: .01em;
  line-height: 1.2;
}

.brand-sub {
  font-size: .7rem;
  color: var(--text-muted);
  letter-spacing: .1em;
  text-transform: uppercase;
  margin-top: .15rem;
}

/* ── Sticky controls ──────────────────────────────────────── */
.controls-sticky {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(9,6,10,.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: .5px solid var(--gold-dim);
  padding: .75rem 1rem;
}

.controls-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

/* Search */
.search-wrap {
  position: relative;
}

.search-icon {
  position: absolute;
  left: .75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: .6rem .75rem .6rem 2.2rem;
  background: rgba(255,255,255,.05);
  border: .5px solid var(--gold-dim);
  border-radius: var(--radius-chip);
  color: var(--text);
  font-size: .875rem;
  font-family: inherit;
  outline: none;
  transition: border-color .2s;
  -webkit-appearance: none;
  appearance: none;
}

.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { border-color: rgba(201,152,106,.45); }

/* Filters */
.filters {
  display: flex;
  gap: .4rem;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding-bottom: 2px; /* prevent clip */
}
.filters::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  padding: .3rem .85rem;
  border-radius: var(--radius-chip);
  font-size: .7rem;
  font-weight: 400;
  letter-spacing: .06em;
  border: .5px solid var(--gold-dim);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all .2s;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.chip:active { transform: scale(.96); }
.chip.active {
  background: var(--wine);
  border-color: rgba(138,29,40,.8);
  color: var(--gold-light);
}

/* ── Results bar ──────────────────────────────────────────── */
.results-bar {
  position: relative;
  z-index: 5;
  padding: .5rem 1rem .2rem;
}
.results-bar-inner {
  max-width: 1200px;
  margin: 0 auto;
}
.results-line {
  font-size: .7rem;
  color: var(--text-muted);
  letter-spacing: .08em;
  text-transform: uppercase;
}

/* ── Grid ─────────────────────────────────────────────────── */
.main {
  position: relative;
  z-index: 5;
  padding: .5rem 1rem 5rem;
}

.grid-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
}

/* Responsive column sizing */
@media (max-width: 380px) {
  .grid-inner { grid-template-columns: repeat(2, 1fr); gap: .75rem; }
}
@media (min-width: 600px) {
  .grid-inner { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
@media (min-width: 900px) {
  .grid-inner { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1.25rem; }
}
@media (min-width: 1200px) {
  .main { padding-inline: 2rem; }
  .controls-inner, .header-inner, .results-bar-inner { max-width: 1400px; }
  .grid-inner { max-width: 1400px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
}

/* ── Book card ────────────────────────────────────────────── */
.book-card {
  cursor: pointer;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.book-card:focus-visible .cover-wrap {
  box-shadow: 0 0 0 2px var(--gold);
}

.cover-wrap {
  position: relative;
  aspect-ratio: var(--cover-ratio);
  border-radius: var(--radius-card);
  overflow: hidden;
  border: .5px solid var(--gold-dim);
  background: var(--bg-card);
  transition: transform var(--transition), box-shadow var(--transition);
}

@media (hover: hover) {
  .book-card:hover .cover-wrap {
    transform: translateY(-6px) scale(1.02);
    box-shadow: 0 20px 40px rgba(0,0,0,.75), 0 0 20px rgba(180,50,60,.15);
  }
  .book-card:hover .cover-hover { opacity: 1; }
}

/* Cover image — hidden until loaded */
.cover-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
  display: none;
}

.cover-img.loaded { display: block; }



/* Skeleton shimmer */
.cover-skeleton {
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, #1a0e14 30%, #241420 50%, #1a0e14 70%);
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Hover overlay */
.cover-hover {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 35%, rgba(0,0,0,.9) 100%);
  opacity: 0;
  transition: opacity .25s;
  display: flex;
  align-items: flex-end;
  padding: .6rem;
}

.cover-hover-label {
  font-size: .65rem;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--gold-light);
  font-weight: 500;
  width: 100%;
  text-align: center;
}

/* Series badge */
.badge-series {
  position: absolute;
  top: .45rem;
  left: .45rem;
  z-index: 2;
  background: rgba(50,20,10,.85);
  color: var(--gold);
  font-size: .55rem;
  font-weight: 500;
  letter-spacing: .07em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 3px;
  max-width: 70%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Card info */
.book-info {
  padding: .5rem .1rem 0;
}

.book-title {
  font-family: 'Playfair Display', serif;
  font-size: .78rem;
  font-weight: 600;
  line-height: 1.32;
  color: var(--text);
  margin-bottom: .15rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-author {
  font-size: .65rem;
  color: var(--text-muted);
  letter-spacing: .03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Skeleton grid ────────────────────────────────────────── */
.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  max-width: 1200px;
  margin: 0 auto;
}

@media (max-width: 380px) { .skeleton-grid { grid-template-columns: repeat(2, 1fr); gap: .75rem; } }

.skel {
  aspect-ratio: var(--cover-ratio);
  border-radius: var(--radius-card);
  background: linear-gradient(110deg, #1a0e14 30%, #241420 50%, #1a0e14 70%);
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
}

/* ── Empty state ──────────────────────────────────────────── */
.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-icon { font-size: 2.5rem; margin-bottom: .75rem; }
.empty-txt  { font-size: .875rem; }

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(4,2,5,.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-end;        /* bottom-sheet on mobile */
  justify-content: center;
  padding: 0;
  animation: overlay-in .2s ease;
}

.modal-overlay[hidden] { display: none !important; }

@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-card {
  background: var(--bg-modal);
  border: .5px solid rgba(201,152,106,.22);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  position: relative;
  animation: sheet-up .28s cubic-bezier(.23,1,.32,1);
}

@keyframes sheet-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

/* On wider screens, center as a floating card */
@media (min-width: 600px) {
  .modal-overlay { align-items: center; padding: 1rem; }
  .modal-card {
    border-radius: 16px;
    max-height: 85dvh;
    animation: card-in .22s cubic-bezier(.23,1,.32,1);
  }
  @keyframes card-in {
    from { opacity: 0; transform: scale(.96) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
  }
}

.modal-close {
  position: absolute;
  top: .75rem;
  right: .75rem;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: rgba(255,255,255,.07);
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s;
}
.modal-close:hover { background: rgba(255,255,255,.12); color: var(--text); }

/* Cover inside modal */
.modal-cover-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  flex-shrink: 0;
  background: #0d080c;
  border-radius: 20px 20px 0 0;
}

@media (min-width: 600px) {
  .modal-cover-wrap { border-radius: 16px 16px 0 0; }
}

.modal-cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
  display: block;
}

.modal-cover-img.hidden { display: none; }

.modal-cover-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.5rem;
  background: linear-gradient(155deg, #160a10, #3a1020);
}

.modal-cover-fallback.hidden { display: none; }

/* Gradient over cover */
.modal-cover-wrap::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, transparent 30%, var(--bg-modal) 100%);
  pointer-events: none;
}

/* Info section */
.modal-info {
  padding: .25rem 1.25rem 1.5rem;
}

.modal-cat {
  font-size: .65rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: .4rem;
}

.modal-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.2rem;
  font-style: italic;
  color: var(--gold-light);
  line-height: 1.3;
  margin-bottom: .25rem;
}

.modal-author {
  font-size: .8rem;
  color: var(--text-mid);
  margin-bottom: .15rem;
}

.modal-series {
  font-size: .72rem;
  color: var(--text-muted);
  margin-bottom: .9rem;
}

.modal-series:empty { display: none; }

.modal-desc {
  font-size: .78rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 1rem;
}

.modal-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  width: 100%;
  padding: .8rem;
  background: var(--wine);
  border: .5px solid rgba(138,29,40,.8);
  border-radius: 10px;
  color: var(--gold-light);
  font-size: .875rem;
  font-weight: 500;
  letter-spacing: .04em;
  cursor: pointer;
  text-decoration: none;
  transition: background .2s;
  font-family: inherit;
  margin-bottom: .5rem;
  -webkit-tap-highlight-color: transparent;
}

.modal-cta:hover  { background: var(--wine-hover); }
.modal-cta:active { transform: scale(.98); }

.modal-cancel {
  display: block;
  width: 100%;
  padding: .55rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: .8rem;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: color .2s;
}
.modal-cancel:hover { color: var(--text); }

/* Safe area for notched phones */
.modal-info { padding-bottom: max(1.5rem, env(safe-area-inset-bottom)); }
