/* ============================================================
   添加物Bye — 見た目の設定
   色を変えたいときは、下の :root の値を書き換えてください
   ============================================================ */

:root {
  --brand: #e8613c;
  --brand-dark: #c94a28;
  --bg: #f6f4f0;
  --card: #ffffff;
  --text: #23201d;
  --text-sub: #6d675f;
  --line: #e6e1d8;
  --red: #d93b30;
  --red-bg: #fdeceb;
  --yellow: #c98a06;
  --yellow-bg: #fdf5e2;
  --green: #2e8b57;
  --green-bg: #eaf6ee;
  --gray: #8a837a;
  --gray-bg: #f0eeea;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 6px 18px rgba(0,0,0,.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17150f;
    --card: #221f1a;
    --text: #f2efe9;
    --text-sub: #a49d92;
    --line: #35302a;
    --red: #ff7b6f;
    --red-bg: #3a201d;
    --yellow: #f0b93f;
    --yellow-bg: #362c14;
    --green: #6fd39a;
    --green-bg: #1a3226;
    --gray: #9a938a;
    --gray-bg: #2b2822;
    --shadow: 0 1px 3px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 0 0 calc(72px + env(safe-area-inset-bottom));
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  font-size: 16px;
}

/* ---------- ヘッダー ---------- */
.appbar {
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #fff;
  padding: calc(16px + env(safe-area-inset-top)) 20px 16px;
  text-align: center;
}
.appbar h1 { margin: 0; font-size: 22px; letter-spacing: .04em; font-weight: 800; }
.appbar h1 span { font-weight: 400; opacity: .85; }
.tagline { margin: 4px 0 0; font-size: 12.5px; opacity: .9; }

main { max-width: 640px; margin: 0 auto; padding: 14px 14px 0; }

/* ---------- 画面切り替え ---------- */
.view { display: none; }
.view.is-active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- カード ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card-title { margin: 0 0 8px; font-size: 15px; font-weight: 700; }
.hint { margin: 0 0 12px; font-size: 13px; color: var(--text-sub); }

/* ---------- 入力ボタン ---------- */
.input-buttons { display: grid; gap: 10px; }
.bigbtn {
  display: grid; gap: 1px;
  border: 2px dashed var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
  font: inherit;
  width: 100%;
  transition: border-color .15s, background .15s;
}
.bigbtn:active { border-color: var(--brand); background: var(--gray-bg); }
.bigbtn-icon { font-size: 22px; line-height: 1.2; }
.bigbtn-label { font-weight: 700; font-size: 15.5px; }
.bigbtn-sub { font-size: 12.5px; color: var(--text-sub); }

.tip { margin-top: 12px; font-size: 13px; }
.tip summary { cursor: pointer; color: var(--brand); font-weight: 600; }
.tip p { margin: 8px 0 0; color: var(--text-sub); line-height: 1.75; }

/* ---------- OCR進捗 ---------- */
.ocr-progress { margin-top: 14px; }
.ocr-bar { height: 6px; border-radius: 99px; background: var(--gray-bg); overflow: hidden; }
.ocr-bar-fill { height: 100%; width: 0%; background: var(--brand); transition: width .25s; }
.ocr-status { margin: 6px 0 0; font-size: 13px; font-weight: 600; }
.ocr-note { margin: 2px 0 0; font-size: 12px; color: var(--text-sub); }

.preview { display: block; width: 100%; border-radius: 10px; margin-top: 12px; max-height: 220px; object-fit: cover; }

/* ---------- フォーム ---------- */
.field-label { display: block; margin: 14px 0 6px; font-size: 13px; font-weight: 700; color: var(--text-sub); }
textarea, input[type="search"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  padding: 11px 12px;
  font: inherit;
  font-size: 16px;
  resize: vertical;
}
textarea:focus, input[type="search"]:focus { outline: 2px solid var(--brand); outline-offset: 1px; }

.row { display: flex; gap: 8px; margin-top: 12px; }
button.primary, button.ghost {
  font: inherit; font-weight: 700; border-radius: 10px; padding: 12px 16px; cursor: pointer; border: 1px solid transparent;
}
button.primary { flex: 1; background: var(--brand); color: #fff; font-size: 16.5px; }
button.primary:active { background: var(--brand-dark); }
button.primary:disabled { opacity: .5; }
button.ghost { background: transparent; color: var(--text-sub); border-color: var(--line); }
button.ghost.danger { color: var(--red); border-color: var(--red); width: 100%; }

/* ---------- 判定結果 ---------- */
.summary-card { display: flex; gap: 8px; }
.summary-pill {
  flex: 1; text-align: center; border-radius: 10px; padding: 10px 4px;
}
.summary-pill b { display: block; font-size: 22px; line-height: 1.2; }
.summary-pill span { font-size: 11.5px; }
.summary-pill.red { background: var(--red-bg); color: var(--red); }
.summary-pill.yellow { background: var(--yellow-bg); color: var(--yellow); }
.summary-pill.green { background: var(--green-bg); color: var(--green); }

.result-item {
  display: flex; align-items: flex-start; gap: 10px;
  width: 100%; text-align: left; font: inherit; cursor: pointer;
  background: var(--card); color: var(--text);
  border: 0; border-bottom: 1px solid var(--line);
  padding: 13px 14px;
}
.result-item:last-child { border-bottom: 0; }
.result-item:active { background: var(--gray-bg); }
.result-list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 14px; }
.result-dot { font-size: 15px; line-height: 1.6; }
.result-main { flex: 1; min-width: 0; }
.result-name { font-weight: 700; font-size: 15px; }
.result-meta { font-size: 12.5px; color: var(--text-sub); }
.result-arrow { color: var(--text-sub); font-size: 13px; align-self: center; }
.badge-fuzzy {
  display: inline-block; font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 99px;
  background: var(--yellow-bg); color: var(--yellow); margin-left: 6px; vertical-align: 1px;
}

.section-label { margin: 0 2px 6px; font-size: 12.5px; font-weight: 700; color: var(--text-sub); }
.unknown-card p { margin: 0 0 6px; font-size: 13px; color: var(--text-sub); }
.unknown-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.unknown-tag { font-size: 12.5px; background: var(--gray-bg); color: var(--text-sub); border-radius: 99px; padding: 3px 10px; }

.empty { text-align: center; color: var(--text-sub); font-size: 14px; padding: 26px 10px; }

/* ---------- 辞書 ---------- */
.filter-chips { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 99px;
  border: 1px solid var(--line); background: transparent; color: var(--text-sub); cursor: pointer;
}
.chip.is-on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.list-count { margin: 0 2px 8px; font-size: 12.5px; color: var(--text-sub); }

/* ---------- 履歴・統計 ---------- */
.stats-card { display: flex; gap: 8px; text-align: center; }
.stat { flex: 1; }
.stat-num { display: block; font-size: 26px; font-weight: 800; line-height: 1.2; color: var(--brand); }
.stat-num.stat-red { color: var(--red); }
.stat-label { font-size: 11.5px; color: var(--text-sub); }

.month-chart { display: flex; align-items: flex-end; gap: 6px; height: 92px; }
.month-bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; height: 100%; }
.month-bar-fill { width: 100%; background: var(--brand); border-radius: 5px 5px 0 0; }
.month-bar-fill.is-zero { background: var(--line); height: 3px !important; }
.month-bar-num { font-size: 11px; font-weight: 700; color: var(--text-sub); }
.month-bar-label { font-size: 10.5px; color: var(--text-sub); }

.history-item .result-main > span { display: block; }
.history-date { font-size: 12px; color: var(--text-sub); }
.history-text { font-size: 13.5px; color: var(--text); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.history-counts { font-size: 12.5px; margin-top: 2px; }

/* ---------- 設定 ---------- */
.switch { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14.5px; }
.switch:last-of-type { border-bottom: 0; }
.switch input { width: 20px; height: 20px; accent-color: var(--brand); }
.disclaimer { border-left: 4px solid var(--brand); }
.disclaimer p { font-size: 13px; color: var(--text-sub); margin: 0 0 8px; }
.disclaimer p:last-child { margin-bottom: 0; }

/* ---------- 詳細シート ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--card); color: var(--text);
  border-radius: 18px 18px 0 0;
  max-height: 86vh; overflow-y: auto;
  padding: 20px 18px calc(28px + env(safe-area-inset-bottom));
  box-shadow: 0 -6px 30px rgba(0,0,0,.2);
  animation: slideup .22s ease;
  max-width: 640px; margin: 0 auto;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }
.sheet-close {
  position: sticky; top: 0; float: right; margin: -6px -4px 0 0;
  border: 0; background: var(--gray-bg); color: var(--text-sub);
  width: 32px; height: 32px; border-radius: 99px; font-size: 15px; cursor: pointer;
}
.sheet h2 { margin: 0 0 2px; font-size: 20px; line-height: 1.4; padding-right: 34px; }
.sheet .sheet-cat { font-size: 13px; color: var(--text-sub); margin: 0 0 12px; }
.rank-tag { display: inline-block; font-size: 12.5px; font-weight: 700; border-radius: 99px; padding: 3px 12px; margin-bottom: 10px; }
.rank-tag.red { background: var(--red-bg); color: var(--red); }
.rank-tag.yellow { background: var(--yellow-bg); color: var(--yellow); }
.rank-tag.green { background: var(--green-bg); color: var(--green); }
.sheet-block { margin: 14px 0 0; }
.sheet-block h3 { margin: 0 0 4px; font-size: 13.5px; color: var(--brand); }
.sheet-block p { margin: 0; font-size: 14px; line-height: 1.8; }
.alias-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.alias { font-size: 12.5px; background: var(--gray-bg); color: var(--text-sub); border-radius: 6px; padding: 3px 8px; }
.alias.is-hit { background: var(--brand); color: #fff; font-weight: 700; }
.sheet-source { margin-top: 16px; font-size: 11.5px; color: var(--text-sub); border-top: 1px solid var(--line); padding-top: 10px; }

/* ---------- タブバー ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 10.5px; color: var(--text-sub);
  padding: 8px 2px 7px; display: grid; gap: 1px; justify-items: center;
}
.tab span { font-size: 20px; line-height: 1.2; filter: grayscale(1); opacity: .6; }
.tab.is-active { color: var(--brand); font-weight: 700; }
.tab.is-active span { filter: none; opacity: 1; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 99px; font-size: 13.5px; font-weight: 600;
  z-index: 60; box-shadow: var(--shadow); animation: fade .2s ease;
}

/* ============================================================
   追加機能（商品情報・裏読み・代替提案・AI）
   ============================================================ */

.bigbtn-main { border-style: solid; border-color: var(--brand); background: var(--card); }
.bigbtn-main .bigbtn-label { color: var(--brand); }

.barcode-row { display: flex; gap: 8px; align-items: center; }
.barcode-row input {
  flex: 1; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  color: var(--text); padding: 11px 12px; font: inherit; font-size: 16px; min-width: 0;
}
.barcode-row button { white-space: nowrap; }

/* --- 見つかった商品 --- */
.product-card { display: flex; gap: 12px; align-items: flex-start; }
.product-photo {
  width: 88px; height: 88px; flex: none; object-fit: contain;
  background: var(--gray-bg); border-radius: 10px;
}
.product-info { flex: 1; min-width: 0; }
.product-name { font-weight: 700; font-size: 15.5px; line-height: 1.45; }
.product-brand { font-size: 12.5px; color: var(--text-sub); }
.product-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.ptag { font-size: 11.5px; font-weight: 700; border-radius: 6px; padding: 2px 8px; background: var(--gray-bg); color: var(--text-sub); }
.ptag.nova4, .ptag.nutri-e, .ptag.nutri-d { background: var(--red-bg); color: var(--red); }
.ptag.nova3, .ptag.nutri-c { background: var(--yellow-bg); color: var(--yellow); }
.ptag.nova1, .ptag.nova2, .ptag.nutri-a, .ptag.nutri-b { background: var(--green-bg); color: var(--green); }

/* --- 裏読みノート --- */
.note {
  border-left: 4px solid var(--gray);
  background: var(--card); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 8px; box-shadow: var(--shadow);
}
.note.warn { border-left-color: var(--red); }
.note.info { border-left-color: var(--yellow); }
.note.good { border-left-color: var(--green); }
.note-title { font-weight: 700; font-size: 14.5px; line-height: 1.5; }
.note-body { font-size: 13.5px; color: var(--text-sub); line-height: 1.75; margin-top: 3px; }

/* --- 代替商品の提案 --- */
.alt-item {
  display: flex; gap: 10px; align-items: center; text-decoration: none;
  padding: 11px 12px; border-bottom: 1px solid var(--line);
  width: 100%; text-align: left; background: var(--card); color: var(--text);
  border-left: 0; border-right: 0; border-top: 0; font: inherit; cursor: pointer;
}
.alt-item:last-child { border-bottom: 0; }
.alt-photo { width: 56px; height: 56px; flex: none; object-fit: contain; background: var(--gray-bg); border-radius: 8px; }
.alt-info { flex: 1; min-width: 0; }
.alt-name { font-weight: 700; font-size: 14px; line-height: 1.4; display: block; }
.alt-item, .alt-item * { text-decoration: none; }
.alt-meta { font-size: 12px; color: var(--text-sub); margin-top: 2px; }
.attribution { font-size: 11px; color: var(--text-sub); padding: 8px 12px 10px; }
.attribution a { color: var(--text-sub); }

/* --- AI --- */
.ai-card { border-left: 4px solid var(--brand); }
.ai-btn {
  width: 100%; font: inherit; font-weight: 700; font-size: 15px;
  border: 1px solid var(--brand); color: var(--brand); background: transparent;
  border-radius: 10px; padding: 12px; cursor: pointer;
}
.ai-btn:active { background: var(--gray-bg); }
.ai-btn:disabled { opacity: .55; }
.ai-output h3 { font-size: 14.5px; color: var(--brand); margin: 14px 0 4px; }
.ai-output h3:first-child { margin-top: 0; }
.ai-output p { font-size: 13.5px; line-height: 1.8; margin: 0 0 6px; }
.ai-output ul { margin: 0 0 8px; padding-left: 1.2em; }
.ai-output li { font-size: 13.5px; line-height: 1.75; margin-bottom: 3px; }
.ai-note { font-size: 11.5px; color: var(--text-sub); margin-top: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
.ai-key-status { font-size: 12.5px; margin: 6px 0 0; }
.ai-key-status.ok { color: var(--green); }
input[type="password"], input[type="text"] {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  color: var(--text); padding: 11px 12px; font: inherit; font-size: 16px;
}

.spinner {
  display: inline-block; width: 14px; height: 14px; vertical-align: -2px; margin-right: 6px;
  border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
