:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --text: #16130e;
  --text-secondary: #6b6660;
  --text-tertiary: #9a948c;
  --border: #e8e4de;
  --accent: #16130e;
  --accent-hover: #000000;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(22, 19, 14, 0.06), 0 8px 24px rgba(22, 19, 14, 0.05);
  --shadow-lg: 0 12px 40px rgba(22, 19, 14, 0.16);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 64px;
  padding: 0 24px;
  background: rgba(250, 249, 247, 0.85);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.brand-sub { font-size: 13px; font-weight: 500; color: var(--text-tertiary); }

.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(520px, 100%);
  margin-left: 24px;
  padding: 0 14px;
  height: 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

body[data-page="home"] .topbar-search { display: none; }

@media (max-width: 640px) {
  .topbar-search { margin-left: 8px; }
  .brand-sub { display: none; }
}

.topbar-search:focus-within { border-color: var(--text); }

.topbar-search-icon { color: var(--text-tertiary); flex-shrink: 0; }

.topbar-search input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
}

.topbar-spacer { flex: 1; }

/* ---------- Views ---------- */
.view { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Home ---------- */
.home-wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 12vh 24px 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.home-title {
  font-size: clamp(32px, 5vw, 52px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-bottom: 12px;
}

.home-sub { font-size: 16px; color: var(--text-secondary); margin-bottom: 40px; }

.hero-search {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 640px;
  height: 60px;
  padding: 0 12px 0 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  transition: box-shadow 0.2s ease;
}

.hero-search:focus-within { border-color: var(--text); }

.hero-search-icon { color: var(--text-tertiary); flex-shrink: 0; }

.hero-search input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: 17px;
  font-family: inherit;
  color: var(--text);
}

.hero-search-btn {
  height: 44px;
  padding: 0 28px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.hero-search-btn:hover { background: var(--accent-hover); }
.hero-search-btn:active { transform: scale(0.97); }

.tag-section { width: 100%; margin-top: 44px; }
.tag-label { font-size: 13px; color: var(--text-tertiary); margin-bottom: 16px; letter-spacing: 0.02em; }

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.tag-chip:hover {
  border-color: var(--text);
  background: var(--text);
  color: #fff;
  transform: translateY(-1px);
}

.trending-section { width: 100%; margin-top: 52px; text-align: left; }
.trending-title { font-size: 13px; color: var(--text-tertiary); margin-bottom: 16px; letter-spacing: 0.02em; }
.trending-list { display: flex; flex-wrap: wrap; gap: 8px 6px; justify-content: center; }
.trending-chip {
  display: inline-block;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}
.trending-chip:hover { border-color: var(--text); color: var(--text); background: #fff; }

/* ---------- Results ---------- */
.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 24px 8px;
  flex-wrap: wrap;
}

.results-title-wrap { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.results-title { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; word-break: break-word; }
.results-count { font-size: 14px; color: var(--text-tertiary); white-space: nowrap; }

.results-toolbar { display: flex; align-items: center; gap: 10px; }
.toolbar-label { font-size: 13px; color: var(--text-tertiary); }
.order-select {
  height: 36px;
  padding: 0 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  outline: none;
}
.order-select:focus { border-color: var(--text); }

.masonry-grid {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 24px 40px;
  column-count: 4;
  column-gap: 14px;
}

@media (max-width: 1100px) { .masonry-grid { column-count: 3; } }
@media (max-width: 760px)  { .masonry-grid { column-count: 2; } }

.tile {
  display: block;
  break-inside: avoid;
  margin-bottom: 14px;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  background: #e5e1da;
  cursor: pointer;
  border: none;
  padding: 0;
  width: 100%;
  text-align: left;
  box-shadow: 0 1px 2px rgba(22, 19, 14, 0.05);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.tile img {
  display: block;
  width: 100%;
  height: auto;
  min-height: 120px;
  object-fit: cover;
}

.tile-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 40px 14px 12px;
  background: linear-gradient(to top, rgba(22,19,14,0.6), transparent 55%);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.tile:hover .tile-overlay { opacity: 1; }

.tile-caption {
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tile-author {
  margin-top: 4px;
  color: rgba(255,255,255,0.85);
  font-size: 12px;
}

.load-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 28px 0 48px;
  color: var(--text-tertiary);
  font-size: 14px;
}
.load-hint.error { color: #b3261e; }

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Detail ---------- */
.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 1fr);
  gap: 0;
  max-width: 1500px;
  margin: 0 auto;
  min-height: calc(100vh - 64px);
}

.detail-media {
  background: #17140f;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  min-height: 60vh;
}

.detail-media img {
  max-width: 100%;
  max-height: calc(100vh - 130px);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  object-fit: contain;
}

.detail-panel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  max-height: calc(100vh - 64px);
  position: sticky;
  top: 64px;
}

.detail-caption { font-size: 17px; font-weight: 600; line-height: 1.45; word-break: break-word; }

.detail-row { display: flex; align-items: flex-start; gap: 8px; font-size: 14px; color: var(--text-secondary); }
.detail-row a { color: var(--text); font-weight: 500; text-decoration: none; word-break: break-all; }
.detail-row a:hover { text-decoration: underline; }

.detail-meta-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-tertiary); margin-bottom: 6px; }

.detail-owner { display: flex; align-items: center; gap: 12px; }
.detail-owner img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; background: var(--border); }
.detail-owner .name { font-weight: 600; font-size: 14px; }

.detail-source-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  text-decoration: none;
  transition: all 0.15s ease;
  word-break: break-all;
}
.detail-source-pill:hover { border-color: var(--text); }

.similar-section {
  grid-column: 1 / -1;
  padding: 40px 24px 60px;
}

.similar-title {
  max-width: 1400px;
  margin: 0 auto 20px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.similar-sub { font-size: 13px; color: var(--text-tertiary); font-weight: 400; }

.detail-back {
  position: fixed;
  top: 74px;
  left: 18px;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: rgba(22,19,14,0.72);
  backdrop-filter: blur(8px);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease;
  text-decoration: none;
}
.detail-back:hover { background: rgba(22,19,14,0.95); }

@media (max-width: 860px) {
  .detail-layout { grid-template-columns: 1fr; }
  .detail-panel { position: static; max-height: none; border-left: none; border-top: 1px solid var(--border); }
  .detail-back { left: 12px; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  padding: 12px 20px;
  font-size: 14px;
  color: #fff;
  background: rgba(22,19,14,0.92);
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
}

/* skeleton */
.skeleton { position: relative; overflow: hidden; background: #e8e4de; }
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.55), transparent);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
