:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --surface: #ffffff;
  --sunken: #efeeeb;
  --text: #1a1a1a;
  --text-muted: #63666b;
  --border: #e4e4e0;
  --brand: #2456a6;
  --brand-dark: #163a78;
  --free: #1a7f37;
  --price: #b3261e;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-md: 0 4px 6px -1px rgba(16, 24, 40, .06), 0 12px 24px -8px rgba(16, 24, 40, .14);
  --shadow-lift: 0 10px 24px -8px rgba(16, 24, 40, .18);
  --ring: 0 0 0 3px rgba(36, 86, 166, .16);
  --max-width: 1200px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 4px; }

/* ── Shared primitives ───────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 600;
  white-space: nowrap;
}
.pill-free { background: #e7f5ec; color: #146c33; }
.pill-paid { background: #fdecea; color: #a3261e; }
.pill-unknown { background: var(--sunken); color: var(--text-muted); }
.pill-warn { background: #fef4e6; color: #8a5a12; }

/* ── Site header ─────────────────────────────────────────── */
.site-header {
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.site-header .inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.site-header img { height: 38px; width: auto; }

.site-header .tagline {
  font-size: .86rem;
  color: var(--text-muted);
  padding-left: 14px;
  border-left: 1px solid var(--border);
}

main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 28px 20px 8px;
}

/* ── Page heading ────────────────────────────────────────── */
.page-title {
  font-size: clamp(1.4rem, 3vw, 1.75rem);
  font-weight: 650;
  letter-spacing: -.022em;
  margin: 0 0 6px;
  line-height: 1.2;
}

.page-subtitle {
  color: var(--text-muted);
  margin: 0 0 24px;
  font-size: .92rem;
}

/* ── Book grid ───────────────────────────────────────────── */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
  gap: 18px;
}

.book-card {
  background: var(--surface);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  color: inherit;
  transition: transform .16s ease, box-shadow .16s ease;
}

a.book-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lift);
  text-decoration: none;
}
a.book-card:focus-visible { outline: none; box-shadow: var(--ring), var(--shadow-lift); }

.book-card img.cover {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  background: var(--sunken);
}

.book-card-body {
  padding: 11px 12px 13px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.book-card-title {
  font-size: .84rem;
  font-weight: 600;
  line-height: 1.32;
  letter-spacing: -.01em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-card-author {
  font-size: .765rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-card-foot {
  margin-top: auto;
  padding-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.genre-chip {
  font-size: .67rem;
  text-transform: uppercase;
  letter-spacing: .045em;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-card.is-unavailable { opacity: .72; }
.unavailable { font-size: .78rem; color: var(--text-muted); font-style: italic; }

/* ── Detail page ─────────────────────────────────────────── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 18px;
  font-size: .88rem;
  color: var(--text-muted);
}
.back-link:hover { color: var(--text); text-decoration: none; }

.book-detail {
  display: grid;
  grid-template-columns: 460px 1fr;
  gap: 40px;
  background: var(--surface);
  border-radius: 16px;
  padding: 30px;
  box-shadow: var(--shadow-sm);
}

.book-detail img.cover {
  width: 100%;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 90px;
}

.book-detail h1 {
  font-size: clamp(1.35rem, 2.6vw, 1.8rem);
  line-height: 1.22;
  letter-spacing: -.022em;
  margin: 0 0 8px;
}

.book-detail .by-author {
  color: var(--text-muted);
  font-size: 1rem;
  margin: 0 0 18px;
}

.detail-price {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.detail-price .pill { font-size: .88rem; padding: 6px 14px; }

.store-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin: 0 0 26px;
}

.store-buttons a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  border-radius: 9px;
  background: var(--brand);
  color: #fff;
  font-size: .9rem;
  font-weight: 550;
  box-shadow: var(--shadow-sm);
  transition: background .12s ease, transform .12s ease;
}
.store-buttons a:hover { background: var(--brand-dark); text-decoration: none; transform: translateY(-1px); }
.store-buttons a svg { opacity: .8; }

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  padding: 16px 0;
  border-top: 1px solid var(--border);
  font-size: .85rem;
  color: var(--text-muted);
}
.detail-meta strong { color: var(--text); font-weight: 600; }

.summary { padding-top: 6px; }
.summary h2 {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin: 0 0 10px;
}
.summary p {
  margin: 0;
  max-width: 68ch;
  line-height: 1.72;
  font-size: .95rem;
}

/* ── Social + footer ─────────────────────────────────────── */
.social-block {
  margin: 40px 0 0;
  padding: 24px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  text-align: center;
}
.social-block p { margin: 0 0 14px; font-size: .92rem; font-weight: 550; }
.social-links { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.social-links a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: .86rem;
  font-weight: 550;
  transition: background .12s ease, border-color .12s ease;
}
.social-links a:hover { background: var(--sunken); border-color: #d8d8d3; text-decoration: none; }

.site-footer {
  max-width: var(--max-width);
  margin: 40px auto 0;
  padding: 22px 20px 34px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: .84rem;
}

.admin-gear {
  display: inline-flex;
  align-items: center;
  color: var(--border);
  opacity: .8;
  transition: color .12s ease, opacity .12s ease;
}
.admin-gear:hover { color: var(--text-muted); opacity: 1; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 1040px) {
  .book-detail { grid-template-columns: 320px 1fr; gap: 30px; }
}

@media (max-width: 760px) {
  main { padding: 20px 14px 4px; }

  .site-header .inner { padding: 10px 14px; gap: 10px; }
  .site-header img { height: 32px; }
  .site-header .tagline { display: none; }

  .book-grid { grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 12px; }
  .book-card-body { padding: 9px 10px 11px; }

  .book-detail {
    grid-template-columns: 1fr;
    gap: 22px;
    padding: 18px;
    border-radius: 14px;
  }
  .book-detail img.cover { position: static; max-width: 320px; margin: 0 auto; }
  .store-buttons a { flex: 1 1 auto; justify-content: center; }
  .social-block { padding: 20px 16px; }
}
