:root {
  --bg: #f7f6f2; --surface: #ffffff; --ink: #1d1d1b; --muted: #77756d; --line: #e7e4db;
  --accent: #1f8a5b; --accent-ink: #ffffff; --accent-soft: #e3f3ea; --danger: #b93b34;
  --new: #fff3bf; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514; --surface: #1f1f1d; --ink: #f1f0ec; --muted: #9c9a90; --line: #2f2e2b;
    --accent: #43b883; --accent-ink: #0c1f15; --accent-soft: #1c3328; --danger: #e5675f;
    --new: #3b3417; --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Hebrew", Arial, sans-serif;
  min-height: 100dvh; display: flex; flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.wrap { width: 100%; max-width: 640px; margin: 0 auto; padding: 0 16px; }

header {
  position: sticky; top: 0; z-index: 2; background: var(--bg);
  padding-top: env(safe-area-inset-top);
}
header .wrap { display: flex; align-items: center; gap: 12px; padding-top: 14px; padding-bottom: 10px; }
h1 { font-size: 24px; letter-spacing: -.01em; margin: 0; }
#count { color: var(--muted); font-size: 14px; margin-top: 2px; }
.title { flex: 1; min-width: 0; }
.sync { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; transition: background .3s; }
.sync.off { background: var(--danger); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent;
  display: grid; place-items: center; color: var(--muted);
}
.icon-btn:hover { background: var(--line); color: var(--ink); }

main { flex: 1; padding-bottom: 16px; }
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.list:empty { display: none; }
.item {
  display: flex; align-items: stretch; border-top: 1px solid var(--line);
  /* keeps an item scrolled into view clear of the sticky header and composer */
  scroll-margin-top: 80px; scroll-margin-bottom: calc(96px + env(safe-area-inset-bottom));
}
.item:first-child { border-top: 0; }
.item.new { animation: flash 2.4s ease-out; }
@keyframes flash { from { background: var(--new); } to { background: transparent; } }
.toggle {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px; text-align: start;
  border: 0; background: transparent; padding: 12px 4px 12px 14px; min-height: 56px;
}
.check {
  flex: none; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--muted);
  display: grid; place-items: center; transition: background .15s, border-color .15s;
}
.check svg { width: 16px; height: 16px; stroke: var(--accent-ink); stroke-width: 3; fill: none; opacity: 0; }
.toggle:hover .check { border-color: var(--accent); }
.done .check { background: var(--accent); border-color: var(--accent); }
.done .check svg { opacity: 1; }
.body { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }
.text { font-size: 17px; overflow-wrap: anywhere; text-align: left; }
.meta { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.done .text { text-decoration: line-through; color: var(--muted); }
.del {
  flex: none; width: 48px; border: 0; background: transparent; color: var(--muted);
  font-size: 22px; line-height: 1; opacity: .55;
}
.del:hover { opacity: 1; color: var(--danger); }

.empty { text-align: center; color: var(--muted); padding: 48px 16px 32px; }
.empty strong { display: block; color: var(--ink); font-size: 18px; margin-bottom: 4px; }

.bought-head { display: flex; align-items: center; justify-content: space-between; margin: 26px 2px 8px; }
.link-btn { border: 0; background: transparent; padding: 6px 4px; color: var(--muted); font-size: 14px; font-weight: 600; }
.link-btn:hover { color: var(--ink); }
#bought .item { background: transparent; }
#bought.list { background: transparent; box-shadow: none; border: 1px solid var(--line); }

.composer {
  position: sticky; bottom: 0; background: var(--bg);
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
.composer form { display: flex; gap: 8px; padding-top: 10px; }
.composer input {
  flex: 1; min-width: 0; height: 50px; padding: 0 16px; border-radius: 25px;
  border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); outline: none;
}
.composer input:focus { border-color: var(--accent); }
.primary {
  height: 50px; padding: 0 20px; border-radius: 25px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-weight: 650;
}
.primary:disabled { opacity: .5; }

dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(420px, calc(100% - 32px));
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog form { padding: 20px; display: grid; gap: 6px; }
dialog h2 { margin: 0 0 8px; font-size: 20px; }
dialog label { font-weight: 600; font-size: 14px; margin-top: 8px; }
.field {
  height: 46px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); outline: none; width: 100%;
}
.field:focus { border-color: var(--accent); }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.row { display: flex; gap: 8px; }
.secondary { height: 46px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; flex: none; }
dialog .primary { margin-top: 14px; }

#locked { text-align: center; padding: 64px 16px; }
#locked h2 { margin: 0 0 6px; }
#locked p { color: var(--muted); margin: 0 0 20px; }
#locked form { display: flex; gap: 8px; max-width: 380px; margin: 0 auto; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); border-radius: 12px; padding: 10px 10px 10px 16px;
  display: flex; align-items: center; gap: 12px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2);
  width: min(560px, calc(100% - 32px)); z-index: 5;
}
.toast button { border: 0; background: transparent; color: var(--accent); font-weight: 700; padding: 6px 8px; flex: none; }
#toast-text { min-width: 0; overflow-wrap: anywhere; }
.lock-error { color: var(--danger); font-weight: 600; margin: -8px 0 16px; }
[hidden] { display: none !important; }

/* ---- list tabs */
.tabs { flex: 1; display: flex; gap: 6px; }
header .wrap + .wrap { padding-top: 0; }
.tab {
  flex: 1; height: 40px; border-radius: 20px; border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); font-weight: 650; font-size: 15px; display: flex; align-items: center; justify-content: center; gap: 6px;
  white-space: nowrap; min-width: 0;
}
.tab[aria-selected="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.badge { min-width: 20px; padding: 0 6px; border-radius: 10px; font-size: 12px; line-height: 20px; background: var(--line); color: var(--ink); }
.badge:empty { display: none; }
.tab[aria-selected="true"] .badge { background: var(--accent); color: var(--accent-ink); }
.tab.pulse { animation: pulse 1.6s ease-out 2; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 var(--accent); } 100% { box-shadow: 0 0 0 8px transparent; } }

/* move an item to the other list */
.move {
  flex: none; width: 40px; border: 0; background: transparent; font-size: 17px; opacity: .7;
}
.move:hover { opacity: 1; }
