
/* ============================================
   GLOBAL TOP SPACE FIX - 徹底修復手機端頂部空白
   ============================================ */
@media (max-width: 980px) {
  /* 強制重置所有可能造成頂部空白的元素 */
  html, body.app-body {
    margin: 0 !important;
    padding: 0 !important;
    padding-top: 0 !important;
  }

  /* Header 強制固定高度，避免 sticky 造成空白 */
  .site-header {
    position: relative !important;
    height: 56px !important;
    min-height: 56px !important;
    max-height: 56px !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
  }

  .site-header::after {
    display: none !important;
  }

  .header-inner {
    height: 56px !important;
    min-height: 56px !important;
    max-height: 56px !important;
    padding: 0 12px !important;
    margin: 0 !important;
  }

  /* 主內容區域 - 消除所有頂部空白 */
  .wrap,
  .shell {
    margin: 0 !important;
    padding: 0 !important;
    padding-top: 0 !important;
    margin-top: 0 !important;
  }

  .wrap.shell {
    padding: 12px !important;
    padding-top: 12px !important;
  }

  main {
    margin: 0 !important;
    padding: 0 !important;
    padding-top: 0 !important;
    margin-top: 0 !important;
  }

  /* main 的第一個子元素消除頂部 margin */
  main > *:first-child {
    margin-top: 0 !important;
    padding-top: 0 !important;
  }

  /* 麵包屑消除頂部空間 */
  .breadcrumb,
  .crumbs,
  nav[class*="crumb"] {
    margin: 0 0 8px 0 !important;
    padding: 0 !important;
  }

  /* 頁面標題消除頂部空間 */
  .page-title,
  h1.page-title {
    margin-top: 0 !important;
    padding-top: 0 !important;
  }

  /* 閃爍消息 */
  .flash {
    margin-top: 0 !important;
    margin-bottom: 10px !important;
  }

  /* 側邊欄頂部位置修正 */
  .sidebar {
    inset: 56px auto 0 0 !important;
    height: calc(100vh - 56px) !important;
  }

  /* 閱讀進度條 */
  .reading-progress {
    top: 0 !important;
  }

  /* Hero 區域手機端不要太高 */
  .hero {
    min-height: auto !important;
    max-height: 200px !important;
    margin-bottom: 12px !important;
  }

  .hero-inner {
    padding: 20px 16px !important;
  }
}

/* 小手機額外優化 */
@media (max-width: 480px) {
  .wrap.shell {
    padding: 10px !important;
  }
}

/* ============================================
   自由人的天空 - 手機端優化CSS
   修復頂部留白、響應式設計、觸控優化
   ============================================ */

/* --- 基礎重置 --- */
* {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body.app-body {
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* --- 修復頂部留白 --- */
.site-header {
  height: auto !important;
  min-height: 56px;
}

.header-inner {
  height: 56px !important;
  padding: 0 12px;
  gap: 8px;
}

/* 品牌標誌手機端縮小 */
.brand-mark {
  width: 36px !important;
  height: 36px !important;
  font-size: 14px;
}

.brand-title {
  font-size: 20px !important;
}

.brand-sub {
  display: none !important;
}

/* 主內容區域 - 消除頂部多餘留白 */
.shell {
  padding-top: 0 !important;
  margin-top: 0 !important;
}

main {
  padding-top: 0 !important;
  margin-top: 0 !important;
}

/* Hero區域手機端優化 */
.hero {
  min-height: auto !important;
  max-height: 280px;
  overflow: hidden;
}

.hero-inner {
  padding: 24px 18px !important;
  max-width: 100% !important;
}

.hero h2 {
  font-size: 24px !important;
  margin-bottom: 8px !important;
  line-height: 1.3 !important;
}

.hero p {
  font-size: 14px !important;
  line-height: 1.7 !important;
  margin-bottom: 0 !important;
}

.hero-actions {
  margin-top: 14px !important;
  gap: 8px !important;
}

.hero-actions .btn {
  padding: 8px 16px !important;
  font-size: 13px !important;
}

/* --- 文章卡片手機端優化 --- */
.article-card,
.card {
  border-radius: 14px !important;
  margin-bottom: 14px !important;
  overflow: hidden;
}

.article-card .cover,
.card .cover {
  height: 160px !important;
  min-height: 160px !important;
}

.article-card .content,
.card .content {
  padding: 14px !important;
}

.article-card h3,
.card h3 {
  font-size: 16px !important;
  line-height: 1.4 !important;
  margin-bottom: 6px !important;
}

.article-card .excerpt,
.card .excerpt {
  font-size: 13px !important;
  line-height: 1.6 !important;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.article-card .meta,
.card .meta {
  font-size: 11px !important;
  margin-top: 8px !important;
  flex-wrap: wrap;
  gap: 6px;
}

/* --- 文章詳情頁手機端優化 --- */
/* 修復文章封面過高導致頂部空白 */
.article-cover {
  max-height: 220px !important;
  height: 220px !important;
  overflow: hidden !important;
  position: relative;
}

.article-cover img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  object-position: center !important;
  display: block;
}

.article-cover .category-badge,
.article-cover span {
  position: absolute !important;
  top: 12px !important;
  left: 12px !important;
  z-index: 2;
}

.article-body {
  padding: 16px !important;
}

.article-body .page-title {
  font-size: 20px !important;
  line-height: 1.4 !important;
  margin-bottom: 10px !important;
}

/* 麵包屑手機端優化 */
.breadcrumb,
.crumbs {
  margin-bottom: 8px !important;
  font-size: 12px !important;
  padding: 0 !important;
}

.article-header {
  padding: 20px 0 14px !important;
}

.article-header h1 {
  font-size: 22px !important;
  line-height: 1.35 !important;
  margin-bottom: 10px !important;
}

.article-meta {
  font-size: 12px !important;
  flex-wrap: wrap;
  gap: 8px;
}

.article-hero {
  border-radius: 14px !important;
  margin-bottom: 18px !important;
}

.prose {
  font-size: 15px !important;
  line-height: 1.85 !important;
}

.prose h2 {
  font-size: 18px !important;
  margin: 24px 0 12px !important;
  padding-bottom: 8px !important;
}

.prose h3 {
  font-size: 16px !important;
  margin: 20px 0 10px !important;
}

.prose p {
  margin-bottom: 14px !important;
}

.prose img {
  border-radius: 12px !important;
  margin: 16px 0 !important;
}

.prose blockquote {
  margin: 16px 0 !important;
  padding: 12px 16px !important;
  font-size: 14px !important;
  border-left-width: 3px !important;
}

.prose pre {
  font-size: 12px !important;
  padding: 12px !important;
  border-radius: 10px !important;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.prose code {
  font-size: 13px !important;
  padding: 2px 6px !important;
  border-radius: 4px !important;
}

/* --- 分享/喜歡區域手機端優化 --- */
.share-bar {
  padding: 14px 0 !important;
  flex-wrap: wrap !important;
  gap: 8px !important;
}

.share-bar a,
.share-bar button {
  flex: 1 1 auto;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.like-form {
  margin: 16px 0 !important;
}

.like-form button {
  min-height: 44px;
  padding: 10px 24px !important;
  font-size: 14px !important;
}

/* --- 相關文章手機端優化 --- */
.related-section {
  margin-top: 28px !important;
  padding-top: 20px !important;
}

.related-section h3 {
  font-size: 17px !important;
  margin-bottom: 14px !important;
}

.related-grid {
  grid-template-columns: 1fr !important;
  gap: 12px !important;
}

.related-card {
  padding: 12px !important;
  border-radius: 12px !important;
}

.related-card h4 {
  font-size: 14px !important;
  line-height: 1.4 !important;
}

/* --- 作者卡片手機端優化 --- */
.author-card {
  margin-top: 28px !important;
  padding: 18px !important;
  border-radius: 16px !important;
  text-align: center;
}

.author-card .avatar {
  width: 56px !important;
  height: 56px !important;
  margin: 0 auto 10px !important;
}

.author-card h4 {
  font-size: 16px !important;
  margin-bottom: 4px !important;
}

.author-card p {
  font-size: 13px !important;
  line-height: 1.6 !important;
}

/* --- 訂閱區域手機端優化 --- */
.subscribe-section {
  margin-top: 28px !important;
  padding: 24px 18px !important;
  border-radius: 18px !important;
}

.subscribe-section h3 {
  font-size: 18px !important;
  margin-bottom: 8px !important;
}

.subscribe-section p {
  font-size: 13px !important;
  margin-bottom: 16px !important;
}

.subscribe-form {
  flex-direction: column !important;
  gap: 8px !important;
}

.subscribe-form input {
  width: 100% !important;
  min-height: 44px;
  padding: 10px 14px !important;
  font-size: 14px !important;
  border-radius: 10px !important;
}

.subscribe-form button {
  width: 100% !important;
  min-height: 44px;
  padding: 10px 16px !important;
  font-size: 14px !important;
  border-radius: 10px !important;
}

/* --- 分頁手機端優化 --- */
.pager-row {
  margin-top: 24px !important;
  gap: 8px !important;
  flex-wrap: wrap;
  justify-content: center;
}

.pager-row a,
.pager-row span {
  min-width: 40px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px !important;
  font-size: 13px !important;
  border-radius: 10px !important;
}

/* --- 側邊欄手機端優化 --- */
.sidebar {
  inset: 56px auto 0 0 !important;
  height: calc(100vh - 56px) !important;
  width: min(88vw, 300px) !important;
  padding: 16px !important;
  border-radius: 0 16px 16px 0 !important;
}

.sidebar .profile {
  padding-bottom: 12px !important;
}

.sidebar .avatar-wrap {
  width: 56px !important;
  height: 56px !important;
  margin: 0 auto;
}

.sidebar .avatar-wrap img {
  width: 56px !important;
  height: 56px !important;
}

.sidebar h1 {
  font-size: 16px !important;
  text-align: center;
}

.side-nav {
  margin-top: 14px !important;
}

.side-nav a {
  min-height: 40px;
  padding: 8px 10px !important;
  font-size: 14px !important;
  border-radius: 10px !important;
}

.side-nav .label {
  font-size: 11px !important;
  padding: 8px 10px 4px !important;
  letter-spacing: 0.08em;
}

.search-box {
  margin: 14px 0 !important;
}

.search-box input {
  min-height: 40px;
  font-size: 14px !important;
  padding: 8px 12px !important;
  border-radius: 10px 0 0 10px !important;
}

.search-box button {
  min-width: 40px;
  min-height: 40px;
  border-radius: 0 10px 10px 0 !important;
}

/* --- 頁尾手機端優化 --- */
.site-footer {
  padding: 32px 0 20px !important;
  margin-top: 32px !important;
}

.foot-grid {
  gap: 20px !important;
  padding: 0 4px !important;
}

.foot-grid h3 {
  font-size: 18px !important;
  margin-bottom: 8px !important;
}

.foot-grid h4 {
  font-size: 14px !important;
  margin-bottom: 8px !important;
}

.foot-grid p {
  font-size: 13px !important;
  line-height: 1.7 !important;
}

.foot-grid a {
  font-size: 13px !important;
  line-height: 1.8 !important;
}

.foot-stats {
  font-size: 12px !important;
  margin-top: 8px !important;
}

.foot-copy {
  padding-top: 14px !important;
  margin-top: 20px !important;
  font-size: 12px !important;
  text-align: center;
  justify-content: center !important;
}

/* --- 回到頂部按鈕手機端優化 --- */
.to-top {
  width: 44px !important;
  height: 44px !important;
  right: 16px !important;
  bottom: 16px !important;
  border-radius: 50% !important;
  font-size: 16px !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15) !important;
}

/* --- 閃爍消息手機端優化 --- */
.flash {
  padding: 12px 16px !important;
  border-radius: 10px !important;
  font-size: 13px !important;
  margin-bottom: 14px !important;
}

/* --- 書籍卡片手機端優化 --- */
.book-card {
  padding: 14px !important;
  border-radius: 14px !important;
  margin-top: 14px !important;
}

.book-card .label {
  font-size: 12px !important;
  margin-bottom: 8px !important;
}

.rank-list {
  gap: 2px !important;
}

.rank-row {
  padding: 6px 4px !important;
  min-height: 40px;
}

.rank-num {
  width: 24px !important;
  height: 24px !important;
  font-size: 11px !important;
}

.rank-title {
  font-size: 13px !important;
}

/* --- 分類標籤手機端優化 --- */
.tag-cloud,
.category-list {
  gap: 8px !important;
}

.tag-cloud a,
.category-list a {
  min-height: 36px;
  padding: 6px 14px !important;
  font-size: 13px !important;
  border-radius: 999px !important;
}

/* --- 表格手機端優化 --- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 16px 0;
  border-radius: 12px;
}

.table {
  min-width: 100%;
  font-size: 13px !important;
}

.table th,
.table td {
  padding: 10px 12px !important;
  white-space: nowrap;
}

/* --- 圖片燈箱手機端優化 --- */
.lightbox {
  padding: 16px !important;
}

.lightbox img {
  max-width: 100% !important;
  max-height: 85vh !important;
  border-radius: 12px !important;
}

/* --- 安全區域適配 (iPhone瀏海) --- */
@supports (padding: max(0px)) {
  .site-header {
    padding-top: max(0px, env(safe-area-inset-top));
  }

  .to-top {
    bottom: max(16px, env(safe-area-inset-bottom));
  }

  .site-footer {
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }
}

/* --- 橫屏優化 --- */
@media (max-width: 980px) and (orientation: landscape) {
  .hero {
    max-height: 200px;
  }

  .hero-inner {
    padding: 18px 20px !important;
  }

  .hero h2 {
    font-size: 20px !important;
  }

  .article-hero {
    border-radius: 12px !important;
  }
}

/* --- 平板優化 --- */
@media (min-width: 601px) and (max-width: 980px) {
  .header-inner {
    height: 64px !important;
    padding: 0 16px;
  }

  .brand-mark {
    width: 42px !important;
    height: 42px !important;
  }

  .brand-title {
    font-size: 24px !important;
  }

  .sidebar {
    inset: 64px auto 0 0 !important;
    height: calc(100vh - 64px) !important;
  }

  .related-grid {
    grid-template-columns: 1fr 1fr !important;
  }

  .foot-grid {
    grid-template-columns: 1fr 1fr !important;
  }
}

/* --- 小手機優化 (iPhone SE等) --- */
@media (max-width: 380px) {
  .brand-title {
    font-size: 18px !important;
  }

  .hero h2 {
    font-size: 20px !important;
  }

  .article-header h1 {
    font-size: 20px !important;
  }

  .prose {
    font-size: 14px !important;
  }

  .article-card h3,
  .card h3 {
    font-size: 15px !important;
  }
}

/* --- 減少動畫 (尊重用戶偏好) --- */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* --- 高對比度模式優化 --- */
@media (prefers-contrast: high) {
  .site-header {
    border-bottom-width: 2px !important;
  }

  .card,
  .article-card {
    border: 1px solid var(--line) !important;
  }
}
