:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --border: #e3e1dc;
  --accent: #1d1d1f;
  --accent-text: #ffffff;
  --danger: #d93036;
  --p1: #e5484d; --p1-bg: #fdeceb;
  --p2: #e8850c; --p2-bg: #fff2e0;
  --p3: #7c8ba1; --p3-bg: #eef1f5;
  --radius: 14px;
  --bar-h: 66px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --surface: #1c1c1f;
    --text: #f2f2f3;
    --muted: #9a9aa1;
    --border: #2c2c31;
    --accent: #f2f2f3;
    --accent-text: #111113;
    --danger: #ff6369;
    --p1: #ff6369; --p1-bg: #3a1c1e;
    --p2: #ffa94d; --p2-bg: #3a2a14;
    --p3: #8d9bb0; --p3-bg: #232830;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--p, var(--text)); outline-offset: 2px; }

.p1 { --p: var(--p1); --p-bg: var(--p1-bg); }
.p2 { --p: var(--p2); --p-bg: var(--p2-bg); }
.p3 { --p: var(--p3); --p-bg: var(--p3-bg); }

/* Buttons and fields */
.field, .add-input, .edit-text {
  width: 100%;
  min-width: 0;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.btn {
  height: 44px;
  padding: 0 14px;
  border-radius: 10px;
  font-weight: 600;
  background: var(--bg);
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.armed { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .5; }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login form { width: min(100%, 360px); display: grid; gap: 12px; }
.login h1 { margin: 0 0 8px; font-size: 32px; }
.login .btn { height: 48px; }
.error { margin: 0; color: var(--danger); }

/* App shell */
.app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom) + 24px);
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.tabs {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border-radius: 12px;
  background: var(--border);
}
.tab { height: 44px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.count { margin-left: 6px; font-size: 13px; font-weight: 500; opacity: .7; }
.icon-btn { flex: none; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 12px; color: var(--muted); }
.icon-btn:active { background: var(--border); }
.title { flex: 1; margin: 0; font-size: 20px; }

/* List */
.list {
  list-style: none;
  margin: 0;
  padding: 4px max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  display: grid;
  gap: 8px;
}
.todo {
  display: flex;
  align-items: center;
  min-height: 56px;
  border-left: 5px solid var(--p);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 2px rgb(0 0 0 / .06);
  transition: opacity .2s;
}
.todo.completing { opacity: .35; }
.check { flex: none; align-self: stretch; width: 54px; display: grid; place-items: center; }
.check::before {
  content: '';
  width: 24px;
  height: 24px;
  border: 2px solid var(--p);
  border-radius: 50%;
  background: var(--p-bg);
  transition: background .15s;
}
.check.checked::before { background: var(--p); box-shadow: inset 0 0 0 4px var(--surface); }
.todo .text {
  flex: 1;
  min-width: 0;
  padding: 14px 14px 14px 0;
  text-align: left;
  overflow-wrap: anywhere;
}
.todo.done { gap: 6px; padding-right: 8px; }
.todo.done .text { padding-left: 14px; }
.todo.done .label { color: var(--muted); text-decoration: line-through; }
.meta { display: block; margin-top: 2px; font-size: 13px; color: var(--muted); }
.todo.done .btn { padding: 0 12px; font-size: 14px; }

/* Editor */
.todo.editing { display: block; padding: 12px; }
.editor { display: grid; gap: 10px; }
.edit-text { height: 46px; background: var(--bg); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Priority picker */
.prio-picker { display: flex; gap: 6px; }
.prio {
  flex: 1;
  height: 44px;
  padding: 0 12px;
  border: 2px solid var(--p);
  border-radius: 999px;
  background: var(--p-bg);
  color: var(--p);
  font-size: 14px;
  font-weight: 700;
}
.prio[aria-checked="true"] { background: var(--p); color: #fff; }
/* Add bar: 44px tap targets drawn as small dots */
.addbar .prio-picker { gap: 0; }
.addbar .prio { flex: none; width: 44px; padding: 0; border: 0; background: none; display: grid; place-items: center; }
.addbar .prio::before {
  content: '';
  width: 26px;
  height: 26px;
  border: 2px solid var(--p);
  border-radius: 50%;
  background: var(--p-bg);
}
.addbar .prio[aria-checked="true"]::before { background: var(--p); }

/* Add bar */
.addbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  padding: 10px max(12px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.addbar-inner { max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 8px; }
.add-input { flex: 1; height: 46px; }
.add-btn {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 28px;
  line-height: 1;
}

/* Empty state + toast */
.empty { margin: 0; padding: 56px 16px; text-align: center; color: var(--muted); }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bar-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 10;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 10px 10px 16px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 6px 20px rgb(0 0 0 / .2);
}
.toast button {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 8px;
  font-weight: 700;
  background: color-mix(in srgb, var(--accent-text) 18%, transparent);
}
