/* Hábitos — design rules
   1. Colour always means something: chrome is ink-on-paper; red→green is only
      performance (tiers); each habit's own colour is only identity.
   2. One loud thing per screen: on Hoy it is the day's tira, which fills with
      each habit's colour as it gets done.
   3. Rounded, friendly type (SF Pro Rounded on Apple devices) — it's for a family. */

:root {
  --bg: #f2f3f7;
  --card: #ffffff;
  --ink: #20233f;
  --muted: #666a82;
  --line: #dcdfe9;
  --soft: #e8eaf1;
  --accent: #2c3070;
  --on-accent: #ffffff;
  --danger: #c92a2a;
  --t0: #e03131; --t1: #f76707; --t2: #e8a800; --t3: #2f9e44;
  --radius: 18px;
  --tabs-h: 64px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161829;
    --card: #20233a;
    --ink: #eceef8;
    --muted: #9da1ba;
    --line: #313554;
    --soft: #2a2d47;
    --accent: #dfe1ff;
    --on-accent: #1d2050;
    --danger: #ff6b6b;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
body.authed main { padding-bottom: calc(var(--tabs-h) + 28px + env(safe-area-inset-bottom)); }
main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 16px 32px;
}
a { color: inherit; }
h1 { font-size: 1.75rem; line-height: 1.15; margin: 0; font-weight: 800; letter-spacing: -0.02em; }
h1::first-letter { text-transform: uppercase; }
h2 { font-size: 1.15rem; line-height: 1.25; margin: 0 0 10px; font-weight: 750; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.sub { color: var(--muted); margin: 4px 0 0; font-size: 0.95rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

.top { margin: 10px 0 20px; }
.top.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.crumb { margin: 6px 0 0; font-size: 0.95rem; }
.crumb a { color: var(--muted); text-decoration: none; display: inline-block; padding: 6px 0; }
h2.section { margin: 30px 0 10px; font-size: 1rem; color: var(--muted); }
.hint { margin: 14px 0 8px; font-weight: 400; color: var(--muted); font-size: 0.9rem; }
.hint.center { font-size: 0.82rem; }

/* ---- buttons & forms ---- */
button, .button {
  font: inherit;
  font-weight: 650;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 14px;
  padding: 12px 18px;
  min-height: 48px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }
.small { min-height: 42px; padding: 8px 14px; font-size: 0.95rem; }
.link { border: 0; background: none; color: var(--muted); text-decoration: underline; min-height: 44px; font-weight: 500; }
.danger { color: var(--danger); }
button:disabled { opacity: 0.3; cursor: default; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }
input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

.stack { display: flex; flex-direction: column; gap: 18px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 650; font-size: 0.95rem; }
input[type=text], input:not([type]), input[type=password] {
  font: inherit;
  font-weight: 400;
  font-size: 17px; /* ≥16px stops iOS zooming in */
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  width: 100%;
}
.row-fields { display: flex; gap: 12px; }
.emoji-field { width: 84px; flex: none; }
.emoji-field input { text-align: center; font-size: 22px; padding: 9px 6px; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 650; font-size: 0.95rem; margin-bottom: 8px; }
.error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); padding: 10px 14px; border-radius: 14px; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch input { position: absolute; opacity: 0; }
.swatch::before {
  content: ""; display: block; width: 40px; height: 40px; border-radius: 50%;
  background: var(--c); box-shadow: 0 0 0 3px var(--bg);
}
.swatch:has(input:checked)::before { box-shadow: 0 0 0 3px var(--bg), 0 0 0 6px var(--c); }

.daypick { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.daypick input { position: absolute; opacity: 0; }
.daypick span {
  display: flex; align-items: center; justify-content: center; height: 46px;
  border-radius: 14px; border: 1px solid var(--line); background: var(--card); font-weight: 700;
}
.daypick input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg input, .when-weekly input { position: absolute; opacity: 0; }
.seg span, .seg a {
  display: flex; align-items: center; justify-content: center; text-align: center; min-height: 46px; padding: 4px 6px;
  border-radius: 14px; border: 1px solid var(--line); background: var(--card); font-size: 0.92rem; line-height: 1.2;
  font-weight: 650; text-decoration: none;
}
.seg input:checked + span, .seg a[aria-current] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.seg-2 { grid-template-columns: 1fr 1fr; }
.when-weekly .daypick { grid-template-columns: repeat(6, 1fr); }
.when-weekly input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.freq-pick:has(input[value=daily]:checked) .when-days,
.freq-pick:has(input[value=daily]:checked) .when-weekly,
.freq-pick:has(input[value=days]:checked) .when-weekly,
.freq-pick:has(input[value=weekly]:checked) .when-days { display: none; }

/* ---- login ---- */
.login { max-width: 360px; margin: 12vh auto 0; text-align: center; }
.login form { text-align: left; margin-top: 28px; }
.logo {
  width: 76px; height: 76px; margin: 0 auto 16px; border-radius: 24px;
  background: var(--accent); color: var(--on-accent); font-size: 40px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.login h1 { font-size: 2.1rem; }

/* ---- completion tiers ---- */
.t0 { --t: var(--t0); --t-ink: #b42020; }
.t1 { --t: var(--t1); --t-ink: #b8480a; }
.t2 { --t: var(--t2); --t-ink: #8a6400; }
.t3 { --t: var(--t3); --t-ink: #23782f; }
.none { --t: var(--line); --t-ink: var(--muted); }
@media (prefers-color-scheme: dark) {
  .t0 { --t-ink: #ff8787; } .t1 { --t-ink: #ffa94d; } .t2 { --t-ink: #ffd43b; } .t3 { --t-ink: #69db7c; }
}
.rate {
  font-size: 0.8rem; font-weight: 750; padding: 1px 8px; border-radius: 999px; white-space: nowrap;
  color: var(--t-ink); background: color-mix(in srgb, var(--t) 16%, transparent);
}
.rate:empty, .rate.none { display: none; }
.rate.big {
  display: inline-block; font-size: 0.95rem; padding: 5px 10px; min-width: 56px; text-align: center;
  color: #fff; background: var(--t);
}
.rate.big.t2 { color: #3a2a00; }
.rate.big.none { display: inline-block; background: var(--soft); color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--t); }
.tiers { display: flex; gap: 6px 14px; justify-content: center; flex-wrap: wrap; font-size: 0.8rem; margin-top: 22px; color: var(--muted); }
.tiers span { display: inline-flex; align-items: center; gap: 5px; }
.trend { font-size: 0.85rem; font-weight: 750; white-space: nowrap; }
.trend.up { color: var(--t3); }
.trend.down { color: var(--t0); }

/* ---- week strip ---- */
.week { display: grid; grid-template-columns: 28px repeat(7, 1fr) 28px; gap: 4px; align-items: center; margin-bottom: 14px; }
.wk-nav { text-align: center; font-size: 1.6rem; text-decoration: none; color: var(--muted); line-height: 1; padding: 8px 0; }
.pill {
  position: relative; display: flex; flex-direction: column; align-items: center;
  padding: 6px 0 12px; border-radius: 14px; text-decoration: none;
}
.pill small { color: var(--muted); font-size: 0.75rem; font-weight: 650; }
.pill b { font-size: 1.05rem; }
.pill.future { opacity: 0.35; }
.pill.today b { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.pill.sel { background: var(--accent); color: var(--on-accent); }
.pill.sel small { color: inherit; opacity: 0.75; }
.ring {
  position: absolute; bottom: 5px; left: 50%; width: 22px; height: 4px; transform: translateX(-50%);
  border-radius: 2px; background: linear-gradient(90deg, var(--t3) calc(var(--p) * 1%), color-mix(in srgb, currentColor 18%, transparent) 0);
}

/* ---- today: heading + tira ---- */
.day-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 6px 0 14px; }
.day-head h1 { font-size: 2.2rem; line-height: 1.05; }
.day-head .wd { display: block; }
.day-head .dm { display: block; font-size: 1.05rem; font-weight: 600; color: var(--muted); letter-spacing: 0; margin-top: 4px; }
.back { font-size: 0.95rem; font-weight: 650; color: var(--accent); text-decoration: none; padding: 8px 0; white-space: nowrap; }

.tally { display: flex; align-items: center; gap: 14px; margin: 0 0 16px; }
.tally p { margin: 0; white-space: nowrap; color: var(--muted); font-weight: 600; }
.tally p b { color: var(--ink); font-size: 1.15rem; }
.tally .all { display: none; color: var(--t3); }
.tally.full .all { display: inline; }
.tira { flex: 1; display: flex; gap: 4px; height: 12px; }
.tira i { flex: 1; border-radius: 999px; background: var(--soft); transition: background 0.25s; }
.tira i.on { background: var(--c); }
.tira i.on.just { animation: pop 0.35s ease-out; } /* only right after a tap, not on page load */
.tira.thin { height: 6px; gap: 3px; margin: 6px 0 12px; }
@keyframes pop { 40% { transform: scaleY(1.6); } }

/* ---- habit toggles ---- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.habit {
  width: 100%; min-height: 74px; justify-content: flex-start; gap: 14px; text-align: left; font-weight: 400;
  padding: 12px 14px 12px 12px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--card); transition: background 0.2s, border-color 0.2s, transform 0.08s;
}
.habit:active { transform: scale(0.98); }
.habit .emoji {
  flex: none; width: 46px; height: 46px; border-radius: 14px; font-size: 24px;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--c) 16%, transparent);
}
.habit .body { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.habit .name { font-weight: 700; line-height: 1.25; }
.habit .meta { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; font-size: 0.85rem; color: var(--muted); }
.habit .meta:not(:has(.wk)):not(:has(.flag)):has(.rate:empty):has(.streak[hidden]) { display: none; }
.habit .streak { white-space: nowrap; }
.habit .flag { color: var(--t-ink, #b8480a); font-weight: 700; }
.habit .rate.t0 ~ .flag { --t-ink: #b42020; }
@media (prefers-color-scheme: dark) { .habit .flag { color: #ffa94d; } .habit .rate.t0 ~ .flag { color: #ff8787; } }
.habit .check {
  flex: none; width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--line);
  display: flex; align-items: center; justify-content: center; transition: background 0.2s, border-color 0.2s;
}
.habit .check svg { width: 22px; height: 22px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 20; stroke-dashoffset: 20; }
.habit.done { background: color-mix(in srgb, var(--c) 12%, var(--card)); border-color: color-mix(in srgb, var(--c) 40%, transparent); }
.habit.done .check { background: var(--c); border-color: var(--c); }
.habit.done .check svg { stroke-dashoffset: 0; transition: stroke-dashoffset 0.3s ease-out 0.05s; }
.habit.done .name { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--ink) 35%, transparent); }
.habit.done .flag { display: none; }
.habit.busy { opacity: 0.6; }
.habit .wk b { color: var(--ink); }
.habit.met:not(.done) { border-color: color-mix(in srgb, var(--c) 40%, transparent); }
.habit.met .wk b { color: var(--t3); }

.others { margin-top: 26px; }
.others summary { color: var(--muted); cursor: pointer; padding: 10px 0; margin-bottom: 8px; font-weight: 650; }
.empty { text-align: center; padding: 40px 12px; }
.empty p { color: var(--muted); max-width: 34ch; margin: 0 auto 18px; }

/* ---- family ---- */
.member { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.member-head { display: flex; align-items: center; gap: 12px; }
.member-head h2 { margin: 0; flex: 1; }
.avatar {
  flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: var(--on-accent);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1.1rem;
}
.today-count { margin: 12px 0 0; font-size: 0.9rem; color: var(--muted); }
.today-count b { color: var(--ink); }
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 5px 11px; border-radius: 999px; border: 1px dashed var(--line); font-size: 0.9rem; color: var(--muted); }
.chip.done { border: 1px solid transparent; background: color-mix(in srgb, var(--c) 16%, transparent); color: var(--ink); }
.focus-line { margin: 12px 0 0; padding-top: 10px; border-top: 1px solid var(--line); font-size: 0.9rem; line-height: 1.7; }

/* ---- habits list ---- */
.focus {
  border-radius: var(--radius); padding: 16px; margin-bottom: 8px;
  background: color-mix(in srgb, var(--t1) 9%, var(--card)); border: 1px solid color-mix(in srgb, var(--t1) 28%, var(--line));
}
.focus h2 { margin: 0; }
.focus .sub { margin: 2px 0 12px; font-size: 0.9rem; }
.focus .list { gap: 8px; }
.focus-row, .summary a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px;
  background: var(--card); text-decoration: none; border: 1px solid var(--line);
}
.focus-row .emoji, .summary .emoji, .manage-main .emoji { font-size: 24px; width: 32px; text-align: center; flex: none; }
.focus-row .name, .summary .name, .manage-main .name { display: block; font-weight: 700; }
.freq { display: block; color: var(--muted); font-size: 0.85rem; margin: 1px 0 0; }

.manage-row {
  display: flex; align-items: center; gap: 8px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 8px 8px 12px;
  box-shadow: inset 5px 0 0 var(--c);
}
.manage-row.archived { opacity: 0.75; }
.manage-main { flex: 1; display: flex; align-items: center; gap: 12px; text-decoration: none; min-height: 54px; min-width: 0; padding-left: 4px; }
.order { display: flex; gap: 4px; }
.icon { min-height: 44px; min-width: 44px; padding: 0; border-radius: 12px; }
.logout, .archive { margin-top: 28px; text-align: center; }

/* ---- habit detail ---- */
.score {
  border-radius: var(--radius); padding: 18px; margin-bottom: 10px;
  background: color-mix(in srgb, var(--t) 13%, var(--card)); border: 1px solid color-mix(in srgb, var(--t) 40%, transparent);
}
.score-main { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.score-main b { font-size: 3rem; line-height: 1; font-weight: 800; letter-spacing: -0.03em; color: var(--t-ink); }
.score-main span { color: var(--muted); font-weight: 600; }
.score-note { margin: 8px 0 0; font-weight: 600; }
.score-note:empty { display: none; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 0 26px; }
.stats div { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 8px; text-align: center; }
.stats dt { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.stats dd { margin: 0; font-size: 1.5rem; font-weight: 800; }
.stats dd small { font-size: 0.8rem; font-weight: 600; color: var(--muted); }

.wdays { margin-bottom: 26px; }
.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; height: 150px; }
.bar { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; min-width: 0; }
.bar i { width: 100%; max-width: 38px; height: calc(var(--h) * 0.9%); min-height: 4px; border-radius: 8px 8px 4px 4px; background: var(--t); }
.bar .val { font-size: 0.78rem; font-weight: 700; color: var(--muted); }
.bar small { font-size: 0.8rem; font-weight: 700; color: var(--muted); }
.bar.worst small, .bar.worst .val { color: var(--t-ink); }
.bar.none i { background: var(--soft); }

.heat-wrap { display: grid; grid-template-columns: auto 1fr; gap: 6px; }
.heat-labels { display: grid; grid-template-rows: repeat(7, 1fr); gap: 3px; font-size: 0.7rem; color: var(--muted); }
.heat-labels i { font-style: normal; display: flex; align-items: center; }
.heat { display: grid; grid-template-rows: repeat(7, 1fr); grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; }
.heat a { aspect-ratio: 1; border-radius: 4px; background: var(--soft); display: block; }
.heat .done { background: var(--c); }
.heat .miss { background: color-mix(in srgb, var(--c) 18%, var(--soft)); }
.heat .pending { box-shadow: inset 0 0 0 2px var(--c); }
.heat .off { background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.heat .future { background: transparent; }
.legend { grid-column: 2; font-size: 0.8rem; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 6px 0 0; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; background: var(--soft); }
.legend i.done { background: var(--c); }
.legend i.miss { background: color-mix(in srgb, var(--c) 18%, var(--soft)); }
.legend i.off { background: transparent; box-shadow: inset 0 0 0 1px var(--line); }

/* ---- calendar ---- */
.cal-bar { display: grid; grid-template-columns: 36px 1fr 36px; align-items: center; gap: 8px; margin-bottom: 16px; }
.month { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.dow { text-align: center; font-size: 0.75rem; color: var(--muted); font-weight: 700; padding-bottom: 2px; }
.mday {
  aspect-ratio: 1; border-radius: 12px; text-decoration: none; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--card); border: 1px solid var(--line);
}
.mday b { font-size: 1rem; line-height: 1.1; }
.mday small { font-size: 0.68rem; opacity: 0.85; }
.mday.t0, .mday.t1, .mday.t2, .mday.t3 { background: var(--t); border-color: transparent; color: #fff; }
.mday.t2 { color: #3a2a00; }
.mday.none { color: var(--muted); }
.mday.out { opacity: 0.35; }
.mday.future { background: transparent; border-style: dashed; color: var(--muted); opacity: 0.5; }
.mday.today { outline: 3px solid var(--ink); outline-offset: 1px; }
.summary .frac { font-size: 0.85rem; }

.wgrid { display: flex; flex-direction: column; gap: 8px; }
.wrow { display: block; text-decoration: none; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 8px 10px; }
.whead { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; background: none; border: 0; padding: 0 10px; }
.whead > span { display: none; }
.wday { display: flex; flex-direction: column; align-items: center; padding: 4px 0; border-radius: 10px; text-decoration: none; border-bottom: 4px solid var(--t); }
.wday small { color: var(--muted); font-size: 0.72rem; font-weight: 650; }
.wday.today b { text-decoration: underline; text-underline-offset: 3px; }
.wname { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 0.95rem; margin-bottom: 6px; }
.wname .rate { margin-left: auto; }
.wcells { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.wcells i { height: 26px; border-radius: 7px; background: var(--soft); }
.wcells .done { background: var(--c); }
.wcells .miss { background: color-mix(in srgb, var(--c) 18%, var(--soft)); }
.wcells .pending { box-shadow: inset 0 0 0 2px var(--c); background: transparent; }
.wcells .off { background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.wcells .future { background: transparent; }
.wgrid + .legend { --c: var(--accent); margin: 10px 0 0; justify-content: center; }

/* ---- bottom tabs ---- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; max-width: 160px; height: var(--tabs-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--muted); font-size: 0.75rem; font-weight: 650;
}
.tabs svg {
  width: 52px; height: 30px; padding: 3px 14px; border-radius: 999px;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.tabs a[aria-current] { color: var(--ink); font-weight: 750; }
.tabs a[aria-current] svg { background: color-mix(in srgb, var(--accent) 14%, transparent); stroke-width: 2.2; }

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