:root {
  --green: #16a34a;
  --green-600: #15803d;
  --green-700: #166534;
  --green-soft: #dcfce7;
  --green-tint: #f0fdf4;
  --bg: #fbfaf5;
  --surface: #ffffff;
  --surface-2: #f7f5ee;
  --ink: #1c2418;
  --ink-soft: #5d6b54;
  --ink-faint: #8a9680;
  --border: #e7e3d6;
  --border-strong: #d6d1c0;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --shadow: 0 1px 2px rgba(20,40,20,.06), 0 8px 24px rgba(20,40,20,.07);
  --shadow-lg: 0 12px 40px rgba(20,40,20,.18);
  --radius: 16px;
  --radius-sm: 11px;
  --tap: 44px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

[data-theme="dark"] {
  --green: #22c55e;
  --green-600: #16a34a;
  --green-700: #4ade80;
  --green-soft: #14331f;
  --green-tint: #11271a;
  --bg: #11140f;
  --surface: #191d15;
  --surface-2: #20251b;
  --ink: #eef3e8;
  --ink-soft: #aebaa3;
  --ink-faint: #7e8a74;
  --border: #2c3325;
  --border-strong: #3a4330;
  --danger: #f87171;
  --danger-soft: #3a1d1d;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.5);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  background-image:
    radial-gradient(circle at 92% -5%, var(--green-tint) 0%, transparent 42%),
    radial-gradient(circle at -5% 8%, var(--green-tint) 0%, transparent 36%);
  background-attachment: fixed;
}

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

.app-shell {
  max-width: 640px;
  margin: 0 auto;
  padding:
    calc(var(--safe-t) + 14px)
    calc(var(--safe-r) + 16px)
    calc(var(--safe-b) + 120px)
    calc(var(--safe-l) + 16px);
  min-height: 100vh;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-icon {
  flex: none;
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(145deg, var(--green) 0%, var(--green-700) 100%);
  box-shadow: 0 6px 16px rgba(22,163,74,.35);
}
.brand-text { min-width: 0; }
.brand-text h1 {
  margin: 0;
  font-size: 1.26rem;
  font-weight: 800;
  letter-spacing: -.02em;
  line-height: 1.05;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-text h1 span { color: var(--green); }
.brand-sub {
  margin: 2px 0 0;
  font-size: .8rem;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 56vw;
}
.header-actions { display: flex; gap: 6px; flex: none; }

.icon-btn {
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-soft);
  border-radius: 13px;
  transition: background .15s, color .15s, transform .1s, border-color .15s;
}
.icon-btn:hover { color: var(--green); border-color: var(--green-soft); }
.icon-btn:active { transform: scale(.93); }

.ico-moon { display: none; }
[data-theme="dark"] .ico-sun { display: none; }
[data-theme="dark"] .ico-moon { display: block; }

/* ---------- Add bar ---------- */
.add-bar {
  position: sticky;
  top: calc(var(--safe-t) + 6px);
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.add-row { display: flex; gap: 9px; align-items: stretch; }
.item-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  height: 48px;
  font-size: 1.02rem;
  outline: none;
  transition: border-color .15s, background .15s;
}
.item-input::placeholder { color: var(--ink-faint); }
.item-input:focus {
  border-color: var(--green);
  background: var(--surface);
}
.add-btn {
  flex: none;
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  background: linear-gradient(145deg, var(--green) 0%, var(--green-600) 100%);
  box-shadow: 0 5px 14px rgba(22,163,74,.34);
  transition: transform .1s, filter .15s;
}
.add-btn:hover { filter: brightness(1.05); }
.add-btn:active { transform: scale(.92); }
.add-btn.small { width: 44px; height: 44px; }
.add-hint {
  margin: 8px 4px 2px;
  font-size: .78rem;
  color: var(--ink-soft);
  min-height: 1.1em;
  word-break: break-word;
}
.add-hint b { color: var(--green); }

/* ---------- List groups ---------- */
.list-area { display: flex; flex-direction: column; gap: 14px; }

.cat-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.cat-group.is-done-group { opacity: .82; }

.cat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.cat-emoji {
  flex: none;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  font-size: 1.1rem;
  border-radius: 9px;
  background: var(--green-soft);
}
.cat-name {
  font-weight: 700;
  font-size: .96rem;
  letter-spacing: -.01em;
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cat-count {
  flex: none;
  font-size: .76rem;
  font-weight: 700;
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 2px 9px;
  border-radius: 999px;
}

.items { list-style: none; margin: 0; padding: 4px 0; }

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  position: relative;
}
.item + .item::before {
  content: "";
  position: absolute;
  left: 52px; right: 14px; top: 0;
  border-top: 1px solid var(--border);
}

.check {
  flex: none;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: var(--surface);
  display: grid; place-items: center;
  color: #fff;
  padding: 0;
  transition: background .15s, border-color .15s, transform .1s;
}
.check svg { width: 16px; height: 16px; opacity: 0; transition: opacity .12s; }
.check:active { transform: scale(.88); }
.item.done .check {
  background: var(--green);
  border-color: var(--green);
}
.item.done .check svg { opacity: 1; }

.item-body { flex: 1 1 auto; min-width: 0; }
.item-name {
  font-size: 1rem;
  line-height: 1.25;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.item-qty {
  display: inline-block;
  font-size: .76rem;
  font-weight: 700;
  color: var(--green-600);
  background: var(--green-soft);
  padding: 1px 7px;
  border-radius: 6px;
  margin-right: 7px;
  vertical-align: 1px;
}
.item.done .item-name {
  text-decoration: line-through;
  color: var(--ink-faint);
}
.item.done .item-qty { opacity: .55; }

.item-actions { flex: none; display: flex; gap: 2px; }
.mini-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: none;
  background: transparent;
  color: var(--ink-faint);
  border-radius: 9px;
  transition: color .15s, background .15s, transform .1s;
}
.mini-btn:hover { background: var(--surface-2); color: var(--green); }
.mini-btn.del:hover { color: var(--danger); background: var(--danger-soft); }
.mini-btn:active { transform: scale(.9); }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: var(--ink-soft);
}
.empty-illo {
  width: 92px; height: 92px;
  margin: 0 auto 16px;
  display: grid; place-items: center;
  border-radius: 26px;
  color: var(--green);
  background: var(--green-soft);
}
.empty-state h2 { margin: 0 0 6px; font-size: 1.15rem; color: var(--ink); }
.empty-state p { margin: 0 auto; max-width: 320px; font-size: .92rem; line-height: 1.5; }

/* ---------- Footer ---------- */
.app-footer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding:
    12px
    calc(var(--safe-r) + 18px)
    calc(var(--safe-b) + 12px)
    calc(var(--safe-l) + 18px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.footer-stats {
  font-size: .85rem;
  color: var(--ink-soft);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.footer-stats b { color: var(--green); font-weight: 800; }

.ghost-btn {
  flex: none;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink-soft);
  padding: 9px 14px;
  border-radius: 11px;
  font-size: .85rem;
  font-weight: 600;
  transition: color .15s, border-color .15s, background .15s, transform .1s;
}
.ghost-btn:hover { color: var(--green); border-color: var(--green); }
.ghost-btn:active { transform: scale(.96); }
.danger-btn {
  flex: none;
  border: none;
  background: var(--danger);
  color: #fff;
  padding: 10px 18px;
  border-radius: 11px;
  font-size: .9rem;
  font-weight: 700;
  transition: filter .15s, transform .1s;
}
.danger-btn:hover { filter: brightness(1.06); }
.danger-btn:active { transform: scale(.96); }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: end center;
}
@media (min-width: 560px) { .modal { place-items: center; } }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(15,25,12,.5);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  animation: fade .2s ease;
}
.modal-card {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px 22px 0 0;
  padding: 16px 16px calc(var(--safe-b) + 16px);
  box-shadow: var(--shadow-lg);
  animation: slideUp .26s cubic-bezier(.2,.8,.25,1);
}
@media (min-width: 560px) {
  .modal-card { border-radius: 22px; animation: pop .2s ease; }
}
.modal-card.narrow { max-width: 380px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.modal-head h2 { margin: 0; font-size: 1.12rem; letter-spacing: -.01em; }
.confirm-text { margin: 0 4px 18px; color: var(--ink-soft); line-height: 1.5; word-break: break-word; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; }

/* List collection */
.list-collection { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.list-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface-2);
  transition: border-color .15s;
}
.list-row.active {
  border-color: var(--green);
  background: var(--green-soft);
}
.list-pick {
  flex: 1 1 auto;
  text-align: left;
  border: none; background: transparent; color: var(--ink);
  min-width: 0; padding: 0;
  font-size: .98rem; font-weight: 600;
}
.list-pick .lp-name {
  display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list-pick .lp-meta { display: block; font-size: .76rem; color: var(--ink-soft); font-weight: 500; margin-top: 1px; }
.list-row.active .list-pick .lp-meta { color: var(--green-600); }
.list-check { flex: none; color: var(--green); display: none; }
.list-row.active .list-check { display: grid; place-items: center; }
.new-list-form { display: flex; gap: 9px; }
.new-list-form input {
  flex: 1 1 auto; min-width: 0;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: 11px; padding: 0 13px; height: 44px; font-size: .96rem; outline: none;
}
.new-list-form input:focus { border-color: var(--green); }

/* Category choices */
.cat-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.cat-choice {
  display: flex; align-items: center; gap: 9px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: .9rem; font-weight: 600;
  text-align: left;
  transition: border-color .15s, background .15s, transform .1s;
}
.cat-choice:hover { border-color: var(--green); }
.cat-choice:active { transform: scale(.97); }
.cat-choice.active { border-color: var(--green); background: var(--green-soft); }
.cat-choice .ce { font-size: 1.15rem; flex: none; }
.cat-choice .cn { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 84px);
  transform: translateX(-50%) translateY(8px);
  z-index: 200;
  background: var(--ink);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: .88rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  max-width: calc(100vw - 32px);
  text-align: center;
  word-break: break-word;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s, transform .22s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Focus & motion ---------- */
:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 2px;
  border-radius: 8px;
}
.modal-backdrop:focus-visible { outline: none; }

@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes pop { from { transform: scale(.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes itemIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.item { animation: itemIn .18s ease; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
