:root {
  --bg: #f7f3ee;
  --card: #ffffff;
  --ink: #2a1f1d;
  --muted: #7a6b66;
  --line: #e6ddd5;
  --wine: #7b1e3a;
  --wine-soft: #f5e6eb;
  --ok: #2f7a4a;
  --ok-soft: #e4f2e8;
  --warn: #9a6200;
  --warn-soft: #fbf0d9;
  --bad: #a3262b;
  --bad-soft: #fbe5e5;
  --radius: 14px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif; line-height: 1.55;
}
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--card);
  position: sticky; top: 0; z-index: 5;
}
header h1 { font-size: 18px; margin: 0; letter-spacing: .04em; }
header h1 span { color: var(--wine); }
header a { color: var(--muted); font-size: 13px; }
main { max-width: 980px; margin: 0 auto; padding: 16px; }

.upload {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px 16px;
  background: var(--card); text-align: center;
}
.upload p { margin: 0; color: var(--muted); font-size: 14px; }
.btn {
  appearance: none; border: 0; border-radius: 999px; padding: 11px 20px; font-size: 15px;
  background: var(--wine); color: #fff; cursor: pointer; font-weight: 600;
}
.btn.ghost { background: transparent; color: var(--wine); border: 1px solid var(--wine); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.on { background: var(--warn); color: #fff; border-color: var(--warn); }

.loading { text-align: center; padding: 36px 0; color: var(--muted); }
.spinner {
  width: 34px; height: 34px; margin: 0 auto 10px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--wine); animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.warn { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 14px; margin: 12px 0; font-size: 14px; }
.error { background: var(--bad-soft); color: var(--bad); border-radius: 10px; padding: 10px 14px; margin: 12px 0; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; margin-top: 16px; }
@media (min-width: 860px) { .layout { grid-template-columns: 380px minmax(0, 1fr); align-items: start; }
  .photo-col { position: sticky; top: 70px; } }

.stage { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; user-select: none; }
.stage img { display: block; width: 100%; height: auto; }
.stage.adding { cursor: crosshair; touch-action: none; outline: 3px solid var(--warn); }
.box { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 2px rgba(123,30,58,.9); border-radius: 4px; pointer-events: none; }
.box.manual { box-shadow: 0 0 0 2px rgba(154,98,0,.95); }
.box.temp { border-style: dashed; box-shadow: 0 0 0 2px rgba(154,98,0,.95); }
.box span {
  position: absolute; left: -2px; top: -2px; background: var(--wine); color: #fff; font-size: 12px; font-weight: 700;
  min-width: 22px; text-align: center; border-radius: 4px 0 6px 0; padding: 1px 5px;
}
.box.manual span { background: var(--warn); }
.photo-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.hint { color: var(--muted); font-size: 13px; }

.bottle { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.bottle-head { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.num { background: var(--wine); color: #fff; border-radius: 6px; font-weight: 700; padding: 1px 8px; font-size: 14px; }
.num.manual { background: var(--warn); }
.read { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.qthumb { width: 46px; height: 64px; object-fit: cover; border-radius: 6px; background: #eee; flex: none; }

/* 第1候補: 大きく独立した欄 */
.top1 { border: 2px solid var(--wine); background: var(--wine-soft); border-radius: 12px; padding: 14px; }
.top1.unsure { border-color: var(--warn); background: var(--warn-soft); }
.top1 .vbox { background: #fff; }
.match { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 16px; align-items: start; }
.match img { width: 200px; height: 280px; object-fit: cover; border-radius: 10px; background: #fff; cursor: zoom-in; }
.match .labels { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 6px; }
.match h3 { margin: 0 0 4px; font-size: 21px; line-height: 1.35; }
.match .prod { font-size: 14px; color: var(--muted); }
@media (max-width: 560px) {
  .match { grid-template-columns: minmax(0, 1fr); }
  .match img { width: 100%; height: 300px; object-fit: contain; }
}
.vin { font-size: 26px; font-weight: 700; color: var(--wine); margin: 4px 0; }
.badge { display: inline-block; font-size: 12px; border-radius: 999px; padding: 2px 10px; font-weight: 600; margin-right: 4px; }
.badge.high { background: var(--ok-soft); color: var(--ok); }
.badge.medium { background: var(--warn-soft); color: var(--warn); }
.badge.low { background: var(--bad-soft); color: var(--bad); }
.reason { font-size: 13px; color: var(--ink); margin: 6px 0; }
.desc { font-size: 12px; color: var(--muted); }

.vbox { border-radius: 10px; padding: 8px 12px; margin-top: 10px; font-size: 13px; }
.vbox.v-match { background: var(--ok-soft); color: var(--ok); }
.vbox.v-nv, .vbox.v-unread_single { background: #f1ede9; color: var(--muted); }
.vbox.v-match_uncertain, .vbox.v-unread_multi, .vbox.v-not_in_db { background: var(--warn-soft); color: var(--warn); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 12px; font-size: 13px; cursor: pointer; color: var(--ink); }
.chip.current { border-color: var(--wine); background: var(--wine-soft); font-weight: 700; }

details { margin-top: 10px; }
summary { cursor: pointer; color: var(--wine); font-size: 14px; }
/* 第2候補以降: 小さく並べる */
.cands { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 8px; }
@media (max-width: 560px) { .cands { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.cand { border: 1px solid var(--line); border-radius: 10px; padding: 6px; font-size: 11px; background: #fff; display: flex; flex-direction: column; gap: 4px; }
.cand img { width: 100%; height: 100px; object-fit: cover; border-radius: 6px; background: #eee; cursor: zoom-in; }
.cand b { font-size: 12px; line-height: 1.35; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.cand .btn.small { padding: 4px 8px; font-size: 11px; }
.cand .sc { color: var(--muted); font-size: 11px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.done { color: var(--ok); font-size: 13px; font-weight: 600; }
.searchbox { display: flex; gap: 6px; margin-top: 10px; }
.searchbox input { flex: 1; padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; font-size: 14px; }

.zoom { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; z-index: 20; }
.zoom img { max-width: 94vw; max-height: 92vh; border-radius: 8px; }

.login { max-width: 360px; margin: 12vh auto; background: var(--card); border-radius: var(--radius); padding: 28px; border: 1px solid var(--line); }
.login h1 { font-size: 20px; margin: 0 0 18px; }
.login label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.login input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 16px; }
.login .btn { width: 100%; margin-top: 18px; }

.cand-title { margin-top: 16px; font-size: 13px; font-weight: 700; color: var(--muted); }
.cand .rank { font-size: 11px; font-weight: 700; color: var(--wine); }
.rank1 { font-size: 13px; font-weight: 700; color: #fff; background: var(--wine); border-radius: 999px; padding: 2px 12px; }

/* 写真を選ぶボタン: 透明な選択欄をボタン全体に重ねる（iPhone/Android/LINE内ブラウザでも開くように） */
.btn.pick { position: relative; overflow: hidden; display: inline-block; }
.btn.pick input[type=file] {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; font-size: 100px;
}
