:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --line: #e4e2dc;
  --accent: #2f6f5e;
  --accent-soft: #e2efe9;
  --warn: #b4561f;
  --warn-soft: #fbe9dd;
  --done: #8e8e93;
  --danger: #c0392b;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151517;
    --surface: #1f1f22;
    --text: #f2f2f4;
    --muted: #9b9ba1;
    --line: #2e2e33;
    --accent: #6cc4a8;
    --accent-soft: #1f3530;
    --warn: #f0a070;
    --warn-soft: #3a261b;
    --done: #6e6e73;
    --danger: #ff6b5b;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }

.screen {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 96px);
}

/* Login */
#login { display: grid; place-items: center; min-height: 100vh; padding-bottom: 0; }
.login-card { width: 100%; max-width: 320px; display: grid; gap: 12px; text-align: center; justify-items: center; }
.login-card img { border-radius: 14px; }
.login-card h1 { margin: 4px 0 8px; font-size: 24px; }
.login-card input { width: 100%; }

/* Header */
.top { display: flex; align-items: center; gap: 4px; padding: 8px 0 12px; }
.day { flex: 1; text-align: center; }
.day-label { font-size: 20px; font-weight: 700; }
.icon-btn {
  width: 44px; height: 44px; border: 0; background: transparent; border-radius: 22px;
  font-size: 28px; line-height: 1; display: grid; place-items: center; color: var(--muted);
}
.icon-btn:active { background: var(--line); }

.summary { color: var(--muted); font-size: 14px; margin: 0 4px 12px; }
.summary .bar { height: 6px; background: var(--line); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.summary .bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }

/* Banner */
.banner {
  background: var(--accent-soft); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; font-size: 15px;
}
.banner button { margin-top: 8px; }

/* Task list */
.tasks { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.task {
  background: var(--surface); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow);
  border: 1px solid var(--line); display: grid; grid-template-columns: 78px 1fr; gap: 4px 12px;
  scroll-margin: 80px;
}
.task.highlight { outline: 2px solid var(--accent); }

.task .time { white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 15px; padding-top: 1px; }
.task .time small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.task .body { min-width: 0; }
.task .title { font-weight: 600; font-size: 17px; overflow-wrap: anywhere; }
.task .meta { color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; margin-top: 2px; }
.task .notes { color: var(--muted); font-size: 14px; margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.pill { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: var(--line); color: var(--muted); }
.pill.active { background: var(--accent-soft); color: var(--accent); }
.pill.overdue { background: var(--warn-soft); color: var(--warn); }
.progress { grid-column: 2; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; margin-top: 6px; }
.progress > i { display: block; height: 100%; background: var(--accent); }
.task.overdue .progress > i { background: var(--warn); }
.actions { grid-column: 2; display: flex; gap: 8px; margin-top: 8px; }
.actions button { border: 1px solid var(--line); background: transparent; border-radius: 10px; padding: 7px 12px; font-size: 14px; font-weight: 500; }
.actions .done-btn { background: var(--accent); color: #fff; border-color: var(--accent); }
@media (prefers-color-scheme: dark) { .actions .done-btn { color: #0d1f1a; } }
.task.done, .task.skipped { opacity: .6; }
.task.done .title { text-decoration: line-through; text-decoration-color: var(--done); }

.empty { text-align: center; color: var(--muted); padding: 48px 0; }

.fab {
  position: fixed; right: max(16px, calc(50% - 320px + 16px)); bottom: calc(env(safe-area-inset-bottom) + 20px);
  width: 58px; height: 58px; border-radius: 29px; border: 0; background: var(--accent); color: #fff;
  font-size: 32px; line-height: 1; box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
@media (prefers-color-scheme: dark) { .fab { color: #0d1f1a; } }

/* Buttons and inputs */
.primary, .secondary, .danger {
  width: 100%; border-radius: 12px; padding: 12px 16px; font-weight: 600; border: 0;
}
.primary { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .primary { color: #0d1f1a; } }
.secondary { background: var(--line); }
.danger { background: transparent; color: var(--danger); margin-top: 8px; }
.link { background: none; border: 0; color: var(--accent); padding: 4px; font-size: 15px; }
.link.strong { font-weight: 700; }
input, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 11px 12px; font-size: 16px; /* 16px stops iOS zooming on focus */
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.error { color: var(--danger); font-size: 14px; min-height: 1em; margin: 4px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; display: block; margin-top: 6px; }

/* Sheets */
dialog.sheet {
  width: 100%; max-width: 640px; margin: auto auto 0; border: 0; padding: 0;
  background: var(--bg); color: var(--text); border-radius: 16px 16px 0 0;
  max-height: 92vh; overflow: auto;
}
dialog.sheet::backdrop { background: rgba(0,0,0,.35); }
dialog.sheet form, .settings-body { padding: 0 16px calc(env(safe-area-inset-bottom) + 20px); }
.sheet-head {
  position: sticky; top: 0; background: var(--bg); display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: center; padding: 12px 0; margin: 0 0 4px; z-index: 1;
}
.settings .sheet-head, #settings .sheet-head { padding: 12px 16px; }
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-head > :first-child { justify-self: start; }
.sheet-head > :last-child { justify-self: end; }
.field { display: block; margin: 0 0 12px; border: 0; padding: 0; min-width: 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 4px 2px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 12px; }
.chips.days { margin: 0 0 8px; }
.chips button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 16px; padding: 6px 11px; font-size: 14px;
}
.chips button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
@media (prefers-color-scheme: dark) { .chips button.on { color: #0d1f1a; } }
.settings-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 8px; }
.settings-body button { margin-bottom: 8px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 92px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 20px; font-size: 14px;
  max-width: calc(100% - 32px); text-align: center; z-index: 10;
}
