:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1c2522;
  --muted: #6b7975;
  --line: #e2e7e5;
  --accent: #1f6f5c;
  --accent-soft: #dcefe9;
  --danger: #b3261e;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111615;
    --card: #1b2220;
    --text: #e8eeec;
    --muted: #93a29e;
    --line: #2b3431;
    --accent: #4fbf9f;
    --accent-soft: #1f3a33;
    --danger: #f2827a;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
}
button, input { font: inherit; color: inherit; }

.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: calc(10px + env(safe-area-inset-top)) 16px 8px;
  border-bottom: 1px solid var(--line);
}
.top-row { display: flex; align-items: center; gap: 8px; }
.top-row.small { justify-content: space-between; font-size: 14px; color: var(--muted); margin: 6px 0; }
h1 { font-size: 22px; margin: 0; flex: 1; }
.btn-ghost {
  background: none; border: 0; padding: 8px 10px; border-radius: 10px;
  color: var(--accent); font-weight: 600; cursor: pointer;
}
.btn-ghost.on { background: var(--accent-soft); }
#menuBtn { font-size: 22px; line-height: 1; }

.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 8px; }
#progressBar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.seg { display: flex; background: var(--line); border-radius: 10px; padding: 2px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; font-size: 14px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .count { opacity: .75; margin-left: 4px; }

main { padding: 12px 16px; max-width: 640px; margin: 0 auto; }
.cat { background: var(--card); border-radius: 14px; margin-bottom: 14px; overflow: hidden; border: 1px solid var(--line); }
.cat-head {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 12px 14px; background: none; border: 0; text-align: left; cursor: pointer;
}
.cat-head h2 { font-size: 18px; margin: 0; flex: 1; }
.cat-head .count { color: var(--muted); font-size: 14px; }
.cat-head .count.done { color: var(--accent); font-weight: 600; }
.cat-head .arrow { color: var(--muted); transition: transform .15s; }
.cat.closed .arrow { transform: rotate(-90deg); }
.cat.closed ul, .cat.closed .add { display: none; }

ul { list-style: none; margin: 0; padding: 0; }
li { display: flex; align-items: center; border-top: 1px solid var(--line); }
.item {
  flex: 1; display: flex; align-items: center; gap: 12px;
  min-height: 50px; padding: 10px 14px; background: none; border: 0; text-align: left; cursor: pointer;
}
.box {
  flex: none; width: 26px; height: 26px; border-radius: 8px;
  border: 2px solid var(--muted); display: grid; place-items: center;
  color: #fff; font-size: 16px; font-weight: 700;
}
li.checked .box { background: var(--accent); border-color: var(--accent); }
li.checked .text { color: var(--muted); text-decoration: line-through; }
.icon-btn {
  flex: none; width: 48px; height: 50px; border: 0; background: none;
  color: var(--danger); font-size: 20px; cursor: pointer;
}

.add { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
.add input, .field {
  flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg);
}
.add button, .primary {
  border: 0; border-radius: 10px; padding: 10px 14px;
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}
.cat-tools { display: flex; gap: 8px; padding: 0 14px 12px; }
.cat-tools button { font-size: 14px; }
.cat-tools .danger { color: var(--danger); }

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

dialog { border: 0; border-radius: 16px; padding: 0; background: var(--card); color: var(--text); width: min(92vw, 360px); }
dialog::backdrop { background: rgba(0,0,0,.4); }
.menu { display: flex; flex-direction: column; padding: 8px; }
.menu button { border: 0; background: none; text-align: left; padding: 14px 12px; border-radius: 10px; cursor: pointer; }
.menu button:hover { background: var(--bg); }
.menu .danger { color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 15px;
}

.back { font-size: 28px; line-height: 1; padding: 2px 10px 6px; text-decoration: none; }

.new-list { display: flex; gap: 8px; margin-bottom: 16px; }
.list-card {
  display: block; text-decoration: none; color: inherit;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; margin-bottom: 10px;
}
.list-card h2 { font-size: 18px; margin: 0 0 4px; }
.list-card .meta { color: var(--muted); font-size: 14px; }
.list-card .progress { margin-top: 10px; }
.list-card .progress div { height: 100%; background: var(--accent); }
.list-card.base { border-style: dashed; }
.section-title { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 20px 4px 8px; }
.hint { color: var(--muted); font-size: 14px; margin: 0 4px 12px; }
.plain .item { cursor: default; }

.ask { display: flex; flex-direction: column; gap: 8px; padding: 18px; }
.ask p { margin: 0 0 8px; }
.ask button { padding: 12px; border-radius: 10px; cursor: pointer; }
.secondary { border: 1px solid var(--line); background: var(--bg); font-weight: 600; }
.primary { border: 0; }

[hidden] { display: none !important; }
