:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --text: #1c1f1d;
  --muted: #6c726e;
  --line: #e4e1d9;
  --accent: #1f6f5c;
  --accent-soft: #dcebe5;
  --gold: #e0a92e;
  --danger: #c4442f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .05);
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141614;
    --surface: #1e211f;
    --text: #ecefec;
    --muted: #8f9792;
    --line: #2c302d;
    --accent: #4fb596;
    --accent-soft: #233a32;
    --gold: #f0c35a;
    --danger: #ec7562;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

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

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(env(safe-area-inset-bottom) + 150px);
}

/* Header */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
}
h1 {
  margin: 2px 0 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -.01em;
}

.ring {
  position: relative;
  width: 64px;
  height: 64px;
  padding: 0;
  border: 0;
  background: none;
  flex: none;
}
.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(--accent);
  stroke-linecap: round;
  stroke-dasharray: 113.1;
  stroke-dashoffset: 113.1;
  transition: stroke-dashoffset .4s ease, stroke .3s;
}
.ring.complete .ring-fill { stroke: var(--gold); }
.ring span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Week strip */
.week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin: 20px 0 8px;
}
.day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.day .dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: conic-gradient(var(--accent) calc(var(--p, 0) * 1turn), transparent 0);
  -webkit-mask: radial-gradient(circle, transparent 0 7px, #000 7.5px);
          mask: radial-gradient(circle, transparent 0 7px, #000 7.5px);
}
.day.full .dot { background: var(--gold); border-color: var(--gold); -webkit-mask: none; mask: none; }
.day.today { color: var(--text); font-weight: 600; }

/* Sections */
.list-section { margin-top: 24px; }
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0 4px 8px;
}
h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
}
.hint { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.empty {
  margin: 0;
  padding: 16px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}
.empty[hidden] { display: none; }

/* Tasks */
.tasks {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.tasks:empty { display: none; }
.task {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 0 8px 0 14px;
  border-top: 1px solid var(--line);
}
.task:first-child { border-top: 0; }

.check {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  min-height: 56px;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
}
.box {
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  display: grid;
  place-items: center;
  transition: background .15s, border-color .15s, transform .15s;
}
.box svg { width: 14px; height: 14px; stroke: #fff; stroke-width: 3; fill: none; opacity: 0; }
.task.done .box { background: var(--accent); border-color: var(--accent); }
.task.done .box svg { opacity: 1; }
.check:active .box { transform: scale(.88); }

.title {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
  padding: 8px 0;
}
.task.done .title { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--muted); }

.meta {
  flex: none;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  padding-right: 6px;
}
.meta.streak { color: var(--gold); font-weight: 600; }

.tools { display: none; gap: 2px; flex: none; }
.editing .tools { display: flex; }
.editing .meta { display: none; }
.tool {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: none;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.tool:disabled { opacity: .3; }
.tool svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.tool.del { color: var(--danger); }

/* Footer */
.foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 32px;
  color: var(--muted);
  font-size: 14px;
}
.link { border: 0; background: none; padding: 6px; color: var(--muted); }
.editing #edit-toggle { color: var(--accent); font-weight: 600; }

/* Composer */
.composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 12px);
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.composer > * { max-width: 528px; margin-left: auto; margin-right: auto; }
.kind {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.kind label { cursor: pointer; }
.kind input { position: absolute; opacity: 0; pointer-events: none; }
.kind span {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px;
  color: var(--muted);
}
.kind input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.kind input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.row {
  display: flex;
  gap: 8px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.row input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  padding: 0 10px;
  font-size: 16px;
  outline: none;
}
.add {
  width: 44px;
  height: 44px;
  flex: none;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  display: grid;
  place-items: center;
}
.add svg { width: 22px; height: 22px; stroke: #fff; stroke-width: 2.5; stroke-linecap: round; }
.add:active { transform: scale(.95); }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 130px);
  transform: translate(-50%, 12px);
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  display: flex;
  gap: 12px;
  align-items: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { border: 0; background: none; color: var(--gold); font-weight: 600; padding: 0; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
