:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --text: #1f2328;
  --sub: #6b7280;
  --line: #e4e1d9;
  --accent: #2f7d6b;
  --accent-soft: #e3f1ed;
  --up: #c8402f;
  --up-soft: #fbe9e6;
  --down: #1f6fb5;
  --down-soft: #e4f0fa;
  --check: #9a6b12;
  --check-soft: #f8efd9;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --card: #232528;
    --text: #eceef0;
    --sub: #9aa1aa;
    --line: #34373c;
    --accent: #5fc2aa;
    --accent-soft: #1f3a34;
    --up: #ff8a78;
    --up-soft: #47241f;
    --down: #7cbcf2;
    --down-soft: #1d3346;
    --check: #e3b860;
    --check-soft: #3d3220;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}
#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* ---- 上部バー ---- */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
}
.bar h1 { margin: 0; font-size: 22px; }
.bar .link {
  border: 0; background: none; padding: 8px 4px;
  color: var(--accent); font-weight: 600; font-size: 16px;
}

/* ---- ホーム ---- */
.search { padding: 0 16px 12px; }
.search input {
  width: 100%; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); font-size: 16px;
  -webkit-appearance: none; appearance: none;
}
.plist { list-style: none; margin: 0; padding: 0 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.pitem {
  display: flex; gap: 12px; align-items: center;
  padding: 10px; border-radius: 14px;
  background: var(--card); border: 1px solid var(--line);
}
.thumb {
  flex: none; width: 64px; height: 64px; border-radius: 10px;
  background: var(--bg); object-fit: cover;
  display: grid; place-items: center; color: var(--sub); font-size: 24px;
}
.pitem .info { min-width: 0; flex: 1; }
.pitem .name { font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
.pitem .last { font-size: 14px; color: var(--sub); overflow-wrap: anywhere; }
.pitem .last b { font-size: 17px; color: var(--text); margin: 0 4px 0 2px; }
.pitem .now { font-size: 13px; color: var(--check); }
.empty { padding: 48px 24px; text-align: center; color: var(--sub); }
.fab {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom));
  padding: 14px 28px; border: 0; border-radius: 999px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 17px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .22);
  white-space: nowrap; z-index: 6;
}
@media (prefers-color-scheme: dark) { .fab, .btn.primary, .seg input:checked + span, .chips input:checked + span { color: #10201c; } }

/* ---- 商品ページ ---- */
.photo { display: block; width: 100%; max-height: 300px; object-fit: contain; background: var(--card); }
.pad { padding: 0 16px; }
.pname { margin: 14px 0 4px; font-size: 21px; line-height: 1.35; overflow-wrap: anywhere; }
.pmemo { margin: 0 0 12px; white-space: pre-wrap; color: var(--sub); font-size: 15px; overflow-wrap: anywhere; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0 4px; }
.stat { padding: 12px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); }
.stat .label { font-size: 13px; color: var(--sub); }
.stat .price { font-size: 26px; font-weight: 700; line-height: 1.25; }
.stat .where { font-size: 13px; color: var(--sub); }
.stat.best { background: var(--accent-soft); border-color: transparent; }
.stat.best .price { color: var(--accent); }
h2.sec { margin: 22px 0 8px; font-size: 15px; color: var(--sub); font-weight: 600; }
.rows { border-radius: 14px; background: var(--card); border: 1px solid var(--line); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 11px 12px; border: 0; border-top: 1px solid var(--line);
  background: none; text-align: left;
}
.row:first-child { border-top: 0; }
.row .main { flex: 1; min-width: 0; }
.row .top { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.row .price { font-size: 18px; font-weight: 700; }
.row .meta { font-size: 13px; color: var(--sub); }
.row .note { font-size: 13px; color: var(--sub); overflow-wrap: anywhere; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.tag.up { background: var(--up-soft); color: var(--up); }
.tag.down { background: var(--down-soft); color: var(--down); }
.tag.same { background: var(--bg); color: var(--sub); }
.tag.check { background: var(--check-soft); color: var(--check); }
.tag.best { background: var(--accent-soft); color: var(--accent); }
.btn {
  border: 1px solid var(--line); background: var(--card);
  padding: 8px 14px; border-radius: 10px; font-weight: 600; font-size: 15px; white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--up); }
.btn.block { display: block; width: 100%; padding: 12px; }
.hint { font-size: 13px; color: var(--sub); margin: 8px 0 0; }

/* ---- 入力シート ---- */
dialog#sheet {
  width: 100%; max-width: 560px; max-height: 92vh; max-height: 92dvh;
  margin: auto auto 0; padding: 0; border: 0;
  border-radius: 18px 18px 0 0;
  background: var(--bg); color: var(--text);
  overflow: auto;
}
dialog#sheet::backdrop { background: rgba(0, 0, 0, .45); }
.sheet-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-head button { border: 0; background: none; padding: 6px 4px; font-size: 16px; color: var(--accent); }
.sheet-head button[type=submit] { font-weight: 700; }
.sheet-body { padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); display: grid; gap: 16px; }
.field { display: grid; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span, .field > legend { font-size: 13px; color: var(--sub); font-weight: 600; padding: 0; }
.field > legend { margin-bottom: 6px; }
.field input[type=text], .field input[type=date], .field textarea, .field input:not([type]) {
  width: 100%; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); font-size: 16px;
  -webkit-appearance: none; appearance: none;
}
.field input[type=date] { min-height: 46px; }
.field textarea { resize: vertical; }
.price-in { display: flex; align-items: center; gap: 8px; }
.price-in input { font-size: 24px !important; font-weight: 700; text-align: right; }
.price-in span { font-size: 18px; font-weight: 600; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 0; padding: 3px; border-radius: 12px; background: var(--line); }
.seg input, .chips input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 9px; border-radius: 10px; text-align: center; font-weight: 600; color: var(--sub); }
.seg input:checked + span { background: var(--accent); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips span, .chips button {
  display: block; padding: 9px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); font-size: 15px;
}
.chips input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.chips button { color: var(--accent); border-style: dashed; }
.photo-pick {
  display: grid; place-items: center; position: relative;
  min-height: 150px; border-radius: 14px; overflow: hidden;
  border: 1px dashed var(--line); background: var(--card); color: var(--sub);
}
.photo-pick input, .file-btn input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; }
.crop {
  width: 100%; max-width: 300px; aspect-ratio: 1; margin: 0 auto;
  border-radius: 14px; overflow: hidden;
  border: 1px solid var(--line); background: var(--card);
}
.crop img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  pointer-events: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.crop.movable { touch-action: none; cursor: grab; }
.photo-tools { display: flex; justify-content: center; gap: 8px; margin-top: 10px; }
.file-btn { position: relative; overflow: hidden; }
.hint.center { text-align: center; }
.version { margin: 28px 0 0; text-align: center; font-size: 12px; color: var(--sub); opacity: .7; }

/* ---- 設定 ---- */
.store-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-top: 1px solid var(--line); }
.store-row:first-child { border-top: 0; }
.store-row button { border: 0; background: none; color: var(--up); padding: 6px; font-size: 14px; }
.stack { display: grid; gap: 10px; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(90px + env(safe-area-inset-bottom));
  padding: 10px 18px; border-radius: 999px;
  background: rgba(30, 30, 30, .92); color: #fff; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 100; white-space: nowrap;
}
#toast.show { opacity: 1; }
