:root {
  --bg: #f7f3ee; --surface: #ffffff; --surface-2: #f1ebe3; --text: #2a2118; --muted: #7a6d60;
  --line: #e6ddd2; --accent: #7a4a1e; --accent-ink: #ffffff; --accent-soft: #f3e4d3;
  --ok: #2f7d4f; --ok-soft: #e2f1e7; --warn: #b4561b; --warn-soft: #fbe9dc; --danger: #b3261e;
  --radius: 14px; --shadow: 0 1px 2px rgba(42,33,24,.06), 0 4px 14px rgba(42,33,24,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17130f; --surface: #221c16; --surface-2: #2b241d; --text: #f1e9df; --muted: #a8998a;
    --line: #3a3128; --accent: #e0a35f; --accent-ink: #1b140d; --accent-soft: #3a2b1c;
    --ok: #6cc28f; --ok-soft: #1f3327; --warn: #f0a46a; --warn-soft: #3a2719; --danger: #ff8a80;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px calc(110px + env(safe-area-inset-bottom)); }

/* header */
.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; border-bottom: 1px solid var(--line); }
.top-in { max-width: 760px; margin: 0 auto; display: flex; align-items: center; gap: 10px; }
.top h1 { font-size: 19px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { border: 0; background: var(--surface-2); width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none; color: var(--accent); }
.who { font-size: 13px; color: var(--muted); }
.link { border: 0; background: none; color: var(--accent); padding: 6px 4px; font-weight: 600; }

/* buttons */
.btn { border: 0; border-radius: 12px; padding: 13px 18px; font-weight: 650; background: var(--surface-2); min-height: 48px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ok { background: var(--ok); color: #fff; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--surface); border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
.bar-in { max-width: 760px; margin: 0 auto; display: flex; gap: 10px; align-items: center; }
.bar-in .grow { flex: 1; }
.bar .sum { font-size: 13px; color: var(--muted); }
.bar .sum b { color: var(--text); font-size: 16px; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 320px; text-align: center; }
.login-card h1 { font-size: 22px; margin: 12px 0 4px; }
.login-card p { color: var(--muted); margin: 0 0 22px; }
.dots { display: flex; justify-content: center; gap: 14px; margin-bottom: 18px; }
.dots span { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--accent); }
.dots span.on { background: var(--accent); }
.dots.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.err { color: var(--danger); min-height: 22px; font-size: 14px; }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pad button { height: 64px; border-radius: 16px; border: 0; background: var(--surface); box-shadow: var(--shadow); font-size: 24px; font-weight: 600; }
.pad button.ghost { background: none; box-shadow: none; font-size: 15px; color: var(--muted); }

/* home */
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 2px 8px; font-weight: 700; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.tile { border: 0; text-align: left; background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-height: 108px;
  display: flex; flex-direction: column; justify-content: space-between; gap: 8px; }
.tile.main { grid-column: 1 / -1; background: var(--accent); color: var(--accent-ink); }
.tile b { font-size: 18px; }
.tile small { opacity: .8; font-size: 13px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.list-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border: 0; width: 100%; text-align: left; background: none; border-top: 1px solid var(--line); }
.list-row:first-child { border-top: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row small { color: var(--muted); display: block; font-size: 13px; }
.pill { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.shopping { background: var(--ok-soft); color: var(--ok); }
.pill.draft { background: var(--accent-soft); color: var(--accent); }
.empty { color: var(--muted); padding: 18px 16px; text-align: center; font-size: 14px; }

/* item rows (check / list / inventory) */
.search { position: sticky; top: 61px; z-index: 4; background: var(--bg); padding: 10px 0 8px; display: flex; gap: 8px; }
.search input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 11px 14px; min-height: 46px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 7px 13px; font-size: 14px; white-space: nowrap; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.items { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.item { display: grid; grid-template-columns: 56px 1fr; gap: 12px; background: var(--surface); border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow); align-items: center; }
.item.need { box-shadow: inset 4px 0 0 var(--warn), var(--shadow); }
.thumb { width: 56px; height: 56px; border-radius: 10px; background: #fff; object-fit: contain; border: 1px solid var(--line); }
.thumb.ph { display: grid; place-items: center; font-weight: 700; color: var(--muted); background: var(--surface-2); }
.item .name { font-weight: 600; font-size: 15px; line-height: 1.25; }
.item .meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.item .controls { grid-column: 1 / -1; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
@media (min-width: 560px) {
  .item { grid-template-columns: 56px 1fr auto; }
  .item .controls { grid-column: auto; flex-wrap: nowrap; }
}
.field { display: flex; flex-direction: column; gap: 3px; }
.field > span { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); }
.stepper button { border: 0; background: var(--surface-2); width: 44px; height: 44px; font-size: 22px; line-height: 1; }
.stepper input { width: 56px; height: 44px; border: 0; text-align: center; background: none; font-weight: 650; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper.buy input { color: var(--warn); }
.stepper.zero input { color: var(--muted); font-weight: 400; }
.x { border: 0; background: none; color: var(--muted); font-size: 22px; width: 40px; height: 44px; }

/* shop mode */
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 12px 0 4px; }
.progress i { display: block; height: 100%; background: var(--ok); transition: width .25s; }
.progress-label { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }
.shop-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
@media (min-width: 560px) { .shop-grid { grid-template-columns: repeat(3, 1fr); } }
.shop-card { position: relative; border: 2px solid transparent; background: var(--surface); border-radius: 16px; padding: 10px; text-align: left; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px; transition: transform .08s; }
.shop-card:active { transform: scale(.97); }
.shop-card img, .shop-card .ph { width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; border-radius: 10px; }
.shop-card .ph { display: grid; place-items: center; font-size: 32px; font-weight: 700; color: var(--muted); background: var(--surface-2); }
.shop-card .nm { font-size: 14px; font-weight: 600; line-height: 1.25; }
.shop-card .qty { position: absolute; top: 14px; left: 14px; background: var(--accent); color: var(--accent-ink); font-weight: 800; border-radius: 10px; padding: 3px 9px; font-size: 16px; }
.shop-card.picked { opacity: .55; border-color: var(--ok); }
.shop-card.picked img { filter: grayscale(.7); }
.shop-card .tick { position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--line); background: var(--surface); display: grid; place-items: center; }
.shop-card.picked .tick { background: var(--ok); border-color: var(--ok); color: #fff; }
.shop-card .by { font-size: 11.5px; color: var(--ok); }

/* sheet / dialog */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 760px; max-height: 85dvh; border-radius: 20px 20px 0 0; padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.sheet h2 { margin: 0; font-size: 18px; }
.sheet .scroll { overflow-y: auto; margin: 0 -16px; padding: 0 16px; }
.pick-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border: 0; background: none; width: 100%; text-align: left; border-bottom: 1px solid var(--line); }
.pick-row .thumb { width: 44px; height: 44px; }
.check-line { display: flex; gap: 10px; align-items: center; font-size: 15px; }
.check-line input { width: 22px; height: 22px; accent-color: var(--ok); }

#toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 30; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }
