:root {
  --bg: #faf7f2;
  --panel: #ffffff;
  --text: #2b2b2b;
  --muted: #767065;
  --border: #e6e0d6;
  --accent: #b71c1c;
  --accent-soft: #fdecea;
  --sale: #c62828;
  --link: #1558b0;
  --chip-bg: #f1ece3;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171512;
    --panel: #211e1a;
    --text: #ece7de;
    --muted: #a39b8d;
    --border: #38332c;
    --accent: #ef5350;
    --accent-soft: #3a2222;
    --sale: #ff8a80;
    --link: #82b1ff;
    --chip-bg: #2c2822;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.site-header { padding: 28px 20px 10px; max-width: 1080px; margin: 0 auto; position: relative; }
.lang-toggle {
  position: absolute; top: 30px; right: 20px;
  font: inherit; font-size: 0.82rem; font-weight: 600;
  padding: 5px 14px; border-radius: 999px; cursor: pointer;
  border: 1.5px solid var(--border); background: var(--panel); color: var(--text);
}
.lang-toggle:hover { border-color: var(--accent); color: var(--accent); }
.site-header h1 { margin: 0; font-size: 1.7rem; padding-right: 100px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo { width: 74px; height: 74px; border-radius: 50%; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-main { font-size: 1.65rem; font-weight: 800; letter-spacing: 0.01em; }
.brand-main .accent { color: var(--accent); }
.brand-sub { font-size: 0.82rem; font-weight: 600; color: var(--muted); letter-spacing: 0.03em; }
.subtitle { margin: 4px 0 0; color: var(--muted); }
.updated { margin: 4px 0 0; font-size: 1.05rem; font-weight: 600; color: var(--accent); }

.tabs {
  display: flex; gap: 8px; padding: 14px 20px 0;
  max-width: 1080px; margin: 0 auto;
  border-bottom: 2px solid var(--border);
}
.tab {
  appearance: none; border: none; background: none;
  font: inherit; font-weight: 600; color: var(--muted);
  padding: 8px 14px; cursor: pointer;
  border-bottom: 3px solid transparent; margin-bottom: -2px;
  /* タブ名を1行に保つ。折り返すと狭い画面で1文字ずつ縦に崩れる */
  white-space: nowrap; flex: none;
}

@media (max-width: 700px) {
  /* タブが増えて収まらない画面では、縦に潰さず横スクロールさせる */
  .tabs {
    overflow-x: auto;
    scrollbar-width: none;
    padding-left: 16px; padding-right: 16px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 8px 10px; font-size: 0.94rem; }
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab:hover { color: var(--accent); }

main { max-width: 1080px; margin: 0 auto; padding: 16px 20px 40px; }
.panel { display: none; }
.panel.active { display: block; }

.controls { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.controls .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.controls input[type="search"], .controls select {
  font: inherit; padding: 7px 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel); color: var(--text);
}
.controls input[type="search"] { flex: 1 1 220px; min-width: 180px; }
.check { font-size: 0.9rem; color: var(--muted); white-space: nowrap; }

.store-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit; font-size: 0.85rem; font-weight: 600;
  padding: 4px 12px; border-radius: 999px; cursor: pointer;
  border: 1.5px solid var(--border); background: var(--chip-bg); color: var(--muted);
}
.chip.active { color: #fff; border-color: transparent; background: var(--accent); }
.chip-store { display: inline-flex; align-items: center; gap: 6px; }
.chip-ico {
  width: 16px; height: 16px; object-fit: contain;
  border-radius: 3px; background: #fff; flex: none;
}
.chip-sm { font-size: 0.78rem; padding: 3px 10px; font-weight: 500; }
.chip:disabled { opacity: 0.35; cursor: default; }
.origin-row { align-items: flex-start; flex-wrap: nowrap; }
.filter-label { font-size: 0.85rem; font-weight: 600; color: var(--muted); padding-top: 4px; white-space: nowrap; }

.count { color: var(--muted); font-size: 0.85rem; margin: 6px 2px; }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
th, td { text-align: left; padding: 9px 12px; border-top: 1px solid var(--border); vertical-align: top; }
thead th { border-top: none; font-size: 0.8rem; color: var(--muted); white-space: nowrap; position: sticky; top: 0; background: var(--panel); }
.num { text-align: right; white-space: nowrap; }
td.num { font-variant-numeric: tabular-nums; }
tr.oos { opacity: 0.5; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

.store-tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.78rem; font-weight: 600; color: var(--text); white-space: nowrap;
}
.badge-ico {
  width: 15px; height: 15px; object-fit: contain;
  border-radius: 50%; background: #fff; flex: none;
}
.price-main { font-weight: 700; }
.price-was { color: var(--muted); text-decoration: line-through; font-size: 0.8rem; margin-left: 4px; }
.badge-sale {
  display: inline-block; background: var(--accent-soft); color: var(--sale);
  font-size: 0.72rem; font-weight: 700; padding: 1px 7px; border-radius: 4px; white-space: nowrap;
}
.badge-oos { font-size: 0.72rem; color: var(--muted); white-space: nowrap; }
.prod-cell { display: flex; align-items: center; gap: 10px; min-width: 240px; }
.thumb {
  width: 80px; height: 80px; object-fit: contain; flex: none;
  border-radius: 8px; border: 1px solid var(--border); background: #fff;
}
.thumb-ph { display: flex; align-items: center; justify-content: center; font-size: 34px; }
.spark-cell { vertical-align: middle; }
.spark { display: block; }
.spark-none { color: var(--muted); }
.trend-down { color: #2e7d32; font-size: 0.78rem; font-weight: 700; margin-left: 5px; white-space: nowrap; }
.trend-up { color: var(--sale); font-size: 0.78rem; font-weight: 700; margin-left: 5px; white-space: nowrap; }
@media (prefers-color-scheme: dark) { .trend-down { color: #81c784; } }
.unit-best { color: var(--sale); font-weight: 700; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; display: flex; flex-direction: column; gap: 8px;
}
.card h3 { margin: 0; font-size: 1rem; line-height: 1.4; }
.card .meta { font-size: 0.8rem; color: var(--muted); }
.card .period-line { font-weight: 600; color: var(--text); }
.card ul { margin: 0; padding-left: 18px; font-size: 0.85rem; }
.card li { margin: 2px 0; }
.card .more { margin-top: auto; font-size: 0.85rem; font-weight: 600; }
.period-active { color: #2e7d32; font-weight: 700; }
@media (prefers-color-scheme: dark) { .period-active { color: #81c784; } }

.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pill {
  font-size: 0.75rem; font-weight: 700; white-space: nowrap;
  padding: 2px 10px; border-radius: 999px;
  background: var(--chip-bg); color: var(--text);
}
.pill-active { background: #e3f2e5; color: #2e7d32; }
.pill-upcoming { background: #fdf0dc; color: #b26a00; }
@media (prefers-color-scheme: dark) { .pill-upcoming { background: #3a2f1c; color: #ffb74d; } }
.pill-muted { background: none; border: 1px dashed var(--border); color: var(--muted); font-weight: 500; }
@media (prefers-color-scheme: dark) {
  .pill-active { background: #24361f; color: #81c784; }
}

.site-footer {
  max-width: 1080px; margin: 0 auto; padding: 24px 20px 48px;
  color: var(--muted); font-size: 0.8rem; border-top: 1px solid var(--border);
}

/* 過去のセール履歴 */
.hist-heading { font-size: 1.05rem; margin: 30px 2px 10px; }
.hist-entry {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 14px; margin-bottom: 10px; font-size: 0.9rem;
}
.hist-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hist-period { font-weight: 700; color: var(--accent); white-space: nowrap; }
.hist-title { font-weight: 600; }
.hist-count { font-size: 0.78rem; color: var(--muted); }
.hist-items { margin: 6px 0 0; padding-left: 20px; color: var(--muted); }
.hist-items li { margin: 2px 0; }

/* 同一商品の店舗比較カード */
.cmp-name { font-weight: 600; font-size: 0.92rem; line-height: 1.45; }
.cmp-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 2px; border-top: 1px solid var(--border); font-size: 0.9rem;
}
.cmp-row a { color: inherit; }
.cmp-price { font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.cmp-best .cmp-price { color: #2e7d32; }
@media (prefers-color-scheme: dark) { .cmp-best .cmp-price { color: #81c784; } }
.cmp-pack { font-size: 0.75rem; color: var(--muted); margin-left: 4px; }
.cmp-unit { font-size: 0.78rem; color: var(--muted); font-weight: 500; }
.pill-live { background: var(--accent-soft); color: var(--sale); }
.note { color: var(--muted); font-size: 0.78rem; margin: 4px 2px 0; }

/* 本日の最安米ハイライト */
.highlights { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 12px; margin-bottom: 4px; }
.hl-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
/* カード見出しはセール情報カード(h3)と同じ1remに揃える */
.hl-label { font-size: 1rem; font-weight: 700; color: var(--accent); margin-bottom: 8px; }
.hl-best { display: flex; gap: 12px; align-items: center; color: inherit; }
.hl-best:hover, .hl-row:hover { text-decoration: none; }
.hl-best:hover .hl-name, .hl-row:hover .hl-row-name { text-decoration: underline; }
.hl-best .thumb { width: 64px; height: 64px; }
.hl-best-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
/* 価格行: 「1kgあたり 単価(赤・小さめ) 総額(黒)」— リスト表示と同じ並び */
.hl-price-line { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px; }
.hl-unit-label { font-size: 0.72rem; font-weight: 600; color: var(--muted); }
.hl-unit { font-size: 1.15rem; font-weight: 800; color: var(--sale); line-height: 1.15; }
.hl-total { font-size: 1.3rem; font-weight: 800; color: var(--text); line-height: 1.15; }
.hl-unit-sm { font-size: 0.9rem; font-weight: 700; color: var(--sale); }
.hl-total-sm { font-size: 0.9rem; font-weight: 700; color: var(--text); }
.hl-per { font-size: 0.78rem; font-weight: 600; color: var(--muted); margin-left: 2px; }
.hl-name { font-size: 0.9rem; font-weight: 600; color: var(--link); }
.hl-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 0.78rem; color: var(--muted); }
/* 2・3位も1位と同じ構成: 左に商品画像、右に「メダル+金額 / 商品名 / 店舗・産地・容量」の3行 */
.hl-row {
  display: flex; align-items: flex-start; gap: 12px; color: inherit;
  border-top: 1px solid var(--border); margin-top: 8px; padding-top: 8px; font-size: 0.82rem;
}
.hl-medal { width: 19px; height: 19px; flex: none; }
.hl-medal-lg { width: 26px; height: 26px; vertical-align: -5px; margin-right: 4px; }
.hl-row-img { flex: none; display: flex; justify-content: center; width: 64px; }
.hl-row-img .thumb { width: 48px; height: 48px; border-radius: 6px; }
/* 1位(.hl-best-body)と同じく「単価 / 商品名 / 店舗・産地・容量」の縦3行に固定する。
   折り返し前提の横並びにすると、商品名が短い行だけ単価と同じ行に載って構成がずれる。 */
.hl-row-body { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.hl-row-unit { display: flex; align-items: baseline; gap: 5px; white-space: nowrap; flex: none; }
.hl-per-sm { font-size: 0.72rem; font-weight: 600; color: var(--muted); margin-left: 1px; }
.hl-row-name { color: var(--link); line-height: 1.35; }
.hl-row-meta { display: flex; align-items: center; gap: 8px; flex: none; }
.hl-row-origin, .hl-row-size { color: var(--muted); white-space: nowrap; }

/* スマホ: メダルと画像を左に固定し、右側を「単価 → 商品名 → 産地・店舗」の縦並びにする
   (1位カードと同じ視線の流れに揃える) */
@media (max-width: 560px) {
  .hl-row-unit { font-size: 0.95rem; }
}

/* ==== スマホ: 表を縦積みカードに再構成 ====
   横スクロールを無くし「商品 → 単価・価格 → 店舗などの補足」の重要度順に並べる */
@media (max-width: 560px) {
  .table-wrap { overflow-x: visible; }
  /* 行をグリッド化するため、表自体もブロック化して幅を画面に合わせる */
  table { display: block; width: 100%; font-size: 0.88rem; }
  tbody { display: block; width: 100%; }
  thead { display: none; }
  tbody tr { display: grid; gap: 3px 10px; padding: 10px 12px; border-top: 1px solid var(--border); }
  /* .num の nowrap/右寄せより強い指定にして、狭い幅でも折り返せるようにする */
  tbody td, tbody td.num { border: none; padding: 0; text-align: left; white-space: normal; min-width: 0; }
  td[data-label]::before {
    content: attr(data-label) " ";
    color: var(--muted); font-size: 0.72rem; font-weight: 500;
  }
  .prod-cell { min-width: 0; gap: 8px; }
  .prod-cell .thumb { width: 64px; height: 64px; }
  .td-prod { grid-area: prod; }
  .td-store { grid-area: store; }
  .td-origin { grid-area: origin; color: var(--muted); }
  .td-size { grid-area: size; color: var(--muted); }
  .td-price { grid-area: price; }
  .td-badge { grid-area: badge; }
  .td-unit { grid-area: unit; font-weight: 700; }
  .td-serv { grid-area: serv; font-weight: 700; }
  .td-per100 { grid-area: per100; font-weight: 700; }
  .td-bbd { grid-area: bbd; }
  .td-disc { grid-area: disc; }
  #rice-table tbody tr {
    /* 3列目はSALEバッジの実寸に合わせ、左2列を伸縮させる */
    grid-template-columns: minmax(0, auto) minmax(0, 1fr) max-content;
    grid-template-areas: "prod prod prod" "unit price badge" "store origin size";
  }
  #noodle-table tbody tr {
    grid-template-columns: minmax(0, auto) minmax(0, 1fr) max-content;
    grid-template-areas: "prod prod prod" "price serv per100" "store size badge";
  }
  #seasoning-table tbody tr {
    grid-template-columns: minmax(0, auto) minmax(0, 1fr) max-content;
    grid-template-areas: "prod prod prod" "price per100 badge" "store heat size";
  }
  #curry-table tbody tr {
    grid-template-columns: minmax(0, auto) minmax(0, 1fr) max-content;
    grid-template-areas: "prod prod prod" "price per100 serv" "store size heat" "badge badge badge";
  }
  .td-heat { grid-area: heat; color: var(--muted); }
  #cl-table tbody tr {
    grid-template-columns: minmax(0, auto) minmax(0, 1fr);
    grid-template-areas: "prod prod" "price disc" "store bbd";
  }
}
.per-unit { font-size: 0.72rem; font-weight: 500; color: var(--muted); }
.until-tag { font-size: 0.72rem; font-weight: 700; color: var(--sale); white-space: nowrap; }

/* 「もっと見る」: 一覧の初期表示を絞り、必要な人だけ追記する */
.more-btn {
  display: block; width: 100%; max-width: 320px; margin: 14px auto 0;
  padding: 11px 18px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--card); color: var(--link);
  font-size: 0.9rem; font-weight: 700; font-family: inherit; cursor: pointer;
}
.more-btn:hover { border-color: var(--accent); color: var(--accent); }

.footer-links { margin-top: 10px; }
.footer-links a { font-weight: 600; }

/* 辛さは短い語なので折り返さない(「甘口」が縦に割れるのを防ぐ) */
#curry-table .td-heat { white-space: nowrap; color: var(--muted); }

/* カレータブ先頭の「同一商品の店舗比較」の見出し */
.cmp-heading { font-size: 1rem; font-weight: 700; color: var(--accent); margin: 18px 0 2px; }
.cmp-heading + .note { margin-top: 0; margin-bottom: 10px; }

/* ==== セール中の商品カード ==== */
.deal-cards { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); margin-bottom: 6px; }
.deal-card {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel); color: inherit;
}
.deal-card:hover { border-color: var(--accent); text-decoration: none; }
.deal-card .thumb { width: 56px; height: 56px; flex: none; border-radius: 6px; }
.deal-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.deal-name { font-size: 0.85rem; font-weight: 600; color: var(--link); line-height: 1.35; }
.deal-price { font-size: 1.05rem; font-weight: 800; }
.deal-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 0.75rem; color: var(--muted); }
.deal-size { white-space: nowrap; }
/* 割引率は価格の横に置く。カード右上に浮かせると商品名に重なる */
.deal-price { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; }

/* ==== 送料表 ==== */
/* 下の余白はフッターと切り離すためのもの。詰めると、フッターの区切り線が
   送料表の行罫線と同じ太さ・色・幅のため、表の一部に見えてしまう */
.shipping { max-width: 1200px; margin: 28px auto 44px; padding: 0 16px; }
/* 見出しの隣に免責を置く。表全体にかかる注意なので脚注より頭に出す */
.shipping-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-bottom: 8px; }
.shipping-title { font-size: 1rem; font-weight: 700; color: var(--accent); margin: 0; }
.shipping-caveat { margin: 0; font-size: 0.75rem; color: var(--muted); line-height: 1.5; }
#shipping-table { font-size: 0.85rem; }
#shipping-table td { vertical-align: top; }
/* 補足条件は本体より一段弱く、必ず改行して添える */
.ship-sub { display: block; font-size: 0.75rem; color: var(--muted); line-height: 1.4; margin-top: 2px; }
.td-ship-fee, .td-ship-free { font-weight: 700; }
/* 送料無料の設定が無い店は数値と区別できるよう弱める */
.ship-none { font-weight: 500; color: var(--muted); }
.ship-warn { color: var(--sale); font-weight: 700; }
.ship-link { display: inline-block; margin-left: 10px; font-weight: 600; white-space: nowrap; }

@media (max-width: 560px) {
  /* 表の共通スマホ処理(カード化)に合わせ、店舗を見出し行にして送料2項目を並べる */
  #shipping-table tbody tr {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "store" "fee" "free";
    gap: 6px;
  }
  .td-ship-fee { grid-area: fee; }
  .td-ship-free { grid-area: free; }
  .td-ship-stale { grid-area: fee; }
  .ship-link { margin-left: 0; display: block; margin-top: 4px; }
}
