:root {
  --bg: #f6f5f1; --card: #fff; --ink: #1d1f1e; --muted: #7a7d7a; --line: #e6e4de;
  --accent: #2f7d5b; --accent-ink: #fff; --chip: #ecebe5; --danger: #c0392b;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #17181a; --card: #222427; --ink: #ececea; --muted: #8e918f; --line: #33363a; --accent: #4fb586; --accent-ink: #0d1f17; --chip: #2c2f33; --danger: #ef6f61; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 17px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
[hidden] { display: none !important; }

#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; padding: calc(var(--safe-t) + 8px) 16px calc(var(--safe-b) + 40px); }

/* header: list tabs + settings */
.top { display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 6px 0 10px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { white-space: nowrap; padding: 7px 14px; border-radius: 999px; background: var(--chip); font-size: 15px; font-weight: 600; }
.tab.on { background: var(--ink); color: var(--bg); }
.tab .n { opacity: .55; font-weight: 500; margin-left: 4px; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none; color: var(--muted); }
.icon-btn:active { background: var(--chip); }
.icon-btn svg { width: 22px; height: 22px; }

/* add field */
.add { position: relative; display: flex; gap: 8px; margin-bottom: 12px; }
.add input { flex: 1; min-width: 0; height: 50px; padding: 0 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); outline: none; }
.add input:focus { border-color: var(--accent); }
.add > button { width: 50px; height: 50px; border-radius: 14px; background: var(--accent); color: var(--accent-ink); font-size: 28px; line-height: 1; flex: none; }
.suggest { position: absolute; left: 0; right: 58px; top: 54px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.12); z-index: 6; overflow: hidden; }
.suggest div { display: flex; align-items: center; }
.suggest button.s { flex: 1; text-align: left; padding: 12px 16px; }
.suggest button.s b { font-weight: 700; }
.suggest button.x { padding: 12px 16px; color: var(--muted); font-size: 15px; }
.suggest div + div { border-top: 1px solid var(--line); }

/* "often bought" chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 16px; }
.chips .label { width: 100%; font-size: 13px; color: var(--muted); margin-bottom: 2px; }
.chip { padding: 6px 12px; border-radius: 999px; background: var(--chip); font-size: 15px; }
.chip::before { content: "+ "; color: var(--muted); }
.chip:active { background: var(--line); }

/* items */
.items { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: 16px; overflow: hidden; }
.items:empty { display: none; }
.item { display: flex; align-items: center; min-height: 54px; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .tick { flex: 1; display: flex; align-items: center; gap: 14px; padding: 10px 0 10px 16px; text-align: left; min-width: 0; }
.box { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; }
.done .box { background: var(--accent); border-color: var(--accent); }
.done .box::after { content: ""; width: 10px; height: 6px; border: 2.5px solid var(--accent-ink); border-top: 0; border-right: 0; transform: translateY(-1px) rotate(-45deg); }
.txt { min-width: 0; }
.txt .name { display: block; overflow-wrap: anywhere; }
.txt small { display: block; color: var(--muted); font-size: 13px; }
.done .name { text-decoration: line-through; color: var(--muted); }
.item .edit { padding: 0 16px; height: 54px; color: var(--muted); }
.item.flash { animation: flash 1s; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 22%, transparent); } }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty b { display: block; color: var(--ink); font-size: 19px; margin-bottom: 4px; }

.cart-head { display: flex; align-items: center; justify-content: space-between; margin: 24px 4px 8px; color: var(--muted); font-size: 14px; }
.cart-head button { color: var(--accent); font-weight: 600; font-size: 15px; padding: 4px 0; }

/* sheets (dialog) */
dialog { border: 0; padding: 0; width: 100%; max-width: 560px; margin: auto auto 0; border-radius: 20px 20px 0 0; background: var(--card); color: var(--ink); max-height: 90dvh; }
dialog::backdrop { background: rgba(0,0,0,.35); }
@media (min-width: 600px) { dialog { margin: auto; border-radius: 20px; } }
.sheet { padding: 20px 16px calc(var(--safe-b) + 20px); }
.sheet h2 { margin: 0 0 14px; font-size: 20px; }
.sheet h3 { margin: 22px 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.sheet label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }
.sheet input { width: 100%; height: 46px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); outline: none; }
.sheet input:focus { border-color: var(--accent); }
.row { display: flex; gap: 8px; margin-top: 16px; }
.btn { flex: 1; height: 46px; border-radius: 12px; background: var(--chip); font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.line { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.line span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.line small { color: var(--muted); }
.line button { color: var(--accent); font-size: 15px; padding: 4px 6px; }
.line button.danger { color: var(--danger); }
.link-box { word-break: break-all; font-size: 14px; background: var(--bg); padding: 10px 12px; border-radius: 10px; margin-top: 10px; }
.hint { color: var(--muted); font-size: 14px; }

/* join screen */
.join { padding-top: 12vh; }
.join h1 { font-size: 28px; margin: 0 0 6px; }
.join .sheet { padding: 0; }

#toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 20px); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px; display: flex; gap: 14px; align-items: center; z-index: 20; max-width: calc(100% - 32px); }
#toast button { color: var(--accent); font-weight: 700; filter: brightness(1.3); }
.offline { background: var(--danger); color: #fff; text-align: center; font-size: 14px; padding: 6px; border-radius: 10px; margin-bottom: 10px; }
