/* === Reset / Base === */
body {
  font-family: 'Noto Sans TC', sans-serif;
  margin: 0;
  padding: 0;
  background: #fff;
  color: #333;
}

header {
  padding: 16px;
  text-align: center;
  border-bottom: 1px solid #eee;
  background-color: #fff;
}

.loading {
  font-size: 14px;
  color: #888;
  padding: 20px 10px;
}

#query {
  width: 90%;
  max-width: 600px;
  padding: 10px 14px;
  font-size: 16px;
  border-radius: 6px;
  border: 1px solid #ddd;
  background: #f9f9f9;
  box-sizing: border-box;
}

/* === Tabs === */
.tabs {
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid #eee;
  background-color: #fff;
  padding: 8px 16px;
  gap: 12px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  all: unset;
  display: inline-block;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 15px;
  color: #666;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-bottom 0.2s;
}
.tab:hover { color: #000; }
.tab.active { color: #000; font-weight: 600; border-bottom: 2px solid #000; }

/* === Sort & Layout Toggle Row === */
.sort-layout-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background-color: #fff;
  border-bottom: 1px solid #eee;
  flex-wrap: wrap;
}
.sort-options {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 14px;
  color: #444;
}
.sort-options span { font-weight: 500; color: #111; }
.sort-button {
  all: unset;
  cursor: pointer;
  font-size: 14px;
  color: #666;
  padding: 4px 8px;
  border-bottom: 2px solid transparent;
  transition: color 0.2s ease, border-color 0.2s ease;
}
.sort-button:hover { color: #000; }
.sort-button.active { color: #000; font-weight: 600; border-bottom: 2px solid #000; }

/* === Main === */
main { padding: 20px 16px; background-color: #fff; }
.category { margin-bottom: 40px; }
.category h2 {
  font-size: 16px;
  font-weight: 500;
  color: #111;
  border-left: 2px solid #000;
  padding-left: 8px;
  margin-bottom: 12px;
}

/* === Scroll containers === */
.scroll-container {
  display: flex;
  overflow-x: auto;
  gap: 16px;
  padding-bottom: 10px;
}
/* list 模式：多張卡垂直堆疊、可捲動（單一 Tab 時啟用） */
.scroll-container.vertical {
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  margin-bottom: 16px;
  gap: 12px;
}

/* === Card (shared) === */
.card {
  flex: 0 0 auto;
  width: 100%;
  max-width: 540px;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  border: 1px solid #eee;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  transition: box-shadow 0.2s ease-in-out;
  display: flex;
  flex-direction: column; /* 直式：圖在上、文在下 */
}
.card:hover { box-shadow: 0 4px 10px rgba(0,0,0,0.08); }

/* 圖片（直式預設高度） */
.card img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  background-color: #f0f0f0;
  display: block;
}

/* 內容 */
.card-content {
  padding: 16px 12px;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  color: #222;
}
.card-subtitle {
  font-size: 13px;
  color: #777;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* === 橫式（list）：左圖右文 === */
.card--list {
  flex-direction: row;      /* 變成左右 */
  align-items: stretch;
  max-width: 100%;          /* 行動優先：佔滿容器寬 */
}

/* 左側圖容器固定寬，右側撐滿 */
.card--list .card-img-wrapper {
  position: relative;
  flex: 0 0 42%;            /* 左側約 42% 寬（行動裝置視覺平衡） */
  max-width: 380px;
}

/* 橫式時圖片用滿左側容器；用 aspect-ratio 穩定高度 */
.card--list img {
  width: 100%;
  height: 100%;
  aspect-ratio: 4 / 3;      /* iOS 15+ 支援，畫面穩定 */
  object-fit: cover;
  min-height: 180px;        /* 下限避免太扁 */
}

.card--list img.card-img--xl {
  height: 100%;
  min-height: 200px;
}

/* 右側內容區 */
.card--list .card-content {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
}

/* 操作列貼底，提升穩定性 */
.card--list .card-actions {
  margin-top: auto;
}

/* 橫式下，摘要顯示多行 */
.card--list .card-content--list .card-subtitle {
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* === meta list & pills（在 list 模式下多出來的資訊） === */
.meta-list {
  margin: 4px 0 0;
  padding: 0 0 2px 18px;
  color: #666;
  font-size: 12px;
}
.meta-list li { margin: 4px 0; }

.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  display: inline-block;
  border-radius: 999px;
  font-size: 12px;
  padding: 4px 8px;
  line-height: 1;
}
.pill--accent { background: #111; color: #fff; }
.pill--ghost { background: #f1f1f1; color: #666; }

/* === Heart & actions === */
.card-img-wrapper { position: relative; }
.card-icon-btn.heart {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255,255,255,0.9);
  border: none;
  border-radius: 50%;
  padding: 6px;
  font-size: 16px;
  cursor: pointer;
  color: #999;
  transition: color 0.2s ease;
}
.card-icon-btn.heart:hover { color: red; }

.card-actions {
  display: flex;
  gap: 12px;
  margin-top: 2px;
  flex-wrap: wrap;
}
.card-action-btn {
  all: unset;
  cursor: pointer;
  font-size: 13px;
  color: #333;
  background-color: #eee;
  padding: 6px 10px;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}
.card-action-btn:hover { background-color: #ddd; }

/* === Footer === */
footer {
  text-align: center;
  padding: 20px;
  font-size: 14px;
  background: #fafafa;
  color: #888;
  border-top: 1px solid #eee;
}

/* === 尺寸優化（平板與桌面） === */
@media (min-width: 640px) {
  .card { max-width: 620px; }
  .card--list .card-img-wrapper { flex-basis: 38%; }
  .card--list img { min-height: 220px; }
}

@media (min-width: 1024px) {
  /* 在桌面上，直式卡片寬度稍放大、清晰度更好 */
  .card { max-width: 720px; }
  .card--list .card-img-wrapper { flex-basis: 34%; max-width: 420px; }
  .card--list img { min-height: 260px; }
}

/* === 版型切換按鈕 === */
.layout-toggle { display: flex; gap: 12px; }
.layout-btn {
  all: unset;
  cursor: pointer;
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #f5f5f5;
  display: inline-flex;
  align-items: center;
}
.layout-btn i { font-size: 18px; line-height: 1; }
.layout-btn:hover { background: #e9e9e9; }
.layout-btn.is-active { background: #111; color: #fff; border-color: #111; }

/* 讓可點擊圖片有可用性提示 */
.card-img-wrapper.clickable { cursor: pointer; }

/* === 根節點模式控制（新增） === */
/* ALL：隱藏版型切換；維持橫向滑動（不加 vertical） */
.mode-all .layout-toggle { display: none; }
/* 單一 Tab：顯示版型切換；方格模式下把圖放大一些 */
.mode-single .layout-toggle { display: flex; }
.mode-single.view-grid .card img {
  height: 220px;
  min-height: 220px;
}
@media (min-width: 640px) {
  .mode-single.view-grid .card img { height: 240px; min-height: 240px; }
}
@media (min-width: 1024px) {
  .mode-single.view-grid .card img { height: 260px; min-height: 260px; }
}