:root {
  --bg: #f6f7f9;
  --panel: #fff;
  --panel-2: #fbfcfd;
  --text: #12161c;
  --muted: #6b7684;
  --line: #e4e8ed;
  --line-2: #eef1f4;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --done: #16a34a;
  --danger: #d0342c;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.04), 0 1px 3px rgb(16 24 40 / 0.06);
  --shadow-lg: 0 12px 32px rgb(16 24 40 / 0.14);
  --r: 10px;
  --wrap: 760px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1014;
    --panel: #161a20;
    --panel-2: #1b2027;
    --text: #e7ebf0;
    --muted: #8b95a3;
    --line: #262d36;
    --line-2: #202730;
    --accent: #5b9dff;
    --accent-soft: #17263d;
    --done: #3ac07d;
    --danger: #ef6b60;
    --shadow: none;
    --shadow-lg: 0 16px 40px rgb(0 0 0 / 0.5);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15.5px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh; display: flex; flex-direction: column;
}
kbd {
  font: 600 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; padding: 3px 5px; color: var(--muted);
}

/* ---------- header ---------- */
.bar { position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--panel) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.bar__in { max-width: var(--wrap); margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 10px; }

.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; color: inherit; flex: 0 0 auto; }
.brand__mark { width: 24px; height: 24px; flex: 0 0 auto; }
.brand__mark rect { fill: var(--accent); }
.brand__mark path { stroke: #fff; stroke-width: 11; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.brand__word { font-size: 16px; font-weight: 650; letter-spacing: -0.015em; }
.brand__word em { font-style: normal; font-weight: 400; color: var(--muted); }

.bar__actions { margin-left: auto; display: flex; gap: 8px; align-items: center; min-width: 0; }
.picker { position: relative; min-width: 0; display: flex; }
.picker::after {
  content: ""; position: absolute; right: 11px; top: 50%; width: 7px; height: 7px;
  border-right: 1.6px solid var(--muted); border-bottom: 1.6px solid var(--muted);
  transform: translateY(-70%) rotate(45deg); pointer-events: none;
}

select, .btn, input[type="text"] {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--r); padding: 8px 12px;
  transition: border-color .14s ease, background .14s ease, box-shadow .14s ease;
}
select {
  appearance: none; padding-right: 30px; min-width: 0; max-width: 260px;
  text-overflow: ellipsis; cursor: pointer;
}
select:hover, .btn:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.btn { cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 550; }
.btn--primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); border-color: transparent; }
.btn--icon { padding: 9px; }
.btn--icon svg { width: 16px; height: 16px; display: block; fill: currentColor; }
:where(select, .btn, input):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- menu ---------- */
.menuwrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 40;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 5px; display: flex; flex-direction: column; min-width: 208px;
  box-shadow: var(--shadow-lg);
}
.menu[hidden] { display: none; }
.menu button {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  text-align: left; background: none; border: 0; color: inherit; font: inherit;
  padding: 8px 10px; border-radius: 7px; cursor: pointer; width: 100%;
}
.menu button:hover, .menu button:focus-visible { background: var(--bg); outline: none; }
.menu hr { border: 0; border-top: 1px solid var(--line-2); margin: 5px 4px; }
.menu .danger { color: var(--danger); }

/* ---------- layout ---------- */
.wrap { max-width: var(--wrap); width: 100%; margin: 0 auto; padding: 26px 16px 72px; flex: 1; }

/* ---------- progress head ---------- */
.head { display: flex; align-items: center; gap: 15px; margin-bottom: 22px; }
.ring { position: relative; width: 52px; height: 52px; flex: 0 0 auto; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 4.5; }
.ring__track { stroke: var(--line); }
.ring__fill {
  stroke: var(--done); stroke-linecap: round;
  stroke-dasharray: 119.4; stroke-dashoffset: 119.4;
  transition: stroke-dashoffset .4s cubic-bezier(.4,0,.2,1);
}
.ring__pct {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 11.5px; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--muted);
}
.head__title { margin: 0; font-size: 21px; font-weight: 650; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.head__sub { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }
.head__sub.is-complete { color: var(--done); font-weight: 550; }

/* ---------- add ---------- */
.add { display: flex; gap: 8px; margin-bottom: 14px; }
.add input { flex: 1; min-width: 0; padding: 10px 13px; box-shadow: var(--shadow); }
.add input:focus { border-color: var(--accent); }

/* ---------- filters ---------- */
.filters { display: flex; gap: 6px; margin-bottom: 12px; }
.chip {
  font: inherit; font-size: 13px; color: var(--muted); background: none;
  border: 1px solid transparent; border-radius: 999px; padding: 5px 11px; cursor: pointer;
  display: inline-flex; gap: 6px; align-items: center;
}
.chip span { font-variant-numeric: tabular-nums; opacity: .75; font-size: 12px; }
.chip:hover { background: var(--panel); }
.chip.is-on { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 25%, transparent); font-weight: 550; }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- items ---------- */
.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.item {
  display: flex; align-items: flex-start; gap: 11px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r); padding: 11px 12px; box-shadow: var(--shadow);
  animation: pop .16s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .item { animation: none; } .ring__fill { transition: none; } }
.item:hover { border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); }
.item.done { background: var(--panel-2); }

.item input[type="checkbox"] {
  appearance: none; width: 19px; height: 19px; margin: 2px 0 0; flex: 0 0 auto;
  border: 1.8px solid var(--line); border-radius: 6px; cursor: pointer;
  background: var(--panel); transition: background .12s, border-color .12s;
}
.item input[type="checkbox"]:hover { border-color: var(--done); }
.item input[type="checkbox"]:checked {
  background: var(--done) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5 10.5l3.5 3.5L15 7' stroke='white' stroke-width='2.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/15px no-repeat;
  border-color: var(--done);
}
.item input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.item label { flex: 1; min-width: 0; cursor: pointer; overflow-wrap: anywhere; }
.item.done label { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }
.item .note { display: block; font-size: 13px; color: var(--muted); margin-top: 3px; text-decoration: none; }
.item.done .note { opacity: .65; }

.item .del {
  background: none; border: 0; color: var(--muted); cursor: pointer;
  padding: 4px 6px; border-radius: 6px; flex: 0 0 auto; line-height: 1;
  opacity: 0; transition: opacity .12s, color .12s;
}
.item .del svg { width: 14px; height: 14px; display: block; fill: currentColor; }
.item:hover .del, .del:focus-visible { opacity: 1; }
.del:hover { color: var(--danger); background: var(--bg); }
@media (hover: none) { .item .del { opacity: .55; } }

/* ---------- empty ---------- */
.empty { text-align: center; padding: 44px 16px; color: var(--muted); }
.empty[hidden] { display: none; }
.empty p { margin: 0 0 14px; }

/* ---------- dialog ---------- */
.dlg {
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text);
  padding: 18px; max-width: 480px; width: calc(100% - 32px); box-shadow: var(--shadow-lg);
}
.dlg::backdrop { background: rgb(10 14 20 / 0.5); backdrop-filter: blur(2px); }
.dlg__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.dlg__head h2 { margin: 0; font-size: 16px; }
.tpl { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.tpl button {
  width: 100%; text-align: left; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--r); padding: 12px 13px; cursor: pointer; font: inherit; color: inherit;
}
.tpl button:hover { border-color: var(--accent); background: var(--accent-soft); }
.tpl strong { display: block; font-weight: 600; }
.tpl small { display: block; color: var(--muted); margin-top: 2px; font-size: 13px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 9px 15px; border-radius: 999px;
  font-size: 13.5px; z-index: 60; box-shadow: var(--shadow-lg); animation: rise .18s ease-out;
}
.toast[hidden] { display: none; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- footer ---------- */
.foot { border-top: 1px solid var(--line); padding: 15px 16px; text-align: center; }
.foot p { margin: 0; color: var(--muted); font-size: 12.5px; }

/* ---------- mobile ---------- */
@media (max-width: 620px) {
  .bar__in { flex-wrap: wrap; row-gap: 9px; }
  .bar__actions { margin-left: 0; width: 100%; }
  /* min-width:0 is load-bearing: a flex item defaults to min-width:auto, and the
     longest option name then sets a floor the select refuses to shrink below —
     which pushes the ⋯ button off-screen and makes the menu unreachable. */
  .picker { flex: 1; min-width: 0; }
  select { flex: 1; max-width: none; min-width: 0; }
  .btn__text { display: none; }
  .head__title { font-size: 19px; }
  .foot kbd { display: none; }
}

/* Footer links inherit the muted footer colour rather than shouting. */
.foot a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.foot a:hover { color: var(--accent); }
