/* ══════════════════════════════════════
   Components — Cards · Reactions · Badges
   ══════════════════════════════════════ */

/* ── Pull to refresh ── */
.ptr-spacer {
  flex-shrink: 0;
  height: 0;
  overflow: hidden;
}

.ptr-slot {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 10px;
  gap: 6px;
  pointer-events: none;
  z-index: 80;
  box-sizing: border-box;
}

.ptr-spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.12s, transform 0.12s;
  flex-shrink: 0;
}

.ptr-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  opacity: 0;
  transition: opacity 0.12s;
  line-height: 1;
}

.ptr-slot.ptr-active .ptr-spinner {
  opacity: 1;
  transform: scale(1);
}

.ptr-slot.ptr-refreshing .ptr-spinner {
  animation: ptr-spin 0.75s linear infinite;
}

.ptr-slot.ptr-refreshing .ptr-label {
  opacity: 1;
}

.list-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 56px 16px 72px;
}

/* Full-page refresh overlay (profile pull-to-refresh) */
.page-refresh-loading {
  position: absolute;
  inset: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(13, 13, 13, 0.72);
  pointer-events: none;
}

.page-refresh-loading-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ptr-spin 0.75s linear infinite;
}

.page-refresh-loading-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

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

/* ── Page Header ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(16px + var(--safe-top)) var(--space-md) 12px;
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-base);
  border-bottom: 1px solid var(--border-soft);
}

.page-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.page-title span {
  color: var(--accent);
}

/* ── Filter Tabs ── */
.filter-tabs {
  display: flex;
  gap: 8px;
  padding: 10px var(--space-md);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  background: var(--bg-base);
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 61px;
  z-index: 40;
}

.filter-tabs::-webkit-scrollbar { display: none; }

.filter-chip {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: all 0.15s;
  cursor: pointer;
}

.filter-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Post Card ── */
.post-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 16px;
  margin: 8px var(--space-md);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s;
  overflow-x: clip;
  overflow-y: visible;
}

.post-card-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
  position: relative;
  padding-right: 28px;
}

.post-avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  color: var(--text-secondary);
  flex-shrink: 0;
  overflow: hidden;
}

.post-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.post-meta {
  flex: 1;
  min-width: 0;
}

.post-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.post-time {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 1px;
}

/* ── Category Badge ── */
.cat-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.cat-badge[data-cat="學業"] { background: rgba(124, 58, 237, 0.15); color: #a78bfa; }
.cat-badge[data-cat="生活"] { background: rgba(14, 165, 233, 0.15); color: #38bdf8; }
.cat-badge[data-cat="感情"] { background: rgba(236, 72, 153, 0.15); color: #f472b6; }
.cat-badge[data-cat="打工"] { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.cat-badge[data-cat="健康"] { background: rgba(16, 185, 129, 0.15); color: #34d399; }

/* ── Post Content ── */
.post-content {
  font-size: 16px;
  line-height: 1.65;
  color: var(--text-primary);
  margin-bottom: 16px;
  word-break: break-word;
}

.post-rating-section {
  margin-bottom: 14px;
  overflow: visible;
}

/* ── Post Action Row（拍拍 / 留言，靠左小膠囊） ── */
.post-action-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.post-action-pill {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
  user-select: none;
}

.post-action-pill svg {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
}

.post-action-pill-num {
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.post-action-pill:active:not(.pat-pop) {
  transform: scale(0.97);
}

.post-action-pill.pat-btn {
  position: relative;
  overflow: visible;
}

.post-action-pill.pat-btn.patted {
  background: rgba(251, 113, 133, 0.12);
  border-color: rgba(251, 113, 133, 0.45);
  color: #fb7185;
}

.post-action-pill.comment-btn:hover {
  border-color: rgba(168, 85, 247, 0.45);
  color: #c084fc;
}

/* legacy action-btn（其他頁可能仍用） */
.action-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 6px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-tertiary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
  user-select: none;
  white-space: nowrap;
  line-height: 1;
}

.action-btn svg { flex-shrink: 0; }
.action-btn:active { transform: scale(0.93); }
.action-label { font-size: 12px; font-weight: 600; }
.action-count { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pat-btn.patted {
  background: rgba(251, 113, 133, 0.12);
  border-color: rgba(251, 113, 133, 0.45);
  color: #fb7185;
}

/* legacy — keep for any remaining usage */
.reaction-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.reaction-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid var(--border);
  color: var(--text-tertiary);
  background: transparent;
  user-select: none;
}

.reaction-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.reaction-btn .reaction-count {
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

/* ── Misery Rating Bar ── */
.rating-bar {
  margin: 0;
}

.rating-score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.rating-dots {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding: 6px 0 2px;
  overflow: visible;
}

.rating-dot {
  width: 34px;
  height: 34px;
  min-width: 34px;
  min-height: 34px;
  max-width: 34px;
  max-height: 34px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text-tertiary);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  flex: 0 0 auto;
  box-sizing: border-box;
  padding: 0;
}

.rating-dot:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.rating-dot.past {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  opacity: 0.5;
}

.rating-dot.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.25);
}

.rating-dot.rating-dot-pop {
  animation: ratingDotPop 0.4s cubic-bezier(0.34, 1.45, 0.64, 1);
}

.rating-meta-score.rating-meta-flash {
  animation: ratingMetaFlash 0.48s ease;
}

.pat-pop {
  animation: patPop 0.38s cubic-bezier(0.34, 1.5, 0.64, 1);
}

.pat-btn svg.pat-hand-wave {
  transform-origin: 65% 75%;
  animation: patHandWave 0.44s ease;
}

.pat-ring-fx {
  position: absolute;
  inset: -3px;
  border-radius: 999px;
  border: 2px solid rgba(251, 113, 133, 0.55);
  pointer-events: none;
  animation: patRingOut 0.52s ease-out forwards;
}

.pill-num-bump {
  display: inline-block;
  animation: pillNumBump 0.42s cubic-bezier(0.34, 1.55, 0.64, 1);
}

@keyframes patPop {
  0%   { transform: scale(1); }
  38%  { transform: scale(1.13); }
  68%  { transform: scale(0.97); }
  100% { transform: scale(1); }
}

@keyframes patHandWave {
  0%, 100% { transform: rotate(0deg) scale(1); }
  28%  { transform: rotate(-14deg) scale(1.12); }
  62%  { transform: rotate(10deg) scale(1.06); }
}

@keyframes patRingOut {
  0%   { transform: scale(0.85); opacity: 0.75; }
  100% { transform: scale(2.1); opacity: 0; }
}

@keyframes ratingDotPop {
  0%   { transform: scale(1); box-shadow: 0 0 0 0 rgba(230, 57, 70, 0.45); }
  42%  { transform: scale(1.16); box-shadow: 0 0 0 10px rgba(230, 57, 70, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(230, 57, 70, 0); }
}

@keyframes ratingMetaFlash {
  0%, 100% { transform: scale(1); }
  35%  { transform: scale(1.12); color: #ff6b6b; }
}

@keyframes pillNumBump {
  0%, 100% { transform: scale(1); }
  45%  { transform: scale(1.32); }
}

.rating-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
  text-align: right;
}

.rating-meta-score {
  font-size: 18px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.5px;
  line-height: 1.1;
}

.rating-meta-max {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-tertiary);
}

.rating-meta-count {
  font-size: 12px;
  color: var(--text-tertiary);
  font-weight: 600;
}

.rating-meta-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  font-weight: 500;
}

.rating-my-label {
  font-size: 11px;
  color: var(--accent);
  margin-top: 4px;
  font-weight: 600;
  opacity: 0.85;
}

.reaction-btn.comment-btn:active {
  border-color: rgba(168,85,247,0.5);
  color: #a855f7;
  background: rgba(168,85,247,0.08);
}

/* ── Rank Crown Card ── */
.rank-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 16px;
  margin: 8px var(--space-md);
  border: 1px solid var(--border-soft);
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.rank-card.rank-1 {
  border-color: rgba(244, 196, 48, 0.3);
  background: linear-gradient(135deg, var(--bg-card), rgba(244, 196, 48, 0.04));
}

.rank-badge {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  font-weight: 900;
  color: var(--text-tertiary);
}

.rank-badge.rank-1 { font-size: 24px; }
.rank-badge.rank-2 { color: #a3a3a3; font-size: 15px; }
.rank-badge.rank-3 { color: #92713a; font-size: 15px; }

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

.rank-user {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.rank-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
}

.rank-content {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 8px;
}

.rank-votes {
  font-size: 12px;
  color: var(--accent);
  font-weight: 700;
}

/* ── Empty State ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 32px;
  text-align: center;
  gap: 12px;
}

.empty-icon { font-size: 52px; line-height: 1; }

.empty-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
}

.empty-sub {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 240px;
}

/* ── Clickable Avatar ── */
.avatar-clickable {
  cursor: pointer;
}

.avatar-clickable:hover {
  opacity: 0.8;
}

/* Visually hidden file input — works on iOS (unlike [hidden]) */
.avatar-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

/* ── Profile Avatar ── */
.profile-avatar-block {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.profile-avatar-wrap {
  position: relative;
  width: 72px;
  height: 72px;
  flex-shrink: 0;
  overflow: visible;
  z-index: 2;
}

.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 800;
  color: var(--text-secondary);
  overflow: hidden;
  border: 3px solid var(--border);
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-avatar-wrap--clickable {
  cursor: pointer;
}

.profile-avatar-wrap--clickable .profile-avatar {
  cursor: pointer;
}

.profile-avatar-edit-btn {
  position: absolute;
  bottom: -4px;
  right: -4px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-base);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  color: #fff;
  z-index: 30;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.profile-avatar-edit-btn svg {
  width: 14px;
  height: 14px;
  pointer-events: none;
}

html.in-app .profile-avatar-wrap {
  cursor: pointer;
}

html.in-app .profile-change-avatar-hint {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-top: 6px;
  text-align: center;
  width: 72px;
  cursor: pointer;
  touch-action: manipulation;
}

.profile-bio {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 5px;
  line-height: 1.45;
}

/* ── Stats Row ── */
.stats-row {
  display: flex;
  gap: 1px;
  background: var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
}

.stat-cell {
  flex: 1;
  padding: 14px 8px;
  background: var(--bg-card);
  text-align: center;
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 4px;
}

.stat-value.crown { color: var(--crown); }
.stat-value.red   { color: var(--accent); }
.stat-value.blue  { color: var(--sympathy); }

.stat-label {
  font-size: 11px;
  color: var(--text-tertiary);
  font-weight: 500;
}

/* ── Settings Item ── */
.settings-group {
  margin: 0 var(--space-md) 16px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-soft);
  overflow: hidden;
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  cursor: pointer;
  transition: background 0.1s;
  gap: 12px;
}

.settings-item:not(:last-child) {
  border-bottom: 1px solid var(--border-soft);
}

.settings-item:active { background: var(--bg-elevated); }

.settings-item-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.settings-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}

.settings-item-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.settings-item-title--danger {
  color: #ef4444;
}

.settings-item--danger:active {
  background: rgba(239, 68, 68, 0.08);
}

.settings-item-sub {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 1px;
}

/* ── Toggle ── */
.toggle {
  width: 44px;
  height: 26px;
  border-radius: var(--radius-full);
  background: var(--border);
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle.on { background: var(--accent); }

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  background: #fff;
  transition: transform 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.toggle.on .toggle-thumb {
  transform: translateX(18px);
}

/* ── Section Label ── */
.section-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-tertiary);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 20px var(--space-md) 6px;
}

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--border-soft);
  margin: 0 var(--space-md);
}

/* ── Primary Button ── */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 15px;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  border: none;
  letter-spacing: 0.02em;
}

.btn-primary:active { opacity: 0.85; transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Text Button ── */
.btn-text {
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
}

/* ── Char Counter ── */
.char-counter {
  font-size: 12px;
  color: var(--text-tertiary);
  text-align: right;
  margin-top: 4px;
}

.char-counter.warn { color: var(--accent); }
