:root {
  --bg: #f6f7f4;
  --card: #ffffff;
  --text: #17201a;
  --muted: #5f6b63;
  --line: #e3e7e1;
  --brand: #16a34a;
  --brand-ink: #ffffff;
  --brand-soft: #dcfce7;
  --flame: #f97316;
  --flame-soft: #ffedd5;
  --star: #ca8a04;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --late: #7c3aed;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.05);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1411;
    --card: #182019;
    --text: #e8efe9;
    --muted: #98a59c;
    --line: #2a352d;
    --brand: #22c55e;
    --brand-ink: #062b13;
    --brand-soft: #14361f;
    --flame: #fb923c;
    --flame-soft: #3a2413;
    --star: #facc15;
    --danger: #f87171;
    --danger-soft: #3b1717;
    --late: #a78bfa;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
main {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
  min-height: 100vh;
}
h1 { font-size: 26px; margin: 4px 0 16px; letter-spacing: -.02em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 24px 4px 8px; }
p { margin: 0 0 8px; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }

/* Top bar on Today */
.topbar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.topbar .logo { font-weight: 800; font-size: 20px; letter-spacing: -.02em; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 6px 10px; border-radius: 999px; font-weight: 700; font-size: 15px; background: var(--card); box-shadow: var(--shadow); border: 1px solid var(--line); }
.pill.flame { color: var(--flame); }
.pill.flame.off { color: var(--muted); filter: grayscale(1); }
.pill.star { color: var(--star); }
.pill.debt { color: var(--danger); background: var(--danger-soft); border-color: transparent; }

.hero { background: var(--brand); color: var(--brand-ink); border-radius: var(--radius); padding: 16px; margin: 12px 0 4px; }
.hero b { font-size: 18px; display: block; }
.hero.flame { background: var(--flame); color: #fff; }
.hero.done { background: var(--brand-soft); color: var(--text); }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); margin-bottom: 10px; }
.goal { display: flex; gap: 12px; align-items: flex-start; }
.goal .body { flex: 1; min-width: 0; }
.goal .title { font-weight: 650; font-size: 17px; overflow-wrap: anywhere; }
.goal.is-done .title { text-decoration: line-through; color: var(--muted); }
.goal .why { color: var(--muted); font-size: 14px; font-style: italic; margin-top: 2px; }
.goal .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); font-size: 13px; color: var(--text); }
.chip.brand { background: var(--brand-soft); border-color: transparent; }
.chip.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.chip.late { color: var(--late); }
.chip.warn { background: var(--flame-soft); color: var(--flame); border-color: transparent; }

.check {
  flex: none; width: 46px; height: 46px; border-radius: 50%;
  border: 3px solid var(--line); background: var(--card); color: transparent;
  font-size: 22px; font-weight: 900; display: grid; place-items: center; cursor: pointer;
  transition: transform .12s, background .15s, border-color .15s;
}
.check:active { transform: scale(.9); }
.check:hover { border-color: var(--brand); }
.check.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.check.missed { border-style: dashed; border-color: var(--danger); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.actions .ghost { padding-left: 0; }

/* Buttons and forms */
button, .btn {
  font: inherit; font-weight: 650; border: 0; border-radius: 12px; padding: 11px 16px; cursor: pointer;
  background: var(--brand); color: var(--brand-ink); text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  box-shadow: 0 3px 0 rgba(0,0,0,.18);
}
button:active, .btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.18); }
button.secondary { background: var(--card); color: var(--text); border: 1px solid var(--line); box-shadow: none; }
button.ghost { background: transparent; color: var(--muted); box-shadow: none; padding: 8px 10px; }
button.danger { background: var(--danger); color: #fff; }
button.small { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
button.block { width: 100%; }
button:disabled { opacity: .5; cursor: default; }

label { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
label .hint { font-weight: 400; color: var(--muted); }
input, textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--card);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 12px;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--brand); }
textarea { min-height: 72px; resize: vertical; }
input[type=range] { padding: 0; border: 0; accent-color: var(--brand); }
.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; background: transparent; color: var(--muted); box-shadow: none; padding: 9px 4px; font-size: 14px; border-radius: 9px; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; margin-top: 14px; }
.switch input { width: 22px; height: 22px; accent-color: var(--brand); }
.error { color: var(--danger); font-size: 14px; margin-top: 10px; min-height: 1em; }
.formfoot { display: flex; gap: 8px; margin-top: 20px; }
.formfoot > * { flex: 1; }

/* Auth */
.auth { max-width: 380px; margin: 8vh auto 0; text-align: center; }
.auth .mascot { font-size: 64px; }
.auth h1 { margin-bottom: 4px; }
.auth form { text-align: left; margin-top: 20px; }

/* Lists */
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty .big { font-size: 46px; }
.reward { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.reward .emoji { font-size: 30px; width: 44px; text-align: center; }
.reward .body { flex: 1; min-width: 0; }
.weight { display: inline-flex; gap: 2px; }
.weight i { width: 6px; height: 14px; border-radius: 2px; background: var(--line); }
.weight i.on { background: var(--star); }
.listgoal { cursor: pointer; }

.fab {
  position: fixed; right: max(16px, calc(50% - 304px)); bottom: calc(84px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%; font-size: 30px; padding: 0; z-index: 5;
}

/* Stats */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.tile .n { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.tile .l { color: var(--muted); font-size: 13px; }
.tile.good .n { color: var(--brand); }
.tile.bad .n { color: var(--danger); }
.tile.flame .n { color: var(--flame); }
.tile.star .n { color: var(--star); }
.heat { display: grid; grid-template-rows: repeat(7, 1fr); grid-auto-flow: column; gap: 3px; overflow-x: auto; }
.heat i { width: 100%; aspect-ratio: 1; min-width: 12px; border-radius: 3px; background: var(--line); }
.heat i.good { background: var(--brand); }
.heat i.bad { background: var(--danger); opacity: .75; }
.heat i.pending { outline: 2px solid var(--brand); outline-offset: -2px; background: transparent; }
.heat i.blank { background: transparent; }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; background: var(--line); }
.legend .g::before { background: var(--brand); }
.legend .b::before { background: var(--danger); opacity: .75; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: right; padding: 8px 4px; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.history { display: flex; flex-wrap: wrap; gap: 4px; }
.history i { width: 14px; height: 14px; border-radius: 50%; background: var(--line); }
.history i.done { background: var(--brand); }
.history i.missed { background: var(--danger); }
.history i.late { background: var(--late); }
.history i.open { outline: 2px solid var(--brand); outline-offset: -2px; background: transparent; }

/* Tabs */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: center; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a { flex: 1; max-width: 160px; display: flex; flex-direction: column; align-items: center; padding: 8px 0 10px; color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600; }
.tabs a .ti { font-size: 22px; filter: grayscale(1); opacity: .7; }
.tabs a.on { color: var(--brand); }
.tabs a.on .ti { filter: none; opacity: 1; }

/* Toast, modal, celebration */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-weight: 600;
  max-width: calc(100% - 32px); z-index: 30; box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
dialog {
  border: 0; border-radius: 20px; padding: 20px; width: min(520px, calc(100% - 24px));
  background: var(--card); color: var(--text); max-height: 90vh; overflow: auto;
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h1 { font-size: 22px; margin-top: 0; }
.celebrate { text-align: center; }
.celebrate .big { font-size: 72px; animation: pop .5s ease-out; }
@keyframes pop { 0% { transform: scale(.3); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px; animation: fall 1.4s ease-in forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(540deg); opacity: .6; } }
@media (prefers-reduced-motion: reduce) {
  .confetti { display: none; }
  .celebrate .big { animation: none; }
}
.emoji-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-pick button { background: var(--bg); box-shadow: none; padding: 6px; font-size: 22px; border: 1.5px solid transparent; width: 44px; }
.emoji-pick button.on { border-color: var(--brand); }
