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

:root {
  --blue:       #1e40af;
  --blue-light: #3b82f6;
  --blue-bg:    #eff6ff;
  --green:      #15803d;
  --green-bg:   #f0fdf4;
  --amber:      #b45309;
  --amber-bg:   #fffbeb;
  --purple:     #7c3aed;
  --purple-bg:  #f5f3ff;
  --red:        #dc2626;
  --gray-50:    #f9fafb;
  --gray-100:   #f3f4f6;
  --gray-200:   #e5e7eb;
  --gray-400:   #9ca3af;
  --gray-600:   #4b5563;
  --gray-800:   #1f2937;
  --radius:     12px;
  --shadow:     0 2px 12px rgba(0,0,0,.08);
  --bottom-nav: 64px;
}

/* ── Dark mode overrides ─────────────────────────────────────────────────── */
[data-theme="dark"] {
  --blue:       #60a5fa;
  --blue-light: #93c5fd;
  --blue-bg:    #1e3a5f;
  --green:      #4ade80;
  --green-bg:   #14532d;
  --amber:      #fbbf24;
  --amber-bg:   #451a03;
  --purple:     #a78bfa;
  --purple-bg:  #2e1065;
  --red:        #f87171;
  --gray-50:    #0f172a;
  --gray-100:   #1e293b;
  --gray-200:   #334155;
  --gray-400:   #94a3b8;
  --gray-600:   #cbd5e1;
  --gray-800:   #f1f5f9;
  --shadow:     0 2px 12px rgba(0,0,0,.4);
}
[data-theme="dark"] body              { background: #0f172a; color: #f1f5f9; }
[data-theme="dark"] .top-bar         { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .bottom-nav      { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .book-card       { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .modal-overlay   { background: rgba(0,0,0,.7); }
[data-theme="dark"] .profile-sheet,
[data-theme="dark"] .detail-sheet,
[data-theme="dark"] .scanner-sheet,
[data-theme="dark"] .import-sheet    { background: #1e293b; }
[data-theme="dark"] .sort-bar        { background: #0f172a; border-color: #334155; }
[data-theme="dark"] .sort-btn        { background: #1e293b; border-color: #334155; color: #cbd5e1; }
[data-theme="dark"] .sort-btn-active { background: #1e3a5f; border-color: #60a5fa; color: #60a5fa; }
[data-theme="dark"] .search-bar      { background: #1e293b; border-color: #334155; color: #f1f5f9; }
[data-theme="dark"] .search-bar input { background: #1e293b; border-color: #334155; color: #f1f5f9; }
[data-theme="dark"] .search-bar input::placeholder { color: #64748b; }
[data-theme="dark"] .search-bar::placeholder { color: #64748b; }
[data-theme="dark"] .note-textarea,
[data-theme="dark"] .progress-input  { background: #0f172a; border-color: #334155; color: #f1f5f9; }
[data-theme="dark"] .recent-card     { background: #1e293b; }
[data-theme="dark"] .cover-grid-item { background: #1e293b; }
[data-theme="dark"] .tab-btn         { color: #94a3b8; }
[data-theme="dark"] .tab-btn.active  { color: #60a5fa; }
[data-theme="dark"] .view-toggle-btn { background: #1e293b; border-color: #334155; color: #94a3b8; }
[data-theme="dark"] .view-toggle-btn.view-toggle-active { background: #1e3a5f; border-color: #60a5fa; color: #60a5fa; }
[data-theme="dark"] .detail-section  { border-color: #334155; }
[data-theme="dark"] .book-note       { background: #0f172a; border-color: #334155; }
[data-theme="dark"] .progress-bar-track { background: #334155; }
[data-theme="dark"] input, [data-theme="dark"] textarea { color-scheme: dark; }
[data-theme="dark"] .detail-move-btn    { background: #1e293b; border-color: #334155; color: #cbd5e1; }
[data-theme="dark"] .detail-move-btn:hover { background: #334155; }
[data-theme="dark"] .detail-remove-btn  { border-color: #7f1d1d; color: #f87171; }
[data-theme="dark"] .detail-actions     { border-color: #334155; }
[data-theme="dark"] .family-member      { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .sort-dropdown      { background: #1e293b; border-color: #334155; color: #f1f5f9; }
[data-theme="dark"] .search-hero .search-bar button { background: #1e293b; }
[data-theme="dark"] .toast              { background: #1e293b; color: #f1f5f9; }
[data-theme="dark"] .my-code-card       { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .carousel-title,
[data-theme="dark"] .carousel-author    { color: #cbd5e1; }
[data-theme="dark"] .cover-grid-rating  { color: #94a3b8; }
[data-theme="dark"] .book-title         { color: #f1f5f9; }
[data-theme="dark"] .book-author        { color: #94a3b8; }
[data-theme="dark"] .book-desc          { color: #94a3b8; }
@media (min-width: 768px) {
  [data-theme="dark"] .app-page { background: #1e293b; }
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

/* ── Auth page ───────────────────────────────────────────────────────────── */
.auth-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
}

.auth-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  padding: 2rem 1.5rem;
  width: 100%;
  max-width: 400px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 1.5rem;
}
.auth-logo h1 {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--blue);
  letter-spacing: -0.03em;
}
.auth-logo p {
  color: var(--gray-400);
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--gray-100);
  border-radius: 8px;
  padding: 3px;
  margin-bottom: 1.5rem;
}
.auth-tab {
  padding: 0.5rem;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--gray-600);
  cursor: pointer;
  border-radius: 6px;
  border: none;
  background: none;
  transition: all .15s;
}
.auth-tab.active {
  background: #fff;
  color: var(--blue);
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
}

.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.form-group input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: 1rem;
  color: var(--gray-800);
  outline: none;
  transition: border-color .15s;
  background: #fff;
}
.form-group input:focus { border-color: var(--blue-light); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
}
.btn-primary {
  background: var(--blue);
  color: #fff;
  width: 100%;
}
.btn-primary:hover { background: #1e3a8a; }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.btn-ghost {
  background: none;
  color: var(--gray-600);
  padding: 0.5rem;
}
.btn-ghost:hover { color: var(--gray-800); }

.error-msg {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: var(--red);
  font-size: 0.875rem;
  padding: 0.6rem 0.875rem;
  margin-bottom: 1rem;
  display: none;
}
.error-msg.show { display: block; }

/* ── App shell ───────────────────────────────────────────────────────────── */
.app-page { padding-bottom: var(--bottom-nav); min-height: 100dvh; }

.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.top-bar-logo {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--gray-800);
  flex: 1;
  letter-spacing: -0.01em;
}
[data-theme="dark"] .top-bar-logo { color: #f1f5f9; }
.dark-toggle {
  background: none;
  border: none;
  padding: 6px;
  cursor: pointer;
  color: var(--gray-600);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}
.dark-toggle:hover { background: var(--gray-100); }
[data-theme="dark"] .dark-toggle { color: var(--gray-400); }
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Bottom nav ──────────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: #fff;
  border-top: 1px solid var(--gray-200);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  height: var(--bottom-nav);
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  cursor: pointer;
  padding: 0.5rem 0;
  color: var(--gray-400);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: color .15s;
}
.nav-item svg { width: 22px; height: 22px; flex-shrink: 0; }
.nav-item.active { color: var(--blue); }

/* ── Search hero banner ──────────────────────────────────────────────────── */
.search-hero {
  background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
  padding: 1.75rem 1.25rem 1.5rem;
  border-bottom: none;
}
.search-hero-title {
  color: #fff;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 0.25rem;
}
.search-hero-sub {
  color: rgba(255,255,255,.75);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}
.search-hero .search-bar input {
  border: none;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.search-hero .search-bar input:focus { border-color: transparent; outline: 2px solid rgba(255,255,255,.5); }
.search-hero .search-bar button {
  background: #fff;
  color: var(--blue);
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.search-hero .search-bar button:hover { background: #f0f9ff; }

/* ── Search bar (standalone) ─────────────────────────────────────────────── */
.search-bar {
  display: flex;
  gap: 0.5rem;
}
.search-bar input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--gray-200);
  border-radius: 10px;
  font-size: 1rem;
  outline: none;
  transition: border-color .15s;
  background: #fff;
}
.search-bar input:focus { border-color: var(--blue-light); }
.search-bar button {
  padding: 0.75rem 1.1rem;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  flex-shrink: 0;
  transition: background .15s;
}
.search-bar button:hover { background: #1e3a8a; }

/* ── List hero banners ───────────────────────────────────────────────────── */
.list-hero {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.4rem 1.25rem 1.2rem;
  margin-bottom: 0;
  border-bottom: none;
  position: relative;
  overflow: hidden;
}
.list-hero::after {
  content: '';
  position: absolute;
  top: -30px; right: -30px;
  width: 120px; height: 120px;
  border-radius: 50%;
  background: rgba(255,255,255,.07);
  pointer-events: none;
}
.list-hero-blue   { background: linear-gradient(135deg,#1e3a8a 0%,#2563eb 100%); }
.list-hero-amber  { background: linear-gradient(135deg,#78350f 0%,#d97706 100%); }
.list-hero-green  { background: linear-gradient(135deg,#14532d 0%,#16a34a 100%); }
.list-hero-icon   {
  width: 48px; height: 48px;
  border-radius: 14px;
  background: rgba(255,255,255,.15);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.list-hero > div  { flex: 1; }
.list-hero-title  {
  font-family: 'Playfair Display', Georgia, serif;
  color: #fff;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.list-hero-sub    { color: rgba(255,255,255,.7); font-size: 0.78rem; margin-top: 3px; font-weight: 400; }
.list-hero .count-badge {
  background: rgba(255,255,255,.2);
  color: #fff;
  font-size: 0.9rem;
  padding: 0.3rem 0.8rem;
}

.view { display: none; }
.view.active { display: block; }
.view > .results-grid,
.view > div > .results-grid { padding: 1rem; }

.results-grid {
  display: grid;
  gap: 0.75rem;
}

/* ── Book card ───────────────────────────────────────────────────────────── */
.book-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 0.875rem;
  padding: 0.875rem;
  position: relative;
}
.book-cover {
  width: 80px;
  height: 110px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--gray-100);
  flex-shrink: 0;
}
.book-cover-placeholder {
  width: 80px;
  height: 110px;
  border-radius: 6px;
  background: var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-400);
  flex-shrink: 0;
}
.book-info { min-width: 0; }
.book-title {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.3;
  margin-bottom: 0.25rem;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.book-author {
  font-size: 0.8rem;
  color: var(--gray-600);
  margin-bottom: 0.3rem;
}
.book-desc {
  font-size: 0.78rem;
  color: var(--gray-600);
  line-height: 1.45;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  margin-bottom: 0.6rem;
}
.book-year {
  font-size: 0.72rem;
  color: var(--gray-400);
  margin-bottom: 0.6rem;
}

/* Add-to-list button */
.add-btn-wrap { position: relative; }
.add-btn {
  background: var(--blue-bg);
  color: var(--blue);
  border: none;
  border-radius: 7px;
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: background .15s;
}
.add-btn:hover { background: #dbeafe; }

.dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  z-index: 200;
  min-width: 170px;
  overflow: hidden;
  display: none;
}
.dropdown.open { display: block; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  color: var(--gray-800);
  transition: background .1s;
}
.dropdown-item:hover { background: var(--gray-50); }
.dropdown-item .dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-to-read   { background: var(--blue); }
.dot-purchased { background: var(--amber); }
.dot-read      { background: var(--green); }

/* ── List badges on cards ────────────────────────────────────────────────── */
.list-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}
.badge-to-read   { background: var(--blue-bg);   color: var(--blue); }
.badge-purchased { background: var(--amber-bg);  color: var(--amber); }
.badge-read      { background: var(--green-bg);  color: var(--green); }

.remove-btn {
  background: #fef2f2;
  color: var(--red);
  border: none;
  border-radius: 7px;
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}
.remove-btn:hover { background: #fee2e2; }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--gray-400);
}
.empty-state svg { width: 56px; height: 56px; margin-bottom: 1rem; opacity: .4; }
.empty-state h3 { font-size: 1rem; color: var(--gray-600); margin-bottom: 0.4rem; }
.empty-state p  { font-size: 0.875rem; }

/* ── List header ─────────────────────────────────────────────────────────── */
.list-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.list-header h2 {
  font-size: 1.1rem;
  font-weight: 800;
  flex: 1;
}
.count-badge {
  background: var(--gray-100);
  color: var(--gray-600);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
}

/* ── Toast notification ──────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--bottom-nav) + 0.75rem);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--gray-800);
  color: #fff;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  opacity: 0;
  transition: all .25s;
  white-space: nowrap;
  z-index: 500;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
#toast-undo {
  background: none;
  border: 1.5px solid rgba(255,255,255,.6);
  color: #fff;
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

/* ── Reading progress ─────────────────────────────────────────────────────── */
.progress-section { margin: 0.4rem 0 0.2rem; }
.progress-bar-track {
  height: 6px;
  background: var(--gray-100);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.25rem;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #f59e0b, #d97706);
  border-radius: 999px;
  transition: width .4s ease;
}
.progress-label {
  font-size: 0.72rem;
  color: var(--gray-500);
  margin-bottom: 0.3rem;
}
.progress-toggle-btn {
  background: none;
  border: none;
  color: #d97706;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}
.progress-editor { margin-top: 0.4rem; }
.progress-inputs {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}
.progress-input {
  width: 5rem;
  padding: 0.3rem 0.4rem;
  border: 1.5px solid var(--gray-200);
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: inherit;
}
.progress-sep { font-size: 0.8rem; color: var(--gray-400); }
.progress-save-btn {
  padding: 0.3rem 0.75rem;
  background: #d97706;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

/* ── Recently added ───────────────────────────────────────────────────────── */
.section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gray-400);
  margin-bottom: 0.6rem;
}
.recent-scroll {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.recent-scroll::-webkit-scrollbar { display: none; }
.recent-card {
  flex-shrink: 0;
  width: 80px;
  cursor: pointer;
  text-align: center;
}
.recent-cover {
  width: 80px;
  height: 110px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
  background: var(--gray-100);
}
.recent-cover-ph {
  width: 80px;
  height: 110px;
  border-radius: 6px;
  background: var(--gray-100);
}
.recent-title {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--gray-700);
  margin: 0.3rem 0 0.2rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}

/* ── View toggle ─────────────────────────────────────────────────────────── */
.view-toggle-wrap {
  display: flex;
  gap: 2px;
  margin-left: auto;
  background: var(--gray-100);
  border-radius: 6px;
  padding: 2px;
}
.view-toggle-btn {
  background: none;
  border: none;
  border-radius: 4px;
  padding: 0.25rem 0.35rem;
  cursor: pointer;
  color: var(--gray-400);
  display: flex;
  align-items: center;
  transition: background .15s, color .15s;
}
.view-toggle-btn.view-toggle-active {
  background: #fff;
  color: var(--gray-700);
  box-shadow: 0 1px 3px rgba(0,0,0,.1);
}

/* ── Cover grid ──────────────────────────────────────────────────────────── */
.cover-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.55rem;
  padding: 0.75rem 1rem 1.5rem;
}
@media (min-width: 480px) {
  .cover-grid { grid-template-columns: repeat(4, 1fr); }
}
.cover-grid-item {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 2/3;
  background: var(--gray-100);
  box-shadow: 0 2px 8px rgba(0,0,0,.18), 2px 2px 0 rgba(0,0,0,.08);
  transition: transform .15s, box-shadow .15s;
}
.cover-grid-item:active { transform: scale(0.96); box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.cover-grid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.cover-grid-ph {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-300);
}
.cover-grid-rating {
  position: absolute;
  bottom: 3px;
  right: 4px;
  font-size: 0.65rem;
  color: #f59e0b;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
  line-height: 1;
}
.cover-grid-progress-track {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255,255,255,.25);
}
.cover-grid-progress {
  height: 100%;
  background: #f59e0b;
}

/* ── Bookshelf spine view ────────────────────────────────────────────────── */
.cover-carousel {
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  align-items: flex-end;
  gap: 3px;
  padding: 2rem 1rem 0;
  /* wooden shelf */
  background:
    linear-gradient(to bottom, transparent calc(100% - 14px), #a07850 calc(100% - 14px), #7a5c38 100%);
  min-height: 260px;
}
.cover-carousel::-webkit-scrollbar { display: none; }
.cover-carousel { scrollbar-width: none; }

.cover-carousel-item {
  flex: 0 0 42px;
  min-width: 42px;
  cursor: pointer;
  transition: transform .18s ease;
}
.cover-carousel-item:hover,
.cover-carousel-item:active { transform: translateY(-10px); }

.carousel-spine {
  width: 100%;
  height: 100%;
  border-radius: 2px 4px 4px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 5px;
  overflow: hidden;
  gap: 6px;
  box-shadow:
    2px 0 6px rgba(0,0,0,.4),
    inset -3px 0 8px rgba(0,0,0,.25),
    inset 2px 0 4px rgba(255,255,255,.12);
}
.carousel-spine-title {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-height: 75%;
  letter-spacing: 0.04em;
  line-height: 1;
}
.carousel-spine-author {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 0.6rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-height: 40%;
  letter-spacing: 0.02em;
  line-height: 1;
}

/* ── Book detail sheet ───────────────────────────────────────────────────── */
.detail-sheet {
  background: #fff;
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.25rem 1.1rem 2.5rem;
  position: relative;
}
.detail-cover-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.1rem;
}
.detail-cover {
  width: 90px;
  height: 130px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}
.detail-cover-ph {
  width: 90px;
  height: 130px;
  background: var(--gray-100);
  border-radius: 8px;
  flex-shrink: 0;
}
.detail-meta { flex: 1; padding-top: 0.1rem; }
.detail-title {
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.3;
  color: var(--gray-900);
  margin: 0.3rem 0 0.2rem;
}
.detail-author { font-size: 0.82rem; color: var(--gray-500); margin-bottom: 0.2rem; }
.detail-year   { font-size: 0.75rem; color: var(--gray-400); }
.detail-finished { font-size: 0.75rem; color: var(--green); margin-top: 0.2rem; font-weight: 600; }
.detail-section { border-top: 1px solid var(--gray-100); padding-top: 0.75rem; margin-top: 0.75rem; }
.detail-section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gray-400);
  margin-bottom: 0.5rem;
}
.detail-desc {
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--gray-700);
}
.detail-stars-row { display: flex; gap: 0.3rem; }
.detail-star { font-size: 1.5rem; cursor: pointer; color: var(--gray-300); transition: color .15s; }
.detail-star.star-filled { color: #f59e0b; }
.detail-progress-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}
.detail-actions {
  border-top: 1px solid var(--gray-100);
  padding-top: 0.75rem;
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.detail-move-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--gray-50);
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  color: var(--gray-700);
}
.detail-remove-btn {
  background: none;
  border: 1.5px solid #fecaca;
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  color: var(--red);
}
.detail-tap { cursor: pointer; }
.detail-tap:hover { text-decoration: underline; }

/* ── Profile menu ────────────────────────────────────────────────────────── */
.profile-menu {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 300;
  display: none;
}
.profile-menu.open { display: block; }
.profile-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.3);
}
.profile-sheet {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.5rem 1.25rem;
  box-shadow: 0 -4px 20px rgba(0,0,0,.1);
}
/* ── Profile header / avatar ─────────────────────────────────────────────── */
.profile-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--gray-200);
  margin-bottom: 1rem;
}
.profile-avatar-wrap {
  position: relative;
  margin-bottom: 0.75rem;
}
.profile-avatar-large {
  width: 80px; height: 80px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 2rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,.15);
  transition: opacity .2s;
}
.profile-avatar-edit-btn {
  position: absolute;
  bottom: 2px; right: 2px;
  width: 22px; height: 22px;
  background: var(--gray-800);
  color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
[data-theme="dark"] .profile-avatar-edit-btn { background: #475569; }
.profile-code-section {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
}
.profile-section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--gray-400);
  margin-bottom: 0.4rem;
}
[data-theme="dark"] .profile-code-section { background: #0f172a; border-color: #334155; }
.profile-name {
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 0.2rem;
}
.profile-name-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.2rem;
}
.profile-name-input {
  font-weight: 700;
  font-size: 1.1rem;
  border: none;
  border-bottom: 1.5px solid transparent;
  background: transparent;
  color: var(--gray-800);
  padding: 0.1rem 0;
  flex: 1;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
.profile-name-input:focus { border-bottom-color: var(--blue); }
.profile-name-save {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--blue);
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  opacity: 0.6;
  transition: opacity .15s;
}
.profile-name-save:hover { opacity: 1; }
[data-theme="dark"] .profile-name-input { color: #f1f5f9; }
.profile-email {
  font-size: 0.85rem;
  color: var(--gray-400);
  margin-bottom: 1.25rem;
}
.profile-actions { display: flex; flex-direction: column; gap: 0.5rem; }
.btn-logout {
  width: 100%;
  padding: 0.75rem;
  background: #fef2f2;
  color: var(--red);
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-logout:hover { background: #fee2e2; }

/* ── Loading spinner ─────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2.5px solid var(--gray-200);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 2rem;
  color: var(--gray-400);
  font-size: 0.875rem;
}

/* ── Sort bar ────────────────────────────────────────────────────────────── */
.sort-bar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 1rem 0;
  flex-wrap: wrap;
}
.sort-label {
  font-size: 0.75rem;
  color: var(--gray-400);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 0.1rem;
}
.sort-btn {
  padding: 0.2rem 0.55rem;
  border: 1.5px solid var(--gray-200);
  border-radius: 999px;
  background: #fff;
  color: var(--gray-500);
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
}
.sort-btn:hover { border-color: #1e40af; color: #1e40af; }
.sort-btn-active { background: #eff6ff; border-color: #1e40af; color: #1e40af; font-weight: 600; }

/* ── Stars ───────────────────────────────────────────────────────────────── */
.star-row {
  display: flex;
  gap: 1px;
  margin: 0.35rem 0 0.1rem;
}
.star {
  font-size: 1.1rem;
  color: var(--gray-200);
  cursor: pointer;
  line-height: 1;
  transition: color .1s;
  user-select: none;
}
.star:hover,
.star-row:hover .star { color: #f59e0b; }
.star-row .star:hover ~ .star { color: var(--gray-200); }
.star.star-filled { color: #f59e0b; }

/* ── Notes ───────────────────────────────────────────────────────────────── */
.book-note {
  font-size: 0.78rem;
  color: var(--gray-500);
  background: var(--gray-50);
  border-left: 3px solid var(--gray-200);
  padding: 0.3rem 0.5rem;
  border-radius: 0 4px 4px 0;
  margin: 0.3rem 0 0.1rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.note-btn {
  background: none;
  border: none;
  color: #1e40af;
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0;
  margin: 0.1rem 0 0.2rem;
  font-family: inherit;
}
.note-btn:hover { text-decoration: underline; }
.note-editor {
  margin: 0.3rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.note-textarea {
  width: 100%;
  min-height: 70px;
  padding: 0.4rem 0.5rem;
  border: 1.5px solid var(--gray-200);
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: inherit;
  resize: vertical;
  outline: none;
}
.note-textarea:focus { border-color: #1e40af; }
.note-save-btn {
  align-self: flex-end;
  padding: 0.3rem 0.75rem;
  background: #1e40af;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
}
.note-save-btn:disabled { opacity: .6; }

/* ── Finished date ───────────────────────────────────────────────────────── */
.book-finished {
  font-size: 0.75rem;
  color: #16a34a;
  font-weight: 600;
  margin: 0.1rem 0;
}

/* ── List filter bar ─────────────────────────────────────────────────────── */
.list-filter-bar {
  padding: 0.6rem 1rem 0;
}
.list-filter-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  background: #fff;
  color: var(--gray-900);
  transition: border-color .15s;
}
.list-filter-input:focus { border-color: #1e40af; }

/* ── Import button in list hero ─────────────────────────────────────────── */
.import-hero-btn {
  background: rgba(255,255,255,.2);
  border: none;
  border-radius: 6px;
  padding: 0.3rem;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}
.import-hero-btn:hover { background: rgba(255,255,255,.35); }

/* ── Scan button in search bar ───────────────────────────────────────────── */
.scan-btn {
  background: rgba(255,255,255,.15);
  border: none;
  border-radius: 8px;
  padding: 0 0.6rem;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}
.scan-btn:hover { background: rgba(255,255,255,.3); }

/* ── Scanner modal ───────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 400;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
#recommend-modal { z-index: 500; }
.scanner-sheet {
  background: #fff;
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 480px;
  padding: 1.1rem 1.1rem 2rem;
}
.scanner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.scanner-title { font-size: 1rem; font-weight: 700; }
.scanner-close {
  background: var(--gray-100);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--gray-600);
}
.scanner-hint {
  font-size: 0.82rem;
  color: var(--gray-600);
  margin-bottom: 0.75rem;
  line-height: 1.5;
}
/* Camera view — html5-qrcode renders inside this div */
.scanner-preview {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
}
/* Contain everything html5-qrcode injects */
.scanner-preview > * { box-sizing: border-box; }
.scanner-preview video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
  display: block;
}
/* Hide text labels injected by the library */
#scanner-preview > span,
#scanner-preview > div > span,
#scanner-preview > div:last-child:not([id]) {
  display: none !important;
}
.scanner-status {
  margin-top: 0.6rem;
  font-size: 0.8rem;
  color: var(--gray-400);
  text-align: center;
}
/* Manual ISBN fallback */
.scanner-manual-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.scanner-isbn-input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  outline: none;
}
.scanner-isbn-input:focus { border-color: #1e40af; }
.manual-cover-label {
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  border: 2px dashed var(--gray-300); border-radius: 8px; padding: .75rem;
  cursor: pointer; color: var(--gray-500); font-size: .85rem; min-height: 56px;
}
.manual-cover-label:hover { border-color: var(--blue); color: var(--blue); }
[data-theme="dark"] .manual-cover-label { border-color: #334155; color: #94a3b8; }
.scanner-isbn-btn {
  padding: 0.6rem 1rem;
  background: #1e40af;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

/* ── Family view ─────────────────────────────────────────────────────────── */
.family-member {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 0.75rem;
  overflow: hidden;
}
.family-member-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem 0.6rem;
  border-bottom: 1px solid var(--gray-100);
}
.family-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5b21b6, #7c3aed);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.family-name  { font-size: 0.9rem; font-weight: 700; color: var(--gray-800); }
.family-count { font-size: 0.75rem; color: var(--gray-400); }
.family-books-row {
  display: flex;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.family-book {
  flex-shrink: 0;
  width: 72px;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.family-book-cover {
  width: 72px;
  height: 100px;
  object-fit: cover;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.family-book-no-cover {
  width: 72px;
  height: 100px;
  background: var(--gray-100);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-400);
}
.family-book-title {
  font-size: 0.65rem;
  color: var(--gray-600);
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.family-book-rating { font-size: 0.6rem; color: #f59e0b; }
.family-empty {
  padding: 0.75rem 1rem;
  font-size: 0.82rem;
  color: var(--gray-400);
  font-style: italic;
}

/* ── My share code card ──────────────────────────────────────────────────── */
.my-code-card {
  background: #f5f3ff;
  border-bottom: 1px solid #ede9fe;
  padding: 0.75rem 1rem;
}
.my-code-label {
  font-size: 0.72rem;
  color: #7c3aed;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.35rem;
}
.my-code-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.my-code-value {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: #4c1d95;
  font-family: monospace;
  flex: 1;
}
.my-code-copy {
  padding: 0.3rem 0.75rem;
  background: #7c3aed;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

/* ── Family code input ───────────────────────────────────────────────────── */
.family-code-input {
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
}

/* ── Disconnect button ───────────────────────────────────────────────────── */
.family-disconnect-btn {
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  padding: 0.2rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.family-disconnect-btn:hover { color: var(--red); background: #fef2f2; }

/* ── Detail utility row (Shop / Recommend) ───────────────────────────────── */
.detail-utility-row {
  display: flex;
  gap: 0.5rem;
  margin: 0.75rem 0;
}
.detail-util-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 0.5rem;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  background: var(--gray-50);
  color: var(--gray-600);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, border-color .15s;
}
.detail-util-btn:hover { background: var(--blue-bg); border-color: var(--blue); color: var(--blue); }
.detail-util-reading { background: var(--green-bg) !important; border-color: var(--green) !important; color: var(--green) !important; }
[data-theme="dark"] .detail-util-btn { background: #1e293b; border-color: #334155; color: #cbd5e1; }
[data-theme="dark"] .detail-util-btn:hover { background: #1e3a5f; border-color: #60a5fa; color: #60a5fa; }
[data-theme="dark"] .detail-util-reading { background: #14532d !important; border-color: #4ade80 !important; color: #4ade80 !important; }

/* ── Recommend modal ─────────────────────────────────────────────────────── */
.rec-book-info { margin-bottom: 0.75rem; }
.rec-book-row { display: flex; align-items: center; gap: 0.75rem; }
.rec-book-thumb { width: 48px; height: 68px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.rec-book-title { font-weight: 700; font-size: 0.9rem; color: var(--gray-800); }
.rec-book-author { font-size: 0.8rem; color: var(--gray-400); margin-top: 0.15rem; }
.rec-friends-list { display: flex; flex-direction: column; gap: 0.4rem; max-height: 180px; overflow-y: auto; }
.rec-friend-btn {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--gray-200); border-radius: 8px;
  background: none; cursor: pointer; font-size: 0.875rem; font-weight: 600;
  color: var(--gray-800); font-family: inherit; text-align: left;
  transition: background .12s, border-color .12s;
}
.rec-friend-btn:hover { background: var(--blue-bg); border-color: var(--blue-light); }
.rec-friend-btn.rec-friend-selected { background: var(--blue-bg); border-color: var(--blue); color: var(--blue); }
.rec-friend-avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--blue);
  color: #fff; font-size: 0.75rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
[data-theme="dark"] .rec-friend-btn { border-color: #334155; color: #f1f5f9; }

/* ── Recommendations section on Friends tab ──────────────────────────────── */
.rec-section { margin-bottom: 1rem; }
.rec-section-title { font-size: 0.875rem; font-weight: 700; color: var(--gray-800); padding: 0.25rem 0 0.5rem; }
.friends-section-title { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--gray-500); padding: 1rem 0 0.4rem; border-top: 1px solid var(--gray-200); margin-top: .25rem; }
.friends-section-title:first-child { border-top: none; margin-top: 0; }

/* ── Activity Feed ──────────────────────────────────────────────────────── */
.activity-section { margin-bottom: 0.75rem; }
.activity-item { display: flex; align-items: center; gap: 0.6rem; padding: 0.55rem 0; border-bottom: 1px solid var(--gray-100); }
.activity-item:last-child { border-bottom: none; }
.activity-avatar { width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg,#1e40af,#3b82f6); color: #fff; font-size: 0.8rem; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.activity-body { flex: 1; min-width: 0; }
.activity-text { font-size: 0.82rem; color: var(--gray-700); line-height: 1.4; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.activity-time { font-size: 0.72rem; color: var(--gray-400); margin-top: 0.1rem; }
.activity-thumb { width: 32px; height: 44px; object-fit: cover; border-radius: 3px; flex-shrink: 0; }
[data-theme="dark"] .activity-item { border-color: #334155; }
[data-theme="dark"] .activity-text { color: #cbd5e1; }

/* ── Book Clubs ─────────────────────────────────────────────────────────── */
.clubs-section { margin-bottom: 1rem; }
.club-card { display: flex; align-items: center; gap: 0.75rem; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 0.75rem; margin-bottom: 0.5rem; cursor: pointer; }
.club-book-cover { width: 44px; height: 62px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.club-book-cover-ph { width: 44px; height: 62px; background: var(--gray-100); border-radius: 4px; flex-shrink: 0; }
.club-card-body { flex: 1; min-width: 0; }
.club-card-name { font-weight: 700; font-size: 0.9rem; color: var(--gray-800); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.club-card-meta { font-size: 0.75rem; color: var(--gray-400); margin-top: 0.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.club-detail-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 450; display: none; align-items: flex-end; justify-content: center; }
.club-detail-overlay.open { display: flex; }
.club-detail-panel { background: var(--gray-50); width: 100%; max-width: 480px; height: 92dvh; border-radius: var(--radius) var(--radius) 0 0; display: flex; flex-direction: column; overflow: hidden; }
.club-detail-topbar { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1rem; background: #fff; border-bottom: 1px solid var(--gray-200); flex-shrink: 0; }
.club-detail-name { font-size: 1.2rem; font-weight: 800; color: var(--gray-800); margin-bottom: 0.3rem; }
.club-invite-row { font-size: 0.78rem; color: var(--gray-500); display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.club-invite-code { font-family: monospace; font-weight: 700; font-size: 0.9rem; letter-spacing: 0.15em; color: var(--blue); }
.club-current-book, .club-members-section, .club-notes-section { background: #fff; border-radius: var(--radius); padding: 0.75rem; margin-bottom: 0.75rem; box-shadow: var(--shadow); }
.club-book-row { display: flex; align-items: center; gap: 0.6rem; cursor: pointer; }
.club-members-list { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.25rem; }
.club-member-row { display: flex; align-items: center; gap: 0.5rem; }
.club-member-name { font-size: 0.875rem; font-weight: 600; color: var(--gray-700); }
.club-creator-badge { font-size: 0.65rem; background: #ede9fe; color: #7c3aed; border-radius: 999px; padding: 1px 7px; font-weight: 700; }
.club-note-item { display: flex; gap: 0.5rem; padding: 0.5rem 0; border-bottom: 1px solid var(--gray-100); }
.club-note-item:last-of-type { border-bottom: none; }
.club-note-header { display: flex; align-items: center; gap: 0.4rem; font-size: 0.78rem; margin-bottom: 0.2rem; flex-wrap: wrap; }
.club-note-text { font-size: 0.82rem; color: var(--gray-700); line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.club-note-delete { background: none; border: none; color: var(--gray-400); cursor: pointer; font-size: 0.7rem; padding: 0 2px; margin-left: auto; font-family: inherit; }
.club-note-delete:hover { color: #dc2626; }
.club-note-input-row { margin-top: 0.75rem; }
.club-book-result { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--gray-100); cursor: pointer; border-radius: 6px; }
.club-book-result:hover { background: var(--gray-50); }
[data-theme="dark"] .club-card { background: #1e293b; }
[data-theme="dark"] .club-detail-panel { background: #0f172a; }
[data-theme="dark"] .club-detail-topbar { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .club-current-book, [data-theme="dark"] .club-members-section, [data-theme="dark"] .club-notes-section { background: #1e293b; }
[data-theme="dark"] .club-note-item { border-color: #334155; }
[data-theme="dark"] .club-note-text, [data-theme="dark"] .club-member-name { color: #cbd5e1; }
.rec-card {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--blue-bg); border: 1.5px solid var(--blue-light);
  border-radius: var(--radius); padding: 0.75rem; margin-bottom: 0.5rem;
  cursor: pointer; position: relative; transition: background .15s;
}
.rec-card-seen { background: var(--gray-50); border-color: var(--gray-200); }
.rec-card-thumb { width: 44px; height: 62px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.rec-card-thumb-ph { width: 44px; height: 62px; border-radius: 4px; background: var(--gray-200); flex-shrink: 0; }
.rec-card-body { flex: 1; min-width: 0; }
.rec-card-title { font-weight: 700; font-size: 0.875rem; color: var(--gray-800); }
.rec-card-author { font-size: 0.78rem; color: var(--gray-600); margin-top: 0.1rem; }
.rec-card-from { font-size: 0.75rem; color: var(--gray-400); margin-top: 0.3rem; font-style: italic; }
.rec-badge {
  position: absolute; top: 0.5rem; right: 0.5rem;
  background: var(--blue); color: #fff;
  font-size: 0.65rem; font-weight: 700; border-radius: 999px; padding: 2px 7px;
}
[data-theme="dark"] .rec-card { background: #1e3a5f; border-color: #3b82f6; }
[data-theme="dark"] .rec-card-seen { background: #1e293b; border-color: #334155; }

/* ── Stats view ──────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.stats-card {
  background: var(--blue-bg);
  border: 1.5px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 0.9rem 0.75rem;
  text-align: center;
}
.stats-num {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--blue);
  line-height: 1;
  margin-bottom: 0.25rem;
}
.stats-label {
  font-size: 0.72rem;
  color: var(--gray-600);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stats-section {
  background: #fff;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-bottom: 0.75rem;
}
.stats-section-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.6rem;
}
.stats-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
  padding: 0.3rem 0;
  color: var(--gray-800);
}
.stats-goal-row { display: flex; gap: 0.5rem; }
.stats-goal-input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  background: var(--gray-50);
  color: var(--gray-800);
}
.stats-goal-input:focus { border-color: var(--blue); }
.stats-goal-btn {
  padding: 0.5rem 1rem;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.stats-goal-track {
  height: 8px;
  background: var(--gray-200);
  border-radius: 999px;
  overflow: hidden;
}
.stats-goal-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--blue-light));
  border-radius: 999px;
  transition: width .4s ease;
}
.stats-year-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.25rem 0; }
.stats-year-label { font-size: 0.8rem; font-weight: 700; color: var(--gray-600); width: 36px; flex-shrink: 0; }
.stats-year-bar-wrap { flex: 1; height: 10px; background: var(--gray-100); border-radius: 999px; overflow: hidden; }
.stats-year-bar { height: 100%; background: var(--blue); border-radius: 999px; min-width: 4px; }
.stats-year-count { font-size: 0.8rem; font-weight: 700; color: var(--gray-800); width: 24px; text-align: right; flex-shrink: 0; }
[data-theme="dark"] .stats-card     { background: #1e3a5f; border-color: #3b82f6; }
[data-theme="dark"] .stats-section  { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .stats-goal-input { background: #0f172a; border-color: #334155; color: #f1f5f9; }
[data-theme="dark"] .stats-year-bar-wrap { background: #334155; }

/* ── Family invite prompt ────────────────────────────────────────────────── */
.family-invite-prompt {
  text-align: center;
  padding: 2.5rem 1.5rem;
  color: var(--gray-400);
}
.family-invite-prompt svg {
  margin-bottom: 1rem;
  opacity: .4;
}
.family-invite-prompt h3 {
  font-size: 1rem;
  color: var(--gray-600);
  margin-bottom: 0.5rem;
}
.family-invite-prompt p {
  font-size: 0.875rem;
  line-height: 1.55;
  margin-bottom: 1.25rem;
}
.family-invite-btn {
  display: inline-block;
  padding: 0.65rem 1.5rem;
  background: linear-gradient(135deg, #5b21b6, #7c3aed);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.invite-link-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

/* ── Responsive tweaks ───────────────────────────────────────────────────── */
@media (min-width: 480px) {
  .results-grid { grid-template-columns: 1fr 1fr; }
  .book-card {
    grid-template-columns: 1fr;
    overflow: hidden;
  }
  .book-card .book-cover,
  .book-card .book-cover-placeholder {
    width: 100%;
    height: 160px;
    border-radius: 8px 8px 0 0;
  }
  .book-card {
    padding: 0;
  }
  .book-info { padding: 0.875rem; }
}

@media (min-width: 768px) {
  .app-page   { max-width: 680px; margin: 0 auto; box-shadow: 0 0 40px rgba(0,0,0,.08); min-height: 100dvh; background: #fff; }
  .top-bar    { position: sticky; left: unset; right: unset; transform: none; max-width: 100%; }
  .bottom-nav { max-width: 680px; left: 50%; right: auto; transform: translateX(-50%); }
}

/* ── Onboarding overlay ──────────────────────────────────────────────────── */
.onboarding-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(160deg, #1e3a8a 0%, #5b21b6 100%);
  z-index: 600;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.75rem 3rem;
  text-align: center;
}
.onboarding-overlay.open { display: flex; }
.onboarding-skip {
  position: absolute;
  top: 1rem; right: 1rem;
  background: rgba(255,255,255,.15);
  border: none;
  color: rgba(255,255,255,.85);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.85rem;
  border-radius: 20px;
  cursor: pointer;
}
.onboarding-slides { width: 100%; max-width: 340px; }
.onboarding-slide { display: none; }
.onboarding-slide.active { display: block; }
.onboarding-icon { font-size: 3.5rem; margin-bottom: 1.5rem; line-height: 1; }
.onboarding-heading {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 2rem;
  font-weight: 800;
  color: #fff;
  margin-bottom: 1rem;
  line-height: 1.2;
}
.onboarding-body {
  font-size: 1rem;
  color: rgba(255,255,255,.8);
  line-height: 1.6;
  max-width: 280px;
  margin: 0 auto;
}
.onboarding-body strong { color: #fff; }
.onboarding-dots { display: flex; gap: 0.5rem; margin-top: 2.5rem; }
.onboarding-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,.3);
  transition: background .2s, transform .2s;
}
.onboarding-dot-active { background: #fff; transform: scale(1.25); }
.onboarding-nav { display: flex; gap: 0.75rem; margin-top: 1.5rem; align-items: center; }
.onboarding-back-btn {
  background: rgba(255,255,255,.15);
  border: none;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.75rem 1.5rem;
  border-radius: 10px;
  cursor: pointer;
  min-width: 90px;
}
.onboarding-next-btn {
  background: #fff;
  border: none;
  color: #1e3a8a;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 0.75rem 2rem;
  border-radius: 10px;
  cursor: pointer;
  min-width: 120px;
}

/* ── Series badge (book cards) ───────────────────────────────────────────── */
.series-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--purple);
  background: var(--purple-bg);
  border-radius: 4px;
  padding: 0.1rem 0.45rem;
  margin-bottom: 0.2rem;
}

/* ── Series section (detail sheet) ──────────────────────────────────────── */
.detail-series-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.4rem;
}
.series-others-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray-400);
  margin-bottom: 0.4rem;
}
.series-other-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0;
  cursor: pointer;
  border-bottom: 1px solid var(--gray-100);
}
.series-other-row:last-child { border-bottom: none; }
[data-theme="dark"] .series-other-row { border-color: #334155; }

/* ── New Releases ────────────────────────────────────────────────────────── */
.nr-genre-tabs {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 0.6rem;
  margin-bottom: 0.75rem;
}
.nr-genre-tabs::-webkit-scrollbar { display: none; }
.nr-tab {
  flex-shrink: 0;
  padding: 0.4rem 1rem;
  border-radius: 999px;
  border: none;
  background: var(--gray-100);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--gray-400);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  letter-spacing: 0.01em;
}
.nr-tab.active {
  background: var(--blue);
  color: #fff;
}
.nr-tab:hover:not(.active) {
  background: var(--gray-200);
  color: var(--text);
}
.nr-scroll { padding-bottom: 0.75rem; }
.nr-card {
  flex-shrink: 0;
  width: 92px;
  cursor: pointer;
  text-align: center;
}
.nr-cover {
  width: 92px;
  height: 130px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
  background: var(--gray-100);
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  transition: transform 0.15s, box-shadow 0.15s;
}
.nr-card:active .nr-cover,
.nr-card:hover .nr-cover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.18);
}
.nr-title {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text);
  margin: 0.35rem 0 0.15rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}
.nr-author {
  font-size: 0.62rem;
  color: var(--gray-400);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.nr-in-list {
  font-size: 0.6rem;
  color: var(--blue-light);
  font-weight: 700;
  margin-top: 0.2rem;
}
.nr-hint {
  font-size: 0.8rem;
  color: var(--gray-400);
  padding: 0.75rem 0 0.5rem;
  font-style: italic;
}
.nr-loading {
  font-size: 0.8rem;
  color: var(--gray-400);
  padding: 0.75rem 0 0.5rem;
}
[data-theme="dark"] .nr-tab { background: #1e293b; color: #94a3b8; }
[data-theme="dark"] .nr-tab.active { background: var(--blue); color: #fff; }
[data-theme="dark"] .nr-tab:hover:not(.active) { background: #334155; color: #e2e8f0; }
[data-theme="dark"] .nr-cover { box-shadow: 0 2px 8px rgba(0,0,0,0.4); }
