:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #eef0ec;
  --text: #14181a;
  --muted: #667079;
  --line: #e0e4de;
  --brand: #16a34a;
  --brand-ink: #ffffff;
  --danger: #c02626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 8px 24px rgba(16, 24, 20, .06);
  --topbar-h: 56px;
  --composer-h: 68px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1311;
    --surface: #171c19;
    --surface-2: #1f2622;
    --text: #e9eeea;
    --muted: #93a09a;
    --line: #2a332e;
    --brand: #22c55e;
    --brand-ink: #05130a;
    --danger: #ef6b6b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

h1, h2, p, ul { margin: 0; }
ul { list-style: none; padding: 0; }

button, input {
  font: inherit;
  color: inherit;
}

/* ---------- chrome ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 8px 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-left: 8px;
}

.brand img { border-radius: 7px; display: block; }

.topbar h1 {
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -.01em;
}

.title {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border-radius: 9px;
  outline: none;
  overflow-wrap: anywhere;
}

.title:focus { background: var(--surface-2); }

.iconbtn {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  text-decoration: none;
  cursor: pointer;
}

.iconbtn:active { background: var(--surface-2); }

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 14px calc(24px + env(safe-area-inset-bottom));
}

.list-wrap { padding-bottom: calc(var(--composer-h) + 28px + env(safe-area-inset-bottom)); }

/* ---------- buttons ---------- */

.btn {
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 11px 16px;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface-2);
}

.btn.primary {
  background: var(--brand);
  color: var(--brand-ink);
}

.btn.primary:active { filter: brightness(.92); }

.btn.ghost {
  background: transparent;
  border-color: var(--line);
  width: 100%;
  margin-top: 10px;
}

.btn.danger { color: var(--danger); }

/* ---------- home ---------- */

.newlist {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}

.newlist input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  outline: none;
}

.newlist input:focus { border-color: var(--brand); }

.cards { display: grid; gap: 10px; }

.card a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
}

.card .name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card .meta {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.card .count {
  display: grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--brand);
  color: var(--brand-ink);
  font-size: 13px;
  font-weight: 700;
}

.card .count.zero {
  background: var(--surface-2);
  color: var(--muted);
}

.empty {
  padding: 28px 6px;
  color: var(--muted);
  text-align: center;
}

/* ---------- items ---------- */

.items {
  display: grid;
  gap: 8px;
}

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 8px 12px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.item.pending { opacity: .55; }

.check {
  flex: none;
  width: 26px;
  height: 26px;
  border: 2px solid var(--line);
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.check .tick {
  font-size: 15px;
  line-height: 1;
  color: var(--brand-ink);
  opacity: 0;
}

.checked .check {
  background: var(--brand);
  border-color: var(--brand);
}

.checked .check .tick { opacity: 1; }

.item .text {
  flex: 1;
  min-width: 0;
  padding: 2px 0;
  outline: none;
  overflow-wrap: anywhere;
  cursor: text;
}

.checked .item .text {
  color: var(--muted);
  text-decoration: line-through;
}

.del {
  flex: none;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
}

.del:active { background: var(--surface-2); }

.done {
  margin-top: 22px;
}

.done summary {
  padding: 8px 4px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.done .items { margin-top: 8px; }

/* ---------- composer ---------- */

.composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  gap: 8px;
  max-width: 720px;
  margin: 0 auto;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}

.composer input {
  flex: 1;
  min-width: 0;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  outline: none;
}

.composer input:focus { border-color: var(--brand); }

.composer .btn {
  width: 50px;
  font-size: 22px;
  line-height: 1;
  padding: 0;
}

/* ---------- banners ---------- */

.banner {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 9px 14px;
  background: #b45309;
  color: #fff;
  font-size: 14px;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--composer-h) + 24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 30;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  box-shadow: var(--shadow);
}

@media (prefers-reduced-motion: no-preference) {
  .item { transition: opacity .15s ease; }
}
