:root {
  --bg: #f1f1ef;
  --card: #ffffff;
  --ink: #2b2b2b;
  --ink-soft: #6b6b6b;
  --ink-faint: #a5a5a5;
  --rule: #ececea;
  --rule-strong: #d8d8d4;
  --green: #2f9d6e;
  --green-soft: #d6efe2;
  --amber: #c98a2b;
  --highlight: #f1efe9;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 14px;
  --tap: 44px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button {
  font: inherit; color: inherit;
  background: none; border: 0; padding: 0; margin: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--green); text-decoration: none; }

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 14px 80px;
}

/* ---- Card ---- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ---- Top bar (checklist screen) ---- */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 4px 14px;
}
.topbar .back {
  min-width: var(--tap); min-height: var(--tap);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-soft);
  font-size: 22px;
}
.topbar .spacer { flex: 1; }
.topbar .action {
  min-height: var(--tap); padding: 0 12px;
  color: var(--ink-soft); font-size: 14px;
}

/* ---- Checklist header ---- */
.cl-header { padding: 16px 18px 12px; }
.cl-eyebrow {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-faint);
}
.cl-eyebrow .progress-text { color: var(--ink-soft); letter-spacing: 0; text-transform: none; font-size: 12px; }
.cl-title {
  margin: 4px 0 10px; font-size: 22px; font-weight: 600;
}
.cl-bar {
  height: 3px; background: var(--rule); border-radius: 2px; overflow: hidden;
}
.cl-bar > span {
  display: block; height: 100%; background: var(--green);
  transition: width .25s ease;
}

/* ---- Sections ---- */
.section + .section { border-top: 1px solid var(--rule); }
.section-header {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  min-height: var(--tap);
  text-align: left;
}
.section-header .chev {
  width: 14px; color: var(--ink-faint); font-size: 14px;
  transition: transform .15s ease;
}
.section.open .section-header .chev { transform: rotate(90deg); }
.section-header .label { flex: 1; font-weight: 500; }
.section-header .count {
  font-variant-numeric: tabular-nums; font-size: 13px;
  color: var(--ink-faint);
}
.section.state-done .section-header .count { color: var(--green); }
.section.state-progress .section-header .count { color: var(--amber); }

.section-body { display: none; padding: 0 12px 8px; }
.section.open .section-body { display: block; }

/* ---- Items ---- */
.item {
  width: 100%;
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 10px;
  min-height: var(--tap);
  border-radius: 10px;
  text-align: left;
}
.item + .item { margin-top: 2px; }
.item .box {
  flex: 0 0 auto;
  width: 24px; height: 24px; border-radius: 6px;
  border: 1.5px solid var(--rule-strong);
  display: flex; align-items: center; justify-content: center;
  margin-top: 1px;
  background: var(--card);
  transition: background .12s ease, border-color .12s ease;
}
.item .box svg { width: 16px; height: 16px; opacity: 0; transition: opacity .12s ease; }
.item.done .box { background: var(--green-soft); border-color: var(--green-soft); }
.item.done .box svg { opacity: 1; color: var(--green); }
.item .body { flex: 1; min-width: 0; }
.item .text {
  font-size: 15px; color: var(--ink);
}
.item.done .text { color: var(--ink-faint); text-decoration: line-through; }
.item .detail {
  display: none;
  font-size: 13px; color: var(--ink-soft); margin-top: 2px;
}
.item.highlight { background: var(--highlight); }
.item.highlight .detail { display: block; }

/* ---- Home screen ---- */
.home-header {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 2px 6px 14px;
}
.home-header h1 { margin: 0; font-size: 22px; font-weight: 600; }
.home-header .sub { color: var(--ink-faint); font-size: 13px; }

.cl-list { display: flex; flex-direction: column; gap: 10px; }
.cl-row {
  position: relative; overflow: hidden; border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow);
}
.cl-row .swipe-bg {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: flex-end;
  padding-right: 22px;
  background: #d94c4c; color: #fff; font-weight: 500;
}
.cl-row .swipe-fg {
  position: relative; background: var(--card);
  padding: 14px 16px; transition: transform .2s ease;
  touch-action: pan-y;
}
.cl-row .row-title { font-size: 16px; font-weight: 500; }
.cl-row .row-meta {
  display: flex; align-items: center; gap: 10px;
  margin-top: 8px; font-size: 12px; color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}
.cl-row .mini-bar {
  flex: 1; height: 3px; background: var(--rule); border-radius: 2px; overflow: hidden;
}
.cl-row .mini-bar > span { display: block; height: 100%; background: var(--green); }

.empty {
  padding: 40px 16px; text-align: center; color: var(--ink-faint);
}
.empty p { margin: 6px 0; }

/* ---- Floating action ---- */
.fab-row {
  position: fixed; left: 0; right: 0; bottom: 16px;
  display: flex; justify-content: center; gap: 10px; pointer-events: none;
  padding: 0 14px;
}
.fab {
  pointer-events: auto;
  background: var(--ink); color: #fff;
  border-radius: 999px; padding: 12px 18px; min-height: var(--tap);
  box-shadow: 0 4px 20px rgba(0,0,0,.18);
  font-size: 14px; font-weight: 500;
}
.fab.secondary { background: #fff; color: var(--ink); border: 1px solid var(--rule-strong); }

/* ---- Import / settings forms ---- */
.form { padding: 16px 18px; }
.form h2 { margin: 0 0 12px; font-size: 18px; font-weight: 600; }
.form label { display: block; font-size: 13px; color: var(--ink-soft); margin: 12px 0 6px; }
.form input, .form textarea {
  width: 100%; font: inherit; color: var(--ink);
  background: #fafaf8; border: 1px solid var(--rule-strong);
  border-radius: 10px; padding: 10px 12px;
}
.form textarea { min-height: 240px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.form .row { display: flex; gap: 10px; margin-top: 16px; }
.form .row .fab { flex: 1; text-align: center; }
.form .err { color: #c0392b; font-size: 13px; margin-top: 8px; min-height: 1em; }
.form .hint { color: var(--ink-faint); font-size: 12px; margin-top: 4px; }

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%);
  background: rgba(0,0,0,.82); color: #fff;
  padding: 10px 14px; border-radius: 10px;
  font-size: 13px; opacity: 0; pointer-events: none;
  transition: opacity .2s ease;
}
.toast.show { opacity: 1; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #181816;
    --card: #232321;
    --ink: #ececea;
    --ink-soft: #a5a5a0;
    --ink-faint: #6e6e6a;
    --rule: #2f2f2c;
    --rule-strong: #3a3a36;
    --green-soft: #1f3a30;
    --highlight: #2a2a27;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  }
  .form input, .form textarea { background: #1c1c1a; }
  .fab.secondary { background: var(--card); color: var(--ink); }
}
