/* ── Reset & Base ──────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --gold: #c9a84c;
  --gold-dim: #a07a2a;
  --bg: #141414;
  --bg2: #1e1e1e;
  --bg3: #2a2a2a;
  --text: #e8e8e8;
  --text-muted: #888;
  --border: #333;
  --radius: 10px;
  --font: -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
}

html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100svh;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
img { display: block; width: 100%; height: 100%; object-fit: cover; }

/* ── Layout ────────────────────────────────────── */
.app { display: flex; flex-direction: column; min-height: 100svh; }

header {
  position: sticky; top: 0; z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px 10px;
}

.header-top {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px;
}

.header-logo {
  font-size: 17px; font-weight: 700;
  color: var(--gold);
  flex: 1;
}

.header-logo span {
  font-size: 11px; font-weight: 400;
  color: var(--text-muted);
  display: block;
}

.btn-refresh {
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--bg3);
  color: var(--text-muted);
  font-size: 13px;
  transition: color .15s;
}
.btn-refresh:active { color: var(--gold); }
.btn-refresh.loading { animation: spin .6s linear infinite; }

/* ── 搜尋欄 ────────────────────────────────────── */
.search-wrap {
  position: relative;
}
.search-wrap svg {
  position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  stroke: var(--text-muted); fill: none;
  pointer-events: none;
}
#search-input {
  width: 100%;
  padding: 9px 12px 9px 34px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  font-family: var(--font);
  outline: none;
  -webkit-appearance: none;
  transition: border-color .15s;
}
#search-input:focus { border-color: var(--gold-dim); }
#search-input::placeholder { color: var(--text-muted); }
.clear-btn {
  position: absolute; right: 10px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 16px;
  padding: 4px;
  display: none;
}
.clear-btn.visible { display: block; }

/* ── 狀態列 ────────────────────────────────────── */
.status-bar {
  padding: 8px 16px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex; align-items: center; gap: 6px;
  border-bottom: 1px solid var(--border);
  min-height: 34px;
}
.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.status-dot.ok { background: #4caf50; }
.status-dot.err { background: #f44336; }
.status-dot.loading {
  background: var(--gold);
  animation: pulse .8s ease-in-out infinite alternate;
}

/* ── 商品列表容器 ───────────────────────────────── */
main {
  flex: 1;
  padding: 12px 12px 80px;
}

.items-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── 商品卡片 ───────────────────────────────────── */
.item-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color .15s;
}
.item-card:active { border-color: var(--gold-dim); }

/* 圖片輪播 */
.img-carousel {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--bg3);
  overflow: hidden;
}
.img-track {
  display: flex;
  width: 100%;
  height: 100%;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.img-track::-webkit-scrollbar { display: none; }
.img-slide {
  scroll-snap-align: start;
  flex-shrink: 0;
  width: 100%;
  height: 100%;
  position: relative;
}
.img-slide img {
  position: absolute; inset: 0;
  object-fit: contain;
  background: var(--bg3);
}
.img-slide img.err {
  opacity: .3;
}

/* 圖片點數 */
.img-dots {
  position: absolute;
  bottom: 6px; left: 0; right: 0;
  display: flex; justify-content: center; gap: 4px;
  pointer-events: none;
}
.img-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: rgba(255,255,255,.4);
  transition: background .2s;
}
.img-dot.active { background: rgba(255,255,255,.9); }

.no-image {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 13px;
}

/* 商品資訊區 */
.item-info {
  padding: 10px 12px 12px;
}

.item-title {
  font-size: 14px;
  line-height: 1.4;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 8px;
}

.item-meta {
  display: flex; align-items: center; justify-content: space-between;
}

.item-price {
  font-size: 18px; font-weight: 700;
  color: var(--gold);
}
.item-price.na {
  font-size: 13px; font-weight: 400;
  color: var(--text-muted);
}

.item-date {
  font-size: 11px;
  color: var(--text-muted);
}

.item-link {
  display: flex; align-items: center; gap: 4px;
  margin-top: 8px;
  padding: 7px 0;
  border-top: 1px solid var(--border);
  color: var(--gold-dim);
  font-size: 13px;
}
.item-link svg {
  width: 13px; height: 13px;
  stroke: currentColor; fill: none;
  flex-shrink: 0;
}

/* ── 空狀態 / 載入狀態 ─────────────────────────── */
.state-box {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
  gap: 10px;
  text-align: center;
}
.state-box svg {
  width: 40px; height: 40px;
  stroke: var(--border); fill: none;
}
.state-box p { font-size: 14px; }

.skeleton {
  background: linear-gradient(90deg, var(--bg3) 25%, var(--bg2) 50%, var(--bg3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 4px;
}

/* ── 分頁 ───────────────────────────────────────── */
.pagination {
  display: flex; justify-content: center; align-items: center;
  gap: 8px;
  padding: 16px 0 8px;
}
.btn-page {
  padding: 9px 18px;
  border-radius: 8px;
  background: var(--bg3);
  color: var(--text);
  font-size: 14px;
  border: 1px solid var(--border);
  transition: background .15s, border-color .15s;
}
.btn-page:active { background: var(--bg2); border-color: var(--gold-dim); }
.btn-page:disabled {
  opacity: .35; pointer-events: none;
}
.page-info {
  font-size: 13px; color: var(--text-muted);
  min-width: 60px; text-align: center;
}

/* ── Toast ──────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 999;
  transition: transform .25s ease, opacity .25s;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
#toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ── Animations ─────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { to { opacity: .3; } }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Desktop 適配（平板以上加寬卡片） ────────────── */
@media (min-width: 600px) {
  main { max-width: 680px; margin: 0 auto; }
  .items-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }
}
