/* --- 頁面整體布局 --- */
#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;
}