:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef1ec;
  --text: #1a1d1a;
  --muted: #687068;
  --line: #e2e6df;
  --accent: #1f8a4c;
  --accent-ink: #ffffff;
  --accent-soft: #e3f3e8;
  --danger: #c2372c;
  --warn: #b7791f;
  --mark: #fff1a8;
  --shadow: 0 1px 2px rgb(20 30 20 / 6%), 0 6px 24px rgb(20 30 20 / 7%);
  --radius: 16px;
  --tap: 52px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121412;
    --surface: #1b1e1b;
    --surface-2: #242824;
    --text: #e8ebe7;
    --muted: #9aa39a;
    --line: #2c312c;
    --accent: #3fbf74;
    --accent-ink: #08210f;
    --accent-soft: #19301f;
    --danger: #ff6b5e;
    --warn: #e3a64a;
    --mark: #4d4416;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 28px rgb(0 0 0 / 35%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121412; --surface: #1b1e1b; --surface-2: #242824; --text: #e8ebe7; --muted: #9aa39a; --line: #2c312c;
  --accent: #3fbf74; --accent-ink: #08210f; --accent-soft: #19301f; --danger: #ff6b5e; --warn: #e3a64a; --mark: #4d4416;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; opacity: .5; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; border-radius: 10px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.noscript { padding: 24px; text-align: center; }

/* boot */
.boot { min-height: 100dvh; display: grid; place-items: center; }
.boot-mark, .logo {
  width: 56px; height: 56px; border-radius: 16px; background: var(--accent) url("icon.svg") center / cover no-repeat;
}
.boot-mark { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(.92); opacity: .7; } }

/* sign-in */
.center-card { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); }
.card { width: min(400px, 100%); background: var(--surface); border-radius: 24px; padding: 28px 24px; box-shadow: var(--shadow); }
.card h1 { margin: 16px 0 4px; font-size: 26px; letter-spacing: -.01em; }
.card > .muted { margin: 0 0 20px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack label { font-weight: 600; font-size: 14px; color: var(--muted); }
.stack input:not([type="checkbox"]), .stack select {
  width: 100%; min-height: var(--tap); padding: 12px 14px; border-radius: 12px;
  background: var(--surface-2); border: 1.5px solid transparent; font-size: 17px;
}
.stack input:focus, .stack select:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.code-input { font-size: 28px !important; letter-spacing: .35em; text-align: center; font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500 !important; color: var(--text) !important; font-size: 16px !important; min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.form-error { color: var(--danger); margin: 0; font-size: 15px; }
.row { display: flex; gap: 8px; align-items: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }

.btn { min-height: 44px; padding: 10px 18px; border-radius: 12px; font-weight: 600; }
.btn.big { min-height: var(--tap); font-size: 17px; margin-top: 6px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:active { filter: brightness(.95); transform: translateY(1px); }
.btn.ghost { background: var(--surface-2); }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn.link { color: var(--accent); padding: 8px 0; min-height: 40px; font-weight: 500; }
.btn.danger, .danger { color: var(--danger); }

/* app shell */
#shell { max-width: 720px; margin: 0 auto; min-height: 100dvh; padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.top {
  position: relative; display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 6px;
}
.title { margin: 0; font-size: 28px; letter-spacing: -.02em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-switch { flex: 1; min-width: 0; }
.list-switch select {
  appearance: none; border: 0; background: transparent; font-size: 28px; font-weight: 700; letter-spacing: -.02em;
  padding: 2px 28px 2px 0; max-width: 100%;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 10px center, right 4px center; background-size: 6px 6px; background-repeat: no-repeat;
}
.status { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--accent); }
.dot.busy { background: var(--accent); animation: pulse 1s infinite; }
.dot.warn { background: var(--warn); }
.dot.off { background: var(--muted); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  font-weight: 700; display: grid; place-items: center; flex: none;
}
.menu {
  position: absolute; right: 12px; top: calc(56px + env(safe-area-inset-top)); z-index: 30; min-width: 240px;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 6px; border: 1px solid var(--line);
  display: flex; flex-direction: column; animation: pop .14s ease-out;
}
.menu button { text-align: left; padding: 12px 14px; border-radius: 10px; min-height: 44px; }
.menu button:hover { background: var(--surface-2); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }
.menu-who { padding: 10px 14px 8px; display: flex; flex-direction: column; font-size: 15px; overflow-wrap: anywhere; }
.menu-who .muted { font-size: 13px; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }

/* add bar */
.addbar-wrap {
  position: sticky; top: 0; z-index: 20; padding: 8px 16px 10px;
  background: linear-gradient(var(--bg) 75%, transparent);
}
.addbar {
  position: relative; display: flex; align-items: center; gap: 4px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 4px 4px 4px 14px; border: 1.5px solid transparent; transition: border-color .15s;
}
.addbar:focus-within { border-color: var(--accent); }
.plus { width: 22px; height: 22px; flex: none; position: relative; color: var(--accent); }
.plus::before, .plus::after { content: ""; position: absolute; background: currentColor; border-radius: 2px; left: 50%; top: 50%; transform: translate(-50%, -50%); }
.plus::before { width: 16px; height: 2.5px; }
.plus::after { width: 2.5px; height: 16px; }
.add-input { flex: 1; min-width: 0; border: 0; background: transparent; min-height: var(--tap); font-size: 18px; padding: 0 6px; }
.add-input:focus { outline: none; }
.add-input::placeholder { color: var(--muted); }
.qty-hint { display: none; font-size: 13px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 4px 8px; border-radius: 8px; white-space: nowrap; }
.qty-hint.on { display: inline-block; }
.add-btn { min-height: 44px; padding: 0 16px; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.sugg {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 25;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line);
  overflow: hidden; display: none; max-height: min(60vh, 440px); overflow-y: auto;
}
.sugg.open { display: block; animation: pop .12s ease-out; }
.sugg-row { width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; padding: 12px 16px; min-height: 50px; border-bottom: 1px solid var(--line); }
.sugg-row:last-child { border-bottom: 0; }
.sugg-row:hover, .sugg-row.sel { background: var(--surface-2); }
.sugg-row.on .sugg-name { color: var(--muted); }
.sugg-row.new { color: var(--accent); }
.sugg-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
.tag { font-size: 12px; color: var(--muted); background: var(--surface-2); padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.usuals { padding: 12px 12px 14px; }
.usuals-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 4px 10px; }
.usuals-title .muted { text-transform: none; letter-spacing: 0; font-weight: 500; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: stretch; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.chip.due { background: var(--accent-soft); }
.chip-add { padding: 9px 4px 9px 14px; min-height: 40px; display: inline-flex; align-items: center; gap: 6px; font-size: 15px; }
.chip-x { padding: 0 12px 0 8px; color: var(--muted); font-size: 18px; }
.due-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }

.banner { margin: 0 16px 8px; padding: 10px 14px; border-radius: 12px; background: color-mix(in srgb, var(--warn) 16%, var(--surface)); font-size: 14px; }

/* list */
.list { padding: 0 16px; }
.group { margin: 10px 0 18px; }
.group-title { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 6px 8px; }
.count { margin-left: 6px; font-weight: 600; font-size: 12px; background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 1px 8px; letter-spacing: 0; }
.items { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item { position: relative; border-bottom: 1px solid var(--line); overflow: hidden; }
.item:last-child { border-bottom: 0; }
.swipe-bg {
  position: absolute; inset: 0; background: var(--danger); color: #fff; font-weight: 700; display: flex; align-items: center;
  justify-content: flex-end; padding-right: 22px; opacity: 0; transition: opacity .1s;
}
.item.swiping .swipe-bg, .item.removing .swipe-bg { opacity: .75; }
.item.armed .swipe-bg { opacity: 1; }
.item-main {
  position: relative; display: flex; align-items: center; background: var(--surface); min-height: 60px;
  transition: transform .2s ease; touch-action: pan-y; user-select: none; -webkit-user-select: none;
}
.item.swiping .item-main { transition: none; }
.tick {
  flex: none; width: 60px; align-self: stretch; display: grid; place-items: center; position: relative;
}
.tick::before {
  content: ""; width: 26px; height: 26px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--muted) 70%, transparent);
  transition: background .15s, border-color .15s, transform .15s;
}
.tick::after {
  content: ""; position: absolute; width: 7px; height: 13px; border: solid var(--accent-ink); border-width: 0 2.5px 2.5px 0;
  transform: translate(0, -2px) rotate(45deg) scale(0); transition: transform .18s cubic-bezier(.3, 1.6, .6, 1);
}
.item.done .tick::before { background: var(--accent); border-color: var(--accent); }
.item.done .tick::after { transform: translate(0, -2px) rotate(45deg) scale(1); }
.item.just .tick::before { animation: bounce .3s ease-out; }
@keyframes bounce { 50% { transform: scale(1.18); } }
.item-body { flex: 1; min-width: 0; text-align: left; padding: 12px 4px 12px 0; display: flex; flex-direction: column; gap: 2px; min-height: 60px; justify-content: center; }
.name { font-size: 17px; overflow-wrap: anywhere; transition: color .2s; }
.item.done .name { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent); }
.item.just .name { text-decoration: line-through; }
.sub { display: flex; gap: 8px; flex-wrap: wrap; font-size: 14px; color: var(--muted); }
.qty { font-weight: 700; color: var(--accent); }
.item.done .qty { color: var(--muted); }
.note { overflow-wrap: anywhere; }
.who { font-size: 12px; color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: 2px 8px; margin-right: 2px; white-space: nowrap; }
.edit { flex: none; width: 48px; align-self: stretch; display: grid; place-items: center; color: var(--muted); opacity: .7; }
.edit::before { content: "⋯"; font-size: 22px; line-height: 1; }
.edit:hover { opacity: 1; }
.item.pending .name::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 8px; border-radius: 50%; background: var(--warn); vertical-align: middle; opacity: .8; }

.cart .items { box-shadow: none; background: transparent; border: 1px solid var(--line); }
.cart .item-main { background: transparent; }
.cart-head { display: flex; justify-content: space-between; align-items: center; margin: 0 2px 8px; }
.cart-toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); min-height: 40px; padding: 0 4px; }
.chev { width: 8px; height: 8px; border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(45deg); margin: -3px 4px 0 2px; transition: transform .15s; }
.cart.collapsed .chev { transform: rotate(-45deg); margin-top: 0; }

.empty { text-align: center; padding: 56px 16px 32px; }
.empty.small { padding: 28px 16px 12px; }
.empty p { margin: 4px 0; }
.empty-art { font-size: 52px; margin-bottom: 8px; filter: saturate(.8); }

/* sheet */
.sheet {
  border: 0; padding: 0; background: var(--surface); color: var(--text); width: min(520px, 100%); max-width: 100%;
  border-radius: 24px; box-shadow: var(--shadow);
}
.sheet::backdrop { background: rgb(0 0 0 / 38%); backdrop-filter: blur(2px); }
.sheet form { padding: 14px 20px calc(20px + env(safe-area-inset-bottom)); }
.sheet h2 { margin: 4px 0 6px; font-size: 20px; }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 4px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two > div { display: flex; flex-direction: column; gap: 10px; }
@media (max-width: 560px) {
  .sheet { margin: auto 0 0; border-radius: 24px 24px 0 0; width: 100%; animation: up .2s ease-out; }
  @keyframes up { from { transform: translateY(40px); opacity: 0; } }
}

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 50;
  transform: translate(-50%, 140%); transition: transform .22s cubic-bezier(.2, .9, .3, 1.2);
  display: flex; align-items: center; gap: 14px; max-width: calc(100% - 32px);
  background: #232823; color: #f2f5f1; border-radius: 14px; padding: 12px 14px 12px 18px; box-shadow: 0 10px 30px rgb(0 0 0 / 25%); font-size: 15px;
}
.toast.show { transform: translate(-50%, 0); }
.toast-undo { color: #7be3a2; font-weight: 700; padding: 6px 8px; min-height: 36px; }

@media (min-width: 760px) {
  .top { padding-top: 28px; }
  .title, .list-switch select { font-size: 32px; }
  .addbar-wrap { padding-top: 12px; }
  .item-main:hover { background: color-mix(in srgb, var(--surface-2) 45%, var(--surface)); }
  .cart .item-main:hover { background: transparent; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
