/* --- 页面整体布局 --- */
#moments-page {
  max-width: 750px; /* 减小页面最大宽度 */
  margin: 0 auto;
  padding: 0 1rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* 页面级别的图片样式重置 */
#moments-page img {
  border: none !important;
  outline: none !important;
  box-sizing: border-box;
}

#moments-page a {
  border: none !important;
  outline: none !important;
}

#moments-page a:focus {
  outline: none !important;
}

/* --- 时间线核心结构 --- */
#mastodon-timeline {
  position: relative;
  padding: 2rem 0 2rem 10px; /* 取消左侧padding */
}

/* 左侧时间线 */
#mastodon-timeline::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0; /* 取消左侧空间后，时间线贴齐容器左侧 */
  width: 3px;
  height: 100%;
  background: currentColor; /* 使用当前文字颜色 */
  opacity: 0.3; /* 添加透明度以保持视觉层次 */
  border-radius: 1.5px;
}

html[data-theme=dark] #mastodon-timeline::before {
  opacity: 0.4; /* 深色模式下稍微提高透明度 */
}

/* --- 单条动态卡片样式 --- */
.mastodon-post {
  position: relative;
  width: calc(100% - 40px); /* 减小卡片宽度，让连接点更靠近 */
  max-width: 500px; /* 限制最大宽度，使卡片更窄 */
  margin-bottom: 2.5rem;
  padding: 1.5rem;
  border-radius: 16px;
  transition: all 0.3s ease;
  cursor: pointer;
  margin-left: 40px;

  /* 加载动画 */
  opacity: 0;
  transform: translateY(20px) translateX(30px);
  animation: slideInRight 0.6s ease forwards;
  animation-fill-mode: forwards;
}



/* --- 时间线连接点 --- */
.mastodon-post::after {
  content: '';
  position: absolute;
  top: 1.5rem; /* 调整到卡片内容位置 */
  left: -60px; /* 调整连接点位置，更靠近卡片 */
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid currentColor; /* 使用当前文字颜色 */
  opacity: 0.8;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  z-index: 2;
}

html[data-theme=dark] .mastodon-post::after {
  background: #2c2c2c;
  opacity: 0.9;
}

/* --- 动态内容样式 --- */
/* 帖子内容区域 */
.post-content {
  color: #333;
  word-wrap: break-word;
  font-size: 1rem;
  line-height: 1.6;
  margin-bottom: 1rem;
}

html[data-theme=dark] .post-content { 
  color: #ddd; 
}

.post-content p { 
  margin: 0 0 1em 0; 
}

.post-content a { 
  color: #2196F3; 
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-bottom 0.3s ease;
}

.post-content a:hover { 
  border-bottom: 1px solid #2196F3;
}

html[data-theme=dark] .post-content a {
  color: #64b5f6;
}

html[data-theme=dark] .post-content a:hover {
  border-bottom-color: #64b5f6;
}

/* 图片附件样式 */
.media-attachments {
  margin-top: 1.5rem;
  display: grid;
  gap: 8px;
  border-radius: 12px;
  overflow: hidden;
  max-width: 100%;
  border: none; /* 确保容器没有边框 */
  background: transparent; /* 确保背景透明 */
}

/* 单张图片 - 保持原始比例 */
.media-attachments:has(img:only-child) {
  grid-template-columns: 1fr;
  max-width: 500px;
}

.media-attachments:has(img:only-child) img {
  height: auto;
  max-height: 300px;
  object-fit: scale-down;
  background-color: transparent;
}

/* 两张图片 - 并排显示，等高 */
.media-attachments:has(img:nth-child(2):last-child) {
  grid-template-columns: 1fr 1fr;
  max-height: 280px;
}

.media-attachments:has(img:nth-child(2):last-child) img {
  height: 280px;
  object-fit: cover;
}

/* 三张图片 - 大图+两小图布局 */
.media-attachments:has(img:nth-child(3):last-child) {
  grid-template-columns: 2fr 1fr;
  grid-template-rows: 1fr 1fr;
  max-height: 280px;
}

.media-attachments:has(img:nth-child(3):last-child) img:first-child {
  grid-row: span 2;
  height: 280px;
  object-fit: cover;
}

.media-attachments:has(img:nth-child(3):last-child) img:not(:first-child) {
  height: 136px;
  object-fit: cover;
}

/* 四张图片 - 2x2 均匀网格 */
.media-attachments:has(img:nth-child(4):last-child) {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  max-height: 280px;
}

.media-attachments:has(img:nth-child(4):last-child) img {
  height: 136px;
  object-fit: cover;
}

/* 五张图片 - 上2下3布局 */
.media-attachments:has(img:nth-child(5):last-child) {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: auto auto;
  max-height: 280px;
}

.media-attachments:has(img:nth-child(5):last-child) img:nth-child(-n+2) {
  grid-column: span 1.5;
  height: 136px;
  object-fit: cover;
}

.media-attachments:has(img:nth-child(5):last-child) img:nth-child(n+3) {
  height: 136px;
  object-fit: cover;
}

/* 六张及以上图片 - 3列网格 */
.media-attachments:has(img:nth-child(n+6)) {
  grid-template-columns: repeat(3, 1fr);
  max-height: 300px;
}

.media-attachments:has(img:nth-child(n+6)) img {
  height: 92px;
  object-fit: cover;
}

/* 超过9张图片时显示数量提示 */
.media-attachments img[data-count] {
  position: relative;
}

.media-attachments img[data-count]::after {
  content: '+' attr(data-count);
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5em;
  font-weight: bold;
  border-radius: 8px;
}

/* 降级支持 - 当浏览器不支持 :has() 选择器时 */
@supports not selector(:has(*)) {
  .media-attachments {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    max-height: 300px;
  }
  
  .media-attachments img {
    height: 120px;
    object-fit: cover;
  }
}

/* 基础图片样式 */
.media-attachments img {
  width: 100%;
  border-radius: 8px;
  background-color: transparent;
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
  cursor: pointer;
  display: block;
  border: none; /* 完全移除边框 */
  padding-bottom: 1rem;
}

/* 确保移除所有可能的图片边框和轮廓 */
.media-attachments img,
.media-attachments .media-link,
.media-attachments .media-link:focus,
.media-attachments .media-link:active,
.media-attachments .media-link:visited {
  border: none !important;
  outline: none !important;
  box-shadow: none; /* 移除默认阴影，只保留hover效果 */
}

.media-attachments img:focus {
  outline: none !important;
  border: none !important;
}

/* 重新定义hover效果，确保只有我们想要的阴影 */
.media-attachments img:hover {
  border: none !important;
  outline: none !important;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2) !important;
}

html[data-theme=dark] .media-attachments img:hover {
  border: none !important;
  outline: none !important;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4) !important;
}

/* 深色模式下的图片样式 */
html[data-theme=dark] .media-attachments img {
  background-color: transparent;
  border: none; /* 深色模式下也完全移除边框 */
}

html[data-theme=dark] .media-attachments img:hover {
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

/* 移动端优化 */
@media (max-width: 768px) {
  .media-attachments {
    gap: 6px;
  }
  
  /* 移动端三张图片改为竖向布局 */
  .media-attachments:has(img:nth-child(3):last-child) {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    max-height: none;
  }
  
  .media-attachments:has(img:nth-child(3):last-child) img:first-child {
    grid-row: span 1;
    height: 200px;
  }
  
  .media-attachments:has(img:nth-child(3):last-child) img:not(:first-child) {
    height: 150px;
  }
  
  /* 移动端四张图片保持2x2 */
  .media-attachments:has(img:nth-child(4):last-child) img {
    height: 120px;
  }
  
  /* 移动端五张及以上图片使用2列 */
  .media-attachments:has(img:nth-child(n+5)) {
    grid-template-columns: 1fr 1fr;
  }
  
  .media-attachments:has(img:nth-child(n+5)) img {
    height: 100px;
  }
  
  .media-attachments:has(img:nth-child(5):last-child) img:nth-child(-n+2) {
    grid-column: span 1;
  }
}


/* --- 加载提示、按钮等辅助样式 --- */
.timeline-loading { 
  display: flex; 
  justify-content: center; 
  align-items: center; 
  padding: 40px; 
  font-size: 1.2em; 
  color: #888; 
}

.timeline-loading .spinner { 
  border: 4px solid rgba(33, 150, 243, 0.1); 
  width: 36px; 
  height: 36px; 
  border-radius: 50%; 
  border-left-color: #2196F3; 
  margin-right: 10px; 
  animation: spin 1s ease infinite; 
}

#load-more-btn { 
  display: none; 
  margin: 20px auto; 
  padding: 1rem 2rem; 
  font-size: 1rem; 
  font-weight: 600; 
  cursor: pointer; 
  border: none; 
  border-radius: 12px; 
  background: linear-gradient(135deg, #2196F3, #64b5f6);
  color: white; 
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(33, 150, 243, 0.3);
}

#load-more-btn:hover { 
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(33, 150, 243, 0.4); 
}

.no-more-posts { 
  text-align: center; 
  padding: 20px; 
  color: #999; 
  font-style: italic;
}

/* --- 动画效果 --- */
@keyframes slideInRight { 
  to { 
    opacity: 1; 
    transform: translateY(0) translateX(0); 
  } 
}

@keyframes spin { 
  0% { transform: rotate(0deg); } 
  100% { transform: rotate(360deg); } 
}

.mastodon-post:nth-child(1) { animation-delay: 0.1s; }
.mastodon-post:nth-child(2) { animation-delay: 0.2s; }
.mastodon-post:nth-child(3) { animation-delay: 0.3s; }
.mastodon-post:nth-child(4) { animation-delay: 0.4s; }
.mastodon-post:nth-child(5) { animation-delay: 0.5s; }
.mastodon-post:nth-child(6) { animation-delay: 0.6s; }
.mastodon-post:nth-child(7) { animation-delay: 0.7s; }
.mastodon-post:nth-child(8) { animation-delay: 0.8s; }

/* --- 响应式设计 (手机端) --- */
@media (max-width: 768px) {
  #moments-page {
    padding: 0rem 0.5rem;
  }
  
  #mastodon-timeline {
    padding: 0rem 0; /* 移除左侧padding */
  }
  
  .mastodon-post {
    width: calc(100%); /* 考虑到父容器的padding，避免溢出 */
    max-width: none; /* 移除最大宽度限制 */
    margin-left: 0; /* 移除左边距 */
    margin-right: 0; /* 确保右边距为0 */
    padding: 1rem;
    margin-bottom: 1rem;
    box-sizing: border-box; /* 确保padding包含在宽度内 */
  }
  
  /* 移动端完全隐藏时间线和连接点 */
  #mastodon-timeline::before {
    display: none;
  }
  .mastodon-post::after { 
    display: none;
  }
  .mastodon-post::before {
    display: none;
  }
  
  .media-attachments {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
  }
  
  .media-attachments img {
    max-height: 250px; /* 移动端适当减小最大高度 */
    border-radius: 8px;
  }
}

/* 图片预览模态框样式 */
.image-preview-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  cursor: pointer;
}

.modal-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.modal-close {
  position: absolute;
  top: -40px;
  right: 0;
  background: none;
  border: none;
  color: white;
  font-size: 2em;
  cursor: pointer;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background-color 0.2s ease;
}

.modal-close:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

.modal-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.5);
  border: none;
  color: white;
  font-size: 2em;
  cursor: pointer;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease;
  user-select: none;
}

.modal-nav:hover {
  background: rgba(0, 0, 0, 0.8);
}

.modal-prev {
  left: -70px;
}

.modal-next {
  right: -70px;
}

.modal-counter {
  position: absolute;
  bottom: -40px;
  left: 50%;
  transform: translateX(-50%);
  color: white;
  background: rgba(0, 0, 0, 0.7);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.9em;
  white-space: nowrap;
}

/* 移动端模态框优化 */
@media (max-width: 768px) {
  .modal-close {
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.7);
  }
  
  .modal-nav {
    width: 40px;
    height: 40px;
    font-size: 1.5em;
  }
  
  .modal-prev {
    left: 20px;
  }
  
  .modal-next {
    right: 20px;
  }
  
  .modal-counter {
    bottom: 20px;
    font-size: 0.8em;
    padding: 6px 12px;
  }
}

/* 媒体链接样式优化 */
.media-attachments .media-link {
  display: block;
  text-decoration: none;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  border: none; /* 移除链接边框 */
  outline: none; /* 移除焦点轮廓 */
  background: transparent; /* 确保背景透明 */
}

.media-attachments .media-link:hover {
  transform: none; /* 移除链接本身的变换，让图片处理 */
}

.media-attachments .media-link:focus {
  outline: none; /* 移除焦点时的轮廓 */
}

/* 图片加载失败时的占位样式 */
.media-attachments img[style*="display: none"] + .image-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-color);
  border: 2px dashed var(--border-color);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 0.9em;
  min-height: 100px;
}

.media-attachments img[style*="display: none"] + .image-placeholder::before {
  content: "图片加载失败";
}

/* 加载动画 */
@keyframes imageLoading {
  0% { opacity: 0.7; }
  50% { opacity: 0.3; }
  100% { opacity: 0.7; }
}

.media-attachments img[loading="lazy"] {
  animation: imageLoading 1.5s ease-in-out infinite;
}

.media-attachments img[loading="lazy"].loaded {
  animation: none;
}

/* 卡片内时间显示 */
.post-date {
  display: block;
  font-size: 0.85rem;
  color: currentColor;
  opacity: 0.7;
  margin-bottom: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.5px;
  white-space: nowrap; /* 防止换行 */
  overflow: hidden; /* 隐藏溢出内容 */
  text-overflow: ellipsis; /* 用省略号表示截断 */
  width: 100%; /* 确保有足够宽度 */
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace; /* 使用等宽字体 */
}

html[data-theme=dark] .post-date {
  opacity: 0.8;
}

/* --- 页面描述样式 --- */
.moments-description {
  text-align: center;
  margin-top: -5px; /* 减少与标题的间距 */
  margin-bottom: 0;
  font-size: 0.95rem;
  line-height: 1.4; /* 减小行距 */
  color: currentColor;
  opacity: 0.8;
}

.moments-description p {
  margin: 0 0 0.4em 0; /* 减少段落间距 */
}

.moments-description p:last-child {
  margin-bottom: 0;
}

html[data-theme=dark] .moments-description {
  opacity: 0.9;
}

/* 移动端描述优化 */
@media (max-width: 768px) {
  .moments-description {
    font-size: 0.9rem;
    padding: 0 1rem;
    margin-top: -2px;
  }
}

/* 转发内容样式 */

.reblog-header {
  display: flex;
  align-items: center;
  margin-bottom: 0.8rem;
  padding: 0.5rem 0.8rem;
  background: rgba(29, 161, 242, 0.1);
  border-radius: 8px;
  font-size: 0.9rem;
  color: #1DA1F2;
  border: 1px solid rgba(29, 161, 242, 0.2);
}

html[data-theme=dark] .reblog-header {
  background: rgba(29, 161, 242, 0.15);
  border-color: rgba(29, 161, 242, 0.3);
}

.reblog-icon {
  margin-right: 0.5rem;
  font-size: 1em;
}

.reblog-text {
  font-weight: 500;
  opacity: 0.9;
}