/* =============================================
   MILLIBRO — Design System & Component Styles
   ============================================= */

/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;500;600;700;800&family=DM+Sans:wght@300;400;500;600;700&display=swap');

/* ---- CSS Variables ---- */
:root {
  --cream: #F5F0E8;
  --cream-dark: #EDE6D6;
  --forest: #2C5545;
  --forest-light: #3D7A62;
  --gold: #C4973A;
  --ink: #1A1A1A;
  --ink-muted: #6B6356;
  --border: #DDD5C4;
  --white: #FFFFFF;

  --dot-yellow: #F4C542;
  --dot-blue: #4A9EE0;
  --dot-green: #52B788;
  --dot-purple: #9B72CF;
  --dot-white: #E8E8E8;
  --dot-black: #2D2D2D;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.10);
  --transition: 0.2s ease;

  --sidebar-w: 240px;
  --right-w: 280px;
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--cream);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  line-height: 1.25;
}

a { color: var(--forest); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--forest-light); }

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

/* ---- Utilities ---- */
.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }
.text-center { text-align: center; }
.text-muted { color: var(--ink-muted); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
  line-height: 1.4;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--forest);
  color: var(--white);
}
.btn-primary:hover:not(:disabled) { background: var(--forest-light); transform: translateY(-1px); }

.btn-secondary {
  background: var(--cream-dark);
  color: var(--ink);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-gold {
  background: var(--gold);
  color: var(--white);
}
.btn-gold:hover:not(:disabled) { background: #d4a73a; }

.btn-ghost {
  background: transparent;
  color: var(--forest);
  padding: 8px 16px;
}
.btn-ghost:hover { background: rgba(44,85,69,0.08); }

.btn-danger {
  background: #dc3545;
  color: var(--white);
}

.btn-sm { padding: 6px 16px; font-size: 0.85rem; }
.btn-lg { padding: 14px 32px; font-size: 1.05rem; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; border-radius: 50%; width: 36px; height: 36px; }

/* ---- Form Elements ---- */
.input-group { margin-bottom: 16px; }
.input-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--ink);
}

.input, input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], textarea, select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--white);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.input:focus, input:focus, textarea:focus, select:focus {
  border-color: var(--forest);
  box-shadow: 0 0 0 3px rgba(44,85,69,0.12);
}
.input::placeholder, input::placeholder, textarea::placeholder {
  color: var(--ink-muted);
  opacity: 0.7;
}
textarea { resize: vertical; min-height: 80px; }

.input-error { border-color: #dc3545 !important; }
.error-text { color: #dc3545; font-size: 0.82rem; margin-top: 4px; }
.success-text { color: var(--forest); font-size: 0.82rem; margin-top: 4px; }

/* ---- Cards ---- */
.card {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow); }

.card-flat {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
}

/* ---- Avatar with Dot ---- */
.avatar-wrap {
  position: relative;
  display: inline-block;
  flex-shrink: 0;
}
.avatar {
  border-radius: 50%;
  object-fit: cover;
  background: var(--cream-dark);
  border: 2px solid var(--white);
}
.avatar-xs { width: 28px; height: 28px; }
.avatar-sm { width: 36px; height: 36px; }
.avatar-md { width: 44px; height: 44px; }
.avatar-lg { width: 64px; height: 64px; }
.avatar-xl { width: 96px; height: 96px; }

.avatar-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  border-radius: 50%;
  border: 2px solid var(--white);
  z-index: 2;
}
.avatar-xs + .avatar-dot, .avatar-sm + .avatar-dot { width: 10px; height: 10px; }
.avatar-md + .avatar-dot { width: 12px; height: 12px; }
.avatar-lg + .avatar-dot { width: 14px; height: 14px; }
.avatar-xl + .avatar-dot { width: 18px; height: 18px; }

.dot-yellow { background: var(--dot-yellow); }
.dot-blue { background: var(--dot-blue); }
.dot-green { background: var(--dot-green); }
.dot-purple { background: var(--dot-purple); }
.dot-white { background: var(--dot-white); }
.dot-black { background: var(--dot-black); }

.avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--forest);
  color: var(--white);
  font-weight: 700;
  font-family: 'Playfair Display', serif;
}

/* ---- Founder Badge ---- */
.founder-badge { margin-left: 4px; font-size: 0.9em; }

/* ---- Navigation / Sidebar ---- */
.app-layout {
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--white);
  border-right: 1px solid var(--border);
  padding: 20px;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  font-family: 'Playfair Display', serif;
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--forest);
  margin-bottom: 24px;
  letter-spacing: -0.5px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--cream);
  border-radius: var(--radius);
  margin-bottom: 24px;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-handle {
  font-size: 0.8rem;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav { list-style: none; flex: 1; }
.sidebar-nav li { margin-bottom: 4px; }
.sidebar-nav a, .sidebar-nav button {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 500;
  transition: all var(--transition);
  width: 100%;
  border: none;
  background: none;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  text-align: left;
}
.sidebar-nav a:hover, .sidebar-nav button:hover { background: var(--cream); color: var(--forest); }
.sidebar-nav a.active { background: var(--forest); color: var(--white); }
.sidebar-nav .nav-icon { width: 20px; text-align: center; font-size: 1.1rem; }
.sidebar-nav .nav-badge {
  margin-left: auto;
  background: var(--gold);
  color: var(--white);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.sidebar-bottom {
  padding-top: 16px;
  border-top: 1px solid var(--border);
  margin-top: 16px;
}

/* ---- Main Content Area ---- */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
}

.feed-layout {
  display: flex;
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px;
  gap: 24px;
}

.feed-center { flex: 1; min-width: 0; }

.right-panel {
  width: var(--right-w);
  flex-shrink: 0;
}
.right-panel .card { margin-bottom: 16px; }
.right-panel h3 { font-size: 1rem; margin-bottom: 12px; }

/* ---- Post Card ---- */
.post-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  transition: box-shadow var(--transition);
}
.post-card:hover { box-shadow: var(--shadow); }

.post-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.post-user-info { flex: 1; }
.post-user-name {
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}
.post-user-name:hover { color: var(--forest); }
.post-user-handle {
  font-size: 0.82rem;
  color: var(--ink-muted);
}
.post-time {
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.post-content {
  font-size: 0.95rem;
  line-height: 1.65;
  margin-bottom: 12px;
  white-space: pre-wrap;
}

.post-book-tag {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--cream);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  cursor: pointer;
  transition: background var(--transition);
}
.post-book-tag:hover { background: var(--cream-dark); }
.post-book-tag img { width: 36px; height: 52px; object-fit: cover; border-radius: 4px; }
.post-book-tag .book-info { flex: 1; }
.post-book-tag .book-title { font-weight: 600; font-size: 0.88rem; }
.post-book-tag .book-author { font-size: 0.8rem; color: var(--ink-muted); }

.post-progress-bar {
  height: 6px;
  background: var(--cream-dark);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 12px;
}
.post-progress-bar .fill {
  height: 100%;
  background: var(--forest);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.post-actions {
  display: flex;
  gap: 4px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.post-action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
  font-size: 0.85rem;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  transition: all var(--transition);
}
.post-action-btn:hover { background: var(--cream); color: var(--forest); }
.post-action-btn.liked { color: var(--gold); }
.post-action-btn .count { font-weight: 600; }

/* ---- Compose Box ---- */
.compose-box {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.compose-box textarea {
  border: none;
  padding: 0;
  min-height: 60px;
  resize: none;
  font-size: 0.95rem;
}
.compose-box textarea:focus { box-shadow: none; }
.compose-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
}
.compose-book-tag {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--cream);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}
.compose-book-tag .remove-book {
  cursor: pointer;
  color: var(--ink-muted);
  font-size: 1rem;
  border: none;
  background: none;
  padding: 0 4px;
}

/* ---- Book Card (Grid) ---- */
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 16px;
}
.book-grid-item {
  position: relative;
  cursor: pointer;
  border-radius: var(--radius-sm);
  overflow: hidden;
  aspect-ratio: 2/3;
  background: var(--cream-dark);
  transition: transform var(--transition), box-shadow var(--transition);
}
.book-grid-item:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.book-grid-item img { width: 100%; height: 100%; object-fit: cover; }
.book-grid-item .overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: flex-end;
  padding: 10px;
  opacity: 0;
  transition: opacity var(--transition);
}
.book-grid-item:hover .overlay { opacity: 1; }
.book-grid-item .overlay span {
  color: var(--white);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.3;
}

/* ---- Book Search List ---- */
.book-search-results { list-style: none; max-height: 320px; overflow-y: auto; }
.book-search-item {
  display: flex;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}
.book-search-item:hover { background: var(--cream); }
.book-search-item img { width: 44px; height: 64px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.book-search-item .book-info { flex: 1; }
.book-search-item .book-title { font-weight: 600; font-size: 0.9rem; }
.book-search-item .book-author { font-size: 0.82rem; color: var(--ink-muted); }
.book-search-item .book-meta { font-size: 0.78rem; color: var(--ink-muted); margin-top: 2px; }

/* ---- Progress Bar ---- */
.progress-bar {
  height: 8px;
  background: var(--cream-dark);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar .fill {
  height: 100%;
  background: linear-gradient(90deg, var(--forest), var(--forest-light));
  border-radius: 4px;
  transition: width 0.5s ease;
}
.progress-text { font-size: 0.82rem; color: var(--ink-muted); margin-top: 4px; }

/* ---- Star Rating ---- */
.stars { display: flex; gap: 2px; }
.stars .star {
  color: var(--cream-dark);
  font-size: 1.2rem;
  cursor: pointer;
  transition: color var(--transition);
}
.stars .star.filled { color: var(--gold); }
.stars .star:hover { color: var(--gold); }
.stars-display .star { cursor: default; }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition);
}
.modal-overlay.active { opacity: 1; visibility: visible; }

.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(20px);
  transition: transform var(--transition);
  box-shadow: var(--shadow-lg);
}
.modal-overlay.active .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.modal-header h2 { font-size: 1.3rem; }
.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--cream);
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-muted);
  transition: all var(--transition);
}
.modal-close:hover { background: var(--cream-dark); color: var(--ink); }

/* ---- Tabs ---- */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}
.tab-btn {
  padding: 10px 20px;
  border: none;
  background: none;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--ink-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition);
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.active { color: var(--forest); border-bottom-color: var(--forest); font-weight: 600; }

/* ---- Dot Legend ---- */
.dot-legend { display: flex; flex-direction: column; gap: 8px; }
.dot-legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}
.dot-legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-legend-label { color: var(--ink-muted); }
.dot-legend-count { font-weight: 600; margin-left: auto; font-size: 0.82rem; }

/* ---- User Card (Discover/Suggestions) ---- */
.user-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.user-card:hover { background: var(--cream); }
.user-card-info { flex: 1; min-width: 0; }
.user-card-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-card-handle { font-size: 0.8rem; color: var(--ink-muted); }
.user-card-meta { font-size: 0.78rem; color: var(--ink-muted); }

/* ---- Notification Item ---- */
.notif-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}
.notif-item:hover { background: var(--cream); }
.notif-item.unread { background: rgba(44,85,69,0.04); }
.notif-item .notif-text { flex: 1; font-size: 0.9rem; line-height: 1.5; }
.notif-item .notif-time { font-size: 0.78rem; color: var(--ink-muted); white-space: nowrap; }

/* ---- Profile Header ---- */
.profile-banner {
  height: 200px;
  background: linear-gradient(135deg, var(--forest), var(--forest-light));
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  position: relative;
  overflow: hidden;
}
.profile-banner img { width: 100%; height: 100%; object-fit: cover; }
.profile-banner .banner-upload {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(0,0,0,0.5);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.82rem;
  cursor: pointer;
}

.profile-info {
  padding: 0 24px;
  margin-top: -40px;
  position: relative;
}
.profile-info .avatar-wrap { border: 4px solid var(--white); border-radius: 50%; }
.profile-meta {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-top: 12px;
}
.profile-name { font-size: 1.5rem; }
.profile-handle { color: var(--ink-muted); font-size: 0.95rem; }
.profile-bio { margin-top: 8px; font-size: 0.95rem; line-height: 1.6; }
.profile-joined { font-size: 0.82rem; color: var(--ink-muted); margin-top: 4px; }

.profile-stats {
  display: flex;
  gap: 28px;
  margin-top: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.profile-stat { text-align: center; }
.profile-stat .stat-value { font-size: 1.3rem; font-weight: 700; font-family: 'Playfair Display', serif; }
.profile-stat .stat-label { font-size: 0.78rem; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.5px; }

/* ---- Currently Reading Card ---- */
.reading-card {
  display: flex;
  gap: 16px;
  padding: 16px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
}
.reading-card img { width: 56px; height: 80px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.reading-card-info { flex: 1; }
.reading-card-title { font-weight: 600; font-size: 0.95rem; margin-bottom: 2px; }
.reading-card-author { font-size: 0.82rem; color: var(--ink-muted); margin-bottom: 8px; }
.reading-card-streak { font-size: 0.78rem; color: var(--gold); font-weight: 600; margin-top: 6px; }

/* ---- Review Card ---- */
.review-card {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.review-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.review-text { font-size: 0.92rem; line-height: 1.6; margin-top: 8px; }
.review-date { font-size: 0.78rem; color: var(--ink-muted); margin-top: 6px; }

/* ---- Book Detail Page ---- */
.book-detail {
  display: flex;
  gap: 32px;
  padding: 32px 0;
}
.book-cover-large {
  width: 240px;
  flex-shrink: 0;
}
.book-cover-large img {
  width: 100%;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.book-detail-info { flex: 1; }
.book-detail-title { font-size: 2rem; margin-bottom: 4px; }
.book-detail-author { font-size: 1.1rem; color: var(--ink-muted); margin-bottom: 16px; }
.book-detail-meta {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  font-size: 0.88rem;
  color: var(--ink-muted);
}
.book-detail-meta span { display: flex; align-items: center; gap: 4px; }

.affiliate-links { display: flex; gap: 12px; margin-bottom: 24px; }

/* ---- Comment Thread ---- */
.comments-section { margin-top: 12px; }
.comment-item {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.comment-item:first-child { border-top: none; }
.comment-content { flex: 1; }
.comment-author { font-weight: 600; font-size: 0.85rem; }
.comment-text { font-size: 0.88rem; margin-top: 2px; }
.comment-time { font-size: 0.75rem; color: var(--ink-muted); margin-top: 2px; }

.comment-form {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.comment-form input {
  flex: 1;
  padding: 8px 12px;
  font-size: 0.88rem;
}
.comment-form button { flex-shrink: 0; }

/* ---- Empty State ---- */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--ink-muted);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state h3 { font-size: 1.2rem; margin-bottom: 8px; color: var(--ink); }
.empty-state p { font-size: 0.92rem; max-width: 400px; margin: 0 auto 16px; }

/* ---- Toast ---- */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
  max-width: 360px;
}
.toast-success { background: var(--forest); color: var(--white); }
.toast-error { background: #dc3545; color: var(--white); }
.toast-info { background: var(--ink); color: var(--white); }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; transform: translateY(-10px); } }

/* ---- Loading Spinner ---- */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--forest);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 20px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Landing Page ---- */
.landing {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  background: linear-gradient(180deg, var(--cream) 0%, var(--cream-dark) 100%);
}
.landing-logo {
  font-family: 'Playfair Display', serif;
  font-size: 4.5rem;
  font-weight: 800;
  color: var(--forest);
  margin-bottom: 16px;
  letter-spacing: -2px;
}
.landing-tagline {
  font-size: 1.2rem;
  color: var(--ink-muted);
  max-width: 440px;
  margin-bottom: 40px;
  line-height: 1.6;
}

.landing-dots {
  display: flex;
  gap: 24px;
  margin-bottom: 48px;
  flex-wrap: wrap;
  justify-content: center;
}
.landing-dot-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.landing-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border);
  transition: transform var(--transition);
}
.landing-dot:hover { transform: scale(1.15); }
.landing-dot-label {
  font-size: 0.78rem;
  color: var(--ink-muted);
  font-weight: 500;
}

.landing-actions { display: flex; gap: 16px; flex-direction: column; align-items: center; }
.landing-actions .btn-primary { min-width: 200px; padding: 14px 36px; font-size: 1.05rem; }
.landing-signin { font-size: 0.92rem; color: var(--ink-muted); margin-top: 8px; }
.landing-signin a { font-weight: 600; }

/* ---- Auth Page ---- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}
.auth-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
}
.auth-card h1 {
  font-size: 1.8rem;
  margin-bottom: 8px;
  text-align: center;
}
.auth-card .auth-subtitle {
  text-align: center;
  color: var(--ink-muted);
  margin-bottom: 28px;
  font-size: 0.92rem;
}
.auth-switch {
  text-align: center;
  margin-top: 20px;
  font-size: 0.9rem;
  color: var(--ink-muted);
}
.auth-switch a { font-weight: 600; }
.auth-logo {
  text-align: center;
  margin-bottom: 24px;
}
.auth-logo a {
  font-family: 'Playfair Display', serif;
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--forest);
}

/* ---- Onboarding ---- */
.onboarding-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}
.onboarding-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
}
.onboarding-card h1 { font-size: 1.5rem; margin-bottom: 8px; }
.onboarding-card .step-subtitle { color: var(--ink-muted); margin-bottom: 24px; }

.progress-steps {
  display: flex;
  gap: 8px;
  margin-bottom: 28px;
}
.progress-step {
  flex: 1;
  height: 4px;
  background: var(--cream-dark);
  border-radius: 2px;
  transition: background var(--transition);
}
.progress-step.active { background: var(--forest); }
.progress-step.done { background: var(--gold); }

.avatar-upload-area {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 2px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  cursor: pointer;
  overflow: hidden;
  transition: border-color var(--transition);
  background: var(--cream);
}
.avatar-upload-area:hover { border-color: var(--forest); }
.avatar-upload-area img { width: 100%; height: 100%; object-fit: cover; }
.avatar-upload-area .upload-icon { font-size: 2rem; color: var(--ink-muted); }

.onboarding-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 24px;
}

/* ---- Genre Tags ---- */
.genre-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.genre-tag {
  padding: 8px 16px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--white);
  font-size: 0.88rem;
  cursor: pointer;
  transition: all var(--transition);
  font-family: 'DM Sans', sans-serif;
}
.genre-tag:hover, .genre-tag.active { background: var(--forest); color: var(--white); border-color: var(--forest); }

/* ---- My Books List ---- */
.my-book-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.my-book-item img { width: 48px; height: 68px; object-fit: cover; border-radius: 6px; }
.my-book-info { flex: 1; }
.my-book-title { font-weight: 600; }
.my-book-author { font-size: 0.85rem; color: var(--ink-muted); }
.my-book-date { font-size: 0.82rem; color: var(--ink-muted); }

/* ---- Progress Page ---- */
.progress-page-header {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 32px;
}
.progress-page-header img { width: 140px; border-radius: var(--radius); box-shadow: var(--shadow); }
.progress-page-info { flex: 1; }
.progress-page-info h1 { font-size: 1.5rem; margin-bottom: 4px; }
.progress-page-info .author { color: var(--ink-muted); margin-bottom: 16px; }

.log-entry {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.log-date { font-size: 0.82rem; color: var(--ink-muted); white-space: nowrap; min-width: 80px; }
.log-pages { font-weight: 600; font-size: 0.92rem; }
.log-note { font-size: 0.88rem; color: var(--ink-muted); margin-top: 2px; }

/* ---- Streak Badge ---- */
.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: linear-gradient(135deg, #F4C542, #C4973A);
  color: var(--white);
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
}

/* ---- Page Header ---- */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.page-header h1 { font-size: 1.6rem; }

/* ---- Responsive ---- */

/* --- Bottom Navigation for Mobile --- */
.bottom-nav {
  display: none;
}

@media (max-width: 1024px) {
  .right-panel { display: none; }
}

@media (max-width: 768px) {
  /* --- Safe area insets for notched phones --- */
  html, body {
    overflow-x: hidden;
    max-width: 100vw;
  }
  html {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  }

  body {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    padding-bottom: 68px; /* space for bottom nav */
  }

  /* --- App layout: stack vertically on mobile --- */
  .app-layout {
    flex-direction: column;
    flex-wrap: nowrap;
  }

  /* --- Sidebar: hidden on mobile, bottom nav is used instead --- */
  .sidebar {
    display: none !important;
    width: 0 !important;
    min-width: 0 !important;
    overflow: hidden !important;
  }
  .sidebar.open {
    display: flex !important;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px !important;
    z-index: 200;
  }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 150;
    display: none;
  }
  .sidebar-overlay.active { display: block; }

  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    flex: 1 1 100% !important;
    min-width: 0 !important;
  }

  /* --- Mobile Header --- */
  .mobile-header {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    padding-top: calc(10px + env(safe-area-inset-top));
    background: var(--white);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    min-height: 52px;
  }
  .hamburger {
    width: 44px;
    height: 44px;
    border: none;
    background: none;
    font-size: 1.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    -webkit-tap-highlight-color: transparent;
  }
  .hamburger:active { background: var(--cream); }

  /* --- Bottom Navigation Bar --- */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--white);
    border-top: 1px solid var(--border);
    z-index: 100;
    padding: 6px 0;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around;
    align-items: center;
  }
  .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 0;
    min-width: 56px;
    text-decoration: none;
    color: var(--ink-muted);
    font-size: 0.68rem;
    font-weight: 500;
    transition: color var(--transition);
    -webkit-tap-highlight-color: transparent;
    position: relative;
  }
  .bottom-nav-item .nav-emoji {
    font-size: 1.3rem;
    line-height: 1;
  }
  .bottom-nav-item.active {
    color: var(--forest);
    font-weight: 700;
  }
  .bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 3px;
    background: var(--forest);
    border-radius: 0 0 3px 3px;
  }
  .bottom-nav-item .bottom-badge {
    position: absolute;
    top: 2px;
    right: 8px;
    background: var(--gold);
    color: var(--white);
    font-size: 0.6rem;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
  }

  /* --- Feed Layout --- */
  .feed-layout {
    padding: 12px;
    gap: 12px;
  }

  /* --- Post Cards --- */
  .post-card {
    padding: 14px;
    margin-bottom: 12px;
    border-radius: var(--radius-sm);
  }
  .post-header { gap: 10px; margin-bottom: 10px; }
  .post-content { font-size: 0.92rem; margin-bottom: 10px; }
  .post-actions { padding-top: 10px; gap: 0; justify-content: space-around; }
  .post-action-btn {
    padding: 8px 12px;
    min-height: 44px;
    font-size: 0.82rem;
  }

  /* --- Compose Box --- */
  .compose-box {
    padding: 14px;
    margin-bottom: 12px;
  }
  .compose-box textarea { font-size: 0.92rem; min-height: 48px; }

  /* --- Page Header --- */
  .page-header {
    padding: 0;
    margin-bottom: 16px;
  }
  .page-header h1 { font-size: 1.35rem; }

  /* --- Tabs (horizontal scrollable) --- */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    white-space: nowrap;
    margin-bottom: 16px;
    gap: 0;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab-btn {
    padding: 10px 16px;
    font-size: 0.88rem;
    white-space: nowrap;
    flex-shrink: 0;
    min-height: 44px;
  }

  /* --- Cards --- */
  .card, .card-flat {
    padding: 14px;
    border-radius: var(--radius-sm);
  }

  /* --- Book Grid --- */
  .books-grid {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 10px;
  }

  /* --- Book Search Results --- */
  .book-search-item {
    padding: 12px 8px;
    gap: 10px;
  }
  .book-search-item img { width: 40px; height: 58px; }

  /* --- Book Detail Layout --- */
  .book-detail {
    flex-direction: column;
    gap: 20px;
    padding: 20px 0;
  }
  .book-cover-large {
    width: 140px;
    margin: 0 auto;
  }
  .book-detail-title { font-size: 1.5rem; text-align: center; }
  .book-detail-author { text-align: center; font-size: 1rem; }
  .book-detail-meta { justify-content: center; flex-wrap: wrap; gap: 12px; font-size: 0.82rem; }
  .affiliate-links { justify-content: center; flex-wrap: wrap; }

  /* --- Modal (full-screen on mobile) --- */
  .modal {
    width: 100%;
    max-width: 100%;
    min-height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    padding: 20px 16px;
    padding-top: calc(20px + env(safe-area-inset-top));
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
  .modal-header h2 { font-size: 1.15rem; }
  .modal-close {
    width: 40px;
    height: 40px;
    font-size: 1.3rem;
  }

  /* --- Profile Page --- */
  .profile-banner { height: 120px; }
  .profile-info { padding: 0 16px; margin-top: -32px; }
  .profile-name { font-size: 1.3rem; }
  .profile-handle { font-size: 0.88rem; }
  .profile-bio { font-size: 0.9rem; }
  .profile-meta {
    flex-direction: column;
    gap: 12px;
  }
  .profile-stats {
    gap: 16px;
    flex-wrap: wrap;
    justify-content: center;
  }
  .profile-stat .stat-value { font-size: 1.15rem; }

  /* --- Progress Page --- */
  .progress-page-header {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 16px;
  }
  .progress-page-header img { width: 110px; }
  .progress-page-info h1 { font-size: 1.25rem; }

  /* --- My Books Items --- */
  .my-book-item {
    padding: 12px 8px;
    gap: 12px;
  }
  .my-book-item img { width: 42px; height: 60px; }
  .my-book-title { font-size: 0.92rem; }

  /* --- Reading Card --- */
  .reading-card {
    padding: 12px;
    gap: 12px;
  }
  .reading-card img { width: 48px; height: 68px; }

  /* --- Notifications --- */
  .notif-item {
    padding: 12px;
    gap: 10px;
  }
  .notif-item .notif-text { font-size: 0.85rem; }

  /* --- User Cards (Discover) --- */
  .user-card {
    padding: 12px 8px;
    gap: 10px;
  }
  .user-card .btn { padding: 8px 14px; font-size: 0.82rem; min-height: 40px; }

  /* --- Landing Page --- */
  .landing {
    padding: 32px 16px;
  }
  .landing-logo { font-size: 2.8rem; letter-spacing: -1px; }
  .landing-tagline { font-size: 1rem; margin-bottom: 28px; max-width: 320px; }
  .landing-dots { gap: 14px; margin-bottom: 32px; }
  .landing-dot { width: 26px; height: 26px; }
  .landing-dot-label { font-size: 0.7rem; }
  .landing-actions .btn-primary { min-width: 180px; padding: 12px 28px; font-size: 1rem; }

  /* --- Auth & Onboarding --- */
  .auth-page, .onboarding-page {
    padding: 20px 12px;
    align-items: flex-start;
    padding-top: 40px;
  }
  .auth-card, .onboarding-card {
    padding: 24px 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }
  .auth-card h1 { font-size: 1.5rem; }
  .auth-logo a { font-size: 1.5rem; }
  .onboarding-card h1 { font-size: 1.3rem; }

  /* --- Buttons: bigger touch targets --- */
  .btn {
    min-height: 44px;
    padding: 10px 20px;
  }
  .btn-sm {
    min-height: 36px;
    padding: 6px 12px;
  }
  .btn-lg {
    min-height: 48px;
    padding: 12px 28px;
  }
  .btn-block {
    min-height: 48px;
  }
  .btn-icon {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
  }

  /* --- Input fields: bigger for thumb --- */
  .input, input[type="text"], input[type="email"], input[type="password"],
  input[type="number"], input[type="date"], textarea, select {
    padding: 12px 14px;
    font-size: 16px; /* prevents iOS zoom */
    min-height: 44px;
  }

  /* --- Genre Tags --- */
  .genre-tags { gap: 6px; }
  .genre-tag {
    padding: 8px 14px;
    font-size: 0.85rem;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
  }

  /* --- Toast on mobile --- */
  .toast-container {
    top: auto;
    bottom: 80px; /* above bottom nav */
    right: 12px;
    left: 12px;
  }
  .toast {
    max-width: 100%;
    text-align: center;
  }

  /* --- Dot Legend (compact) --- */
  .dot-legend {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }
  .dot-legend-item {
    font-size: 0.78rem;
    gap: 6px;
  }
  .dot-legend-dot { width: 12px; height: 12px; }

  /* --- Comment form --- */
  .comment-form {
    gap: 6px;
  }
  .comment-form input {
    padding: 10px 12px;
    font-size: 16px;
    min-height: 44px;
  }

  /* --- Avatar sizes on mobile (slightly smaller) --- */
  .avatar-xl { width: 72px; height: 72px; }

  /* --- Streak badge --- */
  .streak-badge { font-size: 0.78rem; padding: 3px 10px; }

  /* --- Star Rating (bigger for touch) --- */
  .stars .star { font-size: 1.5rem; padding: 4px; }

  /* --- Log entries --- */
  .log-entry { gap: 8px; padding: 12px 0; }
  .log-date { min-width: 70px; font-size: 0.78rem; }

  /* --- Sidebar user section on mobile --- */
  .sidebar-user { padding: 10px; gap: 10px; }

  /* --- Empty State --- */
  .empty-state { padding: 32px 16px; }
  .empty-state-icon { font-size: 2.5rem; }
  .empty-state h3 { font-size: 1.05rem; }
  .empty-state p { font-size: 0.88rem; }

  /* --- Onboarding actions --- */
  .onboarding-actions {
    gap: 12px;
  }
  .onboarding-actions .btn {
    flex: 1;
  }

  /* --- Progress steps --- */
  .progress-steps { gap: 6px; margin-bottom: 20px; }

  /* --- Avatar upload --- */
  .avatar-upload-area {
    width: 100px;
    height: 100px;
    margin-bottom: 16px;
  }
}

/* --- Extra small screens (iPhone SE / 320px) --- */
@media (max-width: 374px) {
  .landing-logo { font-size: 2.2rem; }
  .landing-tagline { font-size: 0.92rem; }
  .landing-dots { gap: 10px; }
  .landing-dot { width: 22px; height: 22px; }

  .auth-card, .onboarding-card { padding: 20px 12px; }
  .auth-card h1 { font-size: 1.3rem; }

  .post-card { padding: 12px; }
  .post-actions { flex-wrap: wrap; }

  .page-header h1 { font-size: 1.2rem; }

  .bottom-nav-item { min-width: 48px; font-size: 0.62rem; }
  .bottom-nav-item .nav-emoji { font-size: 1.15rem; }

  .profile-name { font-size: 1.15rem; }
  .profile-stats { gap: 12px; }
  .profile-stat .stat-value { font-size: 1rem; }
}

/* --- Desktop override --- */
@media (min-width: 769px) {
  .mobile-header { display: none; }
  .sidebar-overlay { display: none !important; }
  .bottom-nav { display: none !important; }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-muted); }

/* ---- Selection ---- */
::selection { background: rgba(44,85,69,0.15); }

/* ---- Search Input ---- */
.search-input-wrap {
  position: relative;
}
.search-input-wrap .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-muted);
}
.search-input-wrap input {
  padding-left: 36px;
}

/* ---- Toggle ---- */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}
.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--cream-dark);
  border-radius: 12px;
  cursor: pointer;
  transition: background var(--transition);
  border: none;
}
.toggle.active { background: var(--forest); }
.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--white);
  border-radius: 50%;
  transition: transform var(--transition);
}
.toggle.active::after { transform: translateX(20px); }
.toggle-label { font-size: 0.88rem; }

