:root {
  --bg: #f4f4f7;
  --surface: #ffffff;
  --surface-2: #f0f0f4;
  --text: #1c1c1e;
  --text-2: #6e6e73;
  --text-3: #a1a1a6;
  --line: rgba(60, 60, 67, 0.12);
  --accent: #4f46e5;
  --accent-soft: rgba(79, 70, 229, 0.1);
  --on-accent: #ffffff;
  --urgent: #e5484d;
  --urgent-soft: rgba(229, 72, 77, 0.12);
  --today: #d97706;
  --today-soft: rgba(245, 158, 11, 0.14);
  --low: #8e8e93;
  --low-soft: rgba(142, 142, 147, 0.14);
  --good: #16a34a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 2px 8px rgba(0, 0, 0, 0.04);
  --radius: 14px;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111114;
    --surface: #1c1c1f;
    --surface-2: #26262a;
    --text: #f2f2f7;
    --text-2: #98989f;
    --text-3: #636366;
    --line: rgba(255, 255, 255, 0.09);
    --accent: #8b85ff;
    --accent-soft: rgba(139, 133, 255, 0.16);
    --on-accent: #111114;
    --urgent: #ff6369;
    --urgent-soft: rgba(255, 99, 105, 0.16);
    --today: #fbbf24;
    --today-soft: rgba(251, 191, 36, 0.14);
    --low-soft: rgba(142, 142, 147, 0.2);
    --good: #4ade80;
    --shadow: none;
  }
}

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

.boot { height: 100dvh; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  padding: calc(var(--top) + 10px) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
}
.topbar-row { display: flex; align-items: center; gap: 8px; max-width: 760px; margin: 0 auto; }
.topbar h1 { font-size: 30px; line-height: 1.15; letter-spacing: -0.02em; margin: 0; flex: 1; min-width: 0; }
.topbar .sub { max-width: 760px; margin: 2px auto 0; color: var(--text-2); font-size: 14px; }
.topbar .sub b { color: var(--text); font-weight: 600; }
.topbar .sub .red { color: var(--urgent); }
.topbar .sub .amber { color: var(--today); }

.icon-btn {
  width: 40px; height: 40px; border-radius: 20px; border: 0;
  background: var(--surface); box-shadow: var(--shadow);
  display: inline-grid; place-items: center; color: var(--accent); flex: none; text-decoration: none;
}
.icon-btn svg { width: 20px; height: 20px; }
.back-btn {
  border: 0; background: none; color: var(--accent); font-size: 17px; padding: 8px 4px 8px 0; text-decoration: none;
  display: inline-flex; align-items: center; gap: 2px;
}
.back-btn svg { width: 22px; height: 22px; }

/* ---------- group filter chips ---------- */
.chips {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  max-width: 760px; margin: 10px auto 0; padding: 2px 0 4px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; border-radius: 999px; padding: 7px 13px; font-size: 14px; font-weight: 500;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow); white-space: nowrap;
}
.chip .n { color: var(--text-3); margin-left: 4px; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.chip[aria-pressed="true"] .n { color: inherit; opacity: 0.75; }

/* ---------- content ---------- */
.content {
  max-width: 760px; margin: 0 auto;
  padding: 8px max(16px, env(safe-area-inset-right)) calc(var(--bottom) + 104px) max(16px, env(safe-area-inset-left));
}
.section-title {
  display: flex; align-items: baseline; gap: 8px; margin: 22px 4px 8px;
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-2);
}
.section-title .n { color: var(--text-3); font-weight: 500; }

.card-list { display: grid; gap: 10px; }

.task {
  display: grid; grid-template-columns: 44px 1fr; align-items: start;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px 12px 4px; transition: opacity 0.25s, transform 0.25s;
}
.task.leaving { opacity: 0; transform: translateX(24px); }
.task .check {
  width: 44px; height: 44px; margin-top: -8px; border: 0; background: none; display: grid; place-items: center; padding: 0;
}
.task .check span {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--text-3); display: grid; place-items: center;
  transition: background 0.15s, border-color 0.15s;
}
.task .check svg { width: 14px; height: 14px; color: var(--on-accent); opacity: 0; }
.task .check:hover span { border-color: var(--accent); }
.task.checked .check span { background: var(--good); border-color: var(--good); }
.task.checked .check svg { opacity: 1; color: #fff; }
.task .body { min-width: 0; border: 0; background: none; text-align: left; padding: 0; cursor: pointer; }
.task .title-row { display: flex; align-items: flex-start; gap: 8px; }
.task .title { font-weight: 600; font-size: 16px; line-height: 1.3; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.task .desc { margin: 4px 0 0; color: var(--text); opacity: 0.86; font-size: 14.5px; line-height: 1.4; overflow-wrap: anywhere; }
.task .meta { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; color: var(--text-2); }
.task .meta .src { flex-basis: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task .meta .red { color: var(--urgent); font-weight: 600; }
.task .meta .amber { color: var(--today); font-weight: 600; }

.pill {
  flex: none; font-size: 11.5px; font-weight: 600; border-radius: 999px; padding: 2px 8px; line-height: 1.5;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.pill.urgent { background: var(--urgent-soft); color: var(--urgent); }
.pill.normal { background: var(--accent-soft); color: var(--accent); }
.pill.low { background: var(--low-soft); color: var(--low); }
.pill.group { background: var(--surface-2); color: var(--text-2); text-transform: none; letter-spacing: 0; font-weight: 500; }

.empty { text-align: center; color: var(--text-2); padding: 64px 24px; }
.empty .big { font-size: 44px; margin-bottom: 8px; }
.empty h2 { color: var(--text); margin: 0 0 6px; font-size: 20px; }
.empty p { margin: 0 auto; max-width: 340px; }

.fab {
  position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: calc(var(--bottom) + 20px); z-index: 20;
  width: 56px; height: 56px; border-radius: 28px; border: 0; background: var(--accent); color: var(--on-accent);
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.35); display: grid; place-items: center;
}
.fab svg { width: 26px; height: 26px; }

/* ---------- done history ---------- */
.done-item {
  display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px;
}
.done-item .title { font-weight: 600; font-size: 15px; text-decoration: line-through; text-decoration-color: var(--text-3); overflow-wrap: anywhere; }
.done-item .meta { font-size: 12.5px; color: var(--text-2); margin-top: 3px; }
.done-item .desc { font-size: 13.5px; color: var(--text-2); margin-top: 4px; overflow-wrap: anywhere; }

/* ---------- settings ---------- */
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel + .panel-note { margin: 8px 4px 0; }
.panel-note { color: var(--text-2); font-size: 13px; margin: 8px 4px 0; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 48px;
  border-top: 0.5px solid var(--line);
}
.row:first-child { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .label { font-size: 15.5px; overflow-wrap: anywhere; }
.row .hint { font-size: 12.5px; color: var(--text-2); margin-top: 2px; overflow-wrap: anywhere; }
.row .hint.ok { color: var(--good); }
.row .hint.bad { color: var(--urgent); }
.row code { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.row form { display: flex; gap: 8px; width: 100%; }

/* ---------- buttons & fields ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 600; font-size: 16px;
  background: var(--accent); color: var(--on-accent); display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.small { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.plain { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--urgent-soft); color: var(--urgent); }
.btn[disabled] { opacity: 0.5; cursor: default; }
.btn svg { width: 20px; height: 20px; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.input, .field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 11px 12px; font-size: 16px; outline: none; appearance: none; -webkit-appearance: none;
}
.field textarea { min-height: 96px; resize: vertical; line-height: 1.4; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field select {
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px;
}
.date-row { display: flex; gap: 8px; }
.date-row input { flex: 1; min-width: 0; }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.segmented button { border: 0; background: none; border-radius: 9px; padding: 8px 4px; font-size: 14.5px; font-weight: 500; color: var(--text-2); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.segmented button[aria-pressed="true"][data-p="urgent"] { color: var(--urgent); }

.readonly { font-size: 14px; color: var(--text-2); display: grid; gap: 4px; margin: 4px 0 16px; }
.readonly b { color: var(--text); font-weight: 500; }

/* ---------- sign-in screens ---------- */
.auth {
  min-height: 100dvh; display: grid; place-items: center;
  padding: calc(var(--top) + 24px) 20px calc(var(--bottom) + 24px);
}
.auth-card { width: 100%; max-width: 380px; text-align: center; }
.auth-card .logo { width: 76px; height: 76px; border-radius: 18px; box-shadow: 0 8px 24px rgba(79, 70, 229, 0.25); }
.auth-card h1 { font-size: 26px; margin: 18px 0 6px; letter-spacing: -0.01em; }
.auth-card p { color: var(--text-2); margin: 0 0 22px; }
.auth-card form { display: grid; gap: 12px; text-align: left; }
.auth-card .input { text-align: center; font-size: 20px; letter-spacing: 0.12em; padding: 14px; }
.auth-card .error { color: var(--urgent); font-size: 14px; min-height: 20px; margin: 0; text-align: center; }
.auth-card .steps { display: flex; justify-content: center; gap: 6px; margin-bottom: 18px; }
.auth-card .steps i { width: 26px; height: 4px; border-radius: 2px; background: var(--line); }
.auth-card .steps i.on { background: var(--accent); }
.faceid { width: 22px; height: 22px; }

/* ---------- sheet (edit / add) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.35);
  display: flex; align-items: flex-end; justify-content: center; animation: fade 0.2s ease;
}
.sheet {
  width: 100%; max-width: 560px; max-height: calc(100dvh - var(--top) - 24px); overflow-y: auto;
  background: var(--bg); border-radius: 20px 20px 0 0; padding: 8px 18px calc(var(--bottom) + 18px);
  animation: rise 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet .grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 14px; }
.sheet-head h2 { font-size: 20px; margin: 0; }
.sheet-head button { border: 0; background: none; color: var(--accent); font-size: 16px; padding: 6px 0; }
.sheet-actions { display: grid; gap: 10px; margin-top: 8px; }
.sheet-actions .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (min-width: 700px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 20px; padding-bottom: 18px; }
  .sheet .grabber { display: none; }
}
@keyframes rise { from { transform: translateY(40px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--bottom) + 88px); transform: translateX(-50%); z-index: 60;
  background: #1c1c1e; color: #fff; border-radius: 14px; padding: 10px 10px 10px 16px;
  display: flex; align-items: center; gap: 14px; font-size: 15px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  width: max-content; max-width: calc(100vw - 32px); animation: rise 0.2s ease;
}
#toast button { border: 0; background: rgba(255, 255, 255, 0.14); color: #fff; border-radius: 10px; padding: 6px 12px; font-weight: 600; }
@media (prefers-color-scheme: dark) { #toast { background: #3a3a3f; } }

.muted { color: var(--text-2); }
.center { text-align: center; }
.mt { margin-top: 16px; }
.spinner {
  width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite; margin: 48px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.copy-area { width: 100%; height: 120px; font: 11px ui-monospace, Menlo, monospace; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); padding: 8px; }
.code-big { font: 600 34px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.12em; margin: 18px 0 10px; }
