:root {
  --bg: #14161c;
  --surface: #1c1f27;
  --surface-2: #232732;
  --line: #2f3440;
  --text: #e8eaf0;
  --muted: #9aa1b1;
  --accent: #6c8cff;
  --ok: #46c08a;
  --danger: #ff5f6d;
  --glow-rgb: 255, 72, 88;
  --radius: 12px;
  --gap: 14px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f8;
    --surface: #ffffff;
    --surface-2: #f0f2f6;
    --line: #dfe3ea;
    --text: #1b1e25;
    --muted: #666e7e;
    --accent: #3b5bdb;
    --ok: #2f9e6b;
    --danger: #d9364a;
    --glow-rgb: 226, 45, 62;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  /* Installed on iOS the status bar is translucent, so the page would otherwise
     run underneath it. The insets are zero everywhere else. */
  padding:
    env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 64px;
}

h1 { font-size: 1.4rem; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 24px 0 8px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

/* --- top bar --- */
.bar {
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
.bar nav { display: flex; gap: 12px; margin-right: auto; }
.bar nav a { color: var(--muted); font-size: 0.92rem; }
.bar nav a.on { color: var(--text); font-weight: 600; }
.who { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; }
.who a { color: var(--muted); }

/* --- forms --- */
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; }
label > span { color: var(--muted); }
label em { font-style: normal; opacity: 0.7; }

input, select, textarea, button {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

button { cursor: pointer; width: auto; }
button.primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
  padding: 10px 18px;
}
button.link {
  background: none;
  border: none;
  padding: 2px 4px;
  color: var(--muted);
  width: auto;
}
button.link.danger:hover { color: var(--danger); }
.button {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.button.ghost { color: var(--muted); }

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}
.grid .wide { grid-column: 1 / -1; }
@media (max-width: 460px) {
  .grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.card.narrow { max-width: 380px; margin: 40px auto; display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; }

.composer {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
}
.composer summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.composer[open] summary { margin-bottom: 14px; }

.filters { display: flex; gap: 12px; align-items: flex-end; margin: 14px 0; flex-wrap: wrap; }
.filters label { flex: 1 1 140px; }

/* --- flashes --- */
.flashes { margin: 12px 0; display: flex; flex-direction: column; gap: 6px; }
.flash { margin: 0; padding: 9px 12px; border-radius: 8px; font-size: 0.9rem; }
.flash.error { background: rgba(255, 95, 109, 0.14); color: var(--danger); }
.flash.ok { background: rgba(70, 192, 138, 0.14); color: var(--ok); }

/* --- toolbar / toggle --- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.toggle { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.toggle a { padding: 6px 14px; border-radius: 999px; color: var(--muted); font-size: 0.88rem; }
.toggle a:hover { text-decoration: none; }
.toggle a.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,0.25); }

/* --- item list --- */
.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}

/* Overdue glow. --glow runs 0..1, set per item from days overdue x urgency.
   Both the halo and the border ramp with it, so a mildly late low-urgency item
   is a faint blush while a very late urgent one is unmistakable. */
.item.overdue {
  border-color: rgba(var(--glow-rgb), calc(0.25 + var(--glow) * 0.75));
  box-shadow:
    0 0 calc(var(--glow) * 22px) rgba(var(--glow-rgb), calc(var(--glow) * 0.55)),
    inset 0 0 calc(var(--glow) * 40px) rgba(var(--glow-rgb), calc(var(--glow) * 0.10));
}
.item.overdue[style*="--glow: 1"] { animation: pulse 2.4s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 18px rgba(var(--glow-rgb), 0.45), inset 0 0 40px rgba(var(--glow-rgb), 0.10); }
  50%      { box-shadow: 0 0 34px rgba(var(--glow-rgb), 0.75), inset 0 0 40px rgba(var(--glow-rgb), 0.16); }
}
@media (prefers-reduced-motion: reduce) {
  .item.overdue[style*="--glow: 1"] { animation: none; }
}

.tick { flex: 0 0 auto; }
.tick button {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  display: grid;
  place-items: center;
}
.tick button:hover { background: var(--ok); border-color: transparent; color: #fff; }

.item .body { flex: 1 1 auto; min-width: 0; }
.line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.title { font-weight: 600; }
.notes { margin: 6px 0 0; font-size: 0.88rem; color: var(--muted); white-space: pre-wrap; }

.meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 0.82rem; color: var(--muted); margin-top: 3px; }
.due.late { color: var(--danger); font-weight: 600; }
.urgency { letter-spacing: 1px; color: var(--danger); font-size: 0.6rem; }
.urgency i { opacity: 0.22; font-style: normal; }
.reward { font-variant-numeric: tabular-nums; }

.tag { padding: 1px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 0.75rem; }
.tag.repeat { color: var(--accent); }

.actions { flex: 0 0 auto; display: flex; align-items: center; gap: 2px; }
.actions a { color: var(--muted); padding: 2px 6px; }
.actions a:hover { color: var(--text); text-decoration: none; }
.actions form { display: inline; }

.done-block { margin-top: 24px; }
.done-block summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
.items.done { margin-top: 12px; opacity: 0.72; }
.items.done .title { font-weight: 500; text-decoration: line-through; text-decoration-color: var(--muted); }

/* --- history --- */
.trail { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.trail li {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
}
.trail li:nth-child(odd) { background: var(--surface); }
.action {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--muted);
  flex: 0 0 auto;
}
.action.completed { background: rgba(70, 192, 138, 0.18); color: var(--ok); }
.action.created { background: rgba(108, 140, 255, 0.18); color: var(--accent); }
.action.deleted, .action.uncompleted { background: rgba(255, 95, 109, 0.16); color: var(--danger); }
.what { font-weight: 600; }
.by { color: var(--muted); }
.when { color: var(--muted); margin-left: auto; font-variant-numeric: tabular-nums; font-size: 0.8rem; }
.diff { flex-basis: 100%; color: var(--muted); font-size: 0.8rem; }
.pts { color: var(--ok); font-weight: 600; font-size: 0.8rem; }
.pts.minus { color: var(--danger); }

/* --- audit --- */
.board { list-style: none; margin: 18px 0; padding: 0; display: flex; flex-direction: column; gap: 18px; }
.board .name { font-weight: 600; margin-bottom: 6px; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--ok)); border-radius: 999px; }
.figures { margin-top: 6px; font-size: 0.88rem; }
