/* Community · 方案 A (Supabase) — 与 portal 风格统一 */

.community-bar {
  position: sticky;
  top: 0;
  z-index: 900;
  background: rgba(255, 255, 255, 0.97);
  border-bottom: 1px solid var(--hairline, #d1e2ec);
  box-shadow: var(--shadow-xs, 0 1px 2px rgba(15, 34, 48, 0.06));
  backdrop-filter: blur(8px);
}

.community-bar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 10px 32px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.community-bar-status {
  font-size: 0.76rem;
  color: var(--ink-muted, #69757f);
  margin-right: auto;
}

.community-bar-status.is-error {
  color: #b45309;
}

.community-bar-status[hidden] {
  display: none;
}

.community-login-actions[hidden] {
  display: none !important;
}

.community-bar--logged-out .community-user {
  display: none !important;
}

.community-bar--logged-out .community-user-meta,
.community-bar--logged-out #community-logout {
  display: none !important;
}

.community-bar--logged-in .community-login-actions {
  display: none !important;
}

.community-bar-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.community-login-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.community-user {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.community-user-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.community-subscribe-trigger {
  flex-shrink: 0;
  gap: 5px;
  padding: 7px 12px;
  color: var(--ink-soft, #3c4b57);
}

.community-subscribe-trigger:hover:not(:disabled) {
  color: var(--accent-dark, #0a5c72);
}

.community-subscribe-trigger.is-subscribed {
  color: var(--accent-dark, #0a5c72);
  background: var(--accent-soft, #e6f3f8);
  border-color: rgba(13, 124, 150, 0.35);
}

.community-subscribe-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  display: block;
}

.community-subscribe-label {
  line-height: 1;
}

.community-avatar-slot {
  position: relative;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
}

.community-avatar,
.community-avatar-fallback {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--hairline, #d1e2ec);
}

.community-avatar {
  display: block;
  object-fit: cover;
  background: var(--paper, #f1f6fa);
}

.community-avatar[hidden] {
  display: none !important;
}

.community-avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  color: var(--accent-dark, #0a5c72);
  background: var(--accent-soft, #e6f3f8);
  text-transform: uppercase;
}

.community-avatar-fallback[hidden] {
  display: none !important;
}

.community-login-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft, #3c4b57);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.community-btn {
  appearance: none;
  -webkit-appearance: none;
  font-family: var(--font-ui, sans-serif);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.2;
  border-radius: var(--radius-pill, 999px);
  padding: 7px 14px;
  cursor: pointer;
  border: 1px solid var(--hairline, #d1e2ec);
  background: var(--surface, #fff);
  color: var(--ink-soft, #3c4b57);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.2s var(--ease, ease), border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}

.community-btn:hover:not(:disabled) {
  background: var(--accent-soft, #e6f3f8);
  border-color: rgba(13, 124, 150, 0.35);
}

.community-btn--primary {
  color: #fff;
  background: var(--gradient-primary, linear-gradient(135deg, #0a6680 0%, #0d7c96 55%, #18a0bd 100%));
  border-color: transparent;
  padding-left: 12px;
}

.community-btn--primary:hover:not(:disabled) {
  color: #fff;
  box-shadow: 0 4px 14px rgba(13, 124, 150, 0.35);
  transform: translateY(-1px);
}

.community-github-mark {
  width: 16px;
  height: 16px;
  fill: currentColor;
  flex-shrink: 0;
}

.community-btn--ghost {
  background: transparent;
}

.community-btn--pulse {
  animation: community-pulse 0.8s ease 2;
}

@keyframes community-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(13, 124, 150, 0.45); }
  50% { box-shadow: 0 0 0 8px rgba(13, 124, 150, 0); }
}

.community-btn.is-active {
  color: var(--accent-dark, #0a5c72);
  background: var(--accent-soft, #e6f3f8);
  border-color: rgba(13, 124, 150, 0.4);
}

.community-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* 文献卡片 · 已读圆形印章（登录用户确认读完） */
.paper-read-stamp {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  pointer-events: none;
  transform: rotate(-12deg);
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border: 2px solid rgba(13, 124, 150, 0.72);
  border-radius: 50%;
  color: rgba(10, 92, 114, 0.9);
  font-family: var(--font-serif, "Noto Serif SC", serif);
  font-size: 0.58rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.1em;
  text-indent: 0.1em;
  white-space: nowrap;
  background: rgba(230, 243, 248, 0.78);
  box-shadow:
    inset 0 0 0 1.5px rgba(24, 160, 189, 0.22),
    0 0 0 1px rgba(255, 255, 255, 0.55);
  opacity: 0.93;
  mix-blend-mode: multiply;
}

.paper-read-stamp::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(13, 124, 150, 0.38);
  border-radius: 50%;
  pointer-events: none;
}

.paper-read-stamp[hidden] {
  display: none;
}

.paper-card--read .paper-card-body::before {
  opacity: 0.32;
}

/* 文献卡片右侧互动区 */
.paper-card-tools {
  width: 100%;
}

.paper-engagement .community-action,
.paper-engagement .community-stat {
  position: relative;
}

.paper-card-action .community-action.community-stat {
  pointer-events: auto;
  cursor: default;
}

.community-action-tip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.2;
  color: #e8f4fa;
  background: #0f2230;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s var(--ease, ease), transform 0.2s var(--ease, ease), visibility 0.2s;
  z-index: 20;
  box-shadow: 0 4px 12px rgba(15, 34, 48, 0.18);
}

.community-action-tip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #0f2230;
}

.paper-engagement .community-action:hover .community-action-tip,
.paper-engagement .community-action:focus-visible .community-action-tip,
.paper-engagement .community-stat:hover .community-action-tip {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.paper-engagement {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: stretch;
  gap: 6px;
  width: 100%;
}

.community-action.community-stat {
  pointer-events: none;
  cursor: default;
}

.community-action.community-stat:hover {
  transform: none;
  border-color: rgba(13, 124, 150, 0.16);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 2px 8px rgba(15, 34, 48, 0.06);
}

.paper-engagement .community-action,
.paper-engagement .community-stat {
  flex: unset;
  min-width: 0;
  padding: 4px 2px;
  gap: 4px;
  border-radius: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}

.paper-engagement .community-action:hover:not(:disabled) {
  background: transparent;
  border: none;
  box-shadow: none;
  transform: none;
  color: var(--accent, #0d7c96);
}

.paper-engagement .community-action.community-stat:hover {
  background: transparent;
  border: none;
  box-shadow: none;
  color: inherit;
}

.paper-engagement .community-action-icon-wrap {
  width: auto;
  height: auto;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.paper-engagement .community-action-icon {
  width: 20px;
  height: 20px;
}

.paper-engagement .community-count {
  font-size: 0.72rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.community-count {
  min-width: 1em;
  max-width: 100%;
  padding-right: 0;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  line-height: 1;
  color: var(--ink-soft, #3c4b57);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.community-action {
  appearance: none;
  -webkit-appearance: none;
  font-family: var(--font-ui, sans-serif);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  padding: 8px 6px;
  border-radius: 14px;
  cursor: pointer;
  border: 1px solid rgba(13, 124, 150, 0.16);
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink-muted, #69757f);
  box-shadow: 0 2px 8px rgba(15, 34, 48, 0.06);
  transition: background 0.2s var(--ease, ease), border-color 0.2s, box-shadow 0.2s, transform 0.15s, color 0.2s;
}

.community-action:hover:not(:disabled) {
  border-color: rgba(13, 124, 150, 0.32);
  background: #fff;
  box-shadow: 0 4px 14px rgba(13, 124, 150, 0.12);
  transform: translateY(-1px);
}

.community-action:active:not(:disabled) {
  transform: translateY(0);
}

.community-action-icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: transparent;
  border: none;
  transition: color 0.2s;
}

.community-action-icon {
  width: 20px;
  height: 20px;
  display: block;
}

.community-action-icon--filled {
  display: none;
}

.paper-share-btn.community-action:hover:not(:disabled) {
  color: var(--accent-dark, #0a5c72);
}

.paper-share-btn.community-action:hover:not(:disabled) .community-action-icon-wrap {
  color: inherit;
}

/* 点赞 · 大拇指 */
.community-like[aria-pressed="true"] {
  color: var(--accent-dark, #0a5c72);
  border-color: rgba(13, 124, 150, 0.35);
  background: linear-gradient(180deg, #eef8fb 0%, #e6f3f8 100%);
  box-shadow: 0 4px 14px rgba(13, 124, 150, 0.14);
}

.paper-engagement .community-like[aria-pressed="true"] {
  background: transparent;
  border: none;
  box-shadow: none;
}

.community-like[aria-pressed="true"] .community-action-icon-wrap {
  background: transparent;
  border: none;
  color: var(--accent-dark, #0a5c72);
  box-shadow: none;
}

.community-like[aria-pressed="true"] .community-action-icon--outline {
  display: none;
}

.community-like[aria-pressed="true"] .community-action-icon--filled {
  display: block;
}

.community-like[aria-pressed="true"] .community-count {
  color: var(--accent-dark, #0a5c72);
}

/* 收藏 · 星号 */
.community-favorite[aria-pressed="true"] {
  color: #b45309;
  border-color: rgba(245, 158, 11, 0.35);
  background: linear-gradient(180deg, #fffbeb 0%, #fef3c7 100%);
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.16);
}

.paper-engagement .community-favorite[aria-pressed="true"] {
  background: transparent;
  border: none;
  box-shadow: none;
}

.community-favorite[aria-pressed="true"] .community-action-icon-wrap {
  background: transparent;
  border: none;
  color: #f59e0b;
  box-shadow: none;
}

.community-favorite[aria-pressed="true"] .community-action-icon--outline {
  display: none;
}

.community-favorite[aria-pressed="true"] .community-action-icon--filled {
  display: block;
}

.community-favorite[aria-pressed="true"] .community-count {
  color: #b45309;
}

.paper-list.is-sorted-hot {
  display: flex;
  flex-direction: column;
}

.community-toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(12px);
  z-index: 3000;
  background: #0f2230;
  color: #e8f4fa;
  font-size: 0.82rem;
  padding: 10px 18px;
  border-radius: var(--radius-pill, 999px);
  box-shadow: var(--shadow-md, 0 12px 32px rgba(15, 34, 48, 0.2));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  max-width: min(92vw, 420px);
  text-align: center;
}

.community-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* 阅读页顶栏 */
.content-topbar .community-bar {
  position: static;
  border: none;
  box-shadow: none;
  background: transparent;
  margin-bottom: 4px;
}

.content-topbar .community-bar-inner {
  padding: 0;
  justify-content: flex-start;
}

@media (max-width: 720px) {
  .community-bar-inner {
    padding: 8px 18px;
  }
  .community-login-name {
    max-width: 88px;
  }
}

/* Login modal */
.community-btn--block {
  width: 100%;
  justify-content: center;
}

.community-btn--github {
  color: #fff;
  background: #24292f;
  border-color: transparent;
}

.community-btn--github:hover:not(:disabled) {
  color: #fff;
  background: #1b1f23;
  box-shadow: 0 4px 14px rgba(36, 41, 47, 0.35);
}

.community-login-modal,
.community-subscribe-modal {
  position: fixed;
  inset: 0;
  z-index: 4000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.community-login-modal[hidden],
.community-subscribe-modal[hidden] {
  display: none;
}

.community-login-modal-backdrop,
.community-subscribe-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 34, 48, 0.45);
}

.community-login-modal-panel {
  position: relative;
  width: min(100%, 400px);
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--hairline, #d1e2ec);
  box-shadow: 0 20px 48px rgba(15, 34, 48, 0.18);
  padding: 28px 24px 24px;
}

.community-subscribe-modal-panel {
  position: relative;
  width: min(100%, 468px);
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--hairline, #d1e2ec);
  box-shadow: 0 20px 48px rgba(15, 34, 48, 0.18);
  padding: 28px 24px 24px;
}

.community-login-modal-close,
.community-subscribe-modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--ink-muted, #69757f);
  cursor: pointer;
}

.community-login-modal-title,
.community-subscribe-modal-title {
  margin: 0 0 8px;
  font-size: 1.15rem;
  color: var(--ink, #0f2230);
}

.community-login-modal-desc,
.community-subscribe-modal-desc {
  margin: 0 0 18px;
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--ink-muted, #69757f);
}

.community-subscribe-modal-desc[hidden] {
  display: none;
}

.community-login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--ink-muted, #69757f);
  font-size: 0.78rem;
}

.community-login-divider::before,
.community-login-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--hairline, #d1e2ec);
}

.community-login-email-form,
.email-subscribe-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.community-login-email-input,
.email-subscribe-input {
  width: 100%;
  box-sizing: border-box;
  font-family: var(--font-ui, sans-serif);
  font-size: 0.88rem;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--hairline, #d1e2ec);
  background: #fff;
  color: var(--ink, #0f2230);
}

.community-login-email-input:focus,
.email-subscribe-input:focus {
  outline: none;
  border-color: rgba(13, 124, 150, 0.55);
  box-shadow: 0 0 0 3px rgba(13, 124, 150, 0.12);
}

.community-login-modal-msg,
.email-subscribe-msg {
  margin: 12px 0 0;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--accent-dark, #0a5c72);
}

.community-login-modal-msg.is-error,
.email-subscribe-msg.is-error {
  color: #b45309;
}

.community-login-modal-msg[hidden],
.email-subscribe-msg[hidden] {
  display: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Email subscribe modal */
.email-subscribe-form[hidden],
.email-subscribe-active[hidden] {
  display: none !important;
}

.email-subscribe-active {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.email-subscribe-status {
  width: 100%;
  box-sizing: border-box;
  padding: 12px 14px;
  border-radius: var(--radius-sm, 12px);
  background: var(--accent-soft, #e6f3f8);
  border: 1px solid rgba(13, 124, 150, 0.22);
  color: var(--ink-soft, #3c4b57);
}

.email-subscribe-status-main {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.email-subscribe-unsubscribe {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  padding: 4px 8px;
  border: none;
  background: transparent;
  font-family: var(--font-ui, sans-serif);
  font-size: 0.74rem;
  font-weight: 500;
  line-height: 1.3;
  color: var(--ink-muted, #69757f);
  cursor: pointer;
  opacity: 0.85;
  transition: color 0.15s ease, opacity 0.15s ease;
}

.email-subscribe-unsubscribe:hover:not(:disabled) {
  color: #b45309;
  opacity: 1;
}

.email-subscribe-unsubscribe:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.email-subscribe-status-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  color: var(--accent-dark, #0a5c72);
  background: #fff;
}

.email-subscribe-status-text {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.5;
}

.email-subscribe-status-text strong {
  font-weight: 600;
  color: var(--ink, #0f2230);
  word-break: break-all;
}
