:root {
  --bg: #f2f4f6;
  --text: #191f28;
  --sub: #6b7684;
  --faint: #8b95a1;
  --line: #f2f4f6;
  --field: #f2f4f6;
  --red: #e5323c;
  --blue: #3182f6;
  color-scheme: light;
}
* { box-sizing: border-box; }
/* 버튼을 빠르게 두 번 눌러도 화면이 확대되지 않게 */
html { touch-action: manipulation; }
button, label, summary { -webkit-tap-highlight-color: transparent; }
p { margin: 0; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

header {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fff;
  padding: calc(14px + env(safe-area-inset-top)) 0 0;
}
header > * { max-width: 640px; margin-left: auto; margin-right: auto; padding-left: 16px; padding-right: 16px; }
h1 { margin-bottom: 12px; font-size: 22px; font-weight: 700; letter-spacing: -0.03em; }

.search { position: relative; display: flex; gap: 8px; margin-bottom: 0; }
.search .glass {
  position: absolute;
  left: 30px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  fill: none;
  stroke: var(--faint);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}
.search input {
  flex: 1;
  min-width: 0;
  height: 46px;
  padding: 0 14px 0 40px;
  border: 0;
  border-radius: 12px;
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  outline: none;
}
.search input::placeholder { color: var(--faint); }
.search input:focus { box-shadow: inset 0 0 0 2px var(--blue); background: #fff; }
.cam {
  display: grid;
  padding: 0;
  border: 0;
  place-items: center;
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--text);
  cursor: pointer;
}
.cam svg { width: 22px; height: 22px; fill: none; stroke: #fff; stroke-width: 1.8; stroke-linejoin: round; }
.cam:active { transform: scale(0.96); }
.cam.busy { opacity: 0.4; pointer-events: none; }
.status { padding-top: 8px; font-size: 13px; color: var(--sub); }
.status:empty { display: none; }
.status.err { color: var(--red); }

#cats {
  display: flex;
  gap: 20px;
  margin-top: 6px;
  /* 좌우로만 움직이게: 세로 스크롤과 끝에서 튕기는 동작을 막는다 */
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  border-bottom: 1px solid #e5e8eb;
}
#cats::-webkit-scrollbar { display: none; }
#cats button {
  flex: none;
  padding: 10px 0 12px;
  border: 0;
  background: none;
  color: var(--faint);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
/* 밑줄을 테두리 대신 안쪽 그림자로 그려서 탭 줄 밖으로 삐져나오지 않게 한다 */
#cats button.on { color: var(--text); box-shadow: inset 0 -2px 0 var(--text); }

main { max-width: 640px; margin: 0 auto; padding: 0 12px; }
.caption { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 2px 8px 6px; font-size: 13px; color: var(--sub); }
#sort {
  appearance: none;
  -webkit-appearance: none;
  height: 32px;
  padding: 0 26px 0 10px;
  border: 0;
  border-radius: 8px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%236b7684' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 8px center / 12px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

#list { list-style: none; margin: 0; padding: 0; background: #fff; border-radius: 16px; overflow: hidden; }
.row + .row .head { border-top: 1px solid var(--line); }
.head { display: flex; gap: 14px; padding: 14px 16px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.head:active { background: #f9fafb; }
.bottle {
  flex: none;
  width: 60px;
  height: 80px;
  padding: 4px;
  border-radius: 10px;
  background: #f9fafb;
  object-fit: contain;
  mix-blend-mode: multiply;
}
.bottle.none { display: block; }
img.bottle { cursor: zoom-in; }

#viewer {
  width: min(92vw, 520px);
  max-height: 90vh;
  padding: 20px 20px 16px;
  border: 0;
  border-radius: 20px;
  background: #fff;
  overflow: hidden;
  outline: none;
  text-align: center;
  cursor: zoom-out;
}
#viewer::backdrop { background: rgba(0, 0, 0, 0.55); }
#viewer img { display: block; width: 100%; max-height: calc(90vh - 90px); object-fit: contain; mix-blend-mode: multiply; }
#viewer p { margin-top: 10px; font-size: 15px; font-weight: 600; }
.body { flex: 1; min-width: 0; }
.name { display: flex; align-items: baseline; gap: 6px; }
.name strong { font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name span { flex: none; font-size: 12px; color: var(--faint); }
.sub { margin-top: 1px; font-size: 12px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pp { margin-top: 8px; display: grid; gap: 2px; }
.pp p { display: flex; align-items: baseline; gap: 6px; font-size: 15px; white-space: nowrap; }
.pp .lb { width: 26px; flex: none; font-size: 13px; color: var(--sub); }
.pp b { font-weight: 600; }
.pp .krw { font-size: 13px; color: var(--sub); }
.pct { font-size: 12px; font-weight: 600; color: var(--red); }
.pct.up { color: var(--blue); }

.detail { padding: 0 16px 16px 90px; font-size: 14px; }
.range { font-size: 13px; color: var(--sub); }
.verdict { margin-top: 6px; font-weight: 500; }
.cheap { color: var(--red); }
.calc { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.calc input[type="number"] {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: var(--field);
  font: inherit;
  font-size: 16px;
  outline: none;
}
.calc input[type="number"]:focus { box-shadow: inset 0 0 0 2px var(--blue); background: #fff; }
.calc .tax { display: flex; align-items: center; gap: 5px; flex: none; color: var(--sub); font-size: 14px; }
.calc .tax input { width: 18px; height: 18px; margin: 0; accent-color: var(--blue); }
output { display: block; margin-top: 8px; font-size: 14px; }
output:empty { display: none; }
.info { margin-top: 12px; font-size: 12px; color: var(--faint); }
.info summary { cursor: pointer; }
.info p { margin-top: 6px; }
.info a { color: inherit; }

.empty { padding: 48px 16px; text-align: center; color: var(--sub); }

footer { max-width: 640px; margin: 0 auto; padding: 20px 18px calc(32px + env(safe-area-inset-bottom)); font-size: 12px; color: var(--faint); }
footer p + p { margin-top: 8px; }

@media (max-width: 380px) {
  .detail { padding-left: 16px; }
}

#camera {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: #000;
  outline: none;
}
#camera::backdrop { background: #000; }
#camera video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#camera .hint {
  position: absolute;
  top: calc(20px + env(safe-area-inset-top));
  left: 0;
  right: 0;
  text-align: center;
  color: #fff;
  font-size: 14px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}
#camera .bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 20px 16px calc(28px + env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.45);
}
#camera .bar button { min-width: 64px; padding: 10px; border: 0; background: none; color: #fff; font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; }
#camera .bar .shutter {
  width: 72px;
  height: 72px;
  min-width: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.45), 0 0 0 7px #fff;
}
#camera .bar .shutter:active { transform: scale(0.94); }

.add {
  width: 100%;
  height: 42px;
  margin-top: 10px;
  border: 0;
  border-radius: 10px;
  background: #e8f3ff;
  color: var(--blue);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.add:active { background: #d6e8ff; }

/* 화면 아래에 떠 있는 면세 장바구니 요약 */
#cartbar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 616px;
  margin: 0 auto;
  padding: 14px 16px;
  border: 0;
  border-radius: 14px;
  background: var(--text);
  color: #fff;
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
#cartbar[hidden] { display: none; }
#cartbar .ttl { font-weight: 700; }
#cartbar .sum { flex: 1; color: #c5ccd6; }
#cartbar .flag { font-size: 13px; font-weight: 600; color: #7dd3a0; }
#cartbar .flag.over { color: #ff8a8f; }
body:has(#cartbar:not([hidden])) footer { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

#cart {
  width: min(94vw, 520px);
  max-height: 88vh;
  padding: 0;
  border: 0;
  border-radius: 20px;
  outline: none;
}
#cart::backdrop { background: rgba(0, 0, 0, 0.45); }
#cart .content { padding: 22px 20px 18px; }
#cart h2 { margin: 0 0 14px; font-size: 19px; }
#cart h2 small { font-size: 14px; font-weight: 500; color: var(--sub); }
#cart .items li:not(.taxed) em { display: none; }
#cart .items em { margin-right: 6px; padding: 1px 5px; border-radius: 4px; background: #ffeceb; color: var(--red); font-size: 11px; font-style: normal; font-weight: 600; }
.meter { margin-bottom: 10px; }
.meter p { display: flex; justify-content: space-between; font-size: 14px; color: var(--sub); }
.meter b { color: var(--text); font-weight: 600; }
.meter i { display: block; height: 6px; margin-top: 5px; border-radius: 3px; background: linear-gradient(var(--blue), var(--blue)) left / var(--w) 100% no-repeat, #e5e8eb; }
.meter.over b { color: var(--red); }
.meter.over i { background: linear-gradient(var(--red), var(--red)) left / 100% 100% no-repeat; }
#cart .verdict { margin: 14px 0 6px; font-size: 14px; line-height: 1.55; }
#cart .items { list-style: none; margin: 8px 0 0; padding: 0; }
#cart .items li { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
#cart .items .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#cart .items small { color: var(--faint); }
#cart .items label { display: flex; align-items: center; gap: 3px; color: var(--sub); }
#cart .items input { width: 92px; height: 36px; padding: 0 8px; border: 0; border-radius: 8px; background: var(--field); font: inherit; font-size: 16px; text-align: right; outline: none; }
#cart .items input:focus { box-shadow: inset 0 0 0 2px var(--blue); background: #fff; }
#cart h2:focus { outline: none; }
#cart .del { width: 32px; height: 32px; border: 0; border-radius: 8px; background: none; color: var(--faint); font-size: 14px; cursor: pointer; }
#cart .note { margin-top: 8px; font-size: 12px; color: var(--faint); }
#cart .actions { display: flex; gap: 8px; margin-top: 16px; }
#cart .actions button { flex: 1; height: 46px; border: 0; border-radius: 12px; background: var(--field); color: var(--text); font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; }
#cart .actions .primary { background: var(--text); color: #fff; }

.cartctl { margin-top: 10px; }
.cartctl:has([data-dec]) { display: flex; align-items: center; height: 42px; border-radius: 10px; background: #e8f3ff; color: var(--blue); }
.cartctl [data-dec],
.cartctl:has([data-dec]) [data-add] {
  width: 52px;
  height: 100%;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 22px;
  font-weight: 500;
  cursor: pointer;
}
.cartctl:has([data-dec]) span { flex: 1; text-align: center; font-size: 14px; font-weight: 600; }
.cartctl .add { margin-top: 0; }
