:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --text: #1c2321;
  --muted: #5d6663;
  --line: #dfe3e0;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --good: #15803d;
  --good-bg: #e7f6ec;
  --warn: #a16207;
  --warn-bg: #fdf4dc;
  --bad: #b91c1c;
  --bad-bg: #fde8e8;
  --ad-bg: #eef0ee;
  --radius: 12px;
  --tabbar-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121615;
    --surface: #1b2120;
    --text: #e8ecea;
    --muted: #9aa5a1;
    --line: #2d3533;
    --accent: #2dd4bf;
    --accent-ink: #062b27;
    --good: #4ade80;
    --good-bg: #13301d;
    --warn: #facc15;
    --warn-bg: #332a0c;
    --bad: #f87171;
    --bad-bg: #3a1616;
    --ad-bg: #222927;
  }
}
:root[data-theme="dark"] {
  --bg: #121615; --surface: #1b2120; --text: #e8ecea; --muted: #9aa5a1; --line: #2d3533;
  --accent: #2dd4bf; --accent-ink: #062b27; --good: #4ade80; --good-bg: #13301d;
  --warn: #facc15; --warn-bg: #332a0c; --bad: #f87171; --bad-bg: #3a1616; --ad-bg: #222927;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.35; }

/* ---------- 共通部品 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin: 0 0 12px;
  display: block;
}
label { display: block; font-size: 14px; color: var(--muted); }
input, select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  font: inherit;
  font-size: 16px; /* iPhoneで拡大されないように16px以上 */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.grid2 .span2 { grid-column: 1 / -1; }
.stack { display: grid; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  font: inherit; font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; white-space: nowrap; flex: none; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.file-btn input { display: none; }

.chip {
  min-height: 36px; padding: 0 14px;
  font: inherit; font-size: 14px;
  color: var(--muted); background: var(--surface);
  border: 1px solid var(--line); border-radius: 999px; cursor: pointer;
}
.chip.active { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }

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

/* 広告枠：実際の広告に差し替える場所 */
.ad-slot {
  display: flex; align-items: center; justify-content: center;
  min-height: 60px;
  margin: 12px 0;
  font-size: 12px; color: var(--muted);
  background: var(--ad-bg);
  border: 1px dashed var(--line);
  border-radius: 8px;
  list-style: none;
}

/* ---------- アプリ画面 ---------- */
body.app { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
.app-header {
  position: sticky; top: 0; z-index: 5;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.tentative { color: var(--muted); font-weight: 400; font-size: 13px; }
#main { max-width: 640px; margin: 0 auto; padding: 12px 16px; }
.tab-title { font-size: 20px; margin: 4px 0 12px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tabbar button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font: inherit; font-size: 11px;
  color: var(--muted); background: none; border: 0; cursor: pointer;
}
.tabbar button span { font-size: 20px; line-height: 1; }
.tabbar button.active { color: var(--accent); font-weight: 700; }

.scanner { margin: 12px 0; }
#reader { border-radius: var(--radius); overflow: hidden; background: #000; margin-bottom: 8px; }
#scan-btn { margin-bottom: 12px; }

.search-links { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }
.search-links:empty { display: none; }
#research-form > label { margin-bottom: 10px; }
#jan-form .row input { margin-top: 0; flex: 1; min-width: 0; }
#jan-form label { margin-bottom: 4px; }
.lookup-status { margin: 8px 0 0; font-size: 14px; color: var(--muted); }
.lookup-status:empty { display: none; }

/* スキャン後の部類ごとの表示 */
.sec {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0 0 10px;
}
.sec > summary {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 14px;
  cursor: pointer; list-style: none;
}
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary::after { content: "▾"; color: var(--muted); transition: transform .15s; }
.sec:not([open]) > summary::after { transform: rotate(-90deg); }
.sec-title { font-weight: 700; }
.sec-sum { margin-left: auto; font-size: 13px; color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }
.sec-body { padding: 0 14px 14px; }
.sec-body > .note:first-child { margin-top: 0; }
.product { display: flex; gap: 12px; align-items: flex-start; }
.product img { width: 96px; height: 96px; object-fit: contain; background: #fff; border-radius: 8px; flex: none; }
.product strong { display: block; margin-bottom: 4px; overflow-wrap: anywhere; }
.product .note { margin: 0; font-size: 13px; }
.offers { margin-top: 10px; }
.offers a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
.inapp-notice {
  margin-bottom: 12px; padding: 12px;
  background: var(--warn-bg); color: var(--warn);
  border-radius: 8px;
}
.inapp-notice p { margin: 4px 0 10px; font-size: 14px; color: var(--text); }
.inapp-notice .note { color: var(--muted); margin-bottom: 0; }
.shop-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.shop-buttons:empty::before { content: "JANを入れると、各ショップの検索結果をワンタップで開けます。"; grid-column: 1 / -1; font-size: 14px; color: var(--muted); }
.shop-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 56px; padding: 6px 8px;
  font-weight: 700; color: var(--text); text-decoration: none;
  background: var(--bg); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 10px;
}
.shop-btn small { font-size: 11px; font-weight: 400; color: var(--muted); }
.shop-btn.shop-amazon { grid-column: 1 / -1; border-left-color: #f59e0b; }
.shop-btn.shop-mercari { border-left-color: #ef4444; }
.shop-btn.shop-surugaya { border-left-color: #3b82f6; }
.shop-btn.shop-yahuoku { border-left-color: #eab308; }
.shop-btn.shop-rakuten { border-left-color: #bf0000; }
.caution-list { margin: 0; padding-left: 1.2em; font-size: 14px; }
.caution-list li { margin-bottom: 6px; color: var(--muted); }
.caution-list li.strong { color: var(--warn); font-weight: 600; }
.credit { text-align: center; font-size: 12px; }
.credit a { color: var(--muted); }

.result .verdict {
  padding: 10px 12px; margin-bottom: 12px;
  border-radius: 8px; font-weight: 600;
  background: var(--bg); color: var(--muted);
}
.verdict.good { background: var(--good-bg); color: var(--good); }
.verdict.warn { background: var(--warn-bg); color: var(--warn); }
.verdict.bad { background: var(--bad-bg); color: var(--bad); }
.figures { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 0 14px; }
.figures div { padding: 8px 10px; background: var(--bg); border-radius: 8px; }
.figures dt { font-size: 12px; color: var(--muted); }
.figures dd { margin: 0; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 12px; }
.summary div { padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.summary dt { font-size: 12px; color: var(--muted); }
.summary dd { margin: 0; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.filters { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; }

.list { list-style: none; margin: 0; padding: 0; }
.list.compact li { padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.item { border-left: 4px solid var(--line); }
.item.status-bought { border-left-color: var(--warn); }
.item.status-listed { border-left-color: var(--accent); }
.item.status-sold { border-left-color: var(--good); }
.item-head { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.item-head strong { overflow-wrap: anywhere; }
.item-head select { width: auto; margin: 0; padding: 6px 8px; font-size: 14px; }
.item-meta { display: flex; flex-wrap: wrap; gap: 2px 14px; margin: 8px 0; font-size: 14px; color: var(--muted); }
.item-jan { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.pos { color: var(--good); font-weight: 600; }
.neg { color: var(--bad); font-weight: 600; }

.chart { width: 100%; height: auto; display: block; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-target { stroke: var(--warn); stroke-width: 1.5; stroke-dasharray: 4 4; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.chart-dot { fill: var(--accent); }
.chart-label { fill: var(--muted); font-size: 10px; }
.chart-empty { fill: var(--muted); font-size: 12px; }
.track-status { margin: 8px 0 0; font-size: 14px; }
.track-status.reached { color: var(--good); font-weight: 700; }

dialog {
  width: min(92vw, 400px);
  padding: 18px;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog h2 { margin: 0; font-size: 18px; }
dialog .row { justify-content: flex-end; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  padding: 10px 16px;
  color: var(--accent-ink); background: var(--accent);
  border-radius: 999px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 20; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 紹介・解説ページ ---------- */
.site-header {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px 12px;
  max-width: 960px; margin: 0 auto; padding: 14px 16px;
}
.site-header .brand { white-space: nowrap; }
.site-header nav { display: flex; gap: 14px; flex-wrap: wrap; font-size: 14px; }
.page { max-width: 760px; margin: 0 auto; padding: 8px 16px 48px; }
.hero { padding: 32px 0 24px; }
.hero h1 { font-size: clamp(26px, 6vw, 38px); margin: 0 0 12px; }
.hero p { font-size: 17px; color: var(--muted); margin: 0 0 20px; }
.features { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin: 16px 0 32px; }
.features h3 { margin: 0 0 6px; font-size: 17px; }
.features p { margin: 0; font-size: 15px; color: var(--muted); }
.page h2 { font-size: 22px; margin: 36px 0 12px; }
.page h3 { font-size: 18px; margin: 24px 0 8px; }
.definition { padding: 14px 16px; background: var(--surface); border-left: 4px solid var(--accent); border-radius: 0 8px 8px 0; }
.faq details { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 8px; }
.faq summary { font-weight: 600; cursor: pointer; }
.formula { padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; font-weight: 600; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.breadcrumb { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.breadcrumb a { color: var(--muted); }
.site-footer { border-top: 1px solid var(--line); padding: 20px 16px 32px; font-size: 13px; color: var(--muted); text-align: center; }
.site-footer nav { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin-bottom: 8px; }
