:root {
  --bg: #f3f6f8;
  --surface: #ffffff;
  --text: #17222b;
  --muted: #5d6b76;
  --line: #dde4ea;
  --primary: #1f5f8b;
  --primary-ink: #ffffff;
  --ok: #1d7a4a;
  --ok-bg: #e3f4ea;
  --warn: #8a5a00;
  --warn-bg: #fff3d6;
  --err: #b42318;
  --err-bg: #fde8e6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11181e;
    --surface: #1a232b;
    --text: #e6edf2;
    --muted: #93a2ad;
    --line: #2b3742;
    --primary: #4f9fd3;
    --primary-ink: #0b1620;
    --ok: #6fd39b;
    --ok-bg: #173526;
    --warn: #f0c060;
    --warn-bg: #3a2e12;
    --err: #ff8a7a;
    --err-bg: #3d1a17;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 16px;
}
.hidden { display: none !important; }
button { font: inherit; color: inherit; }
.btn {
  border: 0; border-radius: 12px; padding: 14px 18px;
  font-size: 17px; font-weight: 700; cursor: pointer;
  background: var(--line);
}
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.block { width: 100%; }
.btn:focus-visible, .tabs button:focus-visible, .items li:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* 로그인 */
#login { display: flex; align-items: center; justify-content: center; min-height: 100%; padding: 24px 16px; }
.login-box { width: 100%; max-width: 380px; }
.login-box h1 { margin: 0 0 6px; font-size: 26px; }
.sub { margin: 0 0 20px; color: var(--muted); }
.login-box form { display: flex; flex-direction: column; gap: 8px; }
.login-box label { font-size: 14px; color: var(--muted); margin-top: 6px; }
.login-box input {
  font-size: 20px; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.login-box .btn { margin-top: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 12px; font-size: 15px; cursor: pointer;
}
.err { color: var(--err); min-height: 1.4em; font-size: 15px; }

/* 메인 레이아웃: 하단 탭바를 엄지 영역에 고정 */
#main { min-height: 100%; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.top {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.date { font-weight: 700; font-size: 17px; }
.counts { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.who { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 6px 12px; font-size: 15px; cursor: pointer; }
.offline { background: var(--err-bg); color: var(--err); padding: 8px 16px; font-size: 14px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: 1fr 1fr;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  height: 68px; border: 0; background: none; font-size: 19px; font-weight: 700; color: var(--muted); cursor: pointer;
}
.tabs button.on { color: var(--primary); box-shadow: inset 0 3px 0 var(--primary); }
.badge {
  display: inline-block; min-width: 24px; padding: 1px 7px; border-radius: 999px;
  background: var(--err); color: #fff; font-size: 14px; font-variant-numeric: tabular-nums;
}

/* 카메라 */
.cam { position: relative; background: #000; height: 46vh; min-height: 240px; overflow: hidden; }
.cam video { width: 100%; height: 100%; object-fit: cover; display: block; }
.finder {
  position: absolute; top: 50%; left: 50%; width: 58vw; max-width: 260px; aspect-ratio: 1;
  transform: translate(-50%, -50%); border: 3px solid rgba(255,255,255,.85); border-radius: 18px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.28); pointer-events: none;
  --p: 0; transition: border-color .15s;
}
/* 유지 진행 막대: 테두리 아래쪽이 0.8초 동안 차오름 */
.finder::after {
  content: ""; position: absolute; left: 10%; bottom: -14px; height: 6px; border-radius: 3px;
  width: calc(80% * var(--p)); background: currentColor; color: #ffd24a;
}
.finder.hold { border-color: #ffd24a; }
.finder.done { border-color: #3ddc84; border-width: 5px; }
.finder.done::after { color: #3ddc84; }
.cam-start { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
.flash {
  position: absolute; left: 12px; right: 12px; bottom: 12px; padding: 12px 14px;
  border-radius: 12px; font-size: 17px; font-weight: 700; line-height: 1.35;
  background: var(--ok-bg); color: var(--ok);
}
.flash.warn { background: var(--warn-bg); color: var(--warn); }
.flash.err { background: var(--err-bg); color: var(--err); }

/* 목록 */
.list-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 14px 16px 8px; font-weight: 700;
}
.hint { font-weight: 400; color: var(--muted); font-size: 13px; }
.items { list-style: none; margin: 0; padding: 0 12px; display: flex; flex-direction: column; gap: 8px; }
.items li {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; display: flex; align-items: center; gap: 12px;
}
.items .info { flex: 1; min-width: 0; }
.items .nm { font-weight: 700; font-size: 17px; overflow-wrap: anywhere; }
.items .meta { color: var(--muted); font-size: 14px; margin-top: 2px; }
.items .qty { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 46px; text-align: right; }
.items li.new { animation: pop .6s ease-out; }
@keyframes pop { from { background: var(--ok-bg); } to { background: var(--surface); } }
/* 수량: 맨 왼쪽에 + / 숫자 / − 세로 배치 (엄지로 누르기 쉽게) */
.stepper { display: flex; flex-direction: column; align-items: center; gap: 2px; flex: none; }
.stepper button {
  width: 48px; height: 38px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); font-size: 22px; font-weight: 700; cursor: pointer; line-height: 1;
}
.stepper .n { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.3; }
.stepper .n small { font-size: 12px; font-weight: 600; margin-left: 1px; color: var(--muted); }
.x { border: 0; background: none; color: var(--muted); font-size: 22px; width: 36px; height: 40px; cursor: pointer; }
.mine-tag { font-size: 12px; color: var(--primary); font-weight: 700; margin-left: 4px; }
.empty { color: var(--muted); text-align: center; padding: 28px 16px; }

#pick-list li { cursor: pointer; min-height: 68px; }
.check {
  width: 34px; height: 34px; border-radius: 9px; border: 2px solid var(--muted); flex: none;
  display: grid; place-items: center; font-weight: 900; color: var(--primary-ink);
}
.done li { opacity: .65; cursor: pointer; }
.done .check { background: var(--ok); border-color: var(--ok); color: #fff; }
.picked { margin: 8px 0 0; }
.picked[open] .items { margin-bottom: 8px; }
.picked summary { padding: 10px 16px; color: var(--muted); cursor: pointer; font-weight: 700; }
.pick-all-bar { padding: 16px 12px 20px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 10px; font-size: 14px; cursor: pointer; }
.seg button.on { background: var(--primary); color: var(--primary-ink); }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 20;
  background: var(--text); color: var(--bg); border-radius: 12px; padding: 12px 14px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 16px;
}
.toast button { border: 0; background: none; color: var(--bg); font-weight: 800; text-decoration: underline; cursor: pointer; }

@media (prefers-reduced-motion: reduce) { .items li.new { animation: none; } }
