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

:root {
  --blue: #0063b1;
  --blue-light: #e8f0fa;
  --orange: #e05a00;
  --orange-light: #fff3ec;
  --green: #1a7a1a;
  --green-light: #eaf5ea;
  --text: #111;
  --text-sub: #666;
  --border: #ddd;
  --bg: #f4f4f4;
  --white: #fff;
  --shadow: 0 1px 4px rgba(0,0,0,0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* ヘッダー */
.site-header {
  background: var(--blue);
  color: white;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.header-inner { display: flex; align-items: center; justify-content: space-between; height: 52px; }

.logo { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 1.1rem; color: white; }
.logo-lab { color: #ffcc00; font-size: 0.85rem; }

.header-nav { display: flex; gap: 20px; }
.header-nav a { color: rgba(255,255,255,0.85); text-decoration: none; font-size: 0.88rem; }
.header-nav a:hover { color: white; }

/* ヒーロー */
.hero {
  background: linear-gradient(135deg, #004080, #0063b1);
  color: white;
  padding: 28px 0 24px;
}

.hero-title { font-size: clamp(1.1rem, 2.5vw, 1.6rem); font-weight: 800; margin-bottom: 8px; line-height: 1.4; }
.highlight { color: #ffcc00; }
.hero-sub { font-size: 0.88rem; opacity: 0.85; }
.hero-updated { font-size: 0.78rem; opacity: 0.7; margin-top: 8px; }

/* フィルターバー */
.filter-bar-wrap {
  background: white;
  border-bottom: 2px solid var(--blue);
  position: sticky;
  top: 52px;
  z-index: 90;
}

.filter-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 0;
  flex-wrap: wrap;
}

.filter-left, .filter-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter-label { font-size: 0.8rem; color: var(--text-sub); font-weight: 600; white-space: nowrap; }

.tag-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.tag-btn {
  padding: 4px 12px;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: white;
  font-size: 0.78rem;
  cursor: pointer;
  color: var(--text-sub);
  font-weight: 500;
}
.tag-btn:hover { border-color: var(--blue); color: var(--blue); }
.tag-btn.active { background: var(--blue); border-color: var(--blue); color: white; }

.sort-select {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 0.82rem;
  background: white;
  color: var(--text);
  cursor: pointer;
}

/* 比較テーブル */
.compare-section { padding: 20px 0 40px; }

.table-wrap {
  background: white;
  border-radius: 4px;
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.compare-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 800px;
}

.compare-table thead tr {
  background: #f0f4fa;
  border-bottom: 2px solid var(--blue);
}

.compare-table th {
  padding: 10px 12px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--blue);
  white-space: nowrap;
}

.col-product { text-align: left !important; width: 220px; }
.col-spec { width: 90px; }
.col-cost { width: 100px; color: var(--orange) !important; }
.col-price { width: auto; }

.compare-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.compare-table tbody tr:hover { background: #fafbff; }

/* 商品セル */
.td-product { padding: 12px; vertical-align: top; }

.product-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 190px;
  position: relative;
}

/* 王冠バッジ */
.rank-badge {
  position: absolute;
  top: -10px;
  left: -10px;
  font-size: 2rem;
  line-height: 1;
  z-index: 10;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
}

.product-name-wrap {
  width: 100%;
  text-align: center;
}
.product-brand { font-size: 0.68rem; color: var(--text-sub); text-transform: uppercase; letter-spacing: 0.04em; }
.product-name { font-size: 1rem; font-weight: 800; line-height: 1.3; margin: 3px 0 0; color: var(--text); }

.product-img {
  width: 160px;
  height: 160px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fafafa;
  flex-shrink: 0;
}

.product-tags { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.tag {
  font-size: 0.66rem;
  padding: 1px 6px;
  border-radius: 2px;
  background: var(--blue-light);
  color: var(--blue);
  font-weight: 600;
}
.tag.origin-jp { background: var(--green-light); color: var(--green); }

.rating-row { font-size: 0.72rem; color: var(--text-sub); text-align: center; }

.product-name-link { text-decoration: none; color: inherit; }
.product-name-link:hover .product-name { color: var(--blue); text-decoration: underline; }

.btn-detail {
  display: block;
  margin-top: 8px;
  padding: 5px 10px;
  background: white;
  color: var(--blue);
  border: 1px solid var(--blue);
  border-radius: 3px;
  font-size: 0.72rem;
  font-weight: 700;
  text-decoration: none;
  text-align: center;
  transition: background 0.15s;
}
.btn-detail:hover { background: var(--blue); color: white; }
.star { color: #f5a623; }

/* スペックセル */
.td-spec { padding: 12px 8px; text-align: center; vertical-align: middle; }
.spec-value { font-size: 1rem; font-weight: 700; color: var(--text); }
.spec-unit { font-size: 0.68rem; color: var(--text-sub); }

/* コストセル */
.td-cost { padding: 12px 8px; text-align: center; vertical-align: middle; }
.cost-value { font-size: 1.1rem; font-weight: 800; color: var(--orange); }
.cost-unit { font-size: 0.68rem; color: var(--text-sub); display: block; }

/* 価格・購入セル */
.td-price { padding: 10px 12px; vertical-align: middle; }

.retailer-list {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  min-width: 560px;
}

.retailer-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  padding: 8px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fafafa;
  text-align: center;
  position: relative;
}

.retailer-row.is-cheapest {
  border-color: var(--orange);
  background: var(--orange-light);
}

.retailer-name {
  font-size: 0.72rem;
  font-weight: 600;
  text-align: center;
  padding: 3px 4px;
  border-radius: 2px;
  align-self: center;
  min-width: 56px;
}

.retailer-name.amazon { background: #ff9900; color: white; }
.retailer-name.rakuten { background: #bf0000; color: white; }
.retailer-name.yahoo { background: #720096; color: white; }
.retailer-name.official { background: #333; color: white; }
.retailer-name.iherb { background: #5c8a00; color: white; }

.retailer-price {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  text-align: center;
}

.retailer-price.cheapest { color: var(--orange); font-size: 1.05rem; }

.badge-cheapest {
  font-size: 0.6rem;
  background: var(--orange);
  color: white;
  padding: 1px 5px;
  border-radius: 2px;
  font-weight: 700;
  position: absolute;
  top: -8px;
  right: 4px;
}

.btn-buy {
  display: block;
  padding: 5px 8px;
  background: var(--orange);
  color: white;
  border-radius: 3px;
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
  transition: background 0.15s;
  text-align: center;
}
.btn-buy:hover { background: #c04a00; }

.btn-buy.secondary {
  background: white;
  color: var(--blue);
  border: 1px solid var(--blue);
}
.btn-buy.secondary:hover { background: var(--blue-light); }

.retailer-row.disabled {
  background: #f5f5f5;
  border-color: #e0e0e0;
  opacity: 0.4;
}
.retailer-row.disabled .retailer-price { color: #aaa; }
.retailer-row.disabled .btn-buy {
  background: #ccc;
  color: #888;
  pointer-events: none;
}

/* ガイド */
.guide-section { padding: 32px 0 48px; }

.section-title {
  font-size: 1.2rem;
  font-weight: 800;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--blue);
  color: var(--blue);
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.guide-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 18px 16px;
}

.guide-icon { font-size: 1.6rem; margin-bottom: 8px; }
.guide-card h3 { font-size: 0.92rem; font-weight: 700; margin-bottom: 6px; color: var(--blue); }
.guide-card p { font-size: 0.82rem; color: var(--text-sub); line-height: 1.6; }

/* フッター */
.site-footer { background: #222; color: #999; padding: 24px 0; text-align: center; }
.footer-note { font-size: 0.75rem; line-height: 1.8; margin-bottom: 8px; }
.footer-copy { font-size: 0.75rem; color: #555; }

/* ===== モバイル：カード表示 ===== */
@media (max-width: 768px) {
  .header-nav { display: none; }
  .hero { padding: 20px 0 16px; }
  .filter-bar { gap: 10px; }

  /* テーブルを非表示にしてカードに切り替え */
  .table-wrap { display: none; }
  .card-list { display: flex; flex-direction: column; gap: 16px; padding: 16px 0 40px; }

  .product-card {
    background: white;
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
    position: relative;
  }

  .card-rank {
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 1.6rem;
    z-index: 10;
  }

  .card-top {
    display: flex;
    gap: 12px;
    padding: 16px;
    align-items: flex-start;
  }

  .card-img {
    width: 90px;
    height: 90px;
    object-fit: contain;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #fafafa;
    flex-shrink: 0;
  }

  .card-info { flex: 1; min-width: 0; }
  .card-brand { font-size: 0.68rem; color: var(--text-sub); text-transform: uppercase; letter-spacing: 0.04em; }
  .card-name { font-size: 0.95rem; font-weight: 800; line-height: 1.3; margin: 2px 0 6px; }
  .card-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
  .card-rating { font-size: 0.72rem; color: var(--text-sub); }

  .card-specs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: #f8f9fa;
  }

  .card-spec-item {
    padding: 8px 4px;
    text-align: center;
    border-right: 1px solid var(--border);
  }
  .card-spec-item:last-child { border-right: none; }
  .card-spec-label { font-size: 0.6rem; color: var(--text-sub); }
  .card-spec-value { font-size: 0.88rem; font-weight: 700; }
  .card-spec-value.cost { color: var(--orange); font-size: 1rem; font-weight: 800; }

  .card-prices {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    padding: 12px;
  }

  .card-price-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px 4px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #fafafa;
    text-align: center;
    position: relative;
    font-size: 0.68rem;
  }

  .card-price-item.is-cheapest {
    border-color: var(--orange);
    background: var(--orange-light);
  }

  .card-price-item .retailer-name {
    font-size: 0.6rem;
    padding: 2px 3px;
    width: auto;
    min-width: unset;
  }

  .card-price-item .price-val {
    font-size: 0.78rem;
    font-weight: 700;
  }

  .card-price-item .price-val.cheapest { color: var(--orange); }

  .card-price-item .badge-cheapest {
    font-size: 0.52rem;
    top: -7px;
    right: 2px;
  }

  .card-price-item a {
    display: block;
    padding: 3px 4px;
    background: var(--orange);
    color: white;
    border-radius: 2px;
    text-decoration: none;
    font-size: 0.62rem;
    font-weight: 700;
    width: 100%;
    text-align: center;
  }

  .card-price-item.disabled {
    opacity: 0.35;
  }
  .card-price-item.disabled a {
    background: #ccc;
    pointer-events: none;
  }

  .card-name-link { text-decoration: none; color: inherit; }
  .card-name-link:hover .card-name { color: var(--blue); }

  .btn-detail-card {
    display: block;
    margin: 0 12px 12px;
    padding: 8px;
    background: white;
    color: var(--blue);
    border: 1px solid var(--blue);
    border-radius: 4px;
    font-size: 0.78rem;
    font-weight: 700;
    text-decoration: none;
    text-align: center;
  }
}

/* デスクトップではカードリスト非表示 */
@media (min-width: 769px) {
  .card-list { display: none; }
}

/* ===== 商品詳細ページ ===== */

.breadcrumb-wrap {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 8px 0;
}
.breadcrumb {
  font-size: 0.8rem;
  color: var(--text-sub);
  display: flex;
  gap: 6px;
  align-items: center;
}
.breadcrumb a { color: var(--blue); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

.detail-main { padding: 24px 0 48px; }

.detail-section { margin-bottom: 32px; }

/* 商品ヘッダー */
.detail-hero {
  display: flex;
  gap: 28px;
  align-items: flex-start;
  background: white;
  border-radius: 6px;
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 28px;
}

.detail-hero-img {
  flex-shrink: 0;
  width: 200px;
}
.detail-hero-img img {
  width: 200px;
  height: 200px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fafafa;
}

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

.detail-title {
  font-size: clamp(1.1rem, 2.5vw, 1.5rem);
  font-weight: 800;
  line-height: 1.3;
  margin: 4px 0 8px;
  color: var(--text);
}

.detail-cost-big {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 16px 0 8px;
  padding: 12px 16px;
  background: var(--orange-light);
  border: 1px solid var(--orange);
  border-radius: 4px;
}
.detail-cost-label { font-size: 0.78rem; color: var(--orange); font-weight: 600; }
.detail-cost-num { font-size: 1.8rem; font-weight: 900; color: var(--orange); }

.detail-updated { font-size: 0.75rem; color: var(--text-sub); margin-top: 6px; }

/* スペックグリッド */
.spec-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.spec-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 8px;
  text-align: center;
  box-shadow: var(--shadow);
}
.spec-card-label { font-size: 0.68rem; color: var(--text-sub); margin-bottom: 4px; }
.spec-card-val { font-size: 1.2rem; font-weight: 800; color: var(--text); }
.spec-card-unit { font-size: 0.68rem; font-weight: 400; color: var(--text-sub); margin-left: 2px; }

.spec-note { font-size: 0.8rem; color: var(--text-sub); }

/* 詳細ページの価格リスト（横幅を広めに） */
.detail-retailer-list {
  grid-template-columns: repeat(5, 1fr);
  min-width: 0;
  max-width: 700px;
}

/* 関連商品 */
.related-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.related-card {
  display: flex;
  gap: 12px;
  align-items: center;
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s;
  box-shadow: var(--shadow);
}
.related-card:hover { box-shadow: 0 3px 10px rgba(0,0,0,0.12); }

.related-card img {
  width: 60px;
  height: 60px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: #fafafa;
  flex-shrink: 0;
}
.related-info { flex: 1; min-width: 0; }
.related-brand { font-size: 0.65rem; color: var(--text-sub); text-transform: uppercase; }
.related-name { font-size: 0.82rem; font-weight: 700; line-height: 1.3; margin: 2px 0 4px; }
.related-cost { font-size: 1rem; font-weight: 800; color: var(--orange); }
.related-cost span { font-size: 0.7rem; font-weight: 400; color: var(--text-sub); }

/* 戻るボタン */
.back-link-wrap { margin-top: 16px; text-align: center; }
.btn-back {
  display: inline-block;
  padding: 10px 24px;
  border: 2px solid var(--blue);
  color: var(--blue);
  border-radius: 4px;
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 700;
  transition: background 0.15s;
}
.btn-back:hover { background: var(--blue); color: white; }

/* モバイル対応：詳細ページ */
@media (max-width: 768px) {
  .detail-hero { flex-direction: column; gap: 16px; padding: 16px; }
  .detail-hero-img { width: 100%; }
  .detail-hero-img img { width: 140px; height: 140px; }
  .spec-grid { grid-template-columns: repeat(3, 1fr); }
  .related-grid { grid-template-columns: 1fr; }
  .detail-retailer-list { grid-template-columns: repeat(2, 1fr) !important; gap: 8px; }
}
