/* Ledger — the design system (ADR 0008).
   A tally kept on warm paper: ink-dark text, ruled hairlines, serif
   headings and big serif numerals, one amber accent (a desk lamp), moss
   for on-target and brick for off-target. Light and dark follow the OS.
   System fonts only: no third-party requests. */

:root {
  --paper: #f4efe4;
  --sheet: #fbf8f1;
  --ink: #1d2029;
  --muted: #6d675b;
  --rule: #e1d8c5;
  --accent: #c2741a;
  --accent-ink: #fff9ef;
  --met: #4f7b4a;
  --met-bg: #dde8d4;
  --missed: #b0452f;
  --missed-bg: #f1d9cf;
  --logged: #8b8169;
  --logged-bg: #e8e0cd;
  --empty: #ece5d6;
  --shadow: 0 1px 0 rgba(60, 48, 20, .06), 0 6px 18px -10px rgba(60, 48, 20, .25);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, ui-serif, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #17171a;
    --sheet: #1f1f23;
    --ink: #ece6da;
    --muted: #9d968a;
    --rule: #34343a;
    --accent: #e39b45;
    --accent-ink: #1a1306;
    --met: #8fbf86;
    --met-bg: #2a3a28;
    --missed: #e5806a;
    --missed-bg: #45261f;
    --logged: #b3a98f;
    --logged-bg: #3a362c;
    --empty: #2a2a2f;
    --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 8px 20px -12px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.5 var(--sans);
  min-height: 100vh; display: flex; flex-direction: column;
}
main { width: 100%; max-width: 980px; margin: 0 auto; padding: 8px 20px 40px; flex: 1; }
a { color: inherit; text-decoration-color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--accent); }
h1, h2 { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; line-height: 1.15; }
h1 { font-size: 2rem; margin: .6em 0 .4em; }
h2 { font-size: 1.25rem; margin: 0 0 .5em; }
p { margin: .5em 0; }
.muted, .hint { color: var(--muted); }
.hint { font-size: .9rem; }
.small { font-size: .85rem; }
.icon { width: 1.1em; height: 1.1em; vertical-align: -.18em; flex: none; }

/* top bar */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  max-width: 980px; width: 100%; margin: 0 auto; padding: 14px 20px;
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-family: var(--serif); font-size: 1.3rem; font-weight: 600; }
.mark { width: 28px; height: 28px; }
.top nav { display: flex; gap: 18px; align-items: center; }
.top nav a { text-decoration: none; color: var(--muted); }
.top nav a[aria-current] { color: var(--ink); box-shadow: inset 0 -2px var(--accent); }
.top nav a.btn { color: var(--accent-ink); }

.foot { max-width: 980px; width: 100%; margin: 0 auto; padding: 18px 20px 28px; border-top: 1px solid var(--rule); color: var(--muted); font-size: .85rem; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.foot form { display: flex; gap: 8px; align-items: baseline; }
.stamp { margin: 0; font-size: .75rem; opacity: .8; font-variant-numeric: tabular-nums; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 999px;
  padding: 10px 20px; font: 600 1rem var(--sans); text-decoration: none; cursor: pointer;
}
.btn:hover { filter: brightness(1.06); color: var(--accent-ink); }
.btn.small { padding: 6px 14px; font-size: .9rem; }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--rule); }
.btn.ghost:hover { box-shadow: inset 0 0 0 1.5px var(--accent); color: var(--ink); }
.btn.danger { background: var(--missed); color: #fff; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); text-decoration: underline; text-decoration-color: var(--rule); cursor: pointer; }
button.link:hover { color: var(--accent); }
button:disabled { opacity: .35; cursor: default; }

/* surfaces */
.card { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); margin: 0 0 18px; }
.narrow { max-width: 520px; margin-left: auto; margin-right: auto; }
.pagehead { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.pagehead h1 { margin-bottom: .3em; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.notice { background: var(--met-bg); color: var(--ink); border-radius: var(--radius); padding: 10px 14px; }
.error { color: var(--missed); font-weight: 500; }
p.error[role=alert] { background: var(--missed-bg); padding: 8px 12px; border-radius: 8px; color: var(--ink); }
.banner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--sheet); border: 1px dashed var(--accent); border-radius: var(--radius); padding: 10px 16px; margin: 0 0 18px; }
.banner[hidden] { display: none; }
.pushmsg { color: var(--muted); font-size: .9rem; }

/* forms */
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.grow { flex: 1 1 200px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }
label.check, label.choice { display: block; color: var(--ink); font-size: 1rem; line-height: 1.9; }
label.check input, label.choice input { vertical-align: -.15em; margin: 0 6px 0 0; }
label.choice { padding: 2px 0 2px 28px; text-indent: -28px; line-height: 1.5; }
input, select {
  font: 1rem var(--sans); color: var(--ink); background: var(--paper);
  border: 1.5px solid var(--rule); border-radius: 8px; padding: 9px 11px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 1.1em; height: 1.1em; }
label.check select { padding: 4px 8px; }
fieldset { border: 0; border-top: 1px solid var(--rule); margin: 6px 0 0; padding: 12px 0 0; display: flex; flex-direction: column; gap: 10px; }
legend { font-family: var(--serif); font-weight: 600; font-size: 1.1rem; padding-right: 10px; }
.habitform:has(input[name=goal][value=""]:checked) .plan-fields { display: none; }
.habitform:not(:has(input[name=taper]:checked)) .taper-fields { display: none; }
.taper-fields { padding-left: 26px; border-left: 2px solid var(--rule); }
details.danger { margin-top: 24px; }
details.danger summary { cursor: pointer; color: var(--missed); }
.aside { text-align: center; color: var(--muted); }

/* landing */
.hero { max-width: 640px; margin: 40px auto 30px; }
.hero h1 { font-size: 3rem; }
.lede { font-size: 1.15rem; }
.how { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 18px; margin: 30px 0; }
.how div { border-top: 3px solid var(--accent); padding-top: 10px; }

/* today */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 18px; }
.habit { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); padding: 16px 18px 12px; box-shadow: var(--shadow); border-top: 4px solid var(--rule); scroll-margin-top: 16px; }
.habit.met { border-top-color: var(--met); }
.habit.missed { border-top-color: var(--missed); }
.habit.open { border-top-color: var(--accent); }
.habit header { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.habit h2 { margin: 0; }
.habit h2 a { text-decoration: none; }
.target { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.habit.met .target { color: var(--met); }
.habit.missed .target { color: var(--missed); font-weight: 600; }
.count { display: grid; grid-template-columns: 52px 1fr 52px; align-items: center; gap: 8px; margin: 14px 0 12px; }
.round { width: 52px; height: 52px; border-radius: 50%; border: 1.5px solid var(--rule); background: var(--paper); color: var(--ink); display: grid; place-items: center; cursor: pointer; }
.round .icon { width: 22px; height: 22px; }
.round.plus { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.round:not(:disabled):active { transform: scale(.94); }
.value { display: flex; flex-direction: column; align-items: center; text-decoration: none; min-height: 88px; justify-content: center; }
.num { font-family: var(--serif); font-size: 3.2rem; line-height: 1; font-variant-numeric: tabular-nums lining-nums; }
.num.none { color: var(--rule); }
.unit { color: var(--muted); font-size: .85rem; }
.tally { display: flex; gap: 6px; margin-top: 6px; color: var(--ink); }
.tg { width: 30px; height: 26px; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; fill: none; }
.tg .slash { stroke: var(--accent); }
.habit.missed .tg .slash { stroke: var(--missed); }
.habit footer { display: flex; gap: 14px; align-items: center; color: var(--muted); font-size: .85rem; margin-top: 10px; }
.habit footer a { margin-left: auto; }
.empty { text-align: center; padding: 36px; }

/* day squares, shared by the strip, the month and the legend */
.strip { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 3px; }
.strip li { min-width: 0; }
.strip .sq { width: 100%; }
.sq { display: grid; place-items: center; aspect-ratio: 1; border-radius: 4px; background: var(--empty); color: transparent; font-size: .65rem; text-decoration: none; }
.sq.met { background: var(--met); }
.sq.missed { background: var(--missed); }
.sq.logged { background: var(--logged); }
.strip li:last-child .sq { outline: 1.5px solid var(--ink); outline-offset: 1px; }
.strip a:hover span, .strip a:focus span { color: var(--paper); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; color: var(--muted); font-size: .85rem; }
.legend .sq { display: inline-block; width: 12px; height: 12px; vertical-align: -1px; margin-right: 4px; }

/* habit page */
.plan { color: var(--muted); margin-top: 0; }
.month header { display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; text-align: center; }
.month header h2 { margin: 0; }
.month header a { display: grid; place-items: center; height: 36px; border-radius: 50%; }
.month table { width: 100%; border-collapse: separate; border-spacing: 4px; table-layout: fixed; margin-top: 8px; }
.month th { font-weight: 500; color: var(--muted); font-size: .8rem; }
.month td { background: var(--empty); border-radius: 6px; height: 66px; vertical-align: top; padding: 0; }
.month td > a, .month td > span { display: flex; flex-direction: column; height: 100%; padding: 4px 6px; text-decoration: none; }
.month td .d { font-size: .75rem; color: var(--muted); }
.month td .v { font-family: var(--serif); font-size: 1.4rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.month td .t { font-size: .7rem; color: var(--muted); margin-top: auto; white-space: nowrap; overflow: hidden; }
.month td.met { background: var(--met-bg); }
.month td.met .v { color: var(--met); }
.month td.missed { background: var(--missed-bg); }
.month td.missed .v { color: var(--missed); }
.month td.logged { background: var(--logged-bg); }
.month td.future { background: transparent; box-shadow: inset 0 0 0 1px var(--rule); }
.month td.out { opacity: .4; }
.month td.today { box-shadow: inset 0 0 0 2px var(--accent); }
.month td > a:hover { background: rgba(194, 116, 26, .08); border-radius: 6px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 0 0 18px; }
.stats div { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px 14px; }
.stats dt { color: var(--muted); font-size: .85rem; }
.stats dd { margin: 2px 0 0; font-family: var(--serif); font-size: 1.6rem; font-variant-numeric: tabular-nums; }

/* log page */
.daynav { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; text-align: center; }
.daynav h1 { margin: 0; }
.daynav p { margin: 0; color: var(--muted); }
.daynav a { display: grid; place-items: center; height: 44px; }
.target.big { text-align: center; font-size: 1.1rem; }
.bignum { align-items: center; text-align: center; }
.bignum input { font-family: var(--serif); font-size: 3rem; width: 7ch; text-align: center; padding: 6px; }
.logday .btn { align-self: center; padding-left: 40px; padding-right: 40px; }
.clear { text-align: center; margin-top: 12px; }

/* settings */
.devices { list-style: none; padding: 0; margin: 12px 0; }
.devices li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--rule); align-items: baseline; }
.card h2 .icon { color: var(--accent); }

@media (max-width: 520px) {
  main { padding: 4px 14px 32px; }
  h1 { font-size: 1.6rem; }
  .hero h1 { font-size: 2.3rem; }
  .card { padding: 16px; }
  .month table { border-spacing: 2px; }
  .month td { height: 52px; }
  .month td .t { display: none; }
  .month td .v { font-size: 1.1rem; }
}

/* this device, in the settings device list */
.devices li.here { background: var(--met-bg); margin: 0 -10px; padding-left: 10px; padding-right: 10px; border-radius: 8px; }
.devices .actions { gap: 14px; flex-wrap: nowrap; }
.thisdevice p[hidden], [data-push-enable][hidden] { display: none; }
