:root {
  --bg: #fffaf3; --surface: #ffffff; --ink: #1c1917; --muted: #78716c; --line: #e7e5e4;
  --accent: #f59e0b; --accent-ink: #1c1917; --good: #16a34a; --heat0: #f1ece4;
  --radius: 16px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12100e; --surface: #1c1917; --ink: #f5f5f4; --muted: #a8a29e; --line: #2e2a27;
    --heat0: #26221f; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12100e; --surface: #1c1917; --ink: #f5f5f4; --muted: #a8a29e; --line: #2e2a27;
  --heat0: #26221f; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  max-width: 560px; margin-inline: auto;
  padding: env(safe-area-inset-top) 16px calc(96px + env(safe-area-inset-bottom));
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 8px 14px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; font-size: 14px; font-weight: 500; text-transform: none; letter-spacing: 0; }
input { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 12px; min-width: 0; }
h1 { margin: 0; font-size: 30px; letter-spacing: -.02em; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 24px 0 10px; }
h2.row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.eyebrow { margin: 16px 0 2px; color: var(--muted); font-size: 14px; }

.top { display: flex; justify-content: space-between; align-items: flex-end; }
.ring { --p: 0; width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--line) 0); }
.ring span { width: 50px; height: 50px; border-radius: 50%; background: var(--bg); display: grid; place-items: center; font-size: 13px; font-weight: 700; }

.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 16px; }
.week button { display: grid; gap: 2px; padding: 8px 0; text-align: center; font-size: 12px; color: var(--muted); }
.week button b { font-size: 17px; color: var(--ink); }
.week button.sel { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.week button.sel b { color: var(--accent-ink); }
.week button.full::after { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--good); justify-self: center; }

ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.habits li { display: flex; align-items: center; gap: 12px; background: var(--surface); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow); border-left: 5px solid var(--c, var(--accent)); }
.habits .emoji { font-size: 24px; }
.habits .meta { flex: 1; min-width: 0; }
.habits .meta b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.habits .meta small { color: var(--muted); }
.check { width: 40px; height: 40px; border-radius: 50%; padding: 0; font-size: 20px; border: 2px solid var(--c, var(--accent)); background: none; }
.check.done { background: var(--c, var(--accent)); color: #fff; }
.habits li.done .meta b { text-decoration: line-through; color: var(--muted); }
.del { border: 0; background: none; color: var(--muted); padding: 4px 6px; font-size: 18px; }

.add-task { display: flex; gap: 8px; }
.add-task input { flex: 1; }
.tasks { margin-top: 8px; }
.tasks li { display: flex; align-items: center; gap: 10px; background: var(--surface); border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow); }
.tasks li span { flex: 1; overflow-wrap: anywhere; }
.tasks li.done span { text-decoration: line-through; color: var(--muted); }
.tasks input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }
.empty, .hint { color: var(--muted); font-size: 14px; }

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.card { background: var(--surface); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); display: grid; }
.card b { font-size: 24px; }
.card span { color: var(--muted); font-size: 12px; }
.heatmap { display: grid; grid-template-rows: repeat(7, 1fr); grid-auto-flow: column; gap: 4px; }
.heatmap i { aspect-ratio: 1; border-radius: 4px; background: var(--heat0); }
.habit-stats li { display: flex; justify-content: space-between; gap: 8px; background: var(--surface); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.habit-stats small { color: var(--muted); white-space: nowrap; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.row-field { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 8px 14px; cursor: pointer; }

.fab { position: fixed; right: max(16px, calc(50% - 264px)); bottom: calc(84px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  border: 0; font-size: 28px; box-shadow: 0 6px 20px rgba(245,158,11,.4); }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; gap: 4px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); }
.tabs button { border: 0; background: none; flex: 1; max-width: 160px; color: var(--muted); }
.tabs button.on { color: var(--accent); font-weight: 700; }

dialog { border: 0; border-radius: 20px; padding: 20px; width: min(520px, calc(100% - 32px)); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h2 { margin-top: 0; }
dialog .label { margin: 16px 0 6px; font-size: 14px; color: var(--muted); }
.emoji-in { width: 56px; text-align: center; }
#habitName { flex: 1; }
.days, .colors, .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.days button { width: 40px; padding: 8px 0; }
.days button.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.colors button { width: 32px; height: 32px; border-radius: 50%; padding: 0; background: var(--c); border: 3px solid transparent; }
.colors button.on { border-color: var(--ink); }
.chips button { font-size: 13px; padding: 6px 10px; border-radius: 999px; }
menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 20px 0 0; }
.error { color: #dc2626; font-size: 14px; min-height: 1em; margin: 8px 0 0; }

.toast { position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none; transition: opacity .2s; }
.toast.show { opacity: 1; }
