:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c2129;
  --muted: #646d7a;
  --border: #dde1e7;
  --accent: #4b44c9;
  --accent-text: #ffffff;
  --good: #1a7a4f;
  --bad: #c0392b;
  --field: #ffffff;
  /* Priority: low, medium, high */
  --p1: #2a78d6;
  --p2: #d98a00;
  --p3: #d1344b;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151a;
    --card: #1b2028;
    --text: #e8ecf2;
    --muted: #99a3b1;
    --border: #2d3440;
    --accent: #9a95f5;
    --accent-text: #120f33;
    --good: #4fce94;
    --bad: #ff7b6b;
    --field: #141920;
    --p1: #5b9cf0;
    --p2: #f0a92e;
    --p3: #ff6b7f;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%; }
.wrap { max-width: 640px; margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom)); }
.wrap.wide { max-width: 980px; }
a { color: var(--accent); }
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1rem; margin: 0 0 0.6rem; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.topnav { display: flex; gap: 4px; margin-bottom: 12px; padding: 4px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; }
.topnav a { flex: 1; text-align: center; padding: 8px 4px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-size: 0.9rem; font-weight: 600; }
.topnav a.active { background: var(--accent); color: var(--accent-text); }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; margin-bottom: 12px; }
.card.narrow { margin-top: 10vh; }
.card.narrow h1 { margin-bottom: 0.8rem; }

label { display: block; margin: 0.7rem 0 0.25rem; font-size: 0.85rem; color: var(--muted); }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number],
select, textarea {
  width: 100%; min-height: 44px; padding: 0.5rem 0.65rem; border: 1px solid var(--border);
  border-radius: 10px; background: var(--field); color: var(--text);
  font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */ }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number],
textarea {
  -webkit-appearance: none; appearance: none; }
textarea { resize: vertical; line-height: 1.4; }
input:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; }

button, .button { display: inline-block; min-height: 44px; margin-top: 0.9rem; padding: 0.55rem 1.1rem;
  border: 1px solid var(--border); border-radius: 10px; background: var(--card); color: var(--text);
  font: inherit; font-size: 1rem; font-weight: 600; text-align: center; text-decoration: none;
  cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--bad); }
button:disabled { opacity: 0.5; cursor: default; }
.flush { margin-top: 0; }
.flash { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; font-size: 0.9rem;
  line-height: 1.4; border: 1px solid var(--border); background: var(--card); }
.flash.ok { color: var(--good); }
.flash.error { color: var(--bad); }
form .flash { margin: 12px 0 0; }

.segmented { display: flex; gap: 4px; padding: 4px; margin: 0;
  border: 1px solid var(--border); border-radius: 10px; background: var(--card); }
.segmented label { flex: 1; display: flex; align-items: center; justify-content: center;
  min-height: 40px; margin: 0; padding: 6px 4px; border-radius: 7px; color: var(--muted);
  font-size: 0.9rem; font-weight: 600; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--accent); color: var(--accent-text); }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid2 > div { min-width: 0; }

/* Tasks page */
.viewbar { display: flex; align-items: center; gap: 8px; margin: 4px 0 12px; }
.viewbar select { flex: 1; font-size: 1.15rem; font-weight: 700; }
.icon-button { display: flex; align-items: center; justify-content: center; width: 44px;
  padding: 0; color: var(--muted); }
.group { padding: 0; overflow: hidden; }
.group h2 { margin: 0; padding: 10px 16px 4px; font-size: 0.8rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em; }
.group.overdue h2 { color: var(--bad); }
.tasks { list-style: none; margin: 0; padding: 0 0 4px; }
.tasks li + li { border-top: 1px solid var(--border); }
.task { display: flex; align-items: center; gap: 4px; padding-left: 4px; }
.check { flex: none; display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; min-height: 0; margin: 0; padding: 0; border: 0; background: none;
  color: var(--muted); }
.check svg { width: 24px; height: 24px; }
.check .tick { stroke: var(--card); stroke-width: 2.6; }
.check.p1 { color: var(--p1); }
.check.p2 { color: var(--p2); }
.check.p3 { color: var(--p3); }
.task.is-done .check { color: var(--muted); }
.check.selecting { color: var(--accent); }
.task.is-selected { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.task, .task-open { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.selectbar { display: flex; align-items: center; gap: 8px; margin: 4px 0 12px; padding: 4px 4px 4px 0; }
.selectbar strong { flex: 1; font-size: 1.1rem; }
.selectbar .primary { min-width: 6rem; }
.task-open { flex: 1; min-width: 0; min-height: 0; margin: 0; padding: 10px 16px 10px 4px; border: 0;
  border-radius: 0; background: none; font-weight: normal; text-align: left; }
.task-open:active { background: color-mix(in srgb, var(--text) 8%, transparent); }
@media (hover: hover) {
  .task-open:hover { background: color-mix(in srgb, var(--text) 5%, transparent); }
}
.task-title { display: block; overflow-wrap: anywhere; }
.task.is-done .task-title { color: var(--muted); text-decoration: line-through; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; margin-top: 2px;
  font-size: 0.8rem; color: var(--muted); }
.meta .late { color: var(--bad); font-weight: 600; }
.meta svg { width: 13px; height: 13px; vertical-align: -2px; margin-right: 3px; }
.empty { margin: 0 0 12px; padding: 24px 16px; text-align: center; color: var(--muted); }

.title-input { font-size: 1.15rem !important; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chips.fill { flex-wrap: nowrap; }
.chips.fill .chip { flex: 1; padding: 0.35rem 0.2rem; white-space: nowrap; }
.chip { min-height: 36px; margin: 0; padding: 0.35rem 0.7rem; border-radius: 18px;
  font-size: 0.9rem; font-weight: 600; color: var(--muted); }
.chip[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.due-fields { margin-top: 2px; }
.presets-row { margin-top: 8px; }
.chip.preset { display: inline-flex; align-items: baseline; gap: 5px; }
.chip.preset small { font-weight: normal; opacity: 0.85; }
.with-clear { position: relative; }
.with-clear input { padding-right: 40px; }
.clear { position: absolute; right: 2px; bottom: 2px; width: 40px; min-height: 40px; margin: 0;
  padding: 0; border: 0; background: none; color: var(--muted); font-size: 1.3rem; }
.inline { display: flex; align-items: center; gap: 10px; margin: 0.7rem 0 0.6rem; }
.inline label { margin: 0; font-size: 0.95rem; color: var(--text); }
.inline input { width: 5rem !important; }
.weekdays { display: flex; gap: 4px; margin-bottom: 0.6rem; }
.weekdays button { flex: 1; min-height: 38px; margin: 0; padding: 0; border-radius: 19px;
  font-size: 0.85rem; color: var(--muted); }
.weekdays button[aria-pressed=true] { background: var(--accent); border-color: var(--accent);
  color: var(--accent-text); }
.custom-rule { margin: 0.4rem 0 0; font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }
.priority .p1:has(input:checked) { background: var(--p1); color: #fff; }
.priority .p2:has(input:checked) { background: var(--p2); color: #fff; }
.priority .p3:has(input:checked) { background: var(--p3); color: #fff; }

.list-editor { list-style: none; margin: 0.6rem 0; padding: 0; }
.list-editor li { display: flex; gap: 8px; align-items: center; padding: 4px 0; }
.list-editor input { flex: 1; }
.list-editor button { margin: 0; }
.add-row { display: flex; gap: 8px; align-items: center; margin-top: 0.6rem; }
.add-row input { flex: 1; min-width: 0; }

/* Account */
.status { margin: 0; font-weight: 600; }
.status.on { color: var(--good); }
.status.off { color: var(--muted); }
.status.bad { color: var(--bad); }
.unsaved { position: fixed; z-index: 35; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom)); width: min(calc(100vw - 32px), 608px);
  display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25); }
.unsaved span { flex: 1; }
.wrap:has(.unsaved:not([hidden])) { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.presets { list-style: none; margin: 0; padding: 0; }
.presets li { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.presets input[type=text] { flex: 1; min-width: 0; }
.presets input[type=time] { width: 9.5rem; flex: none; }
.presets button { width: 40px; padding: 0; color: var(--muted); font-size: 1.2rem; }
#add-preset { margin-top: 0.2rem; }
.people { list-style: none; margin: 0; padding: 0; }
.people li { display: flex; align-items: center; gap: 8px; padding: 6px 0;
  border-bottom: 1px solid var(--border); }
.person { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.person small { margin-left: 4px; color: var(--muted); font-weight: normal; }
button.small { min-height: 36px; padding: 0.3rem 0.7rem; font-size: 0.85rem; }

dialog { width: min(94vw, 480px); max-height: 92vh; max-height: 92dvh; padding: 16px; border: 1px solid var(--border);
  border-radius: 14px; background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog h2 { margin-bottom: 0.2rem; }
/* Stays at the top of the editor as it scrolls, so Save is reachable with the keyboard open. */
.dialog-top { position: sticky; top: -16px; z-index: 2; display: flex; align-items: center; gap: 8px;
  margin: -16px -16px 10px; padding: 10px 16px; background: var(--card);
  border-bottom: 1px solid var(--border); }
.dialog-top h2 { flex: 1; margin: 0; }
.dialog-top button { min-width: 5.5rem; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 88px);
  transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 0.7rem 1rem;
  border-radius: 10px; background: var(--text); color: var(--bg); font-size: 0.95rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25); z-index: 40; }
.toast { display: flex; align-items: center; gap: 12px; }
.toast button { min-height: 32px; padding: 0.2rem 0.6rem; border: 0; background: none;
  color: var(--bg); text-decoration: underline; }
.toast.is-error { background: var(--bad); color: #fff; }

/* Round add button floating over the page, at the bottom right of the column. */
.fab { position: fixed; z-index: 30; display: flex; align-items: center; justify-content: center;
  right: max(calc(16px + env(safe-area-inset-right)), calc(50% - 304px));
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; min-height: 0; margin: 0; padding: 0; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-text); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3); }
.wrap:has(.fab) { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

