/* BookNook — Warm, clean, mobile-first ebook discovery */

:root {
  --bg: #fdf6f0;
  --surface: #ffffff;
  --text: #3a2e2a;
  --text-muted: #8a7e7a;
  --accent: #8b4557;
  --accent-light: #f3e4e8;
  --accent-hover: #73384a;
  --heart: #d4485b;
  --heart-bg: rgba(212, 72, 91, 0.12);
  --gutenberg: #4a7c59;
  --openlibrary: #3b6fa0;
  --border: #ebe4de;
  --shadow: 0 2px 12px rgba(60, 40, 30, 0.08);
  --shadow-hover: 0 6px 20px rgba(60, 40, 30, 0.14);
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* Header */
header {
  text-align: center;
  padding: 1.75rem 1rem 0.5rem;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* Top nav */
.top-nav {
  display: flex;
  justify-content: center;
  gap: 0;
  padding: 0.5rem 1rem 0.25rem;
}

.nav-tab {
  padding: 0.5rem 1.5rem;
  border: none;
  background: none;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2.5px solid transparent;
  transition: all 0.2s;
}

.nav-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Search bar */
.search-bar {
  padding: 0.75rem 1rem;
  display: flex;
  gap: 0.5rem;
}

.search-bar input {
  flex: 1;
  padding: 0.8rem 1rem;
  border: 2px solid var(--border);
  border-radius: 2rem;
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.search-bar input:focus {
  border-color: var(--accent);
}

.search-submit {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

.search-submit:active {
  background: var(--accent-hover);
}

/* Genre chips */
.genre-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.25rem 1rem 0.75rem;
  justify-content: center;
}

.chip {
  flex-shrink: 0;
  padding: 0.4rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: 2rem;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.chip:active,
.chip.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.chip-sep {
  margin-left: 0.25rem;
}

/* Results count */
.results-count {
  padding: 0.25rem 1rem 0.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Loading skeleton cards */
.skeleton-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.skeleton-cover {
  aspect-ratio: 2 / 3;
  background: linear-gradient(110deg, var(--border) 30%, #f5efe9 50%, var(--border) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton-info {
  padding: 0.6rem 0.65rem 0.75rem;
}

.skeleton-line {
  border-radius: 4px;
  background: linear-gradient(110deg, var(--border) 30%, #f5efe9 50%, var(--border) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton-title {
  height: 0.8rem;
  width: 85%;
  margin-bottom: 0.4rem;
}

.skeleton-author {
  height: 0.65rem;
  width: 60%;
}

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

/* Results grid */
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  padding: 0.5rem 1rem 3rem;
  max-width: 800px;
  margin: 0 auto;
}

/* Book card */
.book-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
}

.book-card:active {
  transform: scale(0.97);
}

@media (hover: hover) {
  .book-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
  }
}

.book-cover-wrap {
  aspect-ratio: 2 / 3;
  background: var(--accent-light);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

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

.no-cover {
  font-size: 2rem;
  color: var(--accent);
  opacity: 0.4;
}

.source-tag {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  font-size: 0.625rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.source-tag.gutenberg {
  background: var(--gutenberg);
}

.source-tag.openlibrary {
  background: var(--openlibrary);
}

.source-tag.standardebooks {
  background: #2d6a4f;
}

.source-tag.internetarchive {
  background: #7b2d8b;
}

/* Heart button on card */
.heart-btn {
  position: absolute;
  top: 0.35rem;
  left: 0.35rem;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
  transition: transform 0.15s, background 0.15s;
  z-index: 2;
  padding: 0;
  color: var(--text-muted);
}

.heart-btn:active {
  transform: scale(0.85);
}

.heart-btn.saved {
  background: var(--heart-bg);
  color: var(--heart);
}

.book-card-info {
  padding: 0.6rem 0.65rem 0.75rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.book-card-title {
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

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

.book-card-download {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: auto;
  padding-top: 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}

.book-card-borrow {
  font-size: 0.72rem;
  color: #2563eb;
  font-weight: 600;
  margin-top: 0.25rem;
}

.borrow-btn {
  background: #2563eb !important;
  color: #fff !important;
}

.borrow-btn:hover {
  background: #1d4ed8 !important;
}

/* Welcome state */
.welcome {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}

.welcome-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
}

.welcome p {
  font-size: 1rem;
  line-height: 1.5;
}

.welcome-sub {
  font-size: 0.8rem;
  margin-top: 0.5rem;
  opacity: 0.7;
}

.no-results {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

/* Shelf tabs */
.shelf-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 1rem 0.5rem;
  justify-content: center;
}

.shelf-tab {
  padding: 0.4rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: 2rem;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.shelf-tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Shelf status badge on card */
.shelf-status-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 1rem;
  margin-top: auto;
  padding-top: 0.35rem;
  display: inline-block;
  align-self: flex-start;
}

.shelf-status-badge.want_to_read {
  color: var(--accent);
  background: var(--accent-light);
}

.shelf-status-badge.reading {
  color: #e67e22;
  background: #fff3e0;
}

.shelf-status-badge.finished {
  color: #2e7d32;
  background: #e8f5e9;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--surface);
  width: 100%;
  max-width: 500px;
  max-height: 90dvh;
  overflow-y: auto;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.5rem;
  animation: slide-up 0.25s ease-out;
  position: relative;
}

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

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
  z-index: 1;
}

.modal-body {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.modal-cover {
  width: 120px;
  height: 180px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--accent-light);
  flex-shrink: 0;
}

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

.modal-info h2 {
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.3;
  padding-right: 1.5rem;
}

.modal-author {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.modal-year {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.125rem;
}

.modal-subjects {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.75rem;
}

.modal-subjects .subject-tag {
  font-size: 0.675rem;
  padding: 0.15rem 0.5rem;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 1rem;
  white-space: nowrap;
}

.modal-source {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Description */
.modal-description {
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--text);
  margin-bottom: 1.25rem;
  max-height: 8rem;
  overflow-y: auto;
}

.modal-description.loading-desc {
  color: var(--text-muted);
  font-style: italic;
}

/* Shelf controls in modal */
.modal-shelf {
  margin-bottom: 1rem;
}

.shelf-status-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.shelf-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
}

.shelf-select {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  cursor: pointer;
}

.shelf-select:focus {
  border-color: var(--accent);
}

.download-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 1rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: white;
  font-size: 1.05rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s;
}

.download-btn:active {
  background: var(--accent-hover);
}

.hidden {
  display: none !important;
}

/* Desktop */
@media (min-width: 600px) {
  main, #shelf-view {
    max-width: 700px;
    margin: 0 auto;
  }

  .results-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }

  .modal {
    align-items: center;
  }

  .modal-content {
    border-radius: var(--radius);
    max-height: 80vh;
  }
}

@media (min-width: 800px) {
  main, #shelf-view {
    max-width: 800px;
  }

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

/* --- New This Week --- */

.section-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #8b4557;
  margin: 1.5rem 0 0.75rem;
  text-align: center;
}

.books-row, .related-row {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  padding: 0.25rem 0.5rem 1rem;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.books-row::-webkit-scrollbar,
.related-row::-webkit-scrollbar {
  height: 4px;
}

.books-row::-webkit-scrollbar-thumb,
.related-row::-webkit-scrollbar-thumb {
  background: #d4a99a;
  border-radius: 2px;
}

.mini-card {
  flex: 0 0 120px;
  scroll-snap-align: start;
  cursor: pointer;
  transition: transform 0.15s;
}

.mini-card:hover {
  transform: translateY(-3px);
}

.mini-card img {
  width: 120px;
  height: 175px;
  object-fit: cover;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.mini-no-cover {
  width: 120px;
  height: 175px;
  background: #e8d5c4;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
}

.mini-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: #3d2c22;
  margin-top: 0.35rem;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.mini-author {
  font-size: 0.68rem;
  color: #8b7355;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Author link --- */

.author-link {
  color: #8b4557;
  text-decoration: none;
  cursor: pointer;
}

.author-link:hover {
  text-decoration: underline;
}

/* --- More Like This --- */

.modal-related {
  margin-top: 1.25rem;
  border-top: 1px solid #e8d5c4;
  padding-top: 0.75rem;
}

.related-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #4a3728;
  margin-bottom: 0.5rem;
}

/* --- Modal actions row --- */

.modal-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

/* --- Send to Kindle --- */

.kindle-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.65rem 1.25rem;
  background: #f59e0b;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.kindle-btn:hover {
  background: #d97706;
}

.kindle-setup {
  max-width: 420px;
  text-align: center;
}

.kindle-setup h2 {
  margin-bottom: 0.5rem;
}

.kindle-info {
  font-size: 0.88rem;
  color: #6b5c4a;
  margin-bottom: 1rem;
  line-height: 1.5;
}

.kindle-input {
  width: 100%;
  padding: 0.75rem;
  border: 2px solid #d4a99a;
  border-radius: 8px;
  font-size: 1rem;
  margin-bottom: 0.75rem;
  box-sizing: border-box;
}

.kindle-input:focus {
  outline: none;
  border-color: #8b4557;
}

.kindle-note {
  font-size: 0.78rem;
  color: #8b7355;
  margin-bottom: 1rem;
  line-height: 1.4;
}

.kindle-send-btn {
  width: 100%;
  padding: 0.75rem;
  background: #f59e0b;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}

.kindle-send-btn:hover {
  background: #d97706;
}

.kindle-send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.kindle-status {
  margin-top: 0.75rem;
  padding: 0.5rem;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 500;
}

.kindle-status.success {
  background: #d1fae5;
  color: #065f46;
}

.kindle-status.error {
  background: #fee2e2;
  color: #991b1b;
}

/* ============================
   Auth Loading Spinner
   ============================ */
.auth-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  gap: 1rem;
  color: var(--text-muted);
}
.auth-loading.hidden { display: none; }
.auth-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================
   Landing Page
   ============================ */
.landing {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}
.landing.hidden { display: none; }

.landing-hero {
  text-align: center;
  max-width: 440px;
}
.landing-title {
  font-size: 2.75rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.03em;
  margin-bottom: 0.5rem;
}
.landing-tagline {
  font-size: 1.15rem;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 2rem;
}
.landing-features {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  text-align: left;
  margin: 0 auto 2rem;
  max-width: 320px;
}
.landing-feature {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.95rem;
  color: var(--text);
}
.feature-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
  width: 2rem;
  text-align: center;
}
.landing-price {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 1.5rem;
}
.g-signin-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 0.75rem;
  min-height: 44px;
}
.landing-note {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ============================
   Subscribe Page
   ============================ */
.subscribe {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}
.subscribe.hidden { display: none; }

.subscribe-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.5rem 2rem;
  max-width: 440px;
  text-align: center;
  width: 100%;
}
.subscribe-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 1rem;
}
.sub-user-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}
.sub-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}
.sub-pitch {
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 1.5rem;
}
.sub-features {
  text-align: left;
  max-width: 340px;
  margin: 0 auto 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.sub-feature {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.4;
}
.subscribe-cta {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 600;
  padding: 0.85rem 2rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: background 0.2s;
  margin-bottom: 0.75rem;
}
.subscribe-cta:hover {
  background: var(--accent-hover);
}
.sub-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}
.sub-logout {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
}

/* ============================
   Header Row (with user menu)
   ============================ */
.header-row {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.user-menu {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
}
.user-menu-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.75rem 0.25rem 0.25rem;
  cursor: pointer;
  transition: box-shadow 0.2s;
}
.user-menu-btn:hover {
  box-shadow: var(--shadow);
}
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}
.user-name {
  font-size: 0.8rem;
  color: var(--text);
  font-weight: 500;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  min-width: 180px;
  z-index: 100;
  padding: 0.5rem 0;
}
.user-dropdown.hidden { display: none; }
.dropdown-email {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0.4rem 1rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
}
.dropdown-item:hover {
  background: var(--accent-light);
}

/* ============================
   App container visibility
   ============================ */
#app-container.hidden { display: none; }
