/* ── Tokens ─────────────────────────────────────────────────────── */
:root {
  --bg:       #ffffff;
  --bg-soft:  #f9f9f9;
  --border:   #e8e8e8;
  --text:     #111111;
  --muted:    #888888;
  --accent:   #1a6b7c;
  --accent-light: rgba(26,107,124,0.08);
  --radius:   8px;
  --max:      1080px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ─────────────────────────────────────────────────────── */
.site-header {
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
}

.header-inner {
  max-width: var(--max);
  margin: 0 auto;
  display: flex;
  align-items: center;
  height: 56px;
}

.logo { text-decoration: none; display: flex; align-items: center; gap: 0.5rem; }

.logo-icon {
  width: 28px;
  height: 28px;
  border: 1.5px solid var(--text);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.logo-icon svg { display: block; }

.logo-text { display: flex; flex-direction: column; line-height: 1.1; }

.logo-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.logo-sub {
  font-size: 0.6rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.header-tagline {
  margin-left: auto;
  font-size: 0.78rem;
  color: var(--muted);
}

/* ── Hero ───────────────────────────────────────────────────────── */
.hero {
  max-width: var(--max);
  margin: 0 auto;
  padding: 3.5rem 2rem 2rem;
}

.hero h1 {
  font-size: clamp(1.6rem, 3.5vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  text-wrap: balance;
  margin-bottom: 0.5rem;
}

.hero p {
  font-size: 0.95rem;
  color: var(--muted);
  text-wrap: pretty;
  max-width: 480px;
}

/* ── Tabs ───────────────────────────────────────────────────────── */
.tabs-nav {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 2rem;
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-top: 2rem;
}

.tab-btn {
  background: none;
  border: none;
  padding: 0.75rem 1.1rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  position: relative;
  transition: color 0.15s;
}

.tab-btn::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 0; right: 0;
  height: 2px;
  background: var(--text);
  transform: scaleX(0);
  transition: transform 0.2s;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--text); font-weight: 600; }
.tab-btn.active::after { transform: scaleX(1); }

/* ── Filters ────────────────────────────────────────────────────── */
.filters-section {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1.25rem 2rem;
  display: flex;
  flex-wrap: wrap;
  flex-direction: row;
  gap: 0.75rem;
  align-items: flex-end;
  border-bottom: 1px solid var(--border);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.filter-group label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.filter-group select {
  appearance: none;
  background: var(--bg-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23888' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 0.7rem center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
  min-width: 140px;
  transition: border-color 0.15s;
}

.filter-group select:focus {
  outline: none;
  border-color: var(--accent);
}

.format-checkboxes { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.format-checkbox {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  font-size: 0.83rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.38rem 0.75rem;
  transition: all 0.15s;
  user-select: none;
  background: var(--bg-soft);
}

.format-checkbox input { display: none; }

.format-checkbox:has(input:checked) {
  border-color: var(--text);
  color: var(--text);
  background: var(--bg);
  font-weight: 500;
}

.dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.dot-physical { background: #1a6b7c; }
.dot-ebook    { background: #6b4fa8; }
.dot-audio    { background: #b05c1a; }

.search-btn {
  background: var(--text);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0.56rem 1.5rem;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  white-space: nowrap;
  align-self: flex-end;
  letter-spacing: -0.01em;
}

.search-btn:hover { opacity: 0.82; }
.search-btn:active { opacity: 0.7; }
.search-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Results area ───────────────────────────────────────────────── */
.results-section {
  max-width: var(--max);
  margin: 0 auto;
  padding: 2rem;
}

.results-header {
  display: flex;
  align-items: center;
  margin-bottom: 1.5rem;
  min-height: 24px;
}

.results-count {
  font-size: 0.82rem;
  color: var(--muted);
}

/* ── States ─────────────────────────────────────────────────────── */
.state-container {
  text-align: center;
  padding: 5rem 2rem;
  color: var(--muted);
}

.state-icon { font-size: 2rem; margin-bottom: 0.75rem; display: block; }

.state-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.3rem;
}

.state-sub { font-size: 0.85rem; }

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 0.75rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Book cards grid ────────────────────────────────────────────── */
.books-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
}

.book-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  transition: border-color 0.15s, transform 0.15s;
}

.book-card:hover {
  border-color: #bbb;
  transform: translateY(-2px);
}

.book-cover-wrap {
  background: var(--bg-soft);
  height: 190px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.availability-badge {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  background: rgba(255,255,255,0.92);
  border-radius: 20px;
  padding: 0.22rem 0.55rem;
  font-size: 0.68rem;
  font-weight: 600;
  backdrop-filter: blur(4px);
}

.avail-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.avail-dot.available { background: #2e9e6b; }
.avail-dot.on-loan   { background: #aaa; }
.avail-text.available { color: #2e9e6b; }
.avail-text.on-loan   { color: #aaa; }

.book-cover-wrap { position: relative; }

.book-cover-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cover-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  color: #ccc;
  font-size: 0.72rem;
}

.cover-fallback svg { opacity: 0.3; }

.book-info {
  padding: 0.85rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.book-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  text-wrap: balance;
}

.book-author {
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.book-year {
  font-size: 0.7rem;
  color: #ccc;
  margin-left: auto;
}

.format-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: auto;
  margin-bottom: 0.65rem;
}

.format-badge {
  font-size: 0.63rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 3px;
  padding: 0.18rem 0.42rem;
  color: #fff;
}

.format-badge.physical  { background: #1a6b7c; }
.format-badge.ebook     { background: #6b4fa8; }
.format-badge.audiobook { background: #b05c1a; }

.view-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: calc(100% + 1.7rem);
  margin: 0 -0.85rem -0.85rem;
  padding: 0.55rem;
  font-size: 0.77rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  border-top: 1px solid var(--border);
  transition: background 0.15s, color 0.15s;
  background: transparent;
  margin-top: auto;
}

.view-link:hover {
  background: var(--accent);
  color: #fff;
}

/* ── Bestsellers ────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.section-source {
  font-size: 0.72rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.12rem 0.45rem;
}

.nyt-key-notice {
  background: #fffbeb;
  border: 1px solid #f0d060;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  color: #7a6200;
  margin-bottom: 1.25rem;
}

.bestseller-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 2rem;
}

.bestseller-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  display: flex;
  gap: 0.9rem;
  align-items: flex-start;
  transition: border-color 0.15s;
  background: var(--bg);
}

.bestseller-card:hover { border-color: #bbb; }

.bestseller-rank {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--border);
  min-width: 1.75rem;
  line-height: 1;
  padding-top: 0.1rem;
  font-variant-numeric: tabular-nums;
}

.bestseller-rank.top3 { color: var(--accent); }

.bestseller-cover {
  width: 44px;
  height: 62px;
  object-fit: cover;
  border-radius: 3px;
  flex-shrink: 0;
  background: var(--bg-soft);
  border: 1px solid var(--border);
}

.bestseller-info { flex: 1; min-width: 0; }

.bestseller-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.12rem;
  letter-spacing: -0.01em;
}

.bestseller-author {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.bestseller-desc {
  font-size: 0.78rem;
  color: #555;
  line-height: 1.45;
  margin-bottom: 0.45rem;
  text-wrap: pretty;
}

.bestseller-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.weeks-badge {
  font-size: 0.67rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.12rem 0.4rem;
}

.weeks-badge + .view-link {
  width: auto;
  margin: 0;
  padding: 0.12rem 0;
  font-size: 0.77rem;
  border: none;
  color: var(--accent);
  background: none;
  justify-content: flex-start;
}

.weeks-badge + .view-link:hover {
  background: none;
  color: var(--text);
}

/* ── BookTok ────────────────────────────────────────────────────── */
.booktok-sub {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
  text-wrap: pretty;
}

.booktok-updated {
  font-size: 0.75rem;
  color: #bbb;
  margin-bottom: 1.5rem;
}

.booktok-updated code {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.08rem 0.3rem;
  font-size: 0.72rem;
}

.booktok-tag {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent-light);
  background: var(--accent-light);
  border-radius: 3px;
  padding: 0.15rem 0.4rem;
  margin-bottom: 0.4rem;
}

.book-blurb {
  font-size: 0.77rem;
  color: var(--muted);
  line-height: 1.45;
  margin-bottom: 0.5rem;
  text-wrap: pretty;
}

/* ── Footer ─────────────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 2rem;
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 4rem;
}

.site-footer a { color: var(--muted); }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .books-grid { grid-template-columns: repeat(2, 1fr); }
  .header-tagline { display: none; }
}

@media (max-width: 560px) {
  .books-grid { grid-template-columns: 1fr; }
  .hero { padding: 2rem 1.25rem 1.5rem; }
  .filters-section { padding: 1.1rem 1.25rem; flex-direction: column; align-items: stretch; }
  .filter-group select { min-width: unset; }
  .search-btn { width: 100%; text-align: center; }
  .results-section { padding: 1.25rem; }
  .tabs-nav { padding: 0 1.25rem; }
}
