:root {
  --bg: #f6f3ec;
  --card: #ffffff;
  --ink: #1d1b18;
  --muted: #736d63;
  --line: #e4dfd3;
  --accent: #e4572e;
  --accent-ink: #ffffff;
  --missed: #e9e4d8;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 14px rgb(0 0 0 / 5%);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15140f;
    --card: #211f19;
    --ink: #f3efe6;
    --muted: #a39c8e;
    --line: #35322a;
    --accent: #ff7a50;
    --accent-ink: #1d1b18;
    --missed: #2f2c25;
    --danger: #ff8a80;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

#app {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
  min-height: 100dvh;
}

h1 { font-size: 30px; line-height: 1.1; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 26px 4px 8px; font-weight: 600; }
.sub { color: var(--muted); font-size: 15px; }
.error { color: var(--danger); font-size: 15px; min-height: 1.4em; margin: 8px 0 0; }

.card { background: var(--card); border-radius: 18px; box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 12px; }

/* Buttons */
.btn {
  display: block; width: 100%; padding: 14px 16px; border: 0; border-radius: 14px;
  background: var(--accent); color: var(--accent-ink); font-weight: 650; font-size: 17px;
}
.btn.quiet { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1.5px solid var(--line); }
.btn:disabled { opacity: 0.5; }
.btn + .btn { margin-top: 10px; }
.link { background: none; border: 0; padding: 8px 4px; color: var(--accent); font-weight: 600; }
.round {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--card);
  box-shadow: var(--shadow); font-size: 20px; line-height: 1; display: grid; place-items: center;
}
.round:disabled { opacity: 0.35; }

/* Forms */
label.field { display: block; margin-top: 14px; font-size: 14px; color: var(--muted); font-weight: 600; }
.field input, .field textarea {
  display: block; width: 100%; margin-top: 6px; padding: 13px 14px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--bg); font-size: 17px;
}
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.legend { margin: 18px 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; }

/* Sign in */
.auth { padding-top: 12vh; }
.auth .mark { width: 64px; height: 64px; border-radius: 18px; display: block; margin-bottom: 20px; }
.auth form { margin-top: 22px; }
.auth .btn { margin-top: 20px; }
.auth .switch { text-align: center; margin-top: 14px; }

/* Today */
.top { display: flex; align-items: center; gap: 10px; }
.top .when { flex: 1; min-width: 0; }
.progress { margin-top: 18px; }
.progress .bar { height: 10px; border-radius: 99px; background: var(--missed); overflow: hidden; }
.progress .fill { height: 100%; border-radius: 99px; background: var(--accent); transition: width 0.25s ease; }
.progress .words { display: flex; justify-content: space-between; margin-top: 6px; font-size: 14px; color: var(--muted); }

.habit {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--card); border-radius: 18px; box-shadow: var(--shadow); padding: 10px 14px 10px 10px;
}
.habit + .habit { margin-top: 10px; }
.habit .tick {
  flex: none; width: 56px; height: 56px; border-radius: 50%; border: 3px solid var(--c);
  background: transparent; font-size: 26px; line-height: 1; display: grid; place-items: center;
  transition: transform 0.12s ease, background 0.15s ease;
}
.habit .tick:active { transform: scale(0.92); }
.habit.done .tick { background: var(--c); }
.habit .body { flex: 1; min-width: 0; background: none; border: 0; text-align: left; padding: 6px 0; }
.habit .name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.habit.done .name { text-decoration: line-through; text-decoration-color: var(--muted); color: var(--muted); }
.habit .meta { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.habit .more { color: var(--muted); font-size: 22px; flex: none; }

/* Next */
.hero { margin-top: 18px; text-align: center; padding: 22px 18px 18px; border-top: 6px solid var(--c); }
.hero .eyebrow { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.hero.late .eyebrow::after { content: " · late"; color: var(--danger); }
.hero .badge {
  width: 76px; height: 76px; margin: 14px auto 10px; border-radius: 50%; border: 3px solid var(--c);
  display: grid; place-items: center; font-size: 36px; line-height: 1;
}
.hero .what {
  display: block; width: 100%; background: none; border: 0; padding: 0; font-size: 26px; font-weight: 700;
  line-height: 1.2; letter-spacing: -0.01em; overflow-wrap: anywhere;
}
.hero .about { display: flex; justify-content: center; align-items: center; gap: 8px; flex-wrap: wrap; margin: 8px 0 4px; font-size: 15px; color: var(--muted); }
.hero .btn { margin-top: 10px; }
.hero .error:empty { min-height: 0; margin: 0; }
.habit.skipped { opacity: 0.55; }
.habit .meta.late, .hero.late .about { color: var(--danger); }
.pill.p1 { color: var(--accent); border-color: var(--accent); }
.pill.p3 { opacity: 0.7; }
.link.back { display: block; margin: 10px auto 0; }
.field input[type="date"] { min-height: 50px; -webkit-appearance: none; appearance: none; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .big { font-size: 44px; }
.empty .btn { margin-top: 18px; }
.add { margin-top: 22px; }

/* Tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; max-width: 130px; background: none; border: 0; padding: 10px 0 8px; font-size: 12px;
  font-weight: 600; color: var(--muted); display: grid; gap: 2px; justify-items: center;
}
.tabs button span { font-size: 22px; line-height: 1; filter: grayscale(1); opacity: 0.7; }
.tabs button.on { color: var(--accent); }
.tabs button.on span { filter: none; opacity: 1; }

/* Sheet */
.shade { position: fixed; inset: 0; background: rgb(0 0 0 / 45%); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet {
  width: 100%; max-width: 520px; max-height: 92dvh; overflow-y: auto; background: var(--card);
  border-radius: 22px 22px 0 0; padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
}
.sheet .head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.sheet .head h3 { margin: 0; font-size: 20px; }
.sheet .btn.first { margin-top: 22px; }

.icons { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.icons button {
  aspect-ratio: 1; border-radius: 12px; border: 2px solid transparent; background: var(--bg);
  font-size: 22px; line-height: 1; padding: 0;
}
.icons button.on { border-color: var(--accent); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--card); background: var(--c); padding: 0; }
.swatches button.on { box-shadow: 0 0 0 3px var(--c); }
.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1; padding: 10px 2px; border-radius: 12px; border: 1.5px solid var(--line); background: transparent;
  font-size: 14px; font-weight: 600; color: var(--muted);
}
.seg button.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }

/* Stats */
.trio { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.trio b { display: block; font-size: 28px; line-height: 1.1; letter-spacing: -0.02em; }
.trio span { font-size: 13px; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-top: 14px; }
.grid .dow { font-size: 11px; color: var(--muted); text-align: center; font-weight: 600; }
.grid .cell { aspect-ratio: 1; border-radius: 8px; background: var(--missed); }
.grid .cell.none { background: transparent; border: 1.5px dashed var(--line); }
.grid .cell.blank { background: transparent; }
.grid .cell.today { outline: 2px solid var(--ink); outline-offset: 1px; }
.key { font-size: 13px; color: var(--muted); margin-top: 10px; }

.stat .row { display: flex; align-items: center; gap: 12px; }
.stat .badge { width: 44px; height: 44px; border-radius: 50%; background: var(--c); display: grid; place-items: center; font-size: 21px; flex: none; }
.stat .title { font-weight: 650; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat .trio { margin-top: 14px; }
.stat .trio b { font-size: 22px; }
.dots { display: grid; grid-template-columns: repeat(35, 1fr); gap: 2px; margin-top: 14px; }
.dots i { aspect-ratio: 1 / 2.4; border-radius: 3px; background: var(--missed); }
.dots i.done { background: var(--c); }
.dots i.off { background: transparent; }
.dots i.open { background: transparent; box-shadow: inset 0 0 0 1.5px var(--c); }
.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; align-items: end; height: 56px; margin-top: 14px; }
.bars i { background: var(--c); border-radius: 4px 4px 2px 2px; min-height: 3px; }
.bars i.none { background: var(--missed); }
.caption { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }
.pill { font-size: 12px; font-weight: 600; color: var(--muted); border: 1.5px solid var(--line); border-radius: 99px; padding: 2px 9px; flex: none; }
