:root {
  --bg: #f6f1e7;
  --card: #fffdf8;
  --ink: #2a261f;
  --muted: #857c6c;
  --line: #e6dfd0;
  --accent: #2f7d4f;
  --accent-ink: #ffffff;
  --accent-soft: #e2efe5;
  --new: #d9622b;
  --danger: #b43c2c;
  --shadow: 0 1px 2px rgba(60, 45, 20, .06), 0 4px 16px rgba(60, 45, 20, .06);
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17150f;
    --card: #221f18;
    --ink: #f1ece1;
    --muted: #a39a88;
    --line: #353025;
    --accent: #5cb582;
    --accent-ink: #0d1a12;
    --accent-soft: #1f3327;
    --new: #f08a55;
    --danger: #ea7a68;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.app { max-width: 560px; margin: 0 auto; padding: calc(var(--safe-t) + 14px) 16px calc(var(--safe-b) + 110px); }

.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
h1 { font-size: 32px; line-height: 1.1; margin: 4px 0 2px; letter-spacing: -.02em; }
.subtitle { margin: 0; color: var(--muted); font-size: 15px; }
.icon-btn { background: var(--card); border: 1px solid var(--line); width: 42px; height: 42px; border-radius: 50%; font-size: 20px; line-height: 1; display: grid; place-items: center; }

.btn {
  border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-ink);
  font-weight: 600; padding: 12px 18px; min-height: 46px;
}
.btn:active { transform: scale(.98); }
.btn.small { padding: 8px 14px; min-height: 38px; font-size: 15px; }
.btn.big { width: 100%; min-height: 56px; font-size: 18px; border-radius: 16px; }
.btn.secondary { background: var(--accent-soft); color: var(--ink); }
.btn.light { background: rgba(255,255,255,.92); color: #1d4d31; }
.btn.ghost { background: transparent; color: var(--muted); font-weight: 500; }
.btn.danger { color: var(--danger); }

.banner {
  display: flex; align-items: center; gap: 12px; justify-content: space-between;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 12px; font-size: 15px;
}

.trip {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--accent); color: #fff; border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.trip strong { display: block; font-size: 17px; }
.trip span { font-size: 14px; opacity: .9; }
@media (prefers-color-scheme: dark) { .trip { color: var(--accent-ink); } .btn.light { background: var(--accent-ink); color: var(--accent); } }

.add { display: flex; gap: 8px; }
.add input {
  flex: 1; min-width: 0; font: inherit; font-size: 17px; padding: 14px 16px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); outline: none;
}
.add input:focus { border-color: var(--accent); }
.add-btn { width: 54px; padding: 0; font-size: 28px; font-weight: 400; border-radius: 14px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 4px; scrollbar-width: none; min-height: 12px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 7px 13px; font-size: 15px; white-space: nowrap;
}
.chip:active { background: var(--accent-soft); }

.list { margin-top: 10px; }
.section { margin-top: 18px; }
.section h3 {
  font-size: 19px; color: var(--ink); margin: 0 0 8px 4px; font-weight: 700; letter-spacing: -.01em;
}
.section.new h3 { color: var(--new); }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); overflow: hidden; }

.row { display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 12px; min-height: 58px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.check {
  flex: none; width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line);
  background: transparent; display: grid; place-items: center; padding: 0; color: transparent; font-size: 16px;
}
.row.done .check { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.info { flex: 1; min-width: 0; padding: 4px 0; background: none; border: 0; text-align: left; }
.name { display: block; font-size: 17px; overflow-wrap: anywhere; }
.who { display: block; font-size: 13px; color: var(--muted); margin-top: 1px; }
.row.done .name { text-decoration: line-through; color: var(--muted); }
.badge-new { display: inline-block; font-size: 11px; font-weight: 700; color: #fff; background: var(--new); border-radius: 6px; padding: 1px 6px; margin-left: 6px; vertical-align: 2px; }
.qty { flex: none; display: flex; align-items: center; gap: 2px; }
.qty button { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: transparent; font-size: 19px; line-height: 1; padding: 0; color: var(--muted); }
.qty span { min-width: 30px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.row.done .qty { opacity: .45; }

.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty .big-emoji { font-size: 48px; display: block; margin-bottom: 8px; }

.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(var(--safe-b) + 12px);
  background: linear-gradient(to top, var(--bg) 70%, transparent); z-index: 5;
}
.bottom-bar .btn { max-width: 528px; margin: 0 auto; display: block; box-shadow: var(--shadow); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-b) + 88px);
  background: var(--ink); color: var(--bg); border-radius: 14px; padding: 10px 10px 10px 16px;
  display: flex; align-items: center; gap: 14px; z-index: 20; font-size: 15px;
  width: max-content; min-width: 240px; justify-content: space-between;
  max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.2);
}
.toast-undo { background: transparent; border: 0; color: var(--accent); font-weight: 700; padding: 6px 8px; filter: brightness(1.4); }

.backdrop { position: fixed; inset: 0; background: rgba(20, 15, 5, .35); z-index: 30; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; background: var(--card);
  border-radius: 22px 22px 0 0; padding: 10px 18px calc(var(--safe-b) + 18px);
  max-width: 560px; margin: 0 auto; max-height: 88vh; overflow-y: auto;
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet h2 { margin: 4px 0 16px; font-size: 22px; }
.sheet .btn.big + .btn.big { margin-top: 10px; }
.sheet-input {
  width: 100%; font: inherit; font-size: 18px; padding: 13px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); outline: none;
}
.sheet-input:focus { border-color: var(--accent); }
.sheet-label { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; font-weight: 600; display: block; }
.qty-row { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg); font-size: 22px; padding: 0; }
.stepper span { min-width: 34px; text-align: center; font-size: 19px; font-weight: 700; }
.aisle-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.aisle-grid button { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 8px 12px; font-size: 15px; }
.aisle-grid button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.meta-line { color: var(--muted); font-size: 14px; margin: 14px 0 0; }
.sheet-actions { display: flex; gap: 10px; margin-top: 20px; }
.sheet-actions .btn { flex: 1; }
.hint { color: var(--muted); font-size: 14px; margin: 8px 4px 12px; }
#endCancel { width: 100%; margin-top: 4px; }

.overlay { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: grid; place-items: center; padding: 24px 20px calc(var(--safe-b) + 24px); overflow-y: auto; }
.welcome-card { width: 100%; max-width: 420px; text-align: center; }
.welcome-card .sheet-label { text-align: left; }
.welcome-card .btn.big { margin-top: 16px; }
.welcome-emoji { font-size: 64px; }
.welcome-card h2 { font-size: 26px; margin: 8px 0; }
.welcome-card p { color: var(--muted); margin: 0 0 8px; }
.steps { text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 16px 16px 36px; margin: 16px 0 0; }
.steps li { margin: 6px 0; }
.steps .ios-share { display: inline-block; border: 1.5px solid currentColor; border-radius: 5px; padding: 0 5px; font-size: 14px; }

.divider { margin: 28px 4px 0; color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 10px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.section.other { opacity: .55; }
.shop-pick button { font-size: 16px; padding: 10px 14px; }
.btn:disabled { opacity: .45; }

.amount { flex: none; font-weight: 600; font-size: 15px; background: var(--accent-soft); border-radius: 999px; padding: 5px 11px; max-width: 42%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.done .amount { opacity: .45; }
.weekly { display: block; place-items: initial; padding: 0; z-index: 35; }
.weekly-inner { padding-bottom: calc(var(--safe-b) + 110px); }
.weekly .bottom-bar { z-index: 36; }
.weekly-add .amount-input { flex: 0 0 34%; }
.top-sheet { z-index: 41; }
#sheetBackdrop.over-weekly { z-index: 40; }
.tpl-row { cursor: pointer; }
