/* ============================================================
   BEATRICE'S READING CHALLENGE — Main Stylesheet
   ============================================================ */

/* ── Variables ──────────────────────────────────────────── */
:root {
  --cream:        #FDF8F0;
  --parchment:    #F4EAD5;
  --white:        #FFFFFF;
  --header-start: #110A2E;
  --header-end:   #1A3050;
  --gold:         #D4900A;
  --gold-light:   #F5C430;
  --purple:       #6B3FA0;
  --purple-soft:  #EDE4F8;
  --rose:         #C03060;
  --rose-soft:    #FCE8F0;
  --teal:         #1A7A8A;
  --teal-soft:    #E0F5F8;
  --green:        #2A7A4A;
  --green-soft:   #E2F5EA;
  --orange:       #D4600A;
  --orange-soft:  #FFF0E5;
  --star:         #FFB700;
  --text:         #1C1008;
  --text-mid:     #5C3820;
  --text-light:   #9B7860;
  --border:       #E0D0B8;
  --shadow-sm:    0 2px 8px rgba(28,16,8,0.10);
  --shadow-md:    0 4px 20px rgba(28,16,8,0.14);
  --shadow-lg:    0 8px 32px rgba(28,16,8,0.18);
  --radius:       12px;
  --radius-sm:    8px;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Nunito', system-ui, sans-serif;
  background: var(--cream);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Header ─────────────────────────────────────────────── */
header {
  background: linear-gradient(160deg, var(--header-start) 0%, #1E1050 45%, var(--header-end) 100%);
  color: #FFF;
  padding: 3.5rem 1.5rem 4rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.header-bg-stars {
  position: absolute; inset: 0;
  background-image:
    radial-gradient(circle, rgba(255,255,255,0.55) 1px, transparent 1px),
    radial-gradient(circle, rgba(255,255,255,0.35) 1px, transparent 1px),
    radial-gradient(circle, rgba(255,255,255,0.2) 1.5px, transparent 1.5px);
  background-size: 80px 80px, 130px 130px, 200px 200px;
  background-position: 0 0, 40px 40px, 100px 20px;
  pointer-events: none;
}

.header-content { position: relative; z-index: 1; }

.header-book {
  font-size: 4rem;
  display: block;
  margin-bottom: 0.5rem;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.4));
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-8px); }
}

header h1 {
  font-family: 'Coiny', Georgia, serif;
  font-size: clamp(1.9rem, 5vw, 3.2rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.15;
  color: #FFF;
  text-shadow: 0 2px 16px rgba(0,0,0,0.4);
  margin-bottom: 0.4rem;
}

.header-sub {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gold-light);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* ── Main layout ────────────────────────────────────────── */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
}

.section-title {
  font-family: 'Coiny', Georgia, serif;
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1.25rem;
}

/* ── Stats ──────────────────────────────────────────────── */
.stats-section {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-top: -2rem;
  position: relative;
  z-index: 10;
  padding-bottom: 3rem;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.4rem 1.2rem;
  text-align: center;
  box-shadow: var(--shadow-md);
  border-top: 4px solid transparent;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.stat-card.stat-books  { border-top-color: var(--orange); }
.stat-card.stat-reading { border-top-color: var(--green); }
.stat-card.stat-words  { border-top-color: var(--purple); }
.stat-card.stat-money  { border-top-color: var(--gold); }

.stat-icon {
  font-size: 2rem;
  display: block;
  margin-bottom: 0.3rem;
}

.stat-value {
  font-size: 2rem;
  font-weight: 900;
  line-height: 1.1;
  color: var(--text);
}

.stat-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-light);
  margin-top: 0.25rem;
}

/* ── Sponsors ───────────────────────────────────────────── */
.sponsors-section {
  padding-bottom: 3rem;
}

.sponsors-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
}

.sponsor-card {
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border: 1.5px solid transparent;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.sponsor-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.sponsor-card.memere {
  background: var(--purple-soft);
  border-color: #C4A0E8;
}
.sponsor-card.mum {
  background: var(--rose-soft);
  border-color: #E8A0C0;
}
.sponsor-card.grandpabob {
  background: var(--green-soft);
  border-color: #90D0B0;
}
.sponsor-card.dad {
  background: var(--teal-soft);
  border-color: #90D0E0;
}

.sponsor-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.sponsor-emoji { font-size: 1.6rem; }

.sponsor-name {
  font-family: 'Coiny', serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}

.sponsor-model {
  font-size: 0.85rem;
  color: var(--text-mid);
  line-height: 1.45;
}

.sponsor-model span { display: block; }

.sponsor-total {
  font-size: 2rem;
  font-weight: 900;
  margin-top: 0.25rem;
}

.sponsor-card.memere      .sponsor-total { color: var(--purple); }
.sponsor-card.mum         .sponsor-total { color: var(--rose); }
.sponsor-card.grandpabob  .sponsor-total { color: var(--green); }
.sponsor-card.dad         .sponsor-total { color: var(--teal); }

.sponsor-detail {
  font-size: 0.8rem;
  color: var(--text-light);
  font-weight: 600;
}

/* ── Books section ──────────────────────────────────────── */
.books-section { padding-bottom: 2rem; }

.books-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.books-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.filter-btns {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 0.4rem 1rem;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: var(--white);
  color: var(--text-mid);
  font-family: 'Nunito', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-btn:hover {
  border-color: var(--purple);
  color: var(--purple);
}

.filter-btn.active {
  background: var(--purple);
  border-color: var(--purple);
  color: #fff;
}

.group-btn {
  padding: 0.4rem 1rem;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: var(--white);
  color: var(--text-mid);
  font-family: 'Nunito', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.group-btn:hover {
  border-color: var(--green);
  color: var(--green);
}

.group-btn.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.sort-select {
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--white);
  font-family: 'Nunito', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-mid);
  cursor: pointer;
  outline: none;
}

.sort-select:focus {
  border-color: var(--purple);
}

.books-count {
  font-size: 0.85rem;
  color: var(--text-light);
  font-weight: 600;
  margin-bottom: 1.25rem;
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1.25rem;
}

/* ── Series groups ──────────────────────────────────────── */
.books-grid.grouped {
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

.series-group-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 0.6rem;
  border-bottom: 2px solid var(--border);
}

.series-group-name {
  font-family: 'Coiny', Georgia, serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

.series-group-count {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-light);
  background: var(--parchment);
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
}

.series-group-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1.25rem;
}

/* ── Book card ──────────────────────────────────────────── */
.book-card {
  background: var(--white);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1.5px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.book-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}

.book-card.status-to-read {
  opacity: 0.75;
}

/* Cover */
.book-cover-wrap {
  width: 100%;
  aspect-ratio: 2/3;
  max-height: 200px;
  overflow: hidden;
  position: relative;
  background: var(--parchment);
  flex-shrink: 0;
}

.book-cover-placeholder {
  position: absolute; inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  text-align: center;
}

.book-cover-placeholder .ph-initial {
  font-size: 2.5rem;
  font-weight: 900;
  color: rgba(255,255,255,0.9);
  font-family: 'Coiny', serif;
  line-height: 1;
  margin-bottom: 0.3rem;
  text-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.book-cover-placeholder .ph-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: rgba(255,255,255,0.9);
  line-height: 1.35;
  word-break: break-word;
  text-align: center;
}

/* Cover image (when custom coverUrl is set) */
.book-cover-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Body */
.book-body {
  padding: 0.75rem 0.85rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
}

.book-author {
  font-size: 0.78rem;
  color: var(--text-mid);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-card-stars {
  color: var(--star);
  font-size: 0.8rem;
  letter-spacing: -0.03em;
  line-height: 1;
}

/* ── Modal ──────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle, rgba(255,255,255,0.5) 1px, transparent 1px),
    radial-gradient(circle, rgba(255,255,255,0.3) 1px, transparent 1px),
    radial-gradient(circle, rgba(255,255,255,0.18) 1.5px, transparent 1.5px),
    linear-gradient(160deg, #110A2E 0%, #1E1050 45%, #1A3050 100%);
  background-size: 80px 80px, 130px 130px, 200px 200px, auto;
  background-position: 0 0, 40px 40px, 100px 20px, 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1.25rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--white);
  border-radius: var(--radius);
  max-width: 860px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  position: relative;
  display: flex;
  gap: 0;
  box-shadow: 0 24px 64px rgba(0,0,0,0.35);
  transform: translateY(24px) scale(0.98);
  transition: transform 0.22s ease;
}

.modal-backdrop.open .modal {
  transform: translateY(0) scale(1);
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: none;
  background: var(--parchment);
  color: var(--text-mid);
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: background 0.15s;
}

.modal-close:hover { background: var(--border); }

.modal-cover-col {
  width: 260px;
  flex-shrink: 0;
  position: relative;
  align-self: stretch;
  min-height: 540px;
  border-radius: var(--radius) 0 0 var(--radius);
  overflow: hidden;
  background: var(--white);
  border-right: 1.5px solid var(--border);
}

.modal-cover-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  text-align: center;
  gap: 0.5rem;
  /* background set via inline style in JS (placeholderColor) */
}

.modal-ph-initial {
  font-family: 'Coiny', serif;
  font-size: 4rem;
  font-weight: 700;
  color: rgba(255,255,255,0.9);
  line-height: 1;
  text-shadow: 0 2px 12px rgba(0,0,0,0.2);
}

.modal-ph-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: rgba(255,255,255,0.8);
  line-height: 1.35;
  word-break: break-word;
}

.modal-cover-img {
  position: absolute;
  inset: 20px;
  width: calc(100% - 40px);
  height: calc(100% - 40px);
  object-fit: contain;
  display: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  border-radius: 3px;
}

.modal-cover-img.loaded {
  display: block;
  opacity: 1;
}

.modal-details {
  flex: 1;
  padding: 2rem 2rem 2rem 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  min-width: 0;
}

.modal-title {
  font-family: 'Coiny', serif;
  font-size: 2.1rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
  padding-right: 1.5rem;
}

.modal-top-block {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.9rem;
}

.modal-top-block .modal-field {
  border-bottom: none;
  padding: 0;
}

.modal-author { font-size: 0.9rem; font-weight: 700; color: var(--text-mid); }

.modal-field {
  font-size: 0.95rem;
  color: var(--text);
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
  flex-wrap: wrap;
}

.modal-label {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-light);
  flex-shrink: 0;
  min-width: 5.5rem;
}

.modal-rating {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
}

.modal-rating-stars { color: var(--star); font-size: 0.95rem; letter-spacing: -0.03em; }
.modal-rating-num   { font-size: 0.95rem; font-weight: 900; color: var(--text); }
.modal-rating-denom { font-size: 0.85rem; color: var(--text-light); }

.modal-divider {
  border: none;
  border-top: 1.5px solid var(--border);
  margin: 0.25rem 0;
}

.modal-meta {
  font-size: 0.95rem;
  color: var(--text-mid);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.modal-meta > span {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
}

.modal-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
}

.modal-sponsor-tiles {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-top: auto;
  border-top: 2px solid var(--border);
  padding-top: 1.5rem;
}

.modal-sponsor-tile {
  flex: 1;
  min-width: 72px;
  padding: 0.85rem 0.75rem;
  border-radius: var(--radius-sm);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.modal-sponsor-tile-name {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.modal-sponsor-tile-amount {
  font-size: 1.4rem;
  font-weight: 900;
}

.modal-sponsor-tile--memere { background: var(--purple-soft); }
.modal-sponsor-tile--memere .modal-sponsor-tile-name   { color: var(--purple); }
.modal-sponsor-tile--memere .modal-sponsor-tile-amount { color: var(--purple); }

.modal-sponsor-tile--mum { background: var(--rose-soft); }
.modal-sponsor-tile--mum .modal-sponsor-tile-name   { color: var(--rose); }
.modal-sponsor-tile--mum .modal-sponsor-tile-amount { color: var(--rose); }

.modal-sponsor-tile--dad { background: var(--teal-soft); }
.modal-sponsor-tile--dad .modal-sponsor-tile-name   { color: var(--teal); }
.modal-sponsor-tile--dad .modal-sponsor-tile-amount { color: var(--teal); }

.modal-sponsor-tile--total {
  background: var(--parchment);
  border: 1.5px solid var(--border);
}
.modal-sponsor-tile--total .modal-sponsor-tile-name   { color: var(--text-light); }
.modal-sponsor-tile--total .modal-sponsor-tile-amount { color: var(--text); }

.modal-notes {
  font-size: 0.78rem;
  color: var(--text-light);
  font-style: italic;
}

@media (max-width: 520px) {
  .modal { flex-direction: column; }
  .modal-cover-col {
    width: 100%;
    height: 180px;
    border-radius: var(--radius) var(--radius) 0 0;
  }
  .modal-details { padding: 1.25rem; }
}

/* Badges */
.book-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.4rem;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.badge-finished  { background: var(--green-soft);  color: var(--green);  }
.badge-reading   { background: var(--orange-soft); color: var(--orange); }
.badge-to-read   { background: var(--parchment);   color: var(--text-light); }
.badge-new       { background: #E8F4FF;             color: #1A6FA8; }
.badge-reread    { background: #FFF0E8;             color: #C05000; }
.badge-mum       { background: var(--rose-soft);    color: var(--rose); }
.badge-format    { background: #F0F0F0;             color: #555; }

/* ── Loading / empty ────────────────────────────────────── */
.loading-msg {
  color: var(--text-light);
  font-style: italic;
  font-size: 0.9rem;
  padding: 2rem;
}

.no-books-msg {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem;
  color: var(--text-light);
  font-style: italic;
}

/* ── Footer ─────────────────────────────────────────────── */
footer {
  background: var(--header-start);
  color: rgba(255,255,255,0.7);
  text-align: center;
  padding: 2rem 1.5rem;
  font-size: 0.9rem;
}

footer p { margin-bottom: 0.5rem; }

.footer-admin-link {
  display: inline-block;
  margin-top: 0.5rem;
  color: var(--gold-light);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0.6;
  transition: opacity 0.15s;
}

.footer-admin-link:hover { opacity: 1; text-decoration: underline; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 900px) {
  .stats-section { grid-template-columns: repeat(2, 1fr); margin-top: 0; }
  .sponsors-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  header { padding: 2.5rem 1rem 3rem; }
  .stats-section { grid-template-columns: repeat(2, 1fr); gap: 0.75rem; padding: 1rem 0 2rem; }
  .stat-value { font-size: 1.5rem; }
  .books-header { flex-direction: column; }
  .books-controls { width: 100%; }
  .filter-btns { flex-wrap: wrap; }
  .books-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.75rem; }
}
