@font-face {
  font-family: 'Spoqa Han Sans Neo';
  font-weight: 500;
  font-style: normal;
  src: local('Spoqa Han Sans Neo Medium'),
    url('../fonts/SpoqaHanSansNeo/SpoqaHanSansNeo-Medium.woff2') format('woff2');
}

@font-face {
  font-family: 'Spoqa Han Sans Neo';
  font-weight: 400;
  font-style: normal;
  src: local('Spoqa Han Sans Neo Regular'),
    url('../fonts/SpoqaHanSansNeo/SpoqaHanSansNeo-Regular.woff2') format('woff2');
}

:root {
  --header-bg: #ffffff;
  --content-bg: #f5f5f5;
  --card-bg: #ffffff;
  --search-bg: #f5f5f5;
  --border: #ebebeb;
  --text: #1c1c1e;
  --text-muted: #8a8a8e;
  --accent: #ff5722;
  --price-color: #ff2d2d;
  --thumb-bg: #f5f5f5;
  --price-box-bg: #fdecea;
}

@media (prefers-color-scheme: dark) {
  :root {
    --header-bg: #1c1c1e;
    --content-bg: #0e0e10;
    --card-bg: #1c1c1e;
    --search-bg: #2c2c2e;
    --border: #2c2c2e;
    --text: #f2f2f2;
    --text-muted: #9a9a9e;
    --accent: #ff7043;
    --price-color: #ff453a;
    --thumb-bg: #2a2a2c;
    --price-box-bg: #3a1f1d;
  }
}

* {
  box-sizing: border-box;
}

/* 링크/버튼/이미지 드래그, 탭 하이라이트, 포커스 테두리 제거 (동적으로 추가되는 요소에도 적용되도록 CSS로 처리) */
a, button, img {
  -webkit-user-drag: none;
  -webkit-tap-highlight-color: transparent;
}

a:focus, button:focus, img:focus {
  outline: none;
}

body {
  margin: 0;
  background: var(--content-bg);
  color: var(--text);
  font-family: 'Spoqa Han Sans Neo', -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", Roboto, sans-serif;
}

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
}

.logo {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
  white-space: nowrap;
  letter-spacing: -0.02em;
  text-decoration: none;
}

.search-form {
  flex: 1;
  display: flex;
  justify-content: center;
}

.search-box {
  position: relative;
  width: 100%;
  max-width: 420px;
}

.search-input {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 16px;
  padding: 7px 30px;
  font-size: 13px;
  color: var(--text);
  background: var(--search-bg);
  outline: none;
}

.search-input:focus {
  border-color: var(--accent);
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.1);
  color: var(--text-muted);
  cursor: pointer;
}

.search-clear:hover {
  background: rgba(0, 0, 0, 0.18);
}

.search-clear[hidden] {
  display: none;
}

/* ---------- Grid ---------- */

.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 0 40px;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  padding: 20px 16px;
}

@media (max-width: 900px) {
  .product-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
  }
}

@media (max-width: 600px) {
  .product-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 12px 10px;
  }
}

/* ---------- Card ---------- */

.product-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: box-shadow 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
  text-decoration: none;
  color: inherit;
}

/* 폴링으로 새로 추가된 카드에 잠깐 표시되는 페이드인 하이라이트 */
.product-card.is-new {
  animation: product-card-new 1.2s ease;
}

@keyframes product-card-new {
  0% {
    opacity: 0;
    transform: translateY(-8px);
    box-shadow: 0 0 0 2px var(--accent);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  }
}

.product-card:hover {
  border-color: transparent;
  transform: translateY(-4px);
  box-shadow:
    0 16px 28px rgba(0, 0, 0, 0.14),
    0 4px 10px rgba(0, 0, 0, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

@media (prefers-color-scheme: dark) {
  .product-card:hover {
    box-shadow:
      0 16px 28px rgba(0, 0, 0, 0.5),
      0 4px 10px rgba(0, 0, 0, 0.3),
      inset 0 1px 0 rgba(255, 255, 255, 0.06);
  }
}

.product-card .thumb {
  position: relative;
  width: 100%;
  padding-top: 100%;
  background: var(--thumb-bg);
  overflow: hidden;
}

.product-card .thumb img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.product-card .info {
  padding: 10px 12px 12px;
}

.product-name {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.4;
  height: 2.8em;
  color: var(--text);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.product-price {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 800;
  color: var(--price-color);
}

.product-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.meta-site {
  display: inline-block;
  max-width: 60%;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  color: #666;
  background: #eee;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/*
 * 사이트별 배지 색상. site_name(예: "11번가", "지마켓") 값을 그대로 data-site 속성에 넣어 렌더링한다.
 * 아래 값은 원하는 대로 자유롭게 바꾸거나 항목을 추가하면 된다.
 */
.meta-site[data-site="11번가"] {
  background: #FF0038;
  color: #fff;
}

.meta-site[data-site="지마켓"] {
  background: #0ABB26;
  color: #fff;
}

.meta-site[data-site="쿠팡"] {
  background: #346AFF;
  color: #fff;
}

.meta-site[data-site="이마트몰"] {
  background: #FFD040;
  color: #fff;
}

.meta-site[data-site="GS SHOP"] {
  background: #0088FF;
  color: #fff;
}

.meta-site[data-site="마켓컬리"] {
  background: #5F0080;
  color: #fff;
}

.meta-site[data-site="롯데홈쇼핑"] {
  background: #CD3129;
  color: #fff;
}

.meta-site[data-site="하이마트"] {
  background: #000000;
  color: #fff;
}

.meta-site[data-site="롯데온"] {
  background: #000000;
  color: #fff;
}

.meta-site[data-site="토스쇼핑"] {
  background: #0064FF;
  color: #fff;
}

.meta-time {
  flex-shrink: 0;
  margin-left: 8px;
}

/* ---------- States ---------- */

.empty-message,
.loading-indicator {
  text-align: center;
  padding: 24px 0;
  font-size: 14px;
  color: var(--text-muted);
}

.scroll-sentinel {
  height: 1px;
}

/* ---------- Scroll-to-top FAB (PC only) ---------- */

.scroll-top-btn {
  position: fixed;
  right: 32px;
  bottom: 32px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--card-bg);
  color: var(--text);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.scroll-top-btn.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.scroll-top-btn:hover {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

@media (max-width: 900px) {
  .scroll-top-btn {
    display: none;
  }
}

/* ---------- Back-to-home / list button ---------- */

.back-home-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 20px 16px 0;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.back-home-btn:hover {
  background: var(--search-bg);
}

/* ---------- Product detail page ---------- */

.detail-card {
  background: var(--card-bg);
  border-radius: 16px;
  margin: 16px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.product-detail {
  display: flex;
  gap: 32px;
}

.detail-image {
  /*
   * padding-top(%) 트릭은 쓸 수 없다: 이 요소는 .detail-info 와 나란히 배치되는 flex row 안의
   * 아이템이라, padding-top: 100% 가 "자기 자신의 폭"이 아니라 부모(.product-detail 전체 폭) 기준으로
   * 계산되어 정사각형이 아니라 세로로 길게 늘어나 버린다. 여기서는 aspect-ratio 를 그대로 쓴다.
   */
  flex: 1 1 0;
  width: 100%;
  max-width: 560px;
  aspect-ratio: 1 / 1;
  background: var(--thumb-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}

.detail-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.detail-info {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding-top: 4px;
}

.detail-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}

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

.detail-title {
  margin: 0 0 16px;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--text);
}

.detail-price-box {
  margin-bottom: 16px;
  padding: 20px 24px;
  border-radius: 12px;
  background: var(--price-box-bg);
}

.detail-price {
  display: block;
  text-align: right;
  font-size: 30px;
  font-weight: 800;
  color: var(--price-color);
}

.affiliate-disclosure {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: right;
}

.buy-button-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
  margin-top: auto;
}

.buy-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  padding: 20px 24px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  text-decoration: none;
}

.buy-button:hover {
  filter: brightness(0.94);
}

.share-button {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  padding: 0;
  border: 2px solid var(--accent);
  border-radius: 12px;
  background: var(--card-bg);
  color: var(--accent);
  cursor: pointer;
}

.share-button:hover {
  background: var(--search-bg);
}

.share-toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  z-index: 60;
  padding: 10px 20px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
}

.share-toast[hidden] {
  display: none;
}

@media (max-width: 700px) {
  .detail-card {
    margin: 0;
    border-radius: 0;
    padding: 16px 16px 24px;
    box-shadow: none;
  }

  .product-detail {
    flex-direction: column;
    gap: 16px;
  }

  .detail-image {
    order: 2;
    flex: none;
    width: 100%;
    max-width: none;
  }

  .detail-info {
    display: contents;
  }

  .detail-meta {
    order: 1;
    margin-bottom: 0;
  }

  .detail-title {
    order: 3;
    margin: 0;
    font-size: 18px;
  }

  .detail-price-box {
    order: 4;
    margin-bottom: 0;
    padding: 16px 18px;
  }

  .detail-price {
    font-size: 24px;
  }

  .affiliate-disclosure {
    order: 5;
    margin: 8px 0 0;
  }

  body.product-page .main {
    padding-bottom: 88px;
  }

  .buy-button-row {
    order: 5;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    margin: 0;
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    background: var(--card-bg);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
  }

  .buy-button {
    padding: 14px 20px;
    font-size: 16px;
    border-radius: 10px;
  }

  .share-button {
    width: 50px;
    border-radius: 10px;
  }

  .share-toast {
    bottom: 96px;
  }
}

/* ---------- 관리자 전용: 비교상품 재처리 버튼/배너 ---------- */

.admin-reprocess-form {
  flex-shrink: 0;
}

.admin-reprocess-btn {
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  background: #333;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.admin-reprocess-btn:hover {
  background: #111;
}

.reprocess-banner {
  margin: 16px 16px 0;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
}

.reprocess-banner.success {
  background: #e6f4ea;
  color: #1e7e34;
}

.reprocess-banner.error {
  background: #fdecea;
  color: #c0392b;
}

.reprocess-banner-note {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  font-weight: 400;
  opacity: 0.85;
}

/* ---------- 함께 비교하면 좋을 상품 ---------- */

.related-card {
  background: var(--card-bg);
  border-radius: 16px;
  margin: 0 16px 16px;
  padding: 20px 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.related-title {
  margin: 0 0 8px;
  font-size: 19px;
  font-weight: 700;
  color: var(--text);
}

.related-list {
  display: flex;
  flex-direction: column;
}

.related-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 8px;
  margin: 0 -8px;
  border-radius: 8px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  background: var(--card-bg);
  transition: background 0.15s ease;
}

.related-item:hover {
  background: var(--search-bg);
}

.related-item:last-child {
  border-bottom: none;
}

.related-thumb {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--thumb-bg);
  overflow: hidden;
}

.related-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.related-info {
  flex: 1;
  min-width: 0;
}

.related-name {
  margin: 0 0 6px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.related-price {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
  color: var(--price-color);
}

@media (max-width: 700px) {
  .related-card {
    margin: 0;
    border-radius: 0;
    padding: 16px;
  }
}

/* ---------- 404 ---------- */

.not-found {
  text-align: center;
  padding: 80px 16px;
}

.not-found-title {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.not-found-desc {
  margin: 0 0 20px;
  font-size: 14px;
  color: var(--text-muted);
}
