/* ============================================================
   SUDONE scanner PWA — shares the landing's "tactile scanner"
   language (Plus Jakarta Sans + Noto Sans JP, blue/teal, scan
   brackets + scan-line) but pared down to a single-purpose tool.
   ============================================================ */
:root {
  --blue: #1f5cff;
  --blue-dark: #1746c8;
  --teal: #18c39a;
  --teal-dark: #0c7d5f;

  --ink: #161f33;
  --muted: #5a6678;
  --bg: #ffffff;
  --bg-soft: #f3f7fd;
  --bg-tint: #eaf1fe;
  --border: #e4eaf3;

  /* Dark "scanner" stage — mirrors the landing video section */
  --scanner-1: #0e1c3c;
  --scanner-2: #0a1226;

  --radius: 22px;
  --radius-sm: 14px;
  --shadow-sm: 0 2px 10px rgba(20, 31, 51, 0.05);
  --shadow: 0 16px 44px rgba(31, 92, 255, 0.13);

  --rakuten: #bf0000;
  --amber-ink: #9a6a00;
  --danger: #b42318;

  --font: "Plus Jakarta Sans", "Noto Sans JP", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(120% 60% at 50% -8%, rgba(31, 92, 255, 0.07), transparent 60%),
    var(--bg-soft);
  color: var(--ink);
  line-height: 1.6;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
main { max-width: 560px; margin: 0 auto; padding: 16px clamp(14px, 4vw, 20px) 44px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px clamp(14px, 4vw, 20px);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.logo { height: 30px; display: block; }
.install-btn {
  background: var(--bg-tint);
  border: 1px solid rgba(31, 92, 255, 0.18);
  color: var(--blue-dark);
  font-family: inherit; font-weight: 700; font-size: 0.82rem;
  padding: 8px 15px; border-radius: 999px; cursor: pointer;
  transition: transform 0.15s ease;
}
.install-btn:active { transform: scale(0.97); }

/* ---------- Scanner stage ---------- */
.video-wrap {
  position: relative; width: 100%; aspect-ratio: 4 / 3;
  background:
    radial-gradient(120% 90% at 50% 0, rgba(31, 92, 255, 0.28), transparent 58%),
    linear-gradient(180deg, var(--scanner-1), var(--scanner-2));
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
#video { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Scan-bracket reticle (the brand motif) */
.reticle { position: absolute; inset: 15% 12%; pointer-events: none; z-index: 2; }
.reticle span {
  position: absolute; width: 32px; height: 32px;
  border: 3px solid var(--teal);
  filter: drop-shadow(0 0 6px rgba(24, 195, 154, 0.45));
}
.reticle span:nth-child(1) { top: 0; left: 0; border-right: none; border-bottom: none; border-radius: 5px 0 0 0; }
.reticle span:nth-child(2) { top: 0; right: 0; border-left: none; border-bottom: none; border-radius: 0 5px 0 0; }
.reticle span:nth-child(3) { bottom: 0; left: 0; border-right: none; border-top: none; border-radius: 0 0 0 5px; }
.reticle span:nth-child(4) { bottom: 0; right: 0; border-left: none; border-top: none; border-radius: 0 0 5px 0; }

/* Sweeping scan-line — the signature motion, also functionally apt here */
.scanline {
  position: absolute; left: 12%; right: 12%; top: 15%; height: 2px;
  background: linear-gradient(90deg, transparent, var(--teal), transparent);
  box-shadow: 0 0 14px 2px rgba(24, 195, 154, 0.5);
  pointer-events: none; z-index: 1;
}
.scan-hint {
  position: absolute; left: 0; right: 0; bottom: 12px; text-align: center;
  color: rgba(255, 255, 255, 0.92); font-size: 0.85rem; font-weight: 600;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6); z-index: 2;
}

/* ---------- Controls + buttons ---------- */
.scan-controls { margin-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  border: none; border-radius: 14px; font-family: inherit;
  font-size: 1rem; font-weight: 700; padding: 14px 18px; min-height: 50px;
  cursor: pointer; transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn-primary { background: var(--blue); color: #fff; box-shadow: var(--shadow); width: 100%; }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 20px 50px rgba(31, 92, 255, 0.32); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost { background: #fff; color: var(--blue-dark); border: 1px solid var(--border); }
.btn-ghost:active { background: var(--bg-tint); }

.manual { display: flex; gap: 8px; }
.manual input {
  flex: 1; min-width: 0; padding: 13px 15px;
  border: 1px solid var(--border); border-radius: 14px;
  font-family: inherit; font-size: 1rem; background: #fff; color: var(--ink);
}
.manual input::placeholder { color: var(--muted); }
.manual input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(31, 92, 255, 0.15); }

/* ---------- Result card ---------- */
.result {
  margin-top: 18px; background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px;
  animation: pop 0.25s ease;
}
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.r-loading { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.r-top { display: flex; gap: 14px; align-items: flex-start; }
.result img.thumb,
.result .thumb {
  width: 72px; height: 72px; border-radius: 14px; object-fit: cover;
  background: var(--bg-soft); border: 1px solid var(--border); flex: none;
}
.r-name { font-weight: 700; font-size: 1.06rem; line-height: 1.35; }
.r-jan { color: var(--muted); font-size: 0.82rem; font-variant-numeric: tabular-nums; margin-top: 2px; }
.badge {
  display: inline-block; font-size: 0.72rem; font-weight: 700;
  padding: 3px 10px; border-radius: 999px; margin-top: 8px;
}
.badge.exact { background: rgba(24, 195, 154, 0.16); color: var(--teal-dark); }
.badge.likely { background: rgba(255, 194, 61, 0.22); color: var(--amber-ink); }
.badge.none { background: #fdecec; color: var(--danger); }
.badge.weak { background: #fdf1e7; color: #b4561f; }
/* Match feedback nudge (shown on low-confidence matches) */
.match-fb {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-top: 12px; padding: 10px 12px; font-size: 0.85rem;
  background: #fdf6ef; border: 1px solid #f3ddc6; border-radius: var(--radius-sm);
}
.fb-btn {
  font-family: inherit;
  padding: 4px 14px; font-size: 0.85rem; font-weight: 700;
  background: #fff; border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
}
.fb-btn:hover { border-color: var(--ink); }
.fb-btn:disabled { opacity: 0.55; pointer-events: none; }

.shelf { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--border); }
.shelf label { font-size: 0.85rem; color: var(--muted); font-weight: 600; display: block; margin-bottom: 8px; }
.shelf .row { display: flex; gap: 8px; }
.shelf input {
  flex: 1; min-width: 0; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 12px; font-family: inherit; font-size: 1rem; background: #fff;
}
.shelf input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(24, 195, 154, 0.16); }
.shelf .btn { background: var(--teal); color: #fff; min-height: 0; padding: 12px 18px; }
.shelf .btn:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(24, 195, 154, 0.3); }
.r-error { color: var(--danger); font-weight: 700; }

/* ---------- Offers (multi-source price comparison) ---------- */
.offers {
  margin: 16px 0 4px; padding-top: 16px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 12px;
}
.offer { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; }
.offer .src { font-weight: 700; min-width: 52px; }
.offer .src.rakuten { color: var(--rakuten); }
.offer .src.yahoo { color: #e60023; }
.offer .src.amazon { color: #c45500; }
.offer .amount { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.offer.best .amount { color: var(--teal-dark); }
.offer .tag {
  font-size: 0.66rem; font-weight: 800; color: var(--teal-dark);
  background: rgba(24, 195, 154, 0.16); padding: 2px 8px; border-radius: 999px;
}
.offer .spacer { flex: 1; min-width: 0; }
.offer a.go {
  flex: none; margin-left: auto;
  text-decoration: none; color: #fff; font-weight: 700; font-size: 0.85rem;
  padding: 9px 16px; border-radius: 12px; white-space: nowrap;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.offer a.go.rakuten { background: var(--rakuten); }
.offer a.go.yahoo { background: #e60023; }
.offer a.go.amazon { background: #c45500; }
.offer a.go.other { background: var(--blue); }
.offer a.go:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(0, 0, 0, 0.18); }
.offer-empty { color: var(--muted); font-weight: 600; }
.offer-store { color: var(--muted); font-size: 0.85rem; font-weight: 600; }
/* True-price extras: shipping chip + effective (price - points) */
.ship {
  font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  white-space: nowrap;
}
.ship.free { background: rgba(24, 195, 154, 0.14); color: var(--teal-dark); }
.ship.extra { background: #fdecec; color: var(--danger); }
.ship.conditional { background: #f3f1ec; color: var(--muted); }
.eff { color: var(--teal-dark); font-size: 0.85rem; font-weight: 700; white-space: nowrap; }
.eff small { color: var(--muted); font-weight: 600; }
.btn:disabled { opacity: 0.55; pointer-events: none; }

/* ---------- Tax basis toggle (税込 / 税抜) ---------- */
.tax-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; background: var(--bg); }
.seg button { border: none; background: transparent; padding: 7px 14px; font: inherit; font-size: 0.85rem; font-weight: 700; color: var(--muted); cursor: pointer; min-height: 0; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.seg-on { background: var(--teal); color: #fff; }
/* author display rules beat the UA [hidden] rule — restore it for the rate seg */
.seg[hidden] { display: none; }
.tax-note { font-size: 0.82rem; font-weight: 700; color: var(--teal-dark); }

/* ---------- Verdict (the one clear answer at the shelf) ---------- */
.verdict { margin-top: 14px; }
.vbox { border-radius: var(--radius-sm); padding: 14px 16px; border: 1.5px solid transparent; }
.vbox .v-title { font-weight: 800; font-size: 1.18rem; line-height: 1.3; }
.vbox .v-sub { font-size: 0.9rem; font-weight: 600; margin-top: 3px; }
.v-buy { background: rgba(24, 195, 154, 0.14); border-color: rgba(24, 195, 154, 0.5); }
.v-buy .v-title, .v-buy .v-sub { color: var(--teal-dark); }
.v-check { background: var(--bg-tint); border-color: rgba(31, 92, 255, 0.4); }
.v-check .v-title, .v-check .v-sub { color: var(--blue-dark); }
.v-caution { background: rgba(255, 194, 61, 0.18); border-color: rgba(154, 106, 0, 0.4); }
.v-caution .v-title, .v-caution .v-sub { color: var(--amber-ink); }
.v-weak { background: var(--bg-soft); border-color: var(--border); }
.v-weak .v-title, .v-weak .v-sub { color: var(--muted); }

/* Notebook indicator under the verdict (安い / 普通 / 高い vs your own records) */
.verdict-book { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; font-weight: 700; font-size: 0.9rem; }
.verdict-book .vb-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.verdict-book .vb-meta { color: var(--muted); font-weight: 600; font-size: 0.82rem; }
.verdict-book.v-low { color: var(--teal-dark); }
.verdict-book.v-low .vb-dot { background: var(--teal); }
.verdict-book.v-mid { color: var(--blue-dark); }
.verdict-book.v-mid .vb-dot { background: var(--blue); }
.verdict-book.v-high { color: var(--amber-ink); }
.verdict-book.v-high .vb-dot { background: #e0a92e; }

/* ---------- All-prices (detail) ---------- */
.all-prices-btn {
  margin-top: 14px; width: 100%;
  background: var(--bg-tint); color: var(--blue-dark);
  border: 1px solid rgba(31, 92, 255, 0.18); border-radius: 12px;
  font-family: inherit; font-weight: 700; font-size: 0.9rem;
  padding: 11px 16px; cursor: pointer;
}
.all-prices-btn:active { transform: scale(0.99); }
.all-prices { margin-top: 12px; }
.all-list { list-style: none; padding: 0; margin: 0; }
.all-row {
  display: flex; flex-direction: column; gap: 4px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.all-row:last-child { border-bottom: none; }
.all-row.best .amount { color: var(--teal-dark); }
.all-main { display: flex; align-items: baseline; gap: 10px; }
.all-main .src { font-weight: 700; min-width: 64px; }
.all-main .src.rakuten { color: var(--rakuten); }
.all-main .src.yahoo { color: #e60023; }
.all-main .amount { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.all-unit { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.all-title { color: var(--ink); font-size: 0.82rem; line-height: 1.35; }
.all-row a.go {
  align-self: flex-start; margin-top: 2px; text-decoration: none; color: #fff;
  font-weight: 700; font-size: 0.8rem; padding: 7px 13px; border-radius: 10px;
}
.all-row a.go.rakuten { background: var(--rakuten); }
.all-row a.go.yahoo { background: #e60023; }
.all-row a.go.other { background: var(--blue); }
.all-empty { color: var(--muted); font-weight: 600; padding: 10px 0; }

/* ---------- Update bar (new-version prompt) ---------- */
.update-bar {
  position: fixed; left: 16px; right: 16px; margin: 0 auto; max-width: 528px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: var(--blue); color: #fff; padding: 12px 12px 12px 20px;
  border-radius: 16px; font-size: 0.92rem; font-weight: 700; line-height: 1.35;
  box-shadow: 0 12px 34px rgba(31, 92, 255, 0.4); z-index: 60;
}
.update-btn {
  flex: none; white-space: nowrap;
  background: #fff; color: var(--blue-dark); border: none; cursor: pointer;
  font-family: inherit; font-weight: 800; font-size: 0.88rem;
  padding: 10px 20px; border-radius: 10px;
}
.update-btn:active { transform: scale(0.97); }

/* ---------- Per-product price history (inside result card) ---------- */
.phist { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--border); }
.phist-title { font-size: 0.85rem; color: var(--muted); font-weight: 700; margin-bottom: 10px; }
.phist-list { list-style: none; padding: 0; margin: 0; }
.phist-list li {
  display: flex; align-items: baseline; gap: 10px;
  padding: 7px 0; border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.phist-list li:last-child { border-bottom: none; }
.phist-list .h-src { font-weight: 700; font-size: 0.9rem; flex: 1; }
.phist-list .h-amt { font-weight: 800; }
.phist-list .h-date { color: var(--muted); font-size: 0.8rem; width: 56px; text-align: right; }

/* ---------- History ---------- */
.history { margin-top: 30px; }
.history-head { display: flex; align-items: center; justify-content: space-between; }
.history-head h2 { font-size: 1.12rem; font-weight: 800; letter-spacing: -0.01em; margin: 0; }
.link-btn {
  background: none; border: none; color: var(--muted);
  font-family: inherit; font-weight: 600; font-size: 0.85rem; cursor: pointer; padding: 4px 6px;
}
.link-btn:hover { color: var(--ink); }
.history-list { list-style: none; padding: 0; margin: 14px 0 0; }
.history-list li {
  padding: 13px 15px; background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 9px; box-shadow: var(--shadow-sm);
}
.history-list li.has-book { cursor: pointer; }
.history-list .h-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.history-actions { display: flex; gap: 14px; }
.history-hint { color: var(--muted); font-size: 0.78rem; margin-top: 10px; }
/* My price notebook (entries I recorded for this item) */
.mybook { list-style: none; padding: 10px 0 0; margin: 10px 0 0; border-top: 1px dashed var(--border); }
.mybook li { display: flex; align-items: center; gap: 10px; padding: 4px 0; font-size: 0.86rem; }
.mybook .mb-date { color: var(--muted); width: 44px; font-variant-numeric: tabular-nums; }
.mybook .mb-store { flex: 1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mybook .mb-price { font-variant-numeric: tabular-nums; }
.mybook-empty { padding: 10px 0 0; margin-top: 10px; border-top: 1px dashed var(--border); color: var(--muted); font-size: 0.82rem; }
.history-list .h-name { font-weight: 700; font-size: 0.92rem; }
.history-list .h-jan { color: var(--muted); font-size: 0.76rem; font-variant-numeric: tabular-nums; margin-top: 2px; }
.history-list .h-price { font-weight: 800; white-space: nowrap; font-variant-numeric: tabular-nums; }
.history-empty { color: var(--muted); font-size: 0.92rem; margin-top: 12px; }

/* ---------- App footer (disclosure + legal links) ---------- */
.app-foot { margin-top: 36px; padding-top: 18px; border-top: 1px solid var(--border); text-align: center; }
.app-disclosure { color: var(--muted); font-size: 0.78rem; line-height: 1.7; margin: 0 0 10px; }
.app-foot-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 18px; }
.app-foot-links a { color: var(--blue-dark); font-size: 0.8rem; font-weight: 600; text-decoration: none; }
.app-foot-links a:hover { text-decoration: underline; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px;
  font-size: 0.9rem; font-weight: 600; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28); z-index: 50;
}

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: no-preference) {
  .scanline { animation: scan 2.6s cubic-bezier(0.5, 0, 0.5, 1) infinite; }
}
@keyframes scan {
  0% { top: 15%; opacity: 0.4; }
  50% { top: 85%; opacity: 1; }
  100% { top: 15%; opacity: 0.4; }
}

@media (max-width: 380px) {
  .reticle { inset: 16% 10%; }
  .result { padding: 18px; }
}

/* Optional store name + location opt-in on the shelf-price form (#16) */
#storeInput { width: 100%; margin-top: 10px; }
.shelf-loc {
  display: flex; align-items: center; gap: 8px; margin-top: 10px;
  font-size: 0.85rem; color: var(--muted); font-weight: 600; cursor: pointer;
}
.shelf-loc input[type="checkbox"] {
  width: auto; flex: none; min-height: 0; padding: 0; margin: 0;
  accent-color: var(--teal);
}
