:root {
  --bg: #0b1220;
  --bg-elevated: #121a2b;
  --panel: #162033;
  --panel-2: #1b2740;
  --border: #2a3a58;
  --text: #e8eef9;
  --muted: #8b9bb8;
  --faint: #5c6d8c;
  --accent: #5b8cff;
  --accent-2: #34d399;
  --danger: #f87171;
  --warn: #fbbf24;
  --ok: #34d399;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: ui-sans-serif, system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100%;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 400px at 50% -10%, rgba(91, 140, 255, 0.14), transparent 60%),
    var(--bg);
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: rgba(11, 18, 32, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar .title {
  flex: 1;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.topbar .brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 12px rgba(91, 140, 255, 0.55);
}
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: grid; place-items: center;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.icon-btn:active { transform: scale(0.96); }
.icon-btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--accent);
  font-weight: 600;
  width: auto;
  padding: 0 8px;
  font-size: 15px;
}
.icon-btn.primary {
  background: linear-gradient(135deg, #3b6fe0, #2f9d78);
  border-color: transparent;
  color: #fff;
  width: auto;
  padding: 0 14px;
  font-weight: 600;
  font-size: 14px;
}

/* ---------- main ---------- */
.main {
  flex: 1;
  padding: 14px 16px calc(24px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.banner {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
  color: var(--muted);
}
.banner strong { color: var(--text); font-weight: 600; }
.banner .sim {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(91, 140, 255, 0.12);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.section-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 0 4px;
}

/* ---------- task list ---------- */
.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.task-card {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 12px;
  align-items: start;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 14px 12px;
  text-align: left;
  width: 100%;
  color: inherit;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.task-card:active { background: var(--panel-2); }
.task-card.done .task-title { color: var(--muted); text-decoration: line-through; }
.check {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border);
  margin-top: 1px;
  display: grid; place-items: center;
  flex-shrink: 0;
  background: transparent;
}
.check.checked {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #052e1c;
}
.check svg { width: 14px; height: 14px; }
.task-body { min-width: 0; }
.task-title {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
  word-break: break-word;
}
.task-meta {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(91, 140, 255, 0.14);
  color: var(--accent);
}
.pill.linked { background: rgba(52, 211, 153, 0.14); color: var(--accent-2); }
.pill.none { background: rgba(139, 155, 184, 0.12); color: var(--muted); }
.chev { color: var(--faint); margin-top: 4px; }

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty h3 { color: var(--text); margin-bottom: 8px; font-size: 17px; }
.empty p { font-size: 14px; max-width: 280px; margin: 0 auto 16px; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--faint);
}
.field input,
.field textarea {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  outline: none;
  resize: vertical;
  min-height: 44px;
}
.field input:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.18);
}
.field textarea.note-body {
  min-height: min(55vh, 420px);
  line-height: 1.55;
  font-size: 16px;
}
.field .hint { font-size: 12px; color: var(--muted); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.btn {
  appearance: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 15px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  min-height: 44px;
}
.btn:active { transform: scale(0.98); }
.btn.primary {
  background: linear-gradient(135deg, #3b6fe0, #2f9d78);
  border-color: transparent;
  color: #fff;
  flex: 1;
}
.btn.danger {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.35);
  color: var(--danger);
}
.btn.ghost {
  background: transparent;
}
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- bridge panel ---------- */
.bridge {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(91, 140, 255, 0.12), rgba(52, 211, 153, 0.1)),
    var(--panel);
  border: 1px solid var(--border);
}
.bridge h3 {
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.bridge p { font-size: 13px; color: var(--muted); }
.bridge .ids {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--faint);
  word-break: break-all;
}
.link-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- status bar ---------- */
.footer-meta {
  margin-top: auto;
  padding-top: 8px;
  font-size: 11px;
  color: var(--faint);
  text-align: center;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%) translateY(120%);
  background: #1f2b44;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 50;
  opacity: 0;
  transition: transform 0.22s ease, opacity 0.22s ease;
  max-width: calc(100% - 32px);
  pointer-events: none;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ---------- filter tabs ---------- */
.tabs {
  display: flex;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
}
.tab {
  flex: 1;
  padding: 8px 10px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
}
.tab.active {
  background: var(--panel-2);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(255,255,255,0.04);
}

/* ---------- modal-ish new task ---------- */
.composer {
  display: flex;
  gap: 8px;
}
.composer input {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  min-height: 44px;
}
.composer input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.18);
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}
